@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.
- package/CHANGELOG.md +97 -0
- package/README.md +54 -2
- 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-nXmDP0ei.d.cts → cards-BPu8Ill7.d.cts} +159 -12
- package/dist/{cards-CuUdrQ0H.d.ts → cards-DP1fJc_c.d.ts} +159 -12
- package/dist/index.cjs +261 -89
- 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 +257 -90
- 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 +66 -3
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +7 -2
- package/dist/resources/auth.d.ts +7 -2
- package/dist/resources/auth.js +66 -3
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/cards.cjs +111 -3
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +3 -1
- package/dist/resources/cards.d.ts +3 -1
- package/dist/resources/cards.js +110 -4
- 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 +3 -1
- package/dist/resources/deposits.d.ts +3 -1
- package/dist/resources/deposits.js +50 -0
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/funding-options.d.cts +3 -1
- package/dist/resources/funding-options.d.ts +3 -1
- package/dist/resources/me.d.cts +1 -1
- package/dist/resources/me.d.ts +1 -1
- package/dist/telegram.cjs +253 -69
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +35 -4
- package/dist/telegram.d.ts +35 -4
- package/dist/telegram.js +253 -70
- package/dist/telegram.js.map +1 -1
- package/package.json +1 -1
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 {
|
|
@@ -170,6 +336,26 @@ function cardRequestBody(input) {
|
|
|
170
336
|
if (consentChannel !== void 0) body["consent_channel"] = consentChannel;
|
|
171
337
|
return body;
|
|
172
338
|
}
|
|
339
|
+
function priceChangedQuote(error) {
|
|
340
|
+
const body = isApiError(error) ? error.body : error;
|
|
341
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
342
|
+
const { code, quote } = body;
|
|
343
|
+
if (code !== "price_changed" || typeof quote !== "object" || quote === null) return void 0;
|
|
344
|
+
return quote;
|
|
345
|
+
}
|
|
346
|
+
function cardOrderQuoteBody(input) {
|
|
347
|
+
const body = {
|
|
348
|
+
product_id: input.productId,
|
|
349
|
+
method: input.method
|
|
350
|
+
};
|
|
351
|
+
if (input.designId !== void 0) body["design_id"] = input.designId;
|
|
352
|
+
if (input.funderSlug !== void 0) body["funder_slug"] = input.funderSlug;
|
|
353
|
+
if (input.currency !== void 0) body["currency"] = input.currency;
|
|
354
|
+
if (input.extraLoad !== void 0) body["extra_load"] = input.extraLoad;
|
|
355
|
+
if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
|
|
356
|
+
if (input.useBonus !== void 0) body["use_bonus"] = input.useBonus;
|
|
357
|
+
return body;
|
|
358
|
+
}
|
|
173
359
|
function cardOrderBody(input) {
|
|
174
360
|
const body = {
|
|
175
361
|
product_id: input.productId,
|
|
@@ -185,6 +371,10 @@ function cardOrderBody(input) {
|
|
|
185
371
|
if (input.consents !== void 0) body["consents"] = input.consents;
|
|
186
372
|
if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
|
|
187
373
|
if (input.metadata !== void 0) body["metadata"] = input.metadata;
|
|
374
|
+
const ids = input.analyticsIds ?? analyticsIds();
|
|
375
|
+
if (ids !== void 0) body["analytics_ids"] = ids;
|
|
376
|
+
if (input.expectedAmount !== void 0) body["expected_amount"] = input.expectedAmount;
|
|
377
|
+
if (input.expectedCurrency !== void 0) body["expected_currency"] = input.expectedCurrency;
|
|
188
378
|
return body;
|
|
189
379
|
}
|
|
190
380
|
function revealState(r) {
|
|
@@ -219,8 +409,13 @@ var CardsResource = class {
|
|
|
219
409
|
* `idempotencyKey` returns the same order.
|
|
220
410
|
* Errors: 400 `unknown_product` / `method_not_available` / a limit of the
|
|
221
411
|
* way of paying, 409 `holder_data_consent_required` (the product has
|
|
222
|
-
* `holder_data_required` and the user has not agreed to it),
|
|
223
|
-
*
|
|
412
|
+
* `holder_data_required` and the user has not agreed to it), 409
|
|
413
|
+
* `payments_on_hold` (a payment on this account was not accepted and new
|
|
414
|
+
* ones wait until support sorts it out: show the message and point the
|
|
415
|
+
* user to support), 409 `price_changed` (the order came to another amount
|
|
416
|
+
* than `expectedAmount`; no payment was opened, and
|
|
417
|
+
* {@link priceChangedQuote} gives the new quote), 503 no funding connector
|
|
418
|
+
* or no exchange rate.
|
|
224
419
|
*/
|
|
225
420
|
async order(input) {
|
|
226
421
|
const { idempotencyKey, ...order } = input;
|
|
@@ -229,12 +424,41 @@ var CardsResource = class {
|
|
|
229
424
|
idempotencyKey
|
|
230
425
|
});
|
|
231
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* What an order of this card would cost the signed-in user now, with the
|
|
429
|
+
* promo code: the same calculation {@link order} makes, with every
|
|
430
|
+
* condition of the code checked. Nothing is reserved or used up. Pass
|
|
431
|
+
* `amount` and `currency` to the order as `expectedAmount` and
|
|
432
|
+
* `expectedCurrency`.
|
|
433
|
+
*/
|
|
434
|
+
async quote(input) {
|
|
435
|
+
return this.http.post("/me/card-orders/quote", {
|
|
436
|
+
body: cardOrderQuoteBody(input)
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The same quote before sign-in, for a landing page or the purchase form
|
|
441
|
+
* before the e-mail code. Prices are list prices, and a code whose
|
|
442
|
+
* conditions depend on the person (first card only, say) comes back
|
|
443
|
+
* `conditional`, with `preliminary` set. Send `expectedAmount` with the
|
|
444
|
+
* order placed at sign-in: if the price turns out different, no payment
|
|
445
|
+
* is opened and `card_order_error` carries the new quote. The API limits
|
|
446
|
+
* how often one address can ask (429 `too_many_requests`).
|
|
447
|
+
*/
|
|
448
|
+
async quotePublic(input) {
|
|
449
|
+
return this.http.post("/card-orders/quote", {
|
|
450
|
+
body: cardOrderQuoteBody(input),
|
|
451
|
+
skipAuth: true
|
|
452
|
+
});
|
|
453
|
+
}
|
|
232
454
|
/**
|
|
233
455
|
* The cards the caller can order, in the order the storefront shows them
|
|
234
456
|
* (`is_default` marks the one issued when none is chosen). Each item
|
|
235
457
|
* carries its product card (name, tagline, benefits, tile picture),
|
|
236
458
|
* artwork, and the issuance price after the caller's subscription
|
|
237
|
-
* discount, in the
|
|
459
|
+
* discount, in the currency the operator set it in (`price.from_wallet`
|
|
460
|
+
* is the same price from the wallet, when that holds another currency).
|
|
461
|
+
* Pass an item's `id` as
|
|
238
462
|
* `productId` to {@link create}.
|
|
239
463
|
*/
|
|
240
464
|
async listProducts() {
|
|
@@ -479,8 +703,11 @@ var AuthResource = class {
|
|
|
479
703
|
/** Password-auth entry. May resolve to a JWT, or to a step-up
|
|
480
704
|
* challenge that needs `verifyTotp` / `verifyOtp` next. */
|
|
481
705
|
async login(input) {
|
|
706
|
+
const body = withRemember(input);
|
|
707
|
+
const attribution = withAnalyticsIds(void 0);
|
|
708
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
482
709
|
const resp = await this.http.post("/auth/login", {
|
|
483
|
-
body
|
|
710
|
+
body,
|
|
484
711
|
skipAuth: true
|
|
485
712
|
});
|
|
486
713
|
if (resp.stage === "jwt") {
|
|
@@ -517,6 +744,8 @@ var AuthResource = class {
|
|
|
517
744
|
async register(input) {
|
|
518
745
|
const { cardOrder, ...rest } = input;
|
|
519
746
|
const body = withRemember(rest);
|
|
747
|
+
const attribution = withAnalyticsIds(rest.attribution);
|
|
748
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
520
749
|
if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
|
|
521
750
|
const resp = await this.http.post("/auth/register", {
|
|
522
751
|
body,
|
|
@@ -552,7 +781,8 @@ var AuthResource = class {
|
|
|
552
781
|
};
|
|
553
782
|
if (input.remember) body["remember_me"] = true;
|
|
554
783
|
if (input.walletCurrency !== void 0) body["wallet_currency"] = input.walletCurrency;
|
|
555
|
-
|
|
784
|
+
const attribution = withAnalyticsIds(input.attribution);
|
|
785
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
556
786
|
if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
|
|
557
787
|
if (input.consents !== void 0) body["consents"] = input.consents;
|
|
558
788
|
if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
|
|
@@ -598,7 +828,8 @@ var AuthResource = class {
|
|
|
598
828
|
init_data: input.initData
|
|
599
829
|
};
|
|
600
830
|
if (input.provision !== void 0) body.provision = input.provision;
|
|
601
|
-
|
|
831
|
+
const attribution = withAnalyticsIds(input.attribution);
|
|
832
|
+
if (attribution !== void 0) body.attribution = attribution;
|
|
602
833
|
if (input.code !== void 0) body.code = input.code;
|
|
603
834
|
if (input.consents !== void 0) body.consents = input.consents;
|
|
604
835
|
if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
|
|
@@ -704,10 +935,17 @@ var DepositsResource = class {
|
|
|
704
935
|
if (connectorSlug !== void 0) body["connector_slug"] = connectorSlug;
|
|
705
936
|
return this.http.post("/me/deposits/quotes", { body });
|
|
706
937
|
}
|
|
938
|
+
/**
|
|
939
|
+
* Start a top-up. 409 `payments_on_hold`: a payment on this account was
|
|
940
|
+
* not accepted and new ones wait until support sorts it out. Show the
|
|
941
|
+
* message as it comes and point the user to support.
|
|
942
|
+
*/
|
|
707
943
|
async initiate(input) {
|
|
708
944
|
const { idempotencyKey, issue_card, ...rest } = input;
|
|
709
945
|
const body = { ...rest };
|
|
710
946
|
if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
|
|
947
|
+
const ids = input.analytics_ids ?? analyticsIds();
|
|
948
|
+
if (ids !== void 0) body["analytics_ids"] = ids;
|
|
711
949
|
return this.http.post("/me/deposits", {
|
|
712
950
|
body,
|
|
713
951
|
idempotencyKey
|
|
@@ -1312,81 +1550,6 @@ var DevicesResource = class {
|
|
|
1312
1550
|
}
|
|
1313
1551
|
};
|
|
1314
1552
|
|
|
1315
|
-
// src/resources/attribution.ts
|
|
1316
|
-
var AttributionResource = class {
|
|
1317
|
-
constructor(http) {
|
|
1318
|
-
this.http = http;
|
|
1319
|
-
}
|
|
1320
|
-
/** Record a visit. No session needed; safe to call on every page load. */
|
|
1321
|
-
async touch(input) {
|
|
1322
|
-
return this.http.post("/attribution/touches", { body: input, skipAuth: true });
|
|
1323
|
-
}
|
|
1324
|
-
/** Whether to ask the signed-in user how they heard about us. */
|
|
1325
|
-
async status() {
|
|
1326
|
-
return this.http.get("/me/attribution");
|
|
1327
|
-
}
|
|
1328
|
-
/** Answer the question once. Send `"skipped"` when the user closes it.
|
|
1329
|
-
* `otherText` is kept only with `"other"`, up to 500 characters.
|
|
1330
|
-
* Errors: 400 `validation`, 409 `survey_answered`. */
|
|
1331
|
-
async answerSurvey(answer, otherText) {
|
|
1332
|
-
const body = { answer };
|
|
1333
|
-
if (otherText !== void 0) body.other_text = otherText;
|
|
1334
|
-
return this.http.put("/me/attribution/survey", { body });
|
|
1335
|
-
}
|
|
1336
|
-
};
|
|
1337
|
-
function tgWebApp() {
|
|
1338
|
-
return globalThis.Telegram?.WebApp?.initDataUnsafe;
|
|
1339
|
-
}
|
|
1340
|
-
function readCookie(name) {
|
|
1341
|
-
const doc = globalThis.document;
|
|
1342
|
-
if (!doc?.cookie) return void 0;
|
|
1343
|
-
for (const part of doc.cookie.split(";")) {
|
|
1344
|
-
const [k, ...v] = part.trim().split("=");
|
|
1345
|
-
if (k === name) return decodeURIComponent(v.join("="));
|
|
1346
|
-
}
|
|
1347
|
-
return void 0;
|
|
1348
|
-
}
|
|
1349
|
-
var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
|
|
1350
|
-
function anonymousKey(opts = {}) {
|
|
1351
|
-
const tgId = tgWebApp()?.user?.id;
|
|
1352
|
-
if (tgId) return `tg:${tgId}`;
|
|
1353
|
-
const g = globalThis;
|
|
1354
|
-
if (!g.document) return void 0;
|
|
1355
|
-
const name = opts.name ?? "takeal_anon";
|
|
1356
|
-
let stored;
|
|
1357
|
-
try {
|
|
1358
|
-
stored = g.localStorage?.getItem(name) ?? void 0;
|
|
1359
|
-
} catch {
|
|
1360
|
-
stored = void 0;
|
|
1361
|
-
}
|
|
1362
|
-
const fromCookie = readCookie(name);
|
|
1363
|
-
let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
|
|
1364
|
-
if (!key) {
|
|
1365
|
-
key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
|
|
1366
|
-
}
|
|
1367
|
-
try {
|
|
1368
|
-
g.localStorage?.setItem(name, key);
|
|
1369
|
-
} catch {
|
|
1370
|
-
}
|
|
1371
|
-
const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
|
|
1372
|
-
g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
|
|
1373
|
-
return key;
|
|
1374
|
-
}
|
|
1375
|
-
function currentTouch() {
|
|
1376
|
-
const g = globalThis;
|
|
1377
|
-
const tg = tgWebApp();
|
|
1378
|
-
const out = {};
|
|
1379
|
-
if (g.location?.href) out.url = g.location.href;
|
|
1380
|
-
if (g.document?.referrer) out.referrer = g.document.referrer;
|
|
1381
|
-
if (tg?.start_param) out.campaign_code = tg.start_param;
|
|
1382
|
-
if (tg?.user?.id) out.platform = "miniapp";
|
|
1383
|
-
const ym = readCookie("_ym_uid");
|
|
1384
|
-
if (ym) out.metrika_client_id = ym;
|
|
1385
|
-
const ga = readCookie("_ga")?.split(".").slice(-2).join(".");
|
|
1386
|
-
if (ga) out.ga_client_id = ga;
|
|
1387
|
-
return out;
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
1553
|
// src/resources/history.ts
|
|
1391
1554
|
var HistoryResource = class {
|
|
1392
1555
|
constructor(http) {
|
|
@@ -1490,6 +1653,7 @@ var ConsentsResource = class {
|
|
|
1490
1653
|
const key = input.anonymousKey ?? anonymousKey();
|
|
1491
1654
|
if (key !== void 0) body.anonymous_key = key;
|
|
1492
1655
|
if (input.channel !== void 0) body.channel = input.channel;
|
|
1656
|
+
if (!input.analytics) forgetAnalyticsIds();
|
|
1493
1657
|
return this.http.post("/consents/cookies", { body });
|
|
1494
1658
|
}
|
|
1495
1659
|
};
|
|
@@ -1587,7 +1751,7 @@ var FundingOptionsResource = class {
|
|
|
1587
1751
|
};
|
|
1588
1752
|
|
|
1589
1753
|
// src/version.ts
|
|
1590
|
-
var SDK_VERSION = "0.
|
|
1754
|
+
var SDK_VERSION = "0.8.0";
|
|
1591
1755
|
|
|
1592
1756
|
// src/client-platform.ts
|
|
1593
1757
|
var CLIENT_HEADER = "X-Takeal-Client";
|
|
@@ -1662,7 +1826,7 @@ function isAbsolute(url) {
|
|
|
1662
1826
|
}
|
|
1663
1827
|
|
|
1664
1828
|
// src/compat.ts
|
|
1665
|
-
var SUPPORTED_MEISTER = ">=0.
|
|
1829
|
+
var SUPPORTED_MEISTER = ">=0.8.0, <1.0.0";
|
|
1666
1830
|
var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1667
1831
|
function parse(v) {
|
|
1668
1832
|
const m = SEMVER.exec(v.trim());
|
|
@@ -2061,6 +2225,9 @@ var MetrikaSink = class {
|
|
|
2061
2225
|
trackLinks: false,
|
|
2062
2226
|
accurateTrackBounce: true
|
|
2063
2227
|
});
|
|
2228
|
+
this.ym("getClientID", (id) => {
|
|
2229
|
+
if (id !== void 0 && id !== null) rememberAnalyticsIds({ metrika_client_id: String(id) });
|
|
2230
|
+
});
|
|
2064
2231
|
}
|
|
2065
2232
|
ym(...args) {
|
|
2066
2233
|
if (this.live) win().ym?.(this.id, ...args);
|
|
@@ -2112,19 +2279,19 @@ function setAnalyticsZone(zone) {
|
|
|
2112
2279
|
function track(event, props = {}) {
|
|
2113
2280
|
const s = state();
|
|
2114
2281
|
if (!s || !ANALYTICS_EVENTS.includes(event)) return;
|
|
2115
|
-
const
|
|
2116
|
-
for (const sink of sinks(s)) sink.capture(event,
|
|
2282
|
+
const clean2 = sanitizeProperties(props);
|
|
2283
|
+
for (const sink of sinks(s)) sink.capture(event, clean2);
|
|
2117
2284
|
}
|
|
2118
2285
|
function page(url) {
|
|
2119
2286
|
const s = state();
|
|
2120
2287
|
const w = win();
|
|
2121
2288
|
const raw = url ?? w.location?.href;
|
|
2122
2289
|
if (!s || !raw) return;
|
|
2123
|
-
const
|
|
2124
|
-
if (
|
|
2290
|
+
const clean2 = sanitizeUrl(raw);
|
|
2291
|
+
if (clean2 === s.lastPage) return;
|
|
2125
2292
|
const referrer = s.lastPage ?? (w.document?.referrer ? sanitizeUrl(w.document.referrer) : void 0);
|
|
2126
|
-
s.lastPage =
|
|
2127
|
-
for (const sink of sinks(s)) sink.page(
|
|
2293
|
+
s.lastPage = clean2;
|
|
2294
|
+
for (const sink of sinks(s)) sink.page(clean2, referrer);
|
|
2128
2295
|
}
|
|
2129
2296
|
function identify(userId) {
|
|
2130
2297
|
const s = state();
|
|
@@ -2223,11 +2390,13 @@ exports.NO_CAPTURE_CLASS = NO_CAPTURE_CLASS;
|
|
|
2223
2390
|
exports.NetworkError = NetworkError;
|
|
2224
2391
|
exports.SDK_VERSION = SDK_VERSION;
|
|
2225
2392
|
exports.SUPPORTED_MEISTER = SUPPORTED_MEISTER;
|
|
2393
|
+
exports.analyticsIds = analyticsIds;
|
|
2226
2394
|
exports.anonymousKey = anonymousKey;
|
|
2227
2395
|
exports.createClient = createClient;
|
|
2228
2396
|
exports.currentTouch = currentTouch;
|
|
2229
2397
|
exports.defaultBrowserStore = defaultBrowserStore;
|
|
2230
2398
|
exports.detectClientPlatform = detectClientPlatform;
|
|
2399
|
+
exports.forgetAnalyticsIds = forgetAnalyticsIds;
|
|
2231
2400
|
exports.identify = identify;
|
|
2232
2401
|
exports.inMemoryStore = inMemoryStore;
|
|
2233
2402
|
exports.initAnalytics = initAnalytics;
|
|
@@ -2236,6 +2405,8 @@ exports.isCardOtp = isCardOtp;
|
|
|
2236
2405
|
exports.isNetworkError = isNetworkError;
|
|
2237
2406
|
exports.page = page;
|
|
2238
2407
|
exports.posthogDistinctId = posthogDistinctId;
|
|
2408
|
+
exports.priceChangedQuote = priceChangedQuote;
|
|
2409
|
+
exports.rememberAnalyticsIds = rememberAnalyticsIds;
|
|
2239
2410
|
exports.resetAnalytics = resetAnalytics;
|
|
2240
2411
|
exports.resolveAssetUrl = resolveAssetUrl;
|
|
2241
2412
|
exports.revealState = revealState;
|
|
@@ -2244,5 +2415,6 @@ exports.sanitizeUrl = sanitizeUrl;
|
|
|
2244
2415
|
exports.satisfies = satisfies;
|
|
2245
2416
|
exports.setAnalyticsZone = setAnalyticsZone;
|
|
2246
2417
|
exports.track = track;
|
|
2418
|
+
exports.withAnalyticsIds = withAnalyticsIds;
|
|
2247
2419
|
//# sourceMappingURL=index.cjs.map
|
|
2248
2420
|
//# sourceMappingURL=index.cjs.map
|