@veloxts/auth 0.4.0 → 0.4.2

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,61 @@
1
+ /**
2
+ * Cookie Plugin Support Utilities
3
+ *
4
+ * Shared type guards and utilities for @fastify/cookie plugin detection.
5
+ * Used by both session and CSRF modules.
6
+ *
7
+ * @module auth/utils/cookie-support
8
+ */
9
+ import type { FastifyReply, FastifyRequest } from 'fastify';
10
+ /**
11
+ * Cookie serialization options (mirrors @fastify/cookie types)
12
+ */
13
+ export interface CookieSerializeOptions {
14
+ domain?: string;
15
+ path?: string;
16
+ sameSite?: 'strict' | 'lax' | 'none' | boolean;
17
+ secure?: boolean;
18
+ httpOnly?: boolean;
19
+ maxAge?: number;
20
+ expires?: Date;
21
+ }
22
+ /**
23
+ * Fastify reply with cookie methods from @fastify/cookie plugin
24
+ */
25
+ export interface FastifyReplyWithCookies extends FastifyReply {
26
+ cookie(name: string, value: string, options?: CookieSerializeOptions): FastifyReply;
27
+ clearCookie(name: string, options?: CookieSerializeOptions): FastifyReply;
28
+ }
29
+ /**
30
+ * Fastify request with cookies from @fastify/cookie plugin
31
+ */
32
+ export interface FastifyRequestWithCookies extends FastifyRequest {
33
+ cookies: Record<string, string | undefined>;
34
+ }
35
+ /**
36
+ * Check if request has cookie support from @fastify/cookie plugin
37
+ */
38
+ export declare function hasCookieSupport(request: FastifyRequest): request is FastifyRequestWithCookies;
39
+ /**
40
+ * Check if reply has cookie methods from @fastify/cookie plugin
41
+ */
42
+ export declare function hasReplyCookieSupport(reply: FastifyReply): reply is FastifyReplyWithCookies;
43
+ /**
44
+ * Options for cookie context validation
45
+ */
46
+ export interface CookieContextValidationOptions {
47
+ /**
48
+ * Name of the middleware requiring cookies (for error message)
49
+ * @default 'This middleware'
50
+ */
51
+ middlewareName?: string;
52
+ }
53
+ /**
54
+ * Get request and reply with validated cookie support
55
+ * @throws Error with helpful message if @fastify/cookie plugin is not registered
56
+ */
57
+ export declare function getValidatedCookieContext(request: FastifyRequest, reply: FastifyReply, options?: CookieContextValidationOptions): {
58
+ request: FastifyRequestWithCookies;
59
+ reply: FastifyReplyWithCookies;
60
+ };
61
+ //# sourceMappingURL=cookie-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-support.d.ts","sourceRoot":"","sources":["../../src/utils/cookie-support.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM5D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,YAAY;IAC3D,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,YAAY,CAAC;IACpF,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,YAAY,CAAC;CAC3E;AAED;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC7C;AAMD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,IAAI,yBAAyB,CAE9F;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,uBAAuB,CAE3F;AAMD;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,EACnB,OAAO,GAAE,8BAAmC,GAC3C;IAAE,OAAO,EAAE,yBAAyB,CAAC;IAAC,KAAK,EAAE,uBAAuB,CAAA;CAAE,CAYxE"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Cookie Plugin Support Utilities
3
+ *
4
+ * Shared type guards and utilities for @fastify/cookie plugin detection.
5
+ * Used by both session and CSRF modules.
6
+ *
7
+ * @module auth/utils/cookie-support
8
+ */
9
+ // ============================================================================
10
+ // Type Guards
11
+ // ============================================================================
12
+ /**
13
+ * Check if request has cookie support from @fastify/cookie plugin
14
+ */
15
+ export function hasCookieSupport(request) {
16
+ return 'cookies' in request && request.cookies !== null && typeof request.cookies === 'object';
17
+ }
18
+ /**
19
+ * Check if reply has cookie methods from @fastify/cookie plugin
20
+ */
21
+ export function hasReplyCookieSupport(reply) {
22
+ return 'cookie' in reply && typeof reply.cookie === 'function';
23
+ }
24
+ /**
25
+ * Get request and reply with validated cookie support
26
+ * @throws Error with helpful message if @fastify/cookie plugin is not registered
27
+ */
28
+ export function getValidatedCookieContext(request, reply, options = {}) {
29
+ const middlewareName = options.middlewareName ?? 'This middleware';
30
+ if (!hasCookieSupport(request) || !hasReplyCookieSupport(reply)) {
31
+ throw new Error(`${middlewareName} requires @fastify/cookie plugin. ` +
32
+ 'Please register it before using this middleware:\n\n' +
33
+ " import cookie from '@fastify/cookie';\n" +
34
+ ' await app.register(cookie);\n');
35
+ }
36
+ return { request, reply };
37
+ }
38
+ //# sourceMappingURL=cookie-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-support.js","sourceRoot":"","sources":["../../src/utils/cookie-support.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoCH,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACtD,OAAO,SAAS,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC;AACjG,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAmB;IACvD,OAAO,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,CAAC;AACjE,CAAC;AAiBD;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAuB,EACvB,KAAmB,EACnB,UAA0C,EAAE;IAE5C,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,iBAAiB,CAAC;IAEnE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CACb,GAAG,cAAc,oCAAoC;YACnD,sDAAsD;YACtD,2CAA2C;YAC3C,iCAAiC,CACpC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/auth",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Authentication and authorization system for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,8 +42,8 @@
42
42
  "dependencies": {
43
43
  "@fastify/cookie": "11.0.2",
44
44
  "fastify": "5.6.2",
45
- "@veloxts/core": "0.4.0",
46
- "@veloxts/router": "0.4.0"
45
+ "@veloxts/core": "0.4.2",
46
+ "@veloxts/router": "0.4.2"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "argon2": ">=0.30.0",
@@ -67,8 +67,8 @@
67
67
  "fastify-plugin": "5.1.0",
68
68
  "typescript": "5.9.3",
69
69
  "vitest": "4.0.15",
70
- "@veloxts/testing": "0.1.0",
71
- "@veloxts/validation": "0.4.0"
70
+ "@veloxts/testing": "0.1.2",
71
+ "@veloxts/validation": "0.4.2"
72
72
  },
73
73
  "keywords": [
74
74
  "velox",