@takeal/cusfront-sdk 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +87 -0
  3. package/dist/{cards-CF3-He2x.d.ts → cards-BrqeBqLV.d.ts} +442 -1
  4. package/dist/{cards-qfHz6xZY.d.cts → cards-ofoGRU9v.d.cts} +442 -1
  5. package/dist/index.cjs +329 -205
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +14 -8
  8. package/dist/index.d.ts +14 -8
  9. package/dist/index.js +329 -205
  10. package/dist/index.js.map +1 -1
  11. package/dist/react/index.d.cts +3 -2
  12. package/dist/react/index.d.ts +3 -2
  13. package/dist/resources/auth.cjs +48 -5
  14. package/dist/resources/auth.cjs.map +1 -1
  15. package/dist/resources/auth.d.cts +53 -7
  16. package/dist/resources/auth.d.ts +53 -7
  17. package/dist/resources/auth.js +48 -5
  18. package/dist/resources/auth.js.map +1 -1
  19. package/dist/resources/cards.cjs +36 -0
  20. package/dist/resources/cards.cjs.map +1 -1
  21. package/dist/resources/cards.d.cts +2 -1
  22. package/dist/resources/cards.d.ts +2 -1
  23. package/dist/resources/cards.js +36 -1
  24. package/dist/resources/cards.js.map +1 -1
  25. package/dist/resources/consents.cjs +91 -0
  26. package/dist/resources/consents.cjs.map +1 -0
  27. package/dist/resources/consents.d.cts +83 -0
  28. package/dist/resources/consents.d.ts +83 -0
  29. package/dist/resources/consents.js +89 -0
  30. package/dist/resources/consents.js.map +1 -0
  31. package/dist/resources/deposits.cjs +2 -0
  32. package/dist/resources/deposits.cjs.map +1 -1
  33. package/dist/resources/deposits.d.cts +2 -2
  34. package/dist/resources/deposits.d.ts +2 -2
  35. package/dist/resources/deposits.js +2 -0
  36. package/dist/resources/deposits.js.map +1 -1
  37. package/dist/resources/funding-options.d.cts +2 -2
  38. package/dist/resources/funding-options.d.ts +2 -2
  39. package/dist/resources/me.d.cts +2 -0
  40. package/dist/resources/me.d.ts +2 -0
  41. package/dist/resources/receipts.cjs +22 -0
  42. package/dist/resources/receipts.cjs.map +1 -0
  43. package/dist/resources/receipts.d.cts +51 -0
  44. package/dist/resources/receipts.d.ts +51 -0
  45. package/dist/resources/receipts.js +20 -0
  46. package/dist/resources/receipts.js.map +1 -0
  47. package/dist/telegram.cjs +367 -205
  48. package/dist/telegram.cjs.map +1 -1
  49. package/dist/telegram.d.cts +3 -2
  50. package/dist/telegram.d.ts +3 -2
  51. package/dist/telegram.js +367 -205
  52. package/dist/telegram.js.map +1 -1
  53. package/package.json +11 -1
  54. package/dist/deposits-B2LBe2k1.d.ts +0 -373
  55. package/dist/deposits-ZjT_btgi.d.cts +0 -373
@@ -1,8 +1,8 @@
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-ZjT_btgi.cjs';
5
- import './cards-qfHz6xZY.cjs';
4
+ import './cards-ofoGRU9v.cjs';
5
+ import './resources/consents.cjs';
6
6
  import './resources/balance.cjs';
7
7
  import './resources/bonus.cjs';
8
8
  import './resources/codes.cjs';
@@ -20,6 +20,7 @@ import './resources/notifications.cjs';
20
20
  import './devices-a5Z45Mx_.cjs';
21
21
  import './resources/attribution.cjs';
22
22
  import './resources/history.cjs';
23
+ import './resources/receipts.cjs';
23
24
  import './analytics.cjs';
24
25
 
25
26
  /**
@@ -1,8 +1,8 @@
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-B2LBe2k1.js';
5
- import './cards-CF3-He2x.js';
4
+ import './cards-BrqeBqLV.js';
5
+ import './resources/consents.js';
6
6
  import './resources/balance.js';
7
7
  import './resources/bonus.js';
8
8
  import './resources/codes.js';
@@ -20,6 +20,7 @@ import './resources/notifications.js';
20
20
  import './devices-B_YveTl9.js';
21
21
  import './resources/attribution.js';
22
22
  import './resources/history.js';
23
+ import './resources/receipts.js';
23
24
  import './analytics.js';
24
25
 
25
26
  /**
package/dist/telegram.js CHANGED
@@ -132,208 +132,6 @@ async function parseResponse(resp) {
132
132
  return body;
133
133
  }
134
134
 
135
- // src/resources/auth.ts
136
- function withRemember(input) {
137
- const { remember, ...rest } = input;
138
- return remember ? { ...rest, remember_me: true } : rest;
139
- }
140
- var AuthResource = class {
141
- constructor(http, tokens, remembered) {
142
- this.http = http;
143
- this.tokens = tokens;
144
- this.remembered = remembered;
145
- if (remembered) http.setRefresher(() => this.renew().then((r) => r.kind !== "gone"));
146
- }
147
- /** Store what a finished sign-in returned. */
148
- async keep(resp) {
149
- await Promise.resolve(this.tokens.set(resp.access_token));
150
- if (resp.remember_token && this.remembered) {
151
- await Promise.resolve(this.remembered.set(resp.remember_token));
152
- }
153
- }
154
- /** Renew a remembered sign-in: a new session and a new remember token,
155
- * both stored. Resolves `null` (and forgets the remember token) when there
156
- * is none or it no longer works; the app then shows the sign-in form.
157
- * The SDK does this by itself on a 401; call it on app start to resume a
158
- * session without a request failing first. */
159
- async refresh() {
160
- const r = await this.renew();
161
- if (r.kind === "renewed") return r.resp;
162
- if (r.kind === "taken_over") {
163
- const access = await Promise.resolve(this.tokens.get());
164
- const user = await this.me();
165
- return { stage: "jwt", access_token: access ?? "", expires_at: "", user };
166
- }
167
- return null;
168
- }
169
- /** The renewal itself, for the 401 path: it must not call the API again
170
- * through the client, or a second 401 would wait on this very renewal. */
171
- async renew() {
172
- const token = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
173
- if (!token) return { kind: "gone" };
174
- try {
175
- const resp = await this.http.post("/auth/refresh", {
176
- body: { remember_token: token },
177
- skipAuth: true
178
- });
179
- await this.keep(resp);
180
- return { kind: "renewed", resp };
181
- } catch (e) {
182
- if (isApiError(e) && e.status === 401) {
183
- const now = await Promise.resolve(this.remembered.get());
184
- if (now && now !== token && await Promise.resolve(this.tokens.get())) {
185
- return { kind: "taken_over" };
186
- }
187
- await Promise.resolve(this.remembered.clear());
188
- await Promise.resolve(this.tokens.clear());
189
- return { kind: "gone" };
190
- }
191
- throw e;
192
- }
193
- }
194
- /** Password-auth entry. May resolve to a JWT, or to a step-up
195
- * challenge that needs `verifyTotp` / `verifyOtp` next. */
196
- async login(input) {
197
- const resp = await this.http.post("/auth/login", {
198
- body: withRemember(input),
199
- skipAuth: true
200
- });
201
- if (resp.stage === "jwt") {
202
- await this.keep(resp);
203
- }
204
- return resp;
205
- }
206
- /** Verify a TOTP code (or XXXX-XXXX backup code) against a
207
- * `totp_required` challenge. On success the JWT is stored. */
208
- async verifyTotp(input) {
209
- const resp = await this.http.post("/auth/login/totp", {
210
- body: withRemember(input),
211
- skipAuth: true
212
- });
213
- await this.keep(resp);
214
- return resp;
215
- }
216
- /** Verify a 6-digit OTP code (Telegram / email) against an
217
- * `otp_sent` challenge. */
218
- async verifyOtp(input) {
219
- const resp = await this.http.post("/auth/login/otp/verify", {
220
- body: withRemember(input),
221
- skipAuth: true
222
- });
223
- await this.keep(resp);
224
- return resp;
225
- }
226
- /** Create an end-user account and sign it in. The JWT is stored.
227
- * `wallet_currency` must be one the deployment offers; omit it to take
228
- * the deployment default (it can be switched later via `client.wallet`
229
- * while the wallet is empty).
230
- * Errors: 400 `validation` / `currency_not_allowed`, 409 email taken. */
231
- async register(input) {
232
- const resp = await this.http.post("/auth/register", {
233
- body: withRemember(input),
234
- skipAuth: true
235
- });
236
- await this.keep(resp);
237
- return resp;
238
- }
239
- /** Finish a `totp_setup_required` login: send the first code from the
240
- * authenticator app. The JWT is stored. The response carries ten
241
- * one-time `backup_codes` that are never returned again, so show them to
242
- * the user right away and don't keep them on the device. */
243
- async completeTotpSetup(input) {
244
- const resp = await this.http.post("/auth/login/totp-setup", {
245
- body: withRemember(input),
246
- skipAuth: true
247
- });
248
- await this.keep(resp);
249
- return resp;
250
- }
251
- /** Change the signed-in user's password. Every other session of the
252
- * account is signed out; this one stays valid.
253
- * Errors: 400 when the new password fails the policy, 401 when the
254
- * current one is wrong. */
255
- async changePassword(input) {
256
- return this.http.post("/auth/password", {
257
- body: input
258
- });
259
- }
260
- /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
261
- * telegram/email; for TOTP it short-circuits back to the challenge. */
262
- async switchMethod(input) {
263
- return this.http.post("/auth/login/2fa/switch", {
264
- body: input,
265
- skipAuth: true
266
- });
267
- }
268
- async exchangeTelegram(input) {
269
- const body = {
270
- init_data: input.initData
271
- };
272
- if (input.provision !== void 0) body.provision = input.provision;
273
- if (input.attribution !== void 0) body.attribution = input.attribution;
274
- if (input.code !== void 0) body.code = input.code;
275
- let resp;
276
- try {
277
- resp = await this.http.post("/auth/telegram/exchange", {
278
- body,
279
- skipAuth: true
280
- });
281
- } catch (e) {
282
- if (isApiError(e) && e.status === 404 && e.code === "telegram_unknown") {
283
- return { stage: "unknown" };
284
- }
285
- throw e;
286
- }
287
- await Promise.resolve(this.tokens.set(resp.access_token));
288
- return resp;
289
- }
290
- /** Attach the Telegram account behind `initData` to an existing email +
291
- * password account and sign in as that account. No bearer needed; the
292
- * password is checked the same way `login` checks it. The JWT is stored.
293
- *
294
- * Errors: 401 `unauthenticated` (wrong email or password, as with
295
- * `login`) / `invalid_init_data`; 403
296
- * `user_disabled` / `second_factor_required` (accounts that sign in with
297
- * a second factor can't be linked from a Mini App); 409
298
- * `telegram_already_linked_other` (this account already has a different
299
- * Telegram; unlink it first) / `telegram_in_use` (this Telegram belongs to
300
- * another account); 503 `telegram_not_configured`. */
301
- async linkTelegram(input) {
302
- const resp = await this.http.post("/auth/telegram/link", {
303
- body: { init_data: input.initData, email: input.email, password: input.password },
304
- skipAuth: true
305
- });
306
- await Promise.resolve(this.tokens.set(resp.access_token));
307
- return resp;
308
- }
309
- /** Attach a real email to the current user (and clear `email_pending`).
310
- * Used after a Telegram exchange to satisfy the email requirement; also
311
- * works for a password user changing their address. 409 if taken. */
312
- async linkEmail(input) {
313
- return this.http.post("/me/email", { body: { email: input.email } });
314
- }
315
- /** Current user — fails 401 when the stored JWT is expired or
316
- * missing. Useful as a "do I have a session" probe on app boot. */
317
- async me() {
318
- return this.http.get("/auth/me");
319
- }
320
- /** Sign out: ends this session and the remembered sign-in on the
321
- * server (best effort: a network failure still signs out locally), then
322
- * forgets both tokens. */
323
- async signOut() {
324
- const remember = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
325
- try {
326
- await this.http.post("/auth/logout", {
327
- body: remember ? { remember_token: remember } : {},
328
- retried: true
329
- });
330
- } catch {
331
- }
332
- await Promise.resolve(this.tokens.clear());
333
- if (this.remembered) await Promise.resolve(this.remembered.clear());
334
- }
335
- };
336
-
337
135
  // src/resources/cards.ts
338
136
  function cardRequestBody(input) {
339
137
  const {
@@ -343,6 +141,7 @@ function cardRequestBody(input) {
343
141
  useBonus,
344
142
  bonusAmount,
345
143
  promoCode,
144
+ consentChannel,
346
145
  initial_amount: _ignored,
347
146
  ...rest
348
147
  } = input;
@@ -353,6 +152,24 @@ function cardRequestBody(input) {
353
152
  if (useBonus !== void 0) body["use_bonus"] = useBonus;
354
153
  if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
355
154
  if (promoCode !== void 0) body["promo_code"] = promoCode;
155
+ if (consentChannel !== void 0) body["consent_channel"] = consentChannel;
156
+ return body;
157
+ }
158
+ function cardOrderBody(input) {
159
+ const body = {
160
+ product_id: input.productId,
161
+ method: input.method
162
+ };
163
+ if (input.designId !== void 0) body["design_id"] = input.designId;
164
+ if (input.name !== void 0) body["name"] = input.name;
165
+ if (input.funderSlug !== void 0) body["funder_slug"] = input.funderSlug;
166
+ if (input.currency !== void 0) body["currency"] = input.currency;
167
+ if (input.extraLoad !== void 0) body["extra_load"] = input.extraLoad;
168
+ if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
169
+ if (input.useBonus !== void 0) body["use_bonus"] = input.useBonus;
170
+ if (input.consents !== void 0) body["consents"] = input.consents;
171
+ if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
172
+ if (input.metadata !== void 0) body["metadata"] = input.metadata;
356
173
  return body;
357
174
  }
358
175
  var CardsResource = class {
@@ -372,6 +189,22 @@ var CardsResource = class {
372
189
  idempotencyKey
373
190
  });
374
191
  }
192
+ /**
193
+ * Buy a card in one step: the API prices the product in the payment's
194
+ * currency, locks the rate and opens the top-up that issues the card.
195
+ * Send the user to `order.deposit.redirect_url`; the card shows as
196
+ * `pending_payment` until the payment is confirmed. The same
197
+ * `idempotencyKey` returns the same order.
198
+ * Errors: 400 `unknown_product` / `method_not_available` / a limit of the
199
+ * way of paying, 503 no funding connector or no exchange rate.
200
+ */
201
+ async order(input) {
202
+ const { idempotencyKey, ...order } = input;
203
+ return this.http.post("/me/card-orders", {
204
+ body: cardOrderBody(order),
205
+ idempotencyKey
206
+ });
207
+ }
375
208
  /**
376
209
  * The cards the caller can order, in the order the storefront shows them
377
210
  * (`is_default` marks the one issued when none is chosen). Each item
@@ -534,6 +367,232 @@ var CardsResource = class {
534
367
  }
535
368
  };
536
369
 
370
+ // src/resources/auth.ts
371
+ function withRemember(input) {
372
+ const { remember, ...rest } = input;
373
+ return remember ? { ...rest, remember_me: true } : rest;
374
+ }
375
+ var AuthResource = class {
376
+ constructor(http, tokens, remembered) {
377
+ this.http = http;
378
+ this.tokens = tokens;
379
+ this.remembered = remembered;
380
+ if (remembered) http.setRefresher(() => this.renew().then((r) => r.kind !== "gone"));
381
+ }
382
+ /** Store what a finished sign-in returned. */
383
+ async keep(resp) {
384
+ await Promise.resolve(this.tokens.set(resp.access_token));
385
+ if (resp.remember_token && this.remembered) {
386
+ await Promise.resolve(this.remembered.set(resp.remember_token));
387
+ }
388
+ }
389
+ /** Renew a remembered sign-in: a new session and a new remember token,
390
+ * both stored. Resolves `null` (and forgets the remember token) when there
391
+ * is none or it no longer works; the app then shows the sign-in form.
392
+ * The SDK does this by itself on a 401; call it on app start to resume a
393
+ * session without a request failing first. */
394
+ async refresh() {
395
+ const r = await this.renew();
396
+ if (r.kind === "renewed") return r.resp;
397
+ if (r.kind === "taken_over") {
398
+ const access = await Promise.resolve(this.tokens.get());
399
+ const user = await this.me();
400
+ return { stage: "jwt", access_token: access ?? "", expires_at: "", user };
401
+ }
402
+ return null;
403
+ }
404
+ /** The renewal itself, for the 401 path: it must not call the API again
405
+ * through the client, or a second 401 would wait on this very renewal. */
406
+ async renew() {
407
+ const token = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
408
+ if (!token) return { kind: "gone" };
409
+ try {
410
+ const resp = await this.http.post("/auth/refresh", {
411
+ body: { remember_token: token },
412
+ skipAuth: true
413
+ });
414
+ await this.keep(resp);
415
+ return { kind: "renewed", resp };
416
+ } catch (e) {
417
+ if (isApiError(e) && e.status === 401) {
418
+ const now = await Promise.resolve(this.remembered.get());
419
+ if (now && now !== token && await Promise.resolve(this.tokens.get())) {
420
+ return { kind: "taken_over" };
421
+ }
422
+ await Promise.resolve(this.remembered.clear());
423
+ await Promise.resolve(this.tokens.clear());
424
+ return { kind: "gone" };
425
+ }
426
+ throw e;
427
+ }
428
+ }
429
+ /** Password-auth entry. May resolve to a JWT, or to a step-up
430
+ * challenge that needs `verifyTotp` / `verifyOtp` next. */
431
+ async login(input) {
432
+ const resp = await this.http.post("/auth/login", {
433
+ body: withRemember(input),
434
+ skipAuth: true
435
+ });
436
+ if (resp.stage === "jwt") {
437
+ await this.keep(resp);
438
+ }
439
+ return resp;
440
+ }
441
+ /** Verify a TOTP code (or XXXX-XXXX backup code) against a
442
+ * `totp_required` challenge. On success the JWT is stored. */
443
+ async verifyTotp(input) {
444
+ const resp = await this.http.post("/auth/login/totp", {
445
+ body: withRemember(input),
446
+ skipAuth: true
447
+ });
448
+ await this.keep(resp);
449
+ return resp;
450
+ }
451
+ /** Verify a 6-digit OTP code (Telegram / email) against an
452
+ * `otp_sent` challenge. */
453
+ async verifyOtp(input) {
454
+ const resp = await this.http.post("/auth/login/otp/verify", {
455
+ body: withRemember(input),
456
+ skipAuth: true
457
+ });
458
+ await this.keep(resp);
459
+ return resp;
460
+ }
461
+ /** Create an end-user account and sign it in. The JWT is stored.
462
+ * `wallet_currency` must be one the deployment offers; omit it to take
463
+ * the deployment default (it can be switched later via `client.wallet`
464
+ * while the wallet is empty).
465
+ * Errors: 400 `validation` / `currency_not_allowed` / `consents_required`
466
+ * / `unknown_consent`, 409 email taken. */
467
+ async register(input) {
468
+ const { cardOrder, ...rest } = input;
469
+ const body = withRemember(rest);
470
+ if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
471
+ const resp = await this.http.post("/auth/register", {
472
+ body,
473
+ skipAuth: true
474
+ });
475
+ await this.keep(resp);
476
+ return resp;
477
+ }
478
+ /** Finish a `totp_setup_required` login: send the first code from the
479
+ * authenticator app. The JWT is stored. The response carries ten
480
+ * one-time `backup_codes` that are never returned again, so show them to
481
+ * the user right away and don't keep them on the device. */
482
+ async completeTotpSetup(input) {
483
+ const resp = await this.http.post("/auth/login/totp-setup", {
484
+ body: withRemember(input),
485
+ skipAuth: true
486
+ });
487
+ await this.keep(resp);
488
+ return resp;
489
+ }
490
+ /** Change the signed-in user's password. Every other session of the
491
+ * account is signed out; this one stays valid.
492
+ * Errors: 400 when the new password fails the policy, 401 when the
493
+ * current one is wrong. */
494
+ async changePassword(input) {
495
+ return this.http.post("/auth/password", {
496
+ body: input
497
+ });
498
+ }
499
+ /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
500
+ * telegram/email; for TOTP it short-circuits back to the challenge. */
501
+ async switchMethod(input) {
502
+ return this.http.post("/auth/login/2fa/switch", {
503
+ body: input,
504
+ skipAuth: true
505
+ });
506
+ }
507
+ async exchangeTelegram(input) {
508
+ const body = {
509
+ init_data: input.initData
510
+ };
511
+ if (input.provision !== void 0) body.provision = input.provision;
512
+ if (input.attribution !== void 0) body.attribution = input.attribution;
513
+ if (input.code !== void 0) body.code = input.code;
514
+ if (input.consents !== void 0) body.consents = input.consents;
515
+ if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
516
+ let resp;
517
+ try {
518
+ resp = await this.http.post("/auth/telegram/exchange", {
519
+ body,
520
+ skipAuth: true
521
+ });
522
+ } catch (e) {
523
+ if (isApiError(e) && e.status === 404 && e.code === "telegram_unknown") {
524
+ return { stage: "unknown" };
525
+ }
526
+ throw e;
527
+ }
528
+ await Promise.resolve(this.tokens.set(resp.access_token));
529
+ return resp;
530
+ }
531
+ /** Attach the Telegram account behind `initData` to an existing email +
532
+ * password account and sign in as that account. No bearer needed; the
533
+ * password is checked the same way `login` checks it. The JWT is stored.
534
+ *
535
+ * Errors: 401 `unauthenticated` (wrong email or password, as with
536
+ * `login`) / `invalid_init_data`; 403
537
+ * `user_disabled` / `second_factor_required` (accounts that sign in with
538
+ * a second factor can't be linked from a Mini App); 409
539
+ * `telegram_already_linked_other` (this account already has a different
540
+ * Telegram; unlink it first) / `telegram_in_use` (this Telegram belongs to
541
+ * another account); 503 `telegram_not_configured`. */
542
+ async linkTelegram(input) {
543
+ const resp = await this.http.post("/auth/telegram/link", {
544
+ body: { init_data: input.initData, email: input.email, password: input.password },
545
+ skipAuth: true
546
+ });
547
+ await Promise.resolve(this.tokens.set(resp.access_token));
548
+ return resp;
549
+ }
550
+ /** Attach the first real email to a Telegram-made account (and clear
551
+ * `email_pending`). 409 if taken. An account that already has a real
552
+ * address gets 409 `email_change_needs_code`: change it with
553
+ * {@link requestEmailChange} and {@link confirmEmailChange}. */
554
+ async linkEmail(input) {
555
+ return this.http.post("/me/email", { body: { email: input.email } });
556
+ }
557
+ /** Step one of an email change: a six-digit code goes to the new address
558
+ * and works for 5 minutes. Nothing changes yet.
559
+ * Errors: 400 `same_email`, 409 address taken, 429 `too_many_requests`
560
+ * (five codes an hour). */
561
+ async requestEmailChange(input) {
562
+ return this.http.post("/me/email/change", {
563
+ body: { email: input.email }
564
+ });
565
+ }
566
+ /** Step two: the code from the e-mail changes the address; the old one
567
+ * gets a notice. Errors: 401 `invalid_code` (after five wrong codes a new
568
+ * request is needed), 409 the address was taken meanwhile. */
569
+ async confirmEmailChange(input) {
570
+ return this.http.post("/me/email/change/confirm", {
571
+ body: { challenge_id: input.challengeId, code: input.code }
572
+ });
573
+ }
574
+ /** Current user — fails 401 when the stored JWT is expired or
575
+ * missing. Useful as a "do I have a session" probe on app boot. */
576
+ async me() {
577
+ return this.http.get("/auth/me");
578
+ }
579
+ /** Sign out: ends this session and the remembered sign-in on the
580
+ * server (best effort: a network failure still signs out locally), then
581
+ * forgets both tokens. */
582
+ async signOut() {
583
+ const remember = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
584
+ try {
585
+ await this.http.post("/auth/logout", {
586
+ body: remember ? { remember_token: remember } : {},
587
+ retried: true
588
+ });
589
+ } catch {
590
+ }
591
+ await Promise.resolve(this.tokens.clear());
592
+ if (this.remembered) await Promise.resolve(this.remembered.clear());
593
+ }
594
+ };
595
+
537
596
  // src/resources/deposits.ts
538
597
  var DepositsResource = class {
539
598
  constructor(http) {
@@ -1073,6 +1132,44 @@ var AttributionResource = class {
1073
1132
  return this.http.put("/me/attribution/survey", { body });
1074
1133
  }
1075
1134
  };
1135
+ function tgWebApp() {
1136
+ return globalThis.Telegram?.WebApp?.initDataUnsafe;
1137
+ }
1138
+ function readCookie(name) {
1139
+ const doc = globalThis.document;
1140
+ if (!doc?.cookie) return void 0;
1141
+ for (const part of doc.cookie.split(";")) {
1142
+ const [k, ...v] = part.trim().split("=");
1143
+ if (k === name) return decodeURIComponent(v.join("="));
1144
+ }
1145
+ return void 0;
1146
+ }
1147
+ var KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;
1148
+ function anonymousKey(opts = {}) {
1149
+ const tgId = tgWebApp()?.user?.id;
1150
+ if (tgId) return `tg:${tgId}`;
1151
+ const g = globalThis;
1152
+ if (!g.document) return void 0;
1153
+ const name = opts.name ?? "takeal_anon";
1154
+ let stored;
1155
+ try {
1156
+ stored = g.localStorage?.getItem(name) ?? void 0;
1157
+ } catch {
1158
+ stored = void 0;
1159
+ }
1160
+ const fromCookie = readCookie(name);
1161
+ let key = [fromCookie, stored].find((k) => !!k && KEY_SHAPE.test(k));
1162
+ if (!key) {
1163
+ key = g.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
1164
+ }
1165
+ try {
1166
+ g.localStorage?.setItem(name, key);
1167
+ } catch {
1168
+ }
1169
+ const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : "";
1170
+ g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;
1171
+ return key;
1172
+ }
1076
1173
 
1077
1174
  // src/resources/history.ts
1078
1175
  var HistoryResource = class {
@@ -1102,6 +1199,69 @@ var HistoryResource = class {
1102
1199
  }
1103
1200
  };
1104
1201
 
1202
+ // src/resources/consents.ts
1203
+ var ConsentsResource = class {
1204
+ constructor(http) {
1205
+ this.http = http;
1206
+ }
1207
+ /** Where each consent stands. */
1208
+ async get() {
1209
+ return this.http.get("/me/consents");
1210
+ }
1211
+ /**
1212
+ * Give (`true`) or withdraw (`false`) an optional consent: `marketing` or
1213
+ * `cookies_analytics`. Withdrawing `marketing` turns advertising off in
1214
+ * every channel at once; giving it turns on advertising by e-mail. A call
1215
+ * that changes nothing records nothing.
1216
+ *
1217
+ * Errors: 400 `consent_required` for `terms` or `personal_data`,
1218
+ * 400 `unknown_consent`.
1219
+ */
1220
+ async set(kind, given, channel) {
1221
+ const body = { kind, given };
1222
+ if (channel !== void 0) body.channel = channel;
1223
+ return this.http.post("/me/consents", { body });
1224
+ }
1225
+ /**
1226
+ * Record what the cookie banner or the cookie settings say about
1227
+ * analytics. Works signed in or not: before sign-in the choice is kept
1228
+ * under the anonymous key and moves to the account at sign-up (send the
1229
+ * same key in `register({ attribution })`). Declining deletes the
1230
+ * visitor's recorded visits and analytics ids and stops their conversions
1231
+ * going to Metrica. Call it on every change, not on every page load; the
1232
+ * same answer twice records nothing (`recorded: false`).
1233
+ *
1234
+ * Errors: 400 `invalid_anonymous_key` when not signed in and no key could
1235
+ * be found.
1236
+ */
1237
+ async setCookies(input) {
1238
+ const body = {
1239
+ analytics: input.analytics
1240
+ };
1241
+ const key = input.anonymousKey ?? anonymousKey();
1242
+ if (key !== void 0) body.anonymous_key = key;
1243
+ if (input.channel !== void 0) body.channel = input.channel;
1244
+ return this.http.post("/consents/cookies", { body });
1245
+ }
1246
+ };
1247
+
1248
+ // src/resources/receipts.ts
1249
+ var ReceiptsResource = class {
1250
+ constructor(http) {
1251
+ this.http = http;
1252
+ }
1253
+ async list(params = {}) {
1254
+ const q = new URLSearchParams();
1255
+ if (params.refId !== void 0) q.set("ref_id", params.refId);
1256
+ if (params.limit !== void 0) q.set("limit", String(params.limit));
1257
+ const qs = q.toString();
1258
+ return this.http.get(`/me/receipts${qs ? `?${qs}` : ""}`);
1259
+ }
1260
+ async get(id) {
1261
+ return this.http.get(`/me/receipts/${encodeURIComponent(id)}`);
1262
+ }
1263
+ };
1264
+
1105
1265
  // src/resources/funding-options.ts
1106
1266
  var FundingOptionsResource = class {
1107
1267
  constructor(http) {
@@ -1114,7 +1274,7 @@ var FundingOptionsResource = class {
1114
1274
  };
1115
1275
 
1116
1276
  // src/version.ts
1117
- var SDK_VERSION = "0.6.1";
1277
+ var SDK_VERSION = "0.6.3";
1118
1278
 
1119
1279
  // src/client-platform.ts
1120
1280
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1189,7 +1349,7 @@ function isAbsolute(url) {
1189
1349
  }
1190
1350
 
1191
1351
  // src/compat.ts
1192
- var SUPPORTED_MEISTER = ">=0.6.4, <0.7.0";
1352
+ var SUPPORTED_MEISTER = ">=0.6.8, <0.7.0";
1193
1353
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1194
1354
  function parse(v) {
1195
1355
  const m = SEMVER.exec(v.trim());
@@ -1298,7 +1458,9 @@ function createClient(opts) {
1298
1458
  notifications: new NotificationsResource(http),
1299
1459
  devices: new DevicesResource(http, client),
1300
1460
  attribution: new AttributionResource(http),
1301
- history: new HistoryResource(http)
1461
+ history: new HistoryResource(http),
1462
+ consents: new ConsentsResource(http),
1463
+ receipts: new ReceiptsResource(http)
1302
1464
  };
1303
1465
  }
1304
1466
  function pickDefaultStore(key) {