@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.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-
|
|
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,
|
|
5
|
+
import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-BPu8Ill7.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-BPu8Ill7.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';
|
|
@@ -81,7 +81,7 @@ interface BrandConfig {
|
|
|
81
81
|
* Which platform versions this SDK works with, as a semver range:
|
|
82
82
|
* comparators separated by ", ". Keep this the only definition.
|
|
83
83
|
*/
|
|
84
|
-
declare const SUPPORTED_MEISTER = ">=0.
|
|
84
|
+
declare const SUPPORTED_MEISTER = ">=0.8.0, <1.0.0";
|
|
85
85
|
/** What `client.ready()` returns. */
|
|
86
86
|
interface ReadyInfo {
|
|
87
87
|
/** `true` when the platform reported a version inside `supportedMeister`. */
|
|
@@ -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.
|
|
190
|
+
declare const SDK_VERSION = "0.8.0";
|
|
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-
|
|
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,
|
|
5
|
+
import { b as DepositsResource, F as FundingOptionsResource, c as CardsResource } from './cards-DP1fJc_c.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-DP1fJc_c.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';
|
|
@@ -81,7 +81,7 @@ interface BrandConfig {
|
|
|
81
81
|
* Which platform versions this SDK works with, as a semver range:
|
|
82
82
|
* comparators separated by ", ". Keep this the only definition.
|
|
83
83
|
*/
|
|
84
|
-
declare const SUPPORTED_MEISTER = ">=0.
|
|
84
|
+
declare const SUPPORTED_MEISTER = ">=0.8.0, <1.0.0";
|
|
85
85
|
/** What `client.ready()` returns. */
|
|
86
86
|
interface ReadyInfo {
|
|
87
87
|
/** `true` when the platform reported a version inside `supportedMeister`. */
|
|
@@ -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.
|
|
190
|
+
declare const SDK_VERSION = "0.8.0";
|
|
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 {
|
|
@@ -168,6 +334,26 @@ function cardRequestBody(input) {
|
|
|
168
334
|
if (consentChannel !== void 0) body["consent_channel"] = consentChannel;
|
|
169
335
|
return body;
|
|
170
336
|
}
|
|
337
|
+
function priceChangedQuote(error) {
|
|
338
|
+
const body = isApiError(error) ? error.body : error;
|
|
339
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
340
|
+
const { code, quote } = body;
|
|
341
|
+
if (code !== "price_changed" || typeof quote !== "object" || quote === null) return void 0;
|
|
342
|
+
return quote;
|
|
343
|
+
}
|
|
344
|
+
function cardOrderQuoteBody(input) {
|
|
345
|
+
const body = {
|
|
346
|
+
product_id: input.productId,
|
|
347
|
+
method: input.method
|
|
348
|
+
};
|
|
349
|
+
if (input.designId !== void 0) body["design_id"] = input.designId;
|
|
350
|
+
if (input.funderSlug !== void 0) body["funder_slug"] = input.funderSlug;
|
|
351
|
+
if (input.currency !== void 0) body["currency"] = input.currency;
|
|
352
|
+
if (input.extraLoad !== void 0) body["extra_load"] = input.extraLoad;
|
|
353
|
+
if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
|
|
354
|
+
if (input.useBonus !== void 0) body["use_bonus"] = input.useBonus;
|
|
355
|
+
return body;
|
|
356
|
+
}
|
|
171
357
|
function cardOrderBody(input) {
|
|
172
358
|
const body = {
|
|
173
359
|
product_id: input.productId,
|
|
@@ -183,6 +369,10 @@ function cardOrderBody(input) {
|
|
|
183
369
|
if (input.consents !== void 0) body["consents"] = input.consents;
|
|
184
370
|
if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
|
|
185
371
|
if (input.metadata !== void 0) body["metadata"] = input.metadata;
|
|
372
|
+
const ids = input.analyticsIds ?? analyticsIds();
|
|
373
|
+
if (ids !== void 0) body["analytics_ids"] = ids;
|
|
374
|
+
if (input.expectedAmount !== void 0) body["expected_amount"] = input.expectedAmount;
|
|
375
|
+
if (input.expectedCurrency !== void 0) body["expected_currency"] = input.expectedCurrency;
|
|
186
376
|
return body;
|
|
187
377
|
}
|
|
188
378
|
function revealState(r) {
|
|
@@ -217,8 +407,13 @@ var CardsResource = class {
|
|
|
217
407
|
* `idempotencyKey` returns the same order.
|
|
218
408
|
* Errors: 400 `unknown_product` / `method_not_available` / a limit of the
|
|
219
409
|
* way of paying, 409 `holder_data_consent_required` (the product has
|
|
220
|
-
* `holder_data_required` and the user has not agreed to it),
|
|
221
|
-
*
|
|
410
|
+
* `holder_data_required` and the user has not agreed to it), 409
|
|
411
|
+
* `payments_on_hold` (a payment on this account was not accepted and new
|
|
412
|
+
* ones wait until support sorts it out: show the message and point the
|
|
413
|
+
* user to support), 409 `price_changed` (the order came to another amount
|
|
414
|
+
* than `expectedAmount`; no payment was opened, and
|
|
415
|
+
* {@link priceChangedQuote} gives the new quote), 503 no funding connector
|
|
416
|
+
* or no exchange rate.
|
|
222
417
|
*/
|
|
223
418
|
async order(input) {
|
|
224
419
|
const { idempotencyKey, ...order } = input;
|
|
@@ -227,12 +422,41 @@ var CardsResource = class {
|
|
|
227
422
|
idempotencyKey
|
|
228
423
|
});
|
|
229
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* What an order of this card would cost the signed-in user now, with the
|
|
427
|
+
* promo code: the same calculation {@link order} makes, with every
|
|
428
|
+
* condition of the code checked. Nothing is reserved or used up. Pass
|
|
429
|
+
* `amount` and `currency` to the order as `expectedAmount` and
|
|
430
|
+
* `expectedCurrency`.
|
|
431
|
+
*/
|
|
432
|
+
async quote(input) {
|
|
433
|
+
return this.http.post("/me/card-orders/quote", {
|
|
434
|
+
body: cardOrderQuoteBody(input)
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* The same quote before sign-in, for a landing page or the purchase form
|
|
439
|
+
* before the e-mail code. Prices are list prices, and a code whose
|
|
440
|
+
* conditions depend on the person (first card only, say) comes back
|
|
441
|
+
* `conditional`, with `preliminary` set. Send `expectedAmount` with the
|
|
442
|
+
* order placed at sign-in: if the price turns out different, no payment
|
|
443
|
+
* is opened and `card_order_error` carries the new quote. The API limits
|
|
444
|
+
* how often one address can ask (429 `too_many_requests`).
|
|
445
|
+
*/
|
|
446
|
+
async quotePublic(input) {
|
|
447
|
+
return this.http.post("/card-orders/quote", {
|
|
448
|
+
body: cardOrderQuoteBody(input),
|
|
449
|
+
skipAuth: true
|
|
450
|
+
});
|
|
451
|
+
}
|
|
230
452
|
/**
|
|
231
453
|
* The cards the caller can order, in the order the storefront shows them
|
|
232
454
|
* (`is_default` marks the one issued when none is chosen). Each item
|
|
233
455
|
* carries its product card (name, tagline, benefits, tile picture),
|
|
234
456
|
* artwork, and the issuance price after the caller's subscription
|
|
235
|
-
* discount, in the
|
|
457
|
+
* discount, in the currency the operator set it in (`price.from_wallet`
|
|
458
|
+
* is the same price from the wallet, when that holds another currency).
|
|
459
|
+
* Pass an item's `id` as
|
|
236
460
|
* `productId` to {@link create}.
|
|
237
461
|
*/
|
|
238
462
|
async listProducts() {
|
|
@@ -477,8 +701,11 @@ var AuthResource = class {
|
|
|
477
701
|
/** Password-auth entry. May resolve to a JWT, or to a step-up
|
|
478
702
|
* challenge that needs `verifyTotp` / `verifyOtp` next. */
|
|
479
703
|
async login(input) {
|
|
704
|
+
const body = withRemember(input);
|
|
705
|
+
const attribution = withAnalyticsIds(void 0);
|
|
706
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
480
707
|
const resp = await this.http.post("/auth/login", {
|
|
481
|
-
body
|
|
708
|
+
body,
|
|
482
709
|
skipAuth: true
|
|
483
710
|
});
|
|
484
711
|
if (resp.stage === "jwt") {
|
|
@@ -515,6 +742,8 @@ var AuthResource = class {
|
|
|
515
742
|
async register(input) {
|
|
516
743
|
const { cardOrder, ...rest } = input;
|
|
517
744
|
const body = withRemember(rest);
|
|
745
|
+
const attribution = withAnalyticsIds(rest.attribution);
|
|
746
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
518
747
|
if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
|
|
519
748
|
const resp = await this.http.post("/auth/register", {
|
|
520
749
|
body,
|
|
@@ -550,7 +779,8 @@ var AuthResource = class {
|
|
|
550
779
|
};
|
|
551
780
|
if (input.remember) body["remember_me"] = true;
|
|
552
781
|
if (input.walletCurrency !== void 0) body["wallet_currency"] = input.walletCurrency;
|
|
553
|
-
|
|
782
|
+
const attribution = withAnalyticsIds(input.attribution);
|
|
783
|
+
if (attribution !== void 0) body["attribution"] = attribution;
|
|
554
784
|
if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
|
|
555
785
|
if (input.consents !== void 0) body["consents"] = input.consents;
|
|
556
786
|
if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
|
|
@@ -596,7 +826,8 @@ var AuthResource = class {
|
|
|
596
826
|
init_data: input.initData
|
|
597
827
|
};
|
|
598
828
|
if (input.provision !== void 0) body.provision = input.provision;
|
|
599
|
-
|
|
829
|
+
const attribution = withAnalyticsIds(input.attribution);
|
|
830
|
+
if (attribution !== void 0) body.attribution = attribution;
|
|
600
831
|
if (input.code !== void 0) body.code = input.code;
|
|
601
832
|
if (input.consents !== void 0) body.consents = input.consents;
|
|
602
833
|
if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
|
|
@@ -702,10 +933,17 @@ var DepositsResource = class {
|
|
|
702
933
|
if (connectorSlug !== void 0) body["connector_slug"] = connectorSlug;
|
|
703
934
|
return this.http.post("/me/deposits/quotes", { body });
|
|
704
935
|
}
|
|
936
|
+
/**
|
|
937
|
+
* Start a top-up. 409 `payments_on_hold`: a payment on this account was
|
|
938
|
+
* not accepted and new ones wait until support sorts it out. Show the
|
|
939
|
+
* message as it comes and point the user to support.
|
|
940
|
+
*/
|
|
705
941
|
async initiate(input) {
|
|
706
942
|
const { idempotencyKey, issue_card, ...rest } = input;
|
|
707
943
|
const body = { ...rest };
|
|
708
944
|
if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
|
|
945
|
+
const ids = input.analytics_ids ?? analyticsIds();
|
|
946
|
+
if (ids !== void 0) body["analytics_ids"] = ids;
|
|
709
947
|
return this.http.post("/me/deposits", {
|
|
710
948
|
body,
|
|
711
949
|
idempotencyKey
|
|
@@ -1310,81 +1548,6 @@ var DevicesResource = class {
|
|
|
1310
1548
|
}
|
|
1311
1549
|
};
|
|
1312
1550
|
|
|
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
1551
|
// src/resources/history.ts
|
|
1389
1552
|
var HistoryResource = class {
|
|
1390
1553
|
constructor(http) {
|
|
@@ -1488,6 +1651,7 @@ var ConsentsResource = class {
|
|
|
1488
1651
|
const key = input.anonymousKey ?? anonymousKey();
|
|
1489
1652
|
if (key !== void 0) body.anonymous_key = key;
|
|
1490
1653
|
if (input.channel !== void 0) body.channel = input.channel;
|
|
1654
|
+
if (!input.analytics) forgetAnalyticsIds();
|
|
1491
1655
|
return this.http.post("/consents/cookies", { body });
|
|
1492
1656
|
}
|
|
1493
1657
|
};
|
|
@@ -1585,7 +1749,7 @@ var FundingOptionsResource = class {
|
|
|
1585
1749
|
};
|
|
1586
1750
|
|
|
1587
1751
|
// src/version.ts
|
|
1588
|
-
var SDK_VERSION = "0.
|
|
1752
|
+
var SDK_VERSION = "0.8.0";
|
|
1589
1753
|
|
|
1590
1754
|
// src/client-platform.ts
|
|
1591
1755
|
var CLIENT_HEADER = "X-Takeal-Client";
|
|
@@ -1660,7 +1824,7 @@ function isAbsolute(url) {
|
|
|
1660
1824
|
}
|
|
1661
1825
|
|
|
1662
1826
|
// src/compat.ts
|
|
1663
|
-
var SUPPORTED_MEISTER = ">=0.
|
|
1827
|
+
var SUPPORTED_MEISTER = ">=0.8.0, <1.0.0";
|
|
1664
1828
|
var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1665
1829
|
function parse(v) {
|
|
1666
1830
|
const m = SEMVER.exec(v.trim());
|
|
@@ -2059,6 +2223,9 @@ var MetrikaSink = class {
|
|
|
2059
2223
|
trackLinks: false,
|
|
2060
2224
|
accurateTrackBounce: true
|
|
2061
2225
|
});
|
|
2226
|
+
this.ym("getClientID", (id) => {
|
|
2227
|
+
if (id !== void 0 && id !== null) rememberAnalyticsIds({ metrika_client_id: String(id) });
|
|
2228
|
+
});
|
|
2062
2229
|
}
|
|
2063
2230
|
ym(...args) {
|
|
2064
2231
|
if (this.live) win().ym?.(this.id, ...args);
|
|
@@ -2110,19 +2277,19 @@ function setAnalyticsZone(zone) {
|
|
|
2110
2277
|
function track(event, props = {}) {
|
|
2111
2278
|
const s = state();
|
|
2112
2279
|
if (!s || !ANALYTICS_EVENTS.includes(event)) return;
|
|
2113
|
-
const
|
|
2114
|
-
for (const sink of sinks(s)) sink.capture(event,
|
|
2280
|
+
const clean2 = sanitizeProperties(props);
|
|
2281
|
+
for (const sink of sinks(s)) sink.capture(event, clean2);
|
|
2115
2282
|
}
|
|
2116
2283
|
function page(url) {
|
|
2117
2284
|
const s = state();
|
|
2118
2285
|
const w = win();
|
|
2119
2286
|
const raw = url ?? w.location?.href;
|
|
2120
2287
|
if (!s || !raw) return;
|
|
2121
|
-
const
|
|
2122
|
-
if (
|
|
2288
|
+
const clean2 = sanitizeUrl(raw);
|
|
2289
|
+
if (clean2 === s.lastPage) return;
|
|
2123
2290
|
const referrer = s.lastPage ?? (w.document?.referrer ? sanitizeUrl(w.document.referrer) : void 0);
|
|
2124
|
-
s.lastPage =
|
|
2125
|
-
for (const sink of sinks(s)) sink.page(
|
|
2291
|
+
s.lastPage = clean2;
|
|
2292
|
+
for (const sink of sinks(s)) sink.page(clean2, referrer);
|
|
2126
2293
|
}
|
|
2127
2294
|
function identify(userId) {
|
|
2128
2295
|
const s = state();
|
|
@@ -2211,6 +2378,6 @@ function defaultFetch() {
|
|
|
2211
2378
|
);
|
|
2212
2379
|
}
|
|
2213
2380
|
|
|
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 };
|
|
2381
|
+
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 };
|
|
2215
2382
|
//# sourceMappingURL=index.js.map
|
|
2216
2383
|
//# sourceMappingURL=index.js.map
|