@txgw/payout-components 0.2.2 → 0.3.0

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": "@txgw/payout-components",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -23,20 +23,25 @@
23
23
  "@mi18n/react": "^5.16.4",
24
24
  "@types/react": "^18.0.0",
25
25
  "@types/react-dom": "^18.0.0",
26
- "@vitejs/plugin-react-swc": "^4.0.0",
26
+ "@vitejs/plugin-react-swc": "^4.2.1",
27
27
  "amis": "^6.13.0",
28
28
  "amis-ui": "^6.13.0",
29
29
  "mitt": "^3.0.1",
30
- "postcss-discard-comments": "^7.0.4",
30
+ "postcss-discard-comments": "^7.0.5",
31
31
  "react": "^18.3.1",
32
32
  "react-dom": "^18.3.1",
33
- "rollup-plugin-visualizer": "^6.0.3",
34
- "vite": "^7.1.2",
35
- "vite-plugin-dts": "^4.5.4"
33
+ "rollup-plugin-visualizer": "^6.0.5",
34
+ "vite": "^7.2.2",
35
+ "vite-plugin-dts": "^4.5.4",
36
+ "vite-plugin-inspect": "^11.3.3",
37
+ "vite-plugin-strip-comments": "0.0.6"
36
38
  },
37
39
  "scripts": {
38
40
  "dev": "tsc -b && cross-env NODE_ENV=development vite build --watch --mode development",
41
+ "dev:inspect": "tsc -b && cross-env NODE_ENV=development INSPECT=true vite build --watch --mode development",
39
42
  "build": "tsc -b && cross-env NODE_ENV=production vite build --mode production",
40
- "lint": "eslint ."
43
+ "build:inspect": "tsc -b && cross-env NODE_ENV=production INSPECT=true vite build --mode production",
44
+ "lint": "eslint .",
45
+ "inspect": "pnpx serve .vite-inspect"
41
46
  }
42
47
  }
@@ -1,359 +0,0 @@
1
- import { bX as d, bY as N, ab as i, bZ as L } from "./vendor-D9Vb1NW1.js";
2
- import { t as F, d as $, r as E, T as q } from "./amis-CLFtZoO7.js";
3
- const D = "bankDetails";
4
- async function b(t, n, o, u = 1) {
5
- if (u < 0)
6
- throw new Error("[payout-sdk] fetchWithAuth retries exceeded");
7
- const { headers: s, authCode: l, domain: f, codeVerifier: y } = o, p = localStorage.getItem("access_token");
8
- if (p)
9
- n.access_token = p;
10
- else {
11
- const e = await M(
12
- l,
13
- f,
14
- y
15
- );
16
- if (!e.access_token || !e.refresh_token)
17
- throw localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token"), new Error(
18
- "[payout-sdk] getAccessToken failed, check authCode validity"
19
- );
20
- n.access_token = e.access_token, localStorage.setItem("access_token", e.access_token), localStorage.setItem("refresh_token", e.refresh_token);
21
- }
22
- const _ = await fetch(t, {
23
- ...o,
24
- body: JSON.stringify(n),
25
- headers: {
26
- ...s,
27
- "Content-Type": "application/json"
28
- }
29
- });
30
- if (_.status === 400) {
31
- const e = await _.json();
32
- if (e.name != "INTERNAL_ERROR")
33
- throw F.error(`${e.name}: ${e.message}`), new Error(`[payout-sdk] ${e.name}: ${e.message}`);
34
- const k = localStorage.getItem("refresh_token");
35
- if (k) {
36
- const g = await J(
37
- k,
38
- f
39
- );
40
- if (!g.access_token || !g.refresh_token)
41
- localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token");
42
- else
43
- return localStorage.setItem(
44
- "refresh_token",
45
- g.refresh_token
46
- ), localStorage.setItem("access_token", g.access_token), b(t, n, o, --u);
47
- }
48
- const m = await M(
49
- l,
50
- f,
51
- y
52
- );
53
- if (!m.access_token || !m.refresh_token)
54
- throw new Error(
55
- "[payout-sdk] getAccessToken failed, check authCode validity"
56
- );
57
- return localStorage.setItem("refresh_token", m.refresh_token), localStorage.setItem("access_token", m.access_token), b(t, n, o, --u);
58
- }
59
- return _;
60
- }
61
- async function M(t, n, o) {
62
- const u = {
63
- authorization_code: t,
64
- code_verifier: o
65
- };
66
- return await (await fetch(`${n}/v1/payout/auth/token`, {
67
- method: "POST",
68
- body: JSON.stringify(u),
69
- headers: {
70
- "Content-Type": "application/json"
71
- }
72
- })).json();
73
- }
74
- async function J(t, n) {
75
- const o = {
76
- refresh_token: t
77
- };
78
- return await (await fetch(`${n}/v1/payout/auth/token/refresh`, {
79
- method: "POST",
80
- body: JSON.stringify(o),
81
- headers: {
82
- "Content-Type": "application/json"
83
- }
84
- })).json();
85
- }
86
- function O(t) {
87
- return t && t.startsWith("zh") ? "zh_CN" : "en_US";
88
- }
89
- async function Y(t, n, o) {
90
- return (await (await b(
91
- "/v1/payout/beneficiary/token/countryinfos",
92
- {},
93
- {
94
- method: "POST",
95
- authCode: t,
96
- domain: n,
97
- codeVerifier: o
98
- }
99
- )).json()).country_infos || [];
100
- }
101
- async function W(t, n, o, u) {
102
- return await (await b(
103
- "/v1/payout/beneficiary/token/paymentmethodinfos",
104
- {
105
- region_code: t
106
- },
107
- {
108
- method: "POST",
109
- authCode: n,
110
- domain: o,
111
- codeVerifier: u
112
- }
113
- )).json();
114
- }
115
- function z({ inputPayoutType: t, inputCurrency: n }, o, u, s) {
116
- const l = [];
117
- for (const f of Object.values(o.countries)) {
118
- const y = f.payoutTypes?.[t]?.currencies;
119
- if (y)
120
- for (const [p, _] of Object.entries(y))
121
- p === n && l.push(_);
122
- }
123
- if (l.length !== 0)
124
- return {
125
- type: "list-select",
126
- name: "inputPaymentMethod",
127
- label: u("paymentMethodInputLabel", "Transfer method"),
128
- options: l.map((f) => ({
129
- value: f.payment_method,
130
- body: /* @__PURE__ */ d.jsxs("div", { children: [
131
- /* @__PURE__ */ d.jsx("span", { className: "flex font-bold", children: f.display_name }),
132
- /* @__PURE__ */ d.jsx("span", { className: "flex mt-1", children: f.description })
133
- ] })
134
- })),
135
- value: s?.payment_method
136
- };
137
- }
138
- async function K({
139
- inputRegionCode: t,
140
- inputCurrency: n,
141
- inputPaymentMethod: o
142
- }, u, s, l) {
143
- const p = await (await b(
144
- "/v1/payout/beneficiary/form/schema/token/query",
145
- {
146
- payment_method: o,
147
- region: t,
148
- currency: n,
149
- local_clearing_system: "",
150
- version: "v1",
151
- entity_type: "ENTITY_TYPE_PERSONAL"
152
- },
153
- {
154
- method: "POST",
155
- authCode: u,
156
- domain: s,
157
- codeVerifier: l
158
- }
159
- )).json();
160
- return JSON.parse(
161
- p.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
162
- );
163
- }
164
- function Q({
165
- authCode: t,
166
- domain: n,
167
- codeVerifier: o,
168
- emitter: u,
169
- defaultValues: s,
170
- customizations: l,
171
- locale: f
172
- }) {
173
- const { t: y } = N("beneficiaryForm"), [p, _] = i.useState([]), [e, k] = i.useState(), [m, g] = i.useState(), [S, C] = i.useState(), [T, j] = i.useState(), v = i.useMemo(() => !l?.layout?.find(
174
- (a) => a.name === D
175
- )?.hidden, [l?.layout]), I = i.useCallback(
176
- (r) => {
177
- const a = r.body.findIndex(
178
- (h) => h.type === "form"
179
- ), c = r.body[a];
180
- r.body[a].onFinished = (h) => {
181
- const B = $(c.api.data, h, void 0, !0);
182
- u.emit("submit", B.value);
183
- }, j(r);
184
- },
185
- [u]
186
- ), w = i.useMemo(() => {
187
- const r = /* @__PURE__ */ new Set();
188
- return p.filter(
189
- (c) => c.country_number && !r.has(c.country_number) && r.add(c.country_number)
190
- ).map((c) => ({
191
- label: c.country_name_standard || c.country_name,
192
- value: c.country_code
193
- })).sort((c, h) => c.label.localeCompare(h.label));
194
- }, [p]), [P, x] = i.useState();
195
- i.useEffect(() => {
196
- if (!e?.inputRegionCode || !e?.inputPayoutType) return;
197
- const r = e.inputRegionCode;
198
- W(r, t, n, o).then(
199
- (a) => {
200
- g(a);
201
- const c = Object.keys(
202
- a.countries?.[r].payoutTypes?.[e.inputPayoutType]?.currencies
203
- );
204
- c && c.length > 0 && x(
205
- c.map((h) => ({
206
- label: h,
207
- value: h
208
- }))
209
- );
210
- }
211
- );
212
- }, [
213
- t,
214
- o,
215
- n,
216
- e?.inputPayoutType,
217
- e?.inputRegionCode
218
- ]);
219
- const R = i.useMemo(() => Array.from(
220
- new Set(p.map((a) => a.currency_code))
221
- ).map((a) => ({
222
- label: a,
223
- value: a
224
- })).filter((a) => !!a.label && a.label !== "-").sort((a, c) => a.label.localeCompare(c.label)), [p]);
225
- i.useEffect(() => {
226
- if (!m || !e) return;
227
- const r = z(
228
- {
229
- inputPayoutType: e.inputPayoutType,
230
- inputCurrency: e.inputCurrency
231
- },
232
- m,
233
- y,
234
- s
235
- );
236
- C(r);
237
- }, [s, e, m, y]), i.useEffect(() => {
238
- p.length !== 0 && S && e?.inputPaymentMethod && e?.inputRegionCode && e?.inputCurrency && K(
239
- {
240
- inputPaymentMethod: e.inputPaymentMethod,
241
- inputRegionCode: e.inputRegionCode,
242
- inputCurrency: e.inputCurrency
243
- },
244
- t,
245
- n,
246
- o
247
- ).then((r) => r && I(r));
248
- }, [
249
- p,
250
- S,
251
- t,
252
- n,
253
- o,
254
- e?.inputPaymentMethod,
255
- e?.inputRegionCode,
256
- e?.inputCurrency,
257
- I
258
- ]), i.useEffect(() => {
259
- e?.inputCurrency || C(void 0);
260
- }, [e?.inputCurrency]), i.useEffect(() => {
261
- s && k({
262
- inputPayoutType: s.payout_type || "B2P",
263
- inputPaymentMethod: s.payment_method,
264
- inputRegionCode: s.region_code,
265
- inputCurrency: s.currency
266
- });
267
- }, [s]);
268
- const A = i.useMemo(
269
- () => ({
270
- type: "page",
271
- visible: v,
272
- body: {
273
- type: "spinner",
274
- show: p.length === 0,
275
- overlay: !0,
276
- body: [
277
- {
278
- type: "form",
279
- title: y("title", "Bank Details"),
280
- submitText: "",
281
- onChange: (r) => {
282
- k(r);
283
- },
284
- body: [
285
- {
286
- label: y("regionInputLabel", "Bank Location"),
287
- type: "input-text",
288
- creatable: !1,
289
- name: "inputRegionCode",
290
- options: w,
291
- value: s?.region_code
292
- },
293
- {
294
- label: y("payoutTypeInputLabel", "Bank account type"),
295
- type: "radios",
296
- name: "inputPayoutType",
297
- selectFirst: !0,
298
- options: [
299
- {
300
- label: "Individual",
301
- value: "B2P"
302
- }
303
- ],
304
- value: s?.payout_type
305
- },
306
- {
307
- label: y("currencyInputLabel", "Account currency"),
308
- type: "input-text",
309
- creatable: !1,
310
- name: "inputCurrency",
311
- options: P || R,
312
- value: s?.currency
313
- },
314
- S
315
- ]
316
- }
317
- ]
318
- }
319
- }),
320
- [
321
- v,
322
- p.length,
323
- y,
324
- w,
325
- s?.region_code,
326
- s?.payout_type,
327
- s?.currency,
328
- P,
329
- R,
330
- S
331
- ]
332
- );
333
- return i.useEffect(() => {
334
- async function r() {
335
- const a = await Y(
336
- t,
337
- n,
338
- o
339
- );
340
- _(a);
341
- }
342
- r();
343
- }, [t, o, n]), /* @__PURE__ */ d.jsxs(d.Fragment, { children: [
344
- /* @__PURE__ */ d.jsx(q, {}),
345
- E(A, {
346
- locale: O(f)
347
- }),
348
- T && E(T, {
349
- locale: O(f)
350
- })
351
- ] });
352
- }
353
- function Z(t) {
354
- const { mi18n: n } = t;
355
- return /* @__PURE__ */ d.jsx(L, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ d.jsx(Q, { ...t }) });
356
- }
357
- export {
358
- Z as default
359
- };