@takeal/cusfront-sdk 0.8.1 → 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 +68 -1
  2. package/README.md +49 -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 +59 -4
  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 +59 -4
  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 +58 -3
  14. package/dist/resources/auth.cjs.map +1 -1
  15. package/dist/resources/auth.d.cts +102 -7
  16. package/dist/resources/auth.d.ts +102 -7
  17. package/dist/resources/auth.js +58 -3
  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 +59 -4
  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 +59 -4
  38. package/dist/telegram.js.map +1 -1
  39. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { CusfrontClient, CreateClientOptions } from './index.cjs';
2
2
  import { JwtIssued, TelegramUnknown } from './resources/auth.cjs';
3
3
  import './http-CL97TjMO.cjs';
4
- import './cards-BPu8Ill7.cjs';
4
+ import './cards-DwxkVJUB.cjs';
5
5
  import './resources/claims.cjs';
6
6
  import './resources/codes.cjs';
7
7
  import './resources/consents.cjs';
@@ -1,7 +1,7 @@
1
1
  import { CusfrontClient, CreateClientOptions } from './index.js';
2
2
  import { JwtIssued, TelegramUnknown } from './resources/auth.js';
3
3
  import './http-CL97TjMO.js';
4
- import './cards-DP1fJc_c.js';
4
+ import './cards-VkS_2lPe.js';
5
5
  import './resources/claims.js';
6
6
  import './resources/codes.js';
7
7
  import './resources/consents.js';
package/dist/telegram.js CHANGED
@@ -682,12 +682,17 @@ var AuthResource = class {
682
682
  return resp;
683
683
  }
684
684
  /** Verify a TOTP code (or XXXX-XXXX backup code) against a
685
- * `totp_required` challenge. On success the JWT is stored. */
685
+ * `totp_required` challenge. On success the JWT is stored. A backup code
686
+ * signs nobody in: it is used up and the answer is
687
+ * `totp_setup_email_required`, the start of connecting a new
688
+ * authenticator ({@link confirmTotpSetupEmail}). Nothing is stored then.
689
+ * Errors after a backup code: see {@link TotpSetupEmailErrorCode}. */
686
690
  async verifyTotp(input) {
687
691
  const resp = await this.http.post("/auth/login/totp", {
688
692
  body: withRemember(input),
689
693
  skipAuth: true
690
694
  });
695
+ if (resp.stage === "totp_setup_email_required") return resp;
691
696
  await this.keep(resp);
692
697
  return resp;
693
698
  }
@@ -760,6 +765,28 @@ var AuthResource = class {
760
765
  await this.keep(resp);
761
766
  return resp;
762
767
  }
768
+ /** Send the code from the e-mail of a `totp_setup_email_required`
769
+ * answer. A right code answers `totp_setup_required`: show its
770
+ * `otpauth_url` as a QR, then finish with {@link completeTotpSetup}.
771
+ * Each code works for 5 minutes and takes five tries; only the newest
772
+ * one works. Nothing is stored. Errors: {@link TotpSetupEmailErrorCode}. */
773
+ async confirmTotpSetupEmail(input) {
774
+ return this.http.post("/auth/login/totp-setup/email", {
775
+ body: { challenge_token: input.challenge_token, code: input.code },
776
+ skipAuth: true
777
+ });
778
+ }
779
+ /** A new e-mail code for the same `totp_setup_email_required` sign-in;
780
+ * the one before it stops working. Use the `challenge_token` of the
781
+ * answer from now on. Five codes an hour at most.
782
+ * Errors: {@link TotpSetupEmailErrorCode}; 401 means the sign-in is over,
783
+ * so start again with {@link login}. */
784
+ async resendTotpSetupEmail(input) {
785
+ return this.http.post("/auth/login/totp-setup/email/resend", {
786
+ body: { challenge_token: input.challenge_token },
787
+ skipAuth: true
788
+ });
789
+ }
763
790
  /** Finish a `totp_setup_required` login: send the first code from the
764
791
  * authenticator app. The JWT is stored. The response carries ten
765
792
  * one-time `backup_codes` that are never returned again, so show them to
@@ -774,13 +801,41 @@ var AuthResource = class {
774
801
  }
775
802
  /** Change the signed-in user's password. Every other session of the
776
803
  * account is signed out; this one stays valid.
777
- * Errors: 400 when the new password fails the policy, 401 when the
778
- * current one is wrong. */
804
+ * Errors: 400 `weak_password` when the new password fails the policy,
805
+ * 400 `no_password` when the account has none yet (use
806
+ * {@link requestPasswordSetup}), 401 when the current one is wrong. */
779
807
  async changePassword(input) {
780
808
  return this.http.post("/auth/password", {
781
809
  body: input
782
810
  });
783
811
  }
812
+ /** Step one of setting the first password of an account that has none
813
+ * (`user.has_password === false`, e.g. made by signing in with an e-mail
814
+ * code): a six-digit code goes to the account's address and works for 5
815
+ * minutes. Nothing changes yet.
816
+ * Errors: 409 `password_exists` (use {@link changePassword}),
817
+ * `email_required` (a Telegram account with no address yet: attach one
818
+ * with {@link requestEmailChange} first), `email_not_proven` (sign in
819
+ * with an e-mail code first); 429 `too_many_requests` (five codes an
820
+ * hour); 503 `delivery_failed`. Platform 0.8.2 and newer. */
821
+ async requestPasswordSetup() {
822
+ return this.http.post("/auth/password/setup", {});
823
+ }
824
+ /** Step two: the code from the e-mail and the new password set the
825
+ * account's first password. Every other session of the account is signed
826
+ * out; this one stays valid, and signing in with a code keeps working.
827
+ * Errors: 400 `weak_password` (the code is not used up, fix the password
828
+ * and send again), 401 `invalid_code` (after five wrong codes ask for a
829
+ * new one), 409 `password_exists`. */
830
+ async confirmPasswordSetup(input) {
831
+ return this.http.post("/auth/password/setup/confirm", {
832
+ body: {
833
+ challenge_id: input.challengeId,
834
+ code: input.code,
835
+ new_password: input.newPassword
836
+ }
837
+ });
838
+ }
784
839
  /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
785
840
  * telegram/email; for TOTP it short-circuits back to the challenge. */
786
841
  async switchMethod(input) {
@@ -1716,7 +1771,7 @@ var FundingOptionsResource = class {
1716
1771
  };
1717
1772
 
1718
1773
  // src/version.ts
1719
- var SDK_VERSION = "0.8.1";
1774
+ var SDK_VERSION = "0.8.4";
1720
1775
 
1721
1776
  // src/client-platform.ts
1722
1777
  var CLIENT_HEADER = "X-Takeal-Client";