@nauth-toolkit/nestjs 0.1.14 → 0.1.18
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/dist/auth.module.d.ts +48 -0
- package/dist/auth.module.d.ts.map +1 -1
- package/dist/auth.module.js +161 -19
- package/dist/auth.module.js.map +1 -1
- package/dist/decorators/client-info.decorator.d.ts +39 -0
- package/dist/decorators/client-info.decorator.d.ts.map +1 -1
- package/dist/decorators/client-info.decorator.js +41 -0
- package/dist/decorators/client-info.decorator.js.map +1 -1
- package/dist/decorators/current-user.decorator.d.ts +6 -0
- package/dist/decorators/current-user.decorator.d.ts.map +1 -1
- package/dist/decorators/current-user.decorator.js +6 -0
- package/dist/decorators/current-user.decorator.js.map +1 -1
- package/dist/decorators/public.decorator.d.ts +7 -0
- package/dist/decorators/public.decorator.d.ts.map +1 -1
- package/dist/decorators/public.decorator.js +7 -0
- package/dist/decorators/public.decorator.js.map +1 -1
- package/dist/decorators/token-delivery.decorator.d.ts +20 -0
- package/dist/decorators/token-delivery.decorator.d.ts.map +1 -1
- package/dist/dto/index.d.ts +9 -0
- package/dist/dto/index.d.ts.map +1 -1
- package/dist/dto/index.js +10 -0
- package/dist/dto/index.js.map +1 -1
- package/dist/factories/storage-adapter.factory.d.ts +107 -0
- package/dist/factories/storage-adapter.factory.d.ts.map +1 -1
- package/dist/factories/storage-adapter.factory.js +129 -0
- package/dist/factories/storage-adapter.factory.js.map +1 -1
- package/dist/filters/nauth-http-exception.filter.d.ts +80 -0
- package/dist/filters/nauth-http-exception.filter.d.ts.map +1 -1
- package/dist/filters/nauth-http-exception.filter.js +96 -0
- package/dist/filters/nauth-http-exception.filter.js.map +1 -1
- package/dist/guards/auth.guard.d.ts +26 -0
- package/dist/guards/auth.guard.d.ts.map +1 -1
- package/dist/guards/auth.guard.js +44 -0
- package/dist/guards/auth.guard.js.map +1 -1
- package/dist/guards/csrf.guard.d.ts +21 -0
- package/dist/guards/csrf.guard.d.ts.map +1 -1
- package/dist/guards/csrf.guard.js +30 -1
- package/dist/guards/csrf.guard.js.map +1 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -1
- package/dist/interceptors/client-info.interceptor.d.ts +37 -0
- package/dist/interceptors/client-info.interceptor.d.ts.map +1 -1
- package/dist/interceptors/client-info.interceptor.js +89 -1
- package/dist/interceptors/client-info.interceptor.js.map +1 -1
- package/dist/interceptors/cookie-token.interceptor.d.ts +16 -0
- package/dist/interceptors/cookie-token.interceptor.d.ts.map +1 -1
- package/dist/interceptors/cookie-token.interceptor.js +61 -2
- package/dist/interceptors/cookie-token.interceptor.js.map +1 -1
- package/dist/providers/nestjs-logger.adapter.d.ts +96 -0
- package/dist/providers/nestjs-logger.adapter.d.ts.map +1 -1
- package/dist/providers/nestjs-logger.adapter.js +105 -1
- package/dist/providers/nestjs-logger.adapter.js.map +1 -1
- package/dist/services/csrf.service.d.ts +61 -0
- package/dist/services/csrf.service.d.ts.map +1 -1
- package/dist/services/csrf.service.js +62 -1
- package/dist/services/csrf.service.js.map +1 -1
- package/dist/services/migrations-bootstrap.service.d.ts +6 -0
- package/dist/services/migrations-bootstrap.service.d.ts.map +1 -1
- package/dist/services/migrations-bootstrap.service.js +6 -0
- package/dist/services/migrations-bootstrap.service.js.map +1 -1
- package/package.json +7 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csrf.guard.d.ts","sourceRoot":"","sources":["../../src/guards/csrf.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,gBAAgB,EAAU,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAA4D,MAAM,qBAAqB,CAAC;AAG5G,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"csrf.guard.d.ts","sourceRoot":"","sources":["../../src/guards/csrf.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,gBAAgB,EAAU,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAA4D,MAAM,qBAAqB,CAAC;AAG5G,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBACa,SAAU,YAAW,WAAW;IAGzC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAFT,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS;IAGvC,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;CA0EhD"}
|
|
@@ -19,6 +19,27 @@ const core_2 = require("@nauth-toolkit/core");
|
|
|
19
19
|
const public_decorator_1 = require("../decorators/public.decorator");
|
|
20
20
|
const token_delivery_decorator_1 = require("../decorators/token-delivery.decorator");
|
|
21
21
|
const csrf_service_1 = require("../services/csrf.service");
|
|
22
|
+
/**
|
|
23
|
+
* CSRF Guard
|
|
24
|
+
*
|
|
25
|
+
* Validates CSRF tokens for state-changing requests when using cookie-based token delivery.
|
|
26
|
+
* CSRF protection prevents Cross-Site Request Forgery attacks.
|
|
27
|
+
*
|
|
28
|
+
* Security Rules:
|
|
29
|
+
* - Only enforces for cookie-based token delivery (cookies or hybrid with web origins)
|
|
30
|
+
* - Skips safe HTTP methods (GET, HEAD, OPTIONS)
|
|
31
|
+
* - Skips excluded paths from configuration
|
|
32
|
+
* - Validates CSRF token from header matches cookie value
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Applied globally via AuthModule when tokenDelivery.method === 'cookies' or 'hybrid'
|
|
37
|
+
* // Or applied per-route:
|
|
38
|
+
* @UseGuards(CsrfGuard)
|
|
39
|
+
* @Post('sensitive-action')
|
|
40
|
+
* async sensitiveAction() { ... }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
22
43
|
let CsrfGuard = class CsrfGuard {
|
|
23
44
|
config;
|
|
24
45
|
csrfService;
|
|
@@ -29,17 +50,21 @@ let CsrfGuard = class CsrfGuard {
|
|
|
29
50
|
this.reflector = reflector;
|
|
30
51
|
}
|
|
31
52
|
canActivate(context) {
|
|
53
|
+
// Only operate in HTTP context
|
|
32
54
|
if (context.getType() !== 'http') {
|
|
33
55
|
return true;
|
|
34
56
|
}
|
|
35
57
|
const request = context.switchToHttp().getRequest();
|
|
36
58
|
const csrfConfig = this.config.security?.csrf;
|
|
59
|
+
// Skip if CSRF config is not provided
|
|
37
60
|
if (!csrfConfig) {
|
|
38
61
|
return true;
|
|
39
62
|
}
|
|
63
|
+
// Skip for safe HTTP methods (GET, HEAD, OPTIONS)
|
|
40
64
|
if (['GET', 'HEAD', 'OPTIONS'].includes(request.method)) {
|
|
41
65
|
return true;
|
|
42
66
|
}
|
|
67
|
+
// Skip if route is marked as public
|
|
43
68
|
const isPublic = this.reflector.getAllAndOverride(public_decorator_1.IS_PUBLIC_KEY, [
|
|
44
69
|
context.getHandler(),
|
|
45
70
|
context.getClass(),
|
|
@@ -47,9 +72,11 @@ let CsrfGuard = class CsrfGuard {
|
|
|
47
72
|
if (isPublic) {
|
|
48
73
|
return true;
|
|
49
74
|
}
|
|
75
|
+
// Skip excluded paths
|
|
50
76
|
if (csrfConfig.excludedPaths?.some((path) => request.url.startsWith(path))) {
|
|
51
77
|
return true;
|
|
52
78
|
}
|
|
79
|
+
// Determine token delivery method
|
|
53
80
|
const deliveryConfig = this.config.tokenDelivery;
|
|
54
81
|
const routeMode = this.reflector.get(token_delivery_decorator_1.TOKEN_DELIVERY_KEY, context.getHandler());
|
|
55
82
|
const method = deliveryConfig?.method || 'json';
|
|
@@ -66,9 +93,11 @@ let CsrfGuard = class CsrfGuard {
|
|
|
66
93
|
else {
|
|
67
94
|
effective = 'json';
|
|
68
95
|
}
|
|
96
|
+
// Only enforce CSRF for cookie-based token delivery
|
|
69
97
|
if (effective !== 'cookies') {
|
|
70
|
-
return true;
|
|
98
|
+
return true; // JSON mode doesn't need CSRF (Bearer tokens are CSRF-safe)
|
|
71
99
|
}
|
|
100
|
+
// Validate CSRF token
|
|
72
101
|
const cookieName = this.csrfService.getCookieName();
|
|
73
102
|
const headerName = this.csrfService.getHeaderName();
|
|
74
103
|
const csrfToken = request.headers[headerName.toLowerCase()];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csrf.guard.js","sourceRoot":"","sources":["../../src/guards/csrf.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmF;AACnF,uCAAyC;AACzC,8CAA4G;AAC5G,qEAA+D;AAC/D,qFAA2F;AAC3F,2DAAuD;
|
|
1
|
+
{"version":3,"file":"csrf.guard.js","sourceRoot":"","sources":["../../src/guards/csrf.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmF;AACnF,uCAAyC;AACzC,8CAA4G;AAC5G,qEAA+D;AAC/D,qFAA2F;AAC3F,2DAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IAGD;IACA;IACA;IAJnB,YAEmB,MAAmB,EACnB,WAAwB,EACxB,SAAoB;QAFpB,WAAM,GAAN,MAAM,CAAa;QACnB,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAW;IACpC,CAAC;IAEJ,WAAW,CAAC,OAAyB;QACnC,+BAA+B;QAC/B,IAAI,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC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|
|
2
|
+
* @nauth-toolkit/nestjs
|
|
3
|
+
*
|
|
4
|
+
* NestJS adapter for nauth-toolkit.
|
|
5
|
+
* This package provides NestJS-specific integrations while re-exporting
|
|
6
|
+
* all core functionality for seamless backward compatibility.
|
|
7
|
+
*/
|
|
1
8
|
export * from '@nauth-toolkit/core';
|
|
9
|
+
/**
|
|
10
|
+
* NestJS Module - Main entry point for integrating NAuth into NestJS apps
|
|
11
|
+
*/
|
|
2
12
|
export { AuthModule, NAuthModuleConfig } from './auth.module';
|
|
13
|
+
/**
|
|
14
|
+
* NestJS Guards - Route protection and authentication
|
|
15
|
+
*/
|
|
3
16
|
export { AuthGuard } from './guards/auth.guard';
|
|
4
17
|
export { CsrfGuard } from './guards/csrf.guard';
|
|
18
|
+
/**
|
|
19
|
+
* NestJS Interceptors - Request/response processing
|
|
20
|
+
*/
|
|
5
21
|
export { ClientInfoInterceptor } from './interceptors/client-info.interceptor';
|
|
6
22
|
export { CookieTokenInterceptor } from './interceptors/cookie-token.interceptor';
|
|
23
|
+
/**
|
|
24
|
+
* NestJS Decorators - Parameter decorators and metadata
|
|
25
|
+
*/
|
|
7
26
|
export { CurrentUser } from './decorators/current-user.decorator';
|
|
8
27
|
export { Public, IS_PUBLIC_KEY } from './decorators/public.decorator';
|
|
9
28
|
export { ClientInfo } from './decorators/client-info.decorator';
|
|
10
29
|
export { TokenDelivery, TOKEN_DELIVERY_KEY, RouteDelivery } from './decorators/token-delivery.decorator';
|
|
30
|
+
/**
|
|
31
|
+
* NestJS Filters - Exception handling
|
|
32
|
+
*/
|
|
11
33
|
export { NAuthHttpExceptionFilter } from './filters/nauth-http-exception.filter';
|
|
34
|
+
/**
|
|
35
|
+
* NestJS Providers - Logger adapters and utilities
|
|
36
|
+
*/
|
|
12
37
|
export { NestJsLoggerAdapter } from './providers/nestjs-logger.adapter';
|
|
38
|
+
/**
|
|
39
|
+
* NestJS Services - CSRF protection
|
|
40
|
+
*/
|
|
13
41
|
export { CsrfService } from './services/csrf.service';
|
|
42
|
+
/**
|
|
43
|
+
* NestJS DTOs - Data Transfer Objects with class-validator
|
|
44
|
+
*/
|
|
14
45
|
export * from './dto';
|
|
46
|
+
/**
|
|
47
|
+
* Factory Functions - Simplified adapter creation
|
|
48
|
+
*/
|
|
15
49
|
export { createDatabaseStorageAdapter, createRedisStorageAdapter, createRedisClusterAdapter, } from './factories/storage-adapter.factory';
|
|
16
50
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,cAAc,qBAAqB,CAAC;AAMpC;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE9D;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;GAEG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAEjF;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAEzG;;GAEG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAEjF;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;GAEG;AACH,cAAc,OAAO,CAAC;AAEtB;;GAEG;AACH,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qCAAqC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @nauth-toolkit/nestjs
|
|
4
|
+
*
|
|
5
|
+
* NestJS adapter for nauth-toolkit.
|
|
6
|
+
* This package provides NestJS-specific integrations while re-exporting
|
|
7
|
+
* all core functionality for seamless backward compatibility.
|
|
8
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -15,17 +22,41 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
22
|
};
|
|
16
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
24
|
exports.createRedisClusterAdapter = exports.createRedisStorageAdapter = exports.createDatabaseStorageAdapter = exports.CsrfService = exports.NestJsLoggerAdapter = exports.NAuthHttpExceptionFilter = exports.TOKEN_DELIVERY_KEY = exports.TokenDelivery = exports.ClientInfo = exports.IS_PUBLIC_KEY = exports.Public = exports.CurrentUser = exports.CookieTokenInterceptor = exports.ClientInfoInterceptor = exports.CsrfGuard = exports.AuthGuard = exports.AuthModule = void 0;
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// Re-export Public API from Core
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Note: Internal services (ChallengeService, AuthChallengeHelperService, etc.)
|
|
29
|
+
// are NOT re-exported. They are only available via '@nauth-toolkit/core/internal'
|
|
30
|
+
// for framework adapter development.
|
|
31
|
+
//
|
|
32
|
+
// Consumer applications should use the public services:
|
|
33
|
+
// - AuthService, MFAService, SocialAuthService, etc.
|
|
18
34
|
__exportStar(require("@nauth-toolkit/core"), exports);
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// NestJS-Specific Exports
|
|
37
|
+
// ============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* NestJS Module - Main entry point for integrating NAuth into NestJS apps
|
|
40
|
+
*/
|
|
19
41
|
var auth_module_1 = require("./auth.module");
|
|
20
42
|
Object.defineProperty(exports, "AuthModule", { enumerable: true, get: function () { return auth_module_1.AuthModule; } });
|
|
43
|
+
/**
|
|
44
|
+
* NestJS Guards - Route protection and authentication
|
|
45
|
+
*/
|
|
21
46
|
var auth_guard_1 = require("./guards/auth.guard");
|
|
22
47
|
Object.defineProperty(exports, "AuthGuard", { enumerable: true, get: function () { return auth_guard_1.AuthGuard; } });
|
|
23
48
|
var csrf_guard_1 = require("./guards/csrf.guard");
|
|
24
49
|
Object.defineProperty(exports, "CsrfGuard", { enumerable: true, get: function () { return csrf_guard_1.CsrfGuard; } });
|
|
50
|
+
/**
|
|
51
|
+
* NestJS Interceptors - Request/response processing
|
|
52
|
+
*/
|
|
25
53
|
var client_info_interceptor_1 = require("./interceptors/client-info.interceptor");
|
|
26
54
|
Object.defineProperty(exports, "ClientInfoInterceptor", { enumerable: true, get: function () { return client_info_interceptor_1.ClientInfoInterceptor; } });
|
|
27
55
|
var cookie_token_interceptor_1 = require("./interceptors/cookie-token.interceptor");
|
|
28
56
|
Object.defineProperty(exports, "CookieTokenInterceptor", { enumerable: true, get: function () { return cookie_token_interceptor_1.CookieTokenInterceptor; } });
|
|
57
|
+
/**
|
|
58
|
+
* NestJS Decorators - Parameter decorators and metadata
|
|
59
|
+
*/
|
|
29
60
|
var current_user_decorator_1 = require("./decorators/current-user.decorator");
|
|
30
61
|
Object.defineProperty(exports, "CurrentUser", { enumerable: true, get: function () { return current_user_decorator_1.CurrentUser; } });
|
|
31
62
|
var public_decorator_1 = require("./decorators/public.decorator");
|
|
@@ -36,13 +67,28 @@ Object.defineProperty(exports, "ClientInfo", { enumerable: true, get: function (
|
|
|
36
67
|
var token_delivery_decorator_1 = require("./decorators/token-delivery.decorator");
|
|
37
68
|
Object.defineProperty(exports, "TokenDelivery", { enumerable: true, get: function () { return token_delivery_decorator_1.TokenDelivery; } });
|
|
38
69
|
Object.defineProperty(exports, "TOKEN_DELIVERY_KEY", { enumerable: true, get: function () { return token_delivery_decorator_1.TOKEN_DELIVERY_KEY; } });
|
|
70
|
+
/**
|
|
71
|
+
* NestJS Filters - Exception handling
|
|
72
|
+
*/
|
|
39
73
|
var nauth_http_exception_filter_1 = require("./filters/nauth-http-exception.filter");
|
|
40
74
|
Object.defineProperty(exports, "NAuthHttpExceptionFilter", { enumerable: true, get: function () { return nauth_http_exception_filter_1.NAuthHttpExceptionFilter; } });
|
|
75
|
+
/**
|
|
76
|
+
* NestJS Providers - Logger adapters and utilities
|
|
77
|
+
*/
|
|
41
78
|
var nestjs_logger_adapter_1 = require("./providers/nestjs-logger.adapter");
|
|
42
79
|
Object.defineProperty(exports, "NestJsLoggerAdapter", { enumerable: true, get: function () { return nestjs_logger_adapter_1.NestJsLoggerAdapter; } });
|
|
80
|
+
/**
|
|
81
|
+
* NestJS Services - CSRF protection
|
|
82
|
+
*/
|
|
43
83
|
var csrf_service_1 = require("./services/csrf.service");
|
|
44
84
|
Object.defineProperty(exports, "CsrfService", { enumerable: true, get: function () { return csrf_service_1.CsrfService; } });
|
|
85
|
+
/**
|
|
86
|
+
* NestJS DTOs - Data Transfer Objects with class-validator
|
|
87
|
+
*/
|
|
45
88
|
__exportStar(require("./dto"), exports);
|
|
89
|
+
/**
|
|
90
|
+
* Factory Functions - Simplified adapter creation
|
|
91
|
+
*/
|
|
46
92
|
var storage_adapter_factory_1 = require("./factories/storage-adapter.factory");
|
|
47
93
|
Object.defineProperty(exports, "createDatabaseStorageAdapter", { enumerable: true, get: function () { return storage_adapter_factory_1.createDatabaseStorageAdapter; } });
|
|
48
94
|
Object.defineProperty(exports, "createRedisStorageAdapter", { enumerable: true, get: function () { return storage_adapter_factory_1.createRedisStorageAdapter; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;AAEH,+EAA+E;AAC/E,iCAAiC;AACjC,+EAA+E;AAC/E,+EAA+E;AAC/E,kFAAkF;AAClF,qCAAqC;AACrC,EAAE;AACF,wDAAwD;AACxD,qDAAqD;AACrD,sDAAoC;AAEpC,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E;;GAEG;AACH,6CAA8D;AAArD,yGAAA,UAAU,OAAA;AAEnB;;GAEG;AACH,kDAAgD;AAAvC,uGAAA,SAAS,OAAA;AAClB,kDAAgD;AAAvC,uGAAA,SAAS,OAAA;AAElB;;GAEG;AACH,kFAA+E;AAAtE,gIAAA,qBAAqB,OAAA;AAC9B,oFAAiF;AAAxE,kIAAA,sBAAsB,OAAA;AAE/B;;GAEG;AACH,8EAAkE;AAAzD,qHAAA,WAAW,OAAA;AACpB,kEAAsE;AAA7D,0GAAA,MAAM,OAAA;AAAE,iHAAA,aAAa,OAAA;AAC9B,4EAAgE;AAAvD,mHAAA,UAAU,OAAA;AACnB,kFAAyG;AAAhG,yHAAA,aAAa,OAAA;AAAE,8HAAA,kBAAkB,OAAA;AAE1C;;GAEG;AACH,qFAAiF;AAAxE,uIAAA,wBAAwB,OAAA;AAEjC;;GAEG;AACH,2EAAwE;AAA/D,4HAAA,mBAAmB,OAAA;AAE5B;;GAEG;AACH,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AAEpB;;GAEG;AACH,wCAAsB;AAEtB;;GAEG;AACH,+EAI6C;AAH3C,uIAAA,4BAA4B,OAAA;AAC5B,oIAAA,yBAAyB,OAAA;AACzB,oIAAA,yBAAyB,OAAA"}
|
|
@@ -2,12 +2,49 @@ import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { NAuthConfig } from '@nauth-toolkit/core';
|
|
4
4
|
import { GeoLocationService } from '@nauth-toolkit/core/internal';
|
|
5
|
+
/**
|
|
6
|
+
* Client Info Interceptor
|
|
7
|
+
*
|
|
8
|
+
* Automatically extracts client information (IP address, user agent, device info)
|
|
9
|
+
* from incoming HTTP requests and stores it in async local storage (CLS).
|
|
10
|
+
*
|
|
11
|
+
* This interceptor runs globally when configured in AuthModule, ensuring that
|
|
12
|
+
* all authentication services have transparent access to client metadata without
|
|
13
|
+
* needing to pass it as parameters.
|
|
14
|
+
*
|
|
15
|
+
* Benefits:
|
|
16
|
+
* - Transparent IP/user agent handling (like AWS Cognito)
|
|
17
|
+
* - Handles proxies and load balancers automatically
|
|
18
|
+
* - No parameters needed - services read from context automatically
|
|
19
|
+
* - Works across async boundaries
|
|
20
|
+
* - Type-safe and consistent
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // In your controller (no IP/UA parameters needed!)
|
|
24
|
+
* @Post('login')
|
|
25
|
+
* async login(@Body() dto: LoginDTO) {
|
|
26
|
+
* return this.authService.login(dto); // IP extracted internally!
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // In AuthService (reads from context automatically)
|
|
30
|
+
* async login(dto: LoginDTO) {
|
|
31
|
+
* const clientInfo = this.clientInfoService.get(); // From context!
|
|
32
|
+
* // Use clientInfo.ipAddress, clientInfo.userAgent, etc.
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
5
35
|
export declare class ClientInfoInterceptor implements NestInterceptor {
|
|
6
36
|
private readonly config?;
|
|
7
37
|
private readonly geoLocationService?;
|
|
8
38
|
private readonly clientInfoService;
|
|
9
39
|
constructor(config?: NAuthConfig | undefined, geoLocationService?: GeoLocationService | undefined);
|
|
10
40
|
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Extract and store client information in context
|
|
43
|
+
*
|
|
44
|
+
* @param context - Execution context
|
|
45
|
+
* @param next - Call handler
|
|
46
|
+
* @returns Observable
|
|
47
|
+
*/
|
|
11
48
|
private extractAndStoreClientInfo;
|
|
12
49
|
}
|
|
13
50
|
//# sourceMappingURL=client-info.interceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-info.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/client-info.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAY,MAAM,MAAM,CAAC;AAE5C,OAAO,EAKL,WAAW,EAEZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"client-info.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/client-info.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAY,MAAM,MAAM,CAAC;AAE5C,OAAO,EAKL,WAAW,EAEZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBACa,qBAAsB,YAAW,eAAe;IAMzD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAExB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IAPtC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA2B;gBAK1C,MAAM,CAAC,EAAE,WAAW,YAAA,EAEpB,kBAAkB,CAAC,EAAE,kBAAkB,YAAA;IAG1D,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IAa5E;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;CAkIlC"}
|
|
@@ -18,6 +18,36 @@ const rxjs_1 = require("rxjs");
|
|
|
18
18
|
const operators_1 = require("rxjs/operators");
|
|
19
19
|
const core_1 = require("@nauth-toolkit/core");
|
|
20
20
|
const internal_1 = require("@nauth-toolkit/core/internal");
|
|
21
|
+
/**
|
|
22
|
+
* Client Info Interceptor
|
|
23
|
+
*
|
|
24
|
+
* Automatically extracts client information (IP address, user agent, device info)
|
|
25
|
+
* from incoming HTTP requests and stores it in async local storage (CLS).
|
|
26
|
+
*
|
|
27
|
+
* This interceptor runs globally when configured in AuthModule, ensuring that
|
|
28
|
+
* all authentication services have transparent access to client metadata without
|
|
29
|
+
* needing to pass it as parameters.
|
|
30
|
+
*
|
|
31
|
+
* Benefits:
|
|
32
|
+
* - Transparent IP/user agent handling (like AWS Cognito)
|
|
33
|
+
* - Handles proxies and load balancers automatically
|
|
34
|
+
* - No parameters needed - services read from context automatically
|
|
35
|
+
* - Works across async boundaries
|
|
36
|
+
* - Type-safe and consistent
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // In your controller (no IP/UA parameters needed!)
|
|
40
|
+
* @Post('login')
|
|
41
|
+
* async login(@Body() dto: LoginDTO) {
|
|
42
|
+
* return this.authService.login(dto); // IP extracted internally!
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* // In AuthService (reads from context automatically)
|
|
46
|
+
* async login(dto: LoginDTO) {
|
|
47
|
+
* const clientInfo = this.clientInfoService.get(); // From context!
|
|
48
|
+
* // Use clientInfo.ipAddress, clientInfo.userAgent, etc.
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
21
51
|
let ClientInfoInterceptor = class ClientInfoInterceptor {
|
|
22
52
|
config;
|
|
23
53
|
geoLocationService;
|
|
@@ -27,6 +57,7 @@ let ClientInfoInterceptor = class ClientInfoInterceptor {
|
|
|
27
57
|
this.geoLocationService = geoLocationService;
|
|
28
58
|
}
|
|
29
59
|
intercept(context, next) {
|
|
60
|
+
// Initialize context storage for this request (platform-agnostic)
|
|
30
61
|
return new rxjs_1.Observable((subscriber) => {
|
|
31
62
|
core_1.ContextStorage.run(() => {
|
|
32
63
|
this.extractAndStoreClientInfo(context, next).subscribe({
|
|
@@ -37,49 +68,101 @@ let ClientInfoInterceptor = class ClientInfoInterceptor {
|
|
|
37
68
|
});
|
|
38
69
|
});
|
|
39
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Extract and store client information in context
|
|
73
|
+
*
|
|
74
|
+
* @param context - Execution context
|
|
75
|
+
* @param next - Call handler
|
|
76
|
+
* @returns Observable
|
|
77
|
+
*/
|
|
40
78
|
extractAndStoreClientInfo(context, next) {
|
|
41
79
|
const request = context.switchToHttp().getRequest();
|
|
42
80
|
const response = context.switchToHttp().getResponse();
|
|
81
|
+
// Extract client information
|
|
43
82
|
const headers = request.headers || {};
|
|
44
83
|
const userAgent = headers['user-agent'];
|
|
45
84
|
const userAgentString = typeof userAgent === 'string' ? userAgent : 'unknown';
|
|
85
|
+
// Parse user agent to extract platform and browser using ClientInfoService
|
|
46
86
|
const parsedUA = this.clientInfoService.parseUserAgent(userAgentString);
|
|
87
|
+
// Extract device token from cookie (web) or header (mobile)
|
|
88
|
+
// Security: Never accept device token from request body (prevent client manipulation)
|
|
47
89
|
const deviceTokenCookieName = this.config ? (0, core_1.getDeviceTokenCookieName)(this.config) : 'nauth_device_token';
|
|
48
90
|
const deviceTokenCookie = request.cookies?.[deviceTokenCookieName];
|
|
49
91
|
const deviceTokenHeader = headers['x-device-token'] || headers['X-Device-Token'];
|
|
50
92
|
const deviceToken = (typeof deviceTokenCookie === 'string' ? deviceTokenCookie : undefined) ||
|
|
51
93
|
(typeof deviceTokenHeader === 'string' ? deviceTokenHeader : undefined) ||
|
|
52
94
|
(deviceTokenHeader ? String(deviceTokenHeader) : undefined);
|
|
95
|
+
// Extract sessionId and userId from token (set by AuthGuard after validation)
|
|
96
|
+
// sessionId and sub (userId) are strings in JWT payload, convert to number for database
|
|
53
97
|
const sessionIdFromToken = request?.token?.sessionId;
|
|
54
98
|
const sessionIdNumber = sessionIdFromToken ? parseInt(sessionIdFromToken, 10) : undefined;
|
|
55
99
|
const userIdFromToken = request?.token?.sub;
|
|
56
100
|
const userIdNumber = userIdFromToken ? parseInt(userIdFromToken, 10) : undefined;
|
|
57
101
|
const clientInfo = {
|
|
102
|
+
//ipAddress: extractClientIp(request),
|
|
103
|
+
/**
|
|
104
|
+
* In development mode, assign a random known public IP address
|
|
105
|
+
* for better testability (to trigger geolocation flows, etc.).
|
|
106
|
+
* In production, default to 'unknown' if IP extraction fails.
|
|
107
|
+
*/
|
|
58
108
|
ipAddress: (0, core_1.extractClientIp)(request),
|
|
109
|
+
// process.env.NODE_ENV === 'development'
|
|
110
|
+
// ? [
|
|
111
|
+
// '203.97.24.118', // Invercargill, New Zealand
|
|
112
|
+
// '194.103.82.33', // Umeå, Sweden
|
|
113
|
+
// '80.12.134.67', // La Rochelle, France
|
|
114
|
+
// '124.148.98.45', // Port Hedland, Australia
|
|
115
|
+
// '200.68.114.22', // Mar del Plata, Argentina
|
|
116
|
+
// '213.216.200.77', // Oulu, Finland
|
|
117
|
+
// '206.248.142.91', // Timmins, Canada
|
|
118
|
+
// '95.43.18.140', // Plovdiv, Bulgaria
|
|
119
|
+
// '110.164.231.162', // Surat Thani, Thailand
|
|
120
|
+
// '190.186.7.20', // Cochabamba, Bolivia
|
|
121
|
+
// ][Math.floor(Math.random() * 10)]
|
|
122
|
+
// : extractClientIp(request),
|
|
59
123
|
userAgent: userAgentString,
|
|
60
|
-
deviceToken,
|
|
124
|
+
deviceToken, // Extracted from cookie or header only
|
|
125
|
+
// Use deviceName from request body if provided, otherwise parse from user agent
|
|
61
126
|
deviceName: request.body?.deviceName || parsedUA.deviceName || undefined,
|
|
62
127
|
deviceType: request.body?.deviceType || parsedUA.deviceType || undefined,
|
|
63
128
|
platform: parsedUA.platform || undefined,
|
|
64
129
|
browser: parsedUA.browser || undefined,
|
|
130
|
+
// Session ID from authenticated request (set by AuthGuard after token validation)
|
|
65
131
|
sessionId: sessionIdNumber && !isNaN(sessionIdNumber) ? sessionIdNumber : undefined,
|
|
132
|
+
// User ID from authenticated request (set by AuthGuard after token validation)
|
|
66
133
|
userId: userIdNumber && !isNaN(userIdNumber) ? userIdNumber : undefined,
|
|
134
|
+
// Geolocation populated below if GeoLocationService is available
|
|
67
135
|
ipCountry: undefined,
|
|
68
136
|
ipCity: undefined,
|
|
69
137
|
ipLatitude: undefined,
|
|
70
138
|
ipLongitude: undefined,
|
|
71
139
|
};
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Populate Geolocation (Optional)
|
|
142
|
+
// ============================================================================
|
|
72
143
|
if (this.geoLocationService && clientInfo.ipAddress) {
|
|
144
|
+
// Use RxJS operators to await geolocation lookup
|
|
145
|
+
// CRITICAL: Use catchError BEFORE switchMap to only catch geolocation errors,
|
|
146
|
+
// not errors from the controller (which would cause duplicate execution)
|
|
73
147
|
return (0, rxjs_1.from)(this.geoLocationService.getIpGeolocation(clientInfo.ipAddress)).pipe((0, operators_1.catchError)(() => {
|
|
148
|
+
// Non-blocking: Silently fail - geolocation remains undefined
|
|
149
|
+
// Errors are already logged by GeoLocationService
|
|
150
|
+
// Return empty geo data to continue the request
|
|
74
151
|
return (0, rxjs_1.of)({ country: undefined, city: undefined, latitude: undefined, longitude: undefined });
|
|
75
152
|
}), (0, operators_1.switchMap)((geo) => {
|
|
153
|
+
// Update clientInfo with geolocation (or undefined if lookup failed)
|
|
76
154
|
clientInfo.ipCountry = geo.country;
|
|
77
155
|
clientInfo.ipCity = geo.city;
|
|
78
156
|
clientInfo.ipLatitude = geo.latitude;
|
|
79
157
|
clientInfo.ipLongitude = geo.longitude;
|
|
158
|
+
// Store in async local storage for transparent access
|
|
80
159
|
core_1.ContextStorage.set('CLIENT_INFO', clientInfo);
|
|
160
|
+
// Store response object for services to access (e.g., for clearing cookies)
|
|
81
161
|
core_1.ContextStorage.set('HTTP_RESPONSE', response);
|
|
162
|
+
// Also attach to request object for @ClientInfo() decorator (backward compatibility)
|
|
82
163
|
request.clientInfo = clientInfo;
|
|
164
|
+
// Expose current session id for observability/debugging (set by AuthGuard after validation)
|
|
165
|
+
// This is safe metadata; tokens are never exposed. If unavailable, header is omitted.
|
|
83
166
|
const sessionId = request?.token?.sessionId;
|
|
84
167
|
if (sessionId && typeof response.setHeader === 'function') {
|
|
85
168
|
response.setHeader('X-Session-Id', sessionId);
|
|
@@ -87,9 +170,14 @@ let ClientInfoInterceptor = class ClientInfoInterceptor {
|
|
|
87
170
|
return next.handle();
|
|
88
171
|
}));
|
|
89
172
|
}
|
|
173
|
+
// Store in async local storage for transparent access
|
|
90
174
|
core_1.ContextStorage.set('CLIENT_INFO', clientInfo);
|
|
175
|
+
// Store response object for services to access (e.g., for clearing cookies)
|
|
91
176
|
core_1.ContextStorage.set('HTTP_RESPONSE', response);
|
|
177
|
+
// Also attach to request object for @ClientInfo() decorator (backward compatibility)
|
|
92
178
|
request.clientInfo = clientInfo;
|
|
179
|
+
// Expose current session id for observability/debugging (set by AuthGuard after validation)
|
|
180
|
+
// This is safe metadata; tokens are never exposed. If unavailable, header is omitted.
|
|
93
181
|
const sessionId = request?.token?.sessionId;
|
|
94
182
|
if (sessionId && typeof response.setHeader === 'function') {
|
|
95
183
|
response.setHeader('X-Session-Id', sessionId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-info.interceptor.js","sourceRoot":"","sources":["../../src/interceptors/client-info.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8G;AAC9G,+BAA4C;AAC5C,8CAAuD;AACvD,8CAO6B;AAC7B,2DAAkE;
|
|
1
|
+
{"version":3,"file":"client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QAED,sDAAsD;QACtD,qBAAc,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;QAE9C,4EAA4E;QAC5E,qBAAc,CAAC,GAAG,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QAE9C,qFAAqF;QACrF,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;QAEhC,4FAA4F;QAC5F,sFAAsF;QACtF,MAAM,SAAS,GAAuB,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;QAChE,IAAI,SAAS,IAAI,OAAO,QAAQ,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;YAC1D,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF,CAAA;AAjKY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,cAAc,CAAC,CAAA;IAEtB,WAAA,IAAA,iBAAQ,GAAE,CAAA;6CAC2B,6BAAkB;GAR/C,qBAAqB,CAiKjC"}
|
|
@@ -4,6 +4,22 @@ import { Observable } from 'rxjs';
|
|
|
4
4
|
import { NAuthConfig } from '@nauth-toolkit/core';
|
|
5
5
|
import { JwtService } from '@nauth-toolkit/core/internal';
|
|
6
6
|
import { CsrfService } from '../services/csrf.service';
|
|
7
|
+
/**
|
|
8
|
+
* Cookie Token Interceptor
|
|
9
|
+
*
|
|
10
|
+
* Automatically sets JWT tokens as httpOnly cookies for HTTP responses when
|
|
11
|
+
* token delivery mode is configured as 'cookies' or 'hybrid'.
|
|
12
|
+
*
|
|
13
|
+
* Security defaults:
|
|
14
|
+
* - Cookie names prefixed with 'nauth_' to avoid conflicts: 'nauth_access_token', 'nauth_refresh_token'
|
|
15
|
+
* - httpOnly: true (always)
|
|
16
|
+
* - secure: true (configurable via cookieOptions.secure)
|
|
17
|
+
* - sameSite: 'strict' (configurable via cookieOptions.sameSite)
|
|
18
|
+
* - path: '/' (configurable via cookieOptions.path)
|
|
19
|
+
*
|
|
20
|
+
* This interceptor is transport-aware and only applies to HTTP requests.
|
|
21
|
+
* It does nothing in other contexts (e.g., WebSocket, GraphQL).
|
|
22
|
+
*/
|
|
7
23
|
export declare class CookieTokenInterceptor implements NestInterceptor {
|
|
8
24
|
private readonly config;
|
|
9
25
|
private readonly jwtService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie-token.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/cookie-token.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAU,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAEL,WAAW,EAQZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"cookie-token.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/cookie-token.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAU,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAEL,WAAW,EAQZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,qBACa,sBAAuB,YAAW,eAAe;IAG1D,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;gBAHZ,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,WAAW,YAAA;IAG5C,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CAuN7E"}
|