@stripe/connect-js 1.0.6 → 1.0.7
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/README.md +2 -0
- package/package.json +1 -1
- package/src/shared.ts +5 -1
- package/types/shared.d.ts +23 -1
- package/dist/connect.esm.js +0 -117
- package/dist/connect.js +0 -121
- package/dist/index.d.ts +0 -3
- package/dist/pure.d.ts +0 -2
- package/dist/pure.esm.js +0 -107
- package/dist/pure.js +0 -111
- package/dist/shared.d.ts +0 -5
- package/dist/utils/jestHelpers.d.ts +0 -2
- package/dist/utils/jestSetup.d.ts +0 -1
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
The [Connect.js library](https://stripe.com/docs/connect/get-started-connect-embedded-components) and its supporting API allows you to add connected account dashboard functionality to your website.
|
|
4
4
|
This NPM package contains initialization logic for Connect embedded components along with related types.
|
|
5
5
|
|
|
6
|
+
Calling `loadConnect` always loads the latest version of Connect.js, regardless of which version of `@stripe/connect-js` you use. Updates for this package only impact tooling around the `loadConnect` helper itself and the TypeScript type definitions provided for Connect.js. Updates do not affect runtime availability of features of Connect.js.
|
|
7
|
+
|
|
6
8
|
Note: Connect embedded components is currently still in beta. Please [contact us](https://stripe.com/docs/connect/get-started-connect-embedded-components#access) to request beta access.
|
|
7
9
|
|
|
8
10
|
## Installation
|
package/package.json
CHANGED
package/src/shared.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { version } from ".././package.json";
|
|
1
2
|
import { StripeConnectWrapper, IStripeConnectInitParams } from "../types";
|
|
2
3
|
|
|
3
4
|
export type LoadConnect = () => Promise<StripeConnectWrapper>;
|
|
@@ -95,7 +96,10 @@ const createWrapper = (stripeConnect: any) => {
|
|
|
95
96
|
...params,
|
|
96
97
|
metaOptions: {
|
|
97
98
|
...metaOptions,
|
|
98
|
-
sdk: true
|
|
99
|
+
sdk: true,
|
|
100
|
+
sdkOptions: {
|
|
101
|
+
sdkVersion: version
|
|
102
|
+
}
|
|
99
103
|
}
|
|
100
104
|
});
|
|
101
105
|
},
|
package/types/shared.d.ts
CHANGED
|
@@ -116,20 +116,42 @@ export interface IStripeConnectInitParams {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
export interface StripeConnectWrapper {
|
|
119
|
+
/**
|
|
120
|
+
* Initializes a Connect JS instance that can be used to create and update Connect components.
|
|
121
|
+
* @param params Initialization parameters for Connect JS. See https://stripe.com/docs/connect/get-started-connect-embedded-components#configuring-connect-js for more details.
|
|
122
|
+
* @returns A Connect JS instance.
|
|
123
|
+
*/
|
|
119
124
|
initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Logs the user out of Connect JS sessions
|
|
128
|
+
* @returns A promise that resolves when the user is logged out.
|
|
129
|
+
*/
|
|
120
130
|
logout: () => Promise<void>;
|
|
121
131
|
}
|
|
122
132
|
|
|
123
133
|
export interface StripeConnectInstance {
|
|
134
|
+
/**
|
|
135
|
+
* Creates a Connect element.
|
|
136
|
+
* @tagName Name of the Connect component to create.
|
|
137
|
+
* @returns An HTML component corresponding to that connect component
|
|
138
|
+
*/
|
|
124
139
|
create: (tagName: ConnectElementTagName) => HTMLElement | null;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Updates the Connect instance with new parameters.
|
|
143
|
+
* @options New parameters to update the Connect instance with.
|
|
144
|
+
*/
|
|
125
145
|
update: (options: IStripeConnectUpdateParams) => void;
|
|
126
146
|
}
|
|
127
147
|
|
|
128
|
-
export type
|
|
148
|
+
export type ConnectElementHTMLName =
|
|
129
149
|
| "stripe-connect-payments"
|
|
130
150
|
| "stripe-connect-payouts"
|
|
131
151
|
| "stripe-connect-payment-details";
|
|
132
152
|
|
|
153
|
+
export type ConnectElementTagName = "payments" | "payouts" | "payment-details";
|
|
154
|
+
|
|
133
155
|
export declare const findScript: () => HTMLScriptElement | null;
|
|
134
156
|
|
|
135
157
|
export declare const loadScript: () => Promise<any | null>;
|
package/dist/connect.esm.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
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
|
-
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
26
|
-
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
27
|
-
const findScript = () => {
|
|
28
|
-
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
29
|
-
};
|
|
30
|
-
const injectScript = () => {
|
|
31
|
-
const script = document.createElement("script");
|
|
32
|
-
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
33
|
-
const head = document.head;
|
|
34
|
-
if (!head) {
|
|
35
|
-
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
36
|
-
}
|
|
37
|
-
document.head.appendChild(script);
|
|
38
|
-
return script;
|
|
39
|
-
};
|
|
40
|
-
let stripePromise = null;
|
|
41
|
-
const loadScript = () => {
|
|
42
|
-
// Ensure that we only attempt to load Connect.js at most once
|
|
43
|
-
if (stripePromise !== null) {
|
|
44
|
-
return stripePromise;
|
|
45
|
-
}
|
|
46
|
-
stripePromise = new Promise((resolve, reject) => {
|
|
47
|
-
if (window.StripeConnect) {
|
|
48
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
49
|
-
}
|
|
50
|
-
if (window.StripeConnect) {
|
|
51
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
52
|
-
resolve(wrapper);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
let script = findScript();
|
|
57
|
-
if (script) {
|
|
58
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
59
|
-
} else if (!script) {
|
|
60
|
-
script = injectScript();
|
|
61
|
-
}
|
|
62
|
-
script.addEventListener("load", () => {
|
|
63
|
-
if (window.StripeConnect) {
|
|
64
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
65
|
-
resolve(wrapper);
|
|
66
|
-
} else {
|
|
67
|
-
reject(new Error("Connect.js did not load the necessary objects"));
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
script.addEventListener("error", () => {
|
|
71
|
-
reject(new Error("Failed to load Connect.js"));
|
|
72
|
-
});
|
|
73
|
-
} catch (error) {
|
|
74
|
-
reject(error);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
return stripePromise;
|
|
78
|
-
};
|
|
79
|
-
const initStripeConnect = stripeConnectPromise => {
|
|
80
|
-
if (stripeConnectPromise === null) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return stripeConnectPromise;
|
|
84
|
-
};
|
|
85
|
-
const createWrapper = stripeConnect => {
|
|
86
|
-
const wrapper = {
|
|
87
|
-
initialize: params => {
|
|
88
|
-
var _a;
|
|
89
|
-
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
90
|
-
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
91
|
-
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
92
|
-
sdk: true
|
|
93
|
-
})
|
|
94
|
-
}));
|
|
95
|
-
},
|
|
96
|
-
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
-
yield stripeConnect.logout();
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
return wrapper;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Execute our own script injection after a tick to give users time to do their
|
|
104
|
-
// own script injection.
|
|
105
|
-
const stripePromise$1 = Promise.resolve().then(() => loadScript());
|
|
106
|
-
let loadCalled = false;
|
|
107
|
-
stripePromise$1.catch(err => {
|
|
108
|
-
if (!loadCalled) {
|
|
109
|
-
console.warn(err);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
const loadConnect = () => {
|
|
113
|
-
loadCalled = true;
|
|
114
|
-
return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export { loadConnect };
|
package/dist/connect.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
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
|
-
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
30
|
-
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
31
|
-
const findScript = () => {
|
|
32
|
-
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
33
|
-
};
|
|
34
|
-
const injectScript = () => {
|
|
35
|
-
const script = document.createElement("script");
|
|
36
|
-
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
37
|
-
const head = document.head;
|
|
38
|
-
if (!head) {
|
|
39
|
-
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
40
|
-
}
|
|
41
|
-
document.head.appendChild(script);
|
|
42
|
-
return script;
|
|
43
|
-
};
|
|
44
|
-
let stripePromise = null;
|
|
45
|
-
const loadScript = () => {
|
|
46
|
-
// Ensure that we only attempt to load Connect.js at most once
|
|
47
|
-
if (stripePromise !== null) {
|
|
48
|
-
return stripePromise;
|
|
49
|
-
}
|
|
50
|
-
stripePromise = new Promise((resolve, reject) => {
|
|
51
|
-
if (window.StripeConnect) {
|
|
52
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
53
|
-
}
|
|
54
|
-
if (window.StripeConnect) {
|
|
55
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
56
|
-
resolve(wrapper);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
let script = findScript();
|
|
61
|
-
if (script) {
|
|
62
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
63
|
-
} else if (!script) {
|
|
64
|
-
script = injectScript();
|
|
65
|
-
}
|
|
66
|
-
script.addEventListener("load", () => {
|
|
67
|
-
if (window.StripeConnect) {
|
|
68
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
69
|
-
resolve(wrapper);
|
|
70
|
-
} else {
|
|
71
|
-
reject(new Error("Connect.js did not load the necessary objects"));
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
script.addEventListener("error", () => {
|
|
75
|
-
reject(new Error("Failed to load Connect.js"));
|
|
76
|
-
});
|
|
77
|
-
} catch (error) {
|
|
78
|
-
reject(error);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return stripePromise;
|
|
82
|
-
};
|
|
83
|
-
const initStripeConnect = stripeConnectPromise => {
|
|
84
|
-
if (stripeConnectPromise === null) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
return stripeConnectPromise;
|
|
88
|
-
};
|
|
89
|
-
const createWrapper = stripeConnect => {
|
|
90
|
-
const wrapper = {
|
|
91
|
-
initialize: params => {
|
|
92
|
-
var _a;
|
|
93
|
-
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
94
|
-
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
95
|
-
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
96
|
-
sdk: true
|
|
97
|
-
})
|
|
98
|
-
}));
|
|
99
|
-
},
|
|
100
|
-
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
-
yield stripeConnect.logout();
|
|
102
|
-
})
|
|
103
|
-
};
|
|
104
|
-
return wrapper;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// Execute our own script injection after a tick to give users time to do their
|
|
108
|
-
// own script injection.
|
|
109
|
-
const stripePromise$1 = Promise.resolve().then(() => loadScript());
|
|
110
|
-
let loadCalled = false;
|
|
111
|
-
stripePromise$1.catch(err => {
|
|
112
|
-
if (!loadCalled) {
|
|
113
|
-
console.warn(err);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
const loadConnect = () => {
|
|
117
|
-
loadCalled = true;
|
|
118
|
-
return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
exports.loadConnect = loadConnect;
|
package/dist/index.d.ts
DELETED
package/dist/pure.d.ts
DELETED
package/dist/pure.esm.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
26
|
-
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
27
|
-
const findScript = () => {
|
|
28
|
-
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
29
|
-
};
|
|
30
|
-
const injectScript = () => {
|
|
31
|
-
const script = document.createElement("script");
|
|
32
|
-
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
33
|
-
const head = document.head;
|
|
34
|
-
if (!head) {
|
|
35
|
-
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
36
|
-
}
|
|
37
|
-
document.head.appendChild(script);
|
|
38
|
-
return script;
|
|
39
|
-
};
|
|
40
|
-
let stripePromise = null;
|
|
41
|
-
const loadScript = () => {
|
|
42
|
-
// Ensure that we only attempt to load Connect.js at most once
|
|
43
|
-
if (stripePromise !== null) {
|
|
44
|
-
return stripePromise;
|
|
45
|
-
}
|
|
46
|
-
stripePromise = new Promise((resolve, reject) => {
|
|
47
|
-
if (window.StripeConnect) {
|
|
48
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
49
|
-
}
|
|
50
|
-
if (window.StripeConnect) {
|
|
51
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
52
|
-
resolve(wrapper);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
let script = findScript();
|
|
57
|
-
if (script) {
|
|
58
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
59
|
-
} else if (!script) {
|
|
60
|
-
script = injectScript();
|
|
61
|
-
}
|
|
62
|
-
script.addEventListener("load", () => {
|
|
63
|
-
if (window.StripeConnect) {
|
|
64
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
65
|
-
resolve(wrapper);
|
|
66
|
-
} else {
|
|
67
|
-
reject(new Error("Connect.js did not load the necessary objects"));
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
script.addEventListener("error", () => {
|
|
71
|
-
reject(new Error("Failed to load Connect.js"));
|
|
72
|
-
});
|
|
73
|
-
} catch (error) {
|
|
74
|
-
reject(error);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
return stripePromise;
|
|
78
|
-
};
|
|
79
|
-
const initStripeConnect = stripeConnectPromise => {
|
|
80
|
-
if (stripeConnectPromise === null) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return stripeConnectPromise;
|
|
84
|
-
};
|
|
85
|
-
const createWrapper = stripeConnect => {
|
|
86
|
-
const wrapper = {
|
|
87
|
-
initialize: params => {
|
|
88
|
-
var _a;
|
|
89
|
-
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
90
|
-
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
91
|
-
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
92
|
-
sdk: true
|
|
93
|
-
})
|
|
94
|
-
}));
|
|
95
|
-
},
|
|
96
|
-
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
-
yield stripeConnect.logout();
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
return wrapper;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const loadConnect = () => {
|
|
104
|
-
return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export { loadConnect };
|
package/dist/pure.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
30
|
-
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
31
|
-
const findScript = () => {
|
|
32
|
-
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
33
|
-
};
|
|
34
|
-
const injectScript = () => {
|
|
35
|
-
const script = document.createElement("script");
|
|
36
|
-
script.src = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
37
|
-
const head = document.head;
|
|
38
|
-
if (!head) {
|
|
39
|
-
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
40
|
-
}
|
|
41
|
-
document.head.appendChild(script);
|
|
42
|
-
return script;
|
|
43
|
-
};
|
|
44
|
-
let stripePromise = null;
|
|
45
|
-
const loadScript = () => {
|
|
46
|
-
// Ensure that we only attempt to load Connect.js at most once
|
|
47
|
-
if (stripePromise !== null) {
|
|
48
|
-
return stripePromise;
|
|
49
|
-
}
|
|
50
|
-
stripePromise = new Promise((resolve, reject) => {
|
|
51
|
-
if (window.StripeConnect) {
|
|
52
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
53
|
-
}
|
|
54
|
-
if (window.StripeConnect) {
|
|
55
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
56
|
-
resolve(wrapper);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
let script = findScript();
|
|
61
|
-
if (script) {
|
|
62
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
63
|
-
} else if (!script) {
|
|
64
|
-
script = injectScript();
|
|
65
|
-
}
|
|
66
|
-
script.addEventListener("load", () => {
|
|
67
|
-
if (window.StripeConnect) {
|
|
68
|
-
const wrapper = createWrapper(window.StripeConnect);
|
|
69
|
-
resolve(wrapper);
|
|
70
|
-
} else {
|
|
71
|
-
reject(new Error("Connect.js did not load the necessary objects"));
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
script.addEventListener("error", () => {
|
|
75
|
-
reject(new Error("Failed to load Connect.js"));
|
|
76
|
-
});
|
|
77
|
-
} catch (error) {
|
|
78
|
-
reject(error);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return stripePromise;
|
|
82
|
-
};
|
|
83
|
-
const initStripeConnect = stripeConnectPromise => {
|
|
84
|
-
if (stripeConnectPromise === null) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
return stripeConnectPromise;
|
|
88
|
-
};
|
|
89
|
-
const createWrapper = stripeConnect => {
|
|
90
|
-
const wrapper = {
|
|
91
|
-
initialize: params => {
|
|
92
|
-
var _a;
|
|
93
|
-
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
94
|
-
return stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
95
|
-
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
96
|
-
sdk: true
|
|
97
|
-
})
|
|
98
|
-
}));
|
|
99
|
-
},
|
|
100
|
-
logout: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
-
yield stripeConnect.logout();
|
|
102
|
-
})
|
|
103
|
-
};
|
|
104
|
-
return wrapper;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const loadConnect = () => {
|
|
108
|
-
return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
exports.loadConnect = loadConnect;
|
package/dist/shared.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|