expresso-macchiato 1.0.0-dev.5 → 1.0.0-dev.7

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.mts CHANGED
@@ -503,7 +503,7 @@ declare class Token<Payload extends Record<string, any> = DefaultTokenPayload> {
503
503
  private keyStore;
504
504
  constructor(tokenPayload: TokenConstructor);
505
505
  private getKey;
506
- authorize: (req: Request | string) => Promise<Payload>;
506
+ authorize(req: Request): Promise<Payload>;
507
507
  private deriveEncryptionKey;
508
508
  generateJWE(payload: Payload): Promise<string>;
509
509
  verifyJWE(token: string): Promise<Payload>;
package/dist/index.d.ts CHANGED
@@ -503,7 +503,7 @@ declare class Token<Payload extends Record<string, any> = DefaultTokenPayload> {
503
503
  private keyStore;
504
504
  constructor(tokenPayload: TokenConstructor);
505
505
  private getKey;
506
- authorize: (req: Request | string) => Promise<Payload>;
506
+ authorize(req: Request): Promise<Payload>;
507
507
  private deriveEncryptionKey;
508
508
  generateJWE(payload: Payload): Promise<string>;
509
509
  verifyJWE(token: string): Promise<Payload>;
package/dist/index.js CHANGED
@@ -884,25 +884,6 @@ var _nodejose = require('node-jose'); var _nodejose2 = _interopRequireDefault(_n
884
884
  var Token = class {
885
885
  constructor(tokenPayload) {
886
886
  this.keyStore = null;
887
- // Metodo per autorizzare una richiesta
888
- this.authorize = async (req) => {
889
- if (typeof req === "string") {
890
- const payload = await this.verifyJWE(req);
891
- return payload;
892
- } else if (this.TOKEN_COOKIE_NAME) {
893
- const rawCookies = _nullishCoalesce(req.headers.cookie, () => ( ""));
894
- const cookies = _cookie.parse.call(void 0, rawCookies);
895
- const cookieToken = _nullishCoalesce(cookies[this.TOKEN_COOKIE_NAME], () => ( null));
896
- if (cookieToken === null) throw new Error("UNAUTH");
897
- const payload = await this.verifyJWE(cookieToken);
898
- return payload;
899
- } else {
900
- const token = _nullishCoalesce(_optionalChain([req, 'access', _56 => _56.headers, 'access', _57 => _57.authorization, 'optionalAccess', _58 => _58.split, 'call', _59 => _59("Bearer "), 'optionalAccess', _60 => _60[1]]), () => ( null));
901
- if (token === null) throw new Error("UNAUTH");
902
- const payload = await this.verifyJWE(token);
903
- return payload;
904
- }
905
- };
906
887
  if (!tokenPayload.SECRET_KEY) throw new Error("SECRET_KEY is required if you want to use the Token Class");
907
888
  this.SECRET_KEY = tokenPayload.SECRET_KEY;
908
889
  this.TOKEN_COOKIE_NAME = tokenPayload.TOKEN_COOKIE_NAME;
@@ -923,6 +904,22 @@ var Token = class {
923
904
  }
924
905
  return this.keyStore.all({ use: "enc" })[0];
925
906
  }
907
+ // Metodo per autorizzare una richiesta
908
+ async authorize(req) {
909
+ if (this.TOKEN_COOKIE_NAME) {
910
+ const rawCookies = _nullishCoalesce(req.headers.cookie, () => ( ""));
911
+ const cookies = _cookie.parse.call(void 0, rawCookies);
912
+ const cookieToken = _nullishCoalesce(cookies[this.TOKEN_COOKIE_NAME], () => ( null));
913
+ if (cookieToken === null) throw new Error("UNAUTH");
914
+ const payload = await this.verifyJWE(cookieToken);
915
+ return payload;
916
+ } else {
917
+ const token = _nullishCoalesce(_optionalChain([req, 'access', _56 => _56.headers, 'access', _57 => _57.authorization, 'optionalAccess', _58 => _58.split, 'call', _59 => _59("Bearer "), 'optionalAccess', _60 => _60[1]]), () => ( null));
918
+ if (token === null) throw new Error("UNAUTH");
919
+ const payload = await this.verifyJWE(token);
920
+ return payload;
921
+ }
922
+ }
926
923
  // Metodo per derivare chiave di cifratura
927
924
  deriveEncryptionKey() {
928
925
  return _crypto2.default.createHash("sha256").update(this.SECRET_KEY).digest().slice(0, this.KeyLength);
package/dist/index.mjs CHANGED
@@ -884,25 +884,6 @@ import jose from "node-jose";
884
884
  var Token = class {
885
885
  constructor(tokenPayload) {
886
886
  this.keyStore = null;
887
- // Metodo per autorizzare una richiesta
888
- this.authorize = async (req) => {
889
- if (typeof req === "string") {
890
- const payload = await this.verifyJWE(req);
891
- return payload;
892
- } else if (this.TOKEN_COOKIE_NAME) {
893
- const rawCookies = req.headers.cookie ?? "";
894
- const cookies = parse(rawCookies);
895
- const cookieToken = cookies[this.TOKEN_COOKIE_NAME] ?? null;
896
- if (cookieToken === null) throw new Error("UNAUTH");
897
- const payload = await this.verifyJWE(cookieToken);
898
- return payload;
899
- } else {
900
- const token = req.headers.authorization?.split("Bearer ")?.[1] ?? null;
901
- if (token === null) throw new Error("UNAUTH");
902
- const payload = await this.verifyJWE(token);
903
- return payload;
904
- }
905
- };
906
887
  if (!tokenPayload.SECRET_KEY) throw new Error("SECRET_KEY is required if you want to use the Token Class");
907
888
  this.SECRET_KEY = tokenPayload.SECRET_KEY;
908
889
  this.TOKEN_COOKIE_NAME = tokenPayload.TOKEN_COOKIE_NAME;
@@ -923,6 +904,22 @@ var Token = class {
923
904
  }
924
905
  return this.keyStore.all({ use: "enc" })[0];
925
906
  }
907
+ // Metodo per autorizzare una richiesta
908
+ async authorize(req) {
909
+ if (this.TOKEN_COOKIE_NAME) {
910
+ const rawCookies = req.headers.cookie ?? "";
911
+ const cookies = parse(rawCookies);
912
+ const cookieToken = cookies[this.TOKEN_COOKIE_NAME] ?? null;
913
+ if (cookieToken === null) throw new Error("UNAUTH");
914
+ const payload = await this.verifyJWE(cookieToken);
915
+ return payload;
916
+ } else {
917
+ const token = req.headers.authorization?.split("Bearer ")?.[1] ?? null;
918
+ if (token === null) throw new Error("UNAUTH");
919
+ const payload = await this.verifyJWE(token);
920
+ return payload;
921
+ }
922
+ }
926
923
  // Metodo per derivare chiave di cifratura
927
924
  deriveEncryptionKey() {
928
925
  return crypto.createHash("sha256").update(this.SECRET_KEY).digest().slice(0, this.KeyLength);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expresso-macchiato",
3
- "version": "1.0.0-dev.5",
3
+ "version": "1.0.0-dev.7",
4
4
  "author": "Alessio Velluso",
5
5
  "license": "MIT",
6
6
  "description": "Description",