@vritti/api-sdk 0.3.2 → 0.3.5
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.cjs +942 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +95 -0
- package/dist/auth.d.ts +95 -0
- package/dist/auth.js +884 -0
- package/dist/auth.js.map +1 -0
- package/dist/cache.cjs +182 -14
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.cts +48 -4
- package/dist/cache.d.ts +48 -4
- package/dist/cache.js +177 -12
- package/dist/cache.js.map +1 -1
- package/dist/catalog-resolver.cjs +226 -51
- package/dist/catalog-resolver.cjs.map +1 -1
- package/dist/catalog-resolver.d.cts +41 -19
- package/dist/catalog-resolver.d.ts +41 -19
- package/dist/catalog-resolver.js +212 -46
- package/dist/catalog-resolver.js.map +1 -1
- package/dist/code-pattern-BP4zkNtT.d.cts +12 -0
- package/dist/code-pattern-BP4zkNtT.d.ts +12 -0
- package/dist/context.cjs +93 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +19 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.js +64 -0
- package/dist/context.js.map +1 -0
- package/dist/countries.cjs +1559 -0
- package/dist/countries.cjs.map +1 -0
- package/dist/countries.d.cts +13 -0
- package/dist/countries.d.ts +13 -0
- package/dist/countries.js +1532 -0
- package/dist/countries.js.map +1 -0
- package/dist/data-table.cjs +1280 -0
- package/dist/data-table.cjs.map +1 -0
- package/dist/data-table.d.cts +123 -0
- package/dist/data-table.d.ts +123 -0
- package/dist/data-table.js +1260 -0
- package/dist/data-table.js.map +1 -0
- package/dist/database.cjs +1510 -0
- package/dist/database.cjs.map +1 -0
- package/dist/database.d.cts +287 -0
- package/dist/database.d.ts +287 -0
- package/dist/database.js +1469 -0
- package/dist/database.js.map +1 -0
- package/dist/decimal.d.cts +0 -1
- package/dist/decimal.d.ts +0 -1
- package/dist/decorators.cjs +1817 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +24 -0
- package/dist/decorators.d.ts +24 -0
- package/dist/decorators.js +1780 -0
- package/dist/decorators.js.map +1 -0
- package/dist/document-BoS0NIbf.d.cts +12 -0
- package/dist/document-BoS0NIbf.d.ts +12 -0
- package/dist/drizzle-pg-core.cjs +25 -0
- package/dist/drizzle-pg-core.cjs.map +1 -1
- package/dist/drizzle-pg-core.d.cts +7 -0
- package/dist/drizzle-pg-core.d.ts +7 -0
- package/dist/drizzle-pg-core.js +22 -0
- package/dist/drizzle-pg-core.js.map +1 -1
- package/dist/exceptions.cjs +301 -0
- package/dist/exceptions.cjs.map +1 -0
- package/dist/exceptions.d.cts +90 -0
- package/dist/exceptions.d.ts +90 -0
- package/dist/exceptions.js +257 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/filter.types-PuARU9XD.d.cts +50 -0
- package/dist/filter.types-PuARU9XD.d.ts +50 -0
- package/dist/filters.cjs +407 -0
- package/dist/filters.cjs.map +1 -0
- package/dist/filters.d.cts +55 -0
- package/dist/filters.d.ts +55 -0
- package/dist/filters.js +377 -0
- package/dist/filters.js.map +1 -0
- package/dist/index.cjs +0 -5423
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -854
- package/dist/index.d.ts +93 -854
- package/dist/index.js +0 -5301
- package/dist/index.js.map +1 -1
- package/dist/is-country.decorator-CcNwSSr5.d.cts +5 -0
- package/dist/is-country.decorator-CcNwSSr5.d.ts +5 -0
- package/dist/license.cjs +9 -56
- package/dist/license.cjs.map +1 -1
- package/dist/license.d.cts +3 -14
- package/dist/license.d.ts +3 -14
- package/dist/license.js +8 -51
- package/dist/license.js.map +1 -1
- package/dist/lodash.cjs.map +1 -1
- package/dist/lodash.js.map +1 -1
- package/dist/logger.cjs +862 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +118 -0
- package/dist/logger.d.ts +118 -0
- package/dist/logger.js +816 -0
- package/dist/logger.js.map +1 -0
- package/dist/migrate.cjs +2 -2
- package/dist/migrate.cjs.map +1 -1
- package/dist/migrate.d.cts +2 -0
- package/dist/migrate.d.ts +2 -0
- package/dist/migrate.js +2 -2
- package/dist/migrate.js.map +1 -1
- package/dist/money.cjs +18 -3
- package/dist/money.cjs.map +1 -1
- package/dist/money.d.cts +13 -13
- package/dist/money.d.ts +13 -13
- package/dist/money.js +18 -3
- package/dist/money.js.map +1 -1
- package/dist/nats.cjs +34 -35
- package/dist/nats.cjs.map +1 -1
- package/dist/nats.d.cts +14 -14
- package/dist/nats.d.ts +14 -14
- package/dist/nats.js +32 -33
- package/dist/nats.js.map +1 -1
- package/dist/root.cjs +225 -0
- package/dist/root.cjs.map +1 -0
- package/dist/root.d.cts +4 -0
- package/dist/root.d.ts +4 -0
- package/dist/root.js +200 -0
- package/dist/root.js.map +1 -0
- package/dist/signing.cjs +159 -0
- package/dist/signing.cjs.map +1 -0
- package/dist/signing.d.cts +35 -0
- package/dist/signing.d.ts +35 -0
- package/dist/signing.js +128 -0
- package/dist/signing.js.map +1 -0
- package/dist/{types-DQRwj5rr.d.cts → types-C9jPdQqH.d.cts} +32 -6
- package/dist/{types-DQRwj5rr.d.ts → types-C9jPdQqH.d.ts} +32 -6
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +17 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.cjs +273 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +8 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +245 -0
- package/dist/utils.js.map +1 -0
- package/package.json +132 -1
- package/dist/cache.service-_SuJIcNA.d.cts +0 -20
- package/dist/cache.service-_SuJIcNA.d.ts +0 -20
- package/dist/fastify-augmentation-CQPBNS5a.d.cts +0 -105
- package/dist/fastify-augmentation-CQPBNS5a.d.ts +0 -105
package/dist/auth.cjs
ADDED
|
@@ -0,0 +1,942 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/auth/index.ts
|
|
32
|
+
var auth_exports = {};
|
|
33
|
+
__export(auth_exports, {
|
|
34
|
+
AUTH_CONFIG: () => AUTH_CONFIG,
|
|
35
|
+
AUTH_CONFIG_DEFAULTS: () => AUTH_CONFIG_DEFAULTS,
|
|
36
|
+
AccessToken: () => AccessToken,
|
|
37
|
+
AuthConfigModule: () => AuthConfigModule,
|
|
38
|
+
ClientIp: () => ClientIp,
|
|
39
|
+
CookieDomain: () => CookieDomain,
|
|
40
|
+
CookieName: () => CookieName,
|
|
41
|
+
Hostname: () => Hostname,
|
|
42
|
+
Public: () => Public,
|
|
43
|
+
REQUIRE_SESSION_KEY: () => REQUIRE_SESSION_KEY,
|
|
44
|
+
RefreshCookieOptions: () => RefreshCookieOptions,
|
|
45
|
+
RefreshTokenCookie: () => RefreshTokenCookie,
|
|
46
|
+
RequireSession: () => RequireSession,
|
|
47
|
+
SKIP_CSRF_KEY: () => SKIP_CSRF_KEY,
|
|
48
|
+
SessionData: () => SessionData,
|
|
49
|
+
SkipCsrf: () => SkipCsrf,
|
|
50
|
+
Subdomain: () => Subdomain,
|
|
51
|
+
TokenService: () => TokenService,
|
|
52
|
+
TokenType: () => TokenType,
|
|
53
|
+
UserAgent: () => UserAgent,
|
|
54
|
+
UserId: () => UserId,
|
|
55
|
+
VrittiAuthGuard: () => VrittiAuthGuard,
|
|
56
|
+
hashToken: () => hashToken,
|
|
57
|
+
verifyTokenHash: () => verifyTokenHash
|
|
58
|
+
});
|
|
59
|
+
module.exports = __toCommonJS(auth_exports);
|
|
60
|
+
|
|
61
|
+
// src/auth/auth.config.ts
|
|
62
|
+
var AUTH_CONFIG = Symbol("AUTH_CONFIG");
|
|
63
|
+
var AUTH_CONFIG_DEFAULTS = {
|
|
64
|
+
cookie: {
|
|
65
|
+
refreshCookieName: "vritti_refresh",
|
|
66
|
+
refreshCookieMaxAge: 30 * 24 * 60 * 60 * 1e3,
|
|
67
|
+
refreshCookiePath: "/",
|
|
68
|
+
refreshCookieSecure: process.env.NODE_ENV === "production",
|
|
69
|
+
refreshCookieSameSite: "strict",
|
|
70
|
+
refreshCookieDomain: "localhost"
|
|
71
|
+
},
|
|
72
|
+
guard: {
|
|
73
|
+
authHeaderName: "authorization",
|
|
74
|
+
tokenPrefix: "Bearer",
|
|
75
|
+
csrfExemptSessionTypes: [],
|
|
76
|
+
csrfExemptTransports: [],
|
|
77
|
+
refreshTokenBindingExemptSessionTypes: []
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var TokenType = /* @__PURE__ */ (function(TokenType2) {
|
|
81
|
+
TokenType2["ACCESS"] = "access";
|
|
82
|
+
TokenType2["REFRESH"] = "refresh";
|
|
83
|
+
return TokenType2;
|
|
84
|
+
})({});
|
|
85
|
+
|
|
86
|
+
// src/auth/auth-config.module.ts
|
|
87
|
+
var import_common7 = require("@nestjs/common");
|
|
88
|
+
var import_config = require("@nestjs/config");
|
|
89
|
+
var import_core3 = require("@nestjs/core");
|
|
90
|
+
var import_jwt2 = require("@nestjs/jwt");
|
|
91
|
+
|
|
92
|
+
// src/request/request.module.ts
|
|
93
|
+
var import_common2 = require("@nestjs/common");
|
|
94
|
+
|
|
95
|
+
// src/request/services/request.service.ts
|
|
96
|
+
var import_common = require("@nestjs/common");
|
|
97
|
+
var import_core = require("@nestjs/core");
|
|
98
|
+
|
|
99
|
+
// src/context/resolve-request.ts
|
|
100
|
+
function resolveInjectedRequest(injected) {
|
|
101
|
+
const candidate = injected;
|
|
102
|
+
if (candidate && candidate.headers === void 0 && candidate.req) {
|
|
103
|
+
return candidate.req;
|
|
104
|
+
}
|
|
105
|
+
return injected;
|
|
106
|
+
}
|
|
107
|
+
__name(resolveInjectedRequest, "resolveInjectedRequest");
|
|
108
|
+
|
|
109
|
+
// src/request/services/request.service.ts
|
|
110
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
111
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
112
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
113
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
114
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
115
|
+
}
|
|
116
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
117
|
+
function _ts_metadata(k, v) {
|
|
118
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
119
|
+
}
|
|
120
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
121
|
+
function _ts_param(paramIndex, decorator) {
|
|
122
|
+
return function(target, key) {
|
|
123
|
+
decorator(target, key, paramIndex);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
__name(_ts_param, "_ts_param");
|
|
127
|
+
var RequestService = class {
|
|
128
|
+
static {
|
|
129
|
+
__name(this, "RequestService");
|
|
130
|
+
}
|
|
131
|
+
injectedRequest;
|
|
132
|
+
config;
|
|
133
|
+
constructor(injectedRequest, config) {
|
|
134
|
+
this.injectedRequest = injectedRequest;
|
|
135
|
+
this.config = config;
|
|
136
|
+
}
|
|
137
|
+
// Unwraps the GraphQL { req, reply } context wrapper so every accessor below works across both transports
|
|
138
|
+
get request() {
|
|
139
|
+
return resolveInjectedRequest(this.injectedRequest);
|
|
140
|
+
}
|
|
141
|
+
// Extracts the bearer access token from the Authorization header
|
|
142
|
+
getAccessToken() {
|
|
143
|
+
const authHeader = this.request.headers?.[this.config.guard.authHeaderName];
|
|
144
|
+
if (!authHeader || typeof authHeader !== "string") {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const [type, token] = authHeader.split(" ") ?? [];
|
|
148
|
+
return type === this.config.guard.tokenPrefix && token ? token : null;
|
|
149
|
+
}
|
|
150
|
+
// Extracts the refresh token from the configured httpOnly cookie
|
|
151
|
+
getRefreshToken() {
|
|
152
|
+
try {
|
|
153
|
+
const cookies = this.request.cookies;
|
|
154
|
+
if (cookies && typeof cookies === "object") {
|
|
155
|
+
const refreshToken = cookies[this.config.cookie.refreshCookieName];
|
|
156
|
+
if (refreshToken) {
|
|
157
|
+
return refreshToken;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
} catch (_error) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Returns the value of a specific request header by key
|
|
166
|
+
getHeader(key) {
|
|
167
|
+
return this.request.headers?.[key];
|
|
168
|
+
}
|
|
169
|
+
// Returns the request hostname (without port)
|
|
170
|
+
getHostname() {
|
|
171
|
+
return this.request.hostname ?? "";
|
|
172
|
+
}
|
|
173
|
+
// Returns all request headers
|
|
174
|
+
getAllHeaders() {
|
|
175
|
+
return this.request.headers || {};
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
RequestService = _ts_decorate([
|
|
179
|
+
(0, import_common.Injectable)({
|
|
180
|
+
scope: import_common.Scope.REQUEST
|
|
181
|
+
}),
|
|
182
|
+
_ts_param(0, (0, import_common.Inject)(import_core.REQUEST)),
|
|
183
|
+
_ts_param(1, (0, import_common.Inject)(AUTH_CONFIG)),
|
|
184
|
+
_ts_metadata("design:type", Function),
|
|
185
|
+
_ts_metadata("design:paramtypes", [
|
|
186
|
+
typeof FastifyRequest === "undefined" ? Object : FastifyRequest,
|
|
187
|
+
typeof AuthConfig === "undefined" ? Object : AuthConfig
|
|
188
|
+
])
|
|
189
|
+
], RequestService);
|
|
190
|
+
|
|
191
|
+
// src/request/request.module.ts
|
|
192
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
193
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
194
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
195
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
196
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
197
|
+
}
|
|
198
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
199
|
+
var RequestModule = class {
|
|
200
|
+
static {
|
|
201
|
+
__name(this, "RequestModule");
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
RequestModule = _ts_decorate2([
|
|
205
|
+
(0, import_common2.Global)(),
|
|
206
|
+
(0, import_common2.Module)({
|
|
207
|
+
providers: [
|
|
208
|
+
RequestService
|
|
209
|
+
],
|
|
210
|
+
exports: [
|
|
211
|
+
RequestService
|
|
212
|
+
]
|
|
213
|
+
})
|
|
214
|
+
], RequestModule);
|
|
215
|
+
|
|
216
|
+
// src/auth/guards/vritti-auth.guard.ts
|
|
217
|
+
var import_common6 = require("@nestjs/common");
|
|
218
|
+
var import_constants = require("@nestjs/common/constants");
|
|
219
|
+
var import_core2 = require("@nestjs/core");
|
|
220
|
+
|
|
221
|
+
// src/context/extractors/graphql.extractor.ts
|
|
222
|
+
var graphqlExtractor = {
|
|
223
|
+
getRequest: /* @__PURE__ */ __name((host) => host.getArgByIndex(2).req, "getRequest"),
|
|
224
|
+
getResponse: /* @__PURE__ */ __name((host) => host.getArgByIndex(2).reply, "getResponse")
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// src/context/extractors/http.extractor.ts
|
|
228
|
+
var httpExtractor = {
|
|
229
|
+
getRequest: /* @__PURE__ */ __name((host) => host.switchToHttp().getRequest(), "getRequest"),
|
|
230
|
+
getResponse: /* @__PURE__ */ __name((host) => host.switchToHttp().getResponse(), "getResponse")
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/context/context.registry.ts
|
|
234
|
+
var registry = /* @__PURE__ */ new Map([
|
|
235
|
+
[
|
|
236
|
+
"http",
|
|
237
|
+
httpExtractor
|
|
238
|
+
],
|
|
239
|
+
[
|
|
240
|
+
"graphql",
|
|
241
|
+
graphqlExtractor
|
|
242
|
+
]
|
|
243
|
+
]);
|
|
244
|
+
function resolveExtractor(type) {
|
|
245
|
+
return registry.get(type) ?? httpExtractor;
|
|
246
|
+
}
|
|
247
|
+
__name(resolveExtractor, "resolveExtractor");
|
|
248
|
+
|
|
249
|
+
// src/context/get-request.ts
|
|
250
|
+
function getRequestFromContext(host) {
|
|
251
|
+
return resolveExtractor(host.getType()).getRequest(host);
|
|
252
|
+
}
|
|
253
|
+
__name(getRequestFromContext, "getRequestFromContext");
|
|
254
|
+
|
|
255
|
+
// src/context/get-response.ts
|
|
256
|
+
function getResponseFromContext(host) {
|
|
257
|
+
return resolveExtractor(host.getType()).getResponse(host);
|
|
258
|
+
}
|
|
259
|
+
__name(getResponseFromContext, "getResponseFromContext");
|
|
260
|
+
|
|
261
|
+
// src/auth/decorators/require-session.decorator.ts
|
|
262
|
+
var import_common3 = require("@nestjs/common");
|
|
263
|
+
var REQUIRE_SESSION_KEY = "requiredSessionTypes";
|
|
264
|
+
var RequireSession = /* @__PURE__ */ __name((...types) => (0, import_common3.SetMetadata)(REQUIRE_SESSION_KEY, types), "RequireSession");
|
|
265
|
+
|
|
266
|
+
// src/auth/decorators/skip-csrf.decorator.ts
|
|
267
|
+
var import_common4 = require("@nestjs/common");
|
|
268
|
+
var SKIP_CSRF_KEY = "skipCsrf";
|
|
269
|
+
var SkipCsrf = /* @__PURE__ */ __name(() => (0, import_common4.SetMetadata)(SKIP_CSRF_KEY, true), "SkipCsrf");
|
|
270
|
+
|
|
271
|
+
// src/auth/services/token.service.ts
|
|
272
|
+
var import_common5 = require("@nestjs/common");
|
|
273
|
+
var import_jwt = require("@nestjs/jwt");
|
|
274
|
+
|
|
275
|
+
// src/utils/time.utils.ts
|
|
276
|
+
function parseExpiryToMs(expiry) {
|
|
277
|
+
const match = expiry.match(/^(\d+)([smhdwy])$/);
|
|
278
|
+
if (!match) throw new Error(`Invalid expiry format: ${expiry}`);
|
|
279
|
+
const [, digits = "", unit = ""] = match;
|
|
280
|
+
const value = Number.parseInt(digits, 10);
|
|
281
|
+
const multipliers = {
|
|
282
|
+
s: 1e3,
|
|
283
|
+
m: 6e4,
|
|
284
|
+
h: 36e5,
|
|
285
|
+
d: 864e5,
|
|
286
|
+
w: 6048e5,
|
|
287
|
+
y: 31536e6
|
|
288
|
+
};
|
|
289
|
+
const multiplier = multipliers[unit];
|
|
290
|
+
if (multiplier === void 0) throw new Error(`Invalid expiry format: ${expiry}`);
|
|
291
|
+
return value * multiplier;
|
|
292
|
+
}
|
|
293
|
+
__name(parseExpiryToMs, "parseExpiryToMs");
|
|
294
|
+
|
|
295
|
+
// src/auth/utils/token-hash.util.ts
|
|
296
|
+
var crypto = __toESM(require("crypto"), 1);
|
|
297
|
+
function hashToken(token) {
|
|
298
|
+
return crypto.createHash("sha256").update(token).digest("hex");
|
|
299
|
+
}
|
|
300
|
+
__name(hashToken, "hashToken");
|
|
301
|
+
function verifyTokenHash(token, expectedHash) {
|
|
302
|
+
const computedHash = hashToken(token);
|
|
303
|
+
if (computedHash.length !== expectedHash.length) return false;
|
|
304
|
+
return crypto.timingSafeEqual(Buffer.from(computedHash, "hex"), Buffer.from(expectedHash, "hex"));
|
|
305
|
+
}
|
|
306
|
+
__name(verifyTokenHash, "verifyTokenHash");
|
|
307
|
+
|
|
308
|
+
// src/auth/services/token.service.ts
|
|
309
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
310
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
311
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
312
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
313
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
314
|
+
}
|
|
315
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
316
|
+
function _ts_metadata2(k, v) {
|
|
317
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
318
|
+
}
|
|
319
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
320
|
+
function _ts_param2(paramIndex, decorator) {
|
|
321
|
+
return function(target, key) {
|
|
322
|
+
decorator(target, key, paramIndex);
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
__name(_ts_param2, "_ts_param");
|
|
326
|
+
var TokenService = class _TokenService {
|
|
327
|
+
static {
|
|
328
|
+
__name(this, "TokenService");
|
|
329
|
+
}
|
|
330
|
+
jwtService;
|
|
331
|
+
config;
|
|
332
|
+
logger = new import_common5.Logger(_TokenService.name);
|
|
333
|
+
constructor(jwtService, config) {
|
|
334
|
+
this.jwtService = jwtService;
|
|
335
|
+
this.config = config;
|
|
336
|
+
}
|
|
337
|
+
// ---- Generation ----
|
|
338
|
+
// Generates an access token bound to the given refresh token
|
|
339
|
+
generateAccessToken(sessionInfo, refreshToken) {
|
|
340
|
+
const { userId, sessionId, sessionType, ...metadata } = sessionInfo;
|
|
341
|
+
return this.jwtService.sign({
|
|
342
|
+
sessionType,
|
|
343
|
+
tokenType: TokenType.ACCESS,
|
|
344
|
+
userId,
|
|
345
|
+
sessionId,
|
|
346
|
+
refreshTokenHash: hashToken(refreshToken),
|
|
347
|
+
...metadata
|
|
348
|
+
}, {
|
|
349
|
+
expiresIn: this.config.tokenExpiry.access
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
// Generates a refresh token for session persistence
|
|
353
|
+
generateRefreshToken(sessionInfo) {
|
|
354
|
+
const { userId, sessionId, sessionType, ...metadata } = sessionInfo;
|
|
355
|
+
return this.jwtService.sign({
|
|
356
|
+
sessionType,
|
|
357
|
+
tokenType: TokenType.REFRESH,
|
|
358
|
+
userId,
|
|
359
|
+
sessionId,
|
|
360
|
+
...metadata
|
|
361
|
+
}, {
|
|
362
|
+
expiresIn: this.config.tokenExpiry.refresh
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
// Signs an arbitrary payload with optional JWT options
|
|
366
|
+
sign(payload, options) {
|
|
367
|
+
return this.jwtService.sign(payload, options);
|
|
368
|
+
}
|
|
369
|
+
// Verifies a token and ensures it matches the expected token type
|
|
370
|
+
verify(token, expectedType) {
|
|
371
|
+
try {
|
|
372
|
+
const payload = this.jwtService.verify(token);
|
|
373
|
+
if (payload.tokenType !== expectedType) {
|
|
374
|
+
throw new Error(`Expected ${expectedType} token, got ${payload.tokenType}`);
|
|
375
|
+
}
|
|
376
|
+
return payload;
|
|
377
|
+
} catch (error) {
|
|
378
|
+
this.logger.error(`Failed to verify ${expectedType} token`, error);
|
|
379
|
+
throw error;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
// Returns the expiry as a Date for the given token type
|
|
383
|
+
getExpiryTime(type) {
|
|
384
|
+
return new Date(Date.now() + parseExpiryToMs(this.config.tokenExpiry[type]));
|
|
385
|
+
}
|
|
386
|
+
// Returns the token lifetime in seconds for the given type
|
|
387
|
+
getExpiryInSeconds(type) {
|
|
388
|
+
return Math.floor(parseExpiryToMs(this.config.tokenExpiry[type]) / 1e3);
|
|
389
|
+
}
|
|
390
|
+
// ---- Validation ----
|
|
391
|
+
// Decodes and validates an access token JWT
|
|
392
|
+
validateAccessToken(token) {
|
|
393
|
+
try {
|
|
394
|
+
const decoded = this.jwtService.verify(token);
|
|
395
|
+
if (decoded.tokenType !== TokenType.ACCESS) {
|
|
396
|
+
throw new import_common5.UnauthorizedException("Invalid token type");
|
|
397
|
+
}
|
|
398
|
+
return decoded;
|
|
399
|
+
} catch (error) {
|
|
400
|
+
if (error instanceof import_common5.UnauthorizedException) throw error;
|
|
401
|
+
const jwtError = error;
|
|
402
|
+
switch (jwtError.name) {
|
|
403
|
+
case "TokenExpiredError":
|
|
404
|
+
throw new import_common5.UnauthorizedException("Access token has expired");
|
|
405
|
+
case "JsonWebTokenError":
|
|
406
|
+
throw new import_common5.UnauthorizedException("Invalid access token");
|
|
407
|
+
case "NotBeforeError":
|
|
408
|
+
throw new import_common5.UnauthorizedException("Access token not yet valid");
|
|
409
|
+
default:
|
|
410
|
+
throw new import_common5.UnauthorizedException("Access token validation failed");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// Decodes and validates a refresh token JWT
|
|
415
|
+
validateRefreshToken(token) {
|
|
416
|
+
try {
|
|
417
|
+
const decoded = this.jwtService.verify(token);
|
|
418
|
+
if (decoded.tokenType !== TokenType.REFRESH) {
|
|
419
|
+
throw new import_common5.UnauthorizedException("Invalid token type");
|
|
420
|
+
}
|
|
421
|
+
return decoded;
|
|
422
|
+
} catch (error) {
|
|
423
|
+
if (error instanceof import_common5.UnauthorizedException) throw error;
|
|
424
|
+
throw new import_common5.UnauthorizedException("Invalid or expired session");
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
// Validates that the access token is bound to the refresh token
|
|
428
|
+
validateTokenBinding(accessToken, refreshToken) {
|
|
429
|
+
if (!verifyTokenHash(refreshToken, accessToken.refreshTokenHash)) {
|
|
430
|
+
throw new import_common5.UnauthorizedException("Session validation failed");
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
TokenService = _ts_decorate3([
|
|
435
|
+
(0, import_common5.Injectable)(),
|
|
436
|
+
_ts_param2(1, (0, import_common5.Inject)(AUTH_CONFIG)),
|
|
437
|
+
_ts_metadata2("design:type", Function),
|
|
438
|
+
_ts_metadata2("design:paramtypes", [
|
|
439
|
+
typeof import_jwt.JwtService === "undefined" ? Object : import_jwt.JwtService,
|
|
440
|
+
typeof AuthConfig === "undefined" ? Object : AuthConfig
|
|
441
|
+
])
|
|
442
|
+
], TokenService);
|
|
443
|
+
|
|
444
|
+
// src/auth/guards/vritti-auth.guard.ts
|
|
445
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
446
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
447
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
448
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
449
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
450
|
+
}
|
|
451
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
452
|
+
function _ts_metadata3(k, v) {
|
|
453
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
454
|
+
}
|
|
455
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
456
|
+
function _ts_param3(paramIndex, decorator) {
|
|
457
|
+
return function(target, key) {
|
|
458
|
+
decorator(target, key, paramIndex);
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
__name(_ts_param3, "_ts_param");
|
|
462
|
+
var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
463
|
+
static {
|
|
464
|
+
__name(this, "VrittiAuthGuard");
|
|
465
|
+
}
|
|
466
|
+
reflector;
|
|
467
|
+
requestService;
|
|
468
|
+
tokenService;
|
|
469
|
+
config;
|
|
470
|
+
logger = new import_common6.Logger(_VrittiAuthGuard.name);
|
|
471
|
+
constructor(reflector, requestService, tokenService, config) {
|
|
472
|
+
this.reflector = reflector;
|
|
473
|
+
this.requestService = requestService;
|
|
474
|
+
this.tokenService = tokenService;
|
|
475
|
+
this.config = config;
|
|
476
|
+
}
|
|
477
|
+
async canActivate(context) {
|
|
478
|
+
const request = getRequestFromContext(context);
|
|
479
|
+
const reply = getResponseFromContext(context);
|
|
480
|
+
const route = `${request.method} ${request.url}`;
|
|
481
|
+
request.authConfig = this.config;
|
|
482
|
+
const csrfExemptTransports = this.config.guard.csrfExemptTransports ?? [];
|
|
483
|
+
const skipCsrf = this.reflector.getAllAndOverride(SKIP_CSRF_KEY, [
|
|
484
|
+
context.getHandler(),
|
|
485
|
+
context.getClass()
|
|
486
|
+
]) || csrfExemptTransports.includes(context.getType());
|
|
487
|
+
const isPublic = this.reflector.getAllAndOverride("isPublic", [
|
|
488
|
+
context.getHandler(),
|
|
489
|
+
context.getClass()
|
|
490
|
+
]);
|
|
491
|
+
if (isPublic) {
|
|
492
|
+
if (!skipCsrf) {
|
|
493
|
+
await this.validateCsrf(request, reply);
|
|
494
|
+
}
|
|
495
|
+
this.logger.debug(`${route} \u2014 public endpoint, skipping auth`);
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
const requiredSessionTypes = this.reflector.getAllAndOverride(REQUIRE_SESSION_KEY, [
|
|
499
|
+
context.getHandler(),
|
|
500
|
+
context.getClass()
|
|
501
|
+
]);
|
|
502
|
+
const isSseEndpoint = this.reflector.get(import_constants.SSE_METADATA, context.getHandler());
|
|
503
|
+
if (isSseEndpoint) {
|
|
504
|
+
this.logger.debug(`${route} \u2014 SSE endpoint, authenticating via refresh cookie`);
|
|
505
|
+
return this.handleSseAuth(request, requiredSessionTypes);
|
|
506
|
+
}
|
|
507
|
+
const sessionType = await this.handleHttpAuth(request, requiredSessionTypes);
|
|
508
|
+
const csrfExemptSessionTypes = this.config.guard.csrfExemptSessionTypes ?? [];
|
|
509
|
+
if (!skipCsrf && !csrfExemptSessionTypes.includes(sessionType)) {
|
|
510
|
+
await this.validateCsrf(request, reply);
|
|
511
|
+
}
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
// Authenticates standard HTTP requests using the access token from Authorization header
|
|
515
|
+
async handleHttpAuth(request, requiredSessionTypes) {
|
|
516
|
+
const route = `${request.method} ${request.url}`;
|
|
517
|
+
const accessToken = this.requestService.getAccessToken();
|
|
518
|
+
if (!accessToken) {
|
|
519
|
+
this.logger.warn(`${route} \u2014 no access token found`);
|
|
520
|
+
throw new import_common6.UnauthorizedException("Access token not found");
|
|
521
|
+
}
|
|
522
|
+
const decoded = this.tokenService.validateAccessToken(accessToken);
|
|
523
|
+
const refreshTokenBindingExemptSessionTypes = this.config.guard.refreshTokenBindingExemptSessionTypes ?? [];
|
|
524
|
+
if (!refreshTokenBindingExemptSessionTypes.includes(decoded.sessionType)) {
|
|
525
|
+
const refreshToken = this.requestService.getRefreshToken();
|
|
526
|
+
if (!refreshToken) {
|
|
527
|
+
throw new import_common6.UnauthorizedException("Session validation failed");
|
|
528
|
+
}
|
|
529
|
+
this.tokenService.validateTokenBinding(decoded, refreshToken);
|
|
530
|
+
}
|
|
531
|
+
if (requiredSessionTypes?.length && !requiredSessionTypes.includes(decoded.sessionType)) {
|
|
532
|
+
this.logger.warn(`${route} \u2014 session type ${decoded.sessionType} not in allowed: [${requiredSessionTypes.join(", ")}]`);
|
|
533
|
+
throw new import_common6.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
|
|
534
|
+
}
|
|
535
|
+
const { tokenType: _tokenType, refreshTokenHash: _hash, exp: _exp, iat: _iat, ...sessionInfo } = decoded;
|
|
536
|
+
request.sessionInfo = sessionInfo;
|
|
537
|
+
const onAuthenticated = this.config.guard.onAuthenticated;
|
|
538
|
+
if (onAuthenticated) {
|
|
539
|
+
await onAuthenticated(this.requestService, request.sessionInfo);
|
|
540
|
+
}
|
|
541
|
+
this.logger.debug(`${route} \u2014 authenticated user: ${decoded.userId} (${decoded.sessionType})`);
|
|
542
|
+
return decoded.sessionType;
|
|
543
|
+
}
|
|
544
|
+
// Authenticates SSE connections using the refresh token httpOnly cookie
|
|
545
|
+
handleSseAuth(request, requiredSessionTypes) {
|
|
546
|
+
const refreshToken = this.requestService.getRefreshToken();
|
|
547
|
+
if (!refreshToken) {
|
|
548
|
+
this.logger.warn(`SSE ${request.url} \u2014 no refresh token cookie`);
|
|
549
|
+
throw new import_common6.UnauthorizedException("Authentication required");
|
|
550
|
+
}
|
|
551
|
+
const decoded = this.tokenService.validateRefreshToken(refreshToken);
|
|
552
|
+
if (requiredSessionTypes?.length && !requiredSessionTypes.includes(decoded.sessionType)) {
|
|
553
|
+
this.logger.warn(`SSE ${request.url} \u2014 session type ${decoded.sessionType} not allowed`);
|
|
554
|
+
throw new import_common6.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
|
|
555
|
+
}
|
|
556
|
+
const { tokenType: _tokenType, exp: _exp, iat: _iat, ...sessionInfo } = decoded;
|
|
557
|
+
request.sessionInfo = sessionInfo;
|
|
558
|
+
this.logger.debug(`SSE ${request.url} \u2014 authenticated user: ${decoded.userId} (${decoded.sessionType})`);
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
// Validates CSRF token for state-changing requests
|
|
562
|
+
async validateCsrf(request, reply) {
|
|
563
|
+
const safeMethods = [
|
|
564
|
+
"GET",
|
|
565
|
+
"HEAD",
|
|
566
|
+
"OPTIONS"
|
|
567
|
+
];
|
|
568
|
+
if (safeMethods.includes(request.method)) return;
|
|
569
|
+
try {
|
|
570
|
+
const fastifyInstance = request.server;
|
|
571
|
+
const csrfProtection = fastifyInstance.csrfProtection;
|
|
572
|
+
if (!csrfProtection) {
|
|
573
|
+
throw new import_common6.ForbiddenException("CSRF protection not configured");
|
|
574
|
+
}
|
|
575
|
+
await new Promise((resolve, reject) => {
|
|
576
|
+
const originalSend = reply.send.bind(reply);
|
|
577
|
+
reply.send = () => {
|
|
578
|
+
reply.send = originalSend;
|
|
579
|
+
reject(new Error("CSRF validation failed"));
|
|
580
|
+
return reply;
|
|
581
|
+
};
|
|
582
|
+
csrfProtection(request, reply, (err) => {
|
|
583
|
+
reply.send = originalSend;
|
|
584
|
+
if (err) reject(err);
|
|
585
|
+
else resolve();
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
} catch (_error) {
|
|
589
|
+
this.logger.warn(`${request.method} ${request.url} \u2014 CSRF validation failed`);
|
|
590
|
+
throw new import_common6.ForbiddenException({
|
|
591
|
+
errors: [
|
|
592
|
+
{
|
|
593
|
+
field: "csrf",
|
|
594
|
+
message: "Invalid or missing CSRF token"
|
|
595
|
+
}
|
|
596
|
+
],
|
|
597
|
+
message: "CSRF validation failed"
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
VrittiAuthGuard = _ts_decorate4([
|
|
603
|
+
(0, import_common6.Injectable)({
|
|
604
|
+
scope: import_common6.Scope.REQUEST
|
|
605
|
+
}),
|
|
606
|
+
_ts_param3(3, (0, import_common6.Inject)(AUTH_CONFIG)),
|
|
607
|
+
_ts_metadata3("design:type", Function),
|
|
608
|
+
_ts_metadata3("design:paramtypes", [
|
|
609
|
+
typeof import_core2.Reflector === "undefined" ? Object : import_core2.Reflector,
|
|
610
|
+
typeof RequestService === "undefined" ? Object : RequestService,
|
|
611
|
+
typeof TokenService === "undefined" ? Object : TokenService,
|
|
612
|
+
typeof AuthConfig === "undefined" ? Object : AuthConfig
|
|
613
|
+
])
|
|
614
|
+
], VrittiAuthGuard);
|
|
615
|
+
|
|
616
|
+
// src/auth/auth-config.module.ts
|
|
617
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
618
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
619
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
620
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
621
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
622
|
+
}
|
|
623
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
624
|
+
function mergeWithDefaults(input) {
|
|
625
|
+
return {
|
|
626
|
+
tokenExpiry: input.tokenExpiry,
|
|
627
|
+
cookie: {
|
|
628
|
+
...AUTH_CONFIG_DEFAULTS.cookie,
|
|
629
|
+
...input.cookie ?? {}
|
|
630
|
+
},
|
|
631
|
+
guard: {
|
|
632
|
+
...AUTH_CONFIG_DEFAULTS.guard,
|
|
633
|
+
...input.guard ?? {}
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
638
|
+
var AuthConfigModule = class _AuthConfigModule {
|
|
639
|
+
static {
|
|
640
|
+
__name(this, "AuthConfigModule");
|
|
641
|
+
}
|
|
642
|
+
// Registers JWT, TokenService, and global VrittiAuthGuard
|
|
643
|
+
static forRootAsync(options) {
|
|
644
|
+
return {
|
|
645
|
+
module: _AuthConfigModule,
|
|
646
|
+
imports: [
|
|
647
|
+
import_config.ConfigModule,
|
|
648
|
+
RequestModule,
|
|
649
|
+
import_jwt2.JwtModule.registerAsync({
|
|
650
|
+
imports: [
|
|
651
|
+
import_config.ConfigModule
|
|
652
|
+
],
|
|
653
|
+
inject: [
|
|
654
|
+
import_config.ConfigService
|
|
655
|
+
],
|
|
656
|
+
useFactory: /* @__PURE__ */ __name((config) => ({
|
|
657
|
+
secret: config.getOrThrow("JWT_SECRET"),
|
|
658
|
+
signOptions: {
|
|
659
|
+
algorithm: "HS256"
|
|
660
|
+
}
|
|
661
|
+
}), "useFactory")
|
|
662
|
+
})
|
|
663
|
+
],
|
|
664
|
+
providers: [
|
|
665
|
+
{
|
|
666
|
+
provide: import_core3.Reflector,
|
|
667
|
+
useClass: import_core3.Reflector
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
provide: import_core3.APP_GUARD,
|
|
671
|
+
useClass: VrittiAuthGuard
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
provide: AUTH_CONFIG,
|
|
675
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
676
|
+
const input = await options.useFactory(...args);
|
|
677
|
+
return mergeWithDefaults(input);
|
|
678
|
+
}, "useFactory"),
|
|
679
|
+
inject: options.inject || []
|
|
680
|
+
},
|
|
681
|
+
TokenService
|
|
682
|
+
],
|
|
683
|
+
exports: [
|
|
684
|
+
import_jwt2.JwtModule,
|
|
685
|
+
TokenService,
|
|
686
|
+
AUTH_CONFIG
|
|
687
|
+
]
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
AuthConfigModule = _ts_decorate5([
|
|
692
|
+
(0, import_common7.Global)(),
|
|
693
|
+
(0, import_common7.Module)({})
|
|
694
|
+
], AuthConfigModule);
|
|
695
|
+
|
|
696
|
+
// src/auth/decorators/access-token.decorator.ts
|
|
697
|
+
var import_common8 = require("@nestjs/common");
|
|
698
|
+
var AccessToken = (0, import_common8.createParamDecorator)((_data, ctx) => {
|
|
699
|
+
const request = getRequestFromContext(ctx);
|
|
700
|
+
const authHeader = request.headers.authorization;
|
|
701
|
+
return authHeader?.replace("Bearer ", "") || "";
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
// src/auth/decorators/client-ip.decorator.ts
|
|
705
|
+
var import_common9 = require("@nestjs/common");
|
|
706
|
+
var ClientIp = (0, import_common9.createParamDecorator)((_data, ctx) => {
|
|
707
|
+
return getRequestFromContext(ctx).ip;
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
// src/auth/decorators/cookie-domain.decorator.ts
|
|
711
|
+
var import_common10 = require("@nestjs/common");
|
|
712
|
+
var CookieDomain = (0, import_common10.createParamDecorator)((_data, ctx) => {
|
|
713
|
+
const request = getRequestFromContext(ctx);
|
|
714
|
+
const forwarded = request.headers["x-forwarded-host"];
|
|
715
|
+
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
716
|
+
const hostStr = raw ?? request.hostname;
|
|
717
|
+
const domain = hostStr.split(":")[0] ?? hostStr;
|
|
718
|
+
const baseDomain = request.authConfig?.cookie.refreshCookieDomain ?? AUTH_CONFIG_DEFAULTS.cookie.refreshCookieDomain ?? "";
|
|
719
|
+
return domain.endsWith(`.${baseDomain}`) ? domain : baseDomain;
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// src/auth/decorators/cookie-name.decorator.ts
|
|
723
|
+
var import_common11 = require("@nestjs/common");
|
|
724
|
+
var CookieName = (0, import_common11.createParamDecorator)((_data, ctx) => {
|
|
725
|
+
const request = getRequestFromContext(ctx);
|
|
726
|
+
return request.authConfig?.cookie.refreshCookieName ?? AUTH_CONFIG_DEFAULTS.cookie.refreshCookieName;
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
// src/auth/decorators/hostname.decorator.ts
|
|
730
|
+
var import_common12 = require("@nestjs/common");
|
|
731
|
+
var Hostname = (0, import_common12.createParamDecorator)((_data, ctx) => {
|
|
732
|
+
const request = getRequestFromContext(ctx);
|
|
733
|
+
const forwarded = request.headers["x-forwarded-host"];
|
|
734
|
+
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
735
|
+
const hostStr = raw ?? request.hostname;
|
|
736
|
+
return hostStr.split(":")[0] ?? hostStr;
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
// src/auth/decorators/public.decorator.ts
|
|
740
|
+
var import_common13 = require("@nestjs/common");
|
|
741
|
+
var Public = /* @__PURE__ */ __name(() => (0, import_common13.SetMetadata)("isPublic", true), "Public");
|
|
742
|
+
|
|
743
|
+
// src/auth/decorators/refresh-cookie-options.decorator.ts
|
|
744
|
+
var import_common33 = require("@nestjs/common");
|
|
745
|
+
|
|
746
|
+
// src/exceptions/bad-gateway.exception.ts
|
|
747
|
+
var import_common15 = require("@nestjs/common");
|
|
748
|
+
|
|
749
|
+
// src/exceptions/base-field.exception.ts
|
|
750
|
+
var import_common14 = require("@nestjs/common");
|
|
751
|
+
var HttpProblemException = class extends import_common14.HttpException {
|
|
752
|
+
static {
|
|
753
|
+
__name(this, "HttpProblemException");
|
|
754
|
+
}
|
|
755
|
+
constructor(detailOrOptions, httpStatus) {
|
|
756
|
+
const options = typeof detailOrOptions === "string" ? {
|
|
757
|
+
detail: detailOrOptions
|
|
758
|
+
} : detailOrOptions;
|
|
759
|
+
super({
|
|
760
|
+
type: options.type ?? "about:blank",
|
|
761
|
+
label: options.label,
|
|
762
|
+
detail: options.detail,
|
|
763
|
+
errors: options.errors ?? []
|
|
764
|
+
}, httpStatus);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
// src/exceptions/bad-request.exception.ts
|
|
769
|
+
var import_common16 = require("@nestjs/common");
|
|
770
|
+
|
|
771
|
+
// src/exceptions/conflict.exception.ts
|
|
772
|
+
var import_common17 = require("@nestjs/common");
|
|
773
|
+
|
|
774
|
+
// src/exceptions/forbidden.exception.ts
|
|
775
|
+
var import_common18 = require("@nestjs/common");
|
|
776
|
+
|
|
777
|
+
// src/exceptions/gone.exception.ts
|
|
778
|
+
var import_common19 = require("@nestjs/common");
|
|
779
|
+
|
|
780
|
+
// src/exceptions/internal-server-error.exception.ts
|
|
781
|
+
var import_common20 = require("@nestjs/common");
|
|
782
|
+
|
|
783
|
+
// src/exceptions/method-not-allowed.exception.ts
|
|
784
|
+
var import_common21 = require("@nestjs/common");
|
|
785
|
+
|
|
786
|
+
// src/exceptions/not-acceptable.exception.ts
|
|
787
|
+
var import_common22 = require("@nestjs/common");
|
|
788
|
+
|
|
789
|
+
// src/exceptions/not-found.exception.ts
|
|
790
|
+
var import_common23 = require("@nestjs/common");
|
|
791
|
+
|
|
792
|
+
// src/exceptions/not-implemented.exception.ts
|
|
793
|
+
var import_common24 = require("@nestjs/common");
|
|
794
|
+
|
|
795
|
+
// src/exceptions/payload-too-large.exception.ts
|
|
796
|
+
var import_common25 = require("@nestjs/common");
|
|
797
|
+
|
|
798
|
+
// src/exceptions/request-timeout.exception.ts
|
|
799
|
+
var import_common26 = require("@nestjs/common");
|
|
800
|
+
|
|
801
|
+
// src/exceptions/service-unavailable.exception.ts
|
|
802
|
+
var import_common27 = require("@nestjs/common");
|
|
803
|
+
|
|
804
|
+
// src/exceptions/too-many-requests.exception.ts
|
|
805
|
+
var import_common28 = require("@nestjs/common");
|
|
806
|
+
|
|
807
|
+
// src/exceptions/unauthorized.exception.ts
|
|
808
|
+
var import_common29 = require("@nestjs/common");
|
|
809
|
+
var UnauthorizedException3 = class extends HttpProblemException {
|
|
810
|
+
static {
|
|
811
|
+
__name(this, "UnauthorizedException");
|
|
812
|
+
}
|
|
813
|
+
constructor(detailOrOptions) {
|
|
814
|
+
super(detailOrOptions ?? "Unauthorized", import_common29.HttpStatus.UNAUTHORIZED);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
// src/exceptions/unprocessable-entity.exception.ts
|
|
819
|
+
var import_common30 = require("@nestjs/common");
|
|
820
|
+
|
|
821
|
+
// src/exceptions/unsupported-media-type.exception.ts
|
|
822
|
+
var import_common31 = require("@nestjs/common");
|
|
823
|
+
|
|
824
|
+
// src/exceptions/validation.exception.ts
|
|
825
|
+
var import_common32 = require("@nestjs/common");
|
|
826
|
+
|
|
827
|
+
// src/auth/decorators/refresh-cookie-options.decorator.ts
|
|
828
|
+
function buildCookieOptionsForHost(cookieConfig, hostname) {
|
|
829
|
+
const baseDomain = cookieConfig.refreshCookieDomain;
|
|
830
|
+
if (!baseDomain) {
|
|
831
|
+
throw new Error("refreshCookieDomain must be configured before using @RefreshCookieOptions()");
|
|
832
|
+
}
|
|
833
|
+
if (!hostname.endsWith(`.${baseDomain}`)) {
|
|
834
|
+
throw new UnauthorizedException3("Invalid request host.");
|
|
835
|
+
}
|
|
836
|
+
return {
|
|
837
|
+
httpOnly: true,
|
|
838
|
+
secure: cookieConfig.refreshCookieSecure,
|
|
839
|
+
sameSite: cookieConfig.refreshCookieSameSite,
|
|
840
|
+
path: cookieConfig.refreshCookiePath,
|
|
841
|
+
maxAge: cookieConfig.refreshCookieMaxAge,
|
|
842
|
+
domain: hostname
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
__name(buildCookieOptionsForHost, "buildCookieOptionsForHost");
|
|
846
|
+
var RefreshCookieOptions = (0, import_common33.createParamDecorator)((_data, ctx) => {
|
|
847
|
+
const request = getRequestFromContext(ctx);
|
|
848
|
+
const forwarded = request.headers["x-forwarded-host"];
|
|
849
|
+
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
850
|
+
const hostStr = raw ?? request.hostname;
|
|
851
|
+
const domain = hostStr.split(":")[0] ?? hostStr;
|
|
852
|
+
const cookieConfig = request.authConfig?.cookie ?? AUTH_CONFIG_DEFAULTS.cookie;
|
|
853
|
+
return buildCookieOptionsForHost(cookieConfig, domain);
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
// src/auth/decorators/refresh-token-cookie.decorator.ts
|
|
857
|
+
var import_common34 = require("@nestjs/common");
|
|
858
|
+
var RefreshTokenCookie = (0, import_common34.createParamDecorator)((_data, ctx) => {
|
|
859
|
+
const request = getRequestFromContext(ctx);
|
|
860
|
+
const cookies = request.cookies ?? {};
|
|
861
|
+
const cookieName = request.authConfig?.cookie.refreshCookieName ?? AUTH_CONFIG_DEFAULTS.cookie.refreshCookieName;
|
|
862
|
+
return cookies[cookieName];
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
// src/auth/decorators/session-data.decorator.ts
|
|
866
|
+
var import_common35 = require("@nestjs/common");
|
|
867
|
+
var SessionData = (0, import_common35.createParamDecorator)((_data, ctx) => {
|
|
868
|
+
const request = getRequestFromContext(ctx);
|
|
869
|
+
const sessionInfo = request.sessionInfo;
|
|
870
|
+
if (!sessionInfo?.sessionId) {
|
|
871
|
+
throw new Error("Session info not found on request. Ensure route is protected by auth guard.");
|
|
872
|
+
}
|
|
873
|
+
return {
|
|
874
|
+
userId: sessionInfo.userId,
|
|
875
|
+
sessionId: sessionInfo.sessionId,
|
|
876
|
+
sessionType: sessionInfo.sessionType
|
|
877
|
+
};
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
// src/auth/decorators/subdomain.decorator.ts
|
|
881
|
+
var import_common36 = require("@nestjs/common");
|
|
882
|
+
var Subdomain = (0, import_common36.createParamDecorator)((_data, ctx) => {
|
|
883
|
+
const request = getRequestFromContext(ctx);
|
|
884
|
+
const origin = request.headers.origin;
|
|
885
|
+
if (origin) {
|
|
886
|
+
try {
|
|
887
|
+
const url = new URL(origin);
|
|
888
|
+
return url.hostname.split(".")[0];
|
|
889
|
+
} catch {
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
const forwarded = request.headers["x-forwarded-host"];
|
|
893
|
+
const host = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
894
|
+
if (host) return host.split(".")[0];
|
|
895
|
+
return void 0;
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
// src/auth/decorators/user-agent.decorator.ts
|
|
899
|
+
var import_common37 = require("@nestjs/common");
|
|
900
|
+
var UserAgent = (0, import_common37.createParamDecorator)((_data, ctx) => {
|
|
901
|
+
const userAgent = getRequestFromContext(ctx).headers["user-agent"];
|
|
902
|
+
return Array.isArray(userAgent) ? userAgent[0] : userAgent;
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
// src/auth/decorators/user-id.decorator.ts
|
|
906
|
+
var import_common38 = require("@nestjs/common");
|
|
907
|
+
var UserId = (0, import_common38.createParamDecorator)((_data, ctx) => {
|
|
908
|
+
const request = getRequestFromContext(ctx);
|
|
909
|
+
const sessionInfo = request.sessionInfo;
|
|
910
|
+
if (!sessionInfo?.userId) {
|
|
911
|
+
throw new Error("User ID not found on request. Ensure route is protected by auth guard.");
|
|
912
|
+
}
|
|
913
|
+
return sessionInfo.userId;
|
|
914
|
+
});
|
|
915
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
916
|
+
0 && (module.exports = {
|
|
917
|
+
AUTH_CONFIG,
|
|
918
|
+
AUTH_CONFIG_DEFAULTS,
|
|
919
|
+
AccessToken,
|
|
920
|
+
AuthConfigModule,
|
|
921
|
+
ClientIp,
|
|
922
|
+
CookieDomain,
|
|
923
|
+
CookieName,
|
|
924
|
+
Hostname,
|
|
925
|
+
Public,
|
|
926
|
+
REQUIRE_SESSION_KEY,
|
|
927
|
+
RefreshCookieOptions,
|
|
928
|
+
RefreshTokenCookie,
|
|
929
|
+
RequireSession,
|
|
930
|
+
SKIP_CSRF_KEY,
|
|
931
|
+
SessionData,
|
|
932
|
+
SkipCsrf,
|
|
933
|
+
Subdomain,
|
|
934
|
+
TokenService,
|
|
935
|
+
TokenType,
|
|
936
|
+
UserAgent,
|
|
937
|
+
UserId,
|
|
938
|
+
VrittiAuthGuard,
|
|
939
|
+
hashToken,
|
|
940
|
+
verifyTokenHash
|
|
941
|
+
});
|
|
942
|
+
//# sourceMappingURL=auth.cjs.map
|