@txgw/payout-components 0.3.1 → 0.4.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.
@@ -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: f } = 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
83
  f
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,37 +91,37 @@ 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
126
  f
127
127
  );
@@ -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,35 +165,35 @@ 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
171
  const f = p.payoutTypes?.[t]?.currencies;
172
172
  if (f)
173
- for (const [l, k] of Object.entries(f))
174
- l === n && i.push(k);
173
+ for (const [l, _] of Object.entries(f))
174
+ l === 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
198
  const l = await (await b(
199
199
  "/v1/payout/beneficiary/form/schema/token/query",
@@ -208,64 +208,57 @@ 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
216
  l.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
217
217
  );
218
218
  }
219
- function ee({
219
+ function G(t) {
220
+ return "B2P";
221
+ }
222
+ function V({
220
223
  authCode: t,
221
224
  domain: n,
222
225
  codeVerifier: o,
223
226
  emitter: r,
224
- defaultValues: c,
225
- customizations: i,
227
+ defaultValues: i,
228
+ customizations: u,
226
229
  locale: p
227
230
  }) {
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(() => {
231
+ const { t: f } = $("beneficiaryForm"), [l, _] = y.useState([]), [e, C] = y.useState({
232
+ inputPayoutType: G(
233
+ i?.beneficiary?.entity_details?.type
234
+ ),
235
+ inputPaymentMethod: i?.payment_method,
236
+ inputRegionCode: i?.beneficiary?.address?.country,
237
+ inputCurrency: i?.receive_currency
238
+ }), [d, k] = y.useState(), [I, B] = y.useState(), w = y.useMemo(() => !u?.layout?.find(
239
+ (a) => a.name === K
240
+ )?.hidden, [u?.layout]), P = y.useMemo(() => {
248
241
  const s = /* @__PURE__ */ new Set();
249
242
  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();
243
+ (c) => c.country_number && !s.has(c.country_number) && s.add(c.country_number)
244
+ ).map((c) => ({
245
+ label: c.country_name_standard || c.country_name,
246
+ value: c.country_code
247
+ })).sort((c, g) => c.label.localeCompare(g.label));
248
+ }, [l]), [v, L] = y.useState();
256
249
  y.useEffect(() => {
257
250
  if (!e?.inputRegionCode || !e?.inputPayoutType) return;
258
251
  const s = e.inputRegionCode;
259
- Z(s, t, n, o).then(
252
+ H(s, t, n, o).then(
260
253
  (a) => {
261
- g(a);
262
- const u = Object.keys(
254
+ k(a);
255
+ const c = Object.keys(
263
256
  a.countries?.[s].payoutTypes?.[e.inputPayoutType]?.currencies
264
257
  );
265
- u && u.length > 0 && F(
266
- u.map((m) => ({
267
- label: m,
268
- value: m
258
+ c && c.length > 0 && L(
259
+ c.map((g) => ({
260
+ label: g,
261
+ value: g
269
262
  }))
270
263
  );
271
264
  }
@@ -277,25 +270,25 @@ function ee({
277
270
  e?.inputPayoutType,
278
271
  e?.inputRegionCode
279
272
  ]);
280
- const E = y.useMemo(() => Array.from(
273
+ const x = y.useMemo(() => Array.from(
281
274
  new Set(l.map((a) => a.currency_code))
282
275
  ).map((a) => ({
283
276
  label: a,
284
277
  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(
278
+ })).filter((a) => !!a.label && a.label !== "-").sort((a, c) => a.label.localeCompare(c.label)), [l]), T = y.useMemo(() => !e?.inputCurrency || !e?.inputPayoutType || !d ? void 0 : X(
286
279
  {
287
280
  inputPayoutType: e.inputPayoutType,
288
281
  inputCurrency: e.inputCurrency
289
282
  },
290
283
  d,
291
284
  f,
292
- c
293
- ), [c, e, d, f]), M = y.useMemo(() => {
285
+ i
286
+ ), [i, e, d, f]), E = y.useMemo(() => {
294
287
  if (!(l.length === 0 || !T || !e?.inputPaymentMethod || !e?.inputRegionCode || !e?.inputCurrency))
295
288
  return I;
296
289
  }, [l, e, I, T]);
297
290
  y.useEffect(() => {
298
- V(
291
+ Z(
299
292
  {
300
293
  inputPaymentMethod: e.inputPaymentMethod,
301
294
  inputRegionCode: e.inputRegionCode,
@@ -304,17 +297,35 @@ function ee({
304
297
  t,
305
298
  n,
306
299
  o
307
- ).then(P);
300
+ ).then((s) => {
301
+ if (!s) return;
302
+ const a = s.body.findIndex(
303
+ (c) => c.type === "form"
304
+ );
305
+ s.body[a].api.url = "/api/form", s.body[a].api.requestAdaptor = function(c, g) {
306
+ return c?.body?.value && r.emit("submit", c.body.value), {
307
+ mockResponse: {
308
+ status: 200,
309
+ data: {
310
+ status: 0,
311
+ data: {
312
+ name: "mock value"
313
+ }
314
+ }
315
+ }
316
+ };
317
+ }, B(s);
318
+ });
308
319
  }, [
309
320
  l,
310
321
  T,
311
322
  t,
312
323
  n,
313
324
  o,
314
- P,
315
325
  e.inputCurrency,
316
326
  e.inputPaymentMethod,
317
- e.inputRegionCode
327
+ e.inputRegionCode,
328
+ r
318
329
  ]);
319
330
  const D = y.useMemo(
320
331
  () => ({
@@ -330,12 +341,12 @@ function ee({
330
341
  title: f("title", "Bank Details"),
331
342
  submitText: "",
332
343
  onChange: (s) => {
333
- const a = s.inputRegionCode, u = s.inputRegionCode ? s.inputCurrency : "", m = s.inputRegionCode ? s.inputPaymentMethod : "";
344
+ const a = s.inputRegionCode, c = s.inputRegionCode ? s.inputCurrency : "", g = s.inputRegionCode ? s.inputPaymentMethod : "";
334
345
  C({
335
346
  inputPayoutType: s.inputPayoutType,
336
- inputPaymentMethod: m,
347
+ inputPaymentMethod: g,
337
348
  inputRegionCode: a,
338
- inputCurrency: u
349
+ inputCurrency: c
339
350
  });
340
351
  },
341
352
  body: [
@@ -344,7 +355,7 @@ function ee({
344
355
  type: "input-text",
345
356
  creatable: !1,
346
357
  name: "inputRegionCode",
347
- options: x,
358
+ options: P,
348
359
  value: e?.inputRegionCode
349
360
  },
350
361
  {
@@ -365,7 +376,7 @@ function ee({
365
376
  type: "input-text",
366
377
  creatable: !1,
367
378
  name: "inputCurrency",
368
- options: e.inputRegionCode ? v || E : [],
379
+ options: e.inputRegionCode ? v || x : [],
369
380
  value: e?.inputCurrency
370
381
  },
371
382
  T
@@ -377,38 +388,57 @@ function ee({
377
388
  [
378
389
  l.length,
379
390
  e,
380
- E,
381
- v,
382
391
  x,
392
+ v,
393
+ P,
383
394
  w,
384
395
  f,
385
396
  T
386
397
  ]
387
398
  );
388
- return y.useEffect(() => {
399
+ y.useEffect(() => {
389
400
  async function s() {
390
- const a = await X(
401
+ const a = await U(
391
402
  t,
392
403
  n,
393
404
  o
394
405
  );
395
- k(a);
406
+ _(a);
396
407
  }
397
408
  s();
398
- }, [t, o, n]), /* @__PURE__ */ _.jsxs(_.Fragment, { children: [
399
- /* @__PURE__ */ _.jsx(W, {}),
400
- O(D, {
401
- locale: N(p)
409
+ }, [t, o, n]);
410
+ const F = y.useMemo(
411
+ () => ({
412
+ fetcher: () => new Promise(() => ({
413
+ status: 200,
414
+ data: {
415
+ status: 0,
416
+ data: {
417
+ name: "mock value"
418
+ }
419
+ }
420
+ }))
402
421
  }),
403
- M && O(M, {
404
- locale: N(p)
405
- })
422
+ []
423
+ );
424
+ return /* @__PURE__ */ h.jsxs(h.Fragment, { children: [
425
+ /* @__PURE__ */ h.jsx(Y, {}),
426
+ M(D, {
427
+ locale: A(p)
428
+ }),
429
+ E && M(
430
+ E,
431
+ {
432
+ locale: A(p)
433
+ },
434
+ F
435
+ )
406
436
  ] });
407
437
  }
408
- function oe(t) {
438
+ function ne(t) {
409
439
  const { mi18n: n } = t;
410
- return /* @__PURE__ */ _.jsx(J, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ _.jsx(ee, { ...t }) });
440
+ return /* @__PURE__ */ h.jsx(q, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ h.jsx(V, { ...t }) });
411
441
  }
412
442
  export {
413
- oe as default
443
+ ne as default
414
444
  };
package/dist/index.d.ts CHANGED
@@ -20,43 +20,47 @@ declare interface BeneficiaryFormCustomizations {
20
20
  layout?: LayoutSection[];
21
21
  }
22
22
 
23
- declare interface BeneficiaryFormDefaultValues {
24
- region_code?: string;
25
- payout_type?: PayoutType;
26
- currency?: string;
27
- payment_method?: string;
28
- }
29
-
30
- declare type BeneficiaryFormOptions<T extends keyof typeof ElementsMap> = Omit<BeneficiaryFormProps, keyof BaseProps<T>>;
31
-
32
- declare type BeneficiaryFormProps = ComponentProps<typeof BeneficiaryForm>;
33
-
34
- declare interface BeneficiaryFormRequest {
35
- "@type": string;
36
- value: BeneficiaryFormRequestValues;
37
- }
38
-
39
- declare interface BeneficiaryFormRequestValues {
23
+ declare type BeneficiaryFormFinalValues = {
40
24
  beneficiary: {
41
25
  address: {
42
26
  country: string;
43
27
  street_address: string;
44
28
  };
45
- bank_account: {
46
- account_name: string;
29
+ bank_account?: {
47
30
  account_number: string;
31
+ account_routing_type1: string;
32
+ account_routing_value1: string;
33
+ bank_country_code: string;
34
+ bank_name: string;
35
+ swift_code: string;
36
+ };
37
+ wallet_account?: {
38
+ account_id: string;
39
+ sub_account_id: string;
40
+ wallet_type: string;
41
+ country_code: string;
42
+ account_routing_type1: string;
43
+ account_routing_value1: string;
48
44
  };
49
45
  entity_details: {
50
46
  mobile_number: string;
47
+ name: string;
48
+ type: EntityDetailType;
51
49
  };
52
50
  };
53
- }
51
+ payment_method: string;
52
+ receive_currency: string;
53
+ };
54
+
55
+ declare type BeneficiaryFormOptions<T extends keyof typeof ElementsMap> = Omit<BeneficiaryFormProps, keyof BaseProps<T>>;
56
+
57
+ declare type BeneficiaryFormProps = ComponentProps<typeof BeneficiaryForm>;
54
58
 
55
59
  export declare function createElement<T extends keyof typeof ElementsMap>(type: T, options?: ElementOptionsTypes<T>[T]): SDKComponent<T>;
56
60
 
57
61
  declare interface ElementEventsMap extends Record<EventType, unknown> {
58
62
  beneficiaryForm: {
59
- submit: BeneficiaryFormRequest;
63
+ submit: BeneficiaryFormFinalValues;
60
64
  };
61
65
  }
62
66
 
@@ -68,6 +72,8 @@ declare const ElementsMap: {
68
72
  beneficiaryForm: () => Promise<componentsBeneficiaryForm>;
69
73
  };
70
74
 
75
+ declare type EntityDetailType = "ENTITY_TYPE_PERSONAL";
76
+
71
77
  declare type Events<T extends keyof typeof ElementsMap> = ElementEventsMap[T];
72
78
 
73
79
  declare type EventsData<T extends keyof typeof ElementsMap> = Events<T>[keyof Events<T>];
@@ -89,10 +95,8 @@ declare interface LayoutSection {
89
95
 
90
96
  declare type Locale = "en";
91
97
 
92
- declare type PayoutType = "B2P";
93
-
94
98
  declare interface Props extends BaseProps<"beneficiaryForm"> {
95
- defaultValues?: BeneficiaryFormDefaultValues;
99
+ defaultValues?: BeneficiaryFormFinalValues;
96
100
  customizations?: BeneficiaryFormCustomizations;
97
101
  }
98
102
 
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-Dw13hlCn.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.4.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"