UNPKG

react-native-qonversion

Version:

Qonversion provides full in-app purchases infrastructure, so you do not need to build your own server for receipt validation. Implement in-app subscriptions, validate user receipts, check subscription status, and provide access to your app features and co

69 lines 3.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_native_1 = require("react-native"); const Mapper_1 = __importDefault(require("./Mapper")); const NoCodesError_1 = __importDefault(require("../dto/NoCodesError")); const enums_1 = require("../dto/enums"); const { RNNoCodes } = react_native_1.NativeModules; const EVENT_SCREEN_SHOWN = "nocodes_screen_shown"; const EVENT_FINISHED = "nocodes_finished"; const EVENT_ACTION_STARTED = "nocodes_action_started"; const EVENT_ACTION_FAILED = "nocodes_action_failed"; const EVENT_ACTION_FINISHED = "nocodes_action_finished"; const EVENT_SCREEN_FAILED_TO_LOAD = "nocodes_screen_failed_to_load"; class NoCodesInternal { constructor(config) { RNNoCodes.initialize(config.projectKey); if (config.noCodesListener) { this.setNoCodesListener(config.noCodesListener); } } async setScreenPresentationConfig(config, contextKey) { const data = Mapper_1.default.convertScreenPresentationConfig(config); await RNNoCodes.setScreenPresentationConfig(data, contextKey); } async showScreen(contextKey) { await RNNoCodes.showScreen(contextKey); } async close() { await RNNoCodes.close(); } setNoCodesListener(listener) { const eventEmitter = new react_native_1.NativeEventEmitter(RNNoCodes); eventEmitter.removeAllListeners(EVENT_SCREEN_SHOWN); eventEmitter.addListener(EVENT_SCREEN_SHOWN, payload => { const screenId = payload["screenId"] ?? ""; listener.onScreenShown(screenId); }); eventEmitter.removeAllListeners(EVENT_ACTION_STARTED); eventEmitter.addListener(EVENT_ACTION_STARTED, payload => { const action = Mapper_1.default.convertAction(payload); listener.onActionStartedExecuting(action); }); eventEmitter.removeAllListeners(EVENT_ACTION_FAILED); eventEmitter.addListener(EVENT_ACTION_FAILED, payload => { const action = Mapper_1.default.convertAction(payload); listener.onActionFailedToExecute(action); }); eventEmitter.removeAllListeners(EVENT_ACTION_FINISHED); eventEmitter.addListener(EVENT_ACTION_FINISHED, payload => { const action = Mapper_1.default.convertAction(payload); listener.onActionFinishedExecuting(action); }); eventEmitter.removeAllListeners(EVENT_FINISHED); eventEmitter.addListener(EVENT_FINISHED, () => { listener.onFinished(); }); eventEmitter.removeAllListeners(EVENT_SCREEN_FAILED_TO_LOAD); eventEmitter.addListener(EVENT_SCREEN_FAILED_TO_LOAD, payload => { const error = Mapper_1.default.convertNoCodesError(payload); const defaultError = new NoCodesError_1.default(enums_1.NoCodesErrorCode.UNKNOWN, "Failed to load No-Code screen", "Native error parsing failed."); listener.onScreenFailedToLoad(error ?? defaultError); }); } } exports.default = NoCodesInternal; //# sourceMappingURL=NoCodesInternal.js.map