@takeal/cusfront-sdk 0.6.8 → 0.6.14

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 (59) hide show
  1. package/CHANGELOG.md +112 -2
  2. package/README.md +26 -9
  3. package/dist/analytics.cjs +44 -6
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.js +44 -6
  6. package/dist/analytics.js.map +1 -1
  7. package/dist/{cards-BgY00UpU.d.ts → cards-DPlgx76p.d.ts} +86 -18
  8. package/dist/{cards-DGz4Rqu1.d.cts → cards-D_krTWzr.d.cts} +86 -18
  9. package/dist/index.cjs +225 -93
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +5 -5
  12. package/dist/index.d.ts +5 -5
  13. package/dist/index.js +221 -94
  14. package/dist/index.js.map +1 -1
  15. package/dist/react/index.d.cts +1 -1
  16. package/dist/react/index.d.ts +1 -1
  17. package/dist/resources/attribution.cjs +99 -4
  18. package/dist/resources/attribution.cjs.map +1 -1
  19. package/dist/resources/attribution.d.cts +58 -1
  20. package/dist/resources/attribution.d.ts +58 -1
  21. package/dist/resources/attribution.js +96 -5
  22. package/dist/resources/attribution.js.map +1 -1
  23. package/dist/resources/auth.cjs +64 -3
  24. package/dist/resources/auth.cjs.map +1 -1
  25. package/dist/resources/auth.d.cts +1 -1
  26. package/dist/resources/auth.d.ts +1 -1
  27. package/dist/resources/auth.js +64 -3
  28. package/dist/resources/auth.js.map +1 -1
  29. package/dist/resources/cards.cjs +69 -7
  30. package/dist/resources/cards.cjs.map +1 -1
  31. package/dist/resources/cards.d.cts +2 -1
  32. package/dist/resources/cards.d.ts +2 -1
  33. package/dist/resources/cards.js +69 -8
  34. package/dist/resources/cards.js.map +1 -1
  35. package/dist/resources/codes.cjs.map +1 -1
  36. package/dist/resources/codes.d.cts +21 -1
  37. package/dist/resources/codes.d.ts +21 -1
  38. package/dist/resources/codes.js.map +1 -1
  39. package/dist/resources/consents.cjs +15 -0
  40. package/dist/resources/consents.cjs.map +1 -1
  41. package/dist/resources/consents.js +15 -0
  42. package/dist/resources/consents.js.map +1 -1
  43. package/dist/resources/deposits.cjs +50 -0
  44. package/dist/resources/deposits.cjs.map +1 -1
  45. package/dist/resources/deposits.d.cts +2 -1
  46. package/dist/resources/deposits.d.ts +2 -1
  47. package/dist/resources/deposits.js +50 -0
  48. package/dist/resources/deposits.js.map +1 -1
  49. package/dist/resources/funding-options.d.cts +2 -1
  50. package/dist/resources/funding-options.d.ts +2 -1
  51. package/dist/resources/me.d.cts +1 -1
  52. package/dist/resources/me.d.ts +1 -1
  53. package/dist/telegram.cjs +224 -73
  54. package/dist/telegram.cjs.map +1 -1
  55. package/dist/telegram.d.cts +34 -3
  56. package/dist/telegram.d.ts +34 -3
  57. package/dist/telegram.js +224 -74
  58. package/dist/telegram.js.map +1 -1
  59. package/package.json +4 -4
@@ -1,9 +1,10 @@
1
1
  import { CusfrontClient, CreateClientOptions } from './index.cjs';
2
2
  import { JwtIssued, TelegramUnknown } from './resources/auth.cjs';
3
3
  import './http-CL97TjMO.cjs';
4
- import './cards-DGz4Rqu1.cjs';
4
+ import './cards-D_krTWzr.cjs';
5
5
  import './resources/claims.cjs';
6
6
  import './resources/consents.cjs';
7
+ import './resources/attribution.cjs';
7
8
  import './resources/balance.cjs';
8
9
  import './resources/bonus.cjs';
9
10
  import './resources/debt.cjs';
@@ -21,7 +22,6 @@ import './resources/push.cjs';
21
22
  import './resources/me.cjs';
22
23
  import './resources/notifications.cjs';
23
24
  import './devices-CiJrlXum.cjs';
24
- import './resources/attribution.cjs';
25
25
  import './resources/history.cjs';
26
26
  import './resources/receipts.cjs';
27
27
  import './resources/support.cjs';
@@ -89,6 +89,37 @@ interface WellFormedOptions {
89
89
  * `user`, and (optionally) not stale. Throws {@link InitDataError}. Does NOT
90
90
  * verify the HMAC — only the server can. */
91
91
  declare function assertWellFormed(initData: string, opts?: WellFormedOptions): ParsedInitData;
92
+ /** What can be logged about an `initData` value without logging it: no
93
+ * values, no signatures, no user fields. Built by {@link describeInitData}. */
94
+ interface InitDataDiagnostics {
95
+ /** `typeof` of what was received (`"string"` for anything usable). */
96
+ type: string;
97
+ /** Length of the string, 0 for anything else. */
98
+ length: number;
99
+ /** Names of the fields present, sorted. Values are left out. */
100
+ fields: string[];
101
+ hasHash: boolean;
102
+ hasSignature: boolean;
103
+ /** `auth_date` is present and a unix timestamp. */
104
+ hasAuthDate: boolean;
105
+ /** Seconds since `auth_date`, when it parses. Negative means a clock ahead. */
106
+ authDateAgeSeconds?: number;
107
+ /** `user` is present and its `id` is a number. */
108
+ hasUserId: boolean;
109
+ /** Why {@link assertWellFormed} would refuse it, or `null` when it would not.
110
+ * `"not_a_string"` when the value is not a string at all. */
111
+ reason: InitDataError["reason"] | "not_a_string" | null;
112
+ }
113
+ /**
114
+ * Describe an `initData` value for a log line, without the value itself.
115
+ * Use it where the payload is refused, so the log says which check failed:
116
+ *
117
+ * console.warn("telegram sign-in refused", describeInitData(body.initData));
118
+ *
119
+ * The signature is checked only by the server; a payload this reports as
120
+ * well formed can still be refused there, with the reason in the 401.
121
+ */
122
+ declare function describeInitData(initData: unknown, opts?: WellFormedOptions): InitDataDiagnostics;
92
123
  interface FromInitDataOptions extends WellFormedOptions {
93
124
  /** Skip the client-side well-formedness check and let the server be the
94
125
  * sole judge. Default false — the fail-fast check saves a round-trip on
@@ -172,4 +203,4 @@ declare function fromTelegramWebApp(config: CreateClientOptions, opts?: FromInit
172
203
  * when you need the envelope rather than just the client. */
173
204
  type TelegramExchangeSession = JwtIssued;
174
205
 
175
- export { type FromInitDataOptions, InitDataError, type InitDataExchange, type ParsedInitData, type TelegramExchangeSession, TelegramUnknownError, type TelegramUser, type WellFormedOptions, assertWellFormed, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
206
+ export { type FromInitDataOptions, type InitDataDiagnostics, InitDataError, type InitDataExchange, type ParsedInitData, type TelegramExchangeSession, TelegramUnknownError, type TelegramUser, type WellFormedOptions, assertWellFormed, describeInitData, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
@@ -1,9 +1,10 @@
1
1
  import { CusfrontClient, CreateClientOptions } from './index.js';
2
2
  import { JwtIssued, TelegramUnknown } from './resources/auth.js';
3
3
  import './http-CL97TjMO.js';
4
- import './cards-BgY00UpU.js';
4
+ import './cards-DPlgx76p.js';
5
5
  import './resources/claims.js';
6
6
  import './resources/consents.js';
7
+ import './resources/attribution.js';
7
8
  import './resources/balance.js';
8
9
  import './resources/bonus.js';
9
10
  import './resources/debt.js';
@@ -21,7 +22,6 @@ import './resources/push.js';
21
22
  import './resources/me.js';
22
23
  import './resources/notifications.js';
23
24
  import './devices-C88c38hm.js';
24
- import './resources/attribution.js';
25
25
  import './resources/history.js';
26
26
  import './resources/receipts.js';
27
27
  import './resources/support.js';
@@ -89,6 +89,37 @@ interface WellFormedOptions {
89
89
  * `user`, and (optionally) not stale. Throws {@link InitDataError}. Does NOT
90
90
  * verify the HMAC — only the server can. */
91
91
  declare function assertWellFormed(initData: string, opts?: WellFormedOptions): ParsedInitData;
92
+ /** What can be logged about an `initData` value without logging it: no
93
+ * values, no signatures, no user fields. Built by {@link describeInitData}. */
94
+ interface InitDataDiagnostics {
95
+ /** `typeof` of what was received (`"string"` for anything usable). */
96
+ type: string;
97
+ /** Length of the string, 0 for anything else. */
98
+ length: number;
99
+ /** Names of the fields present, sorted. Values are left out. */
100
+ fields: string[];
101
+ hasHash: boolean;
102
+ hasSignature: boolean;
103
+ /** `auth_date` is present and a unix timestamp. */
104
+ hasAuthDate: boolean;
105
+ /** Seconds since `auth_date`, when it parses. Negative means a clock ahead. */
106
+ authDateAgeSeconds?: number;
107
+ /** `user` is present and its `id` is a number. */
108
+ hasUserId: boolean;
109
+ /** Why {@link assertWellFormed} would refuse it, or `null` when it would not.
110
+ * `"not_a_string"` when the value is not a string at all. */
111
+ reason: InitDataError["reason"] | "not_a_string" | null;
112
+ }
113
+ /**
114
+ * Describe an `initData` value for a log line, without the value itself.
115
+ * Use it where the payload is refused, so the log says which check failed:
116
+ *
117
+ * console.warn("telegram sign-in refused", describeInitData(body.initData));
118
+ *
119
+ * The signature is checked only by the server; a payload this reports as
120
+ * well formed can still be refused there, with the reason in the 401.
121
+ */
122
+ declare function describeInitData(initData: unknown, opts?: WellFormedOptions): InitDataDiagnostics;
92
123
  interface FromInitDataOptions extends WellFormedOptions {
93
124
  /** Skip the client-side well-formedness check and let the server be the
94
125
  * sole judge. Default false — the fail-fast check saves a round-trip on
@@ -172,4 +203,4 @@ declare function fromTelegramWebApp(config: CreateClientOptions, opts?: FromInit
172
203
  * when you need the envelope rather than just the client. */
173
204
  type TelegramExchangeSession = JwtIssued;
174
205
 
175
- export { type FromInitDataOptions, InitDataError, type InitDataExchange, type ParsedInitData, type TelegramExchangeSession, TelegramUnknownError, type TelegramUser, type WellFormedOptions, assertWellFormed, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
206
+ export { type FromInitDataOptions, type InitDataDiagnostics, InitDataError, type InitDataExchange, type ParsedInitData, type TelegramExchangeSession, TelegramUnknownError, type TelegramUser, type WellFormedOptions, assertWellFormed, describeInitData, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
package/dist/telegram.js CHANGED
@@ -142,6 +142,150 @@ async function parseResponse(resp) {
142
142
  return body;
143
143
  }
144
144
 
145
+ // src/resources/attribution.ts
146
+ var AttributionResource = class {
147
+ constructor(http) {
148
+ this.http = http;
149
+ }
150
+ /** Record a visit. No session needed; safe to call on every page load. */
151
+ async touch(input) {
152
+ return this.http.post("/attribution/touches", { body: input, skipAuth: true });
153
+ }
154
+ /** A one-day token that carries the visitor's analytics ids into the
155
+ * Telegram Mini App, whose sign-in reads it back. Most callers want
156
+ * {@link AttributionResource.telegramStartParam}. Errors: 400 when none of
157
+ * the ids is valid. */
158
+ async handoff(ids) {
159
+ return this.http.post("/attribution/handoff", { body: ids, skipAuth: true });
160
+ }
161
+ /**
162
+ * The `startapp` value for a link from the site to the Mini App: the code
163
+ * as it is, followed by `__<token>` when the visitor has analytics ids, so
164
+ * a payment made in Telegram is still credited to the visit it came from.
165
+ * Without ids, or when the token can't be had, just the code.
166
+ *
167
+ * ```ts
168
+ * const start = await client.attribution.telegramStartParam("SPRING");
169
+ * location.href = `https://t.me/our_bot/app?startapp=${start}`;
170
+ * ```
171
+ */
172
+ async telegramStartParam(code = "") {
173
+ const ids = analyticsIds();
174
+ if (!ids) return code;
175
+ try {
176
+ const { token } = await this.handoff(ids);
177
+ return `${code}__${token}`;
178
+ } catch {
179
+ return code;
180
+ }
181
+ }
182
+ /** Send the visitor's analytics ids for the signed-in account, e.g. right
183
+ * after they agreed to analytics cookies in the cabinet. Without an
184
+ * argument the ids this browser holds are sent; nothing is sent when it
185
+ * holds none. */
186
+ async sendAnalyticsIds(ids = analyticsIds()) {
187
+ if (!ids) return;
188
+ await this.http.post("/me/analytics/ids", { body: ids });
189
+ }
190
+ /** Whether to ask the signed-in user how they heard about us. */
191
+ async status() {
192
+ return this.http.get("/me/attribution");
193
+ }
194
+ /** Answer the question once. Send `"skipped"` when the user closes it.
195
+ * `otherText` is kept only with `"other"`, up to 500 characters.
196
+ * Errors: 400 `validation`, 409 `survey_answered`. */
197
+ async answerSurvey(answer, otherText) {
198
+ const body = { answer };
199
+ if (otherText !== void 0) body.other_text = otherText;
200
+ return this.http.put("/me/attribution/survey", { body });
201
+ }
202
+ };
203
+ function tgWebApp() {
204
+ return globalThis.Telegram?.WebApp?.initDataUnsafe;
205
+ }
206
+ function readCookie(name) {
207
+ const doc = globalThis.document;
208
+ if (!doc?.cookie) return void 0;
209
+ for (const part of doc.cookie.split(";")) {
210
+ const [k, ...v] = part.trim().split("=");
211
+ if (k === name) return decodeURIComponent(v.join("="));
212
+ }
213
+ return void 0;
214
+ }
215
+ var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
216
+ function anonymousKey(opts = {}) {
217
+ const tgId = tgWebApp()?.user?.id;
218
+ if (tgId) return `tg:${tgId}`;
219
+ const g = globalThis;
220
+ if (!g.document) return void 0;
221
+ const name = opts.name ?? "takeal_anon";
222
+ let stored2;
223
+ try {
224
+ stored2 = g.localStorage?.getItem(name) ?? void 0;
225
+ } catch {
226
+ stored2 = void 0;
227
+ }
228
+ const fromCookie = readCookie(name);
229
+ let key = [fromCookie, stored2].find((k) => !!k && KEY_SHAPE.test(k));
230
+ if (!key) {
231
+ key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
232
+ }
233
+ try {
234
+ g.localStorage?.setItem(name, key);
235
+ } catch {
236
+ }
237
+ const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
238
+ g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
239
+ return key;
240
+ }
241
+ var IDS_KEY = "takeal_analytics_ids";
242
+ function storage() {
243
+ try {
244
+ return globalThis.localStorage;
245
+ } catch {
246
+ return void 0;
247
+ }
248
+ }
249
+ function stored() {
250
+ try {
251
+ const raw = storage()?.getItem(IDS_KEY);
252
+ const v = raw ? JSON.parse(raw) : {};
253
+ return typeof v === "object" && v !== null ? v : {};
254
+ } catch {
255
+ return {};
256
+ }
257
+ }
258
+ function clean(ids) {
259
+ const out = {};
260
+ const ym = ids.metrika_client_id?.trim();
261
+ if (ym && /^\d{1,32}$/.test(ym)) out.metrika_client_id = ym;
262
+ const ga = ids.ga_client_id?.trim();
263
+ if (ga && /^\d+\.\d+$/.test(ga) && ga.length <= 64) out.ga_client_id = ga;
264
+ return out.metrika_client_id || out.ga_client_id ? out : void 0;
265
+ }
266
+ function forgetAnalyticsIds() {
267
+ try {
268
+ storage()?.removeItem(IDS_KEY);
269
+ } catch {
270
+ }
271
+ }
272
+ function analyticsIds() {
273
+ const kept = stored();
274
+ return clean({
275
+ metrika_client_id: kept.metrika_client_id ?? readCookie("_ym_uid"),
276
+ ga_client_id: kept.ga_client_id ?? readCookie("_ga")?.split(".").slice(-2).join(".")
277
+ });
278
+ }
279
+ function withAnalyticsIds(attribution) {
280
+ const ids = analyticsIds();
281
+ if (!ids) return attribution;
282
+ return {
283
+ ...attribution,
284
+ metrika_client_id: attribution?.metrika_client_id ?? ids.metrika_client_id,
285
+ ga_client_id: attribution?.ga_client_id ?? ids.ga_client_id
286
+ };
287
+ }
288
+
145
289
  // src/resources/cards.ts
146
290
  function cardRequestBody(input) {
147
291
  const {
@@ -180,8 +324,15 @@ function cardOrderBody(input) {
180
324
  if (input.consents !== void 0) body["consents"] = input.consents;
181
325
  if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
182
326
  if (input.metadata !== void 0) body["metadata"] = input.metadata;
327
+ const ids = input.analyticsIds ?? analyticsIds();
328
+ if (ids !== void 0) body["analytics_ids"] = ids;
183
329
  return body;
184
330
  }
331
+ function revealState(r) {
332
+ if (r.details_pending) return "pending";
333
+ if (r.reveal_url) return "page";
334
+ return "numbers";
335
+ }
185
336
  var CardsResource = class {
186
337
  constructor(http) {
187
338
  this.http = http;
@@ -209,8 +360,10 @@ var CardsResource = class {
209
360
  * `idempotencyKey` returns the same order.
210
361
  * Errors: 400 `unknown_product` / `method_not_available` / a limit of the
211
362
  * way of paying, 409 `holder_data_consent_required` (the product has
212
- * `holder_data_required` and the user has not agreed to it), 503 no
213
- * funding connector or no exchange rate.
363
+ * `holder_data_required` and the user has not agreed to it), 409
364
+ * `payments_on_hold` (a payment on this account was not accepted and new
365
+ * ones wait until support sorts it out: show the message and point the
366
+ * user to support), 503 no funding connector or no exchange rate.
214
367
  */
215
368
  async order(input) {
216
369
  const { idempotencyKey, ...order } = input;
@@ -224,7 +377,9 @@ var CardsResource = class {
224
377
  * (`is_default` marks the one issued when none is chosen). Each item
225
378
  * carries its product card (name, tagline, benefits, tile picture),
226
379
  * artwork, and the issuance price after the caller's subscription
227
- * discount, in the caller's wallet currency. Pass an item's `id` as
380
+ * discount, in the currency the operator set it in (`price.from_wallet`
381
+ * is the same price from the wallet, when that holds another currency).
382
+ * Pass an item's `id` as
228
383
  * `productId` to {@link create}.
229
384
  */
230
385
  async listProducts() {
@@ -337,15 +492,22 @@ var CardsResource = class {
337
492
  * keep the result in volatile memory only, never write it to
338
493
  * localStorage / logs, and clear it within `expires_in_seconds`.
339
494
  *
340
- * The result is the numbers, or `reveal_url` with empty `pan` and `cvv`
341
- * when the issuer shows them on a page of its own: open that page in a
342
- * frame right away, it is short-lived.
495
+ * `state` tells the three answers apart: `numbers`; `page`, with
496
+ * `reveal_url` and empty `pan` and `cvv` when the issuer shows them on a
497
+ * page of its own (open that page in a frame right away, it is
498
+ * short-lived); or `pending` while the card's details are still being
499
+ * prepared, which doesn't count against the limit. A card says the same
500
+ * in {@link Card.details_pending}, so there is no need to call this just
501
+ * to find out.
343
502
  *
344
503
  * 403 not your card · 409 `card_locked` · 429 rate-limited · 501 connector
345
504
  * has no sensitive-data endpoint · 503 `provider_unavailable`.
346
505
  */
347
506
  async reveal(id, _input) {
348
- return this.http.post(`/me/cards/${encodeURIComponent(id)}/reveal`);
507
+ const r = await this.http.post(
508
+ `/me/cards/${encodeURIComponent(id)}/reveal`
509
+ );
510
+ return { ...r, state: revealState(r) };
349
511
  }
350
512
  /**
351
513
  * Unfreeze a previously-frozen card. Idempotent on an already-active card.
@@ -462,8 +624,11 @@ var AuthResource = class {
462
624
  /** Password-auth entry. May resolve to a JWT, or to a step-up
463
625
  * challenge that needs `verifyTotp` / `verifyOtp` next. */
464
626
  async login(input) {
627
+ const body = withRemember(input);
628
+ const attribution = withAnalyticsIds(void 0);
629
+ if (attribution !== void 0) body["attribution"] = attribution;
465
630
  const resp = await this.http.post("/auth/login", {
466
- body: withRemember(input),
631
+ body,
467
632
  skipAuth: true
468
633
  });
469
634
  if (resp.stage === "jwt") {
@@ -500,6 +665,8 @@ var AuthResource = class {
500
665
  async register(input) {
501
666
  const { cardOrder, ...rest } = input;
502
667
  const body = withRemember(rest);
668
+ const attribution = withAnalyticsIds(rest.attribution);
669
+ if (attribution !== void 0) body["attribution"] = attribution;
503
670
  if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
504
671
  const resp = await this.http.post("/auth/register", {
505
672
  body,
@@ -535,7 +702,8 @@ var AuthResource = class {
535
702
  };
536
703
  if (input.remember) body["remember_me"] = true;
537
704
  if (input.walletCurrency !== void 0) body["wallet_currency"] = input.walletCurrency;
538
- if (input.attribution !== void 0) body["attribution"] = input.attribution;
705
+ const attribution = withAnalyticsIds(input.attribution);
706
+ if (attribution !== void 0) body["attribution"] = attribution;
539
707
  if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
540
708
  if (input.consents !== void 0) body["consents"] = input.consents;
541
709
  if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
@@ -581,7 +749,8 @@ var AuthResource = class {
581
749
  init_data: input.initData
582
750
  };
583
751
  if (input.provision !== void 0) body.provision = input.provision;
584
- if (input.attribution !== void 0) body.attribution = input.attribution;
752
+ const attribution = withAnalyticsIds(input.attribution);
753
+ if (attribution !== void 0) body.attribution = attribution;
585
754
  if (input.code !== void 0) body.code = input.code;
586
755
  if (input.consents !== void 0) body.consents = input.consents;
587
756
  if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
@@ -687,10 +856,17 @@ var DepositsResource = class {
687
856
  if (connectorSlug !== void 0) body["connector_slug"] = connectorSlug;
688
857
  return this.http.post("/me/deposits/quotes", { body });
689
858
  }
859
+ /**
860
+ * Start a top-up. 409 `payments_on_hold`: a payment on this account was
861
+ * not accepted and new ones wait until support sorts it out. Show the
862
+ * message as it comes and point the user to support.
863
+ */
690
864
  async initiate(input) {
691
865
  const { idempotencyKey, issue_card, ...rest } = input;
692
866
  const body = { ...rest };
693
867
  if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
868
+ const ids = input.analytics_ids ?? analyticsIds();
869
+ if (ids !== void 0) body["analytics_ids"] = ids;
694
870
  return this.http.post("/me/deposits", {
695
871
  body,
696
872
  idempotencyKey
@@ -1292,67 +1468,6 @@ var DevicesResource = class {
1292
1468
  }
1293
1469
  };
1294
1470
 
1295
- // src/resources/attribution.ts
1296
- var AttributionResource = class {
1297
- constructor(http) {
1298
- this.http = http;
1299
- }
1300
- /** Record a visit. No session needed; safe to call on every page load. */
1301
- async touch(input) {
1302
- return this.http.post("/attribution/touches", { body: input, skipAuth: true });
1303
- }
1304
- /** Whether to ask the signed-in user how they heard about us. */
1305
- async status() {
1306
- return this.http.get("/me/attribution");
1307
- }
1308
- /** Answer the question once. Send `"skipped"` when the user closes it.
1309
- * `otherText` is kept only with `"other"`, up to 500 characters.
1310
- * Errors: 400 `validation`, 409 `survey_answered`. */
1311
- async answerSurvey(answer, otherText) {
1312
- const body = { answer };
1313
- if (otherText !== void 0) body.other_text = otherText;
1314
- return this.http.put("/me/attribution/survey", { body });
1315
- }
1316
- };
1317
- function tgWebApp() {
1318
- return globalThis.Telegram?.WebApp?.initDataUnsafe;
1319
- }
1320
- function readCookie(name) {
1321
- const doc = globalThis.document;
1322
- if (!doc?.cookie) return void 0;
1323
- for (const part of doc.cookie.split(";")) {
1324
- const [k, ...v] = part.trim().split("=");
1325
- if (k === name) return decodeURIComponent(v.join("="));
1326
- }
1327
- return void 0;
1328
- }
1329
- var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
1330
- function anonymousKey(opts = {}) {
1331
- const tgId = tgWebApp()?.user?.id;
1332
- if (tgId) return `tg:${tgId}`;
1333
- const g = globalThis;
1334
- if (!g.document) return void 0;
1335
- const name = opts.name ?? "takeal_anon";
1336
- let stored;
1337
- try {
1338
- stored = g.localStorage?.getItem(name) ?? void 0;
1339
- } catch {
1340
- stored = void 0;
1341
- }
1342
- const fromCookie = readCookie(name);
1343
- let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
1344
- if (!key) {
1345
- key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
1346
- }
1347
- try {
1348
- g.localStorage?.setItem(name, key);
1349
- } catch {
1350
- }
1351
- const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
1352
- g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
1353
- return key;
1354
- }
1355
-
1356
1471
  // src/resources/history.ts
1357
1472
  var HistoryResource = class {
1358
1473
  constructor(http) {
@@ -1456,6 +1571,7 @@ var ConsentsResource = class {
1456
1571
  const key = input.anonymousKey ?? anonymousKey();
1457
1572
  if (key !== void 0) body.anonymous_key = key;
1458
1573
  if (input.channel !== void 0) body.channel = input.channel;
1574
+ if (!input.analytics) forgetAnalyticsIds();
1459
1575
  return this.http.post("/consents/cookies", { body });
1460
1576
  }
1461
1577
  };
@@ -1553,7 +1669,7 @@ var FundingOptionsResource = class {
1553
1669
  };
1554
1670
 
1555
1671
  // src/version.ts
1556
- var SDK_VERSION = "0.6.8";
1672
+ var SDK_VERSION = "0.6.14";
1557
1673
 
1558
1674
  // src/client-platform.ts
1559
1675
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1628,7 +1744,7 @@ function isAbsolute(url) {
1628
1744
  }
1629
1745
 
1630
1746
  // src/compat.ts
1631
- var SUPPORTED_MEISTER = ">=0.6.13, <1.0.0";
1747
+ var SUPPORTED_MEISTER = ">=0.7.6, <1.0.0";
1632
1748
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1633
1749
  function parse(v) {
1634
1750
  const m = SEMVER.exec(v.trim());
@@ -1811,6 +1927,40 @@ function assertWellFormed(initData, opts = {}) {
1811
1927
  }
1812
1928
  return parsed;
1813
1929
  }
1930
+ function describeInitData(initData, opts = {}) {
1931
+ if (typeof initData !== "string") {
1932
+ return {
1933
+ type: typeof initData,
1934
+ length: 0,
1935
+ fields: [],
1936
+ hasHash: false,
1937
+ hasSignature: false,
1938
+ hasAuthDate: false,
1939
+ hasUserId: false,
1940
+ reason: "not_a_string"
1941
+ };
1942
+ }
1943
+ const parsed = parseInitData(initData);
1944
+ const now = opts.nowUnix ?? Math.floor(Date.now() / 1e3);
1945
+ let reason = null;
1946
+ try {
1947
+ assertWellFormed(initData, opts);
1948
+ } catch (e) {
1949
+ if (e instanceof InitDataError) reason = e.reason;
1950
+ else throw e;
1951
+ }
1952
+ return {
1953
+ type: "string",
1954
+ length: initData.length,
1955
+ fields: Object.keys(parsed.params).sort(),
1956
+ hasHash: parsed.hash !== void 0,
1957
+ hasSignature: typeof parsed.params.signature === "string" && parsed.params.signature !== "",
1958
+ hasAuthDate: parsed.auth_date !== void 0,
1959
+ ...parsed.auth_date !== void 0 ? { authDateAgeSeconds: now - parsed.auth_date } : {},
1960
+ hasUserId: typeof parsed.user?.id === "number",
1961
+ reason
1962
+ };
1963
+ }
1814
1964
  var TelegramUnknownError = class extends Error {
1815
1965
  constructor(initData) {
1816
1966
  super("this Telegram account is not linked to any user (provision: false)");
@@ -1869,6 +2019,6 @@ async function fromTelegramWebApp(config, opts = {}) {
1869
2019
  return fromInitData(initData, config, opts);
1870
2020
  }
1871
2021
 
1872
- export { InitDataError, TelegramUnknownError, assertWellFormed, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
2022
+ export { InitDataError, TelegramUnknownError, assertWellFormed, describeInitData, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
1873
2023
  //# sourceMappingURL=telegram.js.map
1874
2024
  //# sourceMappingURL=telegram.js.map