@stripe/connect-js 3.3.25-preview-1 → 3.3.25
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 +3 -3
- package/dist/connect.esm.js +34 -78
- package/dist/connect.js +34 -78
- package/dist/pure.esm.js +26 -70
- package/dist/pure.js +26 -70
- package/dist/src/index.d.ts +1 -1
- package/dist/src/pure.d.ts +1 -1
- package/dist/src/shared.d.ts +3 -2
- package/dist/types/config.d.ts +8 -60
- package/package.json +14 -10
- package/src/index.ts +3 -6
- package/src/pure.test.ts +2 -2
- package/src/pure.ts +3 -6
- package/src/shared.ts +49 -57
- package/types/checks.ts +2 -2
- package/types/config.ts +19 -104
- package/types/index.d.ts +1 -1
- package/types/shared.d.ts +10 -18
package/dist/pure.js
CHANGED
|
@@ -9,13 +9,6 @@ const ConnectElementCommonMethodConfig = {
|
|
|
9
9
|
setOnLoaderStart: _listener => {}
|
|
10
10
|
};
|
|
11
11
|
const ConnectElementCustomMethodConfig = {
|
|
12
|
-
payments: {
|
|
13
|
-
setDefaultFilters: _filters => {}
|
|
14
|
-
},
|
|
15
|
-
"payment-details": {
|
|
16
|
-
setPayment: _payment => {},
|
|
17
|
-
setOnClose: _listener => {}
|
|
18
|
-
},
|
|
19
12
|
"account-onboarding": {
|
|
20
13
|
setFullTermsOfServiceUrl: _termOfServiceUrl => {},
|
|
21
14
|
setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
|
|
@@ -49,46 +42,16 @@ const ConnectElementCustomMethodConfig = {
|
|
|
49
42
|
"financial-account-transactions": {
|
|
50
43
|
setFinancialAccount: _financialAccount => {}
|
|
51
44
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
"app-install": {
|
|
56
|
-
setApp: _app => {},
|
|
57
|
-
setOnAppInstallStateFetched: _listener => {},
|
|
58
|
-
setOnAppInstallStateChanged: _listener => {}
|
|
59
|
-
},
|
|
60
|
-
"app-viewport": {
|
|
61
|
-
setApp: _app => {},
|
|
62
|
-
setAppData: _appData => {}
|
|
63
|
-
},
|
|
64
|
-
"payment-method-settings": {
|
|
65
|
-
setPaymentMethodConfiguration: _paymentMethodConfiguration => {}
|
|
66
|
-
},
|
|
67
|
-
"capital-financing": {
|
|
68
|
-
setDefaultFinancingOffer: _defaultFinancingOffer => {},
|
|
69
|
-
setShowFinancingSelector: _showFinancingSelector => {},
|
|
70
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
71
|
-
setSupportUrl: _supportUrl => {},
|
|
72
|
-
setOnFinancingsLoaded: _listener => {}
|
|
73
|
-
},
|
|
74
|
-
"capital-financing-application": {
|
|
75
|
-
setOnApplicationSubmitted: _listener => {},
|
|
76
|
-
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
77
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {}
|
|
45
|
+
payments: {
|
|
46
|
+
setDefaultFilters: _filters => {}
|
|
78
47
|
},
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
setOnEligibleFinancingOfferLoaded: _listener => {},
|
|
83
|
-
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
84
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
85
|
-
setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {}
|
|
48
|
+
"payment-details": {
|
|
49
|
+
setPayment: _payment => {},
|
|
50
|
+
setOnClose: _listener => {}
|
|
86
51
|
},
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
setIntervalEnd: _intervalEnd => {},
|
|
91
|
-
setIntervalType: _intervalType => {}
|
|
52
|
+
"payment-disputes": {
|
|
53
|
+
setPayment: _payment => {},
|
|
54
|
+
setOnDisputesLoaded: _listener => {}
|
|
92
55
|
},
|
|
93
56
|
"tax-settings": {
|
|
94
57
|
setHideProductTaxCodeSelector: _hidden => {},
|
|
@@ -98,45 +61,33 @@ const ConnectElementCustomMethodConfig = {
|
|
|
98
61
|
"tax-registrations": {
|
|
99
62
|
setOnAfterTaxRegistrationAdded: _listener => {},
|
|
100
63
|
setDisplayCountries: _countries => {}
|
|
101
|
-
},
|
|
102
|
-
"tax-threshold-monitoring": {
|
|
103
|
-
setDisplayCountries: _countries => {}
|
|
104
64
|
}
|
|
105
65
|
};
|
|
106
66
|
|
|
107
67
|
const componentNameMapping = {
|
|
68
|
+
"account-onboarding": "stripe-connect-account-onboarding",
|
|
69
|
+
"disputes-list": "stripe-connect-disputes-list",
|
|
108
70
|
payments: "stripe-connect-payments",
|
|
109
|
-
payouts: "stripe-connect-payouts",
|
|
110
71
|
"payment-details": "stripe-connect-payment-details",
|
|
111
|
-
"
|
|
112
|
-
|
|
72
|
+
"payment-disputes": "stripe-connect-payment-disputes",
|
|
73
|
+
payouts: "stripe-connect-payouts",
|
|
74
|
+
"payouts-list": "stripe-connect-payouts-list",
|
|
75
|
+
balances: "stripe-connect-balances",
|
|
113
76
|
"account-management": "stripe-connect-account-management",
|
|
114
77
|
"notification-banner": "stripe-connect-notification-banner",
|
|
115
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
116
78
|
"issuing-card": "stripe-connect-issuing-card",
|
|
117
79
|
"issuing-cards-list": "stripe-connect-issuing-cards-list",
|
|
118
80
|
"financial-account": "stripe-connect-financial-account",
|
|
119
|
-
recipients: "stripe-connect-recipients",
|
|
120
81
|
"financial-account-transactions": "stripe-connect-financial-account-transactions",
|
|
121
|
-
"capital-financing": "stripe-connect-capital-financing",
|
|
122
|
-
"capital-financing-application": "stripe-connect-capital-financing-application",
|
|
123
|
-
"capital-financing-promotion": "stripe-connect-capital-financing-promotion",
|
|
124
|
-
"capital-overview": "stripe-connect-capital-overview",
|
|
125
82
|
documents: "stripe-connect-documents",
|
|
126
83
|
"tax-registrations": "stripe-connect-tax-registrations",
|
|
127
|
-
"tax-settings": "stripe-connect-tax-settings"
|
|
128
|
-
"tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
|
|
129
|
-
balances: "stripe-connect-balances",
|
|
130
|
-
"payouts-list": "stripe-connect-payouts-list",
|
|
131
|
-
"app-install": "stripe-connect-app-install",
|
|
132
|
-
"app-viewport": "stripe-connect-app-viewport",
|
|
133
|
-
"reporting-chart": "stripe-connect-reporting-chart"
|
|
84
|
+
"tax-settings": "stripe-connect-tax-settings"
|
|
134
85
|
};
|
|
135
86
|
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
136
87
|
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
137
88
|
const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
138
89
|
const findScript = () => {
|
|
139
|
-
return document.querySelectorAll(`script[src="${
|
|
90
|
+
return document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || null;
|
|
140
91
|
};
|
|
141
92
|
const injectScript = () => {
|
|
142
93
|
const script = document.createElement("script");
|
|
@@ -149,6 +100,13 @@ const injectScript = () => {
|
|
|
149
100
|
return script;
|
|
150
101
|
};
|
|
151
102
|
let stripePromise = null;
|
|
103
|
+
const isWindowStripeConnectDefined = stripeConnect => {
|
|
104
|
+
// We only consider `StripeConnect` defined if `init` is a function
|
|
105
|
+
// Why? HTML markup like:
|
|
106
|
+
// <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
|
|
107
|
+
// can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
|
|
108
|
+
return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
|
|
109
|
+
};
|
|
152
110
|
const loadScript = () => {
|
|
153
111
|
// Ensure that we only attempt to load Connect.js at most once
|
|
154
112
|
if (stripePromise !== null) {
|
|
@@ -159,10 +117,8 @@ const loadScript = () => {
|
|
|
159
117
|
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.");
|
|
160
118
|
return;
|
|
161
119
|
}
|
|
162
|
-
if (window.StripeConnect) {
|
|
120
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
163
121
|
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
164
|
-
}
|
|
165
|
-
if (window.StripeConnect) {
|
|
166
122
|
const wrapper = createWrapper(window.StripeConnect);
|
|
167
123
|
resolve(wrapper);
|
|
168
124
|
return;
|
|
@@ -175,7 +131,7 @@ const loadScript = () => {
|
|
|
175
131
|
script = injectScript();
|
|
176
132
|
}
|
|
177
133
|
script.addEventListener("load", () => {
|
|
178
|
-
if (window.StripeConnect) {
|
|
134
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
179
135
|
const wrapper = createWrapper(window.StripeConnect);
|
|
180
136
|
resolve(wrapper);
|
|
181
137
|
} else {
|
|
@@ -273,7 +229,7 @@ const createWrapper = stripeConnect => {
|
|
|
273
229
|
sdk: true,
|
|
274
230
|
sdkOptions: {
|
|
275
231
|
// This will be replaced by the npm package version when bundling
|
|
276
|
-
sdkVersion: "3.3.
|
|
232
|
+
sdkVersion: "3.3.25"
|
|
277
233
|
}
|
|
278
234
|
})
|
|
279
235
|
}));
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LoadConnectAndInitialize } from "./shared";
|
|
1
|
+
import type { LoadConnectAndInitialize } from "./shared";
|
|
2
2
|
export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
|
package/dist/src/pure.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LoadConnectAndInitialize } from "./shared";
|
|
1
|
+
import type { LoadConnectAndInitialize } from "./shared";
|
|
2
2
|
export declare const loadConnectAndInitialize: LoadConnectAndInitialize;
|
package/dist/src/shared.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IStripeConnectInitParams, StripeConnectInstance, ConnectElementTagName } from "../types";
|
|
1
|
+
import type { IStripeConnectInitParams, StripeConnectInstance, ConnectElementTagName } from "../types";
|
|
2
2
|
export type LoadConnectAndInitialize = (initParams: IStripeConnectInitParams) => StripeConnectInstance;
|
|
3
|
-
|
|
3
|
+
type ConnectElementHTMLName = "stripe-connect-account-onboarding" | "stripe-connect-disputes-list" | "stripe-connect-payments" | "stripe-connect-payment-details" | "stripe-connect-payment-disputes" | "stripe-connect-account-management" | "stripe-connect-notification-banner" | "stripe-connect-issuing-card" | "stripe-connect-issuing-cards-list" | "stripe-connect-financial-account" | "stripe-connect-financial-account-transactions" | "stripe-connect-payouts" | "stripe-connect-payouts-list" | "stripe-connect-balances" | "stripe-connect-documents" | "stripe-connect-tax-registrations" | "stripe-connect-tax-settings";
|
|
4
4
|
export declare const componentNameMapping: Record<ConnectElementTagName, ConnectElementHTMLName>;
|
|
5
5
|
type StripeConnectInstanceExtended = StripeConnectInstance & {
|
|
6
6
|
debugInstance: () => Promise<StripeConnectInstance>;
|
|
@@ -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/dist/types/config.d.ts
CHANGED
|
@@ -42,10 +42,6 @@ export type NotificationCount = {
|
|
|
42
42
|
total: number;
|
|
43
43
|
actionRequired: number;
|
|
44
44
|
};
|
|
45
|
-
export type InstallState = {
|
|
46
|
-
appId: string;
|
|
47
|
-
state: "INSTALLED" | "UNINSTALLED";
|
|
48
|
-
};
|
|
49
45
|
export type LoaderStart = {
|
|
50
46
|
elementTagName: string;
|
|
51
47
|
};
|
|
@@ -60,14 +56,6 @@ export type EmbeddedError = {
|
|
|
60
56
|
type: EmbeddedErrorType;
|
|
61
57
|
message?: string;
|
|
62
58
|
};
|
|
63
|
-
export type FinancingProductType = {
|
|
64
|
-
productType: "standard" | "refill" | "none";
|
|
65
|
-
activeFinancingCount: number;
|
|
66
|
-
};
|
|
67
|
-
export type FinancingPromotionLayoutType = "full" | "banner";
|
|
68
|
-
export type IntervalType = "day" | "week" | "month" | "quarter" | "year";
|
|
69
|
-
export type ReportName = "gross_volume" | "net_volume";
|
|
70
|
-
export type RecipientDataSource = "customers";
|
|
71
59
|
export type EmbeddedErrorType =
|
|
72
60
|
/**
|
|
73
61
|
* Failure to connect to Stripe's API.
|
|
@@ -98,13 +86,6 @@ export declare const ConnectElementCommonMethodConfig: {
|
|
|
98
86
|
setOnLoaderStart: (_listener: (({ elementTagName }: LoaderStart) => void) | undefined) => void;
|
|
99
87
|
};
|
|
100
88
|
export declare const ConnectElementCustomMethodConfig: {
|
|
101
|
-
payments: {
|
|
102
|
-
setDefaultFilters: (_filters: PaymentsListDefaultFilters | undefined) => void;
|
|
103
|
-
};
|
|
104
|
-
"payment-details": {
|
|
105
|
-
setPayment: (_payment: string | undefined) => void;
|
|
106
|
-
setOnClose: (_listener: (() => void) | undefined) => void;
|
|
107
|
-
};
|
|
108
89
|
"account-onboarding": {
|
|
109
90
|
setFullTermsOfServiceUrl: (_termOfServiceUrl: string | undefined) => void;
|
|
110
91
|
setRecipientTermsOfServiceUrl: (_recipientTermsOfServiceUrl: string | undefined) => void;
|
|
@@ -138,49 +119,19 @@ export declare const ConnectElementCustomMethodConfig: {
|
|
|
138
119
|
"financial-account-transactions": {
|
|
139
120
|
setFinancialAccount: (_financialAccount: string) => void;
|
|
140
121
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
};
|
|
144
|
-
"app-install": {
|
|
145
|
-
setApp: (_app: string | undefined) => void;
|
|
146
|
-
setOnAppInstallStateFetched: (_listener: (({ appId, state }: InstallState) => void) | undefined) => void;
|
|
147
|
-
setOnAppInstallStateChanged: (_listener: (({ appId, state }: InstallState) => void) | undefined) => void;
|
|
148
|
-
};
|
|
149
|
-
"app-viewport": {
|
|
150
|
-
setApp: (_app: string | undefined) => void;
|
|
151
|
-
setAppData: (_appData: Record<string, string> | undefined) => void;
|
|
122
|
+
payments: {
|
|
123
|
+
setDefaultFilters: (_filters: PaymentsListDefaultFilters | undefined) => void;
|
|
152
124
|
};
|
|
153
|
-
"payment-
|
|
154
|
-
|
|
125
|
+
"payment-details": {
|
|
126
|
+
setPayment: (_payment: string | undefined) => void;
|
|
127
|
+
setOnClose: (_listener: (() => void) | undefined) => void;
|
|
155
128
|
};
|
|
156
|
-
"
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
setHowCapitalWorksUrl: (_howCapitalWorksUrl: string | undefined) => void;
|
|
160
|
-
setSupportUrl: (_supportUrl: string | undefined) => void;
|
|
161
|
-
setOnFinancingsLoaded: (_listener: (({ total }: {
|
|
129
|
+
"payment-disputes": {
|
|
130
|
+
setPayment: (_payment: string | undefined) => void;
|
|
131
|
+
setOnDisputesLoaded: (_listener: (({ total }: {
|
|
162
132
|
total: number;
|
|
163
133
|
}) => void) | undefined) => void;
|
|
164
134
|
};
|
|
165
|
-
"capital-financing-application": {
|
|
166
|
-
setOnApplicationSubmitted: (_listener: (() => void) | undefined) => void;
|
|
167
|
-
setPrivacyPolicyUrl: (_privacyPolicyUrl: string | undefined) => void;
|
|
168
|
-
setHowCapitalWorksUrl: (_howCapitalWorksUrl: string | undefined) => void;
|
|
169
|
-
};
|
|
170
|
-
"capital-financing-promotion": {
|
|
171
|
-
setLayout: (_layout: FinancingPromotionLayoutType | undefined) => void;
|
|
172
|
-
setOnApplicationSubmitted: (_listener: (() => void) | undefined) => void;
|
|
173
|
-
setOnEligibleFinancingOfferLoaded: (_listener: (({ productType, activeFinancingCount }: FinancingProductType) => void) | undefined) => void;
|
|
174
|
-
setPrivacyPolicyUrl: (_privacyPolicyUrl: string | undefined) => void;
|
|
175
|
-
setHowCapitalWorksUrl: (_howCapitalWorksUrl: string | undefined) => void;
|
|
176
|
-
setEligibilityCriteriaUrl: (_eligibilityCriteriaUrl: string | undefined) => void;
|
|
177
|
-
};
|
|
178
|
-
"reporting-chart": {
|
|
179
|
-
setReportName: (_reportName: ReportName) => void;
|
|
180
|
-
setIntervalStart: (_intervalStart: Date | undefined) => void;
|
|
181
|
-
setIntervalEnd: (_intervalEnd: Date | undefined) => void;
|
|
182
|
-
setIntervalType: (_intervalType: IntervalType | undefined) => void;
|
|
183
|
-
};
|
|
184
135
|
"tax-settings": {
|
|
185
136
|
setHideProductTaxCodeSelector: (_hidden: boolean | undefined) => void;
|
|
186
137
|
setDisplayHeadOfficeCountries: (_countries: string[] | undefined) => void;
|
|
@@ -194,7 +145,4 @@ export declare const ConnectElementCustomMethodConfig: {
|
|
|
194
145
|
}) => void) | undefined) => void;
|
|
195
146
|
setDisplayCountries: (_countries: string[] | undefined) => void;
|
|
196
147
|
};
|
|
197
|
-
"tax-threshold-monitoring": {
|
|
198
|
-
setDisplayCountries: (_countries: string[] | undefined) => void;
|
|
199
|
-
};
|
|
200
148
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stripe/connect-js",
|
|
3
|
-
"version": "3.3.25
|
|
3
|
+
"version": "3.3.25",
|
|
4
4
|
"description": "Connect.js loading utility package",
|
|
5
5
|
"main": "dist/connect.js",
|
|
6
6
|
"module": "dist/connect.esm.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"test:unit": "jest",
|
|
12
12
|
"test:types": "zx ./tests/types/scripts/test.mjs",
|
|
13
13
|
"lint": "eslint '{src,types}/**/*.{ts,js}' && yarn prettier-check",
|
|
14
|
+
"lint-fix": "eslint '{src,types}/**/*.{ts,js}' --fix && yarn prettier-check",
|
|
14
15
|
"typecheck": "tsc --noEmit",
|
|
15
16
|
"build": "yarn clean && rollup -c",
|
|
16
17
|
"validate-change": "yarn run test",
|
|
@@ -45,21 +46,24 @@
|
|
|
45
46
|
"@rollup/plugin-json": "^6.0.0",
|
|
46
47
|
"@rollup/plugin-replace": "^2.3.1",
|
|
47
48
|
"@types/jest": "^24.0.25",
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
49
|
-
"@typescript-eslint/parser": "^
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^7",
|
|
50
|
+
"@typescript-eslint/parser": "^7",
|
|
51
|
+
"@typescript-eslint/rule-tester": "^7",
|
|
52
|
+
"@typescript-eslint/scope-manager": "^7",
|
|
53
|
+
"@typescript-eslint/utils": "^7",
|
|
50
54
|
"babel-eslint": "^10.0.3",
|
|
51
55
|
"babel-jest": "^24.9.0",
|
|
52
56
|
"conditional-type-checks": "^1.0.5",
|
|
53
|
-
"eslint": "
|
|
54
|
-
"eslint-config-prettier": "^
|
|
55
|
-
"eslint-plugin-import": "^2.
|
|
56
|
-
"eslint-plugin-jest": "^
|
|
57
|
-
"eslint-plugin-prettier": "^
|
|
57
|
+
"eslint": "8.56.0",
|
|
58
|
+
"eslint-config-prettier": "^8.3.0",
|
|
59
|
+
"eslint-plugin-import": "^2.20.1",
|
|
60
|
+
"eslint-plugin-jest": "^26.6.0",
|
|
61
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
58
62
|
"jest": "^29.5.0",
|
|
59
63
|
"jest-environment-jsdom": "^29.5.0",
|
|
60
|
-
"prettier": "
|
|
64
|
+
"prettier": "2.8.8",
|
|
61
65
|
"rimraf": "^2.6.2",
|
|
62
|
-
"rollup": "^
|
|
66
|
+
"rollup": "^2.79.2",
|
|
63
67
|
"rollup-plugin-babel": "^4.4.0",
|
|
64
68
|
"rollup-plugin-typescript2": "^0.25.3",
|
|
65
69
|
"ts-jest": "^29.1.0",
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { IStripeConnectInitParams, StripeConnectInstance } from "../types";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
initStripeConnect,
|
|
5
|
-
LoadConnectAndInitialize
|
|
6
|
-
} from "./shared";
|
|
1
|
+
import type { IStripeConnectInitParams, StripeConnectInstance } from "../types";
|
|
2
|
+
import type { LoadConnectAndInitialize } from "./shared";
|
|
3
|
+
import { loadScript, initStripeConnect } from "./shared";
|
|
7
4
|
|
|
8
5
|
// Execute our own script injection after a tick to give users time to do their
|
|
9
6
|
// own script injection.
|
package/src/pure.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
2
|
|
|
3
|
-
import { IStripeConnectInitParams } from "../types";
|
|
3
|
+
import type { IStripeConnectInitParams } from "../types";
|
|
4
4
|
import { SCRIPT_SELECTOR } from "./utils/jestHelpers";
|
|
5
5
|
|
|
6
6
|
describe("pure module", () => {
|
|
@@ -16,7 +16,7 @@ describe("pure module", () => {
|
|
|
16
16
|
publishableKey: "pk_123",
|
|
17
17
|
fetchClientSecret: async () => {
|
|
18
18
|
return "secret_123";
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
20
|
};
|
|
21
21
|
loadConnectAndInitialize(mockInitParams);
|
|
22
22
|
|
package/src/pure.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { IStripeConnectInitParams, StripeConnectInstance } from "../types";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
initStripeConnect,
|
|
5
|
-
LoadConnectAndInitialize
|
|
6
|
-
} from "./shared";
|
|
1
|
+
import type { IStripeConnectInitParams, StripeConnectInstance } from "../types";
|
|
2
|
+
import type { LoadConnectAndInitialize } from "./shared";
|
|
3
|
+
import { loadScript, initStripeConnect } from "./shared";
|
|
7
4
|
|
|
8
5
|
export const loadConnectAndInitialize: LoadConnectAndInitialize = (
|
|
9
6
|
initParams: IStripeConnectInitParams
|
package/src/shared.ts
CHANGED
|
@@ -1,78 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
IStripeConnectInitParams,
|
|
3
3
|
StripeConnectInstance,
|
|
4
4
|
ConnectElementTagName,
|
|
5
|
-
ConnectHTMLElementRecord
|
|
5
|
+
ConnectHTMLElementRecord,
|
|
6
6
|
} from "../types";
|
|
7
7
|
import {
|
|
8
8
|
ConnectElementCommonMethodConfig,
|
|
9
|
-
ConnectElementCustomMethodConfig
|
|
9
|
+
ConnectElementCustomMethodConfig,
|
|
10
10
|
} from "../types/config";
|
|
11
11
|
|
|
12
12
|
export type LoadConnectAndInitialize = (
|
|
13
13
|
initParams: IStripeConnectInitParams
|
|
14
14
|
) => StripeConnectInstance;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
type ConnectElementHTMLName =
|
|
17
|
+
| "stripe-connect-account-onboarding"
|
|
18
|
+
| "stripe-connect-disputes-list"
|
|
17
19
|
| "stripe-connect-payments"
|
|
18
|
-
| "stripe-connect-payouts"
|
|
19
20
|
| "stripe-connect-payment-details"
|
|
20
|
-
| "stripe-connect-
|
|
21
|
-
| "stripe-connect-payment-method-settings"
|
|
21
|
+
| "stripe-connect-payment-disputes"
|
|
22
22
|
| "stripe-connect-account-management"
|
|
23
23
|
| "stripe-connect-notification-banner"
|
|
24
|
-
| "stripe-connect-instant-payouts"
|
|
25
24
|
| "stripe-connect-issuing-card"
|
|
26
25
|
| "stripe-connect-issuing-cards-list"
|
|
27
26
|
| "stripe-connect-financial-account"
|
|
28
27
|
| "stripe-connect-financial-account-transactions"
|
|
29
|
-
| "stripe-connect-
|
|
30
|
-
| "stripe-connect-
|
|
31
|
-
| "stripe-connect-
|
|
32
|
-
| "stripe-connect-capital-financing-promotion"
|
|
33
|
-
| "stripe-connect-capital-overview"
|
|
28
|
+
| "stripe-connect-payouts"
|
|
29
|
+
| "stripe-connect-payouts-list"
|
|
30
|
+
| "stripe-connect-balances"
|
|
34
31
|
| "stripe-connect-documents"
|
|
35
32
|
| "stripe-connect-tax-registrations"
|
|
36
|
-
| "stripe-connect-tax-settings"
|
|
37
|
-
| "stripe-connect-tax-threshold-monitoring"
|
|
38
|
-
| "stripe-connect-balances"
|
|
39
|
-
| "stripe-connect-payouts-list"
|
|
40
|
-
| "stripe-connect-app-install"
|
|
41
|
-
| "stripe-connect-app-viewport"
|
|
42
|
-
| "stripe-connect-reporting-chart";
|
|
33
|
+
| "stripe-connect-tax-settings";
|
|
43
34
|
|
|
44
35
|
export const componentNameMapping: Record<
|
|
45
36
|
ConnectElementTagName,
|
|
46
37
|
ConnectElementHTMLName
|
|
47
38
|
> = {
|
|
39
|
+
"account-onboarding": "stripe-connect-account-onboarding",
|
|
40
|
+
"disputes-list": "stripe-connect-disputes-list",
|
|
48
41
|
payments: "stripe-connect-payments",
|
|
49
|
-
payouts: "stripe-connect-payouts",
|
|
50
42
|
"payment-details": "stripe-connect-payment-details",
|
|
51
|
-
"
|
|
52
|
-
|
|
43
|
+
"payment-disputes": "stripe-connect-payment-disputes",
|
|
44
|
+
payouts: "stripe-connect-payouts",
|
|
45
|
+
"payouts-list": "stripe-connect-payouts-list",
|
|
46
|
+
balances: "stripe-connect-balances",
|
|
53
47
|
"account-management": "stripe-connect-account-management",
|
|
54
48
|
"notification-banner": "stripe-connect-notification-banner",
|
|
55
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
56
49
|
"issuing-card": "stripe-connect-issuing-card",
|
|
57
50
|
"issuing-cards-list": "stripe-connect-issuing-cards-list",
|
|
58
51
|
"financial-account": "stripe-connect-financial-account",
|
|
59
|
-
recipients: "stripe-connect-recipients",
|
|
60
52
|
"financial-account-transactions":
|
|
61
53
|
"stripe-connect-financial-account-transactions",
|
|
62
|
-
"capital-financing": "stripe-connect-capital-financing",
|
|
63
|
-
"capital-financing-application":
|
|
64
|
-
"stripe-connect-capital-financing-application",
|
|
65
|
-
"capital-financing-promotion": "stripe-connect-capital-financing-promotion",
|
|
66
|
-
"capital-overview": "stripe-connect-capital-overview",
|
|
67
54
|
documents: "stripe-connect-documents",
|
|
68
55
|
"tax-registrations": "stripe-connect-tax-registrations",
|
|
69
56
|
"tax-settings": "stripe-connect-tax-settings",
|
|
70
|
-
"tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
|
|
71
|
-
balances: "stripe-connect-balances",
|
|
72
|
-
"payouts-list": "stripe-connect-payouts-list",
|
|
73
|
-
"app-install": "stripe-connect-app-install",
|
|
74
|
-
"app-viewport": "stripe-connect-app-viewport",
|
|
75
|
-
"reporting-chart": "stripe-connect-reporting-chart"
|
|
76
57
|
};
|
|
77
58
|
|
|
78
59
|
type StripeConnectInstanceExtended = StripeConnectInstance & {
|
|
@@ -91,10 +72,10 @@ const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
|
91
72
|
export const findScript = (): HTMLScriptElement | null => {
|
|
92
73
|
return (
|
|
93
74
|
document.querySelectorAll<HTMLScriptElement>(
|
|
94
|
-
`script[src="${
|
|
75
|
+
`script[src="${V1_URL}"]`
|
|
95
76
|
)[0] ||
|
|
96
77
|
document.querySelectorAll<HTMLScriptElement>(
|
|
97
|
-
`script[src="${
|
|
78
|
+
`script[src="${V0_URL}"]`
|
|
98
79
|
)[0] ||
|
|
99
80
|
null
|
|
100
81
|
);
|
|
@@ -119,6 +100,20 @@ const injectScript = (): HTMLScriptElement => {
|
|
|
119
100
|
|
|
120
101
|
let stripePromise: Promise<StripeConnectWrapper> | null = null;
|
|
121
102
|
|
|
103
|
+
export const isWindowStripeConnectDefined = (stripeConnect: unknown) => {
|
|
104
|
+
// We only consider `StripeConnect` defined if `init` is a function
|
|
105
|
+
// Why? HTML markup like:
|
|
106
|
+
// <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
|
|
107
|
+
// can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
|
|
108
|
+
return !!(
|
|
109
|
+
stripeConnect &&
|
|
110
|
+
typeof stripeConnect === "object" &&
|
|
111
|
+
"init" in stripeConnect &&
|
|
112
|
+
typeof (stripeConnect as { init: unknown } & Record<string, unknown>)
|
|
113
|
+
.init === "function"
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
122
117
|
export const loadScript = (): Promise<StripeConnectWrapper> => {
|
|
123
118
|
// Ensure that we only attempt to load Connect.js at most once
|
|
124
119
|
if (stripePromise !== null) {
|
|
@@ -133,11 +128,8 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
|
|
|
133
128
|
return;
|
|
134
129
|
}
|
|
135
130
|
|
|
136
|
-
if ((window as any).StripeConnect) {
|
|
131
|
+
if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
|
|
137
132
|
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if ((window as any).StripeConnect) {
|
|
141
133
|
const wrapper = createWrapper((window as any).StripeConnect);
|
|
142
134
|
resolve(wrapper);
|
|
143
135
|
return;
|
|
@@ -153,7 +145,7 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
|
|
|
153
145
|
}
|
|
154
146
|
|
|
155
147
|
script.addEventListener("load", () => {
|
|
156
|
-
if ((window as any).StripeConnect) {
|
|
148
|
+
if (isWindowStripeConnectDefined((window as any).StripeConnect)) {
|
|
157
149
|
const wrapper = createWrapper((window as any).StripeConnect);
|
|
158
150
|
resolve(wrapper);
|
|
159
151
|
} else {
|
|
@@ -190,18 +182,18 @@ export const initStripeConnect = (
|
|
|
190
182
|
}
|
|
191
183
|
})();
|
|
192
184
|
const metaOptions = (initParams as any).metaOptions ?? {};
|
|
193
|
-
const stripeConnectInstance = stripePromise.then(wrapper =>
|
|
185
|
+
const stripeConnectInstance = stripePromise.then((wrapper) =>
|
|
194
186
|
wrapper.initialize({
|
|
195
187
|
...initParams,
|
|
196
|
-
metaOptions: { ...metaOptions, eagerClientSecretPromise }
|
|
188
|
+
metaOptions: { ...metaOptions, eagerClientSecretPromise },
|
|
197
189
|
} as any)
|
|
198
190
|
);
|
|
199
191
|
|
|
200
192
|
return {
|
|
201
|
-
create: tagName => {
|
|
193
|
+
create: (tagName) => {
|
|
202
194
|
let htmlName = componentNameMapping[tagName];
|
|
203
195
|
if (!htmlName) {
|
|
204
|
-
htmlName =
|
|
196
|
+
htmlName = tagName as unknown as ConnectElementHTMLName;
|
|
205
197
|
}
|
|
206
198
|
const element = document.createElement(htmlName);
|
|
207
199
|
|
|
@@ -210,14 +202,14 @@ export const initStripeConnect = (
|
|
|
210
202
|
: {};
|
|
211
203
|
const methods = { ...customMethods, ...ConnectElementCommonMethodConfig };
|
|
212
204
|
for (const method in methods) {
|
|
213
|
-
(element as any)[method] = function(value: any) {
|
|
205
|
+
(element as any)[method] = function (value: any) {
|
|
214
206
|
stripeConnectInstance.then(() => {
|
|
215
207
|
this[`${method}InternalOnly`](value);
|
|
216
208
|
});
|
|
217
209
|
};
|
|
218
210
|
}
|
|
219
211
|
|
|
220
|
-
stripeConnectInstance.then(instance => {
|
|
212
|
+
stripeConnectInstance.then((instance) => {
|
|
221
213
|
if (!element.isConnected && !(element as any).setConnector) {
|
|
222
214
|
// If the element is not connected to the DOM and the `setConnector` method is not
|
|
223
215
|
// defined, this indicates the element was created before connect.js was loaded, and has
|
|
@@ -245,8 +237,8 @@ export const initStripeConnect = (
|
|
|
245
237
|
|
|
246
238
|
return element as ConnectHTMLElementRecord[typeof tagName];
|
|
247
239
|
},
|
|
248
|
-
update: updateOptions => {
|
|
249
|
-
stripeConnectInstance.then(instance => {
|
|
240
|
+
update: (updateOptions) => {
|
|
241
|
+
stripeConnectInstance.then((instance) => {
|
|
250
242
|
instance.update(updateOptions);
|
|
251
243
|
});
|
|
252
244
|
},
|
|
@@ -254,10 +246,10 @@ export const initStripeConnect = (
|
|
|
254
246
|
return stripeConnectInstance;
|
|
255
247
|
},
|
|
256
248
|
logout: () => {
|
|
257
|
-
return stripeConnectInstance.then(instance => {
|
|
249
|
+
return stripeConnectInstance.then((instance) => {
|
|
258
250
|
return instance.logout();
|
|
259
251
|
});
|
|
260
|
-
}
|
|
252
|
+
},
|
|
261
253
|
};
|
|
262
254
|
};
|
|
263
255
|
|
|
@@ -274,12 +266,12 @@ const createWrapper = (stripeConnect: any) => {
|
|
|
274
266
|
sdk: true,
|
|
275
267
|
sdkOptions: {
|
|
276
268
|
// This will be replaced by the npm package version when bundling
|
|
277
|
-
sdkVersion: "_NPM_PACKAGE_VERSION_"
|
|
278
|
-
}
|
|
279
|
-
}
|
|
269
|
+
sdkVersion: "_NPM_PACKAGE_VERSION_",
|
|
270
|
+
},
|
|
271
|
+
},
|
|
280
272
|
});
|
|
281
273
|
return stripeConnectInstance;
|
|
282
|
-
}
|
|
274
|
+
},
|
|
283
275
|
};
|
|
284
276
|
return wrapper;
|
|
285
277
|
};
|
package/types/checks.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConnectElementCustomMethodConfig } from "./config";
|
|
2
|
-
import { ConnectElementTagName } from "./shared.d";
|
|
1
|
+
import type { ConnectElementCustomMethodConfig } from "./config";
|
|
2
|
+
import type { ConnectElementTagName } from "./shared.d";
|
|
3
3
|
|
|
4
4
|
// ensure that keys of ConnectElementCustomMethodConfig are from ConnectElementTagName
|
|
5
5
|
export type HasType<T, Q extends T> = Q;
|