This commit pulls the constants up from the lib/bindings/http/constants.js
and exports them in the top level index.js. There are some elements of the API
where we expect users to provide constant values, and this makes it easier for
them to be sure the values they provide are what is expected.
I've also added two new constants: `BINARY` and `STRUCTURED`.
Signed-off-by: Lance Ball <lball@redhat.com>
This commit removes the version variable from getVersion and updates the
code to use return statements to be consistent with other functions in
this file, like getMode and accept.
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
This change adds a `ValidationError` type that extends `TypeError`. Any time a `CloudEvent` cannot be received and created with the given input, this error will be thrown. Tests have all
been updated to check for the error type.
Signed-off-by: Lance Ball <lball@redhat.com>
This commit add JSDoc documentation to the CloudEvent and HTTPReceiver
objects exposed by the API when using the top level imports, specifically
`CloudEvent` and `HTTPReceiver`.
This adds a `generate-docs` npm script to generate site and API documentation
for GitHub pages in `./docs`.
Signed-off-by: Lance Ball <lball@redhat.com>
Currently, the mode variable in getMode is set to 'unknown' but this
will never get returned as the else clause will throw a TypeError if the
detected mode (from the passed-in headers) is not structured or binary.
This commit suggests simplifying the getMode function and removes the
mode variable.
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit adds the '.js' suffix to the require of receiver_binary_0_3
to be consistent with the other requires statments in this file.
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit changes the event mode detection in `HTTPReceiver` so that it will
throw a TypeError if the event mode can't be detected per the spec.
Signed-off-by: Lance Ball <lball@redhat.com>
Event receivers in the wild may not always know what version or mode an
incoming event is. Instead of requiring developers to inspect the headers
themselves, the SDK should provide an HTTP receiver that is capable of
figuring out what the version and mode (structured/binary) of an incoming
event is and handle it appropriately.
In determining the best way to expose this, I chose to modify the API a
little bit. Now, instead of `const CloudEvent = require('cloudevents-sdk');`
users need to destructure it.
```js
const { HTTPReceiver, CloudEvent } = require('cloudevents-sdk');
```
This change should not be backported to 1.x.
Fixes: https://github.com/cloudevents/sdk-javascript/issues/93
Signed-off-by: Lance Ball <lball@redhat.com>