@takeal/cusfront-sdk 0.6.11 → 0.8.0

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 +97 -0
  2. package/README.md +54 -2
  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-nXmDP0ei.d.cts → cards-BPu8Ill7.d.cts} +159 -12
  8. package/dist/{cards-CuUdrQ0H.d.ts → cards-DP1fJc_c.d.ts} +159 -12
  9. package/dist/index.cjs +261 -89
  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 +257 -90
  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 +66 -3
  24. package/dist/resources/auth.cjs.map +1 -1
  25. package/dist/resources/auth.d.cts +7 -2
  26. package/dist/resources/auth.d.ts +7 -2
  27. package/dist/resources/auth.js +66 -3
  28. package/dist/resources/auth.js.map +1 -1
  29. package/dist/resources/cards.cjs +111 -3
  30. package/dist/resources/cards.cjs.map +1 -1
  31. package/dist/resources/cards.d.cts +3 -1
  32. package/dist/resources/cards.d.ts +3 -1
  33. package/dist/resources/cards.js +110 -4
  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 +3 -1
  46. package/dist/resources/deposits.d.ts +3 -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 +3 -1
  50. package/dist/resources/funding-options.d.ts +3 -1
  51. package/dist/resources/me.d.cts +1 -1
  52. package/dist/resources/me.d.ts +1 -1
  53. package/dist/telegram.cjs +253 -69
  54. package/dist/telegram.cjs.map +1 -1
  55. package/dist/telegram.d.cts +35 -4
  56. package/dist/telegram.d.ts +35 -4
  57. package/dist/telegram.js +253 -70
  58. package/dist/telegram.js.map +1 -1
  59. package/package.json +1 -1
@@ -1,14 +1,15 @@
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-nXmDP0ei.cjs';
4
+ import './cards-BPu8Ill7.cjs';
5
5
  import './resources/claims.cjs';
6
+ import './resources/codes.cjs';
6
7
  import './resources/consents.cjs';
8
+ import './resources/attribution.cjs';
7
9
  import './resources/balance.cjs';
8
10
  import './resources/bonus.cjs';
9
11
  import './resources/debt.cjs';
10
12
  import './resources/close-requests.cjs';
11
- import './resources/codes.cjs';
12
13
  import './resources/referral.cjs';
13
14
  import './resources/subscription.cjs';
14
15
  import './resources/branding.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,14 +1,15 @@
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-CuUdrQ0H.js';
4
+ import './cards-DP1fJc_c.js';
5
5
  import './resources/claims.js';
6
+ import './resources/codes.js';
6
7
  import './resources/consents.js';
8
+ import './resources/attribution.js';
7
9
  import './resources/balance.js';
8
10
  import './resources/bonus.js';
9
11
  import './resources/debt.js';
10
12
  import './resources/close-requests.js';
11
- import './resources/codes.js';
12
13
  import './resources/referral.js';
13
14
  import './resources/subscription.js';
14
15
  import './resources/branding.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 {
@@ -165,6 +309,19 @@ function cardRequestBody(input) {
165
309
  if (consentChannel !== void 0) body["consent_channel"] = consentChannel;
166
310
  return body;
167
311
  }
312
+ function cardOrderQuoteBody(input) {
313
+ const body = {
314
+ product_id: input.productId,
315
+ method: input.method
316
+ };
317
+ if (input.designId !== void 0) body["design_id"] = input.designId;
318
+ if (input.funderSlug !== void 0) body["funder_slug"] = input.funderSlug;
319
+ if (input.currency !== void 0) body["currency"] = input.currency;
320
+ if (input.extraLoad !== void 0) body["extra_load"] = input.extraLoad;
321
+ if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
322
+ if (input.useBonus !== void 0) body["use_bonus"] = input.useBonus;
323
+ return body;
324
+ }
168
325
  function cardOrderBody(input) {
169
326
  const body = {
170
327
  product_id: input.productId,
@@ -180,6 +337,10 @@ function cardOrderBody(input) {
180
337
  if (input.consents !== void 0) body["consents"] = input.consents;
181
338
  if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
182
339
  if (input.metadata !== void 0) body["metadata"] = input.metadata;
340
+ const ids = input.analyticsIds ?? analyticsIds();
341
+ if (ids !== void 0) body["analytics_ids"] = ids;
342
+ if (input.expectedAmount !== void 0) body["expected_amount"] = input.expectedAmount;
343
+ if (input.expectedCurrency !== void 0) body["expected_currency"] = input.expectedCurrency;
183
344
  return body;
184
345
  }
185
346
  function revealState(r) {
@@ -214,8 +375,13 @@ var CardsResource = class {
214
375
  * `idempotencyKey` returns the same order.
215
376
  * Errors: 400 `unknown_product` / `method_not_available` / a limit of the
216
377
  * way of paying, 409 `holder_data_consent_required` (the product has
217
- * `holder_data_required` and the user has not agreed to it), 503 no
218
- * funding connector or no exchange rate.
378
+ * `holder_data_required` and the user has not agreed to it), 409
379
+ * `payments_on_hold` (a payment on this account was not accepted and new
380
+ * ones wait until support sorts it out: show the message and point the
381
+ * user to support), 409 `price_changed` (the order came to another amount
382
+ * than `expectedAmount`; no payment was opened, and
383
+ * {@link priceChangedQuote} gives the new quote), 503 no funding connector
384
+ * or no exchange rate.
219
385
  */
220
386
  async order(input) {
221
387
  const { idempotencyKey, ...order } = input;
@@ -224,12 +390,41 @@ var CardsResource = class {
224
390
  idempotencyKey
225
391
  });
226
392
  }
393
+ /**
394
+ * What an order of this card would cost the signed-in user now, with the
395
+ * promo code: the same calculation {@link order} makes, with every
396
+ * condition of the code checked. Nothing is reserved or used up. Pass
397
+ * `amount` and `currency` to the order as `expectedAmount` and
398
+ * `expectedCurrency`.
399
+ */
400
+ async quote(input) {
401
+ return this.http.post("/me/card-orders/quote", {
402
+ body: cardOrderQuoteBody(input)
403
+ });
404
+ }
405
+ /**
406
+ * The same quote before sign-in, for a landing page or the purchase form
407
+ * before the e-mail code. Prices are list prices, and a code whose
408
+ * conditions depend on the person (first card only, say) comes back
409
+ * `conditional`, with `preliminary` set. Send `expectedAmount` with the
410
+ * order placed at sign-in: if the price turns out different, no payment
411
+ * is opened and `card_order_error` carries the new quote. The API limits
412
+ * how often one address can ask (429 `too_many_requests`).
413
+ */
414
+ async quotePublic(input) {
415
+ return this.http.post("/card-orders/quote", {
416
+ body: cardOrderQuoteBody(input),
417
+ skipAuth: true
418
+ });
419
+ }
227
420
  /**
228
421
  * The cards the caller can order, in the order the storefront shows them
229
422
  * (`is_default` marks the one issued when none is chosen). Each item
230
423
  * carries its product card (name, tagline, benefits, tile picture),
231
424
  * artwork, and the issuance price after the caller's subscription
232
- * discount, in the caller's wallet currency. Pass an item's `id` as
425
+ * discount, in the currency the operator set it in (`price.from_wallet`
426
+ * is the same price from the wallet, when that holds another currency).
427
+ * Pass an item's `id` as
233
428
  * `productId` to {@link create}.
234
429
  */
235
430
  async listProducts() {
@@ -474,8 +669,11 @@ var AuthResource = class {
474
669
  /** Password-auth entry. May resolve to a JWT, or to a step-up
475
670
  * challenge that needs `verifyTotp` / `verifyOtp` next. */
476
671
  async login(input) {
672
+ const body = withRemember(input);
673
+ const attribution = withAnalyticsIds(void 0);
674
+ if (attribution !== void 0) body["attribution"] = attribution;
477
675
  const resp = await this.http.post("/auth/login", {
478
- body: withRemember(input),
676
+ body,
479
677
  skipAuth: true
480
678
  });
481
679
  if (resp.stage === "jwt") {
@@ -512,6 +710,8 @@ var AuthResource = class {
512
710
  async register(input) {
513
711
  const { cardOrder, ...rest } = input;
514
712
  const body = withRemember(rest);
713
+ const attribution = withAnalyticsIds(rest.attribution);
714
+ if (attribution !== void 0) body["attribution"] = attribution;
515
715
  if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
516
716
  const resp = await this.http.post("/auth/register", {
517
717
  body,
@@ -547,7 +747,8 @@ var AuthResource = class {
547
747
  };
548
748
  if (input.remember) body["remember_me"] = true;
549
749
  if (input.walletCurrency !== void 0) body["wallet_currency"] = input.walletCurrency;
550
- if (input.attribution !== void 0) body["attribution"] = input.attribution;
750
+ const attribution = withAnalyticsIds(input.attribution);
751
+ if (attribution !== void 0) body["attribution"] = attribution;
551
752
  if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
552
753
  if (input.consents !== void 0) body["consents"] = input.consents;
553
754
  if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
@@ -593,7 +794,8 @@ var AuthResource = class {
593
794
  init_data: input.initData
594
795
  };
595
796
  if (input.provision !== void 0) body.provision = input.provision;
596
- if (input.attribution !== void 0) body.attribution = input.attribution;
797
+ const attribution = withAnalyticsIds(input.attribution);
798
+ if (attribution !== void 0) body.attribution = attribution;
597
799
  if (input.code !== void 0) body.code = input.code;
598
800
  if (input.consents !== void 0) body.consents = input.consents;
599
801
  if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
@@ -699,10 +901,17 @@ var DepositsResource = class {
699
901
  if (connectorSlug !== void 0) body["connector_slug"] = connectorSlug;
700
902
  return this.http.post("/me/deposits/quotes", { body });
701
903
  }
904
+ /**
905
+ * Start a top-up. 409 `payments_on_hold`: a payment on this account was
906
+ * not accepted and new ones wait until support sorts it out. Show the
907
+ * message as it comes and point the user to support.
908
+ */
702
909
  async initiate(input) {
703
910
  const { idempotencyKey, issue_card, ...rest } = input;
704
911
  const body = { ...rest };
705
912
  if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
913
+ const ids = input.analytics_ids ?? analyticsIds();
914
+ if (ids !== void 0) body["analytics_ids"] = ids;
706
915
  return this.http.post("/me/deposits", {
707
916
  body,
708
917
  idempotencyKey
@@ -1304,67 +1513,6 @@ var DevicesResource = class {
1304
1513
  }
1305
1514
  };
1306
1515
 
1307
- // src/resources/attribution.ts
1308
- var AttributionResource = class {
1309
- constructor(http) {
1310
- this.http = http;
1311
- }
1312
- /** Record a visit. No session needed; safe to call on every page load. */
1313
- async touch(input) {
1314
- return this.http.post("/attribution/touches", { body: input, skipAuth: true });
1315
- }
1316
- /** Whether to ask the signed-in user how they heard about us. */
1317
- async status() {
1318
- return this.http.get("/me/attribution");
1319
- }
1320
- /** Answer the question once. Send `"skipped"` when the user closes it.
1321
- * `otherText` is kept only with `"other"`, up to 500 characters.
1322
- * Errors: 400 `validation`, 409 `survey_answered`. */
1323
- async answerSurvey(answer, otherText) {
1324
- const body = { answer };
1325
- if (otherText !== void 0) body.other_text = otherText;
1326
- return this.http.put("/me/attribution/survey", { body });
1327
- }
1328
- };
1329
- function tgWebApp() {
1330
- return globalThis.Telegram?.WebApp?.initDataUnsafe;
1331
- }
1332
- function readCookie(name) {
1333
- const doc = globalThis.document;
1334
- if (!doc?.cookie) return void 0;
1335
- for (const part of doc.cookie.split(";")) {
1336
- const [k, ...v] = part.trim().split("=");
1337
- if (k === name) return decodeURIComponent(v.join("="));
1338
- }
1339
- return void 0;
1340
- }
1341
- var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
1342
- function anonymousKey(opts = {}) {
1343
- const tgId = tgWebApp()?.user?.id;
1344
- if (tgId) return `tg:${tgId}`;
1345
- const g = globalThis;
1346
- if (!g.document) return void 0;
1347
- const name = opts.name ?? "takeal_anon";
1348
- let stored;
1349
- try {
1350
- stored = g.localStorage?.getItem(name) ?? void 0;
1351
- } catch {
1352
- stored = void 0;
1353
- }
1354
- const fromCookie = readCookie(name);
1355
- let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
1356
- if (!key) {
1357
- key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
1358
- }
1359
- try {
1360
- g.localStorage?.setItem(name, key);
1361
- } catch {
1362
- }
1363
- const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
1364
- g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
1365
- return key;
1366
- }
1367
-
1368
1516
  // src/resources/history.ts
1369
1517
  var HistoryResource = class {
1370
1518
  constructor(http) {
@@ -1468,6 +1616,7 @@ var ConsentsResource = class {
1468
1616
  const key = input.anonymousKey ?? anonymousKey();
1469
1617
  if (key !== void 0) body.anonymous_key = key;
1470
1618
  if (input.channel !== void 0) body.channel = input.channel;
1619
+ if (!input.analytics) forgetAnalyticsIds();
1471
1620
  return this.http.post("/consents/cookies", { body });
1472
1621
  }
1473
1622
  };
@@ -1565,7 +1714,7 @@ var FundingOptionsResource = class {
1565
1714
  };
1566
1715
 
1567
1716
  // src/version.ts
1568
- var SDK_VERSION = "0.6.11";
1717
+ var SDK_VERSION = "0.8.0";
1569
1718
 
1570
1719
  // src/client-platform.ts
1571
1720
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1640,7 +1789,7 @@ function isAbsolute(url) {
1640
1789
  }
1641
1790
 
1642
1791
  // src/compat.ts
1643
- var SUPPORTED_MEISTER = ">=0.7.6, <1.0.0";
1792
+ var SUPPORTED_MEISTER = ">=0.8.0, <1.0.0";
1644
1793
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1645
1794
  function parse(v) {
1646
1795
  const m = SEMVER.exec(v.trim());
@@ -1823,6 +1972,40 @@ function assertWellFormed(initData, opts = {}) {
1823
1972
  }
1824
1973
  return parsed;
1825
1974
  }
1975
+ function describeInitData(initData, opts = {}) {
1976
+ if (typeof initData !== "string") {
1977
+ return {
1978
+ type: typeof initData,
1979
+ length: 0,
1980
+ fields: [],
1981
+ hasHash: false,
1982
+ hasSignature: false,
1983
+ hasAuthDate: false,
1984
+ hasUserId: false,
1985
+ reason: "not_a_string"
1986
+ };
1987
+ }
1988
+ const parsed = parseInitData(initData);
1989
+ const now = opts.nowUnix ?? Math.floor(Date.now() / 1e3);
1990
+ let reason = null;
1991
+ try {
1992
+ assertWellFormed(initData, opts);
1993
+ } catch (e) {
1994
+ if (e instanceof InitDataError) reason = e.reason;
1995
+ else throw e;
1996
+ }
1997
+ return {
1998
+ type: "string",
1999
+ length: initData.length,
2000
+ fields: Object.keys(parsed.params).sort(),
2001
+ hasHash: parsed.hash !== void 0,
2002
+ hasSignature: typeof parsed.params.signature === "string" && parsed.params.signature !== "",
2003
+ hasAuthDate: parsed.auth_date !== void 0,
2004
+ ...parsed.auth_date !== void 0 ? { authDateAgeSeconds: now - parsed.auth_date } : {},
2005
+ hasUserId: typeof parsed.user?.id === "number",
2006
+ reason
2007
+ };
2008
+ }
1826
2009
  var TelegramUnknownError = class extends Error {
1827
2010
  constructor(initData) {
1828
2011
  super("this Telegram account is not linked to any user (provision: false)");
@@ -1881,6 +2064,6 @@ async function fromTelegramWebApp(config, opts = {}) {
1881
2064
  return fromInitData(initData, config, opts);
1882
2065
  }
1883
2066
 
1884
- export { InitDataError, TelegramUnknownError, assertWellFormed, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
2067
+ export { InitDataError, TelegramUnknownError, assertWellFormed, describeInitData, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
1885
2068
  //# sourceMappingURL=telegram.js.map
1886
2069
  //# sourceMappingURL=telegram.js.map