@stripe/connect-js 3.3.41-preview-1 → 3.3.43-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/connect-js",
3
- "version": "3.3.41-preview-1",
3
+ "version": "3.3.43-preview-1",
4
4
  "description": "Connect.js loading utility package",
5
5
  "main": "dist/connect.js",
6
6
  "module": "dist/connect.esm.js",
package/types/config.ts CHANGED
@@ -385,6 +385,9 @@ export const ConnectElementCustomMethodConfig = {
385
385
  _listener: (({ id }: { id: string }) => void) | undefined
386
386
  ): void => {},
387
387
  setDisplayCountries: (_countries: string[] | undefined): void => {},
388
+ setOnAfterTaxRegistrationExpired: (
389
+ _listener: (({ id }: { id: string }) => void) | undefined
390
+ ): void => {},
388
391
  },
389
392
  "tax-threshold-monitoring": {
390
393
  setDisplayCountries: (_countries: string[] | undefined): void => {},
package/types/shared.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type {
2
2
  ConnectElementCustomMethodConfig,
3
3
  ConnectElementCommonMethodConfig,
4
+ EmbeddedError,
5
+ EmbeddedErrorType,
4
6
  } from "./config";
5
7
  export declare type LoadConnectAndInitialize = (
6
8
  initParams: IStripeConnectInitParams
@@ -417,6 +419,67 @@ export type IStripeConnectUpdateParams = {
417
419
  locale?: string;
418
420
  };
419
421
 
422
+ /**
423
+ * Reasons why risk signals collection was skipped.
424
+ */
425
+ export declare type RiskSignalsCollectionSkippedReason =
426
+ /**
427
+ * Required component (account_onboarding) not enabled.
428
+ */
429
+ | "required_component_not_enabled"
430
+ /**
431
+ * The account doesn't have a risk signals collection requirement.
432
+ */
433
+ | "not_required"
434
+ /**
435
+ * The risk signals collection requirement has already been fulfilled.
436
+ */
437
+ | "requirement_fulfilled";
438
+
439
+ /**
440
+ * Error types that can occur during risk signals collection.
441
+ */
442
+ export declare type RiskSignalsCollectionErrorType = Extract<
443
+ EmbeddedErrorType,
444
+ | "api_connection_error"
445
+ | "invalid_request_error"
446
+ | "rate_limit_error"
447
+ | "api_error"
448
+ >;
449
+
450
+ /**
451
+ * Errors that can occur during risk signals collection.
452
+ */
453
+ export declare type RiskSignalsCollectionError =
454
+ /**
455
+ * Error occurred during general Connect.js loading.
456
+ */
457
+ | { type: "load_error"; loadError: EmbeddedError }
458
+
459
+ /**
460
+ * Error occurred during risk signals collection.
461
+ */
462
+ | { type: RiskSignalsCollectionErrorType; message?: string };
463
+
464
+ /**
465
+ * Event emitted during risk signals collection.
466
+ */
467
+ export declare type RiskSignalsCollectionEvent =
468
+ /**
469
+ * Risk signals collection completed and successfully received by Stripe.
470
+ */
471
+ | { status: "completed" }
472
+
473
+ /**
474
+ * Risk signals collection skipped with reason.
475
+ */
476
+ | { status: "skipped"; skippedReason: RiskSignalsCollectionSkippedReason }
477
+
478
+ /**
479
+ * Risk signals collection failed due to error and was not sent to Stripe server.
480
+ */
481
+ | { status: "failed"; error: RiskSignalsCollectionError };
482
+
420
483
  /**
421
484
  * Initialization parameters for Connect JS. See https://stripe.com/docs/connect/get-started-connect-embedded-components#configuring-connect-js for more details.
422
485
  */
@@ -447,6 +510,12 @@ export interface IStripeConnectInitParams {
447
510
  * An array of custom fonts, which embedded components created from a ConnectInstance can use.
448
511
  */
449
512
  fonts?: Array<CssFontSource | CustomFontSource>;
513
+
514
+ /**
515
+ * Callback for risk signals collection event
516
+ * @param {RiskSignalsCollectionEvent} event - The risk signals collection event containing status and additional details.
517
+ */
518
+ onRiskSignalsCollection?: (event: RiskSignalsCollectionEvent) => void;
450
519
  }
451
520
 
452
521
  type ConnectElementCustomMethods = typeof ConnectElementCustomMethodConfig;
@@ -1,331 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
- const ConnectElementCommonMethodConfig = {
4
- setOnLoadError: _listener => {},
5
- setOnLoaderStart: _listener => {}
6
- };
7
- const ConnectElementCustomMethodConfig = {
8
- payments: {
9
- setDefaultFilters: _filters => {}
10
- },
11
- "payment-details": {
12
- setPayment: _payment => {},
13
- setOnClose: _listener => {}
14
- },
15
- "payment-disputes": {
16
- setPayment: _payment => {},
17
- setOnDisputesLoaded: _listener => {}
18
- },
19
- "account-onboarding": {
20
- setFullTermsOfServiceUrl: _termOfServiceUrl => {},
21
- setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
22
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
23
- setSkipTermsOfServiceCollection: _skipTermsOfServiceCollection => {},
24
- setCollectionOptions: _collectionOptions => {},
25
- setOnExit: _listener => {},
26
- setOnStepChange: _listener => {}
27
- },
28
- "account-management": {
29
- setCollectionOptions: _collectionOptions => {}
30
- },
31
- "notification-banner": {
32
- setCollectionOptions: _collectionOptions => {},
33
- setOnNotificationsChange: _listener => {}
34
- },
35
- "instant-payouts-promotion": {
36
- setOnInstantPayoutsPromotionLoaded: _listener => {},
37
- setOnInstantPayoutCreated: _listener => {}
38
- },
39
- "issuing-card": {
40
- setDefaultCard: _defaultCard => {},
41
- setCardSwitching: _cardSwitching => {},
42
- setFetchEphemeralKey: _fetchEphemeralKey => {},
43
- setShowSpendControls: _showSpendControls => {}
44
- },
45
- "issuing-cards-list": {
46
- setFetchEphemeralKey: _fetchEphemeralKey => {},
47
- setShowSpendControls: _showSpendControls => {},
48
- setIssuingProgram: _issuingProgram => {}
49
- },
50
- "financial-account": {
51
- setFinancialAccount: _financialAccount => {}
52
- },
53
- "financial-account-transactions": {
54
- setFinancialAccount: _financialAccount => {}
55
- },
56
- recipients: {
57
- setDataSource: _dataSource => {}
58
- },
59
- "app-install": {
60
- setApp: _app => {},
61
- setOnAppInstallStateFetched: _listener => {},
62
- setOnAppInstallStateChanged: _listener => {}
63
- },
64
- "app-viewport": {
65
- setApp: _app => {},
66
- setAppData: _appData => {}
67
- },
68
- "payment-method-settings": {
69
- setPaymentMethodConfiguration: _paymentMethodConfiguration => {}
70
- },
71
- "capital-financing": {
72
- setDefaultFinancingOffer: _defaultFinancingOffer => {},
73
- setShowFinancingSelector: _showFinancingSelector => {},
74
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
75
- setSupportUrl: _supportUrl => {},
76
- setOnFinancingsLoaded: _listener => {}
77
- },
78
- "capital-financing-application": {
79
- setOnApplicationSubmitted: _listener => {},
80
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
81
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
82
- setOnApplicationStepChange: _listener => {}
83
- },
84
- "capital-financing-promotion": {
85
- setLayout: _layout => {},
86
- setOnApplicationSubmitted: _listener => {},
87
- setOnEligibleFinancingOfferLoaded: _listener => {},
88
- setPrivacyPolicyUrl: _privacyPolicyUrl => {},
89
- setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
90
- setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {},
91
- setOnApplicationStepChange: _listener => {}
92
- },
93
- "reporting-chart": {
94
- setReportName: _reportName => {},
95
- setIntervalStart: _intervalStart => {},
96
- setIntervalEnd: _intervalEnd => {},
97
- setIntervalType: _intervalType => {}
98
- },
99
- "tax-settings": {
100
- setHideProductTaxCodeSelector: _hidden => {},
101
- setDisplayHeadOfficeCountries: _countries => {},
102
- setOnTaxSettingsUpdated: _listener => {}
103
- },
104
- "tax-registrations": {
105
- setOnAfterTaxRegistrationAdded: _listener => {},
106
- setDisplayCountries: _countries => {}
107
- },
108
- "tax-threshold-monitoring": {
109
- setDisplayCountries: _countries => {}
110
- },
111
- "product-tax-code-selector": {
112
- setOnTaxCodeSelect: _listener => {},
113
- setHideDescription: _hideDescription => {},
114
- setDisabled: _disabled => {},
115
- setInitialTaxCode: _initialTaxCode => {}
116
- },
117
- "export-tax-transactions": {},
118
- "payout-details": {
119
- setPayout: _payout => {},
120
- setOnClose: _listener => {}
121
- }
122
- };
123
-
124
- const componentNameMapping = {
125
- payments: "stripe-connect-payments",
126
- payouts: "stripe-connect-payouts",
127
- "payment-details": "stripe-connect-payment-details",
128
- "payment-disputes": "stripe-connect-payment-disputes",
129
- "disputes-list": "stripe-connect-disputes-list",
130
- "account-onboarding": "stripe-connect-account-onboarding",
131
- "payment-method-settings": "stripe-connect-payment-method-settings",
132
- "account-management": "stripe-connect-account-management",
133
- "notification-banner": "stripe-connect-notification-banner",
134
- "instant-payouts": "stripe-connect-instant-payouts",
135
- "instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
136
- "issuing-card": "stripe-connect-issuing-card",
137
- "issuing-cards-list": "stripe-connect-issuing-cards-list",
138
- "financial-account": "stripe-connect-financial-account",
139
- recipients: "stripe-connect-recipients",
140
- "financial-account-transactions": "stripe-connect-financial-account-transactions",
141
- "capital-financing": "stripe-connect-capital-financing",
142
- "capital-financing-application": "stripe-connect-capital-financing-application",
143
- "capital-financing-promotion": "stripe-connect-capital-financing-promotion",
144
- "capital-overview": "stripe-connect-capital-overview",
145
- documents: "stripe-connect-documents",
146
- "product-tax-code-selector": "stripe-connect-product-tax-code-selector",
147
- "export-tax-transactions": "stripe-connect-export-tax-transactions",
148
- "tax-registrations": "stripe-connect-tax-registrations",
149
- "tax-settings": "stripe-connect-tax-settings",
150
- "tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
151
- balances: "stripe-connect-balances",
152
- "payouts-list": "stripe-connect-payouts-list",
153
- "payout-details": "stripe-connect-payout-details",
154
- "app-install": "stripe-connect-app-install",
155
- "app-viewport": "stripe-connect-app-viewport",
156
- "reporting-chart": "stripe-connect-reporting-chart"
157
- };
158
- const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
159
- const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
160
- const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
161
- const findScript = () => {
162
- return document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || null;
163
- };
164
- const injectScript = () => {
165
- const script = document.createElement("script");
166
- script.src = V1_URL;
167
- const head = document.head;
168
- if (!head) {
169
- throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
170
- }
171
- document.head.appendChild(script);
172
- return script;
173
- };
174
- let stripePromise = null;
175
- const isWindowStripeConnectDefined = stripeConnect => {
176
- // We only consider `StripeConnect` defined if `init` is a function
177
- // Why? HTML markup like:
178
- // <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
179
- // can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
180
- return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
181
- };
182
- const loadScript = () => {
183
- // Ensure that we only attempt to load Connect.js at most once
184
- if (stripePromise !== null) {
185
- return stripePromise;
186
- }
187
- stripePromise = new Promise((resolve, reject) => {
188
- if (typeof window === "undefined") {
189
- 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.");
190
- return;
191
- }
192
- if (isWindowStripeConnectDefined(window.StripeConnect)) {
193
- console.warn(EXISTING_SCRIPT_MESSAGE);
194
- const wrapper = createWrapper(window.StripeConnect);
195
- resolve(wrapper);
196
- return;
197
- }
198
- try {
199
- let script = findScript();
200
- if (script) {
201
- console.warn(EXISTING_SCRIPT_MESSAGE);
202
- } else if (!script) {
203
- script = injectScript();
204
- }
205
- script.addEventListener("load", () => {
206
- if (isWindowStripeConnectDefined(window.StripeConnect)) {
207
- const wrapper = createWrapper(window.StripeConnect);
208
- resolve(wrapper);
209
- } else {
210
- reject(new Error("Connect.js did not load the necessary objects"));
211
- }
212
- });
213
- script.addEventListener("error", () => {
214
- reject(new Error("Failed to load Connect.js"));
215
- });
216
- } catch (error) {
217
- reject(error);
218
- }
219
- });
220
- return stripePromise;
221
- };
222
- const hasCustomMethod = tagName => {
223
- return tagName in ConnectElementCustomMethodConfig;
224
- };
225
- const initStripeConnect = (stripePromise, initParams) => {
226
- var _a;
227
- const eagerClientSecretPromise = (() => {
228
- try {
229
- return initParams.fetchClientSecret();
230
- } catch (error) {
231
- return Promise.reject(error);
232
- }
233
- })();
234
- const metaOptions = (_a = initParams.metaOptions) !== null && _a !== void 0 ? _a : {};
235
- const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(Object.assign(Object.assign({}, initParams), {
236
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
237
- eagerClientSecretPromise
238
- })
239
- })));
240
- return {
241
- create: tagName => {
242
- let htmlName = componentNameMapping[tagName];
243
- if (!htmlName) {
244
- htmlName = tagName;
245
- }
246
- const element = document.createElement(htmlName);
247
- const customMethods = hasCustomMethod(tagName) ? ConnectElementCustomMethodConfig[tagName] : {};
248
- const methods = Object.assign(Object.assign({}, customMethods), ConnectElementCommonMethodConfig);
249
- for (const method in methods) {
250
- element[method] = function (value) {
251
- stripeConnectInstance.then(() => {
252
- if (!this[`${method}InternalOnly`]) {
253
- throw new Error(`Method ${method} is not available in the ${tagName} HTML element. Are you using a supported version of the "@stripe/connect-js" package? Using version: 3.3.41-preview-1`);
254
- }
255
- this[`${method}InternalOnly`](value);
256
- });
257
- };
258
- }
259
- stripeConnectInstance.then(instance => {
260
- if (!element.isConnected && !element.setConnector) {
261
- // If the element is not connected to the DOM and the `setConnector` method is not
262
- // defined, this indicates the element was created before connect.js was loaded, and has
263
- // not been transformed into a custom element yet
264
- // To load the custom element code on it, we need to connect and disconnect it to the DOM
265
- // This isn't a problem, as the element will be invisible, and we know the element is already
266
- // not currently connected to the DOM
267
- const oldDisplay = element.style.display;
268
- element.style.display = "none";
269
- document.body.appendChild(element);
270
- document.body.removeChild(element);
271
- element.style.display = oldDisplay;
272
- }
273
- if (!element || !element.setConnector) {
274
- throw new Error(`Element ${tagName} was not transformed into a custom element. Are you using a documented component? See https://docs.stripe.com/connect/supported-embedded-components for a list of supported components`);
275
- }
276
- element.setConnector(instance.connect);
277
- });
278
- return element;
279
- },
280
- update: updateOptions => {
281
- stripeConnectInstance.then(instance => {
282
- instance.update(updateOptions);
283
- });
284
- },
285
- debugInstance: () => {
286
- return stripeConnectInstance;
287
- },
288
- logout: () => {
289
- return stripeConnectInstance.then(instance => {
290
- return instance.logout();
291
- });
292
- }
293
- };
294
- };
295
- const createWrapper = stripeConnect => {
296
- window.StripeConnect = window.StripeConnect || {};
297
- window.StripeConnect.optimizedLoading = true;
298
- const wrapper = {
299
- initialize: params => {
300
- var _a;
301
- const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
302
- const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
303
- metaOptions: Object.assign(Object.assign({}, metaOptions), {
304
- sdk: true,
305
- sdkOptions: {
306
- // This will be replaced by the npm package version when bundling
307
- sdkVersion: "3.3.41-preview-1"
308
- }
309
- })
310
- }));
311
- return stripeConnectInstance;
312
- }
313
- };
314
- return wrapper;
315
- };
316
-
317
- // Execute our own script injection after a tick to give users time to do their
318
- // own script injection.
319
- const stripePromise$1 = Promise.resolve().then(() => loadScript());
320
- let loadCalled = false;
321
- stripePromise$1.catch(err => {
322
- if (!loadCalled) {
323
- console.warn(err);
324
- }
325
- });
326
- const loadConnectAndInitialize = initParams => {
327
- loadCalled = true;
328
- return initStripeConnect(stripePromise$1, initParams);
329
- };
330
-
331
- export { loadConnectAndInitialize };