@stripe/connect-js 3.3.41-preview-1 → 3.3.43-preview-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/connect.js DELETED
@@ -1,335 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- /* eslint-disable @typescript-eslint/no-empty-function */
6
- /* eslint-disable @typescript-eslint/no-unused-vars */
7
- const ConnectElementCommonMethodConfig = {
8
- setOnLoadError: _listener => {},
9
- setOnLoaderStart: _listener => {}
10
- };
11
- const ConnectElementCustomMethodConfig = {
12
- payments: {
13
- setDefaultFilters: _filters => {}
14
- },
15
- "payment-details": {
16
- setPayment: _payment => {},
17
- setOnClose: _listener => {}
18
- },
19
- "payment-disputes": {
20
- setPayment: _payment => {},
21
- setOnDisputesLoaded: _listener => {}
22
- },
23
- "account-onboarding": {
24
- setFullTermsOfServiceUrl: _termOfServiceUrl => {},
25
- setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
26
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
27
- setSkipTermsOfServiceCollection: _skipTermsOfServiceCollection => {},
28
- setCollectionOptions: _collectionOptions => {},
29
- setOnExit: _listener => {},
30
- setOnStepChange: _listener => {}
31
- },
32
- "account-management": {
33
- setCollectionOptions: _collectionOptions => {}
34
- },
35
- "notification-banner": {
36
- setCollectionOptions: _collectionOptions => {},
37
- setOnNotificationsChange: _listener => {}
38
- },
39
- "instant-payouts-promotion": {
40
- setOnInstantPayoutsPromotionLoaded: _listener => {},
41
- setOnInstantPayoutCreated: _listener => {}
42
- },
43
- "issuing-card": {
44
- setDefaultCard: _defaultCard => {},
45
- setCardSwitching: _cardSwitching => {},
46
- setFetchEphemeralKey: _fetchEphemeralKey => {},
47
- setShowSpendControls: _showSpendControls => {}
48
- },
49
- "issuing-cards-list": {
50
- setFetchEphemeralKey: _fetchEphemeralKey => {},
51
- setShowSpendControls: _showSpendControls => {},
52
- setIssuingProgram: _issuingProgram => {}
53
- },
54
- "financial-account": {
55
- setFinancialAccount: _financialAccount => {}
56
- },
57
- "financial-account-transactions": {
58
- setFinancialAccount: _financialAccount => {}
59
- },
60
- recipients: {
61
- setDataSource: _dataSource => {}
62
- },
63
- "app-install": {
64
- setApp: _app => {},
65
- setOnAppInstallStateFetched: _listener => {},
66
- setOnAppInstallStateChanged: _listener => {}
67
- },
68
- "app-viewport": {
69
- setApp: _app => {},
70
- setAppData: _appData => {}
71
- },
72
- "payment-method-settings": {
73
- setPaymentMethodConfiguration: _paymentMethodConfiguration => {}
74
- },
75
- "capital-financing": {
76
- setDefaultFinancingOffer: _defaultFinancingOffer => {},
77
- setShowFinancingSelector: _showFinancingSelector => {},
78
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
79
- setSupportUrl: _supportUrl => {},
80
- setOnFinancingsLoaded: _listener => {}
81
- },
82
- "capital-financing-application": {
83
- setOnApplicationSubmitted: _listener => {},
84
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
85
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
86
- setOnApplicationStepChange: _listener => {}
87
- },
88
- "capital-financing-promotion": {
89
- setLayout: _layout => {},
90
- setOnApplicationSubmitted: _listener => {},
91
- setOnEligibleFinancingOfferLoaded: _listener => {},
92
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
93
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
94
- setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {},
95
- setOnApplicationStepChange: _listener => {}
96
- },
97
- "reporting-chart": {
98
- setReportName: _reportName => {},
99
- setIntervalStart: _intervalStart => {},
100
- setIntervalEnd: _intervalEnd => {},
101
- setIntervalType: _intervalType => {}
102
- },
103
- "tax-settings": {
104
- setHideProductTaxCodeSelector: _hidden => {},
105
- setDisplayHeadOfficeCountries: _countries => {},
106
- setOnTaxSettingsUpdated: _listener => {}
107
- },
108
- "tax-registrations": {
109
- setOnAfterTaxRegistrationAdded: _listener => {},
110
- setDisplayCountries: _countries => {}
111
- },
112
- "tax-threshold-monitoring": {
113
- setDisplayCountries: _countries => {}
114
- },
115
- "product-tax-code-selector": {
116
- setOnTaxCodeSelect: _listener => {},
117
- setHideDescription: _hideDescription => {},
118
- setDisabled: _disabled => {},
119
- setInitialTaxCode: _initialTaxCode => {}
120
- },
121
- "export-tax-transactions": {},
122
- "payout-details": {
123
- setPayout: _payout => {},
124
- setOnClose: _listener => {}
125
- }
126
- };
127
-
128
- const componentNameMapping = {
129
- payments: "stripe-connect-payments",
130
- payouts: "stripe-connect-payouts",
131
- "payment-details": "stripe-connect-payment-details",
132
- "payment-disputes": "stripe-connect-payment-disputes",
133
- "disputes-list": "stripe-connect-disputes-list",
134
- "account-onboarding": "stripe-connect-account-onboarding",
135
- "payment-method-settings": "stripe-connect-payment-method-settings",
136
- "account-management": "stripe-connect-account-management",
137
- "notification-banner": "stripe-connect-notification-banner",
138
- "instant-payouts": "stripe-connect-instant-payouts",
139
- "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
140
- "issuing-card": "stripe-connect-issuing-card",
141
- "issuing-cards-list": "stripe-connect-issuing-cards-list",
142
- "financial-account": "stripe-connect-financial-account",
143
- recipients: "stripe-connect-recipients",
144
- "financial-account-transactions": "stripe-connect-financial-account-transactions",
145
- "capital-financing": "stripe-connect-capital-financing",
146
- "capital-financing-application": "stripe-connect-capital-financing-application",
147
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
148
- "capital-overview": "stripe-connect-capital-overview",
149
- documents: "stripe-connect-documents",
150
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
151
- "export-tax-transactions": "stripe-connect-export-tax-transactions",
152
- "tax-registrations": "stripe-connect-tax-registrations",
153
- "tax-settings": "stripe-connect-tax-settings",
154
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
155
- balances: "stripe-connect-balances",
156
- "payouts-list": "stripe-connect-payouts-list",
157
- "payout-details": "stripe-connect-payout-details",
158
- "app-install": "stripe-connect-app-install",
159
- "app-viewport": "stripe-connect-app-viewport",
160
- "reporting-chart": "stripe-connect-reporting-chart"
161
- };
162
- const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
163
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
164
- const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
165
- const findScript = () => {
166
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || null;
167
- };
168
- const injectScript = () => {
169
- const script = document.createElement("script");
170
- script.src = V1_URL;
171
- const head = document.head;
172
- if (!head) {
173
- throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
174
- }
175
- document.head.appendChild(script);
176
- return script;
177
- };
178
- let stripePromise = null;
179
- const isWindowStripeConnectDefined = stripeConnect => {
180
- // We only consider `StripeConnect` defined if `init` is a function
181
- // Why? HTML markup like:
182
- // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
183
- // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
184
- return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
185
- };
186
- const loadScript = () => {
187
- // Ensure that we only attempt to load Connect.js at most once
188
- if (stripePromise !== null) {
189
- return stripePromise;
190
- }
191
- stripePromise = new Promise((resolve, reject) => {
192
- if (typeof window === "undefined") {
193
- reject("ConnectJS won't load when rendering code in the server - it can only be loaded on a browser. This error is expected when loading ConnectJS in SSR environments, like NextJS. It will have no impact in the UI, however if you wish to avoid it, you can switch to the `pure` version of the connect.js loader: https://github.com/stripe/connect-js#importing-loadconnect-without-side-effects.");
194
- return;
195
- }
196
- if (isWindowStripeConnectDefined(window.StripeConnect)) {
197
- console.warn(EXISTING_SCRIPT_MESSAGE);
198
- const wrapper = createWrapper(window.StripeConnect);
199
- resolve(wrapper);
200
- return;
201
- }
202
- try {
203
- let script = findScript();
204
- if (script) {
205
- console.warn(EXISTING_SCRIPT_MESSAGE);
206
- } else if (!script) {
207
- script = injectScript();
208
- }
209
- script.addEventListener("load", () => {
210
- if (isWindowStripeConnectDefined(window.StripeConnect)) {
211
- const wrapper = createWrapper(window.StripeConnect);
212
- resolve(wrapper);
213
- } else {
214
- reject(new Error("Connect.js did not load the necessary objects"));
215
- }
216
- });
217
- script.addEventListener("error", () => {
218
- reject(new Error("Failed to load Connect.js"));
219
- });
220
- } catch (error) {
221
- reject(error);
222
- }
223
- });
224
- return stripePromise;
225
- };
226
- const hasCustomMethod = tagName => {
227
- return tagName in ConnectElementCustomMethodConfig;
228
- };
229
- const initStripeConnect = (stripePromise, initParams) => {
230
- var _a;
231
- const eagerClientSecretPromise = (() => {
232
- try {
233
- return initParams.fetchClientSecret();
234
- } catch (error) {
235
- return Promise.reject(error);
236
- }
237
- })();
238
- const metaOptions = (_a = initParams.metaOptions) !== null && _a !== void 0 ? _a : {};
239
- const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(Object.assign(Object.assign({}, initParams), {
240
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
241
- eagerClientSecretPromise
242
- })
243
- })));
244
- return {
245
- create: tagName => {
246
- let htmlName = componentNameMapping[tagName];
247
- if (!htmlName) {
248
- htmlName = tagName;
249
- }
250
- const element = document.createElement(htmlName);
251
- const customMethods = hasCustomMethod(tagName) ? ConnectElementCustomMethodConfig[tagName] : {};
252
- const methods = Object.assign(Object.assign({}, customMethods), ConnectElementCommonMethodConfig);
253
- for (const method in methods) {
254
- element[method] = function (value) {
255
- stripeConnectInstance.then(() => {
256
- if (!this[`${method}InternalOnly`]) {
257
- throw new Error(`Method ${method} is not available in the ${tagName} HTML element. Are you using a supported version of the "@stripe/connect-js" package? Using version: 3.3.41-preview-1`);
258
- }
259
- this[`${method}InternalOnly`](value);
260
- });
261
- };
262
- }
263
- stripeConnectInstance.then(instance => {
264
- if (!element.isConnected && !element.setConnector) {
265
- // If the element is not connected to the DOM and the `setConnector` method is not
266
- // defined, this indicates the element was created before connect.js was loaded, and has
267
- // not been transformed into a custom element yet
268
- // To load the custom element code on it, we need to connect and disconnect it to the DOM
269
- // This isn't a problem, as the element will be invisible, and we know the element is already
270
- // not currently connected to the DOM
271
- const oldDisplay = element.style.display;
272
- element.style.display = "none";
273
- document.body.appendChild(element);
274
- document.body.removeChild(element);
275
- element.style.display = oldDisplay;
276
- }
277
- if (!element || !element.setConnector) {
278
- throw new Error(`Element ${tagName} was not transformed into a custom element. Are you using a documented component? See https://docs.stripe.com/connect/supported-embedded-components for a list of supported components`);
279
- }
280
- element.setConnector(instance.connect);
281
- });
282
- return element;
283
- },
284
- update: updateOptions => {
285
- stripeConnectInstance.then(instance => {
286
- instance.update(updateOptions);
287
- });
288
- },
289
- debugInstance: () => {
290
- return stripeConnectInstance;
291
- },
292
- logout: () => {
293
- return stripeConnectInstance.then(instance => {
294
- return instance.logout();
295
- });
296
- }
297
- };
298
- };
299
- const createWrapper = stripeConnect => {
300
- window.StripeConnect = window.StripeConnect || {};
301
- window.StripeConnect.optimizedLoading = true;
302
- const wrapper = {
303
- initialize: params => {
304
- var _a;
305
- const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
306
- const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
307
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
308
- sdk: true,
309
- sdkOptions: {
310
- // This will be replaced by the npm package version when bundling
311
- sdkVersion: "3.3.41-preview-1"
312
- }
313
- })
314
- }));
315
- return stripeConnectInstance;
316
- }
317
- };
318
- return wrapper;
319
- };
320
-
321
- // Execute our own script injection after a tick to give users time to do their
322
- // own script injection.
323
- const stripePromise$1 = Promise.resolve().then(() => loadScript());
324
- let loadCalled = false;
325
- stripePromise$1.catch(err => {
326
- if (!loadCalled) {
327
- console.warn(err);
328
- }
329
- });
330
- const loadConnectAndInitialize = initParams => {
331
- loadCalled = true;
332
- return initStripeConnect(stripePromise$1, initParams);
333
- };
334
-
335
- exports.loadConnectAndInitialize = loadConnectAndInitialize;
package/dist/pure.esm.js DELETED
@@ -1,325 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
- const ConnectElementCommonMethodConfig = {
4
- setOnLoadError: _listener => {},
5
- setOnLoaderStart: _listener => {}
6
- };
7
- const ConnectElementCustomMethodConfig = {
8
- payments: {
9
- setDefaultFilters: _filters => {}
10
- },
11
- "payment-details": {
12
- setPayment: _payment => {},
13
- setOnClose: _listener => {}
14
- },
15
- "payment-disputes": {
16
- setPayment: _payment => {},
17
- setOnDisputesLoaded: _listener => {}
18
- },
19
- "account-onboarding": {
20
- setFullTermsOfServiceUrl: _termOfServiceUrl => {},
21
- setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
22
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
23
- setSkipTermsOfServiceCollection: _skipTermsOfServiceCollection => {},
24
- setCollectionOptions: _collectionOptions => {},
25
- setOnExit: _listener => {},
26
- setOnStepChange: _listener => {}
27
- },
28
- "account-management": {
29
- setCollectionOptions: _collectionOptions => {}
30
- },
31
- "notification-banner": {
32
- setCollectionOptions: _collectionOptions => {},
33
- setOnNotificationsChange: _listener => {}
34
- },
35
- "instant-payouts-promotion": {
36
- setOnInstantPayoutsPromotionLoaded: _listener => {},
37
- setOnInstantPayoutCreated: _listener => {}
38
- },
39
- "issuing-card": {
40
- setDefaultCard: _defaultCard => {},
41
- setCardSwitching: _cardSwitching => {},
42
- setFetchEphemeralKey: _fetchEphemeralKey => {},
43
- setShowSpendControls: _showSpendControls => {}
44
- },
45
- "issuing-cards-list": {
46
- setFetchEphemeralKey: _fetchEphemeralKey => {},
47
- setShowSpendControls: _showSpendControls => {},
48
- setIssuingProgram: _issuingProgram => {}
49
- },
50
- "financial-account": {
51
- setFinancialAccount: _financialAccount => {}
52
- },
53
- "financial-account-transactions": {
54
- setFinancialAccount: _financialAccount => {}
55
- },
56
- recipients: {
57
- setDataSource: _dataSource => {}
58
- },
59
- "app-install": {
60
- setApp: _app => {},
61
- setOnAppInstallStateFetched: _listener => {},
62
- setOnAppInstallStateChanged: _listener => {}
63
- },
64
- "app-viewport": {
65
- setApp: _app => {},
66
- setAppData: _appData => {}
67
- },
68
- "payment-method-settings": {
69
- setPaymentMethodConfiguration: _paymentMethodConfiguration => {}
70
- },
71
- "capital-financing": {
72
- setDefaultFinancingOffer: _defaultFinancingOffer => {},
73
- setShowFinancingSelector: _showFinancingSelector => {},
74
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
75
- setSupportUrl: _supportUrl => {},
76
- setOnFinancingsLoaded: _listener => {}
77
- },
78
- "capital-financing-application": {
79
- setOnApplicationSubmitted: _listener => {},
80
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
81
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
82
- setOnApplicationStepChange: _listener => {}
83
- },
84
- "capital-financing-promotion": {
85
- setLayout: _layout => {},
86
- setOnApplicationSubmitted: _listener => {},
87
- setOnEligibleFinancingOfferLoaded: _listener => {},
88
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
89
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
90
- setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {},
91
- setOnApplicationStepChange: _listener => {}
92
- },
93
- "reporting-chart": {
94
- setReportName: _reportName => {},
95
- setIntervalStart: _intervalStart => {},
96
- setIntervalEnd: _intervalEnd => {},
97
- setIntervalType: _intervalType => {}
98
- },
99
- "tax-settings": {
100
- setHideProductTaxCodeSelector: _hidden => {},
101
- setDisplayHeadOfficeCountries: _countries => {},
102
- setOnTaxSettingsUpdated: _listener => {}
103
- },
104
- "tax-registrations": {
105
- setOnAfterTaxRegistrationAdded: _listener => {},
106
- setDisplayCountries: _countries => {}
107
- },
108
- "tax-threshold-monitoring": {
109
- setDisplayCountries: _countries => {}
110
- },
111
- "product-tax-code-selector": {
112
- setOnTaxCodeSelect: _listener => {},
113
- setHideDescription: _hideDescription => {},
114
- setDisabled: _disabled => {},
115
- setInitialTaxCode: _initialTaxCode => {}
116
- },
117
- "export-tax-transactions": {},
118
- "payout-details": {
119
- setPayout: _payout => {},
120
- setOnClose: _listener => {}
121
- }
122
- };
123
-
124
- const componentNameMapping = {
125
- payments: "stripe-connect-payments",
126
- payouts: "stripe-connect-payouts",
127
- "payment-details": "stripe-connect-payment-details",
128
- "payment-disputes": "stripe-connect-payment-disputes",
129
- "disputes-list": "stripe-connect-disputes-list",
130
- "account-onboarding": "stripe-connect-account-onboarding",
131
- "payment-method-settings": "stripe-connect-payment-method-settings",
132
- "account-management": "stripe-connect-account-management",
133
- "notification-banner": "stripe-connect-notification-banner",
134
- "instant-payouts": "stripe-connect-instant-payouts",
135
- "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
136
- "issuing-card": "stripe-connect-issuing-card",
137
- "issuing-cards-list": "stripe-connect-issuing-cards-list",
138
- "financial-account": "stripe-connect-financial-account",
139
- recipients: "stripe-connect-recipients",
140
- "financial-account-transactions": "stripe-connect-financial-account-transactions",
141
- "capital-financing": "stripe-connect-capital-financing",
142
- "capital-financing-application": "stripe-connect-capital-financing-application",
143
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
144
- "capital-overview": "stripe-connect-capital-overview",
145
- documents: "stripe-connect-documents",
146
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
147
- "export-tax-transactions": "stripe-connect-export-tax-transactions",
148
- "tax-registrations": "stripe-connect-tax-registrations",
149
- "tax-settings": "stripe-connect-tax-settings",
150
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
151
- balances: "stripe-connect-balances",
152
- "payouts-list": "stripe-connect-payouts-list",
153
- "payout-details": "stripe-connect-payout-details",
154
- "app-install": "stripe-connect-app-install",
155
- "app-viewport": "stripe-connect-app-viewport",
156
- "reporting-chart": "stripe-connect-reporting-chart"
157
- };
158
- const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
159
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
160
- const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
161
- const findScript = () => {
162
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || null;
163
- };
164
- const injectScript = () => {
165
- const script = document.createElement("script");
166
- script.src = V1_URL;
167
- const head = document.head;
168
- if (!head) {
169
- throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
170
- }
171
- document.head.appendChild(script);
172
- return script;
173
- };
174
- let stripePromise = null;
175
- const isWindowStripeConnectDefined = stripeConnect => {
176
- // We only consider `StripeConnect` defined if `init` is a function
177
- // Why? HTML markup like:
178
- // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
179
- // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
180
- return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
181
- };
182
- const loadScript = () => {
183
- // Ensure that we only attempt to load Connect.js at most once
184
- if (stripePromise !== null) {
185
- return stripePromise;
186
- }
187
- stripePromise = new Promise((resolve, reject) => {
188
- if (typeof window === "undefined") {
189
- reject("ConnectJS won't load when rendering code in the server - it can only be loaded on a browser. This error is expected when loading ConnectJS in SSR environments, like NextJS. It will have no impact in the UI, however if you wish to avoid it, you can switch to the `pure` version of the connect.js loader: https://github.com/stripe/connect-js#importing-loadconnect-without-side-effects.");
190
- return;
191
- }
192
- if (isWindowStripeConnectDefined(window.StripeConnect)) {
193
- console.warn(EXISTING_SCRIPT_MESSAGE);
194
- const wrapper = createWrapper(window.StripeConnect);
195
- resolve(wrapper);
196
- return;
197
- }
198
- try {
199
- let script = findScript();
200
- if (script) {
201
- console.warn(EXISTING_SCRIPT_MESSAGE);
202
- } else if (!script) {
203
- script = injectScript();
204
- }
205
- script.addEventListener("load", () => {
206
- if (isWindowStripeConnectDefined(window.StripeConnect)) {
207
- const wrapper = createWrapper(window.StripeConnect);
208
- resolve(wrapper);
209
- } else {
210
- reject(new Error("Connect.js did not load the necessary objects"));
211
- }
212
- });
213
- script.addEventListener("error", () => {
214
- reject(new Error("Failed to load Connect.js"));
215
- });
216
- } catch (error) {
217
- reject(error);
218
- }
219
- });
220
- return stripePromise;
221
- };
222
- const hasCustomMethod = tagName => {
223
- return tagName in ConnectElementCustomMethodConfig;
224
- };
225
- const initStripeConnect = (stripePromise, initParams) => {
226
- var _a;
227
- const eagerClientSecretPromise = (() => {
228
- try {
229
- return initParams.fetchClientSecret();
230
- } catch (error) {
231
- return Promise.reject(error);
232
- }
233
- })();
234
- const metaOptions = (_a = initParams.metaOptions) !== null && _a !== void 0 ? _a : {};
235
- const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(Object.assign(Object.assign({}, initParams), {
236
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
237
- eagerClientSecretPromise
238
- })
239
- })));
240
- return {
241
- create: tagName => {
242
- let htmlName = componentNameMapping[tagName];
243
- if (!htmlName) {
244
- htmlName = tagName;
245
- }
246
- const element = document.createElement(htmlName);
247
- const customMethods = hasCustomMethod(tagName) ? ConnectElementCustomMethodConfig[tagName] : {};
248
- const methods = Object.assign(Object.assign({}, customMethods), ConnectElementCommonMethodConfig);
249
- for (const method in methods) {
250
- element[method] = function (value) {
251
- stripeConnectInstance.then(() => {
252
- if (!this[`${method}InternalOnly`]) {
253
- throw new Error(`Method ${method} is not available in the ${tagName} HTML element. Are you using a supported version of the "@stripe/connect-js" package? Using version: 3.3.41-preview-1`);
254
- }
255
- this[`${method}InternalOnly`](value);
256
- });
257
- };
258
- }
259
- stripeConnectInstance.then(instance => {
260
- if (!element.isConnected && !element.setConnector) {
261
- // If the element is not connected to the DOM and the `setConnector` method is not
262
- // defined, this indicates the element was created before connect.js was loaded, and has
263
- // not been transformed into a custom element yet
264
- // To load the custom element code on it, we need to connect and disconnect it to the DOM
265
- // This isn't a problem, as the element will be invisible, and we know the element is already
266
- // not currently connected to the DOM
267
- const oldDisplay = element.style.display;
268
- element.style.display = "none";
269
- document.body.appendChild(element);
270
- document.body.removeChild(element);
271
- element.style.display = oldDisplay;
272
- }
273
- if (!element || !element.setConnector) {
274
- throw new Error(`Element ${tagName} was not transformed into a custom element. Are you using a documented component? See https://docs.stripe.com/connect/supported-embedded-components for a list of supported components`);
275
- }
276
- element.setConnector(instance.connect);
277
- });
278
- return element;
279
- },
280
- update: updateOptions => {
281
- stripeConnectInstance.then(instance => {
282
- instance.update(updateOptions);
283
- });
284
- },
285
- debugInstance: () => {
286
- return stripeConnectInstance;
287
- },
288
- logout: () => {
289
- return stripeConnectInstance.then(instance => {
290
- return instance.logout();
291
- });
292
- }
293
- };
294
- };
295
- const createWrapper = stripeConnect => {
296
- window.StripeConnect = window.StripeConnect || {};
297
- window.StripeConnect.optimizedLoading = true;
298
- const wrapper = {
299
- initialize: params => {
300
- var _a;
301
- const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
302
- const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
303
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
304
- sdk: true,
305
- sdkOptions: {
306
- // This will be replaced by the npm package version when bundling
307
- sdkVersion: "3.3.41-preview-1"
308
- }
309
- })
310
- }));
311
- return stripeConnectInstance;
312
- }
313
- };
314
- return wrapper;
315
- };
316
-
317
- const loadConnectAndInitialize = initParams => {
318
- const maybeConnect = loadScript();
319
- if (initParams == null) {
320
- throw new Error("You must provide required parameters to initialize Connect");
321
- }
322
- return initStripeConnect(maybeConnect, initParams);
323
- };
324
-
325
- export { loadConnectAndInitialize };