@takeal/cusfront-sdk 0.8.1 → 0.8.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.
@@ -38,6 +38,13 @@ interface User {
38
38
  /** The Telegram account linked to this user, or `null` when none is.
39
39
  * Present on `GET /auth/me` and inside every `stage: "jwt"` envelope. */
40
40
  telegram?: TelegramLink | null;
41
+ /** Whether the account has a password. `false` for an account that signs
42
+ * in with codes only: offer "set a password"
43
+ * ({@link AuthResource.requestPasswordSetup}) instead of "change password"
44
+ * ({@link AuthResource.changePassword}). Present on `GET /auth/me` and
45
+ * inside every `stage: "jwt"` envelope from platform 0.8.2; absent on
46
+ * older servers. */
47
+ has_password?: boolean;
41
48
  }
42
49
  /** A Telegram account attached to a user. One Telegram per account and one
43
50
  * account per Telegram. */
@@ -255,6 +262,22 @@ interface TotpSetupComplete extends Session {
255
262
  /** Ten one-time `XXXX-XXXX` codes, returned only this once. */
256
263
  backup_codes: string[];
257
264
  }
265
+ /** What `requestPasswordSetup` returns: send `challengeId` back with the
266
+ * code and the new password. */
267
+ interface PasswordSetupRequested {
268
+ challenge_id: string;
269
+ /** Where the code went, partly hidden: `al***@example.com`. */
270
+ destination_hint: string;
271
+ expires_at: string;
272
+ }
273
+ interface ConfirmPasswordSetupInput {
274
+ challengeId: string;
275
+ /** The six digits from the e-mail. */
276
+ code: string;
277
+ /** At least 12 characters with a lower-case letter, an upper-case letter
278
+ * and a digit. */
279
+ newPassword: string;
280
+ }
258
281
  interface ChangePasswordInput {
259
282
  current_password: string;
260
283
  /** At least 12 characters with a lower-case letter, an upper-case letter
@@ -325,11 +348,31 @@ declare class AuthResource {
325
348
  completeTotpSetup(input: TotpVerifyInput): Promise<TotpSetupComplete>;
326
349
  /** Change the signed-in user's password. Every other session of the
327
350
  * account is signed out; this one stays valid.
328
- * Errors: 400 when the new password fails the policy, 401 when the
329
- * current one is wrong. */
351
+ * Errors: 400 `weak_password` when the new password fails the policy,
352
+ * 400 `no_password` when the account has none yet (use
353
+ * {@link requestPasswordSetup}), 401 when the current one is wrong. */
330
354
  changePassword(input: ChangePasswordInput): Promise<{
331
355
  revoked_sessions: number;
332
356
  }>;
357
+ /** Step one of setting the first password of an account that has none
358
+ * (`user.has_password === false`, e.g. made by signing in with an e-mail
359
+ * code): a six-digit code goes to the account's address and works for 5
360
+ * minutes. Nothing changes yet.
361
+ * Errors: 409 `password_exists` (use {@link changePassword}),
362
+ * `email_required` (a Telegram account with no address yet: attach one
363
+ * with {@link requestEmailChange} first), `email_not_proven` (sign in
364
+ * with an e-mail code first); 429 `too_many_requests` (five codes an
365
+ * hour); 503 `delivery_failed`. Platform 0.8.2 and newer. */
366
+ requestPasswordSetup(): Promise<PasswordSetupRequested>;
367
+ /** Step two: the code from the e-mail and the new password set the
368
+ * account's first password. Every other session of the account is signed
369
+ * out; this one stays valid, and signing in with a code keeps working.
370
+ * Errors: 400 `weak_password` (the code is not used up, fix the password
371
+ * and send again), 401 `invalid_code` (after five wrong codes ask for a
372
+ * new one), 409 `password_exists`. */
373
+ confirmPasswordSetup(input: ConfirmPasswordSetupInput): Promise<{
374
+ revoked_sessions: number;
375
+ }>;
333
376
  /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
334
377
  * telegram/email; for TOTP it short-circuits back to the challenge. */
335
378
  switchMethod(input: SwitchMethodInput): Promise<OtpSentResponse>;
@@ -398,4 +441,4 @@ declare class AuthResource {
398
441
  signOut(): Promise<void>;
399
442
  }
400
443
 
401
- export { AuthResource, type AvailableMethod, type ChangePasswordInput, type EmailChangeRequested, type EmailCodeSent, type EmailCodeSession, type ExchangeTelegramInput, type JwtIssued, type LinkTelegramInput, type LoginInput, type LoginResponse, type OtpSentResponse, type OtpVerifyInput, type RegisterInput, type RequestEmailCodeInput, type Session, type SwitchMethodInput, type TelegramLink, type TelegramUnknown, type TotpRequired, type TotpSetupComplete, type TotpSetupRequired, type TotpVerifyInput, type User, type VerifyEmailCodeInput };
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 };
@@ -38,6 +38,13 @@ interface User {
38
38
  /** The Telegram account linked to this user, or `null` when none is.
39
39
  * Present on `GET /auth/me` and inside every `stage: "jwt"` envelope. */
40
40
  telegram?: TelegramLink | null;
41
+ /** Whether the account has a password. `false` for an account that signs
42
+ * in with codes only: offer "set a password"
43
+ * ({@link AuthResource.requestPasswordSetup}) instead of "change password"
44
+ * ({@link AuthResource.changePassword}). Present on `GET /auth/me` and
45
+ * inside every `stage: "jwt"` envelope from platform 0.8.2; absent on
46
+ * older servers. */
47
+ has_password?: boolean;
41
48
  }
42
49
  /** A Telegram account attached to a user. One Telegram per account and one
43
50
  * account per Telegram. */
@@ -255,6 +262,22 @@ interface TotpSetupComplete extends Session {
255
262
  /** Ten one-time `XXXX-XXXX` codes, returned only this once. */
256
263
  backup_codes: string[];
257
264
  }
265
+ /** What `requestPasswordSetup` returns: send `challengeId` back with the
266
+ * code and the new password. */
267
+ interface PasswordSetupRequested {
268
+ challenge_id: string;
269
+ /** Where the code went, partly hidden: `al***@example.com`. */
270
+ destination_hint: string;
271
+ expires_at: string;
272
+ }
273
+ interface ConfirmPasswordSetupInput {
274
+ challengeId: string;
275
+ /** The six digits from the e-mail. */
276
+ code: string;
277
+ /** At least 12 characters with a lower-case letter, an upper-case letter
278
+ * and a digit. */
279
+ newPassword: string;
280
+ }
258
281
  interface ChangePasswordInput {
259
282
  current_password: string;
260
283
  /** At least 12 characters with a lower-case letter, an upper-case letter
@@ -325,11 +348,31 @@ declare class AuthResource {
325
348
  completeTotpSetup(input: TotpVerifyInput): Promise<TotpSetupComplete>;
326
349
  /** Change the signed-in user's password. Every other session of the
327
350
  * account is signed out; this one stays valid.
328
- * Errors: 400 when the new password fails the policy, 401 when the
329
- * current one is wrong. */
351
+ * Errors: 400 `weak_password` when the new password fails the policy,
352
+ * 400 `no_password` when the account has none yet (use
353
+ * {@link requestPasswordSetup}), 401 when the current one is wrong. */
330
354
  changePassword(input: ChangePasswordInput): Promise<{
331
355
  revoked_sessions: number;
332
356
  }>;
357
+ /** Step one of setting the first password of an account that has none
358
+ * (`user.has_password === false`, e.g. made by signing in with an e-mail
359
+ * code): a six-digit code goes to the account's address and works for 5
360
+ * minutes. Nothing changes yet.
361
+ * Errors: 409 `password_exists` (use {@link changePassword}),
362
+ * `email_required` (a Telegram account with no address yet: attach one
363
+ * with {@link requestEmailChange} first), `email_not_proven` (sign in
364
+ * with an e-mail code first); 429 `too_many_requests` (five codes an
365
+ * hour); 503 `delivery_failed`. Platform 0.8.2 and newer. */
366
+ requestPasswordSetup(): Promise<PasswordSetupRequested>;
367
+ /** Step two: the code from the e-mail and the new password set the
368
+ * account's first password. Every other session of the account is signed
369
+ * out; this one stays valid, and signing in with a code keeps working.
370
+ * Errors: 400 `weak_password` (the code is not used up, fix the password
371
+ * and send again), 401 `invalid_code` (after five wrong codes ask for a
372
+ * new one), 409 `password_exists`. */
373
+ confirmPasswordSetup(input: ConfirmPasswordSetupInput): Promise<{
374
+ revoked_sessions: number;
375
+ }>;
333
376
  /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
334
377
  * telegram/email; for TOTP it short-circuits back to the challenge. */
335
378
  switchMethod(input: SwitchMethodInput): Promise<OtpSentResponse>;
@@ -398,4 +441,4 @@ declare class AuthResource {
398
441
  signOut(): Promise<void>;
399
442
  }
400
443
 
401
- export { AuthResource, type AvailableMethod, type ChangePasswordInput, type EmailChangeRequested, type EmailCodeSent, type EmailCodeSession, type ExchangeTelegramInput, type JwtIssued, type LinkTelegramInput, type LoginInput, type LoginResponse, type OtpSentResponse, type OtpVerifyInput, type RegisterInput, type RequestEmailCodeInput, type Session, type SwitchMethodInput, type TelegramLink, type TelegramUnknown, type TotpRequired, type TotpSetupComplete, type TotpSetupRequired, type TotpVerifyInput, type User, type VerifyEmailCodeInput };
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 };
@@ -245,13 +245,41 @@ var AuthResource = class {
245
245
  }
246
246
  /** Change the signed-in user's password. Every other session of the
247
247
  * account is signed out; this one stays valid.
248
- * Errors: 400 when the new password fails the policy, 401 when the
249
- * current one is wrong. */
248
+ * Errors: 400 `weak_password` when the new password fails the policy,
249
+ * 400 `no_password` when the account has none yet (use
250
+ * {@link requestPasswordSetup}), 401 when the current one is wrong. */
250
251
  async changePassword(input) {
251
252
  return this.http.post("/auth/password", {
252
253
  body: input
253
254
  });
254
255
  }
256
+ /** Step one of setting the first password of an account that has none
257
+ * (`user.has_password === false`, e.g. made by signing in with an e-mail
258
+ * code): a six-digit code goes to the account's address and works for 5
259
+ * minutes. Nothing changes yet.
260
+ * Errors: 409 `password_exists` (use {@link changePassword}),
261
+ * `email_required` (a Telegram account with no address yet: attach one
262
+ * with {@link requestEmailChange} first), `email_not_proven` (sign in
263
+ * with an e-mail code first); 429 `too_many_requests` (five codes an
264
+ * hour); 503 `delivery_failed`. Platform 0.8.2 and newer. */
265
+ async requestPasswordSetup() {
266
+ return this.http.post("/auth/password/setup", {});
267
+ }
268
+ /** Step two: the code from the e-mail and the new password set the
269
+ * account's first password. Every other session of the account is signed
270
+ * out; this one stays valid, and signing in with a code keeps working.
271
+ * Errors: 400 `weak_password` (the code is not used up, fix the password
272
+ * and send again), 401 `invalid_code` (after five wrong codes ask for a
273
+ * new one), 409 `password_exists`. */
274
+ async confirmPasswordSetup(input) {
275
+ return this.http.post("/auth/password/setup/confirm", {
276
+ body: {
277
+ challenge_id: input.challengeId,
278
+ code: input.code,
279
+ new_password: input.newPassword
280
+ }
281
+ });
282
+ }
255
283
  /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
256
284
  * telegram/email; for TOTP it short-circuits back to the challenge. */
257
285
  async switchMethod(input) {