@campfire-interactive/platform-events 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/envelope.d.ts +14 -14
- package/dist/envelope.js +1 -0
- package/dist/events/notifications.d.ts +45 -0
- package/dist/events/notifications.js +20 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -1
- package/dist/publisher.d.ts +13 -0
- package/dist/publisher.js +49 -0
- package/package.json +30 -30
package/dist/envelope.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ import { z } from 'zod';
|
|
|
14
14
|
* union — hyphenated `master-data`, settled at ratification (plan
|
|
15
15
|
* decision 3; the ADR uses this spelling).
|
|
16
16
|
*/
|
|
17
|
-
export declare const PRODUCERS: readonly ["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"];
|
|
18
|
-
export declare const producerSchema: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>;
|
|
17
|
+
export declare const PRODUCERS: readonly ["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"];
|
|
18
|
+
export declare const producerSchema: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>;
|
|
19
19
|
export type Producer = z.infer<typeof producerSchema>;
|
|
20
20
|
export declare const ENVELOPE_SCHEMA_VERSION: 2;
|
|
21
21
|
/** Envelope with an unvalidated payload — use `envelopeFor(schema)` when the payload shape is known. */
|
|
@@ -25,7 +25,7 @@ export declare const envelopeSchema: z.ZodObject<{
|
|
|
25
25
|
eventId: z.ZodString;
|
|
26
26
|
/** ISO-8601 instant the state change committed at the producer */
|
|
27
27
|
occurredAt: z.ZodString;
|
|
28
|
-
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>;
|
|
28
|
+
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>;
|
|
29
29
|
/** = EventBridge detail-type, `<entity>.<action>` (or `<verb>.<noun>` for commands) */
|
|
30
30
|
type: z.ZodString;
|
|
31
31
|
entityType: z.ZodString;
|
|
@@ -43,7 +43,7 @@ export declare const envelopeSchema: z.ZodObject<{
|
|
|
43
43
|
/** acting user, when the change was user-initiated */
|
|
44
44
|
userId: z.ZodOptional<z.ZodString>;
|
|
45
45
|
/** commands only: the app whose inbox this is routed to */
|
|
46
|
-
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>>;
|
|
46
|
+
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>>;
|
|
47
47
|
/** commands only: async request/reply correlation */
|
|
48
48
|
correlationId: z.ZodOptional<z.ZodString>;
|
|
49
49
|
/** commands only: sender's inbox identifier for the reply */
|
|
@@ -65,14 +65,14 @@ export declare const envelopeSchema: z.ZodObject<{
|
|
|
65
65
|
schemaVersion: 2;
|
|
66
66
|
eventId: string;
|
|
67
67
|
occurredAt: string;
|
|
68
|
-
producer: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity";
|
|
68
|
+
producer: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity" | "notifications";
|
|
69
69
|
entityType: string;
|
|
70
70
|
entityId: string;
|
|
71
71
|
tenantId: string | null;
|
|
72
72
|
traceId: string;
|
|
73
73
|
entityVersion?: number | undefined;
|
|
74
74
|
userId?: string | undefined;
|
|
75
|
-
recipient?: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity" | undefined;
|
|
75
|
+
recipient?: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity" | "notifications" | undefined;
|
|
76
76
|
correlationId?: string | undefined;
|
|
77
77
|
replyTo?: string | undefined;
|
|
78
78
|
sagaId?: string | undefined;
|
|
@@ -85,14 +85,14 @@ export declare const envelopeSchema: z.ZodObject<{
|
|
|
85
85
|
schemaVersion: 2;
|
|
86
86
|
eventId: string;
|
|
87
87
|
occurredAt: string;
|
|
88
|
-
producer: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity";
|
|
88
|
+
producer: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity" | "notifications";
|
|
89
89
|
entityType: string;
|
|
90
90
|
entityId: string;
|
|
91
91
|
tenantId: string | null;
|
|
92
92
|
traceId: string;
|
|
93
93
|
entityVersion?: number | undefined;
|
|
94
94
|
userId?: string | undefined;
|
|
95
|
-
recipient?: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity" | undefined;
|
|
95
|
+
recipient?: "master-data" | "cpq" | "omsf" | "pim" | "erfq" | "forecast" | "identity" | "notifications" | undefined;
|
|
96
96
|
correlationId?: string | undefined;
|
|
97
97
|
replyTo?: string | undefined;
|
|
98
98
|
sagaId?: string | undefined;
|
|
@@ -111,7 +111,7 @@ export declare function envelopeFor<TSchema extends z.ZodTypeAny>(payload: TSche
|
|
|
111
111
|
eventId: z.ZodString;
|
|
112
112
|
/** ISO-8601 instant the state change committed at the producer */
|
|
113
113
|
occurredAt: z.ZodString;
|
|
114
|
-
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>;
|
|
114
|
+
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>;
|
|
115
115
|
/** = EventBridge detail-type, `<entity>.<action>` (or `<verb>.<noun>` for commands) */
|
|
116
116
|
type: z.ZodString;
|
|
117
117
|
entityType: z.ZodString;
|
|
@@ -129,7 +129,7 @@ export declare function envelopeFor<TSchema extends z.ZodTypeAny>(payload: TSche
|
|
|
129
129
|
/** acting user, when the change was user-initiated */
|
|
130
130
|
userId: z.ZodOptional<z.ZodString>;
|
|
131
131
|
/** commands only: the app whose inbox this is routed to */
|
|
132
|
-
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>>;
|
|
132
|
+
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>>;
|
|
133
133
|
/** commands only: async request/reply correlation */
|
|
134
134
|
correlationId: z.ZodOptional<z.ZodString>;
|
|
135
135
|
/** commands only: sender's inbox identifier for the reply */
|
|
@@ -152,7 +152,7 @@ export declare function envelopeFor<TSchema extends z.ZodTypeAny>(payload: TSche
|
|
|
152
152
|
eventId: z.ZodString;
|
|
153
153
|
/** ISO-8601 instant the state change committed at the producer */
|
|
154
154
|
occurredAt: z.ZodString;
|
|
155
|
-
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>;
|
|
155
|
+
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>;
|
|
156
156
|
/** = EventBridge detail-type, `<entity>.<action>` (or `<verb>.<noun>` for commands) */
|
|
157
157
|
type: z.ZodString;
|
|
158
158
|
entityType: z.ZodString;
|
|
@@ -170,7 +170,7 @@ export declare function envelopeFor<TSchema extends z.ZodTypeAny>(payload: TSche
|
|
|
170
170
|
/** acting user, when the change was user-initiated */
|
|
171
171
|
userId: z.ZodOptional<z.ZodString>;
|
|
172
172
|
/** commands only: the app whose inbox this is routed to */
|
|
173
|
-
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>>;
|
|
173
|
+
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>>;
|
|
174
174
|
/** commands only: async request/reply correlation */
|
|
175
175
|
correlationId: z.ZodOptional<z.ZodString>;
|
|
176
176
|
/** commands only: sender's inbox identifier for the reply */
|
|
@@ -193,7 +193,7 @@ export declare function envelopeFor<TSchema extends z.ZodTypeAny>(payload: TSche
|
|
|
193
193
|
eventId: z.ZodString;
|
|
194
194
|
/** ISO-8601 instant the state change committed at the producer */
|
|
195
195
|
occurredAt: z.ZodString;
|
|
196
|
-
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>;
|
|
196
|
+
producer: z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>;
|
|
197
197
|
/** = EventBridge detail-type, `<entity>.<action>` (or `<verb>.<noun>` for commands) */
|
|
198
198
|
type: z.ZodString;
|
|
199
199
|
entityType: z.ZodString;
|
|
@@ -211,7 +211,7 @@ export declare function envelopeFor<TSchema extends z.ZodTypeAny>(payload: TSche
|
|
|
211
211
|
/** acting user, when the change was user-initiated */
|
|
212
212
|
userId: z.ZodOptional<z.ZodString>;
|
|
213
213
|
/** commands only: the app whose inbox this is routed to */
|
|
214
|
-
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity"]>>;
|
|
214
|
+
recipient: z.ZodOptional<z.ZodEnum<["master-data", "cpq", "omsf", "pim", "erfq", "forecast", "identity", "notifications"]>>;
|
|
215
215
|
/** commands only: async request/reply correlation */
|
|
216
216
|
correlationId: z.ZodOptional<z.ZodString>;
|
|
217
217
|
/** commands only: sender's inbox identifier for the reply */
|
package/dist/envelope.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* platform-notifications event catalog — owned by the platform-notifications
|
|
4
|
+
* team (ADR §10). Emitted when a non-email (in-app / bell) notification is
|
|
5
|
+
* created, so the recipient's shell-header bell updates in real time
|
|
6
|
+
* instead of waiting for its poll.
|
|
7
|
+
*
|
|
8
|
+
* SECURITY — payload is deliberately MINIMAL. It carries NO title/body:
|
|
9
|
+
* the event only signals "you have a new notification (id/type)", and the
|
|
10
|
+
* browser fetches the content over the user-scoped REST endpoint
|
|
11
|
+
* (`/v1/notifications/me`). Notification content never travels on the bus,
|
|
12
|
+
* so the realtime path can't leak it. See
|
|
13
|
+
* `platform-notifications/docs/plans/2026-06-25-realtime-notification-delivery.md`.
|
|
14
|
+
*
|
|
15
|
+
* Routing note: the envelope's `userId` is the RECIPIENT (not an actor),
|
|
16
|
+
* which is exactly the audience a notification needs — the socket fanout
|
|
17
|
+
* routes notification events to the recipient's user topic ONLY (never a
|
|
18
|
+
* tenant-scoped resource topic). `tenantId` is nullable: a null tenant is
|
|
19
|
+
* a platform-level notification (no realtime in v1 — poll fallback).
|
|
20
|
+
*/
|
|
21
|
+
export interface NotificationEventDef<TSchema extends z.ZodTypeAny = z.ZodTypeAny> {
|
|
22
|
+
entityType: string;
|
|
23
|
+
/** payload field holding the notification's id */
|
|
24
|
+
entityIdField: string;
|
|
25
|
+
payload: TSchema;
|
|
26
|
+
}
|
|
27
|
+
export declare const notificationEvents: {
|
|
28
|
+
readonly 'notification.created': NotificationEventDef<z.ZodObject<{
|
|
29
|
+
notificationId: z.ZodString;
|
|
30
|
+
/** the notification's stable type, e.g. "rfq.new_response" */
|
|
31
|
+
type: z.ZodString;
|
|
32
|
+
/** the app that emitted it */
|
|
33
|
+
source: z.ZodString;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
type: string;
|
|
36
|
+
notificationId: string;
|
|
37
|
+
source: string;
|
|
38
|
+
}, {
|
|
39
|
+
type: string;
|
|
40
|
+
notificationId: string;
|
|
41
|
+
source: string;
|
|
42
|
+
}>>;
|
|
43
|
+
};
|
|
44
|
+
export type NotificationEventType = keyof typeof notificationEvents;
|
|
45
|
+
export type NotificationPayload<T extends NotificationEventType> = z.infer<(typeof notificationEvents)[T]['payload']>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.notificationEvents = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
function defineEvent(def) {
|
|
6
|
+
return def;
|
|
7
|
+
}
|
|
8
|
+
exports.notificationEvents = {
|
|
9
|
+
'notification.created': defineEvent({
|
|
10
|
+
entityType: 'notification',
|
|
11
|
+
entityIdField: 'notificationId',
|
|
12
|
+
payload: zod_1.z.object({
|
|
13
|
+
notificationId: zod_1.z.string(),
|
|
14
|
+
/** the notification's stable type, e.g. "rfq.new_response" */
|
|
15
|
+
type: zod_1.z.string(),
|
|
16
|
+
/** the app that emitted it */
|
|
17
|
+
source: zod_1.z.string(),
|
|
18
|
+
}),
|
|
19
|
+
}),
|
|
20
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export { ENVELOPE_SCHEMA_VERSION, PRODUCERS, envelopeFor, envelopeSchema, produc
|
|
|
2
2
|
export type { Envelope, Producer } from './envelope';
|
|
3
3
|
export { masterDataEvents } from './events/master-data';
|
|
4
4
|
export type { EventDef, MasterDataEventType, MasterDataPayload } from './events/master-data';
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
5
|
+
export { notificationEvents } from './events/notifications';
|
|
6
|
+
export type { NotificationEventDef, NotificationEventType, NotificationPayload, } from './events/notifications';
|
|
7
|
+
export { buildMasterDataEnvelope, buildNotificationEnvelope, configurePublisher, publishMasterDataEvent, publishNotificationEvent, sendCommand, } from './publisher';
|
|
8
|
+
export type { NotificationPublishContext, PublishContext, PublisherConfig, SendCommandContext, } from './publisher';
|
|
7
9
|
export { isMasterDataEventType, parseEnvelope, parseMasterDataEvent } from './consumer';
|
|
8
10
|
export type { MasterDataEvent } from './consumer';
|
|
9
11
|
export { DynamoDbDedupStore, isReplay, withIdempotency } from './dedup';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startSaga = exports.publishCompensation = exports.childContext = exports.toOutboxRecord = exports.relayOutbox = exports.withIdempotency = exports.isReplay = exports.DynamoDbDedupStore = exports.parseMasterDataEvent = exports.parseEnvelope = exports.isMasterDataEventType = exports.sendCommand = exports.publishMasterDataEvent = exports.configurePublisher = exports.buildMasterDataEnvelope = exports.masterDataEvents = exports.producerSchema = exports.envelopeSchema = exports.envelopeFor = exports.PRODUCERS = exports.ENVELOPE_SCHEMA_VERSION = void 0;
|
|
3
|
+
exports.startSaga = exports.publishCompensation = exports.childContext = exports.toOutboxRecord = exports.relayOutbox = exports.withIdempotency = exports.isReplay = exports.DynamoDbDedupStore = exports.parseMasterDataEvent = exports.parseEnvelope = exports.isMasterDataEventType = exports.sendCommand = exports.publishNotificationEvent = exports.publishMasterDataEvent = exports.configurePublisher = exports.buildNotificationEnvelope = exports.buildMasterDataEnvelope = exports.notificationEvents = exports.masterDataEvents = exports.producerSchema = exports.envelopeSchema = exports.envelopeFor = exports.PRODUCERS = exports.ENVELOPE_SCHEMA_VERSION = void 0;
|
|
4
4
|
var envelope_1 = require("./envelope");
|
|
5
5
|
Object.defineProperty(exports, "ENVELOPE_SCHEMA_VERSION", { enumerable: true, get: function () { return envelope_1.ENVELOPE_SCHEMA_VERSION; } });
|
|
6
6
|
Object.defineProperty(exports, "PRODUCERS", { enumerable: true, get: function () { return envelope_1.PRODUCERS; } });
|
|
@@ -9,10 +9,14 @@ Object.defineProperty(exports, "envelopeSchema", { enumerable: true, get: functi
|
|
|
9
9
|
Object.defineProperty(exports, "producerSchema", { enumerable: true, get: function () { return envelope_1.producerSchema; } });
|
|
10
10
|
var master_data_1 = require("./events/master-data");
|
|
11
11
|
Object.defineProperty(exports, "masterDataEvents", { enumerable: true, get: function () { return master_data_1.masterDataEvents; } });
|
|
12
|
+
var notifications_1 = require("./events/notifications");
|
|
13
|
+
Object.defineProperty(exports, "notificationEvents", { enumerable: true, get: function () { return notifications_1.notificationEvents; } });
|
|
12
14
|
var publisher_1 = require("./publisher");
|
|
13
15
|
Object.defineProperty(exports, "buildMasterDataEnvelope", { enumerable: true, get: function () { return publisher_1.buildMasterDataEnvelope; } });
|
|
16
|
+
Object.defineProperty(exports, "buildNotificationEnvelope", { enumerable: true, get: function () { return publisher_1.buildNotificationEnvelope; } });
|
|
14
17
|
Object.defineProperty(exports, "configurePublisher", { enumerable: true, get: function () { return publisher_1.configurePublisher; } });
|
|
15
18
|
Object.defineProperty(exports, "publishMasterDataEvent", { enumerable: true, get: function () { return publisher_1.publishMasterDataEvent; } });
|
|
19
|
+
Object.defineProperty(exports, "publishNotificationEvent", { enumerable: true, get: function () { return publisher_1.publishNotificationEvent; } });
|
|
16
20
|
Object.defineProperty(exports, "sendCommand", { enumerable: true, get: function () { return publisher_1.sendCommand; } });
|
|
17
21
|
var consumer_1 = require("./consumer");
|
|
18
22
|
Object.defineProperty(exports, "isMasterDataEventType", { enumerable: true, get: function () { return consumer_1.isMasterDataEventType; } });
|
package/dist/publisher.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventBridgeClient } from '@aws-sdk/client-eventbridge';
|
|
2
2
|
import { Envelope, Producer } from './envelope';
|
|
3
3
|
import { MasterDataEventType, MasterDataPayload } from './events/master-data';
|
|
4
|
+
import { NotificationEventType, NotificationPayload } from './events/notifications';
|
|
4
5
|
/**
|
|
5
6
|
* Publisher core. Mirrors the deployed master-data publisher's posture:
|
|
6
7
|
* fire-and-forget, console fallback when EVENT_BUS_NAME is unset, never
|
|
@@ -50,6 +51,18 @@ export declare function buildMasterDataEnvelope<T extends MasterDataEventType>(t
|
|
|
50
51
|
* logged, never thrown into the caller (until the outbox lands).
|
|
51
52
|
*/
|
|
52
53
|
export declare function publishMasterDataEvent<T extends MasterDataEventType>(type: T, payload: MasterDataPayload<T>, ctx: PublishContext): Promise<void>;
|
|
54
|
+
export interface NotificationPublishContext extends Omit<PublishContext, 'userId'> {
|
|
55
|
+
/** The RECIPIENT user (identity sub) — required: it is the routing key. */
|
|
56
|
+
userId: string;
|
|
57
|
+
}
|
|
58
|
+
/** Build + validate the envelope for a catalogued notification event. */
|
|
59
|
+
export declare function buildNotificationEnvelope<T extends NotificationEventType>(type: T, payload: NotificationPayload<T>, ctx: NotificationPublishContext, producer?: Producer): Envelope<NotificationPayload<T>>;
|
|
60
|
+
/**
|
|
61
|
+
* Publish a catalogued notification event (the realtime bell signal).
|
|
62
|
+
* Fire-and-forget like the master-data publisher — a bus failure is
|
|
63
|
+
* logged, never thrown into the notification write.
|
|
64
|
+
*/
|
|
65
|
+
export declare function publishNotificationEvent<T extends NotificationEventType>(type: T, payload: NotificationPayload<T>, ctx: NotificationPublishContext): Promise<void>;
|
|
53
66
|
/**
|
|
54
67
|
* Send a point-to-point command to one app's inbox, routed through the bus
|
|
55
68
|
* on `detail.recipient` (ADR §3, default path). Command payloads are not
|
package/dist/publisher.js
CHANGED
|
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.configurePublisher = configurePublisher;
|
|
4
4
|
exports.buildMasterDataEnvelope = buildMasterDataEnvelope;
|
|
5
5
|
exports.publishMasterDataEvent = publishMasterDataEvent;
|
|
6
|
+
exports.buildNotificationEnvelope = buildNotificationEnvelope;
|
|
7
|
+
exports.publishNotificationEvent = publishNotificationEvent;
|
|
6
8
|
exports.sendCommand = sendCommand;
|
|
7
9
|
const node_crypto_1 = require("node:crypto");
|
|
8
10
|
const client_eventbridge_1 = require("@aws-sdk/client-eventbridge");
|
|
9
11
|
const envelope_1 = require("./envelope");
|
|
10
12
|
const master_data_1 = require("./events/master-data");
|
|
13
|
+
const notifications_1 = require("./events/notifications");
|
|
11
14
|
let config = {};
|
|
12
15
|
let client;
|
|
13
16
|
function configurePublisher(next) {
|
|
@@ -94,6 +97,52 @@ async function publishMasterDataEvent(type, payload, ctx) {
|
|
|
94
97
|
console.error(`[platform-events] publish failed for ${type}`, err);
|
|
95
98
|
}
|
|
96
99
|
}
|
|
100
|
+
/** Build + validate the envelope for a catalogued notification event. */
|
|
101
|
+
function buildNotificationEnvelope(type, payload, ctx, producer = 'notifications') {
|
|
102
|
+
const def = notifications_1.notificationEvents[type];
|
|
103
|
+
const parsedPayload = def.payload.parse(payload);
|
|
104
|
+
if (!ctx.userId) {
|
|
105
|
+
// No recipient → no user topic → undeliverable. Fail loud at build.
|
|
106
|
+
throw new Error(`platform-events: ${type} requires a recipient userId`);
|
|
107
|
+
}
|
|
108
|
+
const entityId = parsedPayload[def.entityIdField];
|
|
109
|
+
if (typeof entityId !== 'string' || entityId.length === 0) {
|
|
110
|
+
throw new Error(`platform-events: ${type} payload is missing id field '${def.entityIdField}'`);
|
|
111
|
+
}
|
|
112
|
+
const envelope = {
|
|
113
|
+
schemaVersion: envelope_1.ENVELOPE_SCHEMA_VERSION,
|
|
114
|
+
eventId: ctx.eventId ?? (0, node_crypto_1.randomUUID)(),
|
|
115
|
+
occurredAt: ctx.occurredAt ?? new Date().toISOString(),
|
|
116
|
+
producer,
|
|
117
|
+
type,
|
|
118
|
+
entityType: def.entityType,
|
|
119
|
+
entityId,
|
|
120
|
+
entityVersion: ctx.entityVersion,
|
|
121
|
+
// nullable: null = platform-level notification (poll-only, no realtime topic).
|
|
122
|
+
tenantId: ctx.tenantId,
|
|
123
|
+
userId: ctx.userId,
|
|
124
|
+
sagaId: ctx.sagaId,
|
|
125
|
+
causationId: ctx.causationId,
|
|
126
|
+
traceId: ctx.traceId ?? (0, node_crypto_1.randomUUID)(),
|
|
127
|
+
payload: parsedPayload,
|
|
128
|
+
};
|
|
129
|
+
envelope_1.envelopeSchema.parse(envelope);
|
|
130
|
+
return envelope;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Publish a catalogued notification event (the realtime bell signal).
|
|
134
|
+
* Fire-and-forget like the master-data publisher — a bus failure is
|
|
135
|
+
* logged, never thrown into the notification write.
|
|
136
|
+
*/
|
|
137
|
+
async function publishNotificationEvent(type, payload, ctx) {
|
|
138
|
+
try {
|
|
139
|
+
const envelope = buildNotificationEnvelope(type, payload, ctx, resolveProducer());
|
|
140
|
+
await putOnBus(envelope, envelope.producer);
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
console.error(`[platform-events] publish failed for ${type}`, err);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
97
146
|
/**
|
|
98
147
|
* Send a point-to-point command to one app's inbox, routed through the bus
|
|
99
148
|
* on `detail.recipient` (ADR §3, default path). Command payloads are not
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@campfire-interactive/platform-events",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Publisher/consumer SDK for the platform-events bus: envelope v2, typed event schemas, publish helpers, sendCommand. 0.x during the Phase 2 dual-publish window; 1.0.0 at cutover (nextgen/docs/plans/2026-06-10-platform-async-messaging.md).",
|
|
5
|
-
"license": "UNLICENSED",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"registry": "https://registry.npmjs.org",
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"main": "dist/index.js",
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist"
|
|
14
|
-
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsc -p tsconfig.build.json",
|
|
17
|
-
"test": "vitest run",
|
|
18
|
-
"typecheck": "tsc --noEmit"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@aws-sdk/client-dynamodb": "^3.600.0",
|
|
22
|
-
"@aws-sdk/client-eventbridge": "^3.600.0",
|
|
23
|
-
"zod": "^3.23.0"
|
|
24
|
-
},
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"@types/node": "^20.14.0",
|
|
27
|
-
"typescript": "^5.5.0",
|
|
28
|
-
"vitest": "^2.0.0"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@campfire-interactive/platform-events",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Publisher/consumer SDK for the platform-events bus: envelope v2, typed event schemas, publish helpers, sendCommand. 0.x during the Phase 2 dual-publish window; 1.0.0 at cutover (nextgen/docs/plans/2026-06-10-platform-async-messaging.md).",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"registry": "https://registry.npmjs.org",
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.build.json",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"typecheck": "tsc --noEmit"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@aws-sdk/client-dynamodb": "^3.600.0",
|
|
22
|
+
"@aws-sdk/client-eventbridge": "^3.600.0",
|
|
23
|
+
"zod": "^3.23.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^20.14.0",
|
|
27
|
+
"typescript": "^5.5.0",
|
|
28
|
+
"vitest": "^2.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|