diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..cf6ee3c --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,29 @@ +name: Publish NPM package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: yarn install + - run: yarn build + + publish-npm: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + registry-url: https://registry.npmjs.org/ + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/build/main/index.d.ts b/build/main/index.d.ts deleted file mode 100644 index 385e685..0000000 --- a/build/main/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Bridge } from './types/bridgeInterface'; -declare const _default: Bridge | null; -export default _default; diff --git a/build/main/index.js b/build/main/index.js deleted file mode 100644 index 4b03215..0000000 --- a/build/main/index.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const constants_1 = require("./lib/constants"); -const platformDetector_1 = __importDefault(require("./lib/platformDetector")); -const android_1 = __importDefault(require("./lib/platforms/android")); -const ios_1 = __importDefault(require("./lib/platforms/ios")); -const web_1 = __importDefault(require("./lib/platforms/web")); -const version_1 = require("./version"); -const getBridge = () => { - if (process.env.NODE_ENV === 'test') - return null; - const platform = (0, platformDetector_1.default)(); - console.log('Bridge ~ version', version_1.LIB_VERSION); - switch (platform) { - case constants_1.PLATFORM.ANDROID: - return new android_1.default(); - case constants_1.PLATFORM.IOS: - return new ios_1.default(); - case constants_1.PLATFORM.WEB: - return new web_1.default(); - default: - console.error('Wrong platform'); - break; - } - return null; -}; -exports.default = getBridge(); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSwrQ0FBMEM7QUFDMUMsOEVBQWdEO0FBQ2hELHNFQUFtRDtBQUNuRCw4REFBMkM7QUFDM0MsOERBQTJDO0FBRTNDLHVDQUF1QztBQUV2QyxNQUFNLFNBQVMsR0FBRyxHQUFrQixFQUFFO0lBQ3BDLElBQUksT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLEtBQUssTUFBTTtRQUFFLE9BQU8sSUFBSSxDQUFBO0lBRWhELE1BQU0sUUFBUSxHQUFHLElBQUEsMEJBQVcsR0FBRSxDQUFBO0lBQzlCLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0JBQWtCLEVBQUUscUJBQVcsQ0FBQyxDQUFBO0lBRTVDLFFBQVEsUUFBUSxFQUFFO1FBQ2hCLEtBQUssb0JBQVEsQ0FBQyxPQUFPO1lBQ25CLE9BQU8sSUFBSSxpQkFBYSxFQUFFLENBQUE7UUFDNUIsS0FBSyxvQkFBUSxDQUFDLEdBQUc7WUFDZixPQUFPLElBQUksYUFBUyxFQUFFLENBQUE7UUFDeEIsS0FBSyxvQkFBUSxDQUFDLEdBQUc7WUFDZixPQUFPLElBQUksYUFBUyxFQUFFLENBQUE7UUFDeEI7WUFDRSxPQUFPLENBQUMsS0FBSyxDQUFDLGdCQUFnQixDQUFDLENBQUE7WUFDL0IsTUFBSztLQUNSO0lBRUQsT0FBTyxJQUFJLENBQUE7QUFDYixDQUFDLENBQUE7QUFFRCxrQkFBZSxTQUFTLEVBQUUsQ0FBQSJ9 \ No newline at end of file diff --git a/build/main/lib/case.d.ts b/build/main/lib/case.d.ts deleted file mode 100644 index 15a5511..0000000 --- a/build/main/lib/case.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare const isUuid: (value: string) => boolean; -export declare const snakeCaseToCamelCase: (data: any) => any; -export declare const camelCaseToSnakeCase: (data: any) => any; diff --git a/build/main/lib/case.js b/build/main/lib/case.js deleted file mode 100644 index dbf2f50..0000000 --- a/build/main/lib/case.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.camelCaseToSnakeCase = exports.snakeCaseToCamelCase = exports.isUuid = void 0; -/* eslint-disable @typescript-eslint/no-explicit-any */ -const camelCase_1 = __importDefault(require("lodash/camelCase")); -const snakeCase_1 = __importDefault(require("lodash/snakeCase")); -const isUuid = (value) => { - return /[0-9a-fA-F-]{32}/.test(value); -}; -exports.isUuid = isUuid; -const snakeCaseToCamelCase = (data) => { - var _a; - if (Array.isArray(data)) - return data.map(exports.snakeCaseToCamelCase); - if (!data || ((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name) !== 'Object') - return data; - return Object.keys(data).reduce((result, key) => { - const value = (0, exports.snakeCaseToCamelCase)(data[key]); - const keyValue = (0, exports.isUuid)(key) ? key : (0, camelCase_1.default)(key); - return Object.assign(Object.assign({}, result), { [keyValue]: value }); - }, {}); -}; -exports.snakeCaseToCamelCase = snakeCaseToCamelCase; -const camelCaseToSnakeCase = (data) => { - var _a; - if (Array.isArray(data)) - return data.map(exports.camelCaseToSnakeCase); - if (!data || ((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name) !== 'Object') - return data; - return Object.keys(data).reduce((result, key) => { - const value = (0, exports.camelCaseToSnakeCase)(data[key]); - return Object.assign(Object.assign({}, result), { [(0, snakeCase_1.default)(key)]: value }); - }, {}); -}; -exports.camelCaseToSnakeCase = camelCaseToSnakeCase; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FzZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL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0FBQyxDQUFBO0FBQ1IsQ0FBQyxDQUFBO0FBUlksUUFBQSxvQkFBb0Isd0JBUWhDO0FBRU0sTUFBTSxvQkFBb0IsR0FBRyxDQUFDLElBQVMsRUFBTyxFQUFFOztJQUNyRCxJQUFJLEtBQUssQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDO1FBQUUsT0FBTyxJQUFJLENBQUMsR0FBRyxDQUFDLDRCQUFvQixDQUFDLENBQUE7SUFFOUQsSUFBSSxDQUFDLElBQUksSUFBSSxDQUFBLE1BQUEsSUFBSSxDQUFDLFdBQVcsMENBQUUsSUFBSSxNQUFLLFFBQVE7UUFBRSxPQUFPLElBQUksQ0FBQTtJQUU3RCxPQUFPLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsTUFBTSxFQUFFLEdBQUcsRUFBRSxFQUFFO1FBQzlDLE1BQU0sS0FBSyxHQUFHLElBQUEsNEJBQW9CLEVBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUE7UUFDN0MsdUNBQVksTUFBTSxLQUFFLENBQUMsSUFBQSxtQkFBUyxFQUFDLEdBQUcsQ0FBQyxDQUFDLEVBQUUsS0FBSyxJQUFFO0lBQy9DLENBQUMsRUFBRSxFQUFFLENBQUMsQ0FBQTtBQUNSLENBQUMsQ0FBQTtBQVRZLFFBQUEsb0JBQW9CLHdCQVNoQyJ9 \ No newline at end of file diff --git a/build/main/lib/constants.d.ts b/build/main/lib/constants.d.ts deleted file mode 100644 index 306b6bb..0000000 --- a/build/main/lib/constants.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -export declare enum PLATFORM { - WEB = "web", - IOS = "ios", - ANDROID = "android", - UNKNOWN = "unknown" -} -export declare enum EVENT_TYPE { - RECEIVE = "recv", - SEND = "send" -} -export declare enum HANDLER { - BOTX = "botx", - EXPRESS = "express" -} -export declare const RESPONSE_TIMEOUT = 30000; -export declare const WEB_COMMAND_TYPE = "smartapp"; -export declare const WEB_COMMAND_TYPE_RPC = "smartapp_rpc"; -export declare const WEB_COMMAND_TYPE_RPC_LOGS = "smartAppLogs"; diff --git a/build/main/lib/constants.js b/build/main/lib/constants.js deleted file mode 100644 index 3483a6b..0000000 --- a/build/main/lib/constants.js +++ /dev/null @@ -1,25 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.WEB_COMMAND_TYPE_RPC_LOGS = exports.WEB_COMMAND_TYPE_RPC = exports.WEB_COMMAND_TYPE = exports.RESPONSE_TIMEOUT = exports.HANDLER = exports.EVENT_TYPE = exports.PLATFORM = void 0; -var PLATFORM; -(function (PLATFORM) { - PLATFORM["WEB"] = "web"; - PLATFORM["IOS"] = "ios"; - PLATFORM["ANDROID"] = "android"; - PLATFORM["UNKNOWN"] = "unknown"; -})(PLATFORM = exports.PLATFORM || (exports.PLATFORM = {})); -var EVENT_TYPE; -(function (EVENT_TYPE) { - EVENT_TYPE["RECEIVE"] = "recv"; - EVENT_TYPE["SEND"] = "send"; -})(EVENT_TYPE = exports.EVENT_TYPE || (exports.EVENT_TYPE = {})); -var HANDLER; -(function (HANDLER) { - HANDLER["BOTX"] = "botx"; - HANDLER["EXPRESS"] = "express"; -})(HANDLER = exports.HANDLER || (exports.HANDLER = {})); -exports.RESPONSE_TIMEOUT = 30000; -exports.WEB_COMMAND_TYPE = 'smartapp'; -exports.WEB_COMMAND_TYPE_RPC = 'smartapp_rpc'; -exports.WEB_COMMAND_TYPE_RPC_LOGS = 'smartAppLogs'; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsSUFBWSxRQUtYO0FBTEQsV0FBWSxRQUFRO0lBQ2xCLHVCQUFXLENBQUE7SUFDWCx1QkFBVyxDQUFBO0lBQ1gsK0JBQW1CLENBQUE7SUFDbkIsK0JBQW1CLENBQUE7QUFDckIsQ0FBQyxFQUxXLFFBQVEsR0FBUixnQkFBUSxLQUFSLGdCQUFRLFFBS25CO0FBRUQsSUFBWSxVQUdYO0FBSEQsV0FBWSxVQUFVO0lBQ3BCLDhCQUFnQixDQUFBO0lBQ2hCLDJCQUFhLENBQUE7QUFDZixDQUFDLEVBSFcsVUFBVSxHQUFWLGtCQUFVLEtBQVYsa0JBQVUsUUFHckI7QUFFRCxJQUFZLE9BR1g7QUFIRCxXQUFZLE9BQU87SUFDakIsd0JBQWEsQ0FBQTtJQUNiLDhCQUFtQixDQUFBO0FBQ3JCLENBQUMsRUFIVyxPQUFPLEdBQVAsZUFBTyxLQUFQLGVBQU8sUUFHbEI7QUFFWSxRQUFBLGdCQUFnQixHQUFHLEtBQUssQ0FBQTtBQUN4QixRQUFBLGdCQUFnQixHQUFHLFVBQVUsQ0FBQTtBQUM3QixRQUFBLG9CQUFvQixHQUFHLGNBQWMsQ0FBQTtBQUNyQyxRQUFBLHlCQUF5QixHQUFHLGNBQWMsQ0FBQSJ9 \ No newline at end of file diff --git a/build/main/lib/eventEmitter.d.ts b/build/main/lib/eventEmitter.d.ts deleted file mode 100644 index 9cc50ef..0000000 --- a/build/main/lib/eventEmitter.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import EventEmitter from 'eventemitter3'; -import { EmitterEventPayload, EmitterEventType } from '../types/eventEmitter'; -/** - * Extended Event Emitted class - * - * ```typescript - * const emitter = new EmitterEventPayload(); - * - * // promise will be rejected in 20 secs - * // if no one event has been received with type 'ref-uuid-value' - * // otherwise promise will be fulfilled with payload object - * const promise = emitter.onceWithTimeout('ref-uuid-value', 20000) - * ``` - */ -declare class ExtendedEventEmitter extends EventEmitter { - constructor(); - /** - * Wait when event with `type` will be emitted for `timeout` ms. - * - * ```js - * emitter.onceWithTimeout('d6910a9d-ea24-5fc6-a654-28781ef21f8f', 20000) - * // => Promise - * ``` - */ - onceWithTimeout(type: EmitterEventType, timeout: number): Promise; -} -export default ExtendedEventEmitter; diff --git a/build/main/lib/eventEmitter.js b/build/main/lib/eventEmitter.js deleted file mode 100644 index 31b9562..0000000 --- a/build/main/lib/eventEmitter.js +++ /dev/null @@ -1,42 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const eventemitter3_1 = __importDefault(require("eventemitter3")); -/** - * Extended Event Emitted class - * - * ```typescript - * const emitter = new EmitterEventPayload(); - * - * // promise will be rejected in 20 secs - * // if no one event has been received with type 'ref-uuid-value' - * // otherwise promise will be fulfilled with payload object - * const promise = emitter.onceWithTimeout('ref-uuid-value', 20000) - * ``` - */ -class ExtendedEventEmitter extends eventemitter3_1.default { - constructor() { - super(); - } - /** - * Wait when event with `type` will be emitted for `timeout` ms. - * - * ```js - * emitter.onceWithTimeout('d6910a9d-ea24-5fc6-a654-28781ef21f8f', 20000) - * // => Promise - * ``` - */ - onceWithTimeout(type, timeout) { - return new Promise((resolve, reject) => { - const timer = setTimeout(() => reject(), timeout); - this.once(type, (event) => { - clearTimeout(timer); - resolve(event); - }); - }); - } -} -exports.default = ExtendedEventEmitter; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnRFbWl0dGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9ldmVudEVtaXR0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxrRUFBd0M7QUFJeEM7Ozs7Ozs7Ozs7O0dBV0c7QUFDSCxNQUFNLG9CQUFxQixTQUFRLHVCQUFZO0lBQzdDO1FBQ0UsS0FBSyxFQUFFLENBQUE7SUFDVCxDQUFDO0lBRUQ7Ozs7Ozs7T0FPRztJQUNILGVBQWUsQ0FBQyxJQUFzQixFQUFFLE9BQWU7UUFDckQsT0FBTyxJQUFJLE9BQU8sQ0FBQyxDQUFDLE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFBRTtZQUNyQyxNQUFNLEtBQUssR0FBRyxVQUFVLENBQUMsR0FBRyxFQUFFLENBQUMsTUFBTSxFQUFFLEVBQUUsT0FBTyxDQUFDLENBQUE7WUFFakQsSUFBSSxDQUFDLElBQUksQ0FBUyxJQUFJLEVBQUUsQ0FBQyxLQUEwQixFQUFFLEVBQUU7Z0JBQ3JELFlBQVksQ0FBQyxLQUFLLENBQUMsQ0FBQTtnQkFDbkIsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1lBQ2hCLENBQUMsQ0FBQyxDQUFBO1FBQ0osQ0FBQyxDQUFDLENBQUE7SUFDSixDQUFDO0NBQ0Y7QUFFRCxrQkFBZSxvQkFBb0IsQ0FBQSJ9 \ No newline at end of file diff --git a/build/main/lib/logger.d.ts b/build/main/lib/logger.d.ts deleted file mode 100644 index ef48cbb..0000000 --- a/build/main/lib/logger.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/** @ignore */ -declare const log: (...args: ReadonlyArray) => void; -export default log; diff --git a/build/main/lib/logger.js b/build/main/lib/logger.js deleted file mode 100644 index 65fc3ac..0000000 --- a/build/main/lib/logger.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -/** @ignore */ -const log = (...args) => { - const text = args.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '); - alert(text); -}; -exports.default = log; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9sb2dnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxjQUFjO0FBQ2QsTUFBTSxHQUFHLEdBQUcsQ0FBQyxHQUFHLElBQTRCLEVBQUUsRUFBRTtJQUM5QyxNQUFNLElBQUksR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsR0FBWSxFQUFVLEVBQUUsQ0FBQyxDQUFDLE9BQU8sR0FBRyxLQUFLLFFBQVEsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDaEgsS0FBSyxDQUFDLElBQUksQ0FBQyxDQUFBO0FBQ2IsQ0FBQyxDQUFBO0FBRUQsa0JBQWUsR0FBRyxDQUFBIn0= \ No newline at end of file diff --git a/build/main/lib/platformDetector.d.ts b/build/main/lib/platformDetector.d.ts deleted file mode 100644 index 6a8a663..0000000 --- a/build/main/lib/platformDetector.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { PLATFORM } from './constants'; -/** - * Get platform. Detection based on GET param `platform` or user agent. - * - * ```typescript - * const platform = getPlatform(); - * - * // => 'web' | 'ios' | 'android' - * ``` - */ -declare const getPlatform: () => PLATFORM; -export default getPlatform; diff --git a/build/main/lib/platformDetector.js b/build/main/lib/platformDetector.js deleted file mode 100644 index ae62ee0..0000000 --- a/build/main/lib/platformDetector.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const constants_1 = require("./constants"); -const getPlatformByGetParam = () => { - const platform = new URLSearchParams(location.search).get('platform'); - const isValidPlatform = Object.values(constants_1.PLATFORM).includes(platform); - if (isValidPlatform) - return platform; - return constants_1.PLATFORM.UNKNOWN; -}; -const detectPlatformByUserAgent = () => { - if (/android/i.test(navigator.userAgent)) { - return constants_1.PLATFORM.ANDROID; - } - if ((/iPad|iPhone|iPod/.test(navigator.userAgent) || - (navigator.userAgent.includes('Mac') && 'ontouchend' in document)) && - !window.MSStream) - return constants_1.PLATFORM.IOS; - return constants_1.PLATFORM.WEB; -}; -/** - * Get platform. Detection based on GET param `platform` or user agent. - * - * ```typescript - * const platform = getPlatform(); - * - * // => 'web' | 'ios' | 'android' - * ``` - */ -const getPlatform = () => { - return getPlatformByGetParam() || detectPlatformByUserAgent(); -}; -exports.default = getPlatform; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGxhdGZvcm1EZXRlY3Rvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvcGxhdGZvcm1EZXRlY3Rvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDJDQUFzQztBQUV0QyxNQUFNLHFCQUFxQixHQUFHLEdBQWEsRUFBRTtJQUMzQyxNQUFNLFFBQVEsR0FBRyxJQUFJLGVBQWUsQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDLENBQUMsR0FBRyxDQUFDLFVBQVUsQ0FBQyxDQUFBO0lBRXJFLE1BQU0sZUFBZSxHQUFHLE1BQU0sQ0FBQyxNQUFNLENBQUMsb0JBQVEsQ0FBQyxDQUFDLFFBQVEsQ0FBVyxRQUFRLENBQUMsQ0FBQTtJQUM1RSxJQUFJLGVBQWU7UUFBRSxPQUFpQixRQUFRLENBQUE7SUFFOUMsT0FBTyxvQkFBUSxDQUFDLE9BQU8sQ0FBQTtBQUN6QixDQUFDLENBQUE7QUFFRCxNQUFNLHlCQUF5QixHQUFHLEdBQWEsRUFBRTtJQUMvQyxJQUFJLFVBQVUsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLFNBQVMsQ0FBQyxFQUFFO1FBQ3hDLE9BQU8sb0JBQVEsQ0FBQyxPQUFPLENBQUE7S0FDeEI7SUFFRCxJQUNFLENBQUMsa0JBQWtCLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxTQUFTLENBQUM7UUFDM0MsQ0FBQyxTQUFTLENBQUMsU0FBUyxDQUFDLFFBQVEsQ0FBQyxLQUFLLENBQUMsSUFBSSxZQUFZLElBQUksUUFBUSxDQUFDLENBQUM7UUFDcEUsQ0FBRSxNQUFjLENBQUMsUUFBUTtRQUV6QixPQUFPLG9CQUFRLENBQUMsR0FBRyxDQUFBO0lBRXJCLE9BQU8sb0JBQVEsQ0FBQyxHQUFHLENBQUE7QUFDckIsQ0FBQyxDQUFBO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSCxNQUFNLFdBQVcsR0FBRyxHQUFhLEVBQUU7SUFDakMsT0FBTyxxQkFBcUIsRUFBRSxJQUFJLHlCQUF5QixFQUFFLENBQUE7QUFDL0QsQ0FBQyxDQUFBO0FBRUQsa0JBQWUsV0FBVyxDQUFBIn0= \ No newline at end of file diff --git a/build/main/lib/platforms/android.d.ts b/build/main/lib/platforms/android.d.ts deleted file mode 100644 index ad6035f..0000000 --- a/build/main/lib/platforms/android.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { Bridge, BridgeSendBotEventParams, BridgeSendClientEventParams, EventEmitterCallback } from '../../types'; -declare class AndroidBridge implements Bridge { - private readonly eventEmitter; - private readonly hasCommunicationObject; - logsEnabled: boolean; - isRenameParamsEnabledForBotx: boolean; - constructor(); - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - * @param callback - Callback function. - */ - onReceive(callback: EventEmitterCallback): void; - private sendEvent; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param files - * @param timeout - Timeout in ms. - * @param guaranteed_delivery_required - boolean. - * @returns Promise. - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }: BridgeSendBotEventParams): Promise; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param timeout - Timeout in ms. - * @returns Promise. - */ - sendClientEvent({ method, params, timeout }: BridgeSendClientEventParams): Promise; - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs(): void; - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams(): void; - log(data: string | object): void; -} -export default AndroidBridge; diff --git a/build/main/lib/platforms/android.js b/build/main/lib/platforms/android.js deleted file mode 100644 index 7204a79..0000000 --- a/build/main/lib/platforms/android.js +++ /dev/null @@ -1,201 +0,0 @@ -"use strict"; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const uuid_1 = require("uuid"); -const case_1 = require("../case"); -const constants_1 = require("../constants"); -const eventEmitter_1 = __importDefault(require("../eventEmitter")); -const logger_1 = __importDefault(require("../logger")); -class AndroidBridge { - constructor() { - this.hasCommunicationObject = typeof window.express !== 'undefined' && !!window.express.handleSmartAppEvent; - this.eventEmitter = new eventEmitter_1.default(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - if (!this.hasCommunicationObject) { - (0, logger_1.default)('No method "express.handleSmartAppEvent", cannot send message to Android'); - return; - } - // Expect json data as string - window.handleAndroidEvent = ({ ref, data, files, }) => { - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2)); - const { type } = data, payload = __rest(data, ["type"]); - const emitterType = ref || constants_1.EVENT_TYPE.RECEIVE; - // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready - const eventFiles = this.isRenameParamsEnabledForBotx ? - files === null || files === void 0 ? void 0 : files.map((file) => (0, case_1.snakeCaseToCamelCase)(file)) : files; - const event = { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? (0, case_1.snakeCaseToCamelCase)(payload) : payload, - files: eventFiles, - }; - this.eventEmitter.emit(emitterType, event); - }; - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - * @param callback - Callback function. - */ - onReceive(callback) { - this.eventEmitter.on(constants_1.EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = constants_1.RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - if (!this.hasCommunicationObject) - return Promise.reject(); - const isRenameParamsEnabled = handler === constants_1.HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true; - const ref = (0, uuid_1.v4)(); // UUID to detect express response. - const eventParams = { - ref, - type: constants_1.WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? (0, case_1.camelCaseToSnakeCase)(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files === null || files === void 0 ? void 0 : files.map((file) => (0, case_1.camelCaseToSnakeCase)(file)) : files; - const event = JSON.stringify(files ? Object.assign(Object.assign({}, eventParams), { files: eventFiles }) : eventParams); - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', JSON.stringify(event, null, ' ')); - window.express.handleSmartAppEvent(event); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param files - * @param timeout - Timeout in ms. - * @param guaranteed_delivery_required - boolean. - * @returns Promise. - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: constants_1.HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param timeout - Timeout in ms. - * @returns Promise. - */ - sendClientEvent({ method, params, timeout }) { - return this.sendEvent({ handler: constants_1.HANDLER.EXPRESS, method, params, timeout }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } - log(data) { - if ((!this.hasCommunicationObject || !data) || - (typeof data !== 'string' && typeof data !== 'object')) - return; - window.express.handleSmartAppEvent(JSON.stringify({ 'SmartApp Log': data }, null, 2)); - } -} -exports.default = AndroidBridge; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5kcm9pZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9saWIvcGxhdGZvcm1zL2FuZHJvaWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLCtCQUFpQztBQVNqQyxrQ0FBb0U7QUFDcEUsNENBQTBGO0FBQzFGLG1FQUFrRDtBQUNsRCx1REFBMkI7QUFFM0IsTUFBTSxhQUFhO0lBTWpCO1FBQ0UsSUFBSSxDQUFDLHNCQUFzQixHQUFHLE9BQU8sTUFBTSxDQUFDLE9BQU8sS0FBSyxXQUFXLElBQUksQ0FBQyxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUMsbUJBQW1CLENBQUE7UUFDM0csSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLHNCQUFvQixFQUFFLENBQUE7UUFDOUMsSUFBSSxDQUFDLFdBQVcsR0FBRyxLQUFLLENBQUE7UUFDeEIsSUFBSSxDQUFDLDRCQUE0QixHQUFHLElBQUksQ0FBQTtRQUV4QyxJQUFJLENBQUMsSUFBSSxDQUFDLHNCQUFzQixFQUFFO1lBQ2hDLElBQUEsZ0JBQUcsRUFBQyx5RUFBeUUsQ0FBQyxDQUFBO1lBQzlFLE9BQU07U0FDUDtRQUVELDZCQUE2QjtRQUM3QixNQUFNLENBQUMsa0JBQWtCLEdBQUcsQ0FDeEIsRUFDRSxHQUFHLEVBQ0gsSUFBSSxFQUNKLEtBQUssR0FPTixFQUFRLEVBQUU7WUFDYixJQUFJLElB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main/lib/platforms/ios.d.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { Bridge, BridgeSendBotEventParams, BridgeSendClientEventParams, EventEmitterCallback } from '../../types'; -declare class IosBridge implements Bridge { - private readonly eventEmitter; - private readonly hasCommunicationObject; - logsEnabled: boolean; - isRenameParamsEnabledForBotx: boolean; - constructor(); - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onRecieve(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback: EventEmitterCallback): void; - private sendEvent; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }: BridgeSendBotEventParams): Promise; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout, }: BridgeSendClientEventParams): Promise; - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs(): void; - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams(): void; - log(data: string | object): void; -} -export default IosBridge; diff --git a/build/main/lib/platforms/ios.js b/build/main/lib/platforms/ios.js deleted file mode 100644 index df14d5f..0000000 --- a/build/main/lib/platforms/ios.js +++ /dev/null @@ -1,207 +0,0 @@ -"use strict"; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const uuid_1 = require("uuid"); -const case_1 = require("../case"); -const constants_1 = require("../constants"); -const eventEmitter_1 = __importDefault(require("../eventEmitter")); -const logger_1 = __importDefault(require("../logger")); -class IosBridge { - constructor() { - this.hasCommunicationObject = - window.webkit && - window.webkit.messageHandlers && - window.webkit.messageHandlers.express && - !!window.webkit.messageHandlers.express.postMessage; - this.eventEmitter = new eventEmitter_1.default(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - if (!this.hasCommunicationObject) { - (0, logger_1.default)('No method "express.postMessage", cannot send message to iOS'); - return; - } - // Expect json data as string - window.handleIosEvent = ({ ref, data, files, }) => { - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2)); - const { type } = data, payload = __rest(data, ["type"]); - const emitterType = ref || constants_1.EVENT_TYPE.RECEIVE; - // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready - const eventFiles = this.isRenameParamsEnabledForBotx ? - files === null || files === void 0 ? void 0 : files.map((file) => (0, case_1.snakeCaseToCamelCase)(file)) : files; - const event = { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? (0, case_1.snakeCaseToCamelCase)(payload) : payload, - files: eventFiles, - }; - this.eventEmitter.emit(emitterType, event); - }; - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onRecieve(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback) { - this.eventEmitter.on(constants_1.EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = constants_1.RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - if (!this.hasCommunicationObject) - return Promise.reject(); - const ref = (0, uuid_1.v4)(); // UUID to detect express response. - const isRenameParamsEnabled = handler === constants_1.HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true; - const eventProps = { - ref, - type: constants_1.WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? (0, case_1.camelCaseToSnakeCase)(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files === null || files === void 0 ? void 0 : files.map((file) => (0, case_1.camelCaseToSnakeCase)(file)) : files; - const event = files ? Object.assign(Object.assign({}, eventProps), { files: eventFiles }) : eventProps; - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', JSON.stringify(event, null, ' ')); - window.webkit.messageHandlers.express.postMessage(event); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout = constants_1.RESPONSE_TIMEOUT, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: constants_1.HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout = constants_1.RESPONSE_TIMEOUT, }) { - return this.sendEvent({ - handler: constants_1.HANDLER.EXPRESS, - method, - params, - timeout, - }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } - log(data) { - if (!this.hasCommunicationObject || !data) - return; - let value = ''; - if (typeof data === 'string') { - value = data; - } - else if (typeof data === 'object') { - value = JSON.stringify(data, null, 2); - } - else - return; - window.webkit.messageHandlers.express.postMessage({ 'SmartApp Log': value }); - } -} -exports.default = IosBridge; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW9zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9wbGF0Zm9ybXMvaW9zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSwrQkFBaUM7QUFTakMsa0NBQW9FO0FBQ3BFLDRDQUEwRjtBQUMxRixtRUFBa0Q7QUFDbEQsdURBQTJCO0FBRTNCLE1BQU0sU0FBUztJQU1iO1FBQ0UsSUFBSSxDQUFDLHNCQUFzQjtZQUN2QixNQUFNLENBQUMsTUFBTTtnQkFDYixNQUFNLENBQUMsTUFBTSxDQUFDLGVBQWU7Z0JBQzdCLE1BQU0sQ0FBQyxNQUFNLENBQUMsZUFBZSxDQUFDLE9BQU87Z0JBQ3JDLENBQUMsQ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sQ0FBQyxJQUFxQjtRQUN2QixJQUFJLENBQUMsSUFBSSxDQUFDLHNCQUFzQixJQUFJLENBQUMsSUFBSTtZQUFFLE9BQU07UUFFakQsSUFBSSxLQUFLLEdBQWdCLEVBQUUsQ0FBQTtRQUMzQixJQUFJLE9BQU8sSUFBSSxLQUFLLFFBQVEsRUFBRTtZQUM1QixLQUFLLEdBQUcsSUFBSSxDQUFBO1NBQ2I7YUFBTSxJQUFJLE9BQU8sSUFBSSxLQUFLLFFBQVEsRUFBRTtZQUNuQyxLQUFLLEdBQUcsSUFBSSxDQUFDLFNBQVMsQ0FBQyxJQUFJLEVBQUUsSUFBSSxFQUFFLENBQUMsQ0FBQyxDQUFBO1NBQ3RDOztZQUFNLE9BQU07UUFFYixNQUFNLENBQUMsTUFBTSxDQUFDLGVBQWUsQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLEVBQUUsY0FBYyxFQUFFLEtBQUssRUFBRSxDQUFDLENBQUE7SUFDOUUsQ0FBQztDQUNGO0FBRUQsa0JBQWUsU0FBUyxDQUFBIn0= \ No newline at end of file diff --git a/build/main/lib/platforms/web.d.ts b/build/main/lib/platforms/web.d.ts deleted file mode 100644 index 47c675b..0000000 --- a/build/main/lib/platforms/web.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { Bridge, BridgeSendBotEventParams, BridgeSendClientEventParams, EventEmitterCallback } from '../../types'; -declare class WebBridge implements Bridge { - private readonly eventEmitter; - logsEnabled: boolean; - isRenameParamsEnabledForBotx: boolean; - constructor(); - addGlobalListener(): void; - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback: EventEmitterCallback): void; - private sendEvent; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }: BridgeSendBotEventParams): Promise; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout }: BridgeSendClientEventParams): Promise; - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs(): void; - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams(): void; -} -export default WebBridge; diff --git a/build/main/lib/platforms/web.js b/build/main/lib/platforms/web.js deleted file mode 100644 index 63c71da..0000000 --- a/build/main/lib/platforms/web.js +++ /dev/null @@ -1,195 +0,0 @@ -"use strict"; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const uuid_1 = require("uuid"); -const case_1 = require("../case"); -const constants_1 = require("../constants"); -const eventEmitter_1 = __importDefault(require("../eventEmitter")); -class WebBridge { - constructor() { - this.eventEmitter = new eventEmitter_1.default(); - this.addGlobalListener(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - } - addGlobalListener() { - window.addEventListener('message', (event) => { - if (typeof event.data !== 'object' || - typeof event.data.data !== 'object' || - typeof event.data.data.type !== 'string') - return; - const _a = event.data, { ref } = _a, _b = _a.data, { type } = _b, payload = __rest(_b, ["type"]), { files } = _a; - const isRenameParamsEnabled = this.isRenameParamsEnabledForBotx; // TODO fix when handler is passed - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', event.data); - const emitterType = ref || constants_1.EVENT_TYPE.RECEIVE; - const eventFiles = isRenameParamsEnabled ? - files === null || files === void 0 ? void 0 : files.map((file) => (0, case_1.snakeCaseToCamelCase)(file)) : files; - this.eventEmitter.emit(emitterType, { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? (0, case_1.snakeCaseToCamelCase)(payload) : payload, - files: eventFiles, - }); - }); - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback) { - this.eventEmitter.on(constants_1.EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = constants_1.RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - const isRenameParamsEnabled = handler === constants_1.HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false; - const ref = (0, uuid_1.v4)(); // UUID to detect express response. - const payload = { - ref, - type: constants_1.WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? (0, case_1.camelCaseToSnakeCase)(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files === null || files === void 0 ? void 0 : files.map((file) => (0, case_1.camelCaseToSnakeCase)(file)) : files; - const event = files ? Object.assign(Object.assign({}, payload), { files: eventFiles }) : payload; - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', event); - window.parent.postMessage({ - type: constants_1.WEB_COMMAND_TYPE, - payload: event, - }, '*'); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: constants_1.HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout }) { - return this.sendEvent({ - handler: constants_1.HANDLER.EXPRESS, - method, - params, - timeout, - }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - const _log = console.log; - console.log = function (...rest) { - window.parent.postMessage({ - type: constants_1.WEB_COMMAND_TYPE_RPC_LOGS, - payload: rest, - }, '*'); - _log.apply(console, rest); - }; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } -} -exports.default = WebBridge; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2ViLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xp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HO0lBQ0gsV0FBVztRQUNULElBQUksQ0FBQyxXQUFXLEdBQUcsS0FBSyxDQUFBO0lBQzFCLENBQUM7SUFFRDs7Ozs7O09BTUc7SUFDSCxrQkFBa0I7UUFDaEIsSUFBSSxDQUFDLDRCQUE0QixHQUFHLElBQUksQ0FBQTtRQUN4QyxPQUFPLENBQUMsR0FBRyxDQUFDLG9GQUFvRixDQUFDLENBQUE7SUFDbkcsQ0FBQztJQUVEOzs7Ozs7T0FNRztJQUNILG1CQUFtQjtRQUNqQixJQUFJLENBQUMsNEJBQTRCLEdBQUcsS0FBSyxDQUFBO1FBQ3pDLE9BQU8sQ0FBQyxHQUFHLENBQUMscUZBQXFGLENBQUMsQ0FBQTtJQUNwRyxDQUFDO0NBQ0Y7QUFFRCxrQkFBZSxTQUFTLENBQUEifQ== \ No newline at end of file diff --git a/build/main/types/bridgeInterface.d.ts b/build/main/types/bridgeInterface.d.ts deleted file mode 100644 index 997a229..0000000 --- a/build/main/types/bridgeInterface.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { HANDLER } from '../lib/constants'; -import { EmitterEventPayload, EventEmitterCallback } from './eventEmitter'; -export type BridgeSendClientEventParams = { - readonly method: string; - readonly params: object | undefined; - readonly timeout?: number; -}; -export type BridgeSendBotEventParams = BridgeSendClientEventParams & { - readonly files?: any; - readonly guaranteed_delivery_required?: boolean | undefined; -}; -export type BridgeSendEventParams = BridgeSendClientEventParams & BridgeSendBotEventParams & { - readonly handler: HANDLER; -}; -export type Bridge = { - readonly onReceive: (callback: EventEmitterCallback) => void; - readonly sendBotEvent: (event: BridgeSendBotEventParams) => Promise; - readonly sendClientEvent: (event: BridgeSendClientEventParams) => Promise; - readonly disableRenameParams: () => void; - readonly enableRenameParams: () => void; - readonly log?: (data: string | object) => void; -}; diff --git a/build/main/types/bridgeInterface.js b/build/main/types/bridgeInterface.js deleted file mode 100644 index e0ae4b0..0000000 --- a/build/main/types/bridgeInterface.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJpZGdlSW50ZXJmYWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3R5cGVzL2JyaWRnZUludGVyZmFjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0= \ No newline at end of file diff --git a/build/main/types/eventEmitter.d.ts b/build/main/types/eventEmitter.d.ts deleted file mode 100644 index 1f4811a..0000000 --- a/build/main/types/eventEmitter.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { EVENT_TYPE, HANDLER } from '../lib/constants'; -export type EmitterEventPayload = { - readonly ref: string | undefined; - readonly type: string; - readonly handler: HANDLER; - readonly payload: object | undefined; - readonly files?: object; -}; -export type EmitterEventType = EVENT_TYPE | string; -export type EventEmitterCallback = (event: EmitterEventPayload) => void; diff --git a/build/main/types/eventEmitter.js b/build/main/types/eventEmitter.js deleted file mode 100644 index 777aa29..0000000 --- a/build/main/types/eventEmitter.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnRFbWl0dGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3R5cGVzL2V2ZW50RW1pdHRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0= \ No newline at end of file diff --git a/build/main/version.d.ts b/build/main/version.d.ts deleted file mode 100644 index 5eda495..0000000 --- a/build/main/version.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const LIB_VERSION = "1.2.1"; diff --git a/build/main/version.js b/build/main/version.js deleted file mode 100644 index a090514..0000000 --- a/build/main/version.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.LIB_VERSION = void 0; -exports.LIB_VERSION = "1.2.1"; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyc2lvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy92ZXJzaW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFhLFFBQUEsV0FBVyxHQUFHLE9BQU8sQ0FBQyJ9 \ No newline at end of file diff --git a/build/module/index.d.ts b/build/module/index.d.ts deleted file mode 100644 index 385e685..0000000 --- a/build/module/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Bridge } from './types/bridgeInterface'; -declare const _default: Bridge | null; -export default _default; diff --git a/build/module/index.js b/build/module/index.js deleted file mode 100644 index b9d8686..0000000 --- a/build/module/index.js +++ /dev/null @@ -1,26 +0,0 @@ -import { PLATFORM } from './lib/constants'; -import getPlatform from './lib/platformDetector'; -import AndroidBridge from './lib/platforms/android'; -import IosBridge from './lib/platforms/ios'; -import WebBridge from './lib/platforms/web'; -import { LIB_VERSION } from './version'; -const getBridge = () => { - if (process.env.NODE_ENV === 'test') - return null; - const platform = getPlatform(); - console.log('Bridge ~ version', LIB_VERSION); - switch (platform) { - case PLATFORM.ANDROID: - return new AndroidBridge(); - case PLATFORM.IOS: - return new IosBridge(); - case PLATFORM.WEB: - return new WebBridge(); - default: - console.error('Wrong platform'); - break; - } - return null; -}; -export default getBridge(); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFBO0FBQzFDLE9BQU8sV0FBVyxNQUFNLHdCQUF3QixDQUFBO0FBQ2hELE9BQU8sYUFBYSxNQUFNLHlCQUF5QixDQUFBO0FBQ25ELE9BQU8sU0FBUyxNQUFNLHFCQUFxQixDQUFBO0FBQzNDLE9BQU8sU0FBUyxNQUFNLHFCQUFxQixDQUFBO0FBRTNDLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxXQUFXLENBQUE7QUFFdkMsTUFBTSxTQUFTLEdBQUcsR0FBa0IsRUFBRTtJQUNwQyxJQUFJLE9BQU8sQ0FBQyxHQUFHLENBQUMsUUFBUSxLQUFLLE1BQU07UUFBRSxPQUFPLElBQUksQ0FBQTtJQUVoRCxNQUFNLFFBQVEsR0FBRyxXQUFXLEVBQUUsQ0FBQTtJQUM5QixPQUFPLENBQUMsR0FBRyxDQUFDLGtCQUFrQixFQUFFLFdBQVcsQ0FBQyxDQUFBO0lBRTVDLFFBQVEsUUFBUSxFQUFFO1FBQ2hCLEtBQUssUUFBUSxDQUFDLE9BQU87WUFDbkIsT0FBTyxJQUFJLGFBQWEsRUFBRSxDQUFBO1FBQzVCLEtBQUssUUFBUSxDQUFDLEdBQUc7WUFDZixPQUFPLElBQUksU0FBUyxFQUFFLENBQUE7UUFDeEIsS0FBSyxRQUFRLENBQUMsR0FBRztZQUNmLE9BQU8sSUFBSSxTQUFTLEVBQUUsQ0FBQTtRQUN4QjtZQUNFLE9BQU8sQ0FBQyxLQUFLLENBQUMsZ0JBQWdCLENBQUMsQ0FBQTtZQUMvQixNQUFLO0tBQ1I7SUFFRCxPQUFPLElBQUksQ0FBQTtBQUNiLENBQUMsQ0FBQTtBQUVELGVBQWUsU0FBUyxFQUFFLENBQUEifQ== \ No newline at end of file diff --git a/build/module/lib/case.d.ts b/build/module/lib/case.d.ts deleted file mode 100644 index 15a5511..0000000 --- a/build/module/lib/case.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare const isUuid: (value: string) => boolean; -export declare const snakeCaseToCamelCase: (data: any) => any; -export declare const camelCaseToSnakeCase: (data: any) => any; diff --git a/build/module/lib/case.js b/build/module/lib/case.js deleted file mode 100644 index 66a6e8f..0000000 --- a/build/module/lib/case.js +++ /dev/null @@ -1,28 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import camelCase from 'lodash/camelCase'; -import snakeCase from 'lodash/snakeCase'; -export const isUuid = (value) => { - return /[0-9a-fA-F-]{32}/.test(value); -}; -export const snakeCaseToCamelCase = (data) => { - if (Array.isArray(data)) - return data.map(snakeCaseToCamelCase); - if (!data || data.constructor?.name !== 'Object') - return data; - return Object.keys(data).reduce((result, key) => { - const value = snakeCaseToCamelCase(data[key]); - const keyValue = isUuid(key) ? key : camelCase(key); - return { ...result, [keyValue]: value }; - }, {}); -}; -export const camelCaseToSnakeCase = (data) => { - if (Array.isArray(data)) - return data.map(camelCaseToSnakeCase); - if (!data || data.constructor?.name !== 'Object') - return data; - return Object.keys(data).reduce((result, key) => { - const value = camelCaseToSnakeCase(data[key]); - return { ...result, [snakeCase(key)]: value }; - }, {}); -}; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FzZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvY2FzZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx1REFBdUQ7QUFDdkQsT0FBTyxTQUFTLE1BQU0sa0JBQWtCLENBQUE7QUFDeEMsT0FBTyxTQUFTLE1BQU0sa0JBQWtCLENBQUE7QUFFeEMsTUFBTSxDQUFDLE1BQU0sTUFBTSxHQUFHLENBQUMsS0FBYSxFQUFFLEVBQUU7SUFDdEMsT0FBTyxrQkFBa0IsQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUE7QUFDdkMsQ0FBQyxDQUFBO0FBRUQsTUFBTSxDQUFDLE1BQU0sb0JBQW9CLEdBQUcsQ0FBQyxJQUFTLEVBQU8sRUFBRTtJQUNyRCxJQUFJLEtBQUssQ0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ENBQUMsQ0FBQyxNQUFNLEVBQUUsR0FBRyxFQUFFLEVBQUU7UUFDOUMsTUFBTSxLQUFLLEdBQUcsb0JBQW9CLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUE7UUFDN0MsT0FBTyxFQUFFLEdBQUcsTUFBTSxFQUFFLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxDQUFDLEVBQUUsS0FBSyxFQUFFLENBQUE7SUFDL0MsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFBO0FBQ1IsQ0FBQyxDQUFBIn0= \ No newline at end of file diff --git a/build/module/lib/constants.d.ts b/build/module/lib/constants.d.ts deleted file mode 100644 index 306b6bb..0000000 --- a/build/module/lib/constants.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -export declare enum PLATFORM { - WEB = "web", - IOS = "ios", - ANDROID = "android", - UNKNOWN = "unknown" -} -export declare enum EVENT_TYPE { - RECEIVE = "recv", - SEND = "send" -} -export declare enum HANDLER { - BOTX = "botx", - EXPRESS = "express" -} -export declare const RESPONSE_TIMEOUT = 30000; -export declare const WEB_COMMAND_TYPE = "smartapp"; -export declare const WEB_COMMAND_TYPE_RPC = "smartapp_rpc"; -export declare const WEB_COMMAND_TYPE_RPC_LOGS = "smartAppLogs"; diff --git a/build/module/lib/constants.js b/build/module/lib/constants.js deleted file mode 100644 index 7b075e5..0000000 --- a/build/module/lib/constants.js +++ /dev/null @@ -1,22 +0,0 @@ -export var PLATFORM; -(function (PLATFORM) { - PLATFORM["WEB"] = "web"; - PLATFORM["IOS"] = "ios"; - PLATFORM["ANDROID"] = "android"; - PLATFORM["UNKNOWN"] = "unknown"; -})(PLATFORM || (PLATFORM = {})); -export var EVENT_TYPE; -(function (EVENT_TYPE) { - EVENT_TYPE["RECEIVE"] = "recv"; - EVENT_TYPE["SEND"] = "send"; -})(EVENT_TYPE || (EVENT_TYPE = {})); -export var HANDLER; -(function (HANDLER) { - HANDLER["BOTX"] = "botx"; - HANDLER["EXPRESS"] = "express"; -})(HANDLER || (HANDLER = {})); -export const RESPONSE_TIMEOUT = 30000; -export const WEB_COMMAND_TYPE = 'smartapp'; -export const WEB_COMMAND_TYPE_RPC = 'smartapp_rpc'; -export const WEB_COMMAND_TYPE_RPC_LOGS = 'smartAppLogs'; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxDQUFOLElBQVksUUFLWDtBQUxELFdBQVksUUFBUTtJQUNsQix1QkFBVyxDQUFBO0lBQ1gsdUJBQVcsQ0FBQTtJQUNYLCtCQUFtQixDQUFBO0lBQ25CLCtCQUFtQixDQUFBO0FBQ3JCLENBQUMsRUFMVyxRQUFRLEtBQVIsUUFBUSxRQUtuQjtBQUVELE1BQU0sQ0FBTixJQUFZLFVBR1g7QUFIRCxXQUFZLFVBQVU7SUFDcEIsOEJBQWdCLENBQUE7SUFDaEIsMkJBQWEsQ0FBQTtBQUNmLENBQUMsRUFIVyxVQUFVLEtBQVYsVUFBVSxRQUdyQjtBQUVELE1BQU0sQ0FBTixJQUFZLE9BR1g7QUFIRCxXQUFZLE9BQU87SUFDakIsd0JBQWEsQ0FBQTtJQUNiLDhCQUFtQixDQUFBO0FBQ3JCLENBQUMsRUFIVyxPQUFPLEtBQVAsT0FBTyxRQUdsQjtBQUVELE1BQU0sQ0FBQyxNQUFNLGdCQUFnQixHQUFHLEtBQUssQ0FBQTtBQUNyQyxNQUFNLENBQUMsTUFBTSxnQkFBZ0IsR0FBRyxVQUFVLENBQUE7QUFDMUMsTUFBTSxDQUFDLE1BQU0sb0JBQW9CLEdBQUcsY0FBYyxDQUFBO0FBQ2xELE1BQU0sQ0FBQyxNQUFNLHlCQUF5QixHQUFHLGNBQWMsQ0FBQSJ9 \ No newline at end of file diff --git a/build/module/lib/eventEmitter.d.ts b/build/module/lib/eventEmitter.d.ts deleted file mode 100644 index 9cc50ef..0000000 --- a/build/module/lib/eventEmitter.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import EventEmitter from 'eventemitter3'; -import { EmitterEventPayload, EmitterEventType } from '../types/eventEmitter'; -/** - * Extended Event Emitted class - * - * ```typescript - * const emitter = new EmitterEventPayload(); - * - * // promise will be rejected in 20 secs - * // if no one event has been received with type 'ref-uuid-value' - * // otherwise promise will be fulfilled with payload object - * const promise = emitter.onceWithTimeout('ref-uuid-value', 20000) - * ``` - */ -declare class ExtendedEventEmitter extends EventEmitter { - constructor(); - /** - * Wait when event with `type` will be emitted for `timeout` ms. - * - * ```js - * emitter.onceWithTimeout('d6910a9d-ea24-5fc6-a654-28781ef21f8f', 20000) - * // => Promise - * ``` - */ - onceWithTimeout(type: EmitterEventType, timeout: number): Promise; -} -export default ExtendedEventEmitter; diff --git a/build/module/lib/eventEmitter.js b/build/module/lib/eventEmitter.js deleted file mode 100644 index 11daa16..0000000 --- a/build/module/lib/eventEmitter.js +++ /dev/null @@ -1,37 +0,0 @@ -import EventEmitter from 'eventemitter3'; -/** - * Extended Event Emitted class - * - * ```typescript - * const emitter = new EmitterEventPayload(); - * - * // promise will be rejected in 20 secs - * // if no one event has been received with type 'ref-uuid-value' - * // otherwise promise will be fulfilled with payload object - * const promise = emitter.onceWithTimeout('ref-uuid-value', 20000) - * ``` - */ -class ExtendedEventEmitter extends EventEmitter { - constructor() { - super(); - } - /** - * Wait when event with `type` will be emitted for `timeout` ms. - * - * ```js - * emitter.onceWithTimeout('d6910a9d-ea24-5fc6-a654-28781ef21f8f', 20000) - * // => Promise - * ``` - */ - onceWithTimeout(type, timeout) { - return new Promise((resolve, reject) => { - const timer = setTimeout(() => reject(), timeout); - this.once(type, (event) => { - clearTimeout(timer); - resolve(event); - }); - }); - } -} -export default ExtendedEventEmitter; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnRFbWl0dGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9ldmVudEVtaXR0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxZQUFZLE1BQU0sZUFBZSxDQUFBO0FBSXhDOzs7Ozs7Ozs7OztHQVdHO0FBQ0gsTUFBTSxvQkFBcUIsU0FBUSxZQUFZO0lBQzdDO1FBQ0UsS0FBSyxFQUFFLENBQUE7SUFDVCxDQUFDO0lBRUQ7Ozs7Ozs7T0FPRztJQUNILGVBQWUsQ0FBQyxJQUFzQixFQUFFLE9BQWU7UUFDckQsT0FBTyxJQUFJLE9BQU8sQ0FBQyxDQUFDLE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFBRTtZQUNyQyxNQUFNLEtBQUssR0FBRyxVQUFVLENBQUMsR0FBRyxFQUFFLENBQUMsTUFBTSxFQUFFLEVBQUUsT0FBTyxDQUFDLENBQUE7WUFFakQsSUFBSSxDQUFDLElBQUksQ0FBUyxJQUFJLEVBQUUsQ0FBQyxLQUEwQixFQUFFLEVBQUU7Z0JBQ3JELFlBQVksQ0FBQyxLQUFLLENBQUMsQ0FBQTtnQkFDbkIsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1lBQ2hCLENBQUMsQ0FBQyxDQUFBO1FBQ0osQ0FBQyxDQUFDLENBQUE7SUFDSixDQUFDO0NBQ0Y7QUFFRCxlQUFlLG9CQUFvQixDQUFBIn0= \ No newline at end of file diff --git a/build/module/lib/logger.d.ts b/build/module/lib/logger.d.ts deleted file mode 100644 index ef48cbb..0000000 --- a/build/module/lib/logger.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/** @ignore */ -declare const log: (...args: ReadonlyArray) => void; -export default log; diff --git a/build/module/lib/logger.js b/build/module/lib/logger.js deleted file mode 100644 index 6c955b9..0000000 --- a/build/module/lib/logger.js +++ /dev/null @@ -1,7 +0,0 @@ -/** @ignore */ -const log = (...args) => { - const text = args.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '); - alert(text); -}; -export default log; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9sb2dnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYztBQUNkLE1BQU0sR0FBRyxHQUFHLENBQUMsR0FBRyxJQUE0QixFQUFFLEVBQUU7SUFDOUMsTUFBTSxJQUFJLEdBQUcsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLEdBQVksRUFBVSxFQUFFLENBQUMsQ0FBQyxPQUFPLEdBQUcsS0FBSyxRQUFRLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFBO0lBQ2hILEtBQUssQ0FBQyxJQUFJLENBQUMsQ0FBQTtBQUNiLENBQUMsQ0FBQTtBQUVELGVBQWUsR0FBRyxDQUFBIn0= \ No newline at end of file diff --git a/build/module/lib/platformDetector.d.ts b/build/module/lib/platformDetector.d.ts deleted file mode 100644 index 6a8a663..0000000 --- a/build/module/lib/platformDetector.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { PLATFORM } from './constants'; -/** - * Get platform. Detection based on GET param `platform` or user agent. - * - * ```typescript - * const platform = getPlatform(); - * - * // => 'web' | 'ios' | 'android' - * ``` - */ -declare const getPlatform: () => PLATFORM; -export default getPlatform; diff --git a/build/module/lib/platformDetector.js b/build/module/lib/platformDetector.js deleted file mode 100644 index 53d7c39..0000000 --- a/build/module/lib/platformDetector.js +++ /dev/null @@ -1,32 +0,0 @@ -import { PLATFORM } from './constants'; -const getPlatformByGetParam = () => { - const platform = new URLSearchParams(location.search).get('platform'); - const isValidPlatform = Object.values(PLATFORM).includes(platform); - if (isValidPlatform) - return platform; - return PLATFORM.UNKNOWN; -}; -const detectPlatformByUserAgent = () => { - if (/android/i.test(navigator.userAgent)) { - return PLATFORM.ANDROID; - } - if ((/iPad|iPhone|iPod/.test(navigator.userAgent) || - (navigator.userAgent.includes('Mac') && 'ontouchend' in document)) && - !window.MSStream) - return PLATFORM.IOS; - return PLATFORM.WEB; -}; -/** - * Get platform. Detection based on GET param `platform` or user agent. - * - * ```typescript - * const platform = getPlatform(); - * - * // => 'web' | 'ios' | 'android' - * ``` - */ -const getPlatform = () => { - return getPlatformByGetParam() || detectPlatformByUserAgent(); -}; -export default getPlatform; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGxhdGZvcm1EZXRlY3Rvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvcGxhdGZvcm1EZXRlY3Rvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sYUFBYSxDQUFBO0FBRXRDLE1BQU0scUJBQXFCLEdBQUcsR0FBYSxFQUFFO0lBQzNDLE1BQU0sUUFBUSxHQUFHLElBQUksZUFBZSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUE7SUFFckUsTUFBTSxlQUFlLEdBQUcsTUFBTSxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxRQUFRLENBQVcsUUFBUSxDQUFDLENBQUE7SUFDNUUsSUFBSSxlQUFlO1FBQUUsT0FBaUIsUUFBUSxDQUFBO0lBRTlDLE9BQU8sUUFBUSxDQUFDLE9BQU8sQ0FBQTtBQUN6QixDQUFDLENBQUE7QUFFRCxNQUFNLHlCQUF5QixHQUFHLEdBQWEsRUFBRTtJQUMvQyxJQUFJLFVBQVUsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLFNBQVMsQ0FBQyxFQUFFO1FBQ3hDLE9BQU8sUUFBUSxDQUFDLE9BQU8sQ0FBQTtLQUN4QjtJQUVELElBQ0UsQ0FBQyxrQkFBa0IsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLFNBQVMsQ0FBQztRQUMzQyxDQUFDLFNBQVMsQ0FBQyxTQUFTLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxJQUFJLFlBQVksSUFBSSxRQUFRLENBQUMsQ0FBQztRQUNwRSxDQUFFLE1BQWMsQ0FBQyxRQUFRO1FBRXpCLE9BQU8sUUFBUSxDQUFDLEdBQUcsQ0FBQTtJQUVyQixPQUFPLFFBQVEsQ0FBQyxHQUFHLENBQUE7QUFDckIsQ0FBQyxDQUFBO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSCxNQUFNLFdBQVcsR0FBRyxHQUFhLEVBQUU7SUFDakMsT0FBTyxxQkFBcUIsRUFBRSxJQUFJLHlCQUF5QixFQUFFLENBQUE7QUFDL0QsQ0FBQyxDQUFBO0FBRUQsZUFBZSxXQUFXLENBQUEifQ== \ No newline at end of file diff --git a/build/module/lib/platforms/android.d.ts b/build/module/lib/platforms/android.d.ts deleted file mode 100644 index ad6035f..0000000 --- a/build/module/lib/platforms/android.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { Bridge, BridgeSendBotEventParams, BridgeSendClientEventParams, EventEmitterCallback } from '../../types'; -declare class AndroidBridge implements Bridge { - private readonly eventEmitter; - private readonly hasCommunicationObject; - logsEnabled: boolean; - isRenameParamsEnabledForBotx: boolean; - constructor(); - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - * @param callback - Callback function. - */ - onReceive(callback: EventEmitterCallback): void; - private sendEvent; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param files - * @param timeout - Timeout in ms. - * @param guaranteed_delivery_required - boolean. - * @returns Promise. - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }: BridgeSendBotEventParams): Promise; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param timeout - Timeout in ms. - * @returns Promise. - */ - sendClientEvent({ method, params, timeout }: BridgeSendClientEventParams): Promise; - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs(): void; - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams(): void; - log(data: string | object): void; -} -export default AndroidBridge; diff --git a/build/module/lib/platforms/android.js b/build/module/lib/platforms/android.js deleted file mode 100644 index 9007384..0000000 --- a/build/module/lib/platforms/android.js +++ /dev/null @@ -1,189 +0,0 @@ -import { v4 as uuid } from 'uuid'; -import { camelCaseToSnakeCase, snakeCaseToCamelCase } from '../case'; -import { EVENT_TYPE, HANDLER, RESPONSE_TIMEOUT, WEB_COMMAND_TYPE_RPC } from '../constants'; -import ExtendedEventEmitter from '../eventEmitter'; -import log from '../logger'; -class AndroidBridge { - eventEmitter; - hasCommunicationObject; - logsEnabled; - isRenameParamsEnabledForBotx; - constructor() { - this.hasCommunicationObject = typeof window.express !== 'undefined' && !!window.express.handleSmartAppEvent; - this.eventEmitter = new ExtendedEventEmitter(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - if (!this.hasCommunicationObject) { - log('No method "express.handleSmartAppEvent", cannot send message to Android'); - return; - } - // Expect json data as string - window.handleAndroidEvent = ({ ref, data, files, }) => { - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2)); - const { type, ...payload } = data; - const emitterType = ref || EVENT_TYPE.RECEIVE; - // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready - const eventFiles = this.isRenameParamsEnabledForBotx ? - files?.map((file) => snakeCaseToCamelCase(file)) : files; - const event = { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload, - files: eventFiles, - }; - this.eventEmitter.emit(emitterType, event); - }; - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - * @param callback - Callback function. - */ - onReceive(callback) { - this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - if (!this.hasCommunicationObject) - return Promise.reject(); - const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true; - const ref = uuid(); // UUID to detect express response. - const eventParams = { - ref, - type: WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => camelCaseToSnakeCase(file)) : files; - const event = JSON.stringify(files ? { ...eventParams, files: eventFiles } : eventParams); - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', JSON.stringify(event, null, ' ')); - window.express.handleSmartAppEvent(event); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param files - * @param timeout - Timeout in ms. - * @param guaranteed_delivery_required - boolean. - * @returns Promise. - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param timeout - Timeout in ms. - * @returns Promise. - */ - sendClientEvent({ method, params, timeout }) { - return this.sendEvent({ handler: HANDLER.EXPRESS, method, params, timeout }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } - log(data) { - if ((!this.hasCommunicationObject || !data) || - (typeof data !== 'string' && typeof data !== 'object')) - return; - window.express.handleSmartAppEvent(JSON.stringify({ 'SmartApp Log': data }, null, 2)); - } -} -export default AndroidBridge; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5kcm9pZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9saWIvcGxhdGZvcm1zL2FuZHJvaWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsSUFBSSxJQUFJLEVBQUUsTUFBTSxNQUFNLENBQUE7QUFTakMsT0FBTyxFQUFFLG9CQUFvQixFQUFFLG9CQUFvQixFQUFFLE1BQU0sU0FBUyxDQUFBO0FBQ3BFLE9BQU8sRUFBRSxVQUFVLEVBQUUsT0FBTyxFQUFFLGdCQUFnQixFQUFFLG9CQUFvQixFQUFFLE1BQU0sY0FBYyxDQUFBO0FBQzFGLE9BQU8sb0JBQW9CLE1BQU0saUJBQWlCLENBQUE7QUFDbEQsT0FBTyxHQUFHLE1BQU0sV0FBVyxDQUFBO0FBRTNCLE1BQU0sYUFBYTtJQUNBLFlBQVksQ0FBc0I7SUFDbEMsc0JBQXNCLENBQVM7SUFDaEQsV0FBVyxDQUFTO0lBQ3BCLDRCQUE0QixDQUFTO0lBRXJDO1FBQ0UsSUFBSSxDQUFDLHNCQUFzQixHQUFHLE9BQU8sTUFBTSxDQUFDLE9BQU8sS0FBSyxXQUFXLElBQUksQ0FBQyxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUMsbUJBQW1CLENBQUE7UUFDM0csSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLG9CQUFvQixFQUFFLENBQUE7UUFDOUMsSUFBSSxDQUFDLFdBQVcsR0FBRyxLQUFLLENBQUE7UUFDeEIsSUFBSSxDQUFDLDRCQUE0QixHQUFHLElBQUksQ0FBQTtRQUV4QyxJQUFJLENBQUMsSUFBSSxDQUFDLHNCQUFzQixFQUFFO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EifQ== \ No newline at end of file diff --git a/build/module/lib/platforms/ios.d.ts b/build/module/lib/platforms/ios.d.ts deleted file mode 100644 index 1e4aefb..0000000 --- a/build/module/lib/platforms/ios.d.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { Bridge, BridgeSendBotEventParams, BridgeSendClientEventParams, EventEmitterCallback } from '../../types'; -declare class IosBridge implements Bridge { - private readonly eventEmitter; - private readonly hasCommunicationObject; - logsEnabled: boolean; - isRenameParamsEnabledForBotx: boolean; - constructor(); - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onRecieve(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback: EventEmitterCallback): void; - private sendEvent; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }: BridgeSendBotEventParams): Promise; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout, }: BridgeSendClientEventParams): Promise; - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs(): void; - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams(): void; - log(data: string | object): void; -} -export default IosBridge; diff --git a/build/module/lib/platforms/ios.js b/build/module/lib/platforms/ios.js deleted file mode 100644 index f447fec..0000000 --- a/build/module/lib/platforms/ios.js +++ /dev/null @@ -1,195 +0,0 @@ -import { v4 as uuid } from 'uuid'; -import { camelCaseToSnakeCase, snakeCaseToCamelCase } from '../case'; -import { EVENT_TYPE, HANDLER, RESPONSE_TIMEOUT, WEB_COMMAND_TYPE_RPC } from '../constants'; -import ExtendedEventEmitter from '../eventEmitter'; -import log from '../logger'; -class IosBridge { - eventEmitter; - hasCommunicationObject; - logsEnabled; - isRenameParamsEnabledForBotx; - constructor() { - this.hasCommunicationObject = - window.webkit && - window.webkit.messageHandlers && - window.webkit.messageHandlers.express && - !!window.webkit.messageHandlers.express.postMessage; - this.eventEmitter = new ExtendedEventEmitter(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - if (!this.hasCommunicationObject) { - log('No method "express.postMessage", cannot send message to iOS'); - return; - } - // Expect json data as string - window.handleIosEvent = ({ ref, data, files, }) => { - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2)); - const { type, ...payload } = data; - const emitterType = ref || EVENT_TYPE.RECEIVE; - // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready - const eventFiles = this.isRenameParamsEnabledForBotx ? - files?.map((file) => snakeCaseToCamelCase(file)) : files; - const event = { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload, - files: eventFiles, - }; - this.eventEmitter.emit(emitterType, event); - }; - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onRecieve(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback) { - this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - if (!this.hasCommunicationObject) - return Promise.reject(); - const ref = uuid(); // UUID to detect express response. - const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true; - const eventProps = { - ref, - type: WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => camelCaseToSnakeCase(file)) : files; - const event = files ? { ...eventProps, files: eventFiles } : eventProps; - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', JSON.stringify(event, null, ' ')); - window.webkit.messageHandlers.express.postMessage(event); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout = RESPONSE_TIMEOUT, }) { - return this.sendEvent({ - handler: HANDLER.EXPRESS, - method, - params, - timeout, - }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } - log(data) { - if (!this.hasCommunicationObject || !data) - return; - let value = ''; - if (typeof data === 'string') { - value = data; - } - else if (typeof data === 'object') { - value = JSON.stringify(data, null, 2); - } - else - return; - window.webkit.messageHandlers.express.postMessage({ 'SmartApp Log': value }); - } -} -export default IosBridge; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW9zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9wbGF0Zm9ybXMvaW9zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLElBQUksSUFBSSxFQUFFLE1BQU0sTUFBTSxDQUFBO0FBU2pDLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxvQkFBb0IsRUFBRSxNQUFNLFNBQVMsQ0FBQTtBQUNwRSxPQUFPLEVBQUUsVUFBVSxFQUFFLE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxvQkFBb0IsRUFBRSxNQUFNLGNBQWMsQ0FBQTtBQUMxRixPQUFPLG9CQUFvQixNQUFNLGlCQUFpQixDQUFBO0FBQ2xELE9BQU8sR0FBRyxNQUFNLFdBQVcsQ0FBQTtBQUUzQixNQUFNLFNBQVM7SUFDSSxZQUFZLENBQXNCO0lBQ2xDLHNCQUFzQixDQUFTO0lBQ2hELFdBQVcsQ0FBUztJQUNwQiw0QkFBNEIsQ0FBUztJQUVyQztRQUNFLElBQUksQ0FBQyxzQkFBc0I7WUFDdkIsTUFBTSxDQUFDLE1BQU07Z0JBQ2IsTUFBTSxDQUFDLE1BQU0sQ0FBQyxlQUFlO2dCQUM3QixNQUFNLENBQUMsTUFBTSxDQUFDLGVBQWUsQ0FB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BQUUsT0FBTTtRQUVqRCxJQUFJLEtBQUssR0FBZ0IsRUFBRSxDQUFBO1FBQzNCLElBQUksT0FBTyxJQUFJLEtBQUssUUFBUSxFQUFFO1lBQzVCLEtBQUssR0FBRyxJQUFJLENBQUE7U0FDYjthQUFNLElBQUksT0FBTyxJQUFJLEtBQUssUUFBUSxFQUFFO1lBQ25DLEtBQUssR0FBRyxJQUFJLENBQUMsU0FBUyxDQUFDLElBQUksRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDLENBQUE7U0FDdEM7O1lBQU0sT0FBTTtRQUViLE1BQU0sQ0FBQyxNQUFNLENBQUMsZUFBZSxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsRUFBRSxjQUFjLEVBQUUsS0FBSyxFQUFFLENBQUMsQ0FBQTtJQUM5RSxDQUFDO0NBQ0Y7QUFFRCxlQUFlLFNBQVMsQ0FBQSJ9 \ No newline at end of file diff --git a/build/module/lib/platforms/web.d.ts b/build/module/lib/platforms/web.d.ts deleted file mode 100644 index 47c675b..0000000 --- a/build/module/lib/platforms/web.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { Bridge, BridgeSendBotEventParams, BridgeSendClientEventParams, EventEmitterCallback } from '../../types'; -declare class WebBridge implements Bridge { - private readonly eventEmitter; - logsEnabled: boolean; - isRenameParamsEnabledForBotx: boolean; - constructor(); - addGlobalListener(): void; - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback: EventEmitterCallback): void; - private sendEvent; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }: BridgeSendBotEventParams): Promise; - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout }: BridgeSendClientEventParams): Promise; - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs(): void; - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams(): void; - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams(): void; -} -export default WebBridge; diff --git a/build/module/lib/platforms/web.js b/build/module/lib/platforms/web.js deleted file mode 100644 index bfdec38..0000000 --- a/build/module/lib/platforms/web.js +++ /dev/null @@ -1,182 +0,0 @@ -import { v4 as uuid } from 'uuid'; -import { camelCaseToSnakeCase, snakeCaseToCamelCase } from '../case'; -import { EVENT_TYPE, HANDLER, RESPONSE_TIMEOUT, WEB_COMMAND_TYPE, WEB_COMMAND_TYPE_RPC, WEB_COMMAND_TYPE_RPC_LOGS, } from '../constants'; -import ExtendedEventEmitter from '../eventEmitter'; -class WebBridge { - eventEmitter; - logsEnabled; - isRenameParamsEnabledForBotx; - constructor() { - this.eventEmitter = new ExtendedEventEmitter(); - this.addGlobalListener(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - } - addGlobalListener() { - window.addEventListener('message', (event) => { - if (typeof event.data !== 'object' || - typeof event.data.data !== 'object' || - typeof event.data.data.type !== 'string') - return; - const { ref, data: { type, ...payload }, files, } = event.data; - const isRenameParamsEnabled = this.isRenameParamsEnabledForBotx; // TODO fix when handler is passed - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', event.data); - const emitterType = ref || EVENT_TYPE.RECEIVE; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => snakeCaseToCamelCase(file)) : files; - this.eventEmitter.emit(emitterType, { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload, - files: eventFiles, - }); - }); - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback) { - this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false; - const ref = uuid(); // UUID to detect express response. - const payload = { - ref, - type: WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => camelCaseToSnakeCase(file)) : files; - const event = files ? { ...payload, files: eventFiles } : payload; - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', event); - window.parent.postMessage({ - type: WEB_COMMAND_TYPE, - payload: event, - }, '*'); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout }) { - return this.sendEvent({ - handler: HANDLER.EXPRESS, - method, - params, - timeout, - }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - const _log = console.log; - console.log = function (...rest) { - window.parent.postMessage({ - type: WEB_COMMAND_TYPE_RPC_LOGS, - payload: rest, - }, '*'); - _log.apply(console, rest); - }; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } -} -export default WebBridge; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2ViLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9wbGF0Zm9ybXMvd2ViLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLElBQUksSUFBSSxFQUFFLE1BQU0sTUFBTSxDQUFBO0FBU2pDLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxvQkFBb0IsRUFBRSxNQUFNLFNBQVMsQ0FBQTtBQUNwRSxPQUFPLEVBQ0wsVUFBVSxFQUNWLE9BQU8sRUFDUCxnQkFBZ0IsRUFDaEIsZ0JBQWdCLEVBQ2hCLG9CQUFvQixFQUNwQix5QkFBeUIsR0FDMUIsTUFBTSxjQUFjLENBQUE7QUFDckIsT0FBTyxvQkFBb0IsTUFBTSxpQkFBaUIsQ0FBQTtBQUVsRCxNQUFNLFNBQVM7SUFDSSxZQUFZLENBQXNC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0FBQTtJQUNuRyxDQUFDO0lBRUQ7Ozs7OztPQU1HO0lBQ0gsbUJBQW1CO1FBQ2pCLElBQUksQ0FBQyw0QkFBNEIsR0FBRyxLQUFLLENBQUE7UUFDekMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxxRkFBcUYsQ0FBQyxDQUFBO0lBQ3BHLENBQUM7Q0FDRjtBQUVELGVBQWUsU0FBUyxDQUFBIn0= \ No newline at end of file diff --git a/build/module/types/bridgeInterface.d.ts b/build/module/types/bridgeInterface.d.ts deleted file mode 100644 index 997a229..0000000 --- a/build/module/types/bridgeInterface.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { HANDLER } from '../lib/constants'; -import { EmitterEventPayload, EventEmitterCallback } from './eventEmitter'; -export type BridgeSendClientEventParams = { - readonly method: string; - readonly params: object | undefined; - readonly timeout?: number; -}; -export type BridgeSendBotEventParams = BridgeSendClientEventParams & { - readonly files?: any; - readonly guaranteed_delivery_required?: boolean | undefined; -}; -export type BridgeSendEventParams = BridgeSendClientEventParams & BridgeSendBotEventParams & { - readonly handler: HANDLER; -}; -export type Bridge = { - readonly onReceive: (callback: EventEmitterCallback) => void; - readonly sendBotEvent: (event: BridgeSendBotEventParams) => Promise; - readonly sendClientEvent: (event: BridgeSendClientEventParams) => Promise; - readonly disableRenameParams: () => void; - readonly enableRenameParams: () => void; - readonly log?: (data: string | object) => void; -}; diff --git a/build/module/types/bridgeInterface.js b/build/module/types/bridgeInterface.js deleted file mode 100644 index 05c015f..0000000 --- a/build/module/types/bridgeInterface.js +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJpZGdlSW50ZXJmYWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3R5cGVzL2JyaWRnZUludGVyZmFjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0= \ No newline at end of file diff --git a/build/module/types/eventEmitter.d.ts b/build/module/types/eventEmitter.d.ts deleted file mode 100644 index 1f4811a..0000000 --- a/build/module/types/eventEmitter.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { EVENT_TYPE, HANDLER } from '../lib/constants'; -export type EmitterEventPayload = { - readonly ref: string | undefined; - readonly type: string; - readonly handler: HANDLER; - readonly payload: object | undefined; - readonly files?: object; -}; -export type EmitterEventType = EVENT_TYPE | string; -export type EventEmitterCallback = (event: EmitterEventPayload) => void; diff --git a/build/module/types/eventEmitter.js b/build/module/types/eventEmitter.js deleted file mode 100644 index 1e96535..0000000 --- a/build/module/types/eventEmitter.js +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnRFbWl0dGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3R5cGVzL2V2ZW50RW1pdHRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0= \ No newline at end of file diff --git a/build/module/version.d.ts b/build/module/version.d.ts deleted file mode 100644 index 5eda495..0000000 --- a/build/module/version.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const LIB_VERSION = "1.2.1"; diff --git a/build/module/version.js b/build/module/version.js deleted file mode 100644 index 5786777..0000000 --- a/build/module/version.js +++ /dev/null @@ -1,2 +0,0 @@ -export const LIB_VERSION = "1.2.1"; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyc2lvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy92ZXJzaW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sQ0FBQyxNQUFNLFdBQVcsR0FBRyxPQUFPLENBQUMifQ== \ No newline at end of file diff --git a/build/umd/index.js b/build/umd/index.js deleted file mode 100644 index bdfc4fa..0000000 --- a/build/umd/index.js +++ /dev/null @@ -1,1975 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SmartAppBridge = factory()); -})(this, (function () { 'use strict'; - - var PLATFORM; - (function (PLATFORM) { - PLATFORM["WEB"] = "web"; - PLATFORM["IOS"] = "ios"; - PLATFORM["ANDROID"] = "android"; - PLATFORM["UNKNOWN"] = "unknown"; - })(PLATFORM || (PLATFORM = {})); - var EVENT_TYPE; - (function (EVENT_TYPE) { - EVENT_TYPE["RECEIVE"] = "recv"; - EVENT_TYPE["SEND"] = "send"; - })(EVENT_TYPE || (EVENT_TYPE = {})); - var HANDLER; - (function (HANDLER) { - HANDLER["BOTX"] = "botx"; - HANDLER["EXPRESS"] = "express"; - })(HANDLER || (HANDLER = {})); - const RESPONSE_TIMEOUT = 30000; - const WEB_COMMAND_TYPE = 'smartapp'; - const WEB_COMMAND_TYPE_RPC = 'smartapp_rpc'; - const WEB_COMMAND_TYPE_RPC_LOGS = 'smartAppLogs'; - - const getPlatformByGetParam = () => { - const platform = new URLSearchParams(location.search).get('platform'); - const isValidPlatform = Object.values(PLATFORM).includes(platform); - if (isValidPlatform) - return platform; - return PLATFORM.UNKNOWN; - }; - const detectPlatformByUserAgent = () => { - if (/android/i.test(navigator.userAgent)) { - return PLATFORM.ANDROID; - } - if ((/iPad|iPhone|iPod/.test(navigator.userAgent) || - (navigator.userAgent.includes('Mac') && 'ontouchend' in document)) && - !window.MSStream) - return PLATFORM.IOS; - return PLATFORM.WEB; - }; - /** - * Get platform. Detection based on GET param `platform` or user agent. - * - * ```typescript - * const platform = getPlatform(); - * - * // => 'web' | 'ios' | 'android' - * ``` - */ - const getPlatform = () => { - return getPlatformByGetParam() || detectPlatformByUserAgent(); - }; - - // Unique ID creation requires a high quality random # generator. In the browser we therefore - // require the crypto API and do not support built-in fallback to lower quality random number - // generators (like Math.random()). - var getRandomValues; - var rnds8 = new Uint8Array(16); - function rng() { - // lazy load so that environments that need to polyfill have a chance to do so - if (!getRandomValues) { - // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also, - // find the complete implementation of crypto (msCrypto) on IE11. - getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto); - - if (!getRandomValues) { - throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'); - } - } - - return getRandomValues(rnds8); - } - - var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; - - function validate(uuid) { - return typeof uuid === 'string' && REGEX.test(uuid); - } - - /** - * Convert array of 16 byte values to UUID string format of the form: - * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX - */ - - var byteToHex = []; - - for (var i = 0; i < 256; ++i) { - byteToHex.push((i + 0x100).toString(16).substr(1)); - } - - function stringify(arr) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - // Note: Be careful editing this code! It's been tuned for performance - // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434 - var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one - // of the following: - // - One or more input array values don't map to a hex octet (leading to - // "undefined" in the uuid) - // - Invalid input values for the RFC `version` or `variant` fields - - if (!validate(uuid)) { - throw TypeError('Stringified UUID is invalid'); - } - - return uuid; - } - - function v4(options, buf, offset) { - options = options || {}; - var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` - - rnds[6] = rnds[6] & 0x0f | 0x40; - rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided - - if (buf) { - offset = offset || 0; - - for (var i = 0; i < 16; ++i) { - buf[offset + i] = rnds[i]; - } - - return buf; - } - - return stringify(rnds); - } - - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function createCommonjsModule(fn) { - var module = { exports: {} }; - return fn(module, module.exports), module.exports; - } - - /** Detect free variable `global` from Node.js. */ - - var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; - - var _freeGlobal = freeGlobal; - - /** Detect free variable `self`. */ - var freeSelf = typeof self == 'object' && self && self.Object === Object && self; - - /** Used as a reference to the global object. */ - var root = _freeGlobal || freeSelf || Function('return this')(); - - var _root = root; - - /** Built-in value references. */ - var Symbol = _root.Symbol; - - var _Symbol = Symbol; - - /** - * A specialized version of `_.map` for arrays without support for iteratee - * shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the new mapped array. - */ - function arrayMap(array, iteratee) { - var index = -1, - length = array == null ? 0 : array.length, - result = Array(length); - - while (++index < length) { - result[index] = iteratee(array[index], index, array); - } - return result; - } - - var _arrayMap = arrayMap; - - /** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * _.isArray(document.body.children); - * // => false - * - * _.isArray('abc'); - * // => false - * - * _.isArray(_.noop); - * // => false - */ - var isArray = Array.isArray; - - var isArray_1 = isArray; - - /** Used for built-in method references. */ - var objectProto$1 = Object.prototype; - - /** Used to check objects for own properties. */ - var hasOwnProperty = objectProto$1.hasOwnProperty; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var nativeObjectToString$1 = objectProto$1.toString; - - /** Built-in value references. */ - var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined; - - /** - * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the raw `toStringTag`. - */ - function getRawTag(value) { - var isOwn = hasOwnProperty.call(value, symToStringTag$1), - tag = value[symToStringTag$1]; - - try { - value[symToStringTag$1] = undefined; - var unmasked = true; - } catch (e) {} - - var result = nativeObjectToString$1.call(value); - if (unmasked) { - if (isOwn) { - value[symToStringTag$1] = tag; - } else { - delete value[symToStringTag$1]; - } - } - return result; - } - - var _getRawTag = getRawTag; - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var nativeObjectToString = objectProto.toString; - - /** - * Converts `value` to a string using `Object.prototype.toString`. - * - * @private - * @param {*} value The value to convert. - * @returns {string} Returns the converted string. - */ - function objectToString(value) { - return nativeObjectToString.call(value); - } - - var _objectToString = objectToString; - - /** `Object#toString` result references. */ - var nullTag = '[object Null]', - undefinedTag = '[object Undefined]'; - - /** Built-in value references. */ - var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined; - - /** - * The base implementation of `getTag` without fallbacks for buggy environments. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - function baseGetTag(value) { - if (value == null) { - return value === undefined ? undefinedTag : nullTag; - } - return (symToStringTag && symToStringTag in Object(value)) - ? _getRawTag(value) - : _objectToString(value); - } - - var _baseGetTag = baseGetTag; - - /** - * Checks if `value` is object-like. A value is object-like if it's not `null` - * and has a `typeof` result of "object". - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - * @example - * - * _.isObjectLike({}); - * // => true - * - * _.isObjectLike([1, 2, 3]); - * // => true - * - * _.isObjectLike(_.noop); - * // => false - * - * _.isObjectLike(null); - * // => false - */ - function isObjectLike(value) { - return value != null && typeof value == 'object'; - } - - var isObjectLike_1 = isObjectLike; - - /** `Object#toString` result references. */ - var symbolTag = '[object Symbol]'; - - /** - * Checks if `value` is classified as a `Symbol` primitive or object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. - * @example - * - * _.isSymbol(Symbol.iterator); - * // => true - * - * _.isSymbol('abc'); - * // => false - */ - function isSymbol(value) { - return typeof value == 'symbol' || - (isObjectLike_1(value) && _baseGetTag(value) == symbolTag); - } - - var isSymbol_1 = isSymbol; - - /** Used as references for various `Number` constants. */ - var INFINITY = 1 / 0; - - /** Used to convert symbols to primitives and strings. */ - var symbolProto = _Symbol ? _Symbol.prototype : undefined, - symbolToString = symbolProto ? symbolProto.toString : undefined; - - /** - * The base implementation of `_.toString` which doesn't convert nullish - * values to empty strings. - * - * @private - * @param {*} value The value to process. - * @returns {string} Returns the string. - */ - function baseToString(value) { - // Exit early for strings to avoid a performance hit in some environments. - if (typeof value == 'string') { - return value; - } - if (isArray_1(value)) { - // Recursively convert values (susceptible to call stack limits). - return _arrayMap(value, baseToString) + ''; - } - if (isSymbol_1(value)) { - return symbolToString ? symbolToString.call(value) : ''; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; - } - - var _baseToString = baseToString; - - /** - * Converts `value` to a string. An empty string is returned for `null` - * and `undefined` values. The sign of `-0` is preserved. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to convert. - * @returns {string} Returns the converted string. - * @example - * - * _.toString(null); - * // => '' - * - * _.toString(-0); - * // => '-0' - * - * _.toString([1, 2, 3]); - * // => '1,2,3' - */ - function toString(value) { - return value == null ? '' : _baseToString(value); - } - - var toString_1 = toString; - - /** - * The base implementation of `_.slice` without an iteratee call guard. - * - * @private - * @param {Array} array The array to slice. - * @param {number} [start=0] The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns the slice of `array`. - */ - function baseSlice(array, start, end) { - var index = -1, - length = array.length; - - if (start < 0) { - start = -start > length ? 0 : (length + start); - } - end = end > length ? length : end; - if (end < 0) { - end += length; - } - length = start > end ? 0 : ((end - start) >>> 0); - start >>>= 0; - - var result = Array(length); - while (++index < length) { - result[index] = array[index + start]; - } - return result; - } - - var _baseSlice = baseSlice; - - /** - * Casts `array` to a slice if it's needed. - * - * @private - * @param {Array} array The array to inspect. - * @param {number} start The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns the cast slice. - */ - function castSlice(array, start, end) { - var length = array.length; - end = end === undefined ? length : end; - return (!start && end >= length) ? array : _baseSlice(array, start, end); - } - - var _castSlice = castSlice; - - /** Used to compose unicode character classes. */ - var rsAstralRange$2 = '\\ud800-\\udfff', - rsComboMarksRange$3 = '\\u0300-\\u036f', - reComboHalfMarksRange$3 = '\\ufe20-\\ufe2f', - rsComboSymbolsRange$3 = '\\u20d0-\\u20ff', - rsComboRange$3 = rsComboMarksRange$3 + reComboHalfMarksRange$3 + rsComboSymbolsRange$3, - rsVarRange$2 = '\\ufe0e\\ufe0f'; - - /** Used to compose unicode capture groups. */ - var rsZWJ$2 = '\\u200d'; - - /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ - var reHasUnicode = RegExp('[' + rsZWJ$2 + rsAstralRange$2 + rsComboRange$3 + rsVarRange$2 + ']'); - - /** - * Checks if `string` contains Unicode symbols. - * - * @private - * @param {string} string The string to inspect. - * @returns {boolean} Returns `true` if a symbol is found, else `false`. - */ - function hasUnicode(string) { - return reHasUnicode.test(string); - } - - var _hasUnicode = hasUnicode; - - /** - * Converts an ASCII `string` to an array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the converted array. - */ - function asciiToArray(string) { - return string.split(''); - } - - var _asciiToArray = asciiToArray; - - /** Used to compose unicode character classes. */ - var rsAstralRange$1 = '\\ud800-\\udfff', - rsComboMarksRange$2 = '\\u0300-\\u036f', - reComboHalfMarksRange$2 = '\\ufe20-\\ufe2f', - rsComboSymbolsRange$2 = '\\u20d0-\\u20ff', - rsComboRange$2 = rsComboMarksRange$2 + reComboHalfMarksRange$2 + rsComboSymbolsRange$2, - rsVarRange$1 = '\\ufe0e\\ufe0f'; - - /** Used to compose unicode capture groups. */ - var rsAstral = '[' + rsAstralRange$1 + ']', - rsCombo$2 = '[' + rsComboRange$2 + ']', - rsFitz$1 = '\\ud83c[\\udffb-\\udfff]', - rsModifier$1 = '(?:' + rsCombo$2 + '|' + rsFitz$1 + ')', - rsNonAstral$1 = '[^' + rsAstralRange$1 + ']', - rsRegional$1 = '(?:\\ud83c[\\udde6-\\uddff]){2}', - rsSurrPair$1 = '[\\ud800-\\udbff][\\udc00-\\udfff]', - rsZWJ$1 = '\\u200d'; - - /** Used to compose unicode regexes. */ - var reOptMod$1 = rsModifier$1 + '?', - rsOptVar$1 = '[' + rsVarRange$1 + ']?', - rsOptJoin$1 = '(?:' + rsZWJ$1 + '(?:' + [rsNonAstral$1, rsRegional$1, rsSurrPair$1].join('|') + ')' + rsOptVar$1 + reOptMod$1 + ')*', - rsSeq$1 = rsOptVar$1 + reOptMod$1 + rsOptJoin$1, - rsSymbol = '(?:' + [rsNonAstral$1 + rsCombo$2 + '?', rsCombo$2, rsRegional$1, rsSurrPair$1, rsAstral].join('|') + ')'; - - /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ - var reUnicode = RegExp(rsFitz$1 + '(?=' + rsFitz$1 + ')|' + rsSymbol + rsSeq$1, 'g'); - - /** - * Converts a Unicode `string` to an array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the converted array. - */ - function unicodeToArray(string) { - return string.match(reUnicode) || []; - } - - var _unicodeToArray = unicodeToArray; - - /** - * Converts `string` to an array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the converted array. - */ - function stringToArray(string) { - return _hasUnicode(string) - ? _unicodeToArray(string) - : _asciiToArray(string); - } - - var _stringToArray = stringToArray; - - /** - * Creates a function like `_.lowerFirst`. - * - * @private - * @param {string} methodName The name of the `String` case method to use. - * @returns {Function} Returns the new case function. - */ - function createCaseFirst(methodName) { - return function(string) { - string = toString_1(string); - - var strSymbols = _hasUnicode(string) - ? _stringToArray(string) - : undefined; - - var chr = strSymbols - ? strSymbols[0] - : string.charAt(0); - - var trailing = strSymbols - ? _castSlice(strSymbols, 1).join('') - : string.slice(1); - - return chr[methodName]() + trailing; - }; - } - - var _createCaseFirst = createCaseFirst; - - /** - * Converts the first character of `string` to upper case. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the converted string. - * @example - * - * _.upperFirst('fred'); - * // => 'Fred' - * - * _.upperFirst('FRED'); - * // => 'FRED' - */ - var upperFirst = _createCaseFirst('toUpperCase'); - - var upperFirst_1 = upperFirst; - - /** - * Converts the first character of `string` to upper case and the remaining - * to lower case. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to capitalize. - * @returns {string} Returns the capitalized string. - * @example - * - * _.capitalize('FRED'); - * // => 'Fred' - */ - function capitalize(string) { - return upperFirst_1(toString_1(string).toLowerCase()); - } - - var capitalize_1 = capitalize; - - /** - * A specialized version of `_.reduce` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {*} [accumulator] The initial value. - * @param {boolean} [initAccum] Specify using the first element of `array` as - * the initial value. - * @returns {*} Returns the accumulated value. - */ - function arrayReduce(array, iteratee, accumulator, initAccum) { - var index = -1, - length = array == null ? 0 : array.length; - - if (initAccum && length) { - accumulator = array[++index]; - } - while (++index < length) { - accumulator = iteratee(accumulator, array[index], index, array); - } - return accumulator; - } - - var _arrayReduce = arrayReduce; - - /** - * The base implementation of `_.propertyOf` without support for deep paths. - * - * @private - * @param {Object} object The object to query. - * @returns {Function} Returns the new accessor function. - */ - function basePropertyOf(object) { - return function(key) { - return object == null ? undefined : object[key]; - }; - } - - var _basePropertyOf = basePropertyOf; - - /** Used to map Latin Unicode letters to basic Latin letters. */ - var deburredLetters = { - // Latin-1 Supplement block. - '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', - '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', - '\xc7': 'C', '\xe7': 'c', - '\xd0': 'D', '\xf0': 'd', - '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', - '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', - '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', - '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', - '\xd1': 'N', '\xf1': 'n', - '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', - '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', - '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', - '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', - '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', - '\xc6': 'Ae', '\xe6': 'ae', - '\xde': 'Th', '\xfe': 'th', - '\xdf': 'ss', - // Latin Extended-A block. - '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', - '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', - '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', - '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', - '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', - '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', - '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', - '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', - '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', - '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', - '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', - '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', - '\u0134': 'J', '\u0135': 'j', - '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', - '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', - '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', - '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', - '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', - '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', - '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', - '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', - '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', - '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', - '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', - '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', - '\u0163': 't', '\u0165': 't', '\u0167': 't', - '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', - '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', - '\u0174': 'W', '\u0175': 'w', - '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', - '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', - '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', - '\u0132': 'IJ', '\u0133': 'ij', - '\u0152': 'Oe', '\u0153': 'oe', - '\u0149': "'n", '\u017f': 's' - }; - - /** - * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A - * letters to basic Latin letters. - * - * @private - * @param {string} letter The matched letter to deburr. - * @returns {string} Returns the deburred letter. - */ - var deburrLetter = _basePropertyOf(deburredLetters); - - var _deburrLetter = deburrLetter; - - /** Used to match Latin Unicode letters (excluding mathematical operators). */ - var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; - - /** Used to compose unicode character classes. */ - var rsComboMarksRange$1 = '\\u0300-\\u036f', - reComboHalfMarksRange$1 = '\\ufe20-\\ufe2f', - rsComboSymbolsRange$1 = '\\u20d0-\\u20ff', - rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1; - - /** Used to compose unicode capture groups. */ - var rsCombo$1 = '[' + rsComboRange$1 + ']'; - - /** - * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and - * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). - */ - var reComboMark = RegExp(rsCombo$1, 'g'); - - /** - * Deburrs `string` by converting - * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) - * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) - * letters to basic Latin letters and removing - * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to deburr. - * @returns {string} Returns the deburred string. - * @example - * - * _.deburr('déjà vu'); - * // => 'deja vu' - */ - function deburr(string) { - string = toString_1(string); - return string && string.replace(reLatin, _deburrLetter).replace(reComboMark, ''); - } - - var deburr_1 = deburr; - - /** Used to match words composed of alphanumeric characters. */ - var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; - - /** - * Splits an ASCII `string` into an array of its words. - * - * @private - * @param {string} The string to inspect. - * @returns {Array} Returns the words of `string`. - */ - function asciiWords(string) { - return string.match(reAsciiWord) || []; - } - - var _asciiWords = asciiWords; - - /** Used to detect strings that need a more robust regexp to match words. */ - var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; - - /** - * Checks if `string` contains a word composed of Unicode symbols. - * - * @private - * @param {string} string The string to inspect. - * @returns {boolean} Returns `true` if a word is found, else `false`. - */ - function hasUnicodeWord(string) { - return reHasUnicodeWord.test(string); - } - - var _hasUnicodeWord = hasUnicodeWord; - - /** Used to compose unicode character classes. */ - var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f', - reComboHalfMarksRange = '\\ufe20-\\ufe2f', - rsComboSymbolsRange = '\\u20d0-\\u20ff', - rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, - rsDingbatRange = '\\u2700-\\u27bf', - rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', - rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', - rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', - rsPunctuationRange = '\\u2000-\\u206f', - rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', - rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', - rsVarRange = '\\ufe0e\\ufe0f', - rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; - - /** Used to compose unicode capture groups. */ - var rsApos$1 = "['\u2019]", - rsBreak = '[' + rsBreakRange + ']', - rsCombo = '[' + rsComboRange + ']', - rsDigits = '\\d+', - rsDingbat = '[' + rsDingbatRange + ']', - rsLower = '[' + rsLowerRange + ']', - rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', - rsFitz = '\\ud83c[\\udffb-\\udfff]', - rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', - rsNonAstral = '[^' + rsAstralRange + ']', - rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', - rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', - rsUpper = '[' + rsUpperRange + ']', - rsZWJ = '\\u200d'; - - /** Used to compose unicode regexes. */ - var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', - rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', - rsOptContrLower = '(?:' + rsApos$1 + '(?:d|ll|m|re|s|t|ve))?', - rsOptContrUpper = '(?:' + rsApos$1 + '(?:D|LL|M|RE|S|T|VE))?', - reOptMod = rsModifier + '?', - rsOptVar = '[' + rsVarRange + ']?', - rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', - rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', - rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', - rsSeq = rsOptVar + reOptMod + rsOptJoin, - rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq; - - /** Used to match complex or compound words. */ - var reUnicodeWord = RegExp([ - rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', - rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', - rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, - rsUpper + '+' + rsOptContrUpper, - rsOrdUpper, - rsOrdLower, - rsDigits, - rsEmoji - ].join('|'), 'g'); - - /** - * Splits a Unicode `string` into an array of its words. - * - * @private - * @param {string} The string to inspect. - * @returns {Array} Returns the words of `string`. - */ - function unicodeWords(string) { - return string.match(reUnicodeWord) || []; - } - - var _unicodeWords = unicodeWords; - - /** - * Splits `string` into an array of its words. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to inspect. - * @param {RegExp|string} [pattern] The pattern to match words. - * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. - * @returns {Array} Returns the words of `string`. - * @example - * - * _.words('fred, barney, & pebbles'); - * // => ['fred', 'barney', 'pebbles'] - * - * _.words('fred, barney, & pebbles', /[^, ]+/g); - * // => ['fred', 'barney', '&', 'pebbles'] - */ - function words(string, pattern, guard) { - string = toString_1(string); - pattern = guard ? undefined : pattern; - - if (pattern === undefined) { - return _hasUnicodeWord(string) ? _unicodeWords(string) : _asciiWords(string); - } - return string.match(pattern) || []; - } - - var words_1 = words; - - /** Used to compose unicode capture groups. */ - var rsApos = "['\u2019]"; - - /** Used to match apostrophes. */ - var reApos = RegExp(rsApos, 'g'); - - /** - * Creates a function like `_.camelCase`. - * - * @private - * @param {Function} callback The function to combine each word. - * @returns {Function} Returns the new compounder function. - */ - function createCompounder(callback) { - return function(string) { - return _arrayReduce(words_1(deburr_1(string).replace(reApos, '')), callback, ''); - }; - } - - var _createCompounder = createCompounder; - - /** - * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the camel cased string. - * @example - * - * _.camelCase('Foo Bar'); - * // => 'fooBar' - * - * _.camelCase('--foo-bar--'); - * // => 'fooBar' - * - * _.camelCase('__FOO_BAR__'); - * // => 'fooBar' - */ - var camelCase = _createCompounder(function(result, word, index) { - word = word.toLowerCase(); - return result + (index ? capitalize_1(word) : word); - }); - - var camelCase_1 = camelCase; - - /** - * Converts `string` to - * [snake case](https://en.wikipedia.org/wiki/Snake_case). - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category String - * @param {string} [string=''] The string to convert. - * @returns {string} Returns the snake cased string. - * @example - * - * _.snakeCase('Foo Bar'); - * // => 'foo_bar' - * - * _.snakeCase('fooBar'); - * // => 'foo_bar' - * - * _.snakeCase('--FOO-BAR--'); - * // => 'foo_bar' - */ - var snakeCase = _createCompounder(function(result, word, index) { - return result + (index ? '_' : '') + word.toLowerCase(); - }); - - var snakeCase_1 = snakeCase; - - /* eslint-disable @typescript-eslint/no-explicit-any */ - const isUuid = (value) => { - return /[0-9a-fA-F-]{32}/.test(value); - }; - const snakeCaseToCamelCase = (data) => { - if (Array.isArray(data)) - return data.map(snakeCaseToCamelCase); - if (!data || data.constructor?.name !== 'Object') - return data; - return Object.keys(data).reduce((result, key) => { - const value = snakeCaseToCamelCase(data[key]); - const keyValue = isUuid(key) ? key : camelCase_1(key); - return { ...result, [keyValue]: value }; - }, {}); - }; - const camelCaseToSnakeCase = (data) => { - if (Array.isArray(data)) - return data.map(camelCaseToSnakeCase); - if (!data || data.constructor?.name !== 'Object') - return data; - return Object.keys(data).reduce((result, key) => { - const value = camelCaseToSnakeCase(data[key]); - return { ...result, [snakeCase_1(key)]: value }; - }, {}); - }; - - var eventemitter3 = createCommonjsModule(function (module) { - - var has = Object.prototype.hasOwnProperty - , prefix = '~'; - - /** - * Constructor to create a storage for our `EE` objects. - * An `Events` instance is a plain object whose properties are event names. - * - * @constructor - * @private - */ - function Events() {} - - // - // We try to not inherit from `Object.prototype`. In some engines creating an - // instance in this way is faster than calling `Object.create(null)` directly. - // If `Object.create(null)` is not supported we prefix the event names with a - // character to make sure that the built-in object properties are not - // overridden or used as an attack vector. - // - if (Object.create) { - Events.prototype = Object.create(null); - - // - // This hack is needed because the `__proto__` property is still inherited in - // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. - // - if (!new Events().__proto__) prefix = false; - } - - /** - * Representation of a single event listener. - * - * @param {Function} fn The listener function. - * @param {*} context The context to invoke the listener with. - * @param {Boolean} [once=false] Specify if the listener is a one-time listener. - * @constructor - * @private - */ - function EE(fn, context, once) { - this.fn = fn; - this.context = context; - this.once = once || false; - } - - /** - * Add a listener for a given event. - * - * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. - * @param {(String|Symbol)} event The event name. - * @param {Function} fn The listener function. - * @param {*} context The context to invoke the listener with. - * @param {Boolean} once Specify if the listener is a one-time listener. - * @returns {EventEmitter} - * @private - */ - function addListener(emitter, event, fn, context, once) { - if (typeof fn !== 'function') { - throw new TypeError('The listener must be a function'); - } - - var listener = new EE(fn, context || emitter, once) - , evt = prefix ? prefix + event : event; - - if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; - else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); - else emitter._events[evt] = [emitter._events[evt], listener]; - - return emitter; - } - - /** - * Clear event by name. - * - * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. - * @param {(String|Symbol)} evt The Event name. - * @private - */ - function clearEvent(emitter, evt) { - if (--emitter._eventsCount === 0) emitter._events = new Events(); - else delete emitter._events[evt]; - } - - /** - * Minimal `EventEmitter` interface that is molded against the Node.js - * `EventEmitter` interface. - * - * @constructor - * @public - */ - function EventEmitter() { - this._events = new Events(); - this._eventsCount = 0; - } - - /** - * Return an array listing the events for which the emitter has registered - * listeners. - * - * @returns {Array} - * @public - */ - EventEmitter.prototype.eventNames = function eventNames() { - var names = [] - , events - , name; - - if (this._eventsCount === 0) return names; - - for (name in (events = this._events)) { - if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); - } - - if (Object.getOwnPropertySymbols) { - return names.concat(Object.getOwnPropertySymbols(events)); - } - - return names; - }; - - /** - * Return the listeners registered for a given event. - * - * @param {(String|Symbol)} event The event name. - * @returns {Array} The registered listeners. - * @public - */ - EventEmitter.prototype.listeners = function listeners(event) { - var evt = prefix ? prefix + event : event - , handlers = this._events[evt]; - - if (!handlers) return []; - if (handlers.fn) return [handlers.fn]; - - for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { - ee[i] = handlers[i].fn; - } - - return ee; - }; - - /** - * Return the number of listeners listening to a given event. - * - * @param {(String|Symbol)} event The event name. - * @returns {Number} The number of listeners. - * @public - */ - EventEmitter.prototype.listenerCount = function listenerCount(event) { - var evt = prefix ? prefix + event : event - , listeners = this._events[evt]; - - if (!listeners) return 0; - if (listeners.fn) return 1; - return listeners.length; - }; - - /** - * Calls each of the listeners registered for a given event. - * - * @param {(String|Symbol)} event The event name. - * @returns {Boolean} `true` if the event had listeners, else `false`. - * @public - */ - EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { - var evt = prefix ? prefix + event : event; - - if (!this._events[evt]) return false; - - var listeners = this._events[evt] - , len = arguments.length - , args - , i; - - if (listeners.fn) { - if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); - - switch (len) { - case 1: return listeners.fn.call(listeners.context), true; - case 2: return listeners.fn.call(listeners.context, a1), true; - case 3: return listeners.fn.call(listeners.context, a1, a2), true; - case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; - case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; - case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; - } - - for (i = 1, args = new Array(len -1); i < len; i++) { - args[i - 1] = arguments[i]; - } - - listeners.fn.apply(listeners.context, args); - } else { - var length = listeners.length - , j; - - for (i = 0; i < length; i++) { - if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); - - switch (len) { - case 1: listeners[i].fn.call(listeners[i].context); break; - case 2: listeners[i].fn.call(listeners[i].context, a1); break; - case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; - case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; - default: - if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { - args[j - 1] = arguments[j]; - } - - listeners[i].fn.apply(listeners[i].context, args); - } - } - } - - return true; - }; - - /** - * Add a listener for a given event. - * - * @param {(String|Symbol)} event The event name. - * @param {Function} fn The listener function. - * @param {*} [context=this] The context to invoke the listener with. - * @returns {EventEmitter} `this`. - * @public - */ - EventEmitter.prototype.on = function on(event, fn, context) { - return addListener(this, event, fn, context, false); - }; - - /** - * Add a one-time listener for a given event. - * - * @param {(String|Symbol)} event The event name. - * @param {Function} fn The listener function. - * @param {*} [context=this] The context to invoke the listener with. - * @returns {EventEmitter} `this`. - * @public - */ - EventEmitter.prototype.once = function once(event, fn, context) { - return addListener(this, event, fn, context, true); - }; - - /** - * Remove the listeners of a given event. - * - * @param {(String|Symbol)} event The event name. - * @param {Function} fn Only remove the listeners that match this function. - * @param {*} context Only remove the listeners that have this context. - * @param {Boolean} once Only remove one-time listeners. - * @returns {EventEmitter} `this`. - * @public - */ - EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { - var evt = prefix ? prefix + event : event; - - if (!this._events[evt]) return this; - if (!fn) { - clearEvent(this, evt); - return this; - } - - var listeners = this._events[evt]; - - if (listeners.fn) { - if ( - listeners.fn === fn && - (!once || listeners.once) && - (!context || listeners.context === context) - ) { - clearEvent(this, evt); - } - } else { - for (var i = 0, events = [], length = listeners.length; i < length; i++) { - if ( - listeners[i].fn !== fn || - (once && !listeners[i].once) || - (context && listeners[i].context !== context) - ) { - events.push(listeners[i]); - } - } - - // - // Reset the array, or remove it completely if we have no more listeners. - // - if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; - else clearEvent(this, evt); - } - - return this; - }; - - /** - * Remove all listeners, or those of the specified event. - * - * @param {(String|Symbol)} [event] The event name. - * @returns {EventEmitter} `this`. - * @public - */ - EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { - var evt; - - if (event) { - evt = prefix ? prefix + event : event; - if (this._events[evt]) clearEvent(this, evt); - } else { - this._events = new Events(); - this._eventsCount = 0; - } - - return this; - }; - - // - // Alias methods names because people roll like that. - // - EventEmitter.prototype.off = EventEmitter.prototype.removeListener; - EventEmitter.prototype.addListener = EventEmitter.prototype.on; - - // - // Expose the prefix. - // - EventEmitter.prefixed = prefix; - - // - // Allow `EventEmitter` to be imported as module namespace. - // - EventEmitter.EventEmitter = EventEmitter; - - // - // Expose the module. - // - { - module.exports = EventEmitter; - } - }); - - /** - * Extended Event Emitted class - * - * ```typescript - * const emitter = new EmitterEventPayload(); - * - * // promise will be rejected in 20 secs - * // if no one event has been received with type 'ref-uuid-value' - * // otherwise promise will be fulfilled with payload object - * const promise = emitter.onceWithTimeout('ref-uuid-value', 20000) - * ``` - */ - class ExtendedEventEmitter extends eventemitter3 { - constructor() { - super(); - } - /** - * Wait when event with `type` will be emitted for `timeout` ms. - * - * ```js - * emitter.onceWithTimeout('d6910a9d-ea24-5fc6-a654-28781ef21f8f', 20000) - * // => Promise - * ``` - */ - onceWithTimeout(type, timeout) { - return new Promise((resolve, reject) => { - const timer = setTimeout(() => reject(), timeout); - this.once(type, (event) => { - clearTimeout(timer); - resolve(event); - }); - }); - } - } - - /** @ignore */ - const log = (...args) => { - const text = args.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '); - alert(text); - }; - - class AndroidBridge { - eventEmitter; - hasCommunicationObject; - logsEnabled; - isRenameParamsEnabledForBotx; - constructor() { - this.hasCommunicationObject = typeof window.express !== 'undefined' && !!window.express.handleSmartAppEvent; - this.eventEmitter = new ExtendedEventEmitter(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - if (!this.hasCommunicationObject) { - log('No method "express.handleSmartAppEvent", cannot send message to Android'); - return; - } - // Expect json data as string - window.handleAndroidEvent = ({ ref, data, files, }) => { - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2)); - const { type, ...payload } = data; - const emitterType = ref || EVENT_TYPE.RECEIVE; - // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready - const eventFiles = this.isRenameParamsEnabledForBotx ? - files?.map((file) => snakeCaseToCamelCase(file)) : files; - const event = { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload, - files: eventFiles, - }; - this.eventEmitter.emit(emitterType, event); - }; - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - * @param callback - Callback function. - */ - onReceive(callback) { - this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - if (!this.hasCommunicationObject) - return Promise.reject(); - const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true; - const ref = v4(); // UUID to detect express response. - const eventParams = { - ref, - type: WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => camelCaseToSnakeCase(file)) : files; - const event = JSON.stringify(files ? { ...eventParams, files: eventFiles } : eventParams); - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', JSON.stringify(event, null, ' ')); - window.express.handleSmartAppEvent(event); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param files - * @param timeout - Timeout in ms. - * @param guaranteed_delivery_required - boolean. - * @returns Promise. - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - * @param method - Event type. - * @param params - * @param timeout - Timeout in ms. - * @returns Promise. - */ - sendClientEvent({ method, params, timeout }) { - return this.sendEvent({ handler: HANDLER.EXPRESS, method, params, timeout }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } - log(data) { - if ((!this.hasCommunicationObject || !data) || - (typeof data !== 'string' && typeof data !== 'object')) - return; - window.express.handleSmartAppEvent(JSON.stringify({ 'SmartApp Log': data }, null, 2)); - } - } - - class IosBridge { - eventEmitter; - hasCommunicationObject; - logsEnabled; - isRenameParamsEnabledForBotx; - constructor() { - this.hasCommunicationObject = - window.webkit && - window.webkit.messageHandlers && - window.webkit.messageHandlers.express && - !!window.webkit.messageHandlers.express.postMessage; - this.eventEmitter = new ExtendedEventEmitter(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - if (!this.hasCommunicationObject) { - log('No method "express.postMessage", cannot send message to iOS'); - return; - } - // Expect json data as string - window.handleIosEvent = ({ ref, data, files, }) => { - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2)); - const { type, ...payload } = data; - const emitterType = ref || EVENT_TYPE.RECEIVE; - // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready - const eventFiles = this.isRenameParamsEnabledForBotx ? - files?.map((file) => snakeCaseToCamelCase(file)) : files; - const event = { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload, - files: eventFiles, - }; - this.eventEmitter.emit(emitterType, event); - }; - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onRecieve(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback) { - this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - if (!this.hasCommunicationObject) - return Promise.reject(); - const ref = v4(); // UUID to detect express response. - const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true; - const eventProps = { - ref, - type: WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => camelCaseToSnakeCase(file)) : files; - const event = files ? { ...eventProps, files: eventFiles } : eventProps; - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', JSON.stringify(event, null, ' ')); - window.webkit.messageHandlers.express.postMessage(event); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendBotEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * files: [] - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * type: 'get_weather', - * handler: 'express', - * payload: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout = RESPONSE_TIMEOUT, }) { - return this.sendEvent({ - handler: HANDLER.EXPRESS, - method, - params, - timeout, - }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } - log(data) { - if (!this.hasCommunicationObject || !data) - return; - let value = ''; - if (typeof data === 'string') { - value = data; - } - else if (typeof data === 'object') { - value = JSON.stringify(data, null, 2); - } - else - return; - window.webkit.messageHandlers.express.postMessage({ 'SmartApp Log': value }); - } - } - - class WebBridge { - eventEmitter; - logsEnabled; - isRenameParamsEnabledForBotx; - constructor() { - this.eventEmitter = new ExtendedEventEmitter(); - this.addGlobalListener(); - this.logsEnabled = false; - this.isRenameParamsEnabledForBotx = true; - } - addGlobalListener() { - window.addEventListener('message', (event) => { - if (typeof event.data !== 'object' || - typeof event.data.data !== 'object' || - typeof event.data.data.type !== 'string') - return; - const { ref, data: { type, ...payload }, files, } = event.data; - const isRenameParamsEnabled = this.isRenameParamsEnabledForBotx; // TODO fix when handler is passed - if (this.logsEnabled) - console.log('Bridge ~ Incoming event', event.data); - const emitterType = ref || EVENT_TYPE.RECEIVE; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => snakeCaseToCamelCase(file)) : files; - this.eventEmitter.emit(emitterType, { - ref, - type, - payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload, - files: eventFiles, - }); - }); - } - /** - * Set callback function to handle events without **ref** - * (notifications for example). - * - * ```js - * bridge.onReceive(({ type, handler, payload }) => { - * // Handle event data - * console.log('event', type, handler, payload) - * }) - * ``` - */ - onReceive(callback) { - this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback); - } - sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) { - const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false; - const ref = v4(); // UUID to detect express response. - const payload = { - ref, - type: WEB_COMMAND_TYPE_RPC, - method, - handler, - payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params, - guaranteed_delivery_required, - }; - const eventFiles = isRenameParamsEnabled ? - files?.map((file) => camelCaseToSnakeCase(file)) : files; - const event = files ? { ...payload, files: eventFiles } : payload; - if (this.logsEnabled) - console.log('Bridge ~ Outgoing event', event); - window.parent.postMessage({ - type: WEB_COMMAND_TYPE, - payload: event, - }, '*'); - return this.eventEmitter.onceWithTimeout(ref, timeout); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) { - return this.sendEvent({ - handler: HANDLER.BOTX, - method, - params, - files, - timeout, - guaranteed_delivery_required, - }); - } - /** - * Send event and wait response from express client. - * - * ```js - * bridge - * .sendClientEvent( - * { - * method: 'get_weather', - * params: { - * city: 'Moscow', - * }, - * } - * ) - * .then(data => { - * // Handle response - * console.log('response', data) - * }) - * ``` - */ - sendClientEvent({ method, params, timeout }) { - return this.sendEvent({ - handler: HANDLER.EXPRESS, - method, - params, - timeout, - }); - } - /** - * Enabling logs. - * - * ```js - * bridge - * .enableLogs() - * ``` - */ - enableLogs() { - this.logsEnabled = true; - const _log = console.log; - console.log = function (...rest) { - window.parent.postMessage({ - type: WEB_COMMAND_TYPE_RPC_LOGS, - payload: rest, - }, '*'); - _log.apply(console, rest); - }; - } - /** - * Disabling logs. - * - * ```js - * bridge - * .disableLogs() - * ``` - */ - disableLogs() { - this.logsEnabled = false; - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .enableRenameParams() - * ``` - */ - enableRenameParams() { - this.isRenameParamsEnabledForBotx = true; - console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa'); - } - /** - * Enabling renaming event params from camelCase to snake_case and vice versa - * ```js - * bridge - * .disableRenameParams() - * ``` - */ - disableRenameParams() { - this.isRenameParamsEnabledForBotx = false; - console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa'); - } - } - - const LIB_VERSION = "1.2.1"; - - const getBridge = () => { - if (process.env.NODE_ENV === 'test') - return null; - const platform = getPlatform(); - console.log('Bridge ~ version', LIB_VERSION); - switch (platform) { - case PLATFORM.ANDROID: - return new AndroidBridge(); - case PLATFORM.IOS: - return new IosBridge(); - case PLATFORM.WEB: - return new WebBridge(); - default: - console.error('Wrong platform'); - break; - } - return null; - }; - var index = getBridge(); - - return index; - -})); diff --git a/src/version.ts b/src/version.ts index eadd554..000df09 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const LIB_VERSION = "1.2.1"; +export const LIB_VERSION = "1.2.2";