Skip to content

Commit 6097622

Browse files
authored
Merge pull request #2 from cloudevents/master
Merge
2 parents 133b864 + e219a30 commit 6097622

File tree

18 files changed

+245
-147
lines changed

18 files changed

+245
-147
lines changed

CHANGELOG.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,93 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [3.0.1](https://github.com/cloudevents/sdk-javascript/compare/v3.0.0...v3.0.1) (2020-07-29)
6+
7+
8+
### Bug Fixes
9+
10+
* ensure that event data can be an array, number, boolean or null ([#281](https://github.com/cloudevents/sdk-javascript/issues/281)) ([b99f728](https://github.com/cloudevents/sdk-javascript/commit/b99f7281904b41d9058fec8f51019c5937821dc9))
11+
12+
13+
### Miscellaneous
14+
15+
* move typedoc them to a dev dependency. ([#279](https://github.com/cloudevents/sdk-javascript/issues/279)) ([c76dda6](https://github.com/cloudevents/sdk-javascript/commit/c76dda6d1052964b772533306f58ef46c8c9b642)), closes [#278](https://github.com/cloudevents/sdk-javascript/issues/278)
16+
17+
## [3.0.0](https://github.com/cloudevents/sdk-javascript/compare/v2.0.2...v3.0.0) (2020-07-27)
18+
19+
20+
### ⚠ BREAKING CHANGES
21+
22+
* This validates the value of the cloud event extension based on the spec,
23+
https://github.com/cloudevents/spec/blob/master/spec.md#type-system
24+
25+
Signed-off-by: Lucas Holmquist <[email protected]>
26+
* This changes the modules name from cloudevents-sdk to cloudevents
27+
28+
* feat: use npm name cloudevents
29+
* **src:** * 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
30+
31+
Signed-off-by: Lucas Holmquist <[email protected]>
32+
* **src:** * This change makes the CloudEvent Read-only and validates the input during object creation.
33+
34+
* To augment an already created CloudEvent object, we have added a `cloneWith` method that takes attributes to add/update.
35+
36+
Signed-off-by: Lucas Holmquist <[email protected]>
37+
38+
### Features
39+
40+
* add types to package.json ([#216](https://github.com/cloudevents/sdk-javascript/issues/216)) ([4265281](https://github.com/cloudevents/sdk-javascript/commit/42652819f32df245e4e314d2df3758f6e5ca6926))
41+
* introduce browser support ([#201](https://github.com/cloudevents/sdk-javascript/issues/201)) ([8b2725b](https://github.com/cloudevents/sdk-javascript/commit/8b2725b10a10ba5da842e23d3d2673b27ca450df))
42+
* pass extension into the constructor. ([#214](https://github.com/cloudevents/sdk-javascript/issues/214)) ([0378f4c](https://github.com/cloudevents/sdk-javascript/commit/0378f4cdf9fde647ac3ffe1f9fb6bd3ff0924280)), closes [#209](https://github.com/cloudevents/sdk-javascript/issues/209)
43+
* remove unused plugins ([#262](https://github.com/cloudevents/sdk-javascript/issues/262)) ([4014da2](https://github.com/cloudevents/sdk-javascript/commit/4014da26f5ae00d8846ab804ba0fb847051c44eb))
44+
* simplify validation logic/imports ([#265](https://github.com/cloudevents/sdk-javascript/issues/265)) ([4b54b27](https://github.com/cloudevents/sdk-javascript/commit/4b54b272a5578523c3a03b21720cb89c0d5177db))
45+
* use npm name cloudevents ([#260](https://github.com/cloudevents/sdk-javascript/issues/260)) ([565f867](https://github.com/cloudevents/sdk-javascript/commit/565f8674246b5f60ff78141ea9548b4137e2befc)), closes [#215](https://github.com/cloudevents/sdk-javascript/issues/215)
46+
* **src:** A CloudEvent should be readonly but provide a way to augment itself. ([#234](https://github.com/cloudevents/sdk-javascript/issues/234)) ([c7a8477](https://github.com/cloudevents/sdk-javascript/commit/c7a84772d59647e2a94991a3051b37b097b0d404))
47+
* **src:** add ext name validation ([#246](https://github.com/cloudevents/sdk-javascript/issues/246)) ([84f1ed9](https://github.com/cloudevents/sdk-javascript/commit/84f1ed9cfe54d60978c525de5b0c49cf38839deb))
48+
49+
50+
### Bug Fixes
51+
52+
* do not require an HTTP body on incoming binary event messages ([a7c326b](https://github.com/cloudevents/sdk-javascript/commit/a7c326b48cf702a077fc4af1eda3f686429ba9df))
53+
* ensure that the HTTP receiver sanitizes headers in accept() ([#239](https://github.com/cloudevents/sdk-javascript/issues/239)) ([51035dc](https://github.com/cloudevents/sdk-javascript/commit/51035dc65b98ce7912d57a78d214612c05c5dc00))
54+
* package.json & package-lock.json to reduce vulnerabilities ([#253](https://github.com/cloudevents/sdk-javascript/issues/253)) ([2ed5f84](https://github.com/cloudevents/sdk-javascript/commit/2ed5f844570efdf3ccc301fd5854fe4100921e04))
55+
* parse method mutating its input ([#231](https://github.com/cloudevents/sdk-javascript/issues/231)) ([060b21b](https://github.com/cloudevents/sdk-javascript/commit/060b21ba36a37afc9002fe2e3d2d3b161633f9ae))
56+
* upgrade uuid from 8.0.0 to 8.1.0 ([#220](https://github.com/cloudevents/sdk-javascript/issues/220)) ([25077a9](https://github.com/cloudevents/sdk-javascript/commit/25077a9b43bc2e54cd52266fb664a9c523d3f65c))
57+
* upgrade uuid from 8.1.0 to 8.2.0 ([#250](https://github.com/cloudevents/sdk-javascript/issues/250)) ([13bcdb4](https://github.com/cloudevents/sdk-javascript/commit/13bcdb4b9817bcf28991269f554f73893b42b458))
58+
59+
60+
### Tests
61+
62+
* inplement the cucumber conformance tests from cloudevents/spec ([#238](https://github.com/cloudevents/sdk-javascript/issues/238)) ([dca2811](https://github.com/cloudevents/sdk-javascript/commit/dca2811627f36427a3b9bc710cc338d76f5d6f8b))
63+
64+
65+
### Documentation
66+
67+
* clean up spec compliance table on README.md ([#252](https://github.com/cloudevents/sdk-javascript/issues/252)) ([c496931](https://github.com/cloudevents/sdk-javascript/commit/c49693189d16655b0de50f1c52baea6ec3e1d9ba))
68+
* **README:** fix wrong order of arguments in the accept example ([#224](https://github.com/cloudevents/sdk-javascript/issues/224)) ([850e893](https://github.com/cloudevents/sdk-javascript/commit/850e893ca7103846e5e85905523a0913ee8a8f4e)), closes [#222](https://github.com/cloudevents/sdk-javascript/issues/222)
69+
* **README:** Update readme to mention that CloudEvents are read-only now ([#248](https://github.com/cloudevents/sdk-javascript/issues/248)) ([de6f0a2](https://github.com/cloudevents/sdk-javascript/commit/de6f0a2945f4fdfb3fdee75c0e20c863a356ff90))
70+
* generate api documentation as a GitHub workflow ([#217](https://github.com/cloudevents/sdk-javascript/issues/217)) ([44b791b](https://github.com/cloudevents/sdk-javascript/commit/44b791bf97fdbcd7e1c4a0a7725e4707892653b7))
71+
* Update references of specific versions to use Latest Supported. ([#211](https://github.com/cloudevents/sdk-javascript/issues/211)) ([ed1d328](https://github.com/cloudevents/sdk-javascript/commit/ed1d3286fa85a0f2eb4c02f4588d9f80dccc5ece)), closes [#160](https://github.com/cloudevents/sdk-javascript/issues/160)
72+
73+
74+
### lib
75+
76+
* validate extension values ([#251](https://github.com/cloudevents/sdk-javascript/issues/251)) ([3c8273f](https://github.com/cloudevents/sdk-javascript/commit/3c8273f1140455ce8346918942c44dda241ead4c))
77+
78+
79+
### Miscellaneous
80+
81+
* add vscode task JSON and GitHub issue/pr templates ([#268](https://github.com/cloudevents/sdk-javascript/issues/268)) ([1613595](https://github.com/cloudevents/sdk-javascript/commit/1613595a38ba1d268dc45da4b09239dfac8afee8))
82+
* adds the return type for the extensions ([#221](https://github.com/cloudevents/sdk-javascript/issues/221)) ([5ab8164](https://github.com/cloudevents/sdk-javascript/commit/5ab81641aeaa7ef2d5dc23265277c65be144a881))
83+
* bump GH stale action to v3 ([#243](https://github.com/cloudevents/sdk-javascript/issues/243)) ([90a9984](https://github.com/cloudevents/sdk-javascript/commit/90a998472c133dfc54c497eb87224fecce2ae031))
84+
* combine v03 and v1 event interfaces, specs and schemas into single files([#270](https://github.com/cloudevents/sdk-javascript/issues/270)) ([129ec48](https://github.com/cloudevents/sdk-javascript/commit/129ec485d96dd38cb1d12f8074c6fcfb4cf6e689))
85+
* consolidate HTTP parsers and header maps into single files ([#267](https://github.com/cloudevents/sdk-javascript/issues/267)) ([45850e3](https://github.com/cloudevents/sdk-javascript/commit/45850e329a636904924d9d719771fdf4ec683a5d))
86+
* simplify ce version parsers ([#274](https://github.com/cloudevents/sdk-javascript/issues/274)) ([3d82fb6](https://github.com/cloudevents/sdk-javascript/commit/3d82fb629182edaee11e571ea895a5f8a7456a0e))
87+
* simplify parser logic and duplicated code ([#269](https://github.com/cloudevents/sdk-javascript/issues/269)) ([a6124cc](https://github.com/cloudevents/sdk-javascript/commit/a6124cc350a106ea41bba2ccd1e0cb42a67f99bf))
88+
* **actions:** don't auto-close stale issues and pull requests ([#235](https://github.com/cloudevents/sdk-javascript/issues/235)) ([d65b013](https://github.com/cloudevents/sdk-javascript/commit/d65b0135e0b5238f7d6e0c4a683401c1dc625b38))
89+
* Update examples to use the latest sdk version(2.0.2) ([#206](https://github.com/cloudevents/sdk-javascript/issues/206)) ([dcb3c4e](https://github.com/cloudevents/sdk-javascript/commit/dcb3c4e98acb5fc4fca518d2121a46797388456f))
90+
* webpack should publish to bundles not _bundles ([#227](https://github.com/cloudevents/sdk-javascript/issues/227)) ([7012433](https://github.com/cloudevents/sdk-javascript/commit/701243307440da7b9890e10faf6d57368912c4a7))
91+
592
### [2.0.2](https://github.com/cloudevents/sdk-javascript/compare/v2.0.1...v2.0.2) (2020-06-08)
693

794

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ const {
3939
Receiver
4040
} = require("cloudevents");
4141

42-
// Create a receiver to accept events over HTTP
43-
const receiver = new Receiver();
44-
4542
// body and headers come from an incoming HTTP request, e.g. express.js
46-
const receivedEvent = receiver.accept(req.headers, req.body);
43+
const receivedEvent = Receiver.accept(req.headers, req.body);
4744
console.log(receivedEvent);
4845
```
4946

@@ -157,4 +154,4 @@ We love contributions from the community! Please check the
157154
for information on how to get involved.
158155

159156
[v1spec]: https://github.com/cloudevents/spec/tree/v1.0
160-
[v103pec]: https://github.com/cloudevents/spec/tree/v0.3
157+
[v103pec]: https://github.com/cloudevents/spec/tree/v0.3

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloudevents",
3-
"version": "2.0.2",
3+
"version": "3.0.1",
44
"description": "CloudEvents SDK for JavaScript",
55
"main": "dist/index.js",
66
"scripts": {
@@ -97,7 +97,6 @@
9797
"dependencies": {
9898
"ajv": "~6.12.3",
9999
"axios": "~0.19.2",
100-
"typedoc-clarity-theme": "^1.1.0",
101100
"uuid": "~8.2.0"
102101
},
103102
"devDependencies": {
@@ -129,6 +128,7 @@
129128
"standard-version": "^8.0.1",
130129
"ts-node": "^8.10.2",
131130
"typedoc": "^0.17.7",
131+
"typedoc-clarity-theme": "~1.1.0",
132132
"typescript": "^3.8.3",
133133
"webpack": "^4.43.0",
134134
"webpack-cli": "^3.3.11"

src/event/cloudevent.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
CloudEventV1OptionalAttributes,
1010
} from "./interfaces";
1111
import { validateV1, validateV03 } from "./spec";
12-
import { ValidationError, isBinary, asBase64 } from "./validation";
12+
import { ValidationError, isBinary, asBase64, isValidType } from "./validation";
1313
import CONSTANTS from "../constants";
1414
import { isString } from "util";
1515

@@ -108,6 +108,13 @@ export class CloudEvent implements CloudEventV1, CloudEventV03 {
108108
if (!key.match(/^[a-z0-9]{1,20}$/)) {
109109
throw new ValidationError("invalid extension name");
110110
}
111+
112+
// Value should be spec compliant
113+
// https://github.com/cloudevents/spec/blob/master/spec.md#type-system
114+
if (!isValidType(value)) {
115+
throw new ValidationError("invalid extension value");
116+
}
117+
111118
this[key] = value;
112119
}
113120

src/event/schemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const schemaV1 = {
1010
type: "string",
1111
},
1212
data: {
13-
type: ["object", "string"],
13+
type: ["object", "string", "array", "number", "boolean", "null"],
1414
},
1515
data_base64: {
1616
type: "string",
@@ -89,7 +89,7 @@ export const schemaV03 = {
8989
type: "string",
9090
},
9191
data: {
92-
type: ["object", "string"],
92+
type: ["object", "string", "array", "number", "boolean", "null"],
9393
},
9494
event: {
9595
properties: {

src/event/spec.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,21 @@
11
import Ajv from "ajv";
2-
import { v4 as uuidv4 } from "uuid";
32
import { ValidationError, isBase64 } from "./validation";
43

5-
import { CloudEvent } from "./cloudevent";
6-
import { CloudEventV1, CloudEventV1Attributes, CloudEventV03, CloudEventV03Attributes } from "./interfaces";
4+
import { CloudEventV1, CloudEventV03 } from "./interfaces";
75
import { schemaV03, schemaV1 } from "./schemas";
86
import CONSTANTS from "../constants";
97

108
const ajv = new Ajv({ extendRefs: true });
119
const isValidAgainstSchemaV1 = ajv.compile(schemaV1);
1210
const isValidAgainstSchemaV03 = ajv.compile(schemaV03);
1311

14-
export function createV1(attributes: CloudEventV1Attributes): CloudEventV1 {
15-
const event: CloudEventV1 = {
16-
specversion: schemaV1.definitions.specversion.const,
17-
id: uuidv4(),
18-
time: new Date().toISOString(),
19-
...attributes,
20-
};
21-
return new CloudEvent(event);
22-
}
23-
2412
export function validateV1(event: CloudEventV1): boolean {
2513
if (!isValidAgainstSchemaV1(event)) {
2614
throw new ValidationError("invalid payload", isValidAgainstSchemaV1.errors);
2715
}
2816
return true;
2917
}
3018

31-
export function createV03(attributes: CloudEventV03Attributes): CloudEventV03 {
32-
const event: CloudEventV03 = {
33-
specversion: schemaV03.definitions.specversion.const,
34-
id: uuidv4(),
35-
time: new Date().toISOString(),
36-
...attributes,
37-
};
38-
return new CloudEvent(event);
39-
}
40-
4119
export function validateV03(event: CloudEventV03): boolean {
4220
if (!isValidAgainstSchemaV03(event)) {
4321
throw new ValidationError("invalid payload", isValidAgainstSchemaV03.errors);

src/event/validation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ export const asData = (data: unknown, contentType: string): string => {
8181
return isBinary(maybeJson) ? asBase64(maybeJson) : maybeJson;
8282
};
8383

84-
export const isValidType = (v: boolean | number | string | Date | Uint32Array): boolean =>
85-
isBoolean(v) || isInteger(v) || isString(v) || isDate(v) || isBinary(v);
84+
export const isValidType = (v: boolean | number | string | Date | Uint32Array | unknown): boolean =>
85+
isBoolean(v) || isInteger(v) || isString(v) || isDate(v) || isBinary(v) || isObject(v);

src/transport/http/binary_receiver.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { CloudEvent, Version } from "../..";
22
import { CloudEventV1, CloudEventV03 } from "../../event/interfaces";
33
import { validateV1, validateV03 } from "../../event/spec";
44
import { Headers, validate } from "./headers";
5-
import { binaryParsers as v1Parsers } from "./v1";
6-
import { binaryParsers as v03Parsers } from "./v03";
5+
import { v03binaryParsers, v1binaryParsers } from "./versions";
76
import { parserByContentType, MappedParser } from "../../parsers";
87
import { isString, isBase64, ValidationError, isStringOrObjectOrThrow } from "../../event/validation";
98
import CONSTANTS from "../../constants";
@@ -52,7 +51,7 @@ export class BinaryHTTPReceiver {
5251
const sanitizedHeaders = validate(headers);
5352

5453
const eventObj: { [key: string]: unknown | string | Record<string, unknown> } = {};
55-
const parserMap: Record<string, MappedParser> = this.version === Version.V1 ? v1Parsers : v03Parsers;
54+
const parserMap: Record<string, MappedParser> = this.version === Version.V1 ? v1binaryParsers : v03binaryParsers;
5655

5756
for (const header in parserMap) {
5857
if (sanitizedHeaders[header]) {

src/transport/http/headers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ValidationError, CloudEvent } from "../..";
2-
import { headerMap as v1Map } from "./v1";
3-
import { headerMap as v03Map } from "./v03";
2+
import { v03headerMap, v1headerMap } from "./versions";
43
import { Version } from "../../event/cloudevent";
54
import { MappedParser } from "../../parsers";
65
import CONSTANTS from "../../constants";
@@ -60,9 +59,9 @@ export function headersFor(event: CloudEvent): Headers {
6059
const headers: Headers = {};
6160
let headerMap: Readonly<{ [key: string]: MappedParser }>;
6261
if (event.specversion === Version.V1) {
63-
headerMap = v1Map;
62+
headerMap = v1headerMap;
6463
} else {
65-
headerMap = v03Map;
64+
headerMap = v03headerMap;
6665
}
6766

6867
// iterate over the event properties - generate a header for each

0 commit comments

Comments
 (0)