react-native-gigya-sdk
Version:
SAP CDC/Gigya SDK for your React Native applications
46 lines (39 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _sendApiCall = _interopRequireDefault(require("./sendApiCall"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _default() {
return new Promise(async (resolve, reject) => {
try {
var _currentSiteConsents$;
const completeGigyaSchema = await (0, _sendApiCall.default)('accounts.getSchema');
const currentSiteConsents = await (0, _sendApiCall.default)('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