@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
@@ -1,7 +1,7 @@
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-CEFKrVkl.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';
@@ -19,10 +19,11 @@ import './resources/sessions.cjs';
19
19
  import './resources/push.cjs';
20
20
  import './resources/me.cjs';
21
21
  import './resources/notifications.cjs';
22
- import './devices-a5Z45Mx_.cjs';
22
+ import './devices-CiJrlXum.cjs';
23
23
  import './resources/attribution.cjs';
24
24
  import './resources/history.cjs';
25
25
  import './resources/receipts.cjs';
26
+ import './resources/support.cjs';
26
27
  import './analytics.cjs';
27
28
 
28
29
  /**
@@ -1,7 +1,7 @@
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-ColpW52n.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';
@@ -19,10 +19,11 @@ import './resources/sessions.js';
19
19
  import './resources/push.js';
20
20
  import './resources/me.js';
21
21
  import './resources/notifications.js';
22
- import './devices-B_YveTl9.js';
22
+ import './devices-C88c38hm.js';
23
23
  import './resources/attribution.js';
24
24
  import './resources/history.js';
25
25
  import './resources/receipts.js';
26
+ import './resources/support.js';
26
27
  import './analytics.js';
27
28
 
28
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;
@@ -1407,6 +1417,70 @@ var ReceiptsResource = class {
1407
1417
  }
1408
1418
  };
1409
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
+
1410
1484
  // src/resources/funding-options.ts
1411
1485
  var FundingOptionsResource = class {
1412
1486
  constructor(http) {
@@ -1419,7 +1493,7 @@ var FundingOptionsResource = class {
1419
1493
  };
1420
1494
 
1421
1495
  // src/version.ts
1422
- var SDK_VERSION = "0.6.5";
1496
+ var SDK_VERSION = "0.6.6";
1423
1497
 
1424
1498
  // src/client-platform.ts
1425
1499
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1494,7 +1568,7 @@ function isAbsolute(url) {
1494
1568
  }
1495
1569
 
1496
1570
  // src/compat.ts
1497
- var SUPPORTED_MEISTER = ">=0.6.11, <0.7.0";
1571
+ var SUPPORTED_MEISTER = ">=0.6.12, <0.7.0";
1498
1572
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1499
1573
  function parse(v) {
1500
1574
  const m = SEMVER.exec(v.trim());
@@ -1607,7 +1681,8 @@ function createClient(opts) {
1607
1681
  attribution: new AttributionResource(http),
1608
1682
  history: new HistoryResource(http),
1609
1683
  consents: new ConsentsResource(http),
1610
- receipts: new ReceiptsResource(http)
1684
+ receipts: new ReceiptsResource(http),
1685
+ support: new SupportResource(http)
1611
1686
  };
1612
1687
  }
1613
1688
  function pickDefaultStore(key) {