@wnodex/cookie-parser 0.2.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/.turbo/turbo-build.log +7 -0
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/configure.d.ts +4 -0
- package/dist/configure.d.ts.map +1 -0
- package/dist/configure.js +16 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/parse-options.d.ts +3 -0
- package/dist/parse-options.d.ts.map +1 -0
- package/dist/parse-options.js +8 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +11 -0
- package/package.json +51 -0
- package/rolldown.config.ts +20 -0
- package/src/configure.ts +27 -0
- package/src/index.ts +3 -0
- package/src/parse-options.ts +17 -0
- package/src/schema.ts +21 -0
- package/tsconfig.json +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Davide Di Criscito
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @wnodex/cookie-parser
|
|
2
|
+
|
|
3
|
+
wnodex cookie-parser middleware
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Content
|
|
8
|
+
|
|
9
|
+
- [License](#license)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
This project is licensed under the MIT License.
|
|
16
|
+
|
|
17
|
+
**Copyright (c) 2026 Davide Di Criscito**
|
|
18
|
+
|
|
19
|
+
For the full details, see the [LICENSE](LICENSE) file.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,qBAAqB,GAChC,KAAK,WAAW,EAChB,QAAQ,wBAAwB,4BAiBjC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import cookieParser from 'cookie-parser';
|
|
2
|
+
import { parseCookieParserOptions } from './parse-options.js';
|
|
3
|
+
export const configureCookieParser = (app, config) => {
|
|
4
|
+
const logger = app.get('logger') ?? console;
|
|
5
|
+
const options = parseCookieParserOptions(config);
|
|
6
|
+
if (typeof options === 'boolean') {
|
|
7
|
+
if (!options) {
|
|
8
|
+
logger.info('Cookie parser disabled');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
logger.info('Cookie parser enabled');
|
|
12
|
+
return app.use(cookieParser());
|
|
13
|
+
}
|
|
14
|
+
logger.info('Cookie parser enabled');
|
|
15
|
+
return app.use(cookieParser(options.secret, options.options));
|
|
16
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-options.d.ts","sourceRoot":"","sources":["../src/parse-options.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAE/B,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,wBAAwB,GACnC,UAAU,wBAAwB,KACjC,yBAQF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CookieParserOptionsSchema, } from './schema.js';
|
|
2
|
+
export const parseCookieParserOptions = (options) => {
|
|
3
|
+
const result = CookieParserOptionsSchema.safeParse(options);
|
|
4
|
+
if (!result.success) {
|
|
5
|
+
throw new Error('Invalid cookie-parser options');
|
|
6
|
+
}
|
|
7
|
+
return result.data;
|
|
8
|
+
};
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CookieParseOptions } from 'cookie-parser';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const CookieParserOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
4
|
+
secret: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
5
|
+
options: z.ZodOptional<z.ZodCustom<CookieParseOptions, CookieParseOptions>>;
|
|
6
|
+
}, z.core.$strip>]>>>;
|
|
7
|
+
export type CookieParserOptionsInput = z.input<typeof CookieParserOptionsSchema>;
|
|
8
|
+
export type CookieParserOptionsOutput = z.output<typeof CookieParserOptionsSchema>;
|
|
9
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,yBAAyB;;;qBASrB,CAAC;AAElB,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,yBAAyB,CACjC,CAAC;AACF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAC9C,OAAO,yBAAyB,CACjC,CAAC"}
|
package/dist/schema.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wnodex/cookie-parser",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "wnodex cookie-parser middleware",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"wnodex",
|
|
8
|
+
"cookie-parser"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/wnodex/wnodex#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/wnodex/wnodex/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/wnodex/wnodex.git",
|
|
17
|
+
"directory": "packages/cookie-parser"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@types/express": "^5.0.6",
|
|
34
|
+
"cookie-parser": "^1.4.7",
|
|
35
|
+
"express": "^5.2.1",
|
|
36
|
+
"zod": "^4.3.6"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/cookie-parser": "^1.4.10",
|
|
40
|
+
"@types/node": "^25.0.10",
|
|
41
|
+
"rolldown": "1.0.0-rc.1",
|
|
42
|
+
"typescript": "5.9.2",
|
|
43
|
+
"@wnodex/typescript-config": "0.2.1"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "rolldown -c && tsc"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig } from 'rolldown';
|
|
2
|
+
|
|
3
|
+
export default defineConfig([
|
|
4
|
+
{
|
|
5
|
+
input: ['src/index.ts'],
|
|
6
|
+
output: {
|
|
7
|
+
format: 'esm',
|
|
8
|
+
dir: 'dist',
|
|
9
|
+
entryFileNames: '[name].js',
|
|
10
|
+
chunkFileNames: '[name]-[hash].js',
|
|
11
|
+
assetFileNames: '[name]-[hash][extname]',
|
|
12
|
+
},
|
|
13
|
+
platform: 'node',
|
|
14
|
+
external: (id) => {
|
|
15
|
+
if (id.startsWith('node:')) return true;
|
|
16
|
+
if (id.startsWith('.') || id.startsWith('/')) return false;
|
|
17
|
+
return true;
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
]);
|
package/src/configure.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Application } from 'express';
|
|
2
|
+
|
|
3
|
+
import cookieParser from 'cookie-parser';
|
|
4
|
+
|
|
5
|
+
import { parseCookieParserOptions } from './parse-options.js';
|
|
6
|
+
import { CookieParserOptionsInput } from './schema.js';
|
|
7
|
+
|
|
8
|
+
export const configureCookieParser = (
|
|
9
|
+
app: Application,
|
|
10
|
+
config: CookieParserOptionsInput
|
|
11
|
+
) => {
|
|
12
|
+
const logger = app.get('logger') ?? console;
|
|
13
|
+
const options = parseCookieParserOptions(config);
|
|
14
|
+
|
|
15
|
+
if (typeof options === 'boolean') {
|
|
16
|
+
if (!options) {
|
|
17
|
+
logger.info('Cookie parser disabled');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
logger.info('Cookie parser enabled');
|
|
22
|
+
return app.use(cookieParser());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
logger.info('Cookie parser enabled');
|
|
26
|
+
return app.use(cookieParser(options.secret, options.options));
|
|
27
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CookieParserOptionsInput,
|
|
3
|
+
type CookieParserOptionsOutput,
|
|
4
|
+
CookieParserOptionsSchema,
|
|
5
|
+
} from './schema.js';
|
|
6
|
+
|
|
7
|
+
export const parseCookieParserOptions = (
|
|
8
|
+
options?: CookieParserOptionsInput
|
|
9
|
+
): CookieParserOptionsOutput => {
|
|
10
|
+
const result = CookieParserOptionsSchema.safeParse(options);
|
|
11
|
+
|
|
12
|
+
if (!result.success) {
|
|
13
|
+
throw new Error('Invalid cookie-parser options');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result.data;
|
|
17
|
+
};
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CookieParseOptions } from 'cookie-parser';
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
export const CookieParserOptionsSchema = z
|
|
6
|
+
.union([
|
|
7
|
+
z.boolean(),
|
|
8
|
+
z.object({
|
|
9
|
+
secret: z.union([z.string(), z.array(z.string())]),
|
|
10
|
+
options: z.custom<CookieParseOptions>().optional(),
|
|
11
|
+
}),
|
|
12
|
+
])
|
|
13
|
+
.optional()
|
|
14
|
+
.default(false);
|
|
15
|
+
|
|
16
|
+
export type CookieParserOptionsInput = z.input<
|
|
17
|
+
typeof CookieParserOptionsSchema
|
|
18
|
+
>;
|
|
19
|
+
export type CookieParserOptionsOutput = z.output<
|
|
20
|
+
typeof CookieParserOptionsSchema
|
|
21
|
+
>;
|
package/tsconfig.json
ADDED