spooder 4.4.6 → 4.4.8

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.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/package.json +1 -1
  3. package/src/api.ts +8 -4
package/README.md CHANGED
@@ -1306,7 +1306,8 @@ type CookieOptions = {
1306
1306
  http_only?: boolean,
1307
1307
  path?: string,
1308
1308
  expires?: number,
1309
- encode?: boolean
1309
+ encode?: boolean,
1310
+ max_age?: number
1310
1311
  };
1311
1312
  ```
1312
1313
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spooder",
3
3
  "type": "module",
4
- "version": "4.4.6",
4
+ "version": "4.4.8",
5
5
  "exports": {
6
6
  ".": {
7
7
  "bun": "./src/api.ts",
package/src/api.ts CHANGED
@@ -400,13 +400,14 @@ export async function db_init_schema_mysql(db_info: mysql_types.ConnectionOption
400
400
  return await _db_init_schema_mysql(db_info, schema_dir, false) as mysql_types.Connection;
401
401
  }
402
402
 
403
- type CookieOptions = {
403
+ export type CookieOptions = {
404
404
  same_site?: 'Strict' | 'Lax' | 'None',
405
405
  secure?: boolean,
406
406
  http_only?: boolean,
407
407
  path?: string,
408
408
  expires?: number,
409
- encode?: boolean
409
+ encode?: boolean,
410
+ max_age?: number
410
411
  };
411
412
 
412
413
  export function set_cookie(res: Response, name: string, value: string, options?: CookieOptions): void {
@@ -430,6 +431,9 @@ export function set_cookie(res: Response, name: string, value: string, options?:
430
431
  const date = new Date(Date.now() + options.expires);
431
432
  cookie += '; Expires=' + date.toUTCString();
432
433
  }
434
+
435
+ if (options.max_age !== undefined)
436
+ cookie += '; Max-Age=' + options.max_age;
433
437
  } else {
434
438
  cookie += value;
435
439
  }
@@ -547,7 +551,7 @@ function route_directory(route_path: string, dir: string, handler: DirHandler):
547
551
  };
548
552
  }
549
553
 
550
- export function validate_req_json(JSONRequestHandler: JSONRequestHandler): RequestHandler {
554
+ export function validate_req_json(json_handler: JSONRequestHandler): RequestHandler {
551
555
  return async (req: Request, url: URL) => {
552
556
  try {
553
557
  // validate content type header
@@ -560,7 +564,7 @@ export function validate_req_json(JSONRequestHandler: JSONRequestHandler): Reque
560
564
  if (json === null || typeof json !== 'object' || Array.isArray(json))
561
565
  return 400; // Bad Request
562
566
 
563
- return JSONRequestHandler(req, url, json);
567
+ return json_handler(req, url, json);
564
568
  } catch (e) {
565
569
  return 400; // Bad Request
566
570
  }