@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
@@ -2,7 +2,7 @@ import { ConsentKind, ConsentChannel } from './consents.cjs';
2
2
  import { H as HttpClient, T as TokenStore } from '../http-CL97TjMO.cjs';
3
3
  import { SignupAttribution } from './attribution.cjs';
4
4
  import { CodeResult } from './codes.cjs';
5
- import { k as CardOrderInput, i as CardOrder, j as CardOrderError } from '../cards-BPu8Ill7.cjs';
5
+ import { k as CardOrderInput, i as CardOrder, j as CardOrderError } from '../cards-C5rk0XkI.cjs';
6
6
  import './claims.cjs';
7
7
 
8
8
  /**
@@ -96,7 +96,7 @@ interface LoginInput {
96
96
  remember?: boolean;
97
97
  }
98
98
  /** Discriminated union — `stage` is the discriminator. */
99
- type LoginResponse = JwtIssued | TotpRequired | TotpSetupRequired;
99
+ type LoginResponse = JwtIssued | TotpRequired | TotpSetupEmailRequired | TotpSetupRequired;
100
100
  interface JwtIssued {
101
101
  stage: "jwt";
102
102
  access_token: string;
@@ -120,6 +120,40 @@ interface TotpRequired {
120
120
  /** Alternate second factors. Pick one with `/2fa/switch`. */
121
121
  available_methods: AvailableMethod[];
122
122
  }
123
+ /** A staff account is about to connect an authenticator: its first one, or
124
+ * a new one after a backup code. The password alone is not enough, so a
125
+ * six-digit code went to the account's e-mail first and no secret exists
126
+ * yet. Send the code with {@link AuthResource.confirmTotpSetupEmail}; the
127
+ * answer is `totp_setup_required` with the QR. Needs platform 0.8.4; older
128
+ * servers answer `totp_setup_required` straight away. */
129
+ interface TotpSetupEmailRequired {
130
+ stage: "totp_setup_email_required";
131
+ challenge_token: string;
132
+ /** When the challenge ends; sign in again after that. */
133
+ challenge_expires_at: string;
134
+ /** Where the code went, partly hidden: `al***@example.com`. */
135
+ destination_hint: string;
136
+ /** When this code stops working. */
137
+ code_expires_at: string;
138
+ }
139
+ /** The `code` of an `ApiError` from the e-mail step before an
140
+ * authenticator is connected (`login`, `verifyTotp` with a backup code,
141
+ * `confirmTotpSetupEmail`, `resendTotpSetupEmail`):
142
+ * - `email_required` (409): the account has no e-mail address; an
143
+ * administrator has to add one;
144
+ * - `too_many_requests` (429): five codes went out in the last hour;
145
+ * - `delivery_failed` (503): the code could not be sent, try again;
146
+ * - `invalid_code` (401): wrong, expired, used or replaced code;
147
+ * - `sign_in_again` (409): the account changed while the code was on its
148
+ * way (its address, or an authenticator was connected meanwhile);
149
+ * - `too_many_attempts` (429): locked after too many wrong codes. */
150
+ type TotpSetupEmailErrorCode = "email_required" | "too_many_requests" | "delivery_failed" | "invalid_code" | "sign_in_again" | "too_many_attempts";
151
+ interface TotpSetupEmailInput {
152
+ /** From the `totp_setup_email_required` answer. */
153
+ challenge_token: string;
154
+ /** The six digits from the e-mail. */
155
+ code: string;
156
+ }
123
157
  interface TotpSetupRequired {
124
158
  stage: "totp_setup_required";
125
159
  challenge_token: string;
@@ -312,8 +346,12 @@ declare class AuthResource {
312
346
  * challenge that needs `verifyTotp` / `verifyOtp` next. */
313
347
  login(input: LoginInput): Promise<LoginResponse>;
314
348
  /** Verify a TOTP code (or XXXX-XXXX backup code) against a
315
- * `totp_required` challenge. On success the JWT is stored. */
316
- verifyTotp(input: TotpVerifyInput): Promise<JwtIssued>;
349
+ * `totp_required` challenge. On success the JWT is stored. A backup code
350
+ * signs nobody in: it is used up and the answer is
351
+ * `totp_setup_email_required`, the start of connecting a new
352
+ * authenticator ({@link confirmTotpSetupEmail}). Nothing is stored then.
353
+ * Errors after a backup code: see {@link TotpSetupEmailErrorCode}. */
354
+ verifyTotp(input: TotpVerifyInput): Promise<JwtIssued | TotpSetupEmailRequired>;
317
355
  /** Verify a 6-digit OTP code (Telegram / email) against an
318
356
  * `otp_sent` challenge. */
319
357
  verifyOtp(input: OtpVerifyInput): Promise<JwtIssued>;
@@ -341,6 +379,20 @@ declare class AuthResource {
341
379
  * `user_disabled` / `second_factor_required` (operator accounts sign in
342
380
  * with a password and their authenticator). */
343
381
  verifyEmailCode(input: VerifyEmailCodeInput): Promise<EmailCodeSession>;
382
+ /** Send the code from the e-mail of a `totp_setup_email_required`
383
+ * answer. A right code answers `totp_setup_required`: show its
384
+ * `otpauth_url` as a QR, then finish with {@link completeTotpSetup}.
385
+ * Each code works for 5 minutes and takes five tries; only the newest
386
+ * one works. Nothing is stored. Errors: {@link TotpSetupEmailErrorCode}. */
387
+ confirmTotpSetupEmail(input: TotpSetupEmailInput): Promise<TotpSetupRequired>;
388
+ /** A new e-mail code for the same `totp_setup_email_required` sign-in;
389
+ * the one before it stops working. Use the `challenge_token` of the
390
+ * answer from now on. Five codes an hour at most.
391
+ * Errors: {@link TotpSetupEmailErrorCode}; 401 means the sign-in is over,
392
+ * so start again with {@link login}. */
393
+ resendTotpSetupEmail(input: {
394
+ challenge_token: string;
395
+ }): Promise<TotpSetupEmailRequired>;
344
396
  /** Finish a `totp_setup_required` login: send the first code from the
345
397
  * authenticator app. The JWT is stored. The response carries ten
346
398
  * one-time `backup_codes` that are never returned again, so show them to
@@ -441,4 +493,4 @@ declare class AuthResource {
441
493
  signOut(): Promise<void>;
442
494
  }
443
495
 
444
- export { AuthResource, type AvailableMethod, type ChangePasswordInput, type ConfirmPasswordSetupInput, type EmailChangeRequested, type EmailCodeSent, type EmailCodeSession, type ExchangeTelegramInput, type JwtIssued, type LinkTelegramInput, type LoginInput, type LoginResponse, type OtpSentResponse, type OtpVerifyInput, type PasswordSetupRequested, type RegisterInput, type RequestEmailCodeInput, type Session, type SwitchMethodInput, type TelegramLink, type TelegramUnknown, type TotpRequired, type TotpSetupComplete, type TotpSetupRequired, type TotpVerifyInput, type User, type VerifyEmailCodeInput };
496
+ export { AuthResource, type AvailableMethod, type ChangePasswordInput, type ConfirmPasswordSetupInput, type EmailChangeRequested, type EmailCodeSent, type EmailCodeSession, type ExchangeTelegramInput, type JwtIssued, type LinkTelegramInput, type LoginInput, type LoginResponse, type OtpSentResponse, type OtpVerifyInput, type PasswordSetupRequested, type RegisterInput, type RequestEmailCodeInput, type Session, type SwitchMethodInput, type TelegramLink, type TelegramUnknown, type TotpRequired, type TotpSetupComplete, type TotpSetupEmailErrorCode, type TotpSetupEmailInput, type TotpSetupEmailRequired, type TotpSetupRequired, type TotpVerifyInput, type User, type VerifyEmailCodeInput };
@@ -2,7 +2,7 @@ import { ConsentKind, ConsentChannel } from './consents.js';
2
2
  import { H as HttpClient, T as TokenStore } from '../http-CL97TjMO.js';
3
3
  import { SignupAttribution } from './attribution.js';
4
4
  import { CodeResult } from './codes.js';
5
- import { k as CardOrderInput, i as CardOrder, j as CardOrderError } from '../cards-DP1fJc_c.js';
5
+ import { k as CardOrderInput, i as CardOrder, j as CardOrderError } from '../cards-CS-oxqLS.js';
6
6
  import './claims.js';
7
7
 
8
8
  /**
@@ -96,7 +96,7 @@ interface LoginInput {
96
96
  remember?: boolean;
97
97
  }
98
98
  /** Discriminated union — `stage` is the discriminator. */
99
- type LoginResponse = JwtIssued | TotpRequired | TotpSetupRequired;
99
+ type LoginResponse = JwtIssued | TotpRequired | TotpSetupEmailRequired | TotpSetupRequired;
100
100
  interface JwtIssued {
101
101
  stage: "jwt";
102
102
  access_token: string;
@@ -120,6 +120,40 @@ interface TotpRequired {
120
120
  /** Alternate second factors. Pick one with `/2fa/switch`. */
121
121
  available_methods: AvailableMethod[];
122
122
  }
123
+ /** A staff account is about to connect an authenticator: its first one, or
124
+ * a new one after a backup code. The password alone is not enough, so a
125
+ * six-digit code went to the account's e-mail first and no secret exists
126
+ * yet. Send the code with {@link AuthResource.confirmTotpSetupEmail}; the
127
+ * answer is `totp_setup_required` with the QR. Needs platform 0.8.4; older
128
+ * servers answer `totp_setup_required` straight away. */
129
+ interface TotpSetupEmailRequired {
130
+ stage: "totp_setup_email_required";
131
+ challenge_token: string;
132
+ /** When the challenge ends; sign in again after that. */
133
+ challenge_expires_at: string;
134
+ /** Where the code went, partly hidden: `al***@example.com`. */
135
+ destination_hint: string;
136
+ /** When this code stops working. */
137
+ code_expires_at: string;
138
+ }
139
+ /** The `code` of an `ApiError` from the e-mail step before an
140
+ * authenticator is connected (`login`, `verifyTotp` with a backup code,
141
+ * `confirmTotpSetupEmail`, `resendTotpSetupEmail`):
142
+ * - `email_required` (409): the account has no e-mail address; an
143
+ * administrator has to add one;
144
+ * - `too_many_requests` (429): five codes went out in the last hour;
145
+ * - `delivery_failed` (503): the code could not be sent, try again;
146
+ * - `invalid_code` (401): wrong, expired, used or replaced code;
147
+ * - `sign_in_again` (409): the account changed while the code was on its
148
+ * way (its address, or an authenticator was connected meanwhile);
149
+ * - `too_many_attempts` (429): locked after too many wrong codes. */
150
+ type TotpSetupEmailErrorCode = "email_required" | "too_many_requests" | "delivery_failed" | "invalid_code" | "sign_in_again" | "too_many_attempts";
151
+ interface TotpSetupEmailInput {
152
+ /** From the `totp_setup_email_required` answer. */
153
+ challenge_token: string;
154
+ /** The six digits from the e-mail. */
155
+ code: string;
156
+ }
123
157
  interface TotpSetupRequired {
124
158
  stage: "totp_setup_required";
125
159
  challenge_token: string;
@@ -312,8 +346,12 @@ declare class AuthResource {
312
346
  * challenge that needs `verifyTotp` / `verifyOtp` next. */
313
347
  login(input: LoginInput): Promise<LoginResponse>;
314
348
  /** Verify a TOTP code (or XXXX-XXXX backup code) against a
315
- * `totp_required` challenge. On success the JWT is stored. */
316
- verifyTotp(input: TotpVerifyInput): Promise<JwtIssued>;
349
+ * `totp_required` challenge. On success the JWT is stored. A backup code
350
+ * signs nobody in: it is used up and the answer is
351
+ * `totp_setup_email_required`, the start of connecting a new
352
+ * authenticator ({@link confirmTotpSetupEmail}). Nothing is stored then.
353
+ * Errors after a backup code: see {@link TotpSetupEmailErrorCode}. */
354
+ verifyTotp(input: TotpVerifyInput): Promise<JwtIssued | TotpSetupEmailRequired>;
317
355
  /** Verify a 6-digit OTP code (Telegram / email) against an
318
356
  * `otp_sent` challenge. */
319
357
  verifyOtp(input: OtpVerifyInput): Promise<JwtIssued>;
@@ -341,6 +379,20 @@ declare class AuthResource {
341
379
  * `user_disabled` / `second_factor_required` (operator accounts sign in
342
380
  * with a password and their authenticator). */
343
381
  verifyEmailCode(input: VerifyEmailCodeInput): Promise<EmailCodeSession>;
382
+ /** Send the code from the e-mail of a `totp_setup_email_required`
383
+ * answer. A right code answers `totp_setup_required`: show its
384
+ * `otpauth_url` as a QR, then finish with {@link completeTotpSetup}.
385
+ * Each code works for 5 minutes and takes five tries; only the newest
386
+ * one works. Nothing is stored. Errors: {@link TotpSetupEmailErrorCode}. */
387
+ confirmTotpSetupEmail(input: TotpSetupEmailInput): Promise<TotpSetupRequired>;
388
+ /** A new e-mail code for the same `totp_setup_email_required` sign-in;
389
+ * the one before it stops working. Use the `challenge_token` of the
390
+ * answer from now on. Five codes an hour at most.
391
+ * Errors: {@link TotpSetupEmailErrorCode}; 401 means the sign-in is over,
392
+ * so start again with {@link login}. */
393
+ resendTotpSetupEmail(input: {
394
+ challenge_token: string;
395
+ }): Promise<TotpSetupEmailRequired>;
344
396
  /** Finish a `totp_setup_required` login: send the first code from the
345
397
  * authenticator app. The JWT is stored. The response carries ten
346
398
  * one-time `backup_codes` that are never returned again, so show them to
@@ -441,4 +493,4 @@ declare class AuthResource {
441
493
  signOut(): Promise<void>;
442
494
  }
443
495
 
444
- export { AuthResource, type AvailableMethod, type ChangePasswordInput, type ConfirmPasswordSetupInput, type EmailChangeRequested, type EmailCodeSent, type EmailCodeSession, type ExchangeTelegramInput, type JwtIssued, type LinkTelegramInput, type LoginInput, type LoginResponse, type OtpSentResponse, type OtpVerifyInput, type PasswordSetupRequested, type RegisterInput, type RequestEmailCodeInput, type Session, type SwitchMethodInput, type TelegramLink, type TelegramUnknown, type TotpRequired, type TotpSetupComplete, type TotpSetupRequired, type TotpVerifyInput, type User, type VerifyEmailCodeInput };
496
+ export { AuthResource, type AvailableMethod, type ChangePasswordInput, type ConfirmPasswordSetupInput, type EmailChangeRequested, type EmailCodeSent, type EmailCodeSession, type ExchangeTelegramInput, type JwtIssued, type LinkTelegramInput, type LoginInput, type LoginResponse, type OtpSentResponse, type OtpVerifyInput, type PasswordSetupRequested, type RegisterInput, type RequestEmailCodeInput, type Session, type SwitchMethodInput, type TelegramLink, type TelegramUnknown, type TotpRequired, type TotpSetupComplete, type TotpSetupEmailErrorCode, type TotpSetupEmailInput, type TotpSetupEmailRequired, type TotpSetupRequired, type TotpVerifyInput, type User, type VerifyEmailCodeInput };
@@ -153,12 +153,17 @@ var AuthResource = class {
153
153
  return resp;
154
154
  }
155
155
  /** Verify a TOTP code (or XXXX-XXXX backup code) against a
156
- * `totp_required` challenge. On success the JWT is stored. */
156
+ * `totp_required` challenge. On success the JWT is stored. A backup code
157
+ * signs nobody in: it is used up and the answer is
158
+ * `totp_setup_email_required`, the start of connecting a new
159
+ * authenticator ({@link confirmTotpSetupEmail}). Nothing is stored then.
160
+ * Errors after a backup code: see {@link TotpSetupEmailErrorCode}. */
157
161
  async verifyTotp(input) {
158
162
  const resp = await this.http.post("/auth/login/totp", {
159
163
  body: withRemember(input),
160
164
  skipAuth: true
161
165
  });
166
+ if (resp.stage === "totp_setup_email_required") return resp;
162
167
  await this.keep(resp);
163
168
  return resp;
164
169
  }
@@ -231,6 +236,28 @@ var AuthResource = class {
231
236
  await this.keep(resp);
232
237
  return resp;
233
238
  }
239
+ /** Send the code from the e-mail of a `totp_setup_email_required`
240
+ * answer. A right code answers `totp_setup_required`: show its
241
+ * `otpauth_url` as a QR, then finish with {@link completeTotpSetup}.
242
+ * Each code works for 5 minutes and takes five tries; only the newest
243
+ * one works. Nothing is stored. Errors: {@link TotpSetupEmailErrorCode}. */
244
+ async confirmTotpSetupEmail(input) {
245
+ return this.http.post("/auth/login/totp-setup/email", {
246
+ body: { challenge_token: input.challenge_token, code: input.code },
247
+ skipAuth: true
248
+ });
249
+ }
250
+ /** A new e-mail code for the same `totp_setup_email_required` sign-in;
251
+ * the one before it stops working. Use the `challenge_token` of the
252
+ * answer from now on. Five codes an hour at most.
253
+ * Errors: {@link TotpSetupEmailErrorCode}; 401 means the sign-in is over,
254
+ * so start again with {@link login}. */
255
+ async resendTotpSetupEmail(input) {
256
+ return this.http.post("/auth/login/totp-setup/email/resend", {
257
+ body: { challenge_token: input.challenge_token },
258
+ skipAuth: true
259
+ });
260
+ }
234
261
  /** Finish a `totp_setup_required` login: send the first code from the
235
262
  * authenticator app. The JWT is stored. The response carries ten
236
263
  * one-time `backup_codes` that are never returned again, so show them to