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