@omni2fa/core 0.7.0 → 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.
Files changed (36) hide show
  1. package/dist/Interfaces/IOmni2Fa.d.ts +3 -0
  2. package/dist/Interfaces/IOmni2Fa.d.ts.map +1 -1
  3. package/dist/client/Interfaces/IOmni2FaClient.d.ts +5 -1
  4. package/dist/client/Interfaces/IOmni2FaClient.d.ts.map +1 -1
  5. package/dist/client/Omni2FaClient.d.ts +4 -1
  6. package/dist/client/Omni2FaClient.d.ts.map +1 -1
  7. package/dist/createOmni2Fa.d.ts.map +1 -1
  8. package/dist/errors/codes.d.ts +1 -0
  9. package/dist/errors/codes.d.ts.map +1 -1
  10. package/dist/errors/messages.d.ts.map +1 -1
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +6 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +341 -160
  16. package/dist/index.js.map +1 -1
  17. package/dist/machines/challenge/challengeMachine.d.ts +0 -6
  18. package/dist/machines/challenge/challengeMachine.d.ts.map +1 -1
  19. package/dist/machines/emailEnrollment/EmailEnrollmentEvent.d.ts +1 -1
  20. package/dist/machines/emailEnrollment/EmailEnrollmentEvent.d.ts.map +1 -1
  21. package/dist/machines/emailEnrollment/emailEnrollmentMachine.d.ts +2 -2
  22. package/dist/machines/emailEnrollment/emailEnrollmentMachine.d.ts.map +1 -1
  23. package/dist/machines/methods/methodsMachine.d.ts.map +1 -1
  24. package/dist/machines/stepup/StepUpContext.d.ts +17 -0
  25. package/dist/machines/stepup/StepUpContext.d.ts.map +1 -0
  26. package/dist/machines/stepup/StepUpEvent.d.ts +13 -0
  27. package/dist/machines/stepup/StepUpEvent.d.ts.map +1 -0
  28. package/dist/machines/stepup/stepUpMachine.d.ts +96 -0
  29. package/dist/machines/stepup/stepUpMachine.d.ts.map +1 -0
  30. package/dist/stepup/constants.d.ts +3 -0
  31. package/dist/stepup/constants.d.ts.map +1 -0
  32. package/dist/types/api.d.ts +190 -8
  33. package/dist/types/api.d.ts.map +1 -1
  34. package/dist/types/dtos.d.ts +1 -0
  35. package/dist/types/dtos.d.ts.map +1 -1
  36. package/package.json +1 -1
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
- }, w = {
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 v(t) {
51
- return w[t] ?? w[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: v(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 || v(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 }) => {
321
- const r = await t.startEmailEnrollment({ email: e.email });
334
+ startEnrollment: i(async ({ input: e }) => {
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: {
@@ -352,21 +366,20 @@ function F(t) {
352
366
  },
353
367
  starting: {
354
368
  entry: ({ context: e, event: r }) => {
355
- r.type === "start" && (e.email = r.email);
369
+ r.type === "start" && (e.email = r.email ?? null);
356
370
  },
357
371
  invoke: {
358
372
  src: "startEnrollment",
359
- input: ({ context: e }) => {
360
- if (!e.email) throw new Error("no email");
361
- return { email: e.email };
362
- },
373
+ // Under the server's default ClaimOnly source the address is derived from the
374
+ // session, so an absent email is valid; HostSupplied callers pass one through.
375
+ input: ({ context: e }) => ({ email: e.email ?? void 0 }),
363
376
  onDone: {
364
377
  target: "awaitingCode",
365
- actions: ({ context: e, event: r }) => T(e, r.output)
378
+ actions: ({ context: e, event: r }) => M(e, r.output)
366
379
  },
367
380
  onError: {
368
381
  target: "failed",
369
- actions: ({ context: e, event: r }) => y(e, r.error)
382
+ actions: ({ context: e, event: r }) => v(e, r.error)
370
383
  }
371
384
  }
372
385
  },
@@ -374,7 +387,7 @@ function F(t) {
374
387
  on: {
375
388
  submit: { target: "confirming" },
376
389
  resend: { target: "resending" },
377
- reset: { target: "idle", actions: f }
390
+ reset: { target: "idle", actions: w }
378
391
  }
379
392
  },
380
393
  resending: {
@@ -386,11 +399,11 @@ function F(t) {
386
399
  },
387
400
  onDone: {
388
401
  target: "awaitingCode",
389
- actions: ({ context: e, event: r }) => T(e, r.output)
402
+ actions: ({ context: e, event: r }) => M(e, r.output)
390
403
  },
391
404
  onError: {
392
405
  target: "awaitingCode",
393
- actions: ({ context: e, event: r }) => y(e, r.error)
406
+ actions: ({ context: e, event: r }) => v(e, r.error)
394
407
  }
395
408
  }
396
409
  },
@@ -410,37 +423,37 @@ function F(t) {
410
423
  },
411
424
  onError: {
412
425
  target: "awaitingCode",
413
- actions: ({ context: e, event: r }) => y(e, r.error)
426
+ actions: ({ context: e, event: r }) => v(e, r.error)
414
427
  }
415
428
  }
416
429
  },
417
430
  enrolled: {
418
431
  on: {
419
- reset: { target: "idle", actions: f }
432
+ reset: { target: "idle", actions: w }
420
433
  }
421
434
  },
422
435
  failed: {
423
436
  on: {
424
437
  start: { target: "starting" },
425
- reset: { target: "idle", actions: f }
438
+ reset: { target: "idle", actions: w }
426
439
  }
427
440
  }
428
441
  }
429
442
  });
430
443
  }
431
- function T(t, e) {
444
+ function M(t, e) {
432
445
  t.enrollmentId = e.enrollmentId, t.expiresAt = e.expiresAt, t.resendAvailableAt = e.resendAvailableAt, t.errorCode = null, t.errorMessage = null;
433
446
  }
434
- function f({ context: t }) {
447
+ function w({ context: t }) {
435
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;
436
449
  }
437
- function y(t, e) {
438
- 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);
439
452
  }
440
- function g(t) {
453
+ function m(t) {
441
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);
442
- for (let i = 0; i < n.length; i++)
443
- o[i] = n.charCodeAt(i);
455
+ for (let l = 0; l < n.length; l++)
456
+ o[l] = n.charCodeAt(l);
444
457
  return o.buffer;
445
458
  }
446
459
  function d(t) {
@@ -450,15 +463,15 @@ function d(t) {
450
463
  r += String.fromCharCode(n);
451
464
  return btoa(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
452
465
  }
453
- function k(t) {
454
- return (t ?? []).map((e) => ({ ...e, id: g(e.id) }));
466
+ function D(t) {
467
+ return (t ?? []).map((e) => ({ ...e, id: m(e.id) }));
455
468
  }
456
- async function L(t) {
469
+ async function Y(t) {
457
470
  const e = JSON.parse(t), r = {
458
471
  ...e,
459
- challenge: g(e.challenge),
460
- user: { ...e.user, id: g(e.user.id) },
461
- excludeCredentials: k(e.excludeCredentials)
472
+ challenge: m(e.challenge),
473
+ user: { ...e.user, id: m(e.user.id) },
474
+ excludeCredentials: D(e.excludeCredentials)
462
475
  // Cast through unknown: the spread carries Fido2's index-signature fields the DOM type omits.
463
476
  }, n = await navigator.credentials.create({ publicKey: r });
464
477
  if (n === null)
@@ -475,11 +488,11 @@ async function L(t) {
475
488
  }
476
489
  });
477
490
  }
478
- async function K(t) {
491
+ async function P(t) {
479
492
  const e = JSON.parse(t), r = {
480
493
  ...e,
481
- challenge: g(e.challenge),
482
- allowCredentials: k(e.allowCredentials)
494
+ challenge: m(e.challenge),
495
+ allowCredentials: D(e.allowCredentials)
483
496
  }, n = await navigator.credentials.get({ publicKey: r });
484
497
  if (n === null)
485
498
  throw new Error("WebAuthn authentication produced no credential.");
@@ -497,7 +510,7 @@ async function K(t) {
497
510
  }
498
511
  });
499
512
  }
500
- const W = {
513
+ const q = {
501
514
  enrollmentId: null,
502
515
  optionsJson: null,
503
516
  name: null,
@@ -506,34 +519,34 @@ const W = {
506
519
  errorCode: null,
507
520
  errorMessage: null
508
521
  };
509
- function $(t) {
522
+ function B(t) {
510
523
  return h({
511
524
  types: {
512
525
  context: {},
513
526
  events: {}
514
527
  },
515
528
  actors: {
516
- startEnrollment: l(async () => {
529
+ startEnrollment: i(async () => {
517
530
  const e = await t.startWebAuthnEnrollment();
518
531
  if (!e.ok)
519
- 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);
520
533
  return e.value;
521
534
  }),
522
- registerAndConfirm: l(async ({ input: e }) => {
523
- 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({
524
537
  enrollmentId: e.enrollmentId,
525
538
  attestationResponseJson: r,
526
539
  name: e.name
527
540
  });
528
541
  if (!n.ok)
529
- 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);
530
543
  return n.value;
531
544
  })
532
545
  }
533
546
  }).createMachine({
534
547
  id: "webauthnEnrollment",
535
548
  initial: "idle",
536
- context: W,
549
+ context: q,
537
550
  states: {
538
551
  idle: {
539
552
  on: {
@@ -554,7 +567,7 @@ function $(t) {
554
567
  },
555
568
  onError: {
556
569
  target: "failed",
557
- actions: ({ context: e, event: r }) => M(e, r.error)
570
+ actions: ({ context: e, event: r }) => U(e, r.error)
558
571
  }
559
572
  }
560
573
  },
@@ -573,31 +586,31 @@ function $(t) {
573
586
  },
574
587
  onError: {
575
588
  target: "failed",
576
- actions: ({ context: e, event: r }) => M(e, r.error)
589
+ actions: ({ context: e, event: r }) => U(e, r.error)
577
590
  }
578
591
  }
579
592
  },
580
593
  enrolled: {
581
594
  on: {
582
- reset: { target: "idle", actions: b }
595
+ reset: { target: "idle", actions: O }
583
596
  }
584
597
  },
585
598
  failed: {
586
599
  on: {
587
600
  retry: { target: "starting" },
588
- reset: { target: "idle", actions: b }
601
+ reset: { target: "idle", actions: O }
589
602
  }
590
603
  }
591
604
  }
592
605
  });
593
606
  }
594
- function b({ context: t }) {
607
+ function O({ context: t }) {
595
608
  t.enrollmentId = null, t.optionsJson = null, t.name = null, t.methodId = null, t.recoveryCodes = null, t.errorCode = null, t.errorMessage = null;
596
609
  }
597
- function M(t, e) {
598
- 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);
599
612
  }
600
- const H = {
613
+ const G = {
601
614
  methodId: null,
602
615
  methodType: null,
603
616
  userId: null,
@@ -608,48 +621,48 @@ const H = {
608
621
  errorCode: null,
609
622
  errorMessage: null
610
623
  };
611
- function Y(t) {
624
+ function X(t) {
612
625
  return h({
613
626
  types: {
614
627
  context: {},
615
628
  events: {}
616
629
  },
617
630
  actors: {
618
- startChallenge: l(async ({ input: e }) => {
631
+ startChallenge: i(async ({ input: e }) => {
619
632
  const r = await t.startChallenge({ methodId: e.methodId });
620
633
  if (!r.ok)
621
- 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);
622
635
  return r.value;
623
636
  }),
624
- resendChallenge: l(async ({ input: e }) => {
637
+ resendChallenge: i(async ({ input: e }) => {
625
638
  const r = await t.resendChallenge({ methodId: e.methodId });
626
639
  if (!r.ok)
627
- 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);
628
641
  return r.value;
629
642
  }),
630
- verifyChallenge: l(async ({ input: e }) => {
643
+ verifyChallenge: i(async ({ input: e }) => {
631
644
  const r = await t.verifyChallenge({ methodId: e.methodId, code: e.code });
632
645
  if (!r.ok)
633
- 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);
634
647
  return r.value;
635
648
  }),
636
- assertChallenge: l(async ({ input: e }) => {
637
- 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 });
638
651
  if (!n.ok)
639
- 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);
640
653
  return n.value;
641
654
  }),
642
- verifyRecoveryCode: l(async ({ input: e }) => {
655
+ verifyRecoveryCode: i(async ({ input: e }) => {
643
656
  const r = await t.verifyRecoveryCode({ recoveryCode: e.code });
644
657
  if (!r.ok)
645
- 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);
646
659
  return r.value;
647
660
  })
648
661
  }
649
662
  }).createMachine({
650
663
  id: "challenge",
651
664
  initial: "idle",
652
- context: H,
665
+ context: G,
653
666
  states: {
654
667
  idle: {
655
668
  on: {
@@ -671,11 +684,11 @@ function Y(t) {
671
684
  {
672
685
  guard: ({ event: e }) => e.output.type === "WebAuthn",
673
686
  target: "asserting",
674
- actions: ({ context: e, event: r }) => C(e, r.output)
687
+ actions: ({ context: e, event: r }) => E(e, r.output)
675
688
  },
676
689
  {
677
690
  target: "awaitingCode",
678
- actions: ({ context: e, event: r }) => C(e, r.output)
691
+ actions: ({ context: e, event: r }) => E(e, r.output)
679
692
  }
680
693
  ],
681
694
  onError: {
@@ -708,7 +721,7 @@ function Y(t) {
708
721
  submit: { target: "verifying" },
709
722
  resend: { target: "resending" },
710
723
  useRecoveryCode: { target: "verifyingRecovery" },
711
- reset: { target: "idle", actions: E }
724
+ reset: { target: "idle", actions: C }
712
725
  }
713
726
  },
714
727
  verifyingRecovery: {
@@ -739,7 +752,7 @@ function Y(t) {
739
752
  },
740
753
  onDone: {
741
754
  target: "awaitingCode",
742
- actions: ({ context: e, event: r }) => C(e, r.output)
755
+ actions: ({ context: e, event: r }) => E(e, r.output)
743
756
  },
744
757
  onError: {
745
758
  target: "awaitingCode",
@@ -769,57 +782,57 @@ function Y(t) {
769
782
  },
770
783
  verified: {
771
784
  on: {
772
- reset: { target: "idle", actions: E }
785
+ reset: { target: "idle", actions: C }
773
786
  }
774
787
  },
775
788
  failed: {
776
789
  on: {
777
790
  pick: { target: "starting" },
778
791
  useRecoveryCode: { target: "verifyingRecovery" },
779
- reset: { target: "idle", actions: E }
792
+ reset: { target: "idle", actions: C }
780
793
  }
781
794
  }
782
795
  }
783
796
  });
784
797
  }
785
- function C(t, e) {
798
+ function E(t, e) {
786
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;
787
800
  }
788
- function E({ context: t }) {
801
+ function C({ context: t }) {
789
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;
790
803
  }
791
804
  function c(t, e) {
792
- 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);
793
806
  }
794
- const V = {
807
+ const j = {
795
808
  items: [],
796
809
  errorCode: null,
797
810
  errorMessage: null
798
811
  };
799
- function B(t) {
812
+ function z(t) {
800
813
  return h({
801
814
  types: {
802
815
  context: {},
803
816
  events: {}
804
817
  },
805
818
  actors: {
806
- load: l(async () => {
819
+ load: i(async () => {
807
820
  const e = await t.listMethods();
808
821
  if (!e.ok)
809
- 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);
810
823
  return e.value;
811
824
  }),
812
- remove: l(async ({ input: e }) => {
825
+ remove: i(async ({ input: e }) => {
813
826
  const r = await t.removeMethod(e.methodId);
814
827
  if (!r.ok)
815
- 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);
816
829
  return e.methodId;
817
830
  })
818
831
  }
819
832
  }).createMachine({
820
833
  id: "methods",
821
834
  initial: "idle",
822
- context: V,
835
+ context: j,
823
836
  states: {
824
837
  idle: {
825
838
  on: {
@@ -837,7 +850,7 @@ function B(t) {
837
850
  },
838
851
  onError: {
839
852
  target: "failed",
840
- actions: ({ context: e, event: r }) => S(e, r.error)
853
+ actions: ({ context: e, event: r }) => N(e, r.error)
841
854
  }
842
855
  }
843
856
  },
@@ -863,54 +876,222 @@ function B(t) {
863
876
  },
864
877
  onError: {
865
878
  target: "ready",
866
- actions: ({ context: e, event: r }) => S(e, r.error)
879
+ actions: ({ context: e, event: r }) => N(e, r.error)
867
880
  }
868
881
  }
869
882
  },
870
883
  failed: {
871
884
  on: {
872
885
  load: { target: "loading" },
873
- reset: { target: "idle", actions: G }
886
+ reset: { target: "idle", actions: Q }
874
887
  }
875
888
  }
876
889
  }
877
890
  });
878
891
  }
879
- function G({ context: t }) {
892
+ function Q({ context: t }) {
880
893
  t.items = [], t.errorCode = null, t.errorMessage = null;
881
894
  }
882
- function S(t, e) {
883
- 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);
884
1061
  }
885
- function Q(t) {
886
- const e = new P(t), r = u(_(e)), n = u(F(e)), o = u($(e)), i = u(Y(e)), m = u(B(e));
887
- 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(), {
888
1066
  client: e,
889
1067
  totpEnrollment: r,
890
1068
  emailEnrollment: n,
891
1069
  webauthnEnrollment: o,
892
- challenge: i,
893
- methods: m,
1070
+ challenge: l,
1071
+ stepUp: p,
1072
+ methods: f,
894
1073
  dispose() {
895
- r.stop(), n.stop(), o.stop(), i.stop(), m.stop();
1074
+ r.stop(), n.stop(), o.stop(), l.stop(), p.stop(), f.stop();
896
1075
  }
897
1076
  };
898
1077
  }
899
1078
  export {
900
- X as LocalStorageStorage,
901
- N as MemoryStorage,
902
- a as Omni2FaApiError,
903
- P as Omni2FaClient,
904
- s as Omni2FaErrorCodes,
905
- z as SessionStorageStorage,
906
- Y as createChallengeMachine,
907
- F as createEmailEnrollmentMachine,
908
- B as createMethodsMachine,
909
- Q as createOmni2Fa,
910
- _ as createTotpEnrollmentMachine,
911
- $ as createWebAuthnEnrollmentMachine,
912
- v as getDefaultMessage,
913
- K as startAuthentication,
914
- 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
915
1096
  };
916
1097
  //# sourceMappingURL=index.js.map