@syntay/fastay 0.2.6 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAOvE,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,IAC1D,KAAK,WAAW,UASzB;AAED,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,WAAW,iBA2B3D"}
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAOvE,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,IAE1D,KAAK,WAAW,UASzB;AAED,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,WAAW,iBA2B3D"}
@@ -25,6 +25,7 @@ import { wrapMiddleware } from './utils/wrapMiddleware.js';
25
25
  * ```
26
26
  */
27
27
  export function createMiddleware(map) {
28
+ logger.info('Loading Fastay core middleware...');
28
29
  return (app) => {
29
30
  for (const [route, middlewares] of Object.entries(map)) {
30
31
  for (const mw of middlewares) {
@@ -1,18 +1,20 @@
1
- import { ServerResponse } from 'http';
1
+ import { ServerResponse } from "http";
2
2
  export declare class RequestCookies {
3
3
  private cookies;
4
- private setCookies;
4
+ setCookies: string[];
5
5
  constructor(cookieHeader?: string);
6
6
  get(name: string): {
7
7
  value: string;
8
8
  } | undefined;
9
9
  has(name: string): boolean;
10
- all(): Record<string, string>;
10
+ all(): {
11
+ [x: string]: string | undefined;
12
+ };
11
13
  set(name: string, value: string, options?: {
12
14
  path?: string;
13
15
  httpOnly?: boolean;
14
16
  secure?: boolean;
15
- sameSite?: 'Lax' | 'Strict' | 'None';
17
+ sameSite?: 'lax' | 'strict' | 'none';
16
18
  domain?: string;
17
19
  maxAge?: number;
18
20
  }): void;
@@ -21,7 +23,6 @@ export declare class RequestCookies {
21
23
  domain?: string;
22
24
  }): void;
23
25
  clear(): void;
24
- toString(): string;
25
26
  applyToResponse(res: ServerResponse): void;
26
27
  }
27
28
  export declare const cookies: typeof RequestCookies;
@@ -1 +1 @@
1
- {"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/utils/cookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAE,MAAM,MAAM,CAAC;AAEvD,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,UAAU,CAAgB;gBAEtB,YAAY,CAAC,EAAE,MAAM;IAU1B,GAAG,CAAC,IAAI,EAAE,MAAM;;;IAMhB,GAAG,CAAC,IAAI,EAAE,MAAM;IAIhB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eR,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAWrE,KAAK;IAIL,eAAe,CAAC,GAAG,EAAE,cAAc;CAOpC;AAED,eAAO,MAAM,OAAO,uBAAiB,CAAC"}
@@ -1,63 +1,49 @@
1
+ import { parse, serialize } from "cookie";
1
2
  export class RequestCookies {
2
3
  constructor(cookieHeader) {
3
- this.cookies = new Map();
4
- this.setCookies = []; // para armazenar cookies que serão enviados no response
5
- if (!cookieHeader)
6
- return;
7
- cookieHeader.split(';').forEach((cookie) => {
8
- const [name, ...rest] = cookie.trim().split('=');
9
- if (!name)
10
- return;
11
- this.cookies.set(name, decodeURIComponent(rest.join('=')));
12
- });
4
+ this.setCookies = [];
5
+ this.cookies = cookieHeader ? parse(cookieHeader) : {};
13
6
  }
14
7
  get(name) {
15
- const value = this.cookies.get(name);
16
- if (!value)
17
- return undefined;
18
- return { value };
8
+ const value = this.cookies[name];
9
+ return value ? { value } : undefined;
19
10
  }
20
11
  has(name) {
21
- return this.cookies.has(name);
12
+ return this.cookies[name] !== undefined;
22
13
  }
23
14
  all() {
24
- const obj = {};
25
- this.cookies.forEach((v, k) => (obj[k] = v));
26
- return obj;
15
+ return { ...this.cookies };
27
16
  }
28
17
  set(name, value, options = {}) {
29
- let cookieStr = `${name}=${encodeURIComponent(value)}`;
30
- if (options.path)
31
- cookieStr += `; Path=${options.path}`;
32
- if (options.httpOnly)
33
- cookieStr += `; HttpOnly`;
34
- if (options.secure)
35
- cookieStr += `; Secure`;
36
- if (options.sameSite)
37
- cookieStr += `; SameSite=${options.sameSite}`;
38
- if (options.domain)
39
- cookieStr += `; Domain=${options.domain}`;
40
- if (options.maxAge)
41
- cookieStr += `; Max-Age=${options.maxAge}`;
18
+ const cookieStr = serialize(name, value, {
19
+ path: options.path,
20
+ httpOnly: options.httpOnly,
21
+ secure: options.secure,
22
+ sameSite: options.sameSite,
23
+ domain: options.domain,
24
+ maxAge: options.maxAge,
25
+ });
42
26
  this.setCookies.push(cookieStr);
43
- this.cookies.set(name, value);
27
+ this.cookies[name] = value;
44
28
  }
45
29
  delete(name, options = {}) {
46
- this.set(name, '', {
30
+ const cookieStr = serialize(name, "", {
47
31
  path: options.path,
48
32
  domain: options.domain,
49
33
  maxAge: 0,
50
34
  });
51
- this.cookies.delete(name);
35
+ this.setCookies.push(cookieStr);
36
+ delete this.cookies[name];
52
37
  }
53
38
  clear() {
54
- this.cookies.forEach((_, name) => this.delete(name));
55
- }
56
- toString() {
57
- return this.setCookies.join('; ');
39
+ Object.keys(this.cookies).forEach((name) => this.delete(name));
58
40
  }
59
41
  applyToResponse(res) {
60
- this.setCookies.forEach((c) => res.setHeader('Set-Cookie', c));
42
+ for (const c of this.setCookies) {
43
+ res.appendHeader
44
+ ? res.appendHeader("Set-Cookie", c)
45
+ : res.setHeader("Set-Cookie", c);
46
+ }
61
47
  }
62
48
  }
63
49
  export const cookies = RequestCookies;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syntay/fastay",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Framework backend moderno baseado em Express.js, para criar APIs rapidamente",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,12 +27,11 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "files": [
31
- "dist"
32
- ],
30
+ "files": ["dist"],
33
31
  "dependencies": {
34
32
  "busboy": "^1.6.0",
35
33
  "chokidar": "^4.0.3",
34
+ "cookie": "^1.0.2",
36
35
  "express": "^5.1.0",
37
36
  "import-fresh": "^3.3.1",
38
37
  "pino": "^10.1.0",