@stripe/connect-js 2.0.5 → 3.0.0-beta.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.
@@ -1,8 +1,17 @@
1
1
  const componentNameMapping = {
2
- "account-onboarding": "stripe-connect-account-onboarding"
2
+ payments: "stripe-connect-payments",
3
+ payouts: "stripe-connect-payouts",
4
+ "payment-details": "stripe-connect-payment-details",
5
+ "account-onboarding": "stripe-connect-account-onboarding",
6
+ "payment-method-settings": "stripe-connect-payment-method-settings",
7
+ "account-management": "stripe-connect-account-management",
8
+ "notification-banner": "stripe-connect-notification-banner",
9
+ "instant-payouts": "stripe-connect-instant-payouts",
10
+ "issuing-card": "stripe-connect-issuing-card",
11
+ "issuing-cards-list": "stripe-connect-issuing-cards-list"
3
12
  };
4
13
  const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
5
- const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
14
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
6
15
  const findScript = () => {
7
16
  return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
8
17
  };
@@ -59,13 +68,38 @@ const loadScript = () => {
59
68
  });
60
69
  return stripePromise;
61
70
  };
62
- const initStripeConnect = stripeConnectPromise => {
63
- if (stripeConnectPromise === null) {
64
- return null;
65
- }
66
- return stripeConnectPromise;
71
+ const initStripeConnect = (stripePromise, initParams) => {
72
+ const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
73
+ return {
74
+ create: tagName => {
75
+ let htmlName = componentNameMapping[tagName];
76
+ if (!htmlName) {
77
+ htmlName = tagName;
78
+ }
79
+ const element = document.createElement(htmlName);
80
+ stripeConnectInstance.then(instance => {
81
+ element.setConnector(instance.connect);
82
+ });
83
+ return element;
84
+ },
85
+ update: updateOptions => {
86
+ stripeConnectInstance.then(instance => {
87
+ instance.update(updateOptions);
88
+ });
89
+ },
90
+ debugInstance: () => {
91
+ return stripeConnectInstance;
92
+ },
93
+ logout: () => {
94
+ return stripeConnectInstance.then(instance => {
95
+ instance.logout();
96
+ });
97
+ }
98
+ };
67
99
  };
68
100
  const createWrapper = stripeConnect => {
101
+ window.StripeConnect = window.StripeConnect || {};
102
+ window.StripeConnect.optimizedLoading = true;
69
103
  const wrapper = {
70
104
  initialize: params => {
71
105
  var _a;
@@ -75,19 +109,10 @@ const createWrapper = stripeConnect => {
75
109
  sdk: true,
76
110
  sdkOptions: {
77
111
  // This will be replaced by the npm package version when bundling
78
- sdkVersion: "2.0.5"
112
+ sdkVersion: "3.0.0-beta.1"
79
113
  }
80
114
  })
81
115
  }));
82
- // We wrap create so we can map its different strings to supported components
83
- const oldCreate = stripeConnectInstance.create.bind(stripeConnectInstance);
84
- stripeConnectInstance.create = tagName => {
85
- let htmlName = componentNameMapping[tagName];
86
- if (!htmlName) {
87
- htmlName = tagName;
88
- }
89
- return oldCreate(htmlName);
90
- };
91
116
  return stripeConnectInstance;
92
117
  }
93
118
  };
@@ -103,9 +128,9 @@ stripePromise$1.catch(err => {
103
128
  console.warn(err);
104
129
  }
105
130
  });
106
- const loadConnect = () => {
131
+ const loadConnectAndInitialize = initParams => {
107
132
  loadCalled = true;
108
- return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
133
+ return initStripeConnect(stripePromise$1, initParams);
109
134
  };
110
135
 
111
- export { loadConnect };
136
+ export { loadConnectAndInitialize };
package/dist/connect.js CHANGED
@@ -3,10 +3,19 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const componentNameMapping = {
6
- "account-onboarding": "stripe-connect-account-onboarding"
6
+ payments: "stripe-connect-payments",
7
+ payouts: "stripe-connect-payouts",
8
+ "payment-details": "stripe-connect-payment-details",
9
+ "account-onboarding": "stripe-connect-account-onboarding",
10
+ "payment-method-settings": "stripe-connect-payment-method-settings",
11
+ "account-management": "stripe-connect-account-management",
12
+ "notification-banner": "stripe-connect-notification-banner",
13
+ "instant-payouts": "stripe-connect-instant-payouts",
14
+ "issuing-card": "stripe-connect-issuing-card",
15
+ "issuing-cards-list": "stripe-connect-issuing-cards-list"
7
16
  };
8
17
  const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
9
- const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
18
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
10
19
  const findScript = () => {
11
20
  return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
12
21
  };
@@ -63,13 +72,38 @@ const loadScript = () => {
63
72
  });
64
73
  return stripePromise;
65
74
  };
66
- const initStripeConnect = stripeConnectPromise => {
67
- if (stripeConnectPromise === null) {
68
- return null;
69
- }
70
- return stripeConnectPromise;
75
+ const initStripeConnect = (stripePromise, initParams) => {
76
+ const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
77
+ return {
78
+ create: tagName => {
79
+ let htmlName = componentNameMapping[tagName];
80
+ if (!htmlName) {
81
+ htmlName = tagName;
82
+ }
83
+ const element = document.createElement(htmlName);
84
+ stripeConnectInstance.then(instance => {
85
+ element.setConnector(instance.connect);
86
+ });
87
+ return element;
88
+ },
89
+ update: updateOptions => {
90
+ stripeConnectInstance.then(instance => {
91
+ instance.update(updateOptions);
92
+ });
93
+ },
94
+ debugInstance: () => {
95
+ return stripeConnectInstance;
96
+ },
97
+ logout: () => {
98
+ return stripeConnectInstance.then(instance => {
99
+ instance.logout();
100
+ });
101
+ }
102
+ };
71
103
  };
72
104
  const createWrapper = stripeConnect => {
105
+ window.StripeConnect = window.StripeConnect || {};
106
+ window.StripeConnect.optimizedLoading = true;
73
107
  const wrapper = {
74
108
  initialize: params => {
75
109
  var _a;
@@ -79,19 +113,10 @@ const createWrapper = stripeConnect => {
79
113
  sdk: true,
80
114
  sdkOptions: {
81
115
  // This will be replaced by the npm package version when bundling
82
- sdkVersion: "2.0.5"
116
+ sdkVersion: "3.0.0-beta.1"
83
117
  }
84
118
  })
85
119
  }));
86
- // We wrap create so we can map its different strings to supported components
87
- const oldCreate = stripeConnectInstance.create.bind(stripeConnectInstance);
88
- stripeConnectInstance.create = tagName => {
89
- let htmlName = componentNameMapping[tagName];
90
- if (!htmlName) {
91
- htmlName = tagName;
92
- }
93
- return oldCreate(htmlName);
94
- };
95
120
  return stripeConnectInstance;
96
121
  }
97
122
  };
@@ -107,9 +132,9 @@ stripePromise$1.catch(err => {
107
132
  console.warn(err);
108
133
  }
109
134
  });
110
- const loadConnect = () => {
135
+ const loadConnectAndInitialize = initParams => {
111
136
  loadCalled = true;
112
- return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
137
+ return initStripeConnect(stripePromise$1, initParams);
113
138
  };
114
139
 
115
- exports.loadConnect = loadConnect;
140
+ exports.loadConnectAndInitialize = loadConnectAndInitialize;
@@ -0,0 +1,2 @@
1
+ import { LoadConnectAndInitialize } from "./shared";
2
+ export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
package/dist/pure.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { LoadConnect } from "./shared";
2
- export declare const loadConnect: LoadConnect;
1
+ import { LoadConnectAndInitialize } from "./shared";
2
+ export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
package/dist/pure.esm.js CHANGED
@@ -1,8 +1,17 @@
1
1
  const componentNameMapping = {
2
- "account-onboarding": "stripe-connect-account-onboarding"
2
+ payments: "stripe-connect-payments",
3
+ payouts: "stripe-connect-payouts",
4
+ "payment-details": "stripe-connect-payment-details",
5
+ "account-onboarding": "stripe-connect-account-onboarding",
6
+ "payment-method-settings": "stripe-connect-payment-method-settings",
7
+ "account-management": "stripe-connect-account-management",
8
+ "notification-banner": "stripe-connect-notification-banner",
9
+ "instant-payouts": "stripe-connect-instant-payouts",
10
+ "issuing-card": "stripe-connect-issuing-card",
11
+ "issuing-cards-list": "stripe-connect-issuing-cards-list"
3
12
  };
4
13
  const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
5
- const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
14
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
6
15
  const findScript = () => {
7
16
  return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
8
17
  };
@@ -59,13 +68,38 @@ const loadScript = () => {
59
68
  });
60
69
  return stripePromise;
61
70
  };
62
- const initStripeConnect = stripeConnectPromise => {
63
- if (stripeConnectPromise === null) {
64
- return null;
65
- }
66
- return stripeConnectPromise;
71
+ const initStripeConnect = (stripePromise, initParams) => {
72
+ const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
73
+ return {
74
+ create: tagName => {
75
+ let htmlName = componentNameMapping[tagName];
76
+ if (!htmlName) {
77
+ htmlName = tagName;
78
+ }
79
+ const element = document.createElement(htmlName);
80
+ stripeConnectInstance.then(instance => {
81
+ element.setConnector(instance.connect);
82
+ });
83
+ return element;
84
+ },
85
+ update: updateOptions => {
86
+ stripeConnectInstance.then(instance => {
87
+ instance.update(updateOptions);
88
+ });
89
+ },
90
+ debugInstance: () => {
91
+ return stripeConnectInstance;
92
+ },
93
+ logout: () => {
94
+ return stripeConnectInstance.then(instance => {
95
+ instance.logout();
96
+ });
97
+ }
98
+ };
67
99
  };
68
100
  const createWrapper = stripeConnect => {
101
+ window.StripeConnect = window.StripeConnect || {};
102
+ window.StripeConnect.optimizedLoading = true;
69
103
  const wrapper = {
70
104
  initialize: params => {
71
105
  var _a;
@@ -75,27 +109,19 @@ const createWrapper = stripeConnect => {
75
109
  sdk: true,
76
110
  sdkOptions: {
77
111
  // This will be replaced by the npm package version when bundling
78
- sdkVersion: "2.0.5"
112
+ sdkVersion: "3.0.0-beta.1"
79
113
  }
80
114
  })
81
115
  }));
82
- // We wrap create so we can map its different strings to supported components
83
- const oldCreate = stripeConnectInstance.create.bind(stripeConnectInstance);
84
- stripeConnectInstance.create = tagName => {
85
- let htmlName = componentNameMapping[tagName];
86
- if (!htmlName) {
87
- htmlName = tagName;
88
- }
89
- return oldCreate(htmlName);
90
- };
91
116
  return stripeConnectInstance;
92
117
  }
93
118
  };
94
119
  return wrapper;
95
120
  };
96
121
 
97
- const loadConnect = () => {
98
- return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
122
+ const loadConnectAndInitialize = initParams => {
123
+ const maybeConnect = loadScript();
124
+ return initStripeConnect(maybeConnect, initParams);
99
125
  };
100
126
 
101
- export { loadConnect };
127
+ export { loadConnectAndInitialize };
package/dist/pure.js CHANGED
@@ -3,10 +3,19 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const componentNameMapping = {
6
- "account-onboarding": "stripe-connect-account-onboarding"
6
+ payments: "stripe-connect-payments",
7
+ payouts: "stripe-connect-payouts",
8
+ "payment-details": "stripe-connect-payment-details",
9
+ "account-onboarding": "stripe-connect-account-onboarding",
10
+ "payment-method-settings": "stripe-connect-payment-method-settings",
11
+ "account-management": "stripe-connect-account-management",
12
+ "notification-banner": "stripe-connect-notification-banner",
13
+ "instant-payouts": "stripe-connect-instant-payouts",
14
+ "issuing-card": "stripe-connect-issuing-card",
15
+ "issuing-cards-list": "stripe-connect-issuing-cards-list"
7
16
  };
8
17
  const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
9
- const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
18
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
10
19
  const findScript = () => {
11
20
  return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
12
21
  };
@@ -63,13 +72,38 @@ const loadScript = () => {
63
72
  });
64
73
  return stripePromise;
65
74
  };
66
- const initStripeConnect = stripeConnectPromise => {
67
- if (stripeConnectPromise === null) {
68
- return null;
69
- }
70
- return stripeConnectPromise;
75
+ const initStripeConnect = (stripePromise, initParams) => {
76
+ const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
77
+ return {
78
+ create: tagName => {
79
+ let htmlName = componentNameMapping[tagName];
80
+ if (!htmlName) {
81
+ htmlName = tagName;
82
+ }
83
+ const element = document.createElement(htmlName);
84
+ stripeConnectInstance.then(instance => {
85
+ element.setConnector(instance.connect);
86
+ });
87
+ return element;
88
+ },
89
+ update: updateOptions => {
90
+ stripeConnectInstance.then(instance => {
91
+ instance.update(updateOptions);
92
+ });
93
+ },
94
+ debugInstance: () => {
95
+ return stripeConnectInstance;
96
+ },
97
+ logout: () => {
98
+ return stripeConnectInstance.then(instance => {
99
+ instance.logout();
100
+ });
101
+ }
102
+ };
71
103
  };
72
104
  const createWrapper = stripeConnect => {
105
+ window.StripeConnect = window.StripeConnect || {};
106
+ window.StripeConnect.optimizedLoading = true;
73
107
  const wrapper = {
74
108
  initialize: params => {
75
109
  var _a;
@@ -79,27 +113,19 @@ const createWrapper = stripeConnect => {
79
113
  sdk: true,
80
114
  sdkOptions: {
81
115
  // This will be replaced by the npm package version when bundling
82
- sdkVersion: "2.0.5"
116
+ sdkVersion: "3.0.0-beta.1"
83
117
  }
84
118
  })
85
119
  }));
86
- // We wrap create so we can map its different strings to supported components
87
- const oldCreate = stripeConnectInstance.create.bind(stripeConnectInstance);
88
- stripeConnectInstance.create = tagName => {
89
- let htmlName = componentNameMapping[tagName];
90
- if (!htmlName) {
91
- htmlName = tagName;
92
- }
93
- return oldCreate(htmlName);
94
- };
95
120
  return stripeConnectInstance;
96
121
  }
97
122
  };
98
123
  return wrapper;
99
124
  };
100
125
 
101
- const loadConnect = () => {
102
- return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
126
+ const loadConnectAndInitialize = initParams => {
127
+ const maybeConnect = loadScript();
128
+ return initStripeConnect(maybeConnect, initParams);
103
129
  };
104
130
 
105
- exports.loadConnect = loadConnect;
131
+ exports.loadConnectAndInitialize = loadConnectAndInitialize;
package/dist/shared.d.ts CHANGED
@@ -1,5 +1,14 @@
1
- import { StripeConnectWrapper } from "../types";
2
- export type LoadConnect = () => Promise<StripeConnectWrapper>;
1
+ import { 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-account-onboarding" | "stripe-connect-payment-method-settings" | "stripe-connect-account-management" | "stripe-connect-notification-banner" | "stripe-connect-instant-payouts" | "stripe-connect-issuing-card" | "stripe-connect-issuing-cards-list";
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
+ }
3
11
  export declare const findScript: () => HTMLScriptElement | null;
4
- export declare const loadScript: () => Promise<StripeConnectWrapper | null>;
5
- export declare const initStripeConnect: (stripeConnectPromise: StripeConnectWrapper | null) => any | null;
12
+ export declare const loadScript: () => Promise<StripeConnectWrapper>;
13
+ export declare const initStripeConnect: (stripePromise: Promise<StripeConnectWrapper>, initParams: IStripeConnectInitParams) => StripeConnectInstanceExtended;
14
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/connect-js",
3
- "version": "2.0.5",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "Connect.js loading utility package",
5
5
  "main": "dist/connect.js",
6
6
  "module": "dist/connect.esm.js",
package/pure.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LoadConnect } from "./src/shared";
1
+ import { LoadConnectAndInitialize } from "./src/shared";
2
2
 
3
- export declare const loadConnect: LoadConnect;
3
+ export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
4
4
  export * from "./types/shared";
package/src/index.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { loadScript, initStripeConnect, LoadConnect } from "./shared";
1
+ import { IStripeConnectInitParams, StripeConnectInstance } from "../types";
2
+ import {
3
+ loadScript,
4
+ initStripeConnect,
5
+ LoadConnectAndInitialize
6
+ } from "./shared";
2
7
 
3
8
  // Execute our own script injection after a tick to give users time to do their
4
9
  // own script injection.
@@ -12,10 +17,9 @@ stripePromise.catch((err: Error) => {
12
17
  }
13
18
  });
14
19
 
15
- export const loadConnect: LoadConnect = () => {
20
+ export const loadConnectAndInitialize: LoadConnectAndInitialize = (
21
+ initParams: IStripeConnectInitParams
22
+ ): StripeConnectInstance => {
16
23
  loadCalled = true;
17
-
18
- return stripePromise.then(maybeConnect => initStripeConnect(maybeConnect));
24
+ return initStripeConnect(stripePromise, initParams);
19
25
  };
20
-
21
- export {};
package/src/pure.test.ts CHANGED
@@ -1,17 +1,24 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
2
 
3
+ import { IStripeConnectInitParams } from "../types";
3
4
  import { SCRIPT_SELECTOR } from "./utils/jestHelpers";
4
5
 
5
6
  describe("pure module", () => {
6
- test("does not inject the script if loadConnect is not called", async () => {
7
+ test("does not inject the script if loadConnectAndInitialize is not called", async () => {
7
8
  require("./pure");
8
9
 
9
10
  expect(document.querySelector(SCRIPT_SELECTOR)).toBe(null);
10
11
  });
11
12
 
12
- test("it injects the script if loadConnect is called", async () => {
13
- const { loadConnect } = require("./pure");
14
- loadConnect();
13
+ test("it injects the script if loadConnectAndInitialize is called", async () => {
14
+ const { loadConnectAndInitialize } = require("./pure");
15
+ const mockInitParams: IStripeConnectInitParams = {
16
+ publishableKey: "pk_123",
17
+ fetchClientSecret: async () => {
18
+ return "secret_123";
19
+ }
20
+ };
21
+ loadConnectAndInitialize(mockInitParams);
15
22
 
16
23
  expect(document.querySelector(SCRIPT_SELECTOR)).not.toBe(null);
17
24
  });
package/src/pure.ts CHANGED
@@ -1,5 +1,13 @@
1
- import { loadScript, initStripeConnect, LoadConnect } from "./shared";
1
+ import { IStripeConnectInitParams, StripeConnectInstance } from "../types";
2
+ import {
3
+ loadScript,
4
+ initStripeConnect,
5
+ LoadConnectAndInitialize
6
+ } from "./shared";
2
7
 
3
- export const loadConnect: LoadConnect = () => {
4
- return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
8
+ export const loadConnectAndInitialize: LoadConnectAndInitialize = (
9
+ initParams: IStripeConnectInitParams
10
+ ): StripeConnectInstance => {
11
+ const maybeConnect = loadScript();
12
+ return initStripeConnect(maybeConnect, initParams);
5
13
  };
package/src/shared.ts CHANGED
@@ -1,23 +1,53 @@
1
1
  import {
2
- StripeConnectWrapper,
3
2
  IStripeConnectInitParams,
4
- ConnectElementTagName
3
+ StripeConnectInstance,
4
+ ConnectElementTagName,
5
+ ConnectHTMLElementRecord
5
6
  } from "../types";
6
7
 
7
- export type LoadConnect = () => Promise<StripeConnectWrapper>;
8
-
9
- type ConnectElementHTMLName = "stripe-connect-account-onboarding";
10
-
11
- const componentNameMapping: Record<
8
+ export type LoadConnectAndInitialize = (
9
+ initParams: IStripeConnectInitParams
10
+ ) => StripeConnectInstance;
11
+
12
+ export type ConnectElementHTMLName =
13
+ | "stripe-connect-payments"
14
+ | "stripe-connect-payouts"
15
+ | "stripe-connect-payment-details"
16
+ | "stripe-connect-account-onboarding"
17
+ | "stripe-connect-payment-method-settings"
18
+ | "stripe-connect-account-management"
19
+ | "stripe-connect-notification-banner"
20
+ | "stripe-connect-instant-payouts"
21
+ | "stripe-connect-issuing-card"
22
+ | "stripe-connect-issuing-cards-list";
23
+
24
+ export const componentNameMapping: Record<
12
25
  ConnectElementTagName,
13
26
  ConnectElementHTMLName
14
27
  > = {
15
- "account-onboarding": "stripe-connect-account-onboarding"
28
+ payments: "stripe-connect-payments",
29
+ payouts: "stripe-connect-payouts",
30
+ "payment-details": "stripe-connect-payment-details",
31
+ "account-onboarding": "stripe-connect-account-onboarding",
32
+ "payment-method-settings": "stripe-connect-payment-method-settings",
33
+ "account-management": "stripe-connect-account-management",
34
+ "notification-banner": "stripe-connect-notification-banner",
35
+ "instant-payouts": "stripe-connect-instant-payouts",
36
+ "issuing-card": "stripe-connect-issuing-card",
37
+ "issuing-cards-list": "stripe-connect-issuing-cards-list"
38
+ };
39
+
40
+ type StripeConnectInstanceExtended = StripeConnectInstance & {
41
+ debugInstance: () => Promise<StripeConnectInstance>;
16
42
  };
17
43
 
44
+ interface StripeConnectWrapper {
45
+ initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
46
+ }
47
+
18
48
  const EXISTING_SCRIPT_MESSAGE =
19
49
  "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
20
- const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
50
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
21
51
 
22
52
  export const findScript = (): HTMLScriptElement | null => {
23
53
  return document.querySelectorAll<HTMLScriptElement>(
@@ -44,13 +74,13 @@ const injectScript = (): HTMLScriptElement => {
44
74
 
45
75
  let stripePromise: Promise<StripeConnectWrapper> | null = null;
46
76
 
47
- export const loadScript = (): Promise<StripeConnectWrapper | null> => {
77
+ export const loadScript = (): Promise<StripeConnectWrapper> => {
48
78
  // Ensure that we only attempt to load Connect.js at most once
49
79
  if (stripePromise !== null) {
50
80
  return stripePromise;
51
81
  }
52
82
 
53
- stripePromise = new Promise((resolve, reject) => {
83
+ stripePromise = new Promise<StripeConnectWrapper>((resolve, reject) => {
54
84
  if (typeof window === "undefined") {
55
85
  reject(
56
86
  "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."
@@ -98,16 +128,45 @@ export const loadScript = (): Promise<StripeConnectWrapper | null> => {
98
128
  };
99
129
 
100
130
  export const initStripeConnect = (
101
- stripeConnectPromise: StripeConnectWrapper | null
102
- ): any | null => {
103
- if (stripeConnectPromise === null) {
104
- return null;
105
- }
131
+ stripePromise: Promise<StripeConnectWrapper>,
132
+ initParams: IStripeConnectInitParams
133
+ ): StripeConnectInstanceExtended => {
134
+ const stripeConnectInstance = stripePromise.then(wrapper =>
135
+ wrapper.initialize(initParams)
136
+ );
137
+
138
+ return {
139
+ create: tagName => {
140
+ let htmlName = componentNameMapping[tagName];
141
+ if (!htmlName) {
142
+ htmlName = tagName as ConnectElementHTMLName;
143
+ }
144
+ const element = document.createElement(htmlName);
145
+ stripeConnectInstance.then(instance => {
146
+ (element as any).setConnector((instance as any).connect);
147
+ });
106
148
 
107
- return stripeConnectPromise;
149
+ return element as ConnectHTMLElementRecord[typeof tagName];
150
+ },
151
+ update: updateOptions => {
152
+ stripeConnectInstance.then(instance => {
153
+ instance.update(updateOptions);
154
+ });
155
+ },
156
+ debugInstance: () => {
157
+ return stripeConnectInstance;
158
+ },
159
+ logout: () => {
160
+ return stripeConnectInstance.then(instance => {
161
+ instance.logout();
162
+ });
163
+ }
164
+ };
108
165
  };
109
166
 
110
167
  const createWrapper = (stripeConnect: any) => {
168
+ (window as any).StripeConnect = (window as any).StripeConnect || {};
169
+ (window as any).StripeConnect.optimizedLoading = true;
111
170
  const wrapper: StripeConnectWrapper = {
112
171
  initialize: (params: IStripeConnectInitParams) => {
113
172
  const metaOptions = (params as any).metaOptions ?? {};
@@ -122,18 +181,6 @@ const createWrapper = (stripeConnect: any) => {
122
181
  }
123
182
  }
124
183
  });
125
-
126
- // We wrap create so we can map its different strings to supported components
127
- const oldCreate = stripeConnectInstance.create.bind(
128
- stripeConnectInstance
129
- );
130
- stripeConnectInstance.create = (tagName: ConnectElementTagName) => {
131
- let htmlName = componentNameMapping[tagName];
132
- if (!htmlName) {
133
- htmlName = tagName as ConnectElementHTMLName;
134
- }
135
- return oldCreate(htmlName);
136
- };
137
184
  return stripeConnectInstance;
138
185
  }
139
186
  };
package/types/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { LoadConnect } from "../src/shared";
1
+ import { IStripeConnectInitParams, StripeConnectInstance } from "../types";
2
2
 
3
- export declare const loadConnect: LoadConnect;
3
+ export declare const loadConnectAndInitialize: (
4
+ initParams: IStripeConnectInitParams
5
+ ) => StripeConnectInstance;
4
6
  export * from "./shared";
package/types/shared.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export declare type LoadConnect = () => Promise<StripeConnectWrapper>;
1
+ export declare type LoadConnectAndInitialize = (
2
+ initParams: IStripeConnectInitParams
3
+ ) => StripeConnectInstance;
2
4
 
3
5
  export declare type OverlayOption = "dialog" | "drawer";
4
6
 
@@ -207,6 +209,14 @@ export declare type AppearanceVariables = {
207
209
  overlayZIndex?: number;
208
210
 
209
211
  // Body Typography
212
+ /**
213
+ * The font size for the large body typography. Body typography variables accept a valid font size value.
214
+ */
215
+ bodyLgFontSize?: string;
216
+ /**
217
+ * The font weight for the large body typography. Body typography variables accept a valid font weight value.
218
+ */
219
+ bodyLgFontWeight?: string;
210
220
  /**
211
221
  * The font size for the medium body typography. Body typography variables accept a valid font size value.
212
222
  */
@@ -287,6 +297,18 @@ export declare type AppearanceVariables = {
287
297
  headingXsTextTransform?: string;
288
298
 
289
299
  // Label Typography
300
+ /**
301
+ * The font size for the large label typography. Label typography variables accept a valid font size value.
302
+ */
303
+ labelLgFontSize?: string;
304
+ /**
305
+ * The font weight for the large label typography. Label typography variables accept a valid font weight value.
306
+ */
307
+ labelLgFontWeight?: string;
308
+ /**
309
+ * The text transform for the large label typography. Label typography variables accept a valid text transform value.
310
+ */
311
+ labelLgTextTransform?: string;
290
312
  /**
291
313
  * The font size for the medium label typography. Label typography variables accept a valid font size value.
292
314
  */
@@ -335,9 +357,10 @@ export interface IStripeConnectInitParams {
335
357
  publishableKey: string;
336
358
 
337
359
  /**
338
- * The client secret for the connected account.
360
+ * Function that fetches client secret
361
+ * @returns A promise that resolves with a new client secret.
339
362
  */
340
- clientSecret: string;
363
+ fetchClientSecret: () => Promise<string>;
341
364
 
342
365
  /**
343
366
  * Appearance options for the Connect instance.
@@ -345,24 +368,37 @@ export interface IStripeConnectInitParams {
345
368
  */
346
369
  appearance?: AppearanceOptions;
347
370
 
348
- /**
349
- * Callback function that returns a new client secret. Used to support long running sessions and called on account session expiry.
350
- */
351
- refreshClientSecret?: () => Promise<string>;
352
-
353
371
  /**
354
372
  * The locale to use for the Connect instance.
355
373
  */
356
374
  locale?: string;
357
375
  }
358
376
 
359
- export interface StripeConnectWrapper {
360
- /**
361
- * Initializes a Connect JS instance that can be used to create and update Connect components.
362
- * @param params Initialization parameters for Connect JS. See https://stripe.com/docs/connect/get-started-connect-embedded-components#configuring-connect-js for more details.
363
- * @returns A Connect JS instance.
364
- */
365
- initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
377
+ type ConnectHTMLElementRecordFallback = {
378
+ [key in string]: HTMLElement | null;
379
+ };
380
+ type ConnectHTMLElementRecordBase = {
381
+ [tagName in ConnectElementTagName]: HTMLElement;
382
+ };
383
+
384
+ interface ConnectHTMLElementRecord
385
+ extends ConnectHTMLElementRecordBase,
386
+ ConnectHTMLElementRecordFallback {
387
+ "payment-details": HTMLElement & {
388
+ setPayment: (payment: string | undefined) => void;
389
+ setOnClose: (listener: (() => void) | undefined) => void;
390
+ };
391
+ "account-onboarding": HTMLElement & {
392
+ setFullTermsOfServiceUrl: (termOfServiceUrl: string | undefined) => void;
393
+ setRecipientTermsOfServiceUrl: (
394
+ recipientTermsOfServiceUrl: string | undefined
395
+ ) => void;
396
+ setPrivacyPolicyUrl: (privacyPolicyUrl: string | undefined) => void;
397
+ setSkipTermsOfServiceCollection: (
398
+ skipTermsOfServiceCollection: boolean | undefined
399
+ ) => void;
400
+ setOnExit: (listener: (() => void) | undefined) => void;
401
+ };
366
402
  }
367
403
 
368
404
  export interface StripeConnectInstance {
@@ -371,7 +407,9 @@ export interface StripeConnectInstance {
371
407
  * @tagName Name of the Connect component to create.
372
408
  * @returns An HTML component corresponding to that connect component
373
409
  */
374
- create: (tagName: ConnectElementTagName) => HTMLElement | null;
410
+ create: <T extends ConnectElementTagName>(
411
+ tagName: T
412
+ ) => ConnectHTMLElementRecord[T];
375
413
 
376
414
  /**
377
415
  * Updates the Connect instance with new parameters.
@@ -389,12 +427,14 @@ export interface StripeConnectInstance {
389
427
  /**
390
428
  * Tagnames to be used with the `create` method of the Connect instance.
391
429
  */
392
- export type ConnectElementTagName = "account-onboarding";
393
-
394
- export declare const findScript: () => HTMLScriptElement | null;
395
-
396
- export declare const loadScript: () => Promise<any | null>;
397
-
398
- export declare const initStripeConnect: (
399
- stripeConnectPromise: StripeConnectWrapper | null
400
- ) => any | null;
430
+ export type ConnectElementTagName =
431
+ | "payments"
432
+ | "payouts"
433
+ | "payment-details"
434
+ | "account-onboarding"
435
+ | "payment-method-settings"
436
+ | "account-management"
437
+ | "notification-banner"
438
+ | "instant-payouts"
439
+ | "issuing-card"
440
+ | "issuing-cards-list";
@@ -1,3 +0,0 @@
1
- import { LoadConnect } from "./shared";
2
- export declare const loadConnect: LoadConnect;
3
- export {};