Commit Graph

8 Commits

Author SHA1 Message Date
Lance Ball 0362a4f11c
feat!: add http transport and remove axios (#481)
* feat: add builtin HTTP emitter

Adds a builtin HTTP event emitter that can be used with `emitterFor()`
to send events over HTTP without pulling in any additional dependencies.

In the past we chose to keep this in our code base by considering axios a
peer dependency - users were required to include it in their projects
explicitly. In working on the HTTP emitter, it became more and more
apparent that the axios emitter was probably no longer needed, and in fact
I doubt it was really used at all. To use it, users would have been required
to do this, since it isn't exported at the top level.

const { axiosEmitter } = require("cloudevents/transport/http");

Based on this, I think the usage in the wild is probably very minimal,
and I like the idea of eliminating this dependency.

Signed-off-by: Lance Ball <lball@redhat.com>
2022-03-18 13:36:12 -04:00
Lance Ball 061c122b86
chore: update eslint and prettier dependencies (#424)
There were some minor changes that resulted in a few code style changes, but not much.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-08-04 15:51:37 -04:00
Remi Cattiau 80d987c1f6
chore: add copyrights header and lint rules (#418)
Signed-off-by: Remi Cattiau <remi@cattiau.com>
2021-05-14 09:28:49 -04:00
Lance Ball 0f11b02a01
fix: defaults properly handled for emitterFor() (#399)
* fix: defaults properly handled for emitterFor()

Fixes: https://github.com/cloudevents/sdk-javascript/issues/391
2021-04-05 13:14:04 -04:00
Remi Cattiau d418a50c56 ci: add unit test for emitter
Signed-off-by: Remi Cattiau <remi@cattiau.com>
2020-11-17 08:41:16 -05:00
Lance Ball f6be285b83
fix: extend Node.js IncomingHttpHeaders in our Headers type (#346)
This commit extends Node.js IncomingHttpHeaders in our Headers type.
Changes the Headers type to make it more compatible with Node.js TypeScript projects.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-10-06 15:50:33 -04:00
Lance Ball 14468980f7
fix: do not alter an event's data attribute (#344)
* fix: do not alter an event's data attribute

When setting an event's data attribute we were trying to be really clever
and this is problematic. Instead, keep the data attribute unchanged. Per
the 1.0 specification, the data attribute is still inspected to determine
if it is binary, and if so, a data_base64 attribute is added with the
contents of the data property encoded as base64.

Fixes: https://github.com/cloudevents/sdk-javascript/issues/343

Signed-off-by: Lance Ball <lball@redhat.com>
2020-10-06 08:20:54 -04:00
Lance Ball e334b6eceb
feat: add emitterFactory and friends (#342)
* feat: add emitterFactory and friends

This commit adds an emitterFactory function that returns an EmitterFunction
object. The EmitterFunction may be used to emit events over a supported
network transport layer. Currently, only HTTP is supported.

Parameters provided to the emitterFactory are the transport Binding (only
HTTP supported), the encoding mode (Mode.BINARY or Mode.STRUCTURED), and
a TransportFunction.

The implementation for emitBinary and emitStructured has been replaced
with this simple pattern and those two functions have been removed.

Example:

```js
// The endpoint URL that will receive the event
const sink = 'https://my-event-sink';

// A function that uses Axios to send a message over HTTP
function axiosEmitter(message: Message, options?: Options): Promise<unknown> {
  return axios.post(sink, message.body, { headers: message.headers, ...options });
}

// Create an event emitter
const emit = emitterFactory(HTTP, Mode.BINARY, axiosEmitter);

// Emit an event, sending it to the endpoint URL
emit(new CloudEvent{ source: '/example', type: 'example' });
```

Signed-off-by: Lance Ball <lball@redhat.com>
2020-09-25 17:25:15 -04:00