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