appos 0.2.1 → 0.2.2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/dist/bin/auth-schema-7KeUwlcd.mjs +2 -0
  2. package/dist/bin/concurrently.mjs +2 -0
  3. package/dist/bin/event-v2sCJkNd.mjs +2 -0
  4. package/dist/bin/extract-blob-metadata-TqNd9w-6.mjs +2 -0
  5. package/dist/bin/generate-image-variant-D8H9FxgD.mjs +2 -0
  6. package/dist/bin/generate-preview-5jLZLX6I.mjs +2 -0
  7. package/dist/bin/main.mjs +362 -0
  8. package/dist/bin/purge-attachment-CMlJMNOk.mjs +2 -0
  9. package/dist/bin/purge-audit-logs-hd6q6vnR.mjs +2 -0
  10. package/dist/bin/purge-unattached-blobs-BYv5b9R9.mjs +2 -0
  11. package/dist/bin/track-db-changes-q0Vl7Htm.mjs +2 -0
  12. package/dist/bin/vite.mjs +2 -0
  13. package/dist/bin/vitest.mjs +2 -0
  14. package/dist/bin/workflow-BagSlsMp.mjs +2 -0
  15. package/dist/bin/youch-handler-Jj6i1XIT.mjs +2 -0
  16. package/dist/exports/api/_virtual/rolldown_runtime.mjs +1 -0
  17. package/dist/exports/api/app-context.d.mts +115 -0
  18. package/dist/exports/api/app-context.mjs +1 -0
  19. package/dist/exports/api/auth-schema.d.mts +4248 -0
  20. package/dist/exports/api/auth-schema.mjs +1 -0
  21. package/dist/exports/api/auth.d.mts +398 -0
  22. package/dist/exports/api/auth.mjs +1 -0
  23. package/dist/exports/api/cache.d.mts +44 -0
  24. package/dist/exports/api/cache.mjs +1 -0
  25. package/dist/exports/api/config.d.mts +28 -0
  26. package/dist/exports/api/config.mjs +1 -0
  27. package/dist/exports/api/container.d.mts +210 -0
  28. package/dist/exports/api/container.mjs +1 -0
  29. package/dist/exports/api/database.d.mts +99 -0
  30. package/dist/exports/api/database.mjs +1 -0
  31. package/dist/exports/api/event.d.mts +235 -0
  32. package/dist/exports/api/event.mjs +1 -0
  33. package/dist/exports/api/i18n.d.mts +34 -0
  34. package/dist/exports/api/i18n.mjs +1 -0
  35. package/dist/exports/api/index.d.mts +21 -0
  36. package/dist/exports/api/index.mjs +1 -0
  37. package/dist/exports/api/logger.d.mts +21 -0
  38. package/dist/exports/api/logger.mjs +1 -0
  39. package/dist/exports/api/mailer.d.mts +70 -0
  40. package/dist/exports/api/mailer.mjs +1 -0
  41. package/dist/exports/api/middleware/request-logger.d.mts +24 -0
  42. package/dist/exports/api/middleware.d.mts +39 -0
  43. package/dist/exports/api/middleware.mjs +1 -0
  44. package/dist/exports/api/node_modules/.bun/change-case@5.4.4/node_modules/change-case/dist/index.mjs +1 -0
  45. package/dist/exports/api/openapi.d.mts +271 -0
  46. package/dist/exports/api/openapi.mjs +1 -0
  47. package/dist/exports/api/orm.d.mts +13 -0
  48. package/dist/exports/api/orm.mjs +1 -0
  49. package/dist/exports/api/otel.d.mts +40 -0
  50. package/dist/exports/api/otel.mjs +1 -0
  51. package/dist/exports/api/packages/appos/src/constants.mjs +1 -0
  52. package/dist/exports/api/packages/appos/src/instrumentation.d.mts +7 -0
  53. package/dist/exports/api/packages/appos/src/instrumentation.mjs +1 -0
  54. package/dist/exports/api/packages/appos/src/web/auth.mjs +1 -0
  55. package/dist/exports/api/redis.d.mts +34 -0
  56. package/dist/exports/api/redis.mjs +1 -0
  57. package/dist/exports/api/storage-schema.d.mts +707 -0
  58. package/dist/exports/api/storage-schema.mjs +1 -0
  59. package/dist/exports/api/storage.d.mts +506 -0
  60. package/dist/exports/api/storage.mjs +1 -0
  61. package/dist/exports/api/workflow.d.mts +250 -0
  62. package/dist/exports/api/workflow.mjs +1 -0
  63. package/dist/exports/api/workflows/_virtual/rolldown_runtime.mjs +1 -0
  64. package/dist/exports/api/workflows/auth-schema.mjs +1 -0
  65. package/dist/exports/api/workflows/auth.d.mts +375 -0
  66. package/dist/exports/api/workflows/cache.d.mts +44 -0
  67. package/dist/exports/api/workflows/config.d.mts +18 -0
  68. package/dist/exports/api/workflows/container.d.mts +167 -0
  69. package/dist/exports/api/workflows/database.d.mts +46 -0
  70. package/dist/exports/api/workflows/event.d.mts +68 -0
  71. package/dist/exports/api/workflows/event.mjs +1 -0
  72. package/dist/exports/api/workflows/extract-blob-metadata.mjs +1 -0
  73. package/dist/exports/api/workflows/generate-image-variant.d.mts +99 -0
  74. package/dist/exports/api/workflows/generate-image-variant.mjs +1 -0
  75. package/dist/exports/api/workflows/generate-preview.mjs +1 -0
  76. package/dist/exports/api/workflows/index.d.mts +2 -0
  77. package/dist/exports/api/workflows/index.mjs +1 -0
  78. package/dist/exports/api/workflows/logger.d.mts +21 -0
  79. package/dist/exports/api/workflows/mailer.d.mts +70 -0
  80. package/dist/exports/api/workflows/orm.d.mts +13 -0
  81. package/dist/exports/api/workflows/purge-attachment.mjs +1 -0
  82. package/dist/exports/api/workflows/purge-audit-logs.mjs +1 -0
  83. package/dist/exports/api/workflows/purge-unattached-blobs.mjs +1 -0
  84. package/dist/exports/api/workflows/redis.mjs +1 -0
  85. package/dist/exports/api/workflows/storage-schema.d.mts +699 -0
  86. package/dist/exports/api/workflows/storage.d.mts +396 -0
  87. package/dist/exports/api/workflows/track-db-changes.d.mts +72 -0
  88. package/dist/exports/api/workflows/track-db-changes.mjs +1 -0
  89. package/dist/exports/api/workflows/workflow.d.mts +24 -0
  90. package/dist/exports/api/workflows/workflow.mjs +1 -0
  91. package/dist/exports/cli/_virtual/rolldown_runtime.mjs +1 -0
  92. package/dist/exports/cli/api/auth-schema.mjs +1 -0
  93. package/dist/exports/cli/api/auth.d.mts +375 -0
  94. package/dist/exports/cli/api/cache.d.mts +44 -0
  95. package/dist/exports/cli/api/config.d.mts +18 -0
  96. package/dist/exports/cli/api/container.d.mts +167 -0
  97. package/dist/exports/cli/api/database.d.mts +46 -0
  98. package/dist/exports/cli/api/event.d.mts +68 -0
  99. package/dist/exports/cli/api/event.mjs +1 -0
  100. package/dist/exports/cli/api/logger.d.mts +21 -0
  101. package/dist/exports/cli/api/mailer.d.mts +70 -0
  102. package/dist/exports/cli/api/orm.d.mts +13 -0
  103. package/dist/exports/cli/api/redis.mjs +1 -0
  104. package/dist/exports/cli/api/storage-schema.d.mts +699 -0
  105. package/dist/exports/cli/api/storage.d.mts +396 -0
  106. package/dist/exports/cli/api/workflow.d.mts +2 -0
  107. package/dist/exports/cli/api/workflow.mjs +1 -0
  108. package/dist/exports/cli/api/workflows/extract-blob-metadata.mjs +1 -0
  109. package/dist/exports/cli/api/workflows/generate-image-variant.d.mts +63 -0
  110. package/dist/exports/cli/api/workflows/generate-image-variant.mjs +1 -0
  111. package/dist/exports/cli/api/workflows/generate-preview.mjs +1 -0
  112. package/dist/exports/cli/api/workflows/purge-attachment.mjs +1 -0
  113. package/dist/exports/cli/api/workflows/purge-audit-logs.mjs +1 -0
  114. package/dist/exports/cli/api/workflows/purge-unattached-blobs.mjs +1 -0
  115. package/dist/exports/cli/api/workflows/track-db-changes.mjs +1 -0
  116. package/dist/exports/cli/command.d.mts +54 -0
  117. package/dist/exports/cli/command.mjs +1 -0
  118. package/dist/exports/cli/context.d.mts +170 -0
  119. package/dist/exports/cli/index.d.mts +3 -0
  120. package/dist/exports/cli/index.mjs +1 -0
  121. package/dist/exports/devtools/index.d.ts +3 -0
  122. package/dist/exports/devtools/index.js +1 -0
  123. package/dist/exports/instrumentation.d.mts +1 -0
  124. package/dist/exports/instrumentation.mjs +1 -0
  125. package/dist/exports/tests/_virtual/rolldown_runtime.mjs +1 -0
  126. package/dist/exports/tests/api.d.mts +86 -0
  127. package/dist/exports/tests/api.mjs +1 -0
  128. package/dist/exports/tests/mock.d.mts +1 -0
  129. package/dist/exports/tests/mock.mjs +1 -0
  130. package/dist/exports/tests/node_modules/.bun/change-case@5.4.4/node_modules/change-case/dist/index.mjs +1 -0
  131. package/dist/exports/tests/node_modules/.bun/rate-limit-redis@4.3.1_f1fa5524233c9c60/node_modules/rate-limit-redis/dist/index.mjs +25 -0
  132. package/dist/exports/tests/packages/appos/src/api/app-context.d.mts +115 -0
  133. package/dist/exports/tests/packages/appos/src/api/auth-schema.d.mts +4248 -0
  134. package/dist/exports/tests/packages/appos/src/api/auth-schema.mjs +1 -0
  135. package/dist/exports/tests/packages/appos/src/api/auth.d.mts +398 -0
  136. package/dist/exports/tests/packages/appos/src/api/cache.d.mts +44 -0
  137. package/dist/exports/tests/packages/appos/src/api/config.d.mts +28 -0
  138. package/dist/exports/tests/packages/appos/src/api/container.d.mts +210 -0
  139. package/dist/exports/tests/packages/appos/src/api/database.d.mts +99 -0
  140. package/dist/exports/tests/packages/appos/src/api/database.mjs +1 -0
  141. package/dist/exports/tests/packages/appos/src/api/event.d.mts +235 -0
  142. package/dist/exports/tests/packages/appos/src/api/event.mjs +1 -0
  143. package/dist/exports/tests/packages/appos/src/api/i18n.d.mts +34 -0
  144. package/dist/exports/tests/packages/appos/src/api/index.d.mts +27 -0
  145. package/dist/exports/tests/packages/appos/src/api/logger.d.mts +21 -0
  146. package/dist/exports/tests/packages/appos/src/api/mailer.d.mts +70 -0
  147. package/dist/exports/tests/packages/appos/src/api/middleware/error-handler.mjs +1 -0
  148. package/dist/exports/tests/packages/appos/src/api/middleware/health.mjs +1 -0
  149. package/dist/exports/tests/packages/appos/src/api/middleware/i18n.mjs +1 -0
  150. package/dist/exports/tests/packages/appos/src/api/middleware/request-logger.d.mts +24 -0
  151. package/dist/exports/tests/packages/appos/src/api/middleware/request-logger.mjs +1 -0
  152. package/dist/exports/tests/packages/appos/src/api/middleware/shutdown.mjs +1 -0
  153. package/dist/exports/tests/packages/appos/src/api/middleware/timeout.mjs +1 -0
  154. package/dist/exports/tests/packages/appos/src/api/middleware/youch-handler.mjs +1 -0
  155. package/dist/exports/tests/packages/appos/src/api/middleware.d.mts +39 -0
  156. package/dist/exports/tests/packages/appos/src/api/middleware.mjs +1 -0
  157. package/dist/exports/tests/packages/appos/src/api/openapi.d.mts +271 -0
  158. package/dist/exports/tests/packages/appos/src/api/orm.d.mts +13 -0
  159. package/dist/exports/tests/packages/appos/src/api/otel.d.mts +40 -0
  160. package/dist/exports/tests/packages/appos/src/api/redis.d.mts +34 -0
  161. package/dist/exports/tests/packages/appos/src/api/redis.mjs +1 -0
  162. package/dist/exports/tests/packages/appos/src/api/server.mjs +1 -0
  163. package/dist/exports/tests/packages/appos/src/api/storage-schema.d.mts +707 -0
  164. package/dist/exports/tests/packages/appos/src/api/storage.d.mts +506 -0
  165. package/dist/exports/tests/packages/appos/src/api/workflow.d.mts +250 -0
  166. package/dist/exports/tests/packages/appos/src/api/workflow.mjs +1 -0
  167. package/dist/exports/tests/packages/appos/src/api/workflows/extract-blob-metadata.mjs +1 -0
  168. package/dist/exports/tests/packages/appos/src/api/workflows/generate-image-variant.d.mts +99 -0
  169. package/dist/exports/tests/packages/appos/src/api/workflows/generate-image-variant.mjs +1 -0
  170. package/dist/exports/tests/packages/appos/src/api/workflows/generate-preview.mjs +1 -0
  171. package/dist/exports/tests/packages/appos/src/api/workflows/purge-attachment.mjs +1 -0
  172. package/dist/exports/tests/packages/appos/src/api/workflows/purge-audit-logs.mjs +1 -0
  173. package/dist/exports/tests/packages/appos/src/api/workflows/purge-unattached-blobs.mjs +1 -0
  174. package/dist/exports/tests/packages/appos/src/api/workflows/track-db-changes.mjs +1 -0
  175. package/dist/exports/tests/packages/appos/src/constants.mjs +1 -0
  176. package/dist/exports/tests/packages/appos/src/instrumentation.d.mts +7 -0
  177. package/dist/exports/tests/packages/appos/src/instrumentation.mjs +1 -0
  178. package/dist/exports/tests/react.d.mts +2 -0
  179. package/dist/exports/tests/react.mjs +1 -0
  180. package/dist/exports/tests/setup.d.mts +1 -0
  181. package/dist/exports/tests/setup.mjs +1 -0
  182. package/dist/exports/vendors/date.js +1 -0
  183. package/dist/exports/vendors/toolkit.js +1 -0
  184. package/dist/exports/vendors/zod.d.ts +1 -0
  185. package/dist/exports/vendors/zod.js +1 -0
  186. package/dist/exports/vite/index.d.mts +19 -0
  187. package/dist/exports/vite/index.mjs +1 -0
  188. package/dist/exports/vitest/config.d.mts +1 -0
  189. package/dist/exports/vitest/config.mjs +1 -0
  190. package/dist/exports/vitest/globals.d.mts +1 -0
  191. package/dist/exports/vitest/globals.mjs +1 -0
  192. package/dist/exports/vitest/index.d.mts +1 -0
  193. package/dist/exports/vitest/index.mjs +1 -0
  194. package/dist/exports/web/api/auth.d.ts +125 -0
  195. package/dist/exports/web/api/database.d.ts +4 -0
  196. package/dist/exports/web/api/logger.d.ts +1 -0
  197. package/dist/exports/web/auth.d.ts +2388 -0
  198. package/dist/exports/web/auth.js +1 -0
  199. package/dist/exports/web/i18n.d.ts +42 -0
  200. package/dist/exports/web/i18n.js +1 -0
  201. package/dist/exports/web/index.d.ts +6 -0
  202. package/dist/exports/web/index.js +1 -0
  203. package/package.json +138 -98
  204. package/build/bin/main.mjs +0 -2
  205. package/build/exports/cli/index.d.mts +0 -325
  206. package/build/exports/cli/index.mjs +0 -1
  207. package/build/exports/instrumentation/execAsync-DaIUcs6_.mjs +0 -1
  208. package/build/exports/instrumentation/getMachineId-bsd-bB6ipDhm.mjs +0 -1
  209. package/build/exports/instrumentation/getMachineId-darwin-D1Bx5aCe.mjs +0 -2
  210. package/build/exports/instrumentation/getMachineId-linux-D_R9Tla0.mjs +0 -1
  211. package/build/exports/instrumentation/getMachineId-unsupported-BZKPE_Ev.mjs +0 -1
  212. package/build/exports/instrumentation/getMachineId-win-CmPvIqHL.mjs +0 -1
  213. package/build/exports/instrumentation/instrumentation.d.mts +0 -1
  214. package/build/exports/instrumentation/instrumentation.mjs +0 -80
  215. package/build/exports/server/index.d.mts +0 -327
  216. package/build/exports/server/index.mjs +0 -219
  217. package/build/exports/server/react-gPO8Jsy-.mjs +0 -13
  218. package/build/exports/server/server.node-D_9RYjm9.mjs +0 -210
  219. package/build/exports/store/index.d.mts +0 -58
  220. package/build/exports/store/index.mjs +0 -15
  221. package/build/exports/support/datetime.js +0 -1
  222. package/build/exports/support/utils.js +0 -1
  223. package/build/exports/support/zod.d.ts +0 -2
  224. package/build/exports/support/zod.js +0 -23
  225. package/build/exports/test/dist-DAsoCGWk.mjs +0 -348
  226. package/build/exports/test/index.d.mts +0 -3
  227. package/build/exports/test/index.mjs +0 -1
  228. package/build/exports/test/magic-string.es-BWgiB2kd.mjs +0 -14
  229. package/build/exports/test/setup.d.mts +0 -1
  230. package/build/exports/test/setup.mjs +0 -329
  231. /package/{build/exports/support/datetime.d.ts → dist/exports/vendors/date.d.ts} +0 -0
  232. /package/{build/exports/support/utils.d.ts → dist/exports/vendors/toolkit.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ import{sql as e}from"drizzle-orm";import{pgTable as t}from"drizzle-orm/pg-core";function n(){let n=t(`accounts`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),accessToken:t.text(`access_token`),accessTokenExpiresAt:t.timestamp(`access_token_expires_at`,{mode:`string`,withTimezone:!0}),accountId:t.text(`account_id`).notNull(),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),idToken:t.text(`id_token`),providerId:t.text(`provider_id`).notNull(),password:t.text(`password`),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),refreshToken:t.text(`refresh_token`),refreshTokenExpiresAt:t.timestamp(`refresh_token_expires_at`,{mode:`string`,withTimezone:!0}),scope:t.text(`scope`),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),r=t(`api_keys`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),name:t.text(`name`),enabled:t.boolean(`enabled`).default(!0),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}),key:t.text(`key`).notNull(),lastRefillAt:t.timestamp(`last_refill_at`,{mode:`string`,withTimezone:!0}),lastRequest:t.timestamp(`last_request`,{mode:`string`,withTimezone:!0}),lastUsedAt:t.timestamp(`last_used_at`,{mode:`string`,withTimezone:!0}),metadata:t.text(`metadata`),permissions:t.text(`permissions`),prefix:t.text(`prefix`),rateLimitEnabled:t.boolean(`rate_limit_enabled`).default(!0),rateLimitTimeWindow:t.integer(`rate_limit_time_window`).default(864e5),rateLimitMax:t.integer(`rate_limit_max`).default(10),refillInterval:t.integer(`refill_interval`),refillAmount:t.integer(`refill_amount`),requestCount:t.integer(`request_count`),remaining:t.integer(`remaining`),start:t.text(`start`),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),i=t(`invitations`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),email:t.text(`email`).notNull(),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}).notNull(),inviterId:t.text(`inviter_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),organizationId:t.text(`organization_id`).notNull().references(()=>o.id,{onDelete:`cascade`}),role:t.text(`role`),status:t.text(`status`).default(`pending`).notNull(),teamId:t.text(`team_id`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),a=t(`members`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),organizationId:t.text(`organization_id`).notNull().references(()=>o.id,{onDelete:`cascade`}),role:t.text(`role`).default(`member`).notNull(),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),o=t(`organizations`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),name:t.text(`name`).notNull(),slug:t.text(`slug`).unique(),logo:t.text(`logo`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),metadata:t.text(`metadata`)}),e=>[]),s=t(`sessions`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),activeOrganizationId:t.text(`active_organization_id`).references(()=>o.id,{onDelete:`set null`}),activeTeamId:t.text(`active_team_id`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}).notNull(),impersonatedBy:t.text(`impersonated_by`).references(()=>l.id,{onDelete:`set null`}),ipAddress:t.text(`ip_address`),token:t.text(`token`).notNull().unique(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),userAgent:t.text(`user_agent`),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`})}),e=>[]),c=t(`sso_providers`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),domain:t.text(`domain`).notNull(),issuer:t.text(`issuer`).notNull(),oidcConfig:t.text(`oidc_config`),organizationId:t.text(`organization_id`).references(()=>o.id,{onDelete:`cascade`}),providerId:t.text(`provider_id`).notNull().unique(),samlConfig:t.text(`saml_config`),userId:t.text(`user_id`).references(()=>l.id,{onDelete:`cascade`})}),e=>[]),l=t(`users`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),banExpires:t.timestamp(`ban_expires`,{mode:`string`,withTimezone:!0}),banReason:t.text(`ban_reason`),banned:t.boolean(`banned`).default(!1),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),displayUsername:t.text(`display_username`),email:t.text(`email`).notNull().unique(),emailVerified:t.boolean(`email_verified`).default(!1).notNull(),image:t.text(`image`),isAnonymous:t.boolean(`is_anonymous`),lastLoginMethod:t.text(`last_login_method`),name:t.text(`name`).notNull(),phoneNumber:t.text(`phone_number`).unique(),phoneNumberVerified:t.boolean(`phone_number_verified`),role:t.text(`role`),twoFactorEnabled:t.boolean(`two_factor_enabled`).default(!1),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),username:t.text(`username`).unique()}),e=>[]),u=t(`teams`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),name:t.text(`name`).notNull(),organizationId:t.text(`organization_id`).notNull().references(()=>o.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),d=t(`team_members`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),teamId:t.text(`team_id`).notNull().references(()=>u.id,{onDelete:`cascade`}),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),f=t(`two_factors`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),secret:t.text(`secret`).notNull(),backupCodes:t.text(`backup_codes`).notNull(),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`})}),e=>[]),p=t(`verifications`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}).notNull(),identifier:t.text(`identifier`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),value:t.text(`value`).notNull()}),e=>[]);return{tables:{accounts:n,apiKeys:r,auditLogs:t(`audit_logs`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),tableName:t.text(`table_name`),action:t.text(`action`).notNull(),customAction:t.text(`custom_action`),oldData:t.jsonb(`old_data`),newData:t.jsonb(`new_data`),metadata:t.jsonb(`metadata`),organizationId:t.text(`organization_id`).references(()=>o.id,{onDelete:`set null`}),userId:t.text(`user_id`).references(()=>l.id,{onDelete:`set null`}),sessionId:t.text(`session_id`).references(()=>s.id,{onDelete:`set null`}),requestId:t.text(`request_id`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),invitations:i,members:a,organizations:o,sessions:s,ssoProviders:c,teams:u,teamMembers:d,twoFactors:f,users:l,verifications:p},relations:e=>({users:{sessions:e.many.sessions({from:e.users.id,to:e.sessions.userId}),accounts:e.many.accounts({from:e.users.id,to:e.accounts.userId}),apiKeys:e.many.apiKeys({from:e.users.id,to:e.apiKeys.userId}),memberships:e.many.members({from:e.users.id,to:e.members.userId}),invitations:e.many.invitations({from:e.users.id,to:e.invitations.inviterId}),ssoProvider:e.one.ssoProviders({from:e.users.id,to:e.ssoProviders.userId}),twoFactor:e.one.twoFactors({from:e.users.id,to:e.twoFactors.userId})},sessions:{user:e.one.users({from:e.sessions.userId,to:e.users.id})},accounts:{user:e.one.users({from:e.accounts.userId,to:e.users.id})},apiKeys:{user:e.one.users({from:e.apiKeys.userId,to:e.users.id})},organizations:{members:e.many.members({from:e.organizations.id,to:e.members.organizationId}),invitations:e.many.invitations({from:e.organizations.id,to:e.invitations.organizationId}),teams:e.many.teams({from:e.organizations.id,to:e.teams.organizationId})},members:{organization:e.one.organizations({from:e.members.organizationId,to:e.organizations.id}),user:e.one.users({from:e.members.userId,to:e.users.id})},invitations:{organization:e.one.organizations({from:e.invitations.organizationId,to:e.organizations.id}),inviter:e.one.users({from:e.invitations.inviterId,to:e.users.id})},teams:{organization:e.one.organizations({from:e.teams.organizationId,to:e.organizations.id})},ssoProviders:{user:e.one.users({from:e.ssoProviders.userId,to:e.users.id})},verifications:{},twoFactors:{user:e.one.users({from:e.twoFactors.userId,to:e.users.id})},auditLogs:{organization:e.one.organizations({from:e.auditLogs.organizationId,to:e.organizations.id}),user:e.one.users({from:e.auditLogs.userId,to:e.users.id}),session:e.one.sessions({from:e.auditLogs.sessionId,to:e.sessions.id})}})}}export{n as defineAuthSchema};
@@ -0,0 +1,398 @@
1
+ import { Database, QualifiedTableNames } from "./database.mjs";
2
+ import { z } from "zod";
3
+ import { betterAuth } from "better-auth";
4
+ import { Role, createAccessControl } from "better-auth/plugins/access";
5
+
6
+ //#region src/api/auth.d.ts
7
+
8
+ /**
9
+ * Type for access controller created via createAccessControl().
10
+ * Used for RBAC on both server and client.
11
+ */
12
+ type AccessController = ReturnType<typeof createAccessControl>;
13
+ /**
14
+ * Type for roles created via ac.newRole().
15
+ * Uses Role type from better-auth for compatibility.
16
+ */
17
+ type AccessControlRoles = Record<string, Role>;
18
+ /**
19
+ * Standard audit log actions following OCSF/CADF standards.
20
+ * Zod enum provides both runtime validation and TypeScript type.
21
+ *
22
+ * Actions:
23
+ * - Data ops: INSERT, UPDATE, DELETE, TRUNCATE, SELECT
24
+ * - Auth ops: LOGIN, LOGOUT, LOGIN_FAILED, PASSWORD_CHANGE
25
+ * - Custom: CUSTOM (use customAction field for app-specific events)
26
+ */
27
+ declare const auditActionSchema: z.ZodEnum<{
28
+ DELETE: "DELETE";
29
+ LOGIN: "LOGIN";
30
+ LOGOUT: "LOGOUT";
31
+ INSERT: "INSERT";
32
+ PASSWORD_CHANGE: "PASSWORD_CHANGE";
33
+ TRUNCATE: "TRUNCATE";
34
+ UPDATE: "UPDATE";
35
+ }>;
36
+ /**
37
+ * TypeScript type extracted from Zod enum.
38
+ * Use this type for type annotations.
39
+ */
40
+ type AuditAction = z.infer<typeof auditActionSchema>;
41
+ /**
42
+ * Type-safe audit log options for defineAuth().
43
+ * Generic over db object to provide autocomplete for excludeTables.
44
+ *
45
+ * @template TDb - Database record type for table name inference
46
+ */
47
+ type AuditLogOptions<TDb> = {
48
+ /**
49
+ * Tables to exclude from audit logging.
50
+ */
51
+ excludeTables?: QualifiedTableNames<TDb>[];
52
+ /**
53
+ * Cron expression for purge schedule.
54
+ *
55
+ * @default "0 0 * * *"
56
+ */
57
+ purgeCron?: string;
58
+ /**
59
+ * Retention period in days. Audit logs older than this are auto-deleted.
60
+ * @default 90
61
+ */
62
+ retentionDays?: number;
63
+ };
64
+ /**
65
+ * Neutral auth configuration - shared between server and client.
66
+ * Contains ONLY fields that affect both sides (UI + server features).
67
+ *
68
+ * PRESENCE-BASED CONFIG: If a key exists, it's enabled. No redundant `enabled` fields.
69
+ * Server-only fields (appName, session) are passed via DefineAuthOptions.
70
+ */
71
+ interface AuthConfig {
72
+ /**
73
+ * Base URL where auth server is hosted.
74
+ *
75
+ * @default "" (same origin - client uses relative URLs)
76
+ * @example "http://localhost:8000" for cross-origin
77
+ */
78
+ baseURL?: string;
79
+ /**
80
+ * Base path for auth routes.
81
+ *
82
+ * @default "/auth"
83
+ */
84
+ basePath?: string;
85
+ /** Authentication methods - if defined, it's enabled */
86
+ methods?: {
87
+ /** Email/password auth. If defined, enabled. */
88
+ emailPassword?: {
89
+ requireEmailVerification?: boolean;
90
+ minPasswordLength?: number;
91
+ maxPasswordLength?: number;
92
+ };
93
+ /** Magic link auth. If defined, enabled. */
94
+ magicLink?: {
95
+ expiresIn?: number;
96
+ };
97
+ /** Passkey auth. If defined (even as empty object), enabled. */
98
+ passkey?: Record<string, never>;
99
+ /** Phone OTP auth. If defined, enabled. */
100
+ phoneOtp?: {
101
+ otpLength?: number;
102
+ expiresIn?: number;
103
+ };
104
+ /** Email OTP auth. If defined, enabled. */
105
+ emailOtp?: {
106
+ otpLength?: number;
107
+ expiresIn?: number;
108
+ };
109
+ };
110
+ /** OAuth providers - true = enabled, undefined/false = disabled */
111
+ oauth?: {
112
+ google?: boolean;
113
+ github?: boolean;
114
+ apple?: boolean;
115
+ facebook?: boolean;
116
+ };
117
+ /** Plugins - if defined, it's enabled */
118
+ plugins?: {
119
+ /** Admin plugin. If defined, enabled. Includes RBAC for both server and client. */
120
+ admin?: {
121
+ defaultRole?: string;
122
+ adminRoles?: string[];
123
+ /** Access controller created via createAccessControl() - shared between server and client */
124
+ ac: AccessController;
125
+ /** Role definitions created via ac.newRole() - shared between server and client */
126
+ roles: AccessControlRoles;
127
+ };
128
+ /** API key plugin. If defined, enabled. */
129
+ apiKey?: {
130
+ defaultPrefix?: string;
131
+ defaultKeyLength?: number;
132
+ rateLimit?: {
133
+ maxRequests?: number;
134
+ timeWindow?: number;
135
+ };
136
+ };
137
+ /** Two-factor plugin. If defined, enabled. Sub-features also presence-based. */
138
+ twoFactor?: {
139
+ issuer?: string;
140
+ totp?: {
141
+ digits?: 6 | 8;
142
+ period?: number;
143
+ };
144
+ otp?: boolean;
145
+ backupCodes?: {
146
+ amount?: number;
147
+ length?: number;
148
+ };
149
+ };
150
+ /** Multi-session plugin. If defined, enabled. */
151
+ multiSession?: {
152
+ maximumSessions?: number;
153
+ };
154
+ /** Username plugin. If defined, enabled. */
155
+ username?: {
156
+ minUsernameLength?: number;
157
+ maxUsernameLength?: number;
158
+ };
159
+ /** Anonymous auth plugin. If defined, enabled. */
160
+ anonymous?: {
161
+ emailDomainName?: string;
162
+ };
163
+ /** SSO plugin. If defined, enabled. Import from @better-auth/sso */
164
+ sso?: {
165
+ providersLimit?: number;
166
+ trustEmailVerified?: boolean;
167
+ domainVerification?: boolean;
168
+ };
169
+ };
170
+ }
171
+ /** Base hook types for reference */
172
+ type EmailHook = (params: {
173
+ email: string;
174
+ url: string;
175
+ token: string;
176
+ }) => Promise<void>;
177
+ type OtpHook = (params: {
178
+ email: string;
179
+ otp: string;
180
+ }) => Promise<void>;
181
+ type PhoneOtpHook = (params: {
182
+ phoneNumber: string;
183
+ otp: string;
184
+ }) => Promise<void>;
185
+ /**
186
+ * Conditionally required hooks based on config.
187
+ * Uses PRESENCE-BASED detection - if key exists, hook is REQUIRED.
188
+ */
189
+ type RequiredHooks<T extends AuthConfig> = (T["methods"] extends {
190
+ emailPassword: {
191
+ requireEmailVerification: true;
192
+ };
193
+ } ? {
194
+ sendVerificationEmail: EmailHook;
195
+ } : {
196
+ sendVerificationEmail?: EmailHook;
197
+ }) & (T["methods"] extends {
198
+ emailPassword: object;
199
+ } ? {
200
+ sendResetPasswordEmail: EmailHook;
201
+ } : {
202
+ sendResetPasswordEmail?: EmailHook;
203
+ }) & (T["methods"] extends {
204
+ magicLink: object;
205
+ } ? {
206
+ sendMagicLink: EmailHook;
207
+ } : {
208
+ sendMagicLink?: EmailHook;
209
+ }) & (T["methods"] extends {
210
+ emailOtp: object;
211
+ } ? {
212
+ sendEmailOTP: OtpHook;
213
+ } : {
214
+ sendEmailOTP?: OtpHook;
215
+ }) & (T["methods"] extends {
216
+ phoneOtp: object;
217
+ } ? {
218
+ sendPhoneOTP: PhoneOtpHook;
219
+ } : {
220
+ sendPhoneOTP?: PhoneOtpHook;
221
+ }) & (T["plugins"] extends {
222
+ twoFactor: {
223
+ otp: true;
224
+ };
225
+ } ? {
226
+ send2FAOTP: OtpHook;
227
+ } : {
228
+ send2FAOTP?: OtpHook;
229
+ });
230
+ /**
231
+ * Conditionally required OAuth credentials based on config.
232
+ * If an OAuth provider is enabled in config, its credentials are REQUIRED.
233
+ */
234
+ type RequiredOAuth<T extends AuthConfig> = (T["oauth"] extends {
235
+ google: true;
236
+ } ? {
237
+ google: {
238
+ clientId: string;
239
+ clientSecret: string;
240
+ };
241
+ } : {
242
+ google?: {
243
+ clientId: string;
244
+ clientSecret: string;
245
+ };
246
+ }) & (T["oauth"] extends {
247
+ github: true;
248
+ } ? {
249
+ github: {
250
+ clientId: string;
251
+ clientSecret: string;
252
+ };
253
+ } : {
254
+ github?: {
255
+ clientId: string;
256
+ clientSecret: string;
257
+ };
258
+ }) & (T["oauth"] extends {
259
+ apple: true;
260
+ } ? {
261
+ apple: {
262
+ clientId: string;
263
+ clientSecret: string;
264
+ };
265
+ } : {
266
+ apple?: {
267
+ clientId: string;
268
+ clientSecret: string;
269
+ };
270
+ }) & (T["oauth"] extends {
271
+ facebook: true;
272
+ } ? {
273
+ facebook: {
274
+ clientId: string;
275
+ clientSecret: string;
276
+ };
277
+ } : {
278
+ facebook?: {
279
+ clientId: string;
280
+ clientSecret: string;
281
+ };
282
+ });
283
+ /** Check if any OAuth provider is enabled */
284
+ type HasOAuthEnabled<T extends AuthConfig> = T["oauth"] extends {
285
+ google: true;
286
+ } | {
287
+ github: true;
288
+ } | {
289
+ apple: true;
290
+ } | {
291
+ facebook: true;
292
+ } ? true : false;
293
+ /** Check if passkey is enabled */
294
+ type HasPasskeyEnabled<T extends AuthConfig> = T["methods"] extends {
295
+ passkey: object;
296
+ } ? true : false;
297
+ /**
298
+ * Server-only session configuration.
299
+ */
300
+ interface AuthSessionConfig {
301
+ /**
302
+ * Session duration in seconds.
303
+ *
304
+ * @default 604800 (7 days)
305
+ */
306
+ expiresIn?: number;
307
+ /**
308
+ * How often to update session in seconds.
309
+ *
310
+ * @default 86400 (1 day)
311
+ */
312
+ updateAge?: number;
313
+ /**
314
+ * Session freshness in seconds for sensitive ops.
315
+ *
316
+ * @default 86400 (1 day)
317
+ */
318
+ freshAge?: number;
319
+ }
320
+ /**
321
+ * Server-only passkey configuration (required if passkey is enabled).
322
+ */
323
+ interface AuthPasskeyConfig {
324
+ /**
325
+ * Relying Party ID - domain for passkey (e.g., "example.com" or "localhost").
326
+ */
327
+ rpID: string;
328
+ /**
329
+ * Origin URL for passkey verification (e.g., "http://localhost:8000").
330
+ */
331
+ origin: string;
332
+ }
333
+ /**
334
+ * Fully type-safe options for defineAuth().
335
+ *
336
+ * Server-only fields:
337
+ * - `appName` - Application name for passkey rpName, TOTP issuer, emails
338
+ * - `auditLog` - Audit logging configuration
339
+ * - `session` - Session duration and freshness settings
340
+ *
341
+ * Conditional requirements:
342
+ * - If config has `oauth.google: true`, then `oauth.google` credentials are REQUIRED
343
+ * - If config has `methods.magicLink` defined, then `hooks.sendMagicLink` is REQUIRED
344
+ *
345
+ * @template T - Auth config type
346
+ * @template TDb - Database record type for type-safe excludeTables
347
+ */
348
+ type DefineAuthOptions<T extends AuthConfig, TDb = unknown> = {
349
+ /**
350
+ * The application name.
351
+ */
352
+ appName: string;
353
+ /**
354
+ * Audit logging configuration (server-only). Use qualified table names: "dbName.tableName".
355
+ */
356
+ auditLog?: AuditLogOptions<TDb>;
357
+ /**
358
+ * The neutral auth configuration.
359
+ */
360
+ config: T;
361
+ /**
362
+ * Full db object (container.db) for type inference.
363
+ */
364
+ db: TDb;
365
+ /**
366
+ * Primary database for Better Auth storage.
367
+ */
368
+ database: Database;
369
+ /**
370
+ * Hooks for email sending and OTP delivery.
371
+ */
372
+ hooks: RequiredHooks<T>;
373
+ /**
374
+ * Session configuration.
375
+ */
376
+ session?: AuthSessionConfig;
377
+ } & (HasOAuthEnabled<T> extends true ? {
378
+ oauth: RequiredOAuth<T>;
379
+ } : {
380
+ oauth?: RequiredOAuth<T>;
381
+ }) & (HasPasskeyEnabled<T> extends true ? {
382
+ passkey: AuthPasskeyConfig;
383
+ } : {
384
+ passkey?: AuthPasskeyConfig;
385
+ });
386
+ /**
387
+ * Defines Better Auth instance from neutral config + server dependencies.
388
+ */
389
+ declare function defineAuth<T extends AuthConfig, TDb extends Record<"primary", Database> & Record<string, Database> = Record<"primary", Database> & Record<string, Database>>(opts: DefineAuthOptions<T, TDb>): ReturnType<typeof betterAuth> & {
390
+ auditLog?: AuditLogOptions<TDb>;
391
+ shouldAudit(tableName: QualifiedTableNames<TDb>): boolean;
392
+ };
393
+ /**
394
+ * The auth instance type.
395
+ */
396
+ type Auth$1<TDb extends Record<"primary", Database> & Record<string, Database> = Record<"primary", Database> & Record<string, Database>> = ReturnType<typeof defineAuth<AuthConfig, TDb>>;
397
+ //#endregion
398
+ export { AccessControlRoles, AccessController, AuditAction, Auth$1 as Auth, AuthConfig, AuthPasskeyConfig, AuthSessionConfig, DefineAuthOptions, type Role, auditActionSchema, createAccessControl, defineAuth };
@@ -0,0 +1,44 @@
1
+ import { Logger } from "./logger.mjs";
2
+ import * as keyv0 from "keyv";
3
+ import { KeyvRedisOptions } from "@keyv/redis";
4
+
5
+ //#region src/api/cache.d.ts
6
+ /**
7
+ * The cache instance type.
8
+ */
9
+ type Cache = ReturnType<typeof defineCache>;
10
+ /**
11
+ * Options for defining the cache.
12
+ */
13
+ type DefineCacheOptions = {
14
+ /**
15
+ * Redis URL(s). Single or comma-separated for cluster.
16
+ */
17
+ url: string;
18
+ /**
19
+ * The logger instance.
20
+ */
21
+ logger: Logger;
22
+ /**
23
+ * The Keyv Redis options.
24
+ */
25
+ options?: KeyvRedisOptions;
26
+ };
27
+ /**
28
+ * Define the cache instance using shared Redis client.
29
+ * Connection is lazy - only connects when first cache operation is performed.
30
+ *
31
+ * Algorithm:
32
+ * 1. Create Redis client using defineRedisClient() (lazy connection)
33
+ * 2. Pass client to createKeyv() - connection happens on first use
34
+ *
35
+ * @param opts - The options for defining the cache.
36
+ * @returns The cache instance.
37
+ */
38
+ declare function defineCache({
39
+ url,
40
+ logger,
41
+ options
42
+ }: DefineCacheOptions): keyv0.Keyv<any>;
43
+ //#endregion
44
+ export { Cache, DefineCacheOptions, defineCache };
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/api/config.d.ts
4
+
5
+ /**
6
+ * The config base schema.
7
+ */
8
+ declare const baseSchema: z.ZodObject<{
9
+ APP_NAME: z.ZodDefault<z.ZodString>;
10
+ APP_DESC: z.ZodDefault<z.ZodString>;
11
+ APP_VERSION: z.ZodDefault<z.ZodString>;
12
+ }, z.core.$strip>;
13
+ /**
14
+ * Creates a configuration object by merging base config with user-defined schema.
15
+ *
16
+ * Variables in default values are expanded after defaults are applied.
17
+ * For example: `DATABASE_URL: z.string().default("postgres://{{DB_HOST}}:5432")`
18
+ *
19
+ * @param userSchema User-defined Zod schema to merge with base config.
20
+ * @returns Parsed and validated configuration object.
21
+ */
22
+ declare function defineConfig<T extends z.ZodRawShape = {}>(userSchema: z.ZodObject<T>): Config<T>;
23
+ /**
24
+ * The configuration type inferred from the merged schema.
25
+ */
26
+ type Config<T extends z.ZodRawShape = {}> = z.infer<ReturnType<typeof baseSchema.extend<T>>>;
27
+ //#endregion
28
+ export { Config, baseSchema, defineConfig };
@@ -0,0 +1,210 @@
1
+ import { Logger } from "./logger.mjs";
2
+ import { Database } from "./database.mjs";
3
+ import { Auth } from "./auth.mjs";
4
+ import { Cache } from "./cache.mjs";
5
+ import { Config } from "./config.mjs";
6
+ import { EventBus } from "./event.mjs";
7
+ import { Mailer } from "./mailer.mjs";
8
+ import { Storage } from "./storage.mjs";
9
+ import { CorsOptions } from "cors";
10
+ import { Options } from "express-rate-limit";
11
+ import { HelmetOptions } from "helmet";
12
+ import { i18n } from "i18next";
13
+
14
+ //#region src/api/container.d.ts
15
+
16
+ /**
17
+ * Server configuration for the HTTP server.
18
+ */
19
+ interface ServerConfig {
20
+ /**
21
+ * The host address the server will bind to.
22
+ *
23
+ * @default "0.0.0.0"
24
+ */
25
+ host?: string;
26
+ /**
27
+ * The port number the server will listen on.
28
+ */
29
+ port: number;
30
+ /**
31
+ * Request timeout in milliseconds. Requests exceeding this duration
32
+ * will receive a 408 Request Timeout response.
33
+ *
34
+ * @default 30000
35
+ */
36
+ timeout?: number;
37
+ /**
38
+ * Maximum request body size for JSON and URL-encoded payloads.
39
+ * Supports bytes.js format strings (e.g., "1mb", "500kb", "10mb").
40
+ *
41
+ * @default "1mb"
42
+ */
43
+ bodyLimit?: string;
44
+ /**
45
+ * The path for the health check endpoint.
46
+ *
47
+ * @default "/health"
48
+ */
49
+ healthPath?: string;
50
+ /**
51
+ * CORS configuration. Omit or set to undefined to disable.
52
+ *
53
+ * @example
54
+ * cors: { origin: "https://example.com", credentials: true }
55
+ */
56
+ cors?: CorsOptions;
57
+ /**
58
+ * Security headers configuration (via helmet). Omit or set to undefined to disable.
59
+ * Recommended for production deployments.
60
+ *
61
+ * @example
62
+ * helmet: { contentSecurityPolicy: false } // Enable with CSP disabled
63
+ * helmet: {} // Enable with all defaults
64
+ */
65
+ helmet?: HelmetOptions;
66
+ /**
67
+ * Rate limiting configuration. Array of express-rate-limit options.
68
+ * Each config is applied as a separate middleware - use `skip` function for path-specific limits.
69
+ * Redis store is automatically configured if `redisUrl` is provided.
70
+ *
71
+ * @example
72
+ * // Global rate limit
73
+ * rateLimit: [{ windowMs: 60000, limit: 100 }]
74
+ *
75
+ * @example
76
+ * // Path-specific rate limits
77
+ * rateLimit: [
78
+ * { windowMs: 900000, limit: 5, skip: (req) => !req.path.startsWith("/api/auth") },
79
+ * { windowMs: 60000, limit: 100 }, // Default for all other routes
80
+ * ]
81
+ */
82
+ rateLimit?: Options[];
83
+ /**
84
+ * Redis URL for rate limiting store (for multi-instance deployments).
85
+ * Server auto-connects and cleans up on shutdown.
86
+ * If omitted, uses in-memory store (not suitable for production clusters).
87
+ *
88
+ * @example
89
+ * redisUrl: "redis://localhost:6379"
90
+ */
91
+ redisUrl?: string;
92
+ }
93
+ /**
94
+ * Worker configuration for the DBOS workflow worker.
95
+ */
96
+ interface WorkerConfig {
97
+ /**
98
+ * The system database URL for DBOS.
99
+ */
100
+ dbUrl: string;
101
+ }
102
+ /**
103
+ * The base application container type that holds required services like
104
+ * config, databases, and caches.
105
+ */
106
+ interface AppContainer<TDb extends Record<"primary", Database> & Record<string, Database> = Record<"primary", Database> & Record<string, Database>> {
107
+ /**
108
+ * The application auth configuration.
109
+ */
110
+ auth: Auth<TDb>;
111
+ /**
112
+ * A map of caches available in the application.
113
+ */
114
+ cache: Record<string, Cache>;
115
+ /**
116
+ * The application configuration.
117
+ */
118
+ config: Config;
119
+ /**
120
+ * A map of databases available in the application.
121
+ */
122
+ db: TDb;
123
+ /**
124
+ * The i18n instance for internationalization.
125
+ */
126
+ i18n: i18n;
127
+ /**
128
+ * The logger instance for logging messages.
129
+ */
130
+ logger: Logger;
131
+ /**
132
+ * The event bus for in-memory and Redis pub/sub messaging.
133
+ */
134
+ eventBus: EventBus;
135
+ /**
136
+ * The mailer instance for sending emails.
137
+ */
138
+ mailer: Mailer;
139
+ /**
140
+ * Server configuration for the HTTP server.
141
+ */
142
+ server: ServerConfig;
143
+ /**
144
+ * A map of storage services available in the application.
145
+ */
146
+ storage: Record<"primary", Storage> & Record<string, Storage>;
147
+ /**
148
+ * Worker configuration for the DBOS workflow worker.
149
+ */
150
+ worker: WorkerConfig;
151
+ }
152
+ /**
153
+ * Global namespace for user container augmentation.
154
+ * Users can extend Container interface in their container.ts file.
155
+ */
156
+ declare global {
157
+ namespace AppOS {
158
+ interface Container {}
159
+ }
160
+ }
161
+ /**
162
+ * The container type used throughout the application.
163
+ * Merges base AppContainer with user's custom Container augmentations.
164
+ */
165
+ type Container = AppContainer & AppOS.Container;
166
+ /**
167
+ * Defines an application container with type-safe validation and inference.
168
+ *
169
+ * This helper function ensures that:
170
+ * 1. All required base fields (config, cache, db) are provided
171
+ * 2. Custom fields are fully preserved in the inferred type
172
+ * 3. TypeScript provides autocomplete for all fields in commands/routes
173
+ *
174
+ * @template T - The container type extending AppContainer
175
+ * @param container - The container object with required and custom fields
176
+ * @returns The same container object with full type inference
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * // In your api/main.ts file:
181
+ * export async function defineContainer() {
182
+ * const config = defineConfig(z.object({
183
+ * PORT: z.coerce.number().default(3000),
184
+ * EVENTS_DB_URL: z.string(),
185
+ * WORKER_DB_URL: z.string(),
186
+ * }));
187
+ * const logger = defineLogger({ level: config.LOG_LEVEL });
188
+ *
189
+ * return defineAppContainer({
190
+ * auth: defineAuth({ config }),
191
+ * cache: {},
192
+ * config,
193
+ * db: {},
194
+ * eventBus: defineEventBus({ dbUrl: config.EVENTS_DB_URL, logger }),
195
+ * i18n: await defineI18n({ ... }),
196
+ * logger,
197
+ * mailer: defineMailer({ ... }),
198
+ * server: {
199
+ * port: config.PORT,
200
+ * },
201
+ * worker: {
202
+ * dbUrl: config.WORKER_DB_URL,
203
+ * },
204
+ * });
205
+ * }
206
+ * ```
207
+ */
208
+ declare function defineAppContainer<T extends AppContainer>(container: T): T;
209
+ //#endregion
210
+ export { AppContainer, Container, ServerConfig, WorkerConfig, defineAppContainer };