@pattern-stack/codegen 0.23.0 → 0.24.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 (85) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/consumer-skills/integration/SKILL.md +11 -3
  3. package/dist/{chunk-XKWOJZZ4.js → chunk-37PILMIT.js} +4 -4
  4. package/dist/{chunk-42763UEE.js → chunk-6M6LZEP6.js} +2 -2
  5. package/dist/{chunk-FIUC6QB5.js → chunk-CKLM57IE.js} +10 -10
  6. package/dist/{chunk-SH76CFAY.js → chunk-ENAR3F5S.js} +2 -2
  7. package/dist/{chunk-FFUDEIFF.js → chunk-HN5HT5WL.js} +2 -2
  8. package/dist/{chunk-4M66MQYA.js → chunk-K4BQQ2NN.js} +4 -2
  9. package/dist/chunk-K4BQQ2NN.js.map +1 -0
  10. package/dist/{chunk-QFUIE37H.js → chunk-KFXXOFDC.js} +4 -4
  11. package/dist/{chunk-O2A6XHGD.js → chunk-LLDJS7PJ.js} +2 -2
  12. package/dist/{chunk-JOBQ6RUU.js → chunk-LQZESSM3.js} +28 -1
  13. package/dist/chunk-LQZESSM3.js.map +1 -0
  14. package/dist/{chunk-JRQO2IOF.js → chunk-MU54DZCC.js} +27 -1
  15. package/dist/chunk-MU54DZCC.js.map +1 -0
  16. package/dist/{chunk-INO47JXD.js → chunk-PBENHIN2.js} +3 -3
  17. package/dist/{chunk-CLWBNXKF.js → chunk-PLUJEQLU.js} +2 -2
  18. package/dist/{chunk-S7C6TIIF.js → chunk-S5G3HO7N.js} +3 -1
  19. package/dist/chunk-S5G3HO7N.js.map +1 -0
  20. package/dist/{chunk-6XP2Q5SS.js → chunk-WZOPWQN2.js} +2 -2
  21. package/dist/{chunk-TDEHU73T.js → chunk-YIVQ7KLS.js} +46 -5
  22. package/dist/chunk-YIVQ7KLS.js.map +1 -0
  23. package/dist/runtime/base-classes/index.js +17 -17
  24. package/dist/runtime/subsystems/auth/auth.module.js +1 -1
  25. package/dist/runtime/subsystems/auth/index.js +3 -3
  26. package/dist/runtime/subsystems/bridge/bridge.module.js +6 -6
  27. package/dist/runtime/subsystems/bridge/index.js +6 -6
  28. package/dist/runtime/subsystems/events/events.module.js +4 -4
  29. package/dist/runtime/subsystems/events/generated/bus.js +3 -3
  30. package/dist/runtime/subsystems/events/generated/index.d.ts +2 -2
  31. package/dist/runtime/subsystems/events/generated/index.js +9 -3
  32. package/dist/runtime/subsystems/events/generated/registry.d.ts +36 -0
  33. package/dist/runtime/subsystems/events/generated/registry.js +1 -1
  34. package/dist/runtime/subsystems/events/generated/schemas.d.ts +109 -1
  35. package/dist/runtime/subsystems/events/generated/schemas.js +7 -1
  36. package/dist/runtime/subsystems/events/generated/types.d.ts +48 -2
  37. package/dist/runtime/subsystems/events/index.js +4 -4
  38. package/dist/runtime/subsystems/index.d.ts +3 -2
  39. package/dist/runtime/subsystems/index.js +26 -22
  40. package/dist/runtime/subsystems/integration/execute-integration.use-case.d.ts +11 -1
  41. package/dist/runtime/subsystems/integration/execute-integration.use-case.js +2 -2
  42. package/dist/runtime/subsystems/integration/index.d.ts +2 -1
  43. package/dist/runtime/subsystems/integration/index.js +10 -8
  44. package/dist/runtime/subsystems/integration/integration-change-emitter.protocol.d.ts +106 -0
  45. package/dist/runtime/subsystems/integration/integration-change-emitter.protocol.js +1 -0
  46. package/dist/runtime/subsystems/integration/integration-change-emitter.protocol.js.map +1 -0
  47. package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js +2 -2
  48. package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js +2 -2
  49. package/dist/runtime/subsystems/integration/integration.module.js +4 -4
  50. package/dist/runtime/subsystems/integration/integration.tokens.d.ts +11 -1
  51. package/dist/runtime/subsystems/integration/integration.tokens.js +3 -1
  52. package/dist/runtime/subsystems/jobs/index.js +11 -11
  53. package/dist/runtime/subsystems/jobs/job-worker.module.js +5 -5
  54. package/dist/runtime/subsystems/jobs/jobs-domain.module.js +4 -4
  55. package/dist/runtime/subsystems/observability/index.js +3 -3
  56. package/dist/runtime/subsystems/observability/observability.module.js +3 -3
  57. package/dist/runtime/subsystems/observability/observability.service.js +2 -2
  58. package/dist/src/cli/index.js +203 -26
  59. package/dist/src/cli/index.js.map +1 -1
  60. package/dist/src/index.d.ts +13 -0
  61. package/dist/src/index.js +7 -7
  62. package/package.json +1 -1
  63. package/runtime/subsystems/events/generated/registry.ts +27 -0
  64. package/runtime/subsystems/events/generated/schemas.ts +26 -0
  65. package/runtime/subsystems/events/generated/types.ts +52 -0
  66. package/runtime/subsystems/index.ts +23 -0
  67. package/runtime/subsystems/integration/execute-integration.use-case.ts +69 -1
  68. package/runtime/subsystems/integration/index.ts +6 -0
  69. package/runtime/subsystems/integration/integration-change-emitter.protocol.ts +107 -0
  70. package/runtime/subsystems/integration/integration.tokens.ts +11 -0
  71. package/dist/chunk-4M66MQYA.js.map +0 -1
  72. package/dist/chunk-JOBQ6RUU.js.map +0 -1
  73. package/dist/chunk-JRQO2IOF.js.map +0 -1
  74. package/dist/chunk-S7C6TIIF.js.map +0 -1
  75. package/dist/chunk-TDEHU73T.js.map +0 -1
  76. /package/dist/{chunk-XKWOJZZ4.js.map → chunk-37PILMIT.js.map} +0 -0
  77. /package/dist/{chunk-42763UEE.js.map → chunk-6M6LZEP6.js.map} +0 -0
  78. /package/dist/{chunk-FIUC6QB5.js.map → chunk-CKLM57IE.js.map} +0 -0
  79. /package/dist/{chunk-SH76CFAY.js.map → chunk-ENAR3F5S.js.map} +0 -0
  80. /package/dist/{chunk-FFUDEIFF.js.map → chunk-HN5HT5WL.js.map} +0 -0
  81. /package/dist/{chunk-QFUIE37H.js.map → chunk-KFXXOFDC.js.map} +0 -0
  82. /package/dist/{chunk-O2A6XHGD.js.map → chunk-LLDJS7PJ.js.map} +0 -0
  83. /package/dist/{chunk-INO47JXD.js.map → chunk-PBENHIN2.js.map} +0 -0
  84. /package/dist/{chunk-CLWBNXKF.js.map → chunk-PLUJEQLU.js.map} +0 -0
  85. /package/dist/{chunk-6XP2Q5SS.js.map → chunk-WZOPWQN2.js.map} +0 -0
@@ -95,6 +95,42 @@ declare const eventRegistry: {
95
95
  readonly backoff: "exponential";
96
96
  };
97
97
  };
98
+ readonly message_created: {
99
+ readonly type: "message_created";
100
+ readonly tier: "domain";
101
+ readonly direction: "change";
102
+ readonly pool: "events_change";
103
+ readonly aggregate: "message";
104
+ readonly version: 1;
105
+ readonly retry: {
106
+ readonly attempts: 3;
107
+ readonly backoff: "exponential";
108
+ };
109
+ };
110
+ readonly message_deleted: {
111
+ readonly type: "message_deleted";
112
+ readonly tier: "domain";
113
+ readonly direction: "change";
114
+ readonly pool: "events_change";
115
+ readonly aggregate: "message";
116
+ readonly version: 1;
117
+ readonly retry: {
118
+ readonly attempts: 3;
119
+ readonly backoff: "exponential";
120
+ };
121
+ };
122
+ readonly message_edited: {
123
+ readonly type: "message_edited";
124
+ readonly tier: "domain";
125
+ readonly direction: "change";
126
+ readonly pool: "events_change";
127
+ readonly aggregate: "message";
128
+ readonly version: 1;
129
+ readonly retry: {
130
+ readonly attempts: 3;
131
+ readonly backoff: "exponential";
132
+ };
133
+ };
98
134
  readonly stripe_payment_received: {
99
135
  readonly type: "stripe_payment_received";
100
136
  readonly tier: "domain";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  eventRegistry,
3
3
  getEventMetadata
4
- } from "../../../../chunk-JOBQ6RUU.js";
4
+ } from "../../../../chunk-LQZESSM3.js";
5
5
  import "../../../../chunk-2E224ZSN.js";
6
6
  export {
7
7
  eventRegistry,
@@ -72,6 +72,60 @@ declare const dealStageChangedPayloadSchema: z.ZodObject<{
72
72
  newStage: string;
73
73
  oldStage: string;
74
74
  }>;
75
+ declare const messageCreatedPayloadSchema: z.ZodObject<{
76
+ changedFields: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
77
+ entityId: z.ZodString;
78
+ externalId: z.ZodString;
79
+ provider: z.ZodString;
80
+ source: z.ZodString;
81
+ }, "strict", z.ZodTypeAny, {
82
+ source: string;
83
+ changedFields: Record<string, unknown> | null;
84
+ entityId: string;
85
+ externalId: string;
86
+ provider: string;
87
+ }, {
88
+ source: string;
89
+ changedFields: Record<string, unknown> | null;
90
+ entityId: string;
91
+ externalId: string;
92
+ provider: string;
93
+ }>;
94
+ declare const messageDeletedPayloadSchema: z.ZodObject<{
95
+ entityId: z.ZodString;
96
+ externalId: z.ZodString;
97
+ provider: z.ZodString;
98
+ source: z.ZodString;
99
+ }, "strict", z.ZodTypeAny, {
100
+ source: string;
101
+ entityId: string;
102
+ externalId: string;
103
+ provider: string;
104
+ }, {
105
+ source: string;
106
+ entityId: string;
107
+ externalId: string;
108
+ provider: string;
109
+ }>;
110
+ declare const messageEditedPayloadSchema: z.ZodObject<{
111
+ changedFields: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
112
+ entityId: z.ZodString;
113
+ externalId: z.ZodString;
114
+ provider: z.ZodString;
115
+ source: z.ZodString;
116
+ }, "strict", z.ZodTypeAny, {
117
+ source: string;
118
+ changedFields: Record<string, unknown> | null;
119
+ entityId: string;
120
+ externalId: string;
121
+ provider: string;
122
+ }, {
123
+ source: string;
124
+ changedFields: Record<string, unknown> | null;
125
+ entityId: string;
126
+ externalId: string;
127
+ provider: string;
128
+ }>;
75
129
  declare const stripePaymentReceivedPayloadSchema: z.ZodObject<{
76
130
  amountCents: z.ZodNumber;
77
131
  currency: z.ZodString;
@@ -177,6 +231,60 @@ declare const eventPayloadSchemas: {
177
231
  newStage: string;
178
232
  oldStage: string;
179
233
  }>;
234
+ readonly message_created: z.ZodObject<{
235
+ changedFields: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
236
+ entityId: z.ZodString;
237
+ externalId: z.ZodString;
238
+ provider: z.ZodString;
239
+ source: z.ZodString;
240
+ }, "strict", z.ZodTypeAny, {
241
+ source: string;
242
+ changedFields: Record<string, unknown> | null;
243
+ entityId: string;
244
+ externalId: string;
245
+ provider: string;
246
+ }, {
247
+ source: string;
248
+ changedFields: Record<string, unknown> | null;
249
+ entityId: string;
250
+ externalId: string;
251
+ provider: string;
252
+ }>;
253
+ readonly message_deleted: z.ZodObject<{
254
+ entityId: z.ZodString;
255
+ externalId: z.ZodString;
256
+ provider: z.ZodString;
257
+ source: z.ZodString;
258
+ }, "strict", z.ZodTypeAny, {
259
+ source: string;
260
+ entityId: string;
261
+ externalId: string;
262
+ provider: string;
263
+ }, {
264
+ source: string;
265
+ entityId: string;
266
+ externalId: string;
267
+ provider: string;
268
+ }>;
269
+ readonly message_edited: z.ZodObject<{
270
+ changedFields: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
271
+ entityId: z.ZodString;
272
+ externalId: z.ZodString;
273
+ provider: z.ZodString;
274
+ source: z.ZodString;
275
+ }, "strict", z.ZodTypeAny, {
276
+ source: string;
277
+ changedFields: Record<string, unknown> | null;
278
+ entityId: string;
279
+ externalId: string;
280
+ provider: string;
281
+ }, {
282
+ source: string;
283
+ changedFields: Record<string, unknown> | null;
284
+ entityId: string;
285
+ externalId: string;
286
+ provider: string;
287
+ }>;
180
288
  readonly stripe_payment_received: z.ZodObject<{
181
289
  amountCents: z.ZodNumber;
182
290
  currency: z.ZodString;
@@ -211,4 +319,4 @@ declare const eventPayloadSchemas: {
211
319
  }>;
212
320
  };
213
321
 
214
- export { contactCreatedPayloadSchema, contactMarkedChampionPayloadSchema, contactMergedPayloadSchema, crmSyncStartedPayloadSchema, dealCreatedPayloadSchema, dealStageChangedPayloadSchema, eventPayloadSchemas, stripePaymentReceivedPayloadSchema, webhookOutboundContactSyncPayloadSchema };
322
+ export { contactCreatedPayloadSchema, contactMarkedChampionPayloadSchema, contactMergedPayloadSchema, crmSyncStartedPayloadSchema, dealCreatedPayloadSchema, dealStageChangedPayloadSchema, eventPayloadSchemas, messageCreatedPayloadSchema, messageDeletedPayloadSchema, messageEditedPayloadSchema, stripePaymentReceivedPayloadSchema, webhookOutboundContactSyncPayloadSchema };
@@ -6,9 +6,12 @@ import {
6
6
  dealCreatedPayloadSchema,
7
7
  dealStageChangedPayloadSchema,
8
8
  eventPayloadSchemas,
9
+ messageCreatedPayloadSchema,
10
+ messageDeletedPayloadSchema,
11
+ messageEditedPayloadSchema,
9
12
  stripePaymentReceivedPayloadSchema,
10
13
  webhookOutboundContactSyncPayloadSchema
11
- } from "../../../../chunk-JRQO2IOF.js";
14
+ } from "../../../../chunk-MU54DZCC.js";
12
15
  import "../../../../chunk-2E224ZSN.js";
13
16
  export {
14
17
  contactCreatedPayloadSchema,
@@ -18,6 +21,9 @@ export {
18
21
  dealCreatedPayloadSchema,
19
22
  dealStageChangedPayloadSchema,
20
23
  eventPayloadSchemas,
24
+ messageCreatedPayloadSchema,
25
+ messageDeletedPayloadSchema,
26
+ messageEditedPayloadSchema,
21
27
  stripePaymentReceivedPayloadSchema,
22
28
  webhookOutboundContactSyncPayloadSchema
23
29
  };
@@ -56,6 +56,52 @@ interface DealStageChangedEvent extends DomainEvent {
56
56
  oldStage: string;
57
57
  };
58
58
  }
59
+ interface MessageCreatedEvent extends DomainEvent {
60
+ readonly type: 'message_created';
61
+ readonly aggregateType: 'message';
62
+ readonly payload: {
63
+ /** Differ's per-field before/after map (same value as integration_run_items.changed_fields). */
64
+ changedFields: Record<string, unknown> | null;
65
+ /** Local aggregate id the sink wrote/soft-deleted. */
66
+ entityId: string;
67
+ /** Vendor external id the change keyed on. */
68
+ externalId: string;
69
+ /** Provider label (e.g. 'slack', 'google'). */
70
+ provider: string;
71
+ /** Provenance marker — always 'integration'. A write-back action reads this to avoid echoing the change back to the vendor. */
72
+ source: string;
73
+ };
74
+ }
75
+ interface MessageDeletedEvent extends DomainEvent {
76
+ readonly type: 'message_deleted';
77
+ readonly aggregateType: 'message';
78
+ readonly payload: {
79
+ /** Local aggregate id the sink wrote/soft-deleted. */
80
+ entityId: string;
81
+ /** Vendor external id the change keyed on. */
82
+ externalId: string;
83
+ /** Provider label (e.g. 'slack', 'google'). */
84
+ provider: string;
85
+ /** Provenance marker — always 'integration'. A write-back action reads this to avoid echoing the change back to the vendor. */
86
+ source: string;
87
+ };
88
+ }
89
+ interface MessageEditedEvent extends DomainEvent {
90
+ readonly type: 'message_edited';
91
+ readonly aggregateType: 'message';
92
+ readonly payload: {
93
+ /** Differ's per-field before/after map (same value as integration_run_items.changed_fields). */
94
+ changedFields: Record<string, unknown> | null;
95
+ /** Local aggregate id the sink wrote/soft-deleted. */
96
+ entityId: string;
97
+ /** Vendor external id the change keyed on. */
98
+ externalId: string;
99
+ /** Provider label (e.g. 'slack', 'google'). */
100
+ provider: string;
101
+ /** Provenance marker — always 'integration'. A write-back action reads this to avoid echoing the change back to the vendor. */
102
+ source: string;
103
+ };
104
+ }
59
105
  /** Stripe charge.succeeded webhook, post-signature-verification. */
60
106
  interface StripePaymentReceivedEvent extends DomainEvent {
61
107
  readonly type: 'stripe_payment_received';
@@ -80,11 +126,11 @@ interface WebhookOutboundContactSyncEvent extends DomainEvent {
80
126
  operation: string;
81
127
  };
82
128
  }
83
- type AppDomainEvent = ContactCreatedEvent | ContactMarkedChampionEvent | ContactMergedEvent | CrmSyncStartedEvent | DealCreatedEvent | DealStageChangedEvent | StripePaymentReceivedEvent | WebhookOutboundContactSyncEvent;
129
+ type AppDomainEvent = ContactCreatedEvent | ContactMarkedChampionEvent | ContactMergedEvent | CrmSyncStartedEvent | DealCreatedEvent | DealStageChangedEvent | MessageCreatedEvent | MessageDeletedEvent | MessageEditedEvent | StripePaymentReceivedEvent | WebhookOutboundContactSyncEvent;
84
130
  type EventTypeName = AppDomainEvent['type'];
85
131
  type EventOfType<T extends EventTypeName> = Extract<AppDomainEvent, {
86
132
  type: T;
87
133
  }>;
88
134
  type PayloadOfType<T extends EventTypeName> = EventOfType<T>['payload'];
89
135
 
90
- export type { AppDomainEvent, ContactCreatedEvent, ContactMarkedChampionEvent, ContactMergedEvent, CrmSyncStartedEvent, DealCreatedEvent, DealStageChangedEvent, EventOfType, EventTypeName, PayloadOfType, StripePaymentReceivedEvent, WebhookOutboundContactSyncEvent };
136
+ export type { AppDomainEvent, ContactCreatedEvent, ContactMarkedChampionEvent, ContactMergedEvent, CrmSyncStartedEvent, DealCreatedEvent, DealStageChangedEvent, EventOfType, EventTypeName, MessageCreatedEvent, MessageDeletedEvent, MessageEditedEvent, PayloadOfType, StripePaymentReceivedEvent, WebhookOutboundContactSyncEvent };
@@ -2,12 +2,12 @@ import "../../../chunk-SYVZ4MD2.js";
2
2
  import {
3
3
  EventSchedulerLifecycle,
4
4
  EventsModule
5
- } from "../../../chunk-42763UEE.js";
5
+ } from "../../../chunk-6M6LZEP6.js";
6
6
  import {
7
7
  TypedEventBus
8
- } from "../../../chunk-INO47JXD.js";
9
- import "../../../chunk-JOBQ6RUU.js";
10
- import "../../../chunk-JRQO2IOF.js";
8
+ } from "../../../chunk-PBENHIN2.js";
9
+ import "../../../chunk-LQZESSM3.js";
10
+ import "../../../chunk-MU54DZCC.js";
11
11
  import {
12
12
  EventScheduler,
13
13
  SCHEDULE_FLOOR_MS,
@@ -1,5 +1,5 @@
1
1
  export { DomainEvent, DrizzleTransaction, IEventBus } from './events/event-bus.protocol.js';
2
- export { EVENT_BUS } from './events/events.tokens.js';
2
+ export { EVENT_BUS, TYPED_EVENT_BUS } from './events/events.tokens.js';
3
3
  export { EventsModule } from './events/events.module.js';
4
4
  export { MemoryEventBus } from './events/event-bus.memory-backend.js';
5
5
  export { DrizzleEventBus } from './events/event-bus.drizzle-backend.js';
@@ -22,6 +22,7 @@ export { ObservabilityError } from './observability/observability-errors.js';
22
22
  export { IChangeSource, IntegrationSubscriptionView } from './integration/integration-change-source.protocol.js';
23
23
  export { CursorSnapshot } from './integration/integration-cursor-store.protocol.js';
24
24
  export { IIntegrationSink } from './integration/integration-sink.protocol.js';
25
+ export { IIntegrationChangeEmitter, IntegrationChangeAction, IntegrationChangeNotification } from './integration/integration-change-emitter.protocol.js';
25
26
  export { IntegrationRunSummary } from './integration/integration-run-recorder.protocol.js';
26
27
  export { IEntityChangeSourceRegistry, UnknownEntityError } from './integration/entity-change-source-registry.protocol.js';
27
28
  export { MemoryEntityChangeSourceRegistry } from './integration/entity-change-source-registry.memory.js';
@@ -30,7 +31,7 @@ export { PollChangeSource, PollChangeSourceOptions, PollCursor, PollFetchCallbac
30
31
  export { IncrementalRead, IncrementalReadBase, RandomRead, ReadContext, ReadMode, ReadRequest, Ref, SourcedRecord, mapConcurrent } from './integration/incremental-read.js';
31
32
  export { WebhookChangeSource, WebhookChangeSourceOptions, WebhookCursor, WebhookFetchCallback, WebhookFetchContext } from './integration/webhook-change-source.js';
32
33
  export { buildChangeSource } from './integration/build-change-source.js';
33
- export { ENTITY_CHANGE_SOURCE_REGISTRY, INTEGRATION_CHANGE_SOURCE, INTEGRATION_SINK } from './integration/integration.tokens.js';
34
+ export { ENTITY_CHANGE_SOURCE_REGISTRY, INTEGRATION_CHANGE_EMITTER, INTEGRATION_CHANGE_SOURCE, INTEGRATION_SINK } from './integration/integration.tokens.js';
34
35
  export { ExecuteIntegrationUseCase } from './integration/execute-integration.use-case.js';
35
36
  export { AuthCredentials, AuthResolveOptions, IAuthStrategy } from './auth/protocols/auth-strategy.js';
36
37
  export { IEncryptionKey } from './auth/protocols/encryption-key.js';
@@ -1,3 +1,4 @@
1
+ import "../../chunk-W4HOHZVF.js";
1
2
  import "../../chunk-ZUMULSEQ.js";
2
3
  import {
3
4
  StorageModule
@@ -19,21 +20,20 @@ import {
19
20
  } from "../../chunk-EWYCWP4H.js";
20
21
  import {
21
22
  ObservabilityModule
22
- } from "../../chunk-XKWOJZZ4.js";
23
+ } from "../../chunk-37PILMIT.js";
23
24
  import "../../chunk-AQFQ4BYM.js";
24
- import "../../chunk-CLWBNXKF.js";
25
25
  import {
26
26
  OBSERVABILITY,
27
27
  OBSERVABILITY_MODULE_OPTIONS
28
28
  } from "../../chunk-Y7RRSEOC.js";
29
- import "../../chunk-W4HOHZVF.js";
29
+ import "../../chunk-PLUJEQLU.js";
30
30
  import "../../chunk-SYVZ4MD2.js";
31
31
  import {
32
32
  EventsModule
33
- } from "../../chunk-42763UEE.js";
34
- import "../../chunk-INO47JXD.js";
35
- import "../../chunk-JOBQ6RUU.js";
36
- import "../../chunk-JRQO2IOF.js";
33
+ } from "../../chunk-6M6LZEP6.js";
34
+ import "../../chunk-PBENHIN2.js";
35
+ import "../../chunk-LQZESSM3.js";
36
+ import "../../chunk-MU54DZCC.js";
37
37
  import "../../chunk-DUUCU77W.js";
38
38
  import "../../chunk-DUBZOXJC.js";
39
39
  import "../../chunk-IWAOY6KC.js";
@@ -57,25 +57,26 @@ import {
57
57
  import {
58
58
  CACHE
59
59
  } from "../../chunk-L6FTY45T.js";
60
- import "../../chunk-SH76CFAY.js";
60
+ import "../../chunk-ENAR3F5S.js";
61
61
  import "../../chunk-7B7MMDOJ.js";
62
- import "../../chunk-FIUC6QB5.js";
63
- import "../../chunk-VQOAATIG.js";
62
+ import "../../chunk-CKLM57IE.js";
64
63
  import "../../chunk-3VEVGL74.js";
65
64
  import "../../chunk-CDLWYZVQ.js";
66
65
  import "../../chunk-L3LZWWSX.js";
67
66
  import "../../chunk-DV4RV2DC.js";
68
- import "../../chunk-PNZSGAB2.js";
69
- import "../../chunk-SNQ3TOWP.js";
70
67
  import "../../chunk-I6MVCB5A.js";
71
68
  import "../../chunk-RHVN6NA7.js";
72
69
  import "../../chunk-E6PLM6QG.js";
70
+ import "../../chunk-VQOAATIG.js";
71
+ import "../../chunk-PNZSGAB2.js";
72
+ import "../../chunk-SNQ3TOWP.js";
73
73
  import "../../chunk-T4BIIU5E.js";
74
74
  import "../../chunk-Q6LRJ4VI.js";
75
75
  import "../../chunk-7P5ODGLA.js";
76
76
  import "../../chunk-ZPL74UQN.js";
77
77
  import {
78
- EVENT_BUS
78
+ EVENT_BUS,
79
+ TYPED_EVENT_BUS
79
80
  } from "../../chunk-H5NH7KPE.js";
80
81
  import "../../chunk-4LH67P4U.js";
81
82
  import {
@@ -119,12 +120,12 @@ import {
119
120
  import {
120
121
  MemoryOAuthStateStore
121
122
  } from "../../chunk-QLTJSCE6.js";
122
- import {
123
- OAuthStateError
124
- } from "../../chunk-BPARRK6F.js";
125
123
  import {
126
124
  AuthController
127
125
  } from "../../chunk-SZVPIHWE.js";
126
+ import {
127
+ OAuthStateError
128
+ } from "../../chunk-BPARRK6F.js";
128
129
  import {
129
130
  authOAuthState
130
131
  } from "../../chunk-NPFPZ2HO.js";
@@ -140,11 +141,11 @@ import {
140
141
  } from "../../chunk-6XY6ZMMD.js";
141
142
  import "../../chunk-GYGNEQSC.js";
142
143
  import "../../chunk-KVOWSC5S.js";
143
- import "../../chunk-QFUIE37H.js";
144
- import "../../chunk-FFUDEIFF.js";
145
- import "../../chunk-EO2QPOKH.js";
146
144
  import "../../chunk-PRWIX6UW.js";
147
- import "../../chunk-O2A6XHGD.js";
145
+ import "../../chunk-KFXXOFDC.js";
146
+ import "../../chunk-HN5HT5WL.js";
147
+ import "../../chunk-EO2QPOKH.js";
148
+ import "../../chunk-LLDJS7PJ.js";
148
149
  import "../../chunk-HNWZFNKP.js";
149
150
  import "../../chunk-AHV4GDYM.js";
150
151
  import "../../chunk-SQDOBLBP.js";
@@ -171,12 +172,13 @@ import {
171
172
  } from "../../chunk-3CJFPU6Q.js";
172
173
  import {
173
174
  ExecuteIntegrationUseCase
174
- } from "../../chunk-TDEHU73T.js";
175
+ } from "../../chunk-YIVQ7KLS.js";
175
176
  import {
176
177
  ENTITY_CHANGE_SOURCE_REGISTRY,
178
+ INTEGRATION_CHANGE_EMITTER,
177
179
  INTEGRATION_CHANGE_SOURCE,
178
180
  INTEGRATION_SINK
179
- } from "../../chunk-S7C6TIIF.js";
181
+ } from "../../chunk-S5G3HO7N.js";
180
182
  import "../../chunk-MZ6GV4YF.js";
181
183
  import {
182
184
  IncrementalReadBase,
@@ -207,6 +209,7 @@ export {
207
209
  EnvEncryptionKey,
208
210
  EventsModule,
209
211
  ExecuteIntegrationUseCase,
212
+ INTEGRATION_CHANGE_EMITTER,
210
213
  INTEGRATION_CHANGE_SOURCE,
211
214
  INTEGRATION_SINK,
212
215
  IncrementalReadBase,
@@ -228,6 +231,7 @@ export {
228
231
  STRATEGY_REGISTRY,
229
232
  SessionExpiredError,
230
233
  StorageModule,
234
+ TYPED_EVENT_BUS,
231
235
  UnknownEntityError,
232
236
  WebhookChangeSource,
233
237
  authOAuthState,
@@ -3,6 +3,7 @@ import { ICursorStore } from './integration-cursor-store.protocol.js';
3
3
  import { IFieldDiffer } from './integration-field-diff.protocol.js';
4
4
  import { IIntegrationSink } from './integration-sink.protocol.js';
5
5
  import { IIntegrationRunRecorder } from './integration-run-recorder.protocol.js';
6
+ import { IIntegrationChangeEmitter } from './integration-change-emitter.protocol.js';
6
7
  import 'zod';
7
8
 
8
9
  interface ExecuteIntegrationInput<T> {
@@ -47,10 +48,19 @@ declare class ExecuteIntegrationUseCase<T extends Record<string, unknown>> {
47
48
  private readonly sink;
48
49
  private readonly recorder;
49
50
  private readonly multiTenant;
51
+ private readonly emitter;
50
52
  private readonly logger;
51
- constructor(source: IChangeSource<T>, cursors: ICursorStore, differ: IFieldDiffer<T>, sink: IIntegrationSink<T>, recorder: IIntegrationRunRecorder, multiTenant?: boolean);
53
+ constructor(source: IChangeSource<T>, cursors: ICursorStore, differ: IFieldDiffer<T>, sink: IIntegrationSink<T>, recorder: IIntegrationRunRecorder, multiTenant?: boolean, emitter?: IIntegrationChangeEmitter | null);
52
54
  execute(input: ExecuteIntegrationInput<T>): Promise<ExecuteIntegrationResult>;
53
55
  private processChange;
56
+ /**
57
+ * Publish one typed data-level change event via the optional emitter
58
+ * (EMIT-CHANGES seam). No-op when no emitter is bound (the back-compat
59
+ * default). A failed publish is logged but never aborts the run — the row is
60
+ * already written; emission is best-effort (the outbox tx, when the generated
61
+ * adapter rides on one, gives the at-least-once guarantee, not this try/catch).
62
+ */
63
+ private emitChange;
54
64
  }
55
65
 
56
66
  export { type ExecuteIntegrationInput, type ExecuteIntegrationResult, ExecuteIntegrationUseCase };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ExecuteIntegrationUseCase
3
- } from "../../../chunk-TDEHU73T.js";
4
- import "../../../chunk-S7C6TIIF.js";
3
+ } from "../../../chunk-YIVQ7KLS.js";
4
+ import "../../../chunk-S5G3HO7N.js";
5
5
  import "../../../chunk-MZ6GV4YF.js";
6
6
  import "../../../chunk-2E224ZSN.js";
7
7
  export {
@@ -2,6 +2,7 @@ export { Change, ChangeSource, IChangeSource, IntegrationSubscriptionView } from
2
2
  export { CursorSnapshot, ICursorStore } from './integration-cursor-store.protocol.js';
3
3
  export { DiffResult, FieldDiff, FieldDiffSchema, FieldDiffValue, FieldDiffValueSchema, IFieldDiffer } from './integration-field-diff.protocol.js';
4
4
  export { IIntegrationSink } from './integration-sink.protocol.js';
5
+ export { IIntegrationChangeEmitter, IntegrationChangeAction, IntegrationChangeNotification } from './integration-change-emitter.protocol.js';
5
6
  export { CompleteRunInput, IIntegrationRunRecorder, IntegrationRunSummary, RecordItemInput, StartRunInput } from './integration-run-recorder.protocol.js';
6
7
  export { ILoopbackFingerprintStore } from './integration-loopback.protocol.js';
7
8
  export { IEntityChangeSourceRegistry, UnknownEntityError } from './entity-change-source-registry.protocol.js';
@@ -13,7 +14,7 @@ export { PollChangeSource, PollChangeSourceOptions, PollCursor, PollFetchCallbac
13
14
  export { IncrementalRead, IncrementalReadBase, RandomRead, ReadContext, ReadMode, ReadRequest, Ref, SourcedRecord, mapConcurrent } from './incremental-read.js';
14
15
  export { WebhookChangeSource, WebhookChangeSourceOptions, WebhookCursor, WebhookFetchCallback, WebhookFetchContext } from './webhook-change-source.js';
15
16
  export { buildChangeSource } from './build-change-source.js';
16
- export { ENTITY_CHANGE_SOURCE_REGISTRY, INTEGRATION_CHANGE_SOURCE, INTEGRATION_CURSOR_STORE, INTEGRATION_FIELD_DIFFER, INTEGRATION_MODULE_OPTIONS, INTEGRATION_MULTI_TENANT, INTEGRATION_RUN_RECORDER, INTEGRATION_SINK } from './integration.tokens.js';
17
+ export { ENTITY_CHANGE_SOURCE_REGISTRY, INTEGRATION_CHANGE_EMITTER, INTEGRATION_CHANGE_SOURCE, INTEGRATION_CURSOR_STORE, INTEGRATION_FIELD_DIFFER, INTEGRATION_MODULE_OPTIONS, INTEGRATION_MULTI_TENANT, INTEGRATION_RUN_RECORDER, INTEGRATION_SINK } from './integration.tokens.js';
17
18
  export { MissingTenantIdError, assertTenantId } from './integration-errors.js';
18
19
  export { IntegrationRunItemRow, IntegrationRunRow, IntegrationSubscriptionRow, integrationRunActionEnum, integrationRunDirectionEnum, integrationRunItemOperationEnum, integrationRunItemStatusEnum, integrationRunItems, integrationRunStatusEnum, integrationRuns, integrationSubscriptions } from './integration-audit.schema.js';
19
20
  export { MemoryCursorStore } from './integration-cursor-store.memory-backend.js';
@@ -1,19 +1,19 @@
1
1
  import "../../../chunk-KVOWSC5S.js";
2
+ import {
3
+ createLoopbackMiddleware
4
+ } from "../../../chunk-PRWIX6UW.js";
2
5
  import {
3
6
  IntegrationModule
4
- } from "../../../chunk-QFUIE37H.js";
7
+ } from "../../../chunk-KFXXOFDC.js";
5
8
  import {
6
9
  DrizzleIntegrationRunRecorder
7
- } from "../../../chunk-FFUDEIFF.js";
10
+ } from "../../../chunk-HN5HT5WL.js";
8
11
  import {
9
12
  MemoryRunRecorder
10
13
  } from "../../../chunk-EO2QPOKH.js";
11
- import {
12
- createLoopbackMiddleware
13
- } from "../../../chunk-PRWIX6UW.js";
14
14
  import {
15
15
  PostgresCursorStore
16
- } from "../../../chunk-O2A6XHGD.js";
16
+ } from "../../../chunk-LLDJS7PJ.js";
17
17
  import {
18
18
  integrationRunActionEnum,
19
19
  integrationRunDirectionEnum,
@@ -61,9 +61,10 @@ import {
61
61
  } from "../../../chunk-3CJFPU6Q.js";
62
62
  import {
63
63
  ExecuteIntegrationUseCase
64
- } from "../../../chunk-TDEHU73T.js";
64
+ } from "../../../chunk-YIVQ7KLS.js";
65
65
  import {
66
66
  ENTITY_CHANGE_SOURCE_REGISTRY,
67
+ INTEGRATION_CHANGE_EMITTER,
67
68
  INTEGRATION_CHANGE_SOURCE,
68
69
  INTEGRATION_CURSOR_STORE,
69
70
  INTEGRATION_FIELD_DIFFER,
@@ -71,7 +72,7 @@ import {
71
72
  INTEGRATION_MULTI_TENANT,
72
73
  INTEGRATION_RUN_RECORDER,
73
74
  INTEGRATION_SINK
74
- } from "../../../chunk-S7C6TIIF.js";
75
+ } from "../../../chunk-S5G3HO7N.js";
75
76
  import {
76
77
  MissingTenantIdError,
77
78
  assertTenantId
@@ -93,6 +94,7 @@ export {
93
94
  FieldDiffSchema,
94
95
  FieldDiffValueSchema,
95
96
  FieldMappingSchema,
97
+ INTEGRATION_CHANGE_EMITTER,
96
98
  INTEGRATION_CHANGE_SOURCE,
97
99
  INTEGRATION_CURSOR_STORE,
98
100
  INTEGRATION_FIELD_DIFFER,
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Integration subsystem — change-emitter protocol (port).
3
+ *
4
+ * `IIntegrationChangeEmitter` is the OPT-IN seam through which the generic
5
+ * orchestrator (`ExecuteIntegrationUseCase`) publishes a typed, data-level
6
+ * domain event after every sink write/soft-delete. It is the upstream-generalized
7
+ * form of the per-sink event emission swe-brain hand-built (ADR-0009 Amendment B):
8
+ * the differ already records `changed_fields` on `integration_run_items`, but
9
+ * nothing publishes a "this entity changed" domain event for downstream
10
+ * trigger→action consumers. This port closes that gap.
11
+ *
12
+ * ## Why a port (not a direct TypedEventBus call in the orchestrator)
13
+ *
14
+ * The orchestrator is strictly provider- AND entity-agnostic: `entityType` is a
15
+ * bare `string` and the canonical record is generic `T` (see the use-case header
16
+ * "No CRM bleed"). It therefore cannot know the typed event NAME
17
+ * (`<entity>_created`) or the typed payload shape at compile time. The typed
18
+ * knowledge lives at the per-entity assembly wiring (codegen knows the entity
19
+ * name there). So the orchestrator depends on this thin, untyped port; codegen
20
+ * binds a per-entity adapter that maps `(operation) → <entity>_<verb>` and calls
21
+ * the project's generated `TypedEventBus.publish(...)` with the typed payload.
22
+ *
23
+ * ## Backwards compatibility
24
+ *
25
+ * The port is `@Optional()` on the orchestrator. Entities that do NOT opt in
26
+ * (`integration.sink.emit_changes` absent/false) bind no emitter, so the
27
+ * orchestrator's `this.emitter` is `undefined` and NOTHING is published — zero
28
+ * behavior change. This is the invariant the snapshot fixture (which opts none
29
+ * in) keeps green.
30
+ *
31
+ * ## Provenance — loop-breaking
32
+ *
33
+ * Every emitted event carries `source: 'integration'` in its payload. A future
34
+ * write-back action (the Intervention layer in swe-brain terms) that subscribes
35
+ * to these events can detect `source === 'integration'` and decline to echo the
36
+ * change back to the vendor, breaking the inbound→writeback→inbound loop. This
37
+ * is the data-layer counterpart of the loopback middleware that already guards
38
+ * the read side (`createLoopbackMiddleware`).
39
+ *
40
+ * ## Transactionality
41
+ *
42
+ * `emitChange` receives the same `tx` the sink wrote under (when the sink exposes
43
+ * one — today the sink owns its own transaction internally, so `tx` is reserved
44
+ * for the future where the orchestrator drives the transaction). The generated
45
+ * adapter forwards `tx` into `TypedEventBus.publish(type, id, payload, { tx })`,
46
+ * so the event lands in the outbox iff the row commits (the events subsystem's
47
+ * outbox guarantee). When `tx` is absent the publish is post-commit best-effort,
48
+ * matching today's sink-owns-its-own-transaction reality.
49
+ */
50
+ /** The data-level action the orchestrator observed. Maps onto the generated
51
+ * event verb: `created → <entity>_created`, `updated → <entity>_edited`
52
+ * (per swe-brain ADR-0009 B1 — `_edited`, never `_updated`),
53
+ * `deleted → <entity>_deleted` (tombstone soft-delete). `noop` never emits. */
54
+ type IntegrationChangeAction = 'created' | 'updated' | 'deleted';
55
+ /**
56
+ * The vendor-blind change descriptor the orchestrator hands the emitter. The
57
+ * generated adapter reshapes this into the typed `<entity>_<verb>` payload
58
+ * (`{ entityId, externalId, provider, changedFields?, source: 'integration' }`).
59
+ */
60
+ interface IntegrationChangeNotification {
61
+ /** The local row id the sink wrote/soft-deleted (the domain aggregate id —
62
+ * becomes `aggregateId` on the published event AND `entityId` in the payload). */
63
+ readonly entityId: string;
64
+ /** Vendor-prefixed-or-bare external id the change keyed on (e.g. `slack:123`). */
65
+ readonly externalId: string;
66
+ /** Provider label from `ExecuteIntegrationInput.provider` (e.g. `'slack'`). */
67
+ readonly provider: string;
68
+ /** The observed action. `created`/`updated` come from the existing-row check;
69
+ * `deleted` from the soft-delete path. */
70
+ readonly action: IntegrationChangeAction;
71
+ /** The differ's structured per-field before/after map (the same value written
72
+ * to `integration_run_items.changed_fields`). Absent on deletes. */
73
+ readonly changedFields?: Record<string, unknown>;
74
+ /** Multi-tenant deployments thread the tenant id through to the event metadata. */
75
+ readonly tenantId?: string | null;
76
+ /** The transaction the sink wrote under, when the orchestrator drives one.
77
+ * Forwarded to `TypedEventBus.publish(..., { tx })` for the outbox guarantee.
78
+ * Reserved: today the sink owns its own transaction, so this is usually
79
+ * `undefined` and the publish is post-commit. Typed `unknown` here so the
80
+ * port stays free of a Drizzle type dependency (the generated adapter narrows). */
81
+ readonly tx?: unknown;
82
+ }
83
+ /**
84
+ * Post-upsert change-event emission port.
85
+ *
86
+ * One implementation per opted-in (entity, provider) assembly — codegen-emitted,
87
+ * bound to `INTEGRATION_CHANGE_EMITTER` in that assembly module. The orchestrator
88
+ * injects it `@Optional()`; an unbound token means no emission (back-compat).
89
+ */
90
+ interface IIntegrationChangeEmitter {
91
+ /**
92
+ * Publish the typed `<entity>_<verb>` domain event for one observed change.
93
+ *
94
+ * MUST be called only for real changes — the orchestrator never calls this on
95
+ * a `noop` diff (canonical state unchanged) or a delete that hit no local row
96
+ * (no tombstone created). Implementations should treat a call as "this thing
97
+ * happened" and publish unconditionally.
98
+ *
99
+ * Errors are the orchestrator's concern: it wraps the call so a failed publish
100
+ * does not abort the run (the row is already written; emission is best-effort
101
+ * unless ridden on the outbox tx). See `ExecuteIntegrationUseCase.processChange`.
102
+ */
103
+ emitChange(notification: IntegrationChangeNotification): Promise<void>;
104
+ }
105
+
106
+ export type { IIntegrationChangeEmitter, IntegrationChangeAction, IntegrationChangeNotification };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=integration-change-emitter.protocol.js.map