@pattern-stack/codegen 0.10.1 → 0.12.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 (279) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/README.md +5 -5
  3. package/consumer-skills/codegen/SKILL.md +2 -2
  4. package/consumer-skills/{sync → integration}/SKILL.md +29 -29
  5. package/consumer-skills/{sync → integration}/audit-and-detection.md +22 -22
  6. package/consumer-skills/{sync → integration}/change-sources-and-sinks.md +60 -60
  7. package/consumer-skills/subsystems/SKILL.md +8 -8
  8. package/consumer-skills/subsystems/wiring-and-order.md +7 -7
  9. package/dist/runtime/base-classes/index.d.ts +4 -4
  10. package/dist/runtime/base-classes/index.js +35 -35
  11. package/dist/runtime/base-classes/index.js.map +1 -1
  12. package/dist/runtime/base-classes/{synced-entity-repository.d.ts → integrated-entity-repository.d.ts} +15 -15
  13. package/dist/runtime/base-classes/{synced-entity-repository.js → integrated-entity-repository.js} +21 -21
  14. package/dist/runtime/base-classes/integrated-entity-repository.js.map +1 -0
  15. package/dist/runtime/base-classes/{synced-entity-service.d.ts → integrated-entity-service.d.ts} +6 -6
  16. package/dist/runtime/base-classes/{synced-entity-service.js → integrated-entity-service.js} +4 -4
  17. package/dist/runtime/base-classes/integrated-entity-service.js.map +1 -0
  18. package/dist/runtime/base-classes/{sync-upsert-config.d.ts → integration-upsert-config.d.ts} +13 -13
  19. package/dist/runtime/base-classes/integration-upsert-config.js +1 -0
  20. package/dist/runtime/base-classes/{junction-sync-repository.d.ts → junction-integration-repository.d.ts} +11 -11
  21. package/dist/runtime/base-classes/{junction-sync-repository.js → junction-integration-repository.js} +15 -15
  22. package/dist/runtime/base-classes/junction-integration-repository.js.map +1 -0
  23. package/dist/runtime/subsystems/auth/auth-oauth-state.schema.js.map +1 -1
  24. package/dist/runtime/subsystems/auth/auth.module.d.ts +4 -4
  25. package/dist/runtime/subsystems/auth/auth.module.js +3 -3
  26. package/dist/runtime/subsystems/auth/auth.module.js.map +1 -1
  27. package/dist/runtime/subsystems/auth/auth.tokens.d.ts +8 -8
  28. package/dist/runtime/subsystems/auth/auth.tokens.js +6 -6
  29. package/dist/runtime/subsystems/auth/auth.tokens.js.map +1 -1
  30. package/dist/runtime/subsystems/auth/backends/state-store.drizzle-backend.js.map +1 -1
  31. package/dist/runtime/subsystems/auth/controllers/auth.controller.d.ts +2 -2
  32. package/dist/runtime/subsystems/auth/controllers/auth.controller.js +3 -3
  33. package/dist/runtime/subsystems/auth/controllers/auth.controller.js.map +1 -1
  34. package/dist/runtime/subsystems/auth/index.d.ts +3 -3
  35. package/dist/runtime/subsystems/auth/index.js +40 -40
  36. package/dist/runtime/subsystems/auth/index.js.map +1 -1
  37. package/dist/runtime/subsystems/auth/middleware/requester-context.js.map +1 -1
  38. package/dist/runtime/subsystems/auth/protocols/auth-strategy.d.ts +3 -3
  39. package/dist/runtime/subsystems/auth/protocols/{integration-store.d.ts → connection-store.d.ts} +20 -20
  40. package/dist/runtime/subsystems/auth/protocols/connection-store.js +1 -0
  41. package/dist/runtime/subsystems/auth/protocols/provider-strategy.d.ts +3 -3
  42. package/dist/runtime/subsystems/auth/runtime/{integration-broken.error.d.ts → connection-broken.error.d.ts} +5 -5
  43. package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js +19 -0
  44. package/dist/runtime/subsystems/auth/runtime/connection-broken.error.js.map +1 -0
  45. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.d.ts +10 -10
  46. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js +28 -28
  47. package/dist/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.js.map +1 -1
  48. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.d.ts +1 -1
  49. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js +3 -3
  50. package/dist/runtime/subsystems/auth/runtime/with-auth-retry.js.map +1 -1
  51. package/dist/runtime/subsystems/index.d.ts +11 -7
  52. package/dist/runtime/subsystems/index.js +1041 -67
  53. package/dist/runtime/subsystems/index.js.map +1 -1
  54. package/dist/runtime/subsystems/{sync → integration}/build-change-source.d.ts +3 -3
  55. package/dist/runtime/subsystems/{sync → integration}/build-change-source.js +3 -3
  56. package/dist/runtime/subsystems/integration/build-change-source.js.map +1 -0
  57. package/dist/runtime/subsystems/{sync → integration}/deep-equal.differ.d.ts +2 -2
  58. package/dist/runtime/subsystems/{sync → integration}/deep-equal.differ.js +1 -1
  59. package/dist/runtime/subsystems/integration/deep-equal.differ.js.map +1 -0
  60. package/dist/runtime/subsystems/{sync → integration}/detection-config.schema.d.ts +3 -3
  61. package/dist/runtime/subsystems/{sync → integration}/detection-config.schema.js +1 -1
  62. package/dist/runtime/subsystems/integration/detection-config.schema.js.map +1 -0
  63. package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.d.ts +25 -0
  64. package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js +34 -0
  65. package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js.map +1 -0
  66. package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.d.ts +53 -0
  67. package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js +13 -0
  68. package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js.map +1 -0
  69. package/dist/runtime/subsystems/{sync/execute-sync.use-case.d.ts → integration/execute-integration.use-case.d.ts} +13 -13
  70. package/dist/runtime/subsystems/{sync/execute-sync.use-case.js → integration/execute-integration.use-case.js} +30 -30
  71. package/dist/runtime/subsystems/integration/execute-integration.use-case.js.map +1 -0
  72. package/dist/runtime/subsystems/integration/index.d.ts +30 -0
  73. package/dist/runtime/subsystems/{sync → integration}/index.js +206 -171
  74. package/dist/runtime/subsystems/integration/index.js.map +1 -0
  75. package/dist/runtime/subsystems/{sync/sync-audit.schema.d.ts → integration/integration-audit.schema.d.ts} +64 -64
  76. package/dist/runtime/subsystems/{sync/sync-audit.schema.js → integration/integration-audit.schema.js} +47 -47
  77. package/dist/runtime/subsystems/integration/integration-audit.schema.js.map +1 -0
  78. package/dist/runtime/subsystems/{sync/sync-change-source.protocol.d.ts → integration/integration-change-source.protocol.d.ts} +10 -10
  79. package/dist/runtime/subsystems/integration/integration-change-source.protocol.js +1 -0
  80. package/dist/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.d.ts → integration/integration-cursor-store.drizzle-backend.d.ts} +1 -1
  81. package/dist/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.js → integration/integration-cursor-store.drizzle-backend.js} +65 -65
  82. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js.map +1 -0
  83. package/dist/runtime/subsystems/{sync/sync-cursor-store.memory-backend.d.ts → integration/integration-cursor-store.memory-backend.d.ts} +6 -6
  84. package/dist/runtime/subsystems/{sync/sync-cursor-store.memory-backend.js → integration/integration-cursor-store.memory-backend.js} +5 -5
  85. package/dist/runtime/subsystems/integration/integration-cursor-store.memory-backend.js.map +1 -0
  86. package/dist/runtime/subsystems/{sync/sync-cursor-store.protocol.d.ts → integration/integration-cursor-store.protocol.d.ts} +13 -13
  87. package/dist/runtime/subsystems/integration/integration-cursor-store.protocol.js +1 -0
  88. package/dist/runtime/subsystems/{sync/sync-errors.d.ts → integration/integration-errors.d.ts} +2 -2
  89. package/dist/runtime/subsystems/{sync/sync-errors.js → integration/integration-errors.js} +3 -3
  90. package/dist/runtime/subsystems/integration/integration-errors.js.map +1 -0
  91. package/dist/runtime/subsystems/{sync/sync-field-diff.protocol.d.ts → integration/integration-field-diff.protocol.d.ts} +2 -2
  92. package/dist/runtime/subsystems/{sync/sync-field-diff.protocol.js → integration/integration-field-diff.protocol.js} +2 -2
  93. package/dist/runtime/subsystems/integration/integration-field-diff.protocol.js.map +1 -0
  94. package/dist/runtime/subsystems/{sync/sync-loopback.protocol.d.ts → integration/integration-loopback.protocol.d.ts} +2 -2
  95. package/dist/runtime/subsystems/integration/integration-loopback.protocol.js +1 -0
  96. package/dist/runtime/subsystems/{sync/sync-middleware.protocol.d.ts → integration/integration-middleware.protocol.d.ts} +5 -5
  97. package/dist/runtime/subsystems/integration/integration-middleware.protocol.js +1 -0
  98. package/dist/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.d.ts → integration/integration-run-recorder.drizzle-backend.d.ts} +5 -5
  99. package/dist/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.js → integration/integration-run-recorder.drizzle-backend.js} +73 -73
  100. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js.map +1 -0
  101. package/dist/runtime/subsystems/{sync/sync-run-recorder.memory-backend.d.ts → integration/integration-run-recorder.memory-backend.d.ts} +15 -15
  102. package/dist/runtime/subsystems/{sync/sync-run-recorder.memory-backend.js → integration/integration-run-recorder.memory-backend.js} +11 -11
  103. package/dist/runtime/subsystems/integration/integration-run-recorder.memory-backend.js.map +1 -0
  104. package/dist/runtime/subsystems/{sync/sync-run-recorder.protocol.d.ts → integration/integration-run-recorder.protocol.d.ts} +25 -25
  105. package/dist/runtime/subsystems/integration/integration-run-recorder.protocol.js +1 -0
  106. package/dist/runtime/subsystems/{sync/sync-sink.protocol.d.ts → integration/integration-sink.protocol.d.ts} +5 -5
  107. package/dist/runtime/subsystems/integration/integration-sink.protocol.js +1 -0
  108. package/dist/runtime/subsystems/{sync/sync.module.d.ts → integration/integration.module.d.ts} +24 -24
  109. package/dist/runtime/subsystems/{sync/sync.module.js → integration/integration.module.js} +132 -132
  110. package/dist/runtime/subsystems/integration/integration.module.js.map +1 -0
  111. package/dist/runtime/subsystems/integration/integration.tokens.d.ts +60 -0
  112. package/dist/runtime/subsystems/integration/integration.tokens.js +20 -0
  113. package/dist/runtime/subsystems/integration/integration.tokens.js.map +1 -0
  114. package/dist/runtime/subsystems/{sync → integration}/loopback.middleware.d.ts +5 -5
  115. package/dist/runtime/subsystems/{sync → integration}/loopback.middleware.js +1 -1
  116. package/dist/runtime/subsystems/integration/loopback.middleware.js.map +1 -0
  117. package/dist/runtime/subsystems/{sync → integration}/poll-change-source.d.ts +5 -5
  118. package/dist/runtime/subsystems/{sync → integration}/poll-change-source.js +1 -1
  119. package/dist/runtime/subsystems/integration/poll-change-source.js.map +1 -0
  120. package/dist/runtime/subsystems/{sync → integration}/webhook-change-source.d.ts +5 -5
  121. package/dist/runtime/subsystems/{sync → integration}/webhook-change-source.js +1 -1
  122. package/dist/runtime/subsystems/integration/webhook-change-source.js.map +1 -0
  123. package/dist/runtime/subsystems/jobs/job-worker.module.d.ts +1 -1
  124. package/dist/runtime/subsystems/observability/index.d.ts +4 -4
  125. package/dist/runtime/subsystems/observability/index.js +11 -11
  126. package/dist/runtime/subsystems/observability/index.js.map +1 -1
  127. package/dist/runtime/subsystems/observability/observability.module.d.ts +2 -2
  128. package/dist/runtime/subsystems/observability/observability.module.js +11 -11
  129. package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
  130. package/dist/runtime/subsystems/observability/observability.protocol.d.ts +11 -11
  131. package/dist/runtime/subsystems/observability/observability.service.d.ts +6 -6
  132. package/dist/runtime/subsystems/observability/observability.service.js +11 -11
  133. package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
  134. package/dist/runtime/subsystems/observability/observability.tokens.d.ts +1 -1
  135. package/dist/runtime/subsystems/observability/observability.tokens.js.map +1 -1
  136. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.d.ts +3 -3
  137. package/dist/runtime/subsystems/observability/reporters/bridge-metrics.reporter.js.map +1 -1
  138. package/dist/runtime/subsystems/observability/reporters/index.d.ts +3 -3
  139. package/dist/runtime/subsystems/observability/reporters/index.js.map +1 -1
  140. package/dist/src/cli/index.js +1336 -376
  141. package/dist/src/cli/index.js.map +1 -1
  142. package/dist/src/index.d.ts +70 -22
  143. package/dist/src/index.js +290 -194
  144. package/dist/src/index.js.map +1 -1
  145. package/examples/auth-integrations/README.md +32 -32
  146. package/examples/auth-integrations/definitions/entities/{integration.yaml → connection.yaml} +10 -10
  147. package/examples/auth-integrations/runtime/{integrations/adapters/integration-grant-sink.adapter.ts → connections/adapters/connection-grant-sink.adapter.ts} +7 -7
  148. package/examples/auth-integrations/runtime/{integrations/adapters/integration-reader.adapter.ts → connections/adapters/connection-reader.adapter.ts} +10 -10
  149. package/examples/auth-integrations/runtime/{integrations/adapters/integration-token-writer.adapter.ts → connections/adapters/connection-token-writer.adapter.ts} +11 -11
  150. package/examples/auth-integrations/runtime/connections/connections-auth.module.ts +81 -0
  151. package/examples/auth-integrations/runtime/{integrations/facade/integrations.service.ts → connections/facade/connections.service.ts} +35 -35
  152. package/examples/auth-integrations/runtime/{integrations → connections}/oauth/use-cases/create-or-update-from-oauth-grant.use-case.ts +11 -11
  153. 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
  154. package/examples/auth-integrations/runtime/connections/oauth/use-cases/list-user-connections.use-case.ts +21 -0
  155. package/examples/auth-integrations/runtime/connections/oauth/use-cases/mark-connection-requires-reauth.use-case.ts +21 -0
  156. package/package.json +9 -1
  157. package/runtime/base-classes/index.ts +8 -8
  158. package/runtime/base-classes/{synced-entity-repository.ts → integrated-entity-repository.ts} +36 -36
  159. package/runtime/base-classes/{synced-entity-service.ts → integrated-entity-service.ts} +6 -6
  160. package/runtime/base-classes/{sync-upsert-config.ts → integration-upsert-config.ts} +12 -12
  161. package/runtime/base-classes/{junction-sync-repository.ts → junction-integration-repository.ts} +28 -28
  162. package/runtime/subsystems/auth/auth-oauth-state.schema.ts +1 -1
  163. package/runtime/subsystems/auth/auth.module.ts +4 -4
  164. package/runtime/subsystems/auth/auth.tokens.ts +7 -7
  165. package/runtime/subsystems/auth/controllers/auth.controller.ts +7 -7
  166. package/runtime/subsystems/auth/index.ts +19 -19
  167. package/runtime/subsystems/auth/protocols/auth-strategy.ts +3 -3
  168. package/runtime/subsystems/auth/protocols/{integration-store.ts → connection-store.ts} +19 -19
  169. package/runtime/subsystems/auth/protocols/provider-strategy.ts +2 -2
  170. package/runtime/subsystems/auth/runtime/{integration-broken.error.ts → connection-broken.error.ts} +5 -5
  171. package/runtime/subsystems/auth/runtime/oauth2-refresh.strategy.ts +35 -35
  172. package/runtime/subsystems/auth/runtime/with-auth-retry.ts +3 -3
  173. package/runtime/subsystems/index.ts +26 -11
  174. package/runtime/subsystems/{sync → integration}/build-change-source.ts +3 -3
  175. package/runtime/subsystems/{sync → integration}/deep-equal.differ.ts +7 -7
  176. package/runtime/subsystems/{sync → integration}/detection-config.schema.ts +3 -3
  177. package/runtime/subsystems/integration/entity-change-source-registry.memory.ts +40 -0
  178. package/runtime/subsystems/integration/entity-change-source-registry.protocol.ts +59 -0
  179. package/runtime/subsystems/{sync/execute-sync.use-case.ts → integration/execute-integration.use-case.ts} +40 -40
  180. package/runtime/subsystems/{sync → integration}/index.ts +56 -47
  181. package/runtime/subsystems/{sync/sync-audit.schema.ts → integration/integration-audit.schema.ts} +61 -61
  182. package/runtime/subsystems/{sync/sync-change-source.protocol.ts → integration/integration-change-source.protocol.ts} +9 -9
  183. package/runtime/subsystems/{sync/sync-cursor-store.drizzle-backend.ts → integration/integration-cursor-store.drizzle-backend.ts} +30 -30
  184. package/runtime/subsystems/{sync/sync-cursor-store.memory-backend.ts → integration/integration-cursor-store.memory-backend.ts} +9 -9
  185. package/runtime/subsystems/{sync/sync-cursor-store.protocol.ts → integration/integration-cursor-store.protocol.ts} +13 -13
  186. package/runtime/subsystems/{sync/sync-errors.ts → integration/integration-errors.ts} +3 -3
  187. package/runtime/subsystems/{sync/sync-field-diff.protocol.ts → integration/integration-field-diff.protocol.ts} +2 -2
  188. package/runtime/subsystems/{sync/sync-loopback.protocol.ts → integration/integration-loopback.protocol.ts} +2 -2
  189. package/runtime/subsystems/{sync/sync-middleware.protocol.ts → integration/integration-middleware.protocol.ts} +6 -6
  190. package/runtime/subsystems/{sync/sync-run-recorder.drizzle-backend.ts → integration/integration-run-recorder.drizzle-backend.ts} +39 -39
  191. package/runtime/subsystems/{sync/sync-run-recorder.memory-backend.ts → integration/integration-run-recorder.memory-backend.ts} +23 -23
  192. package/runtime/subsystems/{sync/sync-run-recorder.protocol.ts → integration/integration-run-recorder.protocol.ts} +25 -25
  193. package/runtime/subsystems/{sync/sync-sink.protocol.ts → integration/integration-sink.protocol.ts} +4 -4
  194. package/runtime/subsystems/{sync/sync.module.ts → integration/integration.module.ts} +48 -48
  195. package/runtime/subsystems/integration/integration.tokens.ts +63 -0
  196. package/runtime/subsystems/{sync → integration}/loopback.middleware.ts +5 -5
  197. package/runtime/subsystems/{sync → integration}/poll-change-source.ts +7 -7
  198. package/runtime/subsystems/{sync → integration}/webhook-change-source.ts +7 -7
  199. package/runtime/subsystems/observability/index.ts +1 -1
  200. package/runtime/subsystems/observability/observability.module.ts +2 -2
  201. package/runtime/subsystems/observability/observability.protocol.ts +11 -11
  202. package/runtime/subsystems/observability/observability.service.ts +13 -13
  203. package/runtime/subsystems/observability/observability.tokens.ts +1 -1
  204. package/src/patterns/library/index.ts +4 -4
  205. package/src/patterns/library/{synced.pattern.ts → integrated.pattern.ts} +12 -12
  206. package/src/patterns/library/junction.pattern.ts +1 -1
  207. package/src/patterns/pattern-definition.ts +3 -3
  208. package/templates/entity/new/backend/modules/core/{sync-source.ejs.t → integration-source.ejs.t} +6 -6
  209. package/templates/entity/new/clean-lite-ps/entity.ejs.t +12 -3
  210. package/templates/entity/new/clean-lite-ps/module.ejs.t +1 -1
  211. package/templates/entity/new/clean-lite-ps/prompt-extension.js +243 -60
  212. package/templates/entity/new/clean-lite-ps/repository.ejs.t +27 -27
  213. package/templates/entity/new/frontend/collections/collection.ejs.t +26 -1
  214. package/templates/entity/new/frontend/collections/collections-base.ejs.t +11 -0
  215. package/templates/entity/new/frontend/entity/combined.ejs.t +31 -1
  216. package/templates/entity/new/prompt.js +27 -15
  217. package/templates/junction/new/entity.ejs.t +1 -1
  218. package/templates/junction/new/prompt.js +24 -24
  219. package/templates/junction/new/repository.ejs.t +19 -19
  220. package/templates/subsystem/auth/auth-oauth-state.schema.ejs.t +2 -2
  221. package/templates/subsystem/auth-config/prompt.js +1 -1
  222. package/templates/subsystem/auth-integrations/app-module-hook.ejs.t +5 -5
  223. package/templates/subsystem/bridge/prompt.js +1 -1
  224. package/templates/subsystem/integration/integration-audit.schema.ejs.t +192 -0
  225. package/templates/subsystem/{sync → integration}/prompt.js +12 -12
  226. package/templates/subsystem/{sync-config/codegen-config-sync-block.ejs.t → integration-config/codegen-config-integration-block.ejs.t} +7 -7
  227. package/templates/subsystem/integration-config/prompt.js +22 -0
  228. package/templates/subsystem/jobs/worker.ejs.t +2 -2
  229. package/templates/subsystem/observability/main-hook.ejs.t +1 -1
  230. package/templates/subsystem/observability/prompt.js +1 -1
  231. package/templates/subsystem/openapi-config/prompt.js +1 -1
  232. package/dist/runtime/base-classes/junction-sync-repository.js.map +0 -1
  233. package/dist/runtime/base-classes/sync-upsert-config.js +0 -1
  234. package/dist/runtime/base-classes/synced-entity-repository.js.map +0 -1
  235. package/dist/runtime/base-classes/synced-entity-service.js.map +0 -1
  236. package/dist/runtime/subsystems/auth/protocols/integration-store.js +0 -1
  237. package/dist/runtime/subsystems/auth/runtime/integration-broken.error.js +0 -19
  238. package/dist/runtime/subsystems/auth/runtime/integration-broken.error.js.map +0 -1
  239. package/dist/runtime/subsystems/sync/build-change-source.js.map +0 -1
  240. package/dist/runtime/subsystems/sync/deep-equal.differ.js.map +0 -1
  241. package/dist/runtime/subsystems/sync/detection-config.schema.js.map +0 -1
  242. package/dist/runtime/subsystems/sync/execute-sync.use-case.js.map +0 -1
  243. package/dist/runtime/subsystems/sync/index.d.ts +0 -28
  244. package/dist/runtime/subsystems/sync/index.js.map +0 -1
  245. package/dist/runtime/subsystems/sync/loopback.middleware.js.map +0 -1
  246. package/dist/runtime/subsystems/sync/poll-change-source.js.map +0 -1
  247. package/dist/runtime/subsystems/sync/sync-audit.schema.js.map +0 -1
  248. package/dist/runtime/subsystems/sync/sync-change-source.protocol.js +0 -1
  249. package/dist/runtime/subsystems/sync/sync-cursor-store.drizzle-backend.js.map +0 -1
  250. package/dist/runtime/subsystems/sync/sync-cursor-store.memory-backend.js.map +0 -1
  251. package/dist/runtime/subsystems/sync/sync-cursor-store.protocol.js +0 -1
  252. package/dist/runtime/subsystems/sync/sync-errors.js.map +0 -1
  253. package/dist/runtime/subsystems/sync/sync-field-diff.protocol.js.map +0 -1
  254. package/dist/runtime/subsystems/sync/sync-loopback.protocol.js +0 -1
  255. package/dist/runtime/subsystems/sync/sync-middleware.protocol.js +0 -1
  256. package/dist/runtime/subsystems/sync/sync-run-recorder.drizzle-backend.js.map +0 -1
  257. package/dist/runtime/subsystems/sync/sync-run-recorder.memory-backend.js.map +0 -1
  258. package/dist/runtime/subsystems/sync/sync-run-recorder.protocol.js +0 -1
  259. package/dist/runtime/subsystems/sync/sync-sink.protocol.js +0 -1
  260. package/dist/runtime/subsystems/sync/sync.module.js.map +0 -1
  261. package/dist/runtime/subsystems/sync/sync.tokens.d.ts +0 -47
  262. package/dist/runtime/subsystems/sync/sync.tokens.js +0 -18
  263. package/dist/runtime/subsystems/sync/sync.tokens.js.map +0 -1
  264. package/dist/runtime/subsystems/sync/webhook-change-source.js.map +0 -1
  265. package/examples/auth-integrations/runtime/integrations/integrations-auth.module.ts +0 -81
  266. package/examples/auth-integrations/runtime/integrations/oauth/use-cases/list-user-integrations.use-case.ts +0 -21
  267. package/examples/auth-integrations/runtime/integrations/oauth/use-cases/mark-integration-requires-reauth.use-case.ts +0 -21
  268. package/runtime/subsystems/sync/sync.tokens.ts +0 -49
  269. package/templates/entity/new/backend/modules/core/sync-source.providers.ejs.t +0 -18
  270. package/templates/subsystem/sync/sync-audit.schema.ejs.t +0 -192
  271. package/templates/subsystem/sync-config/prompt.js +0 -22
  272. /package/dist/runtime/base-classes/{sync-upsert-config.js.map → integration-upsert-config.js.map} +0 -0
  273. /package/dist/runtime/subsystems/auth/protocols/{integration-store.js.map → connection-store.js.map} +0 -0
  274. /package/dist/runtime/subsystems/{sync/sync-change-source.protocol.js.map → integration/integration-change-source.protocol.js.map} +0 -0
  275. /package/dist/runtime/subsystems/{sync/sync-cursor-store.protocol.js.map → integration/integration-cursor-store.protocol.js.map} +0 -0
  276. /package/dist/runtime/subsystems/{sync/sync-loopback.protocol.js.map → integration/integration-loopback.protocol.js.map} +0 -0
  277. /package/dist/runtime/subsystems/{sync/sync-middleware.protocol.js.map → integration/integration-middleware.protocol.js.map} +0 -0
  278. /package/dist/runtime/subsystems/{sync/sync-run-recorder.protocol.js.map → integration/integration-run-recorder.protocol.js.map} +0 -0
  279. /package/dist/runtime/subsystems/{sync/sync-sink.protocol.js.map → integration/integration-sink.protocol.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../runtime/subsystems/integration/integration-run-recorder.drizzle-backend.ts","../../../../runtime/constants/tokens.ts","../../../../runtime/subsystems/integration/integration-audit.schema.ts","../../../../runtime/subsystems/integration/integration-field-diff.protocol.ts","../../../../runtime/subsystems/integration/integration.tokens.ts","../../../../runtime/subsystems/integration/integration-errors.ts"],"sourcesContent":["/**\n * DrizzleIntegrationRunRecorder — Drizzle-backed `IIntegrationRunRecorder` (SYNC-4).\n *\n * Generic write path only — extracted from the source app's\n * `IntegrationRunRecorderService`, minus CRM-specific convenience methods. Those\n * stay consumer-owned; the subsystem ships the substrate.\n *\n * ## Responsibilities\n *\n * - `startRun` — INSERT integration_runs row in status='running', returns id.\n * - `recordItem` — validates `changedFields` via `FieldDiffSchema.parse`\n * BEFORE the INSERT; a malformed shape throws before\n * any DB call fires. Enforces the ADR-0003 contract at\n * the write boundary.\n * - `completeRun` — UPDATE integration_runs with terminal status, counts,\n * cursor_after, duration_ms, completed_at.\n *\n * ## Multi-tenancy\n *\n * When `INTEGRATION_MULTI_TENANT` is true (SYNC-6):\n * - `startRun` and `recordItem` require non-null `tenantId` on input.\n * Enforcement goes through the shared `assertTenantId` helper so the\n * error message shape matches the orchestrator entry point + the\n * cursor-store backends.\n * - `completeRun` does NOT re-check tenancy — the run id was returned\n * by `startRun` which already enforced it, and run ids are uuids that\n * aren't guessable cross-tenant. Matches JOB-3's pattern of trusting\n * the run-id for downstream mutations.\n */\nimport { Inject, Injectable, Optional } from '@nestjs/common';\nimport { and, desc, eq, type SQL } from 'drizzle-orm';\nimport type { DrizzleClient } from '../../types/drizzle';\nimport { DRIZZLE } from '../../constants/tokens';\nimport type {\n CompleteRunInput,\n IIntegrationRunRecorder,\n RecordItemInput,\n StartRunInput,\n IntegrationRunSummary,\n} from './integration-run-recorder.protocol';\nimport { integrationRuns, integrationRunItems, integrationSubscriptions } from './integration-audit.schema';\nimport { FieldDiffSchema } from './integration-field-diff.protocol';\nimport { INTEGRATION_MULTI_TENANT } from './integration.tokens';\nimport { assertTenantId } from './integration-errors';\n\n@Injectable()\nexport class DrizzleIntegrationRunRecorder implements IIntegrationRunRecorder {\n private readonly multiTenant: boolean;\n\n constructor(\n @Inject(DRIZZLE) private readonly db: DrizzleClient,\n @Optional() @Inject(INTEGRATION_MULTI_TENANT) multiTenant?: boolean,\n ) {\n this.multiTenant = multiTenant ?? false;\n }\n\n async startRun(input: StartRunInput): Promise<{ id: string }> {\n assertTenantId(input.tenantId, {\n multiTenant: this.multiTenant,\n operation: 'startRun',\n });\n\n const rows = await this.db\n .insert(integrationRuns)\n .values({\n subscriptionId: input.subscriptionId,\n direction: input.direction,\n action: input.action,\n status: 'running',\n cursorBefore: input.cursorBefore ?? null,\n tenantId: input.tenantId ?? null,\n })\n .returning({ id: integrationRuns.id });\n\n const id = rows[0]?.id;\n if (!id) {\n // Drizzle's insert().returning() contract: at least one row is\n // returned for every successful INSERT. A missing id would indicate\n // a driver misbehavior; throw loudly rather than return bogus data.\n throw new Error('DrizzleIntegrationRunRecorder: INSERT RETURNING produced no id');\n }\n return { id };\n }\n\n async recordItem(input: RecordItemInput): Promise<void> {\n assertTenantId(input.tenantId, {\n multiTenant: this.multiTenant,\n operation: 'recordItem',\n });\n\n // ADR-0003 contract enforcement — reject malformed changedFields\n // before the DB call fires. `parse` throws a ZodError; callers see\n // the validation failure, not a DB constraint error.\n FieldDiffSchema.parse(input.changedFields);\n\n await this.db.insert(integrationRunItems).values({\n integrationRunId: input.integrationRunId,\n entityType: input.entityType,\n externalId: input.externalId,\n localId: input.localId ?? null,\n operation: input.operation,\n status: input.status,\n changedFields: input.changedFields,\n title: input.title ?? null,\n error: input.error ?? null,\n tenantId: input.tenantId ?? null,\n });\n }\n\n async listRecent(\n limit: number,\n subscriptionId?: string,\n tenantId?: string | null,\n ): Promise<IntegrationRunSummary[]> {\n assertTenantId(tenantId, {\n multiTenant: this.multiTenant,\n operation: 'listRecent',\n });\n\n // JOIN against integration_subscriptions to resolve `connection_id` per run.\n // `integration_runs.subscription_id` is a non-null FK so INNER JOIN is correct;\n // there should be no orphaned runs.\n const conditions: SQL[] = [];\n if (subscriptionId !== undefined) {\n conditions.push(eq(integrationRuns.subscriptionId, subscriptionId));\n }\n if (this.multiTenant) {\n conditions.push(eq(integrationRuns.tenantId, tenantId as string));\n }\n const where =\n conditions.length === 0\n ? undefined\n : conditions.length === 1\n ? conditions[0]\n : and(...conditions);\n\n const rows = await this.db\n .select({\n id: integrationRuns.id,\n subscriptionId: integrationRuns.subscriptionId,\n connectionId: integrationSubscriptions.connectionId,\n status: integrationRuns.status,\n startedAt: integrationRuns.startedAt,\n completedAt: integrationRuns.completedAt,\n recordsProcessed: integrationRuns.recordsProcessed,\n tenantId: integrationRuns.tenantId,\n })\n .from(integrationRuns)\n .innerJoin(\n integrationSubscriptions,\n eq(integrationRuns.subscriptionId, integrationSubscriptions.id),\n )\n .where(where)\n .orderBy(desc(integrationRuns.startedAt))\n .limit(limit);\n\n return rows.map((row) => ({\n id: row.id,\n subscriptionId: row.subscriptionId,\n connectionId: row.connectionId,\n status: row.status,\n startedAt: row.startedAt,\n completedAt: row.completedAt,\n recordsProcessed: row.recordsProcessed,\n tenantId: row.tenantId,\n }));\n }\n\n async completeRun(runId: string, input: CompleteRunInput): Promise<void> {\n await this.db\n .update(integrationRuns)\n .set({\n status: input.status,\n recordsFound: input.recordsFound,\n recordsProcessed: input.recordsProcessed,\n cursorAfter: input.cursorAfter ?? null,\n durationMs: input.durationMs,\n error: input.error ?? null,\n completedAt: new Date(),\n })\n .where(eq(integrationRuns.id, runId));\n }\n}\n","/**\n * NestJS injection tokens\n *\n * Used with @Inject() decorator in concrete repository constructors.\n */\n\n/**\n * Injection token for the Drizzle ORM database client.\n *\n * Usage in concrete repositories:\n * ```typescript\n * constructor(@Inject(DRIZZLE) db: DrizzleClient) { super(db); }\n * ```\n */\nexport const DRIZZLE = 'DRIZZLE' as const;\n\n/**\n * Injection token for the event bus (IEventBus).\n *\n * Optional — only resolved when EventsModule.forRoot() is registered.\n * BaseService uses this with @Optional() to emit lifecycle events\n * without requiring the events subsystem to be installed.\n *\n * Usage in services/use cases:\n * ```typescript\n * @Optional() @Inject(EVENT_BUS) eventBus?: IEventBus\n * ```\n */\nexport const EVENT_BUS = 'EVENT_BUS' as const;\n","/**\n * Drizzle schema for the integration subsystem audit/observability tables (SYNC-1).\n *\n * Three tables model end-to-end integration observability, keyed by the single port\n * every integration adapter implements (`IChangeSource<T>` from SYNC-2):\n *\n * - `integration_subscriptions` — owns the cursor per\n * `(connection_id, adapter, domain, external_ref)` tuple. Addressed\n * by id by `ICursorStore` (SYNC-3/SYNC-4).\n * - `integration_runs` — per-run audit log: start/complete, status,\n * cursor before/after, counts, direction (inbound|outbound),\n * action (poll|cdc|webhook|manual|writeback).\n * - `integration_run_items` — per-record change log with structured\n * `changed_fields` jsonb enforced by the Zod `FieldDiffSchema`\n * contract (ADR-0003; protocol lives in SYNC-2's\n * integration-field-diff.protocol.ts).\n *\n * Design calls (vs. issue #126 open questions):\n *\n * - `integration_subscriptions` ships in the subsystem (not consumer-owned).\n * Rationale: SYNC-4's `PostgresCursorStore` needs to read/write this\n * table directly; making it consumer-owned would require consumers to\n * hand-wire a shape the backend already knows. The row is addressable\n * by id and scoped by the uniqueness tuple; consumers can still\n * query/list it freely. Same stance as `job_run` being subsystem-\n * owned while remaining consumer-queryable.\n *\n * - `tenant_id` is always emitted on the three tables as nullable text.\n * The `INTEGRATION_MULTI_TENANT` DI flag (SYNC-6) is what enforces the\n * non-null + cross-tenant-isolation contract at the service/orchestrator\n * boundary. This mirrors JOB-1/JOB-8's final shape — runtime guard, not\n * a scaffold-time conditional column. Keeps the schema file uniform\n * across single-tenant and multi-tenant deployments.\n *\n * - `changed_fields` on `integration_run_items` is typed via the Zod-inferred\n * `FieldDiff` shape from SYNC-2 (`{ [fieldName]: { from, to } }`). The\n * recorder service (SYNC-5) validates every write against\n * `FieldDiffSchema.parse` so consumers can rely on the shape.\n */\nimport {\n pgEnum,\n pgTable,\n uuid,\n text,\n jsonb,\n integer,\n boolean,\n timestamp,\n index,\n uniqueIndex,\n} from 'drizzle-orm/pg-core';\nimport type { InferSelectModel } from 'drizzle-orm';\n\nimport type { FieldDiff } from './integration-field-diff.protocol';\n\n// ─── Enums ──────────────────────────────────────────────────────────────────\n\n/**\n * Direction of a integration run relative to local state.\n *\n * - `inbound` — external → local (the common case: SFDC poll → local DB).\n * - `outbound` — local → external (writeback; deferred per epic but the\n * column shape is reserved so future writeback runs share the audit log).\n */\nexport const integrationRunDirectionEnum = pgEnum('integration_run_direction', [\n 'inbound',\n 'outbound',\n]);\n\n/**\n * How the run detected upstream changes. Maps 1:1 to the `Change.source`\n * provenance on inbound runs; `manual` captures operator-triggered re-integrations\n * and `writeback` captures outbound runs.\n */\nexport const integrationRunActionEnum = pgEnum('integration_run_action', [\n 'poll',\n 'cdc',\n 'webhook',\n 'manual',\n 'writeback',\n]);\n\n/**\n * Lifecycle status of a integration run.\n *\n * - `running` — in-flight; recorder has started but not completed.\n * - `success` — completed with at least one change processed.\n * - `no_changes` — completed cleanly, no upstream changes found.\n * - `failed` — errored before completion; `error` column carries the\n * message. `records_processed` may be non-zero (partial progress).\n */\nexport const integrationRunStatusEnum = pgEnum('integration_run_status', [\n 'running',\n 'success',\n 'no_changes',\n 'failed',\n]);\n\n/**\n * Operation applied per record. Mirrors `Change<T>.operation` from SYNC-2,\n * plus the recorder's own `'noop'` for changes that matched existing state.\n */\nexport const integrationRunItemOperationEnum = pgEnum('integration_run_item_operation', [\n 'created',\n 'updated',\n 'deleted',\n 'noop',\n]);\n\n/**\n * Per-record status within a run. `skipped` captures loopback-detected echoes\n * of the local system's own writes (see `ILoopbackFingerprintStore` in the\n * epic), which record the external_id but intentionally do not touch local\n * state.\n */\nexport const integrationRunItemStatusEnum = pgEnum('integration_run_item_status', [\n 'success',\n 'failed',\n 'skipped',\n]);\n\n// ─── integration_subscriptions ─────────────────────────────────────────────────────\n\n/**\n * One cursor owner per (integration, adapter, domain, external_ref).\n *\n * - `connection_id` — opaque id of the connected account/instance. E.g.\n * the SFDC org id for polling strategies, the GitHub installation id\n * for webhook strategies.\n * - `adapter` — short adapter label, e.g. `'salesforce'`, `'hubspot'`.\n * - `domain` — canonical entity domain this subscription tracks,\n * e.g. `'opportunity'`, `'contact'`.\n * - `external_ref` — optional upstream scope (e.g. a filter id, a\n * webhook subscription id). NULL when the subscription covers the\n * entire domain.\n *\n * The cursor shape is opaque jsonb — strategies type it internally (poll:\n * `{ systemModstamp }`, cdc: `{ replayId }`, webhook: `{ ts }`). Overwritten\n * by `ICursorStore.put(id, cursor)`.\n */\nexport const integrationSubscriptions = pgTable(\n 'integration_subscriptions',\n {\n id: uuid('id').primaryKey().defaultRandom(),\n connectionId: text('connection_id').notNull(),\n adapter: text('adapter').notNull(),\n domain: text('domain').notNull(),\n externalRef: text('external_ref'),\n enabled: boolean('enabled').notNull().default(true),\n /**\n * Per-subscription configuration bag. Strategies type it internally;\n * e.g. polling strategies stash `{ batchSize, highWatermark }` here.\n */\n config: jsonb('config').notNull().default({}).$type<Record<string, unknown>>(),\n /**\n * Opaque cursor persisted by `ICursorStore.put()`. NULL until the first\n * successful run advances it.\n */\n cursor: jsonb('cursor').$type<unknown>(),\n lastIntegrationAt: timestamp('last_integration_at', { withTimezone: true }),\n /** Runtime-enforced when `INTEGRATION_MULTI_TENANT` is true; see SYNC-6. */\n tenantId: text('tenant_id'),\n createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),\n },\n (t) => ({\n /**\n * Composite uniqueness per the epic shape. `external_ref` is nullable;\n * Postgres treats NULLs as distinct in a UNIQUE constraint, which means\n * two rows with the same `(connection_id, adapter, domain)` and NULL\n * external_ref are allowed. That's intentional — a subscription with\n * NULL external_ref covers the full domain, and duplicates there would\n * be a consumer-layer modeling issue, not a schema concern.\n */\n uqIntegrationSubscriptionTuple: uniqueIndex('uq_integration_subscriptions_tuple').on(\n t.connectionId,\n t.adapter,\n t.domain,\n t.externalRef,\n ),\n /** Scheduling query: list enabled subscriptions ordered by staleness. */\n idxIntegrationSubscriptionsEnabledLastIntegration: index(\n 'idx_integration_subscriptions_enabled_last_integration',\n ).on(t.enabled, t.lastIntegrationAt),\n }),\n);\n\nexport type IntegrationSubscriptionRow = InferSelectModel<typeof integrationSubscriptions>;\n\n// ─── integration_runs ──────────────────────────────────────────────────────────────\n\n/**\n * One row per invocation of `ExecuteIntegrationUseCase`. `started_at` is set when\n * the recorder opens the run; `completed_at`, `status`, `records_*`,\n * `cursor_after`, and `duration_ms` are filled on completion.\n *\n * `cursor_before` / `cursor_after` carry the opaque cursor snapshots so the\n * run log is fully self-describing — given a run id, an operator can reason\n * about exactly what window was scanned without cross-referencing another\n * table.\n */\nexport const integrationRuns = pgTable(\n 'integration_runs',\n {\n id: uuid('id').primaryKey().defaultRandom(),\n subscriptionId: uuid('subscription_id')\n .notNull()\n .references(() => integrationSubscriptions.id, { onDelete: 'cascade' }),\n direction: integrationRunDirectionEnum('direction').notNull(),\n action: integrationRunActionEnum('action').notNull(),\n status: integrationRunStatusEnum('status').notNull().default('running'),\n recordsFound: integer('records_found').notNull().default(0),\n recordsProcessed: integer('records_processed').notNull().default(0),\n cursorBefore: jsonb('cursor_before').$type<unknown>(),\n cursorAfter: jsonb('cursor_after').$type<unknown>(),\n durationMs: integer('duration_ms'),\n error: text('error'),\n startedAt: timestamp('started_at', { withTimezone: true })\n .notNull()\n .defaultNow(),\n completedAt: timestamp('completed_at', { withTimezone: true }),\n /** Runtime-enforced when `INTEGRATION_MULTI_TENANT` is true; see SYNC-6. */\n tenantId: text('tenant_id'),\n },\n (t) => ({\n /** Timeline read: \"most recent runs for this subscription\". */\n idxIntegrationRunsSubscriptionStartedAt: index(\n 'idx_integration_runs_subscription_started_at',\n ).on(t.subscriptionId, t.startedAt),\n /** Stale-run sweeper: \"runs that started > N minutes ago and are still running\". */\n idxIntegrationRunsStatusStartedAt: index('idx_integration_runs_status_started_at').on(\n t.status,\n t.startedAt,\n ),\n }),\n);\n\nexport type IntegrationRunRow = InferSelectModel<typeof integrationRuns>;\n\n// ─── integration_run_items ─────────────────────────────────────────────────────────\n\n/**\n * One row per upstream change processed within a run. Captures the canonical\n * decision the orchestrator made (`operation` + `status`), the structured\n * per-field diff (`changed_fields`, ADR-0003), and the local row id\n * (`local_id`) for drill-down joins.\n *\n * `changed_fields` is validated at the recorder layer via `FieldDiffSchema`\n * (SYNC-2) — the $type<FieldDiff> annotation here only documents the shape\n * for Drizzle consumers. The runtime enforcement is non-negotiable: downstream\n * drift-detection queries rely on the `{from, to}` shape per field.\n *\n * `title` is an optional human-readable label captured at write time (e.g.\n * `\"Pinnacle opportunity\"`) so run-log UIs don't need to re-hydrate the\n * canonical record.\n */\nexport const integrationRunItems = pgTable(\n 'integration_run_items',\n {\n id: uuid('id').primaryKey().defaultRandom(),\n integrationRunId: uuid('integration_run_id')\n .notNull()\n .references(() => integrationRuns.id, { onDelete: 'cascade' }),\n entityType: text('entity_type').notNull(),\n externalId: text('external_id').notNull(),\n localId: text('local_id'),\n operation: integrationRunItemOperationEnum('operation').notNull(),\n status: integrationRunItemStatusEnum('status').notNull(),\n /**\n * Structured per-field diff — ADR-0003 shape enforced by\n * `FieldDiffSchema.parse` at the recorder service layer.\n *\n * Shape: `{ [fieldName]: { from: unknown, to: unknown } }`.\n * Empty `{}` for `noop` items; `{ [field]: { from: null, to: <value> } }`\n * for created items; `{ [field]: { from: <value>, to: null } }` for\n * deleted items.\n */\n changedFields: jsonb('changed_fields').notNull().default({}).$type<FieldDiff>(),\n title: text('title'),\n error: text('error'),\n createdAt: timestamp('created_at', { withTimezone: true })\n .notNull()\n .defaultNow(),\n /** Runtime-enforced when `INTEGRATION_MULTI_TENANT` is true; see SYNC-6. */\n tenantId: text('tenant_id'),\n },\n (t) => ({\n /** Ordered timeline within a run. */\n idxIntegrationRunItemsRunCreatedAt: index('idx_integration_run_items_run_created_at').on(\n t.integrationRunId,\n t.createdAt,\n ),\n /** Per-record history: \"every integration that touched opportunity/$extId\". */\n idxIntegrationRunItemsEntityExternal: index(\n 'idx_integration_run_items_entity_external',\n ).on(t.entityType, t.externalId),\n }),\n);\n\nexport type IntegrationRunItemRow = InferSelectModel<typeof integrationRunItems>;\n","/**\n * Integration subsystem — field-diff protocol (port)\n *\n * `IFieldDiffer<T>` is the pluggable differ seam. The default implementation\n * (`DeepEqualDiffer`, ships in SYNC-5) walks every field except an ignore\n * list; CDC-aware differs can skip comparison for fields the provider didn't\n * flag as changed.\n *\n * `FieldDiffSchema` is the structural enforcement of the `changed_fields`\n * column per ADR-0003 — enforced at write time by the recorder service so\n * consumers can rely on the shape in downstream queries.\n */\nimport { z } from 'zod';\n\n// ============================================================================\n// FieldDiff shape — the ADR-0003 contract\n// ============================================================================\n\n/**\n * Structured per-field change. Enforced shape for `integration_run_items.changed_fields`.\n *\n * `created` items set `from: null, to: <value>` for every non-null field.\n * `deleted` items set `from: <value>, to: null`.\n * `noop` items carry `{}`.\n */\nexport const FieldDiffValueSchema = z.object({\n from: z.unknown(),\n to: z.unknown(),\n});\n\nexport const FieldDiffSchema = z.record(z.string(), FieldDiffValueSchema);\n\nexport type FieldDiffValue = z.infer<typeof FieldDiffValueSchema>;\nexport type FieldDiff = z.infer<typeof FieldDiffSchema>;\n\n/** Result of comparing a new record against its existing local state. */\nexport type DiffResult = FieldDiff | 'noop';\n\n// ============================================================================\n// IFieldDiffer\n// ============================================================================\n\n/**\n * Pluggable differ. Default ships in SYNC-5 as `DeepEqualDiffer<T>` —\n * deep-equal over every field except an ignore list (`updated_at` and other\n * row metadata). CDC-aware differs restrict comparison to\n * `providerChangedFields` when supplied.\n */\nexport interface IFieldDiffer<T> {\n /**\n * @param existing — current local state, or `null` when the record is new\n * @param incoming — the canonical record coming from the adapter\n * @param providerChangedFields — optional hint from CDC-capable sources;\n * when present, differ may restrict the comparison to these fields\n */\n diff(\n existing: T | null,\n incoming: T,\n providerChangedFields?: string[],\n ): DiffResult;\n}\n","/**\n * Integration subsystem — DI tokens\n *\n * String constants (not Symbols) so they match by value across import\n * boundaries — same convention as the events subsystem (`EVENT_BUS`). The\n * jobs subsystem uses Symbols for its analogous tokens; events and integration\n * stay internally consistent with strings.\n *\n * Usage in use cases:\n * ```ts\n * constructor(\n * @Inject(INTEGRATION_CHANGE_SOURCE) private readonly source: IChangeSource<CanonicalOpportunity>,\n * @Inject(INTEGRATION_CURSOR_STORE) private readonly cursors: ICursorStore,\n * @Inject(INTEGRATION_FIELD_DIFFER) private readonly differ: IFieldDiffer<CanonicalOpportunity>,\n * @Inject(INTEGRATION_SINK) private readonly sink: IIntegrationSink<CanonicalOpportunity>,\n * @Inject(INTEGRATION_RUN_RECORDER) private readonly recorder: IIntegrationRunRecorder,\n * ) {}\n * ```\n *\n * Concrete bindings are registered by `IntegrationModule.forRoot(...)` (SYNC-6).\n */\n\nexport const INTEGRATION_CHANGE_SOURCE = 'INTEGRATION_CHANGE_SOURCE' as const;\nexport const INTEGRATION_CURSOR_STORE = 'INTEGRATION_CURSOR_STORE' as const;\nexport const INTEGRATION_FIELD_DIFFER = 'INTEGRATION_FIELD_DIFFER' as const;\nexport const INTEGRATION_SINK = 'INTEGRATION_SINK' as const;\n\n/**\n * Run-recorder token (SYNC-5). Backed by `IIntegrationRunRecorder`. Drizzle impl\n * lands in SYNC-4; tests provide inline fakes.\n */\nexport const INTEGRATION_RUN_RECORDER = 'INTEGRATION_RUN_RECORDER' as const;\n\n/**\n * Injection token for the resolved `IntegrationModuleOptions` object (SYNC-6).\n *\n * Backends that need to observe module configuration (e.g. `multiTenant`\n * flag, pool filters) inject via this token. Provided automatically by\n * `IntegrationModule.forRoot(...)` / `IntegrationModule.forRootAsync(...)`.\n */\nexport const INTEGRATION_MODULE_OPTIONS = 'INTEGRATION_MODULE_OPTIONS' as const;\n\n/**\n * Injection token for the resolved multi-tenancy flag (SYNC-6).\n *\n * Provided by `IntegrationModule.forRoot(...)` as `options.multiTenant ?? false`.\n * Consumed by `ExecuteIntegrationUseCase` to enforce the tenantId-is-required rule.\n */\nexport const INTEGRATION_MULTI_TENANT = 'INTEGRATION_MULTI_TENANT' as const;\n\n/**\n * Injection token for the entity-keyed `IEntityChangeSourceRegistry` (C7,\n * #336). Bound to the codegen-emitted aggregator that folds per-provider\n * adapter contributions into one registry (RFC-0001 §3, emitted by Track D\n * D3/D4).\n *\n * A string constant, not `Symbol.for(...)`, to match this subsystem's token\n * convention (see file header). The originating issue's code block proposed a\n * `Symbol.for('@pattern-stack/codegen.entity-change-source-registry')` key,\n * predating the sync→integration consolidation onto string tokens; kept as a\n * string here for internal consistency with the other INTEGRATION_* tokens.\n */\nexport const ENTITY_CHANGE_SOURCE_REGISTRY = 'ENTITY_CHANGE_SOURCE_REGISTRY' as const;\n","/**\n * Typed errors + shared boundary helpers for the integration subsystem.\n *\n * Classes (not bare Error) so consumers can `instanceof` them in catch\n * blocks and exception filters can map them to HTTP codes.\n *\n * Mirrors the shape of `events-errors.ts` and `jobs-errors.ts`.\n */\n\n/**\n * Thrown by the Drizzle cursor-store / run-recorder backends AND by the\n * orchestrator entry point when `INTEGRATION_MULTI_TENANT` is enabled but the\n * caller did not supply a non-null `tenantId`. Strict enforcement at the\n * boundary — explicit `null` still throws.\n *\n * Disable multi-tenancy on the module (`multiTenant: false`, the default)\n * to opt out of the requirement entirely.\n *\n * `operation` identifies the call site (e.g. `'cursor.put'`,\n * `'startRun'`, `'execute'`) so the stack-trace message points at the\n * specific boundary that rejected the input.\n */\nexport class MissingTenantIdError extends Error {\n override readonly name = 'MissingTenantIdError';\n constructor(operation: string) {\n super(\n `Missing tenantId for integration operation '${operation}'. IntegrationModule is ` +\n `configured with multiTenant: true — every call must include a ` +\n `non-null tenantId. Either pass the tenantId or disable multi-` +\n `tenancy on the module.`,\n );\n }\n}\n\n/**\n * Shared boundary guard — used at the orchestrator entry AND inside the\n * Drizzle backends. Keeping the check in one function guarantees every\n * `MissingTenantIdError` carries the same message shape regardless of the\n * site that raised it, which makes it easier for consumers to pattern-\n * match on the error in logs/metrics.\n *\n * When `multiTenant` is false, the function is a no-op — `tenantId` may\n * be anything (including `undefined`). When true, `undefined` or `null`\n * throws.\n */\nexport function assertTenantId(\n tenantId: string | null | undefined,\n options: { multiTenant: boolean; operation: string },\n): asserts tenantId is string {\n if (!options.multiTenant) return;\n if (tenantId === undefined || tenantId === null) {\n throw new MissingTenantIdError(options.operation);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA6BA,SAAS,QAAQ,YAAY,gBAAgB;AAC7C,SAAS,KAAK,MAAM,UAAoB;;;AChBjC,IAAM,UAAU;;;ACyBvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcA,IAAM,8BAA8B,OAAO,6BAA6B;AAAA,EAC7E;AAAA,EACA;AACF,CAAC;AAOM,IAAM,2BAA2B,OAAO,0BAA0B;AAAA,EACvE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAWM,IAAM,2BAA2B,OAAO,0BAA0B;AAAA,EACvE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAM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AAM;AAAA,MACd,cAAc,MAAM;AAAA,MACpB,kBAAkB,MAAM;AAAA,MACxB,aAAa,MAAM,eAAe;AAAA,MAClC,YAAY,MAAM;AAAA,MAClB,OAAO,MAAM,SAAS;AAAA,MACtB,aAAa,oBAAI,KAAK;AAAA,IACxB,CAAC,EACA,MAAM,GAAG,gBAAgB,IAAI,KAAK,CAAC;AAAA,EACxC;AACF;AAxIa,gCAAN;AAAA,EADN,WAAW;AAAA,EAKP,0BAAO,OAAO;AAAA,EACd,4BAAS;AAAA,EAAG,0BAAO,wBAAwB;AAAA,GALnC;","names":[]}
@@ -1,27 +1,27 @@
1
- import { ISyncRunRecorder, RecordItemInput, StartRunInput, CompleteRunInput, SyncRunSummary } from './sync-run-recorder.protocol.js';
2
- import './sync-field-diff.protocol.js';
1
+ import { IIntegrationRunRecorder, RecordItemInput, StartRunInput, CompleteRunInput, IntegrationRunSummary } from './integration-run-recorder.protocol.js';
2
+ import './integration-field-diff.protocol.js';
3
3
  import 'zod';
4
4
 
5
5
  /**
6
6
  * Optional per-subscription metadata a test can seed on the memory backend
7
- * so `listRecent` can surface `integrationId`. The memory recorder's write
7
+ * so `listRecent` can surface `connectionId`. The memory recorder's write
8
8
  * path never persists subscription rows (it only stores runs + items), so
9
- * `listRecent` has no way to derive `integrationId` on its own. Tests that
9
+ * `listRecent` has no way to derive `connectionId` on its own. Tests that
10
10
  * care about the field should populate `subscriptions` before calling
11
11
  * `listRecent`; calls that don't seed get an empty string and a stable
12
12
  * shape (see `listRecent` below).
13
13
  */
14
- interface MemorySyncSubscription {
15
- integrationId: string;
14
+ interface MemoryIntegrationSubscription {
15
+ connectionId: string;
16
16
  adapter: string;
17
17
  domain: string;
18
18
  externalRef: string | null;
19
- lastSyncAt?: Date | null;
19
+ lastIntegrationAt?: Date | null;
20
20
  updatedAt: Date;
21
21
  }
22
22
  /**
23
23
  * Concrete run row as held in memory. Shape mirrors the interesting
24
- * columns on `sync_runs` so assertions read like DB queries.
24
+ * columns on `integration_runs` so assertions read like DB queries.
25
25
  */
26
26
  interface MemoryRunRecord {
27
27
  id: string;
@@ -39,32 +39,32 @@ interface MemoryRunRecord {
39
39
  startedAt: Date;
40
40
  completedAt: Date | null;
41
41
  }
42
- declare class MemoryRunRecorder implements ISyncRunRecorder {
42
+ declare class MemoryRunRecorder implements IIntegrationRunRecorder {
43
43
  /**
44
44
  * All started runs keyed by id. Public so tests can inspect lifecycle
45
45
  * transitions without poking through recording methods.
46
46
  */
47
47
  readonly runs: Map<string, MemoryRunRecord>;
48
48
  /**
49
- * Items keyed by `sync_run_id`, array order matches insertion order —
50
- * mirrors the timeline the `(sync_run_id, created_at)` index produces
49
+ * Items keyed by `integration_run_id`, array order matches insertion order —
50
+ * mirrors the timeline the `(integration_run_id, created_at)` index produces
51
51
  * in Postgres.
52
52
  */
53
53
  readonly items: Map<string, RecordItemInput[]>;
54
54
  /**
55
55
  * Seedable subscription metadata — tests populate this to make
56
- * `listRecent` return meaningful `integrationId` values. The memory
56
+ * `listRecent` return meaningful `connectionId` values. The memory
57
57
  * backend doesn't track subscriptions on its own (only runs + items), so
58
58
  * this map is the intentional extension point: tests write entries for
59
59
  * the subscription ids they use, production code never touches it.
60
60
  */
61
- readonly subscriptions: Map<string, MemorySyncSubscription>;
61
+ readonly subscriptions: Map<string, MemoryIntegrationSubscription>;
62
62
  startRun(input: StartRunInput): Promise<{
63
63
  id: string;
64
64
  }>;
65
65
  recordItem(input: RecordItemInput): Promise<void>;
66
66
  completeRun(runId: string, input: CompleteRunInput): Promise<void>;
67
- listRecent(limit: number, subscriptionId?: string, _tenantId?: string | null): Promise<SyncRunSummary[]>;
67
+ listRecent(limit: number, subscriptionId?: string, _tenantId?: string | null): Promise<IntegrationRunSummary[]>;
68
68
  /** Reset state. Tests call this in `beforeEach`. */
69
69
  clear(): void;
70
70
  /** All runs for a subscription, newest first. Timeline reads. */
@@ -73,4 +73,4 @@ declare class MemoryRunRecorder implements ISyncRunRecorder {
73
73
  getItemsForRun(runId: string): RecordItemInput[];
74
74
  }
75
75
 
76
- export { type MemoryRunRecord, MemoryRunRecorder, type MemorySyncSubscription };
76
+ export { type MemoryIntegrationSubscription, type MemoryRunRecord, MemoryRunRecorder };
@@ -9,10 +9,10 @@ var __decorateClass = (decorators, target, key, kind) => {
9
9
  return result;
10
10
  };
11
11
 
12
- // runtime/subsystems/sync/sync-run-recorder.memory-backend.ts
12
+ // runtime/subsystems/integration/integration-run-recorder.memory-backend.ts
13
13
  import { Injectable } from "@nestjs/common";
14
14
 
15
- // runtime/subsystems/sync/sync-field-diff.protocol.ts
15
+ // runtime/subsystems/integration/integration-field-diff.protocol.ts
16
16
  import { z } from "zod";
17
17
  var FieldDiffValueSchema = z.object({
18
18
  from: z.unknown(),
@@ -20,7 +20,7 @@ var FieldDiffValueSchema = z.object({
20
20
  });
21
21
  var FieldDiffSchema = z.record(z.string(), FieldDiffValueSchema);
22
22
 
23
- // runtime/subsystems/sync/sync-run-recorder.memory-backend.ts
23
+ // runtime/subsystems/integration/integration-run-recorder.memory-backend.ts
24
24
  var MemoryRunRecorder = class {
25
25
  /**
26
26
  * All started runs keyed by id. Public so tests can inspect lifecycle
@@ -28,14 +28,14 @@ var MemoryRunRecorder = class {
28
28
  */
29
29
  runs = /* @__PURE__ */ new Map();
30
30
  /**
31
- * Items keyed by `sync_run_id`, array order matches insertion order —
32
- * mirrors the timeline the `(sync_run_id, created_at)` index produces
31
+ * Items keyed by `integration_run_id`, array order matches insertion order —
32
+ * mirrors the timeline the `(integration_run_id, created_at)` index produces
33
33
  * in Postgres.
34
34
  */
35
35
  items = /* @__PURE__ */ new Map();
36
36
  /**
37
37
  * Seedable subscription metadata — tests populate this to make
38
- * `listRecent` return meaningful `integrationId` values. The memory
38
+ * `listRecent` return meaningful `connectionId` values. The memory
39
39
  * backend doesn't track subscriptions on its own (only runs + items), so
40
40
  * this map is the intentional extension point: tests write entries for
41
41
  * the subscription ids they use, production code never touches it.
@@ -64,10 +64,10 @@ var MemoryRunRecorder = class {
64
64
  }
65
65
  async recordItem(input) {
66
66
  FieldDiffSchema.parse(input.changedFields);
67
- const bucket = this.items.get(input.syncRunId);
67
+ const bucket = this.items.get(input.integrationRunId);
68
68
  if (!bucket) {
69
69
  throw new Error(
70
- `MemoryRunRecorder.recordItem: no run started for id '${input.syncRunId}'. Call startRun(...) first.`
70
+ `MemoryRunRecorder.recordItem: no run started for id '${input.integrationRunId}'. Call startRun(...) first.`
71
71
  );
72
72
  }
73
73
  bucket.push(input);
@@ -93,10 +93,10 @@ var MemoryRunRecorder = class {
93
93
  return filtered.sort((a, b) => b.startedAt.getTime() - a.startedAt.getTime()).slice(0, limit).map((r) => ({
94
94
  id: r.id,
95
95
  subscriptionId: r.subscriptionId,
96
- // integrationId is only knowable if the test seeded subscriptions
96
+ // connectionId is only knowable if the test seeded subscriptions
97
97
  // metadata; empty string otherwise. The Drizzle backend resolves
98
98
  // it via JOIN, which is the production path.
99
- integrationId: this.subscriptions.get(r.subscriptionId)?.integrationId ?? "",
99
+ connectionId: this.subscriptions.get(r.subscriptionId)?.connectionId ?? "",
100
100
  status: r.status,
101
101
  startedAt: r.startedAt,
102
102
  completedAt: r.completedAt,
@@ -126,4 +126,4 @@ MemoryRunRecorder = __decorateClass([
126
126
  export {
127
127
  MemoryRunRecorder
128
128
  };
129
- //# sourceMappingURL=sync-run-recorder.memory-backend.js.map
129
+ //# sourceMappingURL=integration-run-recorder.memory-backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../runtime/subsystems/integration/integration-run-recorder.memory-backend.ts","../../../../runtime/subsystems/integration/integration-field-diff.protocol.ts"],"sourcesContent":["/**\n * MemoryRunRecorder — in-memory backend for `IIntegrationRunRecorder` (SYNC-6).\n *\n * Test double so `IntegrationModule.forRoot({ backend: 'memory' })` is genuinely\n * end-to-end runnable without Postgres. Mirrors the role of\n * `MemoryCursorStore`: plain keyed state, `clear()` helper for\n * `beforeEach` resets, public inspection surface so tests can assert on\n * the recorded run + item timeline without scraping logs.\n *\n * Validates `changedFields` through `FieldDiffSchema.parse` on every\n * `recordItem` call — same ADR-0003 contract as the Drizzle backend. An\n * in-memory recorder that skipped the validation would be a silently\n * weaker contract than production.\n *\n * `startRun` generates a uuid via `crypto.randomUUID()` (Node 19+ / Bun).\n * We don't import `uuid` because the subsystem has no other use for it.\n *\n * ## Multi-tenancy\n *\n * `tenantId` is accepted (and recorded on the in-memory row so tests can\n * assert it) but enforcement lives at the module boundary. The memory\n * backend intentionally does not throw on missing `tenantId` — that's\n * the orchestrator's job when `multiTenant=true` (SYNC-6). A permissive\n * memory recorder lets tests exercise error paths where the orchestrator\n * short-circuits before ever reaching the recorder.\n */\nimport { Injectable } from '@nestjs/common';\nimport type {\n CompleteRunInput,\n IIntegrationRunRecorder,\n RecordItemInput,\n StartRunInput,\n IntegrationRunSummary,\n} from './integration-run-recorder.protocol';\nimport { FieldDiffSchema } from './integration-field-diff.protocol';\n\n/**\n * Optional per-subscription metadata a test can seed on the memory backend\n * so `listRecent` can surface `connectionId`. The memory recorder's write\n * path never persists subscription rows (it only stores runs + items), so\n * `listRecent` has no way to derive `connectionId` on its own. Tests that\n * care about the field should populate `subscriptions` before calling\n * `listRecent`; calls that don't seed get an empty string and a stable\n * shape (see `listRecent` below).\n */\nexport interface MemoryIntegrationSubscription {\n connectionId: string;\n adapter: string;\n domain: string;\n externalRef: string | null;\n lastIntegrationAt?: Date | null;\n updatedAt: Date;\n}\n\n/**\n * Concrete run row as held in memory. Shape mirrors the interesting\n * columns on `integration_runs` so assertions read like DB queries.\n */\nexport interface MemoryRunRecord {\n id: string;\n subscriptionId: string;\n direction: 'inbound' | 'outbound';\n action: 'poll' | 'cdc' | 'webhook' | 'manual' | 'writeback';\n status: 'running' | 'success' | 'no_changes' | 'failed';\n cursorBefore: unknown | null;\n cursorAfter: unknown | null;\n recordsFound: number;\n recordsProcessed: number;\n durationMs: number | null;\n error: string | null;\n tenantId: string | null;\n startedAt: Date;\n completedAt: Date | null;\n}\n\n@Injectable()\nexport class MemoryRunRecorder implements IIntegrationRunRecorder {\n /**\n * All started runs keyed by id. Public so tests can inspect lifecycle\n * transitions without poking through recording methods.\n */\n readonly runs: Map<string, MemoryRunRecord> = new Map();\n\n /**\n * Items keyed by `integration_run_id`, array order matches insertion order —\n * mirrors the timeline the `(integration_run_id, created_at)` index produces\n * in Postgres.\n */\n readonly items: Map<string, RecordItemInput[]> = new Map();\n\n /**\n * Seedable subscription metadata — tests populate this to make\n * `listRecent` return meaningful `connectionId` values. The memory\n * backend doesn't track subscriptions on its own (only runs + items), so\n * this map is the intentional extension point: tests write entries for\n * the subscription ids they use, production code never touches it.\n */\n readonly subscriptions: Map<string, MemoryIntegrationSubscription> = new Map();\n\n async startRun(input: StartRunInput): Promise<{ id: string }> {\n const id = crypto.randomUUID();\n this.runs.set(id, {\n id,\n subscriptionId: input.subscriptionId,\n direction: input.direction,\n action: input.action,\n status: 'running',\n cursorBefore: input.cursorBefore ?? null,\n cursorAfter: null,\n recordsFound: 0,\n recordsProcessed: 0,\n durationMs: null,\n error: null,\n tenantId: input.tenantId ?? null,\n startedAt: new Date(),\n completedAt: null,\n });\n this.items.set(id, []);\n return { id };\n }\n\n async recordItem(input: RecordItemInput): Promise<void> {\n // Same ADR-0003 contract as the Drizzle backend.\n FieldDiffSchema.parse(input.changedFields);\n\n const bucket = this.items.get(input.integrationRunId);\n if (!bucket) {\n throw new Error(\n `MemoryRunRecorder.recordItem: no run started for id '${input.integrationRunId}'. ` +\n `Call startRun(...) first.`,\n );\n }\n bucket.push(input);\n }\n\n async completeRun(runId: string, input: CompleteRunInput): Promise<void> {\n const run = this.runs.get(runId);\n if (!run) {\n throw new Error(\n `MemoryRunRecorder.completeRun: no run started for id '${runId}'.`,\n );\n }\n run.status = input.status;\n run.recordsFound = input.recordsFound;\n run.recordsProcessed = input.recordsProcessed;\n run.cursorAfter = input.cursorAfter ?? null;\n run.durationMs = input.durationMs;\n run.error = input.error ?? null;\n run.completedAt = new Date();\n }\n\n async listRecent(\n limit: number,\n subscriptionId?: string,\n _tenantId?: string | null,\n ): Promise<IntegrationRunSummary[]> {\n // Memory backend accepts tenantId for contract symmetry but does not\n // filter on it — state is process-local and cross-tenant isolation is\n // not meaningful here (matches MemoryCursorStore behavior).\n const all = Array.from(this.runs.values());\n const filtered =\n subscriptionId === undefined\n ? all\n : all.filter((r) => r.subscriptionId === subscriptionId);\n return filtered\n .sort((a, b) => b.startedAt.getTime() - a.startedAt.getTime())\n .slice(0, limit)\n .map((r) => ({\n id: r.id,\n subscriptionId: r.subscriptionId,\n // connectionId is only knowable if the test seeded subscriptions\n // metadata; empty string otherwise. The Drizzle backend resolves\n // it via JOIN, which is the production path.\n connectionId:\n this.subscriptions.get(r.subscriptionId)?.connectionId ?? '',\n status: r.status,\n startedAt: r.startedAt,\n completedAt: r.completedAt,\n recordsProcessed: r.recordsProcessed,\n tenantId: r.tenantId,\n }));\n }\n\n /** Reset state. Tests call this in `beforeEach`. */\n clear(): void {\n this.runs.clear();\n this.items.clear();\n this.subscriptions.clear();\n }\n\n // ─── test ergonomics ─────────────────────────────────────────────────\n\n /** All runs for a subscription, newest first. Timeline reads. */\n getRunsForSubscription(subscriptionId: string): MemoryRunRecord[] {\n return Array.from(this.runs.values())\n .filter((r) => r.subscriptionId === subscriptionId)\n .sort((a, b) => b.startedAt.getTime() - a.startedAt.getTime());\n }\n\n /** All item rows for a run, insertion-ordered. */\n getItemsForRun(runId: string): RecordItemInput[] {\n return this.items.get(runId) ?? [];\n }\n}\n","/**\n * Integration subsystem — field-diff protocol (port)\n *\n * `IFieldDiffer<T>` is the pluggable differ seam. The default implementation\n * (`DeepEqualDiffer`, ships in SYNC-5) walks every field except an ignore\n * list; CDC-aware differs can skip comparison for fields the provider didn't\n * flag as changed.\n *\n * `FieldDiffSchema` is the structural enforcement of the `changed_fields`\n * column per ADR-0003 — enforced at write time by the recorder service so\n * consumers can rely on the shape in downstream queries.\n */\nimport { z } from 'zod';\n\n// ============================================================================\n// FieldDiff shape — the ADR-0003 contract\n// ============================================================================\n\n/**\n * Structured per-field change. Enforced shape for `integration_run_items.changed_fields`.\n *\n * `created` items set `from: null, to: <value>` for every non-null field.\n * `deleted` items set `from: <value>, to: null`.\n * `noop` items carry `{}`.\n */\nexport const FieldDiffValueSchema = z.object({\n from: z.unknown(),\n to: z.unknown(),\n});\n\nexport const FieldDiffSchema = z.record(z.string(), FieldDiffValueSchema);\n\nexport type FieldDiffValue = z.infer<typeof FieldDiffValueSchema>;\nexport type FieldDiff = z.infer<typeof FieldDiffSchema>;\n\n/** Result of comparing a new record against its existing local state. */\nexport type DiffResult = FieldDiff | 'noop';\n\n// ============================================================================\n// IFieldDiffer\n// ============================================================================\n\n/**\n * Pluggable differ. Default ships in SYNC-5 as `DeepEqualDiffer<T>` —\n * deep-equal over every field except an ignore list (`updated_at` and other\n * row metadata). CDC-aware differs restrict comparison to\n * `providerChangedFields` when supplied.\n */\nexport interface IFieldDiffer<T> {\n /**\n * @param existing — current local state, or `null` when the record is new\n * @param incoming — the canonical record coming from the adapter\n * @param providerChangedFields — optional hint from CDC-capable sources;\n * when present, differ may restrict the comparison to these fields\n */\n diff(\n existing: T | null,\n incoming: T,\n providerChangedFields?: string[],\n ): DiffResult;\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,SAAS,kBAAkB;;;ACd3B,SAAS,SAAS;AAaX,IAAM,uBAAuB,EAAE,OAAO;AAAA,EAC3C,MAAM,EAAE,QAAQ;AAAA,EAChB,IAAI,EAAE,QAAQ;AAChB,CAAC;AAEM,IAAM,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,oBAAoB;;;AD8CjE,IAAM,oBAAN,MAA2D;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,OAAqC,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,QAAwC,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAShD,gBAA4D,oBAAI,IAAI;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,mBAAmB,SACf,MACA,IAAI,OAAO,CAAC,MAAM,EAAE,mBAAmB,cAAc;AAC3D,WAAO,SACJ,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,QAAQ,IAAI,EAAE,UAAU,QAAQ,CAAC,EAC5D,MAAM,GAAG,KAAK,EACd,IAAI,CAAC,OAAO;AAAA,MACX,IAAI,EAAE;AAAA,MACN,gBAAgB,EAAE;AAAA;AAAA;AAAA;AAAA,MAIlB,cACE,KAAK,cAAc,IAAI,EAAE,cAAc,GAAG,gBAAgB;AAAA,MAC5D,QAAQ,EAAE;AAAA,MACV,WAAW,EAAE;AAAA,MACb,aAAa,EAAE;AAAA,MACf,kBAAkB,EAAE;AAAA,MACpB,UAAU,EAAE;AAAA,IACd,EAAE;AAAA,EACN;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,KAAK,MAAM;AAChB,SAAK,MAAM,MAAM;AACjB,SAAK,cAAc,MAAM;AAAA,EAC3B;AAAA;AAAA;AAAA,EAKA,uBAAuB,gBAA2C;AAChE,WAAO,MAAM,KAAK,KAAK,KAAK,OAAO,CAAC,EACjC,OAAO,CAAC,MAAM,EAAE,mBAAmB,cAAc,EACjD,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,QAAQ,IAAI,EAAE,UAAU,QAAQ,CAAC;AAAA,EACjE;AAAA;AAAA,EAGA,eAAe,OAAkC;AAC/C,WAAO,KAAK,MAAM,IAAI,KAAK,KAAK,CAAC;AAAA,EACnC;AACF;AA/Ha,oBAAN;AAAA,EADN,WAAW;AAAA,GACC;","names":[]}
@@ -1,15 +1,15 @@
1
- import { FieldDiff } from './sync-field-diff.protocol.js';
1
+ import { FieldDiff } from './integration-field-diff.protocol.js';
2
2
  import 'zod';
3
3
 
4
4
  /**
5
- * Sync subsystem — run-recorder protocol (port)
5
+ * Integration subsystem — run-recorder protocol (port)
6
6
  *
7
- * `ISyncRunRecorder` is the write side of the audit log. `ExecuteSyncUseCase`
7
+ * `IIntegrationRunRecorder` is the write side of the audit log. `ExecuteIntegrationUseCase`
8
8
  * (SYNC-5) calls `startRun` at the top of the loop, `recordItem` for each
9
9
  * processed change, and `completeRun` in a `finally` block so a run always
10
10
  * reaches a terminal status.
11
11
  *
12
- * The Drizzle backend (SYNC-4) persists against `sync_runs` / `sync_run_items`
12
+ * The Drizzle backend (SYNC-4) persists against `integration_runs` / `integration_run_items`
13
13
  * from the SYNC-1 schema. Tests use lightweight in-memory fakes — no
14
14
  * dedicated memory backend ships; the surface is small enough that inline
15
15
  * fakes keep the intent local to each spec.
@@ -21,7 +21,7 @@ import 'zod';
21
21
  * always a `FieldDiff`.
22
22
  */
23
23
 
24
- /** Args for `startRun`. Mirrors the non-nullable columns on `sync_runs`. */
24
+ /** Args for `startRun`. Mirrors the non-nullable columns on `integration_runs`. */
25
25
  interface StartRunInput {
26
26
  readonly subscriptionId: string;
27
27
  readonly direction: 'inbound' | 'outbound';
@@ -29,15 +29,15 @@ interface StartRunInput {
29
29
  /** Cursor snapshot at run start, or `null` if this is the first run. */
30
30
  readonly cursorBefore: unknown | null;
31
31
  /**
32
- * Tenant id when `SYNC_MULTI_TENANT` is enabled. The recorder's own
32
+ * Tenant id when `INTEGRATION_MULTI_TENANT` is enabled. The recorder's own
33
33
  * boundary rule (SYNC-6) enforces non-null when the flag is on;
34
- * orchestrator passes it through from `ExecuteSyncInput.tenantId`.
34
+ * orchestrator passes it through from `ExecuteIntegrationInput.tenantId`.
35
35
  */
36
36
  readonly tenantId?: string | null;
37
37
  }
38
- /** Args for `recordItem`. Mirrors the non-nullable columns on `sync_run_items`. */
38
+ /** Args for `recordItem`. Mirrors the non-nullable columns on `integration_run_items`. */
39
39
  interface RecordItemInput {
40
- readonly syncRunId: string;
40
+ readonly integrationRunId: string;
41
41
  readonly entityType: string;
42
42
  readonly externalId: string;
43
43
  readonly localId?: string | null;
@@ -62,36 +62,36 @@ interface CompleteRunInput {
62
62
  readonly error?: string | null;
63
63
  }
64
64
  /**
65
- * Denormalized view of one `sync_runs` row, JOINed against
66
- * `sync_subscriptions` to surface `integrationId` in a single read. Consumed
65
+ * Denormalized view of one `integration_runs` row, JOINed against
66
+ * `integration_subscriptions` to surface `connectionId` in a single read. Consumed
67
67
  * by the OBS-5 observability composer (epic #195).
68
68
  *
69
- * `recordsProcessed` is the denormalized column on `sync_runs` — it does NOT
70
- * count `sync_run_items` rows. A correlated subquery per run would be
69
+ * `recordsProcessed` is the denormalized column on `integration_runs` — it does NOT
70
+ * count `integration_run_items` rows. A correlated subquery per run would be
71
71
  * required for a true item count; deferred as a follow-up if needed.
72
72
  *
73
- * Memory backends can't know `integrationId` without subscription metadata
73
+ * Memory backends can't know `connectionId` without subscription metadata
74
74
  * — see each memory backend for the seedable `subscriptions` side-map that
75
75
  * tests populate. When metadata is missing, memory backends emit an empty
76
76
  * string so the shape stays stable (documented in the memory backend).
77
77
  */
78
- interface SyncRunSummary {
78
+ interface IntegrationRunSummary {
79
79
  readonly id: string;
80
80
  readonly subscriptionId: string;
81
81
  /** Resolved by Drizzle via JOIN; empty string from memory if not seeded. */
82
- readonly integrationId: string;
82
+ readonly connectionId: string;
83
83
  readonly status: 'running' | 'success' | 'no_changes' | 'failed';
84
84
  readonly startedAt: Date;
85
85
  readonly completedAt: Date | null;
86
86
  readonly recordsProcessed: number;
87
87
  readonly tenantId: string | null;
88
88
  }
89
- interface ISyncRunRecorder {
90
- /** Opens a new `sync_runs` row in `status = 'running'`. Returns the run id. */
89
+ interface IIntegrationRunRecorder {
90
+ /** Opens a new `integration_runs` row in `status = 'running'`. Returns the run id. */
91
91
  startRun(input: StartRunInput): Promise<{
92
92
  id: string;
93
93
  }>;
94
- /** Appends one `sync_run_items` row. Throws if `changedFields` is malformed. */
94
+ /** Appends one `integration_run_items` row. Throws if `changedFields` is malformed. */
95
95
  recordItem(input: RecordItemInput): Promise<void>;
96
96
  /**
97
97
  * Finalizes the run. Must be called from a `finally` block so an in-flight
@@ -100,20 +100,20 @@ interface ISyncRunRecorder {
100
100
  */
101
101
  completeRun(runId: string, input: CompleteRunInput): Promise<void>;
102
102
  /**
103
- * Recent `sync_runs` rows ordered by `started_at DESC`, capped at `limit`.
103
+ * Recent `integration_runs` rows ordered by `started_at DESC`, capped at `limit`.
104
104
  *
105
- * Filter is `subscriptionId` — the natural FK on `sync_runs`. An
106
- * integration-wide view requires filtering on `sync_subscriptions.integration_id`
105
+ * Filter is `subscriptionId` — the natural FK on `integration_runs`. An
106
+ * integration-wide view requires filtering on `integration_subscriptions.connection_id`
107
107
  * through the JOIN and is deferred as a follow-up (epic #195 OBS-4 spec).
108
108
  *
109
109
  * @param limit hard cap on rows returned (no implicit default)
110
110
  * @param subscriptionId optional FK filter; omit for cross-subscription view
111
111
  * @param tenantId required by Drizzle backend when
112
- * `SYNC_MULTI_TENANT` is on (throws
112
+ * `INTEGRATION_MULTI_TENANT` is on (throws
113
113
  * `MissingTenantIdError` otherwise); memory backend
114
114
  * accepts but ignores
115
115
  */
116
- listRecent(limit: number, subscriptionId?: string, tenantId?: string | null): Promise<SyncRunSummary[]>;
116
+ listRecent(limit: number, subscriptionId?: string, tenantId?: string | null): Promise<IntegrationRunSummary[]>;
117
117
  }
118
118
 
119
- export type { CompleteRunInput, ISyncRunRecorder, RecordItemInput, StartRunInput, SyncRunSummary };
119
+ export type { CompleteRunInput, IIntegrationRunRecorder, IntegrationRunSummary, RecordItemInput, StartRunInput };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=integration-run-recorder.protocol.js.map
@@ -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
- interface ISyncSink<TCanonical> {
16
+ 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.
@@ -28,11 +28,11 @@ interface ISyncSink<TCanonical> {
28
28
  * - tolerate re-entry (same record twice in a window = no-op)
29
29
  *
30
30
  * Returns the local row id and the canonical projection of the saved row
31
- * (so the orchestrator can record it on `sync_run_items.local_id`).
31
+ * (so the orchestrator can record it on `integration_run_items.local_id`).
32
32
  *
33
33
  * `provider` is the adapter domain string (e.g. `'salesforce-crm'`,
34
34
  * `'hubspot-crm'`) persisted on the DB row. Passed from
35
- * `ExecuteSyncInput.provider`.
35
+ * `ExecuteIntegrationInput.provider`.
36
36
  */
37
37
  upsertByExternalId(userId: string, record: TCanonical, provider: string): Promise<{
38
38
  id: string;
@@ -53,4 +53,4 @@ interface ISyncSink<TCanonical> {
53
53
  readonly reprojectsOnNoop?: boolean;
54
54
  }
55
55
 
56
- export type { ISyncSink };
56
+ export type { IIntegrationSink };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=integration-sink.protocol.js.map
@@ -1,33 +1,33 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
2
 
3
3
  /**
4
- * SyncModule — `DynamicModule.forRoot({ backend, multiTenant? })` factory
5
- * wiring the sync subsystem's substrate (SYNC-6, ADR-008 subsystem pattern).
4
+ * IntegrationModule — `DynamicModule.forRoot({ backend, multiTenant? })` factory
5
+ * wiring the integration subsystem's substrate (SYNC-6, ADR-008 subsystem pattern).
6
6
  *
7
7
  * ## What this module provides
8
8
  *
9
- * - `SYNC_CURSOR_STORE` — Drizzle or Memory cursor store
10
- * - `SYNC_RUN_RECORDER` — Drizzle or Memory run recorder
11
- * - `SYNC_FIELD_DIFFER` — default `DeepEqualDiffer`
12
- * - `SYNC_MULTI_TENANT` — resolved boolean flag (defaults to false)
13
- * - `SYNC_MODULE_OPTIONS` — the options object itself, for backends
9
+ * - `INTEGRATION_CURSOR_STORE` — Drizzle or Memory cursor store
10
+ * - `INTEGRATION_RUN_RECORDER` — Drizzle or Memory run recorder
11
+ * - `INTEGRATION_FIELD_DIFFER` — default `DeepEqualDiffer`
12
+ * - `INTEGRATION_MULTI_TENANT` — resolved boolean flag (defaults to false)
13
+ * - `INTEGRATION_MODULE_OPTIONS` — the options object itself, for backends
14
14
  * that need to inspect config at construction time
15
15
  *
16
16
  * ## What this module does NOT provide
17
17
  *
18
- * - `SYNC_CHANGE_SOURCE` — per-provider per-entity; consumer binds in
19
- * their feature module (e.g. `OpportunitySyncModule` provides a
18
+ * - `INTEGRATION_CHANGE_SOURCE` — per-provider per-entity; consumer binds in
19
+ * their feature module (e.g. `OpportunityIntegrationModule` provides a
20
20
  * `SalesforceOpportunityChangeSource`). Loopback suppression — when
21
21
  * needed — is composed into the primitive's middleware chain via
22
22
  * `createLoopbackMiddleware(store)` (#226-5 / ADR-033); the
23
23
  * orchestrator no longer accepts a fingerprint store directly.
24
- * - `SYNC_SINK` — per canonical entity; consumer binds in their feature
24
+ * - `INTEGRATION_SINK` — per canonical entity; consumer binds in their feature
25
25
  * module.
26
- * - `ExecuteSyncUseCase` — registered by the feature module alongside
26
+ * - `ExecuteIntegrationUseCase` — registered by the feature module alongside
27
27
  * its source + sink bindings. Providing the orchestrator here would
28
- * force Nest to resolve SYNC_CHANGE_SOURCE + SYNC_SINK at module
28
+ * force Nest to resolve INTEGRATION_CHANGE_SOURCE + INTEGRATION_SINK at module
29
29
  * compile time, which fails when the feature module hasn't been
30
- * imported yet. Consumers register `ExecuteSyncUseCase` in the same
30
+ * imported yet. Consumers register `ExecuteIntegrationUseCase` in the same
31
31
  * `providers` array as their source + sink so resolution is local
32
32
  * to where all three are bound.
33
33
  *
@@ -40,7 +40,7 @@ import { DynamicModule } from '@nestjs/common';
40
40
  * ```ts
41
41
  * // AppModule — single source of truth for backend + multi-tenancy.
42
42
  * @Module({
43
- * imports: [SyncModule.forRoot({ backend: 'drizzle' })],
43
+ * imports: [IntegrationModule.forRoot({ backend: 'drizzle' })],
44
44
  * })
45
45
  * export class AppModule {}
46
46
  *
@@ -48,23 +48,23 @@ import { DynamicModule } from '@nestjs/common';
48
48
  * // orchestrator for free.
49
49
  * @Module({
50
50
  * providers: [
51
- * { provide: SYNC_CHANGE_SOURCE, useClass: SalesforceOpportunitySource },
52
- * { provide: SYNC_SINK, useClass: OpportunitySyncSink },
53
- * ExecuteSyncUseCase,
51
+ * { provide: INTEGRATION_CHANGE_SOURCE, useClass: SalesforceOpportunitySource },
52
+ * { provide: INTEGRATION_SINK, useClass: OpportunityIntegrationSink },
53
+ * ExecuteIntegrationUseCase,
54
54
  * ],
55
55
  * })
56
- * export class OpportunitySyncModule {
56
+ * export class OpportunityIntegrationModule {
57
57
  * constructor(
58
- * private readonly execute: ExecuteSyncUseCase<CanonicalOpportunity>,
58
+ * private readonly execute: ExecuteIntegrationUseCase<CanonicalOpportunity>,
59
59
  * ) {}
60
60
  * }
61
61
  * ```
62
62
  *
63
63
  * `global: true` means feature modules do not need to re-import
64
- * `SyncModule` — the substrate tokens are available project-wide.
64
+ * `IntegrationModule` — the substrate tokens are available project-wide.
65
65
  */
66
66
 
67
- interface SyncModuleOptions {
67
+ interface IntegrationModuleOptions {
68
68
  /**
69
69
  * Backend selection. `drizzle` wires the Postgres cursor store +
70
70
  * run-log recorder; `memory` wires in-memory doubles suitable for
@@ -89,8 +89,8 @@ interface SyncModuleOptions {
89
89
  */
90
90
  multiTenant?: boolean;
91
91
  }
92
- declare class SyncModule {
93
- static forRoot(options: SyncModuleOptions): DynamicModule;
92
+ declare class IntegrationModule {
93
+ static forRoot(options: IntegrationModuleOptions): DynamicModule;
94
94
  }
95
95
 
96
- export { SyncModule, type SyncModuleOptions };
96
+ export { IntegrationModule, type IntegrationModuleOptions };