@omni2fa/core 0.7.1 → 0.7.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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import O from "openapi-fetch";
2
- import { setup as h, fromPromise as l, createActor as u } from "xstate";
3
- class N {
1
+ import J from "openapi-fetch";
2
+ import { setup as h, fromPromise as i, createActor as u } from "xstate";
3
+ class _ {
4
4
  map = /* @__PURE__ */ new Map();
5
5
  get(e) {
6
6
  return this.map.get(e) ?? null;
@@ -12,7 +12,7 @@ class N {
12
12
  this.map.delete(e);
13
13
  }
14
14
  }
15
- const s = {
15
+ const a = {
16
16
  InvalidCode: "INVALID_CODE",
17
17
  PreAuthExpired: "PREAUTH_EXPIRED",
18
18
  PreAuthInvalid: "PREAUTH_INVALID",
@@ -27,38 +27,40 @@ const s = {
27
27
  RecoveryCodeUsed: "RECOVERY_CODE_USED",
28
28
  WebAuthnVerificationFailed: "WEBAUTHN_VERIFICATION_FAILED",
29
29
  ValidationFailed: "VALIDATION_FAILED",
30
+ StepUpRequired: "STEP_UP_REQUIRED",
30
31
  NetworkError: "NETWORK_ERROR",
31
32
  Unknown: "UNKNOWN"
32
- }, v = {
33
- [s.InvalidCode]: "The code you entered is invalid.",
34
- [s.PreAuthExpired]: "Your session has expired. Please sign in again.",
35
- [s.PreAuthInvalid]: "Your session is invalid. Please sign in again.",
36
- [s.ChallengeNotFound]: "No active verification step. Please restart.",
37
- [s.ChallengeConsumed]: "This verification step was already used. Please sign in again.",
38
- [s.TooManyAttempts]: "Too many attempts. Please wait before trying again.",
39
- [s.MethodNotFound]: "The selected 2FA method was not found.",
40
- [s.TypeAlreadyEnrolled]: "You already have this type of 2FA enabled.",
41
- [s.MaxMethodsReached]: "You have reached the maximum number of 2FA methods.",
42
- [s.LastMethodProtected]: "You cannot remove your last 2FA method.",
43
- [s.RecoveryCodeInvalid]: "The recovery code is invalid.",
44
- [s.RecoveryCodeUsed]: "This recovery code has already been used.",
45
- [s.WebAuthnVerificationFailed]: "Security key verification failed.",
46
- [s.ValidationFailed]: "The request was malformed.",
47
- [s.NetworkError]: "Network error. Please check your connection.",
48
- [s.Unknown]: "An unexpected error occurred."
33
+ }, S = {
34
+ [a.InvalidCode]: "The code you entered is invalid.",
35
+ [a.PreAuthExpired]: "Your session has expired. Please sign in again.",
36
+ [a.PreAuthInvalid]: "Your session is invalid. Please sign in again.",
37
+ [a.ChallengeNotFound]: "No active verification step. Please restart.",
38
+ [a.ChallengeConsumed]: "This verification step was already used. Please sign in again.",
39
+ [a.TooManyAttempts]: "Too many attempts. Please wait before trying again.",
40
+ [a.MethodNotFound]: "The selected 2FA method was not found.",
41
+ [a.TypeAlreadyEnrolled]: "You already have this type of 2FA enabled.",
42
+ [a.MaxMethodsReached]: "You have reached the maximum number of 2FA methods.",
43
+ [a.LastMethodProtected]: "You cannot remove your last 2FA method.",
44
+ [a.RecoveryCodeInvalid]: "The recovery code is invalid.",
45
+ [a.RecoveryCodeUsed]: "This recovery code has already been used.",
46
+ [a.WebAuthnVerificationFailed]: "Security key verification failed.",
47
+ [a.ValidationFailed]: "The request was malformed.",
48
+ [a.StepUpRequired]: "Please confirm two-factor authentication to continue.",
49
+ [a.NetworkError]: "Network error. Please check your connection.",
50
+ [a.Unknown]: "An unexpected error occurred."
49
51
  };
50
- function w(t) {
51
- return v[t] ?? v[s.Unknown];
52
+ function T(t) {
53
+ return S[t] ?? S[a.Unknown];
52
54
  }
53
- const R = "omni2fa:preauth", D = "omni2fa:session", I = "http://omni2fa.local";
54
- class P {
55
+ const F = "omni2fa:preauth", L = "omni2fa:session", b = "http://omni2fa.local";
56
+ class K {
55
57
  storage;
56
58
  preAuthKey;
57
59
  sessionKey;
58
60
  basePath;
59
61
  inner;
60
62
  constructor(e) {
61
- this.storage = e.storage ?? new N(), this.preAuthKey = e.preAuthStorageKey ?? R, this.sessionKey = e.sessionStorageKey ?? D, this.basePath = new URL(e.baseUrl, I).pathname.replace(/\/$/, ""), this.inner = O({
63
+ this.storage = e.storage ?? new _(), this.preAuthKey = e.preAuthStorageKey ?? F, this.sessionKey = e.sessionStorageKey ?? L, this.basePath = new URL(e.baseUrl, b).pathname.replace(/\/$/, ""), this.inner = J({
62
64
  baseUrl: e.baseUrl,
63
65
  fetch: e.fetch ?? globalThis.fetch.bind(globalThis),
64
66
  ...e.credentials ? { credentials: e.credentials } : {}
@@ -73,7 +75,7 @@ class P {
73
75
  }
74
76
  /** Pre-auth endpoints are exactly the ones mounted under <c>{basePath}/challenge/</c>. */
75
77
  isPreAuthEndpoint(e) {
76
- const r = new URL(e, I).pathname;
78
+ const r = new URL(e, b).pathname;
77
79
  return (r.startsWith(this.basePath) ? r.slice(this.basePath.length) : r).startsWith("/challenge/");
78
80
  }
79
81
  setPreAuthToken(e) {
@@ -143,6 +145,18 @@ class P {
143
145
  const { data: r, error: n, response: o } = await this.inner.POST("/challenge/recovery-code", { body: e });
144
146
  return this.toCall(r, n, o);
145
147
  }
148
+ async startStepUp(e) {
149
+ const { data: r, error: n, response: o } = await this.inner.POST("/stepup/start", { body: e });
150
+ return this.toCall(r, n, o);
151
+ }
152
+ async resendStepUp(e) {
153
+ const { data: r, error: n, response: o } = await this.inner.POST("/stepup/resend", { body: e });
154
+ return this.toCall(r, n, o);
155
+ }
156
+ async verifyStepUp(e) {
157
+ const { data: r, error: n, response: o } = await this.inner.POST("/stepup/verify", { body: e });
158
+ return this.toCall(r, n, o);
159
+ }
146
160
  async regenerateRecoveryCodes() {
147
161
  const { data: e, error: r, response: n } = await this.inner.POST("/recovery-codes/regenerate");
148
162
  return this.toCall(e, r, n);
@@ -150,23 +164,23 @@ class P {
150
164
  toCall(e, r, n) {
151
165
  return r !== void 0 ? this.errorCall(r, n) : e === void 0 ? {
152
166
  ok: !1,
153
- code: s.NetworkError,
154
- message: w(s.NetworkError),
167
+ code: a.NetworkError,
168
+ message: T(a.NetworkError),
155
169
  httpStatus: n.status
156
170
  } : { ok: !0, value: e };
157
171
  }
158
172
  errorCall(e, r) {
159
- const n = e.code || s.Unknown;
173
+ const n = e.code || a.Unknown;
160
174
  return {
161
175
  ok: !1,
162
176
  code: n,
163
- message: e.message || w(n),
177
+ message: e.message || T(n),
164
178
  httpStatus: r.status,
165
179
  details: e.details ?? null
166
180
  };
167
181
  }
168
182
  }
169
- class z {
183
+ class te {
170
184
  get(e) {
171
185
  return globalThis.sessionStorage?.getItem(e) ?? null;
172
186
  }
@@ -177,7 +191,7 @@ class z {
177
191
  globalThis.sessionStorage?.removeItem(e);
178
192
  }
179
193
  }
180
- class X {
194
+ class ne {
181
195
  get(e) {
182
196
  return globalThis.localStorage?.getItem(e) ?? null;
183
197
  }
@@ -188,7 +202,7 @@ class X {
188
202
  globalThis.localStorage?.removeItem(e);
189
203
  }
190
204
  }
191
- class a extends Error {
205
+ class s extends Error {
192
206
  code;
193
207
  httpStatus;
194
208
  details;
@@ -196,7 +210,7 @@ class a extends Error {
196
210
  super(r), this.name = "Omni2FaApiError", this.code = e, this.httpStatus = n, this.details = o;
197
211
  }
198
212
  }
199
- const U = {
213
+ const W = {
200
214
  enrollmentId: null,
201
215
  otpAuthUri: null,
202
216
  secret: null,
@@ -205,34 +219,34 @@ const U = {
205
219
  errorCode: null,
206
220
  errorMessage: null
207
221
  };
208
- function _(t) {
222
+ function $(t) {
209
223
  return h({
210
224
  types: {
211
225
  context: {},
212
226
  events: {}
213
227
  },
214
228
  actors: {
215
- startEnrollment: l(async () => {
229
+ startEnrollment: i(async () => {
216
230
  const e = await t.startTotpEnrollment();
217
231
  if (!e.ok)
218
- throw new a(e.code, e.message, e.httpStatus, e.details ?? null);
232
+ throw new s(e.code, e.message, e.httpStatus, e.details ?? null);
219
233
  return e.value;
220
234
  }),
221
- confirmEnrollment: l(async ({ input: e }) => {
235
+ confirmEnrollment: i(async ({ input: e }) => {
222
236
  const r = await t.confirmTotpEnrollment({
223
237
  enrollmentId: e.enrollmentId,
224
238
  code: e.code,
225
239
  name: e.name
226
240
  });
227
241
  if (!r.ok)
228
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
242
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
229
243
  return r.value;
230
244
  })
231
245
  }
232
246
  }).createMachine({
233
247
  id: "totpEnrollment",
234
248
  initial: "idle",
235
- context: U,
249
+ context: W,
236
250
  states: {
237
251
  idle: {
238
252
  on: {
@@ -250,14 +264,14 @@ function _(t) {
250
264
  },
251
265
  onError: {
252
266
  target: "failed",
253
- actions: ({ context: e, event: r }) => A(e, r.error)
267
+ actions: ({ context: e, event: r }) => k(e, r.error)
254
268
  }
255
269
  }
256
270
  },
257
271
  awaitingCode: {
258
272
  on: {
259
273
  submit: { target: "confirming" },
260
- reset: { target: "idle", actions: p }
274
+ reset: { target: "idle", actions: y }
261
275
  }
262
276
  },
263
277
  confirming: {
@@ -276,31 +290,31 @@ function _(t) {
276
290
  },
277
291
  onError: {
278
292
  target: "awaitingCode",
279
- actions: ({ context: e, event: r }) => A(e, r.error)
293
+ actions: ({ context: e, event: r }) => k(e, r.error)
280
294
  }
281
295
  }
282
296
  },
283
297
  enrolled: {
284
298
  on: {
285
- reset: { target: "idle", actions: p }
299
+ reset: { target: "idle", actions: y }
286
300
  }
287
301
  },
288
302
  failed: {
289
303
  on: {
290
304
  start: { target: "starting" },
291
- reset: { target: "idle", actions: p }
305
+ reset: { target: "idle", actions: y }
292
306
  }
293
307
  }
294
308
  }
295
309
  });
296
310
  }
297
- function p({ context: t }) {
311
+ function y({ context: t }) {
298
312
  t.enrollmentId = null, t.otpAuthUri = null, t.secret = null, t.methodId = null, t.recoveryCodes = null, t.errorCode = null, t.errorMessage = null;
299
313
  }
300
- function A(t, e) {
301
- e instanceof a ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
314
+ function k(t, e) {
315
+ e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
302
316
  }
303
- const J = {
317
+ const H = {
304
318
  enrollmentId: null,
305
319
  email: null,
306
320
  expiresAt: null,
@@ -310,40 +324,40 @@ const J = {
310
324
  errorCode: null,
311
325
  errorMessage: null
312
326
  };
313
- function F(t) {
327
+ function V(t) {
314
328
  return h({
315
329
  types: {
316
330
  context: {},
317
331
  events: {}
318
332
  },
319
333
  actors: {
320
- startEnrollment: l(async ({ input: e }) => {
334
+ startEnrollment: i(async ({ input: e }) => {
321
335
  const r = await t.startEmailEnrollment(e.email !== void 0 ? { email: e.email } : {});
322
336
  if (!r.ok)
323
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
337
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
324
338
  return r.value;
325
339
  }),
326
- resendEnrollment: l(async ({ input: e }) => {
340
+ resendEnrollment: i(async ({ input: e }) => {
327
341
  const r = await t.resendEmailEnrollment({ enrollmentId: e.enrollmentId });
328
342
  if (!r.ok)
329
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
343
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
330
344
  return r.value;
331
345
  }),
332
- confirmEnrollment: l(async ({ input: e }) => {
346
+ confirmEnrollment: i(async ({ input: e }) => {
333
347
  const r = await t.confirmEmailEnrollment({
334
348
  enrollmentId: e.enrollmentId,
335
349
  code: e.code,
336
350
  name: e.name
337
351
  });
338
352
  if (!r.ok)
339
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
353
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
340
354
  return r.value;
341
355
  })
342
356
  }
343
357
  }).createMachine({
344
358
  id: "emailEnrollment",
345
359
  initial: "idle",
346
- context: J,
360
+ context: H,
347
361
  states: {
348
362
  idle: {
349
363
  on: {
@@ -361,11 +375,11 @@ function F(t) {
361
375
  input: ({ context: e }) => ({ email: e.email ?? void 0 }),
362
376
  onDone: {
363
377
  target: "awaitingCode",
364
- actions: ({ context: e, event: r }) => T(e, r.output)
378
+ actions: ({ context: e, event: r }) => M(e, r.output)
365
379
  },
366
380
  onError: {
367
381
  target: "failed",
368
- actions: ({ context: e, event: r }) => y(e, r.error)
382
+ actions: ({ context: e, event: r }) => v(e, r.error)
369
383
  }
370
384
  }
371
385
  },
@@ -373,7 +387,7 @@ function F(t) {
373
387
  on: {
374
388
  submit: { target: "confirming" },
375
389
  resend: { target: "resending" },
376
- reset: { target: "idle", actions: f }
390
+ reset: { target: "idle", actions: w }
377
391
  }
378
392
  },
379
393
  resending: {
@@ -385,11 +399,11 @@ function F(t) {
385
399
  },
386
400
  onDone: {
387
401
  target: "awaitingCode",
388
- actions: ({ context: e, event: r }) => T(e, r.output)
402
+ actions: ({ context: e, event: r }) => M(e, r.output)
389
403
  },
390
404
  onError: {
391
405
  target: "awaitingCode",
392
- actions: ({ context: e, event: r }) => y(e, r.error)
406
+ actions: ({ context: e, event: r }) => v(e, r.error)
393
407
  }
394
408
  }
395
409
  },
@@ -409,37 +423,37 @@ function F(t) {
409
423
  },
410
424
  onError: {
411
425
  target: "awaitingCode",
412
- actions: ({ context: e, event: r }) => y(e, r.error)
426
+ actions: ({ context: e, event: r }) => v(e, r.error)
413
427
  }
414
428
  }
415
429
  },
416
430
  enrolled: {
417
431
  on: {
418
- reset: { target: "idle", actions: f }
432
+ reset: { target: "idle", actions: w }
419
433
  }
420
434
  },
421
435
  failed: {
422
436
  on: {
423
437
  start: { target: "starting" },
424
- reset: { target: "idle", actions: f }
438
+ reset: { target: "idle", actions: w }
425
439
  }
426
440
  }
427
441
  }
428
442
  });
429
443
  }
430
- function T(t, e) {
444
+ function M(t, e) {
431
445
  t.enrollmentId = e.enrollmentId, t.expiresAt = e.expiresAt, t.resendAvailableAt = e.resendAvailableAt, t.errorCode = null, t.errorMessage = null;
432
446
  }
433
- function f({ context: t }) {
447
+ function w({ context: t }) {
434
448
  t.enrollmentId = null, t.email = null, t.expiresAt = null, t.resendAvailableAt = null, t.methodId = null, t.recoveryCodes = null, t.errorCode = null, t.errorMessage = null;
435
449
  }
436
- function y(t, e) {
437
- e instanceof a ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
450
+ function v(t, e) {
451
+ e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
438
452
  }
439
- function g(t) {
453
+ function m(t) {
440
454
  const e = t.replace(/-/g, "+").replace(/_/g, "/"), r = e.padEnd(Math.ceil(e.length / 4) * 4, "="), n = atob(r), o = new Uint8Array(n.length);
441
- for (let i = 0; i < n.length; i++)
442
- o[i] = n.charCodeAt(i);
455
+ for (let l = 0; l < n.length; l++)
456
+ o[l] = n.charCodeAt(l);
443
457
  return o.buffer;
444
458
  }
445
459
  function d(t) {
@@ -449,15 +463,15 @@ function d(t) {
449
463
  r += String.fromCharCode(n);
450
464
  return btoa(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
451
465
  }
452
- function k(t) {
453
- return (t ?? []).map((e) => ({ ...e, id: g(e.id) }));
466
+ function D(t) {
467
+ return (t ?? []).map((e) => ({ ...e, id: m(e.id) }));
454
468
  }
455
- async function L(t) {
469
+ async function Y(t) {
456
470
  const e = JSON.parse(t), r = {
457
471
  ...e,
458
- challenge: g(e.challenge),
459
- user: { ...e.user, id: g(e.user.id) },
460
- excludeCredentials: k(e.excludeCredentials)
472
+ challenge: m(e.challenge),
473
+ user: { ...e.user, id: m(e.user.id) },
474
+ excludeCredentials: D(e.excludeCredentials)
461
475
  // Cast through unknown: the spread carries Fido2's index-signature fields the DOM type omits.
462
476
  }, n = await navigator.credentials.create({ publicKey: r });
463
477
  if (n === null)
@@ -474,11 +488,11 @@ async function L(t) {
474
488
  }
475
489
  });
476
490
  }
477
- async function K(t) {
491
+ async function P(t) {
478
492
  const e = JSON.parse(t), r = {
479
493
  ...e,
480
- challenge: g(e.challenge),
481
- allowCredentials: k(e.allowCredentials)
494
+ challenge: m(e.challenge),
495
+ allowCredentials: D(e.allowCredentials)
482
496
  }, n = await navigator.credentials.get({ publicKey: r });
483
497
  if (n === null)
484
498
  throw new Error("WebAuthn authentication produced no credential.");
@@ -496,7 +510,7 @@ async function K(t) {
496
510
  }
497
511
  });
498
512
  }
499
- const W = {
513
+ const q = {
500
514
  enrollmentId: null,
501
515
  optionsJson: null,
502
516
  name: null,
@@ -505,34 +519,34 @@ const W = {
505
519
  errorCode: null,
506
520
  errorMessage: null
507
521
  };
508
- function $(t) {
522
+ function B(t) {
509
523
  return h({
510
524
  types: {
511
525
  context: {},
512
526
  events: {}
513
527
  },
514
528
  actors: {
515
- startEnrollment: l(async () => {
529
+ startEnrollment: i(async () => {
516
530
  const e = await t.startWebAuthnEnrollment();
517
531
  if (!e.ok)
518
- throw new a(e.code, e.message, e.httpStatus, e.details ?? null);
532
+ throw new s(e.code, e.message, e.httpStatus, e.details ?? null);
519
533
  return e.value;
520
534
  }),
521
- registerAndConfirm: l(async ({ input: e }) => {
522
- const r = await L(e.optionsJson), n = await t.confirmWebAuthnEnrollment({
535
+ registerAndConfirm: i(async ({ input: e }) => {
536
+ const r = await Y(e.optionsJson), n = await t.confirmWebAuthnEnrollment({
523
537
  enrollmentId: e.enrollmentId,
524
538
  attestationResponseJson: r,
525
539
  name: e.name
526
540
  });
527
541
  if (!n.ok)
528
- throw new a(n.code, n.message, n.httpStatus, n.details ?? null);
542
+ throw new s(n.code, n.message, n.httpStatus, n.details ?? null);
529
543
  return n.value;
530
544
  })
531
545
  }
532
546
  }).createMachine({
533
547
  id: "webauthnEnrollment",
534
548
  initial: "idle",
535
- context: W,
549
+ context: q,
536
550
  states: {
537
551
  idle: {
538
552
  on: {
@@ -553,7 +567,7 @@ function $(t) {
553
567
  },
554
568
  onError: {
555
569
  target: "failed",
556
- actions: ({ context: e, event: r }) => M(e, r.error)
570
+ actions: ({ context: e, event: r }) => U(e, r.error)
557
571
  }
558
572
  }
559
573
  },
@@ -572,31 +586,31 @@ function $(t) {
572
586
  },
573
587
  onError: {
574
588
  target: "failed",
575
- actions: ({ context: e, event: r }) => M(e, r.error)
589
+ actions: ({ context: e, event: r }) => U(e, r.error)
576
590
  }
577
591
  }
578
592
  },
579
593
  enrolled: {
580
594
  on: {
581
- reset: { target: "idle", actions: b }
595
+ reset: { target: "idle", actions: O }
582
596
  }
583
597
  },
584
598
  failed: {
585
599
  on: {
586
600
  retry: { target: "starting" },
587
- reset: { target: "idle", actions: b }
601
+ reset: { target: "idle", actions: O }
588
602
  }
589
603
  }
590
604
  }
591
605
  });
592
606
  }
593
- function b({ context: t }) {
607
+ function O({ context: t }) {
594
608
  t.enrollmentId = null, t.optionsJson = null, t.name = null, t.methodId = null, t.recoveryCodes = null, t.errorCode = null, t.errorMessage = null;
595
609
  }
596
- function M(t, e) {
597
- e instanceof a ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
610
+ function U(t, e) {
611
+ e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
598
612
  }
599
- const H = {
613
+ const G = {
600
614
  methodId: null,
601
615
  methodType: null,
602
616
  userId: null,
@@ -607,48 +621,48 @@ const H = {
607
621
  errorCode: null,
608
622
  errorMessage: null
609
623
  };
610
- function Y(t) {
624
+ function X(t) {
611
625
  return h({
612
626
  types: {
613
627
  context: {},
614
628
  events: {}
615
629
  },
616
630
  actors: {
617
- startChallenge: l(async ({ input: e }) => {
631
+ startChallenge: i(async ({ input: e }) => {
618
632
  const r = await t.startChallenge({ methodId: e.methodId });
619
633
  if (!r.ok)
620
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
634
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
621
635
  return r.value;
622
636
  }),
623
- resendChallenge: l(async ({ input: e }) => {
637
+ resendChallenge: i(async ({ input: e }) => {
624
638
  const r = await t.resendChallenge({ methodId: e.methodId });
625
639
  if (!r.ok)
626
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
640
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
627
641
  return r.value;
628
642
  }),
629
- verifyChallenge: l(async ({ input: e }) => {
643
+ verifyChallenge: i(async ({ input: e }) => {
630
644
  const r = await t.verifyChallenge({ methodId: e.methodId, code: e.code });
631
645
  if (!r.ok)
632
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
646
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
633
647
  return r.value;
634
648
  }),
635
- assertChallenge: l(async ({ input: e }) => {
636
- const r = await K(e.optionsJson), n = await t.verifyChallenge({ methodId: e.methodId, assertionResponseJson: r });
649
+ assertChallenge: i(async ({ input: e }) => {
650
+ const r = await P(e.optionsJson), n = await t.verifyChallenge({ methodId: e.methodId, assertionResponseJson: r });
637
651
  if (!n.ok)
638
- throw new a(n.code, n.message, n.httpStatus, n.details ?? null);
652
+ throw new s(n.code, n.message, n.httpStatus, n.details ?? null);
639
653
  return n.value;
640
654
  }),
641
- verifyRecoveryCode: l(async ({ input: e }) => {
655
+ verifyRecoveryCode: i(async ({ input: e }) => {
642
656
  const r = await t.verifyRecoveryCode({ recoveryCode: e.code });
643
657
  if (!r.ok)
644
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
658
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
645
659
  return r.value;
646
660
  })
647
661
  }
648
662
  }).createMachine({
649
663
  id: "challenge",
650
664
  initial: "idle",
651
- context: H,
665
+ context: G,
652
666
  states: {
653
667
  idle: {
654
668
  on: {
@@ -670,11 +684,11 @@ function Y(t) {
670
684
  {
671
685
  guard: ({ event: e }) => e.output.type === "WebAuthn",
672
686
  target: "asserting",
673
- actions: ({ context: e, event: r }) => C(e, r.output)
687
+ actions: ({ context: e, event: r }) => E(e, r.output)
674
688
  },
675
689
  {
676
690
  target: "awaitingCode",
677
- actions: ({ context: e, event: r }) => C(e, r.output)
691
+ actions: ({ context: e, event: r }) => E(e, r.output)
678
692
  }
679
693
  ],
680
694
  onError: {
@@ -707,7 +721,7 @@ function Y(t) {
707
721
  submit: { target: "verifying" },
708
722
  resend: { target: "resending" },
709
723
  useRecoveryCode: { target: "verifyingRecovery" },
710
- reset: { target: "idle", actions: E }
724
+ reset: { target: "idle", actions: C }
711
725
  }
712
726
  },
713
727
  verifyingRecovery: {
@@ -738,7 +752,7 @@ function Y(t) {
738
752
  },
739
753
  onDone: {
740
754
  target: "awaitingCode",
741
- actions: ({ context: e, event: r }) => C(e, r.output)
755
+ actions: ({ context: e, event: r }) => E(e, r.output)
742
756
  },
743
757
  onError: {
744
758
  target: "awaitingCode",
@@ -768,57 +782,57 @@ function Y(t) {
768
782
  },
769
783
  verified: {
770
784
  on: {
771
- reset: { target: "idle", actions: E }
785
+ reset: { target: "idle", actions: C }
772
786
  }
773
787
  },
774
788
  failed: {
775
789
  on: {
776
790
  pick: { target: "starting" },
777
791
  useRecoveryCode: { target: "verifyingRecovery" },
778
- reset: { target: "idle", actions: E }
792
+ reset: { target: "idle", actions: C }
779
793
  }
780
794
  }
781
795
  }
782
796
  });
783
797
  }
784
- function C(t, e) {
798
+ function E(t, e) {
785
799
  t.methodType = e.type, t.expiresAt = e.expiresAt ?? null, t.resendAvailableAt = e.resendAvailableAt ?? null, t.optionsJson = e.optionsJson ?? null, t.errorCode = null, t.errorMessage = null;
786
800
  }
787
- function E({ context: t }) {
801
+ function C({ context: t }) {
788
802
  t.methodId = null, t.methodType = null, t.userId = null, t.verifiedToken = null, t.expiresAt = null, t.resendAvailableAt = null, t.optionsJson = null, t.errorCode = null, t.errorMessage = null;
789
803
  }
790
804
  function c(t, e) {
791
- e instanceof a ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
805
+ e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
792
806
  }
793
- const V = {
807
+ const j = {
794
808
  items: [],
795
809
  errorCode: null,
796
810
  errorMessage: null
797
811
  };
798
- function B(t) {
812
+ function z(t) {
799
813
  return h({
800
814
  types: {
801
815
  context: {},
802
816
  events: {}
803
817
  },
804
818
  actors: {
805
- load: l(async () => {
819
+ load: i(async () => {
806
820
  const e = await t.listMethods();
807
821
  if (!e.ok)
808
- throw new a(e.code, e.message, e.httpStatus, e.details ?? null);
822
+ throw new s(e.code, e.message, e.httpStatus, e.details ?? null);
809
823
  return e.value;
810
824
  }),
811
- remove: l(async ({ input: e }) => {
825
+ remove: i(async ({ input: e }) => {
812
826
  const r = await t.removeMethod(e.methodId);
813
827
  if (!r.ok)
814
- throw new a(r.code, r.message, r.httpStatus, r.details ?? null);
828
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
815
829
  return e.methodId;
816
830
  })
817
831
  }
818
832
  }).createMachine({
819
833
  id: "methods",
820
834
  initial: "idle",
821
- context: V,
835
+ context: j,
822
836
  states: {
823
837
  idle: {
824
838
  on: {
@@ -836,7 +850,7 @@ function B(t) {
836
850
  },
837
851
  onError: {
838
852
  target: "failed",
839
- actions: ({ context: e, event: r }) => S(e, r.error)
853
+ actions: ({ context: e, event: r }) => N(e, r.error)
840
854
  }
841
855
  }
842
856
  },
@@ -862,54 +876,222 @@ function B(t) {
862
876
  },
863
877
  onError: {
864
878
  target: "ready",
865
- actions: ({ context: e, event: r }) => S(e, r.error)
879
+ actions: ({ context: e, event: r }) => N(e, r.error)
866
880
  }
867
881
  }
868
882
  },
869
883
  failed: {
870
884
  on: {
871
885
  load: { target: "loading" },
872
- reset: { target: "idle", actions: G }
886
+ reset: { target: "idle", actions: Q }
873
887
  }
874
888
  }
875
889
  }
876
890
  });
877
891
  }
878
- function G({ context: t }) {
892
+ function Q({ context: t }) {
879
893
  t.items = [], t.errorCode = null, t.errorMessage = null;
880
894
  }
881
- function S(t, e) {
882
- e instanceof a ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
895
+ function N(t, e) {
896
+ e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
897
+ }
898
+ const Z = {
899
+ methodId: null,
900
+ methodType: null,
901
+ stepUpToken: null,
902
+ expiresAt: null,
903
+ resendAvailableAt: null,
904
+ optionsJson: null,
905
+ errorCode: null,
906
+ errorMessage: null
907
+ };
908
+ function x(t) {
909
+ return h({
910
+ types: {
911
+ context: {},
912
+ events: {}
913
+ },
914
+ actors: {
915
+ startStepUp: i(async ({ input: e }) => {
916
+ const r = await t.startStepUp({ methodId: e.methodId });
917
+ if (!r.ok)
918
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
919
+ return r.value;
920
+ }),
921
+ resendStepUp: i(async ({ input: e }) => {
922
+ const r = await t.resendStepUp({ methodId: e.methodId });
923
+ if (!r.ok)
924
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
925
+ return r.value;
926
+ }),
927
+ verifyStepUp: i(async ({ input: e }) => {
928
+ const r = await t.verifyStepUp({ methodId: e.methodId, code: e.code });
929
+ if (!r.ok)
930
+ throw new s(r.code, r.message, r.httpStatus, r.details ?? null);
931
+ return r.value;
932
+ }),
933
+ assertStepUp: i(async ({ input: e }) => {
934
+ const r = await P(e.optionsJson), n = await t.verifyStepUp({ methodId: e.methodId, assertionResponseJson: r });
935
+ if (!n.ok)
936
+ throw new s(n.code, n.message, n.httpStatus, n.details ?? null);
937
+ return n.value;
938
+ })
939
+ }
940
+ }).createMachine({
941
+ id: "stepup",
942
+ initial: "idle",
943
+ context: Z,
944
+ states: {
945
+ idle: {
946
+ on: {
947
+ pick: { target: "starting" }
948
+ }
949
+ },
950
+ starting: {
951
+ entry: ({ context: e, event: r }) => {
952
+ r.type === "pick" && (e.methodId = r.methodId);
953
+ },
954
+ invoke: {
955
+ src: "startStepUp",
956
+ input: ({ context: e }) => {
957
+ if (!e.methodId) throw new Error("no methodId");
958
+ return { methodId: e.methodId };
959
+ },
960
+ onDone: [
961
+ {
962
+ guard: ({ event: e }) => e.output.type === "WebAuthn",
963
+ target: "asserting",
964
+ actions: ({ context: e, event: r }) => I(e, r.output)
965
+ },
966
+ {
967
+ target: "awaitingCode",
968
+ actions: ({ context: e, event: r }) => I(e, r.output)
969
+ }
970
+ ],
971
+ onError: {
972
+ target: "failed",
973
+ actions: ({ context: e, event: r }) => g(e, r.error)
974
+ }
975
+ }
976
+ },
977
+ asserting: {
978
+ invoke: {
979
+ src: "assertStepUp",
980
+ input: ({ context: e }) => {
981
+ if (!e.methodId || !e.optionsJson) throw new Error("no assertion options");
982
+ return { methodId: e.methodId, optionsJson: e.optionsJson };
983
+ },
984
+ onDone: {
985
+ target: "verified",
986
+ actions: ({ context: e, event: r }) => R(e, r.output.stepUpToken)
987
+ },
988
+ onError: {
989
+ target: "failed",
990
+ actions: ({ context: e, event: r }) => g(e, r.error)
991
+ }
992
+ }
993
+ },
994
+ awaitingCode: {
995
+ on: {
996
+ submit: { target: "verifying" },
997
+ resend: { target: "resending" },
998
+ reset: { target: "idle", actions: A }
999
+ }
1000
+ },
1001
+ resending: {
1002
+ invoke: {
1003
+ src: "resendStepUp",
1004
+ input: ({ context: e }) => {
1005
+ if (!e.methodId) throw new Error("no methodId");
1006
+ return { methodId: e.methodId };
1007
+ },
1008
+ onDone: {
1009
+ target: "awaitingCode",
1010
+ actions: ({ context: e, event: r }) => I(e, r.output)
1011
+ },
1012
+ onError: {
1013
+ target: "awaitingCode",
1014
+ actions: ({ context: e, event: r }) => g(e, r.error)
1015
+ }
1016
+ }
1017
+ },
1018
+ verifying: {
1019
+ invoke: {
1020
+ src: "verifyStepUp",
1021
+ input: ({ context: e, event: r }) => {
1022
+ if (r.type !== "submit") throw new Error("verifying requires submit event");
1023
+ if (!e.methodId) throw new Error("no methodId");
1024
+ return { methodId: e.methodId, code: r.code };
1025
+ },
1026
+ onDone: {
1027
+ target: "verified",
1028
+ actions: ({ context: e, event: r }) => R(e, r.output.stepUpToken)
1029
+ },
1030
+ onError: {
1031
+ target: "awaitingCode",
1032
+ actions: ({ context: e, event: r }) => g(e, r.error)
1033
+ }
1034
+ }
1035
+ },
1036
+ verified: {
1037
+ on: {
1038
+ reset: { target: "idle", actions: A }
1039
+ }
1040
+ },
1041
+ failed: {
1042
+ on: {
1043
+ pick: { target: "starting" },
1044
+ reset: { target: "idle", actions: A }
1045
+ }
1046
+ }
1047
+ }
1048
+ });
1049
+ }
1050
+ function I(t, e) {
1051
+ t.methodType = e.type, t.expiresAt = e.expiresAt ?? null, t.resendAvailableAt = e.resendAvailableAt ?? null, t.optionsJson = e.optionsJson ?? null, t.errorCode = null, t.errorMessage = null;
1052
+ }
1053
+ function R(t, e) {
1054
+ t.stepUpToken = e, t.errorCode = null, t.errorMessage = null;
1055
+ }
1056
+ function A({ context: t }) {
1057
+ t.methodId = null, t.methodType = null, t.stepUpToken = null, t.expiresAt = null, t.resendAvailableAt = null, t.optionsJson = null, t.errorCode = null, t.errorMessage = null;
1058
+ }
1059
+ function g(t, e) {
1060
+ e instanceof s ? (t.errorCode = e.code, t.errorMessage = e.message) : (t.errorCode = "UNKNOWN", t.errorMessage = e instanceof Error ? e.message : null);
883
1061
  }
884
- function Q(t) {
885
- const e = new P(t), r = u(_(e)), n = u(F(e)), o = u($(e)), i = u(Y(e)), m = u(B(e));
886
- return r.start(), n.start(), o.start(), i.start(), m.start(), {
1062
+ const oe = "X-Omni2FA-StepUp";
1063
+ function se(t) {
1064
+ const e = new K(t), r = u($(e)), n = u(V(e)), o = u(B(e)), l = u(X(e)), p = u(x(e)), f = u(z(e));
1065
+ return r.start(), n.start(), o.start(), l.start(), p.start(), f.start(), {
887
1066
  client: e,
888
1067
  totpEnrollment: r,
889
1068
  emailEnrollment: n,
890
1069
  webauthnEnrollment: o,
891
- challenge: i,
892
- methods: m,
1070
+ challenge: l,
1071
+ stepUp: p,
1072
+ methods: f,
893
1073
  dispose() {
894
- r.stop(), n.stop(), o.stop(), i.stop(), m.stop();
1074
+ r.stop(), n.stop(), o.stop(), l.stop(), p.stop(), f.stop();
895
1075
  }
896
1076
  };
897
1077
  }
898
1078
  export {
899
- X as LocalStorageStorage,
900
- N as MemoryStorage,
901
- a as Omni2FaApiError,
902
- P as Omni2FaClient,
903
- s as Omni2FaErrorCodes,
904
- z as SessionStorageStorage,
905
- Y as createChallengeMachine,
906
- F as createEmailEnrollmentMachine,
907
- B as createMethodsMachine,
908
- Q as createOmni2Fa,
909
- _ as createTotpEnrollmentMachine,
910
- $ as createWebAuthnEnrollmentMachine,
911
- w as getDefaultMessage,
912
- K as startAuthentication,
913
- L as startRegistration
1079
+ ne as LocalStorageStorage,
1080
+ _ as MemoryStorage,
1081
+ s as Omni2FaApiError,
1082
+ K as Omni2FaClient,
1083
+ a as Omni2FaErrorCodes,
1084
+ oe as STEP_UP_HEADER,
1085
+ te as SessionStorageStorage,
1086
+ X as createChallengeMachine,
1087
+ V as createEmailEnrollmentMachine,
1088
+ z as createMethodsMachine,
1089
+ se as createOmni2Fa,
1090
+ x as createStepUpMachine,
1091
+ $ as createTotpEnrollmentMachine,
1092
+ B as createWebAuthnEnrollmentMachine,
1093
+ T as getDefaultMessage,
1094
+ P as startAuthentication,
1095
+ Y as startRegistration
914
1096
  };
915
1097
  //# sourceMappingURL=index.js.map