@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
@@ -10,7 +10,7 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  };
11
11
  var __decorateParam = (index2, decorator) => (target, key) => decorator(target, key, index2);
12
12
 
13
- // runtime/subsystems/sync/sync-field-diff.protocol.ts
13
+ // runtime/subsystems/integration/integration-field-diff.protocol.ts
14
14
  import { z } from "zod";
15
15
  var FieldDiffValueSchema = z.object({
16
16
  from: z.unknown(),
@@ -18,7 +18,38 @@ var FieldDiffValueSchema = z.object({
18
18
  });
19
19
  var FieldDiffSchema = z.record(z.string(), FieldDiffValueSchema);
20
20
 
21
- // runtime/subsystems/sync/detection-config.schema.ts
21
+ // runtime/subsystems/integration/entity-change-source-registry.protocol.ts
22
+ var UnknownEntityError = class extends Error {
23
+ constructor(entity, available) {
24
+ super(
25
+ `No change source registered for entity '${entity}'. Available: ${available.join(", ")}`
26
+ );
27
+ this.name = "UnknownEntityError";
28
+ }
29
+ };
30
+
31
+ // runtime/subsystems/integration/entity-change-source-registry.memory.ts
32
+ var MemoryEntityChangeSourceRegistry = class {
33
+ constructor(sources) {
34
+ this.sources = sources;
35
+ }
36
+ sources;
37
+ get(name) {
38
+ const source = this.sources.get(name);
39
+ if (!source) {
40
+ throw new UnknownEntityError(name, [...this.sources.keys()]);
41
+ }
42
+ return source;
43
+ }
44
+ has(name) {
45
+ return this.sources.has(name);
46
+ }
47
+ entities() {
48
+ return [...this.sources.keys()];
49
+ }
50
+ };
51
+
52
+ // runtime/subsystems/integration/detection-config.schema.ts
22
53
  import { z as z2 } from "zod";
23
54
  var FieldMappingSchema = z2.object({
24
55
  source: z2.string().min(1),
@@ -76,7 +107,7 @@ var DetectionConfigSchema = z2.discriminatedUnion("mode", [
76
107
  WebhookModeSchema
77
108
  ]);
78
109
 
79
- // runtime/subsystems/sync/loopback.middleware.ts
110
+ // runtime/subsystems/integration/loopback.middleware.ts
80
111
  function createLoopbackMiddleware(store) {
81
112
  return (next) => {
82
113
  return async function* (subscription, cursor) {
@@ -93,7 +124,7 @@ function createLoopbackMiddleware(store) {
93
124
  };
94
125
  }
95
126
 
96
- // runtime/subsystems/sync/poll-change-source.ts
127
+ // runtime/subsystems/integration/poll-change-source.ts
97
128
  var PollChangeSource = class {
98
129
  label;
99
130
  adapter;
@@ -183,7 +214,7 @@ var PollChangeSource = class {
183
214
  }
184
215
  };
185
216
 
186
- // runtime/subsystems/sync/webhook-change-source.ts
217
+ // runtime/subsystems/integration/webhook-change-source.ts
187
218
  var WebhookChangeSource = class {
188
219
  label;
189
220
  queue;
@@ -254,7 +285,7 @@ var WebhookChangeSource = class {
254
285
  }
255
286
  };
256
287
 
257
- // runtime/subsystems/sync/build-change-source.ts
288
+ // runtime/subsystems/integration/build-change-source.ts
258
289
  function buildChangeSource(cfg, fetch, middlewares = []) {
259
290
  switch (cfg.mode) {
260
291
  case "poll":
@@ -272,21 +303,22 @@ function buildChangeSource(cfg, fetch, middlewares = []) {
272
303
  }
273
304
  }
274
305
 
275
- // runtime/subsystems/sync/sync.tokens.ts
276
- var SYNC_CHANGE_SOURCE = "SYNC_CHANGE_SOURCE";
277
- var SYNC_CURSOR_STORE = "SYNC_CURSOR_STORE";
278
- var SYNC_FIELD_DIFFER = "SYNC_FIELD_DIFFER";
279
- var SYNC_SINK = "SYNC_SINK";
280
- var SYNC_RUN_RECORDER = "SYNC_RUN_RECORDER";
281
- var SYNC_MODULE_OPTIONS = "SYNC_MODULE_OPTIONS";
282
- var SYNC_MULTI_TENANT = "SYNC_MULTI_TENANT";
306
+ // runtime/subsystems/integration/integration.tokens.ts
307
+ var INTEGRATION_CHANGE_SOURCE = "INTEGRATION_CHANGE_SOURCE";
308
+ var INTEGRATION_CURSOR_STORE = "INTEGRATION_CURSOR_STORE";
309
+ var INTEGRATION_FIELD_DIFFER = "INTEGRATION_FIELD_DIFFER";
310
+ var INTEGRATION_SINK = "INTEGRATION_SINK";
311
+ var INTEGRATION_RUN_RECORDER = "INTEGRATION_RUN_RECORDER";
312
+ var INTEGRATION_MODULE_OPTIONS = "INTEGRATION_MODULE_OPTIONS";
313
+ var INTEGRATION_MULTI_TENANT = "INTEGRATION_MULTI_TENANT";
314
+ var ENTITY_CHANGE_SOURCE_REGISTRY = "ENTITY_CHANGE_SOURCE_REGISTRY";
283
315
 
284
- // runtime/subsystems/sync/sync-errors.ts
316
+ // runtime/subsystems/integration/integration-errors.ts
285
317
  var MissingTenantIdError = class extends Error {
286
318
  name = "MissingTenantIdError";
287
319
  constructor(operation) {
288
320
  super(
289
- `Missing tenantId for sync operation '${operation}'. SyncModule is configured with multiTenant: true \u2014 every call must include a non-null tenantId. Either pass the tenantId or disable multi-tenancy on the module.`
321
+ `Missing tenantId for integration operation '${operation}'. IntegrationModule is configured with multiTenant: true \u2014 every call must include a non-null tenantId. Either pass the tenantId or disable multi-tenancy on the module.`
290
322
  );
291
323
  }
292
324
  };
@@ -297,7 +329,7 @@ function assertTenantId(tenantId, options) {
297
329
  }
298
330
  }
299
331
 
300
- // runtime/subsystems/sync/sync-audit.schema.ts
332
+ // runtime/subsystems/integration/integration-audit.schema.ts
301
333
  import {
302
334
  pgEnum,
303
335
  pgTable,
@@ -310,39 +342,39 @@ import {
310
342
  index,
311
343
  uniqueIndex
312
344
  } from "drizzle-orm/pg-core";
313
- var syncRunDirectionEnum = pgEnum("sync_run_direction", [
345
+ var integrationRunDirectionEnum = pgEnum("integration_run_direction", [
314
346
  "inbound",
315
347
  "outbound"
316
348
  ]);
317
- var syncRunActionEnum = pgEnum("sync_run_action", [
349
+ var integrationRunActionEnum = pgEnum("integration_run_action", [
318
350
  "poll",
319
351
  "cdc",
320
352
  "webhook",
321
353
  "manual",
322
354
  "writeback"
323
355
  ]);
324
- var syncRunStatusEnum = pgEnum("sync_run_status", [
356
+ var integrationRunStatusEnum = pgEnum("integration_run_status", [
325
357
  "running",
326
358
  "success",
327
359
  "no_changes",
328
360
  "failed"
329
361
  ]);
330
- var syncRunItemOperationEnum = pgEnum("sync_run_item_operation", [
362
+ var integrationRunItemOperationEnum = pgEnum("integration_run_item_operation", [
331
363
  "created",
332
364
  "updated",
333
365
  "deleted",
334
366
  "noop"
335
367
  ]);
336
- var syncRunItemStatusEnum = pgEnum("sync_run_item_status", [
368
+ var integrationRunItemStatusEnum = pgEnum("integration_run_item_status", [
337
369
  "success",
338
370
  "failed",
339
371
  "skipped"
340
372
  ]);
341
- var syncSubscriptions = pgTable(
342
- "sync_subscriptions",
373
+ var integrationSubscriptions = pgTable(
374
+ "integration_subscriptions",
343
375
  {
344
376
  id: uuid("id").primaryKey().defaultRandom(),
345
- integrationId: text("integration_id").notNull(),
377
+ connectionId: text("connection_id").notNull(),
346
378
  adapter: text("adapter").notNull(),
347
379
  domain: text("domain").notNull(),
348
380
  externalRef: text("external_ref"),
@@ -357,8 +389,8 @@ var syncSubscriptions = pgTable(
357
389
  * successful run advances it.
358
390
  */
359
391
  cursor: jsonb("cursor").$type(),
360
- lastSyncAt: timestamp("last_sync_at", { withTimezone: true }),
361
- /** Runtime-enforced when `SYNC_MULTI_TENANT` is true; see SYNC-6. */
392
+ lastIntegrationAt: timestamp("last_integration_at", { withTimezone: true }),
393
+ /** Runtime-enforced when `INTEGRATION_MULTI_TENANT` is true; see SYNC-6. */
362
394
  tenantId: text("tenant_id"),
363
395
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
364
396
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -367,31 +399,31 @@ var syncSubscriptions = pgTable(
367
399
  /**
368
400
  * Composite uniqueness per the epic shape. `external_ref` is nullable;
369
401
  * Postgres treats NULLs as distinct in a UNIQUE constraint, which means
370
- * two rows with the same `(integration_id, adapter, domain)` and NULL
402
+ * two rows with the same `(connection_id, adapter, domain)` and NULL
371
403
  * external_ref are allowed. That's intentional — a subscription with
372
404
  * NULL external_ref covers the full domain, and duplicates there would
373
405
  * be a consumer-layer modeling issue, not a schema concern.
374
406
  */
375
- uqSyncSubscriptionTuple: uniqueIndex("uq_sync_subscriptions_tuple").on(
376
- t.integrationId,
407
+ uqIntegrationSubscriptionTuple: uniqueIndex("uq_integration_subscriptions_tuple").on(
408
+ t.connectionId,
377
409
  t.adapter,
378
410
  t.domain,
379
411
  t.externalRef
380
412
  ),
381
413
  /** Scheduling query: list enabled subscriptions ordered by staleness. */
382
- idxSyncSubscriptionsEnabledLastSync: index(
383
- "idx_sync_subscriptions_enabled_last_sync"
384
- ).on(t.enabled, t.lastSyncAt)
414
+ idxIntegrationSubscriptionsEnabledLastIntegration: index(
415
+ "idx_integration_subscriptions_enabled_last_integration"
416
+ ).on(t.enabled, t.lastIntegrationAt)
385
417
  })
386
418
  );
387
- var syncRuns = pgTable(
388
- "sync_runs",
419
+ var integrationRuns = pgTable(
420
+ "integration_runs",
389
421
  {
390
422
  id: uuid("id").primaryKey().defaultRandom(),
391
- subscriptionId: uuid("subscription_id").notNull().references(() => syncSubscriptions.id, { onDelete: "cascade" }),
392
- direction: syncRunDirectionEnum("direction").notNull(),
393
- action: syncRunActionEnum("action").notNull(),
394
- status: syncRunStatusEnum("status").notNull().default("running"),
423
+ subscriptionId: uuid("subscription_id").notNull().references(() => integrationSubscriptions.id, { onDelete: "cascade" }),
424
+ direction: integrationRunDirectionEnum("direction").notNull(),
425
+ action: integrationRunActionEnum("action").notNull(),
426
+ status: integrationRunStatusEnum("status").notNull().default("running"),
395
427
  recordsFound: integer("records_found").notNull().default(0),
396
428
  recordsProcessed: integer("records_processed").notNull().default(0),
397
429
  cursorBefore: jsonb("cursor_before").$type(),
@@ -400,31 +432,31 @@ var syncRuns = pgTable(
400
432
  error: text("error"),
401
433
  startedAt: timestamp("started_at", { withTimezone: true }).notNull().defaultNow(),
402
434
  completedAt: timestamp("completed_at", { withTimezone: true }),
403
- /** Runtime-enforced when `SYNC_MULTI_TENANT` is true; see SYNC-6. */
435
+ /** Runtime-enforced when `INTEGRATION_MULTI_TENANT` is true; see SYNC-6. */
404
436
  tenantId: text("tenant_id")
405
437
  },
406
438
  (t) => ({
407
439
  /** Timeline read: "most recent runs for this subscription". */
408
- idxSyncRunsSubscriptionStartedAt: index(
409
- "idx_sync_runs_subscription_started_at"
440
+ idxIntegrationRunsSubscriptionStartedAt: index(
441
+ "idx_integration_runs_subscription_started_at"
410
442
  ).on(t.subscriptionId, t.startedAt),
411
443
  /** Stale-run sweeper: "runs that started > N minutes ago and are still running". */
412
- idxSyncRunsStatusStartedAt: index("idx_sync_runs_status_started_at").on(
444
+ idxIntegrationRunsStatusStartedAt: index("idx_integration_runs_status_started_at").on(
413
445
  t.status,
414
446
  t.startedAt
415
447
  )
416
448
  })
417
449
  );
418
- var syncRunItems = pgTable(
419
- "sync_run_items",
450
+ var integrationRunItems = pgTable(
451
+ "integration_run_items",
420
452
  {
421
453
  id: uuid("id").primaryKey().defaultRandom(),
422
- syncRunId: uuid("sync_run_id").notNull().references(() => syncRuns.id, { onDelete: "cascade" }),
454
+ integrationRunId: uuid("integration_run_id").notNull().references(() => integrationRuns.id, { onDelete: "cascade" }),
423
455
  entityType: text("entity_type").notNull(),
424
456
  externalId: text("external_id").notNull(),
425
457
  localId: text("local_id"),
426
- operation: syncRunItemOperationEnum("operation").notNull(),
427
- status: syncRunItemStatusEnum("status").notNull(),
458
+ operation: integrationRunItemOperationEnum("operation").notNull(),
459
+ status: integrationRunItemStatusEnum("status").notNull(),
428
460
  /**
429
461
  * Structured per-field diff — ADR-0003 shape enforced by
430
462
  * `FieldDiffSchema.parse` at the recorder service layer.
@@ -438,23 +470,23 @@ var syncRunItems = pgTable(
438
470
  title: text("title"),
439
471
  error: text("error"),
440
472
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
441
- /** Runtime-enforced when `SYNC_MULTI_TENANT` is true; see SYNC-6. */
473
+ /** Runtime-enforced when `INTEGRATION_MULTI_TENANT` is true; see SYNC-6. */
442
474
  tenantId: text("tenant_id")
443
475
  },
444
476
  (t) => ({
445
477
  /** Ordered timeline within a run. */
446
- idxSyncRunItemsRunCreatedAt: index("idx_sync_run_items_run_created_at").on(
447
- t.syncRunId,
478
+ idxIntegrationRunItemsRunCreatedAt: index("idx_integration_run_items_run_created_at").on(
479
+ t.integrationRunId,
448
480
  t.createdAt
449
481
  ),
450
- /** Per-record history: "every sync that touched opportunity/$extId". */
451
- idxSyncRunItemsEntityExternal: index(
452
- "idx_sync_run_items_entity_external"
482
+ /** Per-record history: "every integration that touched opportunity/$extId". */
483
+ idxIntegrationRunItemsEntityExternal: index(
484
+ "idx_integration_run_items_entity_external"
453
485
  ).on(t.entityType, t.externalId)
454
486
  })
455
487
  );
456
488
 
457
- // runtime/subsystems/sync/sync-cursor-store.memory-backend.ts
489
+ // runtime/subsystems/integration/integration-cursor-store.memory-backend.ts
458
490
  import { Injectable } from "@nestjs/common";
459
491
  var MemoryCursorStore = class {
460
492
  /**
@@ -465,7 +497,7 @@ var MemoryCursorStore = class {
465
497
  /**
466
498
  * Seedable subscription metadata for `listAll` — the memory backend
467
499
  * stores only `subscriptionId → cursor` in its write path, so the
468
- * snapshot shape (`integrationId`, `adapter`, `domain`, `externalRef`,
500
+ * snapshot shape (`connectionId`, `adapter`, `domain`, `externalRef`,
469
501
  * timestamps) has no natural source without test seeding. Tests populate
470
502
  * this map; unseeded entries get empty-string metadata and `new Date(0)`
471
503
  * timestamps so the shape stays stable. Production paths go through the
@@ -485,12 +517,12 @@ var MemoryCursorStore = class {
485
517
  const meta = this.subscriptions.get(subscriptionId);
486
518
  snapshots.push({
487
519
  subscriptionId,
488
- integrationId: meta?.integrationId ?? "",
520
+ connectionId: meta?.connectionId ?? "",
489
521
  adapter: meta?.adapter ?? "",
490
522
  domain: meta?.domain ?? "",
491
523
  externalRef: meta?.externalRef ?? null,
492
524
  cursor: cursor ?? null,
493
- lastSyncAt: meta?.lastSyncAt ?? null,
525
+ lastIntegrationAt: meta?.lastIntegrationAt ?? null,
494
526
  updatedAt: meta?.updatedAt ?? /* @__PURE__ */ new Date(0),
495
527
  tenantId: null
496
528
  });
@@ -509,7 +541,7 @@ MemoryCursorStore = __decorateClass([
509
541
  Injectable()
510
542
  ], MemoryCursorStore);
511
543
 
512
- // runtime/subsystems/sync/sync-run-recorder.memory-backend.ts
544
+ // runtime/subsystems/integration/integration-run-recorder.memory-backend.ts
513
545
  import { Injectable as Injectable2 } from "@nestjs/common";
514
546
  var MemoryRunRecorder = class {
515
547
  /**
@@ -518,14 +550,14 @@ var MemoryRunRecorder = class {
518
550
  */
519
551
  runs = /* @__PURE__ */ new Map();
520
552
  /**
521
- * Items keyed by `sync_run_id`, array order matches insertion order —
522
- * mirrors the timeline the `(sync_run_id, created_at)` index produces
553
+ * Items keyed by `integration_run_id`, array order matches insertion order —
554
+ * mirrors the timeline the `(integration_run_id, created_at)` index produces
523
555
  * in Postgres.
524
556
  */
525
557
  items = /* @__PURE__ */ new Map();
526
558
  /**
527
559
  * Seedable subscription metadata — tests populate this to make
528
- * `listRecent` return meaningful `integrationId` values. The memory
560
+ * `listRecent` return meaningful `connectionId` values. The memory
529
561
  * backend doesn't track subscriptions on its own (only runs + items), so
530
562
  * this map is the intentional extension point: tests write entries for
531
563
  * the subscription ids they use, production code never touches it.
@@ -554,10 +586,10 @@ var MemoryRunRecorder = class {
554
586
  }
555
587
  async recordItem(input) {
556
588
  FieldDiffSchema.parse(input.changedFields);
557
- const bucket = this.items.get(input.syncRunId);
589
+ const bucket = this.items.get(input.integrationRunId);
558
590
  if (!bucket) {
559
591
  throw new Error(
560
- `MemoryRunRecorder.recordItem: no run started for id '${input.syncRunId}'. Call startRun(...) first.`
592
+ `MemoryRunRecorder.recordItem: no run started for id '${input.integrationRunId}'. Call startRun(...) first.`
561
593
  );
562
594
  }
563
595
  bucket.push(input);
@@ -583,10 +615,10 @@ var MemoryRunRecorder = class {
583
615
  return filtered.sort((a, b) => b.startedAt.getTime() - a.startedAt.getTime()).slice(0, limit).map((r) => ({
584
616
  id: r.id,
585
617
  subscriptionId: r.subscriptionId,
586
- // integrationId is only knowable if the test seeded subscriptions
618
+ // connectionId is only knowable if the test seeded subscriptions
587
619
  // metadata; empty string otherwise. The Drizzle backend resolves
588
620
  // it via JOIN, which is the production path.
589
- integrationId: this.subscriptions.get(r.subscriptionId)?.integrationId ?? "",
621
+ connectionId: this.subscriptions.get(r.subscriptionId)?.connectionId ?? "",
590
622
  status: r.status,
591
623
  startedAt: r.startedAt,
592
624
  completedAt: r.completedAt,
@@ -614,7 +646,7 @@ MemoryRunRecorder = __decorateClass([
614
646
  Injectable2()
615
647
  ], MemoryRunRecorder);
616
648
 
617
- // runtime/subsystems/sync/deep-equal.differ.ts
649
+ // runtime/subsystems/integration/deep-equal.differ.ts
618
650
  import { Injectable as Injectable3 } from "@nestjs/common";
619
651
  var DEFAULT_IGNORE_FIELDS = /* @__PURE__ */ new Set([
620
652
  "id",
@@ -713,9 +745,9 @@ function deepEqualObject(a, b) {
713
745
  return true;
714
746
  }
715
747
 
716
- // runtime/subsystems/sync/execute-sync.use-case.ts
748
+ // runtime/subsystems/integration/execute-integration.use-case.ts
717
749
  import { Inject, Injectable as Injectable4, Logger, Optional } from "@nestjs/common";
718
- var ExecuteSyncUseCase = class {
750
+ var ExecuteIntegrationUseCase = class {
719
751
  constructor(source, cursors, differ, sink, recorder, multiTenant = false) {
720
752
  this.source = source;
721
753
  this.cursors = cursors;
@@ -730,7 +762,7 @@ var ExecuteSyncUseCase = class {
730
762
  sink;
731
763
  recorder;
732
764
  multiTenant;
733
- logger = new Logger(ExecuteSyncUseCase.name);
765
+ logger = new Logger(ExecuteIntegrationUseCase.name);
734
766
  async execute(input) {
735
767
  assertTenantId(input.tenantId, {
736
768
  multiTenant: this.multiTenant,
@@ -765,10 +797,10 @@ var ExecuteSyncUseCase = class {
765
797
  recordsFailed++;
766
798
  const message = err instanceof Error ? err.message : String(err);
767
799
  this.logger.warn(
768
- `sync item failed: subscription=${input.subscription.id} externalId=${change.externalId}: ${message}`
800
+ `integration item failed: subscription=${input.subscription.id} externalId=${change.externalId}: ${message}`
769
801
  );
770
802
  await this.recorder.recordItem({
771
- syncRunId: runId,
803
+ integrationRunId: runId,
772
804
  entityType: input.subscription.domain,
773
805
  externalId: change.externalId,
774
806
  operation: change.operation === "deleted" ? "deleted" : "updated",
@@ -791,7 +823,7 @@ var ExecuteSyncUseCase = class {
791
823
  status = "failed";
792
824
  runError = err instanceof Error ? err.message : String(err);
793
825
  this.logger.error(
794
- `sync source failed: subscription=${input.subscription.id}: ${runError}`
826
+ `integration source failed: subscription=${input.subscription.id}: ${runError}`
795
827
  );
796
828
  }
797
829
  if (cursorAdvanced && latestCursor !== null && latestCursor !== void 0) {
@@ -836,7 +868,7 @@ var ExecuteSyncUseCase = class {
836
868
  change.externalId
837
869
  );
838
870
  await this.recorder.recordItem({
839
- syncRunId: runId,
871
+ integrationRunId: runId,
840
872
  entityType: input.subscription.domain,
841
873
  externalId: change.externalId,
842
874
  localId: result?.id ?? null,
@@ -859,7 +891,7 @@ var ExecuteSyncUseCase = class {
859
891
  if (diff === "noop") {
860
892
  if (!this.sink.reprojectsOnNoop) {
861
893
  await this.recorder.recordItem({
862
- syncRunId: runId,
894
+ integrationRunId: runId,
863
895
  entityType: input.subscription.domain,
864
896
  externalId: change.externalId,
865
897
  localId: null,
@@ -876,7 +908,7 @@ var ExecuteSyncUseCase = class {
876
908
  input.provider
877
909
  );
878
910
  await this.recorder.recordItem({
879
- syncRunId: runId,
911
+ integrationRunId: runId,
880
912
  entityType: input.subscription.domain,
881
913
  externalId: change.externalId,
882
914
  localId: noopLocalId,
@@ -893,7 +925,7 @@ var ExecuteSyncUseCase = class {
893
925
  input.provider
894
926
  );
895
927
  await this.recorder.recordItem({
896
- syncRunId: runId,
928
+ integrationRunId: runId,
897
929
  entityType: input.subscription.domain,
898
930
  externalId: change.externalId,
899
931
  localId,
@@ -904,25 +936,25 @@ var ExecuteSyncUseCase = class {
904
936
  });
905
937
  }
906
938
  };
907
- ExecuteSyncUseCase = __decorateClass([
939
+ ExecuteIntegrationUseCase = __decorateClass([
908
940
  Injectable4(),
909
- __decorateParam(0, Inject(SYNC_CHANGE_SOURCE)),
910
- __decorateParam(1, Inject(SYNC_CURSOR_STORE)),
911
- __decorateParam(2, Inject(SYNC_FIELD_DIFFER)),
912
- __decorateParam(3, Inject(SYNC_SINK)),
913
- __decorateParam(4, Inject(SYNC_RUN_RECORDER)),
941
+ __decorateParam(0, Inject(INTEGRATION_CHANGE_SOURCE)),
942
+ __decorateParam(1, Inject(INTEGRATION_CURSOR_STORE)),
943
+ __decorateParam(2, Inject(INTEGRATION_FIELD_DIFFER)),
944
+ __decorateParam(3, Inject(INTEGRATION_SINK)),
945
+ __decorateParam(4, Inject(INTEGRATION_RUN_RECORDER)),
914
946
  __decorateParam(5, Optional()),
915
- __decorateParam(5, Inject(SYNC_MULTI_TENANT))
916
- ], ExecuteSyncUseCase);
947
+ __decorateParam(5, Inject(INTEGRATION_MULTI_TENANT))
948
+ ], ExecuteIntegrationUseCase);
917
949
 
918
- // runtime/subsystems/sync/sync-cursor-store.drizzle-backend.ts
950
+ // runtime/subsystems/integration/integration-cursor-store.drizzle-backend.ts
919
951
  import { Inject as Inject2, Injectable as Injectable5, Optional as Optional2 } from "@nestjs/common";
920
952
  import { and, desc, eq } from "drizzle-orm";
921
953
 
922
954
  // runtime/constants/tokens.ts
923
955
  var DRIZZLE = "DRIZZLE";
924
956
 
925
- // runtime/subsystems/sync/sync-cursor-store.drizzle-backend.ts
957
+ // runtime/subsystems/integration/integration-cursor-store.drizzle-backend.ts
926
958
  var PostgresCursorStore = class {
927
959
  constructor(db, multiTenant) {
928
960
  this.db = db;
@@ -932,15 +964,15 @@ var PostgresCursorStore = class {
932
964
  multiTenant;
933
965
  async get(subscriptionId, tenantId) {
934
966
  const where = this.buildWhere(subscriptionId, tenantId, "cursor.get");
935
- const rows = await this.db.select({ cursor: syncSubscriptions.cursor }).from(syncSubscriptions).where(where).limit(1);
967
+ const rows = await this.db.select({ cursor: integrationSubscriptions.cursor }).from(integrationSubscriptions).where(where).limit(1);
936
968
  if (rows.length === 0) return null;
937
969
  return rows[0]?.cursor ?? null;
938
970
  }
939
971
  async put(subscriptionId, cursor, tenantId) {
940
972
  const where = this.buildWhere(subscriptionId, tenantId, "cursor.put");
941
- await this.db.update(syncSubscriptions).set({
973
+ await this.db.update(integrationSubscriptions).set({
942
974
  cursor,
943
- lastSyncAt: /* @__PURE__ */ new Date(),
975
+ lastIntegrationAt: /* @__PURE__ */ new Date(),
944
976
  updatedAt: /* @__PURE__ */ new Date()
945
977
  }).where(where);
946
978
  }
@@ -949,26 +981,26 @@ var PostgresCursorStore = class {
949
981
  multiTenant: this.multiTenant,
950
982
  operation: "cursor.listAll"
951
983
  });
952
- const where = this.multiTenant ? eq(syncSubscriptions.tenantId, tenantId) : void 0;
984
+ const where = this.multiTenant ? eq(integrationSubscriptions.tenantId, tenantId) : void 0;
953
985
  const rows = await this.db.select({
954
- id: syncSubscriptions.id,
955
- integrationId: syncSubscriptions.integrationId,
956
- adapter: syncSubscriptions.adapter,
957
- domain: syncSubscriptions.domain,
958
- externalRef: syncSubscriptions.externalRef,
959
- cursor: syncSubscriptions.cursor,
960
- lastSyncAt: syncSubscriptions.lastSyncAt,
961
- updatedAt: syncSubscriptions.updatedAt,
962
- tenantId: syncSubscriptions.tenantId
963
- }).from(syncSubscriptions).where(where).orderBy(desc(syncSubscriptions.updatedAt));
986
+ id: integrationSubscriptions.id,
987
+ connectionId: integrationSubscriptions.connectionId,
988
+ adapter: integrationSubscriptions.adapter,
989
+ domain: integrationSubscriptions.domain,
990
+ externalRef: integrationSubscriptions.externalRef,
991
+ cursor: integrationSubscriptions.cursor,
992
+ lastIntegrationAt: integrationSubscriptions.lastIntegrationAt,
993
+ updatedAt: integrationSubscriptions.updatedAt,
994
+ tenantId: integrationSubscriptions.tenantId
995
+ }).from(integrationSubscriptions).where(where).orderBy(desc(integrationSubscriptions.updatedAt));
964
996
  return rows.map((row) => ({
965
997
  subscriptionId: row.id,
966
- integrationId: row.integrationId,
998
+ connectionId: row.connectionId,
967
999
  adapter: row.adapter,
968
1000
  domain: row.domain,
969
1001
  externalRef: row.externalRef,
970
1002
  cursor: row.cursor ?? null,
971
- lastSyncAt: row.lastSyncAt,
1003
+ lastIntegrationAt: row.lastIntegrationAt,
972
1004
  updatedAt: row.updatedAt,
973
1005
  tenantId: row.tenantId
974
1006
  }));
@@ -985,24 +1017,24 @@ var PostgresCursorStore = class {
985
1017
  });
986
1018
  if (this.multiTenant) {
987
1019
  return and(
988
- eq(syncSubscriptions.id, subscriptionId),
989
- eq(syncSubscriptions.tenantId, tenantId)
1020
+ eq(integrationSubscriptions.id, subscriptionId),
1021
+ eq(integrationSubscriptions.tenantId, tenantId)
990
1022
  );
991
1023
  }
992
- return eq(syncSubscriptions.id, subscriptionId);
1024
+ return eq(integrationSubscriptions.id, subscriptionId);
993
1025
  }
994
1026
  };
995
1027
  PostgresCursorStore = __decorateClass([
996
1028
  Injectable5(),
997
1029
  __decorateParam(0, Inject2(DRIZZLE)),
998
1030
  __decorateParam(1, Optional2()),
999
- __decorateParam(1, Inject2(SYNC_MULTI_TENANT))
1031
+ __decorateParam(1, Inject2(INTEGRATION_MULTI_TENANT))
1000
1032
  ], PostgresCursorStore);
1001
1033
 
1002
- // runtime/subsystems/sync/sync-run-recorder.drizzle-backend.ts
1034
+ // runtime/subsystems/integration/integration-run-recorder.drizzle-backend.ts
1003
1035
  import { Inject as Inject3, Injectable as Injectable6, Optional as Optional3 } from "@nestjs/common";
1004
1036
  import { and as and2, desc as desc2, eq as eq2 } from "drizzle-orm";
1005
- var DrizzleSyncRunRecorder = class {
1037
+ var DrizzleIntegrationRunRecorder = class {
1006
1038
  constructor(db, multiTenant) {
1007
1039
  this.db = db;
1008
1040
  this.multiTenant = multiTenant ?? false;
@@ -1014,17 +1046,17 @@ var DrizzleSyncRunRecorder = class {
1014
1046
  multiTenant: this.multiTenant,
1015
1047
  operation: "startRun"
1016
1048
  });
1017
- const rows = await this.db.insert(syncRuns).values({
1049
+ const rows = await this.db.insert(integrationRuns).values({
1018
1050
  subscriptionId: input.subscriptionId,
1019
1051
  direction: input.direction,
1020
1052
  action: input.action,
1021
1053
  status: "running",
1022
1054
  cursorBefore: input.cursorBefore ?? null,
1023
1055
  tenantId: input.tenantId ?? null
1024
- }).returning({ id: syncRuns.id });
1056
+ }).returning({ id: integrationRuns.id });
1025
1057
  const id = rows[0]?.id;
1026
1058
  if (!id) {
1027
- throw new Error("DrizzleSyncRunRecorder: INSERT RETURNING produced no id");
1059
+ throw new Error("DrizzleIntegrationRunRecorder: INSERT RETURNING produced no id");
1028
1060
  }
1029
1061
  return { id };
1030
1062
  }
@@ -1034,8 +1066,8 @@ var DrizzleSyncRunRecorder = class {
1034
1066
  operation: "recordItem"
1035
1067
  });
1036
1068
  FieldDiffSchema.parse(input.changedFields);
1037
- await this.db.insert(syncRunItems).values({
1038
- syncRunId: input.syncRunId,
1069
+ await this.db.insert(integrationRunItems).values({
1070
+ integrationRunId: input.integrationRunId,
1039
1071
  entityType: input.entityType,
1040
1072
  externalId: input.externalId,
1041
1073
  localId: input.localId ?? null,
@@ -1054,29 +1086,29 @@ var DrizzleSyncRunRecorder = class {
1054
1086
  });
1055
1087
  const conditions = [];
1056
1088
  if (subscriptionId !== void 0) {
1057
- conditions.push(eq2(syncRuns.subscriptionId, subscriptionId));
1089
+ conditions.push(eq2(integrationRuns.subscriptionId, subscriptionId));
1058
1090
  }
1059
1091
  if (this.multiTenant) {
1060
- conditions.push(eq2(syncRuns.tenantId, tenantId));
1092
+ conditions.push(eq2(integrationRuns.tenantId, tenantId));
1061
1093
  }
1062
1094
  const where = conditions.length === 0 ? void 0 : conditions.length === 1 ? conditions[0] : and2(...conditions);
1063
1095
  const rows = await this.db.select({
1064
- id: syncRuns.id,
1065
- subscriptionId: syncRuns.subscriptionId,
1066
- integrationId: syncSubscriptions.integrationId,
1067
- status: syncRuns.status,
1068
- startedAt: syncRuns.startedAt,
1069
- completedAt: syncRuns.completedAt,
1070
- recordsProcessed: syncRuns.recordsProcessed,
1071
- tenantId: syncRuns.tenantId
1072
- }).from(syncRuns).innerJoin(
1073
- syncSubscriptions,
1074
- eq2(syncRuns.subscriptionId, syncSubscriptions.id)
1075
- ).where(where).orderBy(desc2(syncRuns.startedAt)).limit(limit);
1096
+ id: integrationRuns.id,
1097
+ subscriptionId: integrationRuns.subscriptionId,
1098
+ connectionId: integrationSubscriptions.connectionId,
1099
+ status: integrationRuns.status,
1100
+ startedAt: integrationRuns.startedAt,
1101
+ completedAt: integrationRuns.completedAt,
1102
+ recordsProcessed: integrationRuns.recordsProcessed,
1103
+ tenantId: integrationRuns.tenantId
1104
+ }).from(integrationRuns).innerJoin(
1105
+ integrationSubscriptions,
1106
+ eq2(integrationRuns.subscriptionId, integrationSubscriptions.id)
1107
+ ).where(where).orderBy(desc2(integrationRuns.startedAt)).limit(limit);
1076
1108
  return rows.map((row) => ({
1077
1109
  id: row.id,
1078
1110
  subscriptionId: row.subscriptionId,
1079
- integrationId: row.integrationId,
1111
+ connectionId: row.connectionId,
1080
1112
  status: row.status,
1081
1113
  startedAt: row.startedAt,
1082
1114
  completedAt: row.completedAt,
@@ -1085,7 +1117,7 @@ var DrizzleSyncRunRecorder = class {
1085
1117
  }));
1086
1118
  }
1087
1119
  async completeRun(runId, input) {
1088
- await this.db.update(syncRuns).set({
1120
+ await this.db.update(integrationRuns).set({
1089
1121
  status: input.status,
1090
1122
  recordsFound: input.recordsFound,
1091
1123
  recordsProcessed: input.recordsProcessed,
@@ -1093,27 +1125,27 @@ var DrizzleSyncRunRecorder = class {
1093
1125
  durationMs: input.durationMs,
1094
1126
  error: input.error ?? null,
1095
1127
  completedAt: /* @__PURE__ */ new Date()
1096
- }).where(eq2(syncRuns.id, runId));
1128
+ }).where(eq2(integrationRuns.id, runId));
1097
1129
  }
1098
1130
  };
1099
- DrizzleSyncRunRecorder = __decorateClass([
1131
+ DrizzleIntegrationRunRecorder = __decorateClass([
1100
1132
  Injectable6(),
1101
1133
  __decorateParam(0, Inject3(DRIZZLE)),
1102
1134
  __decorateParam(1, Optional3()),
1103
- __decorateParam(1, Inject3(SYNC_MULTI_TENANT))
1104
- ], DrizzleSyncRunRecorder);
1135
+ __decorateParam(1, Inject3(INTEGRATION_MULTI_TENANT))
1136
+ ], DrizzleIntegrationRunRecorder);
1105
1137
 
1106
- // runtime/subsystems/sync/sync.module.ts
1138
+ // runtime/subsystems/integration/integration.module.ts
1107
1139
  import { Module } from "@nestjs/common";
1108
- var SyncModule = class {
1140
+ var IntegrationModule = class {
1109
1141
  static forRoot(options) {
1110
1142
  const multiTenant = options.multiTenant ?? false;
1111
1143
  const sharedProviders = [
1112
- { provide: SYNC_MODULE_OPTIONS, useValue: options },
1113
- { provide: SYNC_MULTI_TENANT, useValue: multiTenant },
1144
+ { provide: INTEGRATION_MODULE_OPTIONS, useValue: options },
1145
+ { provide: INTEGRATION_MULTI_TENANT, useValue: multiTenant },
1114
1146
  // Default differ — consumers can override by binding a different
1115
- // `IFieldDiffer<T>` to `SYNC_FIELD_DIFFER` in their feature module.
1116
- { provide: SYNC_FIELD_DIFFER, useValue: new DeepEqualDiffer() }
1147
+ // `IFieldDiffer<T>` to `INTEGRATION_FIELD_DIFFER` in their feature module.
1148
+ { provide: INTEGRATION_FIELD_DIFFER, useValue: new DeepEqualDiffer() }
1117
1149
  ];
1118
1150
  const backendProviders = options.backend === "memory" ? [
1119
1151
  // Wired as singletons via `useValue` so tests can pull
@@ -1121,74 +1153,77 @@ var SyncModule = class {
1121
1153
  // direct assertions. Matches JOB-4 / MemoryJobStore shape.
1122
1154
  { provide: MemoryCursorStore, useValue: new MemoryCursorStore() },
1123
1155
  {
1124
- provide: SYNC_CURSOR_STORE,
1156
+ provide: INTEGRATION_CURSOR_STORE,
1125
1157
  useExisting: MemoryCursorStore
1126
1158
  },
1127
1159
  { provide: MemoryRunRecorder, useValue: new MemoryRunRecorder() },
1128
1160
  {
1129
- provide: SYNC_RUN_RECORDER,
1161
+ provide: INTEGRATION_RUN_RECORDER,
1130
1162
  useExisting: MemoryRunRecorder
1131
1163
  }
1132
1164
  ] : [
1133
1165
  // Drizzle backends — injected with DRIZZLE (provided by the
1134
- // consumer's DrizzleModule) + the SYNC_MULTI_TENANT flag
1166
+ // consumer's DrizzleModule) + the INTEGRATION_MULTI_TENANT flag
1135
1167
  // we bound above.
1136
- { provide: SYNC_CURSOR_STORE, useClass: PostgresCursorStore },
1137
- { provide: SYNC_RUN_RECORDER, useClass: DrizzleSyncRunRecorder }
1168
+ { provide: INTEGRATION_CURSOR_STORE, useClass: PostgresCursorStore },
1169
+ { provide: INTEGRATION_RUN_RECORDER, useClass: DrizzleIntegrationRunRecorder }
1138
1170
  ];
1139
1171
  return {
1140
- module: SyncModule,
1172
+ module: IntegrationModule,
1141
1173
  global: true,
1142
1174
  providers: [...sharedProviders, ...backendProviders],
1143
1175
  exports: [
1144
- SYNC_MODULE_OPTIONS,
1145
- SYNC_MULTI_TENANT,
1146
- SYNC_FIELD_DIFFER,
1147
- SYNC_CURSOR_STORE,
1148
- SYNC_RUN_RECORDER
1176
+ INTEGRATION_MODULE_OPTIONS,
1177
+ INTEGRATION_MULTI_TENANT,
1178
+ INTEGRATION_FIELD_DIFFER,
1179
+ INTEGRATION_CURSOR_STORE,
1180
+ INTEGRATION_RUN_RECORDER
1149
1181
  ]
1150
1182
  };
1151
1183
  }
1152
1184
  };
1153
- SyncModule = __decorateClass([
1185
+ IntegrationModule = __decorateClass([
1154
1186
  Module({})
1155
- ], SyncModule);
1187
+ ], IntegrationModule);
1156
1188
  export {
1157
1189
  CursorStrategySchema,
1158
1190
  DeepEqualDiffer,
1159
1191
  DetectionConfigSchema,
1160
- DrizzleSyncRunRecorder,
1161
- ExecuteSyncUseCase,
1192
+ DrizzleIntegrationRunRecorder,
1193
+ ENTITY_CHANGE_SOURCE_REGISTRY,
1194
+ ExecuteIntegrationUseCase,
1162
1195
  FieldDiffSchema,
1163
1196
  FieldDiffValueSchema,
1164
1197
  FieldMappingSchema,
1198
+ INTEGRATION_CHANGE_SOURCE,
1199
+ INTEGRATION_CURSOR_STORE,
1200
+ INTEGRATION_FIELD_DIFFER,
1201
+ INTEGRATION_MODULE_OPTIONS,
1202
+ INTEGRATION_MULTI_TENANT,
1203
+ INTEGRATION_RUN_RECORDER,
1204
+ INTEGRATION_SINK,
1205
+ IntegrationModule,
1165
1206
  MemoryCursorStore,
1207
+ MemoryEntityChangeSourceRegistry,
1166
1208
  MemoryRunRecorder,
1167
1209
  MissingTenantIdError,
1168
1210
  PollChangeSource,
1169
1211
  PollDetectionSchema,
1170
1212
  PostgresCursorStore,
1171
1213
  ResolvedFilterSchema,
1172
- SYNC_CHANGE_SOURCE,
1173
- SYNC_CURSOR_STORE,
1174
- SYNC_FIELD_DIFFER,
1175
- SYNC_MODULE_OPTIONS,
1176
- SYNC_MULTI_TENANT,
1177
- SYNC_RUN_RECORDER,
1178
- SYNC_SINK,
1179
- SyncModule,
1214
+ UnknownEntityError,
1180
1215
  WebhookChangeSource,
1181
1216
  WebhookDetectionSchema,
1182
1217
  assertTenantId,
1183
1218
  buildChangeSource,
1184
1219
  createLoopbackMiddleware,
1185
- syncRunActionEnum,
1186
- syncRunDirectionEnum,
1187
- syncRunItemOperationEnum,
1188
- syncRunItemStatusEnum,
1189
- syncRunItems,
1190
- syncRunStatusEnum,
1191
- syncRuns,
1192
- syncSubscriptions
1220
+ integrationRunActionEnum,
1221
+ integrationRunDirectionEnum,
1222
+ integrationRunItemOperationEnum,
1223
+ integrationRunItemStatusEnum,
1224
+ integrationRunItems,
1225
+ integrationRunStatusEnum,
1226
+ integrationRuns,
1227
+ integrationSubscriptions
1193
1228
  };
1194
1229
  //# sourceMappingURL=index.js.map