@stripe/connect-js 1.0.7 → 1.0.8
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/dist/connect.esm.js +122 -0
- package/dist/connect.js +126 -0
- package/dist/pure.esm.js +112 -0
- package/dist/pure.js +116 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/pure.d.ts +2 -0
- package/dist/src/shared.d.ts +5 -0
- package/dist/src/utils/jestHelpers.d.ts +2 -0
- package/dist/src/utils/jestSetup.d.ts +1 -0
- package/package.json +4 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
11
|
+
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
21
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var version = "1.0.8";
|
|
26
|
+
|
|
27
|
+
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
28
|
+
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
29
|
+
const findScript = () => {
|
|
30
|
+
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
31
|
+
};
|
|
32
|
+
const injectScript = () => {
|
|
33
|
+
const script = document.createElement("script");
|
|
34
|
+
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
35
|
+
const head = document.head;
|
|
36
|
+
if (!head) {
|
|
37
|
+
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
38
|
+
}
|
|
39
|
+
document.head.appendChild(script);
|
|
40
|
+
return script;
|
|
41
|
+
};
|
|
42
|
+
let stripePromise = null;
|
|
43
|
+
const loadScript = () => {
|
|
44
|
+
// Ensure that we only attempt to load Connect.js at most once
|
|
45
|
+
if (stripePromise !== null) {
|
|
46
|
+
return stripePromise;
|
|
47
|
+
}
|
|
48
|
+
stripePromise = new Promise((resolve, reject) => {
|
|
49
|
+
if (window.StripeConnect) {
|
|
50
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
51
|
+
}
|
|
52
|
+
if (window.StripeConnect) {
|
|
53
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
54
|
+
resolve(wrapper);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
let script = findScript();
|
|
59
|
+
if (script) {
|
|
60
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
61
|
+
} else if (!script) {
|
|
62
|
+
script = injectScript();
|
|
63
|
+
}
|
|
64
|
+
script.addEventListener("load", () => {
|
|
65
|
+
if (window.StripeConnect) {
|
|
66
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
67
|
+
resolve(wrapper);
|
|
68
|
+
} else {
|
|
69
|
+
reject(new Error("Connect.js did not load the necessary objects"));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
script.addEventListener("error", () => {
|
|
73
|
+
reject(new Error("Failed to load Connect.js"));
|
|
74
|
+
});
|
|
75
|
+
} catch (error) {
|
|
76
|
+
reject(error);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return stripePromise;
|
|
80
|
+
};
|
|
81
|
+
const initStripeConnect = stripeConnectPromise => {
|
|
82
|
+
if (stripeConnectPromise === null) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return stripeConnectPromise;
|
|
86
|
+
};
|
|
87
|
+
const createWrapper = stripeConnect => {
|
|
88
|
+
const wrapper = {
|
|
89
|
+
initialize: params => {
|
|
90
|
+
var _a;
|
|
91
|
+
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
92
|
+
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
93
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
94
|
+
sdk: true,
|
|
95
|
+
sdkOptions: {
|
|
96
|
+
sdkVersion: version
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
}));
|
|
100
|
+
},
|
|
101
|
+
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
yield stripeConnect.logout();
|
|
103
|
+
})
|
|
104
|
+
};
|
|
105
|
+
return wrapper;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Execute our own script injection after a tick to give users time to do their
|
|
109
|
+
// own script injection.
|
|
110
|
+
const stripePromise$1 = Promise.resolve().then(() => loadScript());
|
|
111
|
+
let loadCalled = false;
|
|
112
|
+
stripePromise$1.catch(err => {
|
|
113
|
+
if (!loadCalled) {
|
|
114
|
+
console.warn(err);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const loadConnect = () => {
|
|
118
|
+
loadCalled = true;
|
|
119
|
+
return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export { loadConnect };
|
package/dist/connect.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/*! *****************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
12
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
13
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
15
|
+
|
|
16
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
17
|
+
and limitations under the License.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
|
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var version = "1.0.8";
|
|
30
|
+
|
|
31
|
+
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
32
|
+
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
33
|
+
const findScript = () => {
|
|
34
|
+
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
35
|
+
};
|
|
36
|
+
const injectScript = () => {
|
|
37
|
+
const script = document.createElement("script");
|
|
38
|
+
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
39
|
+
const head = document.head;
|
|
40
|
+
if (!head) {
|
|
41
|
+
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
42
|
+
}
|
|
43
|
+
document.head.appendChild(script);
|
|
44
|
+
return script;
|
|
45
|
+
};
|
|
46
|
+
let stripePromise = null;
|
|
47
|
+
const loadScript = () => {
|
|
48
|
+
// Ensure that we only attempt to load Connect.js at most once
|
|
49
|
+
if (stripePromise !== null) {
|
|
50
|
+
return stripePromise;
|
|
51
|
+
}
|
|
52
|
+
stripePromise = new Promise((resolve, reject) => {
|
|
53
|
+
if (window.StripeConnect) {
|
|
54
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
55
|
+
}
|
|
56
|
+
if (window.StripeConnect) {
|
|
57
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
58
|
+
resolve(wrapper);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
let script = findScript();
|
|
63
|
+
if (script) {
|
|
64
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
65
|
+
} else if (!script) {
|
|
66
|
+
script = injectScript();
|
|
67
|
+
}
|
|
68
|
+
script.addEventListener("load", () => {
|
|
69
|
+
if (window.StripeConnect) {
|
|
70
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
71
|
+
resolve(wrapper);
|
|
72
|
+
} else {
|
|
73
|
+
reject(new Error("Connect.js did not load the necessary objects"));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
script.addEventListener("error", () => {
|
|
77
|
+
reject(new Error("Failed to load Connect.js"));
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
reject(error);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return stripePromise;
|
|
84
|
+
};
|
|
85
|
+
const initStripeConnect = stripeConnectPromise => {
|
|
86
|
+
if (stripeConnectPromise === null) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return stripeConnectPromise;
|
|
90
|
+
};
|
|
91
|
+
const createWrapper = stripeConnect => {
|
|
92
|
+
const wrapper = {
|
|
93
|
+
initialize: params => {
|
|
94
|
+
var _a;
|
|
95
|
+
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
96
|
+
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
97
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
98
|
+
sdk: true,
|
|
99
|
+
sdkOptions: {
|
|
100
|
+
sdkVersion: version
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}));
|
|
104
|
+
},
|
|
105
|
+
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
yield stripeConnect.logout();
|
|
107
|
+
})
|
|
108
|
+
};
|
|
109
|
+
return wrapper;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Execute our own script injection after a tick to give users time to do their
|
|
113
|
+
// own script injection.
|
|
114
|
+
const stripePromise$1 = Promise.resolve().then(() => loadScript());
|
|
115
|
+
let loadCalled = false;
|
|
116
|
+
stripePromise$1.catch(err => {
|
|
117
|
+
if (!loadCalled) {
|
|
118
|
+
console.warn(err);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const loadConnect = () => {
|
|
122
|
+
loadCalled = true;
|
|
123
|
+
return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
exports.loadConnect = loadConnect;
|
package/dist/pure.esm.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
11
|
+
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
21
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var version = "1.0.8";
|
|
26
|
+
|
|
27
|
+
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
28
|
+
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
29
|
+
const findScript = () => {
|
|
30
|
+
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
31
|
+
};
|
|
32
|
+
const injectScript = () => {
|
|
33
|
+
const script = document.createElement("script");
|
|
34
|
+
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
35
|
+
const head = document.head;
|
|
36
|
+
if (!head) {
|
|
37
|
+
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
38
|
+
}
|
|
39
|
+
document.head.appendChild(script);
|
|
40
|
+
return script;
|
|
41
|
+
};
|
|
42
|
+
let stripePromise = null;
|
|
43
|
+
const loadScript = () => {
|
|
44
|
+
// Ensure that we only attempt to load Connect.js at most once
|
|
45
|
+
if (stripePromise !== null) {
|
|
46
|
+
return stripePromise;
|
|
47
|
+
}
|
|
48
|
+
stripePromise = new Promise((resolve, reject) => {
|
|
49
|
+
if (window.StripeConnect) {
|
|
50
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
51
|
+
}
|
|
52
|
+
if (window.StripeConnect) {
|
|
53
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
54
|
+
resolve(wrapper);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
let script = findScript();
|
|
59
|
+
if (script) {
|
|
60
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
61
|
+
} else if (!script) {
|
|
62
|
+
script = injectScript();
|
|
63
|
+
}
|
|
64
|
+
script.addEventListener("load", () => {
|
|
65
|
+
if (window.StripeConnect) {
|
|
66
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
67
|
+
resolve(wrapper);
|
|
68
|
+
} else {
|
|
69
|
+
reject(new Error("Connect.js did not load the necessary objects"));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
script.addEventListener("error", () => {
|
|
73
|
+
reject(new Error("Failed to load Connect.js"));
|
|
74
|
+
});
|
|
75
|
+
} catch (error) {
|
|
76
|
+
reject(error);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return stripePromise;
|
|
80
|
+
};
|
|
81
|
+
const initStripeConnect = stripeConnectPromise => {
|
|
82
|
+
if (stripeConnectPromise === null) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return stripeConnectPromise;
|
|
86
|
+
};
|
|
87
|
+
const createWrapper = stripeConnect => {
|
|
88
|
+
const wrapper = {
|
|
89
|
+
initialize: params => {
|
|
90
|
+
var _a;
|
|
91
|
+
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
92
|
+
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
93
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
94
|
+
sdk: true,
|
|
95
|
+
sdkOptions: {
|
|
96
|
+
sdkVersion: version
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
}));
|
|
100
|
+
},
|
|
101
|
+
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
yield stripeConnect.logout();
|
|
103
|
+
})
|
|
104
|
+
};
|
|
105
|
+
return wrapper;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const loadConnect = () => {
|
|
109
|
+
return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export { loadConnect };
|
package/dist/pure.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/*! *****************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
12
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
13
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
15
|
+
|
|
16
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
17
|
+
and limitations under the License.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
|
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var version = "1.0.8";
|
|
30
|
+
|
|
31
|
+
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
32
|
+
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
33
|
+
const findScript = () => {
|
|
34
|
+
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
35
|
+
};
|
|
36
|
+
const injectScript = () => {
|
|
37
|
+
const script = document.createElement("script");
|
|
38
|
+
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
39
|
+
const head = document.head;
|
|
40
|
+
if (!head) {
|
|
41
|
+
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
42
|
+
}
|
|
43
|
+
document.head.appendChild(script);
|
|
44
|
+
return script;
|
|
45
|
+
};
|
|
46
|
+
let stripePromise = null;
|
|
47
|
+
const loadScript = () => {
|
|
48
|
+
// Ensure that we only attempt to load Connect.js at most once
|
|
49
|
+
if (stripePromise !== null) {
|
|
50
|
+
return stripePromise;
|
|
51
|
+
}
|
|
52
|
+
stripePromise = new Promise((resolve, reject) => {
|
|
53
|
+
if (window.StripeConnect) {
|
|
54
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
55
|
+
}
|
|
56
|
+
if (window.StripeConnect) {
|
|
57
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
58
|
+
resolve(wrapper);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
let script = findScript();
|
|
63
|
+
if (script) {
|
|
64
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
65
|
+
} else if (!script) {
|
|
66
|
+
script = injectScript();
|
|
67
|
+
}
|
|
68
|
+
script.addEventListener("load", () => {
|
|
69
|
+
if (window.StripeConnect) {
|
|
70
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
71
|
+
resolve(wrapper);
|
|
72
|
+
} else {
|
|
73
|
+
reject(new Error("Connect.js did not load the necessary objects"));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
script.addEventListener("error", () => {
|
|
77
|
+
reject(new Error("Failed to load Connect.js"));
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
reject(error);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return stripePromise;
|
|
84
|
+
};
|
|
85
|
+
const initStripeConnect = stripeConnectPromise => {
|
|
86
|
+
if (stripeConnectPromise === null) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return stripeConnectPromise;
|
|
90
|
+
};
|
|
91
|
+
const createWrapper = stripeConnect => {
|
|
92
|
+
const wrapper = {
|
|
93
|
+
initialize: params => {
|
|
94
|
+
var _a;
|
|
95
|
+
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
96
|
+
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
97
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
98
|
+
sdk: true,
|
|
99
|
+
sdkOptions: {
|
|
100
|
+
sdkVersion: version
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}));
|
|
104
|
+
},
|
|
105
|
+
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
yield stripeConnect.logout();
|
|
107
|
+
})
|
|
108
|
+
};
|
|
109
|
+
return wrapper;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const loadConnect = () => {
|
|
113
|
+
return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
exports.loadConnect = loadConnect;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StripeConnectWrapper } from "../types";
|
|
2
|
+
export type LoadConnect = () => Promise<StripeConnectWrapper>;
|
|
3
|
+
export declare const findScript: () => HTMLScriptElement | null;
|
|
4
|
+
export declare const loadScript: () => Promise<StripeConnectWrapper | null>;
|
|
5
|
+
export declare const initStripeConnect: (stripeConnectPromise: StripeConnectWrapper | null) => any | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stripe/connect-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Connect.js loading utility package",
|
|
5
5
|
"main": "dist/connect.js",
|
|
6
6
|
"module": "dist/connect.esm.js",
|
|
@@ -65,5 +65,8 @@
|
|
|
65
65
|
"typescript": "^4.1.2",
|
|
66
66
|
"yalc": "^1.0.0-pre.53",
|
|
67
67
|
"zx": "^4.2.0"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@rollup/plugin-json": "^6.0.0"
|
|
68
71
|
}
|
|
69
72
|
}
|