@stripe/connect-js 3.3.31-preview-1 → 3.3.32-preview-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -159,6 +159,13 @@ const injectScript = () => {
159
159
  return script;
160
160
  };
161
161
  let stripePromise = null;
162
+ const isWindowStripeConnectDefined = stripeConnect => {
163
+ // We only consider `StripeConnect` defined if `init` is a function
164
+ // Why? HTML markup like:
165
+ // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
166
+ // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
167
+ return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
168
+ };
162
169
  const loadScript = () => {
163
170
  // Ensure that we only attempt to load Connect.js at most once
164
171
  if (stripePromise !== null) {
@@ -169,10 +176,8 @@ const loadScript = () => {
169
176
  reject("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.");
170
177
  return;
171
178
  }
172
- if (window.StripeConnect) {
179
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
173
180
  console.warn(EXISTING_SCRIPT_MESSAGE);
174
- }
175
- if (window.StripeConnect) {
176
181
  const wrapper = createWrapper(window.StripeConnect);
177
182
  resolve(wrapper);
178
183
  return;
@@ -185,7 +190,7 @@ const loadScript = () => {
185
190
  script = injectScript();
186
191
  }
187
192
  script.addEventListener("load", () => {
188
- if (window.StripeConnect) {
193
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
189
194
  const wrapper = createWrapper(window.StripeConnect);
190
195
  resolve(wrapper);
191
196
  } else {
@@ -283,7 +288,7 @@ const createWrapper = stripeConnect => {
283
288
  sdk: true,
284
289
  sdkOptions: {
285
290
  // This will be replaced by the npm package version when bundling
286
- sdkVersion: "3.3.31-preview-1"
291
+ sdkVersion: "3.3.32-preview-1"
287
292
  }
288
293
  })
289
294
  }));
package/dist/connect.js CHANGED
@@ -163,6 +163,13 @@ const injectScript = () => {
163
163
  return script;
164
164
  };
165
165
  let stripePromise = null;
166
+ const isWindowStripeConnectDefined = stripeConnect => {
167
+ // We only consider `StripeConnect` defined if `init` is a function
168
+ // Why? HTML markup like:
169
+ // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
170
+ // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
171
+ return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
172
+ };
166
173
  const loadScript = () => {
167
174
  // Ensure that we only attempt to load Connect.js at most once
168
175
  if (stripePromise !== null) {
@@ -173,10 +180,8 @@ const loadScript = () => {
173
180
  reject("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.");
174
181
  return;
175
182
  }
176
- if (window.StripeConnect) {
183
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
177
184
  console.warn(EXISTING_SCRIPT_MESSAGE);
178
- }
179
- if (window.StripeConnect) {
180
185
  const wrapper = createWrapper(window.StripeConnect);
181
186
  resolve(wrapper);
182
187
  return;
@@ -189,7 +194,7 @@ const loadScript = () => {
189
194
  script = injectScript();
190
195
  }
191
196
  script.addEventListener("load", () => {
192
- if (window.StripeConnect) {
197
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
193
198
  const wrapper = createWrapper(window.StripeConnect);
194
199
  resolve(wrapper);
195
200
  } else {
@@ -287,7 +292,7 @@ const createWrapper = stripeConnect => {
287
292
  sdk: true,
288
293
  sdkOptions: {
289
294
  // This will be replaced by the npm package version when bundling
290
- sdkVersion: "3.3.31-preview-1"
295
+ sdkVersion: "3.3.32-preview-1"
291
296
  }
292
297
  })
293
298
  }));
package/dist/pure.esm.js CHANGED
@@ -159,6 +159,13 @@ const injectScript = () => {
159
159
  return script;
160
160
  };
161
161
  let stripePromise = null;
162
+ const isWindowStripeConnectDefined = stripeConnect => {
163
+ // We only consider `StripeConnect` defined if `init` is a function
164
+ // Why? HTML markup like:
165
+ // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
166
+ // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
167
+ return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
168
+ };
162
169
  const loadScript = () => {
163
170
  // Ensure that we only attempt to load Connect.js at most once
164
171
  if (stripePromise !== null) {
@@ -169,10 +176,8 @@ const loadScript = () => {
169
176
  reject("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.");
170
177
  return;
171
178
  }
172
- if (window.StripeConnect) {
179
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
173
180
  console.warn(EXISTING_SCRIPT_MESSAGE);
174
- }
175
- if (window.StripeConnect) {
176
181
  const wrapper = createWrapper(window.StripeConnect);
177
182
  resolve(wrapper);
178
183
  return;
@@ -185,7 +190,7 @@ const loadScript = () => {
185
190
  script = injectScript();
186
191
  }
187
192
  script.addEventListener("load", () => {
188
- if (window.StripeConnect) {
193
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
189
194
  const wrapper = createWrapper(window.StripeConnect);
190
195
  resolve(wrapper);
191
196
  } else {
@@ -283,7 +288,7 @@ const createWrapper = stripeConnect => {
283
288
  sdk: true,
284
289
  sdkOptions: {
285
290
  // This will be replaced by the npm package version when bundling
286
- sdkVersion: "3.3.31-preview-1"
291
+ sdkVersion: "3.3.32-preview-1"
287
292
  }
288
293
  })
289
294
  }));
package/dist/pure.js CHANGED
@@ -163,6 +163,13 @@ const injectScript = () => {
163
163
  return script;
164
164
  };
165
165
  let stripePromise = null;
166
+ const isWindowStripeConnectDefined = stripeConnect => {
167
+ // We only consider `StripeConnect` defined if `init` is a function
168
+ // Why? HTML markup like:
169
+ // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
170
+ // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
171
+ return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
172
+ };
166
173
  const loadScript = () => {
167
174
  // Ensure that we only attempt to load Connect.js at most once
168
175
  if (stripePromise !== null) {
@@ -173,10 +180,8 @@ const loadScript = () => {
173
180
  reject("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.");
174
181
  return;
175
182
  }
176
- if (window.StripeConnect) {
183
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
177
184
  console.warn(EXISTING_SCRIPT_MESSAGE);
178
- }
179
- if (window.StripeConnect) {
180
185
  const wrapper = createWrapper(window.StripeConnect);
181
186
  resolve(wrapper);
182
187
  return;
@@ -189,7 +194,7 @@ const loadScript = () => {
189
194
  script = injectScript();
190
195
  }
191
196
  script.addEventListener("load", () => {
192
- if (window.StripeConnect) {
197
+ if (isWindowStripeConnectDefined(window.StripeConnect)) {
193
198
  const wrapper = createWrapper(window.StripeConnect);
194
199
  resolve(wrapper);
195
200
  } else {
@@ -287,7 +292,7 @@ const createWrapper = stripeConnect => {
287
292
  sdk: true,
288
293
  sdkOptions: {
289
294
  // This will be replaced by the npm package version when bundling
290
- sdkVersion: "3.3.31-preview-1"
295
+ sdkVersion: "3.3.32-preview-1"
291
296
  }
292
297
  })
293
298
  }));
@@ -9,6 +9,7 @@ interface StripeConnectWrapper {
9
9
  initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
10
10
  }
11
11
  export declare const findScript: () => HTMLScriptElement | null;
12
+ export declare const isWindowStripeConnectDefined: (stripeConnect: unknown) => boolean;
12
13
  export declare const loadScript: () => Promise<StripeConnectWrapper>;
13
14
  export declare const initStripeConnect: (stripePromise: Promise<StripeConnectWrapper>, initParams: IStripeConnectInitParams) => StripeConnectInstanceExtended;
14
15
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/connect-js",
3
- "version": "3.3.31-preview-1",
3
+ "version": "3.3.32-preview-1",
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
@@ -125,6 +125,19 @@ const injectScript = (): HTMLScriptElement => {
125
125
 
126
126
  let stripePromise: Promise<StripeConnectWrapper> | null = null;
127
127
 
128
+ export const isWindowStripeConnectDefined = (stripeConnect: unknown) => {
129
+ // We only consider `StripeConnect` defined if `init` is a function
130
+ // Why? HTML markup like:
131
+ // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
132
+ // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
133
+ return !!(
134
+ stripeConnect &&
135
+ typeof stripeConnect === "object" &&
136
+ "init" in stripeConnect &&
137
+ typeof stripeConnect.init === "function"
138
+ );
139
+ };
140
+
128
141
  export const loadScript = (): Promise<StripeConnectWrapper> => {
129
142
  // Ensure that we only attempt to load Connect.js at most once
130
143
  if (stripePromise !== null) {
@@ -139,11 +152,8 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
139
152
  return;
140
153
  }
141
154
 
142
- if ((window as any).StripeConnect) {
155
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
143
156
  console.warn(EXISTING_SCRIPT_MESSAGE);
144
- }
145
-
146
- if ((window as any).StripeConnect) {
147
157
  const wrapper = createWrapper((window as any).StripeConnect);
148
158
  resolve(wrapper);
149
159
  return;
@@ -159,7 +169,7 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
159
169
  }
160
170
 
161
171
  script.addEventListener("load", () => {
162
- if ((window as any).StripeConnect) {
172
+ if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
163
173
  const wrapper = createWrapper((window as any).StripeConnect);
164
174
  resolve(wrapper);
165
175
  } else {