@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
package/dist/index.js CHANGED
@@ -135,208 +135,6 @@ async function parseResponse(resp) {
135
135
  return body;
136
136
  }
137
137
 
138
- // src/resources/auth.ts
139
- function withRemember(input) {
140
- const { remember, ...rest } = input;
141
- return remember ? { ...rest, remember_me: true } : rest;
142
- }
143
- var AuthResource = class {
144
- constructor(http, tokens, remembered) {
145
- this.http = http;
146
- this.tokens = tokens;
147
- this.remembered = remembered;
148
- if (remembered) http.setRefresher(() => this.renew().then((r) => r.kind !== "gone"));
149
- }
150
- /** Store what a finished sign-in returned. */
151
- async keep(resp) {
152
- await Promise.resolve(this.tokens.set(resp.access_token));
153
- if (resp.remember_token && this.remembered) {
154
- await Promise.resolve(this.remembered.set(resp.remember_token));
155
- }
156
- }
157
- /** Renew a remembered sign-in: a new session and a new remember token,
158
- * both stored. Resolves `null` (and forgets the remember token) when there
159
- * is none or it no longer works; the app then shows the sign-in form.
160
- * The SDK does this by itself on a 401; call it on app start to resume a
161
- * session without a request failing first. */
162
- async refresh() {
163
- const r = await this.renew();
164
- if (r.kind === "renewed") return r.resp;
165
- if (r.kind === "taken_over") {
166
- const access = await Promise.resolve(this.tokens.get());
167
- const user = await this.me();
168
- return { stage: "jwt", access_token: access ?? "", expires_at: "", user };
169
- }
170
- return null;
171
- }
172
- /** The renewal itself, for the 401 path: it must not call the API again
173
- * through the client, or a second 401 would wait on this very renewal. */
174
- async renew() {
175
- const token = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
176
- if (!token) return { kind: "gone" };
177
- try {
178
- const resp = await this.http.post("/auth/refresh", {
179
- body: { remember_token: token },
180
- skipAuth: true
181
- });
182
- await this.keep(resp);
183
- return { kind: "renewed", resp };
184
- } catch (e) {
185
- if (isApiError(e) && e.status === 401) {
186
- const now = await Promise.resolve(this.remembered.get());
187
- if (now && now !== token && await Promise.resolve(this.tokens.get())) {
188
- return { kind: "taken_over" };
189
- }
190
- await Promise.resolve(this.remembered.clear());
191
- await Promise.resolve(this.tokens.clear());
192
- return { kind: "gone" };
193
- }
194
- throw e;
195
- }
196
- }
197
- /** Password-auth entry. May resolve to a JWT, or to a step-up
198
- * challenge that needs `verifyTotp` / `verifyOtp` next. */
199
- async login(input) {
200
- const resp = await this.http.post("/auth/login", {
201
- body: withRemember(input),
202
- skipAuth: true
203
- });
204
- if (resp.stage === "jwt") {
205
- await this.keep(resp);
206
- }
207
- return resp;
208
- }
209
- /** Verify a TOTP code (or XXXX-XXXX backup code) against a
210
- * `totp_required` challenge. On success the JWT is stored. */
211
- async verifyTotp(input) {
212
- const resp = await this.http.post("/auth/login/totp", {
213
- body: withRemember(input),
214
- skipAuth: true
215
- });
216
- await this.keep(resp);
217
- return resp;
218
- }
219
- /** Verify a 6-digit OTP code (Telegram / email) against an
220
- * `otp_sent` challenge. */
221
- async verifyOtp(input) {
222
- const resp = await this.http.post("/auth/login/otp/verify", {
223
- body: withRemember(input),
224
- skipAuth: true
225
- });
226
- await this.keep(resp);
227
- return resp;
228
- }
229
- /** Create an end-user account and sign it in. The JWT is stored.
230
- * `wallet_currency` must be one the deployment offers; omit it to take
231
- * the deployment default (it can be switched later via `client.wallet`
232
- * while the wallet is empty).
233
- * Errors: 400 `validation` / `currency_not_allowed`, 409 email taken. */
234
- async register(input) {
235
- const resp = await this.http.post("/auth/register", {
236
- body: withRemember(input),
237
- skipAuth: true
238
- });
239
- await this.keep(resp);
240
- return resp;
241
- }
242
- /** Finish a `totp_setup_required` login: send the first code from the
243
- * authenticator app. The JWT is stored. The response carries ten
244
- * one-time `backup_codes` that are never returned again, so show them to
245
- * the user right away and don't keep them on the device. */
246
- async completeTotpSetup(input) {
247
- const resp = await this.http.post("/auth/login/totp-setup", {
248
- body: withRemember(input),
249
- skipAuth: true
250
- });
251
- await this.keep(resp);
252
- return resp;
253
- }
254
- /** Change the signed-in user's password. Every other session of the
255
- * account is signed out; this one stays valid.
256
- * Errors: 400 when the new password fails the policy, 401 when the
257
- * current one is wrong. */
258
- async changePassword(input) {
259
- return this.http.post("/auth/password", {
260
- body: input
261
- });
262
- }
263
- /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
264
- * telegram/email; for TOTP it short-circuits back to the challenge. */
265
- async switchMethod(input) {
266
- return this.http.post("/auth/login/2fa/switch", {
267
- body: input,
268
- skipAuth: true
269
- });
270
- }
271
- async exchangeTelegram(input) {
272
- const body = {
273
- init_data: input.initData
274
- };
275
- if (input.provision !== void 0) body.provision = input.provision;
276
- if (input.attribution !== void 0) body.attribution = input.attribution;
277
- if (input.code !== void 0) body.code = input.code;
278
- let resp;
279
- try {
280
- resp = await this.http.post("/auth/telegram/exchange", {
281
- body,
282
- skipAuth: true
283
- });
284
- } catch (e) {
285
- if (isApiError(e) && e.status === 404 && e.code === "telegram_unknown") {
286
- return { stage: "unknown" };
287
- }
288
- throw e;
289
- }
290
- await Promise.resolve(this.tokens.set(resp.access_token));
291
- return resp;
292
- }
293
- /** Attach the Telegram account behind `initData` to an existing email +
294
- * password account and sign in as that account. No bearer needed; the
295
- * password is checked the same way `login` checks it. The JWT is stored.
296
- *
297
- * Errors: 401 `unauthenticated` (wrong email or password, as with
298
- * `login`) / `invalid_init_data`; 403
299
- * `user_disabled` / `second_factor_required` (accounts that sign in with
300
- * a second factor can't be linked from a Mini App); 409
301
- * `telegram_already_linked_other` (this account already has a different
302
- * Telegram; unlink it first) / `telegram_in_use` (this Telegram belongs to
303
- * another account); 503 `telegram_not_configured`. */
304
- async linkTelegram(input) {
305
- const resp = await this.http.post("/auth/telegram/link", {
306
- body: { init_data: input.initData, email: input.email, password: input.password },
307
- skipAuth: true
308
- });
309
- await Promise.resolve(this.tokens.set(resp.access_token));
310
- return resp;
311
- }
312
- /** Attach a real email to the current user (and clear `email_pending`).
313
- * Used after a Telegram exchange to satisfy the email requirement; also
314
- * works for a password user changing their address. 409 if taken. */
315
- async linkEmail(input) {
316
- return this.http.post("/me/email", { body: { email: input.email } });
317
- }
318
- /** Current user — fails 401 when the stored JWT is expired or
319
- * missing. Useful as a "do I have a session" probe on app boot. */
320
- async me() {
321
- return this.http.get("/auth/me");
322
- }
323
- /** Sign out: ends this session and the remembered sign-in on the
324
- * server (best effort: a network failure still signs out locally), then
325
- * forgets both tokens. */
326
- async signOut() {
327
- const remember = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
328
- try {
329
- await this.http.post("/auth/logout", {
330
- body: remember ? { remember_token: remember } : {},
331
- retried: true
332
- });
333
- } catch {
334
- }
335
- await Promise.resolve(this.tokens.clear());
336
- if (this.remembered) await Promise.resolve(this.remembered.clear());
337
- }
338
- };
339
-
340
138
  // src/resources/cards.ts
341
139
  function cardRequestBody(input) {
342
140
  const {
@@ -346,6 +144,7 @@ function cardRequestBody(input) {
346
144
  useBonus,
347
145
  bonusAmount,
348
146
  promoCode,
147
+ consentChannel,
349
148
  initial_amount: _ignored,
350
149
  ...rest
351
150
  } = input;
@@ -356,6 +155,24 @@ function cardRequestBody(input) {
356
155
  if (useBonus !== void 0) body["use_bonus"] = useBonus;
357
156
  if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
358
157
  if (promoCode !== void 0) body["promo_code"] = promoCode;
158
+ if (consentChannel !== void 0) body["consent_channel"] = consentChannel;
159
+ return body;
160
+ }
161
+ function cardOrderBody(input) {
162
+ const body = {
163
+ product_id: input.productId,
164
+ method: input.method
165
+ };
166
+ if (input.designId !== void 0) body["design_id"] = input.designId;
167
+ if (input.name !== void 0) body["name"] = input.name;
168
+ if (input.funderSlug !== void 0) body["funder_slug"] = input.funderSlug;
169
+ if (input.currency !== void 0) body["currency"] = input.currency;
170
+ if (input.extraLoad !== void 0) body["extra_load"] = input.extraLoad;
171
+ if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
172
+ if (input.useBonus !== void 0) body["use_bonus"] = input.useBonus;
173
+ if (input.consents !== void 0) body["consents"] = input.consents;
174
+ if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
175
+ if (input.metadata !== void 0) body["metadata"] = input.metadata;
359
176
  return body;
360
177
  }
361
178
  var CardsResource = class {
@@ -375,6 +192,22 @@ var CardsResource = class {
375
192
  idempotencyKey
376
193
  });
377
194
  }
195
+ /**
196
+ * Buy a card in one step: the API prices the product in the payment's
197
+ * currency, locks the rate and opens the top-up that issues the card.
198
+ * Send the user to `order.deposit.redirect_url`; the card shows as
199
+ * `pending_payment` until the payment is confirmed. The same
200
+ * `idempotencyKey` returns the same order.
201
+ * Errors: 400 `unknown_product` / `method_not_available` / a limit of the
202
+ * way of paying, 503 no funding connector or no exchange rate.
203
+ */
204
+ async order(input) {
205
+ const { idempotencyKey, ...order } = input;
206
+ return this.http.post("/me/card-orders", {
207
+ body: cardOrderBody(order),
208
+ idempotencyKey
209
+ });
210
+ }
378
211
  /**
379
212
  * The cards the caller can order, in the order the storefront shows them
380
213
  * (`is_default` marks the one issued when none is chosen). Each item
@@ -537,6 +370,232 @@ var CardsResource = class {
537
370
  }
538
371
  };
539
372
 
373
+ // src/resources/auth.ts
374
+ function withRemember(input) {
375
+ const { remember, ...rest } = input;
376
+ return remember ? { ...rest, remember_me: true } : rest;
377
+ }
378
+ var AuthResource = class {
379
+ constructor(http, tokens, remembered) {
380
+ this.http = http;
381
+ this.tokens = tokens;
382
+ this.remembered = remembered;
383
+ if (remembered) http.setRefresher(() => this.renew().then((r) => r.kind !== "gone"));
384
+ }
385
+ /** Store what a finished sign-in returned. */
386
+ async keep(resp) {
387
+ await Promise.resolve(this.tokens.set(resp.access_token));
388
+ if (resp.remember_token && this.remembered) {
389
+ await Promise.resolve(this.remembered.set(resp.remember_token));
390
+ }
391
+ }
392
+ /** Renew a remembered sign-in: a new session and a new remember token,
393
+ * both stored. Resolves `null` (and forgets the remember token) when there
394
+ * is none or it no longer works; the app then shows the sign-in form.
395
+ * The SDK does this by itself on a 401; call it on app start to resume a
396
+ * session without a request failing first. */
397
+ async refresh() {
398
+ const r = await this.renew();
399
+ if (r.kind === "renewed") return r.resp;
400
+ if (r.kind === "taken_over") {
401
+ const access = await Promise.resolve(this.tokens.get());
402
+ const user = await this.me();
403
+ return { stage: "jwt", access_token: access ?? "", expires_at: "", user };
404
+ }
405
+ return null;
406
+ }
407
+ /** The renewal itself, for the 401 path: it must not call the API again
408
+ * through the client, or a second 401 would wait on this very renewal. */
409
+ async renew() {
410
+ const token = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
411
+ if (!token) return { kind: "gone" };
412
+ try {
413
+ const resp = await this.http.post("/auth/refresh", {
414
+ body: { remember_token: token },
415
+ skipAuth: true
416
+ });
417
+ await this.keep(resp);
418
+ return { kind: "renewed", resp };
419
+ } catch (e) {
420
+ if (isApiError(e) && e.status === 401) {
421
+ const now = await Promise.resolve(this.remembered.get());
422
+ if (now && now !== token && await Promise.resolve(this.tokens.get())) {
423
+ return { kind: "taken_over" };
424
+ }
425
+ await Promise.resolve(this.remembered.clear());
426
+ await Promise.resolve(this.tokens.clear());
427
+ return { kind: "gone" };
428
+ }
429
+ throw e;
430
+ }
431
+ }
432
+ /** Password-auth entry. May resolve to a JWT, or to a step-up
433
+ * challenge that needs `verifyTotp` / `verifyOtp` next. */
434
+ async login(input) {
435
+ const resp = await this.http.post("/auth/login", {
436
+ body: withRemember(input),
437
+ skipAuth: true
438
+ });
439
+ if (resp.stage === "jwt") {
440
+ await this.keep(resp);
441
+ }
442
+ return resp;
443
+ }
444
+ /** Verify a TOTP code (or XXXX-XXXX backup code) against a
445
+ * `totp_required` challenge. On success the JWT is stored. */
446
+ async verifyTotp(input) {
447
+ const resp = await this.http.post("/auth/login/totp", {
448
+ body: withRemember(input),
449
+ skipAuth: true
450
+ });
451
+ await this.keep(resp);
452
+ return resp;
453
+ }
454
+ /** Verify a 6-digit OTP code (Telegram / email) against an
455
+ * `otp_sent` challenge. */
456
+ async verifyOtp(input) {
457
+ const resp = await this.http.post("/auth/login/otp/verify", {
458
+ body: withRemember(input),
459
+ skipAuth: true
460
+ });
461
+ await this.keep(resp);
462
+ return resp;
463
+ }
464
+ /** Create an end-user account and sign it in. The JWT is stored.
465
+ * `wallet_currency` must be one the deployment offers; omit it to take
466
+ * the deployment default (it can be switched later via `client.wallet`
467
+ * while the wallet is empty).
468
+ * Errors: 400 `validation` / `currency_not_allowed` / `consents_required`
469
+ * / `unknown_consent`, 409 email taken. */
470
+ async register(input) {
471
+ const { cardOrder, ...rest } = input;
472
+ const body = withRemember(rest);
473
+ if (cardOrder !== void 0) body["card_order"] = cardOrderBody(cardOrder);
474
+ const resp = await this.http.post("/auth/register", {
475
+ body,
476
+ skipAuth: true
477
+ });
478
+ await this.keep(resp);
479
+ return resp;
480
+ }
481
+ /** Finish a `totp_setup_required` login: send the first code from the
482
+ * authenticator app. The JWT is stored. The response carries ten
483
+ * one-time `backup_codes` that are never returned again, so show them to
484
+ * the user right away and don't keep them on the device. */
485
+ async completeTotpSetup(input) {
486
+ const resp = await this.http.post("/auth/login/totp-setup", {
487
+ body: withRemember(input),
488
+ skipAuth: true
489
+ });
490
+ await this.keep(resp);
491
+ return resp;
492
+ }
493
+ /** Change the signed-in user's password. Every other session of the
494
+ * account is signed out; this one stays valid.
495
+ * Errors: 400 when the new password fails the policy, 401 when the
496
+ * current one is wrong. */
497
+ async changePassword(input) {
498
+ return this.http.post("/auth/password", {
499
+ body: input
500
+ });
501
+ }
502
+ /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
503
+ * telegram/email; for TOTP it short-circuits back to the challenge. */
504
+ async switchMethod(input) {
505
+ return this.http.post("/auth/login/2fa/switch", {
506
+ body: input,
507
+ skipAuth: true
508
+ });
509
+ }
510
+ async exchangeTelegram(input) {
511
+ const body = {
512
+ init_data: input.initData
513
+ };
514
+ if (input.provision !== void 0) body.provision = input.provision;
515
+ if (input.attribution !== void 0) body.attribution = input.attribution;
516
+ if (input.code !== void 0) body.code = input.code;
517
+ if (input.consents !== void 0) body.consents = input.consents;
518
+ if (input.consentChannel !== void 0) body.consent_channel = input.consentChannel;
519
+ let resp;
520
+ try {
521
+ resp = await this.http.post("/auth/telegram/exchange", {
522
+ body,
523
+ skipAuth: true
524
+ });
525
+ } catch (e) {
526
+ if (isApiError(e) && e.status === 404 && e.code === "telegram_unknown") {
527
+ return { stage: "unknown" };
528
+ }
529
+ throw e;
530
+ }
531
+ await Promise.resolve(this.tokens.set(resp.access_token));
532
+ return resp;
533
+ }
534
+ /** Attach the Telegram account behind `initData` to an existing email +
535
+ * password account and sign in as that account. No bearer needed; the
536
+ * password is checked the same way `login` checks it. The JWT is stored.
537
+ *
538
+ * Errors: 401 `unauthenticated` (wrong email or password, as with
539
+ * `login`) / `invalid_init_data`; 403
540
+ * `user_disabled` / `second_factor_required` (accounts that sign in with
541
+ * a second factor can't be linked from a Mini App); 409
542
+ * `telegram_already_linked_other` (this account already has a different
543
+ * Telegram; unlink it first) / `telegram_in_use` (this Telegram belongs to
544
+ * another account); 503 `telegram_not_configured`. */
545
+ async linkTelegram(input) {
546
+ const resp = await this.http.post("/auth/telegram/link", {
547
+ body: { init_data: input.initData, email: input.email, password: input.password },
548
+ skipAuth: true
549
+ });
550
+ await Promise.resolve(this.tokens.set(resp.access_token));
551
+ return resp;
552
+ }
553
+ /** Attach the first real email to a Telegram-made account (and clear
554
+ * `email_pending`). 409 if taken. An account that already has a real
555
+ * address gets 409 `email_change_needs_code`: change it with
556
+ * {@link requestEmailChange} and {@link confirmEmailChange}. */
557
+ async linkEmail(input) {
558
+ return this.http.post("/me/email", { body: { email: input.email } });
559
+ }
560
+ /** Step one of an email change: a six-digit code goes to the new address
561
+ * and works for 5 minutes. Nothing changes yet.
562
+ * Errors: 400 `same_email`, 409 address taken, 429 `too_many_requests`
563
+ * (five codes an hour). */
564
+ async requestEmailChange(input) {
565
+ return this.http.post("/me/email/change", {
566
+ body: { email: input.email }
567
+ });
568
+ }
569
+ /** Step two: the code from the e-mail changes the address; the old one
570
+ * gets a notice. Errors: 401 `invalid_code` (after five wrong codes a new
571
+ * request is needed), 409 the address was taken meanwhile. */
572
+ async confirmEmailChange(input) {
573
+ return this.http.post("/me/email/change/confirm", {
574
+ body: { challenge_id: input.challengeId, code: input.code }
575
+ });
576
+ }
577
+ /** Current user — fails 401 when the stored JWT is expired or
578
+ * missing. Useful as a "do I have a session" probe on app boot. */
579
+ async me() {
580
+ return this.http.get("/auth/me");
581
+ }
582
+ /** Sign out: ends this session and the remembered sign-in on the
583
+ * server (best effort: a network failure still signs out locally), then
584
+ * forgets both tokens. */
585
+ async signOut() {
586
+ const remember = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
587
+ try {
588
+ await this.http.post("/auth/logout", {
589
+ body: remember ? { remember_token: remember } : {},
590
+ retried: true
591
+ });
592
+ } catch {
593
+ }
594
+ await Promise.resolve(this.tokens.clear());
595
+ if (this.remembered) await Promise.resolve(this.remembered.clear());
596
+ }
597
+ };
598
+
540
599
  // src/resources/deposits.ts
541
600
  var DepositsResource = class {
542
601
  constructor(http) {
@@ -1160,6 +1219,69 @@ var HistoryResource = class {
1160
1219
  }
1161
1220
  };
1162
1221
 
1222
+ // src/resources/consents.ts
1223
+ var ConsentsResource = class {
1224
+ constructor(http) {
1225
+ this.http = http;
1226
+ }
1227
+ /** Where each consent stands. */
1228
+ async get() {
1229
+ return this.http.get("/me/consents");
1230
+ }
1231
+ /**
1232
+ * Give (`true`) or withdraw (`false`) an optional consent: `marketing` or
1233
+ * `cookies_analytics`. Withdrawing `marketing` turns advertising off in
1234
+ * every channel at once; giving it turns on advertising by e-mail. A call
1235
+ * that changes nothing records nothing.
1236
+ *
1237
+ * Errors: 400 `consent_required` for `terms` or `personal_data`,
1238
+ * 400 `unknown_consent`.
1239
+ */
1240
+ async set(kind, given, channel) {
1241
+ const body = { kind, given };
1242
+ if (channel !== void 0) body.channel = channel;
1243
+ return this.http.post("/me/consents", { body });
1244
+ }
1245
+ /**
1246
+ * Record what the cookie banner or the cookie settings say about
1247
+ * analytics. Works signed in or not: before sign-in the choice is kept
1248
+ * under the anonymous key and moves to the account at sign-up (send the
1249
+ * same key in `register({ attribution })`). Declining deletes the
1250
+ * visitor's recorded visits and analytics ids and stops their conversions
1251
+ * going to Metrica. Call it on every change, not on every page load; the
1252
+ * same answer twice records nothing (`recorded: false`).
1253
+ *
1254
+ * Errors: 400 `invalid_anonymous_key` when not signed in and no key could
1255
+ * be found.
1256
+ */
1257
+ async setCookies(input) {
1258
+ const body = {
1259
+ analytics: input.analytics
1260
+ };
1261
+ const key = input.anonymousKey ?? anonymousKey();
1262
+ if (key !== void 0) body.anonymous_key = key;
1263
+ if (input.channel !== void 0) body.channel = input.channel;
1264
+ return this.http.post("/consents/cookies", { body });
1265
+ }
1266
+ };
1267
+
1268
+ // src/resources/receipts.ts
1269
+ var ReceiptsResource = class {
1270
+ constructor(http) {
1271
+ this.http = http;
1272
+ }
1273
+ async list(params = {}) {
1274
+ const q = new URLSearchParams();
1275
+ if (params.refId !== void 0) q.set("ref_id", params.refId);
1276
+ if (params.limit !== void 0) q.set("limit", String(params.limit));
1277
+ const qs = q.toString();
1278
+ return this.http.get(`/me/receipts${qs ? `?${qs}` : ""}`);
1279
+ }
1280
+ async get(id) {
1281
+ return this.http.get(`/me/receipts/${encodeURIComponent(id)}`);
1282
+ }
1283
+ };
1284
+
1163
1285
  // src/resources/funding-options.ts
1164
1286
  var FundingOptionsResource = class {
1165
1287
  constructor(http) {
@@ -1172,7 +1294,7 @@ var FundingOptionsResource = class {
1172
1294
  };
1173
1295
 
1174
1296
  // src/version.ts
1175
- var SDK_VERSION = "0.6.1";
1297
+ var SDK_VERSION = "0.6.3";
1176
1298
 
1177
1299
  // src/client-platform.ts
1178
1300
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1247,7 +1369,7 @@ function isAbsolute(url) {
1247
1369
  }
1248
1370
 
1249
1371
  // src/compat.ts
1250
- var SUPPORTED_MEISTER = ">=0.6.4, <0.7.0";
1372
+ var SUPPORTED_MEISTER = ">=0.6.8, <0.7.0";
1251
1373
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1252
1374
  function parse(v) {
1253
1375
  const m = SEMVER.exec(v.trim());
@@ -1774,7 +1896,9 @@ function createClient(opts) {
1774
1896
  notifications: new NotificationsResource(http),
1775
1897
  devices: new DevicesResource(http, client),
1776
1898
  attribution: new AttributionResource(http),
1777
- history: new HistoryResource(http)
1899
+ history: new HistoryResource(http),
1900
+ consents: new ConsentsResource(http),
1901
+ receipts: new ReceiptsResource(http)
1778
1902
  };
1779
1903
  }
1780
1904
  function pickDefaultStore(key) {