@txgw/payout-components 0.3.1 → 0.3.2

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.
@@ -88830,7 +88830,6 @@ const PdfViewer$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineP
88830
88830
  }, Symbol.toStringTag, { value: "Module" }));
88831
88831
  export {
88832
88832
  Toast as T,
88833
- dataMapping as d,
88834
88833
  render as r,
88835
88834
  toast as t
88836
88835
  };
@@ -1,7 +1,7 @@
1
- import { bX as _, bY as q, ab as y, bZ as J } from "./vendor-DyrjuDU0.js";
2
- import { t as Y, d as K, r as O, T as W } from "./amis-CGgHoXTI.js";
3
- const z = "bankDetails";
4
- async function j(t, n, o) {
1
+ import { bX as h, bY as $, ab as y, bZ as q } from "./vendor-DyrjuDU0.js";
2
+ import { t as J, r as M, T as Y } from "./amis--C-EQa43.js";
3
+ const K = "bankDetails";
4
+ async function O(t, n, o) {
5
5
  const r = {
6
6
  authorization_code: t,
7
7
  code_verifier: o
@@ -14,7 +14,7 @@ async function j(t, n, o) {
14
14
  }
15
15
  })).json();
16
16
  }
17
- async function B(t, n) {
17
+ async function N(t, n) {
18
18
  const o = {
19
19
  refresh_token: t
20
20
  };
@@ -26,7 +26,7 @@ async function B(t, n) {
26
26
  }
27
27
  })).json();
28
28
  }
29
- function Q(t) {
29
+ function W(t) {
30
30
  const n = Date.parse(t);
31
31
  if (!isNaN(n)) {
32
32
  const o = Date.now(), r = Math.floor((n - o) / 1e3);
@@ -34,39 +34,39 @@ function Q(t) {
34
34
  }
35
35
  return 0;
36
36
  }
37
- let h = null;
38
- const U = 300;
37
+ let m = null;
38
+ const z = 300;
39
39
  function S(t, n) {
40
- h && (clearTimeout(h), h = null);
41
- const o = Q(t);
40
+ m && (clearTimeout(m), m = null);
41
+ const o = W(t);
42
42
  if (o <= 0)
43
43
  return;
44
44
  const r = Math.max(
45
45
  0,
46
- (o - U) * 1e3
46
+ (o - z) * 1e3
47
47
  );
48
- h = setTimeout(async () => {
48
+ m = setTimeout(async () => {
49
49
  try {
50
- const c = localStorage.getItem("refresh_token");
51
- if (!c)
50
+ const i = localStorage.getItem("refresh_token");
51
+ if (!i)
52
52
  return;
53
- const i = await B(
54
- c,
53
+ const u = await N(
54
+ i,
55
55
  n
56
56
  );
57
- i.access_token && i.refresh_token && (localStorage.setItem("access_token", i.access_token), localStorage.setItem(
57
+ u.access_token && u.refresh_token && (localStorage.setItem("access_token", u.access_token), localStorage.setItem(
58
58
  "refresh_token",
59
- i.refresh_token
60
- ), S(i.expires_in, n));
61
- } catch (c) {
62
- console.error("[payout-sdk] Auto refresh token failed:", c), h && (clearTimeout(h), h = null);
59
+ u.refresh_token
60
+ ), S(u.expires_in, n));
61
+ } catch (i) {
62
+ console.error("[payout-sdk] Auto refresh token failed:", i), m && (clearTimeout(m), m = null);
63
63
  }
64
64
  }, r);
65
65
  }
66
- function H() {
67
- h && (clearTimeout(h), h = null);
66
+ function Q() {
67
+ m && (clearTimeout(m), m = null);
68
68
  }
69
- function A() {
69
+ function j() {
70
70
  localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token");
71
71
  }
72
72
  function R(t, n) {
@@ -75,15 +75,15 @@ function R(t, n) {
75
75
  async function b(t, n, o, r = 1) {
76
76
  if (r < 0)
77
77
  throw new Error("[payout-sdk] fetchWithAuth retries exceeded");
78
- const { headers: c, authCode: i, domain: p, codeVerifier: f } = o;
78
+ const { headers: i, authCode: u, domain: p, codeVerifier: l } = o;
79
79
  if (!localStorage.getItem("access_token")) {
80
- const e = await j(
81
- i,
80
+ const e = await O(
81
+ u,
82
82
  p,
83
- f
83
+ l
84
84
  );
85
85
  if (!e.access_token || !e.refresh_token)
86
- throw A(), new Error(
86
+ throw j(), new Error(
87
87
  "[payout-sdk] getAccessToken failed, check authCode validity"
88
88
  );
89
89
  R(
@@ -91,39 +91,39 @@ async function b(t, n, o, r = 1) {
91
91
  e.refresh_token
92
92
  ), S(e.expires_in, p);
93
93
  }
94
- const k = await fetch(new URL(t, p), {
94
+ const _ = await fetch(new URL(t, p), {
95
95
  ...o,
96
96
  body: JSON.stringify({
97
97
  ...n,
98
98
  access_token: localStorage.getItem("access_token")
99
99
  }),
100
100
  headers: {
101
- ...c,
101
+ ...i,
102
102
  "Content-Type": "application/json"
103
103
  }
104
104
  });
105
- if (k.status === 400) {
106
- const e = await k.json();
105
+ if (_.status === 400) {
106
+ const e = await _.json();
107
107
  if (e.name != "INTERNAL_ERROR" && e.name != "INVALID_TOKEN")
108
- throw Y.error(`${e.name}: ${e.message}`), new Error(`[payout-sdk] ${e.name}: ${e.message}`);
108
+ throw J.error(`${e.name}: ${e.message}`), new Error(`[payout-sdk] ${e.name}: ${e.message}`);
109
109
  const C = localStorage.getItem("refresh_token");
110
110
  if (C) {
111
- const g = await B(
111
+ const k = await N(
112
112
  C,
113
113
  p
114
114
  );
115
- if (!g.access_token || !g.refresh_token)
116
- A(), H();
115
+ if (!k.access_token || !k.refresh_token)
116
+ j(), Q();
117
117
  else
118
118
  return R(
119
- g.access_token,
120
- g.refresh_token
121
- ), S(g.expires_in, p), b(t, n, o, --r);
119
+ k.access_token,
120
+ k.refresh_token
121
+ ), S(k.expires_in, p), b(t, n, o, --r);
122
122
  }
123
- const d = await j(
124
- i,
123
+ const d = await O(
124
+ u,
125
125
  p,
126
- f
126
+ l
127
127
  );
128
128
  if (!d.access_token || !d.refresh_token)
129
129
  throw new Error(
@@ -134,12 +134,12 @@ async function b(t, n, o, r = 1) {
134
134
  d.refresh_token
135
135
  ), S(d.expires_in, p), b(t, n, o, --r);
136
136
  }
137
- return k;
137
+ return _;
138
138
  }
139
- function N(t) {
139
+ function A(t) {
140
140
  return t && t.startsWith("zh") ? "zh_CN" : "en_US";
141
141
  }
142
- async function X(t, n, o) {
142
+ async function U(t, n, o) {
143
143
  return (await (await b(
144
144
  "/v1/payout/beneficiary/token/countryinfos",
145
145
  {},
@@ -151,7 +151,7 @@ async function X(t, n, o) {
151
151
  }
152
152
  )).json()).country_infos || [];
153
153
  }
154
- async function Z(t, n, o, r) {
154
+ async function H(t, n, o, r) {
155
155
  return await (await b(
156
156
  "/v1/payout/beneficiary/token/paymentmethodinfos",
157
157
  {
@@ -165,37 +165,37 @@ async function Z(t, n, o, r) {
165
165
  }
166
166
  )).json();
167
167
  }
168
- function G({ inputPayoutType: t, inputCurrency: n }, o, r, c) {
169
- const i = [];
168
+ function X({ inputPayoutType: t, inputCurrency: n }, o, r, i) {
169
+ const u = [];
170
170
  for (const p of Object.values(o.countries)) {
171
- const f = p.payoutTypes?.[t]?.currencies;
172
- if (f)
173
- for (const [l, k] of Object.entries(f))
174
- l === n && i.push(k);
171
+ const l = p.payoutTypes?.[t]?.currencies;
172
+ if (l)
173
+ for (const [f, _] of Object.entries(l))
174
+ f === n && u.push(_);
175
175
  }
176
- if (i.length !== 0)
176
+ if (u.length !== 0)
177
177
  return {
178
178
  type: "list-select",
179
179
  name: "inputPaymentMethod",
180
180
  label: r("paymentMethodInputLabel", "Transfer method"),
181
- options: i.map((p) => ({
181
+ options: u.map((p) => ({
182
182
  value: p.payment_method,
183
- body: /* @__PURE__ */ _.jsxs("div", { children: [
184
- /* @__PURE__ */ _.jsx("span", { className: "flex font-bold", children: p.display_name }),
185
- /* @__PURE__ */ _.jsx("span", { className: "flex mt-1", children: p.description })
183
+ body: /* @__PURE__ */ h.jsxs("div", { children: [
184
+ /* @__PURE__ */ h.jsx("span", { className: "flex font-bold", children: p.display_name }),
185
+ /* @__PURE__ */ h.jsx("span", { className: "flex mt-1", children: p.description })
186
186
  ] })
187
187
  })),
188
- value: c?.payment_method
188
+ value: i?.payment_method
189
189
  };
190
190
  }
191
- async function V({
191
+ async function Z({
192
192
  inputRegionCode: t,
193
193
  inputCurrency: n,
194
194
  inputPaymentMethod: o
195
- }, r, c, i) {
196
- if (!t || !n || !o || !r || !c || !i)
195
+ }, r, i, u) {
196
+ if (!t || !n || !o || !r || !i || !u)
197
197
  return;
198
- const l = await (await b(
198
+ const f = await (await b(
199
199
  "/v1/payout/beneficiary/form/schema/token/query",
200
200
  {
201
201
  payment_method: o,
@@ -208,64 +208,52 @@ async function V({
208
208
  {
209
209
  method: "POST",
210
210
  authCode: r,
211
- domain: c,
212
- codeVerifier: i
211
+ domain: i,
212
+ codeVerifier: u
213
213
  }
214
214
  )).json();
215
215
  return JSON.parse(
216
- l.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
216
+ f.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
217
217
  );
218
218
  }
219
- function ee({
219
+ function G({
220
220
  authCode: t,
221
221
  domain: n,
222
222
  codeVerifier: o,
223
223
  emitter: r,
224
- defaultValues: c,
225
- customizations: i,
224
+ defaultValues: i,
225
+ customizations: u,
226
226
  locale: p
227
227
  }) {
228
- const { t: f } = q("beneficiaryForm"), [l, k] = y.useState([]), [e, C] = y.useState({
229
- inputPayoutType: c?.payout_type || "B2P",
230
- inputPaymentMethod: c?.payment_method,
231
- inputRegionCode: c?.region_code,
232
- inputCurrency: c?.currency
233
- }), [d, g] = y.useState(), [I, L] = y.useState(), w = y.useMemo(() => !i?.layout?.find(
234
- (a) => a.name === z
235
- )?.hidden, [i?.layout]), P = y.useCallback(
236
- (s) => {
237
- if (!s) return;
238
- const a = s.body.findIndex(
239
- (m) => m.type === "form"
240
- ), u = s.body[a];
241
- s.body[a].onFinished = (m) => {
242
- const $ = K(u.api.data, m, void 0, !0);
243
- r.emit("submit", $.value);
244
- }, L(s);
245
- },
246
- [r]
247
- ), x = y.useMemo(() => {
228
+ const { t: l } = $("beneficiaryForm"), [f, _] = y.useState([]), [e, C] = y.useState({
229
+ inputPayoutType: i?.payout_type || "B2P",
230
+ inputPaymentMethod: i?.payment_method,
231
+ inputRegionCode: i?.region_code,
232
+ inputCurrency: i?.currency
233
+ }), [d, k] = y.useState(), [I, B] = y.useState(), w = y.useMemo(() => !u?.layout?.find(
234
+ (a) => a.name === K
235
+ )?.hidden, [u?.layout]), P = y.useMemo(() => {
248
236
  const s = /* @__PURE__ */ new Set();
249
- return l.filter(
250
- (u) => u.country_number && !s.has(u.country_number) && s.add(u.country_number)
251
- ).map((u) => ({
252
- label: u.country_name_standard || u.country_name,
253
- value: u.country_code
254
- })).sort((u, m) => u.label.localeCompare(m.label));
255
- }, [l]), [v, F] = y.useState();
237
+ return f.filter(
238
+ (c) => c.country_number && !s.has(c.country_number) && s.add(c.country_number)
239
+ ).map((c) => ({
240
+ label: c.country_name_standard || c.country_name,
241
+ value: c.country_code
242
+ })).sort((c, g) => c.label.localeCompare(g.label));
243
+ }, [f]), [v, L] = y.useState();
256
244
  y.useEffect(() => {
257
245
  if (!e?.inputRegionCode || !e?.inputPayoutType) return;
258
246
  const s = e.inputRegionCode;
259
- Z(s, t, n, o).then(
247
+ H(s, t, n, o).then(
260
248
  (a) => {
261
- g(a);
262
- const u = Object.keys(
249
+ k(a);
250
+ const c = Object.keys(
263
251
  a.countries?.[s].payoutTypes?.[e.inputPayoutType]?.currencies
264
252
  );
265
- u && u.length > 0 && F(
266
- u.map((m) => ({
267
- label: m,
268
- value: m
253
+ c && c.length > 0 && L(
254
+ c.map((g) => ({
255
+ label: g,
256
+ value: g
269
257
  }))
270
258
  );
271
259
  }
@@ -277,25 +265,25 @@ function ee({
277
265
  e?.inputPayoutType,
278
266
  e?.inputRegionCode
279
267
  ]);
280
- const E = y.useMemo(() => Array.from(
281
- new Set(l.map((a) => a.currency_code))
268
+ const x = y.useMemo(() => Array.from(
269
+ new Set(f.map((a) => a.currency_code))
282
270
  ).map((a) => ({
283
271
  label: a,
284
272
  value: a
285
- })).filter((a) => !!a.label && a.label !== "-").sort((a, u) => a.label.localeCompare(u.label)), [l]), T = y.useMemo(() => !e?.inputCurrency || !e?.inputPayoutType || !d ? void 0 : G(
273
+ })).filter((a) => !!a.label && a.label !== "-").sort((a, c) => a.label.localeCompare(c.label)), [f]), T = y.useMemo(() => !e?.inputCurrency || !e?.inputPayoutType || !d ? void 0 : X(
286
274
  {
287
275
  inputPayoutType: e.inputPayoutType,
288
276
  inputCurrency: e.inputCurrency
289
277
  },
290
278
  d,
291
- f,
292
- c
293
- ), [c, e, d, f]), M = y.useMemo(() => {
294
- if (!(l.length === 0 || !T || !e?.inputPaymentMethod || !e?.inputRegionCode || !e?.inputCurrency))
279
+ l,
280
+ i
281
+ ), [i, e, d, l]), E = y.useMemo(() => {
282
+ if (!(f.length === 0 || !T || !e?.inputPaymentMethod || !e?.inputRegionCode || !e?.inputCurrency))
295
283
  return I;
296
- }, [l, e, I, T]);
284
+ }, [f, e, I, T]);
297
285
  y.useEffect(() => {
298
- V(
286
+ Z(
299
287
  {
300
288
  inputPaymentMethod: e.inputPaymentMethod,
301
289
  inputRegionCode: e.inputRegionCode,
@@ -304,17 +292,35 @@ function ee({
304
292
  t,
305
293
  n,
306
294
  o
307
- ).then(P);
295
+ ).then((s) => {
296
+ if (!s) return;
297
+ const a = s.body.findIndex(
298
+ (c) => c.type === "form"
299
+ );
300
+ s.body[a].api.url = "/api/form", s.body[a].api.requestAdaptor = function(c, g) {
301
+ return c?.body?.value && r.emit("submit", c.body.value), {
302
+ mockResponse: {
303
+ status: 200,
304
+ data: {
305
+ status: 0,
306
+ data: {
307
+ name: "mock value"
308
+ }
309
+ }
310
+ }
311
+ };
312
+ }, B(s);
313
+ });
308
314
  }, [
309
- l,
315
+ f,
310
316
  T,
311
317
  t,
312
318
  n,
313
319
  o,
314
- P,
315
320
  e.inputCurrency,
316
321
  e.inputPaymentMethod,
317
- e.inputRegionCode
322
+ e.inputRegionCode,
323
+ r
318
324
  ]);
319
325
  const D = y.useMemo(
320
326
  () => ({
@@ -322,33 +328,33 @@ function ee({
322
328
  visible: w,
323
329
  body: {
324
330
  type: "spinner",
325
- show: l.length === 0,
331
+ show: f.length === 0,
326
332
  overlay: !0,
327
333
  body: [
328
334
  {
329
335
  type: "form",
330
- title: f("title", "Bank Details"),
336
+ title: l("title", "Bank Details"),
331
337
  submitText: "",
332
338
  onChange: (s) => {
333
- const a = s.inputRegionCode, u = s.inputRegionCode ? s.inputCurrency : "", m = s.inputRegionCode ? s.inputPaymentMethod : "";
339
+ const a = s.inputRegionCode, c = s.inputRegionCode ? s.inputCurrency : "", g = s.inputRegionCode ? s.inputPaymentMethod : "";
334
340
  C({
335
341
  inputPayoutType: s.inputPayoutType,
336
- inputPaymentMethod: m,
342
+ inputPaymentMethod: g,
337
343
  inputRegionCode: a,
338
- inputCurrency: u
344
+ inputCurrency: c
339
345
  });
340
346
  },
341
347
  body: [
342
348
  {
343
- label: f("regionInputLabel", "Bank Location"),
349
+ label: l("regionInputLabel", "Bank Location"),
344
350
  type: "input-text",
345
351
  creatable: !1,
346
352
  name: "inputRegionCode",
347
- options: x,
353
+ options: P,
348
354
  value: e?.inputRegionCode
349
355
  },
350
356
  {
351
- label: f("payoutTypeInputLabel", "Bank account type"),
357
+ label: l("payoutTypeInputLabel", "Bank account type"),
352
358
  type: "radios",
353
359
  name: "inputPayoutType",
354
360
  selectFirst: !0,
@@ -361,11 +367,11 @@ function ee({
361
367
  value: e?.inputPayoutType
362
368
  },
363
369
  {
364
- label: f("currencyInputLabel", "Account currency"),
370
+ label: l("currencyInputLabel", "Account currency"),
365
371
  type: "input-text",
366
372
  creatable: !1,
367
373
  name: "inputCurrency",
368
- options: e.inputRegionCode ? v || E : [],
374
+ options: e.inputRegionCode ? v || x : [],
369
375
  value: e?.inputCurrency
370
376
  },
371
377
  T
@@ -375,40 +381,59 @@ function ee({
375
381
  }
376
382
  }),
377
383
  [
378
- l.length,
384
+ f.length,
379
385
  e,
380
- E,
381
- v,
382
386
  x,
387
+ v,
388
+ P,
383
389
  w,
384
- f,
390
+ l,
385
391
  T
386
392
  ]
387
393
  );
388
- return y.useEffect(() => {
394
+ y.useEffect(() => {
389
395
  async function s() {
390
- const a = await X(
396
+ const a = await U(
391
397
  t,
392
398
  n,
393
399
  o
394
400
  );
395
- k(a);
401
+ _(a);
396
402
  }
397
403
  s();
398
- }, [t, o, n]), /* @__PURE__ */ _.jsxs(_.Fragment, { children: [
399
- /* @__PURE__ */ _.jsx(W, {}),
400
- O(D, {
401
- locale: N(p)
404
+ }, [t, o, n]);
405
+ const F = y.useMemo(
406
+ () => ({
407
+ fetcher: () => new Promise(() => ({
408
+ status: 200,
409
+ data: {
410
+ status: 0,
411
+ data: {
412
+ name: "mock value"
413
+ }
414
+ }
415
+ }))
402
416
  }),
403
- M && O(M, {
404
- locale: N(p)
405
- })
417
+ []
418
+ );
419
+ return /* @__PURE__ */ h.jsxs(h.Fragment, { children: [
420
+ /* @__PURE__ */ h.jsx(Y, {}),
421
+ M(D, {
422
+ locale: A(p)
423
+ }),
424
+ E && M(
425
+ E,
426
+ {
427
+ locale: A(p)
428
+ },
429
+ F
430
+ )
406
431
  ] });
407
432
  }
408
- function oe(t) {
433
+ function te(t) {
409
434
  const { mi18n: n } = t;
410
- return /* @__PURE__ */ _.jsx(J, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ _.jsx(ee, { ...t }) });
435
+ return /* @__PURE__ */ h.jsx(q, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ h.jsx(G, { ...t }) });
411
436
  }
412
437
  export {
413
- oe as default
438
+ te as default
414
439
  };
package/dist/index.d.ts CHANGED
@@ -27,36 +27,17 @@ declare interface BeneficiaryFormDefaultValues {
27
27
  payment_method?: string;
28
28
  }
29
29
 
30
+ declare type BeneficiaryFormFinalValues = Record<string, unknown>;
31
+
30
32
  declare type BeneficiaryFormOptions<T extends keyof typeof ElementsMap> = Omit<BeneficiaryFormProps, keyof BaseProps<T>>;
31
33
 
32
34
  declare type BeneficiaryFormProps = ComponentProps<typeof BeneficiaryForm>;
33
35
 
34
- declare interface BeneficiaryFormRequest {
35
- "@type": string;
36
- value: BeneficiaryFormRequestValues;
37
- }
38
-
39
- declare interface BeneficiaryFormRequestValues {
40
- beneficiary: {
41
- address: {
42
- country: string;
43
- street_address: string;
44
- };
45
- bank_account: {
46
- account_name: string;
47
- account_number: string;
48
- };
49
- entity_details: {
50
- mobile_number: string;
51
- };
52
- };
53
- }
54
-
55
36
  export declare function createElement<T extends keyof typeof ElementsMap>(type: T, options?: ElementOptionsTypes<T>[T]): SDKComponent<T>;
56
37
 
57
38
  declare interface ElementEventsMap extends Record<EventType, unknown> {
58
39
  beneficiaryForm: {
59
- submit: BeneficiaryFormRequest;
40
+ submit: BeneficiaryFormFinalValues;
60
41
  };
61
42
  }
62
43
 
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ class d {
34
34
  }
35
35
  }
36
36
  const g = {
37
- beneficiaryForm: () => import("./component-beneficiary-form-BIz4pTeo.js")
37
+ beneficiaryForm: () => import("./component-beneficiary-form-iyOi2OA3.js")
38
38
  }, w = {
39
39
  staticData: {
40
40
  en: () => import("./en-Cb5xUNU4.js")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txgw/payout-components",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"