@stripe/connect-js 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  The [Connect.js library](https://stripe.com/docs/connect/get-started-connect-embedded-components) and its supporting API allows you to add connected account dashboard functionality to your website.
4
4
  This NPM package contains initialization logic for Connect embedded components along with related types.
5
5
 
6
+ Calling `loadConnect` always loads the latest version of Connect.js, regardless of which version of `@stripe/connect-js` you use. Updates for this package only impact tooling around the `loadConnect` helper itself and the TypeScript type definitions provided for Connect.js. Updates do not affect runtime availability of features of Connect.js.
7
+
6
8
  Note: Connect embedded components is currently still in beta. Please [contact us](https://stripe.com/docs/connect/get-started-connect-embedded-components#access) to request beta access.
7
9
 
8
10
  ## Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/connect-js",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Connect.js loading utility package",
5
5
  "main": "dist/connect.js",
6
6
  "module": "dist/connect.esm.js",
package/src/shared.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { version } from ".././package.json";
1
2
  import { StripeConnectWrapper, IStripeConnectInitParams } from "../types";
2
3
 
3
4
  export type LoadConnect = () => Promise<StripeConnectWrapper>;
@@ -95,9 +96,15 @@ const createWrapper = (stripeConnect: any) => {
95
96
  ...params,
96
97
  metaOptions: {
97
98
  ...metaOptions,
98
- sdk: true
99
+ sdk: true,
100
+ sdkOptions: {
101
+ sdkVersion: version
102
+ }
99
103
  }
100
104
  });
105
+ },
106
+ logout: async () => {
107
+ await stripeConnect.logout();
101
108
  }
102
109
  };
103
110
  return wrapper;
package/types/shared.d.ts CHANGED
@@ -116,19 +116,42 @@ export interface IStripeConnectInitParams {
116
116
  }
117
117
 
118
118
  export interface StripeConnectWrapper {
119
+ /**
120
+ * Initializes a Connect JS instance that can be used to create and update Connect components.
121
+ * @param params Initialization parameters for Connect JS. See https://stripe.com/docs/connect/get-started-connect-embedded-components#configuring-connect-js for more details.
122
+ * @returns A Connect JS instance.
123
+ */
119
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>;
120
131
  }
121
132
 
122
133
  export interface StripeConnectInstance {
134
+ /**
135
+ * Creates a Connect element.
136
+ * @tagName Name of the Connect component to create.
137
+ * @returns An HTML component corresponding to that connect component
138
+ */
123
139
  create: (tagName: ConnectElementTagName) => HTMLElement | null;
140
+
141
+ /**
142
+ * Updates the Connect instance with new parameters.
143
+ * @options New parameters to update the Connect instance with.
144
+ */
124
145
  update: (options: IStripeConnectUpdateParams) => void;
125
146
  }
126
147
 
127
- export type ConnectElementTagName =
148
+ export type ConnectElementHTMLName =
128
149
  | "stripe-connect-payments"
129
150
  | "stripe-connect-payouts"
130
151
  | "stripe-connect-payment-details";
131
152
 
153
+ export type ConnectElementTagName = "payments" | "payouts" | "payment-details";
154
+
132
155
  export declare const findScript: () => HTMLScriptElement | null;
133
156
 
134
157
  export declare const loadScript: () => Promise<any | null>;
@@ -1,90 +0,0 @@
1
- const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
2
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
3
- const findScript = () => {
4
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
5
- };
6
- const injectScript = () => {
7
- const script = document.createElement("script");
8
- script.src = "https://connect-js.stripe.com/v0.1/connect.js";
9
- const head = document.head;
10
- if (!head) {
11
- throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
12
- }
13
- document.head.appendChild(script);
14
- return script;
15
- };
16
- let stripePromise = null;
17
- const loadScript = () => {
18
- // Ensure that we only attempt to load Connect.js at most once
19
- if (stripePromise !== null) {
20
- return stripePromise;
21
- }
22
- stripePromise = new Promise((resolve, reject) => {
23
- if (window.StripeConnect) {
24
- console.warn(EXISTING_SCRIPT_MESSAGE);
25
- }
26
- if (window.StripeConnect) {
27
- const wrapper = createWrapper(window.StripeConnect);
28
- resolve(wrapper);
29
- return;
30
- }
31
- try {
32
- let script = findScript();
33
- if (script) {
34
- console.warn(EXISTING_SCRIPT_MESSAGE);
35
- } else if (!script) {
36
- script = injectScript();
37
- }
38
- script.addEventListener("load", () => {
39
- if (window.StripeConnect) {
40
- const wrapper = createWrapper(window.StripeConnect);
41
- resolve(wrapper);
42
- } else {
43
- reject(new Error("Connect.js did not load the necessary objects"));
44
- }
45
- });
46
- script.addEventListener("error", () => {
47
- reject(new Error("Failed to load Connect.js"));
48
- });
49
- } catch (error) {
50
- reject(error);
51
- }
52
- });
53
- return stripePromise;
54
- };
55
- const initStripeConnect = stripeConnectPromise => {
56
- if (stripeConnectPromise === null) {
57
- return null;
58
- }
59
- return stripeConnectPromise;
60
- };
61
- const createWrapper = stripeConnect => {
62
- const wrapper = {
63
- initialize: params => {
64
- var _a;
65
- const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
66
- return stripeConnect.init(Object.assign(Object.assign({}, params), {
67
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
68
- sdk: true
69
- })
70
- }));
71
- }
72
- };
73
- return wrapper;
74
- };
75
-
76
- // Execute our own script injection after a tick to give users time to do their
77
- // own script injection.
78
- const stripePromise$1 = Promise.resolve().then(() => loadScript());
79
- let loadCalled = false;
80
- stripePromise$1.catch(err => {
81
- if (!loadCalled) {
82
- console.warn(err);
83
- }
84
- });
85
- const loadConnect = () => {
86
- loadCalled = true;
87
- return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
88
- };
89
-
90
- export { loadConnect };
package/dist/connect.js DELETED
@@ -1,94 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
6
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
7
- const findScript = () => {
8
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
9
- };
10
- const injectScript = () => {
11
- const script = document.createElement("script");
12
- script.src = "https://connect-js.stripe.com/v0.1/connect.js";
13
- const head = document.head;
14
- if (!head) {
15
- throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
16
- }
17
- document.head.appendChild(script);
18
- return script;
19
- };
20
- let stripePromise = null;
21
- const loadScript = () => {
22
- // Ensure that we only attempt to load Connect.js at most once
23
- if (stripePromise !== null) {
24
- return stripePromise;
25
- }
26
- stripePromise = new Promise((resolve, reject) => {
27
- if (window.StripeConnect) {
28
- console.warn(EXISTING_SCRIPT_MESSAGE);
29
- }
30
- if (window.StripeConnect) {
31
- const wrapper = createWrapper(window.StripeConnect);
32
- resolve(wrapper);
33
- return;
34
- }
35
- try {
36
- let script = findScript();
37
- if (script) {
38
- console.warn(EXISTING_SCRIPT_MESSAGE);
39
- } else if (!script) {
40
- script = injectScript();
41
- }
42
- script.addEventListener("load", () => {
43
- if (window.StripeConnect) {
44
- const wrapper = createWrapper(window.StripeConnect);
45
- resolve(wrapper);
46
- } else {
47
- reject(new Error("Connect.js did not load the necessary objects"));
48
- }
49
- });
50
- script.addEventListener("error", () => {
51
- reject(new Error("Failed to load Connect.js"));
52
- });
53
- } catch (error) {
54
- reject(error);
55
- }
56
- });
57
- return stripePromise;
58
- };
59
- const initStripeConnect = stripeConnectPromise => {
60
- if (stripeConnectPromise === null) {
61
- return null;
62
- }
63
- return stripeConnectPromise;
64
- };
65
- const createWrapper = stripeConnect => {
66
- const wrapper = {
67
- initialize: params => {
68
- var _a;
69
- const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
70
- return stripeConnect.init(Object.assign(Object.assign({}, params), {
71
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
72
- sdk: true
73
- })
74
- }));
75
- }
76
- };
77
- return wrapper;
78
- };
79
-
80
- // Execute our own script injection after a tick to give users time to do their
81
- // own script injection.
82
- const stripePromise$1 = Promise.resolve().then(() => loadScript());
83
- let loadCalled = false;
84
- stripePromise$1.catch(err => {
85
- if (!loadCalled) {
86
- console.warn(err);
87
- }
88
- });
89
- const loadConnect = () => {
90
- loadCalled = true;
91
- return stripePromise$1.then(maybeConnect => initStripeConnect(maybeConnect));
92
- };
93
-
94
- exports.loadConnect = loadConnect;
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { LoadConnect } from "./shared";
2
- export declare const loadConnect: LoadConnect;
3
- export {};
package/dist/pure.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { LoadConnect } from "./shared";
2
- export declare const loadConnect: LoadConnect;
package/dist/pure.esm.js DELETED
@@ -1,80 +0,0 @@
1
- const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
2
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
3
- const findScript = () => {
4
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
5
- };
6
- const injectScript = () => {
7
- const script = document.createElement("script");
8
- script.src = "https://connect-js.stripe.com/v0.1/connect.js";
9
- const head = document.head;
10
- if (!head) {
11
- throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
12
- }
13
- document.head.appendChild(script);
14
- return script;
15
- };
16
- let stripePromise = null;
17
- const loadScript = () => {
18
- // Ensure that we only attempt to load Connect.js at most once
19
- if (stripePromise !== null) {
20
- return stripePromise;
21
- }
22
- stripePromise = new Promise((resolve, reject) => {
23
- if (window.StripeConnect) {
24
- console.warn(EXISTING_SCRIPT_MESSAGE);
25
- }
26
- if (window.StripeConnect) {
27
- const wrapper = createWrapper(window.StripeConnect);
28
- resolve(wrapper);
29
- return;
30
- }
31
- try {
32
- let script = findScript();
33
- if (script) {
34
- console.warn(EXISTING_SCRIPT_MESSAGE);
35
- } else if (!script) {
36
- script = injectScript();
37
- }
38
- script.addEventListener("load", () => {
39
- if (window.StripeConnect) {
40
- const wrapper = createWrapper(window.StripeConnect);
41
- resolve(wrapper);
42
- } else {
43
- reject(new Error("Connect.js did not load the necessary objects"));
44
- }
45
- });
46
- script.addEventListener("error", () => {
47
- reject(new Error("Failed to load Connect.js"));
48
- });
49
- } catch (error) {
50
- reject(error);
51
- }
52
- });
53
- return stripePromise;
54
- };
55
- const initStripeConnect = stripeConnectPromise => {
56
- if (stripeConnectPromise === null) {
57
- return null;
58
- }
59
- return stripeConnectPromise;
60
- };
61
- const createWrapper = stripeConnect => {
62
- const wrapper = {
63
- initialize: params => {
64
- var _a;
65
- const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
66
- return stripeConnect.init(Object.assign(Object.assign({}, params), {
67
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
68
- sdk: true
69
- })
70
- }));
71
- }
72
- };
73
- return wrapper;
74
- };
75
-
76
- const loadConnect = () => {
77
- return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
78
- };
79
-
80
- export { loadConnect };
package/dist/pure.js DELETED
@@ -1,84 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
6
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
7
- const findScript = () => {
8
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
9
- };
10
- const injectScript = () => {
11
- const script = document.createElement("script");
12
- script.src = "https://connect-js.stripe.com/v0.1/connect.js";
13
- const head = document.head;
14
- if (!head) {
15
- throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
16
- }
17
- document.head.appendChild(script);
18
- return script;
19
- };
20
- let stripePromise = null;
21
- const loadScript = () => {
22
- // Ensure that we only attempt to load Connect.js at most once
23
- if (stripePromise !== null) {
24
- return stripePromise;
25
- }
26
- stripePromise = new Promise((resolve, reject) => {
27
- if (window.StripeConnect) {
28
- console.warn(EXISTING_SCRIPT_MESSAGE);
29
- }
30
- if (window.StripeConnect) {
31
- const wrapper = createWrapper(window.StripeConnect);
32
- resolve(wrapper);
33
- return;
34
- }
35
- try {
36
- let script = findScript();
37
- if (script) {
38
- console.warn(EXISTING_SCRIPT_MESSAGE);
39
- } else if (!script) {
40
- script = injectScript();
41
- }
42
- script.addEventListener("load", () => {
43
- if (window.StripeConnect) {
44
- const wrapper = createWrapper(window.StripeConnect);
45
- resolve(wrapper);
46
- } else {
47
- reject(new Error("Connect.js did not load the necessary objects"));
48
- }
49
- });
50
- script.addEventListener("error", () => {
51
- reject(new Error("Failed to load Connect.js"));
52
- });
53
- } catch (error) {
54
- reject(error);
55
- }
56
- });
57
- return stripePromise;
58
- };
59
- const initStripeConnect = stripeConnectPromise => {
60
- if (stripeConnectPromise === null) {
61
- return null;
62
- }
63
- return stripeConnectPromise;
64
- };
65
- const createWrapper = stripeConnect => {
66
- const wrapper = {
67
- initialize: params => {
68
- var _a;
69
- const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
70
- return stripeConnect.init(Object.assign(Object.assign({}, params), {
71
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
72
- sdk: true
73
- })
74
- }));
75
- }
76
- };
77
- return wrapper;
78
- };
79
-
80
- const loadConnect = () => {
81
- return loadScript().then(maybeStripe => initStripeConnect(maybeStripe));
82
- };
83
-
84
- exports.loadConnect = loadConnect;
package/dist/shared.d.ts DELETED
@@ -1,5 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- export declare const SCRIPT_SELECTOR = "script[src^=\"https://connect-js.stripe.com/v0.1/connect.js\"]";
2
- export {};
@@ -1 +0,0 @@
1
- export {};