@starci/hfs 5.0.8 → 5.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 (339) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +10 -1
  3. package/cache/import-graph.mjs +6 -61
  4. package/cache/lint-family.d.mts +10 -1
  5. package/cache/lint-family.mjs +12 -5
  6. package/codemod/directive-first.d.mts +48 -0
  7. package/codemod/directive-first.mjs +136 -0
  8. package/codemod/explicit-surface-edit.d.mts +14 -0
  9. package/codemod/explicit-surface-edit.mjs +57 -0
  10. package/codemod/explicit-surface-names.d.mts +30 -0
  11. package/codemod/explicit-surface-names.mjs +135 -0
  12. package/codemod/explicit-surface-render.d.mts +29 -0
  13. package/codemod/explicit-surface-render.mjs +197 -0
  14. package/codemod/explicit-surface.d.mts +50 -0
  15. package/codemod/explicit-surface.mjs +374 -0
  16. package/codemod/main.d.mts +7 -5
  17. package/codemod/main.mjs +37 -16
  18. package/codemod/source-tree.d.mts +8 -0
  19. package/codemod/source-tree.mjs +23 -0
  20. package/db/postgres.mjs +9 -1
  21. package/lint/eslint-list.cjs +29 -0
  22. package/lint/run.d.mts +19 -5
  23. package/lint/run.mjs +47 -14
  24. package/package.json +1 -1
  25. package/runtime/knowledge/hfs/canon-pins.yaml +31 -10
  26. package/runtime/knowledge/hfs/fe-stack.yaml +7 -7
  27. package/runtime/knowledge/hfs/fork-images.yaml +7 -0
  28. package/runtime/knowledge/hfs/rules.yaml +107 -8
  29. package/runtime/knowledge/hfs/slots.yaml +75 -24
  30. package/runtime/modules/kernel/failure-codes.yaml +62 -0
  31. package/runtime/modules/schemas/application-stacks.schema.yaml +6 -0
  32. package/runtime/scripts/hfs/architecture/identity.mjs +18 -83
  33. package/runtime/scripts/hfs/architecture/test-world-files.d.mts +4 -3
  34. package/runtime/scripts/hfs/architecture/test-world-files.mjs +26 -7
  35. package/runtime/scripts/hfs/architecture/transport-owner.d.mts +1 -2
  36. package/runtime/scripts/hfs/architecture/transport-owner.mjs +3 -6
  37. package/runtime/scripts/hfs/explicit-surface-rule.d.mts +58 -0
  38. package/runtime/scripts/hfs/explicit-surface-rule.mjs +59 -0
  39. package/runtime/scripts/hfs/manifest-shape.d.mts +1 -0
  40. package/runtime/scripts/hfs/manifest-shape.mjs +3 -1
  41. package/runtime/scripts/hfs/rules/a15-findings.mjs +5 -0
  42. package/runtime/scripts/hfs/rules/stacks-local.d.mts +7 -0
  43. package/runtime/scripts/hfs/rules/stacks-local.mjs +71 -0
  44. package/runtime/scripts/hfs/rules/stacks-runtime.mjs +6 -1
  45. package/runtime/scripts/hfs/rules/stacks-service-images.d.mts +12 -0
  46. package/runtime/scripts/hfs/rules/stacks-service-images.mjs +120 -0
  47. package/runtime/scripts/hfs/secret-dev-init.d.mts +11 -0
  48. package/runtime/scripts/hfs/secret-dev-init.mjs +79 -0
  49. package/runtime/scripts/hfs/secret.mjs +10 -7
  50. package/runtime/scripts/hfs/slots.mjs +1 -1
  51. package/runtime/scripts/hfs/stack-local-config.d.mts +101 -0
  52. package/runtime/scripts/hfs/stack-local-config.mjs +320 -0
  53. package/runtime/scripts/hfs/stacks-gate.mjs +1 -1
  54. package/runtime/scripts/lib/declaration-surface.d.mts +35 -0
  55. package/runtime/scripts/lib/declaration-surface.mjs +112 -0
  56. package/runtime/scripts/lib/swarm-stack.d.mts +2 -1
  57. package/runtime/scripts/lib/swarm-stack.mjs +2 -2
  58. package/scaffold/add-module.d.mts +16 -0
  59. package/scaffold/add-module.mjs +232 -0
  60. package/scaffold/add-queue-lite.mjs +49 -0
  61. package/scaffold/add.mjs +5 -0
  62. package/scaffold/app.mjs +7 -7
  63. package/scaffold/module-registry.d.mts +19 -0
  64. package/scaffold/module-registry.mjs +84 -0
  65. package/src/main.mjs +23 -2
  66. package/stack/cli.mjs +6 -1
  67. package/stack/context.d.mts +15 -0
  68. package/stack/context.mjs +1 -0
  69. package/stack/local-cli.d.mts +25 -0
  70. package/stack/local-cli.mjs +89 -0
  71. package/stack/local-config.d.mts +17 -0
  72. package/stack/local-config.mjs +37 -0
  73. package/stack/local-custody.d.mts +24 -0
  74. package/stack/local-custody.mjs +109 -0
  75. package/stack/local-doctor.d.mts +6 -0
  76. package/stack/local-doctor.mjs +49 -0
  77. package/stack/local-down.d.mts +8 -0
  78. package/stack/local-down.mjs +20 -0
  79. package/stack/local-host.d.mts +42 -0
  80. package/stack/local-host.mjs +163 -0
  81. package/stack/local-logs.d.mts +8 -0
  82. package/stack/local-logs.mjs +32 -0
  83. package/stack/local-ports.d.mts +7 -0
  84. package/stack/local-ports.mjs +39 -0
  85. package/stack/local-prepare.d.mts +22 -0
  86. package/stack/local-prepare.mjs +62 -0
  87. package/stack/local-run.d.mts +71 -0
  88. package/stack/local-run.mjs +200 -0
  89. package/stack/local-state.d.mts +35 -0
  90. package/stack/local-state.mjs +29 -0
  91. package/stack/local-status.d.mts +6 -0
  92. package/stack/local-status.mjs +36 -0
  93. package/stack/local-up.d.mts +11 -0
  94. package/stack/local-up.mjs +166 -0
  95. package/stack/local-verify.d.mts +6 -0
  96. package/stack/local-verify.mjs +21 -0
  97. package/sync/index.d.mts +13 -12
  98. package/sync/index.mjs +83 -28
  99. package/templates/app/module/jest.config.js.tpl +8 -0
  100. package/templates/app/module/src/index.ts.tpl +2 -0
  101. package/templates/app/module/src/manifest/declaration.spec.ts.tpl +11 -0
  102. package/templates/app/module/src/manifest/declaration.ts.tpl +13 -0
  103. package/templates/app/module/src/manifest/index.ts.tpl +1 -0
  104. package/templates/app/module/src/public/index.ts.tpl +2 -0
  105. package/templates/app/module/src/template/__name__.template.spec.ts.tpl +13 -0
  106. package/templates/app/module/src/template/__name__.template.ts.tpl +41 -0
  107. package/templates/app/module/src/template/index.ts.tpl +1 -0
  108. package/templates/app/module/src/workbench/components/__pascal__WorkbenchView.tsx.tpl +16 -0
  109. package/templates/app/module/src/workbench/index.ts.tpl +2 -0
  110. package/templates/app/package-scripts/package.json +1 -1
  111. package/templates/app/package-scripts-lite/package.json +1 -1
  112. package/templates/app/skeleton-lite/.starcistacks/application-stacks.yaml +76 -70
  113. package/templates/app/skeleton-lite/.starcistacks/dev/README.md +23 -13
  114. package/templates/app/skeleton-lite/.starcistacks/dev/infra/compose/compose.yaml +25 -0
  115. package/templates/app/skeleton-lite/.starcistacks/dev/runtime/env/KEYS.md +18 -26
  116. package/templates/app/skeleton-lite/.starcistacks/production/infra/swarm/stack.yaml +1 -0
  117. package/templates/app/skeleton-lite/.starcistacks/production/runtime/env/KEYS.md +2 -1
  118. package/templates/app/skeleton-lite/db/migrations/__timestamp___baseline.sql +57 -14
  119. package/templates/be/auth-lite/src/features/api/auth/application/auth.contracts.ts +11 -0
  120. package/templates/be/auth-lite/src/features/api/auth/application/get-jwks.handler.ts +23 -0
  121. package/templates/be/auth-lite/src/features/api/auth/application/get-jwks.query.ts +12 -0
  122. package/templates/be/auth-lite/src/features/api/auth/application/google-begin.command.ts +11 -0
  123. package/templates/be/auth-lite/src/features/api/auth/application/google-begin.handler.ts +22 -0
  124. package/templates/be/auth-lite/src/features/api/auth/application/google-complete.command.ts +12 -0
  125. package/templates/be/auth-lite/src/features/api/auth/application/google-complete.handler.ts +23 -0
  126. package/templates/be/auth-lite/src/features/api/auth/application/login.command.ts +12 -0
  127. package/templates/be/auth-lite/src/features/api/auth/application/login.handler.ts +23 -0
  128. package/templates/be/auth-lite/src/features/api/auth/application/logout.command.ts +11 -0
  129. package/templates/be/auth-lite/src/features/api/auth/application/logout.handler.ts +22 -0
  130. package/templates/be/auth-lite/src/features/api/auth/application/refresh.command.ts +12 -0
  131. package/templates/be/auth-lite/src/features/api/auth/application/refresh.handler.ts +23 -0
  132. package/templates/be/auth-lite/src/features/api/auth/application/session.command.ts +12 -0
  133. package/templates/be/auth-lite/src/features/api/auth/application/session.handler.ts +23 -0
  134. package/templates/be/auth-lite/src/features/api/auth/auth.module-definition.ts +13 -0
  135. package/templates/be/auth-lite/src/features/api/auth/auth.module.ts +16 -0
  136. package/templates/be/auth-lite/src/features/api/auth/auth.options.ts +3 -0
  137. package/templates/be/auth-lite/src/features/api/auth/index.ts +2 -0
  138. package/templates/be/auth-lite/src/features/api/auth/transport/http/auth-http.module-definition.ts +13 -0
  139. package/templates/be/auth-lite/src/features/api/auth/transport/http/auth-http.module.ts +9 -0
  140. package/templates/be/auth-lite/src/features/api/auth/transport/http/auth-http.options.ts +3 -0
  141. package/templates/be/auth-lite/src/features/api/auth/transport/http/auth.controller.ts +90 -0
  142. package/templates/be/auth-lite/src/features/api/auth/transport/http/dto/google-start.request.ts +17 -0
  143. package/templates/be/auth-lite/src/features/api/auth/transport/http/dto/login.request.ts +16 -0
  144. package/templates/be/auth-lite/src/modules/domain/identity/account-directory.service.spec.ts +46 -0
  145. package/templates/be/auth-lite/src/modules/domain/identity/account-directory.service.ts +28 -0
  146. package/templates/be/auth-lite/src/modules/domain/identity/authenticator.service.spec.ts +145 -0
  147. package/templates/be/auth-lite/src/modules/domain/identity/authenticator.service.ts +95 -0
  148. package/templates/be/auth-lite/src/modules/domain/identity/persistence/entities/auth-identity.entity.ts +38 -0
  149. package/templates/be/auth-lite/src/modules/domain/identity/persistence/entities/auth-user.entity.ts +54 -0
  150. package/templates/be/auth-lite/src/modules/domain/identity/persistence/entities/identity-attempt.entity.ts +18 -0
  151. package/templates/be/auth-lite/src/modules/domain/identity/persistence/entities/identity-refresh-token.entity.ts +34 -0
  152. package/templates/be/auth-lite/src/modules/domain/identity/persistence/entities/identity-session.entity.ts +30 -0
  153. package/templates/be/auth-lite/src/modules/domain/identity/persistence/entities/index.ts +17 -0
  154. package/templates/be/auth-lite/src/modules/domain/identity/rate-counter.service.spec.ts +86 -0
  155. package/templates/be/auth-lite/src/modules/domain/identity/rate-counter.service.ts +45 -0
  156. package/templates/be/auth-lite/src/modules/domain/identity/session-store.service.spec.ts +97 -0
  157. package/templates/be/auth-lite/src/modules/domain/identity/session-store.service.ts +81 -0
  158. package/templates/be/auth-lite/src/modules/domain/identity/sign-in.service.spec.ts +78 -0
  159. package/templates/be/auth-lite/src/modules/domain/identity/sign-in.service.ts +87 -0
  160. package/templates/be/auth-lite/src/tests/fixtures/builders/identity.builder.ts +44 -0
  161. package/templates/be/inbox/delivery-recorded.event.ts.tpl +2 -2
  162. package/templates/be/inbox/entities.index.ts.tpl +1 -1
  163. package/templates/be/inbox/module-definition.ts.tpl +8 -2
  164. package/templates/be/inbox/platform/event-bus/event-bus.module-definition.ts.tpl +10 -2
  165. package/templates/be/inbox/platform/inbox/inbox.module-definition.ts.tpl +8 -2
  166. package/templates/be/patterns/api/feature.module-definition.ts.tpl +9 -3
  167. package/templates/be/patterns/api/graphql.module-definition.ts.tpl +9 -3
  168. package/templates/be/patterns/cli/group.module-definition.ts.tpl +9 -3
  169. package/templates/be/patterns/event-bus/platform/event-bus.module-definition.ts.tpl +8 -3
  170. package/templates/be/patterns/event-bus/platform/persistence/connection.ts.tpl +3 -2
  171. package/templates/be/patterns/event-bus/platform/persistence/event-bus.sql.ts.tpl +4 -3
  172. package/templates/be/patterns/idempotency/platform/inbox/inbox.module-definition.ts.tpl +8 -3
  173. package/templates/be/patterns/idempotency/platform/inbox/persistence/connection.ts.tpl +3 -2
  174. package/templates/be/patterns/idempotency/platform/inbox/persistence/inbox.sql.ts.tpl +7 -6
  175. package/templates/be/patterns/jobs/job.module-definition.ts.tpl +9 -3
  176. package/templates/be/patterns/jobs/job.processor.ts.tpl +1 -1
  177. package/templates/be/patterns/jobs/job.queue.module-definition.ts.tpl +9 -3
  178. package/templates/be/patterns/jobs/platform/jobs.module-definition.ts.tpl +8 -3
  179. package/templates/be/patterns/jobs/platform/persistence.connection.ts.tpl +3 -2
  180. package/templates/be/patterns/jobs/platform/persistence.jobs.sql.ts.tpl +5 -4
  181. package/templates/be/patterns/projections/persistence.connection.ts.tpl +3 -2
  182. package/templates/be/patterns/projections/projection.module-definition.ts.tpl +8 -3
  183. package/templates/be/patterns/queues/platform/persistence.connection.ts.tpl +3 -2
  184. package/templates/be/patterns/queues/platform/persistence.queue.sql.ts.tpl +4 -3
  185. package/templates/be/patterns/queues/platform/queue.module-definition.ts.tpl +8 -3
  186. package/templates/be/patterns/queues/queue.module-definition.ts.tpl +9 -3
  187. package/templates/be/patterns/reactors/consumer.ts.tpl +1 -1
  188. package/templates/be/patterns/reactors/message.module-definition.ts.tpl +9 -3
  189. package/templates/be/patterns/reactors/reactor.module-definition.ts.tpl +9 -3
  190. package/templates/be/patterns/realtime/channel.graphql.module-definition.ts.tpl +9 -3
  191. package/templates/be/patterns/realtime/channel.sse.module-definition.ts.tpl +9 -3
  192. package/templates/be/patterns/realtime/channel.websocket.module-definition.ts.tpl +9 -3
  193. package/templates/be/patterns/saga/saga.done.consumer.ts.tpl +1 -1
  194. package/templates/be/patterns/saga/saga.failed.consumer.ts.tpl +1 -1
  195. package/templates/be/patterns/saga/saga.message.module-definition.ts.tpl +9 -3
  196. package/templates/be/patterns/saga/saga.module-definition.ts.tpl +9 -3
  197. package/templates/be/patterns/webhooks/webhook.http.module-definition.ts.tpl +9 -3
  198. package/templates/be/platform/graphql/graphql.module-definition.ts +8 -3
  199. package/templates/be/skeleton/src/features/api/system-health/system-health.module-definition.ts +9 -3
  200. package/templates/be/skeleton/src/features/api/system-health/transport/http/system-health-http.module-definition.ts +9 -3
  201. package/templates/be/skeleton/src/features/cli/cli.module-definition.ts +9 -3
  202. package/templates/be/skeleton/src/features/cli/migrate/migrate.module-definition.ts +9 -3
  203. package/templates/be/skeleton/src/features/cli/seed/seed.module-definition.ts +9 -3
  204. package/templates/be/skeleton/src/modules/domain/identity/identity.module-definition.ts +8 -3
  205. package/templates/be/skeleton/src/modules/domain/liveness/liveness.module-definition.ts +8 -3
  206. package/templates/be/skeleton/src/modules/domain/note/note.module-definition.ts +8 -3
  207. package/templates/be/skeleton/src/modules/domain/note/persistence/connection.ts +3 -2
  208. package/templates/be/skeleton/src/modules/domain/note/persistence/note.sql.ts +2 -1
  209. package/templates/be/skeleton/src/modules/platform/clock/clock.module-definition.ts +8 -3
  210. package/templates/be/skeleton/src/modules/platform/cqrs/cqrs.module-definition.ts +8 -3
  211. package/templates/be/skeleton/src/modules/platform/database/database.module-definition.ts +8 -3
  212. package/templates/be/skeleton/src/modules/platform/database/index.ts +1 -0
  213. package/templates/be/skeleton/src/modules/platform/errors/errors.module-definition.ts +10 -4
  214. package/templates/be/skeleton/src/modules/platform/http/http.module-definition.ts +8 -4
  215. package/templates/be/skeleton/src/modules/platform/http-security/http-security.module-definition.ts +10 -4
  216. package/templates/be/skeleton/src/modules/platform/http-security/persistence/connection.ts +3 -2
  217. package/templates/be/skeleton/src/modules/platform/http-security/persistence/rate-limit.sql.ts +3 -2
  218. package/templates/be/skeleton/src/modules/platform/i18n/i18n.module-definition.ts +10 -4
  219. package/templates/be/skeleton/src/modules/platform/ids/ids.module-definition.ts +8 -3
  220. package/templates/be/skeleton/src/modules/platform/logging/logging.module-definition.ts +8 -3
  221. package/templates/be/skeleton/src/modules/platform/retry/retry.module-definition.ts +8 -3
  222. package/templates/be/skeleton-lite/apps/api/src/app.module.ts +6 -5
  223. package/templates/be/skeleton-lite/apps/api/src/compose/api.ts +3 -2
  224. package/templates/be/skeleton-lite/apps/api/src/compose/integrations.ts +10 -5
  225. package/templates/be/skeleton-lite/src/modules/domain/identity/errors/identity.error.ts +34 -0
  226. package/templates/be/skeleton-lite/src/modules/domain/identity/identity.decorators.ts +23 -2
  227. package/templates/be/skeleton-lite/src/modules/domain/identity/identity.module.ts +47 -2
  228. package/templates/be/skeleton-lite/src/modules/domain/identity/index.ts +2 -0
  229. package/templates/be/skeleton-lite/src/modules/domain/identity/messages/identity.messages.ts +24 -0
  230. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/index.ts +3 -3
  231. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/object-storage.config.ts +3 -1
  232. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/object-storage.decorators.ts +8 -4
  233. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/object-storage.module-definition.ts +12 -0
  234. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/object-storage.module.ts +29 -0
  235. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/object-storage.options.ts +6 -31
  236. package/templates/be/skeleton-lite/src/modules/integrations/passport/errors/passport.error.ts +18 -9
  237. package/templates/be/skeleton-lite/src/modules/integrations/passport/index.ts +35 -11
  238. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.config.spec.ts +44 -8
  239. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.config.ts +40 -18
  240. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.decorators.ts +18 -6
  241. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.kit.spec.ts +73 -0
  242. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.kit.ts +26 -0
  243. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.options.ts +24 -53
  244. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.registration.ts +31 -0
  245. package/templates/be/skeleton-lite/src/modules/platform/cqrs/index.ts +1 -1
  246. package/templates/be/skeleton-lite/src/modules/platform/database/database.port.ts +1 -1
  247. package/templates/be/skeleton-lite/src/modules/platform/database/entities.ts +2 -1
  248. package/templates/be/skeleton-lite/src/modules/platform/http-security/index.ts +1 -1
  249. package/templates/be/skeleton-lite/src/modules/platform/http-security/persistence/entities/index.ts +1 -1
  250. package/templates/be/skeleton-lite/src/tests/fixtures/builders/api.builder.ts +18 -5
  251. package/templates/be/skeleton-lite/src/tests/fixtures/builders/cli.builder.ts +7 -1
  252. package/templates/be/table/api/feature.module-definition.ts.tpl +9 -3
  253. package/templates/be/table/api/graphql.module-definition.ts.tpl +9 -3
  254. package/templates/be/table/entities.index.ts.tpl +1 -1
  255. package/templates/be/table/module-definition.ts.tpl +8 -3
  256. package/templates/be/test-world/e2e/serves-once-migrated.e2e-spec.ts.tpl +9 -9
  257. package/templates/be/test-world/fixtures/migrations.sql.ts.tpl +4 -3
  258. package/templates/be/test-world/world/test-world.config.ts.tpl +8 -1
  259. package/templates/fe/auth-lite/apps/web/src/modules/auth/client.ts +26 -0
  260. package/templates/fe/common/app-layout.tsx.partial +1 -1
  261. package/templates/fe/common/site-shell.tsx.partial +3 -3
  262. package/templates/fe/skeleton/apps/__app__/src/components/providers/AppProviders/index.tsx +33 -10
  263. package/templates/fe/skeleton/apps/__app__/src/hooks/auth/index.ts +1 -0
  264. package/templates/fe/skeleton/apps/__app__/src/hooks/auth/useSession.ts +2 -1
  265. package/templates/fe/skeleton/apps/__app__/src/hooks/auth/useSignIn.ts +11 -3
  266. package/templates/fe/skeleton/apps/__app__/src/hooks/auth/useSignOut.ts +8 -2
  267. package/templates/fe/skeleton/apps/__app__/src/hooks/auth/useViewerId.ts +11 -0
  268. package/templates/fe/skeleton/apps/__app__/src/hooks/zustand/appGuide/store.ts +2 -1
  269. package/templates/fe/skeleton/apps/__app__/src/modules/toast/hooks.ts +1 -1
  270. package/templates/fe/skeleton/apps/__app__/src/modules/toast/toast.tsx +18 -12
  271. package/templates/fe/skeleton/apps/__app__/src/modules/viewer-cache/index.ts +5 -0
  272. package/templates/fe/skeleton/apps/__app__/src/redux/hooks.ts +3 -2
  273. package/templates/fe/skeleton/apps/__app__/src/redux/index.ts +1 -0
  274. package/templates/fe/skeleton/apps/__app__/src/redux/slices/session.ts +12 -4
  275. package/templates/fe/skeleton/apps/__app__/src/redux/store.ts +8 -3
  276. package/templates/fe/skeleton/apps/app/src/app/[locale]/layout.tsx +4 -3
  277. package/templates/fe/skeleton/apps/app/src/features/layouts/AppLayout/index.tsx +1 -1
  278. package/templates/fe/skeleton/apps/app/src/features/pages/AppHomePage/index.tsx +2 -1
  279. package/templates/fe/skeleton/apps/app/src/features/pages/AppLoadingPage/index.tsx +2 -1
  280. package/templates/fe/skeleton/apps/app/src/features/pages/AppNotFoundPage/index.tsx +2 -1
  281. package/templates/fe/skeleton/apps/app/src/modules/i18n/index.ts +2 -1
  282. package/templates/fe/skeleton/apps/app/src/modules/i18n/request.ts +4 -1
  283. package/templates/fe/skeleton/apps/landing/src/app/[locale]/layout.tsx +4 -3
  284. package/templates/fe/skeleton/apps/landing/src/features/layouts/LandingLayout/index.tsx +2 -2
  285. package/templates/fe/skeleton/apps/landing/src/features/pages/LandingLoadingPage/index.tsx +2 -1
  286. package/templates/fe/skeleton/apps/landing/src/features/pages/LandingNotFoundPage/index.tsx +2 -1
  287. package/templates/fe/skeleton/apps/landing/src/features/pages/LandingPage/index.tsx +2 -1
  288. package/templates/fe/skeleton/apps/landing/src/modules/i18n/index.ts +2 -1
  289. package/templates/fe/skeleton/apps/landing/src/modules/i18n/request.ts +4 -1
  290. package/templates/fe/skeleton/packages/__project__-i18n/src/index.ts +20 -2
  291. package/templates/fe/skeleton/packages/__project__-i18n/src/proxy.ts +1 -1
  292. package/templates/fe/skeleton/packages/__project__-i18n/src/routing.ts +5 -1
  293. package/templates/fe/skeleton/packages/__project__-ui/src/composites/NotFoundNotice/index.tsx +4 -7
  294. package/templates/fe/skeleton/packages/__project__-ui/src/frames/SiteShell/index.tsx +2 -3
  295. package/templates/fe/skeleton-lite/apps/web/src/app/[locale]/layout.tsx +4 -3
  296. package/templates/fe/skeleton-lite/apps/web/src/components/composites/NotFoundNotice/index.tsx +4 -7
  297. package/templates/fe/skeleton-lite/apps/web/src/components/frames/SiteShell/index.tsx +1 -2
  298. package/templates/fe/skeleton-lite/apps/web/src/features/layouts/AppLayout/index.tsx +2 -2
  299. package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppHomePage/index.tsx +2 -1
  300. package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppLoadingPage/index.tsx +2 -1
  301. package/templates/fe/skeleton-lite/apps/web/src/features/pages/AppNotFoundPage/index.tsx +2 -1
  302. package/templates/fe/skeleton-lite/apps/web/src/modules/i18n/request.ts +3 -1
  303. package/templates/fe/skeleton-lite/apps/web/src/modules/i18n/routing.ts +5 -1
  304. package/templates/fe/table/graphql/useMutateSwr.ts.tpl +2 -1
  305. package/templates/fe/table/graphql/useQuerySwr.ts.tpl +2 -1
  306. package/templates/fe/transport/graphql/clients/clients/auth.ts +1 -1
  307. package/templates/fe/transport/graphql/clients/clients/no-auth.ts +1 -1
  308. package/templates/fe/transport/graphql/clients/links/attach-access-token.ts +1 -1
  309. package/templates/fe/transport/graphql/clients/links/error.ts +1 -1
  310. package/templates/fe/transport/graphql/clients/links/http.ts +1 -1
  311. package/templates/fe/transport/graphql/clients/links/locale.ts +1 -1
  312. package/templates/fe/transport/graphql/clients/links/refresh-token.ts +1 -1
  313. package/templates/fe/transport/graphql/clients/links/retry.ts +1 -1
  314. package/templates/fe/transport/graphql/clients/links/timeout.ts +1 -1
  315. package/templates/fe/units/page/index.tsx.tpl +3 -2
  316. package/templates/fe/units/slot/SlotView.tsx.tpl +1 -1
  317. package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/Caddyfile +0 -16
  318. package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/owner-actions.md +0 -11
  319. package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/recovery/restore-proof.md +0 -7
  320. package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/releases/current.yaml +0 -6
  321. package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/releases/images.lock.yaml +0 -8
  322. package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/releases/previous.yaml +0 -6
  323. package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/stack.yaml +0 -186
  324. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/object-storage.client.spec.ts +0 -22
  325. package/templates/be/skeleton-lite/src/modules/integrations/object-storage/object-storage.client.ts +0 -25
  326. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.cookie.spec.ts +0 -104
  327. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.cookie.ts +0 -34
  328. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.password.spec.ts +0 -28
  329. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.password.ts +0 -11
  330. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.tokens.spec.ts +0 -88
  331. package/templates/be/skeleton-lite/src/modules/integrations/passport/passport.tokens.ts +0 -69
  332. package/templates/be/skeleton-lite/src/modules/integrations/passport/strategies/google.strategy.ts +0 -37
  333. package/templates/be/skeleton-lite/src/modules/integrations/passport/strategies/local.strategy.ts +0 -36
  334. package/templates/be/skeleton-lite/src/modules/integrations/passport/strategies/oauth-state.store.ts +0 -63
  335. package/templates/fe/skeleton/packages/__project__-ui/src/frames/SiteShell/classNames.ts +0 -4
  336. package/templates/fe/skeleton-lite/apps/__app__/src/modules/auth/auth-door.ts +0 -30
  337. package/templates/fe/skeleton-lite/apps/__app__/src/modules/auth/client.ts +0 -50
  338. package/templates/fe/skeleton-lite/apps/__app__/src/modules/auth/token-store.ts +0 -31
  339. package/templates/fe/skeleton-lite/apps/web/src/components/frames/SiteShell/classNames.ts +0 -4
@@ -2,7 +2,7 @@ import { SetMetadata, applyDecorators, createParamDecorator } from "@nestjs/comm
2
2
  import type { ExecutionContext } from "@nestjs/common"
3
3
  import { injector } from "@modules/platform/composition"
4
4
  import type { DoorDecorator, TypedParameterDecorator } from "@modules/platform/composition"
5
- import type { VerifyAccessToken } from "@modules/integrations/passport"
5
+ import type { AuthDoors, AuthPasswords, AuthSessions, SignInBudget, VerifyAccessToken } from "@modules/integrations/passport"
6
6
  import { ServerToServer, requestOf } from "@modules/platform/http-security"
7
7
  import type { Principal } from "@modules/platform/cqrs"
8
8
  import type { CredentialAuthenticator, CredentialMetadata } from "./credential.contracts"
@@ -10,6 +10,27 @@ import { IdentityError, IdentityErrorCode } from "./errors/identity.error"
10
10
  import { PublicReason } from "./identity.contracts"
11
11
  import type { PublicMetadata } from "./identity.contracts"
12
12
 
13
+ /** Token of the sign-in doors of the package, provided by the identity module from the passport integration. */
14
+ export const IDENTITY_AUTH_DOORS: unique symbol = Symbol("domain.identity.auth-doors")
15
+ /** Token of the rotating sessions of the package. */
16
+ export const IDENTITY_AUTH_SESSIONS: unique symbol = Symbol("domain.identity.auth-sessions")
17
+ /** Token of the password hasher of the package. */
18
+ export const IDENTITY_AUTH_PASSWORDS: unique symbol = Symbol("domain.identity.auth-passwords")
19
+ /** Token of the failures-only sign-in budget of the package. */
20
+ export const IDENTITY_SIGN_IN_BUDGET: unique symbol = Symbol("domain.identity.sign-in-budget")
21
+
22
+ /** Injects the sign-in doors. Parameter type: AuthDoors. */
23
+ export const InjectAuthDoors = (): TypedParameterDecorator<AuthDoors> => injector<AuthDoors>(IDENTITY_AUTH_DOORS)
24
+
25
+ /** Injects the rotating sessions. Parameter type: AuthSessions. */
26
+ export const InjectAuthSessions = (): TypedParameterDecorator<AuthSessions> => injector<AuthSessions>(IDENTITY_AUTH_SESSIONS)
27
+
28
+ /** Injects the password hasher. Parameter type: AuthPasswords. */
29
+ export const InjectAuthPasswords = (): TypedParameterDecorator<AuthPasswords> => injector<AuthPasswords>(IDENTITY_AUTH_PASSWORDS)
30
+
31
+ /** Injects the sign-in budget. Parameter type: SignInBudget. */
32
+ export const InjectSignInBudget = (): TypedParameterDecorator<SignInBudget> => injector<SignInBudget>(IDENTITY_SIGN_IN_BUDGET)
33
+
13
34
  /** Token of the access-token verifier the composition root hands to identity. */
14
35
  export const ACCESS_TOKEN_VERIFIER: unique symbol = Symbol("domain.identity.access-token-verifier")
15
36
 
@@ -47,7 +68,7 @@ export const Credential = (metadata: CredentialMetadata): DoorDecorator =>
47
68
  applyDecorators(SetMetadata(CREDENTIAL_KEY, metadata), ServerToServer())
48
69
 
49
70
  /** The authenticated caller established by the default-deny guard. */
50
- export const CurrentPrincipal = createParamDecorator((_data: unknown, context: ExecutionContext): Principal => {
71
+ export const CurrentPrincipal: ReturnType<typeof createParamDecorator> = createParamDecorator((_data: unknown, context: ExecutionContext): Principal => {
51
72
  const principal = requestOf(context).principal
52
73
  if (!principal) throw new IdentityError({ code: IdentityErrorCode.Unauthenticated })
53
74
  return principal
@@ -1,10 +1,32 @@
1
1
  import { Module } from "@nestjs/common"
2
2
  import type { DynamicModule, Provider } from "@nestjs/common"
3
+ import {
4
+ PASSPORT_ACCOUNTS,
5
+ PASSPORT_AUTHENTICATOR,
6
+ PASSPORT_DOORS,
7
+ PASSPORT_PASSWORDS,
8
+ PASSPORT_RATE_COUNTER,
9
+ PASSPORT_SESSIONS,
10
+ PASSPORT_SESSION_STORE,
11
+ PASSPORT_SIGN_IN_BUDGET,
12
+ } from "@modules/integrations/passport"
13
+ import { IdentityAccountDirectoryService } from "./account-directory.service"
3
14
  import { AuthGuard } from "./auth.guard"
15
+ import { IdentityAuthenticatorService } from "./authenticator.service"
4
16
  import { CredentialGuard } from "./credential.guard"
5
17
  import { IdentityError, IdentityErrorCode } from "./errors/identity.error"
6
- import { ACCESS_TOKEN_VERIFIER, CREDENTIAL_AUTHENTICATOR } from "./identity.decorators"
18
+ import {
19
+ ACCESS_TOKEN_VERIFIER,
20
+ CREDENTIAL_AUTHENTICATOR,
21
+ IDENTITY_AUTH_DOORS,
22
+ IDENTITY_AUTH_PASSWORDS,
23
+ IDENTITY_AUTH_SESSIONS,
24
+ IDENTITY_SIGN_IN_BUDGET,
25
+ } from "./identity.decorators"
7
26
  import { ConfigurableModuleClass, OPTIONS_TYPE } from "./identity.module-definition"
27
+ import { IdentityRateCounterService } from "./rate-counter.service"
28
+ import { IdentitySessionStoreService } from "./session-store.service"
29
+ import { IdentitySignInService } from "./sign-in.service"
8
30
 
9
31
  const refusingAuthenticator: Provider = {
10
32
  provide: CREDENTIAL_AUTHENTICATOR,
@@ -34,8 +56,31 @@ export class IdentityModule extends ConfigurableModuleClass {
34
56
  authenticator,
35
57
  CredentialGuard,
36
58
  AuthGuard,
59
+ IdentitySessionStoreService,
60
+ IdentityAccountDirectoryService,
61
+ IdentityRateCounterService,
62
+ IdentityAuthenticatorService,
63
+ IdentitySignInService,
64
+ { provide: IDENTITY_AUTH_DOORS, useExisting: PASSPORT_DOORS },
65
+ { provide: IDENTITY_AUTH_SESSIONS, useExisting: PASSPORT_SESSIONS },
66
+ { provide: IDENTITY_AUTH_PASSWORDS, useExisting: PASSPORT_PASSWORDS },
67
+ { provide: IDENTITY_SIGN_IN_BUDGET, useExisting: PASSPORT_SIGN_IN_BUDGET },
68
+ { provide: PASSPORT_SESSION_STORE, useExisting: IdentitySessionStoreService },
69
+ { provide: PASSPORT_ACCOUNTS, useExisting: IdentityAccountDirectoryService },
70
+ { provide: PASSPORT_RATE_COUNTER, useExisting: IdentityRateCounterService },
71
+ { provide: PASSPORT_AUTHENTICATOR, useExisting: IdentityAuthenticatorService },
72
+ ],
73
+ exports: [
74
+ CredentialGuard,
75
+ CREDENTIAL_AUTHENTICATOR,
76
+ AuthGuard,
77
+ ACCESS_TOKEN_VERIFIER,
78
+ IdentitySignInService,
79
+ PASSPORT_SESSION_STORE,
80
+ PASSPORT_ACCOUNTS,
81
+ PASSPORT_RATE_COUNTER,
82
+ PASSPORT_AUTHENTICATOR,
37
83
  ],
38
- exports: [CredentialGuard, CREDENTIAL_AUTHENTICATOR, AuthGuard, ACCESS_TOKEN_VERIFIER],
39
84
  }
40
85
  }
41
86
  }
@@ -5,3 +5,5 @@ export { IDENTITY_MESSAGES } from "./messages/identity.messages"
5
5
  export { PublicReason } from "./identity.contracts"
6
6
  export { ACCESS_TOKEN_VERIFIER, Public } from "./identity.decorators"
7
7
  export { IdentityModule } from "./identity.module"
8
+ export { identityEntities } from "./persistence/entities"
9
+ export { IdentitySignInService } from "./sign-in.service"
@@ -0,0 +1,24 @@
1
+ import type { MessageBundle } from "@modules/platform/i18n"
2
+
3
+ /** Display text of the identity codes, Vietnamese and English. */
4
+ export const IDENTITY_MESSAGES: MessageBundle = {
5
+ vi: {
6
+ "errors.IDENTITY_UNAUTHENTICATED":
7
+ "Bạn cần đăng nhập để thực hiện thao tác này.",
8
+ "errors.IDENTITY_REFRESH_INVALID": "Phiên đăng nhập không hợp lệ hoặc đã hết hạn.",
9
+ "errors.IDENTITY_REFRESH_REUSED": "Phiên đăng nhập đã kết thúc vì bị dùng lại. Hãy đăng nhập lại.",
10
+ "errors.IDENTITY_ACCOUNT_DISABLED": "Tài khoản này đã bị khóa.",
11
+ "errors.IDENTITY_TOO_MANY_ATTEMPTS": "Quá nhiều lần thử. Hãy thử lại sau.",
12
+ "errors.IDENTITY_INVALID_CREDENTIALS": "Email hoặc mật khẩu không đúng.",
13
+ "errors.IDENTITY_EMAIL_NOT_CONFIRMED": "Hãy xác nhận email trước khi đăng nhập.",
14
+ },
15
+ en: {
16
+ "errors.IDENTITY_UNAUTHENTICATED": "You need to sign in to do this.",
17
+ "errors.IDENTITY_REFRESH_INVALID": "The session is invalid or has expired.",
18
+ "errors.IDENTITY_REFRESH_REUSED": "The session ended because it was used again. Please sign in again.",
19
+ "errors.IDENTITY_ACCOUNT_DISABLED": "This account is disabled.",
20
+ "errors.IDENTITY_TOO_MANY_ATTEMPTS": "Too many attempts. Try again later.",
21
+ "errors.IDENTITY_INVALID_CREDENTIALS": "The email or password is wrong.",
22
+ "errors.IDENTITY_EMAIL_NOT_CONFIRMED": "Confirm your email before signing in.",
23
+ },
24
+ }
@@ -1,4 +1,4 @@
1
- export { createObjectStorage } from "./object-storage.client"
1
+ export { OBJECT_STORAGE } from "@starci/object-storage"
2
2
  export { parseObjectStorageConfig } from "./object-storage.config"
3
- export { InjectObjectStorage, OBJECT_STORAGE } from "./object-storage.decorators"
4
- export type { ObjectStorage, PresignedRequest, ObjectStorageOptions } from "./object-storage.options"
3
+ export { ObjectStorageModule } from "./object-storage.module"
4
+ export type { ObjectStorageOptions } from "./object-storage.options"
@@ -1,6 +1,8 @@
1
1
  import type { EnvSource } from "@modules/platform/config"
2
2
  import type { ObjectStorageOptions } from "./object-storage.options"
3
3
 
4
+ const PRESIGN_TTL_SECONDS = 300
5
+
4
6
  /** Reads the object storage configuration with no credential or endpoint defaults; secrets read `<KEY>_FILE` first. */
5
7
  export const parseObjectStorageConfig = (env: EnvSource): ObjectStorageOptions => ({
6
8
  endpoint: env.url("STORAGE_ENDPOINT"),
@@ -8,5 +10,5 @@ export const parseObjectStorageConfig = (env: EnvSource): ObjectStorageOptions =
8
10
  bucket: env.string("STORAGE_BUCKET"),
9
11
  accessKeyId: env.secret("STORAGE_ACCESS_KEY_ID"),
10
12
  secretAccessKey: env.secret("STORAGE_SECRET_ACCESS_KEY"),
11
- presignTtlSeconds: env.int("STORAGE_PRESIGN_TTL_SECONDS", 300),
13
+ defaultExpiresIn: env.int("STORAGE_PRESIGN_TTL_SECONDS", PRESIGN_TTL_SECONDS),
12
14
  })
@@ -1,9 +1,13 @@
1
+ import { OBJECT_STORAGE } from "@starci/object-storage"
2
+ import type { ObjectStorage } from "@starci/object-storage"
1
3
  import { injector } from "@modules/platform/composition"
2
4
  import type { TypedParameterDecorator } from "@modules/platform/composition"
3
- import type { ObjectStorage } from "./object-storage.options"
4
5
 
5
- /** Token of the object storage port. */
6
- export const OBJECT_STORAGE: unique symbol = Symbol("integrations.object-storage")
6
+ /** Token of the bucket of the app's objects. */
7
+ export const OBJECT_STORAGE_BUCKET: unique symbol = Symbol("integrations.object-storage.bucket")
7
8
 
8
- /** Injects the object storage port. Parameter type: ObjectStorage. */
9
+ /** Injects the object storage port of `@starci/object-storage`. Parameter type: ObjectStorage. */
9
10
  export const InjectObjectStorage = (): TypedParameterDecorator<ObjectStorage> => injector<ObjectStorage>(OBJECT_STORAGE)
11
+
12
+ /** Injects the bucket of the app's objects. Parameter type: string. */
13
+ export const InjectObjectStorageBucket = (): TypedParameterDecorator<string> => injector<string>(OBJECT_STORAGE_BUCKET)
@@ -0,0 +1,12 @@
1
+ import { ConfigurableModuleBuilder, type ConfigurableModuleHost } from "@nestjs/common"
2
+ import type { ObjectStorageOptions } from "./object-storage.options"
3
+
4
+ const built = new ConfigurableModuleBuilder<ObjectStorageOptions>()
5
+ .setExtras({ isGlobal: false }, (definition, extras) => ({ ...definition, global: extras.isGlobal }))
6
+ .build()
7
+ type Host = ConfigurableModuleHost<ObjectStorageOptions, "register", "create", { isGlobal: boolean }>
8
+
9
+ /** The configurable-module base of the object storage glue; `isGlobal` is decided by the app root. */
10
+ export const ConfigurableModuleClass: Host["ConfigurableModuleClass"] = built.ConfigurableModuleClass
11
+ /** The options of a synchronous registration, for the register signature. */
12
+ export const OPTIONS_TYPE: Host["OPTIONS_TYPE"] = built.OPTIONS_TYPE
@@ -0,0 +1,29 @@
1
+ import { ObjectStorageModule as StorageModule } from "@starci/object-storage"
2
+ import type { ObjectStorageOptions as StorageSettings } from "@starci/object-storage"
3
+ import { Module } from "@nestjs/common"
4
+ import type { DynamicModule } from "@nestjs/common"
5
+ import { CLOCK } from "@modules/platform/clock"
6
+ import type { Clock } from "@modules/platform/clock"
7
+ import { OBJECT_STORAGE_BUCKET } from "./object-storage.decorators"
8
+ import { ConfigurableModuleClass, OPTIONS_TYPE } from "./object-storage.module-definition"
9
+
10
+ @Module({})
11
+ /** Composes `@starci/object-storage` with the app's typed settings and clock, and provides the bucket of the app's objects. */
12
+ export class ObjectStorageModule extends ConfigurableModuleClass {
13
+ /** Registers the capability once per app. */
14
+ static register(options: typeof OPTIONS_TYPE): DynamicModule {
15
+ const { bucket, isGlobal, ...settings } = options
16
+ const base = super.register(options)
17
+ const storage = StorageModule.registerAsync({
18
+ inject: [CLOCK],
19
+ useFactory: (clock: Clock): StorageSettings => ({ ...settings, clock }),
20
+ })
21
+ return {
22
+ ...base,
23
+ imports: [...(base.imports ?? []), storage],
24
+ providers: [...(base.providers ?? []), { provide: OBJECT_STORAGE_BUCKET, useValue: bucket }],
25
+ exports: [...(base.exports ?? []), storage, OBJECT_STORAGE_BUCKET],
26
+ global: isGlobal === true,
27
+ }
28
+ }
29
+ }
@@ -1,35 +1,10 @@
1
- import type { Secret } from "@modules/platform/config"
1
+ import type { ObjectStorageOptions as StorageSettings } from "@starci/object-storage"
2
2
 
3
- /** S3-compatible object storage (MinIO in lite) parsed once at API boot. */
4
- export interface ObjectStorageOptions {
5
- /** The S3 endpoint origin. */
6
- readonly endpoint: string
7
- /** The region the endpoint signs for. */
8
- readonly region: string
3
+ /**
4
+ * S3-compatible object storage (MinIO in lite) parsed once at API boot: the settings of `@starci/object-storage` (its clock is
5
+ * the app's `Clock`) and the one bucket of the app's objects. The key layout belongs to the domain that stores the object.
6
+ */
7
+ export interface ObjectStorageOptions extends Omit<StorageSettings, "clock"> {
9
8
  /** The bucket of the app's objects. */
10
9
  readonly bucket: string
11
- /** The access key id. */
12
- readonly accessKeyId: Secret
13
- /** The secret access key. */
14
- readonly secretAccessKey: Secret
15
- /** The lifetime of a presigned URL in seconds. */
16
- readonly presignTtlSeconds: number
17
- }
18
-
19
- /** One presigned request: the URL the browser calls and when it stops working. */
20
- export interface PresignedRequest {
21
- /** The presigned URL. */
22
- readonly url: string
23
- /** The expiry instant, ISO-8601. */
24
- readonly expiresAt: string
25
- }
26
-
27
- /** The object storage port: presigned PUT and GET of one key and a server-side delete. */
28
- export interface ObjectStorage {
29
- /** A presigned PUT of `key` with its content type fixed. */
30
- presignPut(key: string, contentType: string): Promise<PresignedRequest>
31
- /** A presigned GET of `key`. */
32
- presignGet(key: string): Promise<PresignedRequest>
33
- /** Deletes `key`. */
34
- remove(key: string): Promise<void>
35
10
  }
@@ -1,21 +1,30 @@
1
1
  import { DomainError } from "@modules/platform/errors"
2
2
  import type { ErrorKind } from "@modules/platform/errors"
3
3
 
4
- /** Codes of the passport integration. */
4
+ /** Codes of the passport integration: the wire codes @starci/auth names for the token, key and Google legs (the kit spec holds the parity). */
5
5
  export enum PassportErrorCode {
6
- /** The access token failed signature or required-claim verification. */
6
+ /** The access token failed signature, issuer, audience or expiry verification. */
7
7
  AccessTokenInvalid = "PASSPORT_ACCESS_TOKEN_INVALID",
8
- /** The email and password do not match an account. */
9
- CredentialsRefused = "PASSPORT_CREDENTIALS_REFUSED",
10
- /** The OAuth state or PKCE verifier of a callback does not match the request that started it. */
11
- OAuthStateInvalid = "PASSPORT_OAUTH_STATE_INVALID",
8
+ /** The signing key set is unusable. */
9
+ KeyInvalid = "PASSPORT_KEY_INVALID",
10
+ /** The request carried no email or password. */
11
+ MissingCredentials = "PASSPORT_MISSING_CREDENTIALS",
12
+ /** The Google round trip could not be proven to be ours (state, PKCE or cookie). */
13
+ GoogleStateInvalid = "PASSPORT_GOOGLE_STATE_INVALID",
14
+ /** Google refused the consent or answered no usable account. */
15
+ GoogleRejected = "PASSPORT_GOOGLE_REJECTED",
16
+ /** This deployment has no Google client. */
17
+ GoogleUnavailable = "PASSPORT_GOOGLE_UNAVAILABLE",
12
18
  }
13
19
 
14
- /** How each passport integration code travels. */
20
+ /** How each passport code travels. */
15
21
  export const PASSPORT_ERROR_KINDS: Record<PassportErrorCode, ErrorKind> = {
16
22
  [PassportErrorCode.AccessTokenInvalid]: "unauthenticated",
17
- [PassportErrorCode.CredentialsRefused]: "unauthenticated",
18
- [PassportErrorCode.OAuthStateInvalid]: "unauthenticated",
23
+ [PassportErrorCode.KeyInvalid]: "internal",
24
+ [PassportErrorCode.MissingCredentials]: "invalid",
25
+ [PassportErrorCode.GoogleStateInvalid]: "unauthenticated",
26
+ [PassportErrorCode.GoogleRejected]: "unauthenticated",
27
+ [PassportErrorCode.GoogleUnavailable]: "unavailable",
19
28
  }
20
29
 
21
30
  /** The one error class of the passport integration. */
@@ -1,12 +1,36 @@
1
+ export { AuthError, isPresentablePassword, normalizeEmail } from "@starci/auth/server"
2
+ export type {
3
+ AccountDirectory,
4
+ AccountStanding,
5
+ AuthAuthenticator,
6
+ AuthDoors,
7
+ AuthPasswords,
8
+ AuthSessions,
9
+ AuthSubject,
10
+ GoogleProfile,
11
+ HttpExchange,
12
+ NewSession,
13
+ RateCounter,
14
+ RefreshTokenRecord,
15
+ SessionStore,
16
+ SessionTransaction,
17
+ SignInBudget,
18
+ } from "@starci/auth/server"
19
+ export type { AccessGrant, GoogleRedirect, JwksDocument } from "@starci/auth/contracts"
1
20
  export { parsePassportConfig } from "./passport.config"
2
- export { OWN_TOKEN_VERIFIER, PASSPORT_OPTIONS, PASSWORD_ACCOUNTS } from "./passport.decorators"
3
- export { PASSPORT_ERROR_KINDS, PassportErrorCode } from "./errors/passport.error"
4
- export { createTokenKit, tokenKit } from "./passport.tokens"
5
- export type { TokenKit } from "./passport.tokens"
6
- export { hashPassword, verifyPassword } from "./passport.password"
7
- export { clearRefreshCookie, newRefreshToken, refreshTokenHash, setRefreshCookie } from "./passport.cookie"
8
- export { GoogleStrategy } from "./strategies/google.strategy"
9
- export type { GoogleIdentity } from "./strategies/google.strategy"
10
- export { LocalStrategy } from "./strategies/local.strategy"
11
- export type { FindPasswordAccount, PasswordAccount } from "./strategies/local.strategy"
12
- export type { OwnPrincipal, PassportOptions, VerifyAccessToken } from "./passport.options"
21
+ export {
22
+ OWN_TOKEN_VERIFIER,
23
+ PASSPORT_ACCOUNTS,
24
+ PASSPORT_AUTHENTICATOR,
25
+ PASSPORT_DOORS,
26
+ PASSPORT_OPTIONS,
27
+ PASSPORT_PASSWORDS,
28
+ PASSPORT_RATE_COUNTER,
29
+ PASSPORT_SESSION_STORE,
30
+ PASSPORT_SESSIONS,
31
+ PASSPORT_SIGN_IN_BUDGET,
32
+ } from "./passport.decorators"
33
+ export { PASSPORT_ERROR_KINDS, PassportError, PassportErrorCode } from "./errors/passport.error"
34
+ export { passportKit } from "./passport.kit"
35
+ export { passportModule } from "./passport.registration"
36
+ export type { PassportOptions, VerifyAccessToken } from "./passport.options"
@@ -5,13 +5,9 @@ import { parsePassportConfig } from "./passport.config"
5
5
  const CONFIG: unique symbol = Symbol("passport.config")
6
6
 
7
7
  const REQUIRED = {
8
- GOOGLE_CLIENT_ID: "client",
9
- GOOGLE_CLIENT_SECRET: "client-secret",
10
- GOOGLE_CALLBACK_URL: "https://api.example.com/auth/google/callback",
11
8
  AUTH_JWT_ISSUER: "https://api.example.com",
12
- AUTH_JWT_AUDIENCE: "app",
13
9
  AUTH_JWT_PRIVATE_KEY: "key",
14
- AUTH_JWT_KEY_ID: "kid-1",
10
+ AUTH_WEB_ORIGIN: "https://app.example.com/home",
15
11
  }
16
12
 
17
13
  const build = async () => {
@@ -21,14 +17,54 @@ const build = async () => {
21
17
 
22
18
  const parse = async (extra: Record<string, string>) => (await build()).parsePassportConfig(new EnvSource({ ...REQUIRED, ...extra }))
23
19
 
20
+ describe("the required keys", () => {
21
+ it("reads the issuer, the web origin and the signing key, and defaults the lifetimes and the budget", async () => {
22
+ const options = await parse({})
23
+ expect(options.issuer).toBe("https://api.example.com")
24
+ expect(options.returnOrigin).toBe("https://app.example.com")
25
+ expect(options.keys).toHaveLength(1)
26
+ expect(options.audience).toBeUndefined()
27
+ expect(options).toMatchObject({
28
+ accessTtlSeconds: 900,
29
+ refreshTtlSeconds: 2_592_000,
30
+ bcryptCost: 10,
31
+ google: null,
32
+ cookie: { name: "refresh_token" },
33
+ budget: { loginAttempts: 10, resetAttempts: 5, windowMs: 900_000 },
34
+ })
35
+ })
36
+
37
+ it("refuses a boot without the signing key", async () => {
38
+ const subject = await build()
39
+ const { AUTH_JWT_PRIVATE_KEY: _key, ...without } = REQUIRED
40
+ expect(() => subject.parsePassportConfig(new EnvSource(without))).toThrow()
41
+ })
42
+ })
43
+
44
+ describe("the Google client", () => {
45
+ it("is declared by its client id and then needs its secret and callback", async () => {
46
+ const options = await parse({ GOOGLE_CLIENT_ID: "client", GOOGLE_CLIENT_SECRET: "secret", GOOGLE_CALLBACK_URL: "https://api.example.com/auth/google/callback" })
47
+ expect(options.google).toMatchObject({ clientId: "client", callbackUrl: "https://api.example.com/auth/google/callback" })
48
+ await expect(parse({ GOOGLE_CLIENT_ID: "client" })).rejects.toBeDefined()
49
+ })
50
+ })
51
+
52
+ describe("the key set", () => {
53
+ it("keeps the previous public key beside the signing key while a rotation runs", async () => {
54
+ const options = await parse({ AUTH_JWT_KEY_ID: "new", AUTH_JWT_PREVIOUS_PUBLIC_KEY: "previous-pem", AUTH_JWT_PREVIOUS_KEY_ID: "old" })
55
+ expect(options.keys.map((key) => key.keyId)).toEqual(["new", "old"])
56
+ expect(options.keys[1]?.publicKey).toBe("previous-pem")
57
+ })
58
+ })
59
+
24
60
  describe("AUTH_COOKIE_DOMAIN", () => {
25
61
  it("leaves the refresh cookie host-only when the key is not declared", async () => {
26
- expect((await parse({})).refresh.cookieDomain).toBeUndefined()
62
+ expect((await parse({})).cookie.domain).toBeUndefined()
27
63
  })
28
64
 
29
65
  it("reads a bare registrable domain", async () => {
30
- expect((await parse({ AUTH_COOKIE_DOMAIN: "example.com" })).refresh.cookieDomain).toBe("example.com")
31
- expect((await parse({ AUTH_COOKIE_DOMAIN: "Sub.Example.CO.uk" })).refresh.cookieDomain).toBe("sub.example.co.uk")
66
+ expect((await parse({ AUTH_COOKIE_DOMAIN: "example.com" })).cookie.domain).toBe("example.com")
67
+ expect((await parse({ AUTH_COOKIE_DOMAIN: "Sub.Example.CO.uk" })).cookie.domain).toBe("sub.example.co.uk")
32
68
  })
33
69
 
34
70
  it.each(["https://example.com", "example.com:443", "example.com/path", ".example.com", "localhost", "127.0.0.1", "exa mple.com", "-a.example.com"])(
@@ -1,24 +1,46 @@
1
1
  import type { EnvSource } from "@modules/platform/config"
2
2
  import type { PassportOptions } from "./passport.options"
3
3
 
4
- /** Reads the passport configuration with no credential or localhost defaults; secrets read `<KEY>_FILE` first. */
4
+ const ACCESS_TTL_SECONDS = 900
5
+ const REFRESH_TTL_SECONDS = 2_592_000
6
+ const BCRYPT_COST = 10
7
+ const LOGIN_ATTEMPTS = 10
8
+ const RESET_ATTEMPTS = 5
9
+ const ATTEMPT_WINDOW_MS = 900_000
10
+
11
+ /** The Google client, or null when the deployment declares none (the Google door is then unavailable). */
12
+ const readGoogle = (env: EnvSource): PassportOptions["google"] =>
13
+ env.has("GOOGLE_CLIENT_ID")
14
+ ? {
15
+ clientId: env.string("GOOGLE_CLIENT_ID"),
16
+ clientSecret: env.secret("GOOGLE_CLIENT_SECRET"),
17
+ callbackUrl: env.url("GOOGLE_CALLBACK_URL"),
18
+ }
19
+ : null
20
+
21
+ /** The key set: the signing key, and the previous public key while its access tokens are still valid (a rotation). */
22
+ const readKeys = (env: EnvSource): PassportOptions["keys"] => {
23
+ const previous = env.optional("AUTH_JWT_PREVIOUS_PUBLIC_KEY")
24
+ return [
25
+ { privateKey: env.secret("AUTH_JWT_PRIVATE_KEY"), keyId: env.optional("AUTH_JWT_KEY_ID") },
26
+ ...(previous === undefined ? [] : [{ publicKey: previous, keyId: env.optional("AUTH_JWT_PREVIOUS_KEY_ID") }]),
27
+ ]
28
+ }
29
+
30
+ /** Reads the sign-in configuration with no credential or localhost defaults; secrets read `<KEY>_FILE` first. */
5
31
  export const parsePassportConfig = (env: EnvSource): PassportOptions => ({
6
- google: {
7
- clientId: env.string("GOOGLE_CLIENT_ID"),
8
- clientSecret: env.secret("GOOGLE_CLIENT_SECRET"),
9
- callbackUrl: env.url("GOOGLE_CALLBACK_URL"),
10
- },
11
- tokens: {
12
- issuer: env.url("AUTH_JWT_ISSUER"),
13
- audience: env.string("AUTH_JWT_AUDIENCE"),
14
- privateKey: env.secret("AUTH_JWT_PRIVATE_KEY"),
15
- keyId: env.string("AUTH_JWT_KEY_ID"),
16
- accessTtlSeconds: env.int("AUTH_ACCESS_TTL_SECONDS", 900),
17
- },
18
- refresh: {
19
- name: "refresh_token",
20
- path: "/auth/refresh",
21
- ttlSeconds: env.int("AUTH_REFRESH_TTL_SECONDS", 2_592_000),
22
- cookieDomain: env.optionalDomain("AUTH_COOKIE_DOMAIN"),
32
+ issuer: env.url("AUTH_JWT_ISSUER"),
33
+ audience: env.optional("AUTH_JWT_AUDIENCE"),
34
+ keys: readKeys(env),
35
+ accessTtlSeconds: env.int("AUTH_ACCESS_TTL_SECONDS", ACCESS_TTL_SECONDS),
36
+ refreshTtlSeconds: env.int("AUTH_REFRESH_TTL_SECONDS", REFRESH_TTL_SECONDS),
37
+ bcryptCost: env.int("AUTH_BCRYPT_COST", BCRYPT_COST),
38
+ returnOrigin: new URL(env.url("AUTH_WEB_ORIGIN")).origin,
39
+ google: readGoogle(env),
40
+ cookie: { name: "refresh_token", domain: env.optionalDomain("AUTH_COOKIE_DOMAIN") },
41
+ budget: {
42
+ loginAttempts: env.int("AUTH_LOGIN_ATTEMPTS", LOGIN_ATTEMPTS),
43
+ resetAttempts: env.int("AUTH_RESET_ATTEMPTS", RESET_ATTEMPTS),
44
+ windowMs: env.duration("AUTH_ATTEMPT_WINDOW", ATTEMPT_WINDOW_MS),
23
45
  },
24
46
  })
@@ -1,14 +1,20 @@
1
+ import { AUTH_DOORS_SERVICE, AUTH_PASSWORDS, AUTH_SESSIONS, AUTH_SIGN_IN_BUDGET } from "@starci/auth/server"
1
2
  import { injector } from "@modules/platform/composition"
2
3
  import type { TypedParameterDecorator } from "@modules/platform/composition"
3
4
  import type { PassportOptions, VerifyAccessToken } from "./passport.options"
4
- import type { FindPasswordAccount } from "./strategies/local.strategy"
5
5
 
6
6
  /** Token of the passport options. */
7
7
  export const PASSPORT_OPTIONS: unique symbol = Symbol("integrations.passport.options")
8
8
  /** Token of the verifier of the app's own access tokens. */
9
9
  export const OWN_TOKEN_VERIFIER: unique symbol = Symbol("integrations.passport.own-token-verifier")
10
- /** Token of the password-account lookup the identity domain provides. */
11
- export const PASSWORD_ACCOUNTS: unique symbol = Symbol("integrations.passport.password-accounts")
10
+ /** Token of the session store the identity domain implements over the package's tables. */
11
+ export const PASSPORT_SESSION_STORE: unique symbol = Symbol("integrations.passport.session-store")
12
+ /** Token of the account directory the identity domain implements over the user table. */
13
+ export const PASSPORT_ACCOUNTS: unique symbol = Symbol("integrations.passport.accounts")
14
+ /** Token of the rate counter the identity domain implements over its attempts table. */
15
+ export const PASSPORT_RATE_COUNTER: unique symbol = Symbol("integrations.passport.rate-counter")
16
+ /** Token of the sign-in decisions (password and Google) the identity domain makes. */
17
+ export const PASSPORT_AUTHENTICATOR: unique symbol = Symbol("integrations.passport.authenticator")
12
18
 
13
19
  /** Injects the passport options. Parameter type: PassportOptions. */
14
20
  export const InjectPassportOptions = (): TypedParameterDecorator<PassportOptions> => injector<PassportOptions>(PASSPORT_OPTIONS)
@@ -17,6 +23,12 @@ export const InjectPassportOptions = (): TypedParameterDecorator<PassportOptions
17
23
  export const InjectOwnTokenVerifier = (): TypedParameterDecorator<VerifyAccessToken> =>
18
24
  injector<VerifyAccessToken>(OWN_TOKEN_VERIFIER)
19
25
 
20
- /** Injects the password-account lookup. Parameter type: FindPasswordAccount. */
21
- export const InjectPasswordAccounts = (): TypedParameterDecorator<FindPasswordAccount> =>
22
- injector<FindPasswordAccount>(PASSWORD_ACCOUNTS)
26
+ /** Token of the sign-in doors. */
27
+ export const PASSPORT_DOORS: typeof AUTH_DOORS_SERVICE = AUTH_DOORS_SERVICE
28
+ /** Token of the rotating sessions. */
29
+ export const PASSPORT_SESSIONS: typeof AUTH_SESSIONS = AUTH_SESSIONS
30
+ /** Token of the password hasher. */
31
+ export const PASSPORT_PASSWORDS: typeof AUTH_PASSWORDS = AUTH_PASSWORDS
32
+ /** Token of the failures-only sign-in budget. */
33
+ export const PASSPORT_SIGN_IN_BUDGET: typeof AUTH_SIGN_IN_BUDGET = AUTH_SIGN_IN_BUDGET
34
+
@@ -0,0 +1,73 @@
1
+ import { Test } from "@nestjs/testing"
2
+ import { AUTH_ERROR_CODES, AUTH_ERROR_KINDS } from "@starci/auth/contracts"
3
+ import { generateTestKeyPair } from "@starci/auth/testing"
4
+ import { PASSPORT_ERROR_KINDS, PassportErrorCode } from "./errors/passport.error"
5
+ import { passportKit } from "./passport.kit"
6
+ import type { PassportOptions } from "./passport.options"
7
+
8
+ const KIT: unique symbol = Symbol("passport.kit")
9
+
10
+ const FAR_FUTURE = 32_503_680_000_000
11
+ const LONG_AGO = 0
12
+
13
+ const build = async () => {
14
+ const moduleRef = await Test.createTestingModule({ providers: [{ provide: KIT, useValue: { passportKit } }] }).compile()
15
+ return moduleRef.get<{ passportKit: typeof passportKit }>(KIT).passportKit
16
+ }
17
+
18
+ const optionsFor = (keys: PassportOptions["keys"]): PassportOptions => ({
19
+ issuer: "https://api.example.test",
20
+ audience: undefined,
21
+ keys,
22
+ accessTtlSeconds: 60,
23
+ refreshTtlSeconds: 3600,
24
+ reuseGraceMs: undefined,
25
+ bcryptCost: 4,
26
+ returnOrigin: "https://app.example.test",
27
+ google: null,
28
+ cookie: { name: "refresh_token" },
29
+ budget: { loginAttempts: 10, resetAttempts: 5, windowMs: 900_000 },
30
+ })
31
+
32
+ describe("PassportErrorCode", () => {
33
+ it("names every PASSPORT wire code of @starci/auth with the same kind", () => {
34
+ const wire = Object.values(AUTH_ERROR_CODES).filter((code) => code.startsWith("PASSPORT_"))
35
+
36
+ expect(Object.values(PassportErrorCode).sort()).toEqual(wire.sort())
37
+ for (const code of Object.values(PassportErrorCode)) expect(PASSPORT_ERROR_KINDS[code]).toBe(AUTH_ERROR_KINDS[code])
38
+ })
39
+ })
40
+
41
+ describe("passportKit", () => {
42
+ it("verifies a token its own signer issued and builds the principal from it", async () => {
43
+ const create = await build()
44
+ const kit = create(optionsFor([{ privateKey: generateTestKeyPair().privateKey, keyId: "k1" }]))
45
+ const { token } = await kit.tokens.sign({ sub: "user-1", email: "a@example.test", sessionId: "s-1" }, new Date(FAR_FUTURE))
46
+
47
+ expect(await kit.verify(token)).toEqual({ kind: "ok", value: { id: "user-1", role: "authenticated", sessionId: "s-1", email: "a@example.test" } })
48
+ expect((await kit.tokens.jwks()).keys).toHaveLength(1)
49
+ })
50
+
51
+ it("refuses an expired token, a token of another key and a token that is no token", async () => {
52
+ const create = await build()
53
+ const kit = create(optionsFor([{ privateKey: generateTestKeyPair().privateKey }]))
54
+ const stranger = create(optionsFor([{ privateKey: generateTestKeyPair().privateKey }]))
55
+ const expired = await kit.tokens.sign({ sub: "user-1", sessionId: "s-1" }, new Date(LONG_AGO))
56
+ const foreign = await stranger.tokens.sign({ sub: "user-1", sessionId: "s-1" }, new Date(FAR_FUTURE))
57
+
58
+ for (const token of [expired.token, foreign.token, "not-a-token"]) {
59
+ expect(await kit.verify(token)).toEqual({ kind: "refused", code: PassportErrorCode.AccessTokenInvalid })
60
+ }
61
+ })
62
+
63
+ it("keeps verifying the token of a retired key while its public key stays in the set", async () => {
64
+ const create = await build()
65
+ const retired = generateTestKeyPair()
66
+ const before = create(optionsFor([{ privateKey: retired.privateKey, keyId: "old" }]))
67
+ const { token } = await before.tokens.sign({ sub: "user-1", sessionId: "s-1" }, new Date(FAR_FUTURE))
68
+ const after = create(optionsFor([{ privateKey: generateTestKeyPair().privateKey, keyId: "new" }, { publicKey: retired.publicKey, keyId: "old" }]))
69
+
70
+ expect((await after.verify(token)).kind).toBe("ok")
71
+ expect((await after.tokens.jwks()).keys.map((key) => key["kid"])).toEqual(["new", "old"])
72
+ })
73
+ })