This commit removes @types/axios from the devDependencies and replaces
it with straight up axios. The @types package is deprecated and has not
been updated in four years. Plus it was raising a security alert. Plus
axios publishes their own types now.
Signed-off-by: Lance Ball <lball@redhat.com>
Fixes: https://github.com/cloudevents/sdk-javascript/issues/392
This commit also removes the external doc theme, since the new version
generates decent looking docs.
After this lands, docs should be published.
Signed-off-by: Lance Ball <lball@redhat.com>
The `HTTP.isEvent()` and `HTTP.toEvent()` functions both had some validation
code that violated the principle of loose validation when receiving an
event over HTTP. As discussed, the validation should be managed by the
receiver in this case with `event.validate()`
Signed-off-by: Lance Ball <lball@redhat.com>
The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-JS-MARKED-1070800
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
Co-authored-by: snyk-bot <snyk-bot@snyk.io>
This change modifies Emitter so that it does not directly extend the Node.js
EventEmitter class. Instead, it holds a singleton instance of an EventEmitter
but is not an instance of EventEmitter itself.
This commit also updates the typescript example to use a modern version of
@types/node and typescript.
Finally there are a few minor formatting changes picked up by eslint.
Fixes: https://github.com/cloudevents/sdk-javascript/issues/385
Signed-off-by: Lance Ball <lball@redhat.com>
* fix: examples/express-ex/package.json to reduce vulnerabilities
The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-JS-AXIOS-1038255
* fix(examples): remove the body-parser module.
* When a structured formatted CloudEvent comes in, the body parser module does know how to parse it since the content type is not application/json, which resulted in an empty request body
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
Co-authored-by: Lucas Holmquist <lholmqui@redhat.com>
* fix: examples/typescript-ex/package.json to reduce vulnerabilities
The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-JS-AXIOS-1038255
* chore: update example to use the 4.0 API
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
Co-authored-by: Lucas Holmquist <lholmqui@redhat.com>
This commit changes the messages produced when validating extension names and
values, including the offending name or value in the message, and including
text from the CloudEvent specification, or a link to the type system.
Fixes: https://github.com/cloudevents/sdk-javascript/issues/364
Signed-off-by: Lance Ball <lball@redhat.com>
* feat!: remove all 4.0 deprecation.
* This removes all the APIs that were deprecated in the 3.x releases and marked as "remove in 4.0".
* Also removes any tests associated with those API's
* squash: remove axios as a dependecy
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
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>
* 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>
* 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>
This commits adds the release-please github action to automate the creation of release PR's
This is only for creating GH releases and they automation of publication to npm will come in the future
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
* feat: add a constructor parameter for loose validation
This commit adds a second, optional boolean parameter to the `CloudEvent`
constructor. When `false` is provided, the event constructor will not
perform validation of the event properties, values and extension names.
This commit also modifies the ValidationError class so that the error message
string includes the JSON.stringified version of any schema validation
errors. It also makes the HTTP.toEvent() function create CloudEvent
objects with loose/no validation.
Incorporates comments from https://github.com/cloudevents/sdk-javascript/pull/328
Fixes: https://github.com/cloudevents/sdk-javascript/issues/325
Signed-off-by: Lance Ball <lball@redhat.com>
Previously, the event's `time` property could be either a string or a date.
this commit modifies that to ensure that the object can only be created with
a timestamp in string format. As long as the string is a valid date, that
can be parsed by `new Date(Date.parse(str))` then whenever the event is
serialized as JSON, the `time` attribute will be formatted as per RFC 3339.
Fixes: https://github.com/cloudevents/sdk-javascript/issues/326
Signed-off-by: Lance Ball <lball@redhat.com>