@takeal/cusfront-sdk 0.6.11 → 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 +73 -0
  2. package/README.md +3 -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-CuUdrQ0H.d.ts → cards-DPlgx76p.d.ts} +38 -11
  8. package/dist/{cards-nXmDP0ei.d.cts → cards-D_krTWzr.d.cts} +38 -11
  9. package/dist/index.cjs +207 -88
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +4 -4
  12. package/dist/index.d.ts +4 -4
  13. package/dist/index.js +204 -89
  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 +52 -3
  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 +52 -3
  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 +207 -68
  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 +207 -69
  58. package/dist/telegram.js.map +1 -1
  59. package/package.json +1 -1
package/dist/index.d.cts CHANGED
@@ -2,8 +2,8 @@ import { T as TokenStore, F as FetchLike } from './http-CL97TjMO.cjs';
2
2
  export { d as defaultBrowserStore, i as inMemoryStore } from './http-CL97TjMO.cjs';
3
3
  import { AuthResource } from './resources/auth.cjs';
4
4
  export { ChangePasswordInput, EmailChangeRequested, EmailCodeSent, EmailCodeSession, ExchangeTelegramInput, JwtIssued, LinkTelegramInput, LoginInput, LoginResponse, OtpSentResponse, RegisterInput, RequestEmailCodeInput, Session, TelegramLink, TelegramUnknown, TotpRequired, TotpSetupComplete, TotpSetupRequired, User, VerifyEmailCodeInput } from './resources/auth.cjs';
5
- import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-nXmDP0ei.cjs';
6
- export { A as Address, B as BillingAddress, a as Card, d as CardBalance, e as CardDesignRef, f as CardForm, g as CardInTransit, h as CardLoadStatus, i as CardOrder, j as CardOrderError, k as CardOrderInput, C as CardProduct, l as CardProductPrice, m as CardStatus, n as CardStatusSource, o as CardTariff, p as CardTopUp, q as CardTopUpStatus, r as CardTransfer, s as CardType, t as Cardholder, u as CloseBlockedReason, v as CreateCardInput, w as CreateDepositRefundInput, x as CreateQuoteInput, y as CustomerInfo, D as Deposit, z as DepositMethod, E as DepositStatus, G as DepositTarget, H as FeeKind, I as FunderMode, J as FundingOption, K as FundingQuote, L as InitiateDepositInput, M as IssuanceBonus, N as IssueCardInput, O as MethodTerms, R as Refund, P as RevealCardInput, Q as RevealState, S as RevealedCard, T as SetPinInput, U as TopUpInput, V as TopUpResult, W as TopUpTerms, X as TransferInput, Y as TransferResult, Z as UpdateCardInput, _ as revealState } from './cards-nXmDP0ei.cjs';
5
+ import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-D_krTWzr.cjs';
6
+ export { A as Address, B as BillingAddress, a as Card, d as CardBalance, e as CardDesignRef, f as CardForm, g as CardInTransit, h as CardLoadStatus, i as CardOrder, j as CardOrderError, k as CardOrderInput, C as CardProduct, l as CardProductPrice, m as CardStatus, n as CardStatusSource, o as CardTariff, p as CardTopUp, q as CardTopUpStatus, r as CardTransfer, s as CardType, t as Cardholder, u as CloseBlockedReason, v as CreateCardInput, w as CreateDepositRefundInput, x as CreateQuoteInput, y as CustomerInfo, D as Deposit, z as DepositMethod, E as DepositStatus, G as DepositTarget, H as FeeKind, I as FunderMode, J as FundingOption, K as FundingQuote, L as InitiateDepositInput, M as IssuanceBonus, N as IssueCardInput, O as MethodTerms, R as Refund, P as RevealCardInput, Q as RevealState, S as RevealedCard, T as SetPinInput, U as TopUpInput, V as TopUpResult, W as TopUpTerms, X as TransferInput, Y as TransferResult, Z as UpdateCardInput, _ as revealState } from './cards-D_krTWzr.cjs';
7
7
  import { BalanceResource } from './resources/balance.cjs';
8
8
  export { Balance } from './resources/balance.cjs';
9
9
  import { BonusResource } from './resources/bonus.cjs';
@@ -40,7 +40,7 @@ export { CardOtpData, InboxItem, ListNotificationsParams, NotificationCategory,
40
40
  import { C as ClientDescriptor, R as ResolvedClientDescriptor, D as DevicesResource } from './devices-CiJrlXum.cjs';
41
41
  export { a as CLIENT_HEADER, b as ClientPlatform, c as Device, d as DeviceKind, e as DevicePlatform, M as MobilePushCredential, f as RegisterDeviceInput, g as RegisterWebPushOptions, h as RegisteredDevice, U as UnregisterWebPushOptions, W as WebPushCredential, i as detectClientPlatform } from './devices-CiJrlXum.cjs';
42
42
  import { AttributionResource } from './resources/attribution.cjs';
43
- export { AnonymousKeyOptions, AttributionStatus, SignupAttribution, SurveyAnswer, TouchFields, TouchInput, TouchResult, anonymousKey, currentTouch } from './resources/attribution.cjs';
43
+ export { AnalyticsIds, AnonymousKeyOptions, AttributionStatus, HandoffToken, SignupAttribution, SurveyAnswer, TouchFields, TouchInput, TouchResult, analyticsIds, anonymousKey, currentTouch, forgetAnalyticsIds, rememberAnalyticsIds, withAnalyticsIds } from './resources/attribution.cjs';
44
44
  import { HistoryResource } from './resources/history.cjs';
45
45
  export { HistoryAmount, HistoryCard, HistoryItem, HistoryKind, HistoryPage, HistoryStatus, ListHistoryParams } from './resources/history.cjs';
46
46
  import { ConsentsResource } from './resources/consents.cjs';
@@ -187,7 +187,7 @@ declare function isNetworkError(e: unknown): e is NetworkError;
187
187
  * `define`. `src/version.test.ts` checks it matches `package.json`, so a
188
188
  * release bump that forgets this file fails the test run.
189
189
  */
190
- declare const SDK_VERSION = "0.6.11";
190
+ declare const SDK_VERSION = "0.6.14";
191
191
 
192
192
  /**
193
193
  * `@takeal/cusfront-sdk` — typed client for the Takeal end-user API.
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import { T as TokenStore, F as FetchLike } from './http-CL97TjMO.js';
2
2
  export { d as defaultBrowserStore, i as inMemoryStore } from './http-CL97TjMO.js';
3
3
  import { AuthResource } from './resources/auth.js';
4
4
  export { ChangePasswordInput, EmailChangeRequested, EmailCodeSent, EmailCodeSession, ExchangeTelegramInput, JwtIssued, LinkTelegramInput, LoginInput, LoginResponse, OtpSentResponse, RegisterInput, RequestEmailCodeInput, Session, TelegramLink, TelegramUnknown, TotpRequired, TotpSetupComplete, TotpSetupRequired, User, VerifyEmailCodeInput } from './resources/auth.js';
5
- import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-CuUdrQ0H.js';
6
- export { A as Address, B as BillingAddress, a as Card, d as CardBalance, e as CardDesignRef, f as CardForm, g as CardInTransit, h as CardLoadStatus, i as CardOrder, j as CardOrderError, k as CardOrderInput, C as CardProduct, l as CardProductPrice, m as CardStatus, n as CardStatusSource, o as CardTariff, p as CardTopUp, q as CardTopUpStatus, r as CardTransfer, s as CardType, t as Cardholder, u as CloseBlockedReason, v as CreateCardInput, w as CreateDepositRefundInput, x as CreateQuoteInput, y as CustomerInfo, D as Deposit, z as DepositMethod, E as DepositStatus, G as DepositTarget, H as FeeKind, I as FunderMode, J as FundingOption, K as FundingQuote, L as InitiateDepositInput, M as IssuanceBonus, N as IssueCardInput, O as MethodTerms, R as Refund, P as RevealCardInput, Q as RevealState, S as RevealedCard, T as SetPinInput, U as TopUpInput, V as TopUpResult, W as TopUpTerms, X as TransferInput, Y as TransferResult, Z as UpdateCardInput, _ as revealState } from './cards-CuUdrQ0H.js';
5
+ import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-DPlgx76p.js';
6
+ export { A as Address, B as BillingAddress, a as Card, d as CardBalance, e as CardDesignRef, f as CardForm, g as CardInTransit, h as CardLoadStatus, i as CardOrder, j as CardOrderError, k as CardOrderInput, C as CardProduct, l as CardProductPrice, m as CardStatus, n as CardStatusSource, o as CardTariff, p as CardTopUp, q as CardTopUpStatus, r as CardTransfer, s as CardType, t as Cardholder, u as CloseBlockedReason, v as CreateCardInput, w as CreateDepositRefundInput, x as CreateQuoteInput, y as CustomerInfo, D as Deposit, z as DepositMethod, E as DepositStatus, G as DepositTarget, H as FeeKind, I as FunderMode, J as FundingOption, K as FundingQuote, L as InitiateDepositInput, M as IssuanceBonus, N as IssueCardInput, O as MethodTerms, R as Refund, P as RevealCardInput, Q as RevealState, S as RevealedCard, T as SetPinInput, U as TopUpInput, V as TopUpResult, W as TopUpTerms, X as TransferInput, Y as TransferResult, Z as UpdateCardInput, _ as revealState } from './cards-DPlgx76p.js';
7
7
  import { BalanceResource } from './resources/balance.js';
8
8
  export { Balance } from './resources/balance.js';
9
9
  import { BonusResource } from './resources/bonus.js';
@@ -40,7 +40,7 @@ export { CardOtpData, InboxItem, ListNotificationsParams, NotificationCategory,
40
40
  import { C as ClientDescriptor, R as ResolvedClientDescriptor, D as DevicesResource } from './devices-C88c38hm.js';
41
41
  export { a as CLIENT_HEADER, b as ClientPlatform, c as Device, d as DeviceKind, e as DevicePlatform, M as MobilePushCredential, f as RegisterDeviceInput, g as RegisterWebPushOptions, h as RegisteredDevice, U as UnregisterWebPushOptions, W as WebPushCredential, i as detectClientPlatform } from './devices-C88c38hm.js';
42
42
  import { AttributionResource } from './resources/attribution.js';
43
- export { AnonymousKeyOptions, AttributionStatus, SignupAttribution, SurveyAnswer, TouchFields, TouchInput, TouchResult, anonymousKey, currentTouch } from './resources/attribution.js';
43
+ export { AnalyticsIds, AnonymousKeyOptions, AttributionStatus, HandoffToken, SignupAttribution, SurveyAnswer, TouchFields, TouchInput, TouchResult, analyticsIds, anonymousKey, currentTouch, forgetAnalyticsIds, rememberAnalyticsIds, withAnalyticsIds } from './resources/attribution.js';
44
44
  import { HistoryResource } from './resources/history.js';
45
45
  export { HistoryAmount, HistoryCard, HistoryItem, HistoryKind, HistoryPage, HistoryStatus, ListHistoryParams } from './resources/history.js';
46
46
  import { ConsentsResource } from './resources/consents.js';
@@ -187,7 +187,7 @@ declare function isNetworkError(e: unknown): e is NetworkError;
187
187
  * `define`. `src/version.test.ts` checks it matches `package.json`, so a
188
188
  * release bump that forgets this file fails the test run.
189
189
  */
190
- declare const SDK_VERSION = "0.6.11";
190
+ declare const SDK_VERSION = "0.6.14";
191
191
 
192
192
  /**
193
193
  * `@takeal/cusfront-sdk` — typed client for the Takeal end-user API.
package/dist/index.js CHANGED
@@ -145,6 +145,172 @@ async function parseResponse(resp) {
145
145
  return body;
146
146
  }
147
147
 
148
+ // src/resources/attribution.ts
149
+ var AttributionResource = class {
150
+ constructor(http) {
151
+ this.http = http;
152
+ }
153
+ /** Record a visit. No session needed; safe to call on every page load. */
154
+ async touch(input) {
155
+ return this.http.post("/attribution/touches", { body: input, skipAuth: true });
156
+ }
157
+ /** A one-day token that carries the visitor's analytics ids into the
158
+ * Telegram Mini App, whose sign-in reads it back. Most callers want
159
+ * {@link AttributionResource.telegramStartParam}. Errors: 400 when none of
160
+ * the ids is valid. */
161
+ async handoff(ids) {
162
+ return this.http.post("/attribution/handoff", { body: ids, skipAuth: true });
163
+ }
164
+ /**
165
+ * The `startapp` value for a link from the site to the Mini App: the code
166
+ * as it is, followed by `__<token>` when the visitor has analytics ids, so
167
+ * a payment made in Telegram is still credited to the visit it came from.
168
+ * Without ids, or when the token can't be had, just the code.
169
+ *
170
+ * ```ts
171
+ * const start = await client.attribution.telegramStartParam("SPRING");
172
+ * location.href = `https://t.me/our_bot/app?startapp=${start}`;
173
+ * ```
174
+ */
175
+ async telegramStartParam(code = "") {
176
+ const ids = analyticsIds();
177
+ if (!ids) return code;
178
+ try {
179
+ const { token } = await this.handoff(ids);
180
+ return `${code}__${token}`;
181
+ } catch {
182
+ return code;
183
+ }
184
+ }
185
+ /** Send the visitor's analytics ids for the signed-in account, e.g. right
186
+ * after they agreed to analytics cookies in the cabinet. Without an
187
+ * argument the ids this browser holds are sent; nothing is sent when it
188
+ * holds none. */
189
+ async sendAnalyticsIds(ids = analyticsIds()) {
190
+ if (!ids) return;
191
+ await this.http.post("/me/analytics/ids", { body: ids });
192
+ }
193
+ /** Whether to ask the signed-in user how they heard about us. */
194
+ async status() {
195
+ return this.http.get("/me/attribution");
196
+ }
197
+ /** Answer the question once. Send `"skipped"` when the user closes it.
198
+ * `otherText` is kept only with `"other"`, up to 500 characters.
199
+ * Errors: 400 `validation`, 409 `survey_answered`. */
200
+ async answerSurvey(answer, otherText) {
201
+ const body = { answer };
202
+ if (otherText !== void 0) body.other_text = otherText;
203
+ return this.http.put("/me/attribution/survey", { body });
204
+ }
205
+ };
206
+ function tgWebApp() {
207
+ return globalThis.Telegram?.WebApp?.initDataUnsafe;
208
+ }
209
+ function readCookie(name) {
210
+ const doc = globalThis.document;
211
+ if (!doc?.cookie) return void 0;
212
+ for (const part of doc.cookie.split(";")) {
213
+ const [k, ...v] = part.trim().split("=");
214
+ if (k === name) return decodeURIComponent(v.join("="));
215
+ }
216
+ return void 0;
217
+ }
218
+ var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
219
+ function anonymousKey(opts = {}) {
220
+ const tgId = tgWebApp()?.user?.id;
221
+ if (tgId) return `tg:${tgId}`;
222
+ const g = globalThis;
223
+ if (!g.document) return void 0;
224
+ const name = opts.name ?? "takeal_anon";
225
+ let stored2;
226
+ try {
227
+ stored2 = g.localStorage?.getItem(name) ?? void 0;
228
+ } catch {
229
+ stored2 = void 0;
230
+ }
231
+ const fromCookie = readCookie(name);
232
+ let key = [fromCookie, stored2].find((k) => !!k && KEY_SHAPE.test(k));
233
+ if (!key) {
234
+ key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
235
+ }
236
+ try {
237
+ g.localStorage?.setItem(name, key);
238
+ } catch {
239
+ }
240
+ const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
241
+ g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
242
+ return key;
243
+ }
244
+ function currentTouch() {
245
+ const g = globalThis;
246
+ const tg = tgWebApp();
247
+ const out = {};
248
+ if (g.location?.href) out.url = g.location.href;
249
+ if (g.document?.referrer) out.referrer = g.document.referrer;
250
+ if (tg?.start_param) out.campaign_code = tg.start_param;
251
+ if (tg?.user?.id) out.platform = "miniapp";
252
+ const ym = readCookie("_ym_uid");
253
+ if (ym) out.metrika_client_id = ym;
254
+ const ga = readCookie("_ga")?.split(".").slice(-2).join(".");
255
+ if (ga) out.ga_client_id = ga;
256
+ return out;
257
+ }
258
+ var IDS_KEY = "takeal_analytics_ids";
259
+ function storage() {
260
+ try {
261
+ return globalThis.localStorage;
262
+ } catch {
263
+ return void 0;
264
+ }
265
+ }
266
+ function stored() {
267
+ try {
268
+ const raw = storage()?.getItem(IDS_KEY);
269
+ const v = raw ? JSON.parse(raw) : {};
270
+ return typeof v === "object" && v !== null ? v : {};
271
+ } catch {
272
+ return {};
273
+ }
274
+ }
275
+ function clean(ids) {
276
+ const out = {};
277
+ const ym = ids.metrika_client_id?.trim();
278
+ if (ym && /^\d{1,32}$/.test(ym)) out.metrika_client_id = ym;
279
+ const ga = ids.ga_client_id?.trim();
280
+ if (ga && /^\d+\.\d+$/.test(ga) && ga.length <= 64) out.ga_client_id = ga;
281
+ return out.metrika_client_id || out.ga_client_id ? out : void 0;
282
+ }
283
+ function rememberAnalyticsIds(ids) {
284
+ const merged = clean({ ...stored(), ...ids });
285
+ if (!merged) return;
286
+ try {
287
+ storage()?.setItem(IDS_KEY, JSON.stringify(merged));
288
+ } catch {
289
+ }
290
+ }
291
+ function forgetAnalyticsIds() {
292
+ try {
293
+ storage()?.removeItem(IDS_KEY);
294
+ } catch {
295
+ }
296
+ }
297
+ function analyticsIds() {
298
+ const kept = stored();
299
+ return clean({
300
+ metrika_client_id: kept.metrika_client_id ?? readCookie("_ym_uid"),
301
+ ga_client_id: kept.ga_client_id ?? readCookie("_ga")?.split(".").slice(-2).join(".")
302
+ });
303
+ }
304
+ function withAnalyticsIds(attribution) {
305
+ const ids = analyticsIds();
306
+ if (!ids) return attribution;
307
+ return {
308
+ ...attribution,
309
+ metrika_client_id: attribution?.metrika_client_id ?? ids.metrika_client_id,
310
+ ga_client_id: attribution?.ga_client_id ?? ids.ga_client_id
311
+ };
312
+ }
313
+
148
314
  // src/resources/cards.ts
149
315
  function cardRequestBody(input) {
150
316
  const {
@@ -183,6 +349,8 @@ function cardOrderBody(input) {
183
349
  if (input.consents !== void 0) body["consents"] = input.consents;
184
350
  if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
185
351
  if (input.metadata !== void 0) body["metadata"] = input.metadata;
352
+ const ids = input.analyticsIds ?? analyticsIds();
353
+ if (ids !== void 0) body["analytics_ids"] = ids;
186
354
  return body;
187
355
  }
188
356
  function revealState(r) {
@@ -217,8 +385,10 @@ var CardsResource = class {
217
385
  * `idempotencyKey` returns the same order.
218
386
  * Errors: 400 `unknown_product` / `method_not_available` / a limit of the
219
387
  * way of paying, 409 `holder_data_consent_required` (the product has
220
- * `holder_data_required` and the user has not agreed to it), 503 no
221
- * funding connector or no exchange rate.
388
+ * `holder_data_required` and the user has not agreed to it), 409
389
+ * `payments_on_hold` (a payment on this account was not accepted and new
390
+ * ones wait until support sorts it out: show the message and point the
391
+ * user to support), 503 no funding connector or no exchange rate.
222
392
  */
223
393
  async order(input) {
224
394
  const { idempotencyKey, ...order } = input;
@@ -232,7 +402,9 @@ var CardsResource = class {
232
402
  * (`is_default` marks the one issued when none is chosen). Each item
233
403
  * carries its product card (name, tagline, benefits, tile picture),
234
404
  * artwork, and the issuance price after the caller's subscription
235
- * discount, in the caller's wallet currency. Pass an item's `id` as
405
+ * discount, in the currency the operator set it in (`price.from_wallet`
406
+ * is the same price from the wallet, when that holds another currency).
407
+ * Pass an item's `id` as
236
408
  * `productId` to {@link create}.
237
409
  */
238
410
  async listProducts() {
@@ -477,8 +649,11 @@ var AuthResource = class {
477
649
  /** Password-auth entry. May resolve to a JWT, or to a step-up
478
650
  * challenge that needs `verifyTotp` / `verifyOtp` next. */
479
651
  async login(input) {
652
+ const body = withRemember(input);
653
+ const attribution = withAnalyticsIds(void 0);
654
+ if (attribution !== void 0) body["attribution"] = attribution;
480
655
  const resp = await this.http.post("/auth/login", {
481
- body: withRemember(input),
656
+ body,
482
657
  skipAuth: true
483
658
  });
484
659
  if (resp.stage === "jwt") {
@@ -515,6 +690,8 @@ var AuthResource = class {
515
690
  async register(input) {
516
691
  const { cardOrder, ...rest } = input;
517
692
  const body = withRemember(rest);
693
+ const attribution = withAnalyticsIds(rest.attribution);
694
+ if (attribution !== void 0) body["attribution"] = attribution;
518
695
  if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
519
696
  const resp = await this.http.post("/auth/register", {
520
697
  body,
@@ -550,7 +727,8 @@ var AuthResource = class {
550
727
  };
551
728
  if (input.remember) body["remember_me"] = true;
552
729
  if (input.walletCurrency !== void 0) body["wallet_currency"] = input.walletCurrency;
553
- if (input.attribution !== void 0) body["attribution"] = input.attribution;
730
+ const attribution = withAnalyticsIds(input.attribution);
731
+ if (attribution !== void 0) body["attribution"] = attribution;
554
732
  if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
555
733
  if (input.consents !== void 0) body["consents"] = input.consents;
556
734
  if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
@@ -596,7 +774,8 @@ var AuthResource = class {
596
774
  init_data: input.initData
597
775
  };
598
776
  if (input.provision !== void 0) body.provision = input.provision;
599
- if (input.attribution !== void 0) body.attribution = input.attribution;
777
+ const attribution = withAnalyticsIds(input.attribution);
778
+ if (attribution !== void 0) body.attribution = attribution;
600
779
  if (input.code !== void 0) body.code = input.code;
601
780
  if (input.consents !== void 0) body.consents = input.consents;
602
781
  if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
@@ -702,10 +881,17 @@ var DepositsResource = class {
702
881
  if (connectorSlug !== void 0) body["connector_slug"] = connectorSlug;
703
882
  return this.http.post("/me/deposits/quotes", { body });
704
883
  }
884
+ /**
885
+ * Start a top-up. 409 `payments_on_hold`: a payment on this account was
886
+ * not accepted and new ones wait until support sorts it out. Show the
887
+ * message as it comes and point the user to support.
888
+ */
705
889
  async initiate(input) {
706
890
  const { idempotencyKey, issue_card, ...rest } = input;
707
891
  const body = { ...rest };
708
892
  if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
893
+ const ids = input.analytics_ids ?? analyticsIds();
894
+ if (ids !== void 0) body["analytics_ids"] = ids;
709
895
  return this.http.post("/me/deposits", {
710
896
  body,
711
897
  idempotencyKey
@@ -1310,81 +1496,6 @@ var DevicesResource = class {
1310
1496
  }
1311
1497
  };
1312
1498
 
1313
- // src/resources/attribution.ts
1314
- var AttributionResource = class {
1315
- constructor(http) {
1316
- this.http = http;
1317
- }
1318
- /** Record a visit. No session needed; safe to call on every page load. */
1319
- async touch(input) {
1320
- return this.http.post("/attribution/touches", { body: input, skipAuth: true });
1321
- }
1322
- /** Whether to ask the signed-in user how they heard about us. */
1323
- async status() {
1324
- return this.http.get("/me/attribution");
1325
- }
1326
- /** Answer the question once. Send `"skipped"` when the user closes it.
1327
- * `otherText` is kept only with `"other"`, up to 500 characters.
1328
- * Errors: 400 `validation`, 409 `survey_answered`. */
1329
- async answerSurvey(answer, otherText) {
1330
- const body = { answer };
1331
- if (otherText !== void 0) body.other_text = otherText;
1332
- return this.http.put("/me/attribution/survey", { body });
1333
- }
1334
- };
1335
- function tgWebApp() {
1336
- return globalThis.Telegram?.WebApp?.initDataUnsafe;
1337
- }
1338
- function readCookie(name) {
1339
- const doc = globalThis.document;
1340
- if (!doc?.cookie) return void 0;
1341
- for (const part of doc.cookie.split(";")) {
1342
- const [k, ...v] = part.trim().split("=");
1343
- if (k === name) return decodeURIComponent(v.join("="));
1344
- }
1345
- return void 0;
1346
- }
1347
- var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
1348
- function anonymousKey(opts = {}) {
1349
- const tgId = tgWebApp()?.user?.id;
1350
- if (tgId) return `tg:${tgId}`;
1351
- const g = globalThis;
1352
- if (!g.document) return void 0;
1353
- const name = opts.name ?? "takeal_anon";
1354
- let stored;
1355
- try {
1356
- stored = g.localStorage?.getItem(name) ?? void 0;
1357
- } catch {
1358
- stored = void 0;
1359
- }
1360
- const fromCookie = readCookie(name);
1361
- let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
1362
- if (!key) {
1363
- key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
1364
- }
1365
- try {
1366
- g.localStorage?.setItem(name, key);
1367
- } catch {
1368
- }
1369
- const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
1370
- g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
1371
- return key;
1372
- }
1373
- function currentTouch() {
1374
- const g = globalThis;
1375
- const tg = tgWebApp();
1376
- const out = {};
1377
- if (g.location?.href) out.url = g.location.href;
1378
- if (g.document?.referrer) out.referrer = g.document.referrer;
1379
- if (tg?.start_param) out.campaign_code = tg.start_param;
1380
- if (tg?.user?.id) out.platform = "miniapp";
1381
- const ym = readCookie("_ym_uid");
1382
- if (ym) out.metrika_client_id = ym;
1383
- const ga = readCookie("_ga")?.split(".").slice(-2).join(".");
1384
- if (ga) out.ga_client_id = ga;
1385
- return out;
1386
- }
1387
-
1388
1499
  // src/resources/history.ts
1389
1500
  var HistoryResource = class {
1390
1501
  constructor(http) {
@@ -1488,6 +1599,7 @@ var ConsentsResource = class {
1488
1599
  const key = input.anonymousKey ?? anonymousKey();
1489
1600
  if (key !== void 0) body.anonymous_key = key;
1490
1601
  if (input.channel !== void 0) body.channel = input.channel;
1602
+ if (!input.analytics) forgetAnalyticsIds();
1491
1603
  return this.http.post("/consents/cookies", { body });
1492
1604
  }
1493
1605
  };
@@ -1585,7 +1697,7 @@ var FundingOptionsResource = class {
1585
1697
  };
1586
1698
 
1587
1699
  // src/version.ts
1588
- var SDK_VERSION = "0.6.11";
1700
+ var SDK_VERSION = "0.6.14";
1589
1701
 
1590
1702
  // src/client-platform.ts
1591
1703
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -2059,6 +2171,9 @@ var MetrikaSink = class {
2059
2171
  trackLinks: false,
2060
2172
  accurateTrackBounce: true
2061
2173
  });
2174
+ this.ym("getClientID", (id) => {
2175
+ if (id !== void 0 && id !== null) rememberAnalyticsIds({ metrika_client_id: String(id) });
2176
+ });
2062
2177
  }
2063
2178
  ym(...args) {
2064
2179
  if (this.live) win().ym?.(this.id, ...args);
@@ -2110,19 +2225,19 @@ function setAnalyticsZone(zone) {
2110
2225
  function track(event, props = {}) {
2111
2226
  const s = state();
2112
2227
  if (!s || !ANALYTICS_EVENTS.includes(event)) return;
2113
- const clean = sanitizeProperties(props);
2114
- for (const sink of sinks(s)) sink.capture(event, clean);
2228
+ const clean2 = sanitizeProperties(props);
2229
+ for (const sink of sinks(s)) sink.capture(event, clean2);
2115
2230
  }
2116
2231
  function page(url) {
2117
2232
  const s = state();
2118
2233
  const w = win();
2119
2234
  const raw = url ?? w.location?.href;
2120
2235
  if (!s || !raw) return;
2121
- const clean = sanitizeUrl(raw);
2122
- if (clean === s.lastPage) return;
2236
+ const clean2 = sanitizeUrl(raw);
2237
+ if (clean2 === s.lastPage) return;
2123
2238
  const referrer = s.lastPage ?? (w.document?.referrer ? sanitizeUrl(w.document.referrer) : void 0);
2124
- s.lastPage = clean;
2125
- for (const sink of sinks(s)) sink.page(clean, referrer);
2239
+ s.lastPage = clean2;
2240
+ for (const sink of sinks(s)) sink.page(clean2, referrer);
2126
2241
  }
2127
2242
  function identify(userId) {
2128
2243
  const s = state();
@@ -2211,6 +2326,6 @@ function defaultFetch() {
2211
2326
  );
2212
2327
  }
2213
2328
 
2214
- export { ANALYTICS_EVENTS, ApiError, CLIENT_HEADER, DISPUTE_DOCUMENTS_CONSENT, HOLDER_DATA_CONSENT, METRIKA_GOALS, NO_CAPTURE_CLASS, NetworkError, SDK_VERSION, SUPPORTED_MEISTER, anonymousKey, createClient, currentTouch, defaultBrowserStore, detectClientPlatform, identify, inMemoryStore, initAnalytics, isApiError, isCardOtp, isNetworkError, page, posthogDistinctId, resetAnalytics, resolveAssetUrl, revealState, sanitizeProperties, sanitizeUrl, satisfies, setAnalyticsZone, track };
2329
+ export { ANALYTICS_EVENTS, ApiError, CLIENT_HEADER, DISPUTE_DOCUMENTS_CONSENT, HOLDER_DATA_CONSENT, METRIKA_GOALS, NO_CAPTURE_CLASS, NetworkError, SDK_VERSION, SUPPORTED_MEISTER, analyticsIds, anonymousKey, createClient, currentTouch, defaultBrowserStore, detectClientPlatform, forgetAnalyticsIds, identify, inMemoryStore, initAnalytics, isApiError, isCardOtp, isNetworkError, page, posthogDistinctId, rememberAnalyticsIds, resetAnalytics, resolveAssetUrl, revealState, sanitizeProperties, sanitizeUrl, satisfies, setAnalyticsZone, track, withAnalyticsIds };
2215
2330
  //# sourceMappingURL=index.js.map
2216
2331
  //# sourceMappingURL=index.js.map