@vritti/api-sdk 0.3.16 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
- Public: () => Public,
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
- RequireApp: () => RequireApp,
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 import_common8 = require("@nestjs/common");
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");
@@ -223,6 +219,15 @@ var RequestService = class {
223
219
  return index === -1 ? "" : url.slice(index + 1);
224
220
  }
225
221
  /**
222
+ * Returns a single decoded query param, or undefined when absent.
223
+ *
224
+ * Reads the raw URL rather than Fastify's parsed `query` so it is usable from the
225
+ * guard, which runs before a route's own parsing is meaningful.
226
+ */
227
+ getQueryParam(key) {
228
+ return new URLSearchParams(this.getQuery()).get(key) ?? void 0;
229
+ }
230
+ /**
226
231
  * Returns the raw request body, as `fastify-raw-body` leaves it.
227
232
  *
228
233
  * Read structurally rather than through a module augmentation: that plugin is the
@@ -276,7 +281,7 @@ RequestModule = _ts_decorate2([
276
281
  ], RequestModule);
277
282
 
278
283
  // src/auth/guards/vritti-auth.guard.ts
279
- var import_common7 = require("@nestjs/common");
284
+ var import_common6 = require("@nestjs/common");
280
285
  var import_constants = require("@nestjs/common/constants");
281
286
  var import_core2 = require("@nestjs/core");
282
287
 
@@ -320,23 +325,28 @@ function getResponseFromContext(host) {
320
325
  }
321
326
  __name(getResponseFromContext, "getResponseFromContext");
322
327
 
323
- // src/auth/decorators/require-app.decorator.ts
328
+ // src/auth/decorators/require.decorator.ts
324
329
  var import_common3 = require("@nestjs/common");
325
- var REQUIRE_APP_KEY = "requiredAppTypes";
326
- var RequireApp = /* @__PURE__ */ __name((...types) => (0, import_common3.SetMetadata)(REQUIRE_APP_KEY, types), "RequireApp");
327
-
328
- // src/auth/decorators/require-session.decorator.ts
329
- var import_common4 = require("@nestjs/common");
330
- var REQUIRE_SESSION_KEY = "requiredSessionTypes";
331
- var RequireSession = /* @__PURE__ */ __name((...types) => (0, import_common4.SetMetadata)(REQUIRE_SESSION_KEY, types), "RequireSession");
330
+ var REQUIRE_AUTH_KEY = "requireAuth";
331
+ var AuthType = /* @__PURE__ */ (function(AuthType2) {
332
+ AuthType2["Session"] = "session";
333
+ AuthType2["App"] = "app";
334
+ AuthType2["Cloud"] = "cloud";
335
+ AuthType2["Public"] = "public";
336
+ return AuthType2;
337
+ })({});
338
+ var Require = /* @__PURE__ */ __name((type, ...subtypes) => (0, import_common3.SetMetadata)(REQUIRE_AUTH_KEY, {
339
+ type,
340
+ subtypes
341
+ }), "Require");
332
342
 
333
343
  // src/auth/decorators/skip-csrf.decorator.ts
334
- var import_common5 = require("@nestjs/common");
344
+ var import_common4 = require("@nestjs/common");
335
345
  var SKIP_CSRF_KEY = "skipCsrf";
336
- var SkipCsrf = /* @__PURE__ */ __name(() => (0, import_common5.SetMetadata)(SKIP_CSRF_KEY, true), "SkipCsrf");
346
+ var SkipCsrf = /* @__PURE__ */ __name(() => (0, import_common4.SetMetadata)(SKIP_CSRF_KEY, true), "SkipCsrf");
337
347
 
338
348
  // src/auth/services/token.service.ts
339
- var import_common6 = require("@nestjs/common");
349
+ var import_common5 = require("@nestjs/common");
340
350
  var import_jwt = require("@nestjs/jwt");
341
351
 
342
352
  // src/utils/time.utils.ts
@@ -396,7 +406,7 @@ var TokenService = class _TokenService {
396
406
  }
397
407
  jwtService;
398
408
  config;
399
- logger = new import_common6.Logger(_TokenService.name);
409
+ logger = new import_common5.Logger(_TokenService.name);
400
410
  constructor(jwtService, config) {
401
411
  this.jwtService = jwtService;
402
412
  this.config = config;
@@ -460,21 +470,21 @@ var TokenService = class _TokenService {
460
470
  try {
461
471
  const decoded = this.jwtService.verify(token);
462
472
  if (decoded.tokenType !== TokenType.ACCESS) {
463
- throw new import_common6.UnauthorizedException("Invalid token type");
473
+ throw new import_common5.UnauthorizedException("Invalid token type");
464
474
  }
465
475
  return decoded;
466
476
  } catch (error) {
467
- if (error instanceof import_common6.UnauthorizedException) throw error;
477
+ if (error instanceof import_common5.UnauthorizedException) throw error;
468
478
  const jwtError = error;
469
479
  switch (jwtError.name) {
470
480
  case "TokenExpiredError":
471
- throw new import_common6.UnauthorizedException("Access token has expired");
481
+ throw new import_common5.UnauthorizedException("Access token has expired");
472
482
  case "JsonWebTokenError":
473
- throw new import_common6.UnauthorizedException("Invalid access token");
483
+ throw new import_common5.UnauthorizedException("Invalid access token");
474
484
  case "NotBeforeError":
475
- throw new import_common6.UnauthorizedException("Access token not yet valid");
485
+ throw new import_common5.UnauthorizedException("Access token not yet valid");
476
486
  default:
477
- throw new import_common6.UnauthorizedException("Access token validation failed");
487
+ throw new import_common5.UnauthorizedException("Access token validation failed");
478
488
  }
479
489
  }
480
490
  }
@@ -483,24 +493,24 @@ var TokenService = class _TokenService {
483
493
  try {
484
494
  const decoded = this.jwtService.verify(token);
485
495
  if (decoded.tokenType !== TokenType.REFRESH) {
486
- throw new import_common6.UnauthorizedException("Invalid token type");
496
+ throw new import_common5.UnauthorizedException("Invalid token type");
487
497
  }
488
498
  return decoded;
489
499
  } catch (error) {
490
- if (error instanceof import_common6.UnauthorizedException) throw error;
491
- throw new import_common6.UnauthorizedException("Invalid or expired session");
500
+ if (error instanceof import_common5.UnauthorizedException) throw error;
501
+ throw new import_common5.UnauthorizedException("Invalid or expired session");
492
502
  }
493
503
  }
494
504
  // Validates that the access token is bound to the refresh token
495
505
  validateTokenBinding(accessToken, refreshToken) {
496
506
  if (!verifyTokenHash(refreshToken, accessToken.refreshTokenHash)) {
497
- throw new import_common6.UnauthorizedException("Session validation failed");
507
+ throw new import_common5.UnauthorizedException("Session validation failed");
498
508
  }
499
509
  }
500
510
  };
501
511
  TokenService = _ts_decorate3([
502
- (0, import_common6.Injectable)(),
503
- _ts_param2(1, (0, import_common6.Inject)(AUTH_CONFIG)),
512
+ (0, import_common5.Injectable)(),
513
+ _ts_param2(1, (0, import_common5.Inject)(AUTH_CONFIG)),
504
514
  _ts_metadata2("design:type", Function),
505
515
  _ts_metadata2("design:paramtypes", [
506
516
  typeof import_jwt.JwtService === "undefined" ? Object : import_jwt.JwtService,
@@ -534,7 +544,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
534
544
  requestService;
535
545
  tokenService;
536
546
  config;
537
- logger = new import_common7.Logger(_VrittiAuthGuard.name);
547
+ logger = new import_common6.Logger(_VrittiAuthGuard.name);
538
548
  constructor(reflector, requestService, tokenService, config) {
539
549
  this.reflector = reflector;
540
550
  this.requestService = requestService;
@@ -551,38 +561,64 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
551
561
  context.getHandler(),
552
562
  context.getClass()
553
563
  ]) || csrfExemptTransports.includes(context.getType());
554
- const requiredAppTypes = this.reflector.getAllAndOverride(REQUIRE_APP_KEY, [
564
+ const requirement = this.reflector.getAllAndOverride(REQUIRE_AUTH_KEY, [
555
565
  context.getHandler(),
556
566
  context.getClass()
557
- ]);
558
- if (requiredAppTypes) {
559
- return this.handleAppAuth(request, requiredAppTypes, route);
560
- }
561
- const isPublic = this.reflector.getAllAndOverride("isPublic", [
562
- context.getHandler(),
563
- context.getClass()
564
- ]);
565
- if (isPublic) {
566
- if (!skipCsrf) {
567
- await this.validateCsrf(request, reply);
567
+ ]) ?? {
568
+ type: AuthType.Session,
569
+ subtypes: []
570
+ };
571
+ switch (requirement.type) {
572
+ // Signed server-to-server calls return before CSRF is ever reached. Neither carries a
573
+ // cookie for CSRF to protect, and that holds on REST too — which a transport-level
574
+ // exemption would not cover.
575
+ case AuthType.App:
576
+ return this.handleAppAuth(request, requirement.subtypes, route);
577
+ case AuthType.Cloud:
578
+ return this.handleCloudAuth(request, route);
579
+ case AuthType.Public: {
580
+ if (!skipCsrf) {
581
+ await this.validateCsrf(request, reply);
582
+ }
583
+ this.logger.debug(`${route} \u2014 public endpoint, skipping auth`);
584
+ return true;
585
+ }
586
+ case AuthType.Session: {
587
+ const isSseEndpoint = this.reflector.get(import_constants.SSE_METADATA, context.getHandler());
588
+ if (isSseEndpoint) {
589
+ this.logger.debug(`${route} \u2014 SSE endpoint, authenticating via refresh cookie`);
590
+ return this.handleSseAuth(request, requirement.subtypes);
591
+ }
592
+ const sessionType = await this.handleHttpAuth(request, requirement.subtypes);
593
+ const csrfExemptSessionTypes = this.config.guard.csrfExemptSessionTypes ?? [];
594
+ if (!skipCsrf && !csrfExemptSessionTypes.includes(sessionType)) {
595
+ await this.validateCsrf(request, reply);
596
+ }
597
+ return true;
568
598
  }
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
599
  }
581
- const sessionType = await this.handleHttpAuth(request, requiredSessionTypes);
582
- const csrfExemptSessionTypes = this.config.guard.csrfExemptSessionTypes ?? [];
583
- if (!skipCsrf && !csrfExemptSessionTypes.includes(sessionType)) {
584
- await this.validateCsrf(request, reply);
600
+ }
601
+ /**
602
+ * Authenticates a signed request from the control plane.
603
+ *
604
+ * Same shape as the app branch and for the same reason: verifying the signature needs a key
605
+ * the consuming server holds, so this delegates to `guard.onAuthenticated` and keeps only
606
+ * what this side can do — recognising the decorator and seeding the context.
607
+ *
608
+ * There is no subtype filter. Cloud is one caller, not a family of them.
609
+ */
610
+ async handleCloudAuth(request, route) {
611
+ const onAuthenticated = this.config.guard.onAuthenticated;
612
+ if (!onAuthenticated) {
613
+ this.logger.error(`${route} \u2014 @Require(AuthType.Cloud) requires guard.onAuthenticated to be configured`);
614
+ throw new import_common6.UnauthorizedException("Cloud authentication is not configured");
585
615
  }
616
+ const auth = {
617
+ kind: "cloud"
618
+ };
619
+ request.auth = auth;
620
+ await onAuthenticated(this.requestService, auth);
621
+ this.logger.debug(`${route} \u2014 authenticated cloud request`);
586
622
  return true;
587
623
  }
588
624
  /**
@@ -604,18 +640,19 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
604
640
  const onAuthenticated = this.config.guard.onAuthenticated;
605
641
  if (!onAuthenticated) {
606
642
  this.logger.error(`${route} \u2014 @RequireApp() requires guard.onAuthenticated to be configured`);
607
- throw new import_common7.UnauthorizedException("App authentication is not configured");
643
+ throw new import_common6.UnauthorizedException("App authentication is not configured");
608
644
  }
609
- const sessionInfo = {
610
- sessionType: APP_SESSION_TYPE
645
+ const auth = {
646
+ kind: "app"
611
647
  };
612
- request.sessionInfo = sessionInfo;
613
- await onAuthenticated(this.requestService, sessionInfo);
614
- if (requiredAppTypes.length && !requiredAppTypes.includes(sessionInfo.appType ?? "")) {
615
- this.logger.warn(`${route} \u2014 app type ${sessionInfo.appType ?? "unknown"} not in allowed: [${requiredAppTypes.join(", ")}]`);
616
- throw new import_common7.UnauthorizedException("This client is not recognised.");
648
+ request.auth = auth;
649
+ await onAuthenticated(this.requestService, auth);
650
+ const appType = auth.kind === "app" ? auth.appType : void 0;
651
+ if (requiredAppTypes.length && !requiredAppTypes.includes(appType ?? "")) {
652
+ this.logger.warn(`${route} \u2014 app type ${appType ?? "unknown"} not in allowed: [${requiredAppTypes.join(", ")}]`);
653
+ throw new import_common6.UnauthorizedException("This client is not recognised.");
617
654
  }
618
- this.logger.debug(`${route} \u2014 authenticated app (${sessionInfo.appType})`);
655
+ this.logger.debug(`${route} \u2014 authenticated app (${appType})`);
619
656
  return true;
620
657
  }
621
658
  // Authenticates standard HTTP requests using the access token from Authorization header
@@ -624,44 +661,56 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
624
661
  const accessToken = this.requestService.getAccessToken();
625
662
  if (!accessToken) {
626
663
  this.logger.warn(`${route} \u2014 no access token found`);
627
- throw new import_common7.UnauthorizedException("Access token not found");
664
+ throw new import_common6.UnauthorizedException("Access token not found");
628
665
  }
629
666
  const decoded = this.tokenService.validateAccessToken(accessToken);
630
667
  const refreshTokenBindingExemptSessionTypes = this.config.guard.refreshTokenBindingExemptSessionTypes ?? [];
631
668
  if (!refreshTokenBindingExemptSessionTypes.includes(decoded.sessionType)) {
632
669
  const refreshToken = this.requestService.getRefreshToken();
633
670
  if (!refreshToken) {
634
- throw new import_common7.UnauthorizedException("Session validation failed");
671
+ throw new import_common6.UnauthorizedException("Session validation failed");
635
672
  }
636
673
  this.tokenService.validateTokenBinding(decoded, refreshToken);
637
674
  }
638
675
  if (requiredSessionTypes?.length && !requiredSessionTypes.includes(decoded.sessionType)) {
639
676
  this.logger.warn(`${route} \u2014 session type ${decoded.sessionType} not in allowed: [${requiredSessionTypes.join(", ")}]`);
640
- throw new import_common7.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
677
+ throw new import_common6.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
641
678
  }
642
- const { tokenType: _tokenType, refreshTokenHash: _hash, exp: _exp, iat: _iat, ...sessionInfo } = decoded;
643
- request.sessionInfo = sessionInfo;
679
+ const { tokenType: _tokenType, refreshTokenHash: _hash, exp: _exp, iat: _iat, ...claims } = decoded;
680
+ const auth = {
681
+ kind: "session",
682
+ ...claims
683
+ };
684
+ request.auth = auth;
644
685
  const onAuthenticated = this.config.guard.onAuthenticated;
645
686
  if (onAuthenticated) {
646
- await onAuthenticated(this.requestService, request.sessionInfo);
687
+ await onAuthenticated(this.requestService, auth);
647
688
  }
648
689
  this.logger.debug(`${route} \u2014 authenticated user: ${decoded.userId} (${decoded.sessionType})`);
649
690
  return decoded.sessionType;
650
691
  }
651
692
  // Authenticates SSE connections using the refresh token httpOnly cookie
652
- handleSseAuth(request, requiredSessionTypes) {
693
+ async handleSseAuth(request, requiredSessionTypes) {
653
694
  const refreshToken = this.requestService.getRefreshToken();
654
695
  if (!refreshToken) {
655
696
  this.logger.warn(`SSE ${request.url} \u2014 no refresh token cookie`);
656
- throw new import_common7.UnauthorizedException("Authentication required");
697
+ throw new import_common6.UnauthorizedException("Authentication required");
657
698
  }
658
699
  const decoded = this.tokenService.validateRefreshToken(refreshToken);
659
700
  if (requiredSessionTypes?.length && !requiredSessionTypes.includes(decoded.sessionType)) {
660
701
  this.logger.warn(`SSE ${request.url} \u2014 session type ${decoded.sessionType} not allowed`);
661
- throw new import_common7.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
702
+ throw new import_common6.UnauthorizedException(`${decoded.sessionType} sessions cannot access this endpoint`);
703
+ }
704
+ const { tokenType: _tokenType, exp: _exp, iat: _iat, ...claims } = decoded;
705
+ const auth = {
706
+ kind: "session",
707
+ ...claims
708
+ };
709
+ request.auth = auth;
710
+ const onAuthenticated = this.config.guard.onAuthenticated;
711
+ if (onAuthenticated) {
712
+ await onAuthenticated(this.requestService, auth);
662
713
  }
663
- const { tokenType: _tokenType, exp: _exp, iat: _iat, ...sessionInfo } = decoded;
664
- request.sessionInfo = sessionInfo;
665
714
  this.logger.debug(`SSE ${request.url} \u2014 authenticated user: ${decoded.userId} (${decoded.sessionType})`);
666
715
  return true;
667
716
  }
@@ -677,7 +726,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
677
726
  const fastifyInstance = request.server;
678
727
  const csrfProtection = fastifyInstance.csrfProtection;
679
728
  if (!csrfProtection) {
680
- throw new import_common7.ForbiddenException("CSRF protection not configured");
729
+ throw new import_common6.ForbiddenException("CSRF protection not configured");
681
730
  }
682
731
  await new Promise((resolve, reject) => {
683
732
  const originalSend = reply.send.bind(reply);
@@ -694,7 +743,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
694
743
  });
695
744
  } catch (_error) {
696
745
  this.logger.warn(`${request.method} ${request.url} \u2014 CSRF validation failed`);
697
- throw new import_common7.ForbiddenException({
746
+ throw new import_common6.ForbiddenException({
698
747
  errors: [
699
748
  {
700
749
  field: "csrf",
@@ -707,10 +756,10 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
707
756
  }
708
757
  };
709
758
  VrittiAuthGuard = _ts_decorate4([
710
- (0, import_common7.Injectable)({
711
- scope: import_common7.Scope.REQUEST
759
+ (0, import_common6.Injectable)({
760
+ scope: import_common6.Scope.REQUEST
712
761
  }),
713
- _ts_param3(3, (0, import_common7.Inject)(AUTH_CONFIG)),
762
+ _ts_param3(3, (0, import_common6.Inject)(AUTH_CONFIG)),
714
763
  _ts_metadata3("design:type", Function),
715
764
  _ts_metadata3("design:paramtypes", [
716
765
  typeof import_core2.Reflector === "undefined" ? Object : import_core2.Reflector,
@@ -797,27 +846,27 @@ var AuthConfigModule = class _AuthConfigModule {
797
846
  }
798
847
  };
799
848
  AuthConfigModule = _ts_decorate5([
800
- (0, import_common8.Global)(),
801
- (0, import_common8.Module)({})
849
+ (0, import_common7.Global)(),
850
+ (0, import_common7.Module)({})
802
851
  ], AuthConfigModule);
803
852
 
804
853
  // src/auth/decorators/access-token.decorator.ts
805
- var import_common9 = require("@nestjs/common");
806
- var AccessToken = (0, import_common9.createParamDecorator)((_data, ctx) => {
854
+ var import_common8 = require("@nestjs/common");
855
+ var AccessToken = (0, import_common8.createParamDecorator)((_data, ctx) => {
807
856
  const request = getRequestFromContext(ctx);
808
857
  const authHeader = request.headers.authorization;
809
858
  return authHeader?.replace("Bearer ", "") || "";
810
859
  });
811
860
 
812
861
  // src/auth/decorators/client-ip.decorator.ts
813
- var import_common10 = require("@nestjs/common");
814
- var ClientIp = (0, import_common10.createParamDecorator)((_data, ctx) => {
862
+ var import_common9 = require("@nestjs/common");
863
+ var ClientIp = (0, import_common9.createParamDecorator)((_data, ctx) => {
815
864
  return getRequestFromContext(ctx).ip;
816
865
  });
817
866
 
818
867
  // src/auth/decorators/cookie-domain.decorator.ts
819
- var import_common11 = require("@nestjs/common");
820
- var CookieDomain = (0, import_common11.createParamDecorator)((_data, ctx) => {
868
+ var import_common10 = require("@nestjs/common");
869
+ var CookieDomain = (0, import_common10.createParamDecorator)((_data, ctx) => {
821
870
  const request = getRequestFromContext(ctx);
822
871
  const forwarded = request.headers["x-forwarded-host"];
823
872
  const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
@@ -828,15 +877,15 @@ var CookieDomain = (0, import_common11.createParamDecorator)((_data, ctx) => {
828
877
  });
829
878
 
830
879
  // src/auth/decorators/cookie-name.decorator.ts
831
- var import_common12 = require("@nestjs/common");
832
- var CookieName = (0, import_common12.createParamDecorator)((_data, ctx) => {
880
+ var import_common11 = require("@nestjs/common");
881
+ var CookieName = (0, import_common11.createParamDecorator)((_data, ctx) => {
833
882
  const request = getRequestFromContext(ctx);
834
883
  return request.authConfig?.cookie.refreshCookieName ?? AUTH_CONFIG_DEFAULTS.cookie.refreshCookieName;
835
884
  });
836
885
 
837
886
  // src/auth/decorators/hostname.decorator.ts
838
- var import_common13 = require("@nestjs/common");
839
- var Hostname = (0, import_common13.createParamDecorator)((_data, ctx) => {
887
+ var import_common12 = require("@nestjs/common");
888
+ var Hostname = (0, import_common12.createParamDecorator)((_data, ctx) => {
840
889
  const request = getRequestFromContext(ctx);
841
890
  const forwarded = request.headers["x-forwarded-host"];
842
891
  const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
@@ -844,19 +893,15 @@ var Hostname = (0, import_common13.createParamDecorator)((_data, ctx) => {
844
893
  return hostStr.split(":")[0] ?? hostStr;
845
894
  });
846
895
 
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
896
  // src/auth/decorators/refresh-cookie-options.decorator.ts
852
- var import_common34 = require("@nestjs/common");
897
+ var import_common32 = require("@nestjs/common");
853
898
 
854
899
  // src/exceptions/bad-gateway.exception.ts
855
- var import_common16 = require("@nestjs/common");
900
+ var import_common14 = require("@nestjs/common");
856
901
 
857
902
  // src/exceptions/base-field.exception.ts
858
- var import_common15 = require("@nestjs/common");
859
- var HttpProblemException = class extends import_common15.HttpException {
903
+ var import_common13 = require("@nestjs/common");
904
+ var HttpProblemException = class extends import_common13.HttpException {
860
905
  static {
861
906
  __name(this, "HttpProblemException");
862
907
  }
@@ -874,63 +919,63 @@ var HttpProblemException = class extends import_common15.HttpException {
874
919
  };
875
920
 
876
921
  // src/exceptions/bad-request.exception.ts
877
- var import_common17 = require("@nestjs/common");
922
+ var import_common15 = require("@nestjs/common");
878
923
 
879
924
  // src/exceptions/conflict.exception.ts
880
- var import_common18 = require("@nestjs/common");
925
+ var import_common16 = require("@nestjs/common");
881
926
 
882
927
  // src/exceptions/forbidden.exception.ts
883
- var import_common19 = require("@nestjs/common");
928
+ var import_common17 = require("@nestjs/common");
884
929
 
885
930
  // src/exceptions/gone.exception.ts
886
- var import_common20 = require("@nestjs/common");
931
+ var import_common18 = require("@nestjs/common");
887
932
 
888
933
  // src/exceptions/internal-server-error.exception.ts
889
- var import_common21 = require("@nestjs/common");
934
+ var import_common19 = require("@nestjs/common");
890
935
 
891
936
  // src/exceptions/method-not-allowed.exception.ts
892
- var import_common22 = require("@nestjs/common");
937
+ var import_common20 = require("@nestjs/common");
893
938
 
894
939
  // src/exceptions/not-acceptable.exception.ts
895
- var import_common23 = require("@nestjs/common");
940
+ var import_common21 = require("@nestjs/common");
896
941
 
897
942
  // src/exceptions/not-found.exception.ts
898
- var import_common24 = require("@nestjs/common");
943
+ var import_common22 = require("@nestjs/common");
899
944
 
900
945
  // src/exceptions/not-implemented.exception.ts
901
- var import_common25 = require("@nestjs/common");
946
+ var import_common23 = require("@nestjs/common");
902
947
 
903
948
  // src/exceptions/payload-too-large.exception.ts
904
- var import_common26 = require("@nestjs/common");
949
+ var import_common24 = require("@nestjs/common");
905
950
 
906
951
  // src/exceptions/request-timeout.exception.ts
907
- var import_common27 = require("@nestjs/common");
952
+ var import_common25 = require("@nestjs/common");
908
953
 
909
954
  // src/exceptions/service-unavailable.exception.ts
910
- var import_common28 = require("@nestjs/common");
955
+ var import_common26 = require("@nestjs/common");
911
956
 
912
957
  // src/exceptions/too-many-requests.exception.ts
913
- var import_common29 = require("@nestjs/common");
958
+ var import_common27 = require("@nestjs/common");
914
959
 
915
960
  // src/exceptions/unauthorized.exception.ts
916
- var import_common30 = require("@nestjs/common");
961
+ var import_common28 = require("@nestjs/common");
917
962
  var UnauthorizedException3 = class extends HttpProblemException {
918
963
  static {
919
964
  __name(this, "UnauthorizedException");
920
965
  }
921
966
  constructor(detailOrOptions) {
922
- super(detailOrOptions ?? "Unauthorized", import_common30.HttpStatus.UNAUTHORIZED);
967
+ super(detailOrOptions ?? "Unauthorized", import_common28.HttpStatus.UNAUTHORIZED);
923
968
  }
924
969
  };
925
970
 
926
971
  // src/exceptions/unprocessable-entity.exception.ts
927
- var import_common31 = require("@nestjs/common");
972
+ var import_common29 = require("@nestjs/common");
928
973
 
929
974
  // src/exceptions/unsupported-media-type.exception.ts
930
- var import_common32 = require("@nestjs/common");
975
+ var import_common30 = require("@nestjs/common");
931
976
 
932
977
  // src/exceptions/validation.exception.ts
933
- var import_common33 = require("@nestjs/common");
978
+ var import_common31 = require("@nestjs/common");
934
979
 
935
980
  // src/auth/decorators/refresh-cookie-options.decorator.ts
936
981
  function buildCookieOptionsForHost(cookieConfig, hostname) {
@@ -951,7 +996,7 @@ function buildCookieOptionsForHost(cookieConfig, hostname) {
951
996
  };
952
997
  }
953
998
  __name(buildCookieOptionsForHost, "buildCookieOptionsForHost");
954
- var RefreshCookieOptions = (0, import_common34.createParamDecorator)((_data, ctx) => {
999
+ var RefreshCookieOptions = (0, import_common32.createParamDecorator)((_data, ctx) => {
955
1000
  const request = getRequestFromContext(ctx);
956
1001
  const forwarded = request.headers["x-forwarded-host"];
957
1002
  const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
@@ -962,8 +1007,8 @@ var RefreshCookieOptions = (0, import_common34.createParamDecorator)((_data, ctx
962
1007
  });
963
1008
 
964
1009
  // src/auth/decorators/refresh-token-cookie.decorator.ts
965
- var import_common35 = require("@nestjs/common");
966
- var RefreshTokenCookie = (0, import_common35.createParamDecorator)((_data, ctx) => {
1010
+ var import_common33 = require("@nestjs/common");
1011
+ var RefreshTokenCookie = (0, import_common33.createParamDecorator)((_data, ctx) => {
967
1012
  const request = getRequestFromContext(ctx);
968
1013
  const cookies = request.cookies ?? {};
969
1014
  const cookieName = request.authConfig?.cookie.refreshCookieName ?? AUTH_CONFIG_DEFAULTS.cookie.refreshCookieName;
@@ -971,23 +1016,22 @@ var RefreshTokenCookie = (0, import_common35.createParamDecorator)((_data, ctx)
971
1016
  });
972
1017
 
973
1018
  // src/auth/decorators/session-data.decorator.ts
974
- var import_common36 = require("@nestjs/common");
975
- var SessionData = (0, import_common36.createParamDecorator)((_data, ctx) => {
976
- const request = getRequestFromContext(ctx);
977
- const sessionInfo = request.sessionInfo;
978
- if (!sessionInfo?.sessionId) {
979
- throw new Error("Session info not found on request. Ensure route is protected by auth guard.");
1019
+ var import_common34 = require("@nestjs/common");
1020
+ var SessionData = (0, import_common34.createParamDecorator)((_data, ctx) => {
1021
+ const auth = getRequestFromContext(ctx).auth;
1022
+ if (auth?.kind !== "session") {
1023
+ throw new Error(`No session on this request (auth: ${auth?.kind ?? "none"}). @SessionData() is session-only.`);
980
1024
  }
981
1025
  return {
982
- userId: sessionInfo.userId,
983
- sessionId: sessionInfo.sessionId,
984
- sessionType: sessionInfo.sessionType
1026
+ userId: auth.userId,
1027
+ sessionId: auth.sessionId,
1028
+ sessionType: auth.sessionType
985
1029
  };
986
1030
  });
987
1031
 
988
1032
  // src/auth/decorators/subdomain.decorator.ts
989
- var import_common37 = require("@nestjs/common");
990
- var Subdomain = (0, import_common37.createParamDecorator)((_data, ctx) => {
1033
+ var import_common35 = require("@nestjs/common");
1034
+ var Subdomain = (0, import_common35.createParamDecorator)((_data, ctx) => {
991
1035
  const request = getRequestFromContext(ctx);
992
1036
  const forwarded = request.headers["x-forwarded-host"];
993
1037
  const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
@@ -998,29 +1042,28 @@ var Subdomain = (0, import_common37.createParamDecorator)((_data, ctx) => {
998
1042
  });
999
1043
 
1000
1044
  // src/auth/decorators/user-agent.decorator.ts
1001
- var import_common38 = require("@nestjs/common");
1002
- var UserAgent = (0, import_common38.createParamDecorator)((_data, ctx) => {
1045
+ var import_common36 = require("@nestjs/common");
1046
+ var UserAgent = (0, import_common36.createParamDecorator)((_data, ctx) => {
1003
1047
  const userAgent = getRequestFromContext(ctx).headers["user-agent"];
1004
1048
  return Array.isArray(userAgent) ? userAgent[0] : userAgent;
1005
1049
  });
1006
1050
 
1007
1051
  // src/auth/decorators/user-id.decorator.ts
1008
- var import_common39 = require("@nestjs/common");
1009
- var UserId = (0, import_common39.createParamDecorator)((_data, ctx) => {
1010
- const request = getRequestFromContext(ctx);
1011
- const sessionInfo = request.sessionInfo;
1012
- if (!sessionInfo?.userId) {
1013
- throw new Error("User ID not found on request. Ensure route is protected by auth guard.");
1052
+ var import_common37 = require("@nestjs/common");
1053
+ var UserId = (0, import_common37.createParamDecorator)((_data, ctx) => {
1054
+ const auth = getRequestFromContext(ctx).auth;
1055
+ if (auth?.kind !== "session") {
1056
+ throw new Error(`No user on this request (auth: ${auth?.kind ?? "none"}). @UserId() is session-only.`);
1014
1057
  }
1015
- return sessionInfo.userId;
1058
+ return auth.userId;
1016
1059
  });
1017
1060
  // Annotate the CommonJS export names for ESM import in node:
1018
1061
  0 && (module.exports = {
1019
- APP_SESSION_TYPE,
1020
1062
  AUTH_CONFIG,
1021
1063
  AUTH_CONFIG_DEFAULTS,
1022
1064
  AccessToken,
1023
1065
  AuthConfigModule,
1066
+ AuthType,
1024
1067
  CLIENT_ID_HEADER,
1025
1068
  ClientIp,
1026
1069
  CookieDomain,
@@ -1028,13 +1071,10 @@ var UserId = (0, import_common39.createParamDecorator)((_data, ctx) => {
1028
1071
  Hostname,
1029
1072
  MAX_CLOCK_SKEW_SECONDS,
1030
1073
  PARTY_ID_HEADER,
1031
- Public,
1032
- REQUIRE_APP_KEY,
1033
- REQUIRE_SESSION_KEY,
1074
+ REQUIRE_AUTH_KEY,
1034
1075
  RefreshCookieOptions,
1035
1076
  RefreshTokenCookie,
1036
- RequireApp,
1037
- RequireSession,
1077
+ Require,
1038
1078
  SKIP_CSRF_KEY,
1039
1079
  SessionData,
1040
1080
  SkipCsrf,