postex-auth-sdk-stage 1.2.4 → 1.3.0

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.
@@ -21,9 +21,9 @@ function k(a) {
21
21
  throw new Error("Invalid base64: expected non-empty string");
22
22
  const e = a.replace(/\s/g, "").replace(/-/g, "+").replace(/_/g, "/"), n = e.length % 4, t = n > 0 ? e + "=".repeat(4 - n) : e;
23
23
  try {
24
- const o = atob(t), s = new Uint8Array(o.length);
25
- for (let r = 0; r < o.length; r++)
26
- s[r] = o.charCodeAt(r);
24
+ const r = atob(t), s = new Uint8Array(r.length);
25
+ for (let o = 0; o < r.length; o++)
26
+ s[o] = r.charCodeAt(o);
27
27
  return s.buffer;
28
28
  } catch {
29
29
  throw new Error(
@@ -31,7 +31,7 @@ function k(a) {
31
31
  );
32
32
  }
33
33
  }
34
- function g(a) {
34
+ function m(a) {
35
35
  return y(a).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
36
36
  }
37
37
  function J(a) {
@@ -81,8 +81,8 @@ async function G(a) {
81
81
  try {
82
82
  const e = await h();
83
83
  return new Promise((n, t) => {
84
- const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, S);
85
- r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
84
+ const r = e.transaction(u, "readwrite"), o = r.objectStore(u).put(a, S);
85
+ o.onerror = () => t(o.error), o.onsuccess = () => n(), r.oncomplete = () => e.close();
86
86
  });
87
87
  } catch {
88
88
  }
@@ -112,8 +112,8 @@ async function X(a) {
112
112
  try {
113
113
  const e = await h();
114
114
  return new Promise((n, t) => {
115
- const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, E);
116
- r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
115
+ const r = e.transaction(u, "readwrite"), o = r.objectStore(u).put(a, E);
116
+ o.onerror = () => t(o.error), o.onsuccess = () => n(), r.oncomplete = () => e.close();
117
117
  });
118
118
  } catch {
119
119
  }
@@ -137,7 +137,7 @@ function D(a) {
137
137
  y: a.y
138
138
  };
139
139
  }
140
- async function B(a) {
140
+ async function q(a) {
141
141
  const e = JSON.stringify({
142
142
  crv: a.crv,
143
143
  kty: a.kty,
@@ -147,14 +147,14 @@ async function B(a) {
147
147
  "SHA-256",
148
148
  new TextEncoder().encode(e)
149
149
  );
150
- return g(n);
150
+ return m(n);
151
151
  }
152
- async function q(a) {
152
+ async function B(a) {
153
153
  try {
154
154
  const e = await h();
155
155
  return new Promise((n, t) => {
156
- const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, x);
157
- r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
156
+ const r = e.transaction(u, "readwrite"), o = r.objectStore(u).put(a, x);
157
+ o.onerror = () => t(o.error), o.onsuccess = () => n(), r.oncomplete = () => e.close();
158
158
  });
159
159
  } catch (e) {
160
160
  console.error("Failed to store DPoP private key:", e);
@@ -164,8 +164,8 @@ async function Z(a) {
164
164
  try {
165
165
  const e = await h();
166
166
  return new Promise((n, t) => {
167
- const o = e.transaction(u, "readwrite"), r = o.objectStore(u).put(a, I);
168
- r.onerror = () => t(r.error), r.onsuccess = () => n(), o.oncomplete = () => e.close();
167
+ const r = e.transaction(u, "readwrite"), o = r.objectStore(u).put(a, I);
168
+ o.onerror = () => t(o.error), o.onsuccess = () => n(), r.oncomplete = () => e.close();
169
169
  });
170
170
  } catch (e) {
171
171
  console.error("Failed to store DPoP public key JWK:", e);
@@ -193,19 +193,19 @@ async function R() {
193
193
  return null;
194
194
  }
195
195
  }
196
- async function U() {
196
+ async function N() {
197
197
  try {
198
198
  const a = await h();
199
199
  return new Promise((e, n) => {
200
- const t = a.transaction(u, "readwrite"), o = t.objectStore(u);
201
- o.delete(x), o.delete(I), t.onerror = () => n(t.error), t.oncomplete = () => {
200
+ const t = a.transaction(u, "readwrite"), r = t.objectStore(u);
201
+ r.delete(x), r.delete(I), t.onerror = () => n(t.error), t.oncomplete = () => {
202
202
  a.close(), e();
203
203
  };
204
204
  });
205
205
  } catch {
206
206
  }
207
207
  }
208
- async function T() {
208
+ async function g() {
209
209
  const a = await crypto.subtle.generateKey(
210
210
  {
211
211
  name: "ECDSA",
@@ -214,44 +214,44 @@ async function T() {
214
214
  !1,
215
215
  // Private key is non-extractable
216
216
  ["sign", "verify"]
217
- ), e = await crypto.subtle.exportKey("jwk", a.publicKey), n = D(e), t = await B(n);
218
- return await q(a.privateKey), await Z(n), { publicKey: n, thumbprint: t };
217
+ ), e = await crypto.subtle.exportKey("jwk", a.publicKey), n = D(e), t = await q(n);
218
+ return await B(a.privateKey), await Z(n), { publicKey: n, thumbprint: t };
219
219
  }
220
220
  async function w(a, e, n) {
221
221
  try {
222
- const t = await A(), o = await R();
223
- if (!t || !o) return null;
222
+ const t = await A(), r = await R();
223
+ if (!t || !r) return null;
224
224
  const s = {
225
225
  typ: "dpop+jwt",
226
226
  alg: "ES256",
227
- jwk: o
227
+ jwk: r
228
228
  // Public key in JWK format
229
- }, r = new URL(
229
+ }, o = new URL(
230
230
  e,
231
231
  typeof window < "u" ? window.location.origin : void 0
232
- ), i = `${r.origin}${r.pathname}`, d = {
232
+ ), c = `${o.origin}${o.pathname}`, d = {
233
233
  jti: crypto.randomUUID(),
234
234
  htm: a.toUpperCase(),
235
- htu: i,
235
+ htu: c,
236
236
  iat: Math.floor(Date.now() / 1e3)
237
237
  };
238
238
  if (n) {
239
239
  const P = new TextEncoder().encode(n), $ = await crypto.subtle.digest("SHA-256", P);
240
- d.ath = g($);
240
+ d.ath = m($);
241
241
  }
242
- const l = g(
242
+ const l = m(
243
243
  new TextEncoder().encode(JSON.stringify(s)).buffer
244
- ), c = g(
244
+ ), i = m(
245
245
  new TextEncoder().encode(JSON.stringify(d)).buffer
246
- ), p = `${l}.${c}`, f = await crypto.subtle.sign(
246
+ ), p = `${l}.${i}`, f = await crypto.subtle.sign(
247
247
  {
248
248
  name: "ECDSA",
249
249
  hash: { name: "SHA-256" }
250
250
  },
251
251
  t,
252
252
  new TextEncoder().encode(p)
253
- ), b = g(f);
254
- return `${l}.${c}.${b}`;
253
+ ), b = m(f);
254
+ return `${l}.${i}.${b}`;
255
255
  } catch (t) {
256
256
  return console.error("Failed to generate DPoP proof:", t), null;
257
257
  }
@@ -259,12 +259,12 @@ async function w(a, e, n) {
259
259
  async function ee() {
260
260
  return await A() !== null;
261
261
  }
262
- const te = q, N = {
262
+ const te = B, U = {
263
263
  isWebAuthnSupported: K,
264
264
  isConditionalUISupported: j,
265
265
  arrayBufferToBase64: y,
266
266
  base64ToArrayBuffer: k,
267
- arrayBufferToBase64url: g,
267
+ arrayBufferToBase64url: m,
268
268
  base64urlToArrayBuffer: M,
269
269
  stringToArrayBuffer: _,
270
270
  uint8ArrayToString: W,
@@ -275,25 +275,26 @@ const te = q, N = {
275
275
  setPasskeyMobileNumber: X,
276
276
  clearPasskeyMobileNumber: Q,
277
277
  toMinimalJWK: D,
278
- calculateThumbprint: B,
278
+ calculateThumbprint: q,
279
279
  getDPoPKey: A,
280
280
  getDPoPPublicKeyJWK: R,
281
- clearDPoPKey: U,
282
- generateDPoPKeyPair: T,
281
+ clearDPoPKey: N,
282
+ generateDPoPKeyPair: g,
283
283
  generateDPoPProof: w,
284
284
  isDPoPEnabled: ee,
285
285
  storeDPoPKey: te
286
286
  };
287
- typeof window < "u" && (window.WebAuthn = N);
287
+ typeof window < "u" && (window.WebAuthn = U);
288
288
  const ne = typeof window < "u" ? window : globalThis;
289
- ne.WebAuthn = N;
290
- const m = "postex-auth-token", se = "postexglobal", oe = {
289
+ ne.WebAuthn = U;
290
+ const T = "postex-auth-token", se = "postexglobal", re = {
291
291
  xstak: "https://auth-stage.xstak.com/public/v1",
292
292
  postex: "https://auth-stage.postex.pk/public/v1",
293
293
  callcourier: "https://auth-stage.callcourier.com.pk/public/v1",
294
- postexglobal: "https://auth-stage.postexglobal.com/public/v1"
294
+ postexglobal: "https://auth-stage.postexglobal.com/public/v1",
295
+ postexsa: "https://auth-stage.postex.sa/public/v1"
295
296
  };
296
- class re extends Error {
297
+ class oe extends Error {
297
298
  constructor(e, n, t) {
298
299
  super(t ?? `Request failed with status ${e}`), this.response = { status: e, data: n }, this.name = "AuthSDKFetchError";
299
300
  }
@@ -305,7 +306,7 @@ class C {
305
306
  }
306
307
  getBaseUrl() {
307
308
  const e = this.config.appId ?? se;
308
- return oe[e];
309
+ return re[e];
309
310
  }
310
311
  normalizeAuthIdentifier(e) {
311
312
  return typeof e == "string" ? { email: e } : {
@@ -314,35 +315,35 @@ class C {
314
315
  };
315
316
  }
316
317
  buildUrl(e, n) {
317
- const t = this.getBaseUrl().replace(/\/$/, ""), o = e.startsWith("/") ? e : `/${e}`, s = `${t}${o}`;
318
+ const t = this.getBaseUrl().replace(/\/$/, ""), r = e.startsWith("/") ? e : `/${e}`, s = `${t}${r}`;
318
319
  if (!n || Object.keys(n).length === 0) return s;
319
- const r = new URLSearchParams(n).toString();
320
- return `${s}?${r}`;
320
+ const o = new URLSearchParams(n).toString();
321
+ return `${s}?${o}`;
321
322
  }
322
323
  async request(e, n, t) {
323
- const o = this.buildUrl(n, t?.params), s = {
324
+ const r = this.buildUrl(n, t?.params), s = {
324
325
  "Content-Type": "application/json",
325
326
  Accept: "application/json",
326
327
  "X-API-Key": this.config.apiKey ?? "",
327
328
  ...t?.headers
328
- }, r = {
329
+ }, o = {
329
330
  method: e,
330
331
  credentials: "include",
331
332
  headers: s
332
333
  };
333
- t?.body !== void 0 && t?.body !== null && (r.body = JSON.stringify(t.body));
334
- const i = await fetch(o, r);
335
- if (!i.ok) {
336
- let c;
334
+ t?.body !== void 0 && t?.body !== null && (o.body = JSON.stringify(t.body));
335
+ const c = await fetch(r, o);
336
+ if (!c.ok) {
337
+ let i;
337
338
  try {
338
- const p = await i.text();
339
- c = p ? JSON.parse(p) : void 0;
339
+ const p = await c.text();
340
+ i = p ? JSON.parse(p) : void 0;
340
341
  } catch {
341
- c = void 0;
342
+ i = void 0;
342
343
  }
343
- throw i.status === 401 && await this.clearTokens(), new re(i.status, c);
344
+ throw c.status === 401 && await this.clearTokens(), new oe(c.status, i);
344
345
  }
345
- const d = await i.text();
346
+ const d = await c.text();
346
347
  return { data: d ? JSON.parse(d) : {} };
347
348
  }
348
349
  /**
@@ -352,16 +353,16 @@ class C {
352
353
  * @param url - Full request URL
353
354
  */
354
355
  async getRequestAuthHeaders(e, n) {
355
- const t = localStorage.getItem(m);
356
+ const t = localStorage.getItem(T);
356
357
  if (!t) return {};
357
- const o = n.startsWith("http") ? n : `${this.getBaseUrl()}${n}`, s = await w(
358
+ const r = n.startsWith("http") ? n : `${this.getBaseUrl()}${n}`, s = await w(
358
359
  e.toUpperCase(),
359
- o,
360
+ r,
360
361
  t
361
- ), r = {
362
+ ), o = {
362
363
  Authorization: `Bearer ${t}`
363
364
  };
364
- return s && (r.DPoP = s), r;
365
+ return s && (o.DPoP = s), o;
365
366
  }
366
367
  /**
367
368
  * GET /auth/status - Check if client has trusted device session and what auth method is available.
@@ -382,12 +383,29 @@ class C {
382
383
  async initiateAuth(e) {
383
384
  const n = this.normalizeAuthIdentifier(e), t = await this.request("POST", "/auth/initiate", {
384
385
  body: n
385
- }), o = t.data.data ?? t.data;
386
+ }), r = t.data.data ?? t.data;
386
387
  return {
387
- status: o.status,
388
- challenge: o.challenge,
389
- credentialIds: o.credentialIds,
390
- rp: o.rp
388
+ status: r.status,
389
+ challenge: r.challenge,
390
+ credentialIds: r.credentialIds,
391
+ rp: r.rp
392
+ };
393
+ }
394
+ /**
395
+ * POST /otp/initiate - Direct OTP initiation using email or mobile number.
396
+ * Requires at least one identifier: email or mobileNumber.
397
+ */
398
+ async initiateOTP(e) {
399
+ const n = this.normalizeAuthIdentifier(e), t = n.email?.trim(), r = n.mobileNumber?.trim();
400
+ if (!t && !r)
401
+ throw new Error("Either mobileNumber or email is required");
402
+ const s = {};
403
+ t && (s.email = t), r && (s.mobileNumber = r);
404
+ const c = (await this.request("POST", "/otp/initiate", {
405
+ body: s
406
+ })).data;
407
+ return {
408
+ message: c.message ?? c.data?.message
391
409
  };
392
410
  }
393
411
  /**
@@ -395,26 +413,26 @@ class C {
395
413
  * Stores tokens from the response.
396
414
  */
397
415
  async verifyOTP(e) {
398
- await T();
416
+ await g();
399
417
  const n = await w(
400
418
  "POST",
401
419
  `${this.getBaseUrl()}/otp/verify`
402
420
  ), t = await this.request("POST", "/otp/verify", {
403
421
  body: { otp: e },
404
422
  headers: n ? { DPoP: n } : {}
405
- }), o = t.data.data ?? t.data, s = o.AuthenticationResult ?? o, r = s.access_token ?? s.accessToken ?? s.AccessToken, i = s.refresh_token ?? s.refreshToken ?? s.RefreshToken, d = s.id_token ?? s.idToken ?? s.IdToken, l = s.expires_in ?? s.expiresIn ?? s.ExpiresIn ?? 3600, c = s.token_type ?? s.tokenType ?? s.TokenType ?? "Bearer";
406
- return r && await this.storeTokens({
407
- accessToken: r,
408
- refreshToken: i ?? "",
423
+ }), r = t.data.data ?? t.data, s = r.AuthenticationResult ?? r, o = s.access_token ?? s.accessToken ?? s.AccessToken, c = s.refresh_token ?? s.refreshToken ?? s.RefreshToken, d = s.id_token ?? s.idToken ?? s.IdToken, l = s.expires_in ?? s.expiresIn ?? s.ExpiresIn ?? 3600, i = s.token_type ?? s.tokenType ?? s.TokenType ?? "Bearer";
424
+ return o && await this.storeTokens({
425
+ accessToken: o,
426
+ refreshToken: c ?? "",
409
427
  idToken: d ?? "",
410
428
  expiresIn: l ?? 3600,
411
- tokenType: c ?? "Bearer"
429
+ tokenType: i ?? "Bearer"
412
430
  }), {
413
- access_token: r,
414
- refresh_token: i ?? "",
431
+ access_token: o,
432
+ refresh_token: c ?? "",
415
433
  id_token: d ?? "",
416
434
  expires_in: l,
417
- token_type: c,
435
+ token_type: i,
418
436
  verified: s.verified ?? s.Verified ?? !0,
419
437
  email: s.email ?? s.Email ?? "",
420
438
  ...s
@@ -440,29 +458,29 @@ class C {
440
458
  mobileNumber: e,
441
459
  otp: n
442
460
  }) {
443
- await T();
461
+ await g();
444
462
  const t = await w(
445
463
  "POST",
446
464
  `${this.getBaseUrl()}/otp/signup/verify`
447
- ), o = await this.request("POST", "/otp/signup/verify", {
465
+ ), r = await this.request("POST", "/otp/signup/verify", {
448
466
  body: { mobileNumber: e, otp: n },
449
467
  headers: t ? { DPoP: t } : {}
450
- }), s = o.data.data ?? o.data, r = s.AuthenticationResult ?? s, i = r.access_token ?? r.accessToken ?? r.AccessToken, d = r.refresh_token ?? r.refreshToken ?? r.RefreshToken, l = r.id_token ?? r.idToken ?? r.IdToken, c = r.expires_in ?? r.expiresIn ?? r.ExpiresIn ?? 3600, p = r.token_type ?? r.tokenType ?? r.TokenType ?? "Bearer";
451
- return i && await this.storeTokens({
452
- accessToken: i,
468
+ }), s = r.data.data ?? r.data, o = s.AuthenticationResult ?? s, c = o.access_token ?? o.accessToken ?? o.AccessToken, d = o.refresh_token ?? o.refreshToken ?? o.RefreshToken, l = o.id_token ?? o.idToken ?? o.IdToken, i = o.expires_in ?? o.expiresIn ?? o.ExpiresIn ?? 3600, p = o.token_type ?? o.tokenType ?? o.TokenType ?? "Bearer";
469
+ return c && await this.storeTokens({
470
+ accessToken: c,
453
471
  refreshToken: d ?? "",
454
472
  idToken: l ?? "",
455
- expiresIn: c ?? 3600,
473
+ expiresIn: i ?? 3600,
456
474
  tokenType: p ?? "Bearer"
457
475
  }), {
458
- access_token: i,
476
+ access_token: c,
459
477
  refresh_token: d ?? "",
460
478
  id_token: l ?? "",
461
- expires_in: c,
479
+ expires_in: i,
462
480
  token_type: p,
463
- verified: r.verified ?? r.Verified ?? !0,
464
- email: r.email ?? r.Email ?? "",
465
- ...r
481
+ verified: o.verified ?? o.Verified ?? !0,
482
+ email: o.email ?? o.Email ?? "",
483
+ ...o
466
484
  };
467
485
  }
468
486
  /**
@@ -474,11 +492,11 @@ class C {
474
492
  }) {
475
493
  const t = await this.request("POST", "/otp/signup/resend", {
476
494
  body: { email: n, mobileNumber: e }
477
- }), o = t.data.data ?? t.data;
495
+ }), r = t.data.data ?? t.data;
478
496
  return {
479
- success: o.success ?? !0,
480
- message: o.message,
481
- ...o
497
+ success: r.success ?? !0,
498
+ message: r.message,
499
+ ...r
482
500
  };
483
501
  }
484
502
  /**
@@ -502,18 +520,18 @@ class C {
502
520
  {
503
521
  body: {}
504
522
  }
505
- ), n = e.data.data ?? e.data, t = n.AuthenticationResult ?? n, o = t.access_token ?? t.accessToken ?? t.AccessToken, s = t.refresh_token ?? t.refreshToken ?? t.RefreshToken, r = t.id_token ?? t.idToken ?? t.IdToken, i = t.expires_in ?? t.expiresIn ?? t.ExpiresIn ?? 3600, d = t.token_type ?? t.tokenType ?? t.TokenType ?? "Bearer";
506
- return o && await this.storeTokens({
507
- accessToken: o,
523
+ ), n = e.data.data ?? e.data, t = n.AuthenticationResult ?? n, r = t.access_token ?? t.accessToken ?? t.AccessToken, s = t.refresh_token ?? t.refreshToken ?? t.RefreshToken, o = t.id_token ?? t.idToken ?? t.IdToken, c = t.expires_in ?? t.expiresIn ?? t.ExpiresIn ?? 3600, d = t.token_type ?? t.tokenType ?? t.TokenType ?? "Bearer";
524
+ return r && await this.storeTokens({
525
+ accessToken: r,
508
526
  refreshToken: s ?? "",
509
- idToken: r ?? "",
510
- expiresIn: i ?? 3600,
527
+ idToken: o ?? "",
528
+ expiresIn: c ?? 3600,
511
529
  tokenType: d ?? "Bearer"
512
530
  }), {
513
- access_token: o,
531
+ access_token: r,
514
532
  refresh_token: s ?? "",
515
- id_token: r ?? "",
516
- expires_in: i,
533
+ id_token: o ?? "",
534
+ expires_in: c,
517
535
  token_type: d,
518
536
  verified: t.verified ?? t.Verified ?? !0,
519
537
  email: t.email ?? t.Email ?? "",
@@ -541,7 +559,7 @@ class C {
541
559
  }
542
560
  else
543
561
  t = _(e);
544
- const o = (n.pubKeyCredParams ?? [
562
+ const r = (n.pubKeyCredParams ?? [
545
563
  { type: "public-key", alg: -7 },
546
564
  { type: "public-key", alg: -257 }
547
565
  ]).map((f) => ({
@@ -550,7 +568,7 @@ class C {
550
568
  })), s = n.excludeCredentials?.map((f) => ({
551
569
  type: "public-key",
552
570
  id: k(f.id)
553
- })), r = {
571
+ })), o = {
554
572
  challenge: k(n.challenge),
555
573
  rp: {
556
574
  name: n.rp?.name ?? "XPay",
@@ -561,7 +579,7 @@ class C {
561
579
  name: n.user?.name ?? e,
562
580
  displayName: n.user?.displayName ?? e
563
581
  },
564
- pubKeyCredParams: o,
582
+ pubKeyCredParams: r,
565
583
  excludeCredentials: s,
566
584
  timeout: n.timeout ?? 6e4,
567
585
  attestation: n.attestation ?? "none",
@@ -569,18 +587,18 @@ class C {
569
587
  residentKey: "required",
570
588
  userVerification: "required"
571
589
  }
572
- }, i = await navigator.credentials.create({
573
- publicKey: r
590
+ }, c = await navigator.credentials.create({
591
+ publicKey: o
574
592
  });
575
- if (!i) throw new Error("Credential creation failed");
576
- const d = i.response, l = {
593
+ if (!c) throw new Error("Credential creation failed");
594
+ const d = c.response, l = {
577
595
  clientDataJSON: y(d.clientDataJSON),
578
596
  attestationObject: y(d.attestationObject),
579
- rawId: y(i.rawId)
597
+ rawId: y(c.rawId)
580
598
  };
581
599
  if (!l.rawId) throw new Error("Raw ID is required");
582
- await T();
583
- const c = await w(
600
+ await g();
601
+ const i = await w(
584
602
  "POST",
585
603
  `${this.getBaseUrl()}/webauthn/register/challenge`
586
604
  ), p = await this.request(
@@ -588,7 +606,7 @@ class C {
588
606
  "/webauthn/register/challenge",
589
607
  {
590
608
  body: l,
591
- headers: c ? { DPoP: c } : {}
609
+ headers: i ? { DPoP: i } : {}
592
610
  }
593
611
  );
594
612
  return p.data.data ?? p.data;
@@ -601,7 +619,7 @@ class C {
601
619
  rp: n,
602
620
  credentialIds: t
603
621
  }) {
604
- const o = await navigator.credentials.get({
622
+ const r = await navigator.credentials.get({
605
623
  publicKey: {
606
624
  challenge: k(e),
607
625
  rpId: n?.host ?? void 0,
@@ -615,78 +633,78 @@ class C {
615
633
  userVerification: "required"
616
634
  }
617
635
  });
618
- if (!o) throw new Error("Authentication failed");
619
- const s = o.response, r = {
636
+ if (!r) throw new Error("Authentication failed");
637
+ const s = r.response, o = {
620
638
  clientDataJSON: y(s.clientDataJSON),
621
639
  authenticatorData: y(
622
640
  s.authenticatorData
623
641
  ),
624
642
  signature: y(s.signature),
625
- rawId: y(o.rawId),
643
+ rawId: y(r.rawId),
626
644
  userHandle: s.userHandle ? y(s.userHandle) : ""
627
645
  };
628
- await T();
629
- const i = await w(
646
+ await g();
647
+ const c = await w(
630
648
  "POST",
631
649
  `${this.getBaseUrl()}/webauthn/authenticate/challenge`
632
650
  ), d = await this.request(
633
651
  "POST",
634
652
  "/webauthn/authenticate/challenge",
635
653
  {
636
- body: r,
637
- headers: i ? { DPoP: i } : {}
654
+ body: o,
655
+ headers: c ? { DPoP: c } : {}
638
656
  }
639
- ), l = d.data.data ?? d.data, c = l.AuthenticationResult ?? l, p = c.AccessToken ?? c.accessToken ?? c.access_token, f = c.RefreshToken ?? c.refreshToken ?? c.refresh_token, b = c.IdToken ?? c.idToken ?? c.id_token;
657
+ ), l = d.data.data ?? d.data, i = l.AuthenticationResult ?? l, p = i.AccessToken ?? i.accessToken ?? i.access_token, f = i.RefreshToken ?? i.refreshToken ?? i.refresh_token, b = i.IdToken ?? i.idToken ?? i.id_token;
640
658
  return p && await this.storeTokens({
641
659
  accessToken: p,
642
660
  refreshToken: f ?? "",
643
661
  idToken: b ?? "",
644
- expiresIn: c.expiresIn ?? c.ExpiresIn ?? 3600,
645
- tokenType: c.tokenType ?? c.token_type ?? "Bearer"
662
+ expiresIn: i.expiresIn ?? i.ExpiresIn ?? 3600,
663
+ tokenType: i.tokenType ?? i.token_type ?? "Bearer"
646
664
  }), {
647
665
  access_token: p,
648
666
  refresh_token: f ?? "",
649
667
  id_token: b,
650
- email: c.email,
651
- name: c.name ?? c.userName,
652
- expiresIn: c.expiresIn ?? c.ExpiresIn,
653
- tokenType: c.tokenType ?? c.token_type,
654
- ...c
668
+ email: i.email,
669
+ name: i.name ?? i.userName,
670
+ expiresIn: i.expiresIn ?? i.ExpiresIn,
671
+ tokenType: i.tokenType ?? i.token_type,
672
+ ...i
655
673
  };
656
674
  }
657
675
  /**
658
676
  * GET /webauthn/credentials/:username - Get user's passkey status.
659
677
  */
660
678
  async getPasskeyStatus(e) {
661
- const t = `/webauthn/credentials/${encodeURIComponent(e)}`, o = await this.signRequest("GET", t), s = await this.request("GET", t, {
662
- headers: o.headers
663
- }), r = s.data.data ?? s.data;
679
+ const t = `/webauthn/credentials/${encodeURIComponent(e)}`, r = await this.signRequest("GET", t), s = await this.request("GET", t, {
680
+ headers: r.headers
681
+ }), o = s.data.data ?? s.data;
664
682
  return {
665
- ...r,
666
- hasCredentials: !!(r.hasCredentials ?? r.credentialId)
683
+ ...o,
684
+ hasCredentials: !!(o.hasCredentials ?? o.credentialId)
667
685
  };
668
686
  }
669
687
  /**
670
688
  * DELETE /webauthn/credentials/:username - Remove passkey.
671
689
  */
672
690
  async removePasskey(e) {
673
- const t = `/webauthn/credentials/${encodeURIComponent(e)}`, o = await this.signRequest("DELETE", t);
691
+ const t = `/webauthn/credentials/${encodeURIComponent(e)}`, r = await this.signRequest("DELETE", t);
674
692
  await this.request("DELETE", t, {
675
- headers: o.headers
693
+ headers: r.headers
676
694
  });
677
695
  }
678
696
  /**
679
697
  * Signs a request with DPoP and Authorization headers (internal use).
680
698
  */
681
699
  async signRequest(e, n, t = {}) {
682
- const o = n.startsWith("http") ? n : `${this.getBaseUrl()}${n}`, s = await this.getRequestAuthHeaders(e, o);
700
+ const r = n.startsWith("http") ? n : `${this.getBaseUrl()}${n}`, s = await this.getRequestAuthHeaders(e, r);
683
701
  return { ...t, headers: { ...t.headers, ...s } };
684
702
  }
685
703
  /**
686
704
  * Replaces native fetch or Axios with a DPoP-signed version.
687
705
  */
688
706
  async authenticatedFetch(e, n) {
689
- const t = typeof e == "string" ? e : e instanceof URL ? e.toString() : e.url, o = n?.method || "GET", s = await this.signRequest(o, t, {
707
+ const t = typeof e == "string" ? e : e instanceof URL ? e.toString() : e.url, r = n?.method || "GET", s = await this.signRequest(r, t, {
690
708
  headers: n?.headers
691
709
  });
692
710
  return fetch(e, { ...n, headers: s.headers });
@@ -695,13 +713,13 @@ class C {
695
713
  * Store tokens from /webauthn/authenticate (per spec: sessionStorage preferred).
696
714
  */
697
715
  async storeTokens(e) {
698
- localStorage.setItem(m, e.accessToken), e.refreshToken && localStorage.setItem(v, e.refreshToken), e.idToken && localStorage.setItem(O, e.idToken);
716
+ localStorage.setItem(T, e.accessToken), e.refreshToken && localStorage.setItem(v, e.refreshToken), e.idToken && localStorage.setItem(O, e.idToken);
699
717
  }
700
718
  /**
701
719
  * Clear stored tokens (call on logout).
702
720
  */
703
721
  async clearTokens() {
704
- localStorage.removeItem(m), localStorage.removeItem(O), localStorage.removeItem(v);
722
+ localStorage.removeItem(T), localStorage.removeItem(O), localStorage.removeItem(v);
705
723
  }
706
724
  /**
707
725
  * POST /auth/refresh - Refresh access token using server-stored refresh token.
@@ -711,17 +729,17 @@ class C {
711
729
  async refreshToken() {
712
730
  const e = await this.request("POST", "/auth/refresh", {
713
731
  body: {}
714
- }), n = e.data.data ?? e.data, t = n.access_token, o = n.id_token ?? "", s = n.token_type ?? "Bearer", r = n.expires_in ?? 3600;
732
+ }), n = e.data.data ?? e.data, t = n.access_token, r = n.id_token ?? "", s = n.token_type ?? "Bearer", o = n.expires_in ?? 3600;
715
733
  return t && await this.storeTokens({
716
734
  accessToken: t,
717
- idToken: o,
718
- expiresIn: r,
735
+ idToken: r,
736
+ expiresIn: o,
719
737
  tokenType: s
720
738
  }), {
721
739
  access_token: t,
722
- id_token: o,
740
+ id_token: r,
723
741
  token_type: s,
724
- expires_in: r
742
+ expires_in: o
725
743
  };
726
744
  }
727
745
  /**
@@ -731,13 +749,13 @@ class C {
731
749
  async logout() {
732
750
  try {
733
751
  const e = await this.getAccessToken(), n = {};
734
- e && (n.Authorization = `Bearer ${e}`), await this.request("POST", "/auth/logout", { body: {}, headers: n }), U();
752
+ e && (n.Authorization = `Bearer ${e}`), await this.request("POST", "/auth/logout", { body: {}, headers: n }), N();
735
753
  } catch {
736
754
  }
737
755
  await this.clearTokens();
738
756
  }
739
757
  async getAccessToken() {
740
- return localStorage.getItem(m);
758
+ return localStorage.getItem(T);
741
759
  }
742
760
  }
743
761
  typeof window < "u" && (window.AuthSDK = C);
@@ -745,16 +763,16 @@ const ae = typeof window < "u" ? window : globalThis;
745
763
  ae.AuthSDK = C;
746
764
  export {
747
765
  C as AuthSDK,
748
- re as AuthSDKFetchError,
766
+ oe as AuthSDKFetchError,
749
767
  y as arrayBufferToBase64,
750
- g as arrayBufferToBase64url,
768
+ m as arrayBufferToBase64url,
751
769
  k as base64ToArrayBuffer,
752
770
  M as base64urlToArrayBuffer,
753
- B as calculateThumbprint,
754
- U as clearDPoPKey,
771
+ q as calculateThumbprint,
772
+ N as clearDPoPKey,
755
773
  V as clearPasskeyEmail,
756
774
  Q as clearPasskeyMobileNumber,
757
- T as generateDPoPKeyPair,
775
+ g as generateDPoPKeyPair,
758
776
  w as generateDPoPProof,
759
777
  A as getDPoPKey,
760
778
  R as getDPoPPublicKeyJWK,