@medicine-wheel/events 0.19.0 → 0.20.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/README.md +52 -21
- package/dist/adapters.d.ts +96 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +178 -0
- package/dist/adapters.js.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/publish.d.ts +7 -18
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +10 -42
- package/dist/publish.js.map +1 -1
- package/dist/route.d.ts +81 -0
- package/dist/route.d.ts.map +1 -0
- package/dist/route.js +148 -0
- package/dist/route.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -142,36 +142,67 @@ The cursor lives in `--state-dir`, which defaults to
|
|
|
142
142
|
`~/.local/state/medicine-wheel-events`, never in the clone. Use `--name` to give
|
|
143
143
|
two followers of one clone separate places.
|
|
144
144
|
|
|
145
|
-
## Publishing
|
|
145
|
+
## Publishing: one port, many adapters
|
|
146
|
+
|
|
147
|
+
`Publisher` is the **port**: one event in, one outcome out (`arrived`, `failed`, `refused`), with the
|
|
148
|
+
destination's declared `guarantees`. Each **adapter** is that port for one destination (ports and adapters,
|
|
149
|
+
Cockburn 2005).
|
|
146
150
|
|
|
147
151
|
```ts
|
|
148
|
-
import { drainLog, httpPublisher, rewind
|
|
152
|
+
import { cloudflareQueuesPublisher, drainLog, hookdeckPublisher, httpPublisher, rewind } from '@medicine-wheel/events/publish';
|
|
149
153
|
|
|
150
|
-
await drainLog(logFile,
|
|
154
|
+
await drainLog(logFile, cloudflareQueuesPublisher({ accountId, queueId, token }));
|
|
151
155
|
```
|
|
152
156
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
**What every broker needs** (`route.ts`, plus the drain):
|
|
158
|
+
|
|
159
|
+
- `topicFor(event, { scheme, naming })` divides events into topics in one of four schemes:
|
|
160
|
+
- `event`: one topic per event type, so one schema per topic;
|
|
161
|
+
- `family`: one ordered topic per lifecycle;
|
|
162
|
+
- `subject`: one per subject kind;
|
|
163
|
+
- `single`: everything in one topic.
|
|
164
|
+
|
|
165
|
+
Names follow the rules of `nats`, `kafka` or `cloudflare`.
|
|
166
|
+
- `partitionKey(event)` is the correlation, else the subject. It keeps a cycle and its beats in order together.
|
|
167
|
+
- `toCloudEvent` / `fromCloudEvent` / `cloudEventHeaders` turn the envelope into CloudEvents 1.0, structured or
|
|
168
|
+
binary, and back, field for field.
|
|
169
|
+
- `classifyHttpStatus` is one rule for every HTTP destination:
|
|
170
|
+
- **failed**, where the pass stops and the event waits: unreachable, 401, 403, 404, 405, 407, 408, 410, 421,
|
|
171
|
+
425, 429 and 5xx. None of these is the receiver's judgement of the event.
|
|
172
|
+
- **refused**, where the event is recorded and passed: any other 4xx.
|
|
173
|
+
- **The drain.** Each publisher keeps its own cursor and receipts, and `rewind` replays an event with the
|
|
174
|
+
same idempotency key.
|
|
175
|
+
|
|
176
|
+
**One adapter per destination** (`adapters.ts`):
|
|
156
177
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
178
|
+
| adapter | request | arrived when |
|
|
179
|
+
|---|---|---|
|
|
180
|
+
| `httpPublisher({ url, token, format })` | POST, as the `envelope`, `cloudevents` or `cloudevents-binary` | 2xx |
|
|
181
|
+
| `hookdeckPublisher({ sourceUrl })` | POST to a Hookdeck source URL | 2xx at the source |
|
|
182
|
+
| `cloudflareQueuesPublisher({ accountId, queueId, token })` | POST `/accounts/{a}/queues/{q}/messages`, `{ "body": … }`, a "Queues Edit" token | 2xx **and** `success: true` |
|
|
162
183
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
Each adapter declares what it promises: acknowledgement, ordering, retention, replay, redelivery, dead
|
|
185
|
+
letters and consumer position. NATS JetStream and Kafka need a client and a server. Their adapter contracts
|
|
186
|
+
and test plans are in miadi-chronicle://548, `foundations/broker-adapters/`.
|
|
166
187
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
188
|
+
Episode 548 draws an event's path as Named → Sent → Arrived | Failed → Replayed:
|
|
189
|
+
|
|
190
|
+
- An event in the log is **Named**.
|
|
191
|
+
- A pass of the drain is **Sent**.
|
|
192
|
+
- The receipt says **Arrived** or **Failed**.
|
|
193
|
+
- `rewind` is **Replayed**.
|
|
194
|
+
|
|
195
|
+
**In the wheel**, each destination is configured by its own environment variables and gets its own cursor.
|
|
196
|
+
One that is down never holds another back.
|
|
197
|
+
|
|
198
|
+
| destination | variables |
|
|
199
|
+
|---|---|
|
|
200
|
+
| any HTTP receiver | `MW_EVENTS_PUBLISH_URL`, with `_TOKEN`, `_NAME` and `_FORMAT` |
|
|
201
|
+
| a Hookdeck source | `MW_EVENTS_HOOKDECK_SOURCE_URL`, with `_FORMAT` |
|
|
202
|
+
| a Cloudflare queue | `MW_EVENTS_CF_ACCOUNT_ID`, `MW_EVENTS_CF_QUEUE_ID` and `MW_EVENTS_CF_API_TOKEN`, with `MW_EVENTS_CF_FORMAT` and `MW_EVENTS_CF_API_BASE` |
|
|
172
203
|
|
|
173
|
-
|
|
174
|
-
|
|
204
|
+
`GET /api/events/publish` and `mw events status` show each destination: its place, its receipts and its
|
|
205
|
+
guarantees. `mw events replay <event-id|all> --publisher <name>` replays one.
|
|
175
206
|
|
|
176
207
|
## Foundations
|
|
177
208
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapters: the provider-specific half of publishing (#165).
|
|
3
|
+
*
|
|
4
|
+
* The port is `Publisher` (`./publish`): one event in, one outcome out. An
|
|
5
|
+
* adapter is that port for one destination. It knows the destination's
|
|
6
|
+
* request shape, its authentication, how its answers map to `arrived`,
|
|
7
|
+
* `failed` and `refused`, and what it actually promises. The jgwill/Miadi
|
|
8
|
+
* Event Spine (rispecs/events §4) requires that promise to be declared rather
|
|
9
|
+
* than assumed, so every adapter here carries `guarantees`.
|
|
10
|
+
*
|
|
11
|
+
* Everything an adapter needs that is not about one provider — topics,
|
|
12
|
+
* partition keys, CloudEvents — is in `./route`.
|
|
13
|
+
*
|
|
14
|
+
* The adapters here speak HTTP and need no dependency: a plain receiver, a
|
|
15
|
+
* Hookdeck source, the Cloudflare Queues API. NATS JetStream and Kafka need
|
|
16
|
+
* a client library and a server to test against; their shape is specified in
|
|
17
|
+
* miadi-chronicle://548 and they come when a server exists.
|
|
18
|
+
*/
|
|
19
|
+
import type { Publisher, PublishOutcome } from './publish';
|
|
20
|
+
/**
|
|
21
|
+
* One rule for every HTTP destination.
|
|
22
|
+
*
|
|
23
|
+
* - `arrived`: 2xx.
|
|
24
|
+
* - `failed` — the pass stops, and the same event goes first next time:
|
|
25
|
+
* - 401, 403, 407: the credentials are wrong;
|
|
26
|
+
* - 404, 405, 410, 421: the address is wrong;
|
|
27
|
+
* - 408, 425, 429 and 5xx: the destination is busy or down;
|
|
28
|
+
* - 1xx and 3xx: an answer this client does not follow.
|
|
29
|
+
*
|
|
30
|
+
* None of these is the receiver's judgement of this event, so passing the
|
|
31
|
+
* event would lose it for that destination.
|
|
32
|
+
* - `refused` — the receiver's judgement of this event as shaped (400, 409,
|
|
33
|
+
* 413, 415, 422 and every other 4xx). It is recorded and passed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function classifyHttpStatus(status: number): PublishOutcome['outcome'];
|
|
36
|
+
/** What a destination actually promises, in its own terms. Each field says what is true, not what is hoped. */
|
|
37
|
+
export interface AdapterGuarantees {
|
|
38
|
+
/** What `arrived` means at this destination. */
|
|
39
|
+
acknowledgement: string;
|
|
40
|
+
ordering: string;
|
|
41
|
+
retention: string;
|
|
42
|
+
replay: string;
|
|
43
|
+
redelivery: string;
|
|
44
|
+
deadLetter: string;
|
|
45
|
+
/** Who keeps a consumer's place. */
|
|
46
|
+
consumerPosition: string;
|
|
47
|
+
}
|
|
48
|
+
/** How the event is put on the wire: the wheel's envelope, or CloudEvents 1.0 in structured or binary mode. */
|
|
49
|
+
export type WireFormat = 'envelope' | 'cloudevents' | 'cloudevents-binary';
|
|
50
|
+
export interface HttpPublisherOptions {
|
|
51
|
+
url: string;
|
|
52
|
+
/** Sent as `Authorization: Bearer <token>`. */
|
|
53
|
+
token?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
format?: WireFormat;
|
|
57
|
+
fetch?: typeof fetch;
|
|
58
|
+
guarantees?: AdapterGuarantees;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* POST each event to a receiver that answers HTTP, with `Idempotency-Key` and
|
|
62
|
+
* `X-Event-Type` headers and the body in the chosen format.
|
|
63
|
+
*/
|
|
64
|
+
export declare function httpPublisher(options: HttpPublisherOptions): Publisher;
|
|
65
|
+
export interface HookdeckPublisherOptions extends Omit<HttpPublisherOptions, 'url' | 'guarantees'> {
|
|
66
|
+
/** The Hookdeck source URL that receives the wheel's events. */
|
|
67
|
+
sourceUrl: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Hookdeck's Event Gateway takes any HTTP POST at a source URL and delivers
|
|
71
|
+
* it to the destinations its connections name, with its own retries,
|
|
72
|
+
* filtering and replay. The wheel's side is a plain POST.
|
|
73
|
+
*/
|
|
74
|
+
export declare function hookdeckPublisher(options: HookdeckPublisherOptions): Publisher;
|
|
75
|
+
export interface CloudflareQueuesOptions {
|
|
76
|
+
accountId: string;
|
|
77
|
+
queueId: string;
|
|
78
|
+
/** An API token with the "Queues Edit" permission. */
|
|
79
|
+
token: string;
|
|
80
|
+
name?: string;
|
|
81
|
+
/** `envelope` (default) or `cloudevents`: what the message body holds. */
|
|
82
|
+
format?: 'envelope' | 'cloudevents';
|
|
83
|
+
apiBase?: string;
|
|
84
|
+
timeoutMs?: number;
|
|
85
|
+
fetch?: typeof fetch;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Cloudflare Queues over its HTTP API, from outside Workers: POST
|
|
89
|
+
* `/accounts/{account}/queues/{queue}/messages` with `{ "body": <message> }`
|
|
90
|
+
* and a bearer token (developers.cloudflare.com, "Publish to a Queue via
|
|
91
|
+
* HTTP"). Arrived means the API answered `success: true`. A consumer — a
|
|
92
|
+
* Worker, or an HTTP pull consumer on another machine — takes it from there,
|
|
93
|
+
* and deduplicates by the message's `idempotency_key`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function cloudflareQueuesPublisher(options: CloudflareQueuesOptions): Publisher;
|
|
96
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAK3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,CAI5E;AAaD,+GAA+G;AAC/G,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAOD,+GAA+G;AAC/G,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAa3E,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAkCtE;AAID,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,KAAK,GAAG,YAAY,CAAC;IAChG,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,SAAS,CAe9E;AAID,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,MAAM,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,uBAAuB,GAAG,SAAS,CAoCrF"}
|
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Adapters: the provider-specific half of publishing (#165).
|
|
4
|
+
*
|
|
5
|
+
* The port is `Publisher` (`./publish`): one event in, one outcome out. An
|
|
6
|
+
* adapter is that port for one destination. It knows the destination's
|
|
7
|
+
* request shape, its authentication, how its answers map to `arrived`,
|
|
8
|
+
* `failed` and `refused`, and what it actually promises. The jgwill/Miadi
|
|
9
|
+
* Event Spine (rispecs/events §4) requires that promise to be declared rather
|
|
10
|
+
* than assumed, so every adapter here carries `guarantees`.
|
|
11
|
+
*
|
|
12
|
+
* Everything an adapter needs that is not about one provider — topics,
|
|
13
|
+
* partition keys, CloudEvents — is in `./route`.
|
|
14
|
+
*
|
|
15
|
+
* The adapters here speak HTTP and need no dependency: a plain receiver, a
|
|
16
|
+
* Hookdeck source, the Cloudflare Queues API. NATS JetStream and Kafka need
|
|
17
|
+
* a client library and a server to test against; their shape is specified in
|
|
18
|
+
* miadi-chronicle://548 and they come when a server exists.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.classifyHttpStatus = classifyHttpStatus;
|
|
22
|
+
exports.httpPublisher = httpPublisher;
|
|
23
|
+
exports.hookdeckPublisher = hookdeckPublisher;
|
|
24
|
+
exports.cloudflareQueuesPublisher = cloudflareQueuesPublisher;
|
|
25
|
+
const route_1 = require("./route");
|
|
26
|
+
// ── what an answer means ────────────────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* One rule for every HTTP destination.
|
|
29
|
+
*
|
|
30
|
+
* - `arrived`: 2xx.
|
|
31
|
+
* - `failed` — the pass stops, and the same event goes first next time:
|
|
32
|
+
* - 401, 403, 407: the credentials are wrong;
|
|
33
|
+
* - 404, 405, 410, 421: the address is wrong;
|
|
34
|
+
* - 408, 425, 429 and 5xx: the destination is busy or down;
|
|
35
|
+
* - 1xx and 3xx: an answer this client does not follow.
|
|
36
|
+
*
|
|
37
|
+
* None of these is the receiver's judgement of this event, so passing the
|
|
38
|
+
* event would lose it for that destination.
|
|
39
|
+
* - `refused` — the receiver's judgement of this event as shaped (400, 409,
|
|
40
|
+
* 413, 415, 422 and every other 4xx). It is recorded and passed.
|
|
41
|
+
*/
|
|
42
|
+
function classifyHttpStatus(status) {
|
|
43
|
+
if (status >= 200 && status < 300)
|
|
44
|
+
return 'arrived';
|
|
45
|
+
if (status >= 400 && status < 500 && ![401, 403, 404, 405, 407, 408, 410, 421, 425, 429].includes(status))
|
|
46
|
+
return 'refused';
|
|
47
|
+
return 'failed';
|
|
48
|
+
}
|
|
49
|
+
async function outcomeOf(res) {
|
|
50
|
+
const outcome = classifyHttpStatus(res.status);
|
|
51
|
+
if (outcome === 'arrived')
|
|
52
|
+
return { outcome, status: res.status };
|
|
53
|
+
const body = await res.text().catch(() => '');
|
|
54
|
+
return { outcome, status: res.status, error: `HTTP ${res.status}${body ? `: ${body.slice(0, 200)}` : ''}` };
|
|
55
|
+
}
|
|
56
|
+
const unreachable = (error) => ({ outcome: 'failed', error: error?.message ?? String(error) });
|
|
57
|
+
/** What the wheel itself gives every adapter: log order, its own cursor, replay by rewind. */
|
|
58
|
+
const WHEEL_SIDE = 'The wheel sends in log order, keeps this publisher\'s cursor and receipts beside the log, and replays by rewind with the same idempotency keys.';
|
|
59
|
+
function wire(event, format) {
|
|
60
|
+
if (format === 'cloudevents') {
|
|
61
|
+
return { headers: { 'content-type': 'application/cloudevents+json' }, body: JSON.stringify((0, route_1.toCloudEvent)(event)) };
|
|
62
|
+
}
|
|
63
|
+
if (format === 'cloudevents-binary') {
|
|
64
|
+
const ce = (0, route_1.toCloudEvent)(event);
|
|
65
|
+
return { headers: (0, route_1.cloudEventHeaders)(ce), body: JSON.stringify(ce.data ?? {}) };
|
|
66
|
+
}
|
|
67
|
+
return { headers: { 'content-type': 'application/json' }, body: JSON.stringify(event) };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* POST each event to a receiver that answers HTTP, with `Idempotency-Key` and
|
|
71
|
+
* `X-Event-Type` headers and the body in the chosen format.
|
|
72
|
+
*/
|
|
73
|
+
function httpPublisher(options) {
|
|
74
|
+
const send = options.fetch ?? fetch;
|
|
75
|
+
const format = options.format ?? 'envelope';
|
|
76
|
+
return {
|
|
77
|
+
name: options.name ?? 'http',
|
|
78
|
+
guarantees: options.guarantees ?? {
|
|
79
|
+
acknowledgement: 'The receiver answered 2xx. What it did next is the receiver\'s.',
|
|
80
|
+
ordering: `${WHEEL_SIDE} Order beyond the receiver is the receiver's.`,
|
|
81
|
+
retention: 'The wheel\'s log keeps every event; the receiver keeps what it keeps.',
|
|
82
|
+
replay: WHEEL_SIDE,
|
|
83
|
+
redelivery: 'A failed send is sent again on the next pass, every minute and after each recorded event.',
|
|
84
|
+
deadLetter: 'A refusal (4xx other than auth, address or rate) is a `refused` receipt, and the cursor passes it.',
|
|
85
|
+
consumerPosition: 'Kept by the wheel, one cursor per publisher.',
|
|
86
|
+
},
|
|
87
|
+
async publish(event) {
|
|
88
|
+
const { headers, body } = wire(event, format);
|
|
89
|
+
try {
|
|
90
|
+
const res = await send(options.url, {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers: {
|
|
93
|
+
...headers,
|
|
94
|
+
'idempotency-key': event.idempotency_key,
|
|
95
|
+
'x-event-type': event.event_type,
|
|
96
|
+
...(options.token ? { authorization: `Bearer ${options.token}` } : {}),
|
|
97
|
+
},
|
|
98
|
+
body,
|
|
99
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 10_000),
|
|
100
|
+
});
|
|
101
|
+
return await outcomeOf(res);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return unreachable(error);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Hookdeck's Event Gateway takes any HTTP POST at a source URL and delivers
|
|
111
|
+
* it to the destinations its connections name, with its own retries,
|
|
112
|
+
* filtering and replay. The wheel's side is a plain POST.
|
|
113
|
+
*/
|
|
114
|
+
function hookdeckPublisher(options) {
|
|
115
|
+
return httpPublisher({
|
|
116
|
+
...options,
|
|
117
|
+
url: options.sourceUrl,
|
|
118
|
+
name: options.name ?? 'hookdeck',
|
|
119
|
+
guarantees: {
|
|
120
|
+
acknowledgement: 'Hookdeck accepted the request at the source (2xx). Delivery to each destination is Hookdeck\'s, by its connection rules.',
|
|
121
|
+
ordering: 'The wheel sends in log order. Delivery order at the destinations is not promised by this adapter.',
|
|
122
|
+
retention: 'Per Hookdeck plan: 3 days on the free Developer plan, 7 on Team (hookdeck.com/pricing, read 2026-10-17). The wheel\'s log keeps every event.',
|
|
123
|
+
replay: `Hookdeck retries and bulk-retries from its dashboard and API within retention. ${WHEEL_SIDE}`,
|
|
124
|
+
redelivery: 'Hookdeck retries failed deliveries to a destination, linearly or exponentially, per connection.',
|
|
125
|
+
deadLetter: 'Failed deliveries stay visible in Hookdeck for retry within retention. A refusal at the source is a `refused` receipt here.',
|
|
126
|
+
consumerPosition: 'Hookdeck pushes to destinations; the wheel keeps its cursor to the source.',
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Cloudflare Queues over its HTTP API, from outside Workers: POST
|
|
132
|
+
* `/accounts/{account}/queues/{queue}/messages` with `{ "body": <message> }`
|
|
133
|
+
* and a bearer token (developers.cloudflare.com, "Publish to a Queue via
|
|
134
|
+
* HTTP"). Arrived means the API answered `success: true`. A consumer — a
|
|
135
|
+
* Worker, or an HTTP pull consumer on another machine — takes it from there,
|
|
136
|
+
* and deduplicates by the message's `idempotency_key`.
|
|
137
|
+
*/
|
|
138
|
+
function cloudflareQueuesPublisher(options) {
|
|
139
|
+
const send = options.fetch ?? fetch;
|
|
140
|
+
const base = (options.apiBase ?? 'https://api.cloudflare.com/client/v4').replace(/\/+$/, '');
|
|
141
|
+
const url = `${base}/accounts/${encodeURIComponent(options.accountId)}/queues/${encodeURIComponent(options.queueId)}/messages`;
|
|
142
|
+
return {
|
|
143
|
+
name: options.name ?? 'cloudflare-queues',
|
|
144
|
+
guarantees: {
|
|
145
|
+
acknowledgement: 'The Queues API answered 2xx with `success: true`: the message is in the queue.',
|
|
146
|
+
ordering: 'The wheel sends in log order. Delivery order to consumers is not promised by this adapter.',
|
|
147
|
+
retention: 'Up to 24 hours on the Workers free plan, up to 14 days on paid plans (Cloudflare changelog, 2026-02-04).',
|
|
148
|
+
replay: `Within the queue, redelivery until acknowledged. ${WHEEL_SIDE}`,
|
|
149
|
+
redelivery: 'At-least-once to a Worker or HTTP pull consumer, retried per the consumer\'s settings.',
|
|
150
|
+
deadLetter: 'A dead-letter queue when the consumer configures one. A refusal by the API is a `refused` receipt here.',
|
|
151
|
+
consumerPosition: 'Cloudflare holds each message until a consumer acknowledges it; the wheel keeps its cursor to the queue.',
|
|
152
|
+
},
|
|
153
|
+
async publish(event) {
|
|
154
|
+
const message = options.format === 'cloudevents' ? (0, route_1.toCloudEvent)(event) : event;
|
|
155
|
+
let res;
|
|
156
|
+
try {
|
|
157
|
+
res = await send(url, {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
headers: { authorization: `Bearer ${options.token}`, 'content-type': 'application/json' },
|
|
160
|
+
body: JSON.stringify({ body: message }),
|
|
161
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 10_000),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
return unreachable(error);
|
|
166
|
+
}
|
|
167
|
+
const outcome = await outcomeOf(res.clone());
|
|
168
|
+
if (outcome.outcome !== 'arrived')
|
|
169
|
+
return outcome;
|
|
170
|
+
// A 2xx that does not say success is not proof of storage.
|
|
171
|
+
const answer = (await res.json().catch(() => null));
|
|
172
|
+
if (answer?.success === true)
|
|
173
|
+
return outcome;
|
|
174
|
+
return { outcome: 'failed', status: res.status, error: `Queues API answered ${res.status} without success: ${JSON.stringify(answer?.errors ?? answer).slice(0, 200)}` };
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAuBH,gDAIC;AA4DD,sCAkCC;AAcD,8CAeC;AAyBD,8DAoC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D,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;YAC7C,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC;YAClD,2DAA2D;YAC3D,MAAM,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAmD,CAAC;YACtG,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI;gBAAE,OAAO,OAAO,CAAC;YAC7C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,uBAAuB,GAAG,CAAC,MAAM,qBAAqB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,IAAI,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;QAC1K,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -105,6 +105,9 @@ function runHandler(command, event) {
|
|
|
105
105
|
});
|
|
106
106
|
child.on('error', () => resolve(false));
|
|
107
107
|
child.on('close', (code) => resolve(code === 0));
|
|
108
|
+
// A handler that never reads stdin may exit before the event is written;
|
|
109
|
+
// the broken pipe is its choice, not a failure. Its exit code decides.
|
|
110
|
+
child.stdin.on('error', () => { });
|
|
108
111
|
child.stdin.end(JSON.stringify(event) + '\n');
|
|
109
112
|
});
|
|
110
113
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2DAA2C;AAC3C,4CAA8B;AAC9B,gDAAkC;AAClC,+BAAuC;AACvC,qCAAmE;AAGnE,SAA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
@@ -19,5 +19,6 @@
|
|
|
19
19
|
export { CATALOG_VERSION, WHEEL_EVENT_CATALOG, WHEEL_EVENTS, familyOf, type EventDefinition, type PayloadField, type PayloadOf, type WheelEventName, type WheelSubjectKind, } from './catalog';
|
|
20
20
|
export { EVENT_NAMESPACE, EVENT_SCHEMA_VERSION, buildEvent, filterEvents, isWheelEvent, shortName, type BuildOptions, type EventFilter, type WheelEvent, type WheelEventInput, } from './envelope';
|
|
21
21
|
export { BEAT_CONTENT_FIELDS, beatWitnessed, beatWritten, ceremonyRemoved, ceremonyWritten, changedFields, conclusionJudged, cycleWritten, diaryRemoved, diaryWritten, isLineage, nodeChanges, nodeFamily, nodeRemoved, nodeWritten, relationId, relationRemoved, relationWritten, type BeatLike, type CeremonyLike, type CycleLike, type DiaryLike, type NodeFamily, type NodeLike, type RelationEnds, type RelationLike, } from './decide';
|
|
22
|
+
export { cloudEventHeaders, fromCloudEvent, nameFor, partitionKey, toCloudEvent, topicFor, type CloudEvent, type CloudEventOptions, type TopicNaming, type TopicOptions, type TopicScheme, } from './route';
|
|
22
23
|
export { asyncApiDocument, envelopeJsonSchema, eventJsonSchema, payloadJsonSchema, schemaId, wheelEventsJsonSchema, } from './schema';
|
|
23
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,eAAe,EACf,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,eAAe,EACf,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,qBAAqB,GACtB,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,eAAe,EACf,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,eAAe,EACf,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,qBAAqB,GACtB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* `@medicine-wheel/events/publish`.
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.wheelEventsJsonSchema = exports.schemaId = exports.payloadJsonSchema = exports.eventJsonSchema = exports.envelopeJsonSchema = exports.asyncApiDocument = exports.relationWritten = exports.relationRemoved = exports.relationId = exports.nodeWritten = exports.nodeRemoved = exports.nodeFamily = exports.nodeChanges = exports.isLineage = exports.diaryWritten = exports.diaryRemoved = exports.cycleWritten = exports.conclusionJudged = exports.changedFields = exports.ceremonyWritten = exports.ceremonyRemoved = exports.beatWritten = exports.beatWitnessed = exports.BEAT_CONTENT_FIELDS = exports.shortName = exports.isWheelEvent = exports.filterEvents = exports.buildEvent = exports.EVENT_SCHEMA_VERSION = exports.EVENT_NAMESPACE = exports.familyOf = exports.WHEEL_EVENTS = exports.WHEEL_EVENT_CATALOG = exports.CATALOG_VERSION = void 0;
|
|
21
|
+
exports.wheelEventsJsonSchema = exports.schemaId = exports.payloadJsonSchema = exports.eventJsonSchema = exports.envelopeJsonSchema = exports.asyncApiDocument = exports.topicFor = exports.toCloudEvent = exports.partitionKey = exports.nameFor = exports.fromCloudEvent = exports.cloudEventHeaders = exports.relationWritten = exports.relationRemoved = exports.relationId = exports.nodeWritten = exports.nodeRemoved = exports.nodeFamily = exports.nodeChanges = exports.isLineage = exports.diaryWritten = exports.diaryRemoved = exports.cycleWritten = exports.conclusionJudged = exports.changedFields = exports.ceremonyWritten = exports.ceremonyRemoved = exports.beatWritten = exports.beatWitnessed = exports.BEAT_CONTENT_FIELDS = exports.shortName = exports.isWheelEvent = exports.filterEvents = exports.buildEvent = exports.EVENT_SCHEMA_VERSION = exports.EVENT_NAMESPACE = exports.familyOf = exports.WHEEL_EVENTS = exports.WHEEL_EVENT_CATALOG = exports.CATALOG_VERSION = void 0;
|
|
22
22
|
var catalog_1 = require("./catalog");
|
|
23
23
|
Object.defineProperty(exports, "CATALOG_VERSION", { enumerable: true, get: function () { return catalog_1.CATALOG_VERSION; } });
|
|
24
24
|
Object.defineProperty(exports, "WHEEL_EVENT_CATALOG", { enumerable: true, get: function () { return catalog_1.WHEEL_EVENT_CATALOG; } });
|
|
@@ -50,6 +50,13 @@ Object.defineProperty(exports, "nodeWritten", { enumerable: true, get: function
|
|
|
50
50
|
Object.defineProperty(exports, "relationId", { enumerable: true, get: function () { return decide_1.relationId; } });
|
|
51
51
|
Object.defineProperty(exports, "relationRemoved", { enumerable: true, get: function () { return decide_1.relationRemoved; } });
|
|
52
52
|
Object.defineProperty(exports, "relationWritten", { enumerable: true, get: function () { return decide_1.relationWritten; } });
|
|
53
|
+
var route_1 = require("./route");
|
|
54
|
+
Object.defineProperty(exports, "cloudEventHeaders", { enumerable: true, get: function () { return route_1.cloudEventHeaders; } });
|
|
55
|
+
Object.defineProperty(exports, "fromCloudEvent", { enumerable: true, get: function () { return route_1.fromCloudEvent; } });
|
|
56
|
+
Object.defineProperty(exports, "nameFor", { enumerable: true, get: function () { return route_1.nameFor; } });
|
|
57
|
+
Object.defineProperty(exports, "partitionKey", { enumerable: true, get: function () { return route_1.partitionKey; } });
|
|
58
|
+
Object.defineProperty(exports, "toCloudEvent", { enumerable: true, get: function () { return route_1.toCloudEvent; } });
|
|
59
|
+
Object.defineProperty(exports, "topicFor", { enumerable: true, get: function () { return route_1.topicFor; } });
|
|
53
60
|
var schema_1 = require("./schema");
|
|
54
61
|
Object.defineProperty(exports, "asyncApiDocument", { enumerable: true, get: function () { return schema_1.asyncApiDocument; } });
|
|
55
62
|
Object.defineProperty(exports, "envelopeJsonSchema", { enumerable: true, get: function () { return schema_1.envelopeJsonSchema; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,qCAUmB;AATjB,0GAAA,eAAe,OAAA;AACf,8GAAA,mBAAmB,OAAA;AACnB,uGAAA,YAAY,OAAA;AACZ,mGAAA,QAAQ,OAAA;AAQV,uCAWoB;AAVlB,2GAAA,eAAe,OAAA;AACf,gHAAA,oBAAoB,OAAA;AACpB,sGAAA,UAAU,OAAA;AACV,wGAAA,YAAY,OAAA;AACZ,wGAAA,YAAY,OAAA;AACZ,qGAAA,SAAS,OAAA;AAOX,mCA2BkB;AA1BhB,6GAAA,mBAAmB,OAAA;AACnB,uGAAA,aAAa,OAAA;AACb,qGAAA,WAAW,OAAA;AACX,yGAAA,eAAe,OAAA;AACf,yGAAA,eAAe,OAAA;AACf,uGAAA,aAAa,OAAA;AACb,0GAAA,gBAAgB,OAAA;AAChB,sGAAA,YAAY,OAAA;AACZ,sGAAA,YAAY,OAAA;AACZ,sGAAA,YAAY,OAAA;AACZ,mGAAA,SAAS,OAAA;AACT,qGAAA,WAAW,OAAA;AACX,oGAAA,UAAU,OAAA;AACV,qGAAA,WAAW,OAAA;AACX,qGAAA,WAAW,OAAA;AACX,oGAAA,UAAU,OAAA;AACV,yGAAA,eAAe,OAAA;AACf,yGAAA,eAAe,OAAA;AAWjB,mC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AChB,4GAAA,kBAAkB,OAAA;AAClB,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,kGAAA,QAAQ,OAAA;AACR,+GAAA,qBAAqB,OAAA"}
|
package/dist/publish.d.ts
CHANGED
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
* second destination starts from the beginning without disturbing the first.
|
|
15
15
|
* The log itself is never changed.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* client is another `Publisher` beside it, not a change to the log.
|
|
17
|
+
* The adapters (`./adapters`) are this port for one destination each: a plain
|
|
18
|
+
* HTTP receiver, a Hookdeck source, Cloudflare Queues. A broker client is
|
|
19
|
+
* another `Publisher` beside them, not a change to the log.
|
|
21
20
|
*
|
|
22
21
|
* Node only — import it as `@medicine-wheel/events/publish`.
|
|
23
22
|
*/
|
|
24
23
|
import type { WheelEvent } from './envelope';
|
|
24
|
+
import type { AdapterGuarantees } from './adapters';
|
|
25
25
|
export type PublishOutcome = {
|
|
26
26
|
outcome: 'arrived';
|
|
27
27
|
status?: number;
|
|
@@ -37,6 +37,8 @@ export type PublishOutcome = {
|
|
|
37
37
|
export interface Publisher {
|
|
38
38
|
/** Names the cursor and the receipts: `http`, `nats`, `hookdeck`. */
|
|
39
39
|
name: string;
|
|
40
|
+
/** What this destination actually promises (rispecs/events §4 in jgwill/Miadi). */
|
|
41
|
+
guarantees?: AdapterGuarantees;
|
|
40
42
|
publish(event: WheelEvent): Promise<PublishOutcome>;
|
|
41
43
|
}
|
|
42
44
|
export interface Receipt {
|
|
@@ -48,20 +50,7 @@ export interface Receipt {
|
|
|
48
50
|
status?: number;
|
|
49
51
|
error?: string;
|
|
50
52
|
}
|
|
51
|
-
export
|
|
52
|
-
url: string;
|
|
53
|
-
/** Sent as `Authorization: Bearer <token>`. */
|
|
54
|
-
token?: string;
|
|
55
|
-
name?: string;
|
|
56
|
-
timeoutMs?: number;
|
|
57
|
-
fetch?: typeof fetch;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* POST each envelope as JSON, with `Idempotency-Key` and `X-Event-Type`.
|
|
61
|
-
* 2xx arrived. Unreachable, timed out, 408, 429 or 5xx failed — may arrive
|
|
62
|
-
* later. Any other answer is refused.
|
|
63
|
-
*/
|
|
64
|
-
export declare function httpPublisher(options: HttpPublisherOptions): Publisher;
|
|
53
|
+
export { classifyHttpStatus, cloudflareQueuesPublisher, hookdeckPublisher, httpPublisher, type AdapterGuarantees, type CloudflareQueuesOptions, type HookdeckPublisherOptions, type HttpPublisherOptions, type WireFormat, } from './adapters';
|
|
65
54
|
/**
|
|
66
55
|
* Where a publisher keeps its cursor and receipts: beside the log, or in
|
|
67
56
|
* `stateDir` — a follower reading someone else's checkout keeps its own state
|
package/dist/publish.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGpD,MAAM,MAAM,cAAc,GACtB;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,OAAO,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,MAAM,WAAW,SAAS;IACxB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAA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AE,YAAY,GAAG,OAAO,EAAE,CAmBnG;AAWD,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,+FAA+F;AAC/F,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAiClH;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAU5H;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACjE;AAED,uFAAuF;AACvF,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAe3G"}
|
package/dist/publish.js
CHANGED
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
* second destination starts from the beginning without disturbing the first.
|
|
16
16
|
* The log itself is never changed.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* client is another `Publisher` beside it, not a change to the log.
|
|
18
|
+
* The adapters (`./adapters`) are this port for one destination each: a plain
|
|
19
|
+
* HTTP receiver, a Hookdeck source, Cloudflare Queues. A broker client is
|
|
20
|
+
* another `Publisher` beside them, not a change to the log.
|
|
22
21
|
*
|
|
23
22
|
* Node only — import it as `@medicine-wheel/events/publish`.
|
|
24
23
|
*/
|
|
@@ -56,7 +55,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
56
55
|
};
|
|
57
56
|
})();
|
|
58
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
-
exports.httpPublisher =
|
|
58
|
+
exports.httpPublisher = exports.hookdeckPublisher = exports.cloudflareQueuesPublisher = exports.classifyHttpStatus = void 0;
|
|
60
59
|
exports.cursorPath = cursorPath;
|
|
61
60
|
exports.receiptsPath = receiptsPath;
|
|
62
61
|
exports.readCursor = readCursor;
|
|
@@ -67,43 +66,12 @@ exports.publisherStatus = publisherStatus;
|
|
|
67
66
|
const fs = __importStar(require("node:fs"));
|
|
68
67
|
const path = __importStar(require("node:path"));
|
|
69
68
|
const log_1 = require("./log");
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
function
|
|
76
|
-
const send = options.fetch ?? fetch;
|
|
77
|
-
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
78
|
-
return {
|
|
79
|
-
name: options.name ?? 'http',
|
|
80
|
-
async publish(event) {
|
|
81
|
-
let res;
|
|
82
|
-
try {
|
|
83
|
-
res = await send(options.url, {
|
|
84
|
-
method: 'POST',
|
|
85
|
-
headers: {
|
|
86
|
-
'content-type': 'application/json',
|
|
87
|
-
'idempotency-key': event.idempotency_key,
|
|
88
|
-
'x-event-type': event.event_type,
|
|
89
|
-
...(options.token ? { authorization: `Bearer ${options.token}` } : {}),
|
|
90
|
-
},
|
|
91
|
-
body: JSON.stringify(event),
|
|
92
|
-
signal: AbortSignal.timeout(timeoutMs),
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
return { outcome: 'failed', error: error?.message ?? String(error) };
|
|
97
|
-
}
|
|
98
|
-
if (res.ok)
|
|
99
|
-
return { outcome: 'arrived', status: res.status };
|
|
100
|
-
const body = await res.text().catch(() => '');
|
|
101
|
-
const error = `HTTP ${res.status}${body ? `: ${body.slice(0, 200)}` : ''}`;
|
|
102
|
-
const later = res.status >= 500 || res.status === 408 || res.status === 429;
|
|
103
|
-
return { outcome: later ? 'failed' : 'refused', status: res.status, error };
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
69
|
+
// The adapters, `httpPublisher` among them, live in `./adapters` (#165).
|
|
70
|
+
var adapters_1 = require("./adapters");
|
|
71
|
+
Object.defineProperty(exports, "classifyHttpStatus", { enumerable: true, get: function () { return adapters_1.classifyHttpStatus; } });
|
|
72
|
+
Object.defineProperty(exports, "cloudflareQueuesPublisher", { enumerable: true, get: function () { return adapters_1.cloudflareQueuesPublisher; } });
|
|
73
|
+
Object.defineProperty(exports, "hookdeckPublisher", { enumerable: true, get: function () { return adapters_1.hookdeckPublisher; } });
|
|
74
|
+
Object.defineProperty(exports, "httpPublisher", { enumerable: true, get: function () { return adapters_1.httpPublisher; } });
|
|
107
75
|
const stateDirOf = (logFile, options) => options?.stateDir ?? path.dirname(logFile);
|
|
108
76
|
function cursorPath(logFile, publisher, options) {
|
|
109
77
|
return path.join(stateDirOf(logFile, options), `events-cursor.${publisher}.json`);
|
package/dist/publish.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDH,gCAEC;AAED,oCAEC;AAQD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"}
|
package/dist/route.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every broker needs from an event, before any one broker is chosen
|
|
3
|
+
* (#165): which topic it goes to, which key keeps its order, and the
|
|
4
|
+
* CloudEvents form many providers already read.
|
|
5
|
+
*
|
|
6
|
+
* Pure and browser-safe. Provider adapters (`./adapters`) use these; so can a
|
|
7
|
+
* consumer that reads a topic and wants the wheel's envelope back.
|
|
8
|
+
*/
|
|
9
|
+
import { type WheelEvent } from './envelope';
|
|
10
|
+
/**
|
|
11
|
+
* How events are divided into topics (Kafka topics, NATS subjects, queues):
|
|
12
|
+
*
|
|
13
|
+
* - `event`: one topic per event type (`medicine-wheel.cycle.opened`). One
|
|
14
|
+
* schema per topic, the shape Bellemare recommends for fact streams
|
|
15
|
+
* (miadi-chronicle://548, Kafka review, 34:00).
|
|
16
|
+
* - `family`: one per family (`medicine-wheel.cycle`, `medicine-wheel.chronicle.lineage`).
|
|
17
|
+
* A record's opened, amended and archived share one ordered stream, the
|
|
18
|
+
* shape he recommends when a lifecycle's order matters (35:45).
|
|
19
|
+
* - `subject`: one per subject kind (`medicine-wheel.relation`).
|
|
20
|
+
* - `single`: everything in one topic (`medicine-wheel.events`).
|
|
21
|
+
*/
|
|
22
|
+
export type TopicScheme = 'event' | 'family' | 'subject' | 'single';
|
|
23
|
+
/** Each provider's naming rules. `none` keeps the dotted name. */
|
|
24
|
+
export type TopicNaming = 'nats' | 'kafka' | 'cloudflare' | 'none';
|
|
25
|
+
export interface TopicOptions {
|
|
26
|
+
scheme?: TopicScheme;
|
|
27
|
+
naming?: TopicNaming;
|
|
28
|
+
/** The single topic's name, for `scheme: 'single'`. */
|
|
29
|
+
single?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Names as each provider allows them:
|
|
33
|
+
* - NATS: dotted tokens, never empty, without spaces, `*` or `>`.
|
|
34
|
+
* - Kafka: `[a-zA-Z0-9._-]`, at most 249 characters.
|
|
35
|
+
* - Cloudflare Queues: lowercase letters, digits and dashes, at most 63.
|
|
36
|
+
*/
|
|
37
|
+
export declare function nameFor(name: string, naming?: TopicNaming): string;
|
|
38
|
+
/** The topic an event goes to. */
|
|
39
|
+
export declare function topicFor(event: Pick<WheelEvent, 'event_type' | 'subject'>, options?: TopicOptions): string;
|
|
40
|
+
/**
|
|
41
|
+
* The key that keeps related events in order within a partition: the
|
|
42
|
+
* correlation (a cycle and its beats, a ceremony and its closing, an episode
|
|
43
|
+
* and its relations), else the subject.
|
|
44
|
+
*/
|
|
45
|
+
export declare function partitionKey(event: Pick<WheelEvent, 'correlation_id' | 'subject'>): string;
|
|
46
|
+
/**
|
|
47
|
+
* A CloudEvents 1.0 event (CNCF, 2019). The wheel's envelope fields that
|
|
48
|
+
* CloudEvents has no attribute for travel as extension attributes, whose names
|
|
49
|
+
* the specification restricts to lowercase letters and digits.
|
|
50
|
+
*/
|
|
51
|
+
export interface CloudEvent {
|
|
52
|
+
specversion: '1.0';
|
|
53
|
+
id: string;
|
|
54
|
+
source: string;
|
|
55
|
+
type: string;
|
|
56
|
+
subject?: string;
|
|
57
|
+
time?: string;
|
|
58
|
+
datacontenttype?: string;
|
|
59
|
+
dataschema?: string;
|
|
60
|
+
data?: unknown;
|
|
61
|
+
[extension: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
export interface CloudEventOptions {
|
|
64
|
+
/** A URI for the payload's schema, e.g. the published JSON Schema. */
|
|
65
|
+
dataschema?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The wheel's envelope as a structured CloudEvent: `id`, the source as a URN
|
|
69
|
+
* naming the wheel, `type` the event type, `subject` the record's id, `time`
|
|
70
|
+
* when it was observed, and the payload as `data`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function toCloudEvent(event: WheelEvent, options?: CloudEventOptions): CloudEvent;
|
|
73
|
+
/** The envelope back from a CloudEvent `toCloudEvent` made, field for field. */
|
|
74
|
+
export declare function fromCloudEvent(ce: CloudEvent): WheelEvent;
|
|
75
|
+
/**
|
|
76
|
+
* CloudEvents' HTTP binary mode: every attribute except `data` as a `ce-`
|
|
77
|
+
* header, `data` as the body, `datacontenttype` as `content-type`. Header
|
|
78
|
+
* values are strings; a receiver reads `mwcontentincluded` as `"true"`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function cloudEventHeaders(ce: CloudEvent): Record<string, string>;
|
|
81
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAoD,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAI/F;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEpE,kEAAkE;AAClE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,WAAoB,GAAG,MAAM,CAW1E;AAED,kCAAkC;AAClC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,YAAY,GAAG,SAAS,CAAC,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAiB9G;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAC,GAAG,MAAM,CAE1F;AAID;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,KAAK,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAcD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAwB3F;AAID,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,EAAE,EAAE,UAAU,GAAG,UAAU,CAmBzD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxE"}
|
package/dist/route.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What every broker needs from an event, before any one broker is chosen
|
|
4
|
+
* (#165): which topic it goes to, which key keeps its order, and the
|
|
5
|
+
* CloudEvents form many providers already read.
|
|
6
|
+
*
|
|
7
|
+
* Pure and browser-safe. Provider adapters (`./adapters`) use these; so can a
|
|
8
|
+
* consumer that reads a topic and wants the wheel's envelope back.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.nameFor = nameFor;
|
|
12
|
+
exports.topicFor = topicFor;
|
|
13
|
+
exports.partitionKey = partitionKey;
|
|
14
|
+
exports.toCloudEvent = toCloudEvent;
|
|
15
|
+
exports.fromCloudEvent = fromCloudEvent;
|
|
16
|
+
exports.cloudEventHeaders = cloudEventHeaders;
|
|
17
|
+
const catalog_1 = require("./catalog");
|
|
18
|
+
const envelope_1 = require("./envelope");
|
|
19
|
+
/**
|
|
20
|
+
* Names as each provider allows them:
|
|
21
|
+
* - NATS: dotted tokens, never empty, without spaces, `*` or `>`.
|
|
22
|
+
* - Kafka: `[a-zA-Z0-9._-]`, at most 249 characters.
|
|
23
|
+
* - Cloudflare Queues: lowercase letters, digits and dashes, at most 63.
|
|
24
|
+
*/
|
|
25
|
+
function nameFor(name, naming = 'none') {
|
|
26
|
+
switch (naming) {
|
|
27
|
+
case 'nats':
|
|
28
|
+
return name.split('.').map((t) => t.replace(/[\s*>]/g, '_') || '_').join('.');
|
|
29
|
+
case 'kafka':
|
|
30
|
+
return name.replace(/[^a-zA-Z0-9._-]/g, '_').slice(0, 249);
|
|
31
|
+
case 'cloudflare':
|
|
32
|
+
return name.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 63);
|
|
33
|
+
default:
|
|
34
|
+
return name;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** The topic an event goes to. */
|
|
38
|
+
function topicFor(event, options = {}) {
|
|
39
|
+
const short = (0, envelope_1.shortName)(event.event_type);
|
|
40
|
+
let name;
|
|
41
|
+
switch (options.scheme ?? 'event') {
|
|
42
|
+
case 'family':
|
|
43
|
+
name = `${envelope_1.EVENT_NAMESPACE}.${(0, catalog_1.familyOf)(short)}`;
|
|
44
|
+
break;
|
|
45
|
+
case 'subject':
|
|
46
|
+
name = `${envelope_1.EVENT_NAMESPACE}.${event.subject.kind}`;
|
|
47
|
+
break;
|
|
48
|
+
case 'single':
|
|
49
|
+
name = options.single ?? `${envelope_1.EVENT_NAMESPACE}.events`;
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
name = event.event_type;
|
|
53
|
+
}
|
|
54
|
+
return nameFor(name, options.naming);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The key that keeps related events in order within a partition: the
|
|
58
|
+
* correlation (a cycle and its beats, a ceremony and its closing, an episode
|
|
59
|
+
* and its relations), else the subject.
|
|
60
|
+
*/
|
|
61
|
+
function partitionKey(event) {
|
|
62
|
+
return event.correlation_id ?? event.subject.id;
|
|
63
|
+
}
|
|
64
|
+
const EXT = {
|
|
65
|
+
subjectKind: 'mwsubjectkind',
|
|
66
|
+
correlation: 'mwcorrelation',
|
|
67
|
+
causation: 'mwcausation',
|
|
68
|
+
actorKind: 'mwactorkind',
|
|
69
|
+
actor: 'mwactor',
|
|
70
|
+
classification: 'mwclassification',
|
|
71
|
+
contentIncluded: 'mwcontentincluded',
|
|
72
|
+
schemaVersion: 'mwschemaversion',
|
|
73
|
+
occurredAt: 'mwoccurredat',
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The wheel's envelope as a structured CloudEvent: `id`, the source as a URN
|
|
77
|
+
* naming the wheel, `type` the event type, `subject` the record's id, `time`
|
|
78
|
+
* when it was observed, and the payload as `data`.
|
|
79
|
+
*/
|
|
80
|
+
function toCloudEvent(event, options = {}) {
|
|
81
|
+
const ce = {
|
|
82
|
+
specversion: '1.0',
|
|
83
|
+
id: event.id,
|
|
84
|
+
source: `urn:${envelope_1.EVENT_NAMESPACE}:${event.source.instance ?? 'wheel'}`,
|
|
85
|
+
type: event.event_type,
|
|
86
|
+
subject: event.subject.id,
|
|
87
|
+
time: event.observed_at,
|
|
88
|
+
datacontenttype: 'application/json',
|
|
89
|
+
...(options.dataschema ? { dataschema: options.dataschema } : {}),
|
|
90
|
+
data: event.payload,
|
|
91
|
+
[EXT.subjectKind]: event.subject.kind,
|
|
92
|
+
[EXT.classification]: event.privacy.classification,
|
|
93
|
+
[EXT.contentIncluded]: event.privacy.content_included,
|
|
94
|
+
[EXT.schemaVersion]: event.schema_version,
|
|
95
|
+
};
|
|
96
|
+
if (event.occurred_at !== event.observed_at)
|
|
97
|
+
ce[EXT.occurredAt] = event.occurred_at;
|
|
98
|
+
if (event.correlation_id)
|
|
99
|
+
ce[EXT.correlation] = event.correlation_id;
|
|
100
|
+
if (event.causation_id)
|
|
101
|
+
ce[EXT.causation] = event.causation_id;
|
|
102
|
+
if (event.actor) {
|
|
103
|
+
ce[EXT.actorKind] = event.actor.kind;
|
|
104
|
+
if (event.actor.id)
|
|
105
|
+
ce[EXT.actor] = event.actor.id;
|
|
106
|
+
}
|
|
107
|
+
return ce;
|
|
108
|
+
}
|
|
109
|
+
const str = (v) => (typeof v === 'string' && v ? v : undefined);
|
|
110
|
+
/** The envelope back from a CloudEvent `toCloudEvent` made, field for field. */
|
|
111
|
+
function fromCloudEvent(ce) {
|
|
112
|
+
const instance = ce.source.startsWith(`urn:${envelope_1.EVENT_NAMESPACE}:`) ? ce.source.slice(`urn:${envelope_1.EVENT_NAMESPACE}:`.length) : undefined;
|
|
113
|
+
const time = str(ce.time) ?? new Date(0).toISOString();
|
|
114
|
+
const actorKind = str(ce[EXT.actorKind]);
|
|
115
|
+
return {
|
|
116
|
+
id: ce.id,
|
|
117
|
+
schema_version: (str(ce[EXT.schemaVersion]) ?? envelope_1.EVENT_SCHEMA_VERSION),
|
|
118
|
+
event_type: ce.type,
|
|
119
|
+
source: { kind: 'miadi', system: envelope_1.EVENT_NAMESPACE, ...(instance && instance !== 'wheel' ? { instance } : {}) },
|
|
120
|
+
subject: { kind: (str(ce[EXT.subjectKind]) ?? 'node'), id: str(ce.subject) ?? '' },
|
|
121
|
+
occurred_at: str(ce[EXT.occurredAt]) ?? time,
|
|
122
|
+
observed_at: time,
|
|
123
|
+
...(actorKind ? { actor: { kind: actorKind, ...(str(ce[EXT.actor]) ? { id: str(ce[EXT.actor]) } : {}) } } : {}),
|
|
124
|
+
...(str(ce[EXT.correlation]) ? { correlation_id: str(ce[EXT.correlation]) } : {}),
|
|
125
|
+
...(str(ce[EXT.causation]) ? { causation_id: str(ce[EXT.causation]) } : {}),
|
|
126
|
+
idempotency_key: ce.id,
|
|
127
|
+
privacy: { classification: str(ce[EXT.classification]) ?? 'internal', content_included: ce[EXT.contentIncluded] === true },
|
|
128
|
+
payload: (ce.data ?? {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* CloudEvents' HTTP binary mode: every attribute except `data` as a `ce-`
|
|
133
|
+
* header, `data` as the body, `datacontenttype` as `content-type`. Header
|
|
134
|
+
* values are strings; a receiver reads `mwcontentincluded` as `"true"`.
|
|
135
|
+
*/
|
|
136
|
+
function cloudEventHeaders(ce) {
|
|
137
|
+
const headers = {};
|
|
138
|
+
for (const [key, value] of Object.entries(ce)) {
|
|
139
|
+
if (key === 'data' || value === undefined)
|
|
140
|
+
continue;
|
|
141
|
+
if (key === 'datacontenttype')
|
|
142
|
+
headers['content-type'] = String(value);
|
|
143
|
+
else
|
|
144
|
+
headers[`ce-${key}`] = String(value);
|
|
145
|
+
}
|
|
146
|
+
return headers;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAqCH,0BAWC;AAGD,4BAiBC;AAOD,oCAEC;AA4CD,oCAwBC;AAKD,wCAmBC;AAOD,8CAQC;AAtLD,uCAAqC;AACrC,yCAA+F;AA4B/F;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,IAAY,EAAE,SAAsB,MAAM;IAChE,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChF,KAAK,OAAO;YACV,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,GA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AAC,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,UAAU,EAAE,gBAAgB,EAAE,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE;QAC1H,OAAO,EAAE,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAA0B;KAClD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,EAAc;IAC9C,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QAC9C,IAAI,GAAG,KAAK,MAAM,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QACpD,IAAI,GAAG,KAAK,iBAAiB;YAAE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;;YAClE,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medicine-wheel/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "The events a Medicine Wheel writes — catalog, MiadiEventEnvelope, JSON Schema and AsyncAPI document, the append-only events.jsonl log, the publisher seam a broker plugs into, and git carriage with a follower (mw-events)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|