expresso-macchiato 1.0.0-dev.4 → 1.0.0-dev.6

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
@@ -495,15 +495,15 @@ declare class SocketWrapper<Metadata extends Record<string, any> = any> {
495
495
  }
496
496
 
497
497
  declare class Token<Payload extends Record<string, any> = DefaultTokenPayload> {
498
+ readonly TOKEN_COOKIE_NAME: string | undefined;
498
499
  private SECRET_KEY;
499
- private TOKEN_COOKIE_NAME;
500
500
  private ExpTime;
501
501
  private EncAlgorithm;
502
502
  private KeyLength;
503
503
  private keyStore;
504
504
  constructor(tokenPayload: TokenConstructor);
505
505
  private getKey;
506
- authorize: (req: Request | string) => Promise<Payload>;
506
+ authorize(req: Request | string): 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
@@ -495,15 +495,15 @@ declare class SocketWrapper<Metadata extends Record<string, any> = any> {
495
495
  }
496
496
 
497
497
  declare class Token<Payload extends Record<string, any> = DefaultTokenPayload> {
498
+ readonly TOKEN_COOKIE_NAME: string | undefined;
498
499
  private SECRET_KEY;
499
- private TOKEN_COOKIE_NAME;
500
500
  private ExpTime;
501
501
  private EncAlgorithm;
502
502
  private KeyLength;
503
503
  private keyStore;
504
504
  constructor(tokenPayload: TokenConstructor);
505
505
  private getKey;
506
- authorize: (req: Request | string) => Promise<Payload>;
506
+ authorize(req: Request | string): 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,25 @@ 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 (typeof req === "string") {
910
+ const payload = await this.verifyJWE(req);
911
+ return payload;
912
+ } else if (this.TOKEN_COOKIE_NAME) {
913
+ const rawCookies = _nullishCoalesce(req.headers.cookie, () => ( ""));
914
+ const cookies = _cookie.parse.call(void 0, rawCookies);
915
+ const cookieToken = _nullishCoalesce(cookies[this.TOKEN_COOKIE_NAME], () => ( null));
916
+ if (cookieToken === null) throw new Error("UNAUTH");
917
+ const payload = await this.verifyJWE(cookieToken);
918
+ return payload;
919
+ } else {
920
+ 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));
921
+ if (token === null) throw new Error("UNAUTH");
922
+ const payload = await this.verifyJWE(token);
923
+ return payload;
924
+ }
925
+ }
926
926
  // Metodo per derivare chiave di cifratura
927
927
  deriveEncryptionKey() {
928
928
  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,25 @@ 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 (typeof req === "string") {
910
+ const payload = await this.verifyJWE(req);
911
+ return payload;
912
+ } else if (this.TOKEN_COOKIE_NAME) {
913
+ const rawCookies = req.headers.cookie ?? "";
914
+ const cookies = parse(rawCookies);
915
+ const cookieToken = cookies[this.TOKEN_COOKIE_NAME] ?? null;
916
+ if (cookieToken === null) throw new Error("UNAUTH");
917
+ const payload = await this.verifyJWE(cookieToken);
918
+ return payload;
919
+ } else {
920
+ const token = req.headers.authorization?.split("Bearer ")?.[1] ?? null;
921
+ if (token === null) throw new Error("UNAUTH");
922
+ const payload = await this.verifyJWE(token);
923
+ return payload;
924
+ }
925
+ }
926
926
  // Metodo per derivare chiave di cifratura
927
927
  deriveEncryptionKey() {
928
928
  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.4",
3
+ "version": "1.0.0-dev.6",
4
4
  "author": "Alessio Velluso",
5
5
  "license": "MIT",
6
6
  "description": "Description",