stratal 0.0.16 → 0.0.17

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.
Files changed (145) hide show
  1. package/README.md +4 -0
  2. package/dist/{application-zG8b-pol.d.mts → application-DfPtIzxF.d.mts} +65 -4
  3. package/dist/application-DfPtIzxF.d.mts.map +1 -0
  4. package/dist/{base-email.provider-Cuw4OAB0.mjs → base-email.provider-DypUAfWm.mjs} +1 -1
  5. package/dist/{base-email.provider-Cuw4OAB0.mjs.map → base-email.provider-DypUAfWm.mjs.map} +1 -1
  6. package/dist/bin/cloudflare-workers-loader.mjs +0 -0
  7. package/dist/bin/quarry.mjs +1 -50
  8. package/dist/bin/quarry.mjs.map +1 -1
  9. package/dist/cache/index.d.mts +1 -1
  10. package/dist/cache/index.mjs +10 -11
  11. package/dist/cache/index.mjs.map +1 -1
  12. package/dist/{colors-DJaRDXoS.mjs → colors-Y7WIFXs7.mjs} +1 -1
  13. package/dist/{colors-DJaRDXoS.mjs.map → colors-Y7WIFXs7.mjs.map} +1 -1
  14. package/dist/{command-BvCOD6df.mjs → command-B1CPgsrU.mjs} +6 -3
  15. package/dist/{command-BvCOD6df.mjs.map → command-B1CPgsrU.mjs.map} +1 -1
  16. package/dist/{command-B-QH-Vu3.d.mts → command-TnkPYWta.d.mts} +2 -2
  17. package/dist/{command-B-QH-Vu3.d.mts.map → command-TnkPYWta.d.mts.map} +1 -1
  18. package/dist/config/index.d.mts +2 -2
  19. package/dist/config/index.mjs +10 -11
  20. package/dist/config/index.mjs.map +1 -1
  21. package/dist/consumer-registry-Bymm6ff4.d.mts +142 -0
  22. package/dist/consumer-registry-Bymm6ff4.d.mts.map +1 -0
  23. package/dist/cron/index.d.mts +3 -116
  24. package/dist/cron/index.d.mts.map +1 -1
  25. package/dist/cron/index.mjs +3 -4
  26. package/dist/{cron-manager-DR7fiG6o.mjs → cron-manager-CFBamKKk.mjs} +3 -3
  27. package/dist/{cron-manager-DR7fiG6o.mjs.map → cron-manager-CFBamKKk.mjs.map} +1 -1
  28. package/dist/cron-manager-D7imGwUT.d.mts +117 -0
  29. package/dist/cron-manager-D7imGwUT.d.mts.map +1 -0
  30. package/dist/di/index.d.mts +1 -1
  31. package/dist/di/index.mjs +2 -3
  32. package/dist/email/index.d.mts +3 -3
  33. package/dist/email/index.mjs +16 -17
  34. package/dist/email/index.mjs.map +1 -1
  35. package/dist/errors/index.d.mts +1 -1
  36. package/dist/errors/index.mjs +2 -3
  37. package/dist/{errors-CtCi1wn6.mjs → errors-DSKapqD8.mjs} +4 -4
  38. package/dist/{errors-CtCi1wn6.mjs.map → errors-DSKapqD8.mjs.map} +1 -1
  39. package/dist/{errors-H3TZnVeX.mjs → errors-DuAR5Wke.mjs} +2 -2
  40. package/dist/{errors-H3TZnVeX.mjs.map → errors-DuAR5Wke.mjs.map} +1 -1
  41. package/dist/events/index.mjs +2 -3
  42. package/dist/{events-CXl-o1Ad.mjs → events-CvUSgEuN.mjs} +2 -3
  43. package/dist/{events-CXl-o1Ad.mjs.map → events-CvUSgEuN.mjs.map} +1 -1
  44. package/dist/{gateway-context-BkZ4UKaX.mjs → gateway-context-CNOLkLUC.mjs} +4 -4
  45. package/dist/{gateway-context-BkZ4UKaX.mjs.map → gateway-context-CNOLkLUC.mjs.map} +1 -1
  46. package/dist/guards/index.d.mts +1 -1
  47. package/dist/i18n/index.d.mts +3 -3
  48. package/dist/i18n/index.mjs +15 -15
  49. package/dist/i18n/validation/index.d.mts +1 -1
  50. package/dist/i18n/validation/index.mjs +1 -1
  51. package/dist/{i18n.module-W8OJxg3d.mjs → i18n.module-Dn9SrFdS.mjs} +210 -160
  52. package/dist/i18n.module-Dn9SrFdS.mjs.map +1 -0
  53. package/dist/{index-BJWm863C.d.mts → index-BFCxSp_f.d.mts} +82 -73
  54. package/dist/index-BFCxSp_f.d.mts.map +1 -0
  55. package/dist/{index-D9iYu2Yc.d.mts → index-DGRe6Yoa.d.mts} +5 -144
  56. package/dist/index-DGRe6Yoa.d.mts.map +1 -0
  57. package/dist/{index-DVhdhLvE.d.mts → index-NGxg-KP_.d.mts} +4 -4
  58. package/dist/{index-DVhdhLvE.d.mts.map → index-NGxg-KP_.d.mts.map} +1 -1
  59. package/dist/index.d.mts +2 -2
  60. package/dist/index.mjs +19 -19
  61. package/dist/{is-command-BfCgWAcQ.mjs → is-command-DJVI6wEJ.mjs} +2 -2
  62. package/dist/{is-command-BfCgWAcQ.mjs.map → is-command-DJVI6wEJ.mjs.map} +1 -1
  63. package/dist/{is-seeder-CebjZCDn.mjs → is-seeder-D5MIEcdz.mjs} +1 -1
  64. package/dist/{is-seeder-CebjZCDn.mjs.map → is-seeder-D5MIEcdz.mjs.map} +1 -1
  65. package/dist/logger/index.mjs +1 -2
  66. package/dist/{logger-BR1-s1Um.mjs → logger-CGT91VY6.mjs} +170 -4
  67. package/dist/logger-CGT91VY6.mjs.map +1 -0
  68. package/dist/middleware/index.d.mts +1 -1
  69. package/dist/middleware/index.mjs +4 -5
  70. package/dist/{middleware-C0Ebzswy.mjs → middleware-Bl-b5pkt.mjs} +3 -3
  71. package/dist/{middleware-C0Ebzswy.mjs.map → middleware-Bl-b5pkt.mjs.map} +1 -1
  72. package/dist/module/index.d.mts +2 -117
  73. package/dist/module/index.d.mts.map +1 -1
  74. package/dist/module/index.mjs +10 -11
  75. package/dist/module-registry-CmjBX6ol.d.mts +121 -0
  76. package/dist/module-registry-CmjBX6ol.d.mts.map +1 -0
  77. package/dist/{module-BgdxxzBe.mjs → module-tUtyVJ5E.mjs} +9 -8
  78. package/dist/module-tUtyVJ5E.mjs.map +1 -0
  79. package/dist/openapi/index.d.mts +54 -54
  80. package/dist/openapi/index.d.mts.map +1 -1
  81. package/dist/openapi/index.mjs +15 -15
  82. package/dist/openapi-tools.service-B3TxYKoQ.mjs +197 -0
  83. package/dist/openapi-tools.service-B3TxYKoQ.mjs.map +1 -0
  84. package/dist/openapi.service-DGnX3Fc4.d.mts +58 -0
  85. package/dist/openapi.service-DGnX3Fc4.d.mts.map +1 -0
  86. package/dist/quarry/index.d.mts +109 -28
  87. package/dist/quarry/index.d.mts.map +1 -1
  88. package/dist/quarry/index.mjs +9 -7
  89. package/dist/quarry-registry-B2rkO-JS.mjs +683 -0
  90. package/dist/quarry-registry-B2rkO-JS.mjs.map +1 -0
  91. package/dist/queue/index.d.mts +2 -1
  92. package/dist/queue/index.mjs +11 -12
  93. package/dist/queue/index.mjs.map +1 -1
  94. package/dist/{queue.module-BZvmeAMj.mjs → queue.module-BtI8f4Jo.mjs} +4 -4
  95. package/dist/{queue.module-BZvmeAMj.mjs.map → queue.module-BtI8f4Jo.mjs.map} +1 -1
  96. package/dist/{resend.provider-BCCACQAU.mjs → resend.provider-bXMEkdRJ.mjs} +4 -5
  97. package/dist/{resend.provider-BCCACQAU.mjs.map → resend.provider-bXMEkdRJ.mjs.map} +1 -1
  98. package/dist/router/index.d.mts +1 -1
  99. package/dist/router/index.mjs +14 -14
  100. package/dist/{router-context-BEJe9HEB.mjs → router-context-D9R1v2Ac.mjs} +7 -4
  101. package/dist/router-context-D9R1v2Ac.mjs.map +1 -0
  102. package/dist/{s3-storage.provider-BLlzQYiJ.mjs → s3-storage.provider-CttzNnDR.mjs} +5 -6
  103. package/dist/{s3-storage.provider-BLlzQYiJ.mjs.map → s3-storage.provider-CttzNnDR.mjs.map} +1 -1
  104. package/dist/seeder/index.d.mts +3 -3
  105. package/dist/seeder/index.mjs +6 -7
  106. package/dist/{seeder-Cupi5jl-.mjs → seeder-R7RXJC35.mjs} +20 -17
  107. package/dist/seeder-R7RXJC35.mjs.map +1 -0
  108. package/dist/{smtp.provider-B8XtOcHU.mjs → smtp.provider-DrbHQztF.mjs} +4 -5
  109. package/dist/{smtp.provider-B8XtOcHU.mjs.map → smtp.provider-DrbHQztF.mjs.map} +1 -1
  110. package/dist/storage/index.d.mts +2 -195
  111. package/dist/storage/index.d.mts.map +1 -1
  112. package/dist/storage/index.mjs +13 -14
  113. package/dist/storage/providers/index.d.mts +272 -0
  114. package/dist/storage/providers/index.d.mts.map +1 -0
  115. package/dist/storage/providers/index.mjs +5 -0
  116. package/dist/{storage-By_ow2o_.mjs → storage-CZKHOhci.mjs} +7 -7
  117. package/dist/{storage-By_ow2o_.mjs.map → storage-CZKHOhci.mjs.map} +1 -1
  118. package/dist/storage-provider.interface-0IqcdhBf.d.mts +197 -0
  119. package/dist/storage-provider.interface-0IqcdhBf.d.mts.map +1 -0
  120. package/dist/{stratal-CE0iTz4f.mjs → stratal-D5smIU1y.mjs} +22 -12
  121. package/dist/stratal-D5smIU1y.mjs.map +1 -0
  122. package/dist/{usage-generator-C9hWziY4.mjs → usage-generator-CVIsENuE.mjs} +2 -2
  123. package/dist/{usage-generator-C9hWziY4.mjs.map → usage-generator-CVIsENuE.mjs.map} +1 -1
  124. package/dist/{validation-Bh875Lyg.mjs → validation-DQTC259A.mjs} +4 -4
  125. package/dist/{validation-Bh875Lyg.mjs.map → validation-DQTC259A.mjs.map} +1 -1
  126. package/dist/websocket/index.d.mts +1 -1
  127. package/dist/websocket/index.mjs +4 -5
  128. package/dist/workers/index.d.mts +1 -1
  129. package/dist/workers/index.mjs +19 -19
  130. package/package.json +13 -8
  131. package/dist/application-zG8b-pol.d.mts.map +0 -1
  132. package/dist/decorate-D5j-d9_z.mjs +0 -171
  133. package/dist/decorate-D5j-d9_z.mjs.map +0 -1
  134. package/dist/i18n.module-W8OJxg3d.mjs.map +0 -1
  135. package/dist/index-BJWm863C.d.mts.map +0 -1
  136. package/dist/index-D9iYu2Yc.d.mts.map +0 -1
  137. package/dist/logger-BR1-s1Um.mjs.map +0 -1
  138. package/dist/module-BgdxxzBe.mjs.map +0 -1
  139. package/dist/quarry-registry-DCwqVcRp.mjs +0 -310
  140. package/dist/quarry-registry-DCwqVcRp.mjs.map +0 -1
  141. package/dist/router-context-BEJe9HEB.mjs.map +0 -1
  142. package/dist/seeder-Cupi5jl-.mjs.map +0 -1
  143. package/dist/stratal-CE0iTz4f.mjs.map +0 -1
  144. package/dist/types-CLhOhYsQ.d.mts +0 -64
  145. package/dist/types-CLhOhYsQ.d.mts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/email/email.tokens.ts","../../src/email/consumers/email.consumer.ts","../../src/email/services/email.service.ts","../../src/email/errors/resend-api-key-missing.error.ts","../../src/email/errors/smtp-configuration-missing.error.ts","../../src/email/errors/smtp-host-missing.error.ts","../../src/email/errors/email-smtp-connection-failed.error.ts","../../src/email/errors/email-resend-api-failed.error.ts","../../src/email/errors/email-provider-not-supported.error.ts","../../src/email/services/email-provider-factory.ts","../../src/email/email.module.ts","../../src/email/contracts/email-attachment.ts","../../src/email/contracts/email-message.contract.ts","../../src/email/contracts/send-email.input.ts"],"sourcesContent":["/**\n * Dependency Injection Tokens for Email Module\n *\n * These Symbol-based tokens ensure type-safe dependency injection\n * throughout the email module and prevent naming collisions.\n */\n\n/**\n * Email Module DI Tokens\n */\nexport const EMAIL_TOKENS = {\n /**\n * Email module configuration options\n */\n Options: Symbol.for('stratal:email:options'),\n\n /**\n * Main email service - facade for sending emails via queues\n */\n EmailService: Symbol.for('stratal:email:service'),\n\n /**\n * Factory for creating email provider instances based on configuration\n */\n EmailProviderFactory: Symbol.for('stratal:email:provider:factory'),\n\n /**\n * Email provider interface - abstracts provider implementation\n */\n EmailProvider: Symbol.for('stratal:email:provider'),\n\n /**\n * Queue sender for email dispatch.\n * Bound via EmailModule.forRoot({ queue: 'queue-name' })\n */\n EmailQueue: Symbol.for('stratal:email:queue'),\n} as const\n","import { inject } from 'tsyringe'\nimport { Transient } from '../../di/decorators'\nimport { LOGGER_TOKENS, type LoggerService } from '../../logger'\nimport type { IQueueConsumer, QueueMessage } from '../../queue/queue-consumer'\nimport { STORAGE_TOKENS, type StorageService } from '../../storage'\nimport type { EmailAttachment, ResolvedEmailAttachment, SendEmailInput } from '../contracts'\nimport { EMAIL_TOKENS } from '../email.tokens'\nimport type { EmailProviderFactory } from '../services/email-provider-factory'\n\n/**\n * Email Consumer\n *\n * Generic queue consumer that handles email.send and email.batch.send messages\n * from ANY queue. Message routing is based on message type, not queue name.\n *\n * This consumer:\n * - Resolves storage-based attachments to streams\n * - Creates email provider instances via factory\n * - Sends emails with proper logging (no PII)\n * - Handles errors with retry support\n *\n * @example\n * ```typescript\n * // Registered in EmailModule\n * @Module({\n * consumers: [EmailConsumer]\n * })\n * ```\n */\n@Transient()\nexport class EmailConsumer implements IQueueConsumer<SendEmailInput> {\n readonly messageTypes = ['email.send', 'email.batch.send']\n\n constructor(\n @inject(LOGGER_TOKENS.LoggerService)\n private readonly logger: LoggerService,\n @inject(EMAIL_TOKENS.EmailProviderFactory)\n private readonly providerFactory: EmailProviderFactory,\n @inject(STORAGE_TOKENS.StorageService)\n private readonly storage: StorageService\n ) { }\n\n async handle(message: QueueMessage<SendEmailInput>): Promise<void> {\n const { type, payload } = message\n const recipientCount = Array.isArray(payload.to) ? payload.to.length : 1\n\n this.logger.info('Processing email message', {\n type,\n recipientCount,\n hasHtml: !!payload.html,\n hasText: !!payload.text,\n hasAttachments: !!payload.attachments?.length,\n })\n\n try {\n // Resolve storage-based attachments before sending\n const resolvedAttachments = await this.resolveAttachments(payload.attachments)\n\n const provider = await this.providerFactory.create()\n const result = await provider.send({\n ...payload,\n attachments: resolvedAttachments,\n })\n\n this.logger.info('Email sent successfully', {\n type,\n recipientCount,\n messageId: result.messageId,\n })\n }\n catch (error) {\n this.logger.error('Failed to send email', {\n type,\n recipientCount,\n error: (error as Error).message,\n })\n throw error // Retry via queue\n }\n }\n\n onError(error: Error, message: QueueMessage<SendEmailInput>): Promise<void> {\n const recipientCount = Array.isArray(message.payload.to)\n ? message.payload.to.length\n : 1\n\n this.logger.error('Email send failed after retries', {\n recipientCount,\n error: error.message,\n stack: error.stack,\n })\n\n return Promise.resolve()\n }\n\n /**\n * Resolve email attachments\n *\n * Converts attachment schemas to resolved attachments.\n * - Inline attachments: decode base64 to Buffer\n * - Storage attachments: pass stream directly (providers support streams)\n */\n private async resolveAttachments(\n attachments: EmailAttachment[] | undefined\n ): Promise<ResolvedEmailAttachment[] | undefined> {\n if (!attachments?.length) return undefined\n\n return Promise.all(attachments.map(async (attachment) => {\n // Check for inline attachment (has content property)\n if ('content' in attachment) {\n return {\n filename: attachment.filename,\n content: Buffer.from(attachment.content, 'base64'),\n contentType: attachment.contentType,\n }\n }\n\n // Storage attachment - pass stream directly to provider\n const result = await this.storage.download(\n attachment.storageKey,\n attachment.disk\n )\n\n return {\n filename: attachment.filename,\n content: result.toStream() ?? Buffer.alloc(0),\n contentType: result.contentType,\n }\n }))\n }\n}\n","import { render } from '@react-email/render'\nimport type { ReactElement } from 'react'\nimport { inject } from 'tsyringe'\nimport { Transient } from '../../di/decorators'\nimport type { IQueueSender } from '../../queue'\nimport type { SendBatchEmailInput, SendEmailInput } from '../contracts'\nimport { EMAIL_TOKENS } from '../email.tokens'\n\nexport type SendEmailInputWithTemplate = Omit<SendEmailInput, 'html' | 'text'> & {\n template?: ReactElement\n}\n\nexport type SendBatchEmailInputWithTemplate = Omit<SendBatchEmailInput, 'messages'> & {\n messages: SendEmailInputWithTemplate[]\n}\n\n/**\n * Email Service\n *\n * Main facade for sending emails. Routes emails to queues for async processing.\n * The queue is injected via EMAIL_TOKENS.EmailQueue, configured by the application\n * via EmailModule.forRoot({ queue: 'queue-name' }).\n *\n * @example Basic usage\n * ```typescript\n * @inject(EMAIL_TOKENS.EmailService)\n * private readonly emailService: EmailService\n *\n * await this.emailService.send({\n * to: 'user@example.com',\n * subject: 'Welcome',\n * template: <WelcomeEmail name=\"John\" />\n * })\n * ```\n */\n@Transient(EMAIL_TOKENS.EmailService)\nexport class EmailService {\n constructor(\n @inject(EMAIL_TOKENS.EmailQueue)\n protected readonly queue: IQueueSender\n ) { }\n\n /**\n * Send a single email\n *\n * Dispatches the email to the queue for async processing.\n * Supports optional React template rendering.\n *\n * @param input - Email message details\n */\n async send({ template, ...input }: SendEmailInputWithTemplate): Promise<void> {\n await this.queue.dispatch({\n type: 'email.send',\n payload: { ...input, html: template ? await render(template) : undefined },\n })\n }\n\n /**\n * Send multiple emails in a batch\n *\n * Dispatches all emails to the queue for async processing.\n * Supports React template rendering for each message.\n *\n * @param input - Batch email details\n */\n async sendBatch(input: SendBatchEmailInputWithTemplate): Promise<void> {\n for (const message of input.messages) {\n await this.send(message)\n }\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * ResendApiKeyMissingError\n *\n * Thrown when the Resend API key is not configured in environment variables.\n * This prevents the Resend email provider from initializing.\n *\n * Resolution: Set the RESEND_EMAIL_API_KEY environment variable.\n */\nexport class ResendApiKeyMissingError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.resendApiKeyMissing',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * SmtpConfigurationMissingError\n *\n * Thrown when SMTP configuration is not found in environment variables.\n * This prevents the SMTP email provider from initializing.\n *\n * Resolution: Set the SMTP_URL environment variable with format: smtp://user:pass@host:port\n */\nexport class SmtpConfigurationMissingError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.smtpConfigurationMissing',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * SmtpHostMissingError\n *\n * Thrown when SMTP host could not be parsed from SMTP_URL or is empty.\n * This prevents the SMTP email provider from initializing.\n *\n * Resolution: Ensure SMTP_URL is correctly formatted: smtp://user:pass@host:port\n */\nexport class SmtpHostMissingError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.smtpHostMissing',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * EmailSmtpConnectionFailedError\n *\n * Thrown when connection to SMTP server fails during email sending.\n * This is a runtime error that may be temporary.\n *\n * Resolution: Check SMTP server availability, network connectivity, or wait and retry.\n */\nexport class EmailSmtpConnectionFailedError extends ApplicationError {\n constructor(smtpHost: string, smtpPort: number) {\n super(\n 'errors.email.smtpConnectionFailed',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { smtpHost, smtpPort }\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * EmailResendApiFailedError\n *\n * Thrown when Resend API returns an error during email sending.\n * This is a runtime error from the Resend service.\n *\n * Resolution: Check Resend API status, API key validity, or wait and retry.\n */\nexport class EmailResendApiFailedError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.resendApiFailed',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * EmailProviderNotSupportedError\n *\n * Thrown when an unsupported email provider is configured.\n * Only 'resend' and 'smtp' providers are currently supported.\n *\n * Resolution: Set EMAIL_PROVIDER to either 'resend' or 'smtp'.\n */\nexport class EmailProviderNotSupportedError extends ApplicationError {\n constructor(provider: string) {\n super(\n 'errors.email.providerNotSupported',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR,\n { provider }\n )\n }\n}\n","import { inject } from 'tsyringe'\nimport { Transient } from '../../di/decorators'\nimport type { EmailModuleOptions } from '../email.module'\nimport { EMAIL_TOKENS } from '../email.tokens'\nimport { EmailProviderNotSupportedError } from '../errors'\nimport type { IEmailProvider } from '../providers/email-provider.interface'\n\n/**\n * Email Provider Factory\n *\n * Creates email provider instances based on configuration.\n * Supports automatic provider selection from module options.\n *\n * Providers are loaded lazily via dynamic imports to avoid pulling in\n * heavy Node.js-only dependencies (e.g. nodemailer) at module parse time,\n * which would break Cloudflare Workers and vitest-pool-workers environments.\n */\n@Transient(EMAIL_TOKENS.EmailProviderFactory)\nexport class EmailProviderFactory {\n constructor(\n @inject(EMAIL_TOKENS.Options)\n private readonly options: EmailModuleOptions\n ) { }\n\n /**\n * Create email provider instance based on configuration\n *\n * @returns Email provider implementation\n * @throws EmailProviderNotSupportedError if provider is not supported\n */\n async create(): Promise<IEmailProvider> {\n switch (this.options.provider) {\n case 'resend': {\n const { ResendProvider } = await import('../providers/resend.provider')\n return new ResendProvider(this.options)\n }\n\n case 'smtp': {\n const { SmtpProvider } = await import('../providers/smtp.provider')\n return new SmtpProvider(this.options)\n }\n\n default:\n throw new EmailProviderNotSupportedError(this.options.provider)\n }\n }\n}\n","/**\n * Email Module\n *\n * Provides email sending capabilities with provider abstraction.\n * Supports multiple email providers (Resend, SMTP) with automatic provider selection.\n * Emails are sent asynchronously via Cloudflare Queues.\n *\n * **Usage:**\n * ```typescript\n * // In AppModule imports with static options\n * EmailModule.forRoot({\n * provider: 'resend',\n * apiKey: 'your-api-key',\n * from: { name: 'App', email: 'noreply@example.com' },\n * queue: 'notifications-queue',\n * })\n *\n * // Or with async options from config namespaces\n * EmailModule.forRootAsync({\n * inject: [emailConfig.KEY],\n * useFactory: (email) => ({\n * provider: email.provider,\n * apiKey: email.apiKey,\n * from: email.from,\n * queue: email.queue,\n * }),\n * })\n *\n * // In your service\n * @inject(EMAIL_TOKENS.EmailService)\n * private readonly emailService: EmailService\n *\n * await this.emailService.send({\n * to: 'user@example.com',\n * subject: 'Welcome',\n * template: <WelcomeEmail name=\"John\" />\n * })\n * ```\n */\n\nimport { Module } from '../module'\nimport type { AsyncModuleOptions, DynamicModule } from '../module/types'\nimport type { QueueName } from '../queue'\nimport { QUEUE_TOKENS, QueueRegistry } from '../queue'\nimport { EmailConsumer } from './consumers/email.consumer'\nimport { EMAIL_TOKENS } from './email.tokens'\nimport { EmailProviderFactory, EmailService } from './services'\n\n/**\n * SMTP configuration options\n */\nexport interface SmtpConfig {\n /** SMTP server host */\n host: string\n /** SMTP server port */\n port: number\n /** Use TLS */\n secure?: boolean\n /** SMTP username */\n username?: string\n /** SMTP password */\n password?: string\n}\n\n/**\n * Email module configuration options\n */\nexport interface EmailModuleOptions {\n /** Email provider type */\n provider: 'resend' | 'smtp'\n\n /** Default from address */\n from: { name: string; email: string }\n\n /** Resend API key (required for resend provider) */\n apiKey?: string\n\n /** SMTP configuration (required for smtp provider) */\n smtp?: SmtpConfig\n\n /** Default reply-to address */\n replyTo?: string\n\n /**\n * Queue name for email dispatch.\n * The queue must be registered via QueueModule.registerQueue(name).\n */\n queue: QueueName\n}\n\n@Module({\n providers: [\n { provide: EMAIL_TOKENS.EmailService, useClass: EmailService },\n { provide: EMAIL_TOKENS.EmailProviderFactory, useClass: EmailProviderFactory },\n ],\n consumers: [EmailConsumer],\n})\nexport class EmailModule {\n /**\n * Configure EmailModule with static options\n *\n * @param options - Email configuration options\n * @returns Dynamic module with email infrastructure\n *\n * @example\n * ```typescript\n * EmailModule.forRoot({\n * provider: 'resend',\n * apiKey: env.RESEND_API_KEY,\n * from: { name: 'App', email: 'noreply@example.com' },\n * queue: 'notifications-queue',\n * })\n * ```\n */\n static forRoot(options: EmailModuleOptions): DynamicModule {\n return {\n module: EmailModule,\n providers: [\n { provide: EMAIL_TOKENS.Options, useValue: options },\n { provide: EMAIL_TOKENS.EmailQueue, useExisting: options.queue },\n ],\n }\n }\n\n /**\n * Configure EmailModule with async factory\n *\n * Use when configuration depends on other services.\n *\n * @param options - Async configuration with factory and inject tokens\n * @returns Dynamic module with email infrastructure\n *\n * @example\n * ```typescript\n * EmailModule.forRootAsync({\n * inject: [emailConfig.KEY],\n * useFactory: (email) => ({\n * provider: email.provider,\n * apiKey: email.apiKey,\n * from: email.from,\n * smtp: email.smtp,\n * queue: email.queue,\n * })\n * })\n * ```\n */\n static forRootAsync(options: AsyncModuleOptions<EmailModuleOptions>): DynamicModule {\n return {\n module: EmailModule,\n providers: [\n {\n provide: EMAIL_TOKENS.Options,\n useFactory: options.useFactory,\n inject: options.inject,\n },\n // Resolve queue from QueueRegistry using the queue name from options\n {\n provide: EMAIL_TOKENS.EmailQueue,\n useFactory: (emailOptions: EmailModuleOptions, registry: QueueRegistry) =>\n registry.getQueue(emailOptions.queue),\n inject: [EMAIL_TOKENS.Options, QUEUE_TOKENS.QueueRegistry],\n },\n ],\n }\n }\n}\n","import { z } from '../../i18n/validation'\n\n/**\n * Inline Email Attachment Schema\n *\n * Attachment with content embedded as base64 string.\n * Use for small files that can fit in queue message.\n */\nexport const inlineEmailAttachmentSchema = z.object({\n /**\n * Filename to display for the attachment\n */\n filename: z.string().min(1).max(255),\n\n /**\n * Base64 encoded content of the attachment\n */\n content: z.string(),\n\n /**\n * MIME type of the attachment (e.g., 'application/pdf', 'image/png')\n */\n contentType: z.string(),\n\n /**\n * Optional size of the attachment in bytes\n */\n size: z.number().positive().optional(),\n})\n\n/**\n * Storage Email Attachment Schema\n *\n * Attachment stored in cloud storage.\n * Content type and size are derived from storage metadata.\n * Use for large files to avoid queue message size limits.\n */\nexport const storageEmailAttachmentSchema = z.object({\n /**\n * Filename to display for the attachment\n */\n filename: z.string().min(1).max(255),\n\n /**\n * Path to the file in storage\n */\n storageKey: z.string(),\n\n /**\n * Optional storage disk name (uses default if not provided)\n */\n disk: z.string().optional(),\n})\n\n/**\n * Email Attachment Schema\n *\n * Union type - type is inferred from presence of `content` vs `storageKey`.\n * - If `content` is present: inline attachment\n * - If `storageKey` is present: storage-based attachment\n */\nexport const emailAttachmentSchema = z.union([\n inlineEmailAttachmentSchema,\n storageEmailAttachmentSchema,\n])\n\n/**\n * Type definitions\n */\nexport type InlineEmailAttachment = z.infer<typeof inlineEmailAttachmentSchema>\nexport type StorageEmailAttachment = z.infer<typeof storageEmailAttachmentSchema>\nexport type EmailAttachment = z.infer<typeof emailAttachmentSchema>\n\n/**\n * Resolved Email Attachment\n *\n * Attachment after resolution, ready for email provider.\n * Content can be Buffer (for inline) or ReadableStream (for storage-based).\n * Both nodemailer and Resend support these formats directly.\n */\nexport interface ResolvedEmailAttachment {\n filename: string\n content: Buffer | ReadableStream\n contentType: string\n}\n","import { withI18n, z } from '../../i18n/validation'\nimport { emailAttachmentSchema, type ResolvedEmailAttachment } from './email-attachment'\n\n/**\n * Email Address Schema\n *\n * Represents an email address with optional name\n */\nexport const emailAddressSchema = z.object({\n name: z.string().optional(),\n email: z.string().email(),\n})\n\n/**\n * Base Email Message Schema\n *\n * Defines the core structure for email messages.\n * Ensures either html or text content is provided.\n */\nexport const emailMessageSchema = z\n .object({\n /**\n * Recipient email address(es)\n * Can be a single email string or array of emails\n */\n to: z.union([z.string().email(), z.array(z.string().email())]),\n\n /**\n * Sender email address with optional name\n * Falls back to default from config if not provided\n */\n from: emailAddressSchema.optional(),\n\n /**\n * Email subject line\n */\n subject: z.string().min(1).max(500),\n\n /**\n * HTML content of the email\n * Either html or text must be provided\n */\n html: z.string().optional(),\n\n /**\n * Plain text content of the email\n * Either html or text must be provided\n */\n text: z.string().optional(),\n\n /**\n * Reply-to email address\n */\n replyTo: z.string().email().optional(),\n\n /**\n * CC recipients\n */\n cc: z.array(z.string().email()).optional(),\n\n /**\n * BCC recipients\n */\n bcc: z.array(z.string().email()).optional(),\n\n /**\n * Email attachments\n */\n attachments: z.array(emailAttachmentSchema).optional(),\n })\n .refine(\n (data) => data.html ?? data.text,\n withI18n('zodI18n.errors.custom.emailOrTextRequired')\n )\n\n/**\n * Type definition for email message\n */\nexport type EmailMessage = z.infer<typeof emailMessageSchema>\n\n/**\n * Type definition for email address\n */\nexport type EmailAddress = z.infer<typeof emailAddressSchema>\n\n/**\n * Resolved Email Message\n *\n * Email message with attachments resolved to Buffer content.\n * Used by providers after the consumer resolves storage-based attachments.\n */\nexport type ResolvedEmailMessage = Omit<EmailMessage, 'attachments'> & {\n attachments?: ResolvedEmailAttachment[]\n}\n","import { z } from '../../i18n/validation'\nimport { emailMessageSchema } from './email-message.contract'\n\n/**\n * Send Email Input Schema\n *\n * Input schema for sending emails through the EmailService.\n * Extends the base email message with optional metadata.\n * Uses safeExtend() because emailMessageSchema contains refinements.\n */\nexport const sendEmailInputSchema = emailMessageSchema.safeExtend({\n /**\n * Optional metadata to include with the email\n * Can be used for tracking, categorization, etc.\n */\n metadata: z.record(z.string(), z.unknown()).optional(),\n})\n\n/**\n * Type definition for send email input\n */\nexport type SendEmailInput = z.infer<typeof sendEmailInputSchema>\n\n/**\n * Send Batch Email Input Schema\n *\n * Schema for sending multiple emails in a batch\n */\nexport const sendBatchEmailInputSchema = z.object({\n /**\n * Array of email messages to send\n */\n messages: z.array(sendEmailInputSchema).min(1).max(100),\n})\n\n/**\n * Type definition for send batch email input\n */\nexport type SendBatchEmailInput = z.infer<typeof sendBatchEmailInputSchema>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,eAAe;CAI1B,SAAS,OAAO,IAAI,wBAAwB;CAK5C,cAAc,OAAO,IAAI,wBAAwB;CAKjD,sBAAsB,OAAO,IAAI,iCAAiC;CAKlE,eAAe,OAAO,IAAI,yBAAyB;CAMnD,YAAY,OAAO,IAAI,sBAAsB;CAC9C;;;ACNM,IAAA,gBAAA,MAAM,cAAwD;CACnE,eAAwB,CAAC,cAAc,mBAAmB;CAE1D,YACE,QAEA,iBAEA,SAEA;AALiB,OAAA,SAAA;AAEA,OAAA,kBAAA;AAEA,OAAA,UAAA;;CAGnB,MAAM,OAAO,SAAsD;EACjE,MAAM,EAAE,MAAM,YAAY;EAC1B,MAAM,iBAAiB,MAAM,QAAQ,QAAQ,GAAG,GAAG,QAAQ,GAAG,SAAS;AAEvE,OAAK,OAAO,KAAK,4BAA4B;GAC3C;GACA;GACA,SAAS,CAAC,CAAC,QAAQ;GACnB,SAAS,CAAC,CAAC,QAAQ;GACnB,gBAAgB,CAAC,CAAC,QAAQ,aAAa;GACxC,CAAC;AAEF,MAAI;GAEF,MAAM,sBAAsB,MAAM,KAAK,mBAAmB,QAAQ,YAAY;GAG9E,MAAM,SAAS,OADE,MAAM,KAAK,gBAAgB,QAAQ,EACtB,KAAK;IACjC,GAAG;IACH,aAAa;IACd,CAAC;AAEF,QAAK,OAAO,KAAK,2BAA2B;IAC1C;IACA;IACA,WAAW,OAAO;IACnB,CAAC;WAEG,O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O;CAC1B,CAAC;;;;;;;AAQF,MAAa,qBAAqB,EAC/B,OAAO;CAKN,IAAI,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;CAM9D,MAAM,mBAAmB,UAAU;CAKnC,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;CAMnC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAM3B,MAAM,EAAE,QAAQ,CAAC,UAAU;CAK3B,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU;CAKtC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU;CAK1C,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU;CAK3C,aAAa,EAAE,MAAM,sBAAsB,CAAC,UAAU;CACvD,CAAC,CACD,QACE,SAAS,KAAK,QAAQ,KAAK,MAC5B,SAAS,4CAA4C,CACtD;;;;;;;;;;AC/DH,MAAa,uBAAuB,mBAAmB,WAAW,EAKhE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,EACvD,CAAC;;;;;;AAYF,MAAa,4BAA4B,EAAE,OAAO,EAIhD,UAAU,EAAE,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,EACxD,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/email/email.tokens.ts","../../src/email/consumers/email.consumer.ts","../../src/email/services/email.service.ts","../../src/email/errors/resend-api-key-missing.error.ts","../../src/email/errors/smtp-configuration-missing.error.ts","../../src/email/errors/smtp-host-missing.error.ts","../../src/email/errors/email-smtp-connection-failed.error.ts","../../src/email/errors/email-resend-api-failed.error.ts","../../src/email/errors/email-provider-not-supported.error.ts","../../src/email/services/email-provider-factory.ts","../../src/email/email.module.ts","../../src/email/contracts/email-attachment.ts","../../src/email/contracts/email-message.contract.ts","../../src/email/contracts/send-email.input.ts"],"sourcesContent":["/**\n * Dependency Injection Tokens for Email Module\n *\n * These Symbol-based tokens ensure type-safe dependency injection\n * throughout the email module and prevent naming collisions.\n */\n\n/**\n * Email Module DI Tokens\n */\nexport const EMAIL_TOKENS = {\n /**\n * Email module configuration options\n */\n Options: Symbol.for('stratal:email:options'),\n\n /**\n * Main email service - facade for sending emails via queues\n */\n EmailService: Symbol.for('stratal:email:service'),\n\n /**\n * Factory for creating email provider instances based on configuration\n */\n EmailProviderFactory: Symbol.for('stratal:email:provider:factory'),\n\n /**\n * Email provider interface - abstracts provider implementation\n */\n EmailProvider: Symbol.for('stratal:email:provider'),\n\n /**\n * Queue sender for email dispatch.\n * Bound via EmailModule.forRoot({ queue: 'queue-name' })\n */\n EmailQueue: Symbol.for('stratal:email:queue'),\n} as const\n","import { inject } from 'tsyringe'\nimport { Transient } from '../../di/decorators'\nimport { LOGGER_TOKENS, type LoggerService } from '../../logger'\nimport type { IQueueConsumer, QueueMessage } from '../../queue/queue-consumer'\nimport { STORAGE_TOKENS, type StorageService } from '../../storage'\nimport type { EmailAttachment, ResolvedEmailAttachment, SendEmailInput } from '../contracts'\nimport { EMAIL_TOKENS } from '../email.tokens'\nimport type { EmailProviderFactory } from '../services/email-provider-factory'\n\n/**\n * Email Consumer\n *\n * Generic queue consumer that handles email.send and email.batch.send messages\n * from ANY queue. Message routing is based on message type, not queue name.\n *\n * This consumer:\n * - Resolves storage-based attachments to streams\n * - Creates email provider instances via factory\n * - Sends emails with proper logging (no PII)\n * - Handles errors with retry support\n *\n * @example\n * ```typescript\n * // Registered in EmailModule\n * @Module({\n * consumers: [EmailConsumer]\n * })\n * ```\n */\n@Transient()\nexport class EmailConsumer implements IQueueConsumer<SendEmailInput> {\n readonly messageTypes = ['email.send', 'email.batch.send']\n\n constructor(\n @inject(LOGGER_TOKENS.LoggerService)\n private readonly logger: LoggerService,\n @inject(EMAIL_TOKENS.EmailProviderFactory)\n private readonly providerFactory: EmailProviderFactory,\n @inject(STORAGE_TOKENS.StorageService)\n private readonly storage: StorageService\n ) { }\n\n async handle(message: QueueMessage<SendEmailInput>): Promise<void> {\n const { type, payload } = message\n const recipientCount = Array.isArray(payload.to) ? payload.to.length : 1\n\n this.logger.info('Processing email message', {\n type,\n recipientCount,\n hasHtml: !!payload.html,\n hasText: !!payload.text,\n hasAttachments: !!payload.attachments?.length,\n })\n\n try {\n // Resolve storage-based attachments before sending\n const resolvedAttachments = await this.resolveAttachments(payload.attachments)\n\n const provider = await this.providerFactory.create()\n const result = await provider.send({\n ...payload,\n attachments: resolvedAttachments,\n })\n\n this.logger.info('Email sent successfully', {\n type,\n recipientCount,\n messageId: result.messageId,\n })\n }\n catch (error) {\n this.logger.error('Failed to send email', {\n type,\n recipientCount,\n error: (error as Error).message,\n })\n throw error // Retry via queue\n }\n }\n\n onError(error: Error, message: QueueMessage<SendEmailInput>): Promise<void> {\n const recipientCount = Array.isArray(message.payload.to)\n ? message.payload.to.length\n : 1\n\n this.logger.error('Email send failed after retries', {\n recipientCount,\n error: error.message,\n stack: error.stack,\n })\n\n return Promise.resolve()\n }\n\n /**\n * Resolve email attachments\n *\n * Converts attachment schemas to resolved attachments.\n * - Inline attachments: decode base64 to Buffer\n * - Storage attachments: pass stream directly (providers support streams)\n */\n private async resolveAttachments(\n attachments: EmailAttachment[] | undefined\n ): Promise<ResolvedEmailAttachment[] | undefined> {\n if (!attachments?.length) return undefined\n\n return Promise.all(attachments.map(async (attachment) => {\n // Check for inline attachment (has content property)\n if ('content' in attachment) {\n return {\n filename: attachment.filename,\n content: Buffer.from(attachment.content, 'base64'),\n contentType: attachment.contentType,\n }\n }\n\n // Storage attachment - pass stream directly to provider\n const result = await this.storage.download(\n attachment.storageKey,\n attachment.disk\n )\n\n return {\n filename: attachment.filename,\n content: result.toStream() ?? Buffer.alloc(0),\n contentType: result.contentType,\n }\n }))\n }\n}\n","import { render } from '@react-email/render'\nimport type { ReactElement } from 'react'\nimport { inject } from 'tsyringe'\nimport { Transient } from '../../di/decorators'\nimport type { IQueueSender } from '../../queue'\nimport type { SendBatchEmailInput, SendEmailInput } from '../contracts'\nimport { EMAIL_TOKENS } from '../email.tokens'\n\nexport type SendEmailInputWithTemplate = Omit<SendEmailInput, 'html' | 'text'> & {\n template?: ReactElement\n}\n\nexport type SendBatchEmailInputWithTemplate = Omit<SendBatchEmailInput, 'messages'> & {\n messages: SendEmailInputWithTemplate[]\n}\n\n/**\n * Email Service\n *\n * Main facade for sending emails. Routes emails to queues for async processing.\n * The queue is injected via EMAIL_TOKENS.EmailQueue, configured by the application\n * via EmailModule.forRoot({ queue: 'queue-name' }).\n *\n * @example Basic usage\n * ```typescript\n * @inject(EMAIL_TOKENS.EmailService)\n * private readonly emailService: EmailService\n *\n * await this.emailService.send({\n * to: 'user@example.com',\n * subject: 'Welcome',\n * template: <WelcomeEmail name=\"John\" />\n * })\n * ```\n */\n@Transient(EMAIL_TOKENS.EmailService)\nexport class EmailService {\n constructor(\n @inject(EMAIL_TOKENS.EmailQueue)\n protected readonly queue: IQueueSender\n ) { }\n\n /**\n * Send a single email\n *\n * Dispatches the email to the queue for async processing.\n * Supports optional React template rendering.\n *\n * @param input - Email message details\n */\n async send({ template, ...input }: SendEmailInputWithTemplate): Promise<void> {\n await this.queue.dispatch({\n type: 'email.send',\n payload: { ...input, html: template ? await render(template) : undefined },\n })\n }\n\n /**\n * Send multiple emails in a batch\n *\n * Dispatches all emails to the queue for async processing.\n * Supports React template rendering for each message.\n *\n * @param input - Batch email details\n */\n async sendBatch(input: SendBatchEmailInputWithTemplate): Promise<void> {\n for (const message of input.messages) {\n await this.send(message)\n }\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * ResendApiKeyMissingError\n *\n * Thrown when the Resend API key is not configured in environment variables.\n * This prevents the Resend email provider from initializing.\n *\n * Resolution: Set the RESEND_EMAIL_API_KEY environment variable.\n */\nexport class ResendApiKeyMissingError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.resendApiKeyMissing',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * SmtpConfigurationMissingError\n *\n * Thrown when SMTP configuration is not found in environment variables.\n * This prevents the SMTP email provider from initializing.\n *\n * Resolution: Set the SMTP_URL environment variable with format: smtp://user:pass@host:port\n */\nexport class SmtpConfigurationMissingError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.smtpConfigurationMissing',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * SmtpHostMissingError\n *\n * Thrown when SMTP host could not be parsed from SMTP_URL or is empty.\n * This prevents the SMTP email provider from initializing.\n *\n * Resolution: Ensure SMTP_URL is correctly formatted: smtp://user:pass@host:port\n */\nexport class SmtpHostMissingError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.smtpHostMissing',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * EmailSmtpConnectionFailedError\n *\n * Thrown when connection to SMTP server fails during email sending.\n * This is a runtime error that may be temporary.\n *\n * Resolution: Check SMTP server availability, network connectivity, or wait and retry.\n */\nexport class EmailSmtpConnectionFailedError extends ApplicationError {\n constructor(smtpHost: string, smtpPort: number) {\n super(\n 'errors.email.smtpConnectionFailed',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { smtpHost, smtpPort }\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * EmailResendApiFailedError\n *\n * Thrown when Resend API returns an error during email sending.\n * This is a runtime error from the Resend service.\n *\n * Resolution: Check Resend API status, API key validity, or wait and retry.\n */\nexport class EmailResendApiFailedError extends ApplicationError {\n constructor() {\n super(\n 'errors.email.resendApiFailed',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * EmailProviderNotSupportedError\n *\n * Thrown when an unsupported email provider is configured.\n * Only 'resend' and 'smtp' providers are currently supported.\n *\n * Resolution: Set EMAIL_PROVIDER to either 'resend' or 'smtp'.\n */\nexport class EmailProviderNotSupportedError extends ApplicationError {\n constructor(provider: string) {\n super(\n 'errors.email.providerNotSupported',\n ERROR_CODES.SYSTEM.CONFIGURATION_ERROR,\n { provider }\n )\n }\n}\n","import { inject } from 'tsyringe'\nimport { Transient } from '../../di/decorators'\nimport type { EmailModuleOptions } from '../email.module'\nimport { EMAIL_TOKENS } from '../email.tokens'\nimport { EmailProviderNotSupportedError } from '../errors'\nimport type { IEmailProvider } from '../providers/email-provider.interface'\n\n/**\n * Email Provider Factory\n *\n * Creates email provider instances based on configuration.\n * Supports automatic provider selection from module options.\n *\n * Providers are loaded lazily via dynamic imports to avoid pulling in\n * heavy Node.js-only dependencies (e.g. nodemailer) at module parse time,\n * which would break Cloudflare Workers and vitest-pool-workers environments.\n */\n@Transient(EMAIL_TOKENS.EmailProviderFactory)\nexport class EmailProviderFactory {\n constructor(\n @inject(EMAIL_TOKENS.Options)\n private readonly options: EmailModuleOptions\n ) { }\n\n /**\n * Create email provider instance based on configuration\n *\n * @returns Email provider implementation\n * @throws EmailProviderNotSupportedError if provider is not supported\n */\n async create(): Promise<IEmailProvider> {\n switch (this.options.provider) {\n case 'resend': {\n const { ResendProvider } = await import('../providers/resend.provider')\n return new ResendProvider(this.options)\n }\n\n case 'smtp': {\n const { SmtpProvider } = await import('../providers/smtp.provider')\n return new SmtpProvider(this.options)\n }\n\n default:\n throw new EmailProviderNotSupportedError(this.options.provider)\n }\n }\n}\n","/**\n * Email Module\n *\n * Provides email sending capabilities with provider abstraction.\n * Supports multiple email providers (Resend, SMTP) with automatic provider selection.\n * Emails are sent asynchronously via Cloudflare Queues.\n *\n * **Usage:**\n * ```typescript\n * // In AppModule imports with static options\n * EmailModule.forRoot({\n * provider: 'resend',\n * apiKey: 'your-api-key',\n * from: { name: 'App', email: 'noreply@example.com' },\n * queue: 'notifications-queue',\n * })\n *\n * // Or with async options from config namespaces\n * EmailModule.forRootAsync({\n * inject: [emailConfig.KEY],\n * useFactory: (email) => ({\n * provider: email.provider,\n * apiKey: email.apiKey,\n * from: email.from,\n * queue: email.queue,\n * }),\n * })\n *\n * // In your service\n * @inject(EMAIL_TOKENS.EmailService)\n * private readonly emailService: EmailService\n *\n * await this.emailService.send({\n * to: 'user@example.com',\n * subject: 'Welcome',\n * template: <WelcomeEmail name=\"John\" />\n * })\n * ```\n */\n\nimport { Module } from '../module'\nimport type { AsyncModuleOptions, DynamicModule } from '../module/types'\nimport type { QueueName } from '../queue'\nimport { QUEUE_TOKENS, QueueRegistry } from '../queue'\nimport { EmailConsumer } from './consumers/email.consumer'\nimport { EMAIL_TOKENS } from './email.tokens'\nimport { EmailProviderFactory, EmailService } from './services'\n\n/**\n * SMTP configuration options\n */\nexport interface SmtpConfig {\n /** SMTP server host */\n host: string\n /** SMTP server port */\n port: number\n /** Use TLS */\n secure?: boolean\n /** SMTP username */\n username?: string\n /** SMTP password */\n password?: string\n}\n\n/**\n * Email module configuration options\n */\nexport interface EmailModuleOptions {\n /** Email provider type */\n provider: 'resend' | 'smtp'\n\n /** Default from address */\n from: { name: string; email: string }\n\n /** Resend API key (required for resend provider) */\n apiKey?: string\n\n /** SMTP configuration (required for smtp provider) */\n smtp?: SmtpConfig\n\n /** Default reply-to address */\n replyTo?: string\n\n /**\n * Queue name for email dispatch.\n * The queue must be registered via QueueModule.registerQueue(name).\n */\n queue: QueueName\n}\n\n@Module({\n providers: [\n { provide: EMAIL_TOKENS.EmailService, useClass: EmailService },\n { provide: EMAIL_TOKENS.EmailProviderFactory, useClass: EmailProviderFactory },\n ],\n consumers: [EmailConsumer],\n})\nexport class EmailModule {\n /**\n * Configure EmailModule with static options\n *\n * @param options - Email configuration options\n * @returns Dynamic module with email infrastructure\n *\n * @example\n * ```typescript\n * EmailModule.forRoot({\n * provider: 'resend',\n * apiKey: env.RESEND_API_KEY,\n * from: { name: 'App', email: 'noreply@example.com' },\n * queue: 'notifications-queue',\n * })\n * ```\n */\n static forRoot(options: EmailModuleOptions): DynamicModule {\n return {\n module: EmailModule,\n providers: [\n { provide: EMAIL_TOKENS.Options, useValue: options },\n { provide: EMAIL_TOKENS.EmailQueue, useExisting: options.queue },\n ],\n }\n }\n\n /**\n * Configure EmailModule with async factory\n *\n * Use when configuration depends on other services.\n *\n * @param options - Async configuration with factory and inject tokens\n * @returns Dynamic module with email infrastructure\n *\n * @example\n * ```typescript\n * EmailModule.forRootAsync({\n * inject: [emailConfig.KEY],\n * useFactory: (email) => ({\n * provider: email.provider,\n * apiKey: email.apiKey,\n * from: email.from,\n * smtp: email.smtp,\n * queue: email.queue,\n * })\n * })\n * ```\n */\n static forRootAsync(options: AsyncModuleOptions<EmailModuleOptions>): DynamicModule {\n return {\n module: EmailModule,\n providers: [\n {\n provide: EMAIL_TOKENS.Options,\n useFactory: options.useFactory,\n inject: options.inject,\n },\n // Resolve queue from QueueRegistry using the queue name from options\n {\n provide: EMAIL_TOKENS.EmailQueue,\n useFactory: (emailOptions: EmailModuleOptions, registry: QueueRegistry) =>\n registry.getQueue(emailOptions.queue),\n inject: [EMAIL_TOKENS.Options, QUEUE_TOKENS.QueueRegistry],\n },\n ],\n }\n }\n}\n","import { z } from '../../i18n/validation'\n\n/**\n * Inline Email Attachment Schema\n *\n * Attachment with content embedded as base64 string.\n * Use for small files that can fit in queue message.\n */\nexport const inlineEmailAttachmentSchema = z.object({\n /**\n * Filename to display for the attachment\n */\n filename: z.string().min(1).max(255),\n\n /**\n * Base64 encoded content of the attachment\n */\n content: z.string(),\n\n /**\n * MIME type of the attachment (e.g., 'application/pdf', 'image/png')\n */\n contentType: z.string(),\n\n /**\n * Optional size of the attachment in bytes\n */\n size: z.number().positive().optional(),\n})\n\n/**\n * Storage Email Attachment Schema\n *\n * Attachment stored in cloud storage.\n * Content type and size are derived from storage metadata.\n * Use for large files to avoid queue message size limits.\n */\nexport const storageEmailAttachmentSchema = z.object({\n /**\n * Filename to display for the attachment\n */\n filename: z.string().min(1).max(255),\n\n /**\n * Path to the file in storage\n */\n storageKey: z.string(),\n\n /**\n * Optional storage disk name (uses default if not provided)\n */\n disk: z.string().optional(),\n})\n\n/**\n * Email Attachment Schema\n *\n * Union type - type is inferred from presence of `content` vs `storageKey`.\n * - If `content` is present: inline attachment\n * - If `storageKey` is present: storage-based attachment\n */\nexport const emailAttachmentSchema = z.union([\n inlineEmailAttachmentSchema,\n storageEmailAttachmentSchema,\n])\n\n/**\n * Type definitions\n */\nexport type InlineEmailAttachment = z.infer<typeof inlineEmailAttachmentSchema>\nexport type StorageEmailAttachment = z.infer<typeof storageEmailAttachmentSchema>\nexport type EmailAttachment = z.infer<typeof emailAttachmentSchema>\n\n/**\n * Resolved Email Attachment\n *\n * Attachment after resolution, ready for email provider.\n * Content can be Buffer (for inline) or ReadableStream (for storage-based).\n * Both nodemailer and Resend support these formats directly.\n */\nexport interface ResolvedEmailAttachment {\n filename: string\n content: Buffer | ReadableStream\n contentType: string\n}\n","import { withI18n, z } from '../../i18n/validation'\nimport { emailAttachmentSchema, type ResolvedEmailAttachment } from './email-attachment'\n\n/**\n * Email Address Schema\n *\n * Represents an email address with optional name\n */\nexport const emailAddressSchema = z.object({\n name: z.string().optional(),\n email: z.string().email(),\n})\n\n/**\n * Base Email Message Schema\n *\n * Defines the core structure for email messages.\n * Ensures either html or text content is provided.\n */\nexport const emailMessageSchema = z\n .object({\n /**\n * Recipient email address(es)\n * Can be a single email string or array of emails\n */\n to: z.union([z.string().email(), z.array(z.string().email())]),\n\n /**\n * Sender email address with optional name\n * Falls back to default from config if not provided\n */\n from: emailAddressSchema.optional(),\n\n /**\n * Email subject line\n */\n subject: z.string().min(1).max(500),\n\n /**\n * HTML content of the email\n * Either html or text must be provided\n */\n html: z.string().optional(),\n\n /**\n * Plain text content of the email\n * Either html or text must be provided\n */\n text: z.string().optional(),\n\n /**\n * Reply-to email address\n */\n replyTo: z.string().email().optional(),\n\n /**\n * CC recipients\n */\n cc: z.array(z.string().email()).optional(),\n\n /**\n * BCC recipients\n */\n bcc: z.array(z.string().email()).optional(),\n\n /**\n * Email attachments\n */\n attachments: z.array(emailAttachmentSchema).optional(),\n })\n .refine(\n (data) => data.html ?? data.text,\n withI18n('zodI18n.errors.custom.emailOrTextRequired')\n )\n\n/**\n * Type definition for email message\n */\nexport type EmailMessage = z.infer<typeof emailMessageSchema>\n\n/**\n * Type definition for email address\n */\nexport type EmailAddress = z.infer<typeof emailAddressSchema>\n\n/**\n * Resolved Email Message\n *\n * Email message with attachments resolved to Buffer content.\n * Used by providers after the consumer resolves storage-based attachments.\n */\nexport type ResolvedEmailMessage = Omit<EmailMessage, 'attachments'> & {\n attachments?: ResolvedEmailAttachment[]\n}\n","import { z } from '../../i18n/validation'\nimport { emailMessageSchema } from './email-message.contract'\n\n/**\n * Send Email Input Schema\n *\n * Input schema for sending emails through the EmailService.\n * Extends the base email message with optional metadata.\n * Uses safeExtend() because emailMessageSchema contains refinements.\n */\nexport const sendEmailInputSchema = emailMessageSchema.safeExtend({\n /**\n * Optional metadata to include with the email\n * Can be used for tracking, categorization, etc.\n */\n metadata: z.record(z.string(), z.unknown()).optional(),\n})\n\n/**\n * Type definition for send email input\n */\nexport type SendEmailInput = z.infer<typeof sendEmailInputSchema>\n\n/**\n * Send Batch Email Input Schema\n *\n * Schema for sending multiple emails in a batch\n */\nexport const sendBatchEmailInputSchema = z.object({\n /**\n * Array of email messages to send\n */\n messages: z.array(sendEmailInputSchema).min(1).max(100),\n})\n\n/**\n * Type definition for send batch email input\n */\nexport type SendBatchEmailInput = z.infer<typeof sendBatchEmailInputSchema>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,eAAe;CAI1B,SAAS,OAAO,IAAI,wBAAwB;CAK5C,cAAc,OAAO,IAAI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QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU;CAK1C,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU;CAK3C,aAAa,EAAE,MAAM,sBAAsB,CAAC,UAAU;CACvD,CAAC,CACD,QACE,SAAS,KAAK,QAAQ,KAAK,MAC5B,SAAS,4CAA4C,CACtD;;;;;;;;;;AC/DH,MAAa,uBAAuB,mBAAmB,WAAW,EAKhE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,EACvD,CAAC;;;;;;AAYF,MAAa,4BAA4B,EAAE,OAAO,EAIhD,UAAU,EAAE,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,EACxD,CAAC"}
@@ -1,2 +1,2 @@
1
- import { Cn as isErrorResponse, Sn as ErrorResponse, a as GlobalErrorHandler, c as ERROR_CODES, i as InternalError, l as ErrorCode, n as RequestContainerNotInitializedError, o as getHttpStatus, r as isApplicationError, s as ApplicationError, t as StratalNotInitializedError, xn as Environment } from "../index-BJWm863C.mjs";
1
+ import { Cn as ErrorResponse, Sn as Environment, a as GlobalErrorHandler, c as ERROR_CODES, i as InternalError, l as ErrorCode, n as RequestContainerNotInitializedError, o as getHttpStatus, r as isApplicationError, s as ApplicationError, t as StratalNotInitializedError, wn as isErrorResponse } from "../index-BFCxSp_f.mjs";
2
2
  export { ApplicationError, ERROR_CODES, Environment, ErrorCode, ErrorResponse, GlobalErrorHandler, InternalError, RequestContainerNotInitializedError, StratalNotInitializedError, getHttpStatus, isApplicationError, isErrorResponse };
@@ -1,4 +1,3 @@
1
- import { S as ApplicationError, a as InternalError, b as ERROR_CODES, i as isApplicationError, n as RequestContainerNotInitializedError, r as GlobalErrorHandler, t as StratalNotInitializedError, x as isErrorResponse, y as getHttpStatus } from "../errors-CtCi1wn6.mjs";
2
- import "../decorate-D5j-d9_z.mjs";
3
- import "../logger-BR1-s1Um.mjs";
1
+ import { S as ApplicationError, a as InternalError, b as ERROR_CODES, i as isApplicationError, n as RequestContainerNotInitializedError, r as GlobalErrorHandler, t as StratalNotInitializedError, x as isErrorResponse, y as getHttpStatus } from "../errors-DSKapqD8.mjs";
2
+ import "../logger-CGT91VY6.mjs";
4
3
  export { ApplicationError, ERROR_CODES, GlobalErrorHandler, InternalError, RequestContainerNotInitializedError, StratalNotInitializedError, getHttpStatus, isApplicationError, isErrorResponse };
@@ -1,5 +1,4 @@
1
- import { c as CONTAINER_TOKEN, i as Transient, l as DI_TOKENS, n as __decorateParam, r as __decorateMetadata, t as __decorate } from "./decorate-D5j-d9_z.mjs";
2
- import { s as LOGGER_TOKENS } from "./logger-BR1-s1Um.mjs";
1
+ import { a as __decorate, d as Transient, g as DI_TOKENS, h as CONTAINER_TOKEN, o as __decorateParam, s as __decorateMetadata, u as LOGGER_TOKENS } from "./logger-CGT91VY6.mjs";
3
2
  import { Lifecycle, container as container$1, delay, inject, inject as inject$1, injectable as injectable$1, instancePerContainerCachingFactory as instancePerContainerCachingFactory$1, predicateAwareClassFactory, singleton } from "tsyringe";
4
3
  //#region src/errors/application-error.ts
5
4
  /**
@@ -537,7 +536,8 @@ let Scope = /* @__PURE__ */ function(Scope) {
537
536
  const I18N_TOKENS = {
538
537
  MessageLoader: Symbol.for("stratal:i18n:message:loader"),
539
538
  I18nService: Symbol.for("stratal:i18n:service"),
540
- Options: Symbol.for("stratal:i18n:options")
539
+ Options: Symbol.for("stratal:i18n:options"),
540
+ MessageRegistry: Symbol.for("stratal:i18n:message:registry")
541
541
  };
542
542
  //#endregion
543
543
  //#region src/errors/internal-error.ts
@@ -704,4 +704,4 @@ var StratalNotInitializedError = class extends ApplicationError {
704
704
  //#endregion
705
705
  export { ApplicationError as S, ConditionalBindingFallbackError as _, InternalError as a, ERROR_CODES as b, Container as c, inject$1 as d, injectable$1 as f, RequestScopeOperationNotAllowedError as g, ConditionalBindingBuilderImpl as h, isApplicationError as i, container$1 as l, singleton as m, RequestContainerNotInitializedError as n, I18N_TOKENS as o, instancePerContainerCachingFactory$1 as p, GlobalErrorHandler as r, Scope as s, StratalNotInitializedError as t, delay as u, ROUTER_TOKENS as v, isErrorResponse as x, getHttpStatus as y };
706
706
 
707
- //# sourceMappingURL=errors-CtCi1wn6.mjs.map
707
+ //# sourceMappingURL=errors-DSKapqD8.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-CtCi1wn6.mjs","names":[],"sources":["../src/errors/application-error.ts","../src/errors/error-response.ts","../src/errors/error-codes.ts","../src/errors/get-http-status.ts","../src/router/router.tokens.ts","../src/di/errors/conditional-binding-fallback.error.ts","../src/di/errors/request-scope-operation-not-allowed.error.ts","../src/di/conditional-binding-builder.ts","../src/di/container.ts","../src/di/types.ts","../src/i18n/i18n.tokens.ts","../src/errors/internal-error.ts","../src/errors/is-application-error.ts","../src/errors/global-error-handler.ts","../src/errors/request-container-not-initialized.error.ts","../src/errors/stratal-not-initialized.error.ts"],"sourcesContent":["import type { Environment, ErrorResponse } from './error-response'\nimport type { MessageKeys } from '../i18n'\nimport type { ErrorCode } from './error-codes'\n\n/**\n * ApplicationError\n *\n * Abstract base class for all application errors.\n * This class should never be used directly - always extend it to create specific error types.\n *\n * Features:\n * - Type-safe error codes from ERROR_CODES registry\n * - Type-safe message keys from i18n module\n * - Localized message keys (translated by GlobalErrorHandler)\n * - Structured metadata for logging and interpolation\n * - Proper Error prototype chain\n * - Automatic timestamp generation\n * - Serialization for RPC transmission\n *\n * Message Localization:\n * - Each error class passes an i18n key (e.g., 'errors.userNotFound') to super()\n * - `Error.message` contains the i18n key for useful stack traces and fallback display\n * - Metadata provides interpolation parameters (e.g., { userId: '123' })\n * - GlobalErrorHandler translates the message key using I18nService before sending response\n * - This ensures errors are localized based on the user's locale (from X-Locale header)\n */\nexport abstract class ApplicationError extends Error {\n /**\n * Controls whether stack traces are captured.\n * Set to false in production to skip the expensive Error.captureStackTrace() call,\n * since stack traces are stripped from responses in production anyway.\n */\n static captureStackTraces = true\n\n /**\n * Type-safe error code from ERROR_CODES registry\n * See error-codes.ts for the complete registry\n */\n public readonly code: ErrorCode\n\n /**\n * ISO timestamp when the error was created\n */\n public readonly timestamp: string\n\n /**\n * Additional structured data about the error\n * Used for:\n * 1. Logging and debugging\n * 2. Message interpolation (e.g., { userId: '123', email: 'user@example.com' })\n */\n public readonly metadata?: Record<string, unknown>\n\n /**\n * @param i18nKey - Type-safe i18n message key (e.g., 'errors.userNotFound')\n * @param code - Type-safe error code from ERROR_CODES registry\n * @param metadata - Optional data for logging and interpolation\n */\n constructor(\n i18nKey: MessageKeys,\n code: ErrorCode,\n metadata?: Record<string, unknown>\n ) {\n // Pass i18nKey to Error.message for useful stack traces (e.g., \"InternalError: errors.internalError\")\n super(i18nKey)\n\n // Maintains proper prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype)\n\n this.name = this.constructor.name\n this.code = code\n this.timestamp = new Date().toISOString()\n this.metadata = metadata\n\n // Capture stack trace, excluding constructor call from it\n // Skip in production where stack traces are stripped from responses anyway\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- captureStackTrace is V8-specific, not always present\n if (ApplicationError.captureStackTraces && Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor)\n }\n }\n\n /**\n * Filter metadata to include only user-facing properties\n *\n * User-facing properties (validation/constraint errors):\n * - issues: Validation errors from SchemaValidationError\n * - fields: Constraint violation fields\n * - field: Single field constraint/foreign key\n *\n * Internal properties (excluded from response):\n * - path, method: Route debugging\n * - controllerName, reason: Controller errors\n * - details, etc.: Internal debugging info\n *\n * @param metadata - Raw metadata object\n * @returns Filtered metadata with only whitelisted properties\n */\n private static filterMetadata(\n metadata?: Record<string, unknown>\n ): Record<string, unknown> | undefined {\n if (!metadata) return undefined\n\n // Whitelist of user-facing metadata properties\n const whitelist = ['issues', 'fields', 'field']\n\n const filtered: Record<string, unknown> = {}\n let hasUserFacingData = false\n\n for (const key of whitelist) {\n if (key in metadata && metadata[key] !== undefined) {\n filtered[key] = metadata[key]\n hasUserFacingData = true\n }\n }\n\n // Only return metadata if there's actual user-facing data\n return hasUserFacingData ? filtered : undefined\n }\n\n /**\n * Serialize error to ErrorResponse format for RPC transmission\n *\n * @param env - Environment (development | production)\n * @param translatedMessage - Optional translated message (from GlobalErrorHandler)\n * @returns ErrorResponse object suitable for JSON serialization\n */\n toErrorResponse(env: Environment, translatedMessage?: string): ErrorResponse {\n const message = translatedMessage ?? this.message\n\n return {\n code: this.code,\n message,\n timestamp: this.timestamp,\n // Include filtered user-facing metadata in all environments\n metadata: ApplicationError.filterMetadata(this.metadata),\n // Stack trace only in development for debugging\n // Rewrite first line with translated message for readable debugging\n stack: env === 'development'\n ? this.stack?.replace(this.message, message)\n : undefined,\n }\n }\n\n /**\n * JSON serialization (used by JSON.stringify)\n * Defaults to development mode for backward compatibility\n * Note: This will use the untranslated message key - use GlobalErrorHandler for proper localization\n */\n toJSON(): ErrorResponse {\n return this.toErrorResponse('development')\n }\n}\n","export type Environment = 'development' | 'staging' | 'production'\n\nexport interface ErrorResponse {\n /**\n * Numeric error code for identification and escalation\n * See error-codes.ts for the complete registry\n */\n code: number\n\n /**\n * Human-readable error message\n * Fixed per error type, not customizable\n */\n message: string\n\n /**\n * ISO timestamp when the error occurred\n */\n timestamp: string\n\n /**\n * Additional structured data about the error\n * Only included in development environment\n */\n metadata?: Record<string, unknown>\n\n /**\n * Stack trace for debugging\n * Only included in development environment\n */\n stack?: string\n}\n\n/**\n * Type guard to check if an object is an ErrorResponse\n */\nexport function isErrorResponse(obj: unknown): obj is ErrorResponse {\n return (\n typeof obj === 'object' &&\n obj !== null &&\n 'code' in obj &&\n typeof (obj as ErrorResponse).code === 'number' &&\n 'message' in obj &&\n typeof (obj as ErrorResponse).message === 'string' &&\n 'timestamp' in obj &&\n typeof (obj as ErrorResponse).timestamp === 'string'\n )\n}\n","/**\n * Centralized Error Code Registry\n *\n * Error codes are organized by category with specific ranges:\n * - 1000-1999: Validation errors\n * - 2000-2999: Database errors (generic)\n * - 3000-3999: Authentication & Authorization\n * - 4000-4999: Resource errors\n * - 5000-5999: Domain-specific business logic (per module)\n * - 9000-9999: System/Internal errors\n * - 9000-9099: Router errors\n * - 9100-9199: Configuration errors\n * - 9200-9299: Infrastructure errors\n * - 9300-9399: I18n errors\n */\n\nexport const ERROR_CODES = {\n /**\n * Database Errors (2000-2999)\n * Generic database errors thrown by Prisma client extensions\n */\n DATABASE: {\n /** Generic database error */\n GENERIC: 2000,\n /** Record not found in database */\n RECORD_NOT_FOUND: 2001,\n /** Unique constraint violation */\n UNIQUE_CONSTRAINT: 2002,\n /** Foreign key constraint violation */\n FOREIGN_KEY_CONSTRAINT: 2003,\n /** Database connection failed */\n CONNECTION_FAILED: 2004,\n /** Database timeout */\n TIMEOUT: 2005,\n /** Null constraint violation */\n NULL_CONSTRAINT: 2006,\n /** Too many database connections */\n TOO_MANY_CONNECTIONS: 2007,\n /** Transaction conflict or deadlock */\n TRANSACTION_CONFLICT: 2008,\n },\n\n /**\n * Authentication Errors (3000-3099)\n * Authentication-related failures\n */\n AUTH: {\n /** Invalid credentials provided */\n INVALID_CREDENTIALS: 3000,\n /** Session expired or invalid */\n SESSION_EXPIRED: 3001,\n /** Account locked or disabled */\n ACCOUNT_LOCKED: 3002,\n /** Invalid or expired token */\n INVALID_TOKEN: 3003,\n /** Context not initialized */\n CONTEXT_NOT_INITIALIZED: 3004,\n /** User not authenticated */\n USER_NOT_AUTHENTICATED: 3005,\n /** Email verification required before login */\n EMAIL_NOT_VERIFIED: 3007,\n /** Password doesn't meet minimum length */\n PASSWORD_TOO_SHORT: 3008,\n /** Password exceeds maximum length */\n PASSWORD_TOO_LONG: 3009,\n /** Account with email already exists */\n ACCOUNT_ALREADY_EXISTS: 3010,\n /** User creation failed */\n FAILED_TO_CREATE_USER: 3011,\n /** Session creation failed */\n FAILED_TO_CREATE_SESSION: 3012,\n /** User update failed */\n FAILED_TO_UPDATE_USER: 3013,\n /** Social account already linked */\n SOCIAL_ACCOUNT_LINKED: 3014,\n /** Last account cannot be unlinked */\n CANNOT_UNLINK_LAST_ACCOUNT: 3015,\n },\n\n /**\n * Authorization Errors (3100-3199)\n * Permission and access control failures\n */\n AUTHZ: {\n /** Insufficient permissions */\n FORBIDDEN: 3100,\n /** Resource access denied */\n ACCESS_DENIED: 3101,\n /** User lacks required role */\n INSUFFICIENT_PERMISSIONS: 3102,\n },\n\n /**\n * Resource Errors (4000-4999)\n * Generic resource-related errors\n */\n RESOURCE: {\n /** Generic resource not found */\n NOT_FOUND: 4000,\n /** Route/endpoint not found */\n ROUTE_NOT_FOUND: 4004,\n /** Resource conflict or duplicate */\n CONFLICT: 4100,\n /** Resource already exists */\n ALREADY_EXISTS: 4101,\n },\n\n /**\n * Validation Errors (1000-1999)\n * Input validation failures\n */\n VALIDATION: {\n /** Generic validation error */\n GENERIC: 1000,\n /** Required field missing */\n REQUIRED_FIELD: 1001,\n /** Invalid format */\n INVALID_FORMAT: 1002,\n /** Schema validation failed */\n SCHEMA_VALIDATION: 1003,\n /** Request validation failed (OpenAPI, etc.) */\n REQUEST_VALIDATION: 1004,\n },\n\n /**\n * Router Errors (9000-9099)\n * Router and controller-related INTERNAL errors\n */\n ROUTER: {\n /** Controller registration error */\n CONTROLLER_REGISTRATION_ERROR: 9005,\n /** Controller method not found */\n CONTROLLER_METHOD_NOT_FOUND: 9006,\n /** OpenAPI route registration failed */\n OPENAPI_ROUTE_REGISTRATION: 9008,\n },\n\n /**\n * I18n Errors (9300-9399)\n * Internationalization and localization errors\n */\n I18N: {\n /** Translation key missing from all locales */\n TRANSLATION_MISSING: 9300,\n /** Requested locale not supported */\n LOCALE_NOT_SUPPORTED: 9301,\n },\n\n /**\n * System Errors (9000-9999)\n * Internal system errors and unexpected failures\n */\n SYSTEM: {\n /** Internal server error */\n INTERNAL_ERROR: 9000,\n\n // Configuration Errors (9100-9199)\n /** Generic configuration error */\n CONFIGURATION_ERROR: 9100,\n /** ConfigService not initialized */\n CONFIG_NOT_INITIALIZED: 9101,\n /** Module already registered */\n MODULE_ALREADY_REGISTERED: 9102,\n /** Circular module dependency detected */\n MODULE_CIRCULAR_DEPENDENCY: 9103,\n /** Module dependency not found */\n MODULE_DEPENDENCY_NOT_FOUND: 9104,\n /** Invalid error code range */\n INVALID_ERROR_CODE_RANGE: 9105,\n /** Invalid module provider configuration */\n INVALID_MODULE_PROVIDER: 9106,\n /** ConfigModule.forRoot() was not called */\n CONFIG_MODULE_NOT_INITIALIZED: 9107,\n\n // Infrastructure Errors (9200-9299)\n /** Generic infrastructure error */\n INFRASTRUCTURE_ERROR: 9200,\n /** Execution context not initialized */\n EXECUTION_CONTEXT_NOT_INITIALIZED: 9201,\n /** Request container not initialized */\n REQUEST_CONTAINER_NOT_INITIALIZED: 9202,\n /** Queue binding not found */\n QUEUE_BINDING_NOT_FOUND: 9203,\n /** Cron job execution failed */\n CRON_EXECUTION_FAILED: 9204,\n /** Queue provider not supported */\n QUEUE_PROVIDER_NOT_SUPPORTED: 9205,\n /** body() called on WebSocket gateway context */\n WEBSOCKET_BODY_NOT_AVAILABLE: 9206,\n /** Duplicate WebSocket event decorator on a gateway */\n WEBSOCKET_DUPLICATE_EVENT_HANDLER: 9207,\n /** Seeder name collision — two seeders share the same class name */\n SEEDER_NAME_COLLISION: 9208,\n /** Seeder not registered in the SeederRegistry */\n SEEDER_NOT_REGISTERED: 9209,\n },\n} as const\n\n/**\n * Recursively extract all leaf values from a nested object type\n * Similar to DeepKeys but extracts values instead of keys\n *\n * Example:\n * { DATABASE: { GENERIC: 2000, NOT_FOUND: 2001 }, AUTH: { INVALID: 3000 } }\n * becomes\n * 2000 | 2001 | 3000\n */\ntype DeepValues<T> = T extends object\n ? { [K in keyof T]: DeepValues<T[K]> }[keyof T]\n : T\n\n/**\n * Type helper to extract all error code values\n * Union type of all numeric error codes defined in ERROR_CODES\n *\n * Type: 2000 | 2001 | 2002 | ... | 9203\n */\nexport type ErrorCode = DeepValues<typeof ERROR_CODES>\n","import type { ContentfulStatusCode } from 'hono/utils/http-status'\nimport { ERROR_CODES } from './error-codes'\n\n/**\n * Maps error codes to HTTP status codes\n *\n * This utility is used by the frontend to set appropriate HTTP status codes\n * when returning errors from API routes.\n *\n * @param code - Numeric error code from ERROR_CODES registry\n * @returns HTTP status code (200-599)\n */\nexport function getHttpStatus(code: number): ContentfulStatusCode {\n // Validation errors (1000-1999) → 400 Bad Request\n if (code >= 1000 && code < 2000) {\n return 400\n }\n\n // Database errors (2000-2999)\n if (code >= 2000 && code < 3000) {\n // Record not found → 404\n if (code === ERROR_CODES.DATABASE.RECORD_NOT_FOUND) return 404\n // Unique constraint / conflict → 409\n if (code === ERROR_CODES.DATABASE.UNIQUE_CONSTRAINT) return 409\n // Other database errors → 500\n return 500\n }\n\n // Authentication errors (3000-3099) → 401 Unauthorized\n if (code >= 3000 && code < 3100) {\n return 401\n }\n\n // Authorization errors (3100-3199) → 403 Forbidden\n if (code >= 3100 && code < 3200) {\n return 403\n }\n\n // Resource not found (4000-4099) → 404 Not Found\n if (code >= 4000 && code < 4100) {\n return 404\n }\n\n // Resource conflict (4100-4199) → 409 Conflict\n if (code >= 4100 && code < 4200) {\n return 409\n }\n\n // Business logic errors (5000-5999)\n if (code >= 5000 && code < 6000) {\n // Domain-specific NOT_FOUND errors → 404\n // 5000: NOTES.NOT_FOUND\n // 5100: USERS.NOT_FOUND\n // 5200: APPLICATIONS.NOT_FOUND\n if (code === 5000 || code === 5100 || code === 5200) {\n return 404\n }\n // Other business logic errors → 422 Unprocessable Entity\n return 422\n }\n\n // System errors (9000-9999) → 500 Internal Server Error\n if (code >= 9000) {\n return 500\n }\n\n // Default to 500 for unknown codes\n return 500\n}\n","/**\n * Dependency injection tokens for the router system\n */\nexport const ROUTER_TOKENS = {\n /**\n * Token for RouterContext (request-scoped)\n * Contains Hono context wrapper with helper methods\n */\n RouterContext: Symbol.for('stratal:router:context'),\n} as const\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\n/**\n * ConditionalBindingFallbackError\n *\n * Thrown when a conditional binding predicate returns false but no fallback\n * implementation was provided and no existing registration exists for the token.\n *\n * This typically indicates a misconfiguration in the DI setup where:\n * - A `when().use().give()` chain was used without `otherwise()`\n * - AND the token wasn't previously registered\n * - AND the predicate evaluated to false at resolution time\n */\nexport class ConditionalBindingFallbackError extends ApplicationError {\n constructor(token: string) {\n super(\n 'errors.conditionalBindingFallback',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { token }\n )\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\n/**\n * RequestScopeOperationNotAllowedError\n *\n * Thrown when attempting to call a method that is not allowed on the current container scope.\n * - `createRequestScope()` and `runInRequestScope()` can only be called on global containers\n */\nexport class RequestScopeOperationNotAllowedError extends ApplicationError {\n constructor(methodName: string) {\n super(\n 'errors.requestScopeOperationNotAllowed',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { methodName }\n )\n }\n}\n","/**\n * Conditional Binding Builder\n *\n * Provides a fluent API for predicate-based service registration.\n * The predicate is evaluated lazily at resolution time using tsyringe's\n * predicateAwareClassFactory.\n *\n * @example With explicit fallback\n * ```typescript\n * container\n * .when((c) => c.resolve(CONFIG_TOKEN).get('env') === 'development')\n * .use(FORMATTER_TOKEN)\n * .give(PrettyFormatter)\n * .otherwise(JsonFormatter)\n * ```\n *\n * @example Without fallback (uses existing registration)\n * ```typescript\n * container\n * .when((c) => c.resolve(FEATURE_FLAG_TOKEN).isEnabled('newFeature'))\n * .use(SERVICE_TOKEN)\n * .give(NewServiceImpl) // Falls back to existing if predicate is false\n * ```\n */\n\nimport type { DependencyContainer } from 'tsyringe'\nimport { predicateAwareClassFactory } from 'tsyringe'\nimport type InjectionToken from 'tsyringe/dist/typings/providers/injection-token'\nimport type { Constructor } from '../types'\nimport { ConditionalBindingFallbackError } from './errors'\nimport type { WhenOptions } from './types'\n\n/**\n * Container interface for predicate functions\n * Using a minimal interface to avoid circular imports\n */\nexport interface PredicateContainer {\n resolve<T>(token: InjectionToken<T>): T\n isRegistered<T>(token: InjectionToken<T>): boolean\n}\n\n/**\n * Initial builder returned by container.when()\n */\nexport interface ConditionalBindingBuilder {\n /**\n * Specify the token to conditionally bind\n *\n * @param token - DI token for the service\n * @returns Builder for specifying implementations\n */\n use<T extends object>(token: InjectionToken<T>): ConditionalBindingUse<T>\n}\n\n/**\n * Builder after specifying token with use()\n */\nexport interface ConditionalBindingUse<T extends object> {\n /**\n * Specify the implementation when predicate returns true.\n * Registration is completed immediately.\n *\n * If predicate is false at resolution time:\n * - Uses `otherwise()` implementation if provided\n * - Falls back to existing registration if available\n * - Throws error if no fallback exists\n *\n * @param implementation - Service class to use when predicate is true\n * @returns Builder for optional fallback specification\n */\n give(implementation: Constructor<T>): ConditionalBindingGive<T>\n}\n\n/**\n * Builder after specifying true implementation with give()\n * Registration is already complete at this point.\n */\nexport interface ConditionalBindingGive<T extends object> {\n /**\n * Optionally specify a fallback implementation when predicate returns false.\n * This re-registers with the explicit fallback instead of existing registration.\n *\n * @param implementation - Service class to use when predicate is false\n */\n otherwise(implementation: Constructor<T>): void\n}\n\n/**\n * Implementation of ConditionalBindingBuilder\n *\n * @internal\n */\nexport class ConditionalBindingBuilderImpl implements ConditionalBindingBuilder {\n constructor(\n private readonly tsyringeContainer: DependencyContainer,\n private readonly predicateContainer: PredicateContainer,\n private readonly predicate: (container: PredicateContainer) => boolean,\n private readonly options: WhenOptions\n ) { }\n\n use<T extends object>(token: InjectionToken<T>): ConditionalBindingUse<T> {\n return new ConditionalBindingUseImpl<T>(\n this.tsyringeContainer,\n this.predicateContainer,\n this.predicate,\n this.options,\n token\n )\n }\n}\n\n/**\n * Implementation of ConditionalBindingUse\n *\n * @internal\n */\nclass ConditionalBindingUseImpl<T extends object> implements ConditionalBindingUse<T> {\n constructor(\n private readonly tsyringeContainer: DependencyContainer,\n private readonly predicateContainer: PredicateContainer,\n private readonly predicate: (container: PredicateContainer) => boolean,\n private readonly options: WhenOptions,\n private readonly token: InjectionToken<T>\n ) { }\n\n give(trueImplementation: Constructor<T>): ConditionalBindingGive<T> {\n // Get fallback: existing registration or a class that throws\n const falseImplementation = this.getFallbackImplementation()\n\n // Register using predicateAwareClassFactory\n this.registerWithPredicate(trueImplementation, falseImplementation)\n\n // Return builder for optional otherwise()\n return {\n otherwise: (implementation: Constructor<T>) => {\n this.registerWithPredicate(trueImplementation, implementation,)\n },\n }\n }\n\n /**\n * Get fallback implementation: existing registration or throw-on-resolve class\n */\n private getFallbackImplementation(): Constructor<T> {\n // Check if token is already registered\n if (this.tsyringeContainer.isRegistered(this.token)) {\n // Create a class that resolves the existing registration\n // We need to capture the current registration before we overwrite it\n const existingInstance = this.tsyringeContainer.resolve<T>(this.token)\n\n // Return a \"class\" that just returns the existing instance\n // Using a factory wrapper since predicateAwareClassFactory expects a constructor\n return class ExistingInstanceWrapper {\n static instance = existingInstance\n constructor() {\n return ExistingInstanceWrapper.instance as unknown as ExistingInstanceWrapper\n }\n } as unknown as Constructor<T>\n }\n\n // No existing registration - create a class that throws\n const tokenStr = typeof this.token === 'symbol'\n ? (this.token.description ?? 'unknown')\n : typeof this.token === 'function'\n ? this.token.name\n // eslint-disable-next-line @typescript-eslint/no-base-to-string -- token can be string or object; String() is intentional fallback\n : String(this.token)\n return class NoFallbackError {\n constructor() {\n throw new ConditionalBindingFallbackError(tokenStr)\n }\n } as unknown as Constructor<T>\n }\n\n private registerWithPredicate(\n trueImplementation: Constructor<T>,\n falseImplementation: Constructor<T>\n ): void {\n const { predicate, predicateContainer, options } = this\n\n this.tsyringeContainer.register(this.token, {\n useFactory: predicateAwareClassFactory<T>(\n () => predicate(predicateContainer),\n trueImplementation,\n falseImplementation,\n options.cache ?? false\n )\n })\n }\n}\n","/**\n * Unified DI Container\n *\n * Provides a developer-friendly wrapper around tsyringe with:\n * - Auto-token extraction from decorator metadata\n * - Auto-scope detection from decorator metadata\n * - Seamless global/request scope interoperability\n * - Request scope lifecycle management\n *\n * **Two-Tier Container Architecture:**\n * ```\n * Global Container (managed by Container)\n * ↓\n * All services registered here\n * (singletons + container-scoped)\n * ↓\n * Request Container (child, per request)\n * ↓\n * Fresh instances for ContainerScoped services\n * RouterContext registered per request\n * ```\n */\nimport { type DependencyContainer, type Lifecycle } from 'tsyringe'\nimport type InjectionToken from 'tsyringe/dist/typings/providers/injection-token'\nimport type { RouterContext } from '../router/router-context'\nimport { ROUTER_TOKENS } from '../router/router.tokens'\nimport type { Constructor } from '../types'\nimport { ConditionalBindingBuilderImpl, type ConditionalBindingBuilder, type PredicateContainer } from './conditional-binding-builder'\nimport { RequestScopeOperationNotAllowedError } from './errors/request-scope-operation-not-allowed.error'\nimport { CONTAINER_TOKEN } from './tokens'\nimport type { ExtensionDecorator, Scope, WhenOptions } from './types'\n\n/**\n * Options for creating a Container instance\n */\nexport interface ContainerOptions {\n /** Pre-created DependencyContainer */\n container: DependencyContainer\n /** Whether this is a request-scoped container */\n isRequestScoped?: boolean\n}\n\n/**\n * Unified Container for DI management\n *\n * Manages the two-tier container hierarchy:\n * - Global scope: Singletons, base instances of request-scoped services\n * - Request scope: Context-enriched instances per HTTP request\n *\n * @example Basic registration\n * ```typescript\n * import { container as tsyringeRootContainer } from 'tsyringe'\n *\n * const container = new Container({\n * container: tsyringeRootContainer.createChildContainer()\n * })\n *\n * container.register(I18nService)\n * container.register(MY_TOKEN, MyService)\n * container.registerSingleton(ConfigService)\n * container.registerValue(MY_TOKEN, myInstance)\n * ```\n *\n * @example Request scope (automatic lifecycle)\n * ```typescript\n * await container.runInRequestScope(routerContext, async (requestContainer) => {\n * const i18n = requestContainer.resolve(I18N_TOKEN)\n * })\n * ```\n */\nexport class Container {\n private readonly container: DependencyContainer\n private readonly isRequestScoped: boolean\n\n constructor(options: ContainerOptions) {\n this.isRequestScoped = options.isRequestScoped ?? false\n this.container = options.container\n\n // Only register CONTAINER_TOKEN for global container (not request-scoped)\n if (!this.isRequestScoped) {\n this.container.register(CONTAINER_TOKEN, { useValue: this })\n }\n }\n\n // ============================================================\n // Registration Methods\n // ============================================================\n\n /**\n * Register a service with optional explicit token and scope\n */\n register<T extends object>(serviceClass: Constructor<T>, scope?: Scope): void\n register<T extends object>(token: InjectionToken<T>, serviceClass: Constructor<T>, scope?: Scope): void\n register<T extends object>(\n tokenOrClass: InjectionToken<T> | Constructor<T>,\n serviceClassOrScope?: Constructor<T> | Scope,\n scope?: Scope\n ): void {\n let token: InjectionToken<T>\n let serviceClass: Constructor<T>\n let lifecycle: Lifecycle | undefined\n\n if (typeof serviceClassOrScope === 'function') {\n // Called as register(token, class, scope?)\n token = tokenOrClass as InjectionToken<T>\n serviceClass = serviceClassOrScope\n lifecycle = scope as Lifecycle | undefined\n } else {\n // Called as register(class, scope?)\n token = tokenOrClass as Constructor<T>\n serviceClass = tokenOrClass as Constructor<T>\n lifecycle = serviceClassOrScope as Lifecycle | undefined\n }\n\n if (lifecycle !== undefined) {\n this.container.register(token, { useClass: serviceClass }, { lifecycle })\n } else {\n this.container.register(token, { useClass: serviceClass })\n }\n }\n\n /**\n * Register a service as singleton\n */\n registerSingleton<T extends object>(serviceClass: Constructor<T>): void\n registerSingleton<T extends object>(token: InjectionToken<T>, serviceClass: Constructor<T>): void\n registerSingleton<T extends object>(\n tokenOrClass: InjectionToken<T> | Constructor<T>,\n serviceClass?: Constructor<T>\n ): void {\n if (serviceClass !== undefined) {\n this.container.registerSingleton(tokenOrClass as InjectionToken<T>, serviceClass)\n } else {\n const targetClass = tokenOrClass as Constructor<T>\n this.container.registerSingleton(targetClass, targetClass)\n }\n }\n\n /**\n * Register a value (instance) directly\n */\n registerValue<T>(token: InjectionToken<T>, value: T): void {\n this.container.register(token, { useValue: value })\n }\n\n /**\n * Register with factory function\n */\n registerFactory<T>(\n token: InjectionToken<T>,\n factory: (container: Container) => T\n ): void {\n this.container.register(token, { useFactory: () => factory(this) })\n }\n\n /**\n * Register an alias to an existing token\n */\n registerExisting<T>(alias: InjectionToken<T>, target: InjectionToken<T>): void {\n this.container.register(alias, { useToken: target })\n }\n\n // ============================================================\n // Resolution Methods\n // ============================================================\n\n /**\n * Resolve a service from the container\n */\n resolve<T>(token: InjectionToken<T>): T {\n return this.container.resolve<T>(token)\n }\n\n /**\n * Check if a token is registered\n */\n isRegistered<T>(token: InjectionToken<T>): boolean {\n return this.container.isRegistered(token)\n }\n\n // ============================================================\n // Conditional Registration Methods\n // ============================================================\n\n /**\n * Start a conditional binding with predicate evaluation\n */\n when(\n predicate: (container: PredicateContainer) => boolean,\n options: WhenOptions = {}\n ): ConditionalBindingBuilder {\n return new ConditionalBindingBuilderImpl(\n this.container,\n this,\n predicate,\n options\n )\n }\n\n /**\n * Replace a service registration with a decorated version\n */\n extend<T>(token: InjectionToken<T>, decorator: ExtensionDecorator<T>): void {\n const currentInstance = this.container.resolve<T>(token)\n const decoratedInstance = decorator(currentInstance, this)\n this.container.register(token, { useValue: decoratedInstance })\n }\n\n // ============================================================\n // Request Scope Management\n // ============================================================\n\n /**\n * Run callback within request scope\n *\n * Creates a child container with fresh instances for services registered with `scope: Scope.Request`.\n * Callback receives the request-scoped container as argument.\n *\n * Can only be called on global container (not request-scoped).\n */\n async runInRequestScope<T>(\n routerContext: RouterContext,\n callback: (requestContainer: Container) => T | Promise<T>\n ): Promise<T> {\n if (this.isRequestScoped) {\n throw new RequestScopeOperationNotAllowedError('runInRequestScope')\n }\n\n const requestContainer = this.createRequestScope(routerContext)\n try {\n return await callback(requestContainer)\n } finally {\n await requestContainer.dispose()\n }\n }\n\n /**\n * Create request scope container\n *\n * Can only be called on global container (not request-scoped).\n */\n createRequestScope(routerContext: RouterContext): Container {\n if (this.isRequestScoped) {\n throw new RequestScopeOperationNotAllowedError('createRequestScope')\n }\n\n const childContainer = this.container.createChildContainer()\n childContainer.register(ROUTER_TOKENS.RouterContext, { useValue: routerContext })\n\n return new Container({ container: childContainer, isRequestScoped: true })\n }\n\n // ============================================================\n // Escape Hatches\n // ============================================================\n\n /**\n * Get underlying tsyringe container\n */\n getTsyringeContainer(): DependencyContainer {\n return this.container\n }\n\n dispose() {\n return this.container.dispose()\n }\n}\n\n// Re-export tsyringe utilities for convenience\nexport { container, delay, inject, injectable, instancePerContainerCachingFactory, singleton } from 'tsyringe'\nexport type { DependencyContainer } from 'tsyringe'\n\n","/**\n * DI Type Definitions\n *\n * Core type definitions for the dependency injection system.\n * Simplified after removing LazyProxy - no more type wrappers needed.\n */\n\nimport { Lifecycle } from 'tsyringe'\nimport type InjectionToken from 'tsyringe/dist/typings/providers/injection-token'\n\n/**\n * Service scope for DI registration\n *\n * Maps directly to tsyringe's Lifecycle enum.\n * Scope is specified at registration time via provider configuration,\n * not at class decoration time.\n *\n * @example\n * ```typescript\n * // In module providers:\n * { provide: MY_TOKEN, useClass: MyService, scope: Scope.Singleton }\n *\n * // In Application.ts:\n * container.register(MY_TOKEN, MyService, Scope.Request)\n * ```\n */\n/* eslint-disable @typescript-eslint/prefer-literal-enum-member -- values must stay in sync with tsyringe Lifecycle */\nexport enum Scope {\n /** New instance per resolution (default) */\n Transient = Lifecycle.Transient,\n /** Single instance shared globally */\n Singleton = Lifecycle.Singleton,\n /** New instance per child container (per request) */\n Request = Lifecycle.ContainerScoped,\n}\n/* eslint-enable @typescript-eslint/prefer-literal-enum-member */\n\n/**\n * Options for conditional binding with `when()` method\n */\nexport interface WhenOptions {\n /**\n * Cache predicate result after first evaluation.\n * When true, the predicate is evaluated once and the result is reused.\n * When false (default), predicate is evaluated on each resolution.\n */\n cache?: boolean\n}\n\n/**\n * Decorator function type for extend() method\n *\n * @template T The service type being decorated\n */\nexport type ExtensionDecorator<T> = (service: T, container: ContainerLike) => T\n\n/**\n * Minimal container interface for decorator functions\n * Avoids circular dependency with Container class\n */\nexport interface ContainerLike {\n resolve<T>(token: InjectionToken<T>): T\n}\n\n","/**\n * I18n Module DI Tokens\n * Symbol-based tokens to avoid string collisions\n */\n\nexport const I18N_TOKENS = {\n /** MessageLoaderService - loads and caches locale messages */\n MessageLoader: Symbol.for('stratal:i18n:message:loader'),\n /** I18nService - request-scoped translation service */\n I18nService: Symbol.for('stratal:i18n:service'),\n /** I18nModuleOptions - configuration options from forRoot() */\n Options: Symbol.for('stratal:i18n:options')\n} as const\n","import { ERROR_CODES } from './error-codes'\nimport { ApplicationError } from './application-error'\n\n/**\n * InternalError\n *\n * Represents an unexpected internal server error.\n * Used to wrap unknown errors that don't fit into specific error categories.\n *\n * This error is thrown when:\n * - An unexpected exception occurs\n * - An error type is not recognized\n * - A system-level failure happens\n */\nexport class InternalError extends ApplicationError {\n constructor(metadata?: Record<string, unknown>) {\n super(\n 'errors.internalError',\n ERROR_CODES.SYSTEM.INTERNAL_ERROR,\n metadata\n )\n }\n}\n","import { ApplicationError } from './application-error'\n\n/**\n * Type guard to check if an error is an ApplicationError\n *\n * @param error - The error to check\n * @returns True if the error is an ApplicationError instance\n */\nexport function isApplicationError(error: unknown): error is ApplicationError {\n return error instanceof ApplicationError\n}\n","import { inject } from 'tsyringe'\nimport { DI_TOKENS } from '../di'\nimport { Transient } from '../di/decorators'\nimport { type StratalEnv } from '../env'\nimport { I18N_TOKENS } from '../i18n/i18n.tokens'\nimport type { II18nService, MessageKeys } from '../i18n/i18n.types'\nimport { LOGGER_TOKENS, type LoggerService } from '../logger'\nimport { ApplicationError } from './application-error'\nimport type { Environment, ErrorResponse } from './error-response'\nimport { InternalError } from './internal-error'\nimport { isApplicationError } from './is-application-error'\n\n/**\n * Log severity levels\n */\ntype LogSeverity = 'error' | 'warn' | 'info'\n\n/**\n * GlobalErrorHandler\n *\n * Centralized error handler registered in the DI container.\n * Responsible for:\n * - Intercepting all errors in the application\n * - Logging errors with appropriate severity via Logger service\n * - Translating error message keys using I18nService (when available)\n * - Serializing errors for RPC transmission\n * - Wrapping unexpected errors in InternalError\n *\n * **Translation Availability by Context:**\n *\n * ✅ **HTTP Requests**: Errors are fully translated\n * - GlobalErrorHandler resolved from request container\n * - I18nService available via AsyncLocalStorage with user's locale\n * - Full translation with parameter interpolation\n *\n * ✅ **Queue Processing**: Errors are fully translated\n * - Error handling executes inside AsyncLocalStorage scope\n * - Locale extracted from queue message metadata\n * - Request container created with mock RouterContext\n * - I18nService available with correct locale\n *\n * ⚠️ **RPC/Startup**: Message keys returned as-is (i18n unavailable)\n * - No request context available during service binding or startup\n * - No locale information available\n * - Frontend can translate message keys using its own i18n if needed\n * - This is expected behavior, not a bug\n *\n * **Implementation Note:**\n * The `isAvailable()` check exists to gracefully handle RPC/startup contexts\n * where no request container exists. For HTTP and Queue contexts, i18n is\n * always available thanks to AsyncLocalStorage scope propagation. This follows\n * the \"Laravel philosophy\" - transparent dependency injection for request contexts,\n * with explicit handling only for legitimate non-request edge cases.\n */\n@Transient()\nexport class GlobalErrorHandler {\n private readonly environment: Environment\n constructor(\n @inject(LOGGER_TOKENS.LoggerService) private readonly logger: LoggerService,\n @inject(I18N_TOKENS.I18nService) private readonly i18n: II18nService,\n @inject(DI_TOKENS.CloudflareEnv)\n private readonly env: StratalEnv,\n ) {\n this.environment = this.env.ENVIRONMENT as Environment\n }\n\n /**\n * Handle an error, log it, and serialize for response\n *\n * @param error - The error to handle\n * @returns Serialized ErrorResponse for RPC transmission\n */\n handle(error: unknown): ErrorResponse {\n // Check if it's an ApplicationError\n if (isApplicationError(error)) {\n // Translate once, use for both logging and response\n const translatedMessage = this.translateError(error)\n\n this.log(error, translatedMessage)\n\n return error.toErrorResponse(this.environment, translatedMessage)\n }\n\n // Unexpected error - wrap in InternalError\n this.logUnexpectedError(error)\n\n const internalError = new InternalError({\n originalError: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n })\n\n const translatedMessage = this.translateError(internalError)\n\n return internalError.toErrorResponse(this.environment, translatedMessage)\n }\n\n /**\n * Translate error message key using I18nService\n * Uses error metadata as interpolation parameters\n *\n * No try/catch - if translation fails, it's a bug that should fail loudly\n *\n * **Note**: This method is only called when isAvailable() returns true,\n * so the service is guaranteed to be resolved.\n *\n * @param error - ApplicationError with messageKey and metadata\n * @returns Translated message string\n */\n private translateError(error: ApplicationError): string {\n // Cast metadata to MessageParams (assuming values are string | number)\n const params = error.metadata as Record<string, string | number> | undefined\n return this.i18n.t(error.message as MessageKeys, params)\n }\n\n /**\n * Log an ApplicationError with appropriate severity\n */\n private log(error: ApplicationError, translatedMessage: string): void {\n const severity = this.getSeverity(error.code)\n\n const logData = {\n code: error.code,\n message: translatedMessage,\n timestamp: error.timestamp,\n metadata: error.metadata,\n name: error.name,\n }\n\n switch (severity) {\n case 'error':\n this.logger.error('[ApplicationError]', logData)\n break\n case 'warn':\n this.logger.warn('[ApplicationError]', logData)\n break\n case 'info':\n this.logger.info('[ApplicationError]', logData)\n break\n }\n }\n\n /**\n * Log an unexpected error\n */\n private logUnexpectedError(error: unknown): void {\n this.logger.error('[UnexpectedError]', {\n error: error instanceof Error ? {\n message: error.message,\n stack: error.stack,\n name: error.name,\n } : String(error),\n timestamp: new Date().toISOString(),\n })\n }\n\n /**\n * Determine log severity based on error code\n */\n private getSeverity(code: number): LogSeverity {\n // System errors (9000+) are critical\n if (code >= 9000) return 'error'\n\n // Database errors (2000-2999) are errors\n if (code >= 2000 && code < 3000) return 'error'\n\n // Business logic errors (5000-5999) are warnings\n if (code >= 5000 && code < 6000) return 'warn'\n\n // Validation errors (1000-1999) are info\n if (code >= 1000 && code < 2000) return 'info'\n\n // Auth/Resource errors (3000-4999) are warnings\n if (code >= 3000 && code < 5000) return 'warn'\n\n // Default to error\n return 'error'\n }\n}\n","import { ApplicationError } from './application-error'\nimport { ERROR_CODES } from './error-codes'\n\n/**\n * RequestContainerNotInitializedError\n *\n * Thrown when attempting to access the request-scoped container before it has been initialized.\n * This typically indicates that the RouterService middleware hasn't run yet,\n * or the router context is being accessed outside of a request lifecycle.\n */\nexport class RequestContainerNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.requestContainerNotInitialized',\n ERROR_CODES.SYSTEM.REQUEST_CONTAINER_NOT_INITIALIZED\n )\n }\n}\n","import { ApplicationError } from './application-error'\nimport { ERROR_CODES } from './error-codes'\n\n/**\n * StratalNotInitializedError\n *\n * Thrown when attempting to resolve the Application instance before Stratal has been instantiated.\n * This typically indicates that the Stratal instance is not exported as the default export.\n */\nexport class StratalNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.stratalNotInitialized',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAsB,mBAAtB,MAAsB,yBAAyB,MAAM;;;;;;CAMnD,OAAO,qBAAqB;;;;;CAM5B;;;;CAKA;;;;;;;CAQA;;;;;;CAOA,YACE,SACA,MACA,UACA;AAEA,QAAM,QAAQ;AAGd,SAAO,eAAe,MAAM,IAAI,OAAO,UAAU;AAEjD,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,OAAO;AACZ,OAAK,6BAAY,IAAI,MAAM,EAAC,aAAa;AACzC,OAAK,WAAW;AAKhB,MAAI,iBAAiB,sBAAsB,MAAM,kBAC/C,OAAM,kBAAkB,MAAM,KAAK,YAAY;;;;;;;;;;;;;;;;;;CAoBnD,OAAe,eACb,UACqC;AACrC,MAAI,CAAC,SAAU,QAAO,KAAA;EAGtB,MAAM,YAAY;GAAC;GAAU;GAAU;GAAQ;EAE/C,MAAM,WAAoC,EAAE;EAC5C,IAAI,oBAAoB;AAExB,OAAK,MAAM,OAAO,UAChB,KAAI,OAAO,YAAY,SAAS,SAAS,KAAA,GAAW;AAClD,YAAS,OAAO,SAAS;AACzB,uBAAoB;;AAKxB,SAAO,oBAAoB,WAAW,KAAA;;;;;;;;;CAUxC,gBAAgB,KAAkB,mBAA2C;EAC3E,MAAM,UAAU,qBAAqB,KAAK;AAE1C,SAAO;GACL,MAAM,KAAK;GACX;GACA,WAAW,KAAK;GAEhB,UAAU,iBAAiB,eAAe,KAAK,SAAS;GAGxD,OAAO,QAAQ,gBACX,KAAK,OAAO,QAAQ,KAAK,SAAS,Q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AAO,YAAY,YAAY,CAAA;oBAC/B,OAAO,UAAU,cAAc,CAAA;;;;;;;;;;;;;;;;AClDpC,IAAa,sCAAb,cAAyD,iBAAiB;CACxE,cAAc;AACZ,QACE,yCACA,YAAY,OAAO,kCACpB;;;;;;;;;;;ACNL,IAAa,6BAAb,cAAgD,iBAAiB;CAC/D,cAAc;AACZ,QACE,gCACA,YAAY,OAAO,qBACpB"}
1
+ {"version":3,"file":"errors-DSKapqD8.mjs","names":[],"sources":["../src/errors/application-error.ts","../src/errors/error-response.ts","../src/errors/error-codes.ts","../src/errors/get-http-status.ts","../src/router/router.tokens.ts","../src/di/errors/conditional-binding-fallback.error.ts","../src/di/errors/request-scope-operation-not-allowed.error.ts","../src/di/conditional-binding-builder.ts","../src/di/container.ts","../src/di/types.ts","../src/i18n/i18n.tokens.ts","../src/errors/internal-error.ts","../src/errors/is-application-error.ts","../src/errors/global-error-handler.ts","../src/errors/request-container-not-initialized.error.ts","../src/errors/stratal-not-initialized.error.ts"],"sourcesContent":["import type { Environment, ErrorResponse } from './error-response'\nimport type { MessageKeys } from '../i18n'\nimport type { ErrorCode } from './error-codes'\n\n/**\n * ApplicationError\n *\n * Abstract base class for all application errors.\n * This class should never be used directly - always extend it to create specific error types.\n *\n * Features:\n * - Type-safe error codes from ERROR_CODES registry\n * - Type-safe message keys from i18n module\n * - Localized message keys (translated by GlobalErrorHandler)\n * - Structured metadata for logging and interpolation\n * - Proper Error prototype chain\n * - Automatic timestamp generation\n * - Serialization for RPC transmission\n *\n * Message Localization:\n * - Each error class passes an i18n key (e.g., 'errors.userNotFound') to super()\n * - `Error.message` contains the i18n key for useful stack traces and fallback display\n * - Metadata provides interpolation parameters (e.g., { userId: '123' })\n * - GlobalErrorHandler translates the message key using I18nService before sending response\n * - This ensures errors are localized based on the user's locale (from X-Locale header)\n */\nexport abstract class ApplicationError extends Error {\n /**\n * Controls whether stack traces are captured.\n * Set to false in production to skip the expensive Error.captureStackTrace() call,\n * since stack traces are stripped from responses in production anyway.\n */\n static captureStackTraces = true\n\n /**\n * Type-safe error code from ERROR_CODES registry\n * See error-codes.ts for the complete registry\n */\n public readonly code: ErrorCode\n\n /**\n * ISO timestamp when the error was created\n */\n public readonly timestamp: string\n\n /**\n * Additional structured data about the error\n * Used for:\n * 1. Logging and debugging\n * 2. Message interpolation (e.g., { userId: '123', email: 'user@example.com' })\n */\n public readonly metadata?: Record<string, unknown>\n\n /**\n * @param i18nKey - Type-safe i18n message key (e.g., 'errors.userNotFound')\n * @param code - Type-safe error code from ERROR_CODES registry\n * @param metadata - Optional data for logging and interpolation\n */\n constructor(\n i18nKey: MessageKeys,\n code: ErrorCode,\n metadata?: Record<string, unknown>\n ) {\n // Pass i18nKey to Error.message for useful stack traces (e.g., \"InternalError: errors.internalError\")\n super(i18nKey)\n\n // Maintains proper prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype)\n\n this.name = this.constructor.name\n this.code = code\n this.timestamp = new Date().toISOString()\n this.metadata = metadata\n\n // Capture stack trace, excluding constructor call from it\n // Skip in production where stack traces are stripped from responses anyway\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- captureStackTrace is V8-specific, not always present\n if (ApplicationError.captureStackTraces && Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor)\n }\n }\n\n /**\n * Filter metadata to include only user-facing properties\n *\n * User-facing properties (validation/constraint errors):\n * - issues: Validation errors from SchemaValidationError\n * - fields: Constraint violation fields\n * - field: Single field constraint/foreign key\n *\n * Internal properties (excluded from response):\n * - path, method: Route debugging\n * - controllerName, reason: Controller errors\n * - details, etc.: Internal debugging info\n *\n * @param metadata - Raw metadata object\n * @returns Filtered metadata with only whitelisted properties\n */\n private static filterMetadata(\n metadata?: Record<string, unknown>\n ): Record<string, unknown> | undefined {\n if (!metadata) return undefined\n\n // Whitelist of user-facing metadata properties\n const whitelist = ['issues', 'fields', 'field']\n\n const filtered: Record<string, unknown> = {}\n let hasUserFacingData = false\n\n for (const key of whitelist) {\n if (key in metadata && metadata[key] !== undefined) {\n filtered[key] = metadata[key]\n hasUserFacingData = true\n }\n }\n\n // Only return metadata if there's actual user-facing data\n return hasUserFacingData ? filtered : undefined\n }\n\n /**\n * Serialize error to ErrorResponse format for RPC transmission\n *\n * @param env - Environment (development | production)\n * @param translatedMessage - Optional translated message (from GlobalErrorHandler)\n * @returns ErrorResponse object suitable for JSON serialization\n */\n toErrorResponse(env: Environment, translatedMessage?: string): ErrorResponse {\n const message = translatedMessage ?? this.message\n\n return {\n code: this.code,\n message,\n timestamp: this.timestamp,\n // Include filtered user-facing metadata in all environments\n metadata: ApplicationError.filterMetadata(this.metadata),\n // Stack trace only in development for debugging\n // Rewrite first line with translated message for readable debugging\n stack: env === 'development'\n ? this.stack?.replace(this.message, message)\n : undefined,\n }\n }\n\n /**\n * JSON serialization (used by JSON.stringify)\n * Defaults to development mode for backward compatibility\n * Note: This will use the untranslated message key - use GlobalErrorHandler for proper localization\n */\n toJSON(): ErrorResponse {\n return this.toErrorResponse('development')\n }\n}\n","export type Environment = 'development' | 'staging' | 'production'\n\nexport interface ErrorResponse {\n /**\n * Numeric error code for identification and escalation\n * See error-codes.ts for the complete registry\n */\n code: number\n\n /**\n * Human-readable error message\n * Fixed per error type, not customizable\n */\n message: string\n\n /**\n * ISO timestamp when the error occurred\n */\n timestamp: string\n\n /**\n * Additional structured data about the error\n * Only included in development environment\n */\n metadata?: Record<string, unknown>\n\n /**\n * Stack trace for debugging\n * Only included in development environment\n */\n stack?: string\n}\n\n/**\n * Type guard to check if an object is an ErrorResponse\n */\nexport function isErrorResponse(obj: unknown): obj is ErrorResponse {\n return (\n typeof obj === 'object' &&\n obj !== null &&\n 'code' in obj &&\n typeof (obj as ErrorResponse).code === 'number' &&\n 'message' in obj &&\n typeof (obj as ErrorResponse).message === 'string' &&\n 'timestamp' in obj &&\n typeof (obj as ErrorResponse).timestamp === 'string'\n )\n}\n","/**\n * Centralized Error Code Registry\n *\n * Error codes are organized by category with specific ranges:\n * - 1000-1999: Validation errors\n * - 2000-2999: Database errors (generic)\n * - 3000-3999: Authentication & Authorization\n * - 4000-4999: Resource errors\n * - 5000-5999: Domain-specific business logic (per module)\n * - 9000-9999: System/Internal errors\n * - 9000-9099: Router errors\n * - 9100-9199: Configuration errors\n * - 9200-9299: Infrastructure errors\n * - 9300-9399: I18n errors\n */\n\nexport const ERROR_CODES = {\n /**\n * Database Errors (2000-2999)\n * Generic database errors thrown by Prisma client extensions\n */\n DATABASE: {\n /** Generic database error */\n GENERIC: 2000,\n /** Record not found in database */\n RECORD_NOT_FOUND: 2001,\n /** Unique constraint violation */\n UNIQUE_CONSTRAINT: 2002,\n /** Foreign key constraint violation */\n FOREIGN_KEY_CONSTRAINT: 2003,\n /** Database connection failed */\n CONNECTION_FAILED: 2004,\n /** Database timeout */\n TIMEOUT: 2005,\n /** Null constraint violation */\n NULL_CONSTRAINT: 2006,\n /** Too many database connections */\n TOO_MANY_CONNECTIONS: 2007,\n /** Transaction conflict or deadlock */\n TRANSACTION_CONFLICT: 2008,\n },\n\n /**\n * Authentication Errors (3000-3099)\n * Authentication-related failures\n */\n AUTH: {\n /** Invalid credentials provided */\n INVALID_CREDENTIALS: 3000,\n /** Session expired or invalid */\n SESSION_EXPIRED: 3001,\n /** Account locked or disabled */\n ACCOUNT_LOCKED: 3002,\n /** Invalid or expired token */\n INVALID_TOKEN: 3003,\n /** Context not initialized */\n CONTEXT_NOT_INITIALIZED: 3004,\n /** User not authenticated */\n USER_NOT_AUTHENTICATED: 3005,\n /** Email verification required before login */\n EMAIL_NOT_VERIFIED: 3007,\n /** Password doesn't meet minimum length */\n PASSWORD_TOO_SHORT: 3008,\n /** Password exceeds maximum length */\n PASSWORD_TOO_LONG: 3009,\n /** Account with email already exists */\n ACCOUNT_ALREADY_EXISTS: 3010,\n /** User creation failed */\n FAILED_TO_CREATE_USER: 3011,\n /** Session creation failed */\n FAILED_TO_CREATE_SESSION: 3012,\n /** User update failed */\n FAILED_TO_UPDATE_USER: 3013,\n /** Social account already linked */\n SOCIAL_ACCOUNT_LINKED: 3014,\n /** Last account cannot be unlinked */\n CANNOT_UNLINK_LAST_ACCOUNT: 3015,\n },\n\n /**\n * Authorization Errors (3100-3199)\n * Permission and access control failures\n */\n AUTHZ: {\n /** Insufficient permissions */\n FORBIDDEN: 3100,\n /** Resource access denied */\n ACCESS_DENIED: 3101,\n /** User lacks required role */\n INSUFFICIENT_PERMISSIONS: 3102,\n },\n\n /**\n * Resource Errors (4000-4999)\n * Generic resource-related errors\n */\n RESOURCE: {\n /** Generic resource not found */\n NOT_FOUND: 4000,\n /** Route/endpoint not found */\n ROUTE_NOT_FOUND: 4004,\n /** Resource conflict or duplicate */\n CONFLICT: 4100,\n /** Resource already exists */\n ALREADY_EXISTS: 4101,\n },\n\n /**\n * Validation Errors (1000-1999)\n * Input validation failures\n */\n VALIDATION: {\n /** Generic validation error */\n GENERIC: 1000,\n /** Required field missing */\n REQUIRED_FIELD: 1001,\n /** Invalid format */\n INVALID_FORMAT: 1002,\n /** Schema validation failed */\n SCHEMA_VALIDATION: 1003,\n /** Request validation failed (OpenAPI, etc.) */\n REQUEST_VALIDATION: 1004,\n },\n\n /**\n * Router Errors (9000-9099)\n * Router and controller-related INTERNAL errors\n */\n ROUTER: {\n /** Controller registration error */\n CONTROLLER_REGISTRATION_ERROR: 9005,\n /** Controller method not found */\n CONTROLLER_METHOD_NOT_FOUND: 9006,\n /** OpenAPI route registration failed */\n OPENAPI_ROUTE_REGISTRATION: 9008,\n },\n\n /**\n * I18n Errors (9300-9399)\n * Internationalization and localization errors\n */\n I18N: {\n /** Translation key missing from all locales */\n TRANSLATION_MISSING: 9300,\n /** Requested locale not supported */\n LOCALE_NOT_SUPPORTED: 9301,\n },\n\n /**\n * System Errors (9000-9999)\n * Internal system errors and unexpected failures\n */\n SYSTEM: {\n /** Internal server error */\n INTERNAL_ERROR: 9000,\n\n // Configuration Errors (9100-9199)\n /** Generic configuration error */\n CONFIGURATION_ERROR: 9100,\n /** ConfigService not initialized */\n CONFIG_NOT_INITIALIZED: 9101,\n /** Module already registered */\n MODULE_ALREADY_REGISTERED: 9102,\n /** Circular module dependency detected */\n MODULE_CIRCULAR_DEPENDENCY: 9103,\n /** Module dependency not found */\n MODULE_DEPENDENCY_NOT_FOUND: 9104,\n /** Invalid error code range */\n INVALID_ERROR_CODE_RANGE: 9105,\n /** Invalid module provider configuration */\n INVALID_MODULE_PROVIDER: 9106,\n /** ConfigModule.forRoot() was not called */\n CONFIG_MODULE_NOT_INITIALIZED: 9107,\n\n // Infrastructure Errors (9200-9299)\n /** Generic infrastructure error */\n INFRASTRUCTURE_ERROR: 9200,\n /** Execution context not initialized */\n EXECUTION_CONTEXT_NOT_INITIALIZED: 9201,\n /** Request container not initialized */\n REQUEST_CONTAINER_NOT_INITIALIZED: 9202,\n /** Queue binding not found */\n QUEUE_BINDING_NOT_FOUND: 9203,\n /** Cron job execution failed */\n CRON_EXECUTION_FAILED: 9204,\n /** Queue provider not supported */\n QUEUE_PROVIDER_NOT_SUPPORTED: 9205,\n /** body() called on WebSocket gateway context */\n WEBSOCKET_BODY_NOT_AVAILABLE: 9206,\n /** Duplicate WebSocket event decorator on a gateway */\n WEBSOCKET_DUPLICATE_EVENT_HANDLER: 9207,\n /** Seeder name collision — two seeders share the same class name */\n SEEDER_NAME_COLLISION: 9208,\n /** Seeder not registered in the SeederRegistry */\n SEEDER_NOT_REGISTERED: 9209,\n },\n} as const\n\n/**\n * Recursively extract all leaf values from a nested object type\n * Similar to DeepKeys but extracts values instead of keys\n *\n * Example:\n * { DATABASE: { GENERIC: 2000, NOT_FOUND: 2001 }, AUTH: { INVALID: 3000 } }\n * becomes\n * 2000 | 2001 | 3000\n */\ntype DeepValues<T> = T extends object\n ? { [K in keyof T]: DeepValues<T[K]> }[keyof T]\n : T\n\n/**\n * Type helper to extract all error code values\n * Union type of all numeric error codes defined in ERROR_CODES\n *\n * Type: 2000 | 2001 | 2002 | ... | 9203\n */\nexport type ErrorCode = DeepValues<typeof ERROR_CODES>\n","import type { ContentfulStatusCode } from 'hono/utils/http-status'\nimport { ERROR_CODES } from './error-codes'\n\n/**\n * Maps error codes to HTTP status codes\n *\n * This utility is used by the frontend to set appropriate HTTP status codes\n * when returning errors from API routes.\n *\n * @param code - Numeric error code from ERROR_CODES registry\n * @returns HTTP status code (200-599)\n */\nexport function getHttpStatus(code: number): ContentfulStatusCode {\n // Validation errors (1000-1999) → 400 Bad Request\n if (code >= 1000 && code < 2000) {\n return 400\n }\n\n // Database errors (2000-2999)\n if (code >= 2000 && code < 3000) {\n // Record not found → 404\n if (code === ERROR_CODES.DATABASE.RECORD_NOT_FOUND) return 404\n // Unique constraint / conflict → 409\n if (code === ERROR_CODES.DATABASE.UNIQUE_CONSTRAINT) return 409\n // Other database errors → 500\n return 500\n }\n\n // Authentication errors (3000-3099) → 401 Unauthorized\n if (code >= 3000 && code < 3100) {\n return 401\n }\n\n // Authorization errors (3100-3199) → 403 Forbidden\n if (code >= 3100 && code < 3200) {\n return 403\n }\n\n // Resource not found (4000-4099) → 404 Not Found\n if (code >= 4000 && code < 4100) {\n return 404\n }\n\n // Resource conflict (4100-4199) → 409 Conflict\n if (code >= 4100 && code < 4200) {\n return 409\n }\n\n // Business logic errors (5000-5999)\n if (code >= 5000 && code < 6000) {\n // Domain-specific NOT_FOUND errors → 404\n // 5000: NOTES.NOT_FOUND\n // 5100: USERS.NOT_FOUND\n // 5200: APPLICATIONS.NOT_FOUND\n if (code === 5000 || code === 5100 || code === 5200) {\n return 404\n }\n // Other business logic errors → 422 Unprocessable Entity\n return 422\n }\n\n // System errors (9000-9999) → 500 Internal Server Error\n if (code >= 9000) {\n return 500\n }\n\n // Default to 500 for unknown codes\n return 500\n}\n","/**\n * Dependency injection tokens for the router system\n */\nexport const ROUTER_TOKENS = {\n /**\n * Token for RouterContext (request-scoped)\n * Contains Hono context wrapper with helper methods\n */\n RouterContext: Symbol.for('stratal:router:context'),\n} as const\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\n/**\n * ConditionalBindingFallbackError\n *\n * Thrown when a conditional binding predicate returns false but no fallback\n * implementation was provided and no existing registration exists for the token.\n *\n * This typically indicates a misconfiguration in the DI setup where:\n * - A `when().use().give()` chain was used without `otherwise()`\n * - AND the token wasn't previously registered\n * - AND the predicate evaluated to false at resolution time\n */\nexport class ConditionalBindingFallbackError extends ApplicationError {\n constructor(token: string) {\n super(\n 'errors.conditionalBindingFallback',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { token }\n )\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\n/**\n * RequestScopeOperationNotAllowedError\n *\n * Thrown when attempting to call a method that is not allowed on the current container scope.\n * - `createRequestScope()` and `runInRequestScope()` can only be called on global containers\n */\nexport class RequestScopeOperationNotAllowedError extends ApplicationError {\n constructor(methodName: string) {\n super(\n 'errors.requestScopeOperationNotAllowed',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { methodName }\n )\n }\n}\n","/**\n * Conditional Binding Builder\n *\n * Provides a fluent API for predicate-based service registration.\n * The predicate is evaluated lazily at resolution time using tsyringe's\n * predicateAwareClassFactory.\n *\n * @example With explicit fallback\n * ```typescript\n * container\n * .when((c) => c.resolve(CONFIG_TOKEN).get('env') === 'development')\n * .use(FORMATTER_TOKEN)\n * .give(PrettyFormatter)\n * .otherwise(JsonFormatter)\n * ```\n *\n * @example Without fallback (uses existing registration)\n * ```typescript\n * container\n * .when((c) => c.resolve(FEATURE_FLAG_TOKEN).isEnabled('newFeature'))\n * .use(SERVICE_TOKEN)\n * .give(NewServiceImpl) // Falls back to existing if predicate is false\n * ```\n */\n\nimport type { DependencyContainer } from 'tsyringe'\nimport { predicateAwareClassFactory } from 'tsyringe'\nimport type InjectionToken from 'tsyringe/dist/typings/providers/injection-token'\nimport type { Constructor } from '../types'\nimport { ConditionalBindingFallbackError } from './errors'\nimport type { WhenOptions } from './types'\n\n/**\n * Container interface for predicate functions\n * Using a minimal interface to avoid circular imports\n */\nexport interface PredicateContainer {\n resolve<T>(token: InjectionToken<T>): T\n isRegistered<T>(token: InjectionToken<T>): boolean\n}\n\n/**\n * Initial builder returned by container.when()\n */\nexport interface ConditionalBindingBuilder {\n /**\n * Specify the token to conditionally bind\n *\n * @param token - DI token for the service\n * @returns Builder for specifying implementations\n */\n use<T extends object>(token: InjectionToken<T>): ConditionalBindingUse<T>\n}\n\n/**\n * Builder after specifying token with use()\n */\nexport interface ConditionalBindingUse<T extends object> {\n /**\n * Specify the implementation when predicate returns true.\n * Registration is completed immediately.\n *\n * If predicate is false at resolution time:\n * - Uses `otherwise()` implementation if provided\n * - Falls back to existing registration if available\n * - Throws error if no fallback exists\n *\n * @param implementation - Service class to use when predicate is true\n * @returns Builder for optional fallback specification\n */\n give(implementation: Constructor<T>): ConditionalBindingGive<T>\n}\n\n/**\n * Builder after specifying true implementation with give()\n * Registration is already complete at this point.\n */\nexport interface ConditionalBindingGive<T extends object> {\n /**\n * Optionally specify a fallback implementation when predicate returns false.\n * This re-registers with the explicit fallback instead of existing registration.\n *\n * @param implementation - Service class to use when predicate is false\n */\n otherwise(implementation: Constructor<T>): void\n}\n\n/**\n * Implementation of ConditionalBindingBuilder\n *\n * @internal\n */\nexport class ConditionalBindingBuilderImpl implements ConditionalBindingBuilder {\n constructor(\n private readonly tsyringeContainer: DependencyContainer,\n private readonly predicateContainer: PredicateContainer,\n private readonly predicate: (container: PredicateContainer) => boolean,\n private readonly options: WhenOptions\n ) { }\n\n use<T extends object>(token: InjectionToken<T>): ConditionalBindingUse<T> {\n return new ConditionalBindingUseImpl<T>(\n this.tsyringeContainer,\n this.predicateContainer,\n this.predicate,\n this.options,\n token\n )\n }\n}\n\n/**\n * Implementation of ConditionalBindingUse\n *\n * @internal\n */\nclass ConditionalBindingUseImpl<T extends object> implements ConditionalBindingUse<T> {\n constructor(\n private readonly tsyringeContainer: DependencyContainer,\n private readonly predicateContainer: PredicateContainer,\n private readonly predicate: (container: PredicateContainer) => boolean,\n private readonly options: WhenOptions,\n private readonly token: InjectionToken<T>\n ) { }\n\n give(trueImplementation: Constructor<T>): ConditionalBindingGive<T> {\n // Get fallback: existing registration or a class that throws\n const falseImplementation = this.getFallbackImplementation()\n\n // Register using predicateAwareClassFactory\n this.registerWithPredicate(trueImplementation, falseImplementation)\n\n // Return builder for optional otherwise()\n return {\n otherwise: (implementation: Constructor<T>) => {\n this.registerWithPredicate(trueImplementation, implementation,)\n },\n }\n }\n\n /**\n * Get fallback implementation: existing registration or throw-on-resolve class\n */\n private getFallbackImplementation(): Constructor<T> {\n // Check if token is already registered\n if (this.tsyringeContainer.isRegistered(this.token)) {\n // Create a class that resolves the existing registration\n // We need to capture the current registration before we overwrite it\n const existingInstance = this.tsyringeContainer.resolve<T>(this.token)\n\n // Return a \"class\" that just returns the existing instance\n // Using a factory wrapper since predicateAwareClassFactory expects a constructor\n return class ExistingInstanceWrapper {\n static instance = existingInstance\n constructor() {\n return ExistingInstanceWrapper.instance as unknown as ExistingInstanceWrapper\n }\n } as unknown as Constructor<T>\n }\n\n // No existing registration - create a class that throws\n const tokenStr = typeof this.token === 'symbol'\n ? (this.token.description ?? 'unknown')\n : typeof this.token === 'function'\n ? this.token.name\n // eslint-disable-next-line @typescript-eslint/no-base-to-string -- token can be string or object; String() is intentional fallback\n : String(this.token)\n return class NoFallbackError {\n constructor() {\n throw new ConditionalBindingFallbackError(tokenStr)\n }\n } as unknown as Constructor<T>\n }\n\n private registerWithPredicate(\n trueImplementation: Constructor<T>,\n falseImplementation: Constructor<T>\n ): void {\n const { predicate, predicateContainer, options } = this\n\n this.tsyringeContainer.register(this.token, {\n useFactory: predicateAwareClassFactory<T>(\n () => predicate(predicateContainer),\n trueImplementation,\n falseImplementation,\n options.cache ?? false\n )\n })\n }\n}\n","/**\n * Unified DI Container\n *\n * Provides a developer-friendly wrapper around tsyringe with:\n * - Auto-token extraction from decorator metadata\n * - Auto-scope detection from decorator metadata\n * - Seamless global/request scope interoperability\n * - Request scope lifecycle management\n *\n * **Two-Tier Container Architecture:**\n * ```\n * Global Container (managed by Container)\n * ↓\n * All services registered here\n * (singletons + container-scoped)\n * ↓\n * Request Container (child, per request)\n * ↓\n * Fresh instances for ContainerScoped services\n * RouterContext registered per request\n * ```\n */\nimport { type DependencyContainer, type Lifecycle } from 'tsyringe'\nimport type InjectionToken from 'tsyringe/dist/typings/providers/injection-token'\nimport type { RouterContext } from '../router/router-context'\nimport { ROUTER_TOKENS } from '../router/router.tokens'\nimport type { Constructor } from '../types'\nimport { ConditionalBindingBuilderImpl, type ConditionalBindingBuilder, type PredicateContainer } from './conditional-binding-builder'\nimport { RequestScopeOperationNotAllowedError } from './errors/request-scope-operation-not-allowed.error'\nimport { CONTAINER_TOKEN } from './tokens'\nimport type { ExtensionDecorator, Scope, WhenOptions } from './types'\n\n/**\n * Options for creating a Container instance\n */\nexport interface ContainerOptions {\n /** Pre-created DependencyContainer */\n container: DependencyContainer\n /** Whether this is a request-scoped container */\n isRequestScoped?: boolean\n}\n\n/**\n * Unified Container for DI management\n *\n * Manages the two-tier container hierarchy:\n * - Global scope: Singletons, base instances of request-scoped services\n * - Request scope: Context-enriched instances per HTTP request\n *\n * @example Basic registration\n * ```typescript\n * import { container as tsyringeRootContainer } from 'tsyringe'\n *\n * const container = new Container({\n * container: tsyringeRootContainer.createChildContainer()\n * })\n *\n * container.register(I18nService)\n * container.register(MY_TOKEN, MyService)\n * container.registerSingleton(ConfigService)\n * container.registerValue(MY_TOKEN, myInstance)\n * ```\n *\n * @example Request scope (automatic lifecycle)\n * ```typescript\n * await container.runInRequestScope(routerContext, async (requestContainer) => {\n * const i18n = requestContainer.resolve(I18N_TOKEN)\n * })\n * ```\n */\nexport class Container {\n private readonly container: DependencyContainer\n private readonly isRequestScoped: boolean\n\n constructor(options: ContainerOptions) {\n this.isRequestScoped = options.isRequestScoped ?? false\n this.container = options.container\n\n // Only register CONTAINER_TOKEN for global container (not request-scoped)\n if (!this.isRequestScoped) {\n this.container.register(CONTAINER_TOKEN, { useValue: this })\n }\n }\n\n // ============================================================\n // Registration Methods\n // ============================================================\n\n /**\n * Register a service with optional explicit token and scope\n */\n register<T extends object>(serviceClass: Constructor<T>, scope?: Scope): void\n register<T extends object>(token: InjectionToken<T>, serviceClass: Constructor<T>, scope?: Scope): void\n register<T extends object>(\n tokenOrClass: InjectionToken<T> | Constructor<T>,\n serviceClassOrScope?: Constructor<T> | Scope,\n scope?: Scope\n ): void {\n let token: InjectionToken<T>\n let serviceClass: Constructor<T>\n let lifecycle: Lifecycle | undefined\n\n if (typeof serviceClassOrScope === 'function') {\n // Called as register(token, class, scope?)\n token = tokenOrClass as InjectionToken<T>\n serviceClass = serviceClassOrScope\n lifecycle = scope as Lifecycle | undefined\n } else {\n // Called as register(class, scope?)\n token = tokenOrClass as Constructor<T>\n serviceClass = tokenOrClass as Constructor<T>\n lifecycle = serviceClassOrScope as Lifecycle | undefined\n }\n\n if (lifecycle !== undefined) {\n this.container.register(token, { useClass: serviceClass }, { lifecycle })\n } else {\n this.container.register(token, { useClass: serviceClass })\n }\n }\n\n /**\n * Register a service as singleton\n */\n registerSingleton<T extends object>(serviceClass: Constructor<T>): void\n registerSingleton<T extends object>(token: InjectionToken<T>, serviceClass: Constructor<T>): void\n registerSingleton<T extends object>(\n tokenOrClass: InjectionToken<T> | Constructor<T>,\n serviceClass?: Constructor<T>\n ): void {\n if (serviceClass !== undefined) {\n this.container.registerSingleton(tokenOrClass as InjectionToken<T>, serviceClass)\n } else {\n const targetClass = tokenOrClass as Constructor<T>\n this.container.registerSingleton(targetClass, targetClass)\n }\n }\n\n /**\n * Register a value (instance) directly\n */\n registerValue<T>(token: InjectionToken<T>, value: T): void {\n this.container.register(token, { useValue: value })\n }\n\n /**\n * Register with factory function\n */\n registerFactory<T>(\n token: InjectionToken<T>,\n factory: (container: Container) => T\n ): void {\n this.container.register(token, { useFactory: () => factory(this) })\n }\n\n /**\n * Register an alias to an existing token\n */\n registerExisting<T>(alias: InjectionToken<T>, target: InjectionToken<T>): void {\n this.container.register(alias, { useToken: target })\n }\n\n // ============================================================\n // Resolution Methods\n // ============================================================\n\n /**\n * Resolve a service from the container\n */\n resolve<T>(token: InjectionToken<T>): T {\n return this.container.resolve<T>(token)\n }\n\n /**\n * Check if a token is registered\n */\n isRegistered<T>(token: InjectionToken<T>): boolean {\n return this.container.isRegistered(token)\n }\n\n // ============================================================\n // Conditional Registration Methods\n // ============================================================\n\n /**\n * Start a conditional binding with predicate evaluation\n */\n when(\n predicate: (container: PredicateContainer) => boolean,\n options: WhenOptions = {}\n ): ConditionalBindingBuilder {\n return new ConditionalBindingBuilderImpl(\n this.container,\n this,\n predicate,\n options\n )\n }\n\n /**\n * Replace a service registration with a decorated version\n */\n extend<T>(token: InjectionToken<T>, decorator: ExtensionDecorator<T>): void {\n const currentInstance = this.container.resolve<T>(token)\n const decoratedInstance = decorator(currentInstance, this)\n this.container.register(token, { useValue: decoratedInstance })\n }\n\n // ============================================================\n // Request Scope Management\n // ============================================================\n\n /**\n * Run callback within request scope\n *\n * Creates a child container with fresh instances for services registered with `scope: Scope.Request`.\n * Callback receives the request-scoped container as argument.\n *\n * Can only be called on global container (not request-scoped).\n */\n async runInRequestScope<T>(\n routerContext: RouterContext,\n callback: (requestContainer: Container) => T | Promise<T>\n ): Promise<T> {\n if (this.isRequestScoped) {\n throw new RequestScopeOperationNotAllowedError('runInRequestScope')\n }\n\n const requestContainer = this.createRequestScope(routerContext)\n try {\n return await callback(requestContainer)\n } finally {\n await requestContainer.dispose()\n }\n }\n\n /**\n * Create request scope container\n *\n * Can only be called on global container (not request-scoped).\n */\n createRequestScope(routerContext: RouterContext): Container {\n if (this.isRequestScoped) {\n throw new RequestScopeOperationNotAllowedError('createRequestScope')\n }\n\n const childContainer = this.container.createChildContainer()\n childContainer.register(ROUTER_TOKENS.RouterContext, { useValue: routerContext })\n\n return new Container({ container: childContainer, isRequestScoped: true })\n }\n\n // ============================================================\n // Escape Hatches\n // ============================================================\n\n /**\n * Get underlying tsyringe container\n */\n getTsyringeContainer(): DependencyContainer {\n return this.container\n }\n\n dispose() {\n return this.container.dispose()\n }\n}\n\n// Re-export tsyringe utilities for convenience\nexport { container, delay, inject, injectable, instancePerContainerCachingFactory, singleton } from 'tsyringe'\nexport type { DependencyContainer } from 'tsyringe'\n\n","/**\n * DI Type Definitions\n *\n * Core type definitions for the dependency injection system.\n * Simplified after removing LazyProxy - no more type wrappers needed.\n */\n\nimport { Lifecycle } from 'tsyringe'\nimport type InjectionToken from 'tsyringe/dist/typings/providers/injection-token'\n\n/**\n * Service scope for DI registration\n *\n * Maps directly to tsyringe's Lifecycle enum.\n * Scope is specified at registration time via provider configuration,\n * not at class decoration time.\n *\n * @example\n * ```typescript\n * // In module providers:\n * { provide: MY_TOKEN, useClass: MyService, scope: Scope.Singleton }\n *\n * // In Application.ts:\n * container.register(MY_TOKEN, MyService, Scope.Request)\n * ```\n */\n/* eslint-disable @typescript-eslint/prefer-literal-enum-member -- values must stay in sync with tsyringe Lifecycle */\nexport enum Scope {\n /** New instance per resolution (default) */\n Transient = Lifecycle.Transient,\n /** Single instance shared globally */\n Singleton = Lifecycle.Singleton,\n /** New instance per child container (per request) */\n Request = Lifecycle.ContainerScoped,\n}\n/* eslint-enable @typescript-eslint/prefer-literal-enum-member */\n\n/**\n * Options for conditional binding with `when()` method\n */\nexport interface WhenOptions {\n /**\n * Cache predicate result after first evaluation.\n * When true, the predicate is evaluated once and the result is reused.\n * When false (default), predicate is evaluated on each resolution.\n */\n cache?: boolean\n}\n\n/**\n * Decorator function type for extend() method\n *\n * @template T The service type being decorated\n */\nexport type ExtensionDecorator<T> = (service: T, container: ContainerLike) => T\n\n/**\n * Minimal container interface for decorator functions\n * Avoids circular dependency with Container class\n */\nexport interface ContainerLike {\n resolve<T>(token: InjectionToken<T>): T\n}\n\n","/**\n * I18n Module DI Tokens\n * Symbol-based tokens to avoid string collisions\n */\n\nexport const I18N_TOKENS = {\n /** MessageLoaderService - loads and caches locale messages */\n MessageLoader: Symbol.for('stratal:i18n:message:loader'),\n /** I18nService - request-scoped translation service */\n I18nService: Symbol.for('stratal:i18n:service'),\n /** I18nModuleOptions - configuration options from forRoot() */\n Options: Symbol.for('stratal:i18n:options'),\n /** MessageRegistry - singleton accumulator for registerMessages() contributions */\n MessageRegistry: Symbol.for('stratal:i18n:message:registry'),\n} as const\n","import { ERROR_CODES } from './error-codes'\nimport { ApplicationError } from './application-error'\n\n/**\n * InternalError\n *\n * Represents an unexpected internal server error.\n * Used to wrap unknown errors that don't fit into specific error categories.\n *\n * This error is thrown when:\n * - An unexpected exception occurs\n * - An error type is not recognized\n * - A system-level failure happens\n */\nexport class InternalError extends ApplicationError {\n constructor(metadata?: Record<string, unknown>) {\n super(\n 'errors.internalError',\n ERROR_CODES.SYSTEM.INTERNAL_ERROR,\n metadata\n )\n }\n}\n","import { ApplicationError } from './application-error'\n\n/**\n * Type guard to check if an error is an ApplicationError\n *\n * @param error - The error to check\n * @returns True if the error is an ApplicationError instance\n */\nexport function isApplicationError(error: unknown): error is ApplicationError {\n return error instanceof ApplicationError\n}\n","import { inject } from 'tsyringe'\nimport { DI_TOKENS } from '../di'\nimport { Transient } from '../di/decorators'\nimport { type StratalEnv } from '../env'\nimport { I18N_TOKENS } from '../i18n/i18n.tokens'\nimport type { II18nService, MessageKeys } from '../i18n/i18n.types'\nimport { LOGGER_TOKENS, type LoggerService } from '../logger'\nimport { ApplicationError } from './application-error'\nimport type { Environment, ErrorResponse } from './error-response'\nimport { InternalError } from './internal-error'\nimport { isApplicationError } from './is-application-error'\n\n/**\n * Log severity levels\n */\ntype LogSeverity = 'error' | 'warn' | 'info'\n\n/**\n * GlobalErrorHandler\n *\n * Centralized error handler registered in the DI container.\n * Responsible for:\n * - Intercepting all errors in the application\n * - Logging errors with appropriate severity via Logger service\n * - Translating error message keys using I18nService (when available)\n * - Serializing errors for RPC transmission\n * - Wrapping unexpected errors in InternalError\n *\n * **Translation Availability by Context:**\n *\n * ✅ **HTTP Requests**: Errors are fully translated\n * - GlobalErrorHandler resolved from request container\n * - I18nService available via AsyncLocalStorage with user's locale\n * - Full translation with parameter interpolation\n *\n * ✅ **Queue Processing**: Errors are fully translated\n * - Error handling executes inside AsyncLocalStorage scope\n * - Locale extracted from queue message metadata\n * - Request container created with mock RouterContext\n * - I18nService available with correct locale\n *\n * ⚠️ **RPC/Startup**: Message keys returned as-is (i18n unavailable)\n * - No request context available during service binding or startup\n * - No locale information available\n * - Frontend can translate message keys using its own i18n if needed\n * - This is expected behavior, not a bug\n *\n * **Implementation Note:**\n * The `isAvailable()` check exists to gracefully handle RPC/startup contexts\n * where no request container exists. For HTTP and Queue contexts, i18n is\n * always available thanks to AsyncLocalStorage scope propagation. This follows\n * the \"Laravel philosophy\" - transparent dependency injection for request contexts,\n * with explicit handling only for legitimate non-request edge cases.\n */\n@Transient()\nexport class GlobalErrorHandler {\n private readonly environment: Environment\n constructor(\n @inject(LOGGER_TOKENS.LoggerService) private readonly logger: LoggerService,\n @inject(I18N_TOKENS.I18nService) private readonly i18n: II18nService,\n @inject(DI_TOKENS.CloudflareEnv)\n private readonly env: StratalEnv,\n ) {\n this.environment = this.env.ENVIRONMENT as Environment\n }\n\n /**\n * Handle an error, log it, and serialize for response\n *\n * @param error - The error to handle\n * @returns Serialized ErrorResponse for RPC transmission\n */\n handle(error: unknown): ErrorResponse {\n // Check if it's an ApplicationError\n if (isApplicationError(error)) {\n // Translate once, use for both logging and response\n const translatedMessage = this.translateError(error)\n\n this.log(error, translatedMessage)\n\n return error.toErrorResponse(this.environment, translatedMessage)\n }\n\n // Unexpected error - wrap in InternalError\n this.logUnexpectedError(error)\n\n const internalError = new InternalError({\n originalError: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n })\n\n const translatedMessage = this.translateError(internalError)\n\n return internalError.toErrorResponse(this.environment, translatedMessage)\n }\n\n /**\n * Translate error message key using I18nService\n * Uses error metadata as interpolation parameters\n *\n * No try/catch - if translation fails, it's a bug that should fail loudly\n *\n * **Note**: This method is only called when isAvailable() returns true,\n * so the service is guaranteed to be resolved.\n *\n * @param error - ApplicationError with messageKey and metadata\n * @returns Translated message string\n */\n private translateError(error: ApplicationError): string {\n // Cast metadata to MessageParams (assuming values are string | number)\n const params = error.metadata as Record<string, string | number> | undefined\n return this.i18n.t(error.message as MessageKeys, params)\n }\n\n /**\n * Log an ApplicationError with appropriate severity\n */\n private log(error: ApplicationError, translatedMessage: string): void {\n const severity = this.getSeverity(error.code)\n\n const logData = {\n code: error.code,\n message: translatedMessage,\n timestamp: error.timestamp,\n metadata: error.metadata,\n name: error.name,\n }\n\n switch (severity) {\n case 'error':\n this.logger.error('[ApplicationError]', logData)\n break\n case 'warn':\n this.logger.warn('[ApplicationError]', logData)\n break\n case 'info':\n this.logger.info('[ApplicationError]', logData)\n break\n }\n }\n\n /**\n * Log an unexpected error\n */\n private logUnexpectedError(error: unknown): void {\n this.logger.error('[UnexpectedError]', {\n error: error instanceof Error ? {\n message: error.message,\n stack: error.stack,\n name: error.name,\n } : String(error),\n timestamp: new Date().toISOString(),\n })\n }\n\n /**\n * Determine log severity based on error code\n */\n private getSeverity(code: number): LogSeverity {\n // System errors (9000+) are critical\n if (code >= 9000) return 'error'\n\n // Database errors (2000-2999) are errors\n if (code >= 2000 && code < 3000) return 'error'\n\n // Business logic errors (5000-5999) are warnings\n if (code >= 5000 && code < 6000) return 'warn'\n\n // Validation errors (1000-1999) are info\n if (code >= 1000 && code < 2000) return 'info'\n\n // Auth/Resource errors (3000-4999) are warnings\n if (code >= 3000 && code < 5000) return 'warn'\n\n // Default to error\n return 'error'\n }\n}\n","import { ApplicationError } from './application-error'\nimport { ERROR_CODES } from './error-codes'\n\n/**\n * RequestContainerNotInitializedError\n *\n * Thrown when attempting to access the request-scoped container before it has been initialized.\n * This typically indicates that the RouterService middleware hasn't run yet,\n * or the router context is being accessed outside of a request lifecycle.\n */\nexport class RequestContainerNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.requestContainerNotInitialized',\n ERROR_CODES.SYSTEM.REQUEST_CONTAINER_NOT_INITIALIZED\n )\n }\n}\n","import { ApplicationError } from './application-error'\nimport { ERROR_CODES } from './error-codes'\n\n/**\n * StratalNotInitializedError\n *\n * Thrown when attempting to resolve the Application instance before Stratal has been instantiated.\n * This typically indicates that the Stratal instance is not exported as the default export.\n */\nexport class StratalNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.stratalNotInitialized',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAsB,mBAAtB,MAAsB,yBAAyB,MAAM;;;;;;CAMnD,OAAO,qBAAqB;;;;;CAM5B;;;;CAKA;;;;;;;CAQA;;;;;;CAOA,YACE,SACA,MACA,UACA;AAEA,QAAM,QAAQ;AAGd,SAAO,eAAe,MAAM,IAAI,OAAO,UAAU;AAEjD,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,OAAO;AACZ,OAAK,6BAAY,IAAI,MAAM,EAAC,aAAa;AACzC,OAAK,WAAW;AAKhB,MAAI,iBAAiB,sBAAsB,MAAM,kBAC/C,OAAM,kBAAkB,MAAM,KAAK,YAAY;;;;;;;;;;;;;;;;;;CAoBnD,OAAe,eACb,UACqC;AACrC,MAAI,CAAC,SAAU,QAAO,KAAA;EAGtB,MAAM,YAAY;GAAC;GAAU;GAAU;GAAQ;EAE/C,MAAM,WAAoC,EAAE;EAC5C,IAAI,oBAAoB;AAExB,OAAK,MAAM,OAAO,UAChB,KAAI,OAAO,YAAY,SAAS,SAAS,KAAA,GAAW;AAClD,YAAS,OAAO,SAAS;AACzB,uBAAoB;;AAKxB,SAAO,oBAAoB,WAAW,KAAA;;;;;;;;;CAUxC,gBAAgB,KAAkB,mBAA2C;EAC3E,MAAM,UAAU,qBAAqB,KAAK;AAE1C,SAAO;GACL,MAAM,KAAK;GACX;GACA,WAAW,KA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AAQ,OAAO,IAAM,QAAO;AAGxC,MAAI,QAAQ,OAAQ,OAAO,IAAM,QAAO;AAGxC,SAAO;;;;CAzHV,WAAW;oBAIP,OAAO,cAAc,cAAc,CAAA;oBACnC,OAAO,YAAY,YAAY,CAAA;oBAC/B,OAAO,UAAU,cAAc,CAAA;;;;;;;;;;;;;;;;AClDpC,IAAa,sCAAb,cAAyD,iBAAiB;CACxE,cAAc;AACZ,QACE,yCACA,YAAY,OAAO,kCACpB;;;;;;;;;;;ACNL,IAAa,6BAAb,cAAgD,iBAAiB;CAC/D,cAAc;AACZ,QACE,gCACA,YAAY,OAAO,qBACpB"}
@@ -1,4 +1,4 @@
1
- import { S as ApplicationError, b as ERROR_CODES } from "./errors-CtCi1wn6.mjs";
1
+ import { S as ApplicationError, b as ERROR_CODES } from "./errors-DSKapqD8.mjs";
2
2
  //#region src/storage/errors/disk-not-configured.error.ts
3
3
  var DiskNotConfiguredError = class extends ApplicationError {
4
4
  constructor(disk) {
@@ -64,4 +64,4 @@ var StorageResponseBodyMissingError = class extends ApplicationError {
64
64
  //#endregion
65
65
  export { InvalidDiskError as a, DiskNotConfiguredError as c, InvalidFileTypeError as i, StorageProviderNotSupportedError as n, FileTooLargeError as o, PresignedUrlInvalidExpiryError as r, FileNotFoundError as s, StorageResponseBodyMissingError as t };
66
66
 
67
- //# sourceMappingURL=errors-H3TZnVeX.mjs.map
67
+ //# sourceMappingURL=errors-DuAR5Wke.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-H3TZnVeX.mjs","names":[],"sources":["../src/storage/errors/disk-not-configured.error.ts","../src/storage/errors/file-not-found.error.ts","../src/storage/errors/file-too-large.error.ts","../src/storage/errors/invalid-disk.error.ts","../src/storage/errors/invalid-file-type.error.ts","../src/storage/errors/presigned-url-invalid-expiry.error.ts","../src/storage/errors/storage-provider-not-supported.error.ts","../src/storage/errors/storage-response-body-missing.error.ts"],"sourcesContent":["import { ApplicationError, ERROR_CODES } from '../../errors'\n\nexport class DiskNotConfiguredError extends ApplicationError {\n constructor(disk: string) {\n super('errors.storage.diskNotConfigured', ERROR_CODES.SYSTEM.CONFIGURATION_ERROR, { disk })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class FileNotFoundError extends ApplicationError {\n constructor(path: string) {\n super('errors.storage.fileNotFound', ERROR_CODES.RESOURCE.NOT_FOUND, { path })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class FileTooLargeError extends ApplicationError {\n constructor(size: number, maxSize: number) {\n super('errors.storage.fileTooLarge', ERROR_CODES.VALIDATION.INVALID_FORMAT, {\n size,\n maxSize,\n })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class InvalidDiskError extends ApplicationError {\n constructor(disk: string) {\n super('errors.storage.invalidDisk', ERROR_CODES.SYSTEM.CONFIGURATION_ERROR, { disk })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class InvalidFileTypeError extends ApplicationError {\n constructor(mimeType: string) {\n super('errors.storage.invalidFileType', ERROR_CODES.VALIDATION.INVALID_FORMAT, {\n mimeType,\n })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class PresignedUrlInvalidExpiryError extends ApplicationError {\n constructor(expiresIn: number, min: number, max: number) {\n super('errors.storage.presignedUrlInvalidExpiry', ERROR_CODES.VALIDATION.INVALID_FORMAT, {\n expiresIn,\n min,\n max,\n })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class StorageProviderNotSupportedError extends ApplicationError {\n constructor(provider: string) {\n super('errors.storage.providerNotSupported', ERROR_CODES.SYSTEM.CONFIGURATION_ERROR, { provider })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class StorageResponseBodyMissingError extends ApplicationError {\n constructor(path: string) {\n super(\n 'errors.storage.responseBodyMissing',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { path }\n )\n }\n}\n"],"mappings":";;AAEA,IAAa,yBAAb,cAA4C,iBAAiB;CAC3D,YAAY,MAAc;AACxB,QAAM,oCAAoC,YAAY,OAAO,qBAAqB,EAAE,MAAM,CAAC;;;;;ACD/F,IAAa,oBAAb,cAAuC,iBAAiB;CACtD,YAAY,MAAc;AACxB,QAAM,+BAA+B,YAAY,SAAS,WAAW,EAAE,MAAM,CAAC;;;;;ACFlF,IAAa,oBAAb,cAAuC,iBAAiB;CACtD,YAAY,MAAc,SAAiB;AACzC,QAAM,+BAA+B,YAAY,WAAW,gBAAgB;GAC1E;GACA;GACD,CAAC;;;;;ACLN,IAAa,mBAAb,cAAsC,iBAAiB;CACrD,YAAY,MAAc;AACxB,QAAM,8BAA8B,YAAY,OAAO,qBAAqB,EAAE,MAAM,CAAC;;;;;ACFzF,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,YAAY,UAAkB;AAC5B,QAAM,kCAAkC,YAAY,WAAW,gBAAgB,EAC7E,UACD,CAAC;;;;;ACJN,IAAa,iCAAb,cAAoD,iBAAiB;CACnE,YAAY,WAAmB,KAAa,KAAa;AACvD,QAAM,4CAA4C,YAAY,WAAW,gBAAgB;GACvF;GACA;GACA;GACD,CAAC;;;;;ACNN,IAAa,mCAAb,cAAsD,iBAAiB;CACrE,YAAY,UAAkB;AAC5B,QAAM,uCAAuC,YAAY,OAAO,qBAAqB,EAAE,UAAU,CAAC;;;;;ACFtG,IAAa,kCAAb,cAAqD,iBAAiB;CACpE,YAAY,MAAc;AACxB,QACE,sCACA,YAAY,OAAO,sBACnB,EAAE,MAAM,CACT"}
1
+ {"version":3,"file":"errors-DuAR5Wke.mjs","names":[],"sources":["../src/storage/errors/disk-not-configured.error.ts","../src/storage/errors/file-not-found.error.ts","../src/storage/errors/file-too-large.error.ts","../src/storage/errors/invalid-disk.error.ts","../src/storage/errors/invalid-file-type.error.ts","../src/storage/errors/presigned-url-invalid-expiry.error.ts","../src/storage/errors/storage-provider-not-supported.error.ts","../src/storage/errors/storage-response-body-missing.error.ts"],"sourcesContent":["import { ApplicationError, ERROR_CODES } from '../../errors'\n\nexport class DiskNotConfiguredError extends ApplicationError {\n constructor(disk: string) {\n super('errors.storage.diskNotConfigured', ERROR_CODES.SYSTEM.CONFIGURATION_ERROR, { disk })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class FileNotFoundError extends ApplicationError {\n constructor(path: string) {\n super('errors.storage.fileNotFound', ERROR_CODES.RESOURCE.NOT_FOUND, { path })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class FileTooLargeError extends ApplicationError {\n constructor(size: number, maxSize: number) {\n super('errors.storage.fileTooLarge', ERROR_CODES.VALIDATION.INVALID_FORMAT, {\n size,\n maxSize,\n })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class InvalidDiskError extends ApplicationError {\n constructor(disk: string) {\n super('errors.storage.invalidDisk', ERROR_CODES.SYSTEM.CONFIGURATION_ERROR, { disk })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class InvalidFileTypeError extends ApplicationError {\n constructor(mimeType: string) {\n super('errors.storage.invalidFileType', ERROR_CODES.VALIDATION.INVALID_FORMAT, {\n mimeType,\n })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class PresignedUrlInvalidExpiryError extends ApplicationError {\n constructor(expiresIn: number, min: number, max: number) {\n super('errors.storage.presignedUrlInvalidExpiry', ERROR_CODES.VALIDATION.INVALID_FORMAT, {\n expiresIn,\n min,\n max,\n })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class StorageProviderNotSupportedError extends ApplicationError {\n constructor(provider: string) {\n super('errors.storage.providerNotSupported', ERROR_CODES.SYSTEM.CONFIGURATION_ERROR, { provider })\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\nexport class StorageResponseBodyMissingError extends ApplicationError {\n constructor(path: string) {\n super(\n 'errors.storage.responseBodyMissing',\n ERROR_CODES.SYSTEM.INFRASTRUCTURE_ERROR,\n { path }\n )\n }\n}\n"],"mappings":";;AAEA,IAAa,yBAAb,cAA4C,iBAAiB;CAC3D,YAAY,MAAc;AACxB,QAAM,oCAAoC,YAAY,OAAO,qBAAqB,EAAE,MAAM,CAAC;;;;;ACD/F,IAAa,oBAAb,cAAuC,iBAAiB;CACtD,YAAY,MAAc;AACxB,QAAM,+BAA+B,YAAY,SAAS,WAAW,EAAE,MAAM,CAAC;;;;;ACFlF,IAAa,oBAAb,cAAuC,iBAAiB;CACtD,YAAY,MAAc,SAAiB;AACzC,QAAM,+BAA+B,YAAY,WAAW,gBAAgB;GAC1E;GACA;GACD,CAAC;;;;;ACLN,IAAa,mBAAb,cAAsC,iBAAiB;CACrD,YAAY,MAAc;AACxB,QAAM,8BAA8B,YAAY,OAAO,qBAAqB,EAAE,MAAM,CAAC;;;;;ACFzF,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,YAAY,UAAkB;AAC5B,QAAM,kCAAkC,YAAY,WAAW,gBAAgB,EAC7E,UACD,CAAC;;;;;ACJN,IAAa,iCAAb,cAAoD,iBAAiB;CACnE,YAAY,WAAmB,KAAa,KAAa;AACvD,QAAM,4CAA4C,YAAY,WAAW,gBAAgB;GACvF;GACA;GACA;GACD,CAAC;;;;;ACNN,IAAa,mCAAb,cAAsD,iBAAiB;CACrE,YAAY,UAAkB;AAC5B,QAAM,uCAAuC,YAAY,OAAO,qBAAqB,EAAE,UAAU,CAAC;;;;;ACFtG,IAAa,kCAAb,cAAqD,iBAAiB;CACpE,YAAY,MAAc;AACxB,QACE,sCACA,YAAY,OAAO,sBACnB,EAAE,MAAM,CACT"}
@@ -1,4 +1,3 @@
1
- import "../decorate-D5j-d9_z.mjs";
2
- import "../logger-BR1-s1Um.mjs";
3
- import { a as isListener, i as Listener, n as On, o as LISTENER_METADATA_KEYS, r as getListenerHandlers, t as EventRegistry } from "../events-CXl-o1Ad.mjs";
1
+ import "../logger-CGT91VY6.mjs";
2
+ import { a as isListener, i as Listener, n as On, o as LISTENER_METADATA_KEYS, r as getListenerHandlers, t as EventRegistry } from "../events-CvUSgEuN.mjs";
4
3
  export { EventRegistry, LISTENER_METADATA_KEYS, Listener, On, getListenerHandlers, isListener };
@@ -1,5 +1,4 @@
1
- import { i as Transient, l as DI_TOKENS, n as __decorateParam, r as __decorateMetadata, t as __decorate } from "./decorate-D5j-d9_z.mjs";
2
- import { s as LOGGER_TOKENS } from "./logger-BR1-s1Um.mjs";
1
+ import { a as __decorate, d as Transient, g as DI_TOKENS, o as __decorateParam, s as __decorateMetadata, u as LOGGER_TOKENS } from "./logger-CGT91VY6.mjs";
3
2
  import { inject } from "tsyringe";
4
3
  //#region src/events/constants.ts
5
4
  /**
@@ -188,4 +187,4 @@ EventRegistry = __decorate([
188
187
  //#endregion
189
188
  export { isListener as a, Listener as i, On as n, LISTENER_METADATA_KEYS as o, getListenerHandlers as r, EventRegistry as t };
190
189
 
191
- //# sourceMappingURL=events-CXl-o1Ad.mjs.map
190
+ //# sourceMappingURL=events-CvUSgEuN.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"events-CXl-o1Ad.mjs","names":[],"sources":["../src/events/constants.ts","../src/events/decorators/listener.decorator.ts","../src/events/decorators/on.decorator.ts","../src/events/event-registry.ts"],"sourcesContent":["/**\n * Metadata keys for event listener decorators.\n *\n * Uses `Symbol.for()` (global symbol registry) so that both core and\n * framework packages can reference the same symbols without cross-imports.\n */\nexport const LISTENER_METADATA_KEYS = {\n IS_LISTENER: Symbol.for('stratal:listener'),\n EVENT_HANDLERS: Symbol.for('stratal:listener:handlers'),\n} as const\n","import { Transient } from '../../di/decorators'\nimport type { Constructor } from '../../types'\nimport { LISTENER_METADATA_KEYS } from '../constants'\n\n/**\n * Mark a class as an event listener.\n *\n * Applies `@Transient()` for DI and sets metadata so the module system\n * can auto-discover and wire listener handlers at bootstrap time.\n *\n * @example\n * ```typescript\n * @Listener()\n * export class UserCreatedListener {\n * @On('after.User.create')\n * async sendWelcomeEmail(context: EventContext<'after.User.create'>) {\n * // ...\n * }\n * }\n * ```\n */\nexport function Listener() {\n return function <T extends Constructor>(target: T) {\n Transient()(target)\n Reflect.defineMetadata(LISTENER_METADATA_KEYS.IS_LISTENER, true, target)\n return target\n }\n}\n\n/**\n * Check if a class is decorated with `@Listener()`\n */\nexport function isListener(target: Constructor): boolean {\n return Reflect.getMetadata(LISTENER_METADATA_KEYS.IS_LISTENER, target) === true\n}\n","import { LISTENER_METADATA_KEYS } from '../constants'\nimport type { EventName, EventOptions, ListenerHandlerMetadata } from '../types'\n\n/**\n * Register a method as an event handler within a `@Listener()` class.\n *\n * Accumulates handler metadata on the class so the framework can\n * auto-wire handlers with the EventRegistry at bootstrap time.\n *\n * @param event - Event name to listen for (fully typed with autocomplete)\n * @param options - Optional handler options (priority, blocking)\n *\n * @example\n * ```typescript\n * @Listener()\n * export class AuditListener {\n * @On('after.User.create')\n * async logCreate(context: EventContext<'after.User.create'>) { ... }\n *\n * @On('after.User.delete', { priority: 10 })\n * async logDelete(context: EventContext<'after.User.delete'>) { ... }\n * }\n * ```\n */\nexport function On<E extends EventName>(event: E, options?: EventOptions) {\n return function (\n target: object,\n propertyKey: string,\n _descriptor: PropertyDescriptor\n ) {\n const existingHandlers: ListenerHandlerMetadata[] =\n (Reflect.getMetadata(LISTENER_METADATA_KEYS.EVENT_HANDLERS, target.constructor) as ListenerHandlerMetadata[] | undefined) ?? []\n\n existingHandlers.push({\n methodName: propertyKey,\n event: event as string,\n options,\n })\n\n Reflect.defineMetadata(\n LISTENER_METADATA_KEYS.EVENT_HANDLERS,\n existingHandlers,\n target.constructor\n )\n }\n}\n\n/**\n * Get all `@On()` handler metadata from a listener class\n */\nexport function getListenerHandlers(target: object): ListenerHandlerMetadata[] {\n const metadataTarget = typeof target === 'function' ? target : target.constructor\n return (Reflect.getMetadata(LISTENER_METADATA_KEYS.EVENT_HANDLERS, metadataTarget) as ListenerHandlerMetadata[] | undefined) ?? []\n}\n","import { inject } from 'tsyringe'\nimport { Transient } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport { LOGGER_TOKENS, type LoggerService } from '../logger'\nimport type {\n EventContext,\n EventHandler,\n EventName,\n EventOptions,\n IEventRegistry,\n RegisteredHandler\n} from './types'\n\n@Transient()\nexport class EventRegistry implements IEventRegistry {\n private handlers = new Map<string, RegisteredHandler[]>()\n\n constructor(\n @inject(DI_TOKENS.ExecutionContext) private readonly ctx: ExecutionContext,\n @inject(LOGGER_TOKENS.LoggerService) private readonly logger: LoggerService\n ) { }\n\n on<E extends EventName>(event: E, handler: EventHandler<E>, options?: EventOptions): void {\n const registered: RegisteredHandler = {\n handler: handler as EventHandler,\n priority: options?.priority ?? 0,\n blocking: options?.blocking\n }\n\n const existingHandlers = this.handlers.get(event) ?? []\n existingHandlers.push(registered)\n this.handlers.set(event, existingHandlers)\n\n this.logger.debug('Event handler registered', {\n event,\n priority: registered.priority,\n blocking: registered.blocking\n })\n }\n\n async emit<E extends EventName>(\n event: E,\n context?: Partial<EventContext<E>>\n ): Promise<void> {\n // Build full context with caller-provided fields\n const fullContext = {\n ...context\n } as EventContext<E>\n\n // Find matching handlers using pattern matching\n const matchingHandlers = this.findMatchingHandlers(event)\n\n if (matchingHandlers.length === 0) {\n return\n }\n\n // Sort by priority (higher first)\n const sortedHandlers = [...matchingHandlers].sort(\n (a, b) => b.priority - a.priority\n )\n\n // Determine if we should use waitUntil\n const shouldUseWaitUntil = this.shouldUseWaitUntil(event, sortedHandlers)\n\n // Execute handlers\n const promises = sortedHandlers.map((registered) =>\n this.executeHandler(registered.handler, fullContext, event)\n )\n\n if (shouldUseWaitUntil) {\n // Non-blocking: use ctx.waitUntil\n this.ctx.waitUntil(Promise.all(promises))\n } else {\n // Blocking: await all handlers\n await Promise.all(promises)\n }\n }\n\n off<E extends EventName>(event: E, handler: EventHandler<E>): void {\n const existingHandlers = this.handlers.get(event)\n if (!existingHandlers) return\n\n const filtered = existingHandlers.filter((h) => h.handler !== handler)\n if (filtered.length > 0) {\n this.handlers.set(event, filtered)\n } else {\n this.handlers.delete(event)\n }\n\n this.logger.debug('Event handler unregistered', { event })\n }\n\n once<E extends EventName>(event: E, handler: EventHandler<E>, options?: EventOptions): void {\n const wrappedHandler = (async (context: EventContext<E>) => {\n await handler(context)\n this.off(event, wrappedHandler)\n }) as EventHandler<E>\n\n this.on(event, wrappedHandler, options)\n }\n\n /**\n * Find all handlers matching the event using pattern matching.\n * Order: exact match -> model wildcard -> operation wildcard -> global wildcard\n */\n private findMatchingHandlers(event: string): RegisteredHandler[] {\n const handlers: RegisteredHandler[] = []\n\n const parts = event.split('.')\n\n if (parts.length === 3) {\n // Database event: \"phase.model.operation\"\n const [phase, model, operation] = parts\n\n // 1. Exact match: \"after.user.create\"\n handlers.push(...(this.handlers.get(event) ?? []))\n\n // 2. Model wildcard: \"after.user\"\n handlers.push(...(this.handlers.get(`${phase}.${model}`) ?? []))\n\n // 3. Operation wildcard: \"after.create\"\n handlers.push(...(this.handlers.get(`${phase}.${operation}`) ?? []))\n\n // 4. Global wildcard: \"after\"\n handlers.push(...(this.handlers.get(phase) ?? []))\n } else if (parts.length === 2) {\n // Could be wildcard like \"after.user\" or custom event like \"auth.verified\"\n handlers.push(...(this.handlers.get(event) ?? []))\n\n if (parts[0] === 'before' || parts[0] === 'after') {\n handlers.push(...(this.handlers.get(parts[0]) ?? []))\n }\n } else {\n handlers.push(...(this.handlers.get(event) ?? []))\n }\n\n return handlers\n }\n\n /**\n * Determine if we should use ctx.waitUntil (non-blocking) or await (blocking)\n */\n private shouldUseWaitUntil(\n event: string,\n handlers: RegisteredHandler[]\n ): boolean {\n const hasBlockingHandler = handlers.some((h) => h.blocking === true)\n if (hasBlockingHandler) return false\n\n const hasNonBlockingHandler = handlers.some((h) => h.blocking === false)\n if (hasNonBlockingHandler) return true\n\n const phase = event.split('.')[0]\n if (phase === 'before') return false\n if (phase === 'after') return true\n return false // Custom events block by default\n }\n\n /**\n * Execute a single handler with error isolation\n */\n private async executeHandler<E extends EventName>(\n handler: EventHandler,\n context: EventContext<E>,\n event: string\n ): Promise<void> {\n try {\n await handler(context as EventContext)\n } catch (error) {\n this.logger.error('Event handler error', {\n event,\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAMA,MAAa,yBAAyB;CACpC,aAAa,OAAO,IAAI,mBAAmB;CAC3C,gBAAgB,OAAO,IAAI,4BAA4B;CACxD;;;;;;;;;;;;;;;;;;;;ACYD,SAAgB,WAAW;AACzB,QAAO,SAAiC,QAAW;AACjD,aAAW,CAAC,OAAO;AACnB,UAAQ,eAAe,uBAAuB,aAAa,MAAM,OAAO;AACxE,SAAO;;;;;;AAOX,SAAgB,WAAW,QAA8B;AACvD,QAAO,QAAQ,YAAY,uBAAuB,aAAa,OAAO,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;ACT7E,SAAgB,GAAwB,OAAU,SAAwB;AACxE,QAAO,SACL,QACA,aACA,aACA;EACA,MAAM,mBACH,QAAQ,YAAY,uBAAuB,gBAAgB,OAAO,YAAY,IAA8C,EAAE;AAEjI,mBAAiB,KAAK;GACpB,YAAY;GACL;GACP;GACD,CAAC;AAEF,UAAQ,eACN,uBAAuB,gBACvB,kBACA,OAAO,YACR;;;;;;AAOL,SAAgB,oBAAoB,QAA2C;CAC7E,MAAM,iBAAiB,OAAO,WAAW,aAAa,SAAS,OAAO;AACtE,QAAQ,QAAQ,YAAY,uBAAuB,gBAAgB,eAAe,IAA8C,EAAE;;;;;ACtC7H,IAAA,gBAAA,MAAM,cAAwC;CACnD,2BAAmB,IAA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ACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC7D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ,KAAA;IAC/C,CAAC;;;;;CAhKP,WAAW;oBAKP,OAAO,UAAU,iBAAiB,CAAA;oBAClC,OAAO,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"events-CvUSgEuN.mjs","names":[],"sources":["../src/events/constants.ts","../src/events/decorators/listener.decorator.ts","../src/events/decorators/on.decorator.ts","../src/events/event-registry.ts"],"sourcesContent":["/**\n * Metadata keys for event listener decorators.\n *\n * Uses `Symbol.for()` (global symbol registry) so that both core and\n * framework packages can reference the same symbols without cross-imports.\n */\nexport const LISTENER_METADATA_KEYS = {\n IS_LISTENER: Symbol.for('stratal:listener'),\n EVENT_HANDLERS: Symbol.for('stratal:listener:handlers'),\n} as const\n","import { Transient } from '../../di/decorators'\nimport type { Constructor } from '../../types'\nimport { LISTENER_METADATA_KEYS } from '../constants'\n\n/**\n * Mark a class as an event listener.\n *\n * Applies `@Transient()` for DI and sets metadata so the module system\n * can auto-discover and wire listener handlers at bootstrap time.\n *\n * @example\n * ```typescript\n * @Listener()\n * export class UserCreatedListener {\n * @On('after.User.create')\n * async sendWelcomeEmail(context: EventContext<'after.User.create'>) {\n * // ...\n * }\n * }\n * ```\n */\nexport function Listener() {\n return function <T extends Constructor>(target: T) {\n Transient()(target)\n Reflect.defineMetadata(LISTENER_METADATA_KEYS.IS_LISTENER, true, target)\n return target\n }\n}\n\n/**\n * Check if a class is decorated with `@Listener()`\n */\nexport function isListener(target: Constructor): boolean {\n return Reflect.getMetadata(LISTENER_METADATA_KEYS.IS_LISTENER, target) === true\n}\n","import { LISTENER_METADATA_KEYS } from '../constants'\nimport type { EventName, EventOptions, ListenerHandlerMetadata } from '../types'\n\n/**\n * Register a method as an event handler within a `@Listener()` class.\n *\n * Accumulates handler metadata on the class so the framework can\n * auto-wire handlers with the EventRegistry at bootstrap time.\n *\n * @param event - Event name to listen for (fully typed with autocomplete)\n * @param options - Optional handler options (priority, blocking)\n *\n * @example\n * ```typescript\n * @Listener()\n * export class AuditListener {\n * @On('after.User.create')\n * async logCreate(context: EventContext<'after.User.create'>) { ... }\n *\n * @On('after.User.delete', { priority: 10 })\n * async logDelete(context: EventContext<'after.User.delete'>) { ... }\n * }\n * ```\n */\nexport function On<E extends EventName>(event: E, options?: EventOptions) {\n return function (\n target: object,\n propertyKey: string,\n _descriptor: PropertyDescriptor\n ) {\n const existingHandlers: ListenerHandlerMetadata[] =\n (Reflect.getMetadata(LISTENER_METADATA_KEYS.EVENT_HANDLERS, target.constructor) as ListenerHandlerMetadata[] | undefined) ?? []\n\n existingHandlers.push({\n methodName: propertyKey,\n event: event as string,\n options,\n })\n\n Reflect.defineMetadata(\n LISTENER_METADATA_KEYS.EVENT_HANDLERS,\n existingHandlers,\n target.constructor\n )\n }\n}\n\n/**\n * Get all `@On()` handler metadata from a listener class\n */\nexport function getListenerHandlers(target: object): ListenerHandlerMetadata[] {\n const metadataTarget = typeof target === 'function' ? target : target.constructor\n return (Reflect.getMetadata(LISTENER_METADATA_KEYS.EVENT_HANDLERS, metadataTarget) as ListenerHandlerMetadata[] | undefined) ?? []\n}\n","import { inject } from 'tsyringe'\nimport { Transient } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport { LOGGER_TOKENS, type LoggerService } from '../logger'\nimport type {\n EventContext,\n EventHandler,\n EventName,\n EventOptions,\n IEventRegistry,\n RegisteredHandler\n} from './types'\n\n@Transient()\nexport class EventRegistry implements IEventRegistry {\n private handlers = new Map<string, RegisteredHandler[]>()\n\n constructor(\n @inject(DI_TOKENS.ExecutionContext) private readonly ctx: ExecutionContext,\n @inject(LOGGER_TOKENS.LoggerService) private readonly logger: LoggerService\n ) { }\n\n on<E extends EventName>(event: E, handler: EventHandler<E>, options?: EventOptions): void {\n const registered: RegisteredHandler = {\n handler: handler as EventHandler,\n priority: options?.priority ?? 0,\n blocking: options?.blocking\n }\n\n const existingHandlers = this.handlers.get(event) ?? []\n existingHandlers.push(registered)\n this.handlers.set(event, existingHandlers)\n\n this.logger.debug('Event handler registered', {\n event,\n priority: registered.priority,\n blocking: registered.blocking\n })\n }\n\n async emit<E extends EventName>(\n event: E,\n context?: Partial<EventContext<E>>\n ): Promise<void> {\n // Build full context with caller-provided fields\n const fullContext = {\n ...context\n } as EventContext<E>\n\n // Find matching handlers using pattern matching\n const matchingHandlers = this.findMatchingHandlers(event)\n\n if (matchingHandlers.length === 0) {\n return\n }\n\n // Sort by priority (higher first)\n const sortedHandlers = [...matchingHandlers].sort(\n (a, b) => b.priority - a.priority\n )\n\n // Determine if we should use waitUntil\n const shouldUseWaitUntil = this.shouldUseWaitUntil(event, sortedHandlers)\n\n // Execute handlers\n const promises = sortedHandlers.map((registered) =>\n this.executeHandler(registered.handler, fullContext, event)\n )\n\n if (shouldUseWaitUntil) {\n // Non-blocking: use ctx.waitUntil\n this.ctx.waitUntil(Promise.all(promises))\n } else {\n // Blocking: await all handlers\n await Promise.all(promises)\n }\n }\n\n off<E extends EventName>(event: E, handler: EventHandler<E>): void {\n const existingHandlers = this.handlers.get(event)\n if (!existingHandlers) return\n\n const filtered = existingHandlers.filter((h) => h.handler !== handler)\n if (filtered.length > 0) {\n this.handlers.set(event, filtered)\n } else {\n this.handlers.delete(event)\n }\n\n this.logger.debug('Event handler unregistered', { event })\n }\n\n once<E extends EventName>(event: E, handler: EventHandler<E>, options?: EventOptions): void {\n const wrappedHandler = (async (context: EventContext<E>) => {\n await handler(context)\n this.off(event, wrappedHandler)\n }) as EventHandler<E>\n\n this.on(event, wrappedHandler, options)\n }\n\n /**\n * Find all handlers matching the event using pattern matching.\n * Order: exact match -> model wildcard -> operation wildcard -> global wildcard\n */\n private findMatchingHandlers(event: string): RegisteredHandler[] {\n const handlers: RegisteredHandler[] = []\n\n const parts = event.split('.')\n\n if (parts.length === 3) {\n // Database event: \"phase.model.operation\"\n const [phase, model, operation] = parts\n\n // 1. Exact match: \"after.user.create\"\n handlers.push(...(this.handlers.get(event) ?? []))\n\n // 2. Model wildcard: \"after.user\"\n handlers.push(...(this.handlers.get(`${phase}.${model}`) ?? []))\n\n // 3. Operation wildcard: \"after.create\"\n handlers.push(...(this.handlers.get(`${phase}.${operation}`) ?? []))\n\n // 4. Global wildcard: \"after\"\n handlers.push(...(this.handlers.get(phase) ?? []))\n } else if (parts.length === 2) {\n // Could be wildcard like \"after.user\" or custom event like \"auth.verified\"\n handlers.push(...(this.handlers.get(event) ?? []))\n\n if (parts[0] === 'before' || parts[0] === 'after') {\n handlers.push(...(this.handlers.get(parts[0]) ?? []))\n }\n } else {\n handlers.push(...(this.handlers.get(event) ?? []))\n }\n\n return handlers\n }\n\n /**\n * Determine if we should use ctx.waitUntil (non-blocking) or await (blocking)\n */\n private shouldUseWaitUntil(\n event: string,\n handlers: RegisteredHandler[]\n ): boolean {\n const hasBlockingHandler = handlers.some((h) => h.blocking === true)\n if (hasBlockingHandler) return false\n\n const hasNonBlockingHandler = handlers.some((h) => h.blocking === false)\n if (hasNonBlockingHandler) return true\n\n const phase = event.split('.')[0]\n if (phase === 'before') return false\n if (phase === 'after') return true\n return false // Custom events block by default\n }\n\n /**\n * Execute a single handler with error isolation\n */\n private async executeHandler<E extends EventName>(\n handler: EventHandler,\n context: EventContext<E>,\n event: string\n ): Promise<void> {\n try {\n await handler(context as EventContext)\n } catch (error) {\n this.logger.error('Event handler error', {\n event,\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;AAMA,MAAa,yBAAyB;CACpC,aAAa,OAAO,IAAI,mBAAmB;CAC3C,gBAAgB,OAAO,IAAI,4BAA4B;CACxD;;;;;;;;;;;;;;;;;;;;ACYD,SAAgB,WAAW;AACzB,QAAO,SAAiC,QAAW;AACjD,aAAW,CAAC,OAAO;AACnB,UAAQ,eAAe,uBAAuB,aAAa,MAAM,OAAO;AACxE,SAAO;;;;;;AAOX,SAAgB,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,UAAS,KAAK,GAAI,KAAK,SAAS,IAAI,MAAM,GAAG,IAAI,EAAE,CAAE;QAGvD,UAAS,KAAK,GAAI,KAAK,SAAS,IAAI,MAAM,IAAI,EAAE,CAAE;AAGpD,SAAO;;;;;CAMT,mBACE,OACA,UACS;AAET,MAD2B,SAAS,MAAM,MAAM,EAAE,aAAa,KAAK,CAC5C,QAAO;AAG/B,MAD8B,SAAS,MAAM,MAAM,EAAE,aAAa,MAAM,CAC7C,QAAO;EAElC,MAAM,QAAQ,MAAM,MAAM,IAAI,CAAC;AAC/B,MAAI,UAAU,SAAU,QAAO;AAC/B,MAAI,UAAU,QAAS,QAAO;AAC9B,SAAO;;;;;CAMT,MAAc,eACZ,SACA,SACA,OACe;AACf,MAAI;AACF,SAAM,QAAQ,QAAwB;WAC/B,OAAO;AACd,QAAK,OAAO,MAAM,uBAAuB;IACvC;IACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC7D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ,KAAA;IAC/C,CAAC;;;;;CAhKP,WAAW;oBAKP,OAAO,UAAU,iBAAiB,CAAA;oBAClC,OAAO,cAAc,cAAc,CAAA"}
@@ -1,6 +1,6 @@
1
- import { S as ApplicationError, b as ERROR_CODES } from "./errors-CtCi1wn6.mjs";
2
- import { i as Transient } from "./decorate-D5j-d9_z.mjs";
3
- import { o as ROUTE_METADATA_KEYS, t as RouterContext } from "./router-context-BEJe9HEB.mjs";
1
+ import { S as ApplicationError, b as ERROR_CODES } from "./errors-DSKapqD8.mjs";
2
+ import { d as Transient } from "./logger-CGT91VY6.mjs";
3
+ import { o as ROUTE_METADATA_KEYS, t as RouterContext } from "./router-context-D9R1v2Ac.mjs";
4
4
  //#region src/websocket/decorators/gateway.decorator.ts
5
5
  const CONTROLLER_ROUTE_KEY = ROUTE_METADATA_KEYS.CONTROLLER_ROUTE;
6
6
  const CONTROLLER_OPTIONS_KEY = ROUTE_METADATA_KEYS.CONTROLLER_OPTIONS;
@@ -223,4 +223,4 @@ var GatewayContext = class extends RouterContext {
223
223
  //#endregion
224
224
  export { OnMessage as a, getWsOnMessageMethod as c, isGateway as d, OnError as i, WebSocketDuplicateEventHandlerError as l, WebSocketBodyNotAvailableError as n, getWsOnCloseMethod as o, OnClose as r, getWsOnErrorMethod as s, GatewayContext as t, Gateway as u };
225
225
 
226
- //# sourceMappingURL=gateway-context-BkZ4UKaX.mjs.map
226
+ //# sourceMappingURL=gateway-context-CNOLkLUC.mjs.map