@campfire-interactive/platform-events 0.1.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/consumer.d.ts +19 -0
- package/dist/consumer.js +36 -0
- package/dist/dedup.d.ts +59 -0
- package/dist/dedup.js +63 -0
- package/dist/envelope.d.ts +231 -0
- package/dist/envelope.js +77 -0
- package/dist/events/master-data.d.ts +460 -0
- package/dist/events/master-data.js +337 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +31 -0
- package/dist/outbox.d.ts +44 -0
- package/dist/outbox.js +38 -0
- package/dist/publisher.d.ts +59 -0
- package/dist/publisher.js +130 -0
- package/dist/saga.d.ts +30 -0
- package/dist/saga.js +39 -0
- package/package.json +30 -0
package/dist/saga.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Envelope } from './envelope';
|
|
2
|
+
import { PublishContext } from './publisher';
|
|
3
|
+
import { MasterDataEventType, MasterDataPayload } from './events/master-data';
|
|
4
|
+
/**
|
|
5
|
+
* Saga-context propagation (ADR §"Cross-app workflows", Mode A
|
|
6
|
+
* choreography): when a handler emits a follow-on event while processing
|
|
7
|
+
* a saga message, the same sagaId rides along and causationId points at
|
|
8
|
+
* the triggering event. Developers derive the child context instead of
|
|
9
|
+
* threading ids by hand.
|
|
10
|
+
*/
|
|
11
|
+
export interface SagaContext {
|
|
12
|
+
sagaId: string;
|
|
13
|
+
causationId: string;
|
|
14
|
+
traceId: string;
|
|
15
|
+
}
|
|
16
|
+
/** Start a new saga (the first event in a choreographed chain). */
|
|
17
|
+
export declare function startSaga(traceId?: string): SagaContext;
|
|
18
|
+
/**
|
|
19
|
+
* Derive the publish context for an event emitted while handling
|
|
20
|
+
* `triggering`. Joins the existing saga if there is one, otherwise the
|
|
21
|
+
* triggering event becomes the saga root. Trace and tenant carry over.
|
|
22
|
+
*/
|
|
23
|
+
export declare function childContext(triggering: Envelope, overrides?: Partial<PublishContext>): PublishContext;
|
|
24
|
+
/**
|
|
25
|
+
* Emit a compensating ("undo") event for a failed saga step (ADR Mode A:
|
|
26
|
+
* "compensation as a first-class event class"). Rides the producer's
|
|
27
|
+
* normal channel with `compensation: true`; upstream consumers subscribe
|
|
28
|
+
* with the same rule mechanics they already use.
|
|
29
|
+
*/
|
|
30
|
+
export declare function publishCompensation<T extends MasterDataEventType>(forEvent: Envelope, type: T, payload: MasterDataPayload<T>, overrides?: Partial<PublishContext>): Promise<void>;
|
package/dist/saga.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startSaga = startSaga;
|
|
4
|
+
exports.childContext = childContext;
|
|
5
|
+
exports.publishCompensation = publishCompensation;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const publisher_1 = require("./publisher");
|
|
8
|
+
/** Start a new saga (the first event in a choreographed chain). */
|
|
9
|
+
function startSaga(traceId) {
|
|
10
|
+
const sagaId = (0, node_crypto_1.randomUUID)();
|
|
11
|
+
return { sagaId, causationId: sagaId, traceId: traceId ?? (0, node_crypto_1.randomUUID)() };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Derive the publish context for an event emitted while handling
|
|
15
|
+
* `triggering`. Joins the existing saga if there is one, otherwise the
|
|
16
|
+
* triggering event becomes the saga root. Trace and tenant carry over.
|
|
17
|
+
*/
|
|
18
|
+
function childContext(triggering, overrides = {}) {
|
|
19
|
+
return {
|
|
20
|
+
tenantId: triggering.tenantId,
|
|
21
|
+
userId: triggering.userId,
|
|
22
|
+
traceId: triggering.traceId,
|
|
23
|
+
sagaId: triggering.sagaId ?? triggering.eventId,
|
|
24
|
+
causationId: triggering.eventId,
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Emit a compensating ("undo") event for a failed saga step (ADR Mode A:
|
|
30
|
+
* "compensation as a first-class event class"). Rides the producer's
|
|
31
|
+
* normal channel with `compensation: true`; upstream consumers subscribe
|
|
32
|
+
* with the same rule mechanics they already use.
|
|
33
|
+
*/
|
|
34
|
+
async function publishCompensation(forEvent, type, payload, overrides = {}) {
|
|
35
|
+
await (0, publisher_1.publishMasterDataEvent)(type, payload, {
|
|
36
|
+
...childContext(forEvent, overrides),
|
|
37
|
+
compensation: true,
|
|
38
|
+
});
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@campfire-interactive/platform-events",
|
|
3
|
+
"version": "0.1.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
|
+
}
|