@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.
- package/CHANGELOG.md +68 -1
- package/README.md +49 -7
- package/dist/{cards-BPu8Ill7.d.cts → cards-DwxkVJUB.d.cts} +36 -3
- package/dist/{cards-DP1fJc_c.d.ts → cards-VkS_2lPe.d.ts} +36 -3
- package/dist/index.cjs +59 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +59 -4
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/resources/auth.cjs +58 -3
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +102 -7
- package/dist/resources/auth.d.ts +102 -7
- package/dist/resources/auth.js +58 -3
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/cards.d.cts +1 -1
- package/dist/resources/cards.d.ts +1 -1
- package/dist/resources/deposits.cjs.map +1 -1
- package/dist/resources/deposits.d.cts +1 -1
- package/dist/resources/deposits.d.ts +1 -1
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/funding-options.d.cts +1 -1
- package/dist/resources/funding-options.d.ts +1 -1
- package/dist/resources/me.d.cts +1 -1
- package/dist/resources/me.d.ts +1 -1
- package/dist/resources/subscription.cjs.map +1 -1
- package/dist/resources/subscription.d.cts +4 -0
- package/dist/resources/subscription.d.ts +4 -0
- package/dist/resources/subscription.js.map +1 -1
- package/dist/telegram.cjs +59 -4
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +1 -1
- package/dist/telegram.d.ts +1 -1
- package/dist/telegram.js +59 -4
- package/dist/telegram.js.map +1 -1
- 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-
|
|
5
|
+
import { k as CardOrderInput, i as CardOrder, j as CardOrderError } from '../cards-DwxkVJUB.cjs';
|
|
6
6
|
import './claims.cjs';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -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. */
|
|
@@ -89,7 +96,7 @@ interface LoginInput {
|
|
|
89
96
|
remember?: boolean;
|
|
90
97
|
}
|
|
91
98
|
/** Discriminated union — `stage` is the discriminator. */
|
|
92
|
-
type LoginResponse = JwtIssued | TotpRequired | TotpSetupRequired;
|
|
99
|
+
type LoginResponse = JwtIssued | TotpRequired | TotpSetupEmailRequired | TotpSetupRequired;
|
|
93
100
|
interface JwtIssued {
|
|
94
101
|
stage: "jwt";
|
|
95
102
|
access_token: string;
|
|
@@ -113,6 +120,40 @@ interface TotpRequired {
|
|
|
113
120
|
/** Alternate second factors. Pick one with `/2fa/switch`. */
|
|
114
121
|
available_methods: AvailableMethod[];
|
|
115
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
|
+
}
|
|
116
157
|
interface TotpSetupRequired {
|
|
117
158
|
stage: "totp_setup_required";
|
|
118
159
|
challenge_token: string;
|
|
@@ -255,6 +296,22 @@ interface TotpSetupComplete extends Session {
|
|
|
255
296
|
/** Ten one-time `XXXX-XXXX` codes, returned only this once. */
|
|
256
297
|
backup_codes: string[];
|
|
257
298
|
}
|
|
299
|
+
/** What `requestPasswordSetup` returns: send `challengeId` back with the
|
|
300
|
+
* code and the new password. */
|
|
301
|
+
interface PasswordSetupRequested {
|
|
302
|
+
challenge_id: string;
|
|
303
|
+
/** Where the code went, partly hidden: `al***@example.com`. */
|
|
304
|
+
destination_hint: string;
|
|
305
|
+
expires_at: string;
|
|
306
|
+
}
|
|
307
|
+
interface ConfirmPasswordSetupInput {
|
|
308
|
+
challengeId: string;
|
|
309
|
+
/** The six digits from the e-mail. */
|
|
310
|
+
code: string;
|
|
311
|
+
/** At least 12 characters with a lower-case letter, an upper-case letter
|
|
312
|
+
* and a digit. */
|
|
313
|
+
newPassword: string;
|
|
314
|
+
}
|
|
258
315
|
interface ChangePasswordInput {
|
|
259
316
|
current_password: string;
|
|
260
317
|
/** At least 12 characters with a lower-case letter, an upper-case letter
|
|
@@ -289,8 +346,12 @@ declare class AuthResource {
|
|
|
289
346
|
* challenge that needs `verifyTotp` / `verifyOtp` next. */
|
|
290
347
|
login(input: LoginInput): Promise<LoginResponse>;
|
|
291
348
|
/** Verify a TOTP code (or XXXX-XXXX backup code) against a
|
|
292
|
-
* `totp_required` challenge. On success the JWT is stored.
|
|
293
|
-
|
|
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>;
|
|
294
355
|
/** Verify a 6-digit OTP code (Telegram / email) against an
|
|
295
356
|
* `otp_sent` challenge. */
|
|
296
357
|
verifyOtp(input: OtpVerifyInput): Promise<JwtIssued>;
|
|
@@ -318,6 +379,20 @@ declare class AuthResource {
|
|
|
318
379
|
* `user_disabled` / `second_factor_required` (operator accounts sign in
|
|
319
380
|
* with a password and their authenticator). */
|
|
320
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>;
|
|
321
396
|
/** Finish a `totp_setup_required` login: send the first code from the
|
|
322
397
|
* authenticator app. The JWT is stored. The response carries ten
|
|
323
398
|
* one-time `backup_codes` that are never returned again, so show them to
|
|
@@ -325,11 +400,31 @@ declare class AuthResource {
|
|
|
325
400
|
completeTotpSetup(input: TotpVerifyInput): Promise<TotpSetupComplete>;
|
|
326
401
|
/** Change the signed-in user's password. Every other session of the
|
|
327
402
|
* account is signed out; this one stays valid.
|
|
328
|
-
* Errors: 400 when the new password fails the policy,
|
|
329
|
-
*
|
|
403
|
+
* Errors: 400 `weak_password` when the new password fails the policy,
|
|
404
|
+
* 400 `no_password` when the account has none yet (use
|
|
405
|
+
* {@link requestPasswordSetup}), 401 when the current one is wrong. */
|
|
330
406
|
changePassword(input: ChangePasswordInput): Promise<{
|
|
331
407
|
revoked_sessions: number;
|
|
332
408
|
}>;
|
|
409
|
+
/** Step one of setting the first password of an account that has none
|
|
410
|
+
* (`user.has_password === false`, e.g. made by signing in with an e-mail
|
|
411
|
+
* code): a six-digit code goes to the account's address and works for 5
|
|
412
|
+
* minutes. Nothing changes yet.
|
|
413
|
+
* Errors: 409 `password_exists` (use {@link changePassword}),
|
|
414
|
+
* `email_required` (a Telegram account with no address yet: attach one
|
|
415
|
+
* with {@link requestEmailChange} first), `email_not_proven` (sign in
|
|
416
|
+
* with an e-mail code first); 429 `too_many_requests` (five codes an
|
|
417
|
+
* hour); 503 `delivery_failed`. Platform 0.8.2 and newer. */
|
|
418
|
+
requestPasswordSetup(): Promise<PasswordSetupRequested>;
|
|
419
|
+
/** Step two: the code from the e-mail and the new password set the
|
|
420
|
+
* account's first password. Every other session of the account is signed
|
|
421
|
+
* out; this one stays valid, and signing in with a code keeps working.
|
|
422
|
+
* Errors: 400 `weak_password` (the code is not used up, fix the password
|
|
423
|
+
* and send again), 401 `invalid_code` (after five wrong codes ask for a
|
|
424
|
+
* new one), 409 `password_exists`. */
|
|
425
|
+
confirmPasswordSetup(input: ConfirmPasswordSetupInput): Promise<{
|
|
426
|
+
revoked_sessions: number;
|
|
427
|
+
}>;
|
|
333
428
|
/** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
|
|
334
429
|
* telegram/email; for TOTP it short-circuits back to the challenge. */
|
|
335
430
|
switchMethod(input: SwitchMethodInput): Promise<OtpSentResponse>;
|
|
@@ -398,4 +493,4 @@ declare class AuthResource {
|
|
|
398
493
|
signOut(): Promise<void>;
|
|
399
494
|
}
|
|
400
495
|
|
|
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 };
|
|
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 };
|
package/dist/resources/auth.d.ts
CHANGED
|
@@ -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-
|
|
5
|
+
import { k as CardOrderInput, i as CardOrder, j as CardOrderError } from '../cards-VkS_2lPe.js';
|
|
6
6
|
import './claims.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -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. */
|
|
@@ -89,7 +96,7 @@ interface LoginInput {
|
|
|
89
96
|
remember?: boolean;
|
|
90
97
|
}
|
|
91
98
|
/** Discriminated union — `stage` is the discriminator. */
|
|
92
|
-
type LoginResponse = JwtIssued | TotpRequired | TotpSetupRequired;
|
|
99
|
+
type LoginResponse = JwtIssued | TotpRequired | TotpSetupEmailRequired | TotpSetupRequired;
|
|
93
100
|
interface JwtIssued {
|
|
94
101
|
stage: "jwt";
|
|
95
102
|
access_token: string;
|
|
@@ -113,6 +120,40 @@ interface TotpRequired {
|
|
|
113
120
|
/** Alternate second factors. Pick one with `/2fa/switch`. */
|
|
114
121
|
available_methods: AvailableMethod[];
|
|
115
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
|
+
}
|
|
116
157
|
interface TotpSetupRequired {
|
|
117
158
|
stage: "totp_setup_required";
|
|
118
159
|
challenge_token: string;
|
|
@@ -255,6 +296,22 @@ interface TotpSetupComplete extends Session {
|
|
|
255
296
|
/** Ten one-time `XXXX-XXXX` codes, returned only this once. */
|
|
256
297
|
backup_codes: string[];
|
|
257
298
|
}
|
|
299
|
+
/** What `requestPasswordSetup` returns: send `challengeId` back with the
|
|
300
|
+
* code and the new password. */
|
|
301
|
+
interface PasswordSetupRequested {
|
|
302
|
+
challenge_id: string;
|
|
303
|
+
/** Where the code went, partly hidden: `al***@example.com`. */
|
|
304
|
+
destination_hint: string;
|
|
305
|
+
expires_at: string;
|
|
306
|
+
}
|
|
307
|
+
interface ConfirmPasswordSetupInput {
|
|
308
|
+
challengeId: string;
|
|
309
|
+
/** The six digits from the e-mail. */
|
|
310
|
+
code: string;
|
|
311
|
+
/** At least 12 characters with a lower-case letter, an upper-case letter
|
|
312
|
+
* and a digit. */
|
|
313
|
+
newPassword: string;
|
|
314
|
+
}
|
|
258
315
|
interface ChangePasswordInput {
|
|
259
316
|
current_password: string;
|
|
260
317
|
/** At least 12 characters with a lower-case letter, an upper-case letter
|
|
@@ -289,8 +346,12 @@ declare class AuthResource {
|
|
|
289
346
|
* challenge that needs `verifyTotp` / `verifyOtp` next. */
|
|
290
347
|
login(input: LoginInput): Promise<LoginResponse>;
|
|
291
348
|
/** Verify a TOTP code (or XXXX-XXXX backup code) against a
|
|
292
|
-
* `totp_required` challenge. On success the JWT is stored.
|
|
293
|
-
|
|
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>;
|
|
294
355
|
/** Verify a 6-digit OTP code (Telegram / email) against an
|
|
295
356
|
* `otp_sent` challenge. */
|
|
296
357
|
verifyOtp(input: OtpVerifyInput): Promise<JwtIssued>;
|
|
@@ -318,6 +379,20 @@ declare class AuthResource {
|
|
|
318
379
|
* `user_disabled` / `second_factor_required` (operator accounts sign in
|
|
319
380
|
* with a password and their authenticator). */
|
|
320
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>;
|
|
321
396
|
/** Finish a `totp_setup_required` login: send the first code from the
|
|
322
397
|
* authenticator app. The JWT is stored. The response carries ten
|
|
323
398
|
* one-time `backup_codes` that are never returned again, so show them to
|
|
@@ -325,11 +400,31 @@ declare class AuthResource {
|
|
|
325
400
|
completeTotpSetup(input: TotpVerifyInput): Promise<TotpSetupComplete>;
|
|
326
401
|
/** Change the signed-in user's password. Every other session of the
|
|
327
402
|
* account is signed out; this one stays valid.
|
|
328
|
-
* Errors: 400 when the new password fails the policy,
|
|
329
|
-
*
|
|
403
|
+
* Errors: 400 `weak_password` when the new password fails the policy,
|
|
404
|
+
* 400 `no_password` when the account has none yet (use
|
|
405
|
+
* {@link requestPasswordSetup}), 401 when the current one is wrong. */
|
|
330
406
|
changePassword(input: ChangePasswordInput): Promise<{
|
|
331
407
|
revoked_sessions: number;
|
|
332
408
|
}>;
|
|
409
|
+
/** Step one of setting the first password of an account that has none
|
|
410
|
+
* (`user.has_password === false`, e.g. made by signing in with an e-mail
|
|
411
|
+
* code): a six-digit code goes to the account's address and works for 5
|
|
412
|
+
* minutes. Nothing changes yet.
|
|
413
|
+
* Errors: 409 `password_exists` (use {@link changePassword}),
|
|
414
|
+
* `email_required` (a Telegram account with no address yet: attach one
|
|
415
|
+
* with {@link requestEmailChange} first), `email_not_proven` (sign in
|
|
416
|
+
* with an e-mail code first); 429 `too_many_requests` (five codes an
|
|
417
|
+
* hour); 503 `delivery_failed`. Platform 0.8.2 and newer. */
|
|
418
|
+
requestPasswordSetup(): Promise<PasswordSetupRequested>;
|
|
419
|
+
/** Step two: the code from the e-mail and the new password set the
|
|
420
|
+
* account's first password. Every other session of the account is signed
|
|
421
|
+
* out; this one stays valid, and signing in with a code keeps working.
|
|
422
|
+
* Errors: 400 `weak_password` (the code is not used up, fix the password
|
|
423
|
+
* and send again), 401 `invalid_code` (after five wrong codes ask for a
|
|
424
|
+
* new one), 409 `password_exists`. */
|
|
425
|
+
confirmPasswordSetup(input: ConfirmPasswordSetupInput): Promise<{
|
|
426
|
+
revoked_sessions: number;
|
|
427
|
+
}>;
|
|
333
428
|
/** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
|
|
334
429
|
* telegram/email; for TOTP it short-circuits back to the challenge. */
|
|
335
430
|
switchMethod(input: SwitchMethodInput): Promise<OtpSentResponse>;
|
|
@@ -398,4 +493,4 @@ declare class AuthResource {
|
|
|
398
493
|
signOut(): Promise<void>;
|
|
399
494
|
}
|
|
400
495
|
|
|
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 };
|
|
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 };
|
package/dist/resources/auth.js
CHANGED
|
@@ -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
|
|
@@ -245,13 +272,41 @@ var AuthResource = class {
|
|
|
245
272
|
}
|
|
246
273
|
/** Change the signed-in user's password. Every other session of the
|
|
247
274
|
* account is signed out; this one stays valid.
|
|
248
|
-
* Errors: 400 when the new password fails the policy,
|
|
249
|
-
*
|
|
275
|
+
* Errors: 400 `weak_password` when the new password fails the policy,
|
|
276
|
+
* 400 `no_password` when the account has none yet (use
|
|
277
|
+
* {@link requestPasswordSetup}), 401 when the current one is wrong. */
|
|
250
278
|
async changePassword(input) {
|
|
251
279
|
return this.http.post("/auth/password", {
|
|
252
280
|
body: input
|
|
253
281
|
});
|
|
254
282
|
}
|
|
283
|
+
/** Step one of setting the first password of an account that has none
|
|
284
|
+
* (`user.has_password === false`, e.g. made by signing in with an e-mail
|
|
285
|
+
* code): a six-digit code goes to the account's address and works for 5
|
|
286
|
+
* minutes. Nothing changes yet.
|
|
287
|
+
* Errors: 409 `password_exists` (use {@link changePassword}),
|
|
288
|
+
* `email_required` (a Telegram account with no address yet: attach one
|
|
289
|
+
* with {@link requestEmailChange} first), `email_not_proven` (sign in
|
|
290
|
+
* with an e-mail code first); 429 `too_many_requests` (five codes an
|
|
291
|
+
* hour); 503 `delivery_failed`. Platform 0.8.2 and newer. */
|
|
292
|
+
async requestPasswordSetup() {
|
|
293
|
+
return this.http.post("/auth/password/setup", {});
|
|
294
|
+
}
|
|
295
|
+
/** Step two: the code from the e-mail and the new password set the
|
|
296
|
+
* account's first password. Every other session of the account is signed
|
|
297
|
+
* out; this one stays valid, and signing in with a code keeps working.
|
|
298
|
+
* Errors: 400 `weak_password` (the code is not used up, fix the password
|
|
299
|
+
* and send again), 401 `invalid_code` (after five wrong codes ask for a
|
|
300
|
+
* new one), 409 `password_exists`. */
|
|
301
|
+
async confirmPasswordSetup(input) {
|
|
302
|
+
return this.http.post("/auth/password/setup/confirm", {
|
|
303
|
+
body: {
|
|
304
|
+
challenge_id: input.challengeId,
|
|
305
|
+
code: input.code,
|
|
306
|
+
new_password: input.newPassword
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
255
310
|
/** Swap the 2FA method mid-flow. Resolves to `otp_sent` for
|
|
256
311
|
* telegram/email; for TOTP it short-circuits back to the challenge. */
|
|
257
312
|
async switchMethod(input) {
|