@pattern-stack/codegen 0.10.0 → 0.11.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 (307) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +5 -5
  3. package/consumer-skills/codegen/SKILL.md +2 -2
  4. package/consumer-skills/events/typed-bus-and-outbox.md +1 -1
  5. package/consumer-skills/{sync → integration}/SKILL.md +29 -29
  6. package/consumer-skills/{sync → integration}/audit-and-detection.md +22 -22
  7. package/consumer-skills/{sync → integration}/change-sources-and-sinks.md +60 -60
  8. package/consumer-skills/subsystems/SKILL.md +64 -8
  9. package/consumer-skills/subsystems/wiring-and-order.md +7 -7
  10. package/dist/runtime/base-classes/index.d.ts +4 -4
  11. package/dist/runtime/base-classes/index.js +35 -35
  12. package/dist/runtime/base-classes/index.js.map +1 -1
  13. package/dist/runtime/base-classes/{synced-entity-repository.d.ts → integrated-entity-repository.d.ts} +15 -15
  14. package/dist/runtime/base-classes/{synced-entity-repository.js → integrated-entity-repository.js} +21 -21
  15. package/dist/runtime/base-classes/integrated-entity-repository.js.map +1 -0
  16. package/dist/runtime/base-classes/{synced-entity-service.d.ts → integrated-entity-service.d.ts} +6 -6
  17. package/dist/runtime/base-classes/{synced-entity-service.js → integrated-entity-service.js} +4 -4
  18. package/dist/runtime/base-classes/integrated-entity-service.js.map +1 -0
  19. package/dist/runtime/base-classes/{sync-upsert-config.d.ts → integration-upsert-config.d.ts} +13 -13
  20. package/dist/runtime/base-classes/integration-upsert-config.js +1 -0
  21. package/dist/runtime/base-classes/{junction-sync-repository.d.ts → junction-integration-repository.d.ts} +11 -11
  22. package/dist/runtime/base-classes/{junction-sync-repository.js → junction-integration-repository.js} +15 -15
  23. package/dist/runtime/base-classes/junction-integration-repository.js.map +1 -0
  24. package/dist/runtime/subsystems/auth/auth-oauth-state.schema.js.map +1 -1
  25. package/dist/runtime/subsystems/auth/auth.module.d.ts +4 -4
  26. package/dist/runtime/subsystems/auth/auth.module.js +3 -3
  27. package/dist/runtime/subsystems/auth/auth.module.js.map +1 -1
  28. package/dist/runtime/subsystems/auth/auth.tokens.d.ts +8 -8
  29. package/dist/runtime/subsystems/auth/auth.tokens.js +6 -6
  30. package/dist/runtime/subsystems/auth/auth.tokens.js.map +1 -1
  31. package/dist/runtime/subsystems/auth/backends/state-store.drizzle-backend.js.map +1 -1
  32. package/dist/runtime/subsystems/auth/controllers/auth.controller.d.ts +2 -2
  33. package/dist/runtime/subsystems/auth/controllers/auth.controller.js +3 -3
  34. package/dist/runtime/subsystems/auth/controllers/auth.controller.js.map +1 -1
  35. package/dist/runtime/subsystems/auth/index.d.ts +3 -3
  36. package/dist/runtime/subsystems/auth/index.js +40 -40
  37. package/dist/runtime/subsystems/auth/index.js.map +1 -1
  38. package/dist/runtime/subsystems/auth/middleware/requester-context.js.map +1 -1
  39. package/dist/runtime/subsystems/auth/protocols/auth-strategy.d.ts +3 -3
  40. package/dist/runtime/subsystems/auth/protocols/{integration-store.d.ts → connection-store.d.ts} +20 -20
  41. package/dist/runtime/subsystems/auth/protocols/connection-store.js +1 -0
  42. package/dist/runtime/subsystems/auth/protocols/provider-strategy.d.ts +3 -3
  43. package/dist/runtime/subsystems/auth/runtime/{integration-broken.error.d.ts → connection-broken.error.d.ts} +5 -5
  44. package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js +19 -0
  45. package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js.map +1 -0
  46. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.d.ts +10 -10
  47. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js +28 -28
  48. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js.map +1 -1
  49. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.d.ts +1 -1
  50. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js +3 -3
  51. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js.map +1 -1
  52. package/dist/runtime/subsystems/bridge/bridge.module.d.ts +0 -1
  53. package/dist/runtime/subsystems/bridge/bridge.module.js +294 -710
  54. package/dist/runtime/subsystems/bridge/bridge.module.js.map +1 -1
  55. package/dist/runtime/subsystems/bridge/index.d.ts +0 -1
  56. package/dist/runtime/subsystems/bridge/index.js +248 -664
  57. package/dist/runtime/subsystems/bridge/index.js.map +1 -1
  58. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +18 -10
  59. package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -1
  60. package/dist/runtime/subsystems/events/events.module.js +43 -244
  61. package/dist/runtime/subsystems/events/events.module.js.map +1 -1
  62. package/dist/runtime/subsystems/events/index.d.ts +0 -1
  63. package/dist/runtime/subsystems/events/index.js +39 -241
  64. package/dist/runtime/subsystems/events/index.js.map +1 -1
  65. package/dist/runtime/subsystems/index.d.ts +7 -7
  66. package/dist/runtime/subsystems/index.js +222 -839
  67. package/dist/runtime/subsystems/index.js.map +1 -1
  68. package/dist/runtime/subsystems/{sync → integration}/build-change-source.d.ts +3 -3
  69. package/dist/runtime/subsystems/{sync → integration}/build-change-source.js +3 -3
  70. package/dist/runtime/subsystems/integration/build-change-source.js.map +1 -0
  71. package/dist/runtime/subsystems/{sync → integration}/deep-equal.differ.d.ts +2 -2
  72. package/dist/runtime/subsystems/{sync → integration}/deep-equal.differ.js +1 -1
  73. package/dist/runtime/subsystems/integration/deep-equal.differ.js.map +1 -0
  74. package/dist/runtime/subsystems/{sync → integration}/detection-config.schema.d.ts +3 -3
  75. package/dist/runtime/subsystems/{sync → integration}/detection-config.schema.js +1 -1
  76. package/dist/runtime/subsystems/integration/detection-config.schema.js.map +1 -0
  77. package/dist/runtime/subsystems/{sync/execute-sync.use-case.d.ts → integration/execute-integration.use-case.d.ts} +13 -13
  78. package/dist/runtime/subsystems/{sync/execute-sync.use-case.js → integration/execute-integration.use-case.js} +30 -30
  79. package/dist/runtime/subsystems/integration/execute-integration.use-case.js.map +1 -0
  80. package/dist/runtime/subsystems/integration/index.d.ts +28 -0
  81. package/dist/runtime/subsystems/{sync → integration}/index.js +171 -171
  82. package/dist/runtime/subsystems/integration/index.js.map +1 -0
  83. package/dist/runtime/subsystems/{sync/sync-audit.schema.d.ts → integration/integration-audit.schema.d.ts} +64 -64
  84. package/dist/runtime/subsystems/{sync/sync-audit.schema.js → integration/integration-audit.schema.js} +47 -47
  85. package/dist/runtime/subsystems/integration/integration-audit.schema.js.map +1 -0
  86. package/dist/runtime/subsystems/{sync/sync-change-source.protocol.d.ts → integration/integration-change-source.protocol.d.ts} +10 -10
  87. package/dist/runtime/subsystems/integration/integration-change-source.protocol.js +1 -0
  88. package/dist/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.d.ts → integration/integration-cursor-store.drizzle-backend.d.ts} +1 -1
  89. package/dist/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.js → integration/integration-cursor-store.drizzle-backend.js} +65 -65
  90. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js.map +1 -0
  91. package/dist/runtime/subsystems/{sync/sync-cursor-store.memory-backend.d.ts → integration/integration-cursor-store.memory-backend.d.ts} +6 -6
  92. package/dist/runtime/subsystems/{sync/sync-cursor-store.memory-backend.js → integration/integration-cursor-store.memory-backend.js} +5 -5
  93. package/dist/runtime/subsystems/integration/integration-cursor-store.memory-backend.js.map +1 -0
  94. package/dist/runtime/subsystems/{sync/sync-cursor-store.protocol.d.ts → integration/integration-cursor-store.protocol.d.ts} +13 -13
  95. package/dist/runtime/subsystems/integration/integration-cursor-store.protocol.js +1 -0
  96. package/dist/runtime/subsystems/{sync/sync-errors.d.ts → integration/integration-errors.d.ts} +2 -2
  97. package/dist/runtime/subsystems/{sync/sync-errors.js → integration/integration-errors.js} +3 -3
  98. package/dist/runtime/subsystems/integration/integration-errors.js.map +1 -0
  99. package/dist/runtime/subsystems/{sync/sync-field-diff.protocol.d.ts → integration/integration-field-diff.protocol.d.ts} +2 -2
  100. package/dist/runtime/subsystems/{sync/sync-field-diff.protocol.js → integration/integration-field-diff.protocol.js} +2 -2
  101. package/dist/runtime/subsystems/integration/integration-field-diff.protocol.js.map +1 -0
  102. package/dist/runtime/subsystems/{sync/sync-loopback.protocol.d.ts → integration/integration-loopback.protocol.d.ts} +2 -2
  103. package/dist/runtime/subsystems/integration/integration-loopback.protocol.js +1 -0
  104. package/dist/runtime/subsystems/{sync/sync-middleware.protocol.d.ts → integration/integration-middleware.protocol.d.ts} +5 -5
  105. package/dist/runtime/subsystems/integration/integration-middleware.protocol.js +1 -0
  106. package/dist/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.d.ts → integration/integration-run-recorder.drizzle-backend.d.ts} +5 -5
  107. package/dist/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.js → integration/integration-run-recorder.drizzle-backend.js} +73 -73
  108. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js.map +1 -0
  109. package/dist/runtime/subsystems/{sync/sync-run-recorder.memory-backend.d.ts → integration/integration-run-recorder.memory-backend.d.ts} +15 -15
  110. package/dist/runtime/subsystems/{sync/sync-run-recorder.memory-backend.js → integration/integration-run-recorder.memory-backend.js} +11 -11
  111. package/dist/runtime/subsystems/integration/integration-run-recorder.memory-backend.js.map +1 -0
  112. package/dist/runtime/subsystems/{sync/sync-run-recorder.protocol.d.ts → integration/integration-run-recorder.protocol.d.ts} +25 -25
  113. package/dist/runtime/subsystems/integration/integration-run-recorder.protocol.js +1 -0
  114. package/dist/runtime/subsystems/{sync/sync-sink.protocol.d.ts → integration/integration-sink.protocol.d.ts} +5 -5
  115. package/dist/runtime/subsystems/integration/integration-sink.protocol.js +1 -0
  116. package/dist/runtime/subsystems/{sync/sync.module.d.ts → integration/integration.module.d.ts} +24 -24
  117. package/dist/runtime/subsystems/{sync/sync.module.js → integration/integration.module.js} +132 -132
  118. package/dist/runtime/subsystems/integration/integration.module.js.map +1 -0
  119. package/dist/runtime/subsystems/integration/integration.tokens.d.ts +47 -0
  120. package/dist/runtime/subsystems/integration/integration.tokens.js +18 -0
  121. package/dist/runtime/subsystems/integration/integration.tokens.js.map +1 -0
  122. package/dist/runtime/subsystems/{sync → integration}/loopback.middleware.d.ts +5 -5
  123. package/dist/runtime/subsystems/{sync → integration}/loopback.middleware.js +1 -1
  124. package/dist/runtime/subsystems/integration/loopback.middleware.js.map +1 -0
  125. package/dist/runtime/subsystems/{sync → integration}/poll-change-source.d.ts +5 -5
  126. package/dist/runtime/subsystems/{sync → integration}/poll-change-source.js +1 -1
  127. package/dist/runtime/subsystems/integration/poll-change-source.js.map +1 -0
  128. package/dist/runtime/subsystems/{sync → integration}/webhook-change-source.d.ts +5 -5
  129. package/dist/runtime/subsystems/{sync → integration}/webhook-change-source.js +1 -1
  130. package/dist/runtime/subsystems/integration/webhook-change-source.js.map +1 -0
  131. package/dist/runtime/subsystems/jobs/bullmq.config.d.ts +22 -3
  132. package/dist/runtime/subsystems/jobs/bullmq.config.js.map +1 -1
  133. package/dist/runtime/subsystems/jobs/index.d.ts +1 -4
  134. package/dist/runtime/subsystems/jobs/index.js +87 -506
  135. package/dist/runtime/subsystems/jobs/index.js.map +1 -1
  136. package/dist/runtime/subsystems/jobs/job-orchestrator.bullmq-backend.js.map +1 -1
  137. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js +3 -0
  138. package/dist/runtime/subsystems/jobs/job-worker.bullmq-backend.js.map +1 -1
  139. package/dist/runtime/subsystems/jobs/job-worker.module.d.ts +10 -3
  140. package/dist/runtime/subsystems/jobs/job-worker.module.js +248 -664
  141. package/dist/runtime/subsystems/jobs/job-worker.module.js.map +1 -1
  142. package/dist/runtime/subsystems/jobs/jobs-domain.module.d.ts +0 -1
  143. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +89 -391
  144. package/dist/runtime/subsystems/jobs/jobs-domain.module.js.map +1 -1
  145. package/dist/runtime/subsystems/observability/index.d.ts +4 -4
  146. package/dist/runtime/subsystems/observability/index.js +11 -11
  147. package/dist/runtime/subsystems/observability/index.js.map +1 -1
  148. package/dist/runtime/subsystems/observability/observability.module.d.ts +2 -2
  149. package/dist/runtime/subsystems/observability/observability.module.js +11 -11
  150. package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
  151. package/dist/runtime/subsystems/observability/observability.protocol.d.ts +11 -11
  152. package/dist/runtime/subsystems/observability/observability.service.d.ts +6 -6
  153. package/dist/runtime/subsystems/observability/observability.service.js +11 -11
  154. package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
  155. package/dist/runtime/subsystems/observability/observability.tokens.d.ts +1 -1
  156. package/dist/runtime/subsystems/observability/observability.tokens.js.map +1 -1
  157. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.d.ts +3 -3
  158. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.js.map +1 -1
  159. package/dist/runtime/subsystems/observability/reporters/index.d.ts +3 -3
  160. package/dist/runtime/subsystems/observability/reporters/index.js.map +1 -1
  161. package/dist/src/cli/index.js +412 -302
  162. package/dist/src/cli/index.js.map +1 -1
  163. package/dist/src/index.d.ts +22 -22
  164. package/dist/src/index.js +191 -191
  165. package/dist/src/index.js.map +1 -1
  166. package/examples/auth-integrations/README.md +32 -32
  167. package/examples/auth-integrations/definitions/entities/{integration.yaml → connection.yaml} +10 -10
  168. package/examples/auth-integrations/runtime/{integrations/adapters/integration-grant-sink.adapter.ts → connections/adapters/connection-grant-sink.adapter.ts} +7 -7
  169. package/examples/auth-integrations/runtime/{integrations/adapters/integration-reader.adapter.ts → connections/adapters/connection-reader.adapter.ts} +10 -10
  170. package/examples/auth-integrations/runtime/{integrations/adapters/integration-token-writer.adapter.ts → connections/adapters/connection-token-writer.adapter.ts} +11 -11
  171. package/examples/auth-integrations/runtime/connections/connections-auth.module.ts +81 -0
  172. package/examples/auth-integrations/runtime/{integrations/facade/integrations.service.ts → connections/facade/connections.service.ts} +35 -35
  173. package/examples/auth-integrations/runtime/{integrations → connections}/oauth/use-cases/create-or-update-from-oauth-grant.use-case.ts +11 -11
  174. package/examples/auth-integrations/runtime/{integrations/oauth/use-cases/disconnect-integration.use-case.ts → connections/oauth/use-cases/disconnect-connection.use-case.ts} +6 -6
  175. package/examples/auth-integrations/runtime/connections/oauth/use-cases/list-user-connections.use-case.ts +21 -0
  176. package/examples/auth-integrations/runtime/connections/oauth/use-cases/mark-connection-requires-reauth.use-case.ts +21 -0
  177. package/package.json +1 -1
  178. package/runtime/base-classes/index.ts +8 -8
  179. package/runtime/base-classes/{synced-entity-repository.ts → integrated-entity-repository.ts} +36 -36
  180. package/runtime/base-classes/{synced-entity-service.ts → integrated-entity-service.ts} +6 -6
  181. package/runtime/base-classes/{sync-upsert-config.ts → integration-upsert-config.ts} +12 -12
  182. package/runtime/base-classes/{junction-sync-repository.ts → junction-integration-repository.ts} +28 -28
  183. package/runtime/subsystems/auth/auth-oauth-state.schema.ts +1 -1
  184. package/runtime/subsystems/auth/auth.module.ts +4 -4
  185. package/runtime/subsystems/auth/auth.tokens.ts +7 -7
  186. package/runtime/subsystems/auth/controllers/auth.controller.ts +7 -7
  187. package/runtime/subsystems/auth/index.ts +19 -19
  188. package/runtime/subsystems/auth/protocols/auth-strategy.ts +3 -3
  189. package/runtime/subsystems/auth/protocols/{integration-store.ts → connection-store.ts} +19 -19
  190. package/runtime/subsystems/auth/protocols/provider-strategy.ts +2 -2
  191. package/runtime/subsystems/auth/runtime/{integration-broken.error.ts → connection-broken.error.ts} +5 -5
  192. package/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.ts +35 -35
  193. package/runtime/subsystems/auth/runtime/with-auth-retry.ts +3 -3
  194. package/runtime/subsystems/events/event-bus.drizzle-backend.ts +32 -10
  195. package/runtime/subsystems/events/events.module.ts +38 -6
  196. package/runtime/subsystems/events/index.ts +7 -1
  197. package/runtime/subsystems/index.ts +11 -11
  198. package/runtime/subsystems/{sync → integration}/build-change-source.ts +3 -3
  199. package/runtime/subsystems/{sync → integration}/deep-equal.differ.ts +7 -7
  200. package/runtime/subsystems/{sync → integration}/detection-config.schema.ts +3 -3
  201. package/runtime/subsystems/{sync/execute-sync.use-case.ts → integration/execute-integration.use-case.ts} +40 -40
  202. package/runtime/subsystems/{sync → integration}/index.ts +47 -47
  203. package/runtime/subsystems/{sync/sync-audit.schema.ts → integration/integration-audit.schema.ts} +61 -61
  204. package/runtime/subsystems/{sync/sync-change-source.protocol.ts → integration/integration-change-source.protocol.ts} +9 -9
  205. package/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.ts → integration/integration-cursor-store.drizzle-backend.ts} +30 -30
  206. package/runtime/subsystems/{sync/sync-cursor-store.memory-backend.ts → integration/integration-cursor-store.memory-backend.ts} +9 -9
  207. package/runtime/subsystems/{sync/sync-cursor-store.protocol.ts → integration/integration-cursor-store.protocol.ts} +13 -13
  208. package/runtime/subsystems/{sync/sync-errors.ts → integration/integration-errors.ts} +3 -3
  209. package/runtime/subsystems/{sync/sync-field-diff.protocol.ts → integration/integration-field-diff.protocol.ts} +2 -2
  210. package/runtime/subsystems/{sync/sync-loopback.protocol.ts → integration/integration-loopback.protocol.ts} +2 -2
  211. package/runtime/subsystems/{sync/sync-middleware.protocol.ts → integration/integration-middleware.protocol.ts} +6 -6
  212. package/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.ts → integration/integration-run-recorder.drizzle-backend.ts} +39 -39
  213. package/runtime/subsystems/{sync/sync-run-recorder.memory-backend.ts → integration/integration-run-recorder.memory-backend.ts} +23 -23
  214. package/runtime/subsystems/{sync/sync-run-recorder.protocol.ts → integration/integration-run-recorder.protocol.ts} +25 -25
  215. package/runtime/subsystems/{sync/sync-sink.protocol.ts → integration/integration-sink.protocol.ts} +4 -4
  216. package/runtime/subsystems/{sync/sync.module.ts → integration/integration.module.ts} +48 -48
  217. package/runtime/subsystems/integration/integration.tokens.ts +49 -0
  218. package/runtime/subsystems/{sync → integration}/loopback.middleware.ts +5 -5
  219. package/runtime/subsystems/{sync → integration}/poll-change-source.ts +7 -7
  220. package/runtime/subsystems/{sync → integration}/webhook-change-source.ts +7 -7
  221. package/runtime/subsystems/jobs/bullmq.config.ts +23 -3
  222. package/runtime/subsystems/jobs/index.ts +13 -8
  223. package/runtime/subsystems/jobs/job-worker.bullmq-backend.ts +5 -2
  224. package/runtime/subsystems/jobs/job-worker.module.ts +27 -7
  225. package/runtime/subsystems/jobs/jobs-domain.module.ts +27 -2
  226. package/runtime/subsystems/observability/index.ts +1 -1
  227. package/runtime/subsystems/observability/observability.module.ts +2 -2
  228. package/runtime/subsystems/observability/observability.protocol.ts +11 -11
  229. package/runtime/subsystems/observability/observability.service.ts +13 -13
  230. package/runtime/subsystems/observability/observability.tokens.ts +1 -1
  231. package/src/patterns/library/index.ts +4 -4
  232. package/src/patterns/library/{synced.pattern.ts → integrated.pattern.ts} +12 -12
  233. package/src/patterns/library/junction.pattern.ts +1 -1
  234. package/src/patterns/pattern-definition.ts +3 -3
  235. package/templates/entity/new/backend/modules/core/{sync-source.ejs.t → integration-source.ejs.t} +6 -6
  236. package/templates/entity/new/backend/modules/core/{sync-source.providers.ejs.t → integration-source.providers.ejs.t} +2 -2
  237. package/templates/entity/new/clean-lite-ps/entity.ejs.t +1 -1
  238. package/templates/entity/new/clean-lite-ps/module.ejs.t +1 -1
  239. package/templates/entity/new/clean-lite-ps/prompt-extension.js +33 -33
  240. package/templates/entity/new/clean-lite-ps/repository.ejs.t +27 -27
  241. package/templates/entity/new/frontend/collections/collection.ejs.t +26 -1
  242. package/templates/entity/new/frontend/collections/collections-base.ejs.t +11 -0
  243. package/templates/entity/new/frontend/entity/combined.ejs.t +31 -1
  244. package/templates/entity/new/prompt.js +27 -15
  245. package/templates/junction/new/entity.ejs.t +1 -1
  246. package/templates/junction/new/prompt.js +24 -24
  247. package/templates/junction/new/repository.ejs.t +19 -19
  248. package/templates/subsystem/auth/auth-oauth-state.schema.ejs.t +2 -2
  249. package/templates/subsystem/auth-config/prompt.js +1 -1
  250. package/templates/subsystem/auth-integrations/app-module-hook.ejs.t +5 -5
  251. package/templates/subsystem/bridge/prompt.js +1 -1
  252. package/templates/subsystem/events/domain-events.schema.ejs.t +43 -2
  253. package/templates/subsystem/integration/integration-audit.schema.ejs.t +192 -0
  254. package/templates/subsystem/{sync → integration}/prompt.js +12 -12
  255. package/templates/subsystem/{sync-config/codegen-config-sync-block.ejs.t → integration-config/codegen-config-integration-block.ejs.t} +7 -7
  256. package/templates/subsystem/integration-config/prompt.js +22 -0
  257. package/templates/subsystem/jobs/worker.ejs.t +2 -2
  258. package/templates/subsystem/observability/main-hook.ejs.t +1 -1
  259. package/templates/subsystem/observability/prompt.js +1 -1
  260. package/templates/subsystem/openapi-config/prompt.js +1 -1
  261. package/dist/runtime/base-classes/junction-sync-repository.js.map +0 -1
  262. package/dist/runtime/base-classes/sync-upsert-config.js +0 -1
  263. package/dist/runtime/base-classes/synced-entity-repository.js.map +0 -1
  264. package/dist/runtime/base-classes/synced-entity-service.js.map +0 -1
  265. package/dist/runtime/subsystems/auth/protocols/integration-store.js +0 -1
  266. package/dist/runtime/subsystems/auth/runtime/integration-broken.error.js +0 -19
  267. package/dist/runtime/subsystems/auth/runtime/integration-broken.error.js.map +0 -1
  268. package/dist/runtime/subsystems/sync/build-change-source.js.map +0 -1
  269. package/dist/runtime/subsystems/sync/deep-equal.differ.js.map +0 -1
  270. package/dist/runtime/subsystems/sync/detection-config.schema.js.map +0 -1
  271. package/dist/runtime/subsystems/sync/execute-sync.use-case.js.map +0 -1
  272. package/dist/runtime/subsystems/sync/index.d.ts +0 -28
  273. package/dist/runtime/subsystems/sync/index.js.map +0 -1
  274. package/dist/runtime/subsystems/sync/loopback.middleware.js.map +0 -1
  275. package/dist/runtime/subsystems/sync/poll-change-source.js.map +0 -1
  276. package/dist/runtime/subsystems/sync/sync-audit.schema.js.map +0 -1
  277. package/dist/runtime/subsystems/sync/sync-change-source.protocol.js +0 -1
  278. package/dist/runtime/subsystems/sync/sync-cursor-store.drizzle-backend.js.map +0 -1
  279. package/dist/runtime/subsystems/sync/sync-cursor-store.memory-backend.js.map +0 -1
  280. package/dist/runtime/subsystems/sync/sync-cursor-store.protocol.js +0 -1
  281. package/dist/runtime/subsystems/sync/sync-errors.js.map +0 -1
  282. package/dist/runtime/subsystems/sync/sync-field-diff.protocol.js.map +0 -1
  283. package/dist/runtime/subsystems/sync/sync-loopback.protocol.js +0 -1
  284. package/dist/runtime/subsystems/sync/sync-middleware.protocol.js +0 -1
  285. package/dist/runtime/subsystems/sync/sync-run-recorder.drizzle-backend.js.map +0 -1
  286. package/dist/runtime/subsystems/sync/sync-run-recorder.memory-backend.js.map +0 -1
  287. package/dist/runtime/subsystems/sync/sync-run-recorder.protocol.js +0 -1
  288. package/dist/runtime/subsystems/sync/sync-sink.protocol.js +0 -1
  289. package/dist/runtime/subsystems/sync/sync.module.js.map +0 -1
  290. package/dist/runtime/subsystems/sync/sync.tokens.d.ts +0 -47
  291. package/dist/runtime/subsystems/sync/sync.tokens.js +0 -18
  292. package/dist/runtime/subsystems/sync/sync.tokens.js.map +0 -1
  293. package/dist/runtime/subsystems/sync/webhook-change-source.js.map +0 -1
  294. package/examples/auth-integrations/runtime/integrations/integrations-auth.module.ts +0 -81
  295. package/examples/auth-integrations/runtime/integrations/oauth/use-cases/list-user-integrations.use-case.ts +0 -21
  296. package/examples/auth-integrations/runtime/integrations/oauth/use-cases/mark-integration-requires-reauth.use-case.ts +0 -21
  297. package/runtime/subsystems/sync/sync.tokens.ts +0 -49
  298. package/templates/subsystem/sync/sync-audit.schema.ejs.t +0 -192
  299. package/templates/subsystem/sync-config/prompt.js +0 -22
  300. /package/dist/runtime/base-classes/{sync-upsert-config.js.map → integration-upsert-config.js.map} +0 -0
  301. /package/dist/runtime/subsystems/auth/protocols/{integration-store.js.map → connection-store.js.map} +0 -0
  302. /package/dist/runtime/subsystems/{sync/sync-change-source.protocol.js.map → integration/integration-change-source.protocol.js.map} +0 -0
  303. /package/dist/runtime/subsystems/{sync/sync-cursor-store.protocol.js.map → integration/integration-cursor-store.protocol.js.map} +0 -0
  304. /package/dist/runtime/subsystems/{sync/sync-loopback.protocol.js.map → integration/integration-loopback.protocol.js.map} +0 -0
  305. /package/dist/runtime/subsystems/{sync/sync-middleware.protocol.js.map → integration/integration-middleware.protocol.js.map} +0 -0
  306. /package/dist/runtime/subsystems/{sync/sync-run-recorder.protocol.js.map → integration/integration-run-recorder.protocol.js.map} +0 -0
  307. /package/dist/runtime/subsystems/{sync/sync-sink.protocol.js.map → integration/integration-sink.protocol.js.map} +0 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Typed errors + shared boundary helpers for the sync subsystem.
2
+ * Typed errors + shared boundary helpers for the integration subsystem.
3
3
  *
4
4
  * Classes (not bare Error) so consumers can `instanceof` them in catch
5
5
  * blocks and exception filters can map them to HTTP codes.
@@ -9,7 +9,7 @@
9
9
 
10
10
  /**
11
11
  * Thrown by the Drizzle cursor-store / run-recorder backends AND by the
12
- * orchestrator entry point when `SYNC_MULTI_TENANT` is enabled but the
12
+ * orchestrator entry point when `INTEGRATION_MULTI_TENANT` is enabled but the
13
13
  * caller did not supply a non-null `tenantId`. Strict enforcement at the
14
14
  * boundary — explicit `null` still throws.
15
15
  *
@@ -24,7 +24,7 @@ export class MissingTenantIdError extends Error {
24
24
  override readonly name = 'MissingTenantIdError';
25
25
  constructor(operation: string) {
26
26
  super(
27
- `Missing tenantId for sync operation '${operation}'. SyncModule is ` +
27
+ `Missing tenantId for integration operation '${operation}'. IntegrationModule is ` +
28
28
  `configured with multiTenant: true — every call must include a ` +
29
29
  `non-null tenantId. Either pass the tenantId or disable multi-` +
30
30
  `tenancy on the module.`,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sync subsystem — field-diff protocol (port)
2
+ * Integration subsystem — field-diff protocol (port)
3
3
  *
4
4
  * `IFieldDiffer<T>` is the pluggable differ seam. The default implementation
5
5
  * (`DeepEqualDiffer`, ships in SYNC-5) walks every field except an ignore
@@ -17,7 +17,7 @@ import { z } from 'zod';
17
17
  // ============================================================================
18
18
 
19
19
  /**
20
- * Structured per-field change. Enforced shape for `sync_run_items.changed_fields`.
20
+ * Structured per-field change. Enforced shape for `integration_run_items.changed_fields`.
21
21
  *
22
22
  * `created` items set `from: null, to: <value>` for every non-null field.
23
23
  * `deleted` items set `from: <value>, to: null`.
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Sync subsystem — loopback-fingerprint protocol (port)
2
+ * Integration subsystem — loopback-fingerprint protocol (port)
3
3
  *
4
4
  * Optional port. When the local system writes to an upstream provider via an
5
5
  * outbound path, the same change typically echoes back on the next inbound
6
- * poll/CDC/webhook. A fingerprint store lets `ExecuteSyncUseCase` skip
6
+ * poll/CDC/webhook. A fingerprint store lets `ExecuteIntegrationUseCase` skip
7
7
  * records it already wrote, avoiding a diff-noop round trip and a spurious
8
8
  * audit row.
9
9
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sync subsystem — change-source middleware protocol (#226-1)
2
+ * Integration subsystem — change-source middleware protocol (#226-1)
3
3
  *
4
4
  * `ChangeMiddleware<T>` lets consumers compose cross-cutting concerns
5
5
  * (loopback suppression, redaction, throttling) onto an `IChangeSource<T>`
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * type ChangeMiddleware<T> =
13
13
  * (next: ChangeIterator<T>) =>
14
- * (subscription: SyncSubscriptionView, cursor: unknown | null) =>
14
+ * (subscription: IntegrationSubscriptionView, cursor: unknown | null) =>
15
15
  * AsyncIterable<Change<T>>;
16
16
  *
17
17
  * The middleware wraps the *next* iterator factory rather than the
@@ -26,13 +26,13 @@
26
26
  * Loopback shipping as middleware (#226-5) is the canonical example —
27
27
  * `createLoopbackMiddleware(store)` filters echoes of local writes
28
28
  * before they reach the orchestrator's diff stage, replacing the prior
29
- * `@Optional() SYNC_LOOPBACK_FINGERPRINT_STORE` orchestrator branch.
29
+ * `@Optional() INTEGRATION_LOOPBACK_FINGERPRINT_STORE` orchestrator branch.
30
30
  */
31
31
 
32
32
  import type {
33
33
  Change,
34
- SyncSubscriptionView,
35
- } from './sync-change-source.protocol';
34
+ IntegrationSubscriptionView,
35
+ } from './integration-change-source.protocol';
36
36
 
37
37
  // ============================================================================
38
38
  // ChangeIterator — the inner shape middleware wraps
@@ -44,7 +44,7 @@ import type {
44
44
  * `IChangeSource<T>` instance method binds 1:1 to this signature.
45
45
  */
46
46
  export type ChangeIterator<T> = (
47
- subscription: SyncSubscriptionView,
47
+ subscription: IntegrationSubscriptionView,
48
48
  cursor: unknown | null,
49
49
  ) => AsyncIterable<Change<T>>;
50
50
 
@@ -1,23 +1,23 @@
1
1
  /**
2
- * DrizzleSyncRunRecorder — Drizzle-backed `ISyncRunRecorder` (SYNC-4).
2
+ * DrizzleIntegrationRunRecorder — Drizzle-backed `IIntegrationRunRecorder` (SYNC-4).
3
3
  *
4
4
  * Generic write path only — extracted from the source app's
5
- * `SyncRunRecorderService`, minus CRM-specific convenience methods. Those
5
+ * `IntegrationRunRecorderService`, minus CRM-specific convenience methods. Those
6
6
  * stay consumer-owned; the subsystem ships the substrate.
7
7
  *
8
8
  * ## Responsibilities
9
9
  *
10
- * - `startRun` — INSERT sync_runs row in status='running', returns id.
10
+ * - `startRun` — INSERT integration_runs row in status='running', returns id.
11
11
  * - `recordItem` — validates `changedFields` via `FieldDiffSchema.parse`
12
12
  * BEFORE the INSERT; a malformed shape throws before
13
13
  * any DB call fires. Enforces the ADR-0003 contract at
14
14
  * the write boundary.
15
- * - `completeRun` — UPDATE sync_runs with terminal status, counts,
15
+ * - `completeRun` — UPDATE integration_runs with terminal status, counts,
16
16
  * cursor_after, duration_ms, completed_at.
17
17
  *
18
18
  * ## Multi-tenancy
19
19
  *
20
- * When `SYNC_MULTI_TENANT` is true (SYNC-6):
20
+ * When `INTEGRATION_MULTI_TENANT` is true (SYNC-6):
21
21
  * - `startRun` and `recordItem` require non-null `tenantId` on input.
22
22
  * Enforcement goes through the shared `assertTenantId` helper so the
23
23
  * error message shape matches the orchestrator entry point + the
@@ -33,23 +33,23 @@ import type { DrizzleClient } from '../../types/drizzle';
33
33
  import { DRIZZLE } from '../../constants/tokens';
34
34
  import type {
35
35
  CompleteRunInput,
36
- ISyncRunRecorder,
36
+ IIntegrationRunRecorder,
37
37
  RecordItemInput,
38
38
  StartRunInput,
39
- SyncRunSummary,
40
- } from './sync-run-recorder.protocol';
41
- import { syncRuns, syncRunItems, syncSubscriptions } from './sync-audit.schema';
42
- import { FieldDiffSchema } from './sync-field-diff.protocol';
43
- import { SYNC_MULTI_TENANT } from './sync.tokens';
44
- import { assertTenantId } from './sync-errors';
39
+ IntegrationRunSummary,
40
+ } from './integration-run-recorder.protocol';
41
+ import { integrationRuns, integrationRunItems, integrationSubscriptions } from './integration-audit.schema';
42
+ import { FieldDiffSchema } from './integration-field-diff.protocol';
43
+ import { INTEGRATION_MULTI_TENANT } from './integration.tokens';
44
+ import { assertTenantId } from './integration-errors';
45
45
 
46
46
  @Injectable()
47
- export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
47
+ export class DrizzleIntegrationRunRecorder implements IIntegrationRunRecorder {
48
48
  private readonly multiTenant: boolean;
49
49
 
50
50
  constructor(
51
51
  @Inject(DRIZZLE) private readonly db: DrizzleClient,
52
- @Optional() @Inject(SYNC_MULTI_TENANT) multiTenant?: boolean,
52
+ @Optional() @Inject(INTEGRATION_MULTI_TENANT) multiTenant?: boolean,
53
53
  ) {
54
54
  this.multiTenant = multiTenant ?? false;
55
55
  }
@@ -61,7 +61,7 @@ export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
61
61
  });
62
62
 
63
63
  const rows = await this.db
64
- .insert(syncRuns)
64
+ .insert(integrationRuns)
65
65
  .values({
66
66
  subscriptionId: input.subscriptionId,
67
67
  direction: input.direction,
@@ -70,14 +70,14 @@ export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
70
70
  cursorBefore: input.cursorBefore ?? null,
71
71
  tenantId: input.tenantId ?? null,
72
72
  })
73
- .returning({ id: syncRuns.id });
73
+ .returning({ id: integrationRuns.id });
74
74
 
75
75
  const id = rows[0]?.id;
76
76
  if (!id) {
77
77
  // Drizzle's insert().returning() contract: at least one row is
78
78
  // returned for every successful INSERT. A missing id would indicate
79
79
  // a driver misbehavior; throw loudly rather than return bogus data.
80
- throw new Error('DrizzleSyncRunRecorder: INSERT RETURNING produced no id');
80
+ throw new Error('DrizzleIntegrationRunRecorder: INSERT RETURNING produced no id');
81
81
  }
82
82
  return { id };
83
83
  }
@@ -93,8 +93,8 @@ export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
93
93
  // the validation failure, not a DB constraint error.
94
94
  FieldDiffSchema.parse(input.changedFields);
95
95
 
96
- await this.db.insert(syncRunItems).values({
97
- syncRunId: input.syncRunId,
96
+ await this.db.insert(integrationRunItems).values({
97
+ integrationRunId: input.integrationRunId,
98
98
  entityType: input.entityType,
99
99
  externalId: input.externalId,
100
100
  localId: input.localId ?? null,
@@ -111,21 +111,21 @@ export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
111
111
  limit: number,
112
112
  subscriptionId?: string,
113
113
  tenantId?: string | null,
114
- ): Promise<SyncRunSummary[]> {
114
+ ): Promise<IntegrationRunSummary[]> {
115
115
  assertTenantId(tenantId, {
116
116
  multiTenant: this.multiTenant,
117
117
  operation: 'listRecent',
118
118
  });
119
119
 
120
- // JOIN against sync_subscriptions to resolve `integration_id` per run.
121
- // `sync_runs.subscription_id` is a non-null FK so INNER JOIN is correct;
120
+ // JOIN against integration_subscriptions to resolve `connection_id` per run.
121
+ // `integration_runs.subscription_id` is a non-null FK so INNER JOIN is correct;
122
122
  // there should be no orphaned runs.
123
123
  const conditions: SQL[] = [];
124
124
  if (subscriptionId !== undefined) {
125
- conditions.push(eq(syncRuns.subscriptionId, subscriptionId));
125
+ conditions.push(eq(integrationRuns.subscriptionId, subscriptionId));
126
126
  }
127
127
  if (this.multiTenant) {
128
- conditions.push(eq(syncRuns.tenantId, tenantId as string));
128
+ conditions.push(eq(integrationRuns.tenantId, tenantId as string));
129
129
  }
130
130
  const where =
131
131
  conditions.length === 0
@@ -136,28 +136,28 @@ export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
136
136
 
137
137
  const rows = await this.db
138
138
  .select({
139
- id: syncRuns.id,
140
- subscriptionId: syncRuns.subscriptionId,
141
- integrationId: syncSubscriptions.integrationId,
142
- status: syncRuns.status,
143
- startedAt: syncRuns.startedAt,
144
- completedAt: syncRuns.completedAt,
145
- recordsProcessed: syncRuns.recordsProcessed,
146
- tenantId: syncRuns.tenantId,
139
+ id: integrationRuns.id,
140
+ subscriptionId: integrationRuns.subscriptionId,
141
+ connectionId: integrationSubscriptions.connectionId,
142
+ status: integrationRuns.status,
143
+ startedAt: integrationRuns.startedAt,
144
+ completedAt: integrationRuns.completedAt,
145
+ recordsProcessed: integrationRuns.recordsProcessed,
146
+ tenantId: integrationRuns.tenantId,
147
147
  })
148
- .from(syncRuns)
148
+ .from(integrationRuns)
149
149
  .innerJoin(
150
- syncSubscriptions,
151
- eq(syncRuns.subscriptionId, syncSubscriptions.id),
150
+ integrationSubscriptions,
151
+ eq(integrationRuns.subscriptionId, integrationSubscriptions.id),
152
152
  )
153
153
  .where(where)
154
- .orderBy(desc(syncRuns.startedAt))
154
+ .orderBy(desc(integrationRuns.startedAt))
155
155
  .limit(limit);
156
156
 
157
157
  return rows.map((row) => ({
158
158
  id: row.id,
159
159
  subscriptionId: row.subscriptionId,
160
- integrationId: row.integrationId,
160
+ connectionId: row.connectionId,
161
161
  status: row.status,
162
162
  startedAt: row.startedAt,
163
163
  completedAt: row.completedAt,
@@ -168,7 +168,7 @@ export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
168
168
 
169
169
  async completeRun(runId: string, input: CompleteRunInput): Promise<void> {
170
170
  await this.db
171
- .update(syncRuns)
171
+ .update(integrationRuns)
172
172
  .set({
173
173
  status: input.status,
174
174
  recordsFound: input.recordsFound,
@@ -178,6 +178,6 @@ export class DrizzleSyncRunRecorder implements ISyncRunRecorder {
178
178
  error: input.error ?? null,
179
179
  completedAt: new Date(),
180
180
  })
181
- .where(eq(syncRuns.id, runId));
181
+ .where(eq(integrationRuns.id, runId));
182
182
  }
183
183
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * MemoryRunRecorder — in-memory backend for `ISyncRunRecorder` (SYNC-6).
2
+ * MemoryRunRecorder — in-memory backend for `IIntegrationRunRecorder` (SYNC-6).
3
3
  *
4
- * Test double so `SyncModule.forRoot({ backend: 'memory' })` is genuinely
4
+ * Test double so `IntegrationModule.forRoot({ backend: 'memory' })` is genuinely
5
5
  * end-to-end runnable without Postgres. Mirrors the role of
6
6
  * `MemoryCursorStore`: plain keyed state, `clear()` helper for
7
7
  * `beforeEach` resets, public inspection surface so tests can assert on
@@ -27,34 +27,34 @@
27
27
  import { Injectable } from '@nestjs/common';
28
28
  import type {
29
29
  CompleteRunInput,
30
- ISyncRunRecorder,
30
+ IIntegrationRunRecorder,
31
31
  RecordItemInput,
32
32
  StartRunInput,
33
- SyncRunSummary,
34
- } from './sync-run-recorder.protocol';
35
- import { FieldDiffSchema } from './sync-field-diff.protocol';
33
+ IntegrationRunSummary,
34
+ } from './integration-run-recorder.protocol';
35
+ import { FieldDiffSchema } from './integration-field-diff.protocol';
36
36
 
37
37
  /**
38
38
  * Optional per-subscription metadata a test can seed on the memory backend
39
- * so `listRecent` can surface `integrationId`. The memory recorder's write
39
+ * so `listRecent` can surface `connectionId`. The memory recorder's write
40
40
  * path never persists subscription rows (it only stores runs + items), so
41
- * `listRecent` has no way to derive `integrationId` on its own. Tests that
41
+ * `listRecent` has no way to derive `connectionId` on its own. Tests that
42
42
  * care about the field should populate `subscriptions` before calling
43
43
  * `listRecent`; calls that don't seed get an empty string and a stable
44
44
  * shape (see `listRecent` below).
45
45
  */
46
- export interface MemorySyncSubscription {
47
- integrationId: string;
46
+ export interface MemoryIntegrationSubscription {
47
+ connectionId: string;
48
48
  adapter: string;
49
49
  domain: string;
50
50
  externalRef: string | null;
51
- lastSyncAt?: Date | null;
51
+ lastIntegrationAt?: Date | null;
52
52
  updatedAt: Date;
53
53
  }
54
54
 
55
55
  /**
56
56
  * Concrete run row as held in memory. Shape mirrors the interesting
57
- * columns on `sync_runs` so assertions read like DB queries.
57
+ * columns on `integration_runs` so assertions read like DB queries.
58
58
  */
59
59
  export interface MemoryRunRecord {
60
60
  id: string;
@@ -74,7 +74,7 @@ export interface MemoryRunRecord {
74
74
  }
75
75
 
76
76
  @Injectable()
77
- export class MemoryRunRecorder implements ISyncRunRecorder {
77
+ export class MemoryRunRecorder implements IIntegrationRunRecorder {
78
78
  /**
79
79
  * All started runs keyed by id. Public so tests can inspect lifecycle
80
80
  * transitions without poking through recording methods.
@@ -82,20 +82,20 @@ export class MemoryRunRecorder implements ISyncRunRecorder {
82
82
  readonly runs: Map<string, MemoryRunRecord> = new Map();
83
83
 
84
84
  /**
85
- * Items keyed by `sync_run_id`, array order matches insertion order —
86
- * mirrors the timeline the `(sync_run_id, created_at)` index produces
85
+ * Items keyed by `integration_run_id`, array order matches insertion order —
86
+ * mirrors the timeline the `(integration_run_id, created_at)` index produces
87
87
  * in Postgres.
88
88
  */
89
89
  readonly items: Map<string, RecordItemInput[]> = new Map();
90
90
 
91
91
  /**
92
92
  * Seedable subscription metadata — tests populate this to make
93
- * `listRecent` return meaningful `integrationId` values. The memory
93
+ * `listRecent` return meaningful `connectionId` values. The memory
94
94
  * backend doesn't track subscriptions on its own (only runs + items), so
95
95
  * this map is the intentional extension point: tests write entries for
96
96
  * the subscription ids they use, production code never touches it.
97
97
  */
98
- readonly subscriptions: Map<string, MemorySyncSubscription> = new Map();
98
+ readonly subscriptions: Map<string, MemoryIntegrationSubscription> = new Map();
99
99
 
100
100
  async startRun(input: StartRunInput): Promise<{ id: string }> {
101
101
  const id = crypto.randomUUID();
@@ -123,10 +123,10 @@ export class MemoryRunRecorder implements ISyncRunRecorder {
123
123
  // Same ADR-0003 contract as the Drizzle backend.
124
124
  FieldDiffSchema.parse(input.changedFields);
125
125
 
126
- const bucket = this.items.get(input.syncRunId);
126
+ const bucket = this.items.get(input.integrationRunId);
127
127
  if (!bucket) {
128
128
  throw new Error(
129
- `MemoryRunRecorder.recordItem: no run started for id '${input.syncRunId}'. ` +
129
+ `MemoryRunRecorder.recordItem: no run started for id '${input.integrationRunId}'. ` +
130
130
  `Call startRun(...) first.`,
131
131
  );
132
132
  }
@@ -153,7 +153,7 @@ export class MemoryRunRecorder implements ISyncRunRecorder {
153
153
  limit: number,
154
154
  subscriptionId?: string,
155
155
  _tenantId?: string | null,
156
- ): Promise<SyncRunSummary[]> {
156
+ ): Promise<IntegrationRunSummary[]> {
157
157
  // Memory backend accepts tenantId for contract symmetry but does not
158
158
  // filter on it — state is process-local and cross-tenant isolation is
159
159
  // not meaningful here (matches MemoryCursorStore behavior).
@@ -168,11 +168,11 @@ export class MemoryRunRecorder implements ISyncRunRecorder {
168
168
  .map((r) => ({
169
169
  id: r.id,
170
170
  subscriptionId: r.subscriptionId,
171
- // integrationId is only knowable if the test seeded subscriptions
171
+ // connectionId is only knowable if the test seeded subscriptions
172
172
  // metadata; empty string otherwise. The Drizzle backend resolves
173
173
  // it via JOIN, which is the production path.
174
- integrationId:
175
- this.subscriptions.get(r.subscriptionId)?.integrationId ?? '',
174
+ connectionId:
175
+ this.subscriptions.get(r.subscriptionId)?.connectionId ?? '',
176
176
  status: r.status,
177
177
  startedAt: r.startedAt,
178
178
  completedAt: r.completedAt,
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Sync subsystem — run-recorder protocol (port)
2
+ * Integration subsystem — run-recorder protocol (port)
3
3
  *
4
- * `ISyncRunRecorder` is the write side of the audit log. `ExecuteSyncUseCase`
4
+ * `IIntegrationRunRecorder` is the write side of the audit log. `ExecuteIntegrationUseCase`
5
5
  * (SYNC-5) calls `startRun` at the top of the loop, `recordItem` for each
6
6
  * processed change, and `completeRun` in a `finally` block so a run always
7
7
  * reaches a terminal status.
8
8
  *
9
- * The Drizzle backend (SYNC-4) persists against `sync_runs` / `sync_run_items`
9
+ * The Drizzle backend (SYNC-4) persists against `integration_runs` / `integration_run_items`
10
10
  * from the SYNC-1 schema. Tests use lightweight in-memory fakes — no
11
11
  * dedicated memory backend ships; the surface is small enough that inline
12
12
  * fakes keep the intent local to each spec.
@@ -17,13 +17,13 @@
17
17
  * orchestrator before reaching the recorder, so the recorder's input is
18
18
  * always a `FieldDiff`.
19
19
  */
20
- import type { FieldDiff } from './sync-field-diff.protocol';
20
+ import type { FieldDiff } from './integration-field-diff.protocol';
21
21
 
22
22
  // ============================================================================
23
23
  // Lifecycle — inputs
24
24
  // ============================================================================
25
25
 
26
- /** Args for `startRun`. Mirrors the non-nullable columns on `sync_runs`. */
26
+ /** Args for `startRun`. Mirrors the non-nullable columns on `integration_runs`. */
27
27
  export interface StartRunInput {
28
28
  readonly subscriptionId: string;
29
29
  readonly direction: 'inbound' | 'outbound';
@@ -31,16 +31,16 @@ export interface StartRunInput {
31
31
  /** Cursor snapshot at run start, or `null` if this is the first run. */
32
32
  readonly cursorBefore: unknown | null;
33
33
  /**
34
- * Tenant id when `SYNC_MULTI_TENANT` is enabled. The recorder's own
34
+ * Tenant id when `INTEGRATION_MULTI_TENANT` is enabled. The recorder's own
35
35
  * boundary rule (SYNC-6) enforces non-null when the flag is on;
36
- * orchestrator passes it through from `ExecuteSyncInput.tenantId`.
36
+ * orchestrator passes it through from `ExecuteIntegrationInput.tenantId`.
37
37
  */
38
38
  readonly tenantId?: string | null;
39
39
  }
40
40
 
41
- /** Args for `recordItem`. Mirrors the non-nullable columns on `sync_run_items`. */
41
+ /** Args for `recordItem`. Mirrors the non-nullable columns on `integration_run_items`. */
42
42
  export interface RecordItemInput {
43
- readonly syncRunId: string;
43
+ readonly integrationRunId: string;
44
44
  readonly entityType: string;
45
45
  readonly externalId: string;
46
46
  readonly localId?: string | null;
@@ -71,24 +71,24 @@ export interface CompleteRunInput {
71
71
  // ============================================================================
72
72
 
73
73
  /**
74
- * Denormalized view of one `sync_runs` row, JOINed against
75
- * `sync_subscriptions` to surface `integrationId` in a single read. Consumed
74
+ * Denormalized view of one `integration_runs` row, JOINed against
75
+ * `integration_subscriptions` to surface `connectionId` in a single read. Consumed
76
76
  * by the OBS-5 observability composer (epic #195).
77
77
  *
78
- * `recordsProcessed` is the denormalized column on `sync_runs` — it does NOT
79
- * count `sync_run_items` rows. A correlated subquery per run would be
78
+ * `recordsProcessed` is the denormalized column on `integration_runs` — it does NOT
79
+ * count `integration_run_items` rows. A correlated subquery per run would be
80
80
  * required for a true item count; deferred as a follow-up if needed.
81
81
  *
82
- * Memory backends can't know `integrationId` without subscription metadata
82
+ * Memory backends can't know `connectionId` without subscription metadata
83
83
  * — see each memory backend for the seedable `subscriptions` side-map that
84
84
  * tests populate. When metadata is missing, memory backends emit an empty
85
85
  * string so the shape stays stable (documented in the memory backend).
86
86
  */
87
- export interface SyncRunSummary {
87
+ export interface IntegrationRunSummary {
88
88
  readonly id: string;
89
89
  readonly subscriptionId: string;
90
90
  /** Resolved by Drizzle via JOIN; empty string from memory if not seeded. */
91
- readonly integrationId: string;
91
+ readonly connectionId: string;
92
92
  readonly status: 'running' | 'success' | 'no_changes' | 'failed';
93
93
  readonly startedAt: Date;
94
94
  readonly completedAt: Date | null;
@@ -97,14 +97,14 @@ export interface SyncRunSummary {
97
97
  }
98
98
 
99
99
  // ============================================================================
100
- // ISyncRunRecorder
100
+ // IIntegrationRunRecorder
101
101
  // ============================================================================
102
102
 
103
- export interface ISyncRunRecorder {
104
- /** Opens a new `sync_runs` row in `status = 'running'`. Returns the run id. */
103
+ export interface IIntegrationRunRecorder {
104
+ /** Opens a new `integration_runs` row in `status = 'running'`. Returns the run id. */
105
105
  startRun(input: StartRunInput): Promise<{ id: string }>;
106
106
 
107
- /** Appends one `sync_run_items` row. Throws if `changedFields` is malformed. */
107
+ /** Appends one `integration_run_items` row. Throws if `changedFields` is malformed. */
108
108
  recordItem(input: RecordItemInput): Promise<void>;
109
109
 
110
110
  /**
@@ -115,16 +115,16 @@ export interface ISyncRunRecorder {
115
115
  completeRun(runId: string, input: CompleteRunInput): Promise<void>;
116
116
 
117
117
  /**
118
- * Recent `sync_runs` rows ordered by `started_at DESC`, capped at `limit`.
118
+ * Recent `integration_runs` rows ordered by `started_at DESC`, capped at `limit`.
119
119
  *
120
- * Filter is `subscriptionId` — the natural FK on `sync_runs`. An
121
- * integration-wide view requires filtering on `sync_subscriptions.integration_id`
120
+ * Filter is `subscriptionId` — the natural FK on `integration_runs`. An
121
+ * integration-wide view requires filtering on `integration_subscriptions.connection_id`
122
122
  * through the JOIN and is deferred as a follow-up (epic #195 OBS-4 spec).
123
123
  *
124
124
  * @param limit hard cap on rows returned (no implicit default)
125
125
  * @param subscriptionId optional FK filter; omit for cross-subscription view
126
126
  * @param tenantId required by Drizzle backend when
127
- * `SYNC_MULTI_TENANT` is on (throws
127
+ * `INTEGRATION_MULTI_TENANT` is on (throws
128
128
  * `MissingTenantIdError` otherwise); memory backend
129
129
  * accepts but ignores
130
130
  */
@@ -132,5 +132,5 @@ export interface ISyncRunRecorder {
132
132
  limit: number,
133
133
  subscriptionId?: string,
134
134
  tenantId?: string | null,
135
- ): Promise<SyncRunSummary[]>;
135
+ ): Promise<IntegrationRunSummary[]>;
136
136
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sync subsystem — sync-sink protocol (port)
2
+ * Integration subsystem — integration-sink protocol (port)
3
3
  *
4
4
  * Write surface for the generic orchestrator. One per canonical entity type.
5
5
  *
@@ -13,7 +13,7 @@
13
13
  * Implementations compose the entity's service + (when the entity has EAV)
14
14
  * `FieldValueService` inside a single transaction. ADR-13-revised.
15
15
  */
16
- export interface ISyncSink<TCanonical> {
16
+ export interface IIntegrationSink<TCanonical> {
17
17
  /**
18
18
  * Canonical-shaped view of local state, or `null` when no local row exists.
19
19
  * Called once per change to source the diff's "before" side.
@@ -32,11 +32,11 @@ export interface ISyncSink<TCanonical> {
32
32
  * - tolerate re-entry (same record twice in a window = no-op)
33
33
  *
34
34
  * Returns the local row id and the canonical projection of the saved row
35
- * (so the orchestrator can record it on `sync_run_items.local_id`).
35
+ * (so the orchestrator can record it on `integration_run_items.local_id`).
36
36
  *
37
37
  * `provider` is the adapter domain string (e.g. `'salesforce-crm'`,
38
38
  * `'hubspot-crm'`) persisted on the DB row. Passed from
39
- * `ExecuteSyncInput.provider`.
39
+ * `ExecuteIntegrationInput.provider`.
40
40
  */
41
41
  upsertByExternalId(
42
42
  userId: string,