@takeal/cusfront-sdk 0.6.5 → 0.6.8

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 (97) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +90 -0
  3. package/dist/{cards-ColpW52n.d.ts → cards-BgY00UpU.d.ts} +18 -1
  4. package/dist/{cards-CEFKrVkl.d.cts → cards-DGz4Rqu1.d.cts} +18 -1
  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 +142 -6
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +19 -11
  12. package/dist/index.d.ts +19 -11
  13. package/dist/index.js +142 -6
  14. package/dist/index.js.map +1 -1
  15. package/dist/react/index.d.cts +5 -3
  16. package/dist/react/index.d.ts +5 -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 +3 -2
  21. package/dist/resources/auth.d.ts +3 -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 +16 -0
  32. package/dist/resources/cards.cjs.map +1 -1
  33. package/dist/resources/cards.d.cts +3 -2
  34. package/dist/resources/cards.d.ts +3 -2
  35. package/dist/resources/cards.js +16 -0
  36. package/dist/resources/cards.js.map +1 -1
  37. package/dist/resources/claims.cjs +40 -0
  38. package/dist/resources/claims.cjs.map +1 -0
  39. package/dist/resources/claims.d.cts +114 -0
  40. package/dist/resources/claims.d.ts +114 -0
  41. package/dist/resources/claims.js +38 -0
  42. package/dist/resources/claims.js.map +1 -0
  43. package/dist/resources/close-requests.d.cts +1 -1
  44. package/dist/resources/close-requests.d.ts +1 -1
  45. package/dist/resources/codes.d.cts +1 -1
  46. package/dist/resources/codes.d.ts +1 -1
  47. package/dist/resources/consents.d.cts +1 -1
  48. package/dist/resources/consents.d.ts +1 -1
  49. package/dist/resources/debt.d.cts +1 -1
  50. package/dist/resources/debt.d.ts +1 -1
  51. package/dist/resources/deposits.cjs.map +1 -1
  52. package/dist/resources/deposits.d.cts +3 -2
  53. package/dist/resources/deposits.d.ts +3 -2
  54. package/dist/resources/deposits.js.map +1 -1
  55. package/dist/resources/devices.d.cts +2 -2
  56. package/dist/resources/devices.d.ts +2 -2
  57. package/dist/resources/documents.d.cts +1 -1
  58. package/dist/resources/documents.d.ts +1 -1
  59. package/dist/resources/funding-options.d.cts +3 -2
  60. package/dist/resources/funding-options.d.ts +3 -2
  61. package/dist/resources/history.d.cts +1 -1
  62. package/dist/resources/history.d.ts +1 -1
  63. package/dist/resources/me.d.cts +3 -2
  64. package/dist/resources/me.d.ts +3 -2
  65. package/dist/resources/notifications.d.cts +1 -1
  66. package/dist/resources/notifications.d.ts +1 -1
  67. package/dist/resources/push.d.cts +1 -1
  68. package/dist/resources/push.d.ts +1 -1
  69. package/dist/resources/receipts.d.cts +1 -1
  70. package/dist/resources/receipts.d.ts +1 -1
  71. package/dist/resources/referral.d.cts +1 -1
  72. package/dist/resources/referral.d.ts +1 -1
  73. package/dist/resources/sessions.d.cts +1 -1
  74. package/dist/resources/sessions.d.ts +1 -1
  75. package/dist/resources/subscription.cjs +9 -0
  76. package/dist/resources/subscription.cjs.map +1 -1
  77. package/dist/resources/subscription.d.cts +20 -3
  78. package/dist/resources/subscription.d.ts +20 -3
  79. package/dist/resources/subscription.js +9 -0
  80. package/dist/resources/subscription.js.map +1 -1
  81. package/dist/resources/subscriptions.d.cts +1 -1
  82. package/dist/resources/subscriptions.d.ts +1 -1
  83. package/dist/resources/support.cjs +69 -0
  84. package/dist/resources/support.cjs.map +1 -0
  85. package/dist/resources/support.d.cts +115 -0
  86. package/dist/resources/support.d.ts +115 -0
  87. package/dist/resources/support.js +67 -0
  88. package/dist/resources/support.js.map +1 -0
  89. package/dist/resources/wallet.d.cts +1 -1
  90. package/dist/resources/wallet.d.ts +1 -1
  91. package/dist/telegram.cjs +142 -6
  92. package/dist/telegram.cjs.map +1 -1
  93. package/dist/telegram.d.cts +5 -3
  94. package/dist/telegram.d.ts +5 -3
  95. package/dist/telegram.js +142 -6
  96. package/dist/telegram.js.map +1 -1
  97. package/package.json +11 -1
package/dist/telegram.cjs CHANGED
@@ -70,10 +70,20 @@ var HttpClient = class {
70
70
  async delete(path, opts = {}) {
71
71
  return this.request("DELETE", path, opts);
72
72
  }
73
+ /** GET a file. Same auth and refresh as the JSON calls; an error status
74
+ * throws `ApiError` the same way. */
75
+ async getBlob(path, opts = {}) {
76
+ const resp = await this.send("GET", path, { ...opts, accept: "*/*" });
77
+ if (!resp.ok) return parseResponse(resp);
78
+ return resp.blob();
79
+ }
73
80
  async request(method, path, opts) {
81
+ return parseResponse(await this.send(method, path, opts));
82
+ }
83
+ async send(method, path, opts) {
74
84
  const url = this.absolute(path);
75
85
  const headers = {
76
- Accept: "application/json",
86
+ Accept: opts.accept ?? "application/json",
77
87
  ...this.defaultHeaders
78
88
  };
79
89
  if (opts.body !== void 0) headers["Content-Type"] = "application/json";
@@ -99,10 +109,10 @@ var HttpClient = class {
99
109
  }
100
110
  if (resp.status === 401 && !opts.skipAuth && !opts.retried && this.refresher) {
101
111
  if (await this.refreshOnce()) {
102
- return this.request(method, path, { ...opts, retried: true });
112
+ return this.send(method, path, { ...opts, retried: true });
103
113
  }
104
114
  }
105
- return parseResponse(resp);
115
+ return resp;
106
116
  }
107
117
  absolute(path) {
108
118
  if (path.startsWith("http://") || path.startsWith("https://")) return path;
@@ -348,6 +358,22 @@ var CardsResource = class {
348
358
  async unfreeze(id) {
349
359
  return this.http.post(`/me/cards/${encodeURIComponent(id)}/unfreeze`, { body: {} });
350
360
  }
361
+ /**
362
+ * Report the card lost or stolen. Works at any time, on an active or a
363
+ * frozen card. The report is recorded first with the server's time, which
364
+ * decides who pays for operations someone else made; then the card is
365
+ * frozen at its issuer and only support can unfreeze it. Resolves to the
366
+ * claim (`client.claims`): show its `number` and `reported_at`. When the
367
+ * issuer can't be reached, `card_freeze` is `"pending"`: the report still
368
+ * counts and support freezes the card by hand. Reporting again while the
369
+ * report is open returns the same claim. 404 / 403 not the user's card ·
370
+ * 409 `card_not_open`: the card is closed or was never issued.
371
+ */
372
+ async reportLost(id, input) {
373
+ return this.http.post(`/me/cards/${encodeURIComponent(id)}/report-lost`, {
374
+ body: { kind: input.kind, details: input.details }
375
+ });
376
+ }
351
377
  /**
352
378
  * Set the PIN of the caller's own physical card. The session is enough; the
353
379
  * call is rate-limited like {@link reveal} and the PIN is kept nowhere.
@@ -800,6 +826,41 @@ var CloseRequestsResource = class {
800
826
  }
801
827
  };
802
828
 
829
+ // src/resources/claims.ts
830
+ var ClaimsResource = class {
831
+ constructor(http) {
832
+ this.http = http;
833
+ }
834
+ /**
835
+ * Dispute a card operation, or complain. 400 `validation`: a description
836
+ * that is too short or too long, an operation that isn't on the user's
837
+ * cards, or a lost or stolen card (use `cards.reportLost()`) · 404 no
838
+ * such card · 409 `too_many_claims`: 20 claims are waiting for an answer.
839
+ */
840
+ async create(input) {
841
+ return this.http.post("/me/claims", {
842
+ body: {
843
+ kind: input.kind,
844
+ description: input.description,
845
+ card_id: input.cardId,
846
+ transaction_id: input.transactionId
847
+ }
848
+ });
849
+ }
850
+ /** The user's claims, lost and stolen cards included, newest first. */
851
+ async list(opts = {}) {
852
+ const qs = new URLSearchParams();
853
+ if (opts.limit != null) qs.set("limit", String(opts.limit));
854
+ if (opts.offset != null) qs.set("offset", String(opts.offset));
855
+ const q = qs.toString();
856
+ return this.http.get(`/me/claims${q ? `?${q}` : ""}`, { signal: opts.signal });
857
+ }
858
+ /** One claim. 404 when it isn't the user's. */
859
+ async get(id, opts = {}) {
860
+ return this.http.get(`/me/claims/${encodeURIComponent(id)}`, { signal: opts.signal });
861
+ }
862
+ };
863
+
803
864
  // src/resources/codes.ts
804
865
  var CodesResource = class {
805
866
  constructor(http) {
@@ -843,6 +904,15 @@ var SubscriptionResource = class {
843
904
  async setPromoCode(code) {
844
905
  return this.http.put("/me/subscription/promo-code", { body: { code } });
845
906
  }
907
+ /**
908
+ * Cancel the subscription now, in one step. What was paid for the current
909
+ * period comes back to the balance for the days not used. No subscription
910
+ * running → 404; 503 `refund_unavailable` when the refund can't be made
911
+ * right now (the subscription keeps running; try again).
912
+ */
913
+ async cancel() {
914
+ return this.http.post("/me/subscription/cancel", {});
915
+ }
846
916
  };
847
917
 
848
918
  // src/resources/branding.ts
@@ -1409,6 +1479,70 @@ var ReceiptsResource = class {
1409
1479
  }
1410
1480
  };
1411
1481
 
1482
+ // src/resources/support.ts
1483
+ function bytesToBase64(bytes) {
1484
+ let binary = "";
1485
+ const chunk = 32768;
1486
+ for (let i = 0; i < bytes.length; i += chunk) {
1487
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
1488
+ }
1489
+ return btoa(binary);
1490
+ }
1491
+ async function toBase64(data) {
1492
+ if (typeof data === "string") return data;
1493
+ if (data instanceof Uint8Array) return bytesToBase64(data);
1494
+ if (data instanceof ArrayBuffer) return bytesToBase64(new Uint8Array(data));
1495
+ return bytesToBase64(new Uint8Array(await data.arrayBuffer()));
1496
+ }
1497
+ var SupportResource = class {
1498
+ constructor(http) {
1499
+ this.http = http;
1500
+ }
1501
+ /** The latest messages, oldest first, and the conversation's status.
1502
+ * `before` reads further back; `limit` is 1 to 100 (50). */
1503
+ async list(opts = {}) {
1504
+ const q = new URLSearchParams();
1505
+ if (opts.before) q.set("before", opts.before);
1506
+ if (opts.limit !== void 0) q.set("limit", String(opts.limit));
1507
+ const qs = q.toString();
1508
+ return this.http.get(`/me/support/messages${qs ? `?${qs}` : ""}`, {
1509
+ signal: opts.signal
1510
+ });
1511
+ }
1512
+ /** Write to support. Text, files or both; up to 10 files. */
1513
+ async send(message, opts = {}) {
1514
+ const attachments = await Promise.all(
1515
+ (message.files ?? []).map(async (f) => ({
1516
+ file_name: f.fileName,
1517
+ content_type: f.contentType,
1518
+ data_base64: await toBase64(f.data)
1519
+ }))
1520
+ );
1521
+ return this.http.post("/me/support/messages", {
1522
+ body: { text: message.text ?? "", attachments },
1523
+ signal: opts.signal
1524
+ });
1525
+ }
1526
+ /** A file from the conversation: the person's own or one support sent. */
1527
+ async attachment(id, opts = {}) {
1528
+ return this.http.getBlob(`/me/support/attachments/${encodeURIComponent(id)}`, {
1529
+ signal: opts.signal
1530
+ });
1531
+ }
1532
+ /** Answer `rating_request`: 1 (bad) to 5 (great), a comment if the person
1533
+ * wrote one. Each question takes one answer; a second one is a 404. */
1534
+ async rate(id, answer, opts = {}) {
1535
+ await this.http.post(`/me/support/ratings/${encodeURIComponent(id)}`, {
1536
+ body: { rating: answer.rating, ...answer.comment ? { comment: answer.comment } : {} },
1537
+ signal: opts.signal
1538
+ });
1539
+ }
1540
+ /** Just the conversation's status. */
1541
+ async status(opts = {}) {
1542
+ return (await this.list({ limit: 1, signal: opts.signal })).status;
1543
+ }
1544
+ };
1545
+
1412
1546
  // src/resources/funding-options.ts
1413
1547
  var FundingOptionsResource = class {
1414
1548
  constructor(http) {
@@ -1421,7 +1555,7 @@ var FundingOptionsResource = class {
1421
1555
  };
1422
1556
 
1423
1557
  // src/version.ts
1424
- var SDK_VERSION = "0.6.5";
1558
+ var SDK_VERSION = "0.6.8";
1425
1559
 
1426
1560
  // src/client-platform.ts
1427
1561
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1496,7 +1630,7 @@ function isAbsolute(url) {
1496
1630
  }
1497
1631
 
1498
1632
  // src/compat.ts
1499
- var SUPPORTED_MEISTER = ">=0.6.11, <0.7.0";
1633
+ var SUPPORTED_MEISTER = ">=0.6.13, <1.0.0";
1500
1634
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1501
1635
  function parse(v) {
1502
1636
  const m = SEMVER.exec(v.trim());
@@ -1593,6 +1727,7 @@ function createClient(opts) {
1593
1727
  bonus: new BonusResource(http),
1594
1728
  debt: new DebtResource(http),
1595
1729
  closeRequests: new CloseRequestsResource(http),
1730
+ claims: new ClaimsResource(http),
1596
1731
  codes: new CodesResource(http),
1597
1732
  referral: new ReferralResource(http),
1598
1733
  subscription: new SubscriptionResource(http),
@@ -1609,7 +1744,8 @@ function createClient(opts) {
1609
1744
  attribution: new AttributionResource(http),
1610
1745
  history: new HistoryResource(http),
1611
1746
  consents: new ConsentsResource(http),
1612
- receipts: new ReceiptsResource(http)
1747
+ receipts: new ReceiptsResource(http),
1748
+ support: new SupportResource(http)
1613
1749
  };
1614
1750
  }
1615
1751
  function pickDefaultStore(key) {