@vritti/api-sdk 0.3.3 → 0.3.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/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 +337 -140
- package/dist/catalog-resolver.cjs.map +1 -1
- package/dist/catalog-resolver.d.cts +70 -45
- package/dist/catalog-resolver.d.ts +70 -45
- package/dist/catalog-resolver.js +322 -135
- 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/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.d.cts +1 -1
- package/dist/license.d.ts +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/{types-DQRwj5rr.d.cts → types-BBK6MG-U.d.cts} +37 -6
- package/dist/{types-DQRwj5rr.d.ts → types-BBK6MG-U.d.ts} +37 -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 +122 -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/nats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filters/rpc-problem-exception.filter.ts","../src/exceptions/conflict.exception.ts","../src/exceptions/base-field.exception.ts","../src/filters/pg-error.translator.ts","../src/nats/decorators/nats-headers.decorator.ts","../src/nats/nats-context.ts","../src/nats/nats-client.module.ts","../src/nats/constants.ts","../src/nats/nats-client.service.ts","../src/context/resolve-request.ts","../src/nats/nats-microservice-client.service.ts"],"sourcesContent":["import { type ArgumentsHost, Catch, type HttpException, HttpStatus, Logger } from '@nestjs/common';\nimport { RpcException } from '@nestjs/microservices';\nimport { type Observable, throwError } from 'rxjs';\nimport { tryTranslatePgError } from './pg-error.translator';\n\ninterface FieldError {\n field: string;\n message: string;\n}\n\ninterface ProblemPayload {\n type: string;\n label?: string;\n detail: string;\n message: string;\n errors: FieldError[];\n status: number;\n statusCode: number;\n}\n\n@Catch()\nexport class RpcProblemExceptionFilter {\n private readonly logger = new Logger(RpcProblemExceptionFilter.name);\n\n catch(exception: unknown, _host: ArgumentsHost): Observable<never> {\n // Translate raw Postgres errors (e.g. 23505 unique_violation from an unguarded INSERT in\n // a NATS handler) into a ConflictException before the rest of the filter handles them.\n const translatedPgError = tryTranslatePgError(exception);\n if (translatedPgError) exception = translatedPgError;\n\n if (exception instanceof RpcException) {\n return throwError(() => exception.getError());\n }\n\n if (this.isHttpException(exception)) {\n const status = exception.getStatus();\n const response = exception.getResponse();\n return throwError(() => this.toProblemPayload(response, status));\n }\n\n if (exception instanceof Error) {\n const cause = (exception as { cause?: unknown }).cause;\n const causeMessage = cause instanceof Error ? cause.message : undefined;\n const causeStack = cause instanceof Error ? cause.stack : undefined;\n this.logger.error(causeMessage ?? exception.message, causeStack ?? exception.stack);\n if (cause && cause !== exception) {\n this.logger.error(`Wrapped by: ${exception.message}`);\n }\n return throwError(() =>\n this.toProblemPayload(\n {\n type: 'about:blank',\n detail: causeMessage ?? exception.message,\n errors: [],\n },\n HttpStatus.INTERNAL_SERVER_ERROR,\n ),\n );\n }\n\n this.logger.error(`Unhandled non-error exception: ${JSON.stringify(exception)}`);\n return throwError(() =>\n this.toProblemPayload(\n {\n type: 'about:blank',\n detail: 'An unexpected error occurred',\n errors: [],\n },\n HttpStatus.INTERNAL_SERVER_ERROR,\n ),\n );\n }\n\n private toProblemPayload(response: unknown, status: number): ProblemPayload {\n if (typeof response === 'string') {\n return {\n type: 'about:blank',\n detail: response,\n message: response,\n errors: [],\n status,\n statusCode: status,\n };\n }\n\n const obj = (response ?? {}) as Record<string, unknown>;\n const detail = typeof obj.detail === 'string' ? obj.detail : 'Request failed';\n return {\n type: typeof obj.type === 'string' ? obj.type : 'about:blank',\n label: typeof obj.label === 'string' ? obj.label : undefined,\n detail,\n message: detail,\n errors: Array.isArray(obj.errors) ? (obj.errors as FieldError[]) : [],\n status,\n statusCode: status,\n };\n }\n\n private isHttpException(error: unknown): error is HttpException {\n return (\n error instanceof Error &&\n typeof (error as { getStatus?: unknown }).getStatus === 'function' &&\n typeof (error as { getResponse?: unknown }).getResponse === 'function'\n );\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ConflictException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Conflict', HttpStatus.CONFLICT);\n }\n}\n","import { HttpException, HttpStatus } from '@nestjs/common';\nimport type { FieldError } from '../types/error-response.types';\n\n// Re-export FieldError for backwards compatibility\nexport type { FieldError } from '../types/error-response.types';\n\nexport interface ProblemOptions {\n type?: string;\n label?: string;\n detail?: string;\n errors?: FieldError[];\n}\n\nexport abstract class HttpProblemException extends HttpException {\n constructor(detailOrOptions: string | ProblemOptions, httpStatus: HttpStatus) {\n const options = typeof detailOrOptions === 'string' ? { detail: detailOrOptions } : detailOrOptions;\n\n super(\n {\n type: options.type ?? 'about:blank',\n label: options.label,\n detail: options.detail,\n errors: options.errors ?? [],\n },\n httpStatus,\n );\n }\n}\n","import { ConflictException } from '../exceptions/conflict.exception';\n\n// Postgres SQLSTATE codes we translate before the global filters render the response.\n// Reference: https://www.postgresql.org/docs/current/errcodes-appendix.html\n//\n// Today we only handle 23505 (unique_violation) — services already pre-check the common\n// duplicate cases for friendly messages; this is the race-condition / unguarded-write backstop\n// so a raw `error: duplicate key value violates unique constraint \"...\"` never reaches the\n// client as a 500. Extend the switch below as we identify other SQLSTATEs worth surfacing\n// (e.g. 23503 foreign_key_violation → 409 with FK info).\nconst PG_UNIQUE_VIOLATION = '23505';\n\nexport type PgErrorShape = {\n code?: string;\n message?: string;\n constraint?: string;\n table?: string;\n schema?: string;\n column?: string;\n detail?: string;\n hint?: string;\n};\n\n// Returns a ConflictException for a Postgres unique-violation error, otherwise undefined.\n// Both global filters call this at the top of their catch method so any 23505 escaping a\n// service produces the same RFC 9457 payload regardless of where it was thrown.\n//\n// Drizzle 1.0+ wraps pg driver errors in `DrizzleQueryError` with the original pg error on\n// `.cause`, so we walk a short cause chain to find the SQLSTATE.\nexport function tryTranslatePgError(error: unknown): ConflictException | undefined {\n const pgError = findPgError(error);\n if (!pgError) return undefined;\n const { code, constraint, table, detail } = pgError;\n if (code !== PG_UNIQUE_VIOLATION) return undefined;\n return new ConflictException({\n label: 'Duplicate Entry',\n detail: detail?.trim() || 'A record with these values already exists.',\n errors: [],\n ...(constraint || table ? { meta: { constraint, table } } : {}),\n });\n}\n\n// Walks up to N levels of `.cause` looking for a pg-shaped error (has SQLSTATE `code`).\n// Caps depth so a circular `cause` graph can't trap us.\nexport function findPgError(error: unknown, depth = 0): PgErrorShape | undefined {\n if (!error || typeof error !== 'object' || depth > 5) return undefined;\n const candidate = error as PgErrorShape & { cause?: unknown };\n if (typeof candidate.code === 'string') return candidate;\n return findPgError(candidate.cause, depth + 1);\n}\n","import { createParamDecorator, type ExecutionContext, InternalServerErrorException } from '@nestjs/common';\nimport { NatsContext } from '@nestjs/microservices';\nimport { parseNatsHeaders } from '../nats-context';\n\n// Extracts parsed NatsContext from NATS message headers\nexport const RpcNatsHeaders = createParamDecorator((_data: unknown, ctx: ExecutionContext) => {\n const rpcCtx = ctx.switchToRpc().getContext<NatsContext>();\n return parseNatsHeaders(rpcCtx.getHeaders());\n});\n\n// Extracts buId from NATS headers — throws if missing or empty\nexport const RpcBuId = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {\n const rpcCtx = ctx.switchToRpc().getContext<NatsContext>();\n const headers = parseNatsHeaders(rpcCtx.getHeaders());\n if (!headers?.buId) throw new InternalServerErrorException('Missing buId in NATS headers.');\n return headers.buId;\n});\n\n// Extracts buCurrencyCode from NATS headers — throws if missing or empty\nexport const RpcBuCurrencyCode = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {\n const rpcCtx = ctx.switchToRpc().getContext<NatsContext>();\n const headers = parseNatsHeaders(rpcCtx.getHeaders());\n if (!headers?.buCurrencyCode) throw new InternalServerErrorException('Missing buCurrencyCode in NATS headers.');\n return headers.buCurrencyCode;\n});\n","export interface NatsHeaders {\n orgId: string;\n userId: string;\n buId: string;\n buTimezone: string;\n buCurrencyCode: string;\n buAncestorIds: string[];\n buDescendantIds: string[];\n}\n\n// Header keys for NATS context transport\nexport const NATS_HEADER_KEYS = {\n ORG_ID: 'x-org-id',\n USER_ID: 'x-user-id',\n BU_ID: 'x-bu-id',\n BU_TIMEZONE: 'x-bu-timezone',\n BU_CURRENCY_CODE: 'x-bu-currency-code',\n BU_ANCESTOR_IDS: 'x-bu-ancestor-ids',\n BU_DESCENDANT_IDS: 'x-bu-descendant-ids',\n} as const;\n\n// Reads a header value from either a plain object or a NATS MsgHdrsImpl\nfunction getHeader(headers: unknown, key: string): string | undefined {\n if (!headers) return undefined;\n // MsgHdrsImpl uses .get(), plain objects use bracket access\n if (typeof (headers as { get?: unknown }).get === 'function') {\n const val = (headers as { get(key: string): string[] }).get(key);\n return Array.isArray(val) ? val[0] : (val as string | undefined);\n }\n return (headers as Record<string, string>)[key];\n}\n\n// Parses NATS message headers into a NatsHeaders object\nexport function parseNatsHeaders(headers: unknown): NatsHeaders | null {\n if (!headers) return null;\n\n const orgId = getHeader(headers, NATS_HEADER_KEYS.ORG_ID);\n const userId = getHeader(headers, NATS_HEADER_KEYS.USER_ID);\n const buId = getHeader(headers, NATS_HEADER_KEYS.BU_ID);\n\n if (!orgId || !userId || !buId) return null;\n\n return {\n orgId,\n userId,\n buId,\n buTimezone: getHeader(headers, NATS_HEADER_KEYS.BU_TIMEZONE) || 'UTC',\n buCurrencyCode: getHeader(headers, NATS_HEADER_KEYS.BU_CURRENCY_CODE) || '',\n buAncestorIds: JSON.parse(getHeader(headers, NATS_HEADER_KEYS.BU_ANCESTOR_IDS) || '[]'),\n buDescendantIds: JSON.parse(getHeader(headers, NATS_HEADER_KEYS.BU_DESCENDANT_IDS) || '[]'),\n };\n}\n","import { type DynamicModule, Global, Logger, Module, type OnModuleDestroy, type Provider } from '@nestjs/common';\nimport { ConfigModule, ConfigService } from '@nestjs/config';\nimport type { ClientProxy } from '@nestjs/microservices';\nimport { ClientProxyFactory, Transport } from '@nestjs/microservices';\nimport { NATS_CONTEXT_RESOLVER, NATS_MODULE_OPTIONS } from './constants';\nimport type {\n NatsMicroserviceModuleAsyncOptions,\n NatsModuleBaseOptions,\n NatsRootModuleAsyncOptions,\n NatsRootModuleOptions,\n} from './nats-client.interfaces';\nimport { NATS_CLIENTS, NatsClientService } from './nats-client.service';\nimport { NATS_MS_CLIENTS, NatsMicroserviceClientService } from './nats-microservice-client.service';\n\nconst NATS_MS_OPTIONS = Symbol('NATS_MS_OPTIONS');\n\n@Global()\n@Module({})\nexport class NatsClientModule implements OnModuleDestroy {\n private static readonly logger = new Logger(NatsClientModule.name);\n private static allClients: ClientProxy[] = [];\n\n async onModuleDestroy() {\n await Promise.all(NatsClientModule.allClients.map((c) => c.close()));\n NatsClientModule.allClients = [];\n }\n\n // Builds a Map of named NATS ClientProxy instances\n private static buildClients(options: NatsModuleBaseOptions, natsUrl: string): Map<string, ClientProxy> {\n const clients = new Map<string, ClientProxy>();\n\n for (const svc of options.services) {\n const proxy = ClientProxyFactory.create({\n transport: Transport.NATS,\n options: { servers: [natsUrl] },\n });\n clients.set(svc.name, proxy);\n NatsClientModule.allClients.push(proxy);\n NatsClientModule.logger.log(`Registered NATS client: ${svc.name} → ${natsUrl}`);\n }\n\n return clients;\n }\n\n // Gateway mode — request-scoped, resolves context from sessionInfo via callback\n static forRoot(asyncOptions: NatsRootModuleAsyncOptions): DynamicModule {\n const optionsProvider: Provider = {\n provide: NATS_MODULE_OPTIONS,\n useFactory: asyncOptions.useFactory,\n inject: asyncOptions.inject || [],\n };\n\n const resolverProvider: Provider = {\n provide: NATS_CONTEXT_RESOLVER,\n useFactory: (options: NatsRootModuleOptions) => options.contextResolver,\n inject: [NATS_MODULE_OPTIONS],\n };\n\n const clientsProvider: Provider = {\n provide: NATS_CLIENTS,\n useFactory: (options: NatsRootModuleOptions, config: ConfigService): Map<string, ClientProxy> => {\n const natsUrl = options.natsUrl ?? config.get<string>('NATS_URL', 'nats://localhost:4222');\n return NatsClientModule.buildClients(options, natsUrl);\n },\n inject: [NATS_MODULE_OPTIONS, ConfigService],\n };\n\n return {\n module: NatsClientModule,\n imports: [ConfigModule, ...(asyncOptions.imports ?? [])],\n providers: [optionsProvider, resolverProvider, clientsProvider, NatsClientService],\n exports: [NatsClientService],\n };\n }\n\n // Microservice mode — singleton, forwards context from incoming NATS payload\n static forMicroservice(asyncOptions: NatsMicroserviceModuleAsyncOptions): DynamicModule {\n const optionsProvider: Provider = {\n provide: NATS_MS_OPTIONS,\n useFactory: asyncOptions.useFactory,\n inject: asyncOptions.inject || [],\n };\n\n const clientsProvider: Provider = {\n provide: NATS_MS_CLIENTS,\n useFactory: (options: NatsModuleBaseOptions, config: ConfigService): Map<string, ClientProxy> => {\n const natsUrl = options.natsUrl ?? config.get<string>('NATS_URL', 'nats://localhost:4222');\n return NatsClientModule.buildClients(options, natsUrl);\n },\n inject: [NATS_MS_OPTIONS, ConfigService],\n };\n\n return {\n module: NatsClientModule,\n imports: [ConfigModule, ...(asyncOptions.imports ?? [])],\n providers: [optionsProvider, clientsProvider, NatsMicroserviceClientService],\n exports: [NatsMicroserviceClientService],\n };\n }\n}\n","export const NATS_MODULE_OPTIONS = Symbol('NATS_MODULE_OPTIONS');\nexport const NATS_CONTEXT_RESOLVER = Symbol('NATS_CONTEXT_RESOLVER');\n","// Pulls the `declare module 'fastify'` augmentation (request.sessionInfo) into this entry's\n// dts graph — tsup builds each entry in isolation and otherwise drops the global augmentation.\nimport '../types/fastify-augmentation';\nimport { Inject, Injectable, Scope } from '@nestjs/common';\nimport { REQUEST } from '@nestjs/core';\nimport type { ClientProxy } from '@nestjs/microservices';\nimport { NatsRecordBuilder } from '@nestjs/microservices';\nimport type { FastifyRequest } from 'fastify';\nimport { headers as natsHeaders } from 'nats';\nimport { resolveInjectedRequest } from '../context/resolve-request';\nimport { NATS_CONTEXT_RESOLVER } from './constants';\nimport type { ContextResolverFn } from './nats-client.interfaces';\nimport { NATS_HEADER_KEYS, type NatsHeaders } from './nats-context';\n\nexport const NATS_CLIENTS = Symbol('NATS_CLIENTS');\n\n@Injectable({ scope: Scope.REQUEST })\nexport class NatsClientService {\n private cachedContext: NatsHeaders | null = null;\n\n constructor(\n @Inject(REQUEST) private readonly injectedRequest: FastifyRequest,\n @Inject(NATS_CONTEXT_RESOLVER) private readonly contextResolver: ContextResolverFn,\n @Inject(NATS_CLIENTS) private readonly clients: Map<string, ClientProxy>,\n ) {}\n\n // For GraphQL, @Inject(REQUEST) is the { req, reply } context wrapper, not the Fastify request;\n // unwrap so `sessionInfo` (set by the auth guard on the request) is visible across both transports.\n private get request(): FastifyRequest {\n return resolveInjectedRequest(this.injectedRequest);\n }\n\n // Sends a message to a named microservice with NatsHeaders as NATS headers\n async send<T>(service: string, cmd: string, data?: object): Promise<T> {\n const client = this.clients.get(service);\n if (!client) {\n throw new Error(\n `NATS service \"${service}\" is not registered. Available: [${[...this.clients.keys()].join(', ')}]`,\n );\n }\n\n if (!this.cachedContext) {\n const sessionInfo = this.request.sessionInfo;\n if (!sessionInfo) {\n throw new Error('No sessionInfo on request — is the auth guard active?');\n }\n this.cachedContext = await this.contextResolver(sessionInfo);\n }\n\n const headers = contextToHeaders(this.cachedContext);\n const record = new NatsRecordBuilder(data ?? {}).setHeaders(headers).build();\n\n return client.send<T>({ cmd }, record).toPromise() as Promise<T>;\n }\n}\n\n// Converts NatsHeaders to a NATS MsgHdrs object for NATS transport\nfunction contextToHeaders(ctx: NatsHeaders): import('nats').MsgHdrs {\n const hdrs = natsHeaders();\n hdrs.set(NATS_HEADER_KEYS.ORG_ID, ctx.orgId);\n hdrs.set(NATS_HEADER_KEYS.USER_ID, ctx.userId);\n hdrs.set(NATS_HEADER_KEYS.BU_ID, ctx.buId);\n hdrs.set(NATS_HEADER_KEYS.BU_TIMEZONE, ctx.buTimezone);\n hdrs.set(NATS_HEADER_KEYS.BU_CURRENCY_CODE, ctx.buCurrencyCode);\n hdrs.set(NATS_HEADER_KEYS.BU_ANCESTOR_IDS, JSON.stringify(ctx.buAncestorIds));\n hdrs.set(NATS_HEADER_KEYS.BU_DESCENDANT_IDS, JSON.stringify(ctx.buDescendantIds));\n return hdrs;\n}\n","import type { FastifyRequest } from 'fastify';\n\n// NestJS injects the raw Fastify request via @Inject(REQUEST) for HTTP, but for GraphQL it injects\n// the GraphQL context object ({ req, reply }) — which has no `.headers` / `.sessionInfo`. Any\n// request-scoped service that reads the request off @Inject(REQUEST) (RequestService,\n// NatsClientService, …) calls this to unwrap to the real Fastify request, so it behaves identically\n// across both transports. (The guard sets `sessionInfo` on this same unwrapped request.)\nexport function resolveInjectedRequest(injected: FastifyRequest): FastifyRequest {\n const candidate = injected as unknown as { headers?: unknown; req?: FastifyRequest };\n if (candidate && candidate.headers === undefined && candidate.req) {\n return candidate.req;\n }\n return injected;\n}\n","import { Inject, Injectable } from '@nestjs/common';\nimport type { ClientProxy } from '@nestjs/microservices';\nimport { NatsRecordBuilder } from '@nestjs/microservices';\nimport { NATS_HEADER_KEYS, type NatsHeaders } from './nats-context';\n\nexport const NATS_MS_CLIENTS = Symbol('NATS_MS_CLIENTS');\n\n@Injectable()\nexport class NatsMicroserviceClientService {\n constructor(@Inject(NATS_MS_CLIENTS) private readonly clients: Map<string, ClientProxy>) {}\n\n // Forwards a message to another microservice with NatsHeaders\n async send<T>(service: string, cmd: string, natsHeaders: NatsHeaders, data?: object): Promise<T> {\n const client = this.clients.get(service);\n if (!client) {\n throw new Error(\n `NATS service \"${service}\" is not registered. Available: [${[...this.clients.keys()].join(', ')}]`,\n );\n }\n\n const headers: Record<string, string> = {\n [NATS_HEADER_KEYS.ORG_ID]: natsHeaders.orgId,\n [NATS_HEADER_KEYS.USER_ID]: natsHeaders.userId,\n [NATS_HEADER_KEYS.BU_ID]: natsHeaders.buId,\n [NATS_HEADER_KEYS.BU_TIMEZONE]: natsHeaders.buTimezone,\n [NATS_HEADER_KEYS.BU_ANCESTOR_IDS]: JSON.stringify(natsHeaders.buAncestorIds),\n [NATS_HEADER_KEYS.BU_DESCENDANT_IDS]: JSON.stringify(natsHeaders.buDescendantIds),\n };\n\n const record = new NatsRecordBuilder(data ?? {}).setHeaders(headers).build();\n return client.send<T>({ cmd }, record).toPromise() as Promise<T>;\n }\n}\n"],"mappings":";;;;AAAA,SAA6BA,OAA2BC,cAAAA,aAAYC,cAAc;AAClF,SAASC,oBAAoB;AAC7B,SAA0BC,kBAAkB;;;ACF5C,SAASC,kBAAkB;;;ACA3B,SAASC,qBAAiC;AAanC,IAAeC,uBAAf,cAA4CC,cAAAA;EAbnD,OAamDA;;;EACjD,YAAYC,iBAA0CC,YAAwB;AAC5E,UAAMC,UAAU,OAAOF,oBAAoB,WAAW;MAAEG,QAAQH;IAAgB,IAAIA;AAEpF,UACE;MACEI,MAAMF,QAAQE,QAAQ;MACtBC,OAAOH,QAAQG;MACfF,QAAQD,QAAQC;MAChBG,QAAQJ,QAAQI,UAAU,CAAA;IAC5B,GACAL,UAAAA;EAEJ;AACF;;;ADxBO,IAAMM,oBAAN,cAAgCC,qBAAAA;EAHvC,OAGuCA;;;EACrC,YAAYC,iBAA2C;AACrD,UAAMA,mBAAmB,YAAYC,WAAWC,QAAQ;EAC1D;AACF;;;AEGA,IAAMC,sBAAsB;AAmBrB,SAASC,oBAAoBC,OAAc;AAChD,QAAMC,UAAUC,YAAYF,KAAAA;AAC5B,MAAI,CAACC,QAAS,QAAOE;AACrB,QAAM,EAAEC,MAAMC,YAAYC,OAAOC,OAAM,IAA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;;;","names":["Catch","HttpStatus","Logger","RpcException","throwError","HttpStatus","HttpException","HttpProblemException","HttpException","detailOrOptions","httpStatus","options","detail","type","label","errors","ConflictException","HttpProblemException","detailOrOptions","HttpStatus","CONFLICT","PG_UNIQUE_VIOLATION","tryTranslatePgError","error","pgError","findPgError","undefined","code","constraint","table","detail","ConflictException","label","trim","errors","meta","depth","candidate","cause","RpcProblemExceptionFilter","logger","Logger","name","catch","exception","_host","translatedPgError","tryTranslatePgError","RpcException","throwError","getError","isHttpException","status","getStatus","response","getResponse","toProblemPayload","Error","cause","causeMessage","message","undefined","causeStack","stack","error","type","detail","errors","HttpStatus","INTERNAL_SERVER_ERROR","JSON","stringify","statusCode","obj","label","Array","isArray","createParamDecorator","InternalServerErrorException","NATS_HEADER_KEYS","ORG_ID","USER_ID","BU_ID","BU_TIMEZONE","BU_CURRENCY_CODE","BU_ANCESTOR_IDS","BU_DESCENDANT_IDS","getHeader","headers","key","undefined","get","val","Array","isArray","parseNatsHeaders","orgId","userId","buId","buTimezone","buCurrencyCode","buAncestorIds","JSON","parse","buDescendantIds","RpcNatsHeaders","createParamDecorator","_data","ctx","rpcCtx","switchToRpc","getContext","parseNatsHeaders","getHeaders","RpcBuId","headers","buId","InternalServerErrorException","RpcBuCurrencyCode","buCurrencyCode","Global","Logger","Module","ConfigModule","ConfigService","ClientProxyFactory","Transport","NATS_MODULE_OPTIONS","Symbol","NATS_CONTEXT_RESOLVER","Inject","Injectable","Scope","REQUEST","NatsRecordBuilder","headers","natsHeaders","resolveInjectedRequest","injected","candidate","headers","undefined","req","NATS_CLIENTS","Symbol","NatsClientService","cachedContext","injectedRequest","contextResolver","clients","request","resolveInjectedRequest","send","service","cmd","data","client","get","Error","keys","join","sessionInfo","headers","contextToHeaders","record","NatsRecordBuilder","setHeaders","build","toPromise","scope","Scope","REQUEST","ctx","hdrs","natsHeaders","set","NATS_HEADER_KEYS","ORG_ID","orgId","USER_ID","userId","BU_ID","buId","BU_TIMEZONE","buTimezone","BU_CURRENCY_CODE","buCurrencyCode","BU_ANCESTOR_IDS","JSON","stringify","buAncestorIds","BU_DESCENDANT_IDS","buDescendantIds","Inject","Injectable","NatsRecordBuilder","NATS_MS_CLIENTS","Symbol","NatsMicroserviceClientService","clients","send","service","cmd","natsHeaders","data","client","get","Error","keys","join","headers","NATS_HEADER_KEYS","ORG_ID","orgId","USER_ID","userId","BU_ID","buId","BU_TIMEZONE","buTimezone","BU_ANCESTOR_IDS","JSON","stringify","buAncestorIds","BU_DESCENDANT_IDS","buDescendantIds","record","NatsRecordBuilder","setHeaders","build","toPromise","NATS_MS_OPTIONS","Symbol","NatsClientModule","logger","Logger","name","allClients","onModuleDestroy","Promise","all","map","c","close","buildClients","options","natsUrl","clients","Map","svc","services","proxy","ClientProxyFactory","create","transport","Transport","NATS","servers","set","push","log","forRoot","asyncOptions","optionsProvider","provide","NATS_MODULE_OPTIONS","useFactory","inject","resolverProvider","NATS_CONTEXT_RESOLVER","contextResolver","clientsProvider","NATS_CLIENTS","config","get","ConfigService","module","imports","ConfigModule","providers","NatsClientService","exports","forMicroservice","NATS_MS_CLIENTS","NatsMicroserviceClientService"]}
|
|
1
|
+
{"version":3,"sources":["../src/filters/rpc-problem-exception.filter.ts","../src/exceptions/conflict.exception.ts","../src/exceptions/base-field.exception.ts","../src/filters/pg-error.translator.ts","../src/nats/decorators/nats-headers.decorator.ts","../src/nats/nats-context.ts","../src/nats/nats-client.module.ts","../src/nats/constants.ts","../src/nats/nats-client.service.ts","../src/context/resolve-request.ts","../src/nats/nats-microservice-client.service.ts"],"sourcesContent":["import { type ArgumentsHost, Catch, type HttpException, HttpStatus, Logger } from '@nestjs/common';\nimport { RpcException } from '@nestjs/microservices';\nimport { type Observable, throwError } from 'rxjs';\nimport { tryTranslatePgError } from './pg-error.translator';\n\ninterface FieldError {\n field: string;\n message: string;\n}\n\ninterface ProblemPayload {\n type: string;\n label?: string;\n detail: string;\n message: string;\n errors: FieldError[];\n status: number;\n statusCode: number;\n}\n\n@Catch()\nexport class RpcProblemExceptionFilter {\n private readonly logger = new Logger(RpcProblemExceptionFilter.name);\n\n catch(exception: unknown, _host: ArgumentsHost): Observable<never> {\n // Translate raw Postgres errors into a ConflictException before the rest of the filter handles them.\n const translatedPgError = tryTranslatePgError(exception);\n if (translatedPgError) exception = translatedPgError;\n\n if (exception instanceof RpcException) {\n return throwError(() => exception.getError());\n }\n\n if (this.isHttpException(exception)) {\n const status = exception.getStatus();\n const response = exception.getResponse();\n const payload = this.toProblemPayload(response, status);\n // Log 4xx/5xx so the microservice terminal shows what actually failed (previously silent)\n const log = status >= HttpStatus.INTERNAL_SERVER_ERROR ? this.logger.error : this.logger.warn;\n log.call(this.logger, `RPC ${status}: ${payload.detail}`);\n return throwError(() => payload);\n }\n\n if (exception instanceof Error) {\n const cause = (exception as { cause?: unknown }).cause;\n const causeMessage = cause instanceof Error ? cause.message : undefined;\n const causeStack = cause instanceof Error ? cause.stack : undefined;\n this.logger.error(causeMessage ?? exception.message, causeStack ?? exception.stack);\n if (cause && cause !== exception) {\n this.logger.error(`Wrapped by: ${exception.message}`);\n }\n return throwError(() =>\n this.toProblemPayload(\n {\n type: 'about:blank',\n detail: causeMessage ?? exception.message,\n errors: [],\n },\n HttpStatus.INTERNAL_SERVER_ERROR,\n ),\n );\n }\n\n this.logger.error(`Unhandled non-error exception: ${JSON.stringify(exception)}`);\n return throwError(() =>\n this.toProblemPayload(\n {\n type: 'about:blank',\n detail: 'An unexpected error occurred',\n errors: [],\n },\n HttpStatus.INTERNAL_SERVER_ERROR,\n ),\n );\n }\n\n private toProblemPayload(response: unknown, status: number): ProblemPayload {\n if (typeof response === 'string') {\n return {\n type: 'about:blank',\n detail: response,\n message: response,\n errors: [],\n status,\n statusCode: status,\n };\n }\n\n const obj = (response ?? {}) as Record<string, unknown>;\n // Prefer RFC 9457 `detail`, then Nest/@nestjs-common's `message` (string or class-validator array),\n // so exceptions thrown as `@nestjs/common` errors still surface their real message across NATS.\n const detail =\n typeof obj.detail === 'string'\n ? obj.detail\n : typeof obj.message === 'string'\n ? obj.message\n : Array.isArray(obj.message)\n ? obj.message.join(', ')\n : 'Request failed';\n return {\n type: typeof obj.type === 'string' ? obj.type : 'about:blank',\n label: typeof obj.label === 'string' ? obj.label : undefined,\n detail,\n message: detail,\n errors: Array.isArray(obj.errors) ? (obj.errors as FieldError[]) : [],\n status,\n statusCode: status,\n };\n }\n\n private isHttpException(error: unknown): error is HttpException {\n return (\n error instanceof Error &&\n typeof (error as { getStatus?: unknown }).getStatus === 'function' &&\n typeof (error as { getResponse?: unknown }).getResponse === 'function'\n );\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ConflictException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Conflict', HttpStatus.CONFLICT);\n }\n}\n","import { HttpException, HttpStatus } from '@nestjs/common';\nimport type { FieldError } from '../types/error-response.types';\n\n// Re-export FieldError for backwards compatibility\nexport type { FieldError } from '../types/error-response.types';\n\nexport interface ProblemOptions {\n type?: string;\n label?: string;\n detail?: string;\n errors?: FieldError[];\n}\n\nexport abstract class HttpProblemException extends HttpException {\n constructor(detailOrOptions: string | ProblemOptions, httpStatus: HttpStatus) {\n const options = typeof detailOrOptions === 'string' ? { detail: detailOrOptions } : detailOrOptions;\n\n super(\n {\n type: options.type ?? 'about:blank',\n label: options.label,\n detail: options.detail,\n errors: options.errors ?? [],\n },\n httpStatus,\n );\n }\n}\n","import { ConflictException } from '../exceptions/conflict.exception';\n\nconst PG_UNIQUE_VIOLATION = '23505';\n\nexport type PgErrorShape = {\n code?: string;\n message?: string;\n constraint?: string;\n table?: string;\n schema?: string;\n column?: string;\n detail?: string;\n hint?: string;\n};\n\n// Returns a ConflictException for a Postgres unique-violation error, otherwise undefined.\nexport function tryTranslatePgError(error: unknown): ConflictException | undefined {\n const pgError = findPgError(error);\n if (!pgError) return undefined;\n const { code, constraint, table, detail } = pgError;\n if (code !== PG_UNIQUE_VIOLATION) return undefined;\n return new ConflictException({\n label: 'Duplicate Entry',\n detail: detail?.trim() || 'A record with these values already exists.',\n errors: [],\n ...(constraint || table ? { meta: { constraint, table } } : {}),\n });\n}\n\n// Walks up to N levels of `.cause` looking for a pg-shaped error (has SQLSTATE `code`), capping depth.\nexport function findPgError(error: unknown, depth = 0): PgErrorShape | undefined {\n if (!error || typeof error !== 'object' || depth > 5) return undefined;\n const candidate = error as PgErrorShape & { cause?: unknown };\n if (typeof candidate.code === 'string') return candidate;\n return findPgError(candidate.cause, depth + 1);\n}\n","import { createParamDecorator, type ExecutionContext, InternalServerErrorException } from '@nestjs/common';\nimport { NatsContext } from '@nestjs/microservices';\nimport { parseNatsHeaders } from '../nats-context';\n\n// Extracts parsed NatsContext from NATS message headers\nexport const RpcNatsHeaders = createParamDecorator((_data: unknown, ctx: ExecutionContext) => {\n const rpcCtx = ctx.switchToRpc().getContext<NatsContext>();\n return parseNatsHeaders(rpcCtx.getHeaders());\n});\n\n// Extracts siteId from NATS headers — throws if missing or empty\nexport const RpcSiteId = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {\n const rpcCtx = ctx.switchToRpc().getContext<NatsContext>();\n const headers = parseNatsHeaders(rpcCtx.getHeaders());\n if (!headers?.siteId) throw new InternalServerErrorException('Missing siteId in NATS headers.');\n return headers.siteId;\n});\n\n// Extracts siteCurrencyCode from NATS headers — throws if missing or empty\nexport const RpcSiteCurrencyCode = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {\n const rpcCtx = ctx.switchToRpc().getContext<NatsContext>();\n const headers = parseNatsHeaders(rpcCtx.getHeaders());\n if (!headers?.siteCurrencyCode) throw new InternalServerErrorException('Missing siteCurrencyCode in NATS headers.');\n return headers.siteCurrencyCode;\n});\n","export interface NatsHeaders {\n orgId: string;\n userId: string;\n siteId: string;\n legalEntityId: string;\n siteGroupId: string;\n siteTimezone: string;\n siteCurrencyCode: string;\n}\n\n// Header keys for NATS context transport\nexport const NATS_HEADER_KEYS = {\n ORG_ID: 'x-org-id',\n USER_ID: 'x-user-id',\n SITE_ID: 'x-site-id',\n LE_ID: 'x-le-id',\n SITE_GROUP_ID: 'x-sg-id',\n SITE_TIMEZONE: 'x-site-timezone',\n SITE_CURRENCY_CODE: 'x-site-currency-code',\n} as const;\n\n// Reads a header value from either a plain object or a NATS MsgHdrsImpl\nfunction getHeader(headers: unknown, key: string): string | undefined {\n if (!headers) return undefined;\n // MsgHdrsImpl uses .get(), plain objects use bracket access\n if (typeof (headers as { get?: unknown }).get === 'function') {\n const val = (headers as { get(key: string): string[] }).get(key);\n return Array.isArray(val) ? val[0] : (val as string | undefined);\n }\n return (headers as Record<string, string>)[key];\n}\n\n// Parses NATS message headers into a NatsHeaders object — siteId is optional (empty for org-level contexts)\nexport function parseNatsHeaders(headers: unknown): NatsHeaders | null {\n if (!headers) return null;\n\n const orgId = getHeader(headers, NATS_HEADER_KEYS.ORG_ID);\n const userId = getHeader(headers, NATS_HEADER_KEYS.USER_ID);\n\n if (!orgId || !userId) return null;\n\n return {\n orgId,\n userId,\n siteId: getHeader(headers, NATS_HEADER_KEYS.SITE_ID) || '',\n legalEntityId: getHeader(headers, NATS_HEADER_KEYS.LE_ID) || '',\n siteGroupId: getHeader(headers, NATS_HEADER_KEYS.SITE_GROUP_ID) || '',\n siteTimezone: getHeader(headers, NATS_HEADER_KEYS.SITE_TIMEZONE) || 'UTC',\n siteCurrencyCode: getHeader(headers, NATS_HEADER_KEYS.SITE_CURRENCY_CODE) || '',\n };\n}\n","import { type DynamicModule, Global, Logger, Module, type OnModuleDestroy, type Provider } from '@nestjs/common';\nimport { ConfigModule, ConfigService } from '@nestjs/config';\nimport type { ClientProxy } from '@nestjs/microservices';\nimport { ClientProxyFactory, Transport } from '@nestjs/microservices';\nimport { NATS_CONTEXT_RESOLVER, NATS_MODULE_OPTIONS } from './constants';\nimport type {\n NatsMicroserviceModuleAsyncOptions,\n NatsModuleBaseOptions,\n NatsRootModuleAsyncOptions,\n NatsRootModuleOptions,\n} from './nats-client.interfaces';\nimport { NATS_CLIENTS, NatsClientService } from './nats-client.service';\nimport { NATS_MS_CLIENTS, NatsMicroserviceClientService } from './nats-microservice-client.service';\n\nconst NATS_MS_OPTIONS = Symbol('NATS_MS_OPTIONS');\n\n@Global()\n@Module({})\nexport class NatsClientModule implements OnModuleDestroy {\n private static readonly logger = new Logger(NatsClientModule.name);\n private static allClients: ClientProxy[] = [];\n\n async onModuleDestroy() {\n await Promise.all(NatsClientModule.allClients.map((c) => c.close()));\n NatsClientModule.allClients = [];\n }\n\n // Builds a Map of named NATS ClientProxy instances\n private static buildClients(options: NatsModuleBaseOptions, natsUrl: string): Map<string, ClientProxy> {\n const clients = new Map<string, ClientProxy>();\n\n for (const svc of options.services) {\n const proxy = ClientProxyFactory.create({\n transport: Transport.NATS,\n options: { servers: [natsUrl] },\n });\n clients.set(svc.name, proxy);\n NatsClientModule.allClients.push(proxy);\n NatsClientModule.logger.log(`Registered NATS client: ${svc.name} → ${natsUrl}`);\n }\n\n return clients;\n }\n\n // Gateway mode — request-scoped, resolves context from sessionInfo via callback\n static forRoot(asyncOptions: NatsRootModuleAsyncOptions): DynamicModule {\n const optionsProvider: Provider = {\n provide: NATS_MODULE_OPTIONS,\n useFactory: asyncOptions.useFactory,\n inject: asyncOptions.inject || [],\n };\n\n const resolverProvider: Provider = {\n provide: NATS_CONTEXT_RESOLVER,\n useFactory: (options: NatsRootModuleOptions) => options.contextResolver,\n inject: [NATS_MODULE_OPTIONS],\n };\n\n const clientsProvider: Provider = {\n provide: NATS_CLIENTS,\n useFactory: (options: NatsRootModuleOptions, config: ConfigService): Map<string, ClientProxy> => {\n const natsUrl = options.natsUrl ?? config.get<string>('NATS_URL', 'nats://localhost:4222');\n return NatsClientModule.buildClients(options, natsUrl);\n },\n inject: [NATS_MODULE_OPTIONS, ConfigService],\n };\n\n return {\n module: NatsClientModule,\n imports: [ConfigModule, ...(asyncOptions.imports ?? [])],\n providers: [optionsProvider, resolverProvider, clientsProvider, NatsClientService],\n exports: [NatsClientService],\n };\n }\n\n // Microservice mode — singleton, forwards context from incoming NATS payload\n static forMicroservice(asyncOptions: NatsMicroserviceModuleAsyncOptions): DynamicModule {\n const optionsProvider: Provider = {\n provide: NATS_MS_OPTIONS,\n useFactory: asyncOptions.useFactory,\n inject: asyncOptions.inject || [],\n };\n\n const clientsProvider: Provider = {\n provide: NATS_MS_CLIENTS,\n useFactory: (options: NatsModuleBaseOptions, config: ConfigService): Map<string, ClientProxy> => {\n const natsUrl = options.natsUrl ?? config.get<string>('NATS_URL', 'nats://localhost:4222');\n return NatsClientModule.buildClients(options, natsUrl);\n },\n inject: [NATS_MS_OPTIONS, ConfigService],\n };\n\n return {\n module: NatsClientModule,\n imports: [ConfigModule, ...(asyncOptions.imports ?? [])],\n providers: [optionsProvider, clientsProvider, NatsMicroserviceClientService],\n exports: [NatsMicroserviceClientService],\n };\n }\n}\n","export const NATS_MODULE_OPTIONS = Symbol('NATS_MODULE_OPTIONS');\nexport const NATS_CONTEXT_RESOLVER = Symbol('NATS_CONTEXT_RESOLVER');\n","// Pulls the fastify module augmentation into this entry's dts graph — tsup builds each entry in isolation\nimport '../types/fastify-augmentation';\nimport { Inject, Injectable, Scope } from '@nestjs/common';\nimport { REQUEST } from '@nestjs/core';\nimport type { ClientProxy } from '@nestjs/microservices';\nimport { NatsRecordBuilder } from '@nestjs/microservices';\nimport type { FastifyRequest } from 'fastify';\nimport { headers as natsHeaders } from 'nats';\nimport { resolveInjectedRequest } from '../context/resolve-request';\nimport { NATS_CONTEXT_RESOLVER } from './constants';\nimport type { ContextResolverFn } from './nats-client.interfaces';\nimport { NATS_HEADER_KEYS, type NatsHeaders } from './nats-context';\n\nexport const NATS_CLIENTS = Symbol('NATS_CLIENTS');\n\n@Injectable({ scope: Scope.REQUEST })\nexport class NatsClientService {\n private cachedContext: NatsHeaders | null = null;\n\n constructor(\n @Inject(REQUEST) private readonly injectedRequest: FastifyRequest,\n @Inject(NATS_CONTEXT_RESOLVER) private readonly contextResolver: ContextResolverFn,\n @Inject(NATS_CLIENTS) private readonly clients: Map<string, ClientProxy>,\n ) {}\n\n // Unwraps the GraphQL { req, reply } context wrapper so sessionInfo is visible across both transports\n private get request(): FastifyRequest {\n return resolveInjectedRequest(this.injectedRequest);\n }\n\n // Sends a message to a named microservice with NatsHeaders as NATS headers\n async send<T>(service: string, cmd: string, data?: object): Promise<T> {\n const client = this.clients.get(service);\n if (!client) {\n throw new Error(\n `NATS service \"${service}\" is not registered. Available: [${[...this.clients.keys()].join(', ')}]`,\n );\n }\n\n if (!this.cachedContext) {\n const sessionInfo = this.request.sessionInfo;\n if (!sessionInfo) {\n throw new Error('No sessionInfo on request — is the auth guard active?');\n }\n this.cachedContext = await this.contextResolver(sessionInfo);\n }\n\n const headers = contextToHeaders(this.cachedContext);\n const record = new NatsRecordBuilder(data ?? {}).setHeaders(headers).build();\n\n return client.send<T>({ cmd }, record).toPromise() as Promise<T>;\n }\n}\n\n// Converts NatsHeaders to a NATS MsgHdrs object for NATS transport\nfunction contextToHeaders(ctx: NatsHeaders): import('nats').MsgHdrs {\n const hdrs = natsHeaders();\n hdrs.set(NATS_HEADER_KEYS.ORG_ID, ctx.orgId);\n hdrs.set(NATS_HEADER_KEYS.USER_ID, ctx.userId);\n if (ctx.siteId) hdrs.set(NATS_HEADER_KEYS.SITE_ID, ctx.siteId);\n if (ctx.legalEntityId) hdrs.set(NATS_HEADER_KEYS.LE_ID, ctx.legalEntityId);\n if (ctx.siteGroupId) hdrs.set(NATS_HEADER_KEYS.SITE_GROUP_ID, ctx.siteGroupId);\n if (ctx.siteTimezone) hdrs.set(NATS_HEADER_KEYS.SITE_TIMEZONE, ctx.siteTimezone);\n if (ctx.siteCurrencyCode) hdrs.set(NATS_HEADER_KEYS.SITE_CURRENCY_CODE, ctx.siteCurrencyCode);\n return hdrs;\n}\n","import type { FastifyRequest } from 'fastify';\n\n// Unwraps the @Inject(REQUEST) value to the real Fastify request (GraphQL injects a { req, reply } context).\nexport function resolveInjectedRequest(injected: FastifyRequest): FastifyRequest {\n const candidate = injected as unknown as { headers?: unknown; req?: FastifyRequest };\n if (candidate && candidate.headers === undefined && candidate.req) {\n return candidate.req;\n }\n return injected;\n}\n","import { Inject, Injectable } from '@nestjs/common';\nimport type { ClientProxy } from '@nestjs/microservices';\nimport { NatsRecordBuilder } from '@nestjs/microservices';\nimport { NATS_HEADER_KEYS, type NatsHeaders } from './nats-context';\n\nexport const NATS_MS_CLIENTS = Symbol('NATS_MS_CLIENTS');\n\n@Injectable()\nexport class NatsMicroserviceClientService {\n constructor(@Inject(NATS_MS_CLIENTS) private readonly clients: Map<string, ClientProxy>) {}\n\n // Forwards a message to another microservice with NatsHeaders\n async send<T>(service: string, cmd: string, natsHeaders: NatsHeaders, data?: object): Promise<T> {\n const client = this.clients.get(service);\n if (!client) {\n throw new Error(\n `NATS service \"${service}\" is not registered. Available: [${[...this.clients.keys()].join(', ')}]`,\n );\n }\n\n const headers: Record<string, string> = {\n [NATS_HEADER_KEYS.ORG_ID]: natsHeaders.orgId,\n [NATS_HEADER_KEYS.USER_ID]: natsHeaders.userId,\n [NATS_HEADER_KEYS.SITE_ID]: natsHeaders.siteId,\n [NATS_HEADER_KEYS.SITE_TIMEZONE]: natsHeaders.siteTimezone,\n };\n\n const record = new NatsRecordBuilder(data ?? {}).setHeaders(headers).build();\n return client.send<T>({ cmd }, record).toPromise() as Promise<T>;\n }\n}\n"],"mappings":";;;;AAAA,SAA6BA,OAA2BC,cAAAA,aAAYC,cAAc;AAClF,SAASC,oBAAoB;AAC7B,SAA0BC,kBAAkB;;;ACF5C,SAASC,kBAAkB;;;ACA3B,SAASC,qBAAiC;AAanC,IAAeC,uBAAf,cAA4CC,cAAAA;EAbnD,OAamDA;;;EACjD,YAAYC,iBAA0CC,YAAwB;AAC5E,UAAMC,UAAU,OAAOF,oBAAoB,WAAW;MAAEG,QAAQH;IAAgB,IAAIA;AAEpF,UACE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WAAW,CAAA;;MACpDE,WAAW;QAAChB;QAAiBK;QAAkBG;QAAiBS;;MAChEC,SAAS;QAACD;;IACZ;EACF;;EAGA,OAAOE,gBAAgBpB,cAAiE;AACtF,UAAMC,kBAA4B;MAChCC,SAASjC;MACTmC,YAAYJ,aAAaI;MACzBC,QAAQL,aAAaK,UAAU,CAAA;IACjC;AAEA,UAAMI,kBAA4B;MAChCP,SAASmB;MACTjB,YAAY,wBAACrB,SAAgC4B,WAAAA;AAC3C,cAAM3B,UAAUD,QAAQC,WAAW2B,OAAOC,IAAY,YAAY,uBAAA;AAClE,eAAOzC,kBAAiBW,aAAaC,SAASC,OAAAA;MAChD,GAHY;MAIZqB,QAAQ;QAACpC;QAAiB4C;;IAC5B;AAEA,WAAO;MACLC,QAAQ3C;MACR4C,SAAS;QAACC;WAAkBhB,aAAae,WAAW,CAAA;;MACpDE,WAAW;QAAChB;QAAiBQ;QAAiBa;;MAC9CH,SAAS;QAACG;;IACZ;EACF;AACF;;;;;","names":["Catch","HttpStatus","Logger","RpcException","throwError","HttpStatus","HttpException","HttpProblemException","HttpException","detailOrOptions","httpStatus","options","detail","type","label","errors","ConflictException","HttpProblemException","detailOrOptions","HttpStatus","CONFLICT","PG_UNIQUE_VIOLATION","tryTranslatePgError","error","pgError","findPgError","undefined","code","constraint","table","detail","ConflictException","label","trim","errors","meta","depth","candidate","cause","RpcProblemExceptionFilter","logger","Logger","name","catch","exception","_host","translatedPgError","tryTranslatePgError","RpcException","throwError","getError","isHttpException","status","getStatus","response","getResponse","payload","toProblemPayload","log","HttpStatus","INTERNAL_SERVER_ERROR","error","warn","call","detail","Error","cause","causeMessage","message","undefined","causeStack","stack","type","errors","JSON","stringify","statusCode","obj","Array","isArray","join","label","createParamDecorator","InternalServerErrorException","NATS_HEADER_KEYS","ORG_ID","USER_ID","SITE_ID","LE_ID","SITE_GROUP_ID","SITE_TIMEZONE","SITE_CURRENCY_CODE","getHeader","headers","key","undefined","get","val","Array","isArray","parseNatsHeaders","orgId","userId","siteId","legalEntityId","siteGroupId","siteTimezone","siteCurrencyCode","RpcNatsHeaders","createParamDecorator","_data","ctx","rpcCtx","switchToRpc","getContext","parseNatsHeaders","getHeaders","RpcSiteId","headers","siteId","InternalServerErrorException","RpcSiteCurrencyCode","siteCurrencyCode","Global","Logger","Module","ConfigModule","ConfigService","ClientProxyFactory","Transport","NATS_MODULE_OPTIONS","Symbol","NATS_CONTEXT_RESOLVER","Inject","Injectable","Scope","REQUEST","NatsRecordBuilder","headers","natsHeaders","resolveInjectedRequest","injected","candidate","headers","undefined","req","NATS_CLIENTS","Symbol","NatsClientService","cachedContext","injectedRequest","contextResolver","clients","request","resolveInjectedRequest","send","service","cmd","data","client","get","Error","keys","join","sessionInfo","headers","contextToHeaders","record","NatsRecordBuilder","setHeaders","build","toPromise","scope","Scope","REQUEST","ctx","hdrs","natsHeaders","set","NATS_HEADER_KEYS","ORG_ID","orgId","USER_ID","userId","siteId","SITE_ID","legalEntityId","LE_ID","siteGroupId","SITE_GROUP_ID","siteTimezone","SITE_TIMEZONE","siteCurrencyCode","SITE_CURRENCY_CODE","Inject","Injectable","NatsRecordBuilder","NATS_MS_CLIENTS","Symbol","NatsMicroserviceClientService","clients","send","service","cmd","natsHeaders","data","client","get","Error","keys","join","headers","NATS_HEADER_KEYS","ORG_ID","orgId","USER_ID","userId","SITE_ID","siteId","SITE_TIMEZONE","siteTimezone","record","NatsRecordBuilder","setHeaders","build","toPromise","NATS_MS_OPTIONS","Symbol","NatsClientModule","logger","Logger","name","allClients","onModuleDestroy","Promise","all","map","c","close","buildClients","options","natsUrl","clients","Map","svc","services","proxy","ClientProxyFactory","create","transport","Transport","NATS","servers","set","push","log","forRoot","asyncOptions","optionsProvider","provide","NATS_MODULE_OPTIONS","useFactory","inject","resolverProvider","NATS_CONTEXT_RESOLVER","contextResolver","clientsProvider","NATS_CLIENTS","config","get","ConfigService","module","imports","ConfigModule","providers","NatsClientService","exports","forMicroservice","NATS_MS_CLIENTS","NatsMicroserviceClientService"]}
|
package/dist/root.cjs
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/root/index.ts
|
|
22
|
+
var root_exports = {};
|
|
23
|
+
__export(root_exports, {
|
|
24
|
+
RootModule: () => RootModule
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(root_exports);
|
|
27
|
+
|
|
28
|
+
// src/root/root.module.ts
|
|
29
|
+
var import_common7 = require("@nestjs/common");
|
|
30
|
+
|
|
31
|
+
// src/root/controllers/app.controller.ts
|
|
32
|
+
var import_common4 = require("@nestjs/common");
|
|
33
|
+
var import_swagger2 = require("@nestjs/swagger");
|
|
34
|
+
|
|
35
|
+
// src/auth/decorators/public.decorator.ts
|
|
36
|
+
var import_common = require("@nestjs/common");
|
|
37
|
+
var Public = /* @__PURE__ */ __name(() => (0, import_common.SetMetadata)("isPublic", true), "Public");
|
|
38
|
+
|
|
39
|
+
// src/root/docs/app.docs.ts
|
|
40
|
+
var import_common2 = require("@nestjs/common");
|
|
41
|
+
var import_swagger = require("@nestjs/swagger");
|
|
42
|
+
function ApiHealthCheck() {
|
|
43
|
+
return (0, import_common2.applyDecorators)((0, import_swagger.ApiOperation)({
|
|
44
|
+
summary: "Health check endpoint"
|
|
45
|
+
}), (0, import_swagger.ApiResponse)({
|
|
46
|
+
status: 200,
|
|
47
|
+
description: "Returns a welcome message indicating the API is running",
|
|
48
|
+
type: String
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
__name(ApiHealthCheck, "ApiHealthCheck");
|
|
52
|
+
|
|
53
|
+
// src/root/services/app.service.ts
|
|
54
|
+
var import_common3 = require("@nestjs/common");
|
|
55
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
56
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
57
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
58
|
+
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;
|
|
59
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
60
|
+
}
|
|
61
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
62
|
+
var AppService = class {
|
|
63
|
+
static {
|
|
64
|
+
__name(this, "AppService");
|
|
65
|
+
}
|
|
66
|
+
// Returns the API welcome message
|
|
67
|
+
getHello() {
|
|
68
|
+
return `Hello World!`;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
AppService = _ts_decorate([
|
|
72
|
+
(0, import_common3.Injectable)()
|
|
73
|
+
], AppService);
|
|
74
|
+
|
|
75
|
+
// src/root/controllers/app.controller.ts
|
|
76
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
77
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
78
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
79
|
+
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;
|
|
80
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
81
|
+
}
|
|
82
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
83
|
+
function _ts_metadata(k, v) {
|
|
84
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
85
|
+
}
|
|
86
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
87
|
+
var AppController = class {
|
|
88
|
+
static {
|
|
89
|
+
__name(this, "AppController");
|
|
90
|
+
}
|
|
91
|
+
appService;
|
|
92
|
+
constructor(appService) {
|
|
93
|
+
this.appService = appService;
|
|
94
|
+
}
|
|
95
|
+
// Returns a welcome message indicating the API is running
|
|
96
|
+
getHello() {
|
|
97
|
+
return this.appService.getHello();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
_ts_decorate2([
|
|
101
|
+
(0, import_common4.Get)(),
|
|
102
|
+
Public(),
|
|
103
|
+
ApiHealthCheck(),
|
|
104
|
+
_ts_metadata("design:type", Function),
|
|
105
|
+
_ts_metadata("design:paramtypes", []),
|
|
106
|
+
_ts_metadata("design:returntype", String)
|
|
107
|
+
], AppController.prototype, "getHello", null);
|
|
108
|
+
AppController = _ts_decorate2([
|
|
109
|
+
(0, import_swagger2.ApiTags)("Health"),
|
|
110
|
+
(0, import_common4.Controller)(),
|
|
111
|
+
_ts_metadata("design:type", Function),
|
|
112
|
+
_ts_metadata("design:paramtypes", [
|
|
113
|
+
typeof AppService === "undefined" ? Object : AppService
|
|
114
|
+
])
|
|
115
|
+
], AppController);
|
|
116
|
+
|
|
117
|
+
// src/root/controllers/csrf.controller.ts
|
|
118
|
+
var import_common6 = require("@nestjs/common");
|
|
119
|
+
var import_swagger4 = require("@nestjs/swagger");
|
|
120
|
+
|
|
121
|
+
// src/root/docs/csrf.docs.ts
|
|
122
|
+
var import_common5 = require("@nestjs/common");
|
|
123
|
+
var import_swagger3 = require("@nestjs/swagger");
|
|
124
|
+
function ApiGetCsrfToken() {
|
|
125
|
+
return (0, import_common5.applyDecorators)((0, import_swagger3.ApiOperation)({
|
|
126
|
+
summary: "Get CSRF token",
|
|
127
|
+
description: "Generates and returns a CSRF token that must be included in all state-changing requests (POST, PUT, PATCH, DELETE). The token should be sent in the X-CSRF-Token header."
|
|
128
|
+
}), (0, import_swagger3.ApiResponse)({
|
|
129
|
+
status: 200,
|
|
130
|
+
description: "CSRF token generated successfully",
|
|
131
|
+
schema: {
|
|
132
|
+
type: "object",
|
|
133
|
+
properties: {
|
|
134
|
+
csrfToken: {
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "The CSRF token to use in subsequent requests",
|
|
137
|
+
example: "abc123xyz789"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
required: [
|
|
141
|
+
"csrfToken"
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
__name(ApiGetCsrfToken, "ApiGetCsrfToken");
|
|
147
|
+
|
|
148
|
+
// src/root/controllers/csrf.controller.ts
|
|
149
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
150
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
151
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
152
|
+
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;
|
|
153
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
154
|
+
}
|
|
155
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
156
|
+
function _ts_metadata2(k, v) {
|
|
157
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
158
|
+
}
|
|
159
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
160
|
+
function _ts_param(paramIndex, decorator) {
|
|
161
|
+
return function(target, key) {
|
|
162
|
+
decorator(target, key, paramIndex);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
__name(_ts_param, "_ts_param");
|
|
166
|
+
var CsrfController = class {
|
|
167
|
+
static {
|
|
168
|
+
__name(this, "CsrfController");
|
|
169
|
+
}
|
|
170
|
+
// Generates a CSRF token via Fastify's csrf-protection plugin
|
|
171
|
+
getToken(reply) {
|
|
172
|
+
const csrfToken = reply.generateCsrf();
|
|
173
|
+
return {
|
|
174
|
+
csrfToken
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
_ts_decorate3([
|
|
179
|
+
(0, import_common6.Get)("token"),
|
|
180
|
+
Public(),
|
|
181
|
+
(0, import_common6.HttpCode)(import_common6.HttpStatus.OK),
|
|
182
|
+
ApiGetCsrfToken(),
|
|
183
|
+
_ts_param(0, (0, import_common6.Res)({
|
|
184
|
+
passthrough: true
|
|
185
|
+
})),
|
|
186
|
+
_ts_metadata2("design:type", Function),
|
|
187
|
+
_ts_metadata2("design:paramtypes", [
|
|
188
|
+
typeof FastifyReply === "undefined" ? Object : FastifyReply
|
|
189
|
+
]),
|
|
190
|
+
_ts_metadata2("design:returntype", Object)
|
|
191
|
+
], CsrfController.prototype, "getToken", null);
|
|
192
|
+
CsrfController = _ts_decorate3([
|
|
193
|
+
(0, import_swagger4.ApiTags)("CSRF"),
|
|
194
|
+
(0, import_common6.Controller)("csrf")
|
|
195
|
+
], CsrfController);
|
|
196
|
+
|
|
197
|
+
// src/root/root.module.ts
|
|
198
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
199
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
200
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
201
|
+
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;
|
|
202
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
203
|
+
}
|
|
204
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
205
|
+
var RootModule = class {
|
|
206
|
+
static {
|
|
207
|
+
__name(this, "RootModule");
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
RootModule = _ts_decorate4([
|
|
211
|
+
(0, import_common7.Module)({
|
|
212
|
+
controllers: [
|
|
213
|
+
AppController,
|
|
214
|
+
CsrfController
|
|
215
|
+
],
|
|
216
|
+
providers: [
|
|
217
|
+
AppService
|
|
218
|
+
]
|
|
219
|
+
})
|
|
220
|
+
], RootModule);
|
|
221
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
+
0 && (module.exports = {
|
|
223
|
+
RootModule
|
|
224
|
+
});
|
|
225
|
+
//# sourceMappingURL=root.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/root/index.ts","../src/root/root.module.ts","../src/root/controllers/app.controller.ts","../src/auth/decorators/public.decorator.ts","../src/root/docs/app.docs.ts","../src/root/services/app.service.ts","../src/root/controllers/csrf.controller.ts","../src/root/docs/csrf.docs.ts"],"sourcesContent":["export { RootModule } from './root.module';\n","import { Module } from '@nestjs/common';\nimport { AppController } from './controllers/app.controller';\nimport { CsrfController } from './controllers/csrf.controller';\nimport { AppService } from './services/app.service';\n\n@Module({\n controllers: [AppController, CsrfController],\n providers: [AppService],\n})\nexport class RootModule {}\n","import { Controller, Get } from '@nestjs/common';\nimport { ApiTags } from '@nestjs/swagger';\nimport { Public } from '../../auth/decorators/public.decorator';\nimport { ApiHealthCheck } from '../docs/app.docs';\nimport { AppService } from '../services/app.service';\n\n@ApiTags('Health')\n@Controller()\nexport class AppController {\n constructor(private readonly appService: AppService) {}\n\n // Returns a welcome message indicating the API is running\n @Get()\n @Public()\n @ApiHealthCheck()\n getHello(): string {\n return this.appService.getHello();\n }\n}\n","import { SetMetadata } from '@nestjs/common';\n\nexport const Public = () => SetMetadata('isPublic', true);\n","import { applyDecorators } from '@nestjs/common';\nimport { ApiOperation, ApiResponse } from '@nestjs/swagger';\n\nexport function ApiHealthCheck() {\n return applyDecorators(\n ApiOperation({ summary: 'Health check endpoint' }),\n ApiResponse({\n status: 200,\n description: 'Returns a welcome message indicating the API is running',\n type: String,\n }),\n );\n}\n","import { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class AppService {\n // Returns the API welcome message\n getHello(): string {\n return `Hello World!`;\n }\n}\n","import { Controller, Get, HttpCode, HttpStatus, Res } from '@nestjs/common';\nimport { ApiTags } from '@nestjs/swagger';\nimport type { FastifyReply } from 'fastify';\nimport { Public } from '../../auth/decorators/public.decorator';\nimport { ApiGetCsrfToken } from '../docs/csrf.docs';\n\n// Type augmentation for @fastify/csrf-protection — added by the consuming server at runtime\ntype FastifyReplyWithCsrf = FastifyReply & { generateCsrf(): string };\n\n@ApiTags('CSRF')\n@Controller('csrf')\nexport class CsrfController {\n // Generates a CSRF token via Fastify's csrf-protection plugin\n @Get('token')\n @Public()\n @HttpCode(HttpStatus.OK)\n @ApiGetCsrfToken()\n getToken(@Res({ passthrough: true }) reply: FastifyReply): { csrfToken: string } {\n const csrfToken = (reply as FastifyReplyWithCsrf).generateCsrf();\n return { csrfToken };\n }\n}\n","import { applyDecorators } from '@nestjs/common';\nimport { ApiOperation, ApiResponse } from '@nestjs/swagger';\n\nexport function ApiGetCsrfToken() {\n return applyDecorators(\n ApiOperation({\n summary: 'Get CSRF token',\n description:\n 'Generates and returns a CSRF token that must be included in all state-changing requests (POST, PUT, PATCH, DELETE). The token should be sent in the X-CSRF-Token header.',\n }),\n ApiResponse({\n status: 200,\n description: 'CSRF token generated successfully',\n schema: {\n type: 'object',\n properties: {\n csrfToken: {\n type: 'string',\n description: 'The CSRF token to use in subsequent requests',\n example: 'abc123xyz789',\n },\n },\n required: ['csrfToken'],\n },\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,IAAAA,iBAAuB;;;ACAvB,IAAAC,iBAAgC;AAChC,IAAAC,kBAAwB;;;ACDxB,oBAA4B;AAErB,IAAMC,SAAS,iCAAMC,2BAAY,YAAY,IAAA,GAA9B;;;ACFtB,IAAAC,iBAAgC;AAChC,qBAA0C;AAEnC,SAASC,iBAAAA;AACd,aAAOC,oCACLC,6BAAa;IAAEC,SAAS;EAAwB,CAAA,OAChDC,4BAAY;IACVC,QAAQ;IACRC,aAAa;IACbC,MAAMC;EACR,CAAA,CAAA;AAEJ;AATgBR;;;ACHhB,IAAAS,iBAA2B;;;;;;;;AAGpB,IAAMC,aAAN,MAAMA;SAAAA;;;;EAEXC,WAAmB;AACjB,WAAO;EACT;AACF;;;;;;;;;;;;;;;;;AHAO,IAAMC,gBAAN,MAAMA;SAAAA;;;;EACX,YAA6BC,YAAwB;SAAxBA,aAAAA;EAAyB;;EAMtDC,WAAmB;AACjB,WAAO,KAAKD,WAAWC,SAAQ;EACjC;AACF;;;;;;;;;;;;;;;;;;;AIlBA,IAAAC,iBAA2D;AAC3D,IAAAC,kBAAwB;;;ACDxB,IAAAC,iBAAgC;AAChC,IAAAC,kBAA0C;AAEnC,SAASC,kBAAAA;AACd,aAAOC,oCACLC,8BAAa;IACXC,SAAS;IACTC,aACE;EACJ,CAAA,OACAC,6BAAY;IACVC,QAAQ;IACRF,aAAa;IACbG,QAAQ;MACNC,MAAM;MACNC,YAAY;QACVC,WAAW;UACTF,MAAM;UACNJ,aAAa;UACbO,SAAS;QACX;MACF;MACAC,UAAU;QAAC;;IACb;EACF,CAAA,CAAA;AAEJ;AAvBgBZ;;;;;;;;;;;;;;;;;;;;ADQT,IAAMa,iBAAN,MAAMA;SAAAA;;;;EAMXC,SAAqCC,OAA4C;AAC/E,UAAMC,YAAaD,MAA+BE,aAAY;AAC9D,WAAO;MAAED;IAAU;EACrB;AACF;;;;yDANuBE,EAAAA;;;IAELC,aAAa;;;;;;;;;;;;;;;;;;;;;ALRxB,IAAMC,aAAN,MAAMA;SAAAA;;;AAAY;;;IAHvBC,aAAa;MAACC;MAAeC;;IAC7BC,WAAW;MAACC;;;;","names":["import_common","import_common","import_swagger","Public","SetMetadata","import_common","ApiHealthCheck","applyDecorators","ApiOperation","summary","ApiResponse","status","description","type","String","import_common","AppService","getHello","AppController","appService","getHello","import_common","import_swagger","import_common","import_swagger","ApiGetCsrfToken","applyDecorators","ApiOperation","summary","description","ApiResponse","status","schema","type","properties","csrfToken","example","required","CsrfController","getToken","reply","csrfToken","generateCsrf","OK","passthrough","RootModule","controllers","AppController","CsrfController","providers","AppService"]}
|
package/dist/root.d.cts
ADDED
package/dist/root.d.ts
ADDED
package/dist/root.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/root/root.module.ts
|
|
5
|
+
import { Module } from "@nestjs/common";
|
|
6
|
+
|
|
7
|
+
// src/root/controllers/app.controller.ts
|
|
8
|
+
import { Controller, Get } from "@nestjs/common";
|
|
9
|
+
import { ApiTags } from "@nestjs/swagger";
|
|
10
|
+
|
|
11
|
+
// src/auth/decorators/public.decorator.ts
|
|
12
|
+
import { SetMetadata } from "@nestjs/common";
|
|
13
|
+
var Public = /* @__PURE__ */ __name(() => SetMetadata("isPublic", true), "Public");
|
|
14
|
+
|
|
15
|
+
// src/root/docs/app.docs.ts
|
|
16
|
+
import { applyDecorators } from "@nestjs/common";
|
|
17
|
+
import { ApiOperation, ApiResponse } from "@nestjs/swagger";
|
|
18
|
+
function ApiHealthCheck() {
|
|
19
|
+
return applyDecorators(ApiOperation({
|
|
20
|
+
summary: "Health check endpoint"
|
|
21
|
+
}), ApiResponse({
|
|
22
|
+
status: 200,
|
|
23
|
+
description: "Returns a welcome message indicating the API is running",
|
|
24
|
+
type: String
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
__name(ApiHealthCheck, "ApiHealthCheck");
|
|
28
|
+
|
|
29
|
+
// src/root/services/app.service.ts
|
|
30
|
+
import { Injectable } from "@nestjs/common";
|
|
31
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
32
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
33
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
34
|
+
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;
|
|
35
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
36
|
+
}
|
|
37
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
38
|
+
var AppService = class {
|
|
39
|
+
static {
|
|
40
|
+
__name(this, "AppService");
|
|
41
|
+
}
|
|
42
|
+
// Returns the API welcome message
|
|
43
|
+
getHello() {
|
|
44
|
+
return `Hello World!`;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
AppService = _ts_decorate([
|
|
48
|
+
Injectable()
|
|
49
|
+
], AppService);
|
|
50
|
+
|
|
51
|
+
// src/root/controllers/app.controller.ts
|
|
52
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
53
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
54
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
55
|
+
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;
|
|
56
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
57
|
+
}
|
|
58
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
59
|
+
function _ts_metadata(k, v) {
|
|
60
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
61
|
+
}
|
|
62
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
63
|
+
var AppController = class {
|
|
64
|
+
static {
|
|
65
|
+
__name(this, "AppController");
|
|
66
|
+
}
|
|
67
|
+
appService;
|
|
68
|
+
constructor(appService) {
|
|
69
|
+
this.appService = appService;
|
|
70
|
+
}
|
|
71
|
+
// Returns a welcome message indicating the API is running
|
|
72
|
+
getHello() {
|
|
73
|
+
return this.appService.getHello();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
_ts_decorate2([
|
|
77
|
+
Get(),
|
|
78
|
+
Public(),
|
|
79
|
+
ApiHealthCheck(),
|
|
80
|
+
_ts_metadata("design:type", Function),
|
|
81
|
+
_ts_metadata("design:paramtypes", []),
|
|
82
|
+
_ts_metadata("design:returntype", String)
|
|
83
|
+
], AppController.prototype, "getHello", null);
|
|
84
|
+
AppController = _ts_decorate2([
|
|
85
|
+
ApiTags("Health"),
|
|
86
|
+
Controller(),
|
|
87
|
+
_ts_metadata("design:type", Function),
|
|
88
|
+
_ts_metadata("design:paramtypes", [
|
|
89
|
+
typeof AppService === "undefined" ? Object : AppService
|
|
90
|
+
])
|
|
91
|
+
], AppController);
|
|
92
|
+
|
|
93
|
+
// src/root/controllers/csrf.controller.ts
|
|
94
|
+
import { Controller as Controller2, Get as Get2, HttpCode, HttpStatus, Res } from "@nestjs/common";
|
|
95
|
+
import { ApiTags as ApiTags2 } from "@nestjs/swagger";
|
|
96
|
+
|
|
97
|
+
// src/root/docs/csrf.docs.ts
|
|
98
|
+
import { applyDecorators as applyDecorators2 } from "@nestjs/common";
|
|
99
|
+
import { ApiOperation as ApiOperation2, ApiResponse as ApiResponse2 } from "@nestjs/swagger";
|
|
100
|
+
function ApiGetCsrfToken() {
|
|
101
|
+
return applyDecorators2(ApiOperation2({
|
|
102
|
+
summary: "Get CSRF token",
|
|
103
|
+
description: "Generates and returns a CSRF token that must be included in all state-changing requests (POST, PUT, PATCH, DELETE). The token should be sent in the X-CSRF-Token header."
|
|
104
|
+
}), ApiResponse2({
|
|
105
|
+
status: 200,
|
|
106
|
+
description: "CSRF token generated successfully",
|
|
107
|
+
schema: {
|
|
108
|
+
type: "object",
|
|
109
|
+
properties: {
|
|
110
|
+
csrfToken: {
|
|
111
|
+
type: "string",
|
|
112
|
+
description: "The CSRF token to use in subsequent requests",
|
|
113
|
+
example: "abc123xyz789"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
required: [
|
|
117
|
+
"csrfToken"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
__name(ApiGetCsrfToken, "ApiGetCsrfToken");
|
|
123
|
+
|
|
124
|
+
// src/root/controllers/csrf.controller.ts
|
|
125
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
126
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
127
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
128
|
+
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;
|
|
129
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
130
|
+
}
|
|
131
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
132
|
+
function _ts_metadata2(k, v) {
|
|
133
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
134
|
+
}
|
|
135
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
136
|
+
function _ts_param(paramIndex, decorator) {
|
|
137
|
+
return function(target, key) {
|
|
138
|
+
decorator(target, key, paramIndex);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
__name(_ts_param, "_ts_param");
|
|
142
|
+
var CsrfController = class {
|
|
143
|
+
static {
|
|
144
|
+
__name(this, "CsrfController");
|
|
145
|
+
}
|
|
146
|
+
// Generates a CSRF token via Fastify's csrf-protection plugin
|
|
147
|
+
getToken(reply) {
|
|
148
|
+
const csrfToken = reply.generateCsrf();
|
|
149
|
+
return {
|
|
150
|
+
csrfToken
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
_ts_decorate3([
|
|
155
|
+
Get2("token"),
|
|
156
|
+
Public(),
|
|
157
|
+
HttpCode(HttpStatus.OK),
|
|
158
|
+
ApiGetCsrfToken(),
|
|
159
|
+
_ts_param(0, Res({
|
|
160
|
+
passthrough: true
|
|
161
|
+
})),
|
|
162
|
+
_ts_metadata2("design:type", Function),
|
|
163
|
+
_ts_metadata2("design:paramtypes", [
|
|
164
|
+
typeof FastifyReply === "undefined" ? Object : FastifyReply
|
|
165
|
+
]),
|
|
166
|
+
_ts_metadata2("design:returntype", Object)
|
|
167
|
+
], CsrfController.prototype, "getToken", null);
|
|
168
|
+
CsrfController = _ts_decorate3([
|
|
169
|
+
ApiTags2("CSRF"),
|
|
170
|
+
Controller2("csrf")
|
|
171
|
+
], CsrfController);
|
|
172
|
+
|
|
173
|
+
// src/root/root.module.ts
|
|
174
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
175
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
176
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
177
|
+
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;
|
|
178
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
179
|
+
}
|
|
180
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
181
|
+
var RootModule = class {
|
|
182
|
+
static {
|
|
183
|
+
__name(this, "RootModule");
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
RootModule = _ts_decorate4([
|
|
187
|
+
Module({
|
|
188
|
+
controllers: [
|
|
189
|
+
AppController,
|
|
190
|
+
CsrfController
|
|
191
|
+
],
|
|
192
|
+
providers: [
|
|
193
|
+
AppService
|
|
194
|
+
]
|
|
195
|
+
})
|
|
196
|
+
], RootModule);
|
|
197
|
+
export {
|
|
198
|
+
RootModule
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=root.js.map
|
package/dist/root.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/root/root.module.ts","../src/root/controllers/app.controller.ts","../src/auth/decorators/public.decorator.ts","../src/root/docs/app.docs.ts","../src/root/services/app.service.ts","../src/root/controllers/csrf.controller.ts","../src/root/docs/csrf.docs.ts"],"sourcesContent":["import { Module } from '@nestjs/common';\nimport { AppController } from './controllers/app.controller';\nimport { CsrfController } from './controllers/csrf.controller';\nimport { AppService } from './services/app.service';\n\n@Module({\n controllers: [AppController, CsrfController],\n providers: [AppService],\n})\nexport class RootModule {}\n","import { Controller, Get } from '@nestjs/common';\nimport { ApiTags } from '@nestjs/swagger';\nimport { Public } from '../../auth/decorators/public.decorator';\nimport { ApiHealthCheck } from '../docs/app.docs';\nimport { AppService } from '../services/app.service';\n\n@ApiTags('Health')\n@Controller()\nexport class AppController {\n constructor(private readonly appService: AppService) {}\n\n // Returns a welcome message indicating the API is running\n @Get()\n @Public()\n @ApiHealthCheck()\n getHello(): string {\n return this.appService.getHello();\n }\n}\n","import { SetMetadata } from '@nestjs/common';\n\nexport const Public = () => SetMetadata('isPublic', true);\n","import { applyDecorators } from '@nestjs/common';\nimport { ApiOperation, ApiResponse } from '@nestjs/swagger';\n\nexport function ApiHealthCheck() {\n return applyDecorators(\n ApiOperation({ summary: 'Health check endpoint' }),\n ApiResponse({\n status: 200,\n description: 'Returns a welcome message indicating the API is running',\n type: String,\n }),\n );\n}\n","import { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class AppService {\n // Returns the API welcome message\n getHello(): string {\n return `Hello World!`;\n }\n}\n","import { Controller, Get, HttpCode, HttpStatus, Res } from '@nestjs/common';\nimport { ApiTags } from '@nestjs/swagger';\nimport type { FastifyReply } from 'fastify';\nimport { Public } from '../../auth/decorators/public.decorator';\nimport { ApiGetCsrfToken } from '../docs/csrf.docs';\n\n// Type augmentation for @fastify/csrf-protection — added by the consuming server at runtime\ntype FastifyReplyWithCsrf = FastifyReply & { generateCsrf(): string };\n\n@ApiTags('CSRF')\n@Controller('csrf')\nexport class CsrfController {\n // Generates a CSRF token via Fastify's csrf-protection plugin\n @Get('token')\n @Public()\n @HttpCode(HttpStatus.OK)\n @ApiGetCsrfToken()\n getToken(@Res({ passthrough: true }) reply: FastifyReply): { csrfToken: string } {\n const csrfToken = (reply as FastifyReplyWithCsrf).generateCsrf();\n return { csrfToken };\n }\n}\n","import { applyDecorators } from '@nestjs/common';\nimport { ApiOperation, ApiResponse } from '@nestjs/swagger';\n\nexport function ApiGetCsrfToken() {\n return applyDecorators(\n ApiOperation({\n summary: 'Get CSRF token',\n description:\n 'Generates and returns a CSRF token that must be included in all state-changing requests (POST, PUT, PATCH, DELETE). The token should be sent in the X-CSRF-Token header.',\n }),\n ApiResponse({\n status: 200,\n description: 'CSRF token generated successfully',\n schema: {\n type: 'object',\n properties: {\n csrfToken: {\n type: 'string',\n description: 'The CSRF token to use in subsequent requests',\n example: 'abc123xyz789',\n },\n },\n required: ['csrfToken'],\n },\n }),\n );\n}\n"],"mappings":";;;;AAAA,SAASA,cAAc;;;ACAvB,SAASC,YAAYC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;;;;;;;;;;;;;;;;;;;;ALRxB,IAAMC,aAAN,MAAMA;SAAAA;;;AAAY;;;IAHvBC,aAAa;MAACC;MAAeC;;IAC7BC,WAAW;MAACC;;;;","names":["Module","Controller","Get","ApiTags","SetMetadata","Public","SetMetadata","applyDecorators","ApiOperation","ApiResponse","ApiHealthCheck","applyDecorators","ApiOperation","summary","ApiResponse","status","description","type","String","Injectable","AppService","getHello","AppController","appService","getHello","Controller","Get","HttpCode","HttpStatus","Res","ApiTags","applyDecorators","ApiOperation","ApiResponse","ApiGetCsrfToken","applyDecorators","ApiOperation","summary","description","ApiResponse","status","schema","type","properties","csrfToken","example","required","CsrfController","getToken","reply","csrfToken","generateCsrf","OK","passthrough","RootModule","controllers","AppController","CsrfController","providers","AppService"]}
|