Commit Graph

19 Commits

Author SHA1 Message Date
Lance Ball 15f6505a58
BREAKING CHANGE: use string instead of enum for `Version` (#561)
TypeScript does not consider enum values equivalent, even if the string
representation is the same. So, when a module imports `cloudevents` and
also has a dependency on `cloudevents` this can cause conflicts where
the `CloudEvent.version` attribute is not considered equal when, in
fact, it is.

Changing the `enum` to a string is pretty straightforward, but should be
considered a breaking change since TypeScript dependents will
potentially fail the build with a change like this.

Signed-off-by: Lance Ball <lball@redhat.com>
2023-07-19 10:53:03 -04:00
Philip Sanetra 2d5fab1b71
fix: Make CloudEvent data field immutable and enumerable using Object.keys() (#515) (#516)
Signed-off-by: Philip Sanetra <code@psanetra.de>
2022-11-01 12:46:26 -04:00
Lance Ball b13bde9b49
feat: precompile cloudevent schema (#471)
* feat: precompile cloudevent schema

This commit modifies the build pipleline so that the cloudevent schema is
precompiled for runtime validation. This eliminates the need to compile the
schema at runtime, improving both performance and security.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2022-02-15 14:06:42 -05:00
Lance Ball 320354f750
chore: update cucumber dependency and remove prettier (#453)
The combination of prettier and eslint was causing some conflicting error
messages in formatting between VSCode and using npm in the CLI. For the most
part, there were only a couple of required formatting changes that prettier
was covering, so the change is minor.

The cucumber dependency had a major version bump and was carrying some unsafe
dependencies in the older version. This commit bumps to the new version and
makes appropriate configuration changes.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-12-22 10:45:35 -05:00
Lance Ball d941e2d4d9
feat: use generic type for CloudEvent data (#446)
Instead of using a big union of types, use a generic type for event data.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2021-11-29 17:03:12 -05:00
Grant Timmerman b38a48fa59
feat: add native logging with headers and body to CloudEvent (#437)
* feat: add native logging with headers and body to CloudEvent

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

* ci: simplify

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

* ci: simplify

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

* ci: returns to return

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

* ci: Update test/integration/cloud_event_test.ts

Co-authored-by: Lance Ball <lball@redhat.com>

* ci: revert symbol change

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

* refactor: improve ts for toString

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

Co-authored-by: Lance Ball <lball@redhat.com>
2021-10-04 11:11:38 -07:00
Lance Ball 2ff7852c36
fix: ensure source property has min length of 1 (#438)
Fixes: https://github.com/cloudevents/sdk-javascript/issues/383

Signed-off-by: Lance Ball <lball@redhat.com>
2021-09-29 09:55:37 -04:00
Lance Ball 2bd9a5a1e4
src!: remove support for 0.3 events (#425)
It has been nearly two years since 1.0 became final. This change removes
support for 0.3 events in the interest of simplifying the project a little.

Signed-off-by: Lance Ball <lball@redhat.com>
2021-08-27 10:34:32 -04:00
Remi Cattiau 80d987c1f6
chore: add copyrights header and lint rules (#418)
Signed-off-by: Remi Cattiau <remi@cattiau.com>
2021-05-14 09:28:49 -04:00
Lance Ball e7d99eb882
test: add a test for extension names with all caps. (#389)
See: https://github.com/cloudevents/sdk-javascript/issues/380

Signed-off-by: Lance Ball <lball@redhat.com>
2021-03-08 16:07:24 -05:00
Lance Ball 14468980f7
fix: do not alter an event's data attribute (#344)
* fix: do not alter an event's data attribute

When setting an event's data attribute we were trying to be really clever
and this is problematic. Instead, keep the data attribute unchanged. Per
the 1.0 specification, the data attribute is still inspected to determine
if it is binary, and if so, a data_base64 attribute is added with the
contents of the data property encoded as base64.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-10-06 08:20:54 -04:00
Lance Ball 1fa3a05aed
feat: add a constructor parameter for loose validation (#328)
* feat: add a constructor parameter for loose validation

This commit adds a second, optional boolean parameter to the `CloudEvent`
constructor. When `false` is provided, the event constructor will not
perform validation of the event properties, values and extension names.

This commit also modifies the ValidationError class so that the error message
string includes the JSON.stringified version of any schema validation
errors. It also makes the HTTP.toEvent() function create CloudEvent
objects with loose/no validation.

Incorporates comments from https://github.com/cloudevents/sdk-javascript/pull/328

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-09-08 15:32:16 -04:00
Lance Ball 6cd310c141
src(event)!: make the event's time property only a string (#330)
Previously, the event's `time` property could be either a string or a date.
this commit modifies that to ensure that the object can only be created with
a timestamp in string format. As long as the string is a valid date, that
can be parsed by `new Date(Date.parse(str))` then whenever the event is
serialized as JSON, the `time` attribute will be formatted as per RFC 3339.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-09-01 10:10:16 -04:00
Lance Ball b5cf8865b9
test: implement pending tests leftover from TS rewrite (#315)
This commit implements 4 of the 6 pending tests that were not completed
during the TypeScript rewrite. The two tests that were not implemented
were (one for each of v1 and v03):

```
it("returns a JSON string even if format is invalid");
```

I don't really know what that's supposed to be/mean, so I removed them.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-08-12 16:49:21 -04:00
Lance Ball b99f728190
fix: ensure that event data can be an array, number, boolean or null (#281)
The schema incorrectly limits data values to only object and string. This is
incorrect, since JSON can be an array, boolean, a single number or null as well.

This commit modifies the schema to allow for array, boolean and null, and adds
tests.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-29 08:35:23 -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
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