@versini/auth-common 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ declare const JWT: {
24
24
  EXPIRES_AT_KEY: string;
25
25
  CREATED_AT_KEY: string;
26
26
  SCOPES_KEY: string;
27
+ CLIENT_ID_KEY: string;
27
28
  ISSUER: string;
28
29
  };
29
30
  declare const JWT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7\nw5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5\ni1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle\naMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+\nl0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE\nsjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81\nawIDAQAB\n-----END PUBLIC KEY-----";
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
- @versini/auth-common v3.3.0
2
+ @versini/auth-common v3.3.1
3
3
  © 2024 gizmette.com
4
4
  */
5
5
  try {
6
6
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
7
- version: "3.3.0",
8
- buildTime: "07/21/2024 07:33 PM EDT",
7
+ version: "3.3.1",
8
+ buildTime: "08/01/2024 10:23 AM EDT",
9
9
  homepage: "https://github.com/aversini/auth-client",
10
10
  license: "MIT"
11
11
  });
@@ -22,7 +22,7 @@ const je = {
22
22
  CLIENT_ID: "X-Auth-ClientId"
23
23
  }, ne = {
24
24
  ACCESS_TOKEN: "access_token"
25
- }, I = {
25
+ }, P = {
26
26
  ALG: "RS256",
27
27
  USER_ID_KEY: "sub",
28
28
  TOKEN_ID_KEY: "__raw",
@@ -32,6 +32,7 @@ const je = {
32
32
  EXPIRES_AT_KEY: "exp",
33
33
  CREATED_AT_KEY: "iat",
34
34
  SCOPES_KEY: "scopes",
35
+ CLIENT_ID_KEY: "aud",
35
36
  ISSUER: "gizmette.com"
36
37
  }, ae = `-----BEGIN PUBLIC KEY-----
37
38
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
@@ -139,7 +140,7 @@ class se extends A {
139
140
  function m(e, t = "algorithm.name") {
140
141
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
141
142
  }
142
- function v(e, t) {
143
+ function _(e, t) {
143
144
  return e.name === t;
144
145
  }
145
146
  function W(e) {
@@ -172,7 +173,7 @@ function le(e, t, ...r) {
172
173
  case "HS256":
173
174
  case "HS384":
174
175
  case "HS512": {
175
- if (!v(e.algorithm, "HMAC"))
176
+ if (!_(e.algorithm, "HMAC"))
176
177
  throw m("HMAC");
177
178
  const n = parseInt(t.slice(2), 10);
178
179
  if (W(e.algorithm.hash) !== n)
@@ -182,7 +183,7 @@ function le(e, t, ...r) {
182
183
  case "RS256":
183
184
  case "RS384":
184
185
  case "RS512": {
185
- if (!v(e.algorithm, "RSASSA-PKCS1-v1_5"))
186
+ if (!_(e.algorithm, "RSASSA-PKCS1-v1_5"))
186
187
  throw m("RSASSA-PKCS1-v1_5");
187
188
  const n = parseInt(t.slice(2), 10);
188
189
  if (W(e.algorithm.hash) !== n)
@@ -192,7 +193,7 @@ function le(e, t, ...r) {
192
193
  case "PS256":
193
194
  case "PS384":
194
195
  case "PS512": {
195
- if (!v(e.algorithm, "RSA-PSS"))
196
+ if (!_(e.algorithm, "RSA-PSS"))
196
197
  throw m("RSA-PSS");
197
198
  const n = parseInt(t.slice(2), 10);
198
199
  if (W(e.algorithm.hash) !== n)
@@ -207,7 +208,7 @@ function le(e, t, ...r) {
207
208
  case "ES256":
208
209
  case "ES384":
209
210
  case "ES512": {
210
- if (!v(e.algorithm, "ECDSA"))
211
+ if (!_(e.algorithm, "ECDSA"))
211
212
  throw m("ECDSA");
212
213
  const n = de(t);
213
214
  if (e.algorithm.namedCurve !== n)
@@ -352,7 +353,7 @@ const Se = async (e) => {
352
353
  ], a = { ...e };
353
354
  return delete a.alg, delete a.use, O.subtle.importKey("jwk", a, ...n);
354
355
  }, Q = (e) => b(e);
355
- let J, D;
356
+ let D, J;
356
357
  const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j = async (e, t, r, n) => {
357
358
  let a = e.get(t);
358
359
  if (a != null && a[n])
@@ -362,13 +363,13 @@ const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j
362
363
  }, ye = (e, t) => {
363
364
  if (Z(e)) {
364
365
  let r = e.export({ format: "jwk" });
365
- return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Q(r.k) : (D || (D = /* @__PURE__ */ new WeakMap()), j(D, e, r, t));
366
+ return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Q(r.k) : (J || (J = /* @__PURE__ */ new WeakMap()), j(J, e, r, t));
366
367
  }
367
368
  return e;
368
369
  }, Ee = (e, t) => {
369
370
  if (Z(e)) {
370
371
  let r = e.export({ format: "jwk" });
371
- return r.k ? Q(r.k) : (J || (J = /* @__PURE__ */ new WeakMap()), j(J, e, r, t));
372
+ return r.k ? Q(r.k) : (D || (D = /* @__PURE__ */ new WeakMap()), j(D, e, r, t));
372
373
  }
373
374
  return e;
374
375
  }, we = { normalizePublicKey: ye, normalizePrivateKey: Ee }, E = (e, t, r = 0) => {
@@ -450,26 +451,26 @@ async function be(e, t, r) {
450
451
  throw new TypeError('"spki" must be SPKI formatted string');
451
452
  return Ae(e, t);
452
453
  }
453
- const P = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
454
+ const I = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
454
455
  if (!(t instanceof Uint8Array)) {
455
456
  if (!X(t))
456
457
  throw new TypeError(z(e, t, ...R, "Uint8Array"));
457
458
  if (t.type !== "secret")
458
- throw new TypeError(`${P(t)} instances for symmetric algorithms must be of type "secret"`);
459
+ throw new TypeError(`${I(t)} instances for symmetric algorithms must be of type "secret"`);
459
460
  }
460
461
  }, Te = (e, t, r) => {
461
462
  if (!X(t))
462
463
  throw new TypeError(z(e, t, ...R));
463
464
  if (t.type === "secret")
464
- throw new TypeError(`${P(t)} instances for asymmetric algorithms must not be of type "secret"`);
465
+ throw new TypeError(`${I(t)} instances for asymmetric algorithms must not be of type "secret"`);
465
466
  if (t.algorithm && r === "verify" && t.type === "private")
466
- throw new TypeError(`${P(t)} instances for asymmetric algorithm verifying must be of type "public"`);
467
+ throw new TypeError(`${I(t)} instances for asymmetric algorithm verifying must be of type "public"`);
467
468
  if (t.algorithm && r === "encrypt" && t.type === "private")
468
- throw new TypeError(`${P(t)} instances for asymmetric algorithm encryption must be of type "public"`);
469
- }, ve = (e, t, r) => {
469
+ throw new TypeError(`${I(t)} instances for asymmetric algorithm encryption must be of type "public"`);
470
+ }, _e = (e, t, r) => {
470
471
  e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : Te(e, t, r);
471
472
  };
472
- function _e(e, t, r, n, a) {
473
+ function ve(e, t, r, n, a) {
473
474
  if (a.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
474
475
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
475
476
  if (!n || n.crit === void 0)
@@ -488,13 +489,13 @@ function _e(e, t, r, n, a) {
488
489
  }
489
490
  return new Set(n.crit);
490
491
  }
491
- const Pe = (e, t) => {
492
+ const Ie = (e, t) => {
492
493
  if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
493
494
  throw new TypeError(`"${e}" option must be an array of strings`);
494
495
  if (t)
495
496
  return new Set(t);
496
497
  };
497
- function Ie(e, t) {
498
+ function Pe(e, t) {
498
499
  const r = `SHA-${e.slice(-3)}`;
499
500
  switch (e) {
500
501
  case "HS256":
@@ -532,7 +533,7 @@ async function Re(e, t, r) {
532
533
  const Ke = async (e, t, r, n) => {
533
534
  const a = await Re(e, t, "verify");
534
535
  pe(e, a);
535
- const o = Ie(e, a.algorithm);
536
+ const o = Pe(e, a.algorithm);
536
537
  try {
537
538
  return await O.subtle.verify(o, a, r, n);
538
539
  } catch {
@@ -565,14 +566,14 @@ async function Oe(e, t, r) {
565
566
  const a = {
566
567
  ...n,
567
568
  ...e.header
568
- }, o = _e(u, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, a);
569
+ }, o = ve(u, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, a);
569
570
  let i = !0;
570
571
  if (o.has("b64") && (i = n.b64, typeof i != "boolean"))
571
572
  throw new u('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
572
573
  const { alg: c } = a;
573
574
  if (typeof c != "string" || !c)
574
575
  throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
575
- const s = r && Pe("algorithms", r.algorithms);
576
+ const s = r && Ie("algorithms", r.algorithms);
576
577
  if (s && !s.has(c))
577
578
  throw new ce('"alg" (Algorithm) Header Parameter value not allowed');
578
579
  if (i) {
@@ -581,7 +582,7 @@ async function Oe(e, t, r) {
581
582
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
582
583
  throw new u("JWS Payload must be a string or an Uint8Array instance");
583
584
  let p = !1;
584
- typeof t == "function" && (t = await t(n, e), p = !0), ve(c, t, "verify");
585
+ typeof t == "function" && (t = await t(n, e), p = !0), _e(c, t, "verify");
585
586
  const g = oe(T.encode(e.protected ?? ""), T.encode("."), typeof e.payload == "string" ? T.encode(e.payload) : e.payload);
586
587
  let f;
587
588
  try {
@@ -611,7 +612,7 @@ async function xe(e, t, r) {
611
612
  const c = await Oe({ payload: a, protected: n, signature: o }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
612
613
  return typeof t == "function" ? { ...s, key: c.key } : s;
613
614
  }
614
- const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te * 24, Je = N * 7, De = N * 365.25, He = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, M = (e) => {
615
+ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te * 24, De = N * 7, Je = N * 365.25, He = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, M = (e) => {
615
616
  const t = He.exec(e);
616
617
  if (!t || t[4] && t[1])
617
618
  throw new TypeError("Invalid time period format");
@@ -647,10 +648,10 @@ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te *
647
648
  case "week":
648
649
  case "weeks":
649
650
  case "w":
650
- a = Math.round(r * Je);
651
+ a = Math.round(r * De);
651
652
  break;
652
653
  default:
653
- a = Math.round(r * De);
654
+ a = Math.round(r * Je);
654
655
  break;
655
656
  }
656
657
  return t[1] === "-" || t[4] === "ago" ? -a : a;
@@ -751,9 +752,9 @@ function ke(e) {
751
752
  }
752
753
  const Me = async (e) => {
753
754
  try {
754
- const t = I.ALG, n = await be(ae, t);
755
+ const t = P.ALG, n = await be(ae, t);
755
756
  return await $e(e, n, {
756
- issuer: I.ISSUER
757
+ issuer: P.ISSUER
757
758
  });
758
759
  } catch {
759
760
  return;
@@ -771,32 +772,32 @@ for (var H = 0; H < 256; ++H)
771
772
  function Be(e, t = 0) {
772
773
  return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
773
774
  }
774
- var _, Fe = new Uint8Array(16);
775
- function Ve() {
776
- if (!_ && (_ = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !_))
775
+ var v, Ye = new Uint8Array(16);
776
+ function Fe() {
777
+ if (!v && (v = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
777
778
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
778
- return _(Fe);
779
+ return v(Ye);
779
780
  }
780
- var Ye = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
781
- const F = {
782
- randomUUID: Ye
781
+ var Ve = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
782
+ const Y = {
783
+ randomUUID: Ve
783
784
  };
784
- function V(e, t, r) {
785
- if (F.randomUUID && !t && !e)
786
- return F.randomUUID();
785
+ function F(e, t, r) {
786
+ if (Y.randomUUID && !t && !e)
787
+ return Y.randomUUID();
787
788
  e = e || {};
788
- var n = e.random || (e.rng || Ve)();
789
+ var n = e.random || (e.rng || Fe)();
789
790
  return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Be(n);
790
791
  }
791
- const Y = globalThis.crypto, Ge = (e) => `${V()}${V()}`.slice(0, e), qe = (e) => btoa(
792
+ const V = globalThis.crypto, Ge = (e) => `${F()}${F()}`.slice(0, e), qe = (e) => btoa(
792
793
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
793
794
  );
794
795
  async function re(e) {
795
- if (!Y.subtle)
796
+ if (!V.subtle)
796
797
  throw new Error(
797
798
  "crypto.subtle is available only in secure contexts (HTTPS)."
798
799
  );
799
- const t = new TextEncoder().encode(e), r = await Y.subtle.digest("SHA-256", t);
800
+ const t = new TextEncoder().encode(e), r = await V.subtle.digest("SHA-256", t);
800
801
  return qe(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
801
802
  }
802
803
  async function at(e) {
@@ -835,9 +836,9 @@ const ze = /^Bearer (.+)$/i, Xe = (e) => {
835
836
  }, ct = async (e, t) => {
836
837
  var a;
837
838
  const r = await Me(e);
838
- if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[I.SCOPES_KEY]))
839
+ if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[P.SCOPES_KEY]))
839
840
  return !1;
840
- const n = r.payload[I.SCOPES_KEY];
841
+ const n = r.payload[P.SCOPES_KEY];
841
842
  return Array.isArray(t) ? t.every((o) => n.includes(o)) : Object.keys(t).some(
842
843
  (o) => t[o].every((i) => n.includes(i))
843
844
  );
@@ -847,7 +848,7 @@ export {
847
848
  je as AUTH_TYPES,
848
849
  ne as BODY,
849
850
  et as HEADERS,
850
- I as JWT,
851
+ P as JWT,
851
852
  ae as JWT_PUBLIC_KEY,
852
853
  tt as TOKEN_EXPIRATION,
853
854
  nt as decodeToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-common",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -36,5 +36,5 @@
36
36
  "jose": "5.6.3",
37
37
  "uuid": "10.0.0"
38
38
  },
39
- "gitHead": "8df31ef170a75c2983d7ac821fe0371641139815"
39
+ "gitHead": "01228321ca4f7b62244a5dc9b2b001053fd0bba2"
40
40
  }