Commit Graph

742 Commits

Author SHA1 Message Date
Daniel Bevenius e43e66028d build: update package-lock.json
After updating and running npm install the package-lock.json file is
updated. I can see that packate-lock.json was included in
Commit b283583c0c ("docs: add JSDocs for
top level API objects") but perhaps there were changes to package.json
that were made after and went unnoticed.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-13 10:38:10 +02:00
Lance Ball b283583c0c
docs: add JSDocs for top level API objects (#140)
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>
2020-05-12 17:27:11 -04:00
Helio Frota f8a62b2843
chore: adds files section in package.json (#147)
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-05-12 15:01:40 -04:00
Daniel Bevenius 2882affb38
test: use constants in spec_03_tests.js (#144)
Co-authored-by: Lance Ball <lball@redhat.com>
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-12 14:56:18 -04:00
Daniel Bevenius 847fff8db2
lib: remove mode variable from getMode (#142)
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>
2020-05-12 14:50:07 -04:00
Daniel Bevenius 94974a7efa
lib: add .js suffix to receiver_binary_0_3 (#143)
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>
2020-05-12 14:49:22 -04:00
Daniel Bevenius c56c203d6a
test: remove uuid require in spec_03_tests.js (#145)
This commit removes the require of uuid from this test and uses a
hardcoded value for the 'id' constant instead.

The motivation for this is that the value for 'id' does not need to be
generated for each test run, and fewer requires helps readabilitly I
find.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-12 14:48:35 -04:00
Daniel Bevenius b7b491202a
lib: remove unnecessary else statements (#146)
This commit removes two unnecessary else clauses in unmarshaller.js, and
also extracts the throwing of TypeError of invalid content types into a
separate function to avoid some code duplication.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-12 14:48:12 -04:00
Lance Ball fd99cb1e59
docs: add instructions and details to contributors guide (#105)
This commit adds instructions and details to contributors guide and provides detailed guidance for pull requests and maintainers in separate documents.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-11 20:08:45 -04:00
Lance Ball ef7550d60d
fix: throw "no cloud event detected" if one can't be read (#139)
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>
2020-05-11 09:42:16 -04:00
Lance Ball b866edddd9
docs: update README and examples with new API (#138)
This commit modifies the README to show new API usage for the
`HTTPReceiver` and `CloudEvent` classes, and updates the examples
to use this as well.

Overall structure and content has been modified to look more like
the sdk-go README.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-11 09:41:05 -04:00
Lance Ball 5a6cde5695
chore: add action to detect and close stale issues
Using this GH action will prevent issues and pull requests from sitting unattended for more than 30 days.

Ref: https://github.com/actions/stale
2020-05-09 00:24:03 -04:00
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
Helio Frota c1fda94d25
chore: Modify CI to also build backport branch(es) (#122)
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-05-07 10:23:37 -04:00
Daniel Bevenius 60bf05c8f2
test: use header constants in receiver tests (#131)
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-06 20:05:33 -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
Grant Timmerman 07323e078f
docs: organize README badges and remove TS example (#112)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-05-04 10:33:40 -07:00
Grant Timmerman 223a7c6f03
docs: remove repo structure docs (#111)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-05-04 10:25:48 -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
Helio Frota 53524acb0e
fix: misspelled word (#115)
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-05-02 08:30:01 -07:00
Grant Timmerman f30c814a09
chore: remove note with bad link and non SDK docs (#109)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-05-01 10:59:21 -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
Grant Timmerman 56036b09dd docs: remove 0.1, 0.2 spec support from README
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-30 12:31:08 -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 005d5327e4
chore: add npm fix command (#74)
* feat: add npm fix command

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

* feat: add npm fix command

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-29 13:36:21 -07: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 6c223e2c34
fix: remove d.ts types. Fixes #83 (#84)
Fixes: https://github.com/cloudevents/sdk-javascript/issues/83

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-29 16:06:57 -04: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
Helio Frota bb8e0f9e0c
fix: Fix Express example installation (#77)
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-04-29 10:44:02 -07:00
Lance Ball 8fb0ddf6eb
chore: fix CI code coverage publishing (#78)
The code coverage publishing in package.json works fine on non-ubuntu systems.
However, in Ubuntu `/bin/sh` is symlinked to `/bin/dash` which doesn't support
everything supported by `/bin/bash` - specifically `-o pipefail`.

This commit changes the code coverage script to explicitly use `bash` instead.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-29 12:10:25 -04:00
Lance Ball f47bca4ff0 chore: add standard-version and release script
This commit adds the `standard-version` module for managing releases.
When running `npm run release` the following steps are taken.

1. Retreive the current version of your repository by looking at package.json.
2. Bump the version in package.json based on the commits.
3. Prepends to the CHANGELOG based on the commits (uses conventional-changelog under the hood).
4. Create a new commit including the package.json and updated CHANGELOG.
5. Create a new tag with the new version number.

This works best if all commits follow the Conventional Commits specification.
https://www.conventionalcommits.org/en/v1.0.0/

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-29 08:50:52 -03:00
Daniel Bevenius e0878055a2
test: use header constants in unmarshaller tests (#60)
This commit updates the http unmarshaller tests to use the constants
available in lib/bindings/http/constants.js.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-04-28 21:14:39 -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
Fabio José 1a4bdce192
Merge pull request #55 from lance/54-add-linter
src: add eslint configuration and npm script
2020-04-28 13:01:03 -03:00
Fabio José bb9b2118f5
Merge pull request #63 from grant/patch-1
Delete OLDOCS.md
2020-04-27 15:24:04 -03:00
Grant Timmerman fc1cb7fb69 Delete OLDOCS.md
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-24 17:27:53 -07: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
Fabio José b03a243b20
Merge pull request #49 from lance/dependency-updates
deps: update old and remove unused dependencies
2020-04-22 09:23:25 -03: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
Fabio José 23426fc4ec
Merge pull request #57 from danbev/formatter-comment
Fix minor typo in JSONFormatter comment
2020-04-20 09:53:43 -03:00