@vritti/api-sdk 0.3.16 → 0.4.0
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 +178 -152
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +25 -43
- package/dist/auth.d.ts +25 -43
- package/dist/auth.js +101 -72
- package/dist/auth.js.map +1 -1
- package/dist/data-table.cjs +4 -5
- package/dist/data-table.cjs.map +1 -1
- package/dist/data-table.js +4 -5
- package/dist/data-table.js.map +1 -1
- package/dist/index.d.cts +15 -9
- package/dist/index.d.ts +15 -9
- package/dist/nats.cjs +30 -36
- package/dist/nats.cjs.map +1 -1
- package/dist/nats.d.cts +20 -9
- package/dist/nats.d.ts +20 -9
- package/dist/nats.js +30 -36
- package/dist/nats.js.map +1 -1
- package/dist/root.cjs +15 -4
- package/dist/root.cjs.map +1 -1
- package/dist/root.js +15 -4
- package/dist/root.js.map +1 -1
- package/package.json +1 -1
package/dist/auth.cjs
CHANGED
|
@@ -31,11 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/auth/index.ts
|
|
32
32
|
var auth_exports = {};
|
|
33
33
|
__export(auth_exports, {
|
|
34
|
-
APP_SESSION_TYPE: () => APP_SESSION_TYPE,
|
|
35
34
|
AUTH_CONFIG: () => AUTH_CONFIG,
|
|
36
35
|
AUTH_CONFIG_DEFAULTS: () => AUTH_CONFIG_DEFAULTS,
|
|
37
36
|
AccessToken: () => AccessToken,
|
|
38
37
|
AuthConfigModule: () => AuthConfigModule,
|
|
38
|
+
AuthType: () => AuthType,
|
|
39
39
|
CLIENT_ID_HEADER: () => CLIENT_ID_HEADER,
|
|
40
40
|
ClientIp: () => ClientIp,
|
|
41
41
|
CookieDomain: () => CookieDomain,
|
|
@@ -43,13 +43,10 @@ __export(auth_exports, {
|
|
|
43
43
|
Hostname: () => Hostname,
|
|
44
44
|
MAX_CLOCK_SKEW_SECONDS: () => MAX_CLOCK_SKEW_SECONDS,
|
|
45
45
|
PARTY_ID_HEADER: () => PARTY_ID_HEADER,
|
|
46
|
-
|
|
47
|
-
REQUIRE_APP_KEY: () => REQUIRE_APP_KEY,
|
|
48
|
-
REQUIRE_SESSION_KEY: () => REQUIRE_SESSION_KEY,
|
|
46
|
+
REQUIRE_AUTH_KEY: () => REQUIRE_AUTH_KEY,
|
|
49
47
|
RefreshCookieOptions: () => RefreshCookieOptions,
|
|
50
48
|
RefreshTokenCookie: () => RefreshTokenCookie,
|
|
51
|
-
|
|
52
|
-
RequireSession: () => RequireSession,
|
|
49
|
+
Require: () => Require,
|
|
53
50
|
SKIP_CSRF_KEY: () => SKIP_CSRF_KEY,
|
|
54
51
|
SessionData: () => SessionData,
|
|
55
52
|
SkipCsrf: () => SkipCsrf,
|
|
@@ -78,7 +75,6 @@ var WORKSPACE_HEADER_ORDER = [
|
|
|
78
75
|
var CLIENT_ID_HEADER = "x-vritti-client-id";
|
|
79
76
|
var PARTY_ID_HEADER = "x-party-id";
|
|
80
77
|
var MAX_CLOCK_SKEW_SECONDS = 300;
|
|
81
|
-
var APP_SESSION_TYPE = "APP";
|
|
82
78
|
|
|
83
79
|
// src/auth/auth.config.ts
|
|
84
80
|
var AUTH_CONFIG = Symbol("AUTH_CONFIG");
|
|
@@ -106,7 +102,7 @@ var TokenType = /* @__PURE__ */ (function(TokenType2) {
|
|
|
106
102
|
})({});
|
|
107
103
|
|
|
108
104
|
// src/auth/auth-config.module.ts
|
|
109
|
-
var
|
|
105
|
+
var import_common7 = require("@nestjs/common");
|
|
110
106
|
var import_config = require("@nestjs/config");
|
|
111
107
|
var import_core3 = require("@nestjs/core");
|
|
112
108
|
var import_jwt2 = require("@nestjs/jwt");
|
|
@@ -276,7 +272,7 @@ RequestModule = _ts_decorate2([
|
|
|
276
272
|
], RequestModule);
|
|
277
273
|
|
|
278
274
|
// src/auth/guards/vritti-auth.guard.ts
|
|
279
|
-
var
|
|
275
|
+
var import_common6 = require("@nestjs/common");
|
|
280
276
|
var import_constants = require("@nestjs/common/constants");
|
|
281
277
|
var import_core2 = require("@nestjs/core");
|
|
282
278
|
|
|
@@ -320,23 +316,28 @@ function getResponseFromContext(host) {
|
|
|
320
316
|
}
|
|
321
317
|
__name(getResponseFromContext, "getResponseFromContext");
|
|
322
318
|
|
|
323
|
-
// src/auth/decorators/require
|
|
319
|
+
// src/auth/decorators/require.decorator.ts
|
|
324
320
|
var import_common3 = require("@nestjs/common");
|
|
325
|
-
var
|
|
326
|
-
var
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
321
|
+
var REQUIRE_AUTH_KEY = "requireAuth";
|
|
322
|
+
var AuthType = /* @__PURE__ */ (function(AuthType2) {
|
|
323
|
+
AuthType2["Session"] = "session";
|
|
324
|
+
AuthType2["App"] = "app";
|
|
325
|
+
AuthType2["Cloud"] = "cloud";
|
|
326
|
+
AuthType2["Public"] = "public";
|
|
327
|
+
return AuthType2;
|
|
328
|
+
})({});
|
|
329
|
+
var Require = /* @__PURE__ */ __name((type, ...subtypes) => (0, import_common3.SetMetadata)(REQUIRE_AUTH_KEY, {
|
|
330
|
+
type,
|
|
331
|
+
subtypes
|
|
332
|
+
}), "Require");
|
|
332
333
|
|
|
333
334
|
// src/auth/decorators/skip-csrf.decorator.ts
|
|
334
|
-
var
|
|
335
|
+
var import_common4 = require("@nestjs/common");
|
|
335
336
|
var SKIP_CSRF_KEY = "skipCsrf";
|
|
336
|
-
var SkipCsrf = /* @__PURE__ */ __name(() => (0,
|
|
337
|
+
var SkipCsrf = /* @__PURE__ */ __name(() => (0, import_common4.SetMetadata)(SKIP_CSRF_KEY, true), "SkipCsrf");
|
|
337
338
|
|
|
338
339
|
// src/auth/services/token.service.ts
|
|
339
|
-
var
|
|
340
|
+
var import_common5 = require("@nestjs/common");
|
|
340
341
|
var import_jwt = require("@nestjs/jwt");
|
|
341
342
|
|
|
342
343
|
// src/utils/time.utils.ts
|
|
@@ -396,7 +397,7 @@ var TokenService = class _TokenService {
|
|
|
396
397
|
}
|
|
397
398
|
jwtService;
|
|
398
399
|
config;
|
|
399
|
-
logger = new
|
|
400
|
+
logger = new import_common5.Logger(_TokenService.name);
|
|
400
401
|
constructor(jwtService, config) {
|
|
401
402
|
this.jwtService = jwtService;
|
|
402
403
|
this.config = config;
|
|
@@ -460,21 +461,21 @@ var TokenService = class _TokenService {
|
|
|
460
461
|
try {
|
|
461
462
|
const decoded = this.jwtService.verify(token);
|
|
462
463
|
if (decoded.tokenType !== TokenType.ACCESS) {
|
|
463
|
-
throw new
|
|
464
|
+
throw new import_common5.UnauthorizedException("Invalid token type");
|
|
464
465
|
}
|
|
465
466
|
return decoded;
|
|
466
467
|
} catch (error) {
|
|
467
|
-
if (error instanceof
|
|
468
|
+
if (error instanceof import_common5.UnauthorizedException) throw error;
|
|
468
469
|
const jwtError = error;
|
|
469
470
|
switch (jwtError.name) {
|
|
470
471
|
case "TokenExpiredError":
|
|
471
|
-
throw new
|
|
472
|
+
throw new import_common5.UnauthorizedException("Access token has expired");
|
|
472
473
|
case "JsonWebTokenError":
|
|
473
|
-
throw new
|
|
474
|
+
throw new import_common5.UnauthorizedException("Invalid access token");
|
|
474
475
|
case "NotBeforeError":
|
|
475
|
-
throw new
|
|
476
|
+
throw new import_common5.UnauthorizedException("Access token not yet valid");
|
|
476
477
|
default:
|
|
477
|
-
throw new
|
|
478
|
+
throw new import_common5.UnauthorizedException("Access token validation failed");
|
|
478
479
|
}
|
|
479
480
|
}
|
|
480
481
|
}
|
|
@@ -483,24 +484,24 @@ var TokenService = class _TokenService {
|
|
|
483
484
|
try {
|
|
484
485
|
const decoded = this.jwtService.verify(token);
|
|
485
486
|
if (decoded.tokenType !== TokenType.REFRESH) {
|
|
486
|
-
throw new
|
|
487
|
+
throw new import_common5.UnauthorizedException("Invalid token type");
|
|
487
488
|
}
|
|
488
489
|
return decoded;
|
|
489
490
|
} catch (error) {
|
|
490
|
-
if (error instanceof
|
|
491
|
-
throw new
|
|
491
|
+
if (error instanceof import_common5.UnauthorizedException) throw error;
|
|
492
|
+
throw new import_common5.UnauthorizedException("Invalid or expired session");
|
|
492
493
|
}
|
|
493
494
|
}
|
|
494
495
|
// Validates that the access token is bound to the refresh token
|
|
495
496
|
validateTokenBinding(accessToken, refreshToken) {
|
|
496
497
|
if (!verifyTokenHash(refreshToken, accessToken.refreshTokenHash)) {
|
|
497
|
-
throw new
|
|
498
|
+
throw new import_common5.UnauthorizedException("Session validation failed");
|
|
498
499
|
}
|
|
499
500
|
}
|
|
500
501
|
};
|
|
501
502
|
TokenService = _ts_decorate3([
|
|
502
|
-
(0,
|
|
503
|
-
_ts_param2(1, (0,
|
|
503
|
+
(0, import_common5.Injectable)(),
|
|
504
|
+
_ts_param2(1, (0, import_common5.Inject)(AUTH_CONFIG)),
|
|
504
505
|
_ts_metadata2("design:type", Function),
|
|
505
506
|
_ts_metadata2("design:paramtypes", [
|
|
506
507
|
typeof import_jwt.JwtService === "undefined" ? Object : import_jwt.JwtService,
|
|
@@ -534,7 +535,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
534
535
|
requestService;
|
|
535
536
|
tokenService;
|
|
536
537
|
config;
|
|
537
|
-
logger = new
|
|
538
|
+
logger = new import_common6.Logger(_VrittiAuthGuard.name);
|
|
538
539
|
constructor(reflector, requestService, tokenService, config) {
|
|
539
540
|
this.reflector = reflector;
|
|
540
541
|
this.requestService = requestService;
|
|
@@ -551,38 +552,64 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
551
552
|
context.getHandler(),
|
|
552
553
|
context.getClass()
|
|
553
554
|
]) || csrfExemptTransports.includes(context.getType());
|
|
554
|
-
const
|
|
555
|
-
context.getHandler(),
|
|
556
|
-
context.getClass()
|
|
557
|
-
]);
|
|
558
|
-
if (requiredAppTypes) {
|
|
559
|
-
return this.handleAppAuth(request, requiredAppTypes, route);
|
|
560
|
-
}
|
|
561
|
-
const isPublic = this.reflector.getAllAndOverride("isPublic", [
|
|
555
|
+
const requirement = this.reflector.getAllAndOverride(REQUIRE_AUTH_KEY, [
|
|
562
556
|
context.getHandler(),
|
|
563
557
|
context.getClass()
|
|
564
|
-
])
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
558
|
+
]) ?? {
|
|
559
|
+
type: AuthType.Session,
|
|
560
|
+
subtypes: []
|
|
561
|
+
};
|
|
562
|
+
switch (requirement.type) {
|
|
563
|
+
// Signed server-to-server calls return before CSRF is ever reached. Neither carries a
|
|
564
|
+
// cookie for CSRF to protect, and that holds on REST too — which a transport-level
|
|
565
|
+
// exemption would not cover.
|
|
566
|
+
case AuthType.App:
|
|
567
|
+
return this.handleAppAuth(request, requirement.subtypes, route);
|
|
568
|
+
case AuthType.Cloud:
|
|
569
|
+
return this.handleCloudAuth(request, route);
|
|
570
|
+
case AuthType.Public: {
|
|
571
|
+
if (!skipCsrf) {
|
|
572
|
+
await this.validateCsrf(request, reply);
|
|
573
|
+
}
|
|
574
|
+
this.logger.debug(`${route} \u2014 public endpoint, skipping auth`);
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
case AuthType.Session: {
|
|
578
|
+
const isSseEndpoint = this.reflector.get(import_constants.SSE_METADATA, context.getHandler());
|
|
579
|
+
if (isSseEndpoint) {
|
|
580
|
+
this.logger.debug(`${route} \u2014 SSE endpoint, authenticating via refresh cookie`);
|
|
581
|
+
return this.handleSseAuth(request, requirement.subtypes);
|
|
582
|
+
}
|
|
583
|
+
const sessionType = await this.handleHttpAuth(request, requirement.subtypes);
|
|
584
|
+
const csrfExemptSessionTypes = this.config.guard.csrfExemptSessionTypes ?? [];
|
|
585
|
+
if (!skipCsrf && !csrfExemptSessionTypes.includes(sessionType)) {
|
|
586
|
+
await this.validateCsrf(request, reply);
|
|
587
|
+
}
|
|
588
|
+
return true;
|
|
568
589
|
}
|
|
569
|
-
this.logger.debug(`${route} \u2014 public endpoint, skipping auth`);
|
|
570
|
-
return true;
|
|
571
|
-
}
|
|
572
|
-
const requiredSessionTypes = this.reflector.getAllAndOverride(REQUIRE_SESSION_KEY, [
|
|
573
|
-
context.getHandler(),
|
|
574
|
-
context.getClass()
|
|
575
|
-
]);
|
|
576
|
-
const isSseEndpoint = this.reflector.get(import_constants.SSE_METADATA, context.getHandler());
|
|
577
|
-
if (isSseEndpoint) {
|
|
578
|
-
this.logger.debug(`${route} \u2014 SSE endpoint, authenticating via refresh cookie`);
|
|
579
|
-
return this.handleSseAuth(request, requiredSessionTypes);
|
|
580
590
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Authenticates a signed request from the control plane.
|
|
594
|
+
*
|
|
595
|
+
* Same shape as the app branch and for the same reason: verifying the signature needs a key
|
|
596
|
+
* the consuming server holds, so this delegates to `guard.onAuthenticated` and keeps only
|
|
597
|
+
* what this side can do — recognising the decorator and seeding the context.
|
|
598
|
+
*
|
|
599
|
+
* There is no subtype filter. Cloud is one caller, not a family of them.
|
|
600
|
+
*/
|
|
601
|
+
async handleCloudAuth(request, route) {
|
|
602
|
+
const onAuthenticated = this.config.guard.onAuthenticated;
|
|
603
|
+
if (!onAuthenticated) {
|
|
604
|
+
this.logger.error(`${route} \u2014 @Require(AuthType.Cloud) requires guard.onAuthenticated to be configured`);
|
|
605
|
+
throw new import_common6.UnauthorizedException("Cloud authentication is not configured");
|
|
585
606
|
}
|
|
607
|
+
const auth = {
|
|
608
|
+
kind: "cloud"
|
|
609
|
+
};
|
|
610
|
+
request.auth = auth;
|
|
611
|
+
await onAuthenticated(this.requestService, auth);
|
|
612
|
+
this.logger.debug(`${route} \u2014 authenticated cloud request`);
|
|
586
613
|
return true;
|
|
587
614
|
}
|
|
588
615
|
/**
|
|
@@ -604,18 +631,19 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
604
631
|
const onAuthenticated = this.config.guard.onAuthenticated;
|
|
605
632
|
if (!onAuthenticated) {
|
|
606
633
|
this.logger.error(`${route} \u2014 @RequireApp() requires guard.onAuthenticated to be configured`);
|
|
607
|
-
throw new
|
|
634
|
+
throw new import_common6.UnauthorizedException("App authentication is not configured");
|
|
608
635
|
}
|
|
609
|
-
const
|
|
610
|
-
|
|
636
|
+
const auth = {
|
|
637
|
+
kind: "app"
|
|
611
638
|
};
|
|
612
|
-
request.
|
|
613
|
-
await onAuthenticated(this.requestService,
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
639
|
+
request.auth = auth;
|
|
640
|
+
await onAuthenticated(this.requestService, auth);
|
|
641
|
+
const appType = auth.kind === "app" ? auth.appType : void 0;
|
|
642
|
+
if (requiredAppTypes.length && !requiredAppTypes.includes(appType ?? "")) {
|
|
643
|
+
this.logger.warn(`${route} \u2014 app type ${appType ?? "unknown"} not in allowed: [${requiredAppTypes.join(", ")}]`);
|
|
644
|
+
throw new import_common6.UnauthorizedException("This client is not recognised.");
|
|
617
645
|
}
|
|
618
|
-
this.logger.debug(`${route} \u2014 authenticated app (${
|
|
646
|
+
this.logger.debug(`${route} \u2014 authenticated app (${appType})`);
|
|
619
647
|
return true;
|
|
620
648
|
}
|
|
621
649
|
// Authenticates standard HTTP requests using the access token from Authorization header
|
|
@@ -624,26 +652,30 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
624
652
|
const accessToken = this.requestService.getAccessToken();
|
|
625
653
|
if (!accessToken) {
|
|
626
654
|
this.logger.warn(`${route} \u2014 no access token found`);
|
|
627
|
-
throw new
|
|
655
|
+
throw new import_common6.UnauthorizedException("Access token not found");
|
|
628
656
|
}
|
|
629
657
|
const decoded = this.tokenService.validateAccessToken(accessToken);
|
|
630
658
|
const refreshTokenBindingExemptSessionTypes = this.config.guard.refreshTokenBindingExemptSessionTypes ?? [];
|
|
631
659
|
if (!refreshTokenBindingExemptSessionTypes.includes(decoded.sessionType)) {
|
|
632
660
|
const refreshToken = this.requestService.getRefreshToken();
|
|
633
661
|
if (!refreshToken) {
|
|
634
|
-
throw new
|
|
662
|
+
throw new import_common6.UnauthorizedException("Session validation failed");
|
|
635
663
|
}
|
|
636
664
|
this.tokenService.validateTokenBinding(decoded, refreshToken);
|
|
637
665
|
}
|
|
638
666
|
if (requiredSessionTypes?.length && !requiredSessionTypes.includes(decoded.sessionType)) {
|
|
639
667
|
this.logger.warn(`${route} \u2014 session type ${decoded.sessionType} not in allowed: [${requiredSessionTypes.join(", ")}]`);
|
|
640
|
-
throw new
|
|
668
|
+
throw new import_common6.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
|
|
641
669
|
}
|
|
642
|
-
const { tokenType: _tokenType, refreshTokenHash: _hash, exp: _exp, iat: _iat, ...
|
|
643
|
-
|
|
670
|
+
const { tokenType: _tokenType, refreshTokenHash: _hash, exp: _exp, iat: _iat, ...claims } = decoded;
|
|
671
|
+
const auth = {
|
|
672
|
+
kind: "session",
|
|
673
|
+
...claims
|
|
674
|
+
};
|
|
675
|
+
request.auth = auth;
|
|
644
676
|
const onAuthenticated = this.config.guard.onAuthenticated;
|
|
645
677
|
if (onAuthenticated) {
|
|
646
|
-
await onAuthenticated(this.requestService,
|
|
678
|
+
await onAuthenticated(this.requestService, auth);
|
|
647
679
|
}
|
|
648
680
|
this.logger.debug(`${route} \u2014 authenticated user: ${decoded.userId} (${decoded.sessionType})`);
|
|
649
681
|
return decoded.sessionType;
|
|
@@ -653,15 +685,18 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
653
685
|
const refreshToken = this.requestService.getRefreshToken();
|
|
654
686
|
if (!refreshToken) {
|
|
655
687
|
this.logger.warn(`SSE ${request.url} \u2014 no refresh token cookie`);
|
|
656
|
-
throw new
|
|
688
|
+
throw new import_common6.UnauthorizedException("Authentication required");
|
|
657
689
|
}
|
|
658
690
|
const decoded = this.tokenService.validateRefreshToken(refreshToken);
|
|
659
691
|
if (requiredSessionTypes?.length && !requiredSessionTypes.includes(decoded.sessionType)) {
|
|
660
692
|
this.logger.warn(`SSE ${request.url} \u2014 session type ${decoded.sessionType} not allowed`);
|
|
661
|
-
throw new
|
|
693
|
+
throw new import_common6.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
|
|
662
694
|
}
|
|
663
|
-
const { tokenType: _tokenType, exp: _exp, iat: _iat, ...
|
|
664
|
-
request.
|
|
695
|
+
const { tokenType: _tokenType, exp: _exp, iat: _iat, ...claims } = decoded;
|
|
696
|
+
request.auth = {
|
|
697
|
+
kind: "session",
|
|
698
|
+
...claims
|
|
699
|
+
};
|
|
665
700
|
this.logger.debug(`SSE ${request.url} \u2014 authenticated user: ${decoded.userId} (${decoded.sessionType})`);
|
|
666
701
|
return true;
|
|
667
702
|
}
|
|
@@ -677,7 +712,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
677
712
|
const fastifyInstance = request.server;
|
|
678
713
|
const csrfProtection = fastifyInstance.csrfProtection;
|
|
679
714
|
if (!csrfProtection) {
|
|
680
|
-
throw new
|
|
715
|
+
throw new import_common6.ForbiddenException("CSRF protection not configured");
|
|
681
716
|
}
|
|
682
717
|
await new Promise((resolve, reject) => {
|
|
683
718
|
const originalSend = reply.send.bind(reply);
|
|
@@ -694,7 +729,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
694
729
|
});
|
|
695
730
|
} catch (_error) {
|
|
696
731
|
this.logger.warn(`${request.method} ${request.url} \u2014 CSRF validation failed`);
|
|
697
|
-
throw new
|
|
732
|
+
throw new import_common6.ForbiddenException({
|
|
698
733
|
errors: [
|
|
699
734
|
{
|
|
700
735
|
field: "csrf",
|
|
@@ -707,10 +742,10 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
707
742
|
}
|
|
708
743
|
};
|
|
709
744
|
VrittiAuthGuard = _ts_decorate4([
|
|
710
|
-
(0,
|
|
711
|
-
scope:
|
|
745
|
+
(0, import_common6.Injectable)({
|
|
746
|
+
scope: import_common6.Scope.REQUEST
|
|
712
747
|
}),
|
|
713
|
-
_ts_param3(3, (0,
|
|
748
|
+
_ts_param3(3, (0, import_common6.Inject)(AUTH_CONFIG)),
|
|
714
749
|
_ts_metadata3("design:type", Function),
|
|
715
750
|
_ts_metadata3("design:paramtypes", [
|
|
716
751
|
typeof import_core2.Reflector === "undefined" ? Object : import_core2.Reflector,
|
|
@@ -797,27 +832,27 @@ var AuthConfigModule = class _AuthConfigModule {
|
|
|
797
832
|
}
|
|
798
833
|
};
|
|
799
834
|
AuthConfigModule = _ts_decorate5([
|
|
800
|
-
(0,
|
|
801
|
-
(0,
|
|
835
|
+
(0, import_common7.Global)(),
|
|
836
|
+
(0, import_common7.Module)({})
|
|
802
837
|
], AuthConfigModule);
|
|
803
838
|
|
|
804
839
|
// src/auth/decorators/access-token.decorator.ts
|
|
805
|
-
var
|
|
806
|
-
var AccessToken = (0,
|
|
840
|
+
var import_common8 = require("@nestjs/common");
|
|
841
|
+
var AccessToken = (0, import_common8.createParamDecorator)((_data, ctx) => {
|
|
807
842
|
const request = getRequestFromContext(ctx);
|
|
808
843
|
const authHeader = request.headers.authorization;
|
|
809
844
|
return authHeader?.replace("Bearer ", "") || "";
|
|
810
845
|
});
|
|
811
846
|
|
|
812
847
|
// src/auth/decorators/client-ip.decorator.ts
|
|
813
|
-
var
|
|
814
|
-
var ClientIp = (0,
|
|
848
|
+
var import_common9 = require("@nestjs/common");
|
|
849
|
+
var ClientIp = (0, import_common9.createParamDecorator)((_data, ctx) => {
|
|
815
850
|
return getRequestFromContext(ctx).ip;
|
|
816
851
|
});
|
|
817
852
|
|
|
818
853
|
// src/auth/decorators/cookie-domain.decorator.ts
|
|
819
|
-
var
|
|
820
|
-
var CookieDomain = (0,
|
|
854
|
+
var import_common10 = require("@nestjs/common");
|
|
855
|
+
var CookieDomain = (0, import_common10.createParamDecorator)((_data, ctx) => {
|
|
821
856
|
const request = getRequestFromContext(ctx);
|
|
822
857
|
const forwarded = request.headers["x-forwarded-host"];
|
|
823
858
|
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
@@ -828,15 +863,15 @@ var CookieDomain = (0, import_common11.createParamDecorator)((_data, ctx) => {
|
|
|
828
863
|
});
|
|
829
864
|
|
|
830
865
|
// src/auth/decorators/cookie-name.decorator.ts
|
|
831
|
-
var
|
|
832
|
-
var CookieName = (0,
|
|
866
|
+
var import_common11 = require("@nestjs/common");
|
|
867
|
+
var CookieName = (0, import_common11.createParamDecorator)((_data, ctx) => {
|
|
833
868
|
const request = getRequestFromContext(ctx);
|
|
834
869
|
return request.authConfig?.cookie.refreshCookieName ?? AUTH_CONFIG_DEFAULTS.cookie.refreshCookieName;
|
|
835
870
|
});
|
|
836
871
|
|
|
837
872
|
// src/auth/decorators/hostname.decorator.ts
|
|
838
|
-
var
|
|
839
|
-
var Hostname = (0,
|
|
873
|
+
var import_common12 = require("@nestjs/common");
|
|
874
|
+
var Hostname = (0, import_common12.createParamDecorator)((_data, ctx) => {
|
|
840
875
|
const request = getRequestFromContext(ctx);
|
|
841
876
|
const forwarded = request.headers["x-forwarded-host"];
|
|
842
877
|
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
@@ -844,19 +879,15 @@ var Hostname = (0, import_common13.createParamDecorator)((_data, ctx) => {
|
|
|
844
879
|
return hostStr.split(":")[0] ?? hostStr;
|
|
845
880
|
});
|
|
846
881
|
|
|
847
|
-
// src/auth/decorators/public.decorator.ts
|
|
848
|
-
var import_common14 = require("@nestjs/common");
|
|
849
|
-
var Public = /* @__PURE__ */ __name(() => (0, import_common14.SetMetadata)("isPublic", true), "Public");
|
|
850
|
-
|
|
851
882
|
// src/auth/decorators/refresh-cookie-options.decorator.ts
|
|
852
|
-
var
|
|
883
|
+
var import_common32 = require("@nestjs/common");
|
|
853
884
|
|
|
854
885
|
// src/exceptions/bad-gateway.exception.ts
|
|
855
|
-
var
|
|
886
|
+
var import_common14 = require("@nestjs/common");
|
|
856
887
|
|
|
857
888
|
// src/exceptions/base-field.exception.ts
|
|
858
|
-
var
|
|
859
|
-
var HttpProblemException = class extends
|
|
889
|
+
var import_common13 = require("@nestjs/common");
|
|
890
|
+
var HttpProblemException = class extends import_common13.HttpException {
|
|
860
891
|
static {
|
|
861
892
|
__name(this, "HttpProblemException");
|
|
862
893
|
}
|
|
@@ -874,63 +905,63 @@ var HttpProblemException = class extends import_common15.HttpException {
|
|
|
874
905
|
};
|
|
875
906
|
|
|
876
907
|
// src/exceptions/bad-request.exception.ts
|
|
877
|
-
var
|
|
908
|
+
var import_common15 = require("@nestjs/common");
|
|
878
909
|
|
|
879
910
|
// src/exceptions/conflict.exception.ts
|
|
880
|
-
var
|
|
911
|
+
var import_common16 = require("@nestjs/common");
|
|
881
912
|
|
|
882
913
|
// src/exceptions/forbidden.exception.ts
|
|
883
|
-
var
|
|
914
|
+
var import_common17 = require("@nestjs/common");
|
|
884
915
|
|
|
885
916
|
// src/exceptions/gone.exception.ts
|
|
886
|
-
var
|
|
917
|
+
var import_common18 = require("@nestjs/common");
|
|
887
918
|
|
|
888
919
|
// src/exceptions/internal-server-error.exception.ts
|
|
889
|
-
var
|
|
920
|
+
var import_common19 = require("@nestjs/common");
|
|
890
921
|
|
|
891
922
|
// src/exceptions/method-not-allowed.exception.ts
|
|
892
|
-
var
|
|
923
|
+
var import_common20 = require("@nestjs/common");
|
|
893
924
|
|
|
894
925
|
// src/exceptions/not-acceptable.exception.ts
|
|
895
|
-
var
|
|
926
|
+
var import_common21 = require("@nestjs/common");
|
|
896
927
|
|
|
897
928
|
// src/exceptions/not-found.exception.ts
|
|
898
|
-
var
|
|
929
|
+
var import_common22 = require("@nestjs/common");
|
|
899
930
|
|
|
900
931
|
// src/exceptions/not-implemented.exception.ts
|
|
901
|
-
var
|
|
932
|
+
var import_common23 = require("@nestjs/common");
|
|
902
933
|
|
|
903
934
|
// src/exceptions/payload-too-large.exception.ts
|
|
904
|
-
var
|
|
935
|
+
var import_common24 = require("@nestjs/common");
|
|
905
936
|
|
|
906
937
|
// src/exceptions/request-timeout.exception.ts
|
|
907
|
-
var
|
|
938
|
+
var import_common25 = require("@nestjs/common");
|
|
908
939
|
|
|
909
940
|
// src/exceptions/service-unavailable.exception.ts
|
|
910
|
-
var
|
|
941
|
+
var import_common26 = require("@nestjs/common");
|
|
911
942
|
|
|
912
943
|
// src/exceptions/too-many-requests.exception.ts
|
|
913
|
-
var
|
|
944
|
+
var import_common27 = require("@nestjs/common");
|
|
914
945
|
|
|
915
946
|
// src/exceptions/unauthorized.exception.ts
|
|
916
|
-
var
|
|
947
|
+
var import_common28 = require("@nestjs/common");
|
|
917
948
|
var UnauthorizedException3 = class extends HttpProblemException {
|
|
918
949
|
static {
|
|
919
950
|
__name(this, "UnauthorizedException");
|
|
920
951
|
}
|
|
921
952
|
constructor(detailOrOptions) {
|
|
922
|
-
super(detailOrOptions ?? "Unauthorized",
|
|
953
|
+
super(detailOrOptions ?? "Unauthorized", import_common28.HttpStatus.UNAUTHORIZED);
|
|
923
954
|
}
|
|
924
955
|
};
|
|
925
956
|
|
|
926
957
|
// src/exceptions/unprocessable-entity.exception.ts
|
|
927
|
-
var
|
|
958
|
+
var import_common29 = require("@nestjs/common");
|
|
928
959
|
|
|
929
960
|
// src/exceptions/unsupported-media-type.exception.ts
|
|
930
|
-
var
|
|
961
|
+
var import_common30 = require("@nestjs/common");
|
|
931
962
|
|
|
932
963
|
// src/exceptions/validation.exception.ts
|
|
933
|
-
var
|
|
964
|
+
var import_common31 = require("@nestjs/common");
|
|
934
965
|
|
|
935
966
|
// src/auth/decorators/refresh-cookie-options.decorator.ts
|
|
936
967
|
function buildCookieOptionsForHost(cookieConfig, hostname) {
|
|
@@ -951,7 +982,7 @@ function buildCookieOptionsForHost(cookieConfig, hostname) {
|
|
|
951
982
|
};
|
|
952
983
|
}
|
|
953
984
|
__name(buildCookieOptionsForHost, "buildCookieOptionsForHost");
|
|
954
|
-
var RefreshCookieOptions = (0,
|
|
985
|
+
var RefreshCookieOptions = (0, import_common32.createParamDecorator)((_data, ctx) => {
|
|
955
986
|
const request = getRequestFromContext(ctx);
|
|
956
987
|
const forwarded = request.headers["x-forwarded-host"];
|
|
957
988
|
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
@@ -962,8 +993,8 @@ var RefreshCookieOptions = (0, import_common34.createParamDecorator)((_data, ctx
|
|
|
962
993
|
});
|
|
963
994
|
|
|
964
995
|
// src/auth/decorators/refresh-token-cookie.decorator.ts
|
|
965
|
-
var
|
|
966
|
-
var RefreshTokenCookie = (0,
|
|
996
|
+
var import_common33 = require("@nestjs/common");
|
|
997
|
+
var RefreshTokenCookie = (0, import_common33.createParamDecorator)((_data, ctx) => {
|
|
967
998
|
const request = getRequestFromContext(ctx);
|
|
968
999
|
const cookies = request.cookies ?? {};
|
|
969
1000
|
const cookieName = request.authConfig?.cookie.refreshCookieName ?? AUTH_CONFIG_DEFAULTS.cookie.refreshCookieName;
|
|
@@ -971,23 +1002,22 @@ var RefreshTokenCookie = (0, import_common35.createParamDecorator)((_data, ctx)
|
|
|
971
1002
|
});
|
|
972
1003
|
|
|
973
1004
|
// src/auth/decorators/session-data.decorator.ts
|
|
974
|
-
var
|
|
975
|
-
var SessionData = (0,
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
throw new Error("Session info not found on request. Ensure route is protected by auth guard.");
|
|
1005
|
+
var import_common34 = require("@nestjs/common");
|
|
1006
|
+
var SessionData = (0, import_common34.createParamDecorator)((_data, ctx) => {
|
|
1007
|
+
const auth = getRequestFromContext(ctx).auth;
|
|
1008
|
+
if (auth?.kind !== "session") {
|
|
1009
|
+
throw new Error(`No session on this request (auth: ${auth?.kind ?? "none"}). @SessionData() is session-only.`);
|
|
980
1010
|
}
|
|
981
1011
|
return {
|
|
982
|
-
userId:
|
|
983
|
-
sessionId:
|
|
984
|
-
sessionType:
|
|
1012
|
+
userId: auth.userId,
|
|
1013
|
+
sessionId: auth.sessionId,
|
|
1014
|
+
sessionType: auth.sessionType
|
|
985
1015
|
};
|
|
986
1016
|
});
|
|
987
1017
|
|
|
988
1018
|
// src/auth/decorators/subdomain.decorator.ts
|
|
989
|
-
var
|
|
990
|
-
var Subdomain = (0,
|
|
1019
|
+
var import_common35 = require("@nestjs/common");
|
|
1020
|
+
var Subdomain = (0, import_common35.createParamDecorator)((_data, ctx) => {
|
|
991
1021
|
const request = getRequestFromContext(ctx);
|
|
992
1022
|
const forwarded = request.headers["x-forwarded-host"];
|
|
993
1023
|
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
@@ -998,29 +1028,28 @@ var Subdomain = (0, import_common37.createParamDecorator)((_data, ctx) => {
|
|
|
998
1028
|
});
|
|
999
1029
|
|
|
1000
1030
|
// src/auth/decorators/user-agent.decorator.ts
|
|
1001
|
-
var
|
|
1002
|
-
var UserAgent = (0,
|
|
1031
|
+
var import_common36 = require("@nestjs/common");
|
|
1032
|
+
var UserAgent = (0, import_common36.createParamDecorator)((_data, ctx) => {
|
|
1003
1033
|
const userAgent = getRequestFromContext(ctx).headers["user-agent"];
|
|
1004
1034
|
return Array.isArray(userAgent) ? userAgent[0] : userAgent;
|
|
1005
1035
|
});
|
|
1006
1036
|
|
|
1007
1037
|
// src/auth/decorators/user-id.decorator.ts
|
|
1008
|
-
var
|
|
1009
|
-
var UserId = (0,
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
throw new Error("User ID not found on request. Ensure route is protected by auth guard.");
|
|
1038
|
+
var import_common37 = require("@nestjs/common");
|
|
1039
|
+
var UserId = (0, import_common37.createParamDecorator)((_data, ctx) => {
|
|
1040
|
+
const auth = getRequestFromContext(ctx).auth;
|
|
1041
|
+
if (auth?.kind !== "session") {
|
|
1042
|
+
throw new Error(`No user on this request (auth: ${auth?.kind ?? "none"}). @UserId() is session-only.`);
|
|
1014
1043
|
}
|
|
1015
|
-
return
|
|
1044
|
+
return auth.userId;
|
|
1016
1045
|
});
|
|
1017
1046
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1018
1047
|
0 && (module.exports = {
|
|
1019
|
-
APP_SESSION_TYPE,
|
|
1020
1048
|
AUTH_CONFIG,
|
|
1021
1049
|
AUTH_CONFIG_DEFAULTS,
|
|
1022
1050
|
AccessToken,
|
|
1023
1051
|
AuthConfigModule,
|
|
1052
|
+
AuthType,
|
|
1024
1053
|
CLIENT_ID_HEADER,
|
|
1025
1054
|
ClientIp,
|
|
1026
1055
|
CookieDomain,
|
|
@@ -1028,13 +1057,10 @@ var UserId = (0, import_common39.createParamDecorator)((_data, ctx) => {
|
|
|
1028
1057
|
Hostname,
|
|
1029
1058
|
MAX_CLOCK_SKEW_SECONDS,
|
|
1030
1059
|
PARTY_ID_HEADER,
|
|
1031
|
-
|
|
1032
|
-
REQUIRE_APP_KEY,
|
|
1033
|
-
REQUIRE_SESSION_KEY,
|
|
1060
|
+
REQUIRE_AUTH_KEY,
|
|
1034
1061
|
RefreshCookieOptions,
|
|
1035
1062
|
RefreshTokenCookie,
|
|
1036
|
-
|
|
1037
|
-
RequireSession,
|
|
1063
|
+
Require,
|
|
1038
1064
|
SKIP_CSRF_KEY,
|
|
1039
1065
|
SessionData,
|
|
1040
1066
|
SkipCsrf,
|