@vritti/api-sdk 0.1.4 → 0.1.6

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/index.d.cts CHANGED
@@ -156,6 +156,30 @@ declare const Onboarding: () => _nestjs_common.CustomDecorator<string>;
156
156
  */
157
157
  declare const Public: () => _nestjs_common.CustomDecorator<string>;
158
158
 
159
+ /**
160
+ * Parameter decorator to extract user ID from authenticated request
161
+ *
162
+ * This decorator retrieves the user ID from the request object,
163
+ * which is set by authentication guards (JwtAuthGuard, VrittiAuthGuard).
164
+ *
165
+ * @returns The user's ID as a string (UUID)
166
+ *
167
+ * @example
168
+ * @Post('verify-email')
169
+ * @Onboarding()
170
+ * async verifyEmail(@UserId() userId: string) {
171
+ * await this.service.verify(userId);
172
+ * }
173
+ *
174
+ * @example
175
+ * @Post('logout-all')
176
+ * @UseGuards(JwtAuthGuard)
177
+ * async logoutAll(@UserId() userId: string) {
178
+ * await this.authService.logoutAll(userId);
179
+ * }
180
+ */
181
+ declare const UserId: (...dataOrPipes: unknown[]) => ParameterDecorator;
182
+
159
183
  /**
160
184
  * Schema Registry Interface
161
185
  *
@@ -558,6 +582,12 @@ interface CookieConfig {
558
582
  * @default 'strict'
559
583
  */
560
584
  refreshCookieSameSite: 'strict' | 'lax' | 'none';
585
+ /**
586
+ * Cookie domain (e.g., 'localhost' for dev, '.vritti.cloud' for prod)
587
+ * Required for cross-subdomain auth (e.g., cloud.localhost accessing localhost API)
588
+ * @default undefined (uses request domain)
589
+ */
590
+ refreshCookieDomain?: string;
561
591
  }
562
592
  /**
563
593
  * JWT token configuration options
@@ -650,13 +680,7 @@ declare function resetConfig(): void;
650
680
  /**
651
681
  * Get refresh cookie options (convenience method)
652
682
  */
653
- declare function getRefreshCookieOptions(): {
654
- httpOnly: boolean;
655
- secure: boolean;
656
- sameSite: "strict" | "lax" | "none";
657
- path: string;
658
- maxAge: number;
659
- };
683
+ declare function getRefreshCookieOptions(): Record<string, unknown>;
660
684
  /**
661
685
  * Get JWT expiry settings (convenience method)
662
686
  */
@@ -2491,4 +2515,4 @@ declare function generateCorrelationId(): string;
2491
2515
  */
2492
2516
  declare function addCorrelationIdToResponse(reply: FastifyReply, correlationId: string, headerName?: string): void;
2493
2517
 
2494
- export { type ApiErrorResponse, type ApiSdkConfig, AuthConfigModule, BadGatewayException, BadRequestException, BaseFieldException, ConflictException, type CookieConfig, type CorrelationContext, CorrelationIdMiddleware, CsrfGuard, DEFAULT_CORRELATION_HEADER, DatabaseModule, type DatabaseModuleOptions, type FieldError, ForbiddenException, GoneException, type GuardConfig, HttpExceptionFilter, HttpLoggerInterceptor, type HttpLoggerOptions, HttpModule, InternalServerErrorException, type JwtConfig, LOGGER_MODULE_OPTIONS, type LogFormat, type LogLevel, type LogMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, type LoggerOptionsFactory, LoggerService, MethodNotAllowedException, NotAcceptableException, NotFoundException, NotImplementedException, Onboarding, PayloadTooLargeException, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, type ProblemDetails, Public, type RegisteredSchema, RequestTimeoutException, ServiceUnavailableException, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, TooManyRequestsException, type TypedDrizzleClient, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, ValidationException, VrittiAuthGuard, addCorrelationIdToResponse, configureApiSdk, correlationStorage, defineConfig, generateCorrelationId, getConfig, getCorrelationContext, getHttpStatusTitle, getJwtExpiry, getRefreshCookieOptions, hashToken, resetConfig, runWithCorrelationContext, updateCorrelationContext, verifyTokenHash };
2518
+ export { type ApiErrorResponse, type ApiSdkConfig, AuthConfigModule, BadGatewayException, BadRequestException, BaseFieldException, ConflictException, type CookieConfig, type CorrelationContext, CorrelationIdMiddleware, CsrfGuard, DEFAULT_CORRELATION_HEADER, DatabaseModule, type DatabaseModuleOptions, type FieldError, ForbiddenException, GoneException, type GuardConfig, HttpExceptionFilter, HttpLoggerInterceptor, type HttpLoggerOptions, HttpModule, InternalServerErrorException, type JwtConfig, LOGGER_MODULE_OPTIONS, type LogFormat, type LogLevel, type LogMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, type LoggerOptionsFactory, LoggerService, MethodNotAllowedException, NotAcceptableException, NotFoundException, NotImplementedException, Onboarding, PayloadTooLargeException, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, type ProblemDetails, Public, type RegisteredSchema, RequestTimeoutException, ServiceUnavailableException, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, TooManyRequestsException, type TypedDrizzleClient, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, UserId, ValidationException, VrittiAuthGuard, addCorrelationIdToResponse, configureApiSdk, correlationStorage, defineConfig, generateCorrelationId, getConfig, getCorrelationContext, getHttpStatusTitle, getJwtExpiry, getRefreshCookieOptions, hashToken, resetConfig, runWithCorrelationContext, updateCorrelationContext, verifyTokenHash };
package/dist/index.d.ts CHANGED
@@ -156,6 +156,30 @@ declare const Onboarding: () => _nestjs_common.CustomDecorator<string>;
156
156
  */
157
157
  declare const Public: () => _nestjs_common.CustomDecorator<string>;
158
158
 
159
+ /**
160
+ * Parameter decorator to extract user ID from authenticated request
161
+ *
162
+ * This decorator retrieves the user ID from the request object,
163
+ * which is set by authentication guards (JwtAuthGuard, VrittiAuthGuard).
164
+ *
165
+ * @returns The user's ID as a string (UUID)
166
+ *
167
+ * @example
168
+ * @Post('verify-email')
169
+ * @Onboarding()
170
+ * async verifyEmail(@UserId() userId: string) {
171
+ * await this.service.verify(userId);
172
+ * }
173
+ *
174
+ * @example
175
+ * @Post('logout-all')
176
+ * @UseGuards(JwtAuthGuard)
177
+ * async logoutAll(@UserId() userId: string) {
178
+ * await this.authService.logoutAll(userId);
179
+ * }
180
+ */
181
+ declare const UserId: (...dataOrPipes: unknown[]) => ParameterDecorator;
182
+
159
183
  /**
160
184
  * Schema Registry Interface
161
185
  *
@@ -558,6 +582,12 @@ interface CookieConfig {
558
582
  * @default 'strict'
559
583
  */
560
584
  refreshCookieSameSite: 'strict' | 'lax' | 'none';
585
+ /**
586
+ * Cookie domain (e.g., 'localhost' for dev, '.vritti.cloud' for prod)
587
+ * Required for cross-subdomain auth (e.g., cloud.localhost accessing localhost API)
588
+ * @default undefined (uses request domain)
589
+ */
590
+ refreshCookieDomain?: string;
561
591
  }
562
592
  /**
563
593
  * JWT token configuration options
@@ -650,13 +680,7 @@ declare function resetConfig(): void;
650
680
  /**
651
681
  * Get refresh cookie options (convenience method)
652
682
  */
653
- declare function getRefreshCookieOptions(): {
654
- httpOnly: boolean;
655
- secure: boolean;
656
- sameSite: "strict" | "lax" | "none";
657
- path: string;
658
- maxAge: number;
659
- };
683
+ declare function getRefreshCookieOptions(): Record<string, unknown>;
660
684
  /**
661
685
  * Get JWT expiry settings (convenience method)
662
686
  */
@@ -2491,4 +2515,4 @@ declare function generateCorrelationId(): string;
2491
2515
  */
2492
2516
  declare function addCorrelationIdToResponse(reply: FastifyReply, correlationId: string, headerName?: string): void;
2493
2517
 
2494
- export { type ApiErrorResponse, type ApiSdkConfig, AuthConfigModule, BadGatewayException, BadRequestException, BaseFieldException, ConflictException, type CookieConfig, type CorrelationContext, CorrelationIdMiddleware, CsrfGuard, DEFAULT_CORRELATION_HEADER, DatabaseModule, type DatabaseModuleOptions, type FieldError, ForbiddenException, GoneException, type GuardConfig, HttpExceptionFilter, HttpLoggerInterceptor, type HttpLoggerOptions, HttpModule, InternalServerErrorException, type JwtConfig, LOGGER_MODULE_OPTIONS, type LogFormat, type LogLevel, type LogMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, type LoggerOptionsFactory, LoggerService, MethodNotAllowedException, NotAcceptableException, NotFoundException, NotImplementedException, Onboarding, PayloadTooLargeException, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, type ProblemDetails, Public, type RegisteredSchema, RequestTimeoutException, ServiceUnavailableException, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, TooManyRequestsException, type TypedDrizzleClient, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, ValidationException, VrittiAuthGuard, addCorrelationIdToResponse, configureApiSdk, correlationStorage, defineConfig, generateCorrelationId, getConfig, getCorrelationContext, getHttpStatusTitle, getJwtExpiry, getRefreshCookieOptions, hashToken, resetConfig, runWithCorrelationContext, updateCorrelationContext, verifyTokenHash };
2518
+ export { type ApiErrorResponse, type ApiSdkConfig, AuthConfigModule, BadGatewayException, BadRequestException, BaseFieldException, ConflictException, type CookieConfig, type CorrelationContext, CorrelationIdMiddleware, CsrfGuard, DEFAULT_CORRELATION_HEADER, DatabaseModule, type DatabaseModuleOptions, type FieldError, ForbiddenException, GoneException, type GuardConfig, HttpExceptionFilter, HttpLoggerInterceptor, type HttpLoggerOptions, HttpModule, InternalServerErrorException, type JwtConfig, LOGGER_MODULE_OPTIONS, type LogFormat, type LogLevel, type LogMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, type LoggerOptionsFactory, LoggerService, MethodNotAllowedException, NotAcceptableException, NotFoundException, NotImplementedException, Onboarding, PayloadTooLargeException, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, type ProblemDetails, Public, type RegisteredSchema, RequestTimeoutException, ServiceUnavailableException, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, TooManyRequestsException, type TypedDrizzleClient, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, UserId, ValidationException, VrittiAuthGuard, addCorrelationIdToResponse, configureApiSdk, correlationStorage, defineConfig, generateCorrelationId, getConfig, getCorrelationContext, getHttpStatusTitle, getJwtExpiry, getRefreshCookieOptions, hashToken, resetConfig, runWithCorrelationContext, updateCorrelationContext, verifyTokenHash };
package/dist/index.js CHANGED
@@ -21,7 +21,8 @@ var defaultConfig = {
21
21
  refreshCookieMaxAge: 30 * 24 * 60 * 60 * 1e3,
22
22
  refreshCookiePath: "/",
23
23
  refreshCookieSecure: process.env.NODE_ENV === "production",
24
- refreshCookieSameSite: "strict"
24
+ refreshCookieSameSite: "strict",
25
+ refreshCookieDomain: "localhost"
25
26
  },
26
27
  jwt: {
27
28
  accessTokenExpiry: "15m",
@@ -70,13 +71,17 @@ function resetConfig() {
70
71
  }
71
72
  __name(resetConfig, "resetConfig");
72
73
  function getRefreshCookieOptions() {
73
- return {
74
+ const options = {
74
75
  httpOnly: true,
75
76
  secure: currentConfig.cookie.refreshCookieSecure,
76
77
  sameSite: currentConfig.cookie.refreshCookieSameSite,
77
78
  path: currentConfig.cookie.refreshCookiePath,
78
79
  maxAge: currentConfig.cookie.refreshCookieMaxAge
79
80
  };
81
+ if (currentConfig.cookie.refreshCookieDomain) {
82
+ options.domain = currentConfig.cookie.refreshCookieDomain;
83
+ }
84
+ return options;
80
85
  }
81
86
  __name(getRefreshCookieOptions, "getRefreshCookieOptions");
82
87
  function getJwtExpiry() {
@@ -726,6 +731,17 @@ var Onboarding = /* @__PURE__ */ __name(() => SetMetadata("isOnboarding", true),
726
731
  import { SetMetadata as SetMetadata2 } from "@nestjs/common";
727
732
  var Public = /* @__PURE__ */ __name(() => SetMetadata2("isPublic", true), "Public");
728
733
 
734
+ // src/auth/decorators/user-id.decorator.ts
735
+ import { createParamDecorator } from "@nestjs/common";
736
+ var UserId = createParamDecorator((_data, ctx) => {
737
+ const request = ctx.switchToHttp().getRequest();
738
+ const user = request.user;
739
+ if (!user?.id) {
740
+ throw new Error("User ID not found on request. Ensure route is protected by auth guard.");
741
+ }
742
+ return user.id;
743
+ });
744
+
729
745
  // src/database/database.module.ts
730
746
  import { Global as Global3, Module as Module3 } from "@nestjs/common";
731
747
  import { APP_INTERCEPTOR } from "@nestjs/core";
@@ -1296,8 +1312,8 @@ DatabaseModule = _ts_decorate10([
1296
1312
  ], DatabaseModule);
1297
1313
 
1298
1314
  // src/database/decorators/tenant.decorator.ts
1299
- import { createParamDecorator } from "@nestjs/common";
1300
- var Tenant = createParamDecorator((_data, ctx) => {
1315
+ import { createParamDecorator as createParamDecorator2 } from "@nestjs/common";
1316
+ var Tenant = createParamDecorator2((_data, ctx) => {
1301
1317
  const request = ctx.switchToHttp().getRequest();
1302
1318
  const tenantContext = request.app?.get?.(TenantContextService);
1303
1319
  if (!tenantContext) {
@@ -3387,6 +3403,7 @@ export {
3387
3403
  UnauthorizedException4 as UnauthorizedException,
3388
3404
  UnprocessableEntityException,
3389
3405
  UnsupportedMediaTypeException,
3406
+ UserId,
3390
3407
  ValidationException,
3391
3408
  VrittiAuthGuard,
3392
3409
  addCorrelationIdToResponse,