@takeal/cusfront-sdk 0.6.5 → 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 (79) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +53 -0
  3. package/dist/{cards-CEFKrVkl.d.cts → cards-BiXmrz7h.d.cts} +1 -1
  4. package/dist/{cards-ColpW52n.d.ts → cards-DwmzjKDC.d.ts} +1 -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 +81 -6
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +13 -9
  12. package/dist/index.d.ts +13 -9
  13. package/dist/index.js +81 -6
  14. package/dist/index.js.map +1 -1
  15. package/dist/react/index.d.cts +4 -3
  16. package/dist/react/index.d.ts +4 -3
  17. package/dist/resources/attribution.d.cts +1 -1
  18. package/dist/resources/attribution.d.ts +1 -1
  19. package/dist/resources/auth.d.cts +2 -2
  20. package/dist/resources/auth.d.ts +2 -2
  21. package/dist/resources/balance.d.cts +1 -1
  22. package/dist/resources/balance.d.ts +1 -1
  23. package/dist/resources/blog.d.cts +1 -1
  24. package/dist/resources/blog.d.ts +1 -1
  25. package/dist/resources/bonus.d.cts +1 -1
  26. package/dist/resources/bonus.d.ts +1 -1
  27. package/dist/resources/branding.d.cts +1 -1
  28. package/dist/resources/branding.d.ts +1 -1
  29. package/dist/resources/cards.d.cts +2 -2
  30. package/dist/resources/cards.d.ts +2 -2
  31. package/dist/resources/close-requests.d.cts +1 -1
  32. package/dist/resources/close-requests.d.ts +1 -1
  33. package/dist/resources/codes.d.cts +1 -1
  34. package/dist/resources/codes.d.ts +1 -1
  35. package/dist/resources/consents.d.cts +1 -1
  36. package/dist/resources/consents.d.ts +1 -1
  37. package/dist/resources/debt.d.cts +1 -1
  38. package/dist/resources/debt.d.ts +1 -1
  39. package/dist/resources/deposits.d.cts +2 -2
  40. package/dist/resources/deposits.d.ts +2 -2
  41. package/dist/resources/devices.d.cts +2 -2
  42. package/dist/resources/devices.d.ts +2 -2
  43. package/dist/resources/documents.d.cts +1 -1
  44. package/dist/resources/documents.d.ts +1 -1
  45. package/dist/resources/funding-options.d.cts +2 -2
  46. package/dist/resources/funding-options.d.ts +2 -2
  47. package/dist/resources/history.d.cts +1 -1
  48. package/dist/resources/history.d.ts +1 -1
  49. package/dist/resources/me.d.cts +2 -2
  50. package/dist/resources/me.d.ts +2 -2
  51. package/dist/resources/notifications.d.cts +1 -1
  52. package/dist/resources/notifications.d.ts +1 -1
  53. package/dist/resources/push.d.cts +1 -1
  54. package/dist/resources/push.d.ts +1 -1
  55. package/dist/resources/receipts.d.cts +1 -1
  56. package/dist/resources/receipts.d.ts +1 -1
  57. package/dist/resources/referral.d.cts +1 -1
  58. package/dist/resources/referral.d.ts +1 -1
  59. package/dist/resources/sessions.d.cts +1 -1
  60. package/dist/resources/sessions.d.ts +1 -1
  61. package/dist/resources/subscription.d.cts +1 -1
  62. package/dist/resources/subscription.d.ts +1 -1
  63. package/dist/resources/subscriptions.d.cts +1 -1
  64. package/dist/resources/subscriptions.d.ts +1 -1
  65. package/dist/resources/support.cjs +69 -0
  66. package/dist/resources/support.cjs.map +1 -0
  67. package/dist/resources/support.d.cts +110 -0
  68. package/dist/resources/support.d.ts +110 -0
  69. package/dist/resources/support.js +67 -0
  70. package/dist/resources/support.js.map +1 -0
  71. package/dist/resources/wallet.d.cts +1 -1
  72. package/dist/resources/wallet.d.ts +1 -1
  73. package/dist/telegram.cjs +81 -6
  74. package/dist/telegram.cjs.map +1 -1
  75. package/dist/telegram.d.cts +4 -3
  76. package/dist/telegram.d.ts +4 -3
  77. package/dist/telegram.js +81 -6
  78. package/dist/telegram.js.map +1 -1
  79. package/package.json +6 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to `@takeal/cusfront-sdk` are documented here. The format
4
4
  follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.6.6] — 2026-10-23
8
+
9
+ ### Added
10
+
11
+ - `support`: the chat with support. `list()` reads the conversation (oldest
12
+ first, `before` for older pages) and its status, `send({ text, files })`
13
+ writes with up to 10 files (a `File`, bytes or base64), `attachment(id)`
14
+ downloads a file as a `Blob`. Answers come with ready, cleaned HTML in
15
+ `html`. Needs the platform's support chat (0.6.12).
16
+ - `support.rate(id, { rating, comment })` and `rating_request` on the
17
+ conversation: support asks how it went after closing a conversation it
18
+ answered.
19
+
7
20
  ## [0.6.5] — 2026-10-21
8
21
 
9
22
  Needs platform (TKL) 0.6.11 or newer: `SUPPORTED_MEISTER` is `>=0.6.11, <0.7.0`.
package/README.md CHANGED
@@ -1040,6 +1040,58 @@ export default {
1040
1040
 
1041
1041
  With Workbox, add `/^\/ingest\//` to `navigateFallbackDenylist` and give the path no runtime caching route.
1042
1042
 
1043
+ ## Support chat
1044
+
1045
+ `client.support` is the chat with support: one conversation per person, the
1046
+ same one the Telegram bot feeds. Support agents answer from their own inbox,
1047
+ and the answers come back here.
1048
+
1049
+ ```ts
1050
+ // A message with a picture from a file input.
1051
+ const file = input.files![0];
1052
+ const sent = await client.support.send({
1053
+ text: "The card was declined at the shop",
1054
+ files: [{ fileName: file.name, contentType: file.type, data: file }],
1055
+ });
1056
+ // sent.status === "queued" at first; "delivered" once support has it.
1057
+
1058
+ const chat = await client.support.list();
1059
+ // chat.status: "none" | "open" | "resolved"; chat.items oldest first.
1060
+ for (const m of chat.items) {
1061
+ if (m.author === "support") {
1062
+ // Cleaned HTML, ready to show: paragraphs, line breaks, bold, italic,
1063
+ // strikethrough, code, links, lists and quotes. Nothing else gets through.
1064
+ bubble.innerHTML = m.html;
1065
+ caption.textContent = m.operator_name ?? "Support";
1066
+ } else {
1067
+ bubble.textContent = m.text;
1068
+ }
1069
+ for (const a of m.attachments) {
1070
+ const blob = await client.support.attachment(a.id); // the person's own or support's
1071
+ }
1072
+ }
1073
+
1074
+ // Older messages:
1075
+ if (chat.has_more) await client.support.list({ before: chat.items[0].created_at });
1076
+ ```
1077
+
1078
+ Show what the person sent right away, with its `status`: `queued` turns into
1079
+ `delivered` within seconds, and `failed` means the message could not be passed
1080
+ on (support sees those too and can send them again). Files are pictures and
1081
+ PDF up to 20 MB by default; the platform sets both, and a file it doesn't take
1082
+ comes back as a 400 with the reason. Up to 10 files per message.
1083
+
1084
+ When support closes the conversation after answering, `chat.rating_request`
1085
+ asks how it went (a `support_rating_requested` notification points there too).
1086
+ Show 1 to 5 and an optional comment, then
1087
+ `client.support.rate(chat.rating_request.id, { rating: 5, comment })`. The
1088
+ question goes away once answered; a person who wrote from Telegram is asked
1089
+ there instead, with buttons.
1090
+
1091
+ A new answer also arrives as a `support_reply` notification (see
1092
+ [Notifications](#notifications-inbox)) with `href: "/support"`. Writing to a
1093
+ conversation support has closed opens it again.
1094
+
1043
1095
  ## Notifications (inbox)
1044
1096
 
1045
1097
  Everything the API tells a user (a confirmed deposit, a card transaction, a
@@ -1300,6 +1352,7 @@ Available now:
1300
1352
  - `@takeal/cusfront-sdk/history` — `HistoryResource` (the user's money history).
1301
1353
  - `@takeal/cusfront-sdk/consents` — `ConsentsResource` (what the user agreed to).
1302
1354
  - `@takeal/cusfront-sdk/receipts` — `ReceiptsResource` (a numbered receipt for every payment).
1355
+ - `@takeal/cusfront-sdk/support` — `SupportResource` (the chat with support; see [Support chat](#support-chat)).
1303
1356
  - `@takeal/cusfront-sdk/attribution` — `AttributionResource`, `anonymousKey`, `currentTouch` (where users come from).
1304
1357
  - `@takeal/cusfront-sdk/webhooks` — HMAC-SHA256 signature verifier (no network, isomorphic).
1305
1358
  - `@takeal/cusfront-sdk/react` — optional React hooks layer (`ClientProvider` + `useMe` / `useDeposits` / `useCards` / `useCardProducts` / `useBalance` / `useNotifications` / `useUnreadCount`). React is a `peerDependency`, never bundled.
@@ -1,5 +1,5 @@
1
1
  import { ConsentKind, ConsentChannel } from './resources/consents.cjs';
2
- import { H as HttpClient } from './http-DeANAoTs.cjs';
2
+ import { H as HttpClient } from './http-CL97TjMO.cjs';
3
3
 
4
4
  /**
5
5
  * Structured customer billing details — shared by the deposits and cards
@@ -1,5 +1,5 @@
1
1
  import { ConsentKind, ConsentChannel } from './resources/consents.js';
2
- import { H as HttpClient } from './http-DeANAoTs.js';
2
+ import { H as HttpClient } from './http-CL97TjMO.js';
3
3
 
4
4
  /**
5
5
  * Structured customer billing details — shared by the deposits and cards
@@ -1,4 +1,4 @@
1
- import { H as HttpClient } from './http-DeANAoTs.js';
1
+ import { H as HttpClient } from './http-CL97TjMO.js';
2
2
  import { PushCapableRegistration } from './resources/push.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { H as HttpClient } from './http-DeANAoTs.cjs';
1
+ import { H as HttpClient } from './http-CL97TjMO.cjs';
2
2
  import { PushCapableRegistration } from './resources/push.cjs';
3
3
 
4
4
  /**
@@ -84,7 +84,11 @@ declare class HttpClient {
84
84
  put<T>(path: string, opts?: HttpOptions): Promise<T>;
85
85
  patch<T>(path: string, opts?: HttpOptions): Promise<T>;
86
86
  delete<T>(path: string, opts?: HttpOptions): Promise<T>;
87
+ /** GET a file. Same auth and refresh as the JSON calls; an error status
88
+ * throws `ApiError` the same way. */
89
+ getBlob(path: string, opts?: HttpOptions): Promise<Blob>;
87
90
  private request;
91
+ private send;
88
92
  private absolute;
89
93
  }
90
94
 
@@ -84,7 +84,11 @@ declare class HttpClient {
84
84
  put<T>(path: string, opts?: HttpOptions): Promise<T>;
85
85
  patch<T>(path: string, opts?: HttpOptions): Promise<T>;
86
86
  delete<T>(path: string, opts?: HttpOptions): Promise<T>;
87
+ /** GET a file. Same auth and refresh as the JSON calls; an error status
88
+ * throws `ApiError` the same way. */
89
+ getBlob(path: string, opts?: HttpOptions): Promise<Blob>;
87
90
  private request;
91
+ private send;
88
92
  private absolute;
89
93
  }
90
94
 
package/dist/index.cjs CHANGED
@@ -73,10 +73,20 @@ var HttpClient = class {
73
73
  async delete(path, opts = {}) {
74
74
  return this.request("DELETE", path, opts);
75
75
  }
76
+ /** GET a file. Same auth and refresh as the JSON calls; an error status
77
+ * throws `ApiError` the same way. */
78
+ async getBlob(path, opts = {}) {
79
+ const resp = await this.send("GET", path, { ...opts, accept: "*/*" });
80
+ if (!resp.ok) return parseResponse(resp);
81
+ return resp.blob();
82
+ }
76
83
  async request(method, path, opts) {
84
+ return parseResponse(await this.send(method, path, opts));
85
+ }
86
+ async send(method, path, opts) {
77
87
  const url = this.absolute(path);
78
88
  const headers = {
79
- Accept: "application/json",
89
+ Accept: opts.accept ?? "application/json",
80
90
  ...this.defaultHeaders
81
91
  };
82
92
  if (opts.body !== void 0) headers["Content-Type"] = "application/json";
@@ -102,10 +112,10 @@ var HttpClient = class {
102
112
  }
103
113
  if (resp.status === 401 && !opts.skipAuth && !opts.retried && this.refresher) {
104
114
  if (await this.refreshOnce()) {
105
- return this.request(method, path, { ...opts, retried: true });
115
+ return this.send(method, path, { ...opts, retried: true });
106
116
  }
107
117
  }
108
- return parseResponse(resp);
118
+ return resp;
109
119
  }
110
120
  absolute(path) {
111
121
  if (path.startsWith("http://") || path.startsWith("https://")) return path;
@@ -1429,6 +1439,70 @@ var ReceiptsResource = class {
1429
1439
  }
1430
1440
  };
1431
1441
 
1442
+ // src/resources/support.ts
1443
+ function bytesToBase64(bytes) {
1444
+ let binary = "";
1445
+ const chunk = 32768;
1446
+ for (let i = 0; i < bytes.length; i += chunk) {
1447
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
1448
+ }
1449
+ return btoa(binary);
1450
+ }
1451
+ async function toBase64(data) {
1452
+ if (typeof data === "string") return data;
1453
+ if (data instanceof Uint8Array) return bytesToBase64(data);
1454
+ if (data instanceof ArrayBuffer) return bytesToBase64(new Uint8Array(data));
1455
+ return bytesToBase64(new Uint8Array(await data.arrayBuffer()));
1456
+ }
1457
+ var SupportResource = class {
1458
+ constructor(http) {
1459
+ this.http = http;
1460
+ }
1461
+ /** The latest messages, oldest first, and the conversation's status.
1462
+ * `before` reads further back; `limit` is 1 to 100 (50). */
1463
+ async list(opts = {}) {
1464
+ const q = new URLSearchParams();
1465
+ if (opts.before) q.set("before", opts.before);
1466
+ if (opts.limit !== void 0) q.set("limit", String(opts.limit));
1467
+ const qs = q.toString();
1468
+ return this.http.get(`/me/support/messages${qs ? `?${qs}` : ""}`, {
1469
+ signal: opts.signal
1470
+ });
1471
+ }
1472
+ /** Write to support. Text, files or both; up to 10 files. */
1473
+ async send(message, opts = {}) {
1474
+ const attachments = await Promise.all(
1475
+ (message.files ?? []).map(async (f) => ({
1476
+ file_name: f.fileName,
1477
+ content_type: f.contentType,
1478
+ data_base64: await toBase64(f.data)
1479
+ }))
1480
+ );
1481
+ return this.http.post("/me/support/messages", {
1482
+ body: { text: message.text ?? "", attachments },
1483
+ signal: opts.signal
1484
+ });
1485
+ }
1486
+ /** A file from the conversation: the person's own or one support sent. */
1487
+ async attachment(id, opts = {}) {
1488
+ return this.http.getBlob(`/me/support/attachments/${encodeURIComponent(id)}`, {
1489
+ signal: opts.signal
1490
+ });
1491
+ }
1492
+ /** Answer `rating_request`: 1 (bad) to 5 (great), a comment if the person
1493
+ * wrote one. Each question takes one answer; a second one is a 404. */
1494
+ async rate(id, answer, opts = {}) {
1495
+ await this.http.post(`/me/support/ratings/${encodeURIComponent(id)}`, {
1496
+ body: { rating: answer.rating, ...answer.comment ? { comment: answer.comment } : {} },
1497
+ signal: opts.signal
1498
+ });
1499
+ }
1500
+ /** Just the conversation's status. */
1501
+ async status(opts = {}) {
1502
+ return (await this.list({ limit: 1, signal: opts.signal })).status;
1503
+ }
1504
+ };
1505
+
1432
1506
  // src/resources/funding-options.ts
1433
1507
  var FundingOptionsResource = class {
1434
1508
  constructor(http) {
@@ -1441,7 +1515,7 @@ var FundingOptionsResource = class {
1441
1515
  };
1442
1516
 
1443
1517
  // src/version.ts
1444
- var SDK_VERSION = "0.6.5";
1518
+ var SDK_VERSION = "0.6.6";
1445
1519
 
1446
1520
  // src/client-platform.ts
1447
1521
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1516,7 +1590,7 @@ function isAbsolute(url) {
1516
1590
  }
1517
1591
 
1518
1592
  // src/compat.ts
1519
- var SUPPORTED_MEISTER = ">=0.6.11, <0.7.0";
1593
+ var SUPPORTED_MEISTER = ">=0.6.12, <0.7.0";
1520
1594
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1521
1595
  function parse(v) {
1522
1596
  const m = SEMVER.exec(v.trim());
@@ -2047,7 +2121,8 @@ function createClient(opts) {
2047
2121
  attribution: new AttributionResource(http),
2048
2122
  history: new HistoryResource(http),
2049
2123
  consents: new ConsentsResource(http),
2050
- receipts: new ReceiptsResource(http)
2124
+ receipts: new ReceiptsResource(http),
2125
+ support: new SupportResource(http)
2051
2126
  };
2052
2127
  }
2053
2128
  function pickDefaultStore(key) {