@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.
- package/LICENSE +674 -0
- package/README.md +39 -0
- package/dist/commonjs/browser.d.ts +5 -0
- package/dist/commonjs/browser.js +37 -0
- package/dist/commonjs/constants/index.d.ts +10 -0
- package/dist/commonjs/constants/index.js +15 -0
- package/dist/commonjs/evokeApp/evoke.d.ts +22 -0
- package/dist/commonjs/evokeApp/evoke.js +101 -0
- package/dist/commonjs/evokeApp/generate.d.ts +5 -0
- package/dist/commonjs/evokeApp/generate.js +66 -0
- package/dist/commonjs/evokeApp/index.d.ts +21 -0
- package/dist/commonjs/evokeApp/index.js +129 -0
- package/dist/commonjs/evokeApp/types.d.ts +37 -0
- package/dist/commonjs/evokeApp/types.js +2 -0
- package/dist/commonjs/evokePortkey/checkPortkeyExtension.d.ts +3 -0
- package/dist/commonjs/evokePortkey/checkPortkeyExtension.js +44 -0
- package/dist/commonjs/evokePortkey/evokeByThirdParty.d.ts +16 -0
- package/dist/commonjs/evokePortkey/evokeByThirdParty.js +6 -0
- package/dist/commonjs/evokePortkey/evokePortkeyApp.d.ts +3 -0
- package/dist/commonjs/evokePortkey/evokePortkeyApp.js +31 -0
- package/dist/commonjs/evokePortkey/index.d.ts +24 -0
- package/dist/commonjs/evokePortkey/index.js +25 -0
- package/dist/commonjs/evokePortkey/types.d.ts +21 -0
- package/dist/commonjs/evokePortkey/types.js +2 -0
- package/dist/commonjs/index.d.ts +4 -0
- package/dist/commonjs/index.js +33 -0
- package/dist/commonjs/package.json +1 -0
- package/dist/commonjs/utils/index.d.ts +1 -0
- package/dist/commonjs/utils/index.js +23 -0
- package/dist/esm/browser.d.ts +5 -0
- package/dist/esm/browser.js +32 -0
- package/dist/esm/constants/index.d.ts +10 -0
- package/dist/esm/constants/index.js +12 -0
- package/dist/esm/evokeApp/evoke.d.ts +22 -0
- package/dist/esm/evokeApp/evoke.js +94 -0
- package/dist/esm/evokeApp/generate.d.ts +5 -0
- package/dist/esm/evokeApp/generate.js +59 -0
- package/dist/esm/evokeApp/index.d.ts +21 -0
- package/dist/esm/evokeApp/index.js +102 -0
- package/dist/esm/evokeApp/types.d.ts +37 -0
- package/dist/esm/evokeApp/types.js +1 -0
- package/dist/esm/evokePortkey/checkPortkeyExtension.d.ts +3 -0
- package/dist/esm/evokePortkey/checkPortkeyExtension.js +39 -0
- package/dist/esm/evokePortkey/evokeByThirdParty.d.ts +16 -0
- package/dist/esm/evokePortkey/evokeByThirdParty.js +4 -0
- package/dist/esm/evokePortkey/evokePortkeyApp.d.ts +3 -0
- package/dist/esm/evokePortkey/evokePortkeyApp.js +29 -0
- package/dist/esm/evokePortkey/index.d.ts +24 -0
- package/dist/esm/evokePortkey/index.js +5 -0
- package/dist/esm/evokePortkey/types.d.ts +21 -0
- package/dist/esm/evokePortkey/types.js +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +16 -0
- package/dist/types/browser.d.ts +6 -0
- package/dist/types/browser.d.ts.map +1 -0
- package/dist/types/constants/index.d.ts +11 -0
- package/dist/types/constants/index.d.ts.map +1 -0
- package/dist/types/evokeApp/evoke.d.ts +23 -0
- package/dist/types/evokeApp/evoke.d.ts.map +1 -0
- package/dist/types/evokeApp/generate.d.ts +6 -0
- package/dist/types/evokeApp/generate.d.ts.map +1 -0
- package/dist/types/evokeApp/index.d.ts +22 -0
- package/dist/types/evokeApp/index.d.ts.map +1 -0
- package/dist/types/evokeApp/types.d.ts +38 -0
- package/dist/types/evokeApp/types.d.ts.map +1 -0
- package/dist/types/evokePortkey/checkPortkeyExtension.d.ts +4 -0
- package/dist/types/evokePortkey/checkPortkeyExtension.d.ts.map +1 -0
- package/dist/types/evokePortkey/evokeByThirdParty.d.ts +17 -0
- package/dist/types/evokePortkey/evokeByThirdParty.d.ts.map +1 -0
- package/dist/types/evokePortkey/evokePortkeyApp.d.ts +4 -0
- package/dist/types/evokePortkey/evokePortkeyApp.d.ts.map +1 -0
- package/dist/types/evokePortkey/index.d.ts +25 -0
- package/dist/types/evokePortkey/index.d.ts.map +1 -0
- package/dist/types/evokePortkey/types.d.ts +22 -0
- package/dist/types/evokePortkey/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# `@portkey/onboarding`
|
2
|
+
|
3
|
+

|
4
|
+

|
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,37 @@
|
|
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
|
+
// e.g. '1.0.0-rc' -- Number('0-rc') = NaN
|
17
|
+
if (!isNaN(snippetA) && isNaN(snippetB))
|
18
|
+
return 1;
|
19
|
+
if (isNaN(snippetA) && !isNaN(snippetB))
|
20
|
+
return -1;
|
21
|
+
}
|
22
|
+
return 0;
|
23
|
+
};
|
24
|
+
exports.semverCompare = semverCompare;
|
25
|
+
const getIOSVersion = () => {
|
26
|
+
var _a;
|
27
|
+
const version = (_a = ua
|
28
|
+
.toLocaleLowerCase()
|
29
|
+
.match(/cpu iphone os (.*?) like mac os/)) === null || _a === void 0 ? void 0 : _a[1].split('_');
|
30
|
+
if (!version)
|
31
|
+
return -1;
|
32
|
+
return Number.parseInt(version[0], 10);
|
33
|
+
};
|
34
|
+
exports.getIOSVersion = getIOSVersion;
|
35
|
+
exports.isAndroid = /android/i.test(ua);
|
36
|
+
exports.isIos = /iphone|ipad|ipod/i.test(ua);
|
37
|
+
exports.isOriginalChrome = /chrome\/[\d.]+ mobile safari\/[\d.]+/i.test(ua) && exports.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,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.WEB_PAGE = 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
|
+
};
|
13
|
+
exports.WEB_PAGE = 'https://openlogin.portkey.finance';
|
14
|
+
// export const WEB_PAGE = 'https://openlogin-test.portkey.finance';
|
15
|
+
// export const WEB_PAGE = 'http://192.168.11.245:3000';
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { OpenStatus } from './types';
|
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,101 @@
|
|
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
|
+
// Opera 12.10 and Firefox 18 and later support
|
12
|
+
hidden = 'hidden';
|
13
|
+
visibilityChange = 'visibilitychange';
|
14
|
+
}
|
15
|
+
else if (typeof document.msHidden !== 'undefined') {
|
16
|
+
hidden = 'msHidden';
|
17
|
+
visibilityChange = 'msvisibilitychange';
|
18
|
+
}
|
19
|
+
else if (typeof document.webkitHidden !== 'undefined') {
|
20
|
+
hidden = 'webkitHidden';
|
21
|
+
visibilityChange = 'webkitvisibilitychange';
|
22
|
+
}
|
23
|
+
}
|
24
|
+
getSupportedProperty();
|
25
|
+
/**
|
26
|
+
* Determine whether the page is hidden (enter the background)
|
27
|
+
*/
|
28
|
+
function isPageHidden() {
|
29
|
+
if (typeof document === 'undefined')
|
30
|
+
return false;
|
31
|
+
if (typeof hidden === 'undefined')
|
32
|
+
return false;
|
33
|
+
return document[hidden];
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* Jump via top.location.href
|
37
|
+
* @param {string} [uri] - open
|
38
|
+
*/
|
39
|
+
function evokeByLocation(uri) {
|
40
|
+
// if (typeof window === 'undefined') return;
|
41
|
+
if (window.top)
|
42
|
+
window.top.location.href = uri;
|
43
|
+
else
|
44
|
+
window.location.href = uri;
|
45
|
+
}
|
46
|
+
exports.evokeByLocation = evokeByLocation;
|
47
|
+
/**
|
48
|
+
* Evoked by the A tag
|
49
|
+
* @param {string} uri - open url
|
50
|
+
*/
|
51
|
+
function evokeByTagA(uri) {
|
52
|
+
const tagA = document.createElement('a');
|
53
|
+
tagA.setAttribute('href', uri);
|
54
|
+
tagA.style.display = 'none';
|
55
|
+
document.body.appendChild(tagA);
|
56
|
+
tagA.click();
|
57
|
+
}
|
58
|
+
exports.evokeByTagA = evokeByTagA;
|
59
|
+
/**
|
60
|
+
* Evoked by iframe
|
61
|
+
* @param {string} [uri] - open url
|
62
|
+
*/
|
63
|
+
function evokeByIFrame(uri) {
|
64
|
+
if (!iframe) {
|
65
|
+
iframe = document.createElement('iframe');
|
66
|
+
iframe.style.cssText = 'display:none;border:0;width:0;height:0;';
|
67
|
+
document.body.appendChild(iframe);
|
68
|
+
}
|
69
|
+
iframe.src = uri;
|
70
|
+
}
|
71
|
+
exports.evokeByIFrame = evokeByIFrame;
|
72
|
+
/**
|
73
|
+
* Check whether the calling end is successful
|
74
|
+
* @param cb - Callback failure callback function
|
75
|
+
* @param timeout
|
76
|
+
*/
|
77
|
+
function checkOpen(callback, timeout) {
|
78
|
+
const timer = setTimeout(() => {
|
79
|
+
const pageHidden = isPageHidden();
|
80
|
+
if (!pageHidden) {
|
81
|
+
callback('failure');
|
82
|
+
if (typeof visibilityChange !== 'undefined') {
|
83
|
+
document.removeEventListener(visibilityChange, visibilityListenHandler);
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
window.removeEventListener('pagehide', visibilityListenHandler);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}, timeout);
|
90
|
+
const visibilityListenHandler = () => {
|
91
|
+
clearTimeout(timer);
|
92
|
+
callback('success');
|
93
|
+
};
|
94
|
+
if (typeof visibilityChange !== 'undefined') {
|
95
|
+
document.addEventListener(visibilityChange, visibilityListenHandler);
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
window.addEventListener('pagehide', visibilityListenHandler);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
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,66 @@
|
|
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
|
+
// Generate basic url scheme
|
6
|
+
function buildScheme(config, options) {
|
7
|
+
const { path, param } = config;
|
8
|
+
const { scheme, buildScheme: customBuildScheme } = options;
|
9
|
+
if (typeof customBuildScheme !== 'undefined') {
|
10
|
+
return customBuildScheme(config, options);
|
11
|
+
}
|
12
|
+
const { domain, protocol } = scheme;
|
13
|
+
return (0, query_string_1.stringifyUrl)({
|
14
|
+
url: `${protocol}://${domain}/${path}`,
|
15
|
+
query: param,
|
16
|
+
}, { encode: true });
|
17
|
+
}
|
18
|
+
exports.buildScheme = buildScheme;
|
19
|
+
// Generate the url scheme required by the business (distinguish whether it is an external link)
|
20
|
+
function generateScheme(config, options) {
|
21
|
+
const { outChain } = options;
|
22
|
+
let uri = buildScheme(config, options);
|
23
|
+
if (typeof outChain !== 'undefined' && outChain) {
|
24
|
+
const { protocol, path, key } = outChain;
|
25
|
+
uri = `${protocol}://${path}?${key}=${encodeURIComponent(uri)}`;
|
26
|
+
}
|
27
|
+
return uri;
|
28
|
+
}
|
29
|
+
exports.generateScheme = generateScheme;
|
30
|
+
// generate android intent
|
31
|
+
function generateIntent(config, options) {
|
32
|
+
const { outChain } = options;
|
33
|
+
const { intent, fallback } = options;
|
34
|
+
if (typeof intent === 'undefined')
|
35
|
+
return '';
|
36
|
+
const keys = Object.keys(intent);
|
37
|
+
const intentParam = keys.map(key => `${key}=${intent[key]};`).join('');
|
38
|
+
const intentTail = `#Intent;${intentParam}S.browser_fallback_url=${encodeURIComponent(fallback || '')};end;`;
|
39
|
+
let urlPath = buildScheme(config, options);
|
40
|
+
if (typeof outChain !== 'undefined' && outChain) {
|
41
|
+
const { path, key } = outChain;
|
42
|
+
return `intent://${path}?${key}=${encodeURIComponent(urlPath)}${intentTail}`;
|
43
|
+
}
|
44
|
+
urlPath = urlPath.slice(urlPath.indexOf('//') + 2);
|
45
|
+
return `intent://${urlPath}${intentTail}`;
|
46
|
+
}
|
47
|
+
exports.generateIntent = generateIntent;
|
48
|
+
// generate universalLink
|
49
|
+
function generateUniversalLink(config, options) {
|
50
|
+
const { universal } = options;
|
51
|
+
if (typeof universal === 'undefined')
|
52
|
+
return '';
|
53
|
+
const { domain, pathKey } = universal;
|
54
|
+
const { path, param } = config;
|
55
|
+
const protocol = 'https';
|
56
|
+
const newUniversalLink = (0, query_string_1.stringifyUrl)({
|
57
|
+
url: `${protocol}://${domain}/${path}`,
|
58
|
+
query: param,
|
59
|
+
}, { encode: true });
|
60
|
+
const oldUniversalLink = (0, query_string_1.stringifyUrl)({
|
61
|
+
url: `${protocol}://${domain}/${path}`,
|
62
|
+
query: pathKey ? Object.assign({ [pathKey]: path }, param) : param,
|
63
|
+
}, { encode: true });
|
64
|
+
return pathKey ? oldUniversalLink : newUniversalLink;
|
65
|
+
}
|
66
|
+
exports.generateUniversalLink = generateUniversalLink;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { EvokeAppConfig, EvokeAppOptions } from './types';
|
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,129 @@
|
|
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
|
+
/**
|
28
|
+
* @remakes https://github.com/suanmei/callapp-lib
|
29
|
+
*/
|
30
|
+
const Browser = __importStar(require("../browser"));
|
31
|
+
const evoke_1 = require("./evoke");
|
32
|
+
const generate = __importStar(require("./generate"));
|
33
|
+
class EvokeApp {
|
34
|
+
// Create an instance of EvokeApp
|
35
|
+
constructor(options) {
|
36
|
+
const defaultOptions = { timeout: 4000 };
|
37
|
+
this.options = Object.assign(defaultOptions, options);
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* register as method
|
41
|
+
* generateScheme | generateIntent | generateUniversalLink | checkOpen
|
42
|
+
*/
|
43
|
+
generateScheme(config) {
|
44
|
+
return generate.generateScheme(config, this.options);
|
45
|
+
}
|
46
|
+
generateIntent(config) {
|
47
|
+
return generate.generateIntent(config, this.options);
|
48
|
+
}
|
49
|
+
generateUniversalLink(config) {
|
50
|
+
return generate.generateUniversalLink(config, this.options);
|
51
|
+
}
|
52
|
+
checkOpen() {
|
53
|
+
const { logFunc, timeout } = this.options;
|
54
|
+
return new Promise((resolve, reject) => {
|
55
|
+
(0, evoke_1.checkOpen)(status => {
|
56
|
+
logFunc === null || logFunc === void 0 ? void 0 : logFunc(status);
|
57
|
+
if (status === 'success')
|
58
|
+
return resolve(status);
|
59
|
+
reject(status);
|
60
|
+
}, timeout);
|
61
|
+
});
|
62
|
+
}
|
63
|
+
// Call terminal failure jump app store
|
64
|
+
fallToAppStore() {
|
65
|
+
this.checkOpen().catch(() => (0, evoke_1.evokeByLocation)(this.options.appStore));
|
66
|
+
}
|
67
|
+
// Redirect to the general (download) page if the terminal call fails
|
68
|
+
fallToFbUrl() {
|
69
|
+
this.checkOpen().catch(() => {
|
70
|
+
if (!this.options.fallback)
|
71
|
+
return;
|
72
|
+
(0, evoke_1.evokeByLocation)(this.options.fallback);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
// Failed to call the terminal to call the custom callback function
|
76
|
+
fallToCustomCb(callback) {
|
77
|
+
this.checkOpen().catch(callback);
|
78
|
+
}
|
79
|
+
/**
|
80
|
+
* Evoke the client
|
81
|
+
* Execute different call-out strategies according to different browsers
|
82
|
+
*/
|
83
|
+
open(config) {
|
84
|
+
const { universal, logFunc, intent } = this.options;
|
85
|
+
const { callback } = config;
|
86
|
+
const supportUniversal = typeof universal !== 'undefined';
|
87
|
+
const schemeURL = this.generateScheme(config);
|
88
|
+
let checkOpenFall;
|
89
|
+
if (typeof logFunc !== 'undefined') {
|
90
|
+
logFunc('pending');
|
91
|
+
}
|
92
|
+
if (Browser.isIos) {
|
93
|
+
if (Browser.getIOSVersion() < 9) {
|
94
|
+
(0, evoke_1.evokeByIFrame)(schemeURL);
|
95
|
+
checkOpenFall = this.fallToAppStore;
|
96
|
+
}
|
97
|
+
else if (!supportUniversal) {
|
98
|
+
(0, evoke_1.evokeByTagA)(schemeURL);
|
99
|
+
checkOpenFall = this.fallToAppStore;
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
(0, evoke_1.evokeByLocation)(this.generateUniversalLink(config));
|
103
|
+
}
|
104
|
+
// Android
|
105
|
+
}
|
106
|
+
else if (Browser.isOriginalChrome) {
|
107
|
+
if (typeof intent !== 'undefined') {
|
108
|
+
(0, evoke_1.evokeByLocation)(this.generateIntent(config));
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
// The scheme cannot pull up the iframe normally on the android chrome25+ version
|
112
|
+
(0, evoke_1.evokeByLocation)(schemeURL);
|
113
|
+
checkOpenFall = this.fallToFbUrl;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
else {
|
117
|
+
(0, evoke_1.evokeByIFrame)(schemeURL);
|
118
|
+
checkOpenFall = this.fallToFbUrl;
|
119
|
+
}
|
120
|
+
if (typeof callback !== 'undefined') {
|
121
|
+
this.fallToCustomCb(callback);
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
if (!checkOpenFall)
|
125
|
+
return;
|
126
|
+
checkOpenFall.call(this);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
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,44 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
const utils_1 = require("../utils");
|
16
|
+
const constants_1 = require("../constants");
|
17
|
+
const detect_provider_1 = __importDefault(require("@portkey/detect-provider"));
|
18
|
+
/**
|
19
|
+
* This method is used to check if the provided object is a Portkey provider.
|
20
|
+
*/
|
21
|
+
function isPortkeyProvider() {
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
23
|
+
try {
|
24
|
+
const provider = yield (0, detect_provider_1.default)();
|
25
|
+
return !!provider;
|
26
|
+
}
|
27
|
+
catch (error) {
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
});
|
31
|
+
}
|
32
|
+
const checkPortkeyExtension = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
33
|
+
const openTarget = params === null || params === void 0 ? void 0 : params.openTarget;
|
34
|
+
if (typeof window === 'undefined')
|
35
|
+
return false;
|
36
|
+
const _window = window;
|
37
|
+
if (yield isPortkeyProvider())
|
38
|
+
return true;
|
39
|
+
const browserName = (0, utils_1.detectBrowserName)();
|
40
|
+
const downloadURL = constants_1.EXTENSION_DOWNLOAD_URL[browserName] || constants_1.EXTENSION_DOWNLOAD_URL.DEFAULT;
|
41
|
+
_window.open(downloadURL, openTarget);
|
42
|
+
return false;
|
43
|
+
});
|
44
|
+
exports.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,6 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const query_string_1 = require("query-string");
|
4
|
+
const constants_1 = require("../constants");
|
5
|
+
const evokeByThirdParty = params => Promise.resolve(window.open(`${constants_1.WEB_PAGE}/portkey-download?${(0, query_string_1.stringify)(params)}`));
|
6
|
+
exports.default = evokeByThirdParty;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const utils_1 = require("@portkey/utils");
|
4
|
+
const evokeApp_1 = require("../evokeApp");
|
5
|
+
const constants_1 = require("../constants");
|
6
|
+
const evokePortkeyApp = ({ domain, custom, action, timeout = 4000, customFailureCallback, onStatusChange, }) => {
|
7
|
+
const callLib = new evokeApp_1.EvokeApp({
|
8
|
+
scheme: {
|
9
|
+
protocol: utils_1.scheme.DID_APP_SCHEMA,
|
10
|
+
domain: domain || (window === null || window === void 0 ? void 0 : window.location.host),
|
11
|
+
},
|
12
|
+
timeout,
|
13
|
+
appStore: constants_1.APP_DOWNLOAD_URL.APP_STORE,
|
14
|
+
fallback: constants_1.APP_DOWNLOAD_URL.CHROME_STORE,
|
15
|
+
logFunc: onStatusChange,
|
16
|
+
buildScheme: (config, options) => {
|
17
|
+
return utils_1.scheme.formatScheme({
|
18
|
+
scheme: utils_1.scheme.DID_APP_SCHEMA,
|
19
|
+
action: action,
|
20
|
+
domain: options.scheme.domain,
|
21
|
+
custom: config.param,
|
22
|
+
});
|
23
|
+
},
|
24
|
+
});
|
25
|
+
callLib.open({
|
26
|
+
path: action,
|
27
|
+
param: custom,
|
28
|
+
callback: customFailureCallback,
|
29
|
+
});
|
30
|
+
};
|
31
|
+
exports.default = evokePortkeyApp;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export * from './types';
|
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,25 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
18
|
+
};
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
+
exports.evokePortkey = void 0;
|
21
|
+
const evokePortkeyApp_1 = __importDefault(require("./evokePortkeyApp"));
|
22
|
+
const checkPortkeyExtension_1 = __importDefault(require("./checkPortkeyExtension"));
|
23
|
+
const evokeByThirdParty_1 = __importDefault(require("./evokeByThirdParty"));
|
24
|
+
__exportStar(require("./types"), exports);
|
25
|
+
exports.evokePortkey = { app: evokePortkeyApp_1.default, extension: checkPortkeyExtension_1.default, thirdParty: evokeByThirdParty_1.default };
|