react-native-unit-components
Version:
Unit React Native components
90 lines (88 loc) • 3.42 kB
JavaScript
import { Platform } from 'react-native';
import { fetchUnitScript } from './UnitSdk.api';
import { UnitUiManager } from './unitUiManager/unitUiManager';
import { warnClientIfNeeded } from '../utils/webVersioningStrategy.utils';
import { UNSDKConstants } from './UnitSdk.constants';
import { setTheme, setLanguage } from '../slices/ConfigurationSlice';
import { store } from '../store/store';
import { UserDataKeys } from '../types/internal/unitStore.types';
import UNStoreManagerHelper from '../nativeModulesHelpers/UNStoreManagerHelper/UNStoreManagerHelper';
import { UnitHelpersManager } from './unitHelpersManager/UnitHelpersManager';
import UNSecurityManagerHelper from '../nativeModulesHelpers/UNSecurityHelper';
import { UNSnapshotProtectionStrategy } from '../types/shared/securitySettings';
import UNSnapshotProtectionHelper from '../nativeModulesHelpers/UNSanpshotProtectionHelper/UNSnapshotProtectionHelper';
export class UnitSDK {
static securitySettings = UNSDKConstants.securitySettings;
static sdkVersion = '1.15.0';
static init = async (env, theme, language, fonts, webVersioningStrategy = UNSDKConstants.webSDKRecommendedStrategy, securitySettings = UNSDKConstants.securitySettings) => {
try {
this.webVersioningStrategy = webVersioningStrategy;
this.ui = new UnitUiManager();
this.helpers = new UnitHelpersManager();
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 != UNSnapshotProtectionStrategy.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 => {
this.customerToken = customerToken;
};
static getCustomerToken = () => {
return this.customerToken;
};
static getSdkVersion = () => {
return this.sdkVersion;
};
static cleanUserData = () => {
UNStoreManagerHelper.cleanValue(UserDataKeys.unitCustomerToken);
UNStoreManagerHelper.cleanValue(UserDataKeys.unitVerifiedToken);
};
}
//# sourceMappingURL=UnitSdkManager.js.map