@takeal/cusfront-sdk 0.6.1 → 0.6.2
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 +28 -0
- package/README.md +55 -0
- package/dist/{cards-qfHz6xZY.d.cts → cards-DU2DdhYO.d.cts} +10 -0
- package/dist/{cards-CF3-He2x.d.ts → cards-DzhPVA9N.d.ts} +10 -0
- package/dist/{deposits-ZjT_btgi.d.cts → deposits-BEkNeE-v.d.cts} +1 -1
- package/dist/{deposits-B2LBe2k1.d.ts → deposits-Dt6A76MB.d.ts} +1 -1
- package/dist/index.cjs +95 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +95 -7
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +4 -2
- package/dist/react/index.d.ts +4 -2
- package/dist/resources/auth.cjs +25 -4
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +40 -5
- package/dist/resources/auth.d.ts +40 -5
- package/dist/resources/auth.js +25 -4
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/cards.cjs +2 -0
- 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 +2 -0
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/consents.cjs +91 -0
- package/dist/resources/consents.cjs.map +1 -0
- package/dist/resources/consents.d.cts +83 -0
- package/dist/resources/consents.d.ts +83 -0
- package/dist/resources/consents.js +89 -0
- package/dist/resources/consents.js.map +1 -0
- package/dist/resources/deposits.cjs +2 -0
- package/dist/resources/deposits.cjs.map +1 -1
- package/dist/resources/deposits.d.cts +3 -2
- package/dist/resources/deposits.d.ts +3 -2
- package/dist/resources/deposits.js +2 -0
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/funding-options.d.cts +3 -2
- package/dist/resources/funding-options.d.ts +3 -2
- package/dist/resources/me.d.cts +1 -0
- package/dist/resources/me.d.ts +1 -0
- package/dist/resources/receipts.cjs +22 -0
- package/dist/resources/receipts.cjs.map +1 -0
- package/dist/resources/receipts.d.cts +51 -0
- package/dist/resources/receipts.d.ts +51 -0
- package/dist/resources/receipts.js +20 -0
- package/dist/resources/receipts.js.map +1 -0
- package/dist/telegram.cjs +133 -7
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +4 -2
- package/dist/telegram.d.ts +4 -2
- package/dist/telegram.js +133 -7
- package/dist/telegram.js.map +1 -1
- package/package.json +11 -1
package/dist/telegram.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CusfrontClient, CreateClientOptions } from './index.cjs';
|
|
2
2
|
import { JwtIssued, TelegramUnknown } from './resources/auth.cjs';
|
|
3
3
|
import './http-DeANAoTs.cjs';
|
|
4
|
-
import './deposits-
|
|
5
|
-
import './cards-
|
|
4
|
+
import './deposits-BEkNeE-v.cjs';
|
|
5
|
+
import './cards-DU2DdhYO.cjs';
|
|
6
|
+
import './resources/consents.cjs';
|
|
6
7
|
import './resources/balance.cjs';
|
|
7
8
|
import './resources/bonus.cjs';
|
|
8
9
|
import './resources/codes.cjs';
|
|
@@ -20,6 +21,7 @@ import './resources/notifications.cjs';
|
|
|
20
21
|
import './devices-a5Z45Mx_.cjs';
|
|
21
22
|
import './resources/attribution.cjs';
|
|
22
23
|
import './resources/history.cjs';
|
|
24
|
+
import './resources/receipts.cjs';
|
|
23
25
|
import './analytics.cjs';
|
|
24
26
|
|
|
25
27
|
/**
|
package/dist/telegram.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CusfrontClient, CreateClientOptions } from './index.js';
|
|
2
2
|
import { JwtIssued, TelegramUnknown } from './resources/auth.js';
|
|
3
3
|
import './http-DeANAoTs.js';
|
|
4
|
-
import './deposits-
|
|
5
|
-
import './cards-
|
|
4
|
+
import './deposits-Dt6A76MB.js';
|
|
5
|
+
import './cards-DzhPVA9N.js';
|
|
6
|
+
import './resources/consents.js';
|
|
6
7
|
import './resources/balance.js';
|
|
7
8
|
import './resources/bonus.js';
|
|
8
9
|
import './resources/codes.js';
|
|
@@ -20,6 +21,7 @@ import './resources/notifications.js';
|
|
|
20
21
|
import './devices-B_YveTl9.js';
|
|
21
22
|
import './resources/attribution.js';
|
|
22
23
|
import './resources/history.js';
|
|
24
|
+
import './resources/receipts.js';
|
|
23
25
|
import './analytics.js';
|
|
24
26
|
|
|
25
27
|
/**
|
package/dist/telegram.js
CHANGED
|
@@ -227,7 +227,8 @@ var AuthResource = class {
|
|
|
227
227
|
* `wallet_currency` must be one the deployment offers; omit it to take
|
|
228
228
|
* the deployment default (it can be switched later via `client.wallet`
|
|
229
229
|
* while the wallet is empty).
|
|
230
|
-
* Errors: 400 `validation` / `currency_not_allowed
|
|
230
|
+
* Errors: 400 `validation` / `currency_not_allowed` / `consents_required`
|
|
231
|
+
* / `unknown_consent`, 409 email taken. */
|
|
231
232
|
async register(input) {
|
|
232
233
|
const resp = await this.http.post("/auth/register", {
|
|
233
234
|
body: withRemember(input),
|
|
@@ -272,6 +273,8 @@ var AuthResource = class {
|
|
|
272
273
|
if (input.provision !== void 0) body.provision = input.provision;
|
|
273
274
|
if (input.attribution !== void 0) body.attribution = input.attribution;
|
|
274
275
|
if (input.code !== void 0) body.code = input.code;
|
|
276
|
+
if (input.consents !== void 0) body.consents = input.consents;
|
|
277
|
+
if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
|
|
275
278
|
let resp;
|
|
276
279
|
try {
|
|
277
280
|
resp = await this.http.post("/auth/telegram/exchange", {
|
|
@@ -306,12 +309,30 @@ var AuthResource = class {
|
|
|
306
309
|
await Promise.resolve(this.tokens.set(resp.access_token));
|
|
307
310
|
return resp;
|
|
308
311
|
}
|
|
309
|
-
/** Attach
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
+
/** Attach the first real email to a Telegram-made account (and clear
|
|
313
|
+
* `email_pending`). 409 if taken. An account that already has a real
|
|
314
|
+
* address gets 409 `email_change_needs_code`: change it with
|
|
315
|
+
* {@link requestEmailChange} and {@link confirmEmailChange}. */
|
|
312
316
|
async linkEmail(input) {
|
|
313
317
|
return this.http.post("/me/email", { body: { email: input.email } });
|
|
314
318
|
}
|
|
319
|
+
/** Step one of an email change: a six-digit code goes to the new address
|
|
320
|
+
* and works for 5 minutes. Nothing changes yet.
|
|
321
|
+
* Errors: 400 `same_email`, 409 address taken, 429 `too_many_requests`
|
|
322
|
+
* (five codes an hour). */
|
|
323
|
+
async requestEmailChange(input) {
|
|
324
|
+
return this.http.post("/me/email/change", {
|
|
325
|
+
body: { email: input.email }
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/** Step two: the code from the e-mail changes the address; the old one
|
|
329
|
+
* gets a notice. Errors: 401 `invalid_code` (after five wrong codes a new
|
|
330
|
+
* request is needed), 409 the address was taken meanwhile. */
|
|
331
|
+
async confirmEmailChange(input) {
|
|
332
|
+
return this.http.post("/me/email/change/confirm", {
|
|
333
|
+
body: { challenge_id: input.challengeId, code: input.code }
|
|
334
|
+
});
|
|
335
|
+
}
|
|
315
336
|
/** Current user — fails 401 when the stored JWT is expired or
|
|
316
337
|
* missing. Useful as a "do I have a session" probe on app boot. */
|
|
317
338
|
async me() {
|
|
@@ -343,6 +364,7 @@ function cardRequestBody(input) {
|
|
|
343
364
|
useBonus,
|
|
344
365
|
bonusAmount,
|
|
345
366
|
promoCode,
|
|
367
|
+
consentChannel,
|
|
346
368
|
initial_amount: _ignored,
|
|
347
369
|
...rest
|
|
348
370
|
} = input;
|
|
@@ -353,6 +375,7 @@ function cardRequestBody(input) {
|
|
|
353
375
|
if (useBonus !== void 0) body["use_bonus"] = useBonus;
|
|
354
376
|
if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
|
|
355
377
|
if (promoCode !== void 0) body["promo_code"] = promoCode;
|
|
378
|
+
if (consentChannel !== void 0) body["consent_channel"] = consentChannel;
|
|
356
379
|
return body;
|
|
357
380
|
}
|
|
358
381
|
var CardsResource = class {
|
|
@@ -1073,6 +1096,44 @@ var AttributionResource = class {
|
|
|
1073
1096
|
return this.http.put("/me/attribution/survey", { body });
|
|
1074
1097
|
}
|
|
1075
1098
|
};
|
|
1099
|
+
function tgWebApp() {
|
|
1100
|
+
return globalThis.Telegram?.WebApp?.initDataUnsafe;
|
|
1101
|
+
}
|
|
1102
|
+
function readCookie(name) {
|
|
1103
|
+
const doc = globalThis.document;
|
|
1104
|
+
if (!doc?.cookie) return void 0;
|
|
1105
|
+
for (const part of doc.cookie.split(";")) {
|
|
1106
|
+
const [k, ...v] = part.trim().split("=");
|
|
1107
|
+
if (k === name) return decodeURIComponent(v.join("="));
|
|
1108
|
+
}
|
|
1109
|
+
return void 0;
|
|
1110
|
+
}
|
|
1111
|
+
var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
|
|
1112
|
+
function anonymousKey(opts = {}) {
|
|
1113
|
+
const tgId = tgWebApp()?.user?.id;
|
|
1114
|
+
if (tgId) return `tg:${tgId}`;
|
|
1115
|
+
const g = globalThis;
|
|
1116
|
+
if (!g.document) return void 0;
|
|
1117
|
+
const name = opts.name ?? "takeal_anon";
|
|
1118
|
+
let stored;
|
|
1119
|
+
try {
|
|
1120
|
+
stored = g.localStorage?.getItem(name) ?? void 0;
|
|
1121
|
+
} catch {
|
|
1122
|
+
stored = void 0;
|
|
1123
|
+
}
|
|
1124
|
+
const fromCookie = readCookie(name);
|
|
1125
|
+
let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
|
|
1126
|
+
if (!key) {
|
|
1127
|
+
key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
|
|
1128
|
+
}
|
|
1129
|
+
try {
|
|
1130
|
+
g.localStorage?.setItem(name, key);
|
|
1131
|
+
} catch {
|
|
1132
|
+
}
|
|
1133
|
+
const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
|
|
1134
|
+
g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
|
|
1135
|
+
return key;
|
|
1136
|
+
}
|
|
1076
1137
|
|
|
1077
1138
|
// src/resources/history.ts
|
|
1078
1139
|
var HistoryResource = class {
|
|
@@ -1102,6 +1163,69 @@ var HistoryResource = class {
|
|
|
1102
1163
|
}
|
|
1103
1164
|
};
|
|
1104
1165
|
|
|
1166
|
+
// src/resources/consents.ts
|
|
1167
|
+
var ConsentsResource = class {
|
|
1168
|
+
constructor(http) {
|
|
1169
|
+
this.http = http;
|
|
1170
|
+
}
|
|
1171
|
+
/** Where each consent stands. */
|
|
1172
|
+
async get() {
|
|
1173
|
+
return this.http.get("/me/consents");
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Give (`true`) or withdraw (`false`) an optional consent: `marketing` or
|
|
1177
|
+
* `cookies_analytics`. Withdrawing `marketing` turns advertising off in
|
|
1178
|
+
* every channel at once; giving it turns on advertising by e-mail. A call
|
|
1179
|
+
* that changes nothing records nothing.
|
|
1180
|
+
*
|
|
1181
|
+
* Errors: 400 `consent_required` for `terms` or `personal_data`,
|
|
1182
|
+
* 400 `unknown_consent`.
|
|
1183
|
+
*/
|
|
1184
|
+
async set(kind, given, channel) {
|
|
1185
|
+
const body = { kind, given };
|
|
1186
|
+
if (channel !== void 0) body.channel = channel;
|
|
1187
|
+
return this.http.post("/me/consents", { body });
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Record what the cookie banner or the cookie settings say about
|
|
1191
|
+
* analytics. Works signed in or not: before sign-in the choice is kept
|
|
1192
|
+
* under the anonymous key and moves to the account at sign-up (send the
|
|
1193
|
+
* same key in `register({ attribution })`). Declining deletes the
|
|
1194
|
+
* visitor's recorded visits and analytics ids and stops their conversions
|
|
1195
|
+
* going to Metrica. Call it on every change, not on every page load; the
|
|
1196
|
+
* same answer twice records nothing (`recorded: false`).
|
|
1197
|
+
*
|
|
1198
|
+
* Errors: 400 `invalid_anonymous_key` when not signed in and no key could
|
|
1199
|
+
* be found.
|
|
1200
|
+
*/
|
|
1201
|
+
async setCookies(input) {
|
|
1202
|
+
const body = {
|
|
1203
|
+
analytics: input.analytics
|
|
1204
|
+
};
|
|
1205
|
+
const key = input.anonymousKey ?? anonymousKey();
|
|
1206
|
+
if (key !== void 0) body.anonymous_key = key;
|
|
1207
|
+
if (input.channel !== void 0) body.channel = input.channel;
|
|
1208
|
+
return this.http.post("/consents/cookies", { body });
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
// src/resources/receipts.ts
|
|
1213
|
+
var ReceiptsResource = class {
|
|
1214
|
+
constructor(http) {
|
|
1215
|
+
this.http = http;
|
|
1216
|
+
}
|
|
1217
|
+
async list(params = {}) {
|
|
1218
|
+
const q = new URLSearchParams();
|
|
1219
|
+
if (params.refId !== void 0) q.set("ref_id", params.refId);
|
|
1220
|
+
if (params.limit !== void 0) q.set("limit", String(params.limit));
|
|
1221
|
+
const qs = q.toString();
|
|
1222
|
+
return this.http.get(`/me/receipts${qs ? `?${qs}` : ""}`);
|
|
1223
|
+
}
|
|
1224
|
+
async get(id) {
|
|
1225
|
+
return this.http.get(`/me/receipts/${encodeURIComponent(id)}`);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1105
1229
|
// src/resources/funding-options.ts
|
|
1106
1230
|
var FundingOptionsResource = class {
|
|
1107
1231
|
constructor(http) {
|
|
@@ -1114,7 +1238,7 @@ var FundingOptionsResource = class {
|
|
|
1114
1238
|
};
|
|
1115
1239
|
|
|
1116
1240
|
// src/version.ts
|
|
1117
|
-
var SDK_VERSION = "0.6.
|
|
1241
|
+
var SDK_VERSION = "0.6.2";
|
|
1118
1242
|
|
|
1119
1243
|
// src/client-platform.ts
|
|
1120
1244
|
var CLIENT_HEADER = "X-Takeal-Client";
|
|
@@ -1189,7 +1313,7 @@ function isAbsolute(url) {
|
|
|
1189
1313
|
}
|
|
1190
1314
|
|
|
1191
1315
|
// src/compat.ts
|
|
1192
|
-
var SUPPORTED_MEISTER = ">=0.6.
|
|
1316
|
+
var SUPPORTED_MEISTER = ">=0.6.7, <0.7.0";
|
|
1193
1317
|
var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1194
1318
|
function parse(v) {
|
|
1195
1319
|
const m = SEMVER.exec(v.trim());
|
|
@@ -1298,7 +1422,9 @@ function createClient(opts) {
|
|
|
1298
1422
|
notifications: new NotificationsResource(http),
|
|
1299
1423
|
devices: new DevicesResource(http, client),
|
|
1300
1424
|
attribution: new AttributionResource(http),
|
|
1301
|
-
history: new HistoryResource(http)
|
|
1425
|
+
history: new HistoryResource(http),
|
|
1426
|
+
consents: new ConsentsResource(http),
|
|
1427
|
+
receipts: new ReceiptsResource(http)
|
|
1302
1428
|
};
|
|
1303
1429
|
}
|
|
1304
1430
|
function pickDefaultStore(key) {
|