@stripe/connect-js 3.3.28-preview-1 → 3.3.28

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/src/shared.ts CHANGED
@@ -1,80 +1,63 @@
1
- import {
1
+ import type {
2
2
  IStripeConnectInitParams,
3
3
  StripeConnectInstance,
4
4
  ConnectElementTagName,
5
- ConnectHTMLElementRecord
5
+ ConnectHTMLElementRecord,
6
6
  } from "../types";
7
7
  import {
8
8
  ConnectElementCommonMethodConfig,
9
- ConnectElementCustomMethodConfig
9
+ ConnectElementCustomMethodConfig,
10
10
  } from "../types/config";
11
11
 
12
12
  export type LoadConnectAndInitialize = (
13
13
  initParams: IStripeConnectInitParams
14
14
  ) => StripeConnectInstance;
15
15
 
16
- export type ConnectElementHTMLName =
16
+ type ConnectElementHTMLName =
17
+ | "stripe-connect-account-onboarding"
18
+ | "stripe-connect-disputes-list"
17
19
  | "stripe-connect-payments"
18
- | "stripe-connect-payouts"
19
20
  | "stripe-connect-payment-details"
20
- | "stripe-connect-account-onboarding"
21
- | "stripe-connect-payment-method-settings"
21
+ | "stripe-connect-payment-disputes"
22
22
  | "stripe-connect-account-management"
23
23
  | "stripe-connect-notification-banner"
24
- | "stripe-connect-instant-payouts"
24
+ | "stripe-connect-instant-payouts-promotion"
25
25
  | "stripe-connect-issuing-card"
26
26
  | "stripe-connect-issuing-cards-list"
27
27
  | "stripe-connect-financial-account"
28
28
  | "stripe-connect-financial-account-transactions"
29
- | "stripe-connect-recipients"
30
- | "stripe-connect-capital-financing"
31
- | "stripe-connect-capital-financing-application"
32
- | "stripe-connect-capital-financing-promotion"
33
- | "stripe-connect-capital-overview"
29
+ | "stripe-connect-payouts"
30
+ | "stripe-connect-payouts-list"
31
+ | "stripe-connect-payout-details"
32
+ | "stripe-connect-balances"
34
33
  | "stripe-connect-documents"
35
- | "stripe-connect-product-tax-code-selector"
36
34
  | "stripe-connect-tax-registrations"
37
- | "stripe-connect-tax-settings"
38
- | "stripe-connect-tax-threshold-monitoring"
39
- | "stripe-connect-balances"
40
- | "stripe-connect-payouts-list"
41
- | "stripe-connect-app-install"
42
- | "stripe-connect-app-viewport"
43
- | "stripe-connect-reporting-chart";
35
+ | "stripe-connect-tax-settings";
44
36
 
45
37
  export const componentNameMapping: Record<
46
38
  ConnectElementTagName,
47
39
  ConnectElementHTMLName
48
40
  > = {
41
+ "account-onboarding": "stripe-connect-account-onboarding",
42
+ "disputes-list": "stripe-connect-disputes-list",
49
43
  payments: "stripe-connect-payments",
50
- payouts: "stripe-connect-payouts",
51
44
  "payment-details": "stripe-connect-payment-details",
52
- "account-onboarding": "stripe-connect-account-onboarding",
53
- "payment-method-settings": "stripe-connect-payment-method-settings",
45
+ "payment-disputes": "stripe-connect-payment-disputes",
46
+ payouts: "stripe-connect-payouts",
47
+ "payouts-list": "stripe-connect-payouts-list",
48
+ "payout-details": "stripe-connect-payout-details",
49
+ balances: "stripe-connect-balances",
54
50
  "account-management": "stripe-connect-account-management",
55
51
  "notification-banner": "stripe-connect-notification-banner",
56
- "instant-payouts": "stripe-connect-instant-payouts",
52
+ "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
57
53
  "issuing-card": "stripe-connect-issuing-card",
58
54
  "issuing-cards-list": "stripe-connect-issuing-cards-list",
59
55
  "financial-account": "stripe-connect-financial-account",
60
- recipients: "stripe-connect-recipients",
61
56
  "financial-account-transactions":
62
57
  "stripe-connect-financial-account-transactions",
63
- "capital-financing": "stripe-connect-capital-financing",
64
- "capital-financing-application":
65
- "stripe-connect-capital-financing-application",
66
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
67
- "capital-overview": "stripe-connect-capital-overview",
68
58
  documents: "stripe-connect-documents",
69
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
70
59
  "tax-registrations": "stripe-connect-tax-registrations",
71
60
  "tax-settings": "stripe-connect-tax-settings",
72
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
73
- balances: "stripe-connect-balances",
74
- "payouts-list": "stripe-connect-payouts-list",
75
- "app-install": "stripe-connect-app-install",
76
- "app-viewport": "stripe-connect-app-viewport",
77
- "reporting-chart": "stripe-connect-reporting-chart"
78
61
  };
79
62
 
80
63
  type StripeConnectInstanceExtended = StripeConnectInstance & {
@@ -93,10 +76,10 @@ const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
93
76
  export const findScript = (): HTMLScriptElement | null => {
94
77
  return (
95
78
  document.querySelectorAll<HTMLScriptElement>(
96
- `script[src="${V0_URL}"]`
79
+ `script[src="${V1_URL}"]`
97
80
  )[0] ||
98
81
  document.querySelectorAll<HTMLScriptElement>(
99
- `script[src="${V1_URL}"]`
82
+ `script[src="${V0_URL}"]`
100
83
  )[0] ||
101
84
  null
102
85
  );
@@ -121,6 +104,20 @@ const injectScript = (): HTMLScriptElement => {
121
104
 
122
105
  let stripePromise: Promise<StripeConnectWrapper> | null = null;
123
106
 
107
+ export const isWindowStripeConnectDefined = (stripeConnect: unknown) => {
108
+ // We only consider `StripeConnect` defined if `init` is a function
109
+ // Why? HTML markup like:
110
+ // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
111
+ // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
112
+ return !!(
113
+ stripeConnect &&
114
+ typeof stripeConnect === "object" &&
115
+ "init" in stripeConnect &&
116
+ typeof (stripeConnect as { init: unknown } & Record<string, unknown>)
117
+ .init === "function"
118
+ );
119
+ };
120
+
124
121
  export const loadScript = (): Promise<StripeConnectWrapper> => {
125
122
  // Ensure that we only attempt to load Connect.js at most once
126
123
  if (stripePromise !== null) {
@@ -135,11 +132,8 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
135
132
  return;
136
133
  }
137
134
 
138
- if ((window as any).StripeConnect) {
135
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
139
136
  console.warn(EXISTING_SCRIPT_MESSAGE);
140
- }
141
-
142
- if ((window as any).StripeConnect) {
143
137
  const wrapper = createWrapper((window as any).StripeConnect);
144
138
  resolve(wrapper);
145
139
  return;
@@ -155,7 +149,7 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
155
149
  }
156
150
 
157
151
  script.addEventListener("load", () => {
158
- if ((window as any).StripeConnect) {
152
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
159
153
  const wrapper = createWrapper((window as any).StripeConnect);
160
154
  resolve(wrapper);
161
155
  } else {
@@ -192,18 +186,18 @@ export const initStripeConnect = (
192
186
  }
193
187
  })();
194
188
  const metaOptions = (initParams as any).metaOptions ?? {};
195
- const stripeConnectInstance = stripePromise.then(wrapper =>
189
+ const stripeConnectInstance = stripePromise.then((wrapper) =>
196
190
  wrapper.initialize({
197
191
  ...initParams,
198
- metaOptions: { ...metaOptions, eagerClientSecretPromise }
192
+ metaOptions: { ...metaOptions, eagerClientSecretPromise },
199
193
  } as any)
200
194
  );
201
195
 
202
196
  return {
203
- create: tagName => {
197
+ create: (tagName) => {
204
198
  let htmlName = componentNameMapping[tagName];
205
199
  if (!htmlName) {
206
- htmlName = (tagName as unknown) as ConnectElementHTMLName;
200
+ htmlName = tagName as unknown as ConnectElementHTMLName;
207
201
  }
208
202
  const element = document.createElement(htmlName);
209
203
 
@@ -212,14 +206,14 @@ export const initStripeConnect = (
212
206
  : {};
213
207
  const methods = { ...customMethods, ...ConnectElementCommonMethodConfig };
214
208
  for (const method in methods) {
215
- (element as any)[method] = function(value: any) {
209
+ (element as any)[method] = function (value: any) {
216
210
  stripeConnectInstance.then(() => {
217
211
  this[`${method}InternalOnly`](value);
218
212
  });
219
213
  };
220
214
  }
221
215
 
222
- stripeConnectInstance.then(instance => {
216
+ stripeConnectInstance.then((instance) => {
223
217
  if (!element.isConnected && !(element as any).setConnector) {
224
218
  // If the element is not connected to the DOM and the `setConnector` method is not
225
219
  // defined, this indicates the element was created before connect.js was loaded, and has
@@ -247,8 +241,8 @@ export const initStripeConnect = (
247
241
 
248
242
  return element as ConnectHTMLElementRecord[typeof tagName];
249
243
  },
250
- update: updateOptions => {
251
- stripeConnectInstance.then(instance => {
244
+ update: (updateOptions) => {
245
+ stripeConnectInstance.then((instance) => {
252
246
  instance.update(updateOptions);
253
247
  });
254
248
  },
@@ -256,10 +250,10 @@ export const initStripeConnect = (
256
250
  return stripeConnectInstance;
257
251
  },
258
252
  logout: () => {
259
- return stripeConnectInstance.then(instance => {
253
+ return stripeConnectInstance.then((instance) => {
260
254
  return instance.logout();
261
255
  });
262
- }
256
+ },
263
257
  };
264
258
  };
265
259
 
@@ -276,12 +270,12 @@ const createWrapper = (stripeConnect: any) => {
276
270
  sdk: true,
277
271
  sdkOptions: {
278
272
  // This will be replaced by the npm package version when bundling
279
- sdkVersion: "_NPM_PACKAGE_VERSION_"
280
- }
281
- }
273
+ sdkVersion: "_NPM_PACKAGE_VERSION_",
274
+ },
275
+ },
282
276
  });
283
277
  return stripeConnectInstance;
284
- }
278
+ },
285
279
  };
286
280
  return wrapper;
287
281
  };
package/types/checks.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ConnectElementCustomMethodConfig } from "./config";
2
- import { ConnectElementTagName } from "./shared.d";
1
+ import type { ConnectElementCustomMethodConfig } from "./config";
2
+ import type { ConnectElementTagName } from "./shared.d";
3
3
 
4
4
  // ensure that keys of ConnectElementCustomMethodConfig are from ConnectElementTagName
5
5
  export type HasType<T, Q extends T> = Q;
package/types/config.ts CHANGED
@@ -134,11 +134,6 @@ export type NotificationCount = {
134
134
  actionRequired: number;
135
135
  };
136
136
 
137
- export type InstallState = {
138
- appId: string;
139
- state: "INSTALLED" | "UNINSTALLED";
140
- };
141
-
142
137
  export type LoaderStart = {
143
138
  elementTagName: string;
144
139
  };
@@ -157,19 +152,6 @@ export type EmbeddedError = {
157
152
  message?: string;
158
153
  };
159
154
 
160
- export type FinancingProductType = {
161
- productType: "standard" | "refill" | "none";
162
- activeFinancingCount: number;
163
- };
164
-
165
- export type FinancingPromotionLayoutType = "full" | "banner";
166
-
167
- export type IntervalType = "day" | "week" | "month" | "quarter" | "year";
168
-
169
- export type ReportName = "gross_volume" | "net_volume";
170
-
171
- export type RecipientDataSource = "customers";
172
-
173
155
  export type EmbeddedErrorType =
174
156
  /**
175
157
  * Failure to connect to Stripe's API.
@@ -202,19 +184,10 @@ export const ConnectElementCommonMethodConfig = {
202
184
  ): void => {},
203
185
  setOnLoaderStart: (
204
186
  _listener: (({ elementTagName }: LoaderStart) => void) | undefined
205
- ): void => {}
187
+ ): void => {},
206
188
  };
207
189
 
208
190
  export const ConnectElementCustomMethodConfig = {
209
- payments: {
210
- setDefaultFilters: (
211
- _filters: PaymentsListDefaultFilters | undefined
212
- ): void => {}
213
- },
214
- "payment-details": {
215
- setPayment: (_payment: string | undefined): void => {},
216
- setOnClose: (_listener: (() => void) | undefined): void => {}
217
- },
218
191
  "account-onboarding": {
219
192
  setFullTermsOfServiceUrl: (
220
193
  _termOfServiceUrl: string | undefined
@@ -232,12 +205,12 @@ export const ConnectElementCustomMethodConfig = {
232
205
  setOnExit: (_listener: (() => void) | undefined): void => {},
233
206
  setOnStepChange: (
234
207
  _listener: (({ step }: StepChange) => void) | undefined
235
- ): void => {}
208
+ ): void => {},
236
209
  },
237
210
  "account-management": {
238
211
  setCollectionOptions: (
239
212
  _collectionOptions: CollectionOptions | undefined
240
- ): void => {}
213
+ ): void => {},
241
214
  },
242
215
  "notification-banner": {
243
216
  setCollectionOptions: (
@@ -247,7 +220,17 @@ export const ConnectElementCustomMethodConfig = {
247
220
  _listener:
248
221
  | (({ total, actionRequired }: NotificationCount) => void)
249
222
  | undefined
250
- ): void => {}
223
+ ): void => {},
224
+ },
225
+ "instant-payouts-promotion": {
226
+ setOnInstantPayoutsPromotionLoaded: (
227
+ _listener:
228
+ | (({ promotionShown }: { promotionShown: boolean }) => void)
229
+ | undefined
230
+ ): void => {},
231
+ setOnInstantPayoutCreated: (
232
+ _listener: (({ payoutId }: { payoutId: string }) => void) | undefined
233
+ ): void => {},
251
234
  },
252
235
  "issuing-card": {
253
236
  setDefaultCard: (_defaultCard: string | undefined): void => {},
@@ -255,90 +238,35 @@ export const ConnectElementCustomMethodConfig = {
255
238
  setFetchEphemeralKey: (
256
239
  _fetchEphemeralKey: FetchEphemeralKeyFunction | undefined
257
240
  ): void => {},
258
- setShowSpendControls: (_showSpendControls: boolean | undefined): void => {}
241
+ setShowSpendControls: (_showSpendControls: boolean | undefined): void => {},
259
242
  },
260
243
  "issuing-cards-list": {
261
244
  setFetchEphemeralKey: (
262
245
  _fetchEphemeralKey: FetchEphemeralKeyFunction | undefined
263
246
  ): void => {},
264
247
  setShowSpendControls: (_showSpendControls: boolean | undefined): void => {},
265
- setIssuingProgram: (_issuingProgram: string | undefined): void => {}
248
+ setIssuingProgram: (_issuingProgram: string | undefined): void => {},
266
249
  },
267
250
  "financial-account": {
268
- setFinancialAccount: (_financialAccount: string): void => {}
251
+ setFinancialAccount: (_financialAccount: string): void => {},
269
252
  },
270
253
  "financial-account-transactions": {
271
- setFinancialAccount: (_financialAccount: string): void => {}
272
- },
273
- recipients: {
274
- setDataSource: (_dataSource: RecipientDataSource): void => {}
254
+ setFinancialAccount: (_financialAccount: string): void => {},
275
255
  },
276
- "app-install": {
277
- setApp: (_app: string | undefined): void => {},
278
- setOnAppInstallStateFetched: (
279
- _listener: (({ appId, state }: InstallState) => void) | undefined
256
+ payments: {
257
+ setDefaultFilters: (
258
+ _filters: PaymentsListDefaultFilters | undefined
280
259
  ): void => {},
281
- setOnAppInstallStateChanged: (
282
- _listener: (({ appId, state }: InstallState) => void) | undefined
283
- ): void => {}
284
- },
285
- "app-viewport": {
286
- setApp: (_app: string | undefined): void => {},
287
- setAppData: (_appData: Record<string, string> | undefined): void => {}
288
260
  },
289
- "payment-method-settings": {
290
- setPaymentMethodConfiguration: (
291
- _paymentMethodConfiguration: string | undefined
292
- ): void => {}
261
+ "payment-details": {
262
+ setPayment: (_payment: string | undefined): void => {},
263
+ setOnClose: (_listener: (() => void) | undefined): void => {},
293
264
  },
294
- "capital-financing": {
295
- setDefaultFinancingOffer: (
296
- _defaultFinancingOffer: string | undefined
297
- ): void => {},
298
- setShowFinancingSelector: (
299
- _showFinancingSelector: boolean | undefined
300
- ): void => {},
301
- setHowCapitalWorksUrl: (
302
- _howCapitalWorksUrl: string | undefined
303
- ): void => {},
304
- setSupportUrl: (_supportUrl: string | undefined): void => {},
305
- setOnFinancingsLoaded: (
265
+ "payment-disputes": {
266
+ setPayment: (_payment: string | undefined): void => {},
267
+ setOnDisputesLoaded: (
306
268
  _listener: (({ total }: { total: number }) => void) | undefined
307
- ): void => {}
308
- },
309
- "capital-financing-application": {
310
- setOnApplicationSubmitted: (
311
- _listener: (() => void) | undefined
312
- ): void => {},
313
- setPrivacyPolicyUrl: (_privacyPolicyUrl: string | undefined): void => {},
314
- setHowCapitalWorksUrl: (_howCapitalWorksUrl: string | undefined): void => {}
315
- },
316
- "capital-financing-promotion": {
317
- setLayout: (_layout: FinancingPromotionLayoutType | undefined): void => {},
318
- setOnApplicationSubmitted: (
319
- _listener: (() => void) | undefined
320
- ): void => {},
321
- setOnEligibleFinancingOfferLoaded: (
322
- _listener:
323
- | (({
324
- productType,
325
- activeFinancingCount
326
- }: FinancingProductType) => void)
327
- | undefined
328
- ): void => {},
329
- setPrivacyPolicyUrl: (_privacyPolicyUrl: string | undefined): void => {},
330
- setHowCapitalWorksUrl: (
331
- _howCapitalWorksUrl: string | undefined
332
269
  ): void => {},
333
- setEligibilityCriteriaUrl: (
334
- _eligibilityCriteriaUrl: string | undefined
335
- ): void => {}
336
- },
337
- "reporting-chart": {
338
- setReportName: (_reportName: ReportName): void => {},
339
- setIntervalStart: (_intervalStart: Date | undefined): void => {},
340
- setIntervalEnd: (_intervalEnd: Date | undefined): void => {},
341
- setIntervalType: (_intervalType: IntervalType | undefined): void => {}
342
270
  },
343
271
  "tax-settings": {
344
272
  setHideProductTaxCodeSelector: (_hidden: boolean | undefined): void => {},
@@ -347,23 +275,16 @@ export const ConnectElementCustomMethodConfig = {
347
275
  ): void => {},
348
276
  setOnTaxSettingsUpdated: (
349
277
  _listener: (({ id }: { id: string }) => void) | undefined
350
- ): void => {}
278
+ ): void => {},
351
279
  },
352
280
  "tax-registrations": {
353
281
  setOnAfterTaxRegistrationAdded: (
354
282
  _listener: (({ id }: { id: string }) => void) | undefined
355
283
  ): void => {},
356
- setDisplayCountries: (_countries: string[] | undefined): void => {}
284
+ setDisplayCountries: (_countries: string[] | undefined): void => {},
357
285
  },
358
- "tax-threshold-monitoring": {
359
- setDisplayCountries: (_countries: string[] | undefined): void => {}
286
+ "payout-details": {
287
+ setPayout: (_payout: string | undefined): void => {},
288
+ setOnClose: (_listener: (() => void) | undefined): void => {},
360
289
  },
361
- "product-tax-code-selector": {
362
- setOnTaxCodeSelect: (
363
- _listener: (({ taxCode }: { taxCode: string }) => void) | undefined
364
- ): void => {},
365
- setHideDescription: (_hideDescription: boolean | undefined): void => {},
366
- setDisabled: (_disabled: boolean | undefined): void => {},
367
- setInitialTaxCode: (_initialTaxCode: string | undefined): void => {}
368
- }
369
290
  };
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IStripeConnectInitParams, StripeConnectInstance } from "../types";
1
+ import type { IStripeConnectInitParams, StripeConnectInstance } from "../types";
2
2
 
3
3
  export declare const loadConnectAndInitialize: (
4
4
  initParams: IStripeConnectInitParams
package/types/shared.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import {
1
+ import type {
2
2
  ConnectElementCustomMethodConfig,
3
- ConnectElementCommonMethodConfig
3
+ ConnectElementCommonMethodConfig,
4
4
  } from "./config";
5
+
5
6
  export declare type LoadConnectAndInitialize = (
6
7
  initParams: IStripeConnectInitParams
7
8
  ) => StripeConnectInstance;
@@ -487,30 +488,22 @@ export interface StripeConnectInstance {
487
488
  * Tagnames to be used with the `create` method of the Connect instance.
488
489
  */
489
490
  export type ConnectElementTagName =
491
+ | "account-onboarding"
492
+ | "disputes-list"
490
493
  | "payments"
491
- | "payouts"
492
494
  | "payment-details"
493
- | "account-onboarding"
494
- | "payment-method-settings"
495
+ | "payment-disputes"
495
496
  | "account-management"
496
497
  | "notification-banner"
497
- | "instant-payouts"
498
+ | "instant-payouts-promotion"
498
499
  | "issuing-card"
499
500
  | "issuing-cards-list"
500
501
  | "financial-account"
501
502
  | "financial-account-transactions"
502
- | "recipients"
503
- | "capital-financing"
504
- | "capital-financing-application"
505
- | "capital-financing-promotion"
506
- | "capital-overview"
503
+ | "payouts"
504
+ | "payouts-list"
505
+ | "payout-details"
506
+ | "balances"
507
507
  | "documents"
508
- | "product-tax-code-selector"
509
508
  | "tax-registrations"
510
- | "tax-settings"
511
- | "tax-threshold-monitoring"
512
- | "balances"
513
- | "payouts-list"
514
- | "app-install"
515
- | "app-viewport"
516
- | "reporting-chart";
509
+ | "tax-settings";