@takeal/cusfront-sdk 0.6.1 → 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 (55) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +55 -0
  3. package/dist/{cards-qfHz6xZY.d.cts → cards-DU2DdhYO.d.cts} +10 -0
  4. package/dist/{cards-CF3-He2x.d.ts → cards-DzhPVA9N.d.ts} +10 -0
  5. package/dist/{deposits-ZjT_btgi.d.cts → deposits-BEkNeE-v.d.cts} +1 -1
  6. package/dist/{deposits-B2LBe2k1.d.ts → deposits-Dt6A76MB.d.ts} +1 -1
  7. package/dist/index.cjs +95 -7
  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 +95 -7
  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 +2 -0
  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 +2 -0
  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 +2 -0
  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 +2 -0
  38. package/dist/resources/deposits.js.map +1 -1
  39. package/dist/resources/funding-options.d.cts +3 -2
  40. package/dist/resources/funding-options.d.ts +3 -2
  41. package/dist/resources/me.d.cts +1 -0
  42. package/dist/resources/me.d.ts +1 -0
  43. package/dist/resources/receipts.cjs +22 -0
  44. package/dist/resources/receipts.cjs.map +1 -0
  45. package/dist/resources/receipts.d.cts +51 -0
  46. package/dist/resources/receipts.d.ts +51 -0
  47. package/dist/resources/receipts.js +20 -0
  48. package/dist/resources/receipts.js.map +1 -0
  49. package/dist/telegram.cjs +133 -7
  50. package/dist/telegram.cjs.map +1 -1
  51. package/dist/telegram.d.cts +4 -2
  52. package/dist/telegram.d.ts +4 -2
  53. package/dist/telegram.js +133 -7
  54. package/dist/telegram.js.map +1 -1
  55. 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 {
@@ -1075,6 +1098,44 @@ var AttributionResource = class {
1075
1098
  return this.http.put("/me/attribution/survey", { body });
1076
1099
  }
1077
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
+ }
1078
1139
 
1079
1140
  // src/resources/history.ts
1080
1141
  var HistoryResource = class {
@@ -1104,6 +1165,69 @@ var HistoryResource = class {
1104
1165
  }
1105
1166
  };
1106
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
+
1107
1231
  // src/resources/funding-options.ts
1108
1232
  var FundingOptionsResource = class {
1109
1233
  constructor(http) {
@@ -1116,7 +1240,7 @@ var FundingOptionsResource = class {
1116
1240
  };
1117
1241
 
1118
1242
  // src/version.ts
1119
- var SDK_VERSION = "0.6.1";
1243
+ var SDK_VERSION = "0.6.2";
1120
1244
 
1121
1245
  // src/client-platform.ts
1122
1246
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1191,7 +1315,7 @@ function isAbsolute(url) {
1191
1315
  }
1192
1316
 
1193
1317
  // src/compat.ts
1194
- var SUPPORTED_MEISTER = ">=0.6.4, <0.7.0";
1318
+ var SUPPORTED_MEISTER = ">=0.6.7, <0.7.0";
1195
1319
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1196
1320
  function parse(v) {
1197
1321
  const m = SEMVER.exec(v.trim());
@@ -1300,7 +1424,9 @@ function createClient(opts) {
1300
1424
  notifications: new NotificationsResource(http),
1301
1425
  devices: new DevicesResource(http, client),
1302
1426
  attribution: new AttributionResource(http),
1303
- history: new HistoryResource(http)
1427
+ history: new HistoryResource(http),
1428
+ consents: new ConsentsResource(http),
1429
+ receipts: new ReceiptsResource(http)
1304
1430
  };
1305
1431
  }
1306
1432
  function pickDefaultStore(key) {