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

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
@@ -13,72 +13,51 @@ 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
21
  | "stripe-connect-payment-disputes"
21
- | "stripe-connect-account-onboarding"
22
- | "stripe-connect-payment-method-settings"
23
22
  | "stripe-connect-account-management"
24
23
  | "stripe-connect-notification-banner"
25
- | "stripe-connect-instant-payouts"
24
+ | "stripe-connect-instant-payouts-promotion"
26
25
  | "stripe-connect-issuing-card"
27
26
  | "stripe-connect-issuing-cards-list"
28
27
  | "stripe-connect-financial-account"
29
28
  | "stripe-connect-financial-account-transactions"
30
- | "stripe-connect-recipients"
31
- | "stripe-connect-capital-financing"
32
- | "stripe-connect-capital-financing-application"
33
- | "stripe-connect-capital-financing-promotion"
34
- | "stripe-connect-capital-overview"
29
+ | "stripe-connect-payouts"
30
+ | "stripe-connect-payouts-list"
31
+ | "stripe-connect-payout-details"
32
+ | "stripe-connect-balances"
35
33
  | "stripe-connect-documents"
36
- | "stripe-connect-product-tax-code-selector"
37
- | "stripe-connect-export-tax-transactions"
38
34
  | "stripe-connect-tax-registrations"
39
- | "stripe-connect-tax-settings"
40
- | "stripe-connect-tax-threshold-monitoring"
41
- | "stripe-connect-balances"
42
- | "stripe-connect-payouts-list"
43
- | "stripe-connect-app-install"
44
- | "stripe-connect-app-viewport"
45
- | "stripe-connect-reporting-chart";
35
+ | "stripe-connect-tax-settings";
46
36
 
47
37
  export const componentNameMapping: Record<
48
38
  ConnectElementTagName,
49
39
  ConnectElementHTMLName
50
40
  > = {
41
+ "account-onboarding": "stripe-connect-account-onboarding",
42
+ "disputes-list": "stripe-connect-disputes-list",
51
43
  payments: "stripe-connect-payments",
52
- payouts: "stripe-connect-payouts",
53
44
  "payment-details": "stripe-connect-payment-details",
54
45
  "payment-disputes": "stripe-connect-payment-disputes",
55
- "account-onboarding": "stripe-connect-account-onboarding",
56
- "payment-method-settings": "stripe-connect-payment-method-settings",
46
+ payouts: "stripe-connect-payouts",
47
+ "payouts-list": "stripe-connect-payouts-list",
48
+ "payout-details": "stripe-connect-payout-details",
49
+ balances: "stripe-connect-balances",
57
50
  "account-management": "stripe-connect-account-management",
58
51
  "notification-banner": "stripe-connect-notification-banner",
59
- "instant-payouts": "stripe-connect-instant-payouts",
52
+ "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
60
53
  "issuing-card": "stripe-connect-issuing-card",
61
54
  "issuing-cards-list": "stripe-connect-issuing-cards-list",
62
55
  "financial-account": "stripe-connect-financial-account",
63
- recipients: "stripe-connect-recipients",
64
56
  "financial-account-transactions":
65
57
  "stripe-connect-financial-account-transactions",
66
- "capital-financing": "stripe-connect-capital-financing",
67
- "capital-financing-application":
68
- "stripe-connect-capital-financing-application",
69
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
70
- "capital-overview": "stripe-connect-capital-overview",
71
58
  documents: "stripe-connect-documents",
72
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
73
- "export-tax-transactions": "stripe-connect-export-tax-transactions",
74
59
  "tax-registrations": "stripe-connect-tax-registrations",
75
60
  "tax-settings": "stripe-connect-tax-settings",
76
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
77
- balances: "stripe-connect-balances",
78
- "payouts-list": "stripe-connect-payouts-list",
79
- "app-install": "stripe-connect-app-install",
80
- "app-viewport": "stripe-connect-app-viewport",
81
- "reporting-chart": "stripe-connect-reporting-chart",
82
61
  };
83
62
 
84
63
  type StripeConnectInstanceExtended = StripeConnectInstance & {
@@ -97,10 +76,10 @@ const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
97
76
  export const findScript = (): HTMLScriptElement | null => {
98
77
  return (
99
78
  document.querySelectorAll<HTMLScriptElement>(
100
- `script[src="${V0_URL}"]`
79
+ `script[src="${V1_URL}"]`
101
80
  )[0] ||
102
81
  document.querySelectorAll<HTMLScriptElement>(
103
- `script[src="${V1_URL}"]`
82
+ `script[src="${V0_URL}"]`
104
83
  )[0] ||
105
84
  null
106
85
  );
@@ -125,6 +104,20 @@ const injectScript = (): HTMLScriptElement => {
125
104
 
126
105
  let stripePromise: Promise<StripeConnectWrapper> | null = null;
127
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
+
128
121
  export const loadScript = (): Promise<StripeConnectWrapper> => {
129
122
  // Ensure that we only attempt to load Connect.js at most once
130
123
  if (stripePromise !== null) {
@@ -139,11 +132,8 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
139
132
  return;
140
133
  }
141
134
 
142
- if ((window as any).StripeConnect) {
135
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
143
136
  console.warn(EXISTING_SCRIPT_MESSAGE);
144
- }
145
-
146
- if ((window as any).StripeConnect) {
147
137
  const wrapper = createWrapper((window as any).StripeConnect);
148
138
  resolve(wrapper);
149
139
  return;
@@ -159,7 +149,7 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
159
149
  }
160
150
 
161
151
  script.addEventListener("load", () => {
162
- if ((window as any).StripeConnect) {
152
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
163
153
  const wrapper = createWrapper((window as any).StripeConnect);
164
154
  resolve(wrapper);
165
155
  } else {
@@ -218,6 +208,12 @@ export const initStripeConnect = (
218
208
  for (const method in methods) {
219
209
  (element as any)[method] = function (value: any) {
220
210
  stripeConnectInstance.then(() => {
211
+ if (!this[`${method}InternalOnly`]) {
212
+ throw new Error(
213
+ `Method ${method} is not available in the ${tagName} HTML element. Are you using a supported version of the "@stripe/connect-js" package? Using version: _NPM_PACKAGE_VERSION_`
214
+ );
215
+ }
216
+
221
217
  this[`${method}InternalOnly`](value);
222
218
  });
223
219
  };
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.
@@ -206,21 +195,6 @@ export const ConnectElementCommonMethodConfig = {
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
- "payment-disputes": {
219
- setPayment: (_payment: string | undefined): void => {},
220
- setOnDisputesLoaded: (
221
- _listener: (({ total }: { total: number }) => void) | undefined
222
- ): void => {},
223
- },
224
198
  "account-onboarding": {
225
199
  setFullTermsOfServiceUrl: (
226
200
  _termOfServiceUrl: string | undefined
@@ -255,6 +229,16 @@ export const ConnectElementCustomMethodConfig = {
255
229
  | undefined
256
230
  ): void => {},
257
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 => {},
241
+ },
258
242
  "issuing-card": {
259
243
  setDefaultCard: (_defaultCard: string | undefined): void => {},
260
244
  setCardSwitching: (_cardSwitching: boolean | undefined): void => {},
@@ -276,78 +260,21 @@ export const ConnectElementCustomMethodConfig = {
276
260
  "financial-account-transactions": {
277
261
  setFinancialAccount: (_financialAccount: string): void => {},
278
262
  },
279
- recipients: {
280
- setDataSource: (_dataSource: RecipientDataSource): void => {},
281
- },
282
- "app-install": {
283
- setApp: (_app: string | undefined): void => {},
284
- setOnAppInstallStateFetched: (
285
- _listener: (({ appId, state }: InstallState) => void) | undefined
286
- ): void => {},
287
- setOnAppInstallStateChanged: (
288
- _listener: (({ appId, state }: InstallState) => void) | undefined
263
+ payments: {
264
+ setDefaultFilters: (
265
+ _filters: PaymentsListDefaultFilters | undefined
289
266
  ): void => {},
290
267
  },
291
- "app-viewport": {
292
- setApp: (_app: string | undefined): void => {},
293
- setAppData: (_appData: Record<string, string> | undefined): void => {},
294
- },
295
- "payment-method-settings": {
296
- setPaymentMethodConfiguration: (
297
- _paymentMethodConfiguration: string | undefined
298
- ): void => {},
268
+ "payment-details": {
269
+ setPayment: (_payment: string | undefined): void => {},
270
+ setOnClose: (_listener: (() => void) | undefined): void => {},
299
271
  },
300
- "capital-financing": {
301
- setDefaultFinancingOffer: (
302
- _defaultFinancingOffer: string | undefined
303
- ): void => {},
304
- setShowFinancingSelector: (
305
- _showFinancingSelector: boolean | undefined
306
- ): void => {},
307
- setHowCapitalWorksUrl: (
308
- _howCapitalWorksUrl: string | undefined
309
- ): void => {},
310
- setSupportUrl: (_supportUrl: string | undefined): void => {},
311
- setOnFinancingsLoaded: (
272
+ "payment-disputes": {
273
+ setPayment: (_payment: string | undefined): void => {},
274
+ setOnDisputesLoaded: (
312
275
  _listener: (({ total }: { total: number }) => void) | undefined
313
276
  ): void => {},
314
277
  },
315
- "capital-financing-application": {
316
- setOnApplicationSubmitted: (
317
- _listener: (() => void) | undefined
318
- ): void => {},
319
- setPrivacyPolicyUrl: (_privacyPolicyUrl: string | undefined): void => {},
320
- setHowCapitalWorksUrl: (
321
- _howCapitalWorksUrl: string | undefined
322
- ): void => {},
323
- },
324
- "capital-financing-promotion": {
325
- setLayout: (_layout: FinancingPromotionLayoutType | undefined): void => {},
326
- setOnApplicationSubmitted: (
327
- _listener: (() => void) | undefined
328
- ): void => {},
329
- setOnEligibleFinancingOfferLoaded: (
330
- _listener:
331
- | (({
332
- productType,
333
- activeFinancingCount,
334
- }: FinancingProductType) => void)
335
- | undefined
336
- ): void => {},
337
- setPrivacyPolicyUrl: (_privacyPolicyUrl: string | undefined): void => {},
338
- setHowCapitalWorksUrl: (
339
- _howCapitalWorksUrl: string | undefined
340
- ): void => {},
341
- setEligibilityCriteriaUrl: (
342
- _eligibilityCriteriaUrl: string | undefined
343
- ): void => {},
344
- },
345
- "reporting-chart": {
346
- setReportName: (_reportName: ReportName): void => {},
347
- setIntervalStart: (_intervalStart: Date | undefined): void => {},
348
- setIntervalEnd: (_intervalEnd: Date | undefined): void => {},
349
- setIntervalType: (_intervalType: IntervalType | undefined): void => {},
350
- },
351
278
  "tax-settings": {
352
279
  setHideProductTaxCodeSelector: (_hidden: boolean | undefined): void => {},
353
280
  setDisplayHeadOfficeCountries: (
@@ -362,17 +289,12 @@ export const ConnectElementCustomMethodConfig = {
362
289
  _listener: (({ id }: { id: string }) => void) | undefined
363
290
  ): void => {},
364
291
  setDisplayCountries: (_countries: string[] | undefined): void => {},
365
- },
366
- "tax-threshold-monitoring": {
367
- setDisplayCountries: (_countries: string[] | undefined): void => {},
368
- },
369
- "product-tax-code-selector": {
370
- setOnTaxCodeSelect: (
371
- _listener: ((taxCode: string) => void) | undefined
292
+ setOnAfterTaxRegistrationExpired: (
293
+ _listener: (({ id }: { id: string }) => void) | undefined
372
294
  ): void => {},
373
- setHideDescription: (_hideDescription: boolean | undefined): void => {},
374
- setDisabled: (_disabled: boolean | undefined): void => {},
375
- setInitialTaxCode: (_initialTaxCode: string | undefined): void => {},
376
295
  },
377
- "export-tax-transactions": {},
296
+ "payout-details": {
297
+ setPayout: (_payout: string | undefined): void => {},
298
+ setOnClose: (_listener: (() => void) | undefined): void => {},
299
+ },
378
300
  };
package/types/shared.d.ts CHANGED
@@ -2,6 +2,7 @@ import type {
2
2
  ConnectElementCustomMethodConfig,
3
3
  ConnectElementCommonMethodConfig,
4
4
  } from "./config";
5
+
5
6
  export declare type LoadConnectAndInitialize = (
6
7
  initParams: IStripeConnectInitParams
7
8
  ) => StripeConnectInstance;
@@ -487,32 +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
495
  | "payment-disputes"
494
- | "account-onboarding"
495
- | "payment-method-settings"
496
496
  | "account-management"
497
497
  | "notification-banner"
498
- | "instant-payouts"
498
+ | "instant-payouts-promotion"
499
499
  | "issuing-card"
500
500
  | "issuing-cards-list"
501
501
  | "financial-account"
502
502
  | "financial-account-transactions"
503
- | "recipients"
504
- | "capital-financing"
505
- | "capital-financing-application"
506
- | "capital-financing-promotion"
507
- | "capital-overview"
503
+ | "payouts"
504
+ | "payouts-list"
505
+ | "payout-details"
506
+ | "balances"
508
507
  | "documents"
509
- | "product-tax-code-selector"
510
- | "export-tax-transactions"
511
508
  | "tax-registrations"
512
- | "tax-settings"
513
- | "tax-threshold-monitoring"
514
- | "balances"
515
- | "payouts-list"
516
- | "app-install"
517
- | "app-viewport"
518
- | "reporting-chart";
509
+ | "tax-settings";