@stripe/connect-js 2.0.4 → 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.4"
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.4"
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.4"
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.4"
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.4",
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
 
@@ -6,114 +8,342 @@ export declare type OverlayOption = "dialog" | "drawer";
6
8
  * Appearance options for the Connect instance.
7
9
  */
8
10
  export declare type AppearanceOptions = {
11
+ /**
12
+ * The type of overlay used throughout the Connect.js design system. Set this to be either a Dialog or Drawer.
13
+ */
9
14
  overlays?: OverlayOption;
10
15
  variables?: AppearanceVariables;
11
16
  };
12
17
 
13
18
  export declare type AppearanceVariables = {
19
+ // Commonly used
20
+
21
+ /**
22
+ * The font family value used throughout embedded components. If an embedded component inherits a font-family value from an element on your site in which it’s placed, this setting overrides that inheritance.
23
+ */
24
+ fontFamily?: string;
25
+
26
+ /**
27
+ * The baseline font size set on the embedded component root. This scales the value of other font size variables. This supports pixel values only.
28
+ */
29
+ fontSizeBase?: string;
30
+
31
+ /**
32
+ * The base spacing unit that derives all spacing values. Increase or decrease this value to make your layout more or less spacious. This supports pixel values only.
33
+ */
34
+ spacingUnit?: string;
35
+
36
+ /**
37
+ * The general border radius used in embedded components. This sets the default border radius for all components. This supports pixel values only.
38
+ */
39
+ borderRadius?: string;
40
+
41
+ /**
42
+ * The primary color used throughout embedded components. Set this to your primary brand color. This accepts hex values or RGB/HSL strings.
43
+ */
14
44
  colorPrimary?: string;
45
+
46
+ /**
47
+ * The background color for embedded components, including overlays, tooltips, and popovers. This accepts hex values or RGB/HSL strings.
48
+ */
49
+ colorBackground?: string;
50
+
51
+ /**
52
+ * The color used for regular text. This accepts hex values or RGB/HSL strings.
53
+ */
54
+ colorText?: string;
55
+
56
+ /**
57
+ * The color used to indicate errors or destructive actions. This accepts hex values or RGB/HSL strings.
58
+ */
59
+ colorDanger?: string;
60
+
61
+ // Less commonly used
62
+
15
63
  // Primary Button
16
- buttonPrimaryColorBorder?: string;
64
+ /**
65
+ * The color used as a background for primary buttons. This accepts hex values or RGB/HSL strings.
66
+ */
17
67
  buttonPrimaryColorBackground?: string;
68
+ /**
69
+ * The border color used for primary buttons. This accepts hex values or RGB/HSL strings.
70
+ */
71
+ buttonPrimaryColorBorder?: string;
72
+ /**
73
+ * The text color used for primary buttons. This accepts hex values or RGB/HSL strings.
74
+ */
18
75
  buttonPrimaryColorText?: string;
76
+
19
77
  // Secondary Button
20
- buttonSecondaryColorBorder?: string;
78
+ /**
79
+ * The color used as a background for secondary buttons. This accepts hex values or RGB/HSL strings.
80
+ */
21
81
  buttonSecondaryColorBackground?: string;
82
+ /**
83
+ * The color used as a border for secondary buttons. This accepts hex values or RGB/HSL strings.
84
+ */
85
+ buttonSecondaryColorBorder?: string;
86
+ /**
87
+ * The text color used for secondary buttons. This accepts hex values or RGB/HSL strings.
88
+ */
22
89
  buttonSecondaryColorText?: string;
23
- // Link
90
+
91
+ /**
92
+ * The color used for secondary text. This accepts hex values or RGB/RGBA/HSL strings.
93
+ */
94
+ colorSecondaryText?: string;
95
+ /**
96
+ * The color used for primary actions and links. This accepts hex values or RGB/HSL strings.
97
+ */
24
98
  actionPrimaryColorText?: string;
99
+ /**
100
+ * The color used for secondary actions and links. This accepts hex values or RGB/HSL strings.
101
+ */
25
102
  actionSecondaryColorText?: string;
26
- // Border
27
- colorBorder?: string;
28
- // Form
29
- formHighlightColorBorder?: string;
30
- formAccentColor?: string;
31
- // Text
32
- colorText?: string;
33
- colorSecondaryText?: string;
34
- // Background
35
- colorBackground?: string;
36
- offsetBackgroundColor?: string;
37
- formBackgroundColor?: string;
38
-
39
- // Feedback Colors
40
- colorDanger?: string;
41
103
 
42
104
  // Neutral Badge Colors
43
- badgeNeutralColorBorder?: string;
105
+ /**
106
+ * The background color used to represent neutral state or lack of state in status badges. This accepts hex values or RGB/HSL strings.
107
+ */
44
108
  badgeNeutralColorBackground?: string;
109
+ /**
110
+ * The text color used to represent neutral state or lack of state in status badges. This accepts hex values or RGB/HSL strings.
111
+ */
45
112
  badgeNeutralColorText?: string;
113
+ /**
114
+ * The border color used to represent neutral state or lack of state in status badges. This accepts hex values or RGB/RGBA/HSL strings.
115
+ */
116
+ badgeNeutralColorBorder?: string;
46
117
 
47
118
  // Success Badge Colors
48
- badgeSuccessColorBorder?: string;
119
+ /**
120
+ * The background color used to reinforce a successful outcome in status badges. This accepts hex values or RGB/HSL strings.
121
+ */
49
122
  badgeSuccessColorBackground?: string;
123
+ /**
124
+ * The text color used to reinforce a successful outcome in status badges. This accepts hex values or RGB/HSL strings.
125
+ */
50
126
  badgeSuccessColorText?: string;
127
+ /**
128
+ * The border color used to reinforce a successful outcome in status badges. This accepts hex values or RGB/RGBA/HSL strings.
129
+ */
130
+ badgeSuccessColorBorder?: string;
51
131
 
52
132
  // Warning Badge Colors
53
- badgeWarningColorBorder?: string;
133
+ /**
134
+ * The background color used in status badges to highlight things that might require action, but are optional to resolve. This accepts hex values or RGB/HSL strings.
135
+ */
54
136
  badgeWarningColorBackground?: string;
137
+ /**
138
+ * The text color used in status badges to highlight things that might require action, but are optional to resolve. This accepts hex values or RGB/HSL strings.
139
+ */
55
140
  badgeWarningColorText?: string;
141
+ /**
142
+ * The border color used in status badges to highlight things that might require action, but are optional to resolve. This accepts hex values or RGB/RGBA/HSL strings.
143
+ */
144
+ badgeWarningColorBorder?: string;
56
145
 
57
146
  // Danger Badge Colors
58
- badgeDangerColorBorder?: string;
147
+ /**
148
+ * The background color used in status badges for high-priority, critical situations that the user must address immediately, and to indicate failed or unsuccessful outcomes. This accepts hex values or RGB/HSL strings.
149
+ */
59
150
  badgeDangerColorBackground?: string;
151
+ /**
152
+ * The text color used in status badges for high-priority, critical situations that the user must address immediately, and to indicate failed or unsuccessful outcomes. This accepts hex values or RGB/HSL strings.
153
+ */
60
154
  badgeDangerColorText?: string;
155
+ /**
156
+ * The border color used in status badges for high-priority, critical situations that the user must address immediately, and to indicate failed or unsuccessful outcomes. This accepts hex values or RGB/RGBA/HSL strings.
157
+ */
158
+ badgeDangerColorBorder?: string;
159
+
160
+ // Background
161
+ /**
162
+ * The background color used when highlighting information, like the selected row on a table or particular piece of UI. This accepts hex values or RGB/HSL strings.
163
+ */
164
+ offsetBackgroundColor?: string;
165
+ /**
166
+ * The background color used for form items. This accepts hex values or RGB/HSL strings.
167
+ */
168
+ formBackgroundColor?: string;
169
+
170
+ /**
171
+ * The color used for borders throughout the component. This accepts hex values or RGB/RGBA/HSL strings.
172
+ */
173
+ colorBorder?: string;
174
+
175
+ // Form
176
+ /**
177
+ * The color used to highlight form items when focused. This accepts hex values or RGB/RGBA/HSL strings.
178
+ */
179
+ formHighlightColorBorder?: string;
180
+ /**
181
+ * The color used for to fill in form items like checkboxes, radio buttons and switches. This accepts hex values or RGB/HSL strings.
182
+ */
183
+ formAccentColor?: string;
61
184
 
62
185
  // Border Sizing
63
- borderRadius?: string;
186
+ /**
187
+ * The border radius used for buttons. This supports pixel values only.
188
+ */
64
189
  buttonBorderRadius?: string;
190
+ /**
191
+ * The border radius used for form elements. This supports pixel values only.
192
+ */
65
193
  formBorderRadius?: string;
194
+ /**
195
+ * The border radius used for badges. This supports pixel values only.
196
+ */
66
197
  badgeBorderRadius?: string;
198
+ /**
199
+ * The border radius used for overlays. This supports pixel values only.
200
+ */
67
201
  overlayBorderRadius?: string;
68
202
 
69
- // Overlay
70
- overlayZIndex?: number;
71
-
72
203
  // Font Sizing
73
- fontSizeBase?: string;
74
204
 
75
- // Spacing
76
- spacingUnit?: string;
205
+ // Overlay
206
+ /**
207
+ * A z-index to use for the overlay throughout embedded components. Set this number to control the z-order of the overlay.
208
+ */
209
+ overlayZIndex?: number;
77
210
 
78
211
  // Body Typography
212
+ /**
213
+ * The font size for the large body typography. Body typography variables accept a valid font size value.
214
+ */
79
215
  bodyLgFontSize?: string;
216
+ /**
217
+ * The font weight for the large body typography. Body typography variables accept a valid font weight value.
218
+ */
80
219
  bodyLgFontWeight?: string;
220
+ /**
221
+ * The font size for the medium body typography. Body typography variables accept a valid font size value.
222
+ */
81
223
  bodyMdFontSize?: string;
224
+ /**
225
+ * The font weight for the medium body typography. Body typography variables accept a valid font weight value.
226
+ */
82
227
  bodyMdFontWeight?: string;
228
+ /**
229
+ * The font size for the small body typography. Body typography variables accept a valid font size value.
230
+ */
83
231
  bodySmFontSize?: string;
232
+ /**
233
+ * The font weight for the small body typography. Body typography variables accept a valid font weight value.
234
+ */
84
235
  bodySmFontWeight?: string;
85
236
 
86
- // Label Typography
87
- labelLgFontSize?: string;
88
- labelLgFontWeight?: string;
89
- labelLgTextTransform?: string;
90
- labelMdFontSize?: string;
91
- labelMdFontWeight?: string;
92
- labelMdTextTransform?: string;
93
- labelSmFontSize?: string;
94
- labelSmFontWeight?: string;
95
- labelSmTextTransform?: string;
96
-
97
237
  // Heading Typography
238
+ /**
239
+ * The font size for the extra large heading typography. Heading typography variables accept a valid font size value.
240
+ */
98
241
  headingXlFontSize?: string;
242
+ /**
243
+ * The font weight for the extra large heading typography. Heading typography variables accept a valid font weight value.
244
+ */
99
245
  headingXlFontWeight?: string;
246
+ /**
247
+ * The text transform for the extra large heading typography. Heading typography variables accept a valid text transform value.
248
+ */
100
249
  headingXlTextTransform?: string;
250
+ /**
251
+ * The font size for the large heading typography. Heading typography variables accept a valid font size value.
252
+ */
101
253
  headingLgFontSize?: string;
254
+ /**
255
+ * The font weight for the large heading typography. Heading typography variables accept a valid font weight value.
256
+ */
102
257
  headingLgFontWeight?: string;
258
+ /**
259
+ * The text transform for the large heading typography. Heading typography variables accept a valid text transform value.
260
+ */
103
261
  headingLgTextTransform?: string;
262
+ /**
263
+ * The font size for the medium heading typography. Heading typography variables accept a valid font size value.
264
+ */
104
265
  headingMdFontSize?: string;
266
+ /**
267
+ * The font weight for the medium heading typography. Heading typography variables accept a valid font weight value.
268
+ */
105
269
  headingMdFontWeight?: string;
270
+ /**
271
+ * The text transform for the medium heading typography. Heading typography variables accept a valid text transform value.
272
+ */
106
273
  headingMdTextTransform?: string;
274
+ /**
275
+ * The font size for the small heading typography. Heading typography variables accept a valid font size value.
276
+ */
107
277
  headingSmFontSize?: string;
278
+ /**
279
+ * The font weight for the small heading typography. Heading typography variables accept a valid font weight value.
280
+ */
108
281
  headingSmFontWeight?: string;
282
+ /**
283
+ * The text transform for the small heading typography. Heading typography variables accept a valid text transform value.
284
+ */
109
285
  headingSmTextTransform?: string;
286
+ /**
287
+ * The font size for the extra small heading typography. Heading typography variables accept a valid font size value.
288
+ */
110
289
  headingXsFontSize?: string;
290
+ /**
291
+ * The font weight for the extra small heading typography. Heading typography variables accept a valid font weight value.
292
+ */
111
293
  headingXsFontWeight?: string;
294
+ /**
295
+ * The text transform for the extra small heading typography. Heading typography variables accept a valid text transform value.
296
+ */
112
297
  headingXsTextTransform?: string;
298
+
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;
312
+ /**
313
+ * The font size for the medium label typography. Label typography variables accept a valid font size value.
314
+ */
315
+ labelMdFontSize?: string;
316
+ /**
317
+ * The font weight for the medium label typography. Label typography variables accept a valid font weight value.
318
+ */
319
+ labelMdFontWeight?: string;
320
+ /**
321
+ * The text transform for the medium label typography. Label typography variables accept a valid text transform value.
322
+ */
323
+ labelMdTextTransform?: string;
324
+ /**
325
+ * The font size for the small label typography. Label typography variables accept a valid font size value.
326
+ */
327
+ labelSmFontSize?: string;
328
+ /**
329
+ * The font weight for the small label typography. Label typography variables accept a valid font weight value.
330
+ */
331
+ labelSmFontWeight?: string;
332
+ /**
333
+ * The text transform for the small label typography. Label typography variables accept a valid text transform value.
334
+ */
335
+ labelSmTextTransform?: string;
113
336
  };
114
337
 
115
338
  export type IStripeConnectUpdateParams = {
339
+ /**
340
+ * Appearance options for the Connect instance.
341
+ */
116
342
  appearance?: AppearanceOptions;
343
+
344
+ /**
345
+ * The locale to use for the Connect instance.
346
+ */
117
347
  locale?: string;
118
348
  };
119
349
 
@@ -127,9 +357,10 @@ export interface IStripeConnectInitParams {
127
357
  publishableKey: string;
128
358
 
129
359
  /**
130
- * The client secret for the connected account.
360
+ * Function that fetches client secret
361
+ * @returns A promise that resolves with a new client secret.
131
362
  */
132
- clientSecret: string;
363
+ fetchClientSecret: () => Promise<string>;
133
364
 
134
365
  /**
135
366
  * Appearance options for the Connect instance.
@@ -137,24 +368,37 @@ export interface IStripeConnectInitParams {
137
368
  */
138
369
  appearance?: AppearanceOptions;
139
370
 
140
- /**
141
- * Callback function that returns a new client secret. Used to support long running sessions and called on account session expiry.
142
- */
143
- refreshClientSecret?: () => Promise<string>;
144
-
145
371
  /**
146
372
  * The locale to use for the Connect instance.
147
373
  */
148
374
  locale?: string;
149
375
  }
150
376
 
151
- export interface StripeConnectWrapper {
152
- /**
153
- * Initializes a Connect JS instance that can be used to create and update Connect components.
154
- * @param params Initialization parameters for Connect JS. See https://stripe.com/docs/connect/get-started-connect-embedded-components#configuring-connect-js for more details.
155
- * @returns A Connect JS instance.
156
- */
157
- 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
+ };
158
402
  }
159
403
 
160
404
  export interface StripeConnectInstance {
@@ -163,7 +407,9 @@ export interface StripeConnectInstance {
163
407
  * @tagName Name of the Connect component to create.
164
408
  * @returns An HTML component corresponding to that connect component
165
409
  */
166
- create: (tagName: ConnectElementTagName) => HTMLElement | null;
410
+ create: <T extends ConnectElementTagName>(
411
+ tagName: T
412
+ ) => ConnectHTMLElementRecord[T];
167
413
 
168
414
  /**
169
415
  * Updates the Connect instance with new parameters.
@@ -181,12 +427,14 @@ export interface StripeConnectInstance {
181
427
  /**
182
428
  * Tagnames to be used with the `create` method of the Connect instance.
183
429
  */
184
- export type ConnectElementTagName = "account-onboarding";
185
-
186
- export declare const findScript: () => HTMLScriptElement | null;
187
-
188
- export declare const loadScript: () => Promise<any | null>;
189
-
190
- export declare const initStripeConnect: (
191
- stripeConnectPromise: StripeConnectWrapper | null
192
- ) => 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 {};