@takeal/cusfront-sdk 0.6.4 → 0.6.6

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +182 -3
  3. package/dist/{cards-ofoGRU9v.d.cts → cards-BiXmrz7h.d.cts} +126 -11
  4. package/dist/{cards-BrqeBqLV.d.ts → cards-DwmzjKDC.d.ts} +126 -11
  5. package/dist/{devices-B_YveTl9.d.ts → devices-C88c38hm.d.ts} +1 -1
  6. package/dist/{devices-a5Z45Mx_.d.cts → devices-CiJrlXum.d.cts} +1 -1
  7. package/dist/{http-DeANAoTs.d.cts → http-CL97TjMO.d.cts} +4 -0
  8. package/dist/{http-DeANAoTs.d.ts → http-CL97TjMO.d.ts} +4 -0
  9. package/dist/index.cjs +200 -15
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +22 -10
  12. package/dist/index.d.ts +22 -10
  13. package/dist/index.js +199 -16
  14. package/dist/index.js.map +1 -1
  15. package/dist/react/index.d.cts +6 -3
  16. package/dist/react/index.d.ts +6 -3
  17. package/dist/resources/attribution.d.cts +1 -1
  18. package/dist/resources/attribution.d.ts +1 -1
  19. package/dist/resources/auth.cjs.map +1 -1
  20. package/dist/resources/auth.d.cts +2 -2
  21. package/dist/resources/auth.d.ts +2 -2
  22. package/dist/resources/auth.js.map +1 -1
  23. package/dist/resources/balance.d.cts +1 -1
  24. package/dist/resources/balance.d.ts +1 -1
  25. package/dist/resources/blog.d.cts +1 -1
  26. package/dist/resources/blog.d.ts +1 -1
  27. package/dist/resources/bonus.d.cts +1 -1
  28. package/dist/resources/bonus.d.ts +1 -1
  29. package/dist/resources/branding.d.cts +1 -1
  30. package/dist/resources/branding.d.ts +1 -1
  31. package/dist/resources/cards.cjs +9 -2
  32. package/dist/resources/cards.cjs.map +1 -1
  33. package/dist/resources/cards.d.cts +2 -2
  34. package/dist/resources/cards.d.ts +2 -2
  35. package/dist/resources/cards.js +9 -2
  36. package/dist/resources/cards.js.map +1 -1
  37. package/dist/resources/close-requests.cjs +54 -0
  38. package/dist/resources/close-requests.cjs.map +1 -0
  39. package/dist/resources/close-requests.d.cts +155 -0
  40. package/dist/resources/close-requests.d.ts +155 -0
  41. package/dist/resources/close-requests.js +52 -0
  42. package/dist/resources/close-requests.js.map +1 -0
  43. package/dist/resources/codes.d.cts +1 -1
  44. package/dist/resources/codes.d.ts +1 -1
  45. package/dist/resources/consents.cjs +42 -7
  46. package/dist/resources/consents.cjs.map +1 -1
  47. package/dist/resources/consents.d.cts +59 -9
  48. package/dist/resources/consents.d.ts +59 -9
  49. package/dist/resources/consents.js +41 -8
  50. package/dist/resources/consents.js.map +1 -1
  51. package/dist/resources/debt.cjs +22 -0
  52. package/dist/resources/debt.cjs.map +1 -0
  53. package/dist/resources/debt.d.cts +76 -0
  54. package/dist/resources/debt.d.ts +76 -0
  55. package/dist/resources/debt.js +20 -0
  56. package/dist/resources/debt.js.map +1 -0
  57. package/dist/resources/deposits.cjs.map +1 -1
  58. package/dist/resources/deposits.d.cts +2 -2
  59. package/dist/resources/deposits.d.ts +2 -2
  60. package/dist/resources/deposits.js.map +1 -1
  61. package/dist/resources/devices.d.cts +2 -2
  62. package/dist/resources/devices.d.ts +2 -2
  63. package/dist/resources/documents.d.cts +1 -1
  64. package/dist/resources/documents.d.ts +1 -1
  65. package/dist/resources/funding-options.d.cts +2 -2
  66. package/dist/resources/funding-options.d.ts +2 -2
  67. package/dist/resources/history.cjs.map +1 -1
  68. package/dist/resources/history.d.cts +13 -2
  69. package/dist/resources/history.d.ts +13 -2
  70. package/dist/resources/history.js.map +1 -1
  71. package/dist/resources/me.d.cts +2 -2
  72. package/dist/resources/me.d.ts +2 -2
  73. package/dist/resources/notifications.d.cts +1 -1
  74. package/dist/resources/notifications.d.ts +1 -1
  75. package/dist/resources/push.d.cts +1 -1
  76. package/dist/resources/push.d.ts +1 -1
  77. package/dist/resources/receipts.d.cts +1 -1
  78. package/dist/resources/receipts.d.ts +1 -1
  79. package/dist/resources/referral.d.cts +1 -1
  80. package/dist/resources/referral.d.ts +1 -1
  81. package/dist/resources/sessions.d.cts +1 -1
  82. package/dist/resources/sessions.d.ts +1 -1
  83. package/dist/resources/subscription.d.cts +1 -1
  84. package/dist/resources/subscription.d.ts +1 -1
  85. package/dist/resources/subscriptions.d.cts +1 -1
  86. package/dist/resources/subscriptions.d.ts +1 -1
  87. package/dist/resources/support.cjs +69 -0
  88. package/dist/resources/support.cjs.map +1 -0
  89. package/dist/resources/support.d.cts +110 -0
  90. package/dist/resources/support.d.ts +110 -0
  91. package/dist/resources/support.js +67 -0
  92. package/dist/resources/support.js.map +1 -0
  93. package/dist/resources/wallet.d.cts +1 -1
  94. package/dist/resources/wallet.d.ts +1 -1
  95. package/dist/telegram.cjs +198 -15
  96. package/dist/telegram.cjs.map +1 -1
  97. package/dist/telegram.d.cts +6 -3
  98. package/dist/telegram.d.ts +6 -3
  99. package/dist/telegram.js +198 -15
  100. package/dist/telegram.js.map +1 -1
  101. package/package.json +16 -1
@@ -1,10 +1,12 @@
1
1
  import { CusfrontClient, CreateClientOptions } from './index.cjs';
2
2
  import { JwtIssued, TelegramUnknown } from './resources/auth.cjs';
3
- import './http-DeANAoTs.cjs';
4
- import './cards-ofoGRU9v.cjs';
3
+ import './http-CL97TjMO.cjs';
4
+ import './cards-BiXmrz7h.cjs';
5
5
  import './resources/consents.cjs';
6
6
  import './resources/balance.cjs';
7
7
  import './resources/bonus.cjs';
8
+ import './resources/debt.cjs';
9
+ import './resources/close-requests.cjs';
8
10
  import './resources/codes.cjs';
9
11
  import './resources/referral.cjs';
10
12
  import './resources/subscription.cjs';
@@ -17,10 +19,11 @@ import './resources/sessions.cjs';
17
19
  import './resources/push.cjs';
18
20
  import './resources/me.cjs';
19
21
  import './resources/notifications.cjs';
20
- import './devices-a5Z45Mx_.cjs';
22
+ import './devices-CiJrlXum.cjs';
21
23
  import './resources/attribution.cjs';
22
24
  import './resources/history.cjs';
23
25
  import './resources/receipts.cjs';
26
+ import './resources/support.cjs';
24
27
  import './analytics.cjs';
25
28
 
26
29
  /**
@@ -1,10 +1,12 @@
1
1
  import { CusfrontClient, CreateClientOptions } from './index.js';
2
2
  import { JwtIssued, TelegramUnknown } from './resources/auth.js';
3
- import './http-DeANAoTs.js';
4
- import './cards-BrqeBqLV.js';
3
+ import './http-CL97TjMO.js';
4
+ import './cards-DwmzjKDC.js';
5
5
  import './resources/consents.js';
6
6
  import './resources/balance.js';
7
7
  import './resources/bonus.js';
8
+ import './resources/debt.js';
9
+ import './resources/close-requests.js';
8
10
  import './resources/codes.js';
9
11
  import './resources/referral.js';
10
12
  import './resources/subscription.js';
@@ -17,10 +19,11 @@ import './resources/sessions.js';
17
19
  import './resources/push.js';
18
20
  import './resources/me.js';
19
21
  import './resources/notifications.js';
20
- import './devices-B_YveTl9.js';
22
+ import './devices-C88c38hm.js';
21
23
  import './resources/attribution.js';
22
24
  import './resources/history.js';
23
25
  import './resources/receipts.js';
26
+ import './resources/support.js';
24
27
  import './analytics.js';
25
28
 
26
29
  /**
package/dist/telegram.js CHANGED
@@ -68,10 +68,20 @@ var HttpClient = class {
68
68
  async delete(path, opts = {}) {
69
69
  return this.request("DELETE", path, opts);
70
70
  }
71
+ /** GET a file. Same auth and refresh as the JSON calls; an error status
72
+ * throws `ApiError` the same way. */
73
+ async getBlob(path, opts = {}) {
74
+ const resp = await this.send("GET", path, { ...opts, accept: "*/*" });
75
+ if (!resp.ok) return parseResponse(resp);
76
+ return resp.blob();
77
+ }
71
78
  async request(method, path, opts) {
79
+ return parseResponse(await this.send(method, path, opts));
80
+ }
81
+ async send(method, path, opts) {
72
82
  const url = this.absolute(path);
73
83
  const headers = {
74
- Accept: "application/json",
84
+ Accept: opts.accept ?? "application/json",
75
85
  ...this.defaultHeaders
76
86
  };
77
87
  if (opts.body !== void 0) headers["Content-Type"] = "application/json";
@@ -97,10 +107,10 @@ var HttpClient = class {
97
107
  }
98
108
  if (resp.status === 401 && !opts.skipAuth && !opts.retried && this.refresher) {
99
109
  if (await this.refreshOnce()) {
100
- return this.request(method, path, { ...opts, retried: true });
110
+ return this.send(method, path, { ...opts, retried: true });
101
111
  }
102
112
  }
103
- return parseResponse(resp);
113
+ return resp;
104
114
  }
105
115
  absolute(path) {
106
116
  if (path.startsWith("http://") || path.startsWith("https://")) return path;
@@ -181,6 +191,8 @@ var CardsResource = class {
181
191
  * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row
182
192
  * to `failed` (never an orphaned active card); inspect `status` /
183
193
  * `failure_reason` on the result.
194
+ * Errors: 409 `holder_data_consent_required` when the product has
195
+ * `holder_data_required` and the user has not agreed to it.
184
196
  */
185
197
  async create(input) {
186
198
  const { idempotencyKey, ...card } = input;
@@ -196,7 +208,9 @@ var CardsResource = class {
196
208
  * `pending_payment` until the payment is confirmed. The same
197
209
  * `idempotencyKey` returns the same order.
198
210
  * Errors: 400 `unknown_product` / `method_not_available` / a limit of the
199
- * way of paying, 503 no funding connector or no exchange rate.
211
+ * way of paying, 409 `holder_data_consent_required` (the product has
212
+ * `holder_data_required` and the user has not agreed to it), 503 no
213
+ * funding connector or no exchange rate.
200
214
  */
201
215
  async order(input) {
202
216
  const { idempotencyKey, ...order } = input;
@@ -358,7 +372,10 @@ var CardsResource = class {
358
372
  /**
359
373
  * Terminate the caller's own card. **One-way** — a terminated card cannot be
360
374
  * reactivated. The optional `reason` is audited. Idempotent on an
361
- * already-terminated card.
375
+ * already-terminated card. A card that still holds money is refused (409
376
+ * `move_balance_first` or `contact_support_to_close`): close it with
377
+ * `client.closeRequests.request(id)` instead, and the money goes back the
378
+ * way it was paid.
362
379
  */
363
380
  async terminate(id, reason) {
364
381
  return this.http.post(`/me/cards/${encodeURIComponent(id)}/terminate`, {
@@ -725,6 +742,72 @@ var BonusResource = class {
725
742
  }
726
743
  };
727
744
 
745
+ // src/resources/debt.ts
746
+ var DebtResource = class {
747
+ constructor(http) {
748
+ this.http = http;
749
+ }
750
+ /** What the user owes in card fees, per currency, and what for. */
751
+ async get(opts = {}) {
752
+ return this.http.get("/me/debt", { signal: opts.signal });
753
+ }
754
+ /** What the user owes in `currency`, decimal string; `"0"` when nothing. */
755
+ async owedIn(currency, opts = {}) {
756
+ const debt = await this.get(opts);
757
+ const want = currency.trim().toUpperCase();
758
+ return debt.total.find((d) => d.currency.toUpperCase() === want)?.amount ?? "0";
759
+ }
760
+ };
761
+
762
+ // src/resources/close-requests.ts
763
+ var CloseRequestsResource = class {
764
+ constructor(http) {
765
+ this.http = http;
766
+ }
767
+ /**
768
+ * Close a card that holds money, the rest going back the way it was paid.
769
+ * Asking again for the same card returns the same request. 404 no such
770
+ * card · 409 {@link CloseRequestError}: `no_balance` means the card holds
771
+ * nothing, close it with `cards.terminate()` · 503 the issuer can't be
772
+ * reached; the card stays as it was.
773
+ */
774
+ async request(cardId, input = {}) {
775
+ return this.http.post(`/me/cards/${encodeURIComponent(cardId)}/close-request`, {
776
+ body: { reason: input.reason }
777
+ });
778
+ }
779
+ /** Every card close request of the user, newest first. */
780
+ async list(opts = {}) {
781
+ const res = await this.http.get("/me/close-requests", {
782
+ signal: opts.signal
783
+ });
784
+ return res.items;
785
+ }
786
+ /** One close request. 404 when it isn't the user's. */
787
+ async get(id, opts = {}) {
788
+ return this.http.get(`/me/close-requests/${encodeURIComponent(id)}`, {
789
+ signal: opts.signal
790
+ });
791
+ }
792
+ /** The request for this card, if the user made one. */
793
+ async forCard(cardId, opts = {}) {
794
+ const all = await this.list(opts);
795
+ return all.find((r) => r.card_id === cardId) ?? null;
796
+ }
797
+ /**
798
+ * Give a bank account or a card in the user's own name, when the request
799
+ * is `payout_details_required` (or `identity_check`, to correct them). 400
800
+ * `validation`: a name, number or bank code that doesn't look right · 409
801
+ * `details_not_needed`.
802
+ */
803
+ async submitPayoutDetails(id, details) {
804
+ return this.http.post(
805
+ `/me/close-requests/${encodeURIComponent(id)}/payout-details`,
806
+ { body: details }
807
+ );
808
+ }
809
+ };
810
+
728
811
  // src/resources/codes.ts
729
812
  var CodesResource = class {
730
813
  constructor(http) {
@@ -1239,6 +1322,8 @@ var HistoryResource = class {
1239
1322
  };
1240
1323
 
1241
1324
  // src/resources/consents.ts
1325
+ var HOLDER_DATA_CONSENT = "holder_data_transfer";
1326
+ var DISPUTE_DOCUMENTS_CONSENT = "dispute_documents_transfer";
1242
1327
  var ConsentsResource = class {
1243
1328
  constructor(http) {
1244
1329
  this.http = http;
@@ -1247,20 +1332,51 @@ var ConsentsResource = class {
1247
1332
  async get() {
1248
1333
  return this.http.get("/me/consents");
1249
1334
  }
1335
+ /** Whether `kind` stands now: given and not withdrawn since. */
1336
+ async stands(kind) {
1337
+ const { consents } = await this.get();
1338
+ return consents.some((c) => c.kind === kind && c.given);
1339
+ }
1250
1340
  /**
1251
- * Give (`true`) or withdraw (`false`) an optional consent: `marketing` or
1252
- * `cookies_analytics`. Withdrawing `marketing` turns advertising off in
1253
- * every channel at once; giving it turns on advertising by e-mail. A call
1254
- * that changes nothing records nothing.
1341
+ * Give (`true`) or withdraw (`false`) an optional consent: `marketing`,
1342
+ * `cookies_analytics`, `holder_data_transfer` or
1343
+ * `dispute_documents_transfer`. Withdrawing `marketing` turns advertising
1344
+ * off in every channel at once; giving it turns on advertising by e-mail.
1345
+ * Withdrawing `holder_data_transfer` leaves the user's cards alone and
1346
+ * stops new cards whose product has `holder_data_required`. A call that
1347
+ * changes nothing records nothing, unless it names a card.
1348
+ *
1349
+ * The third argument is the channel, or {@link ConsentOptions} with the
1350
+ * channel and the card.
1255
1351
  *
1256
1352
  * Errors: 400 `consent_required` for `terms` or `personal_data`,
1257
- * 400 `unknown_consent`.
1353
+ * 400 `unknown_consent`, 400 `card_not_allowed` (a card named with a kind
1354
+ * that takes none), 404 `not_found` (not one of the user's cards).
1258
1355
  */
1259
- async set(kind, given, channel) {
1356
+ async set(kind, given, options) {
1357
+ const opts = typeof options === "string" ? { channel: options } : options ?? {};
1260
1358
  const body = { kind, given };
1261
- if (channel !== void 0) body.channel = channel;
1359
+ if (opts.channel !== void 0) body.channel = opts.channel;
1360
+ if (opts.cardId !== void 0) body.card_id = opts.cardId;
1262
1361
  return this.http.post("/me/consents", { body });
1263
1362
  }
1363
+ /**
1364
+ * The user agreed on the consent screen that their real personal details
1365
+ * go to the card issuer (`holder_data_transfer`). Needed before ordering a
1366
+ * product with `holder_data_required`, unless the order itself carries the
1367
+ * kind in its `consents`.
1368
+ */
1369
+ async allowHolderData(options) {
1370
+ return this.set(HOLDER_DATA_CONSENT, true, options);
1371
+ }
1372
+ /**
1373
+ * The user agreed that their documents go to the card issuer for a
1374
+ * dispute (`dispute_documents_transfer`). Name the disputed card with
1375
+ * `cardId`; each call is then recorded on its own.
1376
+ */
1377
+ async allowDisputeDocuments(options) {
1378
+ return this.set(DISPUTE_DOCUMENTS_CONSENT, true, options);
1379
+ }
1264
1380
  /**
1265
1381
  * Record what the cookie banner or the cookie settings say about
1266
1382
  * analytics. Works signed in or not: before sign-in the choice is kept
@@ -1301,6 +1417,70 @@ var ReceiptsResource = class {
1301
1417
  }
1302
1418
  };
1303
1419
 
1420
+ // src/resources/support.ts
1421
+ function bytesToBase64(bytes) {
1422
+ let binary = "";
1423
+ const chunk = 32768;
1424
+ for (let i = 0; i < bytes.length; i += chunk) {
1425
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
1426
+ }
1427
+ return btoa(binary);
1428
+ }
1429
+ async function toBase64(data) {
1430
+ if (typeof data === "string") return data;
1431
+ if (data instanceof Uint8Array) return bytesToBase64(data);
1432
+ if (data instanceof ArrayBuffer) return bytesToBase64(new Uint8Array(data));
1433
+ return bytesToBase64(new Uint8Array(await data.arrayBuffer()));
1434
+ }
1435
+ var SupportResource = class {
1436
+ constructor(http) {
1437
+ this.http = http;
1438
+ }
1439
+ /** The latest messages, oldest first, and the conversation's status.
1440
+ * `before` reads further back; `limit` is 1 to 100 (50). */
1441
+ async list(opts = {}) {
1442
+ const q = new URLSearchParams();
1443
+ if (opts.before) q.set("before", opts.before);
1444
+ if (opts.limit !== void 0) q.set("limit", String(opts.limit));
1445
+ const qs = q.toString();
1446
+ return this.http.get(`/me/support/messages${qs ? `?${qs}` : ""}`, {
1447
+ signal: opts.signal
1448
+ });
1449
+ }
1450
+ /** Write to support. Text, files or both; up to 10 files. */
1451
+ async send(message, opts = {}) {
1452
+ const attachments = await Promise.all(
1453
+ (message.files ?? []).map(async (f) => ({
1454
+ file_name: f.fileName,
1455
+ content_type: f.contentType,
1456
+ data_base64: await toBase64(f.data)
1457
+ }))
1458
+ );
1459
+ return this.http.post("/me/support/messages", {
1460
+ body: { text: message.text ?? "", attachments },
1461
+ signal: opts.signal
1462
+ });
1463
+ }
1464
+ /** A file from the conversation: the person's own or one support sent. */
1465
+ async attachment(id, opts = {}) {
1466
+ return this.http.getBlob(`/me/support/attachments/${encodeURIComponent(id)}`, {
1467
+ signal: opts.signal
1468
+ });
1469
+ }
1470
+ /** Answer `rating_request`: 1 (bad) to 5 (great), a comment if the person
1471
+ * wrote one. Each question takes one answer; a second one is a 404. */
1472
+ async rate(id, answer, opts = {}) {
1473
+ await this.http.post(`/me/support/ratings/${encodeURIComponent(id)}`, {
1474
+ body: { rating: answer.rating, ...answer.comment ? { comment: answer.comment } : {} },
1475
+ signal: opts.signal
1476
+ });
1477
+ }
1478
+ /** Just the conversation's status. */
1479
+ async status(opts = {}) {
1480
+ return (await this.list({ limit: 1, signal: opts.signal })).status;
1481
+ }
1482
+ };
1483
+
1304
1484
  // src/resources/funding-options.ts
1305
1485
  var FundingOptionsResource = class {
1306
1486
  constructor(http) {
@@ -1313,7 +1493,7 @@ var FundingOptionsResource = class {
1313
1493
  };
1314
1494
 
1315
1495
  // src/version.ts
1316
- var SDK_VERSION = "0.6.4";
1496
+ var SDK_VERSION = "0.6.6";
1317
1497
 
1318
1498
  // src/client-platform.ts
1319
1499
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1388,7 +1568,7 @@ function isAbsolute(url) {
1388
1568
  }
1389
1569
 
1390
1570
  // src/compat.ts
1391
- var SUPPORTED_MEISTER = ">=0.6.9, <0.7.0";
1571
+ var SUPPORTED_MEISTER = ">=0.6.12, <0.7.0";
1392
1572
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1393
1573
  function parse(v) {
1394
1574
  const m = SEMVER.exec(v.trim());
@@ -1483,6 +1663,8 @@ function createClient(opts) {
1483
1663
  cards: new CardsResource(http),
1484
1664
  balance: new BalanceResource(http),
1485
1665
  bonus: new BonusResource(http),
1666
+ debt: new DebtResource(http),
1667
+ closeRequests: new CloseRequestsResource(http),
1486
1668
  codes: new CodesResource(http),
1487
1669
  referral: new ReferralResource(http),
1488
1670
  subscription: new SubscriptionResource(http),
@@ -1499,7 +1681,8 @@ function createClient(opts) {
1499
1681
  attribution: new AttributionResource(http),
1500
1682
  history: new HistoryResource(http),
1501
1683
  consents: new ConsentsResource(http),
1502
- receipts: new ReceiptsResource(http)
1684
+ receipts: new ReceiptsResource(http),
1685
+ support: new SupportResource(http)
1503
1686
  };
1504
1687
  }
1505
1688
  function pickDefaultStore(key) {