@portkey/onboarding 1.4.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +39 -0
  3. package/dist/commonjs/browser.d.ts +5 -0
  4. package/dist/commonjs/browser.js +36 -0
  5. package/dist/commonjs/constants/index.d.ts +9 -0
  6. package/dist/commonjs/constants/index.js +12 -0
  7. package/dist/commonjs/evokeApp/evoke.d.ts +5 -0
  8. package/dist/commonjs/evokeApp/evoke.js +79 -0
  9. package/dist/commonjs/evokeApp/generate.d.ts +5 -0
  10. package/dist/commonjs/evokeApp/generate.js +62 -0
  11. package/dist/commonjs/evokeApp/index.d.ts +13 -0
  12. package/dist/commonjs/evokeApp/index.js +112 -0
  13. package/dist/commonjs/evokeApp/types.d.ts +37 -0
  14. package/dist/commonjs/evokeApp/types.js +2 -0
  15. package/dist/commonjs/evokePortkey/checkPortkeyExtension.d.ts +1 -0
  16. package/dist/commonjs/evokePortkey/checkPortkeyExtension.js +30 -0
  17. package/dist/commonjs/evokePortkey/evokePortkeyApp.d.ts +16 -0
  18. package/dist/commonjs/evokePortkey/evokePortkeyApp.js +32 -0
  19. package/dist/commonjs/evokePortkey/index.d.ts +2 -0
  20. package/dist/commonjs/evokePortkey/index.js +18 -0
  21. package/dist/commonjs/index.d.ts +3 -0
  22. package/dist/commonjs/index.js +32 -0
  23. package/dist/commonjs/package.json +1 -0
  24. package/dist/commonjs/utils/index.d.ts +1 -0
  25. package/dist/commonjs/utils/index.js +23 -0
  26. package/dist/esm/browser.d.ts +5 -0
  27. package/dist/esm/browser.js +31 -0
  28. package/dist/esm/constants/index.d.ts +9 -0
  29. package/dist/esm/constants/index.js +9 -0
  30. package/dist/esm/evokeApp/evoke.d.ts +5 -0
  31. package/dist/esm/evokeApp/evoke.js +72 -0
  32. package/dist/esm/evokeApp/generate.d.ts +5 -0
  33. package/dist/esm/evokeApp/generate.js +55 -0
  34. package/dist/esm/evokeApp/index.d.ts +13 -0
  35. package/dist/esm/evokeApp/index.js +85 -0
  36. package/dist/esm/evokeApp/types.d.ts +37 -0
  37. package/dist/esm/evokeApp/types.js +1 -0
  38. package/dist/esm/evokePortkey/checkPortkeyExtension.d.ts +1 -0
  39. package/dist/esm/evokePortkey/checkPortkeyExtension.js +26 -0
  40. package/dist/esm/evokePortkey/evokePortkeyApp.d.ts +16 -0
  41. package/dist/esm/evokePortkey/evokePortkeyApp.js +28 -0
  42. package/dist/esm/evokePortkey/index.d.ts +2 -0
  43. package/dist/esm/evokePortkey/index.js +2 -0
  44. package/dist/esm/index.d.ts +3 -0
  45. package/dist/esm/index.js +3 -0
  46. package/dist/esm/package.json +1 -0
  47. package/dist/esm/utils/index.d.ts +1 -0
  48. package/dist/esm/utils/index.js +16 -0
  49. package/dist/types/browser.d.ts +6 -0
  50. package/dist/types/browser.d.ts.map +1 -0
  51. package/dist/types/constants/index.d.ts +10 -0
  52. package/dist/types/constants/index.d.ts.map +1 -0
  53. package/dist/types/evokeApp/evoke.d.ts +6 -0
  54. package/dist/types/evokeApp/evoke.d.ts.map +1 -0
  55. package/dist/types/evokeApp/generate.d.ts +6 -0
  56. package/dist/types/evokeApp/generate.d.ts.map +1 -0
  57. package/dist/types/evokeApp/index.d.ts +14 -0
  58. package/dist/types/evokeApp/index.d.ts.map +1 -0
  59. package/dist/types/evokeApp/types.d.ts +38 -0
  60. package/dist/types/evokeApp/types.d.ts.map +1 -0
  61. package/dist/types/evokePortkey/checkPortkeyExtension.d.ts +2 -0
  62. package/dist/types/evokePortkey/checkPortkeyExtension.d.ts.map +1 -0
  63. package/dist/types/evokePortkey/evokePortkeyApp.d.ts +17 -0
  64. package/dist/types/evokePortkey/evokePortkeyApp.d.ts.map +1 -0
  65. package/dist/types/evokePortkey/index.d.ts +3 -0
  66. package/dist/types/evokePortkey/index.d.ts.map +1 -0
  67. package/dist/types/index.d.ts +4 -0
  68. package/dist/types/index.d.ts.map +1 -0
  69. package/dist/types/utils/index.d.ts +2 -0
  70. package/dist/types/utils/index.d.ts.map +1 -0
  71. package/package.json +49 -0
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # `@portkey/onboarding`
2
+
3
+ ![ES Version](https://img.shields.io/badge/ES-2020-yellow)
4
+ ![Node Version](https://img.shields.io/badge/node-14.x-green)
5
+ [![NPM Package Version][npm-image-version]][npm-url]
6
+
7
+ ## Installation
8
+
9
+ ### Using NPM
10
+
11
+ ```bash
12
+ npm install @portkey/onboarding
13
+ ```
14
+
15
+ ### Using Yarn
16
+
17
+ ```bash
18
+ yarn add @portkey/onboarding
19
+ ```
20
+
21
+ ## Prerequisites
22
+
23
+ - :gear: [NodeJS](https://nodejs.org/) (LTS/Fermium)
24
+ - :toolbox: [Yarn](https://yarnpkg.com/)/[Lerna](https://lerna.js.org/)
25
+
26
+ ## Package.json Scripts
27
+
28
+ | Script | Description |
29
+ | -------- | -------------------------------------------------- |
30
+ | clean | Uses `rm` to remove `dist/` |
31
+ | build | Uses `tsc` to build package and dependent packages |
32
+ | lint | Uses `eslint` to lint package |
33
+ | lint:fix | Uses `eslint` to check and fix any warnings |
34
+ | format | Uses `prettier` to format the code |
35
+
36
+ ## Usage
37
+
38
+ [npm-image-version]: https://img.shields.io/npm/v/@portkey/onboarding
39
+ [npm-url]: https://npmjs.org/package/@portkey/onboarding
@@ -0,0 +1,5 @@
1
+ export declare const semverCompare: (verionA: string, versionB: string) => -1 | 0 | 1;
2
+ export declare const getIOSVersion: () => number;
3
+ export declare const isAndroid: boolean;
4
+ export declare const isIos: boolean;
5
+ export declare const isOriginalChrome: boolean;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOriginalChrome = exports.isIos = exports.isAndroid = exports.getIOSVersion = exports.semverCompare = void 0;
4
+ const ua = typeof navigator !== 'undefined' ? navigator.userAgent : '';
5
+ const semverCompare = (verionA, versionB) => {
6
+ const { isNaN } = window;
7
+ const splitA = verionA.split('.');
8
+ const splitB = versionB.split('.');
9
+ for (let i = 0; i < 3; i++) {
10
+ const snippetA = Number(splitA[i]);
11
+ const snippetB = Number(splitB[i]);
12
+ if (snippetA > snippetB)
13
+ return 1;
14
+ if (snippetB > snippetA)
15
+ return -1;
16
+ if (!isNaN(snippetA) && isNaN(snippetB))
17
+ return 1;
18
+ if (isNaN(snippetA) && !isNaN(snippetB))
19
+ return -1;
20
+ }
21
+ return 0;
22
+ };
23
+ exports.semverCompare = semverCompare;
24
+ const getIOSVersion = () => {
25
+ var _a;
26
+ const version = (_a = ua
27
+ .toLocaleLowerCase()
28
+ .match(/cpu iphone os (.*?) like mac os/)) === null || _a === void 0 ? void 0 : _a[1].split('_');
29
+ if (!version)
30
+ return -1;
31
+ return Number.parseInt(version[0], 10);
32
+ };
33
+ exports.getIOSVersion = getIOSVersion;
34
+ exports.isAndroid = /android/i.test(ua);
35
+ exports.isIos = /iphone|ipad|ipod/i.test(ua);
36
+ exports.isOriginalChrome = /chrome\/[\d.]+ mobile safari\/[\d.]+/i.test(ua) && exports.isAndroid && ua.indexOf('Version') < 0;
@@ -0,0 +1,9 @@
1
+ export declare const APP_DOWNLOAD_URL: {
2
+ APP_STORE: string;
3
+ CHROME_STORE: string;
4
+ };
5
+ export declare const EXTENSION_DOWNLOAD_URL: {
6
+ CHROME: string;
7
+ EDGE: string;
8
+ DEFAULT: string;
9
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXTENSION_DOWNLOAD_URL = exports.APP_DOWNLOAD_URL = void 0;
4
+ exports.APP_DOWNLOAD_URL = {
5
+ APP_STORE: 'https://apps.apple.com/us/app/portkey-ca-wallet-crypto-nft/id6445808228',
6
+ CHROME_STORE: 'https://play.google.com/store/apps/details?id=com.portkey.did',
7
+ };
8
+ exports.EXTENSION_DOWNLOAD_URL = {
9
+ CHROME: 'https://chrome.google.com/webstore/detail/portkey-did-crypto-nft/hpjiiechbbhefmpggegmahejiiphbmij',
10
+ EDGE: 'https://chrome.google.com/webstore/detail/portkey-did-crypto-nft/hpjiiechbbhefmpggegmahejiiphbmij',
11
+ DEFAULT: 'https://portkey.finance/download',
12
+ };
@@ -0,0 +1,5 @@
1
+ import { OpenStatus } from './types';
2
+ export declare function evokeByLocation(uri: string): void;
3
+ export declare function evokeByTagA(uri: string): void;
4
+ export declare function evokeByIFrame(uri: string): void;
5
+ export declare function checkOpen(callback: (status: OpenStatus) => void, timeout: number): void;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkOpen = exports.evokeByIFrame = exports.evokeByTagA = exports.evokeByLocation = void 0;
4
+ let hidden = 'hidden';
5
+ let visibilityChange = 'visibilitychange';
6
+ let iframe;
7
+ function getSupportedProperty() {
8
+ if (typeof document === 'undefined')
9
+ return;
10
+ if (typeof document.hidden !== 'undefined') {
11
+ hidden = 'hidden';
12
+ visibilityChange = 'visibilitychange';
13
+ }
14
+ else if (typeof document.msHidden !== 'undefined') {
15
+ hidden = 'msHidden';
16
+ visibilityChange = 'msvisibilitychange';
17
+ }
18
+ else if (typeof document.webkitHidden !== 'undefined') {
19
+ hidden = 'webkitHidden';
20
+ visibilityChange = 'webkitvisibilitychange';
21
+ }
22
+ }
23
+ getSupportedProperty();
24
+ function isPageHidden() {
25
+ if (typeof document === 'undefined')
26
+ return false;
27
+ if (typeof hidden === 'undefined')
28
+ return false;
29
+ return document[hidden];
30
+ }
31
+ function evokeByLocation(uri) {
32
+ if (window.top)
33
+ window.top.location.href = uri;
34
+ else
35
+ window.location.href = uri;
36
+ }
37
+ exports.evokeByLocation = evokeByLocation;
38
+ function evokeByTagA(uri) {
39
+ const tagA = document.createElement('a');
40
+ tagA.setAttribute('href', uri);
41
+ tagA.style.display = 'none';
42
+ document.body.appendChild(tagA);
43
+ tagA.click();
44
+ }
45
+ exports.evokeByTagA = evokeByTagA;
46
+ function evokeByIFrame(uri) {
47
+ if (!iframe) {
48
+ iframe = document.createElement('iframe');
49
+ iframe.style.cssText = 'display:none;border:0;width:0;height:0;';
50
+ document.body.appendChild(iframe);
51
+ }
52
+ iframe.src = uri;
53
+ }
54
+ exports.evokeByIFrame = evokeByIFrame;
55
+ function checkOpen(callback, timeout) {
56
+ const timer = setTimeout(() => {
57
+ const pageHidden = isPageHidden();
58
+ if (!pageHidden) {
59
+ callback('failure');
60
+ if (typeof visibilityChange !== 'undefined') {
61
+ document.removeEventListener(visibilityChange, visibilityListenHandler);
62
+ }
63
+ else {
64
+ window.removeEventListener('pagehide', visibilityListenHandler);
65
+ }
66
+ }
67
+ }, timeout);
68
+ const visibilityListenHandler = () => {
69
+ clearTimeout(timer);
70
+ callback('success');
71
+ };
72
+ if (typeof visibilityChange !== 'undefined') {
73
+ document.addEventListener(visibilityChange, visibilityListenHandler);
74
+ }
75
+ else {
76
+ window.addEventListener('pagehide', visibilityListenHandler);
77
+ }
78
+ }
79
+ exports.checkOpen = checkOpen;
@@ -0,0 +1,5 @@
1
+ import { EvokeAppConfig, EvokeAppOptions } from './types';
2
+ export declare function buildScheme(config: EvokeAppConfig, options: EvokeAppOptions): string;
3
+ export declare function generateScheme(config: EvokeAppConfig, options: EvokeAppOptions): string;
4
+ export declare function generateIntent(config: EvokeAppConfig, options: EvokeAppOptions): string;
5
+ export declare function generateUniversalLink(config: EvokeAppConfig, options: EvokeAppOptions): string;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateUniversalLink = exports.generateIntent = exports.generateScheme = exports.buildScheme = void 0;
4
+ const query_string_1 = require("query-string");
5
+ function buildScheme(config, options) {
6
+ const { path, param } = config;
7
+ const { scheme, buildScheme: customBuildScheme } = options;
8
+ if (typeof customBuildScheme !== 'undefined') {
9
+ return customBuildScheme(config, options);
10
+ }
11
+ const { domain, protocol } = scheme;
12
+ return (0, query_string_1.stringifyUrl)({
13
+ url: `${protocol}://${domain}/${path}`,
14
+ query: param,
15
+ }, { encode: true });
16
+ }
17
+ exports.buildScheme = buildScheme;
18
+ function generateScheme(config, options) {
19
+ const { outChain } = options;
20
+ let uri = buildScheme(config, options);
21
+ if (typeof outChain !== 'undefined' && outChain) {
22
+ const { protocol, path, key } = outChain;
23
+ uri = `${protocol}://${path}?${key}=${encodeURIComponent(uri)}`;
24
+ }
25
+ return uri;
26
+ }
27
+ exports.generateScheme = generateScheme;
28
+ function generateIntent(config, options) {
29
+ const { outChain } = options;
30
+ const { intent, fallback } = options;
31
+ if (typeof intent === 'undefined')
32
+ return '';
33
+ const keys = Object.keys(intent);
34
+ const intentParam = keys.map(key => `${key}=${intent[key]};`).join('');
35
+ const intentTail = `#Intent;${intentParam}S.browser_fallback_url=${encodeURIComponent(fallback || '')};end;`;
36
+ let urlPath = buildScheme(config, options);
37
+ if (typeof outChain !== 'undefined' && outChain) {
38
+ const { path, key } = outChain;
39
+ return `intent://${path}?${key}=${encodeURIComponent(urlPath)}${intentTail}`;
40
+ }
41
+ urlPath = urlPath.slice(urlPath.indexOf('//') + 2);
42
+ return `intent://${urlPath}${intentTail}`;
43
+ }
44
+ exports.generateIntent = generateIntent;
45
+ function generateUniversalLink(config, options) {
46
+ const { universal } = options;
47
+ if (typeof universal === 'undefined')
48
+ return '';
49
+ const { domain, pathKey } = universal;
50
+ const { path, param } = config;
51
+ const protocol = 'https';
52
+ const newUniversalLink = (0, query_string_1.stringifyUrl)({
53
+ url: `${protocol}://${domain}/${path}`,
54
+ query: param,
55
+ }, { encode: true });
56
+ const oldUniversalLink = (0, query_string_1.stringifyUrl)({
57
+ url: `${protocol}://${domain}/${path}`,
58
+ query: pathKey ? Object.assign({ [pathKey]: path }, param) : param,
59
+ }, { encode: true });
60
+ return pathKey ? oldUniversalLink : newUniversalLink;
61
+ }
62
+ exports.generateUniversalLink = generateUniversalLink;
@@ -0,0 +1,13 @@
1
+ import { EvokeAppConfig, EvokeAppOptions } from './types';
2
+ export declare class EvokeApp {
3
+ private readonly options;
4
+ constructor(options: EvokeAppOptions);
5
+ generateScheme(config: EvokeAppConfig): string;
6
+ generateIntent(config: EvokeAppConfig): string;
7
+ generateUniversalLink(config: EvokeAppConfig): string;
8
+ checkOpen(): Promise<unknown>;
9
+ fallToAppStore(): void;
10
+ fallToFbUrl(): void;
11
+ fallToCustomCb(callback: () => void): void;
12
+ open(config: EvokeAppConfig): void;
13
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.EvokeApp = void 0;
27
+ const Browser = __importStar(require("../browser"));
28
+ const evoke_1 = require("./evoke");
29
+ const generate = __importStar(require("./generate"));
30
+ class EvokeApp {
31
+ constructor(options) {
32
+ const defaultOptions = { timeout: 4000 };
33
+ this.options = Object.assign(defaultOptions, options);
34
+ }
35
+ generateScheme(config) {
36
+ return generate.generateScheme(config, this.options);
37
+ }
38
+ generateIntent(config) {
39
+ return generate.generateIntent(config, this.options);
40
+ }
41
+ generateUniversalLink(config) {
42
+ return generate.generateUniversalLink(config, this.options);
43
+ }
44
+ checkOpen() {
45
+ const { logFunc, timeout } = this.options;
46
+ return new Promise((resolve, reject) => {
47
+ (0, evoke_1.checkOpen)(status => {
48
+ logFunc === null || logFunc === void 0 ? void 0 : logFunc(status);
49
+ if (status === 'success')
50
+ return resolve(status);
51
+ reject(status);
52
+ }, timeout);
53
+ });
54
+ }
55
+ fallToAppStore() {
56
+ this.checkOpen().catch(() => (0, evoke_1.evokeByLocation)(this.options.appStore));
57
+ }
58
+ fallToFbUrl() {
59
+ this.checkOpen().catch(() => {
60
+ if (!this.options.fallback)
61
+ return;
62
+ (0, evoke_1.evokeByLocation)(this.options.fallback);
63
+ });
64
+ }
65
+ fallToCustomCb(callback) {
66
+ this.checkOpen().catch(callback);
67
+ }
68
+ open(config) {
69
+ const { universal, logFunc, intent } = this.options;
70
+ const { callback } = config;
71
+ const supportUniversal = typeof universal !== 'undefined';
72
+ const schemeURL = this.generateScheme(config);
73
+ let checkOpenFall;
74
+ if (typeof logFunc !== 'undefined') {
75
+ logFunc('pending');
76
+ }
77
+ if (Browser.isIos) {
78
+ if (Browser.getIOSVersion() < 9) {
79
+ (0, evoke_1.evokeByIFrame)(schemeURL);
80
+ checkOpenFall = this.fallToAppStore;
81
+ }
82
+ else if (!supportUniversal) {
83
+ (0, evoke_1.evokeByTagA)(schemeURL);
84
+ checkOpenFall = this.fallToAppStore;
85
+ }
86
+ else {
87
+ (0, evoke_1.evokeByLocation)(this.generateUniversalLink(config));
88
+ }
89
+ }
90
+ else if (Browser.isOriginalChrome) {
91
+ if (typeof intent !== 'undefined') {
92
+ (0, evoke_1.evokeByLocation)(this.generateIntent(config));
93
+ }
94
+ else {
95
+ (0, evoke_1.evokeByLocation)(schemeURL);
96
+ checkOpenFall = this.fallToFbUrl;
97
+ }
98
+ }
99
+ else {
100
+ (0, evoke_1.evokeByIFrame)(schemeURL);
101
+ checkOpenFall = this.fallToFbUrl;
102
+ }
103
+ if (typeof callback !== 'undefined') {
104
+ this.fallToCustomCb(callback);
105
+ return;
106
+ }
107
+ if (!checkOpenFall)
108
+ return;
109
+ checkOpenFall.call(this);
110
+ }
111
+ }
112
+ exports.EvokeApp = EvokeApp;
@@ -0,0 +1,37 @@
1
+ import { StringifiableRecord } from 'query-string';
2
+ export interface EvokeAppConfig<Params = StringifiableRecord> {
3
+ path: string;
4
+ param?: Params;
5
+ callback?: () => void;
6
+ }
7
+ export interface EvokeAppOptions {
8
+ scheme: {
9
+ protocol: string;
10
+ domain: string;
11
+ };
12
+ outChain?: {
13
+ protocol: string;
14
+ path: string;
15
+ key: string;
16
+ };
17
+ intent?: Intent;
18
+ universal?: {
19
+ domain: string;
20
+ pathKey?: string;
21
+ };
22
+ appStore: string;
23
+ fallback?: string;
24
+ timeout?: number;
25
+ logFunc?: (status: 'pending' | 'failure' | 'success') => void;
26
+ buildScheme?: (config: EvokeAppConfig, options: EvokeAppOptions) => string;
27
+ }
28
+ export interface Intent {
29
+ package: string;
30
+ scheme: string;
31
+ action?: string;
32
+ category?: string;
33
+ component?: string;
34
+ }
35
+ export type Hidden = 'hidden' | 'webkitHidden' | 'msHidden' | undefined;
36
+ export type VisibilityChange = 'visibilitychange' | 'webkitvisibilitychange' | 'msvisibilitychange' | undefined;
37
+ export type OpenStatus = 'failure' | 'success';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare const checkPortkeyExtension: () => Promise<boolean>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.checkPortkeyExtension = void 0;
13
+ const utils_1 = require("@portkey/utils");
14
+ const utils_2 = require("../utils");
15
+ const constants_1 = require("../constants");
16
+ const checkPortkeyExtension = () => __awaiter(void 0, void 0, void 0, function* () {
17
+ if (typeof window === 'undefined')
18
+ return false;
19
+ const _window = window;
20
+ if (_window.portkey)
21
+ return true;
22
+ yield (0, utils_1.sleep)(1000);
23
+ if (_window.portkey)
24
+ return true;
25
+ const browserName = (0, utils_2.detectBrowserName)();
26
+ const downloadURL = constants_1.EXTENSION_DOWNLOAD_URL[browserName] || constants_1.EXTENSION_DOWNLOAD_URL.DEFAULT;
27
+ _window.open(downloadURL, '_blank');
28
+ return false;
29
+ });
30
+ exports.checkPortkeyExtension = checkPortkeyExtension;
@@ -0,0 +1,16 @@
1
+ import { scheme as schemeUtils } from '@portkey/utils';
2
+ import { PartialOption } from '@portkey/types';
3
+ import { EvokeAppOptions } from '../evokeApp/types';
4
+ export interface IBaseEvokeAppOption {
5
+ timeout?: number;
6
+ customFailureCallback?: () => void;
7
+ onStatusChange?: EvokeAppOptions['logFunc'];
8
+ }
9
+ export type EvokePortkeyByLogin = PartialOption<Omit<schemeUtils.ILoginHandleSchemeParams, 'scheme'>, 'domain'> & IBaseEvokeAppOption;
10
+ type EvokePortkeyByLinkDapp = PartialOption<Omit<schemeUtils.ILinkDappHandleSchemeParams, 'scheme'>, 'domain'> & IBaseEvokeAppOption;
11
+ export interface IEvokePortkeyApp {
12
+ evokePortkeyApp(params: EvokePortkeyByLogin): void;
13
+ evokePortkeyApp(params: EvokePortkeyByLinkDapp): void;
14
+ }
15
+ export declare const evokePortkeyApp: IEvokePortkeyApp['evokePortkeyApp'];
16
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evokePortkeyApp = void 0;
4
+ const utils_1 = require("@portkey/utils");
5
+ const evokeApp_1 = require("../evokeApp");
6
+ const constants_1 = require("../constants");
7
+ const evokePortkeyApp = ({ domain, custom, action, timeout = 4000, customFailureCallback, onStatusChange, }) => {
8
+ const callLib = new evokeApp_1.EvokeApp({
9
+ scheme: {
10
+ protocol: utils_1.scheme.DID_APP_SCHEMA,
11
+ domain: domain || window.location.host,
12
+ },
13
+ timeout,
14
+ appStore: constants_1.APP_DOWNLOAD_URL.APP_STORE,
15
+ fallback: constants_1.APP_DOWNLOAD_URL.CHROME_STORE,
16
+ logFunc: onStatusChange,
17
+ buildScheme: (config, options) => {
18
+ return utils_1.scheme.formatScheme({
19
+ scheme: utils_1.scheme.DID_APP_SCHEMA,
20
+ action: action,
21
+ domain: options.scheme.domain,
22
+ custom: config.param,
23
+ });
24
+ },
25
+ });
26
+ callLib.open({
27
+ path: action,
28
+ param: custom,
29
+ callback: customFailureCallback,
30
+ });
31
+ };
32
+ exports.evokePortkeyApp = evokePortkeyApp;
@@ -0,0 +1,2 @@
1
+ export * from './evokePortkeyApp';
2
+ export * from './checkPortkeyExtension';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./evokePortkeyApp"), exports);
18
+ __exportStar(require("./checkPortkeyExtension"), exports);
@@ -0,0 +1,3 @@
1
+ export * from './evokeApp';
2
+ export * as Browser from './browser';
3
+ export * from './evokePortkey';
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Browser = void 0;
30
+ __exportStar(require("./evokeApp"), exports);
31
+ exports.Browser = __importStar(require("./browser"));
32
+ __exportStar(require("./evokePortkey"), exports);
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}
@@ -0,0 +1 @@
1
+ export declare const detectBrowserName: () => string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.detectBrowserName = void 0;
7
+ const bowser_1 = __importDefault(require("bowser"));
8
+ const detectBrowserName = () => {
9
+ if (typeof navigator === 'undefined')
10
+ return '';
11
+ const browserInfo = bowser_1.default.parse(window.navigator.userAgent);
12
+ if (browserInfo.browser.name === 'Firefox') {
13
+ return 'FIREFOX';
14
+ }
15
+ else if (['Chrome', 'Chromium'].includes(browserInfo.browser.name || '')) {
16
+ return 'CHROME';
17
+ }
18
+ else if (browserInfo.browser.name === 'Microsoft Edge') {
19
+ return 'EDGE';
20
+ }
21
+ return browserInfo.browser.name || '';
22
+ };
23
+ exports.detectBrowserName = detectBrowserName;
@@ -0,0 +1,5 @@
1
+ export declare const semverCompare: (verionA: string, versionB: string) => -1 | 0 | 1;
2
+ export declare const getIOSVersion: () => number;
3
+ export declare const isAndroid: boolean;
4
+ export declare const isIos: boolean;
5
+ export declare const isOriginalChrome: boolean;
@@ -0,0 +1,31 @@
1
+ const ua = typeof navigator !== 'undefined' ? navigator.userAgent : '';
2
+ export const semverCompare = (verionA, versionB) => {
3
+ const { isNaN } = window;
4
+ const splitA = verionA.split('.');
5
+ const splitB = versionB.split('.');
6
+ for (let i = 0; i < 3; i++) {
7
+ const snippetA = Number(splitA[i]);
8
+ const snippetB = Number(splitB[i]);
9
+ if (snippetA > snippetB)
10
+ return 1;
11
+ if (snippetB > snippetA)
12
+ return -1;
13
+ if (!isNaN(snippetA) && isNaN(snippetB))
14
+ return 1;
15
+ if (isNaN(snippetA) && !isNaN(snippetB))
16
+ return -1;
17
+ }
18
+ return 0;
19
+ };
20
+ export const getIOSVersion = () => {
21
+ var _a;
22
+ const version = (_a = ua
23
+ .toLocaleLowerCase()
24
+ .match(/cpu iphone os (.*?) like mac os/)) === null || _a === void 0 ? void 0 : _a[1].split('_');
25
+ if (!version)
26
+ return -1;
27
+ return Number.parseInt(version[0], 10);
28
+ };
29
+ export const isAndroid = /android/i.test(ua);
30
+ export const isIos = /iphone|ipad|ipod/i.test(ua);
31
+ export const isOriginalChrome = /chrome\/[\d.]+ mobile safari\/[\d.]+/i.test(ua) && isAndroid && ua.indexOf('Version') < 0;
@@ -0,0 +1,9 @@
1
+ export declare const APP_DOWNLOAD_URL: {
2
+ APP_STORE: string;
3
+ CHROME_STORE: string;
4
+ };
5
+ export declare const EXTENSION_DOWNLOAD_URL: {
6
+ CHROME: string;
7
+ EDGE: string;
8
+ DEFAULT: string;
9
+ };