react-native-gigya-sdk
Version:
SAP CDC/Gigya SDK for your React Native applications
36 lines (33 loc) • 2.02 kB
JavaScript
import sendApiCall from './sendApiCall';
export default function () {
return new Promise(async (resolve, reject) => {
try {
var _currentSiteConsents$;
const completeGigyaSchema = await sendApiCall('accounts.getSchema');
const currentSiteConsents = await sendApiCall('accounts.getConsentsStatements');
const output = {
instantiationRequired: [],
acceptanceRequired: []
};
Object.entries((_currentSiteConsents$ = currentSiteConsents === null || currentSiteConsents === void 0 ? void 0 : currentSiteConsents.preferences) !== null && _currentSiteConsents$ !== void 0 ? _currentSiteConsents$ : {}).forEach(entry => {
var _completeGigyaSchema$, _entry$, _entry$2;
const consentStatementSchema = completeGigyaSchema === null || completeGigyaSchema === void 0 ? void 0 : (_completeGigyaSchema$ = completeGigyaSchema.preferencesSchema) === null || _completeGigyaSchema$ === void 0 ? void 0 : _completeGigyaSchema$.fields[entry[0]];
const isCurrentSiteConsentInstantiationRequired = consentStatementSchema === null || consentStatementSchema === void 0 ? void 0 : consentStatementSchema.required;
const isGlobalSiteConsentAcceptanceRequired = ((_entry$ = entry[1]) === null || _entry$ === void 0 ? void 0 : _entry$.isActive) && ((_entry$2 = entry[1]) === null || _entry$2 === void 0 ? void 0 : _entry$2.isMandatory);
if (consentStatementSchema) {
if (isGlobalSiteConsentAcceptanceRequired) {
consentStatementSchema.key = entry[0];
output.acceptanceRequired = [...output.acceptanceRequired, consentStatementSchema];
} else if (isCurrentSiteConsentInstantiationRequired) {
consentStatementSchema.key = entry[0];
output.instantiationRequired = [...output.instantiationRequired, consentStatementSchema];
}
}
});
resolve(output);
} catch (e) {
reject(e);
}
});
}
//# sourceMappingURL=getRequiredConsentSchemas.js.map