UNPKG

react-native-unit-components

Version:

Unit React Native components

87 lines (85 loc) 3.56 kB
import { Platform } from 'react-native'; import { fetchUnitScript } from './UnitComponentsSdk.api'; import { UnitComponentsUiManager } from './unitComponentsUiManager/unitComponentsUiManager'; import { warnClientIfNeeded } from '../utils/webVersioningStrategy.utils'; import { UNComponentsSDKConstants } from './UnitComponentsSdk.constants'; import { setTheme, setLanguage, setCustomerToken } from '../slices/ConfigurationSlice'; import { store } from '../store/store'; import { UserDataKeys } from '../types/internal/unitStore.types'; import UNStoreManagerHelper from '../nativeModulesHelpers/UNStoreModuleHelper/UNStoreModuleHelper'; import { UnitComponentsHelpersManager } from './unitComponentsHelpersManager/UnitComponentsHelpersManager'; import UNSecurityManagerHelper from '../nativeModulesHelpers/UNSecurityHelper'; import { UNComponentsSnapshotProtectionStrategy } from '../types/shared/securitySettings'; import UNSnapshotProtectionHelper from '../nativeModulesHelpers/UNSanpshotProtectionHelper/UNSnapshotProtectionHelper'; export class UnitComponentsSDK { static securitySettings = UNComponentsSDKConstants.securitySettings; static sdkVersion = '2.0.0'; static init = async (env, theme, language, fonts, webVersioningStrategy = UNComponentsSDKConstants.webSDKRecommendedStrategy, securitySettings = UNComponentsSDKConstants.securitySettings) => { try { this.webVersioningStrategy = webVersioningStrategy; this.ui = new UnitComponentsUiManager(); this.helpers = new UnitComponentsHelpersManager(); const isJailbroke = await UNSecurityManagerHelper.isDeviceJailbroke(); if (isJailbroke) { throw Error('Device is jailbroke'); } this.env = env; this.securitySettings = securitySettings; this.fonts = fonts; store.dispatch(setTheme(theme)); store.dispatch(setLanguage(language)); warnClientIfNeeded(this.webVersioningStrategy); const shouldProtectFromSnapshot = securitySettings.snapshotProtectionStrategy != UNComponentsSnapshotProtectionStrategy.None; if (Platform.OS === 'ios') { UNSnapshotProtectionHelper.setIosSecurity(shouldProtectFromSnapshot, 'light'); } await fetchUnitScript(); } catch (e) { console.log(e); } }; static isInitialized = () => { return this.env != undefined; }; static setPushProvisioningModule = pushProvisionModule => { this.pushProvisionModule = pushProvisionModule; }; static getPushProvisionModule = () => { return this.pushProvisionModule; }; static getSecuritySettings = () => { return this.securitySettings; }; /** * @deprecated - Unit SDK is managing the signedNonce, no need to provide it */ static setSignedNonce = signedNonce => { this.signedNonce = signedNonce; }; static getEnv = () => { return this.env; }; static getWebVersioningStrategy = () => { return this.webVersioningStrategy; }; static getFonts = () => { return this.fonts; }; /** * @deprecated - Unit SDK is managing the signedNonce, no need to provide it */ static getSignedNonce = () => { return this.signedNonce; }; static setCustomerToken = customerToken => { store.dispatch(setCustomerToken(customerToken)); }; static getSdkVersion = () => { return this.sdkVersion; }; static cleanUserData = () => { UNStoreManagerHelper.cleanValue(UserDataKeys.unitCustomerToken); UNStoreManagerHelper.cleanValue(UserDataKeys.unitVerifiedToken); }; } //# sourceMappingURL=UnitComponentsSdkManager.js.map