Commit Graph

72 Commits

Author SHA1 Message Date
Grant Timmerman 3d82fb6291
refactor: simplify ce version parsers (#274)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-07-27 10:25:11 -07:00
Lucas Holmquist 3c8273f114
lib: validate extension values (#251)
BREAKING CHANGE:

This validates the value of the cloud event extension based on the spec, 
https://github.com/cloudevents/spec/blob/master/spec.md#type-system

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-07-27 13:19:09 -04:00
Grant Timmerman 129ec485d9
refactor: combine v03 and v1 event interfaces, specs and schemas into single files(#270)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-07-24 15:35:18 -04:00
Grant Timmerman 45850e329a
chore: consolidate HTTP parsers and header maps into single files (#267)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-07-24 15:10:51 -04:00
Grant Timmerman a6124cc350
refactor: simplify parser logic and duplicated code (#269)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-07-24 15:08:52 -04:00
Lance Ball 9ae32c76cb
lib: change Receiver#accept() to be static Receiver.accept (#271)
Note that I did not add a third `Protocol` parameter to `Receiver.accept` since
that would not currently be used. It's non-breaking to add a third parameter
in the future once additional protocols are supported.

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

BREAKING CHANGE

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-24 15:07:46 -04:00
Grant Timmerman 4b54b272a5
feat: simplify validation logic/imports (#265)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-07-23 16:09:07 -07:00
Lance Ball a7c326b48c fix: do not require an HTTP body on incoming binary event messages
This commit modifies the HTTP receivers/parsers to allow for the incoming body
of an HTTP request to be empty if the event message is sent using the binary
mode. In structured mode, a `ValidationError` will still be thrown, since the
entire event must be encoded in the HTTP body.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-23 14:22:14 -04:00
Lucas Holmquist 84f1ed9cfe
feat(src): add ext name validation (#246)
BREAKING CHANGE:

* Extension names are now validated during object creation.  The values are defined by the specification, and can be lowercase(a-z) or digits(0-9) and must be no longer that 20 characters

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-07-15 09:53:52 -04:00
Lucas Holmquist c7a84772d5
feat(src): A CloudEvent should be readonly but provide a way to augment itself. (#234)
BREAKING CHANGE:

* This change makes the CloudEvent Read-only and validates the input during object creation.

* To augment an already created CloudEvent object, we have added a `cloneWith` method that takes attributes to add/update.

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-07-13 15:15:32 -04:00
Lance Ball dca2811627
test: inplement the cucumber conformance tests from cloudevents/spec (#238)
This commit adds cucumber-js conformance steps and includes the cucumber
tests in 'npm test'.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-13 09:47:02 -04:00
Lance Ball 51035dc65b
fix: ensure that the HTTP receiver sanitizes headers in accept() (#239)
Even though the underlying structured and binary receivers already sanitize
the headers, this needs to be done at the receiver.accept() level since
the headers are inspected there to determine what mode the event is being
sent as.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-06 17:33:13 -04:00
Lance Ball 276b810dd8
BREAKING CHANGE(lib): rewrite in TypeScript (#226)
This is a major rewrite of the entire codebase into TypeScript. Nearly
all tests have been retained except where behavior is significantly
different. Some highlights of these changes:

* lowercase all CloudEvent properties and fix base64 encoded data

Previously there was a format() function that would convert a CloudEvent
object into JSON with all of the properties lowercased. With this rewrite
a CloudEvent object can be converted to JSON simply with JSON.stringify().

However, in order to be compliant with the JSON representation outlined in
the spec here https://github.com/cloudevents/spec/blob/v1.0/json-format.md
all of the event properties must be all lowercase.

* lib(transport): make transport mode an Enum
* src: allow custom headers (#1)
* lib(exports): export explicitly versioned names where appropriate
* lib(cloudevent): modify ctor to accept extensions inline
* lib(cloudevent): make extensions a part of the event object
* test: convert all tests to typescript
* examples: update all examples with latest API changes
* docs: update README with latest API changes
* src: add prettier for code style and fix a lot of linting errors
* lib: move data decoding to occur within the CloudEvent object

Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-29 14:46:20 -04:00
Matej Vasek 060b21ba36
fix: parse method mutating its input (#231)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2020-06-24 16:16:45 -04:00
Lucas Holmquist 5ab81641ae
chore: adds the return type for the extensions (#221)
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-18 17:12:54 -04:00
Lucas Holmquist 0378f4cdf9
feat: pass extension into the constructor. (#214)
* feat!: pass extension into the constructor.

* This allows someone to pass an extension/extensions into the CloudEvent contructor when creating a CloudEvent.

fixes #209

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-09 18:09:40 -04:00
Lance Ball 44b791bf97
docs: generate api documentation as a GitHub workflow (#217)
Fixes: https://github.com/cloudevents/sdk-javascript/issues/212
Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-08 18:25:27 -04:00
Grant Timmerman 90782a9e17
refactor: ts formatter (#210)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-06-08 10:39:38 -07:00
Lance Ball 957aa6f074
lib: remove specversion from the attributes in receiver.accept() (#207)
* lib: remove specversion from the required attributes in receiver.accept()

The `HTTPReceiver` class' `accept()` method should not have a typescript
type designation of `{ specversion: string }` for the `body` parameter
because the event could (and often is) in binary form, which means that
the `specversion` property won't be there.

This commit changes the method signature to:

`accept(headers: {}, body: {}) : CloudEvent`

Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-04 16:59:48 -04:00
Lance Ball da365e09eb
fix: add correct types to improve TypeScript behavior (#202)
This commit modifies the existing TypeScript files with improved
(read: functional) typings for function parameters. This became an
issue when trying to use the module in an existing TypeScript module.

Tests for the TypeScript files have been moved to a new test folder
specifically for testing TypeScript usage via ts-node.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-04 14:35:51 -04:00
Lance Ball c757a2bce1
fix: fix references to constants - remove .js extension (#200)
Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-01 17:55:54 -04:00
Lance Ball a5befbe0cf
fix: introduce CloudEventV1 and CloudEventV03 interfaces (#194)
This extracts all of the attributes from a `CloudEventVX` that
are not generated by the constructor (id and specversion) into their
own `CloudEventVXAttributes` interface which the `CloudEventVX`
interface extends. This allows TS devs to optionally provide `id`
and `specversion` with proper autocompletion.

Additionally, I have added a union type, `CE` in `cloudevent.ts` which
represents any of `CloudEventV1`, `CloudEventv03`, `CloudEventV1Attributes`
and `CloudEventV03Attributes` interfaces.

Finally, this commit changes all of the user facing API to be `.ts` instead
of `.js` files.

The existing documentation in `./docs` was removed. It should be replaced with generated
HTML from tsdocs, pending some other method of publishing API documentation. That will
come as a separate, docs-only PR.

Fixes: https://github.com/cloudevents/skd-javascript/issues/188

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-29 17:49:02 -04:00