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

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,82 +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
- | "stripe-connect-export-tax-transactions"
37
34
  | "stripe-connect-tax-registrations"
38
- | "stripe-connect-tax-settings"
39
- | "stripe-connect-tax-threshold-monitoring"
40
- | "stripe-connect-balances"
41
- | "stripe-connect-payouts-list"
42
- | "stripe-connect-app-install"
43
- | "stripe-connect-app-viewport"
44
- | "stripe-connect-reporting-chart";
35
+ | "stripe-connect-tax-settings";
45
36
 
46
37
  export const componentNameMapping: Record<
47
38
  ConnectElementTagName,
48
39
  ConnectElementHTMLName
49
40
  > = {
41
+ "account-onboarding": "stripe-connect-account-onboarding",
42
+ "disputes-list": "stripe-connect-disputes-list",
50
43
  payments: "stripe-connect-payments",
51
- payouts: "stripe-connect-payouts",
52
44
  "payment-details": "stripe-connect-payment-details",
53
- "account-onboarding": "stripe-connect-account-onboarding",
54
- "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",
55
50
  "account-management": "stripe-connect-account-management",
56
51
  "notification-banner": "stripe-connect-notification-banner",
57
- "instant-payouts": "stripe-connect-instant-payouts",
52
+ "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
58
53
  "issuing-card": "stripe-connect-issuing-card",
59
54
  "issuing-cards-list": "stripe-connect-issuing-cards-list",
60
55
  "financial-account": "stripe-connect-financial-account",
61
- recipients: "stripe-connect-recipients",
62
56
  "financial-account-transactions":
63
57
  "stripe-connect-financial-account-transactions",
64
- "capital-financing": "stripe-connect-capital-financing",
65
- "capital-financing-application":
66
- "stripe-connect-capital-financing-application",
67
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
68
- "capital-overview": "stripe-connect-capital-overview",
69
58
  documents: "stripe-connect-documents",
70
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
71
- "export-tax-transactions": "stripe-connect-export-tax-transactions",
72
59
  "tax-registrations": "stripe-connect-tax-registrations",
73
60
  "tax-settings": "stripe-connect-tax-settings",
74
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
75
- balances: "stripe-connect-balances",
76
- "payouts-list": "stripe-connect-payouts-list",
77
- "app-install": "stripe-connect-app-install",
78
- "app-viewport": "stripe-connect-app-viewport",
79
- "reporting-chart": "stripe-connect-reporting-chart"
80
61
  };
81
62
 
82
63
  type StripeConnectInstanceExtended = StripeConnectInstance & {
@@ -95,10 +76,10 @@ const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
95
76
  export const findScript = (): HTMLScriptElement | null => {
96
77
  return (
97
78
  document.querySelectorAll<HTMLScriptElement>(
98
- `script[src="${V0_URL}"]`
79
+ `script[src="${V1_URL}"]`
99
80
  )[0] ||
100
81
  document.querySelectorAll<HTMLScriptElement>(
101
- `script[src="${V1_URL}"]`
82
+ `script[src="${V0_URL}"]`
102
83
  )[0] ||
103
84
  null
104
85
  );
@@ -123,6 +104,20 @@ const injectScript = (): HTMLScriptElement => {
123
104
 
124
105
  let stripePromise: Promise<StripeConnectWrapper> | null = null;
125
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
+
126
121
  export const loadScript = (): Promise<StripeConnectWrapper> => {
127
122
  // Ensure that we only attempt to load Connect.js at most once
128
123
  if (stripePromise !== null) {
@@ -137,11 +132,8 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
137
132
  return;
138
133
  }
139
134
 
140
- if ((window as any).StripeConnect) {
135
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
141
136
  console.warn(EXISTING_SCRIPT_MESSAGE);
142
- }
143
-
144
- if ((window as any).StripeConnect) {
145
137
  const wrapper = createWrapper((window as any).StripeConnect);
146
138
  resolve(wrapper);
147
139
  return;
@@ -157,7 +149,7 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
157
149
  }
158
150
 
159
151
  script.addEventListener("load", () => {
160
- if ((window as any).StripeConnect) {
152
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
161
153
  const wrapper = createWrapper((window as any).StripeConnect);
162
154
  resolve(wrapper);
163
155
  } else {
@@ -194,18 +186,18 @@ export const initStripeConnect = (
194
186
  }
195
187
  })();
196
188
  const metaOptions = (initParams as any).metaOptions ?? {};
197
- const stripeConnectInstance = stripePromise.then(wrapper =>
189
+ const stripeConnectInstance = stripePromise.then((wrapper) =>
198
190
  wrapper.initialize({
199
191
  ...initParams,
200
- metaOptions: { ...metaOptions, eagerClientSecretPromise }
192
+ metaOptions: { ...metaOptions, eagerClientSecretPromise },
201
193
  } as any)
202
194
  );
203
195
 
204
196
  return {
205
- create: tagName => {
197
+ create: (tagName) => {
206
198
  let htmlName = componentNameMapping[tagName];
207
199
  if (!htmlName) {
208
- htmlName = (tagName as unknown) as ConnectElementHTMLName;
200
+ htmlName = tagName as unknown as ConnectElementHTMLName;
209
201
  }
210
202
  const element = document.createElement(htmlName);
211
203
 
@@ -214,14 +206,14 @@ export const initStripeConnect = (
214
206
  : {};
215
207
  const methods = { ...customMethods, ...ConnectElementCommonMethodConfig };
216
208
  for (const method in methods) {
217
- (element as any)[method] = function(value: any) {
209
+ (element as any)[method] = function (value: any) {
218
210
  stripeConnectInstance.then(() => {
219
211
  this[`${method}InternalOnly`](value);
220
212
  });
221
213
  };
222
214
  }
223
215
 
224
- stripeConnectInstance.then(instance => {
216
+ stripeConnectInstance.then((instance) => {
225
217
  if (!element.isConnected && !(element as any).setConnector) {
226
218
  // If the element is not connected to the DOM and the `setConnector` method is not
227
219
  // defined, this indicates the element was created before connect.js was loaded, and has
@@ -249,8 +241,8 @@ export const initStripeConnect = (
249
241
 
250
242
  return element as ConnectHTMLElementRecord[typeof tagName];
251
243
  },
252
- update: updateOptions => {
253
- stripeConnectInstance.then(instance => {
244
+ update: (updateOptions) => {
245
+ stripeConnectInstance.then((instance) => {
254
246
  instance.update(updateOptions);
255
247
  });
256
248
  },
@@ -258,10 +250,10 @@ export const initStripeConnect = (
258
250
  return stripeConnectInstance;
259
251
  },
260
252
  logout: () => {
261
- return stripeConnectInstance.then(instance => {
253
+ return stripeConnectInstance.then((instance) => {
262
254
  return instance.logout();
263
255
  });
264
- }
256
+ },
265
257
  };
266
258
  };
267
259
 
@@ -278,12 +270,12 @@ const createWrapper = (stripeConnect: any) => {
278
270
  sdk: true,
279
271
  sdkOptions: {
280
272
  // This will be replaced by the npm package version when bundling
281
- sdkVersion: "_NPM_PACKAGE_VERSION_"
282
- }
283
- }
273
+ sdkVersion: "_NPM_PACKAGE_VERSION_",
274
+ },
275
+ },
284
276
  });
285
277
  return stripeConnectInstance;
286
- }
278
+ },
287
279
  };
288
280
  return wrapper;
289
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
@@ -13,6 +13,13 @@ export type FetchEphemeralKeyFunction = (fetchParams: {
13
13
  export type CollectionOptions = {
14
14
  fields: "currently_due" | "eventually_due";
15
15
  futureRequirements?: "omit" | "include";
16
+ requirements?:
17
+ | {
18
+ only: string[];
19
+ }
20
+ | {
21
+ exclude: string[];
22
+ };
16
23
  };
17
24
 
18
25
  export type Status =
@@ -134,11 +141,6 @@ export type NotificationCount = {
134
141
  actionRequired: number;
135
142
  };
136
143
 
137
- export type InstallState = {
138
- appId: string;
139
- state: "INSTALLED" | "UNINSTALLED";
140
- };
141
-
142
144
  export type LoaderStart = {
143
145
  elementTagName: string;
144
146
  };
@@ -157,19 +159,6 @@ export type EmbeddedError = {
157
159
  message?: string;
158
160
  };
159
161
 
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
162
  export type EmbeddedErrorType =
174
163
  /**
175
164
  * Failure to connect to Stripe's API.
@@ -202,19 +191,10 @@ export const ConnectElementCommonMethodConfig = {
202
191
  ): void => {},
203
192
  setOnLoaderStart: (
204
193
  _listener: (({ elementTagName }: LoaderStart) => void) | undefined
205
- ): void => {}
194
+ ): void => {},
206
195
  };
207
196
 
208
197
  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
198
  "account-onboarding": {
219
199
  setFullTermsOfServiceUrl: (
220
200
  _termOfServiceUrl: string | undefined
@@ -232,12 +212,12 @@ export const ConnectElementCustomMethodConfig = {
232
212
  setOnExit: (_listener: (() => void) | undefined): void => {},
233
213
  setOnStepChange: (
234
214
  _listener: (({ step }: StepChange) => void) | undefined
235
- ): void => {}
215
+ ): void => {},
236
216
  },
237
217
  "account-management": {
238
218
  setCollectionOptions: (
239
219
  _collectionOptions: CollectionOptions | undefined
240
- ): void => {}
220
+ ): void => {},
241
221
  },
242
222
  "notification-banner": {
243
223
  setCollectionOptions: (
@@ -247,7 +227,17 @@ export const ConnectElementCustomMethodConfig = {
247
227
  _listener:
248
228
  | (({ total, actionRequired }: NotificationCount) => void)
249
229
  | undefined
250
- ): void => {}
230
+ ): void => {},
231
+ },
232
+ "instant-payouts-promotion": {
233
+ setOnInstantPayoutsPromotionLoaded: (
234
+ _listener:
235
+ | (({ promotionShown }: { promotionShown: boolean }) => void)
236
+ | undefined
237
+ ): void => {},
238
+ setOnInstantPayoutCreated: (
239
+ _listener: (({ payoutId }: { payoutId: string }) => void) | undefined
240
+ ): void => {},
251
241
  },
252
242
  "issuing-card": {
253
243
  setDefaultCard: (_defaultCard: string | undefined): void => {},
@@ -255,90 +245,35 @@ export const ConnectElementCustomMethodConfig = {
255
245
  setFetchEphemeralKey: (
256
246
  _fetchEphemeralKey: FetchEphemeralKeyFunction | undefined
257
247
  ): void => {},
258
- setShowSpendControls: (_showSpendControls: boolean | undefined): void => {}
248
+ setShowSpendControls: (_showSpendControls: boolean | undefined): void => {},
259
249
  },
260
250
  "issuing-cards-list": {
261
251
  setFetchEphemeralKey: (
262
252
  _fetchEphemeralKey: FetchEphemeralKeyFunction | undefined
263
253
  ): void => {},
264
254
  setShowSpendControls: (_showSpendControls: boolean | undefined): void => {},
265
- setIssuingProgram: (_issuingProgram: string | undefined): void => {}
255
+ setIssuingProgram: (_issuingProgram: string | undefined): void => {},
266
256
  },
267
257
  "financial-account": {
268
- setFinancialAccount: (_financialAccount: string): void => {}
258
+ setFinancialAccount: (_financialAccount: string): void => {},
269
259
  },
270
260
  "financial-account-transactions": {
271
- setFinancialAccount: (_financialAccount: string): void => {}
261
+ setFinancialAccount: (_financialAccount: string): void => {},
272
262
  },
273
- recipients: {
274
- setDataSource: (_dataSource: RecipientDataSource): void => {}
275
- },
276
- "app-install": {
277
- setApp: (_app: string | undefined): void => {},
278
- setOnAppInstallStateFetched: (
279
- _listener: (({ appId, state }: InstallState) => void) | undefined
263
+ payments: {
264
+ setDefaultFilters: (
265
+ _filters: PaymentsListDefaultFilters | undefined
280
266
  ): 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
267
  },
289
- "payment-method-settings": {
290
- setPaymentMethodConfiguration: (
291
- _paymentMethodConfiguration: string | undefined
292
- ): void => {}
268
+ "payment-details": {
269
+ setPayment: (_payment: string | undefined): void => {},
270
+ setOnClose: (_listener: (() => void) | undefined): void => {},
293
271
  },
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: (
272
+ "payment-disputes": {
273
+ setPayment: (_payment: string | undefined): void => {},
274
+ setOnDisputesLoaded: (
306
275
  _listener: (({ total }: { total: number }) => void) | undefined
307
- ): void => {}
308
- },
309
- "capital-financing-application": {
310
- setOnApplicationSubmitted: (
311
- _listener: (() => void) | undefined
312
276
  ): 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
- ): 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
277
  },
343
278
  "tax-settings": {
344
279
  setHideProductTaxCodeSelector: (_hidden: boolean | undefined): void => {},
@@ -347,24 +282,16 @@ export const ConnectElementCustomMethodConfig = {
347
282
  ): void => {},
348
283
  setOnTaxSettingsUpdated: (
349
284
  _listener: (({ id }: { id: string }) => void) | undefined
350
- ): void => {}
285
+ ): void => {},
351
286
  },
352
287
  "tax-registrations": {
353
288
  setOnAfterTaxRegistrationAdded: (
354
289
  _listener: (({ id }: { id: string }) => void) | undefined
355
290
  ): void => {},
356
- setDisplayCountries: (_countries: string[] | undefined): void => {}
357
- },
358
- "tax-threshold-monitoring": {
359
- setDisplayCountries: (_countries: string[] | undefined): void => {}
291
+ setDisplayCountries: (_countries: string[] | undefined): void => {},
360
292
  },
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 => {}
293
+ "payout-details": {
294
+ setPayout: (_payout: string | undefined): void => {},
295
+ setOnClose: (_listener: (() => void) | undefined): void => {},
368
296
  },
369
- "export-tax-transactions": {}
370
297
  };
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,31 +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
- | "export-tax-transactions"
510
508
  | "tax-registrations"
511
- | "tax-settings"
512
- | "tax-threshold-monitoring"
513
- | "balances"
514
- | "payouts-list"
515
- | "app-install"
516
- | "app-viewport"
517
- | "reporting-chart";
509
+ | "tax-settings";