@takeal/cusfront-sdk 0.8.3 → 0.8.4

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 (39) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +24 -7
  3. package/dist/{cards-BPu8Ill7.d.cts → cards-DwxkVJUB.d.cts} +36 -3
  4. package/dist/{cards-DP1fJc_c.d.ts → cards-VkS_2lPe.d.ts} +36 -3
  5. package/dist/index.cjs +29 -2
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +4 -4
  8. package/dist/index.d.ts +4 -4
  9. package/dist/index.js +29 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/react/index.d.cts +1 -1
  12. package/dist/react/index.d.ts +1 -1
  13. package/dist/resources/auth.cjs +28 -1
  14. package/dist/resources/auth.cjs.map +1 -1
  15. package/dist/resources/auth.d.cts +57 -5
  16. package/dist/resources/auth.d.ts +57 -5
  17. package/dist/resources/auth.js +28 -1
  18. package/dist/resources/auth.js.map +1 -1
  19. package/dist/resources/cards.d.cts +1 -1
  20. package/dist/resources/cards.d.ts +1 -1
  21. package/dist/resources/deposits.cjs.map +1 -1
  22. package/dist/resources/deposits.d.cts +1 -1
  23. package/dist/resources/deposits.d.ts +1 -1
  24. package/dist/resources/deposits.js.map +1 -1
  25. package/dist/resources/funding-options.d.cts +1 -1
  26. package/dist/resources/funding-options.d.ts +1 -1
  27. package/dist/resources/me.d.cts +1 -1
  28. package/dist/resources/me.d.ts +1 -1
  29. package/dist/resources/subscription.cjs.map +1 -1
  30. package/dist/resources/subscription.d.cts +4 -0
  31. package/dist/resources/subscription.d.ts +4 -0
  32. package/dist/resources/subscription.js.map +1 -1
  33. package/dist/telegram.cjs +29 -2
  34. package/dist/telegram.cjs.map +1 -1
  35. package/dist/telegram.d.cts +1 -1
  36. package/dist/telegram.d.ts +1 -1
  37. package/dist/telegram.js +29 -2
  38. package/dist/telegram.js.map +1 -1
  39. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,7 +4,37 @@ All notable changes to `@takeal/cusfront-sdk` are documented here. The format
4
4
  follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [0.8.4] — 2026-11-25
8
+
9
+ ### Added
10
+
11
+ - `UserSubscription.tier_icon_url`: the picture the operator gave the plan,
12
+ WebP or SVG, or `null` when it has none. Needs platform 0.8.4; older
13
+ platforms leave it out.
14
+ - `deposits.quote()` takes `promo_code`. Where a method's fee is in the rate
15
+ (SBP, for one), the user's plan and a promo code with a percentage off the
16
+ top-up fee lower that fee, and the quote is priced with it. The quote says
17
+ so: `fee_bps` is the user's fee, `list_fee_bps` the method's before the
18
+ discounts, `fee_discount` what they add to `credited_amount`, and
19
+ `promo_code` the code the rate was priced with. The top-up made from the
20
+ quote uses that code by itself. Needs platform 0.8.4.
21
+ - `FundingQuote.effective_rate`: the rate the user gets, fee and discounts
22
+ included. Show it instead of working a rate out from the method's terms.
23
+ - `auth.confirmTotpSetupEmail({ challenge_token, code })` and
24
+ `auth.resendTotpSetupEmail({ challenge_token })`, and the login stage
25
+ `totp_setup_email_required`. From platform 0.8.4 a staff account can't
26
+ connect an authenticator with its password alone: the first sign-in, and
27
+ the one after a backup code, first sends a six-digit code to the account's
28
+ e-mail. The right code answers `totp_setup_required` with the QR, as
29
+ before. `TotpSetupEmailErrorCode` lists the errors of this step.
30
+
31
+ ### Changed
32
+
33
+ - `auth.verifyTotp` resolves to `JwtIssued | TotpSetupEmailRequired`. A
34
+ backup code never signed in: since platform 0.8.2 the server answers it
35
+ with the start of connecting a new authenticator, and the SDK stored that
36
+ answer as if it were a session. Now it stores nothing and hands the answer
37
+ back; check `stage` before using `access_token`.
8
38
 
9
39
  ## [0.8.3] — 2026-11-24
10
40
 
package/README.md CHANGED
@@ -42,10 +42,16 @@ if (result.stage === "jwt") {
42
42
  } else if (result.stage === "totp_required") {
43
43
  // Step-up required. Prompt the user for their TOTP code,
44
44
  // then call client.auth.verifyTotp({ challenge_token, code }).
45
+ } else if (result.stage === "totp_setup_email_required") {
46
+ // A staff account has to connect an authenticator first, and the password
47
+ // alone is not enough: a code went to result.destination_hint. Ask for it
48
+ // and call client.auth.confirmTotpSetupEmail({ challenge_token, code });
49
+ // client.auth.resendTotpSetupEmail({ challenge_token }) sends a new one.
50
+ // The answer is the totp_setup_required stage below.
45
51
  } else if (result.stage === "totp_setup_required") {
46
- // The account has to enrol an authenticator first. Show result.otpauth_url
47
- // as a QR code, then call client.auth.completeTotpSetup({ challenge_token, code })
48
- // and show the backup_codes it returns. They are never sent again.
52
+ // Show result.otpauth_url as a QR code, then call
53
+ // client.auth.completeTotpSetup({ challenge_token, code }) and show the
54
+ // backup_codes it returns. They are never sent again.
49
55
  }
50
56
  ```
51
57
 
@@ -401,25 +407,33 @@ const sbp = funder.method_terms.find((m) => m.method === "sbp")!;
401
407
  // sbp.source_currency → "RUB"; sbp.fee_kind → "markup"; sbp.fee_bps → 2000;
402
408
  // sbp.quote_ttl_seconds → 300; sbp.min_amount, sbp.max_amount, sbp.daily_limit_per_user
403
409
 
404
- // 2. The user types roubles. The quote locks the rate for quote_ttl_seconds.
410
+ // 2. The user types roubles (and a promo code, if they have one). The quote
411
+ // locks the rate for quote_ttl_seconds.
405
412
  const quote = await client.deposits.quote({
406
413
  amount: "1000",
407
414
  currency: "RUB",
408
415
  connectorSlug: funder.slug,
409
416
  method: "sbp",
417
+ promo_code: promoCode, // optional
410
418
  });
411
419
  // quote.credited_amount → "10.41" USD at a bank rate of 80 ₽ and a 20 % markup.
420
+ // The user's plan and a promo code with a percentage off the top-up fee lower
421
+ // the markup: with 5 % off it is 19 %, quote.fee_bps → 1900,
422
+ // quote.list_fee_bps → 2000, quote.credited_amount → "10.50", and
423
+ // quote.promo_code names the code the rate was priced with. Don't take the fee
424
+ // from `sbp.fee_bps`: the quote has the user's own.
412
425
 
413
426
  // 3. What to show. With `fee_kind === "markup"` the fee sits in the rate: show
414
427
  // the rate and the amount credited, no fee line. The rate in the form
415
428
  // people know, roubles per unit of the wallet currency:
416
- const perUnit = Number(quote.source_amount) / Number(quote.credited_amount); // 96.06 ₽ per $
429
+ const perUnit = 1 / Number(quote.effective_rate); // 96.00 ₽ per $
417
430
  show(`${quote.credited_amount} ${quote.credited_currency} at ${perUnit.toFixed(2)} ₽/$, until ${quote.expires_at}`);
418
431
  // If the user types the wallet amount instead, work the roubles out on the
419
432
  // client from the same rate and quote that: roubles = wanted × perUnit,
420
433
  // rounded up to the kopeck, then `quote()` again with that amount.
421
- // With `fee_kind === "commission"` show the fee as its own line:
422
- // commission = credited × fee_bps / 10000.
434
+ // With `fee_kind === "commission"` the rate is the bank's and the fee is a
435
+ // line of its own, taken off what is credited when the top-up settles; a
436
+ // plan's or a promo code's discount comes off that line.
423
437
 
424
438
  // 4. Pay. The deposit is a redirect: send the user to the bank's page.
425
439
  const deposit = await client.deposits.initiate({
@@ -851,6 +865,9 @@ const ref = await client.referral.get();
851
865
  with a sign-up link without the user typing it again.
852
866
  - `client.subscription.get()` shows a gift subscription as `kind: "gift"`;
853
867
  `gift_until: null` means it doesn't end.
868
+ - `tier_icon_url` is the plan's own picture (WebP or SVG) that the operator
869
+ uploaded. When it is `null`, show your own generic one. Draw it with
870
+ `<img>`, not inline, so an SVG stays a picture.
854
871
  - Rewards and code bonuses are bonuses: a discount on our services, not
855
872
  money. Show friends without names; the API sends none.
856
873
 
@@ -159,6 +159,16 @@ interface CreateQuoteInput {
159
159
  connectorSlug?: string;
160
160
  /** The way the user pays. Pass the same method to `initiate()`. */
161
161
  method?: DepositMethod;
162
+ /**
163
+ * A promo code for the top-up. Where the method's fee is in the rate
164
+ * (`fee_kind: "markup"`), the code's percentage discount lowers that fee,
165
+ * so the rate is priced with it and `promo_code` comes back on the quote.
166
+ * The top-up made from the quote uses the same code: pass it again to
167
+ * `initiate()` or leave it out. Without one, the code the user signed up
168
+ * with is used when it works here. A code that can't be used fails with
169
+ * 400 `promo_code_*` and the reason. Needs platform 0.8.4.
170
+ */
171
+ promo_code?: string;
162
172
  }
163
173
  /**
164
174
  * How a method's fee reads. `spread`: taken off the credited amount at the
@@ -197,11 +207,18 @@ interface FundingQuote {
197
207
  credited_amount: string;
198
208
  credited_currency: string;
199
209
  /**
200
- * Provider rate before the fee, credited units per 1 source unit. The
201
- * rate to show the user is `credited_amount / source_amount`, which has
202
- * the fee in it; see the README for the rouble-per-dollar form.
210
+ * Provider rate before the fee, credited units per 1 source unit. Don't
211
+ * show it: the user's rate is `effective_rate`.
203
212
  */
204
213
  rate: string;
214
+ /**
215
+ * The rate the user gets, credited units per 1 source unit, with the fee
216
+ * and any discount of the user's plan or promo code in it. Show this one
217
+ * (or its inverse, see the README) rather than working a rate out from
218
+ * the method's `fee_bps`. Older platforms leave it out; there it is
219
+ * `credited_amount / source_amount`.
220
+ */
221
+ effective_rate?: string;
205
222
  /** The fee in basis points; the same figure as `fee_bps`, under its old name. */
206
223
  spread_bps: number;
207
224
  /** The fee in basis points (2000 = 20 %). */
@@ -213,6 +230,16 @@ interface FundingQuote {
213
230
  method?: DepositMethod;
214
231
  /** The rate is locked until then; the deposit made with it waits for its payment as long. */
215
232
  expires_at: string;
233
+ /**
234
+ * Set when the user's plan or a promo code lowered the fee in the rate:
235
+ * the method's fee before that, in basis points. `fee_bps` is what the
236
+ * user pays.
237
+ */
238
+ list_fee_bps?: number;
239
+ /** What the lower fee adds to `credited_amount`, decimal string in `credited_currency`. */
240
+ fee_discount?: string;
241
+ /** The promo code the rate was priced with; the top-up made from this quote uses it. */
242
+ promo_code?: string;
216
243
  /**
217
244
  * What the user owes in card fees, in `credited_currency`, that this
218
245
  * top-up pays first: it comes off `credited_amount` and the rest is
@@ -369,6 +396,12 @@ interface InitiateDepositInput {
369
396
  * arrive once the top-up is confirmed. A code that can't be used fails the
370
397
  * request with 400 `promo_code_*` and the reason. `client.codes.validate`
371
398
  * checks it first.
399
+ *
400
+ * Where the method's fee is in the rate, the discount lowers the rate, and
401
+ * only the quote prices the rate: send the code to `quote()`. A top-up
402
+ * from that quote uses the quote's `promo_code` without being told; another
403
+ * code here is refused (400 `validation`), and a code the quote was made
404
+ * without is refused with 400 `promo_code_not_applicable`.
372
405
  */
373
406
  promo_code?: string;
374
407
  /** The visitor's analytics ids for the payment's server-side conversions.
@@ -159,6 +159,16 @@ interface CreateQuoteInput {
159
159
  connectorSlug?: string;
160
160
  /** The way the user pays. Pass the same method to `initiate()`. */
161
161
  method?: DepositMethod;
162
+ /**
163
+ * A promo code for the top-up. Where the method's fee is in the rate
164
+ * (`fee_kind: "markup"`), the code's percentage discount lowers that fee,
165
+ * so the rate is priced with it and `promo_code` comes back on the quote.
166
+ * The top-up made from the quote uses the same code: pass it again to
167
+ * `initiate()` or leave it out. Without one, the code the user signed up
168
+ * with is used when it works here. A code that can't be used fails with
169
+ * 400 `promo_code_*` and the reason. Needs platform 0.8.4.
170
+ */
171
+ promo_code?: string;
162
172
  }
163
173
  /**
164
174
  * How a method's fee reads. `spread`: taken off the credited amount at the
@@ -197,11 +207,18 @@ interface FundingQuote {
197
207
  credited_amount: string;
198
208
  credited_currency: string;
199
209
  /**
200
- * Provider rate before the fee, credited units per 1 source unit. The
201
- * rate to show the user is `credited_amount / source_amount`, which has
202
- * the fee in it; see the README for the rouble-per-dollar form.
210
+ * Provider rate before the fee, credited units per 1 source unit. Don't
211
+ * show it: the user's rate is `effective_rate`.
203
212
  */
204
213
  rate: string;
214
+ /**
215
+ * The rate the user gets, credited units per 1 source unit, with the fee
216
+ * and any discount of the user's plan or promo code in it. Show this one
217
+ * (or its inverse, see the README) rather than working a rate out from
218
+ * the method's `fee_bps`. Older platforms leave it out; there it is
219
+ * `credited_amount / source_amount`.
220
+ */
221
+ effective_rate?: string;
205
222
  /** The fee in basis points; the same figure as `fee_bps`, under its old name. */
206
223
  spread_bps: number;
207
224
  /** The fee in basis points (2000 = 20 %). */
@@ -213,6 +230,16 @@ interface FundingQuote {
213
230
  method?: DepositMethod;
214
231
  /** The rate is locked until then; the deposit made with it waits for its payment as long. */
215
232
  expires_at: string;
233
+ /**
234
+ * Set when the user's plan or a promo code lowered the fee in the rate:
235
+ * the method's fee before that, in basis points. `fee_bps` is what the
236
+ * user pays.
237
+ */
238
+ list_fee_bps?: number;
239
+ /** What the lower fee adds to `credited_amount`, decimal string in `credited_currency`. */
240
+ fee_discount?: string;
241
+ /** The promo code the rate was priced with; the top-up made from this quote uses it. */
242
+ promo_code?: string;
216
243
  /**
217
244
  * What the user owes in card fees, in `credited_currency`, that this
218
245
  * top-up pays first: it comes off `credited_amount` and the rest is
@@ -369,6 +396,12 @@ interface InitiateDepositInput {
369
396
  * arrive once the top-up is confirmed. A code that can't be used fails the
370
397
  * request with 400 `promo_code_*` and the reason. `client.codes.validate`
371
398
  * checks it first.
399
+ *
400
+ * Where the method's fee is in the rate, the discount lowers the rate, and
401
+ * only the quote prices the rate: send the code to `quote()`. A top-up
402
+ * from that quote uses the quote's `promo_code` without being told; another
403
+ * code here is refused (400 `validation`), and a code the quote was made
404
+ * without is refused with 400 `promo_code_not_applicable`.
372
405
  */
373
406
  promo_code?: string;
374
407
  /** The visitor's analytics ids for the payment's server-side conversions.
package/dist/index.cjs CHANGED
@@ -716,12 +716,17 @@ var AuthResource = class {
716
716
  return resp;
717
717
  }
718
718
  /** Verify a TOTP code (or XXXX-XXXX backup code) against a
719
- * `totp_required` challenge. On success the JWT is stored. */
719
+ * `totp_required` challenge. On success the JWT is stored. A backup code
720
+ * signs nobody in: it is used up and the answer is
721
+ * `totp_setup_email_required`, the start of connecting a new
722
+ * authenticator ({@link confirmTotpSetupEmail}). Nothing is stored then.
723
+ * Errors after a backup code: see {@link TotpSetupEmailErrorCode}. */
720
724
  async verifyTotp(input) {
721
725
  const resp = await this.http.post("/auth/login/totp", {
722
726
  body: withRemember(input),
723
727
  skipAuth: true
724
728
  });
729
+ if (resp.stage === "totp_setup_email_required") return resp;
725
730
  await this.keep(resp);
726
731
  return resp;
727
732
  }
@@ -794,6 +799,28 @@ var AuthResource = class {
794
799
  await this.keep(resp);
795
800
  return resp;
796
801
  }
802
+ /** Send the code from the e-mail of a `totp_setup_email_required`
803
+ * answer. A right code answers `totp_setup_required`: show its
804
+ * `otpauth_url` as a QR, then finish with {@link completeTotpSetup}.
805
+ * Each code works for 5 minutes and takes five tries; only the newest
806
+ * one works. Nothing is stored. Errors: {@link TotpSetupEmailErrorCode}. */
807
+ async confirmTotpSetupEmail(input) {
808
+ return this.http.post("/auth/login/totp-setup/email", {
809
+ body: { challenge_token: input.challenge_token, code: input.code },
810
+ skipAuth: true
811
+ });
812
+ }
813
+ /** A new e-mail code for the same `totp_setup_email_required` sign-in;
814
+ * the one before it stops working. Use the `challenge_token` of the
815
+ * answer from now on. Five codes an hour at most.
816
+ * Errors: {@link TotpSetupEmailErrorCode}; 401 means the sign-in is over,
817
+ * so start again with {@link login}. */
818
+ async resendTotpSetupEmail(input) {
819
+ return this.http.post("/auth/login/totp-setup/email/resend", {
820
+ body: { challenge_token: input.challenge_token },
821
+ skipAuth: true
822
+ });
823
+ }
797
824
  /** Finish a `totp_setup_required` login: send the first code from the
798
825
  * authenticator app. The JWT is stored. The response carries ten
799
826
  * one-time `backup_codes` that are never returned again, so show them to
@@ -1781,7 +1808,7 @@ var FundingOptionsResource = class {
1781
1808
  };
1782
1809
 
1783
1810
  // src/version.ts
1784
- var SDK_VERSION = "0.8.3";
1811
+ var SDK_VERSION = "0.8.4";
1785
1812
 
1786
1813
  // src/client-platform.ts
1787
1814
  var CLIENT_HEADER = "X-Takeal-Client";