@portkey/onboarding 0.0.2-alpha.2

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 (83) 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 +37 -0
  5. package/dist/commonjs/constants/index.d.ts +10 -0
  6. package/dist/commonjs/constants/index.js +15 -0
  7. package/dist/commonjs/evokeApp/evoke.d.ts +22 -0
  8. package/dist/commonjs/evokeApp/evoke.js +101 -0
  9. package/dist/commonjs/evokeApp/generate.d.ts +5 -0
  10. package/dist/commonjs/evokeApp/generate.js +66 -0
  11. package/dist/commonjs/evokeApp/index.d.ts +21 -0
  12. package/dist/commonjs/evokeApp/index.js +129 -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 +3 -0
  16. package/dist/commonjs/evokePortkey/checkPortkeyExtension.js +44 -0
  17. package/dist/commonjs/evokePortkey/evokeByThirdParty.d.ts +16 -0
  18. package/dist/commonjs/evokePortkey/evokeByThirdParty.js +6 -0
  19. package/dist/commonjs/evokePortkey/evokePortkeyApp.d.ts +3 -0
  20. package/dist/commonjs/evokePortkey/evokePortkeyApp.js +31 -0
  21. package/dist/commonjs/evokePortkey/index.d.ts +24 -0
  22. package/dist/commonjs/evokePortkey/index.js +25 -0
  23. package/dist/commonjs/evokePortkey/types.d.ts +21 -0
  24. package/dist/commonjs/evokePortkey/types.js +2 -0
  25. package/dist/commonjs/index.d.ts +4 -0
  26. package/dist/commonjs/index.js +33 -0
  27. package/dist/commonjs/package.json +1 -0
  28. package/dist/commonjs/utils/index.d.ts +1 -0
  29. package/dist/commonjs/utils/index.js +23 -0
  30. package/dist/esm/browser.d.ts +5 -0
  31. package/dist/esm/browser.js +32 -0
  32. package/dist/esm/constants/index.d.ts +10 -0
  33. package/dist/esm/constants/index.js +12 -0
  34. package/dist/esm/evokeApp/evoke.d.ts +22 -0
  35. package/dist/esm/evokeApp/evoke.js +94 -0
  36. package/dist/esm/evokeApp/generate.d.ts +5 -0
  37. package/dist/esm/evokeApp/generate.js +59 -0
  38. package/dist/esm/evokeApp/index.d.ts +21 -0
  39. package/dist/esm/evokeApp/index.js +102 -0
  40. package/dist/esm/evokeApp/types.d.ts +37 -0
  41. package/dist/esm/evokeApp/types.js +1 -0
  42. package/dist/esm/evokePortkey/checkPortkeyExtension.d.ts +3 -0
  43. package/dist/esm/evokePortkey/checkPortkeyExtension.js +39 -0
  44. package/dist/esm/evokePortkey/evokeByThirdParty.d.ts +16 -0
  45. package/dist/esm/evokePortkey/evokeByThirdParty.js +4 -0
  46. package/dist/esm/evokePortkey/evokePortkeyApp.d.ts +3 -0
  47. package/dist/esm/evokePortkey/evokePortkeyApp.js +29 -0
  48. package/dist/esm/evokePortkey/index.d.ts +24 -0
  49. package/dist/esm/evokePortkey/index.js +5 -0
  50. package/dist/esm/evokePortkey/types.d.ts +21 -0
  51. package/dist/esm/evokePortkey/types.js +1 -0
  52. package/dist/esm/index.d.ts +4 -0
  53. package/dist/esm/index.js +4 -0
  54. package/dist/esm/package.json +1 -0
  55. package/dist/esm/utils/index.d.ts +1 -0
  56. package/dist/esm/utils/index.js +16 -0
  57. package/dist/types/browser.d.ts +6 -0
  58. package/dist/types/browser.d.ts.map +1 -0
  59. package/dist/types/constants/index.d.ts +11 -0
  60. package/dist/types/constants/index.d.ts.map +1 -0
  61. package/dist/types/evokeApp/evoke.d.ts +23 -0
  62. package/dist/types/evokeApp/evoke.d.ts.map +1 -0
  63. package/dist/types/evokeApp/generate.d.ts +6 -0
  64. package/dist/types/evokeApp/generate.d.ts.map +1 -0
  65. package/dist/types/evokeApp/index.d.ts +22 -0
  66. package/dist/types/evokeApp/index.d.ts.map +1 -0
  67. package/dist/types/evokeApp/types.d.ts +38 -0
  68. package/dist/types/evokeApp/types.d.ts.map +1 -0
  69. package/dist/types/evokePortkey/checkPortkeyExtension.d.ts +4 -0
  70. package/dist/types/evokePortkey/checkPortkeyExtension.d.ts.map +1 -0
  71. package/dist/types/evokePortkey/evokeByThirdParty.d.ts +17 -0
  72. package/dist/types/evokePortkey/evokeByThirdParty.d.ts.map +1 -0
  73. package/dist/types/evokePortkey/evokePortkeyApp.d.ts +4 -0
  74. package/dist/types/evokePortkey/evokePortkeyApp.d.ts.map +1 -0
  75. package/dist/types/evokePortkey/index.d.ts +25 -0
  76. package/dist/types/evokePortkey/index.d.ts.map +1 -0
  77. package/dist/types/evokePortkey/types.d.ts +22 -0
  78. package/dist/types/evokePortkey/types.d.ts.map +1 -0
  79. package/dist/types/index.d.ts +5 -0
  80. package/dist/types/index.d.ts.map +1 -0
  81. package/dist/types/utils/index.d.ts +2 -0
  82. package/dist/types/utils/index.d.ts.map +1 -0
  83. package/package.json +52 -0
@@ -0,0 +1,21 @@
1
+ import { PartialOption } from '@portkey/types';
2
+ import { EvokeAppOptions } from '../evokeApp/types';
3
+ import { scheme as schemeUtils } from '@portkey/utils';
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
+ export type EvokePortkeyByLinkDapp = PartialOption<Omit<schemeUtils.ILinkDappHandleSchemeParams, 'scheme'>, 'domain'> & IBaseEvokeAppOption;
11
+ export type EvokePortkeyByAddContact = PartialOption<Omit<schemeUtils.IAddContactHandleSchemeParams, 'scheme'>, 'domain'> & IBaseEvokeAppOption;
12
+ export type EvokePortkeyByAddGroup = PartialOption<Omit<schemeUtils.IAddGroupHandleSchemeParams, 'scheme'>, 'domain'> & IBaseEvokeAppOption;
13
+ export interface IEvokePortkeyApp {
14
+ evokePortkeyApp(params: EvokePortkeyByLogin): void;
15
+ evokePortkeyApp(params: EvokePortkeyByLinkDapp): void;
16
+ evokePortkeyApp(params: EvokePortkeyByAddContact): void;
17
+ evokePortkeyApp(params: EvokePortkeyByAddGroup): void;
18
+ }
19
+ export interface IEvokeExtensionProps {
20
+ openTarget?: '_self' | '_blank';
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from './evokeApp';
2
+ export * as Browser from './browser';
3
+ export * from './evokePortkey';
4
+ export * from './utils';
@@ -0,0 +1,33 @@
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);
33
+ __exportStar(require("./utils"), 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,32 @@
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
+ // e.g. '1.0.0-rc' -- Number('0-rc') = NaN
14
+ if (!isNaN(snippetA) && isNaN(snippetB))
15
+ return 1;
16
+ if (isNaN(snippetA) && !isNaN(snippetB))
17
+ return -1;
18
+ }
19
+ return 0;
20
+ };
21
+ export const getIOSVersion = () => {
22
+ var _a;
23
+ const version = (_a = ua
24
+ .toLocaleLowerCase()
25
+ .match(/cpu iphone os (.*?) like mac os/)) === null || _a === void 0 ? void 0 : _a[1].split('_');
26
+ if (!version)
27
+ return -1;
28
+ return Number.parseInt(version[0], 10);
29
+ };
30
+ export const isAndroid = /android/i.test(ua);
31
+ export const isIos = /iphone|ipad|ipod/i.test(ua);
32
+ export const isOriginalChrome = /chrome\/[\d.]+ mobile safari\/[\d.]+/i.test(ua) && isAndroid && ua.indexOf('Version') < 0;
@@ -0,0 +1,10 @@
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
+ };
10
+ export declare const WEB_PAGE = "https://openlogin.portkey.finance";
@@ -0,0 +1,12 @@
1
+ export const APP_DOWNLOAD_URL = {
2
+ APP_STORE: 'https://apps.apple.com/us/app/portkey-ca-wallet-crypto-nft/id6445808228',
3
+ CHROME_STORE: 'https://play.google.com/store/apps/details?id=com.portkey.did',
4
+ };
5
+ export const EXTENSION_DOWNLOAD_URL = {
6
+ CHROME: 'https://chrome.google.com/webstore/detail/portkey-did-crypto-nft/hpjiiechbbhefmpggegmahejiiphbmij',
7
+ EDGE: 'https://chrome.google.com/webstore/detail/portkey-did-crypto-nft/hpjiiechbbhefmpggegmahejiiphbmij',
8
+ DEFAULT: 'https://portkey.finance/download',
9
+ };
10
+ export const WEB_PAGE = 'https://openlogin.portkey.finance';
11
+ // export const WEB_PAGE = 'https://openlogin-test.portkey.finance';
12
+ // export const WEB_PAGE = 'http://192.168.11.245:3000';
@@ -0,0 +1,22 @@
1
+ import { OpenStatus } from './types.js';
2
+ /**
3
+ * Jump via top.location.href
4
+ * @param {string} [uri] - open
5
+ */
6
+ export declare function evokeByLocation(uri: string): void;
7
+ /**
8
+ * Evoked by the A tag
9
+ * @param {string} uri - open url
10
+ */
11
+ export declare function evokeByTagA(uri: string): void;
12
+ /**
13
+ * Evoked by iframe
14
+ * @param {string} [uri] - open url
15
+ */
16
+ export declare function evokeByIFrame(uri: string): void;
17
+ /**
18
+ * Check whether the calling end is successful
19
+ * @param cb - Callback failure callback function
20
+ * @param timeout
21
+ */
22
+ export declare function checkOpen(callback: (status: OpenStatus) => void, timeout: number): void;
@@ -0,0 +1,94 @@
1
+ let hidden = 'hidden';
2
+ let visibilityChange = 'visibilitychange';
3
+ let iframe;
4
+ function getSupportedProperty() {
5
+ if (typeof document === 'undefined')
6
+ return;
7
+ if (typeof document.hidden !== 'undefined') {
8
+ // Opera 12.10 and Firefox 18 and later support
9
+ hidden = 'hidden';
10
+ visibilityChange = 'visibilitychange';
11
+ }
12
+ else if (typeof document.msHidden !== 'undefined') {
13
+ hidden = 'msHidden';
14
+ visibilityChange = 'msvisibilitychange';
15
+ }
16
+ else if (typeof document.webkitHidden !== 'undefined') {
17
+ hidden = 'webkitHidden';
18
+ visibilityChange = 'webkitvisibilitychange';
19
+ }
20
+ }
21
+ getSupportedProperty();
22
+ /**
23
+ * Determine whether the page is hidden (enter the background)
24
+ */
25
+ function isPageHidden() {
26
+ if (typeof document === 'undefined')
27
+ return false;
28
+ if (typeof hidden === 'undefined')
29
+ return false;
30
+ return document[hidden];
31
+ }
32
+ /**
33
+ * Jump via top.location.href
34
+ * @param {string} [uri] - open
35
+ */
36
+ export function evokeByLocation(uri) {
37
+ // if (typeof window === 'undefined') return;
38
+ if (window.top)
39
+ window.top.location.href = uri;
40
+ else
41
+ window.location.href = uri;
42
+ }
43
+ /**
44
+ * Evoked by the A tag
45
+ * @param {string} uri - open url
46
+ */
47
+ export function evokeByTagA(uri) {
48
+ const tagA = document.createElement('a');
49
+ tagA.setAttribute('href', uri);
50
+ tagA.style.display = 'none';
51
+ document.body.appendChild(tagA);
52
+ tagA.click();
53
+ }
54
+ /**
55
+ * Evoked by iframe
56
+ * @param {string} [uri] - open url
57
+ */
58
+ export function evokeByIFrame(uri) {
59
+ if (!iframe) {
60
+ iframe = document.createElement('iframe');
61
+ iframe.style.cssText = 'display:none;border:0;width:0;height:0;';
62
+ document.body.appendChild(iframe);
63
+ }
64
+ iframe.src = uri;
65
+ }
66
+ /**
67
+ * Check whether the calling end is successful
68
+ * @param cb - Callback failure callback function
69
+ * @param timeout
70
+ */
71
+ export function checkOpen(callback, timeout) {
72
+ const timer = setTimeout(() => {
73
+ const pageHidden = isPageHidden();
74
+ if (!pageHidden) {
75
+ callback('failure');
76
+ if (typeof visibilityChange !== 'undefined') {
77
+ document.removeEventListener(visibilityChange, visibilityListenHandler);
78
+ }
79
+ else {
80
+ window.removeEventListener('pagehide', visibilityListenHandler);
81
+ }
82
+ }
83
+ }, timeout);
84
+ const visibilityListenHandler = () => {
85
+ clearTimeout(timer);
86
+ callback('success');
87
+ };
88
+ if (typeof visibilityChange !== 'undefined') {
89
+ document.addEventListener(visibilityChange, visibilityListenHandler);
90
+ }
91
+ else {
92
+ window.addEventListener('pagehide', visibilityListenHandler);
93
+ }
94
+ }
@@ -0,0 +1,5 @@
1
+ import { EvokeAppConfig, EvokeAppOptions } from './types.js';
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,59 @@
1
+ import { stringifyUrl } from 'query-string';
2
+ // Generate basic url scheme
3
+ export function buildScheme(config, options) {
4
+ const { path, param } = config;
5
+ const { scheme, buildScheme: customBuildScheme } = options;
6
+ if (typeof customBuildScheme !== 'undefined') {
7
+ return customBuildScheme(config, options);
8
+ }
9
+ const { domain, protocol } = scheme;
10
+ return stringifyUrl({
11
+ url: `${protocol}://${domain}/${path}`,
12
+ query: param,
13
+ }, { encode: true });
14
+ }
15
+ // Generate the url scheme required by the business (distinguish whether it is an external link)
16
+ export function generateScheme(config, options) {
17
+ const { outChain } = options;
18
+ let uri = buildScheme(config, options);
19
+ if (typeof outChain !== 'undefined' && outChain) {
20
+ const { protocol, path, key } = outChain;
21
+ uri = `${protocol}://${path}?${key}=${encodeURIComponent(uri)}`;
22
+ }
23
+ return uri;
24
+ }
25
+ // generate android intent
26
+ export function generateIntent(config, options) {
27
+ const { outChain } = options;
28
+ const { intent, fallback } = options;
29
+ if (typeof intent === 'undefined')
30
+ return '';
31
+ const keys = Object.keys(intent);
32
+ const intentParam = keys.map(key => `${key}=${intent[key]};`).join('');
33
+ const intentTail = `#Intent;${intentParam}S.browser_fallback_url=${encodeURIComponent(fallback || '')};end;`;
34
+ let urlPath = buildScheme(config, options);
35
+ if (typeof outChain !== 'undefined' && outChain) {
36
+ const { path, key } = outChain;
37
+ return `intent://${path}?${key}=${encodeURIComponent(urlPath)}${intentTail}`;
38
+ }
39
+ urlPath = urlPath.slice(urlPath.indexOf('//') + 2);
40
+ return `intent://${urlPath}${intentTail}`;
41
+ }
42
+ // generate universalLink
43
+ export function generateUniversalLink(config, options) {
44
+ const { universal } = options;
45
+ if (typeof universal === 'undefined')
46
+ return '';
47
+ const { domain, pathKey } = universal;
48
+ const { path, param } = config;
49
+ const protocol = 'https';
50
+ const newUniversalLink = stringifyUrl({
51
+ url: `${protocol}://${domain}/${path}`,
52
+ query: param,
53
+ }, { encode: true });
54
+ const oldUniversalLink = stringifyUrl({
55
+ url: `${protocol}://${domain}/${path}`,
56
+ query: pathKey ? Object.assign({ [pathKey]: path }, param) : param,
57
+ }, { encode: true });
58
+ return pathKey ? oldUniversalLink : newUniversalLink;
59
+ }
@@ -0,0 +1,21 @@
1
+ import { EvokeAppConfig, EvokeAppOptions } from './types.js';
2
+ export declare class EvokeApp {
3
+ private readonly options;
4
+ constructor(options: EvokeAppOptions);
5
+ /**
6
+ * register as method
7
+ * generateScheme | generateIntent | generateUniversalLink | checkOpen
8
+ */
9
+ generateScheme(config: EvokeAppConfig): string;
10
+ generateIntent(config: EvokeAppConfig): string;
11
+ generateUniversalLink(config: EvokeAppConfig): string;
12
+ checkOpen(): Promise<unknown>;
13
+ fallToAppStore(): void;
14
+ fallToFbUrl(): void;
15
+ fallToCustomCb(callback: () => void): void;
16
+ /**
17
+ * Evoke the client
18
+ * Execute different call-out strategies according to different browsers
19
+ */
20
+ open(config: EvokeAppConfig): void;
21
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @remakes https://github.com/suanmei/callapp-lib
3
+ */
4
+ import * as Browser from '../browser.js';
5
+ import { evokeByLocation, evokeByIFrame, checkOpen, evokeByTagA } from './evoke.js';
6
+ import * as generate from './generate.js';
7
+ export class EvokeApp {
8
+ // Create an instance of EvokeApp
9
+ constructor(options) {
10
+ const defaultOptions = { timeout: 4000 };
11
+ this.options = Object.assign(defaultOptions, options);
12
+ }
13
+ /**
14
+ * register as method
15
+ * generateScheme | generateIntent | generateUniversalLink | checkOpen
16
+ */
17
+ generateScheme(config) {
18
+ return generate.generateScheme(config, this.options);
19
+ }
20
+ generateIntent(config) {
21
+ return generate.generateIntent(config, this.options);
22
+ }
23
+ generateUniversalLink(config) {
24
+ return generate.generateUniversalLink(config, this.options);
25
+ }
26
+ checkOpen() {
27
+ const { logFunc, timeout } = this.options;
28
+ return new Promise((resolve, reject) => {
29
+ checkOpen(status => {
30
+ logFunc === null || logFunc === void 0 ? void 0 : logFunc(status);
31
+ if (status === 'success')
32
+ return resolve(status);
33
+ reject(status);
34
+ }, timeout);
35
+ });
36
+ }
37
+ // Call terminal failure jump app store
38
+ fallToAppStore() {
39
+ this.checkOpen().catch(() => evokeByLocation(this.options.appStore));
40
+ }
41
+ // Redirect to the general (download) page if the terminal call fails
42
+ fallToFbUrl() {
43
+ this.checkOpen().catch(() => {
44
+ if (!this.options.fallback)
45
+ return;
46
+ evokeByLocation(this.options.fallback);
47
+ });
48
+ }
49
+ // Failed to call the terminal to call the custom callback function
50
+ fallToCustomCb(callback) {
51
+ this.checkOpen().catch(callback);
52
+ }
53
+ /**
54
+ * Evoke the client
55
+ * Execute different call-out strategies according to different browsers
56
+ */
57
+ open(config) {
58
+ const { universal, logFunc, intent } = this.options;
59
+ const { callback } = config;
60
+ const supportUniversal = typeof universal !== 'undefined';
61
+ const schemeURL = this.generateScheme(config);
62
+ let checkOpenFall;
63
+ if (typeof logFunc !== 'undefined') {
64
+ logFunc('pending');
65
+ }
66
+ if (Browser.isIos) {
67
+ if (Browser.getIOSVersion() < 9) {
68
+ evokeByIFrame(schemeURL);
69
+ checkOpenFall = this.fallToAppStore;
70
+ }
71
+ else if (!supportUniversal) {
72
+ evokeByTagA(schemeURL);
73
+ checkOpenFall = this.fallToAppStore;
74
+ }
75
+ else {
76
+ evokeByLocation(this.generateUniversalLink(config));
77
+ }
78
+ // Android
79
+ }
80
+ else if (Browser.isOriginalChrome) {
81
+ if (typeof intent !== 'undefined') {
82
+ evokeByLocation(this.generateIntent(config));
83
+ }
84
+ else {
85
+ // The scheme cannot pull up the iframe normally on the android chrome25+ version
86
+ evokeByLocation(schemeURL);
87
+ checkOpenFall = this.fallToFbUrl;
88
+ }
89
+ }
90
+ else {
91
+ evokeByIFrame(schemeURL);
92
+ checkOpenFall = this.fallToFbUrl;
93
+ }
94
+ if (typeof callback !== 'undefined') {
95
+ this.fallToCustomCb(callback);
96
+ return;
97
+ }
98
+ if (!checkOpenFall)
99
+ return;
100
+ checkOpenFall.call(this);
101
+ }
102
+ }
@@ -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 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { IEvokeExtensionProps } from './types.js';
2
+ declare const checkPortkeyExtension: (params?: IEvokeExtensionProps) => Promise<boolean>;
3
+ export default checkPortkeyExtension;
@@ -0,0 +1,39 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { detectBrowserName } from '../utils/index.js';
11
+ import { EXTENSION_DOWNLOAD_URL } from '../constants/index.js';
12
+ import detectProvider from '@portkey/detect-provider';
13
+ /**
14
+ * This method is used to check if the provided object is a Portkey provider.
15
+ */
16
+ function isPortkeyProvider() {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ const provider = yield detectProvider();
20
+ return !!provider;
21
+ }
22
+ catch (error) {
23
+ return false;
24
+ }
25
+ });
26
+ }
27
+ const checkPortkeyExtension = (params) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const openTarget = params === null || params === void 0 ? void 0 : params.openTarget;
29
+ if (typeof window === 'undefined')
30
+ return false;
31
+ const _window = window;
32
+ if (yield isPortkeyProvider())
33
+ return true;
34
+ const browserName = detectBrowserName();
35
+ const downloadURL = EXTENSION_DOWNLOAD_URL[browserName] || EXTENSION_DOWNLOAD_URL.DEFAULT;
36
+ _window.open(downloadURL, openTarget);
37
+ return false;
38
+ });
39
+ export default checkPortkeyExtension;
@@ -0,0 +1,16 @@
1
+ import { scheme } from '@portkey/utils';
2
+ type IBaseOption = {
3
+ timeout?: number;
4
+ };
5
+ interface IEvokeByThirdParty {
6
+ evokeByThirdParty(params?: {
7
+ action: 'login';
8
+ custom: scheme.ILoginHandleSchemeParams['custom'];
9
+ } & IBaseOption): Promise<any>;
10
+ evokeByThirdParty(params?: {
11
+ action: 'linkDapp';
12
+ custom: scheme.ILinkDappHandleSchemeParams['custom'];
13
+ } & IBaseOption): Promise<any>;
14
+ }
15
+ declare const evokeByThirdParty: IEvokeByThirdParty['evokeByThirdParty'];
16
+ export default evokeByThirdParty;
@@ -0,0 +1,4 @@
1
+ import { stringify } from 'query-string';
2
+ import { WEB_PAGE } from '../constants/index.js';
3
+ const evokeByThirdParty = params => Promise.resolve(window.open(`${WEB_PAGE}/portkey-download?${stringify(params)}`));
4
+ export default evokeByThirdParty;
@@ -0,0 +1,3 @@
1
+ import { IEvokePortkeyApp } from './types.js';
2
+ declare const evokePortkeyApp: IEvokePortkeyApp['evokePortkeyApp'];
3
+ export default evokePortkeyApp;
@@ -0,0 +1,29 @@
1
+ import { scheme as schemeUtils } from '@portkey/utils';
2
+ import { EvokeApp } from '../evokeApp/index.js';
3
+ import { APP_DOWNLOAD_URL } from '../constants/index.js';
4
+ const evokePortkeyApp = ({ domain, custom, action, timeout = 4000, customFailureCallback, onStatusChange, }) => {
5
+ const callLib = new EvokeApp({
6
+ scheme: {
7
+ protocol: schemeUtils.DID_APP_SCHEMA,
8
+ domain: domain || (window === null || window === void 0 ? void 0 : window.location.host),
9
+ },
10
+ timeout,
11
+ appStore: APP_DOWNLOAD_URL.APP_STORE,
12
+ fallback: APP_DOWNLOAD_URL.CHROME_STORE,
13
+ logFunc: onStatusChange,
14
+ buildScheme: (config, options) => {
15
+ return schemeUtils.formatScheme({
16
+ scheme: schemeUtils.DID_APP_SCHEMA,
17
+ action: action,
18
+ domain: options.scheme.domain,
19
+ custom: config.param,
20
+ });
21
+ },
22
+ });
23
+ callLib.open({
24
+ path: action,
25
+ param: custom,
26
+ callback: customFailureCallback,
27
+ });
28
+ };
29
+ export default evokePortkeyApp;
@@ -0,0 +1,24 @@
1
+ export * from './types.js';
2
+ export declare const evokePortkey: {
3
+ app: {
4
+ (params: import("./types").EvokePortkeyByLogin): void;
5
+ (params: import("./types").EvokePortkeyByLinkDapp): void;
6
+ (params: import("./types").EvokePortkeyByAddContact): void;
7
+ (params: import("./types").EvokePortkeyByAddGroup): void;
8
+ };
9
+ extension: (params?: import("./types").IEvokeExtensionProps | undefined) => Promise<boolean>;
10
+ thirdParty: {
11
+ (params?: ({
12
+ action: "login";
13
+ custom: any;
14
+ } & {
15
+ timeout?: number | undefined;
16
+ }) | undefined): Promise<any>;
17
+ (params?: ({
18
+ action: "linkDapp";
19
+ custom: import("@portkey/utils/dist/commonjs/scheme").LinkDappData;
20
+ } & {
21
+ timeout?: number | undefined;
22
+ }) | undefined): Promise<any>;
23
+ };
24
+ };
@@ -0,0 +1,5 @@
1
+ import app from './evokePortkeyApp.js';
2
+ import extension from './checkPortkeyExtension.js';
3
+ import thirdParty from './evokeByThirdParty.js';
4
+ export * from './types.js';
5
+ export const evokePortkey = { app, extension, thirdParty };