@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.
- package/CHANGELOG.md +112 -2
- package/README.md +26 -9
- package/dist/analytics.cjs +44 -6
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.js +44 -6
- package/dist/analytics.js.map +1 -1
- package/dist/{cards-BgY00UpU.d.ts → cards-DPlgx76p.d.ts} +86 -18
- package/dist/{cards-DGz4Rqu1.d.cts → cards-D_krTWzr.d.cts} +86 -18
- package/dist/index.cjs +225 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +221 -94
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/resources/attribution.cjs +99 -4
- package/dist/resources/attribution.cjs.map +1 -1
- package/dist/resources/attribution.d.cts +58 -1
- package/dist/resources/attribution.d.ts +58 -1
- package/dist/resources/attribution.js +96 -5
- package/dist/resources/attribution.js.map +1 -1
- package/dist/resources/auth.cjs +64 -3
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +1 -1
- package/dist/resources/auth.d.ts +1 -1
- package/dist/resources/auth.js +64 -3
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/cards.cjs +69 -7
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +2 -1
- package/dist/resources/cards.d.ts +2 -1
- package/dist/resources/cards.js +69 -8
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/codes.cjs.map +1 -1
- package/dist/resources/codes.d.cts +21 -1
- package/dist/resources/codes.d.ts +21 -1
- package/dist/resources/codes.js.map +1 -1
- package/dist/resources/consents.cjs +15 -0
- package/dist/resources/consents.cjs.map +1 -1
- package/dist/resources/consents.js +15 -0
- package/dist/resources/consents.js.map +1 -1
- package/dist/resources/deposits.cjs +50 -0
- package/dist/resources/deposits.cjs.map +1 -1
- package/dist/resources/deposits.d.cts +2 -1
- package/dist/resources/deposits.d.ts +2 -1
- package/dist/resources/deposits.js +50 -0
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/funding-options.d.cts +2 -1
- package/dist/resources/funding-options.d.ts +2 -1
- package/dist/resources/me.d.cts +1 -1
- package/dist/resources/me.d.ts +1 -1
- package/dist/telegram.cjs +224 -73
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +34 -3
- package/dist/telegram.d.ts +34 -3
- package/dist/telegram.js +224 -74
- package/dist/telegram.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -147,6 +147,172 @@ async function parseResponse(resp) {
|
|
|
147
147
|
return body;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
// src/resources/attribution.ts
|
|
151
|
+
var AttributionResource = class {
|
|
152
|
+
constructor(http) {
|
|
153
|
+
this.http = http;
|
|
154
|
+
}
|
|
155
|
+
/** Record a visit. No session needed; safe to call on every page load. */
|
|
156
|
+
async touch(input) {
|
|
157
|
+
return this.http.post("/attribution/touches", { body: input, skipAuth: true });
|
|
158
|
+
}
|
|
159
|
+
/** A one-day token that carries the visitor's analytics ids into the
|
|
160
|
+
* Telegram Mini App, whose sign-in reads it back. Most callers want
|
|
161
|
+
* {@link AttributionResource.telegramStartParam}. Errors: 400 when none of
|
|
162
|
+
* the ids is valid. */
|
|
163
|
+
async handoff(ids) {
|
|
164
|
+
return this.http.post("/attribution/handoff", { body: ids, skipAuth: true });
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The `startapp` value for a link from the site to the Mini App: the code
|
|
168
|
+
* as it is, followed by `__<token>` when the visitor has analytics ids, so
|
|
169
|
+
* a payment made in Telegram is still credited to the visit it came from.
|
|
170
|
+
* Without ids, or when the token can't be had, just the code.
|
|
171
|
+
*
|
|
172
|
+
* ```ts
|
|
173
|
+
* const start = await client.attribution.telegramStartParam("SPRING");
|
|
174
|
+
* location.href = `https://t.me/our_bot/app?startapp=${start}`;
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
async telegramStartParam(code = "") {
|
|
178
|
+
const ids = analyticsIds();
|
|
179
|
+
if (!ids) return code;
|
|
180
|
+
try {
|
|
181
|
+
const { token } = await this.handoff(ids);
|
|
182
|
+
return `${code}__${token}`;
|
|
183
|
+
} catch {
|
|
184
|
+
return code;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** Send the visitor's analytics ids for the signed-in account, e.g. right
|
|
188
|
+
* after they agreed to analytics cookies in the cabinet. Without an
|
|
189
|
+
* argument the ids this browser holds are sent; nothing is sent when it
|
|
190
|
+
* holds none. */
|
|
191
|
+
async sendAnalyticsIds(ids = analyticsIds()) {
|
|
192
|
+
if (!ids) return;
|
|
193
|
+
await this.http.post("/me/analytics/ids", { body: ids });
|
|
194
|
+
}
|
|
195
|
+
/** Whether to ask the signed-in user how they heard about us. */
|
|
196
|
+
async status() {
|
|
197
|
+
return this.http.get("/me/attribution");
|
|
198
|
+
}
|
|
199
|
+
/** Answer the question once. Send `"skipped"` when the user closes it.
|
|
200
|
+
* `otherText` is kept only with `"other"`, up to 500 characters.
|
|
201
|
+
* Errors: 400 `validation`, 409 `survey_answered`. */
|
|
202
|
+
async answerSurvey(answer, otherText) {
|
|
203
|
+
const body = { answer };
|
|
204
|
+
if (otherText !== void 0) body.other_text = otherText;
|
|
205
|
+
return this.http.put("/me/attribution/survey", { body });
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function tgWebApp() {
|
|
209
|
+
return globalThis.Telegram?.WebApp?.initDataUnsafe;
|
|
210
|
+
}
|
|
211
|
+
function readCookie(name) {
|
|
212
|
+
const doc = globalThis.document;
|
|
213
|
+
if (!doc?.cookie) return void 0;
|
|
214
|
+
for (const part of doc.cookie.split(";")) {
|
|
215
|
+
const [k, ...v] = part.trim().split("=");
|
|
216
|
+
if (k === name) return decodeURIComponent(v.join("="));
|
|
217
|
+
}
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
|
|
221
|
+
function anonymousKey(opts = {}) {
|
|
222
|
+
const tgId = tgWebApp()?.user?.id;
|
|
223
|
+
if (tgId) return `tg:${tgId}`;
|
|
224
|
+
const g = globalThis;
|
|
225
|
+
if (!g.document) return void 0;
|
|
226
|
+
const name = opts.name ?? "takeal_anon";
|
|
227
|
+
let stored2;
|
|
228
|
+
try {
|
|
229
|
+
stored2 = g.localStorage?.getItem(name) ?? void 0;
|
|
230
|
+
} catch {
|
|
231
|
+
stored2 = void 0;
|
|
232
|
+
}
|
|
233
|
+
const fromCookie = readCookie(name);
|
|
234
|
+
let key = [fromCookie, stored2].find((k) => !!k && KEY_SHAPE.test(k));
|
|
235
|
+
if (!key) {
|
|
236
|
+
key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
g.localStorage?.setItem(name, key);
|
|
240
|
+
} catch {
|
|
241
|
+
}
|
|
242
|
+
const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
|
|
243
|
+
g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
|
|
244
|
+
return key;
|
|
245
|
+
}
|
|
246
|
+
function currentTouch() {
|
|
247
|
+
const g = globalThis;
|
|
248
|
+
const tg = tgWebApp();
|
|
249
|
+
const out = {};
|
|
250
|
+
if (g.location?.href) out.url = g.location.href;
|
|
251
|
+
if (g.document?.referrer) out.referrer = g.document.referrer;
|
|
252
|
+
if (tg?.start_param) out.campaign_code = tg.start_param;
|
|
253
|
+
if (tg?.user?.id) out.platform = "miniapp";
|
|
254
|
+
const ym = readCookie("_ym_uid");
|
|
255
|
+
if (ym) out.metrika_client_id = ym;
|
|
256
|
+
const ga = readCookie("_ga")?.split(".").slice(-2).join(".");
|
|
257
|
+
if (ga) out.ga_client_id = ga;
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
var IDS_KEY = "takeal_analytics_ids";
|
|
261
|
+
function storage() {
|
|
262
|
+
try {
|
|
263
|
+
return globalThis.localStorage;
|
|
264
|
+
} catch {
|
|
265
|
+
return void 0;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function stored() {
|
|
269
|
+
try {
|
|
270
|
+
const raw = storage()?.getItem(IDS_KEY);
|
|
271
|
+
const v = raw ? JSON.parse(raw) : {};
|
|
272
|
+
return typeof v === "object" && v !== null ? v : {};
|
|
273
|
+
} catch {
|
|
274
|
+
return {};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function clean(ids) {
|
|
278
|
+
const out = {};
|
|
279
|
+
const ym = ids.metrika_client_id?.trim();
|
|
280
|
+
if (ym && /^\d{1,32}$/.test(ym)) out.metrika_client_id = ym;
|
|
281
|
+
const ga = ids.ga_client_id?.trim();
|
|
282
|
+
if (ga && /^\d+\.\d+$/.test(ga) && ga.length <= 64) out.ga_client_id = ga;
|
|
283
|
+
return out.metrika_client_id || out.ga_client_id ? out : void 0;
|
|
284
|
+
}
|
|
285
|
+
function rememberAnalyticsIds(ids) {
|
|
286
|
+
const merged = clean({ ...stored(), ...ids });
|
|
287
|
+
if (!merged) return;
|
|
288
|
+
try {
|
|
289
|
+
storage()?.setItem(IDS_KEY, JSON.stringify(merged));
|
|
290
|
+
} catch {
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function forgetAnalyticsIds() {
|
|
294
|
+
try {
|
|
295
|
+
storage()?.removeItem(IDS_KEY);
|
|
296
|
+
} catch {
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function analyticsIds() {
|
|
300
|
+
const kept = stored();
|
|
301
|
+
return clean({
|
|
302
|
+
metrika_client_id: kept.metrika_client_id ?? readCookie("_ym_uid"),
|
|
303
|
+
ga_client_id: kept.ga_client_id ?? readCookie("_ga")?.split(".").slice(-2).join(".")
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function withAnalyticsIds(attribution) {
|
|
307
|
+
const ids = analyticsIds();
|
|
308
|
+
if (!ids) return attribution;
|
|
309
|
+
return {
|
|
310
|
+
...attribution,
|
|
311
|
+
metrika_client_id: attribution?.metrika_client_id ?? ids.metrika_client_id,
|
|
312
|
+
ga_client_id: attribution?.ga_client_id ?? ids.ga_client_id
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
150
316
|
// src/resources/cards.ts
|
|
151
317
|
function cardRequestBody(input) {
|
|
152
318
|
const {
|
|
@@ -185,8 +351,15 @@ function cardOrderBody(input) {
|
|
|
185
351
|
if (input.consents !== void 0) body["consents"] = input.consents;
|
|
186
352
|
if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
|
|
187
353
|
if (input.metadata !== void 0) body["metadata"] = input.metadata;
|
|
354
|
+
const ids = input.analyticsIds ?? analyticsIds();
|
|
355
|
+
if (ids !== void 0) body["analytics_ids"] = ids;
|
|
188
356
|
return body;
|
|
189
357
|
}
|
|
358
|
+
function revealState(r) {
|
|
359
|
+
if (r.details_pending) return "pending";
|
|
360
|
+
if (r.reveal_url) return "page";
|
|
361
|
+
return "numbers";
|
|
362
|
+
}
|
|
190
363
|
var CardsResource = class {
|
|
191
364
|
constructor(http) {
|
|
192
365
|
this.http = http;
|
|
@@ -214,8 +387,10 @@ var CardsResource = class {
|
|
|
214
387
|
* `idempotencyKey` returns the same order.
|
|
215
388
|
* Errors: 400 `unknown_product` / `method_not_available` / a limit of the
|
|
216
389
|
* way of paying, 409 `holder_data_consent_required` (the product has
|
|
217
|
-
* `holder_data_required` and the user has not agreed to it),
|
|
218
|
-
*
|
|
390
|
+
* `holder_data_required` and the user has not agreed to it), 409
|
|
391
|
+
* `payments_on_hold` (a payment on this account was not accepted and new
|
|
392
|
+
* ones wait until support sorts it out: show the message and point the
|
|
393
|
+
* user to support), 503 no funding connector or no exchange rate.
|
|
219
394
|
*/
|
|
220
395
|
async order(input) {
|
|
221
396
|
const { idempotencyKey, ...order } = input;
|
|
@@ -229,7 +404,9 @@ var CardsResource = class {
|
|
|
229
404
|
* (`is_default` marks the one issued when none is chosen). Each item
|
|
230
405
|
* carries its product card (name, tagline, benefits, tile picture),
|
|
231
406
|
* artwork, and the issuance price after the caller's subscription
|
|
232
|
-
* discount, in the
|
|
407
|
+
* discount, in the currency the operator set it in (`price.from_wallet`
|
|
408
|
+
* is the same price from the wallet, when that holds another currency).
|
|
409
|
+
* Pass an item's `id` as
|
|
233
410
|
* `productId` to {@link create}.
|
|
234
411
|
*/
|
|
235
412
|
async listProducts() {
|
|
@@ -342,15 +519,22 @@ var CardsResource = class {
|
|
|
342
519
|
* keep the result in volatile memory only, never write it to
|
|
343
520
|
* localStorage / logs, and clear it within `expires_in_seconds`.
|
|
344
521
|
*
|
|
345
|
-
*
|
|
346
|
-
* when the issuer shows them on a
|
|
347
|
-
* frame right away, it is
|
|
522
|
+
* `state` tells the three answers apart: `numbers`; `page`, with
|
|
523
|
+
* `reveal_url` and empty `pan` and `cvv` when the issuer shows them on a
|
|
524
|
+
* page of its own (open that page in a frame right away, it is
|
|
525
|
+
* short-lived); or `pending` while the card's details are still being
|
|
526
|
+
* prepared, which doesn't count against the limit. A card says the same
|
|
527
|
+
* in {@link Card.details_pending}, so there is no need to call this just
|
|
528
|
+
* to find out.
|
|
348
529
|
*
|
|
349
530
|
* 403 not your card · 409 `card_locked` · 429 rate-limited · 501 connector
|
|
350
531
|
* has no sensitive-data endpoint · 503 `provider_unavailable`.
|
|
351
532
|
*/
|
|
352
533
|
async reveal(id, _input) {
|
|
353
|
-
|
|
534
|
+
const r = await this.http.post(
|
|
535
|
+
`/me/cards/${encodeURIComponent(id)}/reveal`
|
|
536
|
+
);
|
|
537
|
+
return { ...r, state: revealState(r) };
|
|
354
538
|
}
|
|
355
539
|
/**
|
|
356
540
|
* Unfreeze a previously-frozen card. Idempotent on an already-active card.
|
|
@@ -467,8 +651,11 @@ var AuthResource = class {
|
|
|
467
651
|
/** Password-auth entry. May resolve to a JWT, or to a step-up
|
|
468
652
|
* challenge that needs `verifyTotp` / `verifyOtp` next. */
|
|
469
653
|
async login(input) {
|
|
654
|
+
const body = withRemember(input);
|
|
655
|
+
const attribution = withAnalyticsIds(void 0);
|
|
656
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
470
657
|
const resp = await this.http.post("/auth/login", {
|
|
471
|
-
body
|
|
658
|
+
body,
|
|
472
659
|
skipAuth: true
|
|
473
660
|
});
|
|
474
661
|
if (resp.stage === "jwt") {
|
|
@@ -505,6 +692,8 @@ var AuthResource = class {
|
|
|
505
692
|
async register(input) {
|
|
506
693
|
const { cardOrder, ...rest } = input;
|
|
507
694
|
const body = withRemember(rest);
|
|
695
|
+
const attribution = withAnalyticsIds(rest.attribution);
|
|
696
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
508
697
|
if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
|
|
509
698
|
const resp = await this.http.post("/auth/register", {
|
|
510
699
|
body,
|
|
@@ -540,7 +729,8 @@ var AuthResource = class {
|
|
|
540
729
|
};
|
|
541
730
|
if (input.remember) body["remember_me"] = true;
|
|
542
731
|
if (input.walletCurrency !== void 0) body["wallet_currency"] = input.walletCurrency;
|
|
543
|
-
|
|
732
|
+
const attribution = withAnalyticsIds(input.attribution);
|
|
733
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
544
734
|
if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
|
|
545
735
|
if (input.consents !== void 0) body["consents"] = input.consents;
|
|
546
736
|
if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
|
|
@@ -586,7 +776,8 @@ var AuthResource = class {
|
|
|
586
776
|
init_data: input.initData
|
|
587
777
|
};
|
|
588
778
|
if (input.provision !== void 0) body.provision = input.provision;
|
|
589
|
-
|
|
779
|
+
const attribution = withAnalyticsIds(input.attribution);
|
|
780
|
+
if (attribution !== void 0) body.attribution = attribution;
|
|
590
781
|
if (input.code !== void 0) body.code = input.code;
|
|
591
782
|
if (input.consents !== void 0) body.consents = input.consents;
|
|
592
783
|
if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
|
|
@@ -692,10 +883,17 @@ var DepositsResource = class {
|
|
|
692
883
|
if (connectorSlug !== void 0) body["connector_slug"] = connectorSlug;
|
|
693
884
|
return this.http.post("/me/deposits/quotes", { body });
|
|
694
885
|
}
|
|
886
|
+
/**
|
|
887
|
+
* Start a top-up. 409 `payments_on_hold`: a payment on this account was
|
|
888
|
+
* not accepted and new ones wait until support sorts it out. Show the
|
|
889
|
+
* message as it comes and point the user to support.
|
|
890
|
+
*/
|
|
695
891
|
async initiate(input) {
|
|
696
892
|
const { idempotencyKey, issue_card, ...rest } = input;
|
|
697
893
|
const body = { ...rest };
|
|
698
894
|
if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
|
|
895
|
+
const ids = input.analytics_ids ?? analyticsIds();
|
|
896
|
+
if (ids !== void 0) body["analytics_ids"] = ids;
|
|
699
897
|
return this.http.post("/me/deposits", {
|
|
700
898
|
body,
|
|
701
899
|
idempotencyKey
|
|
@@ -1300,81 +1498,6 @@ var DevicesResource = class {
|
|
|
1300
1498
|
}
|
|
1301
1499
|
};
|
|
1302
1500
|
|
|
1303
|
-
// src/resources/attribution.ts
|
|
1304
|
-
var AttributionResource = class {
|
|
1305
|
-
constructor(http) {
|
|
1306
|
-
this.http = http;
|
|
1307
|
-
}
|
|
1308
|
-
/** Record a visit. No session needed; safe to call on every page load. */
|
|
1309
|
-
async touch(input) {
|
|
1310
|
-
return this.http.post("/attribution/touches", { body: input, skipAuth: true });
|
|
1311
|
-
}
|
|
1312
|
-
/** Whether to ask the signed-in user how they heard about us. */
|
|
1313
|
-
async status() {
|
|
1314
|
-
return this.http.get("/me/attribution");
|
|
1315
|
-
}
|
|
1316
|
-
/** Answer the question once. Send `"skipped"` when the user closes it.
|
|
1317
|
-
* `otherText` is kept only with `"other"`, up to 500 characters.
|
|
1318
|
-
* Errors: 400 `validation`, 409 `survey_answered`. */
|
|
1319
|
-
async answerSurvey(answer, otherText) {
|
|
1320
|
-
const body = { answer };
|
|
1321
|
-
if (otherText !== void 0) body.other_text = otherText;
|
|
1322
|
-
return this.http.put("/me/attribution/survey", { body });
|
|
1323
|
-
}
|
|
1324
|
-
};
|
|
1325
|
-
function tgWebApp() {
|
|
1326
|
-
return globalThis.Telegram?.WebApp?.initDataUnsafe;
|
|
1327
|
-
}
|
|
1328
|
-
function readCookie(name) {
|
|
1329
|
-
const doc = globalThis.document;
|
|
1330
|
-
if (!doc?.cookie) return void 0;
|
|
1331
|
-
for (const part of doc.cookie.split(";")) {
|
|
1332
|
-
const [k, ...v] = part.trim().split("=");
|
|
1333
|
-
if (k === name) return decodeURIComponent(v.join("="));
|
|
1334
|
-
}
|
|
1335
|
-
return void 0;
|
|
1336
|
-
}
|
|
1337
|
-
var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
|
|
1338
|
-
function anonymousKey(opts = {}) {
|
|
1339
|
-
const tgId = tgWebApp()?.user?.id;
|
|
1340
|
-
if (tgId) return `tg:${tgId}`;
|
|
1341
|
-
const g = globalThis;
|
|
1342
|
-
if (!g.document) return void 0;
|
|
1343
|
-
const name = opts.name ?? "takeal_anon";
|
|
1344
|
-
let stored;
|
|
1345
|
-
try {
|
|
1346
|
-
stored = g.localStorage?.getItem(name) ?? void 0;
|
|
1347
|
-
} catch {
|
|
1348
|
-
stored = void 0;
|
|
1349
|
-
}
|
|
1350
|
-
const fromCookie = readCookie(name);
|
|
1351
|
-
let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
|
|
1352
|
-
if (!key) {
|
|
1353
|
-
key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
|
|
1354
|
-
}
|
|
1355
|
-
try {
|
|
1356
|
-
g.localStorage?.setItem(name, key);
|
|
1357
|
-
} catch {
|
|
1358
|
-
}
|
|
1359
|
-
const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
|
|
1360
|
-
g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
|
|
1361
|
-
return key;
|
|
1362
|
-
}
|
|
1363
|
-
function currentTouch() {
|
|
1364
|
-
const g = globalThis;
|
|
1365
|
-
const tg = tgWebApp();
|
|
1366
|
-
const out = {};
|
|
1367
|
-
if (g.location?.href) out.url = g.location.href;
|
|
1368
|
-
if (g.document?.referrer) out.referrer = g.document.referrer;
|
|
1369
|
-
if (tg?.start_param) out.campaign_code = tg.start_param;
|
|
1370
|
-
if (tg?.user?.id) out.platform = "miniapp";
|
|
1371
|
-
const ym = readCookie("_ym_uid");
|
|
1372
|
-
if (ym) out.metrika_client_id = ym;
|
|
1373
|
-
const ga = readCookie("_ga")?.split(".").slice(-2).join(".");
|
|
1374
|
-
if (ga) out.ga_client_id = ga;
|
|
1375
|
-
return out;
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
1501
|
// src/resources/history.ts
|
|
1379
1502
|
var HistoryResource = class {
|
|
1380
1503
|
constructor(http) {
|
|
@@ -1478,6 +1601,7 @@ var ConsentsResource = class {
|
|
|
1478
1601
|
const key = input.anonymousKey ?? anonymousKey();
|
|
1479
1602
|
if (key !== void 0) body.anonymous_key = key;
|
|
1480
1603
|
if (input.channel !== void 0) body.channel = input.channel;
|
|
1604
|
+
if (!input.analytics) forgetAnalyticsIds();
|
|
1481
1605
|
return this.http.post("/consents/cookies", { body });
|
|
1482
1606
|
}
|
|
1483
1607
|
};
|
|
@@ -1575,7 +1699,7 @@ var FundingOptionsResource = class {
|
|
|
1575
1699
|
};
|
|
1576
1700
|
|
|
1577
1701
|
// src/version.ts
|
|
1578
|
-
var SDK_VERSION = "0.6.
|
|
1702
|
+
var SDK_VERSION = "0.6.14";
|
|
1579
1703
|
|
|
1580
1704
|
// src/client-platform.ts
|
|
1581
1705
|
var CLIENT_HEADER = "X-Takeal-Client";
|
|
@@ -1650,7 +1774,7 @@ function isAbsolute(url) {
|
|
|
1650
1774
|
}
|
|
1651
1775
|
|
|
1652
1776
|
// src/compat.ts
|
|
1653
|
-
var SUPPORTED_MEISTER = ">=0.6
|
|
1777
|
+
var SUPPORTED_MEISTER = ">=0.7.6, <1.0.0";
|
|
1654
1778
|
var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1655
1779
|
function parse(v) {
|
|
1656
1780
|
const m = SEMVER.exec(v.trim());
|
|
@@ -2049,6 +2173,9 @@ var MetrikaSink = class {
|
|
|
2049
2173
|
trackLinks: false,
|
|
2050
2174
|
accurateTrackBounce: true
|
|
2051
2175
|
});
|
|
2176
|
+
this.ym("getClientID", (id) => {
|
|
2177
|
+
if (id !== void 0 && id !== null) rememberAnalyticsIds({ metrika_client_id: String(id) });
|
|
2178
|
+
});
|
|
2052
2179
|
}
|
|
2053
2180
|
ym(...args) {
|
|
2054
2181
|
if (this.live) win().ym?.(this.id, ...args);
|
|
@@ -2100,19 +2227,19 @@ function setAnalyticsZone(zone) {
|
|
|
2100
2227
|
function track(event, props = {}) {
|
|
2101
2228
|
const s = state();
|
|
2102
2229
|
if (!s || !ANALYTICS_EVENTS.includes(event)) return;
|
|
2103
|
-
const
|
|
2104
|
-
for (const sink of sinks(s)) sink.capture(event,
|
|
2230
|
+
const clean2 = sanitizeProperties(props);
|
|
2231
|
+
for (const sink of sinks(s)) sink.capture(event, clean2);
|
|
2105
2232
|
}
|
|
2106
2233
|
function page(url) {
|
|
2107
2234
|
const s = state();
|
|
2108
2235
|
const w = win();
|
|
2109
2236
|
const raw = url ?? w.location?.href;
|
|
2110
2237
|
if (!s || !raw) return;
|
|
2111
|
-
const
|
|
2112
|
-
if (
|
|
2238
|
+
const clean2 = sanitizeUrl(raw);
|
|
2239
|
+
if (clean2 === s.lastPage) return;
|
|
2113
2240
|
const referrer = s.lastPage ?? (w.document?.referrer ? sanitizeUrl(w.document.referrer) : void 0);
|
|
2114
|
-
s.lastPage =
|
|
2115
|
-
for (const sink of sinks(s)) sink.page(
|
|
2241
|
+
s.lastPage = clean2;
|
|
2242
|
+
for (const sink of sinks(s)) sink.page(clean2, referrer);
|
|
2116
2243
|
}
|
|
2117
2244
|
function identify(userId) {
|
|
2118
2245
|
const s = state();
|
|
@@ -2211,11 +2338,13 @@ exports.NO_CAPTURE_CLASS = NO_CAPTURE_CLASS;
|
|
|
2211
2338
|
exports.NetworkError = NetworkError;
|
|
2212
2339
|
exports.SDK_VERSION = SDK_VERSION;
|
|
2213
2340
|
exports.SUPPORTED_MEISTER = SUPPORTED_MEISTER;
|
|
2341
|
+
exports.analyticsIds = analyticsIds;
|
|
2214
2342
|
exports.anonymousKey = anonymousKey;
|
|
2215
2343
|
exports.createClient = createClient;
|
|
2216
2344
|
exports.currentTouch = currentTouch;
|
|
2217
2345
|
exports.defaultBrowserStore = defaultBrowserStore;
|
|
2218
2346
|
exports.detectClientPlatform = detectClientPlatform;
|
|
2347
|
+
exports.forgetAnalyticsIds = forgetAnalyticsIds;
|
|
2219
2348
|
exports.identify = identify;
|
|
2220
2349
|
exports.inMemoryStore = inMemoryStore;
|
|
2221
2350
|
exports.initAnalytics = initAnalytics;
|
|
@@ -2224,12 +2353,15 @@ exports.isCardOtp = isCardOtp;
|
|
|
2224
2353
|
exports.isNetworkError = isNetworkError;
|
|
2225
2354
|
exports.page = page;
|
|
2226
2355
|
exports.posthogDistinctId = posthogDistinctId;
|
|
2356
|
+
exports.rememberAnalyticsIds = rememberAnalyticsIds;
|
|
2227
2357
|
exports.resetAnalytics = resetAnalytics;
|
|
2228
2358
|
exports.resolveAssetUrl = resolveAssetUrl;
|
|
2359
|
+
exports.revealState = revealState;
|
|
2229
2360
|
exports.sanitizeProperties = sanitizeProperties;
|
|
2230
2361
|
exports.sanitizeUrl = sanitizeUrl;
|
|
2231
2362
|
exports.satisfies = satisfies;
|
|
2232
2363
|
exports.setAnalyticsZone = setAnalyticsZone;
|
|
2233
2364
|
exports.track = track;
|
|
2365
|
+
exports.withAnalyticsIds = withAnalyticsIds;
|
|
2234
2366
|
//# sourceMappingURL=index.cjs.map
|
|
2235
2367
|
//# sourceMappingURL=index.cjs.map
|