Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
59eba1f
refactor: drop the @ts-ignore from ValidationError (#650)
kahirokunn Oct 13, 2026
e96e8f6
docs: return the transport promise from the custom emitter examples (…
kahirokunn Oct 13, 2026
23aaa91
chore: update TypeScript, TypeDoc and Node.js declarations (#656)
kahirokunn Oct 17, 2026
5ba5f87
feat!: remove Node.js 20 support (#653)
kahirokunn Oct 17, 2026
26d2dcd
build(deps): bump form-data (#627)
dependabot[bot] Oct 21, 2026
6da6d13
build(deps): bump js-yaml (#630)
dependabot[bot] Oct 21, 2026
0ca14b8
build(deps-dev): bump lodash-es from 4.17.21 to 4.17.23 (#635)
dependabot[bot] Oct 21, 2026
b52a07a
build(deps): bump lodash from 4.17.21 to 4.17.23
dependabot[bot] Jan 21, 2026
37d9f1b
build(deps-dev): bump webpack from 5.99.9 to 5.105.0
dependabot[bot] Feb 7, 2026
83cd32b
build(deps-dev): bump qs from 6.14.0 to 6.14.2
dependabot[bot] Feb 14, 2026
6db7c96
build(deps-dev): bump tmp from 0.2.3 to 0.2.4
dependabot[bot] Aug 6, 2025
c80252e
chore(deps): refresh dev dependencies and clear npm audit findings (#…
shiva Oct 25, 2026
a358af2
fix: decode data_base64 as Uint8Array instead of Uint32Array (#662)
shiva Oct 26, 2026
70ddfb9
fix: serialize object-valued extension attributes in binary HTTP head…
shiva Nov 6, 2026
6c62ac8
docs: use ECMAScript modules in README examples (#652)
kahirokunn Nov 6, 2026
48b1745
fix: read binary extension headers regardless of prefix case (#664)
RaphaelFakhri Nov 6, 2026
85e68cd
docs: fix broken CloudEvents community links in README (#667)
fairbearlab Nov 6, 2026
4b17763
docs: fix broken CloudEvents spec link in source comment (#668)
fairbearlab Nov 6, 2026
eb02b2f
feat!: use Fetch API for HTTP transport
kahirokunn Oct 13, 2026
c360009
feat!: report HTTP delivery failures and typed response bodies
kahirokunn Oct 13, 2026
a3dce52
feat!: add abort signals to HTTP transport
kahirokunn Oct 13, 2026
4da9ee5
refactor: keep HTTP response helpers private
kahirokunn Oct 18, 2026
aa87410
refactor!: narrow HTTP transport options
kahirokunn Oct 18, 2026
4659593
fix: validate CloudEvents header overrides
kahirokunn Oct 18, 2026
81df206
refactor: type the compiled schema validator errors
kahirokunn Oct 18, 2026
8dc7749
refactor: remove redundant type assertions
kahirokunn Oct 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-ci-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x, 24.x]
node-version: [22.x, 24.x]

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ package-lock.json

# Jetbrains IDE directories
.idea

# TypeScript incremental build info
*.tsbuildinfo
171 changes: 167 additions & 4 deletions API_TRANSITION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ const { emitterFor, Mode } = require("cloudevents");
function sendWithAxios(message) {
// Do what you need with the message headers
// and body in this function, then send the
// event
axios({
// event. Return the promise so that `await emit(event)`
// waits for the send and rejects if it fails.
return axios({
method: 'post',
url: '...',
data: message.body,
Expand All @@ -81,8 +82,9 @@ const { emitterFor, Mode, CloudEvent, Emitter } = require("cloudevents");
function sendWithAxios(message) {
// Do what you need with the message headers
// and body in this function, then send the
// event
axios({
// event. Return the promise so that `await emit(event)`
// waits for the send and rejects if it fails.
return axios({
method: "post",
url: "...",
data: message.body,
Expand All @@ -100,3 +102,164 @@ new CloudEvent({ type, source, data }).emit();

// You can also have several listener to send the event to several endpoint
```

### Upgrading From 10.x to 11.0

In the 11.0.0 release, the built-in HTTP transport was rewritten on top of the Fetch API.

#### HTTP Transport

`httpTransport()` used to resolve with the response for every status code, so a receiver
that rejected an event looked just like one that accepted it.

```js
import { CloudEvent, emitterFor, httpTransport } from "cloudevents";

const emit = emitterFor(httpTransport("https://my.receiver.com/endpoint"));

// resolved with { body, headers } whether the receiver returned 202 or 503
const response = await emit(new CloudEvent({ type, source, data }));
```

A 2xx response now resolves with the native Fetch `Response` and its body as text, and
anything else rejects with an `HTTPTransportError`.

```js
import {
CloudEvent,
emitterFor,
HTTPTransportError,
httpTransport,
} from "cloudevents";

const emit = emitterFor(httpTransport("https://my.receiver.com/endpoint"));

try {
const { response, body } = await emit(new CloudEvent({ type, source, data }));
console.log(response.status, body);
} catch (error) {
if (error instanceof HTTPTransportError) {
console.error(error.kind, error.response?.status);
}
throw error;
}
```

The transport takes a second argument now, for headers, how the response body
is read and, under `fetchOptions`, the other Fetch options. Its headers are Fetch header
forms, so a `string[]` value becomes a `Headers` you `append()` to. A redirect is a
failed send unless `fetchOptions: { redirect: "follow" }` says otherwise, and a body
that cannot be read after a 2xx resolves with `bodyError` in place of `body`. Pass
`headers` and `signal` with the event for settings that apply to one message.

```js
const headers = new Headers();
headers.append("accept", "application/cloudevents+json");
headers.append("accept", "application/json");
await emit(new CloudEvent({ type, source, data }), { headers });
```

#### The Emitter Singleton

A listener registered with `Emitter.on("cloudevent", emit)` now returns a promise which
rejects for a receiver that did not accept the event. `emitEvent()` awaits those promises
by default, so the rejection reaches whoever called `emit()` on the event:

```js
try {
await new CloudEvent({ type, source, data }).emit();
} catch (error) {
console.error(error.kind, error.response?.status);
}
```

With `ensureDelivery` turned off, the listeners run through `EventEmitter`, which discards
what they return. A rejection there becomes an unhandled promise rejection, which a `503`
could not produce before. Leave `ensureDelivery` alone, or catch inside the listener:

```js
Emitter.on("cloudevent", (event) => emit(event).catch(reportFailedDelivery));

// listeners are not awaited, so nothing else can catch what they reject with
new CloudEvent({ type, source, data }).emit(false);
```

#### Proxies, Custom CAs, mTLS and Connection Pooling

The old transport went through Node.js `http.request()` or `https.request()`, so a proxy
library or connection options set on `http.globalAgent` or `https.globalAgent` reached
the corresponding requests. Fetch does not use those agents; on Node.js the equivalent
is a dispatcher from [undici](https://www.npmjs.com/package/undici), which `fetchOptions`
passes through:

```js
import { emitterFor, httpTransport } from "cloudevents";
import { ProxyAgent } from "undici";

const emit = emitterFor(httpTransport("https://my.receiver.com/endpoint", {
fetchOptions: { dispatcher: new ProxyAgent("http://proxy.example.com:3128") },
}));
```

For example, an order service that presents a client certificate to an events receiver
and trusts the receiver's private CA can use an `Agent`:

```js
import { readFileSync } from "node:fs";
import { emitterFor, httpTransport } from "cloudevents";
import { Agent } from "undici";

const dispatcher = new Agent({
connect: {
cert: readFileSync("./certs/order-service-client.pem"),
key: readFileSync("./certs/order-service-client-key.pem"),
ca: readFileSync("./certs/events-receiver-ca.pem"),
},
});

const emit = emitterFor(httpTransport("https://events.example.com/orders", {
fetchOptions: { dispatcher },
}));
```

The `cert` and `key` identify the client when the receiver requires mTLS. The `ca`
controls which server certificates the client trusts, so it is needed here because the
receiver uses a private CA; it is separate from client authentication. An `Agent` also
tunes connection pooling, and `undici.setGlobalDispatcher()` applies to every send rather
than one transport. In the browser the platform handles proxies, certificates and trust,
so `dispatcher` is a Node.js-only option.

`fetchOptions` takes the Fetch options of whichever declarations type `fetch` in your
project, so TypeScript accepts `dispatcher` only where those are undici's. Against the
DOM `RequestInit` most projects compile with, pass it as
`fetchOptions: { dispatcher } as RequestInit` or reach for
`setGlobalDispatcher()` instead.

#### Emitter Options

`Options` now declares `headers` and `signal` instead of leaving them to an index
signature that resolved to `unknown`. Its default header type remains the
CloudEvent header record used by custom transports. The emitter returned from
`httpTransport()` accepts Fetch header forms instead.

TypeScript now rejects spreading custom transport options into a client
configuration that types its own `headers`:

```ts
// merge the headers of one send over the ones the binding produced
function sendWithAxios(message: Message, options?: Options) {
const { headers, ...rest } = options ?? {};
return axios.post(url, message.body, {
headers: { ...message.headers, ...headers } as AxiosRequestHeaders,
...rest,
});
}
```

Leave the built-in transport and emitter types to inference so their message
options and response body types are preserved:

```ts
const transport = httpTransport(sink);
const emit = emitterFor(transport);
```
Loading