@stripe/connect-js 3.3.54-preview-1 → 3.4.1-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/pure.js CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /* eslint-disable @typescript-eslint/no-empty-function */
6
5
  /* eslint-disable @typescript-eslint/no-unused-vars */
6
+ // Source of truth for the entire list of components. When you add a new component, it should be added here.
7
+ const connectElementTagNames = ["payments", "payouts", "payment-details", "payment-disputes", "disputes-list", "account-onboarding", "payment-method-settings", "account-management", "notification-banner", "instant-payouts", "instant-payouts-promotion", "issuing-card", "issuing-cards-list", "financial-account", "financial-account-transactions", "recipients", "capital-financing", "capital-financing-application", "capital-financing-promotion", "capital-overview", "documents", "product-tax-code-selector", "export-tax-transactions", "tax-registrations", "tax-settings", "tax-threshold-monitoring", "balances", "payouts-list", "payout-details", "app-install", "app-viewport", "reporting-chart", "check-scanning", "agentic-commerce-settings", "terminal-hardware-orders", "terminal-hardware-shop", "network-cost-passthrough-report", "balance-report", "payout-reconciliation-report", "recipients-list", "financial-accounts", "financial-accounts-transactions"];
7
8
  const ConnectElementCommonMethodConfig = {
8
9
  setOnLoadError: _listener => {},
9
10
  setOnLoaderStart: _listener => {}
@@ -139,52 +140,11 @@ const ConnectElementCustomMethodConfig = {
139
140
  }
140
141
  };
141
142
 
142
- const componentNameMapping = {
143
- payments: "stripe-connect-payments",
144
- payouts: "stripe-connect-payouts",
145
- "payment-details": "stripe-connect-payment-details",
146
- "payment-disputes": "stripe-connect-payment-disputes",
147
- "disputes-list": "stripe-connect-disputes-list",
148
- "account-onboarding": "stripe-connect-account-onboarding",
149
- "payment-method-settings": "stripe-connect-payment-method-settings",
150
- "account-management": "stripe-connect-account-management",
151
- "notification-banner": "stripe-connect-notification-banner",
152
- "instant-payouts": "stripe-connect-instant-payouts",
153
- "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
154
- "issuing-card": "stripe-connect-issuing-card",
155
- "issuing-cards-list": "stripe-connect-issuing-cards-list",
156
- "financial-account": "stripe-connect-financial-account",
157
- recipients: "stripe-connect-recipients",
158
- "financial-account-transactions": "stripe-connect-financial-account-transactions",
159
- "capital-financing": "stripe-connect-capital-financing",
160
- "capital-financing-application": "stripe-connect-capital-financing-application",
161
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
162
- "capital-overview": "stripe-connect-capital-overview",
163
- documents: "stripe-connect-documents",
164
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
165
- "export-tax-transactions": "stripe-connect-export-tax-transactions",
166
- "tax-registrations": "stripe-connect-tax-registrations",
167
- "tax-settings": "stripe-connect-tax-settings",
168
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
169
- balances: "stripe-connect-balances",
170
- "payouts-list": "stripe-connect-payouts-list",
171
- "payout-details": "stripe-connect-payout-details",
172
- "app-install": "stripe-connect-app-install",
173
- "app-viewport": "stripe-connect-app-viewport",
174
- "reporting-chart": "stripe-connect-reporting-chart",
175
- "check-scanning": "stripe-connect-check-scanning",
176
- "agentic-commerce-settings": "stripe-connect-agentic-commerce-settings",
177
- "terminal-hardware-orders": "stripe-connect-terminal-hardware-orders",
178
- "terminal-hardware-shop": "stripe-connect-terminal-hardware-shop",
179
- "network-cost-passthrough-report": "stripe-connect-network-cost-passthrough-report",
180
- "balance-report": "stripe-connect-balance-report",
181
- "payout-reconciliation-report": "stripe-connect-payout-reconciliation-report"
182
- };
183
143
  const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
184
144
  const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
185
145
  const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
186
146
  const findScript = () => {
187
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || null;
147
+ return document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || null;
188
148
  };
189
149
  const injectScript = () => {
190
150
  const script = document.createElement("script");
@@ -196,6 +156,11 @@ const injectScript = () => {
196
156
  document.head.appendChild(script);
197
157
  return script;
198
158
  };
159
+
160
+ const componentNameMapping = connectElementTagNames.reduce((acc, name) => {
161
+ acc[name] = `stripe-connect-${name}`;
162
+ return acc;
163
+ }, {});
199
164
  let stripePromise = null;
200
165
  const isWindowStripeConnectDefined = stripeConnect => {
201
166
  // We only consider `StripeConnect` defined if `init` is a function
@@ -275,7 +240,7 @@ const initStripeConnect = (stripePromise, initParams) => {
275
240
  element[method] = function (value) {
276
241
  stripeConnectInstance.then(() => {
277
242
  if (!this[`${method}InternalOnly`]) {
278
- 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.54-preview-1`);
243
+ 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.4.1-preview-1`);
279
244
  }
280
245
  this[`${method}InternalOnly`](value);
281
246
  });
@@ -329,7 +294,7 @@ const createWrapper = stripeConnect => {
329
294
  sdk: true,
330
295
  sdkOptions: {
331
296
  // This will be replaced by the npm package version when bundling
332
- sdkVersion: "3.3.54-preview-1"
297
+ sdkVersion: "3.4.1-preview-1"
333
298
  }
334
299
  })
335
300
  }));
@@ -347,4 +312,7 @@ const loadConnectAndInitialize = initParams => {
347
312
  return initStripeConnect(maybeConnect, initParams);
348
313
  };
349
314
 
315
+ exports.ConnectElementCommonMethodConfig = ConnectElementCommonMethodConfig;
316
+ exports.ConnectElementCustomMethodConfig = ConnectElementCustomMethodConfig;
317
+ exports.connectElementTagNames = connectElementTagNames;
350
318
  exports.loadConnectAndInitialize = loadConnectAndInitialize;
@@ -0,0 +1,3 @@
1
+ export declare const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
2
+ export declare const findScript: () => HTMLScriptElement | null;
3
+ export declare const injectScript: () => HTMLScriptElement;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@stripe/connect-js",
3
- "version": "3.3.54-preview-1",
3
+ "version": "3.4.1-preview-1",
4
4
  "description": "Connect.js loading utility package (preview version)",
5
5
  "main": "dist/connect.js",
6
6
  "module": "dist/connect.esm.js",
7
- "types": "types/index.d.ts",
8
- "typings": "types/index.d.ts",
7
+ "types": "dist/index.d.ts",
8
+ "typings": "dist/index.d.ts",
9
9
  "scripts": {
10
10
  "test": "yarn lint && yarn test:unit --passWithNoTests && yarn typecheck && yarn build",
11
11
  "test:unit": "jest",
package/pure.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import { LoadConnectAndInitialize } from "./src/shared";
2
-
3
- export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
4
- export * from "./types/shared";
1
+ // A simple "redirect" to the pure exports in src
2
+ export * from "./src/pure";
@@ -1,6 +1,53 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
2
 
3
+ // Source of truth for the entire list of components. When you add a new component, it should be added here.
4
+ export const connectElementTagNames = [
5
+ "payments",
6
+ "payouts",
7
+ "payment-details",
8
+ "payment-disputes",
9
+ "disputes-list",
10
+ "account-onboarding",
11
+ "payment-method-settings",
12
+ "account-management",
13
+ "notification-banner",
14
+ "instant-payouts",
15
+ "instant-payouts-promotion",
16
+ "issuing-card",
17
+ "issuing-cards-list",
18
+ "financial-account",
19
+ "financial-account-transactions",
20
+ "recipients",
21
+ "capital-financing",
22
+ "capital-financing-application",
23
+ "capital-financing-promotion",
24
+ "capital-overview",
25
+ "documents",
26
+ "product-tax-code-selector",
27
+ "export-tax-transactions",
28
+ "tax-registrations",
29
+ "tax-settings",
30
+ "tax-threshold-monitoring",
31
+ "balances",
32
+ "payouts-list",
33
+ "payout-details",
34
+ "app-install",
35
+ "app-viewport",
36
+ "reporting-chart",
37
+ "check-scanning",
38
+ "agentic-commerce-settings",
39
+ "terminal-hardware-orders",
40
+ "terminal-hardware-shop",
41
+ "network-cost-passthrough-report",
42
+ "balance-report",
43
+ "payout-reconciliation-report",
44
+ "recipients-list",
45
+ "financial-accounts",
46
+ "financial-accounts-transactions",
47
+ ] as const;
48
+
49
+ // BEGIN: Setter definitions. All setters and their associated types are defined here. When adding a new component, if it has setters, they should be added here as well.
50
+
4
51
  export type FetchEphemeralKeyFunction = (fetchParams: {
5
52
  issuingCard: string;
6
53
  nonce: string;
@@ -1,5 +1,5 @@
1
- import type { ConnectElementCustomMethodConfig } from "./config";
2
- import type { ConnectElementTagName } from "./shared.d";
1
+ import type { ConnectElementTagName } from "../exportedTypes";
2
+ import type { ConnectElementCustomMethodConfig } from "./componentsAndSetters";
3
3
 
4
4
  // ensure that keys of ConnectElementCustomMethodConfig are from ConnectElementTagName
5
5
  export type HasType<T, Q extends T> = Q;
@@ -0,0 +1,4 @@
1
+ // We export all types in this folder
2
+
3
+ export * from "./shared";
4
+ export * from "../components/componentsAndSetters";
@@ -1,19 +1,25 @@
1
1
  import type {
2
- ConnectElementCustomMethodConfig,
3
2
  ConnectElementCommonMethodConfig,
3
+ ConnectElementCustomMethodConfig,
4
+ connectElementTagNames,
4
5
  EmbeddedError,
5
6
  EmbeddedErrorType,
6
- } from "./config";
7
- export declare type LoadConnectAndInitialize = (
7
+ } from "../components/componentsAndSetters";
8
+
9
+ export type LoadConnectAndInitialize = (
8
10
  initParams: IStripeConnectInitParams
9
11
  ) => StripeConnectInstance;
10
12
 
11
- export declare type OverlayOption = "dialog" | "drawer";
13
+ export interface StripeConnectWrapper {
14
+ initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
15
+ }
16
+
17
+ export type OverlayOption = "dialog" | "drawer";
12
18
 
13
19
  /*
14
20
  * Use a `CssFontSource` to pass custom fonts via a stylesheet URL when initializing a Connect instance.
15
21
  */
16
- export declare type CssFontSource = {
22
+ export type CssFontSource = {
17
23
  /**
18
24
  * A relative or absolute URL pointing to a CSS file with [@font-face](https://developer.mozilla.org/en/docs/Web/CSS/@font-face) definitions, for example:
19
25
  *
@@ -27,7 +33,7 @@ export declare type CssFontSource = {
27
33
  /*
28
34
  * Use a `CustomFontSource` to pass custom fonts when initializing a Connect instance.
29
35
  */
30
- export declare type CustomFontSource = {
36
+ export type CustomFontSource = {
31
37
  /**
32
38
  * The name to give the font
33
39
  */
@@ -63,7 +69,7 @@ export declare type CustomFontSource = {
63
69
  /**
64
70
  * Appearance options for the Connect instance.
65
71
  */
66
- export declare type AppearanceOptions = {
72
+ export type AppearanceOptions = {
67
73
  /**
68
74
  * The type of overlay used throughout the Connect.js design system. Set this to be either a Dialog or Drawer.
69
75
  */
@@ -71,7 +77,7 @@ export declare type AppearanceOptions = {
71
77
  variables?: AppearanceVariables;
72
78
  };
73
79
 
74
- export declare type AppearanceVariables = {
80
+ export type AppearanceVariables = {
75
81
  // Commonly used
76
82
 
77
83
  /**
@@ -510,7 +516,7 @@ export type IStripeConnectUpdateParams = {
510
516
  /**
511
517
  * Reasons why risk signals collection was skipped.
512
518
  */
513
- export declare type RiskSignalsCollectionSkippedReason =
519
+ export type RiskSignalsCollectionSkippedReason =
514
520
  /**
515
521
  * Required component (account_onboarding) not enabled.
516
522
  */
@@ -527,7 +533,7 @@ export declare type RiskSignalsCollectionSkippedReason =
527
533
  /**
528
534
  * Error types that can occur during risk signals collection.
529
535
  */
530
- export declare type RiskSignalsCollectionErrorType = Extract<
536
+ export type RiskSignalsCollectionErrorType = Extract<
531
537
  EmbeddedErrorType,
532
538
  | "api_connection_error"
533
539
  | "invalid_request_error"
@@ -538,7 +544,7 @@ export declare type RiskSignalsCollectionErrorType = Extract<
538
544
  /**
539
545
  * Errors that can occur during risk signals collection.
540
546
  */
541
- export declare type RiskSignalsCollectionError =
547
+ export type RiskSignalsCollectionError =
542
548
  /**
543
549
  * Error occurred during general Connect.js loading.
544
550
  */
@@ -643,43 +649,4 @@ export interface StripeConnectInstance {
643
649
  /**
644
650
  * Tagnames to be used with the `create` method of the Connect instance.
645
651
  */
646
- export type ConnectElementTagName =
647
- | "payments"
648
- | "payouts"
649
- | "payment-details"
650
- | "payment-disputes"
651
- | "disputes-list"
652
- | "account-onboarding"
653
- | "payment-method-settings"
654
- | "account-management"
655
- | "notification-banner"
656
- | "instant-payouts"
657
- | "instant-payouts-promotion"
658
- | "issuing-card"
659
- | "issuing-cards-list"
660
- | "financial-account"
661
- | "financial-account-transactions"
662
- | "recipients"
663
- | "capital-financing"
664
- | "capital-financing-application"
665
- | "capital-financing-promotion"
666
- | "capital-overview"
667
- | "documents"
668
- | "product-tax-code-selector"
669
- | "export-tax-transactions"
670
- | "tax-registrations"
671
- | "tax-settings"
672
- | "tax-threshold-monitoring"
673
- | "balances"
674
- | "payouts-list"
675
- | "payout-details"
676
- | "app-install"
677
- | "app-viewport"
678
- | "reporting-chart"
679
- | "check-scanning"
680
- | "agentic-commerce-settings"
681
- | "terminal-hardware-orders"
682
- | "terminal-hardware-shop"
683
- | "network-cost-passthrough-report"
684
- | "balance-report"
685
- | "payout-reconciliation-report";
652
+ export type ConnectElementTagName = (typeof connectElementTagNames)[number];
package/src/index.ts CHANGED
@@ -1,6 +1,9 @@
1
- import type { IStripeConnectInitParams, StripeConnectInstance } from "../types";
2
- import type { LoadConnectAndInitialize } from "./shared";
3
- import { loadScript, initStripeConnect } from "./shared";
1
+ import { initStripeConnect, loadScript } from "./init";
2
+ import type {
3
+ IStripeConnectInitParams,
4
+ StripeConnectInstance,
5
+ LoadConnectAndInitialize,
6
+ } from "./exportedTypes/shared";
4
7
 
5
8
  // Execute our own script injection after a tick to give users time to do their
6
9
  // own script injection.
@@ -20,3 +23,6 @@ export const loadConnectAndInitialize: LoadConnectAndInitialize = (
20
23
  loadCalled = true;
21
24
  return initStripeConnect(stripePromise, initParams);
22
25
  };
26
+
27
+ // Export all types from the exportedTypes folder
28
+ export * from "./exportedTypes";
@@ -1,149 +1,35 @@
1
+ import {
2
+ ConnectElementCommonMethodConfig,
3
+ ConnectElementCustomMethodConfig,
4
+ connectElementTagNames,
5
+ } from "./components/componentsAndSetters";
6
+ import type { ConnectHTMLElementRecord } from "./exportedTypes/shared";
1
7
  import type {
8
+ ConnectElementTagName,
2
9
  IStripeConnectInitParams,
3
10
  StripeConnectInstance,
4
- ConnectElementTagName,
5
- ConnectHTMLElementRecord,
6
- } from "../types";
11
+ StripeConnectWrapper,
12
+ } from "./exportedTypes/shared";
7
13
  import {
8
- ConnectElementCommonMethodConfig,
9
- ConnectElementCustomMethodConfig,
10
- } from "../types/config";
11
-
12
- export type LoadConnectAndInitialize = (
13
- initParams: IStripeConnectInitParams
14
- ) => StripeConnectInstance;
14
+ EXISTING_SCRIPT_MESSAGE,
15
+ findScript,
16
+ injectScript,
17
+ } from "./utils/scriptUtils";
15
18
 
16
- export type ConnectElementHTMLName =
17
- | "stripe-connect-payments"
18
- | "stripe-connect-payouts"
19
- | "stripe-connect-payment-details"
20
- | "stripe-connect-payment-disputes"
21
- | "stripe-connect-disputes-list"
22
- | "stripe-connect-account-onboarding"
23
- | "stripe-connect-payment-method-settings"
24
- | "stripe-connect-account-management"
25
- | "stripe-connect-notification-banner"
26
- | "stripe-connect-instant-payouts"
27
- | "stripe-connect-instant-payouts-promotion"
28
- | "stripe-connect-issuing-card"
29
- | "stripe-connect-issuing-cards-list"
30
- | "stripe-connect-financial-account"
31
- | "stripe-connect-financial-account-transactions"
32
- | "stripe-connect-recipients"
33
- | "stripe-connect-capital-financing"
34
- | "stripe-connect-capital-financing-application"
35
- | "stripe-connect-capital-financing-promotion"
36
- | "stripe-connect-capital-overview"
37
- | "stripe-connect-documents"
38
- | "stripe-connect-product-tax-code-selector"
39
- | "stripe-connect-export-tax-transactions"
40
- | "stripe-connect-tax-registrations"
41
- | "stripe-connect-tax-settings"
42
- | "stripe-connect-tax-threshold-monitoring"
43
- | "stripe-connect-balances"
44
- | "stripe-connect-payouts-list"
45
- | "stripe-connect-payout-details"
46
- | "stripe-connect-app-install"
47
- | "stripe-connect-app-viewport"
48
- | "stripe-connect-reporting-chart"
49
- | "stripe-connect-check-scanning"
50
- | "stripe-connect-agentic-commerce-settings"
51
- | "stripe-connect-terminal-hardware-orders"
52
- | "stripe-connect-terminal-hardware-shop"
53
- | "stripe-connect-network-cost-passthrough-report"
54
- | "stripe-connect-balance-report"
55
- | "stripe-connect-payout-reconciliation-report";
19
+ export type ConnectElementHTMLName = `stripe-connect-${ConnectElementTagName}`;
56
20
 
57
- export const componentNameMapping: Record<
58
- ConnectElementTagName,
59
- ConnectElementHTMLName
60
- > = {
61
- payments: "stripe-connect-payments",
62
- payouts: "stripe-connect-payouts",
63
- "payment-details": "stripe-connect-payment-details",
64
- "payment-disputes": "stripe-connect-payment-disputes",
65
- "disputes-list": "stripe-connect-disputes-list",
66
- "account-onboarding": "stripe-connect-account-onboarding",
67
- "payment-method-settings": "stripe-connect-payment-method-settings",
68
- "account-management": "stripe-connect-account-management",
69
- "notification-banner": "stripe-connect-notification-banner",
70
- "instant-payouts": "stripe-connect-instant-payouts",
71
- "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
72
- "issuing-card": "stripe-connect-issuing-card",
73
- "issuing-cards-list": "stripe-connect-issuing-cards-list",
74
- "financial-account": "stripe-connect-financial-account",
75
- recipients: "stripe-connect-recipients",
76
- "financial-account-transactions":
77
- "stripe-connect-financial-account-transactions",
78
- "capital-financing": "stripe-connect-capital-financing",
79
- "capital-financing-application":
80
- "stripe-connect-capital-financing-application",
81
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
82
- "capital-overview": "stripe-connect-capital-overview",
83
- documents: "stripe-connect-documents",
84
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
85
- "export-tax-transactions": "stripe-connect-export-tax-transactions",
86
- "tax-registrations": "stripe-connect-tax-registrations",
87
- "tax-settings": "stripe-connect-tax-settings",
88
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
89
- balances: "stripe-connect-balances",
90
- "payouts-list": "stripe-connect-payouts-list",
91
- "payout-details": "stripe-connect-payout-details",
92
- "app-install": "stripe-connect-app-install",
93
- "app-viewport": "stripe-connect-app-viewport",
94
- "reporting-chart": "stripe-connect-reporting-chart",
95
- "check-scanning": "stripe-connect-check-scanning",
96
- "agentic-commerce-settings": "stripe-connect-agentic-commerce-settings",
97
- "terminal-hardware-orders": "stripe-connect-terminal-hardware-orders",
98
- "terminal-hardware-shop": "stripe-connect-terminal-hardware-shop",
99
- "network-cost-passthrough-report":
100
- "stripe-connect-network-cost-passthrough-report",
101
- "balance-report": "stripe-connect-balance-report",
102
- "payout-reconciliation-report": "stripe-connect-payout-reconciliation-report",
103
- };
21
+ export const componentNameMapping = connectElementTagNames.reduce(
22
+ (acc, name) => {
23
+ acc[name] = `stripe-connect-${name}`;
24
+ return acc;
25
+ },
26
+ {} as Record<ConnectElementTagName, ConnectElementHTMLName>
27
+ );
104
28
 
105
29
  type StripeConnectInstanceExtended = StripeConnectInstance & {
106
30
  debugInstance: () => Promise<StripeConnectInstance>;
107
31
  };
108
32
 
109
- interface StripeConnectWrapper {
110
- initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
111
- }
112
-
113
- const EXISTING_SCRIPT_MESSAGE =
114
- "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
115
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
116
- const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
117
-
118
- export const findScript = (): HTMLScriptElement | null => {
119
- return (
120
- document.querySelectorAll<HTMLScriptElement>(
121
- `script[src="${V0_URL}"]`
122
- )[0] ||
123
- document.querySelectorAll<HTMLScriptElement>(
124
- `script[src="${V1_URL}"]`
125
- )[0] ||
126
- null
127
- );
128
- };
129
-
130
- const injectScript = (): HTMLScriptElement => {
131
- const script = document.createElement("script");
132
- script.src = V1_URL;
133
-
134
- const head = document.head;
135
-
136
- if (!head) {
137
- throw new Error(
138
- "Expected document.head not to be null. Connect.js requires a <head> element."
139
- );
140
- }
141
-
142
- document.head.appendChild(script);
143
-
144
- return script;
145
- };
146
-
147
33
  let stripePromise: Promise<StripeConnectWrapper> | null = null;
148
34
 
149
35
  export const isWindowStripeConnectDefined = (stripeConnect: unknown) => {
package/src/pure.test.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
2
 
3
- import type { IStripeConnectInitParams } from "../types";
3
+ import type { IStripeConnectInitParams } from "./exportedTypes/shared";
4
4
  import { SCRIPT_SELECTOR } from "./utils/jestHelpers";
5
5
 
6
6
  describe("pure module", () => {
package/src/pure.ts CHANGED
@@ -1,6 +1,9 @@
1
- import type { IStripeConnectInitParams, StripeConnectInstance } from "../types";
2
- import type { LoadConnectAndInitialize } from "./shared";
3
- import { loadScript, initStripeConnect } from "./shared";
1
+ import { initStripeConnect, loadScript } from "./init";
2
+ import type {
3
+ IStripeConnectInitParams,
4
+ LoadConnectAndInitialize,
5
+ StripeConnectInstance,
6
+ } from "./exportedTypes/shared";
4
7
 
5
8
  export const loadConnectAndInitialize: LoadConnectAndInitialize = (
6
9
  initParams: IStripeConnectInitParams
@@ -13,3 +16,6 @@ export const loadConnectAndInitialize: LoadConnectAndInitialize = (
13
16
  }
14
17
  return initStripeConnect(maybeConnect, initParams);
15
18
  };
19
+
20
+ // Export all types from the exportedTypes folder
21
+ export * from "./exportedTypes";
@@ -0,0 +1,33 @@
1
+ export const EXISTING_SCRIPT_MESSAGE =
2
+ "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
3
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
4
+ const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
5
+
6
+ export const findScript = (): HTMLScriptElement | null => {
7
+ return (
8
+ document.querySelectorAll<HTMLScriptElement>(
9
+ `script[src="${V1_URL}"]`
10
+ )[0] ||
11
+ document.querySelectorAll<HTMLScriptElement>(
12
+ `script[src="${V0_URL}"]`
13
+ )[0] ||
14
+ null
15
+ );
16
+ };
17
+
18
+ export const injectScript = (): HTMLScriptElement => {
19
+ const script = document.createElement("script");
20
+ script.src = V1_URL;
21
+
22
+ const head = document.head;
23
+
24
+ if (!head) {
25
+ throw new Error(
26
+ "Expected document.head not to be null. Connect.js requires a <head> element."
27
+ );
28
+ }
29
+
30
+ document.head.appendChild(script);
31
+
32
+ return script;
33
+ };
@@ -1,2 +0,0 @@
1
- import type { LoadConnectAndInitialize } from "./shared";
2
- export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
@@ -1,2 +0,0 @@
1
- import type { LoadConnectAndInitialize } from "./shared";
2
- export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
@@ -1,15 +0,0 @@
1
- import type { IStripeConnectInitParams, StripeConnectInstance, ConnectElementTagName } from "../types";
2
- export type LoadConnectAndInitialize = (initParams: IStripeConnectInitParams) => StripeConnectInstance;
3
- export type ConnectElementHTMLName = "stripe-connect-payments" | "stripe-connect-payouts" | "stripe-connect-payment-details" | "stripe-connect-payment-disputes" | "stripe-connect-disputes-list" | "stripe-connect-account-onboarding" | "stripe-connect-payment-method-settings" | "stripe-connect-account-management" | "stripe-connect-notification-banner" | "stripe-connect-instant-payouts" | "stripe-connect-instant-payouts-promotion" | "stripe-connect-issuing-card" | "stripe-connect-issuing-cards-list" | "stripe-connect-financial-account" | "stripe-connect-financial-account-transactions" | "stripe-connect-recipients" | "stripe-connect-capital-financing" | "stripe-connect-capital-financing-application" | "stripe-connect-capital-financing-promotion" | "stripe-connect-capital-overview" | "stripe-connect-documents" | "stripe-connect-product-tax-code-selector" | "stripe-connect-export-tax-transactions" | "stripe-connect-tax-registrations" | "stripe-connect-tax-settings" | "stripe-connect-tax-threshold-monitoring" | "stripe-connect-balances" | "stripe-connect-payouts-list" | "stripe-connect-payout-details" | "stripe-connect-app-install" | "stripe-connect-app-viewport" | "stripe-connect-reporting-chart" | "stripe-connect-check-scanning" | "stripe-connect-agentic-commerce-settings" | "stripe-connect-terminal-hardware-orders" | "stripe-connect-terminal-hardware-shop" | "stripe-connect-network-cost-passthrough-report" | "stripe-connect-balance-report" | "stripe-connect-payout-reconciliation-report";
4
- export declare const componentNameMapping: Record<ConnectElementTagName, ConnectElementHTMLName>;
5
- type StripeConnectInstanceExtended = StripeConnectInstance & {
6
- debugInstance: () => Promise<StripeConnectInstance>;
7
- };
8
- interface StripeConnectWrapper {
9
- initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
10
- }
11
- export declare const findScript: () => HTMLScriptElement | null;
12
- export declare const isWindowStripeConnectDefined: (stripeConnect: unknown) => boolean;
13
- export declare const loadScript: () => Promise<StripeConnectWrapper>;
14
- export declare const initStripeConnect: (stripePromise: Promise<StripeConnectWrapper>, initParams: IStripeConnectInitParams) => StripeConnectInstanceExtended;
15
- export {};
@@ -1,3 +0,0 @@
1
- rules:
2
- "@typescript-eslint/triple-slash-reference": 0
3
- "@typescript-eslint/adjacent-overload-signatures": 0
package/types/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { IStripeConnectInitParams, StripeConnectInstance } from "../types";
2
-
3
- export declare const loadConnectAndInitialize: (
4
- initParams: IStripeConnectInitParams
5
- ) => StripeConnectInstance;
6
- export * from "./shared";
7
- export * from "./config";
File without changes
File without changes