UNPKG

react-native-efilli-sdk

Version:
158 lines (157 loc) 5.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EfilliNetwork = exports.EfilliSDK = void 0; const react_native_1 = require("react-native"); const models_1 = require("./models"); const enums_1 = require("./enums"); const { RNReactNativeEfilliSdk } = react_native_1.NativeModules; /** * Main Efilli SDK interface */ exports.EfilliSDK = { /** * Initialize the SDK with required parameters * @param options Configuration options for the SDK */ initialize: async (options) => { try { if (!options.endpointUrl) { throw new Error((0, enums_1.getErrorTypeMessage)(enums_1.ErrorType.INVALID_URL)); } if (!options.language) { throw new Error((0, enums_1.getErrorTypeMessage)(enums_1.ErrorType.INVALID_PARAMETERS)); } return await RNReactNativeEfilliSdk.initialize(options); } catch (error) { console.error('Error initializing Efilli SDK:', error); throw error; } }, /** * Check if the SDK is initialized and ready */ isReady: async () => { try { return await RNReactNativeEfilliSdk.isReady(); } catch (error) { console.error('Error checking if SDK is ready:', error); throw error; } }, /** * Present the consent form to the user * @returns Promise resolving with consent result */ showConsentForm: async () => { try { const isReady = await RNReactNativeEfilliSdk.isReady(); if (!isReady) { throw new Error((0, enums_1.getErrorTypeMessage)(enums_1.ErrorType.NOT_INITIALIZED)); } const result = await RNReactNativeEfilliSdk.showConsentForm(); const consentResult = models_1.ConsentResult.fromJSON(result); if (!consentResult) { throw new Error((0, enums_1.getErrorTypeMessage)(enums_1.ErrorType.INVALID_MESSAGE_FORMAT)); } return consentResult; } catch (error) { console.error('Error showing consent form:', error); throw error; } }, /** * Get the stored consent result * @returns Promise resolving with consent result or null if not available */ getStoredConsent: async () => { try { const isReady = await RNReactNativeEfilliSdk.isReady(); if (!isReady) { throw new Error((0, enums_1.getErrorTypeMessage)(enums_1.ErrorType.NOT_INITIALIZED)); } const result = await RNReactNativeEfilliSdk.getStoredConsent(); return result ? models_1.ConsentResult.fromJSON(result) : null; } catch (error) { console.error('Error getting stored consent:', error); throw error; } }, /** * Change the SDK language * @param language The language code to change to */ changeLanguage: async (language) => { try { const isReady = await RNReactNativeEfilliSdk.isReady(); if (!isReady) { throw new Error((0, enums_1.getErrorTypeMessage)(enums_1.ErrorType.NOT_INITIALIZED)); } return await RNReactNativeEfilliSdk.changeLanguage(language); } catch (error) { console.error('Error changing language:', error); throw error; } }, /** * Clear all stored consent data */ clearAllData: async () => { try { const isReady = await RNReactNativeEfilliSdk.isReady(); if (!isReady) { throw new Error((0, enums_1.getErrorTypeMessage)(enums_1.ErrorType.NOT_INITIALIZED)); } return await RNReactNativeEfilliSdk.clearAllData(); } catch (error) { console.error('Error clearing data:', error); throw error; } }, /** * Close the SDK and clean up resources */ closeSDK: async () => { try { return await RNReactNativeEfilliSdk.closeSDK(); } catch (error) { console.error('Error closing SDK:', error); throw error; } } }; /** * Network management functions for error reporting and connection detection */ exports.EfilliNetwork = { /** * Posts error information to the error logging server */ postError: async (errorType, errorMessage, errorStack) => { try { return await RNReactNativeEfilliSdk.postError(errorType, errorMessage, errorStack); } catch (error) { console.error('Error posting error:', error); return false; } }, /** * Gets the current network connection type */ getConnectionType: async () => { try { return await RNReactNativeEfilliSdk.getConnectionType(); } catch (error) { console.error('Error getting connection type:', error); return 'UNKNOWN'; } } };