UNPKG

react-native-gigya-sdk

Version:
58 lines (50 loc) 2 kB
import getState from './getState'; import sendApiCall from './sendApiCall'; export default function (consentSchemaKeys, options) { return new Promise(async (resolve, reject) => { try { var _state$regToken; if (consentSchemaKeys.length < 1) { return reject(new Error('No consent schema provided')); } const state = await getState(); const preferences = {}; for (let key of consentSchemaKeys) { const keyParts = key.split('.'); let objectBuild = {}; for (let index = keyParts.length - 1; index >= 0; index--) { const currentKey = keyParts[index]; let addedValue = objectBuild; if (index === keyParts.length - 1) { addedValue = { isConsentGranted: true }; } if (index === 0) { var _preferences$currentK; preferences[currentKey] = { ...((_preferences$currentK = preferences[currentKey]) !== null && _preferences$currentK !== void 0 ? _preferences$currentK : {}), ...addedValue }; } else { const tempObjectBuild = {}; tempObjectBuild[currentKey] = addedValue; objectBuild = tempObjectBuild; } } } const response = await sendApiCall('accounts.setAccountInfo', { ...((options === null || options === void 0 ? void 0 : options.noUID) && { regToken: (options === null || options === void 0 ? void 0 : options.regToken) || ((_state$regToken = state.regToken) === null || _state$regToken === void 0 ? void 0 : _state$regToken.value) }), ...(!(options !== null && options !== void 0 && options.noUID) && { UID: (options === null || options === void 0 ? void 0 : options.UID) || state.UID }), lang: state.lang, preferences }); resolve(response); } catch (e) { reject(e); } }); } //# sourceMappingURL=acceptConsentSchemas.js.map