@takeal/cusfront-sdk 0.8.4 → 0.9.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 (45) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +46 -5
  3. package/dist/analytics.cjs +74 -22
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.d.cts +43 -4
  6. package/dist/analytics.d.ts +43 -4
  7. package/dist/analytics.js +71 -23
  8. package/dist/analytics.js.map +1 -1
  9. package/dist/{cards-DwxkVJUB.d.cts → cards-C5rk0XkI.d.cts} +47 -5
  10. package/dist/{cards-VkS_2lPe.d.ts → cards-CS-oxqLS.d.ts} +47 -5
  11. package/dist/index.cjs +94 -26
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +13 -5
  14. package/dist/index.d.ts +13 -5
  15. package/dist/index.js +91 -27
  16. package/dist/index.js.map +1 -1
  17. package/dist/react/index.d.cts +1 -1
  18. package/dist/react/index.d.ts +1 -1
  19. package/dist/resources/auth.cjs.map +1 -1
  20. package/dist/resources/auth.d.cts +1 -1
  21. package/dist/resources/auth.d.ts +1 -1
  22. package/dist/resources/auth.js.map +1 -1
  23. package/dist/resources/branding.cjs.map +1 -1
  24. package/dist/resources/branding.d.cts +6 -0
  25. package/dist/resources/branding.d.ts +6 -0
  26. package/dist/resources/branding.js.map +1 -1
  27. package/dist/resources/cards.cjs.map +1 -1
  28. package/dist/resources/cards.d.cts +1 -1
  29. package/dist/resources/cards.d.ts +1 -1
  30. package/dist/resources/cards.js.map +1 -1
  31. package/dist/resources/deposits.cjs.map +1 -1
  32. package/dist/resources/deposits.d.cts +1 -1
  33. package/dist/resources/deposits.d.ts +1 -1
  34. package/dist/resources/deposits.js.map +1 -1
  35. package/dist/resources/funding-options.d.cts +1 -1
  36. package/dist/resources/funding-options.d.ts +1 -1
  37. package/dist/resources/me.d.cts +1 -1
  38. package/dist/resources/me.d.ts +1 -1
  39. package/dist/telegram.cjs +20 -4
  40. package/dist/telegram.cjs.map +1 -1
  41. package/dist/telegram.d.cts +1 -1
  42. package/dist/telegram.d.ts +1 -1
  43. package/dist/telegram.js +20 -4
  44. package/dist/telegram.js.map +1 -1
  45. 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, ConfirmPasswordSetupInput, EmailChangeRequested, EmailCodeSent, EmailCodeSession, ExchangeTelegramInput, JwtIssued, LinkTelegramInput, LoginInput, LoginResponse, OtpSentResponse, PasswordSetupRequested, RegisterInput, RequestEmailCodeInput, Session, TelegramLink, TelegramUnknown, TotpRequired, TotpSetupComplete, TotpSetupEmailErrorCode, TotpSetupEmailInput, TotpSetupEmailRequired, TotpSetupRequired, User, VerifyEmailCodeInput } from './resources/auth.cjs';
5
- import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-DwxkVJUB.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, l as CardOrderQuote, m as CardOrderQuoteInput, C as CardProduct, n as CardProductPrice, o as CardStatus, p as CardStatusSource, q as CardTariff, r as CardTopUp, s as CardTopUpStatus, t as CardTransfer, u as CardType, v as Cardholder, w as CloseBlockedReason, x as CreateCardInput, y as CreateDepositRefundInput, z as CreateQuoteInput, E as CustomerInfo, D as Deposit, G as DepositMethod, H as DepositStatus, I as DepositTarget, J as FeeKind, K as FunderMode, L as FundingOption, M as FundingQuote, N as InitiateDepositInput, O as IssuanceBonus, P as IssueCardInput, Q as MethodTerms, R as PromoCodeQuote, S as PromoCodeStatus, T as Refund, U as RevealCardInput, V as RevealState, W as RevealedCard, X as SetPinInput, Y as TopUpInput, Z as TopUpResult, _ as TopUpTerms, $ as TransferInput, a0 as TransferResult, a1 as UpdateCardInput, a2 as priceChangedQuote, a3 as revealState } from './cards-DwxkVJUB.cjs';
5
+ import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-C5rk0XkI.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, l as CardOrderQuote, m as CardOrderQuoteInput, n as CardOrderRate, C as CardProduct, o as CardProductPrice, p as CardStatus, q as CardStatusSource, r as CardTariff, s as CardTopUp, t as CardTopUpStatus, u as CardTransfer, v as CardType, w as Cardholder, x as CloseBlockedReason, y as CreateCardInput, z as CreateDepositRefundInput, E as CreateQuoteInput, G as CustomerInfo, D as Deposit, H as DepositMethod, I as DepositStatus, J as DepositTarget, K as FeeKind, L as FunderMode, M as FundingOption, N as FundingQuote, O as InitiateDepositInput, P as IssuanceBonus, Q as IssueCardInput, R as MethodTerms, S as PromoCodeQuote, T as PromoCodeStatus, U as Refund, V as RevealCardInput, W as RevealState, X as RevealedCard, Y as SetPinInput, Z as TopUpInput, _ as TopUpResult, $ as TopUpTerms, a0 as TransferInput, a1 as TransferResult, a2 as UpdateCardInput, a3 as priceChangedQuote, a4 as revealState } from './cards-C5rk0XkI.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';
@@ -49,7 +49,7 @@ import { ReceiptsResource } from './resources/receipts.cjs';
49
49
  export { ListReceiptsParams, Receipt, ReceiptKind } from './resources/receipts.cjs';
50
50
  import { SupportResource } from './resources/support.cjs';
51
51
  export { SupportAttachment, SupportChannel, SupportConversation, SupportConversationStatus, SupportFile, SupportMessage, SupportMessageStatus, SupportRatingRequest } from './resources/support.cjs';
52
- export { ANALYTICS_EVENTS, AnalyticsEvent, AnalyticsOptions, AnalyticsProperties, AnalyticsZone, METRIKA_GOALS, MetrikaOptions, NO_CAPTURE_CLASS, PostHogLike, PostHogOptions, identify, initAnalytics, page, posthogDistinctId, resetAnalytics, sanitizeProperties, sanitizeUrl, setAnalyticsZone, track } from './analytics.cjs';
52
+ export { ANALYTICS_EVENTS, AnalyticsEvent, AnalyticsOptions, AnalyticsProperties, AnalyticsZone, MASK_TEXT_CLASS, METRIKA_GOALS, MetrikaOptions, NO_CAPTURE_CLASS, PostHogLike, PostHogOptions, ZONE_ATTRIBUTE, identify, initAnalytics, maskRecordedText, page, posthogDistinctId, resetAnalytics, sanitizeProperties, sanitizeUrl, setAnalyticsConsent, setAnalyticsZone, track } from './analytics.cjs';
53
53
 
54
54
  /**
55
55
  * Brand config — runtime-passed, not build-time-baked.
@@ -155,6 +155,10 @@ declare class ApiError extends Error {
155
155
  /** Full parsed response body when available. Carries field-level
156
156
  * validation details for `code = "validation"`. */
157
157
  readonly body?: unknown | undefined;
158
+ /** Seconds the server asked to wait before trying again (its
159
+ * `Retry-After` header), when it sent one. The SDK never retries by
160
+ * itself. */
161
+ readonly retryAfterSeconds?: number | undefined;
158
162
  readonly isApiError: true;
159
163
  constructor(
160
164
  /** HTTP status code returned by the Takeal API. */
@@ -168,7 +172,11 @@ declare class ApiError extends Error {
168
172
  message: string,
169
173
  /** Full parsed response body when available. Carries field-level
170
174
  * validation details for `code = "validation"`. */
171
- body?: unknown | undefined);
175
+ body?: unknown | undefined,
176
+ /** Seconds the server asked to wait before trying again (its
177
+ * `Retry-After` header), when it sent one. The SDK never retries by
178
+ * itself. */
179
+ retryAfterSeconds?: number | undefined);
172
180
  }
173
181
  declare class NetworkError extends Error {
174
182
  readonly cause?: unknown | undefined;
@@ -187,7 +195,7 @@ declare function isNetworkError(e: unknown): e is NetworkError;
187
195
  * `define`. `src/version.test.ts` checks it matches `package.json`, so a
188
196
  * release bump that forgets this file fails the test run.
189
197
  */
190
- declare const SDK_VERSION = "0.8.4";
198
+ declare const SDK_VERSION = "0.9.0";
191
199
 
192
200
  /**
193
201
  * `@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, ConfirmPasswordSetupInput, EmailChangeRequested, EmailCodeSent, EmailCodeSession, ExchangeTelegramInput, JwtIssued, LinkTelegramInput, LoginInput, LoginResponse, OtpSentResponse, PasswordSetupRequested, RegisterInput, RequestEmailCodeInput, Session, TelegramLink, TelegramUnknown, TotpRequired, TotpSetupComplete, TotpSetupEmailErrorCode, TotpSetupEmailInput, TotpSetupEmailRequired, TotpSetupRequired, User, VerifyEmailCodeInput } from './resources/auth.js';
5
- import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-VkS_2lPe.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, l as CardOrderQuote, m as CardOrderQuoteInput, C as CardProduct, n as CardProductPrice, o as CardStatus, p as CardStatusSource, q as CardTariff, r as CardTopUp, s as CardTopUpStatus, t as CardTransfer, u as CardType, v as Cardholder, w as CloseBlockedReason, x as CreateCardInput, y as CreateDepositRefundInput, z as CreateQuoteInput, E as CustomerInfo, D as Deposit, G as DepositMethod, H as DepositStatus, I as DepositTarget, J as FeeKind, K as FunderMode, L as FundingOption, M as FundingQuote, N as InitiateDepositInput, O as IssuanceBonus, P as IssueCardInput, Q as MethodTerms, R as PromoCodeQuote, S as PromoCodeStatus, T as Refund, U as RevealCardInput, V as RevealState, W as RevealedCard, X as SetPinInput, Y as TopUpInput, Z as TopUpResult, _ as TopUpTerms, $ as TransferInput, a0 as TransferResult, a1 as UpdateCardInput, a2 as priceChangedQuote, a3 as revealState } from './cards-VkS_2lPe.js';
5
+ import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-CS-oxqLS.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, l as CardOrderQuote, m as CardOrderQuoteInput, n as CardOrderRate, C as CardProduct, o as CardProductPrice, p as CardStatus, q as CardStatusSource, r as CardTariff, s as CardTopUp, t as CardTopUpStatus, u as CardTransfer, v as CardType, w as Cardholder, x as CloseBlockedReason, y as CreateCardInput, z as CreateDepositRefundInput, E as CreateQuoteInput, G as CustomerInfo, D as Deposit, H as DepositMethod, I as DepositStatus, J as DepositTarget, K as FeeKind, L as FunderMode, M as FundingOption, N as FundingQuote, O as InitiateDepositInput, P as IssuanceBonus, Q as IssueCardInput, R as MethodTerms, S as PromoCodeQuote, T as PromoCodeStatus, U as Refund, V as RevealCardInput, W as RevealState, X as RevealedCard, Y as SetPinInput, Z as TopUpInput, _ as TopUpResult, $ as TopUpTerms, a0 as TransferInput, a1 as TransferResult, a2 as UpdateCardInput, a3 as priceChangedQuote, a4 as revealState } from './cards-CS-oxqLS.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';
@@ -49,7 +49,7 @@ import { ReceiptsResource } from './resources/receipts.js';
49
49
  export { ListReceiptsParams, Receipt, ReceiptKind } from './resources/receipts.js';
50
50
  import { SupportResource } from './resources/support.js';
51
51
  export { SupportAttachment, SupportChannel, SupportConversation, SupportConversationStatus, SupportFile, SupportMessage, SupportMessageStatus, SupportRatingRequest } from './resources/support.js';
52
- export { ANALYTICS_EVENTS, AnalyticsEvent, AnalyticsOptions, AnalyticsProperties, AnalyticsZone, METRIKA_GOALS, MetrikaOptions, NO_CAPTURE_CLASS, PostHogLike, PostHogOptions, identify, initAnalytics, page, posthogDistinctId, resetAnalytics, sanitizeProperties, sanitizeUrl, setAnalyticsZone, track } from './analytics.js';
52
+ export { ANALYTICS_EVENTS, AnalyticsEvent, AnalyticsOptions, AnalyticsProperties, AnalyticsZone, MASK_TEXT_CLASS, METRIKA_GOALS, MetrikaOptions, NO_CAPTURE_CLASS, PostHogLike, PostHogOptions, ZONE_ATTRIBUTE, identify, initAnalytics, maskRecordedText, page, posthogDistinctId, resetAnalytics, sanitizeProperties, sanitizeUrl, setAnalyticsConsent, setAnalyticsZone, track } from './analytics.js';
53
53
 
54
54
  /**
55
55
  * Brand config — runtime-passed, not build-time-baked.
@@ -155,6 +155,10 @@ declare class ApiError extends Error {
155
155
  /** Full parsed response body when available. Carries field-level
156
156
  * validation details for `code = "validation"`. */
157
157
  readonly body?: unknown | undefined;
158
+ /** Seconds the server asked to wait before trying again (its
159
+ * `Retry-After` header), when it sent one. The SDK never retries by
160
+ * itself. */
161
+ readonly retryAfterSeconds?: number | undefined;
158
162
  readonly isApiError: true;
159
163
  constructor(
160
164
  /** HTTP status code returned by the Takeal API. */
@@ -168,7 +172,11 @@ declare class ApiError extends Error {
168
172
  message: string,
169
173
  /** Full parsed response body when available. Carries field-level
170
174
  * validation details for `code = "validation"`. */
171
- body?: unknown | undefined);
175
+ body?: unknown | undefined,
176
+ /** Seconds the server asked to wait before trying again (its
177
+ * `Retry-After` header), when it sent one. The SDK never retries by
178
+ * itself. */
179
+ retryAfterSeconds?: number | undefined);
172
180
  }
173
181
  declare class NetworkError extends Error {
174
182
  readonly cause?: unknown | undefined;
@@ -187,7 +195,7 @@ declare function isNetworkError(e: unknown): e is NetworkError;
187
195
  * `define`. `src/version.test.ts` checks it matches `package.json`, so a
188
196
  * release bump that forgets this file fails the test run.
189
197
  */
190
- declare const SDK_VERSION = "0.8.4";
198
+ declare const SDK_VERSION = "0.9.0";
191
199
 
192
200
  /**
193
201
  * `@takeal/cusfront-sdk` — typed client for the Takeal end-user API.
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  // src/error.ts
2
2
  var ApiError = class extends Error {
3
- constructor(status, code, message, body) {
3
+ constructor(status, code, message, body, retryAfterSeconds) {
4
4
  super(message);
5
5
  this.status = status;
6
6
  this.code = code;
7
7
  this.body = body;
8
+ this.retryAfterSeconds = retryAfterSeconds;
8
9
  this.isApiError = true;
9
10
  this.name = "ApiError";
10
11
  }
@@ -139,11 +140,20 @@ async function parseResponse(resp) {
139
140
  resp.status,
140
141
  errBody.code ?? `http_${resp.status}`,
141
142
  errBody.message ?? resp.statusText ?? "request failed",
142
- body
143
+ body,
144
+ retryAfter(resp.headers?.get("Retry-After"))
143
145
  );
144
146
  }
145
147
  return body;
146
148
  }
149
+ function retryAfter(v, now = Date.now()) {
150
+ if (!v) return void 0;
151
+ const t = v.trim();
152
+ if (/^\d+$/.test(t)) return Number(t);
153
+ const at = Date.parse(t);
154
+ if (Number.isNaN(at)) return void 0;
155
+ return Math.max(0, Math.ceil((at - now) / 1e3));
156
+ }
147
157
 
148
158
  // src/resources/attribution.ts
149
159
  var AttributionResource = class {
@@ -1806,7 +1816,7 @@ var FundingOptionsResource = class {
1806
1816
  };
1807
1817
 
1808
1818
  // src/version.ts
1809
- var SDK_VERSION = "0.8.4";
1819
+ var SDK_VERSION = "0.9.0";
1810
1820
 
1811
1821
  // src/client-platform.ts
1812
1822
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1943,12 +1953,18 @@ function readyInfo(raw, healthy) {
1943
1953
  }
1944
1954
  return { ...base, compatible: true };
1945
1955
  }
1956
+ function isReadyBody(body) {
1957
+ if (typeof body !== "object" || body === null || Array.isArray(body)) return false;
1958
+ const b = body;
1959
+ const block = (v) => typeof v === "object" && v !== null;
1960
+ return b.code !== "service_unavailable" && typeof b.status === "string" && (block(b.checks) || block(b.ops));
1961
+ }
1946
1962
  async function fetchReady(http, opts = {}) {
1947
1963
  try {
1948
1964
  const body = await http.get("/ready", { skipAuth: true, signal: opts.signal });
1949
1965
  return readyInfo(body ?? {}, true);
1950
1966
  } catch (e) {
1951
- if (isApiError(e) && e.status === 503 && typeof e.body === "object" && e.body !== null) {
1967
+ if (isApiError(e) && e.status === 503 && isReadyBody(e.body)) {
1952
1968
  return readyInfo(e.body, false);
1953
1969
  }
1954
1970
  throw e;
@@ -1982,6 +1998,8 @@ var ANALYTICS_EVENTS = [
1982
1998
  ];
1983
1999
  var METRIKA_GOALS = ["signup_started", "signup_completed"];
1984
2000
  var NO_CAPTURE_CLASS = "ph-no-capture";
2001
+ var MASK_TEXT_CLASS = "ph-mask";
2002
+ var ZONE_ATTRIBUTE = "data-analytics-zone";
1985
2003
  var UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
1986
2004
  var EMAIL = /[^\s@"'<>(),;:]+@[^\s@"'<>(),;:]+\.[a-z]{2,}/gi;
1987
2005
  var DIGIT_RUN = /\+?\d[\d\s().-]{7,}\d/g;
@@ -2247,18 +2265,38 @@ function posthogConfig(zone, o) {
2247
2265
  // Page views go through `page()`, with a cleaned address.
2248
2266
  capture_pageview: false,
2249
2267
  capture_pageleave: true,
2250
- before_send: beforeSend
2268
+ before_send: beforeSend,
2269
+ // Set once. A zone change never touches these: posthog-js hands the
2270
+ // recording options to rrweb when the recorder starts, and changing
2271
+ // `disable_session_recording` stops or restarts it.
2272
+ disable_session_recording: !o.sessionRecording,
2273
+ session_recording: recordingOptions()
2274
+ };
2275
+ return { ...base, ...zoneConfig(zone) };
2276
+ }
2277
+ function recordingOptions() {
2278
+ return {
2279
+ maskAllInputs: true,
2280
+ maskTextSelector: "*",
2281
+ maskTextFn: maskRecordedText,
2282
+ blockClass: NO_CAPTURE_CLASS
2251
2283
  };
2252
- return { ...base, ...zoneConfig(zone, o) };
2253
2284
  }
2254
- function zoneConfig(zone, o) {
2285
+ var PRIVATE_BLOCK = `.${MASK_TEXT_CLASS}, [${ZONE_ATTRIBUTE}]:not([${ZONE_ATTRIBUTE}="public"])`;
2286
+ function maskRecordedText(text, element) {
2287
+ try {
2288
+ if (state()?.zone === "public" && !element?.closest(PRIVATE_BLOCK)) return text;
2289
+ } catch {
2290
+ }
2291
+ return text.replace(/\S/g, "*");
2292
+ }
2293
+ function zoneConfig(zone) {
2255
2294
  if (zone === "public") {
2256
2295
  return {
2257
2296
  autocapture: true,
2258
2297
  mask_all_text: false,
2259
2298
  mask_all_element_attributes: false,
2260
- enable_heatmaps: true,
2261
- disable_session_recording: true
2299
+ enable_heatmaps: true
2262
2300
  };
2263
2301
  }
2264
2302
  return {
@@ -2266,13 +2304,7 @@ function zoneConfig(zone, o) {
2266
2304
  autocapture: { capture_copied_text: false },
2267
2305
  mask_all_text: true,
2268
2306
  mask_all_element_attributes: true,
2269
- enable_heatmaps: false,
2270
- disable_session_recording: !o.sessionRecording,
2271
- session_recording: {
2272
- maskAllInputs: true,
2273
- maskTextSelector: "*",
2274
- blockClass: NO_CAPTURE_CLASS
2275
- }
2307
+ enable_heatmaps: false
2276
2308
  };
2277
2309
  }
2278
2310
  function assetsHost(o) {
@@ -2331,16 +2363,26 @@ var PostHogSink = class {
2331
2363
  }
2332
2364
  setZone(zone) {
2333
2365
  this.with((ph) => {
2334
- ph.set_config(zoneConfig(zone, this.o));
2366
+ ph.set_config(zoneConfig(zone));
2335
2367
  ph.register({ zone });
2336
- if (zone === "public" || !this.o.sessionRecording) ph.stopSessionRecording?.();
2337
- else ph.startSessionRecording?.();
2368
+ });
2369
+ }
2370
+ setConsent(granted) {
2371
+ this.with((ph) => {
2372
+ if (granted) {
2373
+ ph.opt_in_capturing?.();
2374
+ if (this.o.sessionRecording) ph.startSessionRecording?.();
2375
+ } else {
2376
+ ph.stopSessionRecording?.();
2377
+ ph.opt_out_capturing?.();
2378
+ }
2338
2379
  });
2339
2380
  }
2340
2381
  };
2341
2382
  var MetrikaSink = class {
2342
2383
  constructor(o) {
2343
2384
  this.live = true;
2385
+ this.consented = true;
2344
2386
  this.id = Number(o.counterId);
2345
2387
  const w = win();
2346
2388
  if (!w.ym) {
@@ -2363,7 +2405,7 @@ var MetrikaSink = class {
2363
2405
  });
2364
2406
  }
2365
2407
  ym(...args) {
2366
- if (this.live) win().ym?.(this.id, ...args);
2408
+ if (this.live && this.consented) win().ym?.(this.id, ...args);
2367
2409
  }
2368
2410
  capture(event, props) {
2369
2411
  if (METRIKA_GOALS.includes(event)) this.ym("reachGoal", event, props);
@@ -2379,16 +2421,27 @@ var MetrikaSink = class {
2379
2421
  setZone(zone) {
2380
2422
  this.live = zone === "public";
2381
2423
  }
2424
+ setConsent(granted) {
2425
+ this.consented = granted;
2426
+ }
2382
2427
  };
2383
2428
  var KEY = /* @__PURE__ */ Symbol.for("takeal.cusfront-sdk.analytics");
2384
2429
  var holder = globalThis;
2385
2430
  var state = () => holder[KEY];
2431
+ function loaded(s) {
2432
+ return [s.posthog, s.metrika].filter((x) => !!x);
2433
+ }
2386
2434
  function sinks(s) {
2435
+ if (!s.consent) return [];
2436
+ if (s.options.posthog?.key && !s.posthog) {
2437
+ s.posthog = new PostHogSink(s.options.posthog, s.zone);
2438
+ if (s.userId) s.posthog.identify(s.userId);
2439
+ }
2387
2440
  if (s.zone === "public" && s.options.metrika && !s.metrika) {
2388
2441
  s.metrika = new MetrikaSink(s.options.metrika);
2389
2442
  if (s.userId) s.metrika.identify(s.userId);
2390
2443
  }
2391
- return [s.posthog, s.metrika].filter((x) => !!x);
2444
+ return loaded(s);
2392
2445
  }
2393
2446
  function initAnalytics(options) {
2394
2447
  if (state() || !win().document) return;
@@ -2397,17 +2450,28 @@ function initAnalytics(options) {
2397
2450
  "[analytics] Yandex Metrica is on a page outside the public zone; it must not be."
2398
2451
  );
2399
2452
  }
2400
- const s = { options, zone: options.zone };
2453
+ const s = { options, zone: options.zone, consent: options.consent !== false };
2401
2454
  holder[KEY] = s;
2402
- if (options.posthog?.key) s.posthog = new PostHogSink(options.posthog, options.zone);
2403
2455
  sinks(s);
2404
2456
  if (options.initialPageview !== false) page();
2405
2457
  }
2458
+ function setAnalyticsConsent(granted) {
2459
+ const s = state();
2460
+ if (!s || s.consent === granted) return;
2461
+ s.consent = granted;
2462
+ const before = loaded(s);
2463
+ for (const sink of before) sink.setConsent(granted);
2464
+ if (granted) {
2465
+ sinks(s);
2466
+ if (s.lastPage === void 0 && s.options.initialPageview !== false) page();
2467
+ }
2468
+ }
2406
2469
  function setAnalyticsZone(zone) {
2407
2470
  const s = state();
2408
2471
  if (!s || s.zone === zone) return;
2409
2472
  s.zone = zone;
2410
- for (const sink of sinks(s)) sink.setZone(zone);
2473
+ sinks(s);
2474
+ for (const sink of loaded(s)) sink.setZone(zone);
2411
2475
  }
2412
2476
  function track(event, props = {}) {
2413
2477
  const s = state();
@@ -2419,7 +2483,7 @@ function page(url) {
2419
2483
  const s = state();
2420
2484
  const w = win();
2421
2485
  const raw = url ?? w.location?.href;
2422
- if (!s || !raw) return;
2486
+ if (!s || !s.consent || !raw) return;
2423
2487
  const clean2 = sanitizeUrl(raw);
2424
2488
  if (clean2 === s.lastPage) return;
2425
2489
  const referrer = s.lastPage ?? (w.document?.referrer ? sanitizeUrl(w.document.referrer) : void 0);
@@ -2436,7 +2500,7 @@ function resetAnalytics() {
2436
2500
  const s = state();
2437
2501
  if (!s) return;
2438
2502
  s.userId = void 0;
2439
- for (const sink of sinks(s)) sink.reset();
2503
+ for (const sink of loaded(s)) sink.reset();
2440
2504
  }
2441
2505
  async function posthogDistinctId(timeoutMs = 3e3) {
2442
2506
  const ready = state()?.posthog?.ready;
@@ -2513,6 +2577,6 @@ function defaultFetch() {
2513
2577
  );
2514
2578
  }
2515
2579
 
2516
- 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, priceChangedQuote, rememberAnalyticsIds, resetAnalytics, resolveAssetUrl, revealState, sanitizeProperties, sanitizeUrl, satisfies, setAnalyticsZone, track, withAnalyticsIds };
2580
+ export { ANALYTICS_EVENTS, ApiError, CLIENT_HEADER, DISPUTE_DOCUMENTS_CONSENT, HOLDER_DATA_CONSENT, MASK_TEXT_CLASS, METRIKA_GOALS, NO_CAPTURE_CLASS, NetworkError, SDK_VERSION, SUPPORTED_MEISTER, ZONE_ATTRIBUTE, analyticsIds, anonymousKey, createClient, currentTouch, defaultBrowserStore, detectClientPlatform, forgetAnalyticsIds, identify, inMemoryStore, initAnalytics, isApiError, isCardOtp, isNetworkError, maskRecordedText, page, posthogDistinctId, priceChangedQuote, rememberAnalyticsIds, resetAnalytics, resolveAssetUrl, revealState, sanitizeProperties, sanitizeUrl, satisfies, setAnalyticsConsent, setAnalyticsZone, track, withAnalyticsIds };
2517
2581
  //# sourceMappingURL=index.js.map
2518
2582
  //# sourceMappingURL=index.js.map