@wnodex/session 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.
@@ -0,0 +1,7 @@
1
+
2
+ > @wnodex/session@0.2.1 build /home/runner/work/wnodex/wnodex/packages/session
3
+ > rolldown -c && tsc
4
+
5
+ [log] <DIR>/index.js chunk │ size: 1.95 kB
6
+ [log]
7
+ [success] rolldown v1.0.0-rc.1 Finished in 25.93 ms
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/session
2
+
3
+ wnodex session 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,4 @@
1
+ import type { Application } from 'express';
2
+ import { SessionOptionsInput } from './schema.js';
3
+ export declare const configureSession: (app: Application, config: SessionOptionsInput) => Application | undefined;
4
+ //# sourceMappingURL=configure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,gBAAgB,GAC3B,KAAK,WAAW,EAChB,QAAQ,mBAAmB,4BAa5B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import session from 'express-session';
2
+ import { parseSessionOptions } from './parse-options.js';
3
+ export const configureSession = (app, config) => {
4
+ const logger = app.get('logger') ?? console;
5
+ const options = parseSessionOptions(config);
6
+ if (typeof options === 'boolean') {
7
+ logger.info('Session disabled');
8
+ return;
9
+ }
10
+ logger.info('Session enabled');
11
+ return app.use(session({ ...options }));
12
+ };
@@ -0,0 +1,6 @@
1
+ export declare const DEFAULT_SESSION_COOKIE_MAX_AGE: number;
2
+ export declare const DEFAULT_SESSION_COOKIE_SECURE: boolean;
3
+ export declare const DEFAULT_SESSION_COOKIE_HTTP_ONLY = true;
4
+ export declare const DEFAULT_SESSION_RESAVE = false;
5
+ export declare const DEFAULT_SESSION_SAVE_UNINITIALIZED = false;
6
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,QAAsB,CAAC;AAClE,eAAO,MAAM,6BAA6B,SACH,CAAC;AACxC,eAAO,MAAM,gCAAgC,OAAO,CAAC;AACrD,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,kCAAkC,QAAQ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const DEFAULT_SESSION_COOKIE_MAX_AGE = 1000 * 60 * 60 * 24; // 1 day
2
+ export const DEFAULT_SESSION_COOKIE_SECURE = process.env.NODE_ENV === 'production';
3
+ export const DEFAULT_SESSION_COOKIE_HTTP_ONLY = true;
4
+ export const DEFAULT_SESSION_RESAVE = false;
5
+ export const DEFAULT_SESSION_SAVE_UNINITIALIZED = false;
@@ -0,0 +1,5 @@
1
+ export * from './configure.js';
2
+ export * from './defaults.js';
3
+ export * from './parse-options.js';
4
+ export * from './schema.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './configure.js';
2
+ export * from './defaults.js';
3
+ export * from './parse-options.js';
4
+ export * from './schema.js';
@@ -0,0 +1,3 @@
1
+ import { type SessionOptionsInput, type SessionOptionsOutput } from './schema.js';
2
+ export declare const parseSessionOptions: (options?: SessionOptionsInput) => SessionOptionsOutput;
3
+ //# sourceMappingURL=parse-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-options.d.ts","sourceRoot":"","sources":["../src/parse-options.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAE1B,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,mBAAmB,GAC9B,UAAU,mBAAmB,KAC5B,oBAQF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { SessionOptionsSchema, } from './schema.js';
2
+ export const parseSessionOptions = (options) => {
3
+ const result = SessionOptionsSchema.safeParse(options);
4
+ if (!result.success) {
5
+ throw new Error('Invalid session options');
6
+ }
7
+ return result.data;
8
+ };
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ export declare const SessionCookieSchema: z.ZodDefault<z.ZodOptional<z.ZodObject<{
3
+ secure: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
4
+ maxAge: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
5
+ httpOnly: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
6
+ }, z.core.$strip>>>;
7
+ export declare const SessionOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
8
+ secret: z.ZodString;
9
+ resave: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
10
+ saveUninitialized: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
11
+ cookie: z.ZodDefault<z.ZodOptional<z.ZodObject<{
12
+ secure: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
13
+ maxAge: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
14
+ httpOnly: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
15
+ }, z.core.$strip>>>;
16
+ }, z.core.$strip>]>>>;
17
+ export type SessionOptions = z.infer<typeof SessionOptionsSchema>;
18
+ export type SessionOptionsInput = z.input<typeof SessionOptionsSchema>;
19
+ export type SessionOptionsOutput = z.output<typeof SessionOptionsSchema>;
20
+ export type SessionCookie = z.infer<typeof SessionCookieSchema>;
21
+ export type SessionCookieInput = z.input<typeof SessionCookieSchema>;
22
+ export type SessionCookieOutput = z.output<typeof SessionCookieSchema>;
23
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,eAAO,MAAM,mBAAmB;;;;mBAW5B,CAAC;AAEL,eAAO,MAAM,oBAAoB;;;;;;;;;qBAchB,CAAC;AAElB,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACvE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEzE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACrE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import { DEFAULT_SESSION_COOKIE_HTTP_ONLY, DEFAULT_SESSION_COOKIE_MAX_AGE, DEFAULT_SESSION_COOKIE_SECURE, DEFAULT_SESSION_RESAVE, DEFAULT_SESSION_SAVE_UNINITIALIZED, } from './defaults.js';
3
+ export const SessionCookieSchema = z
4
+ .object({
5
+ secure: z.boolean().optional().default(DEFAULT_SESSION_COOKIE_SECURE),
6
+ maxAge: z.number().optional().default(DEFAULT_SESSION_COOKIE_MAX_AGE),
7
+ httpOnly: z.boolean().optional().default(DEFAULT_SESSION_COOKIE_HTTP_ONLY),
8
+ })
9
+ .optional()
10
+ .default({
11
+ secure: DEFAULT_SESSION_COOKIE_SECURE,
12
+ maxAge: DEFAULT_SESSION_COOKIE_MAX_AGE,
13
+ httpOnly: DEFAULT_SESSION_COOKIE_HTTP_ONLY,
14
+ });
15
+ export const SessionOptionsSchema = z
16
+ .union([
17
+ z.literal(false),
18
+ z.object({
19
+ secret: z.string(),
20
+ resave: z.boolean().optional().default(DEFAULT_SESSION_RESAVE),
21
+ saveUninitialized: z
22
+ .boolean()
23
+ .optional()
24
+ .default(DEFAULT_SESSION_SAVE_UNINITIALIZED),
25
+ cookie: SessionCookieSchema,
26
+ }),
27
+ ])
28
+ .optional()
29
+ .default(false);
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@wnodex/session",
3
+ "version": "0.2.1",
4
+ "private": false,
5
+ "description": "wnodex session middleware",
6
+ "keywords": [
7
+ "wnodex"
8
+ ],
9
+ "homepage": "https://github.com/wnodex/wnodex#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/wnodex/wnodex/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/wnodex/wnodex.git",
16
+ "directory": "packages/session"
17
+ },
18
+ "license": "MIT",
19
+ "type": "module",
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "main": "./dist/index.js",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "dependencies": {
32
+ "express": "^5.2.1",
33
+ "express-session": "^1.19.0",
34
+ "zod": "^4.3.6"
35
+ },
36
+ "devDependencies": {
37
+ "@types/express": "^5.0.6",
38
+ "@types/express-session": "^1.18.2",
39
+ "@types/node": "^25.0.10",
40
+ "rolldown": "1.0.0-rc.1",
41
+ "typescript": "5.9.2",
42
+ "@wnodex/typescript-config": "0.2.1"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "scripts": {
48
+ "build": "rolldown -c && tsc"
49
+ }
50
+ }
@@ -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
+ ]);
@@ -0,0 +1,23 @@
1
+ import type { Application } from 'express';
2
+
3
+ import session from 'express-session';
4
+
5
+ import { parseSessionOptions } from './parse-options.js';
6
+ import { SessionOptionsInput } from './schema.js';
7
+
8
+ export const configureSession = (
9
+ app: Application,
10
+ config: SessionOptionsInput
11
+ ) => {
12
+ const logger = app.get('logger') ?? console;
13
+ const options = parseSessionOptions(config);
14
+
15
+ if (typeof options === 'boolean') {
16
+ logger.info('Session disabled');
17
+
18
+ return;
19
+ }
20
+
21
+ logger.info('Session enabled');
22
+ return app.use(session({ ...options }));
23
+ };
@@ -0,0 +1,6 @@
1
+ export const DEFAULT_SESSION_COOKIE_MAX_AGE = 1000 * 60 * 60 * 24; // 1 day
2
+ export const DEFAULT_SESSION_COOKIE_SECURE =
3
+ process.env.NODE_ENV === 'production';
4
+ export const DEFAULT_SESSION_COOKIE_HTTP_ONLY = true;
5
+ export const DEFAULT_SESSION_RESAVE = false;
6
+ export const DEFAULT_SESSION_SAVE_UNINITIALIZED = false;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './configure.js';
2
+ export * from './defaults.js';
3
+ export * from './parse-options.js';
4
+ export * from './schema.js';
@@ -0,0 +1,17 @@
1
+ import {
2
+ type SessionOptionsInput,
3
+ type SessionOptionsOutput,
4
+ SessionOptionsSchema,
5
+ } from './schema.js';
6
+
7
+ export const parseSessionOptions = (
8
+ options?: SessionOptionsInput
9
+ ): SessionOptionsOutput => {
10
+ const result = SessionOptionsSchema.safeParse(options);
11
+
12
+ if (!result.success) {
13
+ throw new Error('Invalid session options');
14
+ }
15
+
16
+ return result.data;
17
+ };
package/src/schema.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+
3
+ import {
4
+ DEFAULT_SESSION_COOKIE_HTTP_ONLY,
5
+ DEFAULT_SESSION_COOKIE_MAX_AGE,
6
+ DEFAULT_SESSION_COOKIE_SECURE,
7
+ DEFAULT_SESSION_RESAVE,
8
+ DEFAULT_SESSION_SAVE_UNINITIALIZED,
9
+ } from './defaults.js';
10
+
11
+ export const SessionCookieSchema = z
12
+ .object({
13
+ secure: z.boolean().optional().default(DEFAULT_SESSION_COOKIE_SECURE),
14
+ maxAge: z.number().optional().default(DEFAULT_SESSION_COOKIE_MAX_AGE),
15
+ httpOnly: z.boolean().optional().default(DEFAULT_SESSION_COOKIE_HTTP_ONLY),
16
+ })
17
+ .optional()
18
+ .default({
19
+ secure: DEFAULT_SESSION_COOKIE_SECURE,
20
+ maxAge: DEFAULT_SESSION_COOKIE_MAX_AGE,
21
+ httpOnly: DEFAULT_SESSION_COOKIE_HTTP_ONLY,
22
+ });
23
+
24
+ export const SessionOptionsSchema = z
25
+ .union([
26
+ z.literal(false),
27
+ z.object({
28
+ secret: z.string(),
29
+ resave: z.boolean().optional().default(DEFAULT_SESSION_RESAVE),
30
+ saveUninitialized: z
31
+ .boolean()
32
+ .optional()
33
+ .default(DEFAULT_SESSION_SAVE_UNINITIALIZED),
34
+ cookie: SessionCookieSchema,
35
+ }),
36
+ ])
37
+ .optional()
38
+ .default(false);
39
+
40
+ export type SessionOptions = z.infer<typeof SessionOptionsSchema>;
41
+ export type SessionOptionsInput = z.input<typeof SessionOptionsSchema>;
42
+ export type SessionOptionsOutput = z.output<typeof SessionOptionsSchema>;
43
+
44
+ export type SessionCookie = z.infer<typeof SessionCookieSchema>;
45
+ export type SessionCookieInput = z.input<typeof SessionCookieSchema>;
46
+ export type SessionCookieOutput = z.output<typeof SessionCookieSchema>;
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@wnodex/typescript-config/base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "tsBuildInfoFile": "./dist/.tsbuildinfo"
7
+ },
8
+ "include": ["src/**/*"],
9
+ "exclude": ["node_modules", "**/*.test.ts"]
10
+ }