@stripe/connect-js 1.0.7 → 1.0.9

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.
@@ -0,0 +1,111 @@
1
+ var version = "1.0.9";
2
+
3
+ const componentNameMapping = {
4
+ payments: "stripe-connect-payments",
5
+ payouts: "stripe-connect-payouts",
6
+ "payment-details": "stripe-connect-payment-details",
7
+ "account-onboarding": "stripe-connect-account-onboarding"
8
+ };
9
+ const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
10
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
11
+ const findScript = () => {
12
+ return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
13
+ };
14
+ const injectScript = () => {
15
+ const script = document.createElement("script");
16
+ script.src = "https://connect-js.stripe.com/v0.1/connect.js";
17
+ const head = document.head;
18
+ if (!head) {
19
+ throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
20
+ }
21
+ document.head.appendChild(script);
22
+ return script;
23
+ };
24
+ let stripePromise = null;
25
+ const loadScript = () => {
26
+ // Ensure that we only attempt to load Connect.js at most once
27
+ if (stripePromise !== null) {
28
+ return stripePromise;
29
+ }
30
+ stripePromise = new Promise((resolve, reject) => {
31
+ if (window.StripeConnect) {
32
+ console.warn(EXISTING_SCRIPT_MESSAGE);
33
+ }
34
+ if (window.StripeConnect) {
35
+ const wrapper = createWrapper(window.StripeConnect);
36
+ resolve(wrapper);
37
+ return;
38
+ }
39
+ try {
40
+ let script = findScript();
41
+ if (script) {
42
+ console.warn(EXISTING_SCRIPT_MESSAGE);
43
+ } else if (!script) {
44
+ script = injectScript();
45
+ }
46
+ script.addEventListener("load", () => {
47
+ if (window.StripeConnect) {
48
+ const wrapper = createWrapper(window.StripeConnect);
49
+ resolve(wrapper);
50
+ } else {
51
+ reject(new Error("Connect.js did not load the necessary objects"));
52
+ }
53
+ });
54
+ script.addEventListener("error", () => {
55
+ reject(new Error("Failed to load Connect.js"));
56
+ });
57
+ } catch (error) {
58
+ reject(error);
59
+ }
60
+ });
61
+ return stripePromise;
62
+ };
63
+ const initStripeConnect = stripeConnectPromise => {
64
+ if (stripeConnectPromise === null) {
65
+ return null;
66
+ }
67
+ return stripeConnectPromise;
68
+ };
69
+ const createWrapper = stripeConnect => {
70
+ const wrapper = {
71
+ initialize: params => {
72
+ var _a;
73
+ const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
74
+ const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
75
+ metaOptions: Object.assign(Object.assign({}, metaOptions), {
76
+ sdk: true,
77
+ sdkOptions: {
78
+ sdkVersion: version
79
+ }
80
+ })
81
+ }));
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
+ return stripeConnectInstance;
92
+ }
93
+ };
94
+ return wrapper;
95
+ };
96
+
97
+ // Execute our own script injection after a tick to give users time to do their
98
+ // own script injection.
99
+ const stripePromise$1 = Promise.resolve().then(() => loadScript());
100
+ let loadCalled = false;
101
+ stripePromise$1.catch(err => {
102
+ if (!loadCalled) {
103
+ console.warn(err);
104
+ }
105
+ });
106
+ const loadConnect = () => {
107
+ loadCalled = true;
108
+ return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
109
+ };
110
+
111
+ export { loadConnect };
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var version = "1.0.9";
6
+
7
+ const componentNameMapping = {
8
+ payments: "stripe-connect-payments",
9
+ payouts: "stripe-connect-payouts",
10
+ "payment-details": "stripe-connect-payment-details",
11
+ "account-onboarding": "stripe-connect-account-onboarding"
12
+ };
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";
14
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
15
+ const findScript = () => {
16
+ return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
17
+ };
18
+ const injectScript = () => {
19
+ const script = document.createElement("script");
20
+ script.src = "https://connect-js.stripe.com/v0.1/connect.js";
21
+ const head = document.head;
22
+ if (!head) {
23
+ throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
24
+ }
25
+ document.head.appendChild(script);
26
+ return script;
27
+ };
28
+ let stripePromise = null;
29
+ const loadScript = () => {
30
+ // Ensure that we only attempt to load Connect.js at most once
31
+ if (stripePromise !== null) {
32
+ return stripePromise;
33
+ }
34
+ stripePromise = new Promise((resolve, reject) => {
35
+ if (window.StripeConnect) {
36
+ console.warn(EXISTING_SCRIPT_MESSAGE);
37
+ }
38
+ if (window.StripeConnect) {
39
+ const wrapper = createWrapper(window.StripeConnect);
40
+ resolve(wrapper);
41
+ return;
42
+ }
43
+ try {
44
+ let script = findScript();
45
+ if (script) {
46
+ console.warn(EXISTING_SCRIPT_MESSAGE);
47
+ } else if (!script) {
48
+ script = injectScript();
49
+ }
50
+ script.addEventListener("load", () => {
51
+ if (window.StripeConnect) {
52
+ const wrapper = createWrapper(window.StripeConnect);
53
+ resolve(wrapper);
54
+ } else {
55
+ reject(new Error("Connect.js did not load the necessary objects"));
56
+ }
57
+ });
58
+ script.addEventListener("error", () => {
59
+ reject(new Error("Failed to load Connect.js"));
60
+ });
61
+ } catch (error) {
62
+ reject(error);
63
+ }
64
+ });
65
+ return stripePromise;
66
+ };
67
+ const initStripeConnect = stripeConnectPromise => {
68
+ if (stripeConnectPromise === null) {
69
+ return null;
70
+ }
71
+ return stripeConnectPromise;
72
+ };
73
+ const createWrapper = stripeConnect => {
74
+ const wrapper = {
75
+ initialize: params => {
76
+ var _a;
77
+ const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
78
+ const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
79
+ metaOptions: Object.assign(Object.assign({}, metaOptions), {
80
+ sdk: true,
81
+ sdkOptions: {
82
+ sdkVersion: version
83
+ }
84
+ })
85
+ }));
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
+ return stripeConnectInstance;
96
+ }
97
+ };
98
+ return wrapper;
99
+ };
100
+
101
+ // Execute our own script injection after a tick to give users time to do their
102
+ // own script injection.
103
+ const stripePromise$1 = Promise.resolve().then(() => loadScript());
104
+ let loadCalled = false;
105
+ stripePromise$1.catch(err => {
106
+ if (!loadCalled) {
107
+ console.warn(err);
108
+ }
109
+ });
110
+ const loadConnect = () => {
111
+ loadCalled = true;
112
+ return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
113
+ };
114
+
115
+ exports.loadConnect = loadConnect;
@@ -0,0 +1,101 @@
1
+ var version = "1.0.9";
2
+
3
+ const componentNameMapping = {
4
+ payments: "stripe-connect-payments",
5
+ payouts: "stripe-connect-payouts",
6
+ "payment-details": "stripe-connect-payment-details",
7
+ "account-onboarding": "stripe-connect-account-onboarding"
8
+ };
9
+ const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
10
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
11
+ const findScript = () => {
12
+ return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
13
+ };
14
+ const injectScript = () => {
15
+ const script = document.createElement("script");
16
+ script.src = "https://connect-js.stripe.com/v0.1/connect.js";
17
+ const head = document.head;
18
+ if (!head) {
19
+ throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
20
+ }
21
+ document.head.appendChild(script);
22
+ return script;
23
+ };
24
+ let stripePromise = null;
25
+ const loadScript = () => {
26
+ // Ensure that we only attempt to load Connect.js at most once
27
+ if (stripePromise !== null) {
28
+ return stripePromise;
29
+ }
30
+ stripePromise = new Promise((resolve, reject) => {
31
+ if (window.StripeConnect) {
32
+ console.warn(EXISTING_SCRIPT_MESSAGE);
33
+ }
34
+ if (window.StripeConnect) {
35
+ const wrapper = createWrapper(window.StripeConnect);
36
+ resolve(wrapper);
37
+ return;
38
+ }
39
+ try {
40
+ let script = findScript();
41
+ if (script) {
42
+ console.warn(EXISTING_SCRIPT_MESSAGE);
43
+ } else if (!script) {
44
+ script = injectScript();
45
+ }
46
+ script.addEventListener("load", () => {
47
+ if (window.StripeConnect) {
48
+ const wrapper = createWrapper(window.StripeConnect);
49
+ resolve(wrapper);
50
+ } else {
51
+ reject(new Error("Connect.js did not load the necessary objects"));
52
+ }
53
+ });
54
+ script.addEventListener("error", () => {
55
+ reject(new Error("Failed to load Connect.js"));
56
+ });
57
+ } catch (error) {
58
+ reject(error);
59
+ }
60
+ });
61
+ return stripePromise;
62
+ };
63
+ const initStripeConnect = stripeConnectPromise => {
64
+ if (stripeConnectPromise === null) {
65
+ return null;
66
+ }
67
+ return stripeConnectPromise;
68
+ };
69
+ const createWrapper = stripeConnect => {
70
+ const wrapper = {
71
+ initialize: params => {
72
+ var _a;
73
+ const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
74
+ const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
75
+ metaOptions: Object.assign(Object.assign({}, metaOptions), {
76
+ sdk: true,
77
+ sdkOptions: {
78
+ sdkVersion: version
79
+ }
80
+ })
81
+ }));
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
+ return stripeConnectInstance;
92
+ }
93
+ };
94
+ return wrapper;
95
+ };
96
+
97
+ const loadConnect = () => {
98
+ return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
99
+ };
100
+
101
+ export { loadConnect };
package/dist/pure.js ADDED
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var version = "1.0.9";
6
+
7
+ const componentNameMapping = {
8
+ payments: "stripe-connect-payments",
9
+ payouts: "stripe-connect-payouts",
10
+ "payment-details": "stripe-connect-payment-details",
11
+ "account-onboarding": "stripe-connect-account-onboarding"
12
+ };
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";
14
+ const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
15
+ const findScript = () => {
16
+ return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
17
+ };
18
+ const injectScript = () => {
19
+ const script = document.createElement("script");
20
+ script.src = "https://connect-js.stripe.com/v0.1/connect.js";
21
+ const head = document.head;
22
+ if (!head) {
23
+ throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
24
+ }
25
+ document.head.appendChild(script);
26
+ return script;
27
+ };
28
+ let stripePromise = null;
29
+ const loadScript = () => {
30
+ // Ensure that we only attempt to load Connect.js at most once
31
+ if (stripePromise !== null) {
32
+ return stripePromise;
33
+ }
34
+ stripePromise = new Promise((resolve, reject) => {
35
+ if (window.StripeConnect) {
36
+ console.warn(EXISTING_SCRIPT_MESSAGE);
37
+ }
38
+ if (window.StripeConnect) {
39
+ const wrapper = createWrapper(window.StripeConnect);
40
+ resolve(wrapper);
41
+ return;
42
+ }
43
+ try {
44
+ let script = findScript();
45
+ if (script) {
46
+ console.warn(EXISTING_SCRIPT_MESSAGE);
47
+ } else if (!script) {
48
+ script = injectScript();
49
+ }
50
+ script.addEventListener("load", () => {
51
+ if (window.StripeConnect) {
52
+ const wrapper = createWrapper(window.StripeConnect);
53
+ resolve(wrapper);
54
+ } else {
55
+ reject(new Error("Connect.js did not load the necessary objects"));
56
+ }
57
+ });
58
+ script.addEventListener("error", () => {
59
+ reject(new Error("Failed to load Connect.js"));
60
+ });
61
+ } catch (error) {
62
+ reject(error);
63
+ }
64
+ });
65
+ return stripePromise;
66
+ };
67
+ const initStripeConnect = stripeConnectPromise => {
68
+ if (stripeConnectPromise === null) {
69
+ return null;
70
+ }
71
+ return stripeConnectPromise;
72
+ };
73
+ const createWrapper = stripeConnect => {
74
+ const wrapper = {
75
+ initialize: params => {
76
+ var _a;
77
+ const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
78
+ const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
79
+ metaOptions: Object.assign(Object.assign({}, metaOptions), {
80
+ sdk: true,
81
+ sdkOptions: {
82
+ sdkVersion: version
83
+ }
84
+ })
85
+ }));
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
+ return stripeConnectInstance;
96
+ }
97
+ };
98
+ return wrapper;
99
+ };
100
+
101
+ const loadConnect = () => {
102
+ return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
103
+ };
104
+
105
+ exports.loadConnect = loadConnect;
@@ -0,0 +1,3 @@
1
+ import { LoadConnect } from "./shared";
2
+ export declare const loadConnect: LoadConnect;
3
+ export {};
@@ -0,0 +1,2 @@
1
+ import { LoadConnect } from "./shared";
2
+ export declare const loadConnect: LoadConnect;
@@ -0,0 +1,5 @@
1
+ import { StripeConnectWrapper } from "../types";
2
+ export type LoadConnect = () => Promise<StripeConnectWrapper>;
3
+ export declare const findScript: () => HTMLScriptElement | null;
4
+ export declare const loadScript: () => Promise<StripeConnectWrapper | null>;
5
+ export declare const initStripeConnect: (stripeConnectPromise: StripeConnectWrapper | null) => any | null;
@@ -0,0 +1,2 @@
1
+ export declare const SCRIPT_SELECTOR = "script[src^=\"https://connect-js.stripe.com/v0.1/connect.js\"]";
2
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/connect-js",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Connect.js loading utility package",
5
5
  "main": "dist/connect.js",
6
6
  "module": "dist/connect.esm.js",
@@ -65,5 +65,8 @@
65
65
  "typescript": "^4.1.2",
66
66
  "yalc": "^1.0.0-pre.53",
67
67
  "zx": "^4.2.0"
68
+ },
69
+ "dependencies": {
70
+ "@rollup/plugin-json": "^6.0.0"
68
71
  }
69
72
  }
package/src/shared.ts CHANGED
@@ -1,8 +1,28 @@
1
1
  import { version } from ".././package.json";
2
- import { StripeConnectWrapper, IStripeConnectInitParams } from "../types";
2
+ import {
3
+ StripeConnectWrapper,
4
+ IStripeConnectInitParams,
5
+ ConnectElementTagName
6
+ } from "../types";
3
7
 
4
8
  export type LoadConnect = () => Promise<StripeConnectWrapper>;
5
9
 
10
+ type ConnectElementHTMLName =
11
+ | "stripe-connect-payments"
12
+ | "stripe-connect-payouts"
13
+ | "stripe-connect-payment-details"
14
+ | "stripe-connect-account-onboarding";
15
+
16
+ const componentNameMapping: Record<
17
+ ConnectElementTagName,
18
+ ConnectElementHTMLName
19
+ > = {
20
+ payments: "stripe-connect-payments",
21
+ payouts: "stripe-connect-payouts",
22
+ "payment-details": "stripe-connect-payment-details",
23
+ "account-onboarding": "stripe-connect-account-onboarding"
24
+ };
25
+
6
26
  const EXISTING_SCRIPT_MESSAGE =
7
27
  "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
8
28
  const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
@@ -92,7 +112,7 @@ const createWrapper = (stripeConnect: any) => {
92
112
  const wrapper: StripeConnectWrapper = {
93
113
  initialize: (params: IStripeConnectInitParams) => {
94
114
  const metaOptions = (params as any).metaOptions ?? {};
95
- return stripeConnect.init({
115
+ const stripeConnectInstance = stripeConnect.init({
96
116
  ...params,
97
117
  metaOptions: {
98
118
  ...metaOptions,
@@ -102,9 +122,19 @@ const createWrapper = (stripeConnect: any) => {
102
122
  }
103
123
  }
104
124
  });
105
- },
106
- logout: async () => {
107
- await stripeConnect.logout();
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
+ return stripeConnectInstance;
108
138
  }
109
139
  };
110
140
  return wrapper;
package/types/shared.d.ts CHANGED
@@ -122,12 +122,6 @@ export interface StripeConnectWrapper {
122
122
  * @returns A Connect JS instance.
123
123
  */
124
124
  initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
125
-
126
- /**
127
- * Logs the user out of Connect JS sessions
128
- * @returns A promise that resolves when the user is logged out.
129
- */
130
- logout: () => Promise<void>;
131
125
  }
132
126
 
133
127
  export interface StripeConnectInstance {
@@ -143,14 +137,19 @@ export interface StripeConnectInstance {
143
137
  * @options New parameters to update the Connect instance with.
144
138
  */
145
139
  update: (options: IStripeConnectUpdateParams) => void;
146
- }
147
140
 
148
- export type ConnectElementHTMLName =
149
- | "stripe-connect-payments"
150
- | "stripe-connect-payouts"
151
- | "stripe-connect-payment-details";
141
+ /**
142
+ * Logs the user out of Connect JS sessions
143
+ * @returns A promise that resolves when the user is logged out.
144
+ */
145
+ logout: () => Promise<void>;
146
+ }
152
147
 
153
- export type ConnectElementTagName = "payments" | "payouts" | "payment-details";
148
+ export type ConnectElementTagName =
149
+ | "payments"
150
+ | "payouts"
151
+ | "payment-details"
152
+ | "account-onboarding";
154
153
 
155
154
  export declare const findScript: () => HTMLScriptElement | null;
156
155