@takeal/cusfront-sdk 0.8.3 → 0.9.0

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 (51) hide show
  1. package/CHANGELOG.md +88 -1
  2. package/README.md +70 -12
  3. package/dist/analytics.cjs +74 -22
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.d.cts +43 -4
  6. package/dist/analytics.d.ts +43 -4
  7. package/dist/analytics.js +71 -23
  8. package/dist/analytics.js.map +1 -1
  9. package/dist/{cards-BPu8Ill7.d.cts → cards-C5rk0XkI.d.cts} +83 -8
  10. package/dist/{cards-DP1fJc_c.d.ts → cards-CS-oxqLS.d.ts} +83 -8
  11. package/dist/index.cjs +122 -27
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +14 -6
  14. package/dist/index.d.ts +14 -6
  15. package/dist/index.js +119 -28
  16. package/dist/index.js.map +1 -1
  17. package/dist/react/index.d.cts +1 -1
  18. package/dist/react/index.d.ts +1 -1
  19. package/dist/resources/auth.cjs +28 -1
  20. package/dist/resources/auth.cjs.map +1 -1
  21. package/dist/resources/auth.d.cts +57 -5
  22. package/dist/resources/auth.d.ts +57 -5
  23. package/dist/resources/auth.js +28 -1
  24. package/dist/resources/auth.js.map +1 -1
  25. package/dist/resources/branding.cjs.map +1 -1
  26. package/dist/resources/branding.d.cts +6 -0
  27. package/dist/resources/branding.d.ts +6 -0
  28. package/dist/resources/branding.js.map +1 -1
  29. package/dist/resources/cards.cjs.map +1 -1
  30. package/dist/resources/cards.d.cts +1 -1
  31. package/dist/resources/cards.d.ts +1 -1
  32. package/dist/resources/cards.js.map +1 -1
  33. package/dist/resources/deposits.cjs.map +1 -1
  34. package/dist/resources/deposits.d.cts +1 -1
  35. package/dist/resources/deposits.d.ts +1 -1
  36. package/dist/resources/deposits.js.map +1 -1
  37. package/dist/resources/funding-options.d.cts +1 -1
  38. package/dist/resources/funding-options.d.ts +1 -1
  39. package/dist/resources/me.d.cts +1 -1
  40. package/dist/resources/me.d.ts +1 -1
  41. package/dist/resources/subscription.cjs.map +1 -1
  42. package/dist/resources/subscription.d.cts +4 -0
  43. package/dist/resources/subscription.d.ts +4 -0
  44. package/dist/resources/subscription.js.map +1 -1
  45. package/dist/telegram.cjs +48 -5
  46. package/dist/telegram.cjs.map +1 -1
  47. package/dist/telegram.d.cts +1 -1
  48. package/dist/telegram.d.ts +1 -1
  49. package/dist/telegram.js +48 -5
  50. package/dist/telegram.js.map +1 -1
  51. package/package.json +1 -1
package/dist/telegram.cjs CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  // src/error.ts
4
4
  var ApiError = class extends Error {
5
- constructor(status, code, message, body) {
5
+ constructor(status, code, message, body, retryAfterSeconds) {
6
6
  super(message);
7
7
  this.status = status;
8
8
  this.code = code;
9
9
  this.body = body;
10
+ this.retryAfterSeconds = retryAfterSeconds;
10
11
  this.isApiError = true;
11
12
  this.name = "ApiError";
12
13
  }
@@ -138,11 +139,20 @@ async function parseResponse(resp) {
138
139
  resp.status,
139
140
  errBody.code ?? `http_${resp.status}`,
140
141
  errBody.message ?? resp.statusText ?? "request failed",
141
- body
142
+ body,
143
+ retryAfter(resp.headers?.get("Retry-After"))
142
144
  );
143
145
  }
144
146
  return body;
145
147
  }
148
+ function retryAfter(v, now = Date.now()) {
149
+ if (!v) return void 0;
150
+ const t = v.trim();
151
+ if (/^\d+$/.test(t)) return Number(t);
152
+ const at = Date.parse(t);
153
+ if (Number.isNaN(at)) return void 0;
154
+ return Math.max(0, Math.ceil((at - now) / 1e3));
155
+ }
146
156
 
147
157
  // src/resources/attribution.ts
148
158
  var AttributionResource = class {
@@ -684,12 +694,17 @@ var AuthResource = class {
684
694
  return resp;
685
695
  }
686
696
  /** Verify a TOTP code (or XXXX-XXXX backup code) against a
687
- * `totp_required` challenge. On success the JWT is stored. */
697
+ * `totp_required` challenge. On success the JWT is stored. A backup code
698
+ * signs nobody in: it is used up and the answer is
699
+ * `totp_setup_email_required`, the start of connecting a new
700
+ * authenticator ({@link confirmTotpSetupEmail}). Nothing is stored then.
701
+ * Errors after a backup code: see {@link TotpSetupEmailErrorCode}. */
688
702
  async verifyTotp(input) {
689
703
  const resp = await this.http.post("/auth/login/totp", {
690
704
  body: withRemember(input),
691
705
  skipAuth: true
692
706
  });
707
+ if (resp.stage === "totp_setup_email_required") return resp;
693
708
  await this.keep(resp);
694
709
  return resp;
695
710
  }
@@ -762,6 +777,28 @@ var AuthResource = class {
762
777
  await this.keep(resp);
763
778
  return resp;
764
779
  }
780
+ /** Send the code from the e-mail of a `totp_setup_email_required`
781
+ * answer. A right code answers `totp_setup_required`: show its
782
+ * `otpauth_url` as a QR, then finish with {@link completeTotpSetup}.
783
+ * Each code works for 5 minutes and takes five tries; only the newest
784
+ * one works. Nothing is stored. Errors: {@link TotpSetupEmailErrorCode}. */
785
+ async confirmTotpSetupEmail(input) {
786
+ return this.http.post("/auth/login/totp-setup/email", {
787
+ body: { challenge_token: input.challenge_token, code: input.code },
788
+ skipAuth: true
789
+ });
790
+ }
791
+ /** A new e-mail code for the same `totp_setup_email_required` sign-in;
792
+ * the one before it stops working. Use the `challenge_token` of the
793
+ * answer from now on. Five codes an hour at most.
794
+ * Errors: {@link TotpSetupEmailErrorCode}; 401 means the sign-in is over,
795
+ * so start again with {@link login}. */
796
+ async resendTotpSetupEmail(input) {
797
+ return this.http.post("/auth/login/totp-setup/email/resend", {
798
+ body: { challenge_token: input.challenge_token },
799
+ skipAuth: true
800
+ });
801
+ }
765
802
  /** Finish a `totp_setup_required` login: send the first code from the
766
803
  * authenticator app. The JWT is stored. The response carries ten
767
804
  * one-time `backup_codes` that are never returned again, so show them to
@@ -1746,7 +1783,7 @@ var FundingOptionsResource = class {
1746
1783
  };
1747
1784
 
1748
1785
  // src/version.ts
1749
- var SDK_VERSION = "0.8.3";
1786
+ var SDK_VERSION = "0.9.0";
1750
1787
 
1751
1788
  // src/client-platform.ts
1752
1789
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1883,12 +1920,18 @@ function readyInfo(raw, healthy) {
1883
1920
  }
1884
1921
  return { ...base, compatible: true };
1885
1922
  }
1923
+ function isReadyBody(body) {
1924
+ if (typeof body !== "object" || body === null || Array.isArray(body)) return false;
1925
+ const b = body;
1926
+ const block = (v) => typeof v === "object" && v !== null;
1927
+ return b.code !== "service_unavailable" && typeof b.status === "string" && (block(b.checks) || block(b.ops));
1928
+ }
1886
1929
  async function fetchReady(http, opts = {}) {
1887
1930
  try {
1888
1931
  const body = await http.get("/ready", { skipAuth: true, signal: opts.signal });
1889
1932
  return readyInfo(body ?? {}, true);
1890
1933
  } catch (e) {
1891
- if (isApiError(e) && e.status === 503 && typeof e.body === "object" && e.body !== null) {
1934
+ if (isApiError(e) && e.status === 503 && isReadyBody(e.body)) {
1892
1935
  return readyInfo(e.body, false);
1893
1936
  }
1894
1937
  throw e;