@takeal/cusfront-sdk 0.6.0 → 0.6.2

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 (57) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +221 -1
  3. package/dist/{cards-B_aNY35J.d.cts → cards-DU2DdhYO.d.cts} +154 -20
  4. package/dist/{cards-Ba1wZttb.d.ts → cards-DzhPVA9N.d.ts} +154 -20
  5. package/dist/{deposits-BEc8U80M.d.cts → deposits-BEkNeE-v.d.cts} +71 -8
  6. package/dist/{deposits-DScyT_D9.d.ts → deposits-Dt6A76MB.d.ts} +71 -8
  7. package/dist/index.cjs +129 -14
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +16 -8
  10. package/dist/index.d.ts +16 -8
  11. package/dist/index.js +129 -14
  12. package/dist/index.js.map +1 -1
  13. package/dist/react/index.d.cts +4 -2
  14. package/dist/react/index.d.ts +4 -2
  15. package/dist/resources/auth.cjs +25 -4
  16. package/dist/resources/auth.cjs.map +1 -1
  17. package/dist/resources/auth.d.cts +40 -5
  18. package/dist/resources/auth.d.ts +40 -5
  19. package/dist/resources/auth.js +25 -4
  20. package/dist/resources/auth.js.map +1 -1
  21. package/dist/resources/cards.cjs +32 -6
  22. package/dist/resources/cards.cjs.map +1 -1
  23. package/dist/resources/cards.d.cts +2 -1
  24. package/dist/resources/cards.d.ts +2 -1
  25. package/dist/resources/cards.js +32 -6
  26. package/dist/resources/cards.js.map +1 -1
  27. package/dist/resources/consents.cjs +91 -0
  28. package/dist/resources/consents.cjs.map +1 -0
  29. package/dist/resources/consents.d.cts +83 -0
  30. package/dist/resources/consents.d.ts +83 -0
  31. package/dist/resources/consents.js +89 -0
  32. package/dist/resources/consents.js.map +1 -0
  33. package/dist/resources/deposits.cjs +6 -1
  34. package/dist/resources/deposits.cjs.map +1 -1
  35. package/dist/resources/deposits.d.cts +3 -2
  36. package/dist/resources/deposits.d.ts +3 -2
  37. package/dist/resources/deposits.js +6 -1
  38. package/dist/resources/deposits.js.map +1 -1
  39. package/dist/resources/funding-options.cjs.map +1 -1
  40. package/dist/resources/funding-options.d.cts +3 -2
  41. package/dist/resources/funding-options.d.ts +3 -2
  42. package/dist/resources/funding-options.js.map +1 -1
  43. package/dist/resources/me.d.cts +1 -0
  44. package/dist/resources/me.d.ts +1 -0
  45. package/dist/resources/receipts.cjs +22 -0
  46. package/dist/resources/receipts.cjs.map +1 -0
  47. package/dist/resources/receipts.d.cts +51 -0
  48. package/dist/resources/receipts.d.ts +51 -0
  49. package/dist/resources/receipts.js +20 -0
  50. package/dist/resources/receipts.js.map +1 -0
  51. package/dist/telegram.cjs +167 -14
  52. package/dist/telegram.cjs.map +1 -1
  53. package/dist/telegram.d.cts +4 -2
  54. package/dist/telegram.d.ts +4 -2
  55. package/dist/telegram.js +167 -14
  56. package/dist/telegram.js.map +1 -1
  57. package/package.json +11 -1
package/dist/telegram.cjs CHANGED
@@ -229,7 +229,8 @@ var AuthResource = class {
229
229
  * `wallet_currency` must be one the deployment offers; omit it to take
230
230
  * the deployment default (it can be switched later via `client.wallet`
231
231
  * while the wallet is empty).
232
- * Errors: 400 `validation` / `currency_not_allowed`, 409 email taken. */
232
+ * Errors: 400 `validation` / `currency_not_allowed` / `consents_required`
233
+ * / `unknown_consent`, 409 email taken. */
233
234
  async register(input) {
234
235
  const resp = await this.http.post("/auth/register", {
235
236
  body: withRemember(input),
@@ -274,6 +275,8 @@ var AuthResource = class {
274
275
  if (input.provision !== void 0) body.provision = input.provision;
275
276
  if (input.attribution !== void 0) body.attribution = input.attribution;
276
277
  if (input.code !== void 0) body.code = input.code;
278
+ if (input.consents !== void 0) body.consents = input.consents;
279
+ if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
277
280
  let resp;
278
281
  try {
279
282
  resp = await this.http.post("/auth/telegram/exchange", {
@@ -308,12 +311,30 @@ var AuthResource = class {
308
311
  await Promise.resolve(this.tokens.set(resp.access_token));
309
312
  return resp;
310
313
  }
311
- /** Attach a real email to the current user (and clear `email_pending`).
312
- * Used after a Telegram exchange to satisfy the email requirement; also
313
- * works for a password user changing their address. 409 if taken. */
314
+ /** Attach the first real email to a Telegram-made account (and clear
315
+ * `email_pending`). 409 if taken. An account that already has a real
316
+ * address gets 409 `email_change_needs_code`: change it with
317
+ * {@link requestEmailChange} and {@link confirmEmailChange}. */
314
318
  async linkEmail(input) {
315
319
  return this.http.post("/me/email", { body: { email: input.email } });
316
320
  }
321
+ /** Step one of an email change: a six-digit code goes to the new address
322
+ * and works for 5 minutes. Nothing changes yet.
323
+ * Errors: 400 `same_email`, 409 address taken, 429 `too_many_requests`
324
+ * (five codes an hour). */
325
+ async requestEmailChange(input) {
326
+ return this.http.post("/me/email/change", {
327
+ body: { email: input.email }
328
+ });
329
+ }
330
+ /** Step two: the code from the e-mail changes the address; the old one
331
+ * gets a notice. Errors: 401 `invalid_code` (after five wrong codes a new
332
+ * request is needed), 409 the address was taken meanwhile. */
333
+ async confirmEmailChange(input) {
334
+ return this.http.post("/me/email/change/confirm", {
335
+ body: { challenge_id: input.challengeId, code: input.code }
336
+ });
337
+ }
317
338
  /** Current user — fails 401 when the stored JWT is expired or
318
339
  * missing. Useful as a "do I have a session" probe on app boot. */
319
340
  async me() {
@@ -345,6 +366,7 @@ function cardRequestBody(input) {
345
366
  useBonus,
346
367
  bonusAmount,
347
368
  promoCode,
369
+ consentChannel,
348
370
  initial_amount: _ignored,
349
371
  ...rest
350
372
  } = input;
@@ -355,6 +377,7 @@ function cardRequestBody(input) {
355
377
  if (useBonus !== void 0) body["use_bonus"] = useBonus;
356
378
  if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
357
379
  if (promoCode !== void 0) body["promo_code"] = promoCode;
380
+ if (consentChannel !== void 0) body["consent_channel"] = consentChannel;
358
381
  return body;
359
382
  }
360
383
  var CardsResource = class {
@@ -473,9 +496,11 @@ var CardsResource = class {
473
496
  });
474
497
  }
475
498
  /**
476
- * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional
477
- * `reason` is recorded on the audit trail. Resolves to the updated card.
478
- * 404 if the card isn't the caller's; 501 if the issuer can't freeze.
499
+ * Freeze the caller's own card. Reversible via {@link unfreeze} while
500
+ * `status_source` is `holder` or `operator`. The optional `reason` is
501
+ * recorded on the audit trail. Resolves to the updated card. 404 if the
502
+ * card isn't the caller's; 409 `card_locked` when support holds it; 501 if
503
+ * the issuer can't freeze.
479
504
  */
480
505
  async freeze(id, reason) {
481
506
  return this.http.post(`/me/cards/${encodeURIComponent(id)}/freeze`, { body: { reason } });
@@ -490,16 +515,38 @@ var CardsResource = class {
490
515
  * keep the result in volatile memory only, never write it to
491
516
  * localStorage / logs, and clear it within `expires_in_seconds`.
492
517
  *
493
- * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector
494
- * has no sensitive-data endpoint · 503 provider error.
518
+ * The result is the numbers, or `reveal_url` with empty `pan` and `cvv`
519
+ * when the issuer shows them on a page of its own: open that page in a
520
+ * frame right away, it is short-lived.
521
+ *
522
+ * 403 not your card · 409 `card_locked` · 429 rate-limited · 501 connector
523
+ * has no sensitive-data endpoint · 503 `provider_unavailable`.
495
524
  */
496
525
  async reveal(id, _input) {
497
526
  return this.http.post(`/me/cards/${encodeURIComponent(id)}/reveal`);
498
527
  }
499
- /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */
528
+ /**
529
+ * Unfreeze a previously-frozen card. Idempotent on an already-active card.
530
+ * A card the issuer froze (`status_source: "provider"`) is not the
531
+ * holder's to unfreeze: the API answers 409 `card_locked`, so hide the
532
+ * button and say the freeze is lifted through the issuer's support.
533
+ */
500
534
  async unfreeze(id) {
501
535
  return this.http.post(`/me/cards/${encodeURIComponent(id)}/unfreeze`, { body: {} });
502
536
  }
537
+ /**
538
+ * Set the PIN of the caller's own physical card. The session is enough; the
539
+ * call is rate-limited like {@link reveal} and the PIN is kept nowhere.
540
+ * Resolves to the card; the user also gets a notification that the PIN
541
+ * was set. 400 not four to six digits or the card is not active · 403 not
542
+ * your card · 409 `card_locked`, or `provider_refused` when the issuer did
543
+ * not take it · 429 too many attempts · 501 a virtual card has no PIN.
544
+ */
545
+ async setPin(id, input) {
546
+ return this.http.post(`/me/cards/${encodeURIComponent(id)}/pin`, {
547
+ body: { pin: input.pin }
548
+ });
549
+ }
503
550
  /**
504
551
  * Terminate the caller's own card. **One-way** — a terminated card cannot be
505
552
  * reactivated. The optional `reason` is audited. Idempotent on an
@@ -529,7 +576,10 @@ var DepositsResource = class {
529
576
  * API answers 400 `no_quote_needed`).
530
577
  */
531
578
  async quote(input) {
532
- return this.http.post("/me/deposits/quotes", { body: input });
579
+ const { connectorSlug, ...rest } = input;
580
+ const body = { ...rest };
581
+ if (connectorSlug !== void 0) body["connector_slug"] = connectorSlug;
582
+ return this.http.post("/me/deposits/quotes", { body });
533
583
  }
534
584
  async initiate(input) {
535
585
  const { idempotencyKey, issue_card, ...rest } = input;
@@ -1048,6 +1098,44 @@ var AttributionResource = class {
1048
1098
  return this.http.put("/me/attribution/survey", { body });
1049
1099
  }
1050
1100
  };
1101
+ function tgWebApp() {
1102
+ return globalThis.Telegram?.WebApp?.initDataUnsafe;
1103
+ }
1104
+ function readCookie(name) {
1105
+ const doc = globalThis.document;
1106
+ if (!doc?.cookie) return void 0;
1107
+ for (const part of doc.cookie.split(";")) {
1108
+ const [k, ...v] = part.trim().split("=");
1109
+ if (k === name) return decodeURIComponent(v.join("="));
1110
+ }
1111
+ return void 0;
1112
+ }
1113
+ var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
1114
+ function anonymousKey(opts = {}) {
1115
+ const tgId = tgWebApp()?.user?.id;
1116
+ if (tgId) return `tg:${tgId}`;
1117
+ const g = globalThis;
1118
+ if (!g.document) return void 0;
1119
+ const name = opts.name ?? "takeal_anon";
1120
+ let stored;
1121
+ try {
1122
+ stored = g.localStorage?.getItem(name) ?? void 0;
1123
+ } catch {
1124
+ stored = void 0;
1125
+ }
1126
+ const fromCookie = readCookie(name);
1127
+ let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
1128
+ if (!key) {
1129
+ key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
1130
+ }
1131
+ try {
1132
+ g.localStorage?.setItem(name, key);
1133
+ } catch {
1134
+ }
1135
+ const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
1136
+ g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
1137
+ return key;
1138
+ }
1051
1139
 
1052
1140
  // src/resources/history.ts
1053
1141
  var HistoryResource = class {
@@ -1077,6 +1165,69 @@ var HistoryResource = class {
1077
1165
  }
1078
1166
  };
1079
1167
 
1168
+ // src/resources/consents.ts
1169
+ var ConsentsResource = class {
1170
+ constructor(http) {
1171
+ this.http = http;
1172
+ }
1173
+ /** Where each consent stands. */
1174
+ async get() {
1175
+ return this.http.get("/me/consents");
1176
+ }
1177
+ /**
1178
+ * Give (`true`) or withdraw (`false`) an optional consent: `marketing` or
1179
+ * `cookies_analytics`. Withdrawing `marketing` turns advertising off in
1180
+ * every channel at once; giving it turns on advertising by e-mail. A call
1181
+ * that changes nothing records nothing.
1182
+ *
1183
+ * Errors: 400 `consent_required` for `terms` or `personal_data`,
1184
+ * 400 `unknown_consent`.
1185
+ */
1186
+ async set(kind, given, channel) {
1187
+ const body = { kind, given };
1188
+ if (channel !== void 0) body.channel = channel;
1189
+ return this.http.post("/me/consents", { body });
1190
+ }
1191
+ /**
1192
+ * Record what the cookie banner or the cookie settings say about
1193
+ * analytics. Works signed in or not: before sign-in the choice is kept
1194
+ * under the anonymous key and moves to the account at sign-up (send the
1195
+ * same key in `register({ attribution })`). Declining deletes the
1196
+ * visitor's recorded visits and analytics ids and stops their conversions
1197
+ * going to Metrica. Call it on every change, not on every page load; the
1198
+ * same answer twice records nothing (`recorded: false`).
1199
+ *
1200
+ * Errors: 400 `invalid_anonymous_key` when not signed in and no key could
1201
+ * be found.
1202
+ */
1203
+ async setCookies(input) {
1204
+ const body = {
1205
+ analytics: input.analytics
1206
+ };
1207
+ const key = input.anonymousKey ?? anonymousKey();
1208
+ if (key !== void 0) body.anonymous_key = key;
1209
+ if (input.channel !== void 0) body.channel = input.channel;
1210
+ return this.http.post("/consents/cookies", { body });
1211
+ }
1212
+ };
1213
+
1214
+ // src/resources/receipts.ts
1215
+ var ReceiptsResource = class {
1216
+ constructor(http) {
1217
+ this.http = http;
1218
+ }
1219
+ async list(params = {}) {
1220
+ const q = new URLSearchParams();
1221
+ if (params.refId !== void 0) q.set("ref_id", params.refId);
1222
+ if (params.limit !== void 0) q.set("limit", String(params.limit));
1223
+ const qs = q.toString();
1224
+ return this.http.get(`/me/receipts${qs ? `?${qs}` : ""}`);
1225
+ }
1226
+ async get(id) {
1227
+ return this.http.get(`/me/receipts/${encodeURIComponent(id)}`);
1228
+ }
1229
+ };
1230
+
1080
1231
  // src/resources/funding-options.ts
1081
1232
  var FundingOptionsResource = class {
1082
1233
  constructor(http) {
@@ -1089,7 +1240,7 @@ var FundingOptionsResource = class {
1089
1240
  };
1090
1241
 
1091
1242
  // src/version.ts
1092
- var SDK_VERSION = "0.6.0";
1243
+ var SDK_VERSION = "0.6.2";
1093
1244
 
1094
1245
  // src/client-platform.ts
1095
1246
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1164,7 +1315,7 @@ function isAbsolute(url) {
1164
1315
  }
1165
1316
 
1166
1317
  // src/compat.ts
1167
- var SUPPORTED_MEISTER = ">=0.5.0, <0.7.0";
1318
+ var SUPPORTED_MEISTER = ">=0.6.7, <0.7.0";
1168
1319
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1169
1320
  function parse(v) {
1170
1321
  const m = SEMVER.exec(v.trim());
@@ -1273,7 +1424,9 @@ function createClient(opts) {
1273
1424
  notifications: new NotificationsResource(http),
1274
1425
  devices: new DevicesResource(http, client),
1275
1426
  attribution: new AttributionResource(http),
1276
- history: new HistoryResource(http)
1427
+ history: new HistoryResource(http),
1428
+ consents: new ConsentsResource(http),
1429
+ receipts: new ReceiptsResource(http)
1277
1430
  };
1278
1431
  }
1279
1432
  function pickDefaultStore(key) {