@outseta/react 0.2.5 → 0.3.1

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.
@@ -0,0 +1,748 @@
1
+ // @ts-nocheck
2
+ import {
3
+ useMutation
4
+ } from '@tanstack/react-query';
5
+ import type {
6
+ MutationFunction,
7
+ UseMutationOptions,
8
+ UseMutationResult
9
+ } from '@tanstack/react-query';
10
+
11
+ import type {
12
+ AuthGetTokenParams,
13
+ AuthResendTwoFactorParams,
14
+ AuthSwitchTwoFactorMechanismParams,
15
+ AuthVerifyTwoFactorRecoveryParams,
16
+ AuthVerifyTwoFactorTokenParams,
17
+ TokenPayload,
18
+ TokenTwoFactorEnrollmentBeginEmailParams,
19
+ TokenTwoFactorEnrollmentBeginTotpParams,
20
+ TokenTwoFactorEnrollmentConfirmEmailParams,
21
+ TokenTwoFactorEnrollmentConfirmTotpParams,
22
+ TwoFactorChallengePayload,
23
+ TwoFactorEnrollmentConfirmationPayload,
24
+ TwoFactorTotpEnrollmentPayload
25
+ } from '../outsetaAPI.schemas';
26
+
27
+ import { customFetch } from '../../mutator';
28
+
29
+
30
+ type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
31
+
32
+
33
+
34
+ /**
35
+ * Post a JSON body with the user's credentials:
36
+
37
+ { "username": "user@example.com", "password": "their-password" }
38
+
39
+ On success the response is `200` with an access token:
40
+
41
+ { "access_token": "eyJ...", "token_type": "Bearer", "expires_in": 31536000 }
42
+
43
+ **Two-factor authentication.** If the user has a verified 2FA method,
44
+ the password alone is not enough. After verifying the password this
45
+ endpoint instead returns `202 Accepted` with a challenge that must be
46
+ satisfied via `POST /api/v1/tokens/two-factor`:
47
+
48
+ {
49
+ "two_factor_required": true,
50
+ "challenge_token": "eyJ...",
51
+ "mechanism": "Totp",
52
+ "masked_destination": "",
53
+ "expires_in": 600,
54
+ "available_mechanisms": ["Totp", "Email"],
55
+ "recovery_codes_available": true
56
+ }
57
+
58
+ `mechanism` is the method this challenge targets. When it is `Email`,
59
+ a one-time code has already been emailed to the user (see
60
+ `masked_destination`); when it is `Totp`, the user reads the current
61
+ code from their authenticator app and nothing is sent.
62
+ `available_mechanisms` lists every method the user has enrolled so a
63
+ client can offer a switch via `POST /api/v1/tokens/two-factor/switch-mechanism`.
64
+
65
+ If the tenant forces 2FA but the user has not enrolled yet, the `202`
66
+ body instead contains `"two_factor_enrollment_required": true` with a
67
+ `challenge_token` to drive the mid-login enrollment endpoints.
68
+
69
+ Invalid credentials return `400` with a body of `invalid_grant`.
70
+ * @summary Log a user in and obtain a JWT access token.
71
+ */
72
+ export const authGetToken = (
73
+ params: AuthGetTokenParams,
74
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
75
+ ) => {
76
+
77
+
78
+ return customFetch<TokenPayload | TwoFactorChallengePayload>(
79
+ {url: `/api/v1/tokens`, method: 'POST',
80
+ params, signal
81
+ },
82
+ options);
83
+ }
84
+
85
+
86
+
87
+ export const getAuthGetTokenMutationOptions = <TError = string,
88
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authGetToken>>, TError,{params: AuthGetTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
89
+ ): UseMutationOptions<Awaited<ReturnType<typeof authGetToken>>, TError,{params: AuthGetTokenParams}, TContext> => {
90
+
91
+ const mutationKey = ['authGetToken'];
92
+ const {mutation: mutationOptions, request: requestOptions} = options ?
93
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
94
+ options
95
+ : {...options, mutation: {...options.mutation, mutationKey}}
96
+ : {mutation: { mutationKey, }, request: undefined};
97
+
98
+
99
+
100
+
101
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof authGetToken>>, {params: AuthGetTokenParams}> = (props) => {
102
+ const {params} = props ?? {};
103
+
104
+ return authGetToken(params,requestOptions)
105
+ }
106
+
107
+
108
+
109
+
110
+ return { mutationFn, ...mutationOptions }}
111
+
112
+ export type AuthGetTokenMutationResult = NonNullable<Awaited<ReturnType<typeof authGetToken>>>
113
+
114
+ export type AuthGetTokenMutationError = string
115
+
116
+ /**
117
+ * @summary Log a user in and obtain a JWT access token.
118
+ */
119
+ export const useAuthGetToken = <TError = string,
120
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authGetToken>>, TError,{params: AuthGetTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
121
+ ): UseMutationResult<
122
+ Awaited<ReturnType<typeof authGetToken>>,
123
+ TError,
124
+ {params: AuthGetTokenParams},
125
+ TContext
126
+ > => {
127
+
128
+ const mutationOptions = getAuthGetTokenMutationOptions(options);
129
+
130
+ return useMutation(mutationOptions);
131
+ }
132
+ /**
133
+ * Call this after `POST /api/v1/tokens` returns `two_factor_required`.
134
+ Post the challenge token from that response together with the user's
135
+ one-time code (the emailed code, or the current code from their
136
+ authenticator app):
137
+
138
+ { "challenge_token": "eyJ...", "code": "123456" }
139
+
140
+ On success the response is `200` with the final access token, in the
141
+ same shape as `POST /api/v1/tokens`:
142
+
143
+ { "access_token": "eyJ...", "token_type": "Bearer", "expires_in": 31536000 }
144
+
145
+ An incorrect code returns `400` (`invalid_grant`). A code has at most
146
+ five attempts before the challenge locks. An expired challenge returns
147
+ `410` (`challenge_expired`) — restart at `POST /api/v1/tokens`. The
148
+ endpoint is rate limited to 10 requests per minute (`429`).
149
+ * @summary Complete a two-factor login challenge and obtain a JWT access token.
150
+ */
151
+ export const authVerifyTwoFactorToken = (
152
+ params: AuthVerifyTwoFactorTokenParams,
153
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
154
+ ) => {
155
+
156
+
157
+ return customFetch<TokenPayload>(
158
+ {url: `/api/v1/tokens/two-factor`, method: 'POST',
159
+ params, signal
160
+ },
161
+ options);
162
+ }
163
+
164
+
165
+
166
+ export const getAuthVerifyTwoFactorTokenMutationOptions = <TError = string,
167
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, TError,{params: AuthVerifyTwoFactorTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
168
+ ): UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, TError,{params: AuthVerifyTwoFactorTokenParams}, TContext> => {
169
+
170
+ const mutationKey = ['authVerifyTwoFactorToken'];
171
+ const {mutation: mutationOptions, request: requestOptions} = options ?
172
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
173
+ options
174
+ : {...options, mutation: {...options.mutation, mutationKey}}
175
+ : {mutation: { mutationKey, }, request: undefined};
176
+
177
+
178
+
179
+
180
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, {params: AuthVerifyTwoFactorTokenParams}> = (props) => {
181
+ const {params} = props ?? {};
182
+
183
+ return authVerifyTwoFactorToken(params,requestOptions)
184
+ }
185
+
186
+
187
+
188
+
189
+ return { mutationFn, ...mutationOptions }}
190
+
191
+ export type AuthVerifyTwoFactorTokenMutationResult = NonNullable<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>>
192
+
193
+ export type AuthVerifyTwoFactorTokenMutationError = string
194
+
195
+ /**
196
+ * @summary Complete a two-factor login challenge and obtain a JWT access token.
197
+ */
198
+ export const useAuthVerifyTwoFactorToken = <TError = string,
199
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorToken>>, TError,{params: AuthVerifyTwoFactorTokenParams}, TContext>, request?: SecondParameter<typeof customFetch>}
200
+ ): UseMutationResult<
201
+ Awaited<ReturnType<typeof authVerifyTwoFactorToken>>,
202
+ TError,
203
+ {params: AuthVerifyTwoFactorTokenParams},
204
+ TContext
205
+ > => {
206
+
207
+ const mutationOptions = getAuthVerifyTwoFactorTokenMutationOptions(options);
208
+
209
+ return useMutation(mutationOptions);
210
+ }
211
+ /**
212
+ * Post the challenge token from the original `POST /api/v1/tokens` response:
213
+
214
+ { "challenge_token": "eyJ..." }
215
+
216
+ A fresh code is emailed and a new challenge is returned (superseding
217
+ the previous one), in the same shape as the `202` from
218
+ `POST /api/v1/tokens` minus `two_factor_required`. Only `Email`
219
+ challenges can be resent — there is nothing to resend for `Totp`
220
+ (the authenticator app generates codes locally), so a `Totp`
221
+ challenge returns `400` with a body of `not_supported`. Rate limited
222
+ to 3 requests per minute (`429`).
223
+ * @summary Re-send the one-time code for an in-progress email two-factor challenge.
224
+ */
225
+ export const authResendTwoFactor = (
226
+ params: AuthResendTwoFactorParams,
227
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
228
+ ) => {
229
+
230
+
231
+ return customFetch<TwoFactorChallengePayload>(
232
+ {url: `/api/v1/tokens/two-factor/resend`, method: 'POST',
233
+ params, signal
234
+ },
235
+ options);
236
+ }
237
+
238
+
239
+
240
+ export const getAuthResendTwoFactorMutationOptions = <TError = string,
241
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authResendTwoFactor>>, TError,{params: AuthResendTwoFactorParams}, TContext>, request?: SecondParameter<typeof customFetch>}
242
+ ): UseMutationOptions<Awaited<ReturnType<typeof authResendTwoFactor>>, TError,{params: AuthResendTwoFactorParams}, TContext> => {
243
+
244
+ const mutationKey = ['authResendTwoFactor'];
245
+ const {mutation: mutationOptions, request: requestOptions} = options ?
246
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
247
+ options
248
+ : {...options, mutation: {...options.mutation, mutationKey}}
249
+ : {mutation: { mutationKey, }, request: undefined};
250
+
251
+
252
+
253
+
254
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof authResendTwoFactor>>, {params: AuthResendTwoFactorParams}> = (props) => {
255
+ const {params} = props ?? {};
256
+
257
+ return authResendTwoFactor(params,requestOptions)
258
+ }
259
+
260
+
261
+
262
+
263
+ return { mutationFn, ...mutationOptions }}
264
+
265
+ export type AuthResendTwoFactorMutationResult = NonNullable<Awaited<ReturnType<typeof authResendTwoFactor>>>
266
+
267
+ export type AuthResendTwoFactorMutationError = string
268
+
269
+ /**
270
+ * @summary Re-send the one-time code for an in-progress email two-factor challenge.
271
+ */
272
+ export const useAuthResendTwoFactor = <TError = string,
273
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authResendTwoFactor>>, TError,{params: AuthResendTwoFactorParams}, TContext>, request?: SecondParameter<typeof customFetch>}
274
+ ): UseMutationResult<
275
+ Awaited<ReturnType<typeof authResendTwoFactor>>,
276
+ TError,
277
+ {params: AuthResendTwoFactorParams},
278
+ TContext
279
+ > => {
280
+
281
+ const mutationOptions = getAuthResendTwoFactorMutationOptions(options);
282
+
283
+ return useMutation(mutationOptions);
284
+ }
285
+ /**
286
+ * When a user has more than one method enrolled (see
287
+ `available_mechanisms` on the login response) they can switch the
288
+ active challenge — for example from `Totp` to `Email` when they have
289
+ lost access to their authenticator. Post the current challenge token
290
+ and the desired mechanism:
291
+
292
+ { "challenge_token": "eyJ...", "mechanism": "Email" }
293
+
294
+ A fresh challenge for that mechanism is returned (and, for `Email`, a
295
+ code is sent), in the same shape as the `202` from `POST /api/v1/tokens`
296
+ minus `two_factor_required`. An unrecognized mechanism returns `400`
297
+ (`invalid_mechanism`); a mechanism the user has not enrolled returns
298
+ `400` (`not_enrolled`). Rate limited to 5 requests per minute (`429`).
299
+ * @summary Switch an in-progress login challenge to a different enrolled mechanism.
300
+ */
301
+ export const authSwitchTwoFactorMechanism = (
302
+ params: AuthSwitchTwoFactorMechanismParams,
303
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
304
+ ) => {
305
+
306
+
307
+ return customFetch<TwoFactorChallengePayload>(
308
+ {url: `/api/v1/tokens/two-factor/switch-mechanism`, method: 'POST',
309
+ params, signal
310
+ },
311
+ options);
312
+ }
313
+
314
+
315
+
316
+ export const getAuthSwitchTwoFactorMechanismMutationOptions = <TError = string,
317
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, TError,{params: AuthSwitchTwoFactorMechanismParams}, TContext>, request?: SecondParameter<typeof customFetch>}
318
+ ): UseMutationOptions<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, TError,{params: AuthSwitchTwoFactorMechanismParams}, TContext> => {
319
+
320
+ const mutationKey = ['authSwitchTwoFactorMechanism'];
321
+ const {mutation: mutationOptions, request: requestOptions} = options ?
322
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
323
+ options
324
+ : {...options, mutation: {...options.mutation, mutationKey}}
325
+ : {mutation: { mutationKey, }, request: undefined};
326
+
327
+
328
+
329
+
330
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, {params: AuthSwitchTwoFactorMechanismParams}> = (props) => {
331
+ const {params} = props ?? {};
332
+
333
+ return authSwitchTwoFactorMechanism(params,requestOptions)
334
+ }
335
+
336
+
337
+
338
+
339
+ return { mutationFn, ...mutationOptions }}
340
+
341
+ export type AuthSwitchTwoFactorMechanismMutationResult = NonNullable<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>>
342
+
343
+ export type AuthSwitchTwoFactorMechanismMutationError = string
344
+
345
+ /**
346
+ * @summary Switch an in-progress login challenge to a different enrolled mechanism.
347
+ */
348
+ export const useAuthSwitchTwoFactorMechanism = <TError = string,
349
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>, TError,{params: AuthSwitchTwoFactorMechanismParams}, TContext>, request?: SecondParameter<typeof customFetch>}
350
+ ): UseMutationResult<
351
+ Awaited<ReturnType<typeof authSwitchTwoFactorMechanism>>,
352
+ TError,
353
+ {params: AuthSwitchTwoFactorMechanismParams},
354
+ TContext
355
+ > => {
356
+
357
+ const mutationOptions = getAuthSwitchTwoFactorMechanismMutationOptions(options);
358
+
359
+ return useMutation(mutationOptions);
360
+ }
361
+ /**
362
+ * A fallback for users who cannot produce their primary code but still
363
+ have a recovery code on file (see `recovery_codes_available` on the
364
+ login response). Post the challenge token together with one recovery
365
+ code:
366
+
367
+ { "challenge_token": "eyJ...", "recovery_code": "abcd-efgh-ijkl" }
368
+
369
+ On success the response is `200` with the final access token, in the
370
+ same shape as `POST /api/v1/tokens`. Each recovery code is single-use.
371
+ An incorrect code returns `400` (`invalid_grant`); an expired
372
+ challenge returns `410` (`challenge_expired`). Rate limited to 10
373
+ requests per minute (`429`).
374
+
375
+ Used by the embed login widget; the hosted Razor flow has its own
376
+ equivalent action on the AuthenticationController.
377
+ * @summary Complete a two-factor login challenge with a recovery code instead of
378
+ the primary one-time code, and obtain a JWT access token.
379
+ */
380
+ export const authVerifyTwoFactorRecovery = (
381
+ params: AuthVerifyTwoFactorRecoveryParams,
382
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
383
+ ) => {
384
+
385
+
386
+ return customFetch<TokenPayload>(
387
+ {url: `/api/v1/tokens/two-factor/recovery`, method: 'POST',
388
+ params, signal
389
+ },
390
+ options);
391
+ }
392
+
393
+
394
+
395
+ export const getAuthVerifyTwoFactorRecoveryMutationOptions = <TError = string,
396
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, TError,{params: AuthVerifyTwoFactorRecoveryParams}, TContext>, request?: SecondParameter<typeof customFetch>}
397
+ ): UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, TError,{params: AuthVerifyTwoFactorRecoveryParams}, TContext> => {
398
+
399
+ const mutationKey = ['authVerifyTwoFactorRecovery'];
400
+ const {mutation: mutationOptions, request: requestOptions} = options ?
401
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
402
+ options
403
+ : {...options, mutation: {...options.mutation, mutationKey}}
404
+ : {mutation: { mutationKey, }, request: undefined};
405
+
406
+
407
+
408
+
409
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, {params: AuthVerifyTwoFactorRecoveryParams}> = (props) => {
410
+ const {params} = props ?? {};
411
+
412
+ return authVerifyTwoFactorRecovery(params,requestOptions)
413
+ }
414
+
415
+
416
+
417
+
418
+ return { mutationFn, ...mutationOptions }}
419
+
420
+ export type AuthVerifyTwoFactorRecoveryMutationResult = NonNullable<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>>
421
+
422
+ export type AuthVerifyTwoFactorRecoveryMutationError = string
423
+
424
+ /**
425
+ * @summary Complete a two-factor login challenge with a recovery code instead of
426
+ the primary one-time code, and obtain a JWT access token.
427
+ */
428
+ export const useAuthVerifyTwoFactorRecovery = <TError = string,
429
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>, TError,{params: AuthVerifyTwoFactorRecoveryParams}, TContext>, request?: SecondParameter<typeof customFetch>}
430
+ ): UseMutationResult<
431
+ Awaited<ReturnType<typeof authVerifyTwoFactorRecovery>>,
432
+ TError,
433
+ {params: AuthVerifyTwoFactorRecoveryParams},
434
+ TContext
435
+ > => {
436
+
437
+ const mutationOptions = getAuthVerifyTwoFactorRecoveryMutationOptions(options);
438
+
439
+ return useMutation(mutationOptions);
440
+ }
441
+ /**
442
+ * Call this when `POST /api/v1/tokens` returned
443
+ `two_factor_enrollment_required` and the user chooses email. Post the
444
+ enrollment token from that response:
445
+
446
+ { "enrollment_token": "eyJ..." }
447
+
448
+ A verification code is emailed to the user and a challenge is returned:
449
+
450
+ {
451
+ "challenge_token": "eyJ...",
452
+ "mechanism": "Email",
453
+ "masked_destination": "b***@outseta.com",
454
+ "expires_in": 600
455
+ }
456
+
457
+ Confirm the code via `POST /api/v1/tokens/two-factor/enroll/email/confirm`.
458
+ Returns `401` if the enrollment token is invalid/expired and `403` if
459
+ forced enrollment does not apply to this user. Rate limited to 5
460
+ requests per minute (`429`).
461
+ * @summary Begin email enrollment during a forced-2FA login.
462
+ */
463
+ export const tokenTwoFactorEnrollmentBeginEmail = (
464
+ params: TokenTwoFactorEnrollmentBeginEmailParams,
465
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
466
+ ) => {
467
+
468
+
469
+ return customFetch<TwoFactorChallengePayload>(
470
+ {url: `/api/v1/tokens/two-factor/enroll/email/begin`, method: 'POST',
471
+ params, signal
472
+ },
473
+ options);
474
+ }
475
+
476
+
477
+
478
+ export const getTokenTwoFactorEnrollmentBeginEmailMutationOptions = <TError = string,
479
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, TError,{params: TokenTwoFactorEnrollmentBeginEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
480
+ ): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, TError,{params: TokenTwoFactorEnrollmentBeginEmailParams}, TContext> => {
481
+
482
+ const mutationKey = ['tokenTwoFactorEnrollmentBeginEmail'];
483
+ const {mutation: mutationOptions, request: requestOptions} = options ?
484
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
485
+ options
486
+ : {...options, mutation: {...options.mutation, mutationKey}}
487
+ : {mutation: { mutationKey, }, request: undefined};
488
+
489
+
490
+
491
+
492
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, {params: TokenTwoFactorEnrollmentBeginEmailParams}> = (props) => {
493
+ const {params} = props ?? {};
494
+
495
+ return tokenTwoFactorEnrollmentBeginEmail(params,requestOptions)
496
+ }
497
+
498
+
499
+
500
+
501
+ return { mutationFn, ...mutationOptions }}
502
+
503
+ export type TokenTwoFactorEnrollmentBeginEmailMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>>
504
+
505
+ export type TokenTwoFactorEnrollmentBeginEmailMutationError = string
506
+
507
+ /**
508
+ * @summary Begin email enrollment during a forced-2FA login.
509
+ */
510
+ export const useTokenTwoFactorEnrollmentBeginEmail = <TError = string,
511
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>, TError,{params: TokenTwoFactorEnrollmentBeginEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
512
+ ): UseMutationResult<
513
+ Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginEmail>>,
514
+ TError,
515
+ {params: TokenTwoFactorEnrollmentBeginEmailParams},
516
+ TContext
517
+ > => {
518
+
519
+ const mutationOptions = getTokenTwoFactorEnrollmentBeginEmailMutationOptions(options);
520
+
521
+ return useMutation(mutationOptions);
522
+ }
523
+ export const tokenTwoFactorEnrollmentBeginTotp = (
524
+ params: TokenTwoFactorEnrollmentBeginTotpParams,
525
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
526
+ ) => {
527
+
528
+
529
+ return customFetch<TwoFactorTotpEnrollmentPayload>(
530
+ {url: `/api/v1/tokens/two-factor/enroll/totp/begin`, method: 'POST',
531
+ params, signal
532
+ },
533
+ options);
534
+ }
535
+
536
+
537
+
538
+ export const getTokenTwoFactorEnrollmentBeginTotpMutationOptions = <TError = string,
539
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, TError,{params: TokenTwoFactorEnrollmentBeginTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
540
+ ): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, TError,{params: TokenTwoFactorEnrollmentBeginTotpParams}, TContext> => {
541
+
542
+ const mutationKey = ['tokenTwoFactorEnrollmentBeginTotp'];
543
+ const {mutation: mutationOptions, request: requestOptions} = options ?
544
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
545
+ options
546
+ : {...options, mutation: {...options.mutation, mutationKey}}
547
+ : {mutation: { mutationKey, }, request: undefined};
548
+
549
+
550
+
551
+
552
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, {params: TokenTwoFactorEnrollmentBeginTotpParams}> = (props) => {
553
+ const {params} = props ?? {};
554
+
555
+ return tokenTwoFactorEnrollmentBeginTotp(params,requestOptions)
556
+ }
557
+
558
+
559
+
560
+
561
+ return { mutationFn, ...mutationOptions }}
562
+
563
+ export type TokenTwoFactorEnrollmentBeginTotpMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>>
564
+
565
+ export type TokenTwoFactorEnrollmentBeginTotpMutationError = string
566
+
567
+ export const useTokenTwoFactorEnrollmentBeginTotp = <TError = string,
568
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>, TError,{params: TokenTwoFactorEnrollmentBeginTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
569
+ ): UseMutationResult<
570
+ Awaited<ReturnType<typeof tokenTwoFactorEnrollmentBeginTotp>>,
571
+ TError,
572
+ {params: TokenTwoFactorEnrollmentBeginTotpParams},
573
+ TContext
574
+ > => {
575
+
576
+ const mutationOptions = getTokenTwoFactorEnrollmentBeginTotpMutationOptions(options);
577
+
578
+ return useMutation(mutationOptions);
579
+ }
580
+ /**
581
+ * Post the enrollment token (from `POST /api/v1/tokens`), the challenge
582
+ token (from `.../enroll/email/begin`), and the emailed code:
583
+
584
+ { "enrollment_token": "eyJ...", "challenge_token": "eyJ...", "code": "123456" }
585
+
586
+ On success email 2FA is enabled and login completes — the response
587
+ carries the final access token plus the user's one-time recovery codes:
588
+
589
+ {
590
+ "confirmed": true,
591
+ "recovery_codes": ["abcd-efgh-ijkl", "..."],
592
+ "access_token": "eyJ...",
593
+ "token_type": "Bearer",
594
+ "expires_in": 31536000
595
+ }
596
+
597
+ Show the `recovery_codes` to the user once — they are not returned
598
+ again. An incorrect code returns `400` (`invalid_grant`); an expired
599
+ challenge returns `410` (`challenge_expired`). Rate limited to 10
600
+ requests per minute (`429`).
601
+ * @summary Confirm email enrollment and complete a forced-2FA login.
602
+ */
603
+ export const tokenTwoFactorEnrollmentConfirmEmail = (
604
+ params: TokenTwoFactorEnrollmentConfirmEmailParams,
605
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
606
+ ) => {
607
+
608
+
609
+ return customFetch<TwoFactorEnrollmentConfirmationPayload>(
610
+ {url: `/api/v1/tokens/two-factor/enroll/email/confirm`, method: 'POST',
611
+ params, signal
612
+ },
613
+ options);
614
+ }
615
+
616
+
617
+
618
+ export const getTokenTwoFactorEnrollmentConfirmEmailMutationOptions = <TError = string,
619
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, TError,{params: TokenTwoFactorEnrollmentConfirmEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
620
+ ): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, TError,{params: TokenTwoFactorEnrollmentConfirmEmailParams}, TContext> => {
621
+
622
+ const mutationKey = ['tokenTwoFactorEnrollmentConfirmEmail'];
623
+ const {mutation: mutationOptions, request: requestOptions} = options ?
624
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
625
+ options
626
+ : {...options, mutation: {...options.mutation, mutationKey}}
627
+ : {mutation: { mutationKey, }, request: undefined};
628
+
629
+
630
+
631
+
632
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, {params: TokenTwoFactorEnrollmentConfirmEmailParams}> = (props) => {
633
+ const {params} = props ?? {};
634
+
635
+ return tokenTwoFactorEnrollmentConfirmEmail(params,requestOptions)
636
+ }
637
+
638
+
639
+
640
+
641
+ return { mutationFn, ...mutationOptions }}
642
+
643
+ export type TokenTwoFactorEnrollmentConfirmEmailMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>>
644
+
645
+ export type TokenTwoFactorEnrollmentConfirmEmailMutationError = string
646
+
647
+ /**
648
+ * @summary Confirm email enrollment and complete a forced-2FA login.
649
+ */
650
+ export const useTokenTwoFactorEnrollmentConfirmEmail = <TError = string,
651
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>, TError,{params: TokenTwoFactorEnrollmentConfirmEmailParams}, TContext>, request?: SecondParameter<typeof customFetch>}
652
+ ): UseMutationResult<
653
+ Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmEmail>>,
654
+ TError,
655
+ {params: TokenTwoFactorEnrollmentConfirmEmailParams},
656
+ TContext
657
+ > => {
658
+
659
+ const mutationOptions = getTokenTwoFactorEnrollmentConfirmEmailMutationOptions(options);
660
+
661
+ return useMutation(mutationOptions);
662
+ }
663
+ /**
664
+ * Post the enrollment token (from `POST /api/v1/tokens`), the challenge
665
+ token (from `.../enroll/totp/begin`), and the current code from the
666
+ user's authenticator app:
667
+
668
+ { "enrollment_token": "eyJ...", "challenge_token": "eyJ...", "code": "123456" }
669
+
670
+ On success authenticator-app 2FA is enabled and login completes — the
671
+ response carries the final access token plus the user's one-time
672
+ recovery codes:
673
+
674
+ {
675
+ "confirmed": true,
676
+ "recovery_codes": ["abcd-efgh-ijkl", "..."],
677
+ "access_token": "eyJ...",
678
+ "token_type": "Bearer",
679
+ "expires_in": 31536000
680
+ }
681
+
682
+ Show the `recovery_codes` to the user once — they are not returned
683
+ again. An incorrect code returns `400` (`invalid_grant`); an expired
684
+ challenge returns `410` (`challenge_expired`). Rate limited to 10
685
+ requests per minute (`429`).
686
+ * @summary Confirm authenticator-app (TOTP) enrollment and complete a forced-2FA login.
687
+ */
688
+ export const tokenTwoFactorEnrollmentConfirmTotp = (
689
+ params: TokenTwoFactorEnrollmentConfirmTotpParams,
690
+ options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
691
+ ) => {
692
+
693
+
694
+ return customFetch<TwoFactorEnrollmentConfirmationPayload>(
695
+ {url: `/api/v1/tokens/two-factor/enroll/totp/confirm`, method: 'POST',
696
+ params, signal
697
+ },
698
+ options);
699
+ }
700
+
701
+
702
+
703
+ export const getTokenTwoFactorEnrollmentConfirmTotpMutationOptions = <TError = string,
704
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, TError,{params: TokenTwoFactorEnrollmentConfirmTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
705
+ ): UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, TError,{params: TokenTwoFactorEnrollmentConfirmTotpParams}, TContext> => {
706
+
707
+ const mutationKey = ['tokenTwoFactorEnrollmentConfirmTotp'];
708
+ const {mutation: mutationOptions, request: requestOptions} = options ?
709
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
710
+ options
711
+ : {...options, mutation: {...options.mutation, mutationKey}}
712
+ : {mutation: { mutationKey, }, request: undefined};
713
+
714
+
715
+
716
+
717
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, {params: TokenTwoFactorEnrollmentConfirmTotpParams}> = (props) => {
718
+ const {params} = props ?? {};
719
+
720
+ return tokenTwoFactorEnrollmentConfirmTotp(params,requestOptions)
721
+ }
722
+
723
+
724
+
725
+
726
+ return { mutationFn, ...mutationOptions }}
727
+
728
+ export type TokenTwoFactorEnrollmentConfirmTotpMutationResult = NonNullable<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>>
729
+
730
+ export type TokenTwoFactorEnrollmentConfirmTotpMutationError = string
731
+
732
+ /**
733
+ * @summary Confirm authenticator-app (TOTP) enrollment and complete a forced-2FA login.
734
+ */
735
+ export const useTokenTwoFactorEnrollmentConfirmTotp = <TError = string,
736
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>, TError,{params: TokenTwoFactorEnrollmentConfirmTotpParams}, TContext>, request?: SecondParameter<typeof customFetch>}
737
+ ): UseMutationResult<
738
+ Awaited<ReturnType<typeof tokenTwoFactorEnrollmentConfirmTotp>>,
739
+ TError,
740
+ {params: TokenTwoFactorEnrollmentConfirmTotpParams},
741
+ TContext
742
+ > => {
743
+
744
+ const mutationOptions = getTokenTwoFactorEnrollmentConfirmTotpMutationOptions(options);
745
+
746
+ return useMutation(mutationOptions);
747
+ }
748
+