Commit Graph

225 Commits

Author SHA1 Message Date
Lance Ball 72a87dfb2d
fix: ensure binary events can handle no content-type header (#134)
* fix: ensure binary events can handle no content-type header

The fix provided in https://github.com/cloudevents/sdk-javascript/pull/118
only included tests for `receiver.check()`, and the change in that
case was to add the `application/json` content type to the cleansed
headers if to type was specified.

However, `receiver.parse()` did not receive the benefit of this change. It
calls `this.check()` but then sanitizes the original headers again, and the
missing content-type was not re-inserted into the newly sanitized headers.

This commit, modifies the code so that `receiver.check()` does not insert
the content-type, but does allow the validation check to pass if no
content-type header exists. When `receiver.parse()` is called, and the
headers are sanitized again - and this time used to look up parser implementation,
the default `application/json` content-is applied if no content-type header
exists.

I've also removed a redundant call to `receiver.check()` in receiver_binary_1.js
and simplified the usage of `Constants` in the test.

Signed-off-by: Lance Ball <lball@redhat.com>

* chore: clean up header sniffing

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-08 23:37:10 -04:00
Lance Ball 63ae1ad527
feat(unmarshaller)!: remove asynchronous 0.3 unmarshaller API (#126)
This commit removes the unnecessary use of Promises in the 0.3 unmarshaller.
There was actually no asynchronous activity happening in that function, so
there was no need to deal with Promises, and as a result testing was made
much more difficult.

Fixes: https://github.com/cloudevents/sdk-javascript/pull/95

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-06 20:05:10 -04:00
Grant Timmerman 106b943ee2
Inline Spec File (#129)
* fix: make application/json the default content type in binary mode (#118)

The Knative Kafka event source does not include a `Content-Type` header when
sending binary events. The CE HTTP binding specification doesn't address how
a receiver should handle this situation.

This commit makes `application/json` the default.

Fixes: https://github.com/cloudevents/sdk-javascript/issues/117
Ref: https://github.com/cloudevents/spec/issues/614

Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

* refactor: remove ext folder

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

* Revert "fix: make application/json the default content type in binary mode (#118)"

This reverts commit 9ccfaf25ba.

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

Co-authored-by: Lance Ball <lball@redhat.com>
2020-05-06 12:12:26 -07:00
Lance Ball 54f242b79e
feat: expose a mode and version agnostic event receiver (#120)
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>
2020-05-06 13:25:16 -04:00
Lance Ball d9e9ae6bdc
fix: make application/json the default content type in binary mode (#118)
The Knative Kafka event source does not include a `Content-Type` header when
sending binary events. The CE HTTP binding specification doesn't address how
a receiver should handle this situation.

This commit makes `application/json` the default.

Fixes: https://github.com/cloudevents/sdk-javascript/issues/117
Ref: https://github.com/cloudevents/spec/issues/614

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-05 18:02:39 -04:00
Grant Timmerman 79ec3ef126
chore: es6 unmarshaller (#108)
* chore: es6 unmarshaller
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-05-05 13:02:43 -07:00
Daniel Bevenius e329d9ac00
lib: use specversion from schema (#116)
This commit updates the 0.1 and 0.3 sources to use the specversion
available in schema definitions.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-04 17:44:16 -07:00
Helio Frota cd6a3eec7d
fix: misspelled word (#113)
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-05-02 08:31:07 -07:00
Grant Timmerman 05ecbdea4f
feat: use CloudEvents not cloudevents everywhere (#101)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-30 16:14:13 -07:00
Grant Timmerman cd6decd749
chore: es6 parser (#98)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-30 15:32:37 -07:00
Lance Ball e83db297ae chore: update eslint rules to disallow var usage
Enforce the use of `let` and `const` by using elsint rules.
When creating the eslint configuration, I had assumed that
`extends: eslint:recommended` would have covered this, but
apparently not!

Existing usage of `var` fixed with `npm run lint -- --fix`.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-30 12:36:04 -03:00
Helio Frota 42246ce36b chore: Update uuid dependency
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-04-30 12:34:30 -03:00
Helio Frota fbcbcec4e8 fix: protects the consts from being changed in other parts of the code.
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-04-30 12:19:24 -03:00
Grant Timmerman 12ac181300
chore: use es6 for cloudevents.js (#73)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-29 13:17:51 -07:00
Grant Timmerman d042ef1dbb
chore: es6 base64 parser (#75)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-29 13:15:00 -07:00
Grant Timmerman c36f1949d0
feat: formatter.js es6 (#87)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-29 12:47:41 -07:00
Lance Ball 5110ad4c67 src,fix: drop support for v0.2 and clean up contenttype
This commit removes support for the v0.2 specification. It also removes the
`contenttype` attribute from the `CloudEvent` object. While the HTTP protocol
binding specifies that in binary mode, the `datacontenttype` attribute should
map to the HTTP Content-Type header, that doesn't mean that the `CloudEvent`
object should have a `contenttype` property.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-28 17:37:49 -03:00
Lance Ball 3f238a0124
src: add eslint configuration and npm script
Automatically fixed > 2000 issues. The remaining 200+ issues need
to be fixed by hand. Additionally, all strings are double quotes
which is not typically standard and I wonder about fixing that too.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-22 10:15:05 -04:00
Lance Ball aa2cef6e3c
deps: update old and remove unused dependencies
This commit updates all of the dependencies in package.json to
their most recent versions. It also removes dependencies that were
specified in package.json but not used - or only used in a
`require()` statement.

These changes have some ripple effects. Istanbul has not been
supported for some time, so it has been replaced with nyc.
The code coverage reporting tool from codacy has been updated
as well. This could not be tested without having the API token.

Finally, the CI job has been modified to run tests on Node.js
versions 10x and 12x. All older versions of Node.js are no longer
maintained.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-20 14:53:53 -04:00
Fabio José e7343b7993
Merge pull request #58 from danbev/use-const
Use const instead of var where applicable
2020-04-20 09:57:56 -03:00
Daniel Bevenius 704c497771 Fix minor typo in JSONFormatter comment
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-04-20 09:54:58 +02:00
Daniel Bevenius df85189a64 Use const instead of var where applicable
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-04-20 09:54:25 +02:00
Lance Ball 71a32d4e89
squash: fix linting error
Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-13 10:10:26 -04:00
Lance Ball 3a063d7245
fix: support mTLS in 1.0 Binary and Structured emitters
This commit modifies both of the 1.0 emitters so that they may
accept typed objects as a part of the configuration. When using
mTLS in Node, you need to provide an `Agent` to the underlying
HTTP handler. In this case, Axios will pass this object along to
Node.js when it is provided.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-08 16:13:57 -04:00
Fabio José 68ca47cc13 Missing semicolon
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-08 10:27:36 -03:00
Fabio José 99c595036a Missing semicolon
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-08 10:17:21 -03:00
Fabio José 470b97fd29 Missing semicolon
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-08 10:08:48 -03:00
Fabio José a66aafc5a6 Missing semicolon
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-08 10:07:51 -03:00
Fabio José 6a197941f8 Support for binary format
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 15:55:29 -03:00
Fabio José 4648305a77 http strutured: handle for data_base64
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 14:08:49 -03:00
Fabio José 49f4d5ec23 Process string, when is not base64
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 14:08:16 -03:00
Fabio José bf4967d30c supporting the data_base64
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 13:50:22 -03:00
Fabio José 1f8940c8a7 Support for data_base64 when event data is Binary
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 13:41:13 -03:00
Fabio José 16d9bfb7e3 asData improvement
asBuffer to transform UintArray to node Buffer

Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 13:15:35 -03:00
Fabio José 8b39902910 Calling getData() to apply some internal state
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 13:13:47 -03:00
Fabio José 89597985ba Binary as 'Uint32Array'
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 10:47:11 -03:00
Fabio José cf701e423c Remove HTTPUnmarshaller
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 10:13:04 -03:00
Fabio José 68aaf48ba7 HTTP Unmarshaller for spec 1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 10:06:47 -03:00
Fabio José 8c7de33ca8 Constants for binary receiver spec 1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 09:45:05 -03:00
Fabio José 645001af0f Http receiver binary for spec 1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 09:44:39 -03:00
Fabio José af7f7fe2ab Filter to process just the availble attributes
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 09:12:42 -03:00
Fabio José 456eb919b0 Constants for spec 1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-02 07:04:54 -03:00
Fabio José ef6f47c6f5 Structured http receiver for spec 1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-02 07:04:30 -03:00
Fabio José 0b9bf5a548 Function to validate types
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-10-31 17:51:16 -03:00
Fabio José 1905266d1f Validating extension types
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-10-31 17:50:54 -03:00
Fabio José 7d47b96273 Headers for binary mode spec v1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-10-29 21:15:08 -03:00
Fabio José ef3549e214 Emitter v1: for binary mode
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-10-29 21:14:17 -03:00
Fabio José 0d34de5315 Remaining attributes tests
Extensions

Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-10-29 16:19:19 -03:00
Fabio José 07f27426f3 Method to check against the json schema
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-10-29 14:03:09 -03:00
Fabio José acd29e142d Spec v1.0 required and optional attributes
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-10-29 10:58:16 -03:00