Commit Graph

598 Commits

Author SHA1 Message Date
Lance Ball c49693189d
docs: clean up spec compliance table on README.md (#252)
This commit separates the spec compliance table in the README.md file
into three: the core spec, event formats, and transport protocols.

Fixes: https://github.com/cloudevents/sdk-javascript/issues/166
Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-16 17:45:03 -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 de6f0a2945
docs(README): Update readme to mention that CloudEvents are read-only now (#248)
* also update readme with a mention about the cloneWith method

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-07-15 09:50:46 -04:00
Snyk bot 13bcdb4b98
fix: upgrade uuid from 8.1.0 to 8.2.0 (#250)
Snyk has created this PR to upgrade uuid from 8.1.0 to 8.2.0.

See this package in NPM:
https://www.npmjs.com/package/uuid

See this project in Snyk:
https://app.snyk.io/org/lance/project/37afc620-45ad-41a3-9acc-1ac155caebc7?utm_source=github&utm_medium=upgrade-pr

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-07-15 09:45:38 -04:00
dependabot[bot] 8e79fdcfed
build(deps-dev): bump standard-version from 7.1.0 to 8.0.1 (#247)
Bumps [standard-version](https://github.com/conventional-changelog/standard-version) from 7.1.0 to 8.0.1.
- [Release notes](https://github.com/conventional-changelog/standard-version/releases)
- [Changelog](https://github.com/conventional-changelog/standard-version/blob/master/CHANGELOG.md)
- [Commits](https://github.com/conventional-changelog/standard-version/compare/v7.1.0...v8.0.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-14 16:45:23 -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 90a998472c
chore: bump GH stale action to v3 (#243)
This is the first version that actually avoids closing stale issues if `days-before-close < 0`.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-07 16:10:53 -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 d65b0135e0
chore(actions): don't auto-close stale issues and pull requests (#235)
* chore(actions): don't auto-close stale issues and pull requests

Open issues and pull requests should be closed by a human who has considered
the issue/pr and made a choice based on the content of the issue/pr and the
state of the repository.

What this means in practice is that some issues will stay open for a long
time, even if they are stale. They may be open because it really is something
that will be considered for future work. Periodic issue triage should be
done by the maintainers, and if an issue _should_ be closed - for example,
the issue is no longer relevant - then a maintainer can close it.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-02 14:41:33 -04:00
Snyk bot 25077a9b43
fix: upgrade uuid from 8.0.0 to 8.1.0 (#220)
Snyk has created this PR to upgrade uuid from 8.0.0 to 8.1.0.

See this package in NPM:
https://www.npmjs.com/package/uuid

See this project in Snyk:
https://app.snyk.io/org/lance/project/37afc620-45ad-41a3-9acc-1ac155caebc7?utm_source=github&utm_medium=upgrade-pr

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-30 11:34:16 -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 850e893ca7
docs(README): fix wrong order of arguments in the accept example (#224)
fixes #222

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-18 17:11:46 -04:00
Lucas Holmquist 7012433074
chore: webpack should publish to bundles not _bundles (#227)
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-17 16:05:31 -04:00
Lance Ball 99bb88be00
examples: add a WebSocket example (#218)
There is nothing really to do in order to support events over websockets.
Since a `CloudEvent` can easily be represented in full with JSON, it can
be sent over a websocket as `event.toString()`. This example illustrates
sending a `CloudEvent` over websocket from a browser or CLI.

Fixes: https://github.com/cloudevents/sdk-javascript/issues/156
Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-10 17:50:35 -04:00
Lance Ball 8b2725b10a
feat: introduce browser support (#201)
This commit introduces a second `tsc` execution which generates JS in ES5 form.
Then, webpack is used to generate a browser bundle.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-10 17:49:01 -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
Lucas Holmquist dcb3c4e98a
chore: Update examples to use the latest sdk version(2.0.2) (#206)
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-09 18:08:15 -04:00
Grant Timmerman 42652819f3
feat: add types to package.json (#216)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-06-08 15:27:31 -07: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
Lucas Holmquist ed1d3286fa
docs: Update references of specific versions to use Latest Supported. (#211)
* docs: Update references of specific versions to use Latest Supported.

fixes #160

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-08 15:47:30 -04:00
Lance Ball b3d9dd2d2a
chore(release): 2.0.2 2020-06-08 14:00:56 -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
Lucas Holmquist 9857eda5ef
docs(README): fix example typo (#208)
fixes #173

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-06-04 18:04:03 -04: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
Grant Timmerman 1b9b3af176
Update README.md (#205)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-06-04 11:29:53 -07:00
Lance Ball fba3294ce0
fix: use /lib in gitignore so src/lib is not ignored (#199)
Signed-off-by: Lance Ball <lball@redhat.com>
2020-06-01 17:56:11 -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 edad2a6182
chore(release): 2.0.1 2020-06-01 14:03:55 -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
Doug Davis 15cd7638da
chore: minor typos in guidance docs (#196)
Signed-off-by: Doug Davis <dug@us.ibm.com>
2020-05-29 14:03:33 -04:00
Lance Ball aa320e7fe4
chore: CI workflow to only upload report if CODACY_PROJECT_TOKEN is set (#193)
GitHub will not set secrets in the environment when a pull request is submitted
from a forked repository. This commit modifies the CI workflow to only send
the report when the API token has been set. It also consolidates the two
workflows into a single one which shares coverage data between jobs.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-28 16:05:19 -04:00
Ali Ok 0710166ce9
fix: initialize CloudEvent's extensions property (#192)
Signed-off-by: Ali Ok <aliok@redhat.com>
2020-05-28 08:49:59 -04:00
Lance Ball daf945c50e
chore(release): 2.0.0 2020-05-27 13:52:33 -04:00
Lance Ball 349fe8e9bd
chore: add coverage GitHub action (#185)
* chore: use codacy coverage reporter via GH Action

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-27 08:45:42 -04:00
Lance Ball 0fe57d123a
chore: add GitHub action for CI on master and prs (#181)
* chore: replace travis-ci badge with github action
* chore: remove .travis.yaml

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-26 17:09:55 -04:00
Lance Ball fdc79ae120
docs: add maintainer guidelines for landing PRs (#177)
Fixes: https://github.com/cloudevents/sdk-javascript/issues/86

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-26 08:53:31 -04:00
Lance Ball f50e80fbf6
lib: make HTTPEmitter headers method a property of the class (#186)
Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-24 13:03:40 -04:00
Lance Ball abc114b24e
lib!: change CloudEvent to use direct object notation and get/set properties (#172)
This commit makes a substantial change to the API, changing the CloudEvent class
to accept properties as an object in the constructor. For example:

```js
const CloudEvent = require('cloudevents-sdk');

// all event properties except extensions may be set in the constructor
const event = new CloudEvent({
  source: 'http://my.event.source',
  type: 'test-event-type'
});

// get and set all properties standard property notation
console.log(event.time); // the event timestamp
event.subject = 'my event subject';
```

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-22 13:03:36 -04:00
Daniel Bevenius 57991e1e1b
lib: make headerByGetter a Map (#171)
This commit turns the headerByGetter Object into a Map to reduces some
code duplication an hopefully improve readability a little.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-19 10:06:54 -04:00
Lance Ball 2c469efaf5
build: add tsc type checks and emit declarations in the ci/test pipeline (#155)
This commit introduces TypeScript checks and generates type declarations
for the existing JavaScript codebase using `tsc` prior to running the linter task.

Ref: https://github.com/cloudevents/sdk-javascript/issues/9

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-18 14:56:01 -04:00
Lance Ball 6f0b5ea5f1
lib!: refactor HTTP bindings and specifications (#165)
This is a breaking change.

This commit makes a number of changes to the HTTP bindings code in an attempt
to simplify its usage and implementation. From a very high level, this inverts
the existing dependencies.

As an example, consider `lib/bindings/http/receiver_structured_1.js`.
https://github.com/cloudevents/sdk-javascript/blob/v1.0.0/lib/bindings/http/receiver_structured_0_3.js

This class instantiates `lib/bindings/http/receiver_structured.js` and delegates
its function invokations to it. This had the effect of requiring a user to know what
event versions they would be receiving. And for me personally was a little confusing
as a maintainer.

The change introduced here reverses that logic, so that the version agnostic receiver
is what the user instantiates. It instantiates the approrpiate version of a specific
receiever and delegates to it - reversing the dependencies.

I've also moved all of the top level directories related to HTTP versions into
`lib/bindings/http/v1` and `lib/bindings/http/v03` and generally done some rearranging
to make the repository structure cleaner and more organized.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-18 11:34:22 -04:00
Daniel Bevenius b99e6ea228
lib: correct name of CONTENT_ENCODING constant (#168)
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-18 09:44:58 -04:00
Lance Ball d836b06ffe
lib: expose constants as a top-level export (#161)
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>
2020-05-18 08:30:28 -04:00
Daniel Bevenius db42ad8d54
lib: remove result variable from asData (#167)
This commit removes the 'result' variable form the utility function
asData. The motivation is to improve readability.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-18 08:29:52 -04:00
Daniel Bevenius cf36a1578a
lib: remove version variable from getVersion (#163)
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>
2020-05-15 14:23:56 -04:00
Daniel Bevenius e2233f8978
lib: fix minor typo in ValidationError comment (#164)
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-05-15 12:11:50 -04:00