Skip to content

Commit dcb3c4e

Browse files
authored
chore: Update examples to use the latest sdk version(2.0.2) (cloudevents#206)
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
1 parent 4265281 commit dcb3c4e

File tree

7 files changed

+38
-40
lines changed

7 files changed

+38
-40
lines changed

examples/express-ex/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22

33
const express = require("express");
4-
const { HTTPReceiver } = require("../../src");
4+
const { HTTPReceiver } = require("cloudevents-sdk");
55

66
const app = express();
77
const receiver = new HTTPReceiver();

examples/express-ex/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"author": "fabiojose@gmail.com",
1515
"license": "Apache-2.0",
1616
"dependencies": {
17-
"cloudevents-sdk": "~1.0.0",
17+
"cloudevents-sdk": "~2.0.2",
1818
"express": "^4.17.1"
1919
}
2020
}

examples/typescript-ex/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ Then, start
1515
```bash
1616
npm start
1717
```
18-
19-
See your event payload [here, at requestbin](https://requestbin.com/r/enu90y24i64jp)

examples/typescript-ex/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "Apache-2.0",
1212
"keywords": [],
1313
"scripts": {
14-
"start": "node build/src/index.js",
14+
"start": "node build/index.js",
1515
"test": "echo \"Error: no test specified\" && exit 1",
1616
"check": "gts check",
1717
"clean": "gts clean",
@@ -22,9 +22,9 @@
2222
"posttest": "npm run check"
2323
},
2424
"devDependencies": {
25-
"gts": "^1.1.0",
26-
"typescript": "~3.5.0",
2725
"@types/node": "^8.9.0",
28-
"cloudevents-sdk": "1.0.0"
26+
"cloudevents-sdk": "~2.0.2",
27+
"gts": "^1.1.0",
28+
"typescript": "~3.9.5"
2929
}
3030
}

examples/typescript-ex/prettier.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/typescript-ex/src/index.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
1-
import { CloudEvent, HTTPREceiver } from '../../';
1+
import { CloudEvent, HTTPReceiver } from "cloudevents-sdk";
2+
import { CloudEventV1 } from "cloudevents-sdk/lib/v1";
23

34
export function doSomeStuff() {
4-
const receiver = new HTTPREceiver();
5+
const receiver = new HTTPReceiver();
56

6-
const myevent: CloudEvent = new CloudEvent()
7-
.source('/source')
8-
.type('type')
9-
.dataContentType('text/plain')
10-
.dataschema('http://d.schema.com/my.json')
11-
.subject('cha.json')
12-
.data('my-data')
13-
.addExtension("my-ext", "0x600");
7+
const myevent: CloudEventV1 = new CloudEvent({
8+
source: "/source",
9+
type: "type",
10+
dataContentType: "text/plain",
11+
dataSchema: "https://d.schema.com/my.json",
12+
subject: "cha.json",
13+
data: "my-data"
14+
});
15+
myevent.addExtension("extension-1", "some extension data");
1416

15-
console.log(myevent.toString());
16-
console.log(myevent.getExtensions());
17+
console.log("My structured event:", myevent.toString());
18+
console.log("My structured event extensions:", myevent.getExtensions());
1719

1820
// ------ receiver structured
19-
const payload = myevent.toString();
21+
// The header names should be standarized to use lowercase
2022
const headers = {
21-
"Content-Type":"application/cloudevents+json"
23+
"content-type": "application/cloudevents+json"
2224
};
2325

24-
console.log(receiver.accept(headers, payload).toString());
26+
// Typically used with an incoming HTTP request where myevent.format() is the actual
27+
// body of the HTTP
28+
console.log("Received structured event:", receiver.accept(headers, myevent.format()).toString());
2529

2630
// ------ receiver binary
27-
const extension1 = "mycuston-ext1";
2831
const data = {
29-
"data" : "dataString"
32+
"data": "dataString"
3033
};
3134
const attributes = {
32-
"ce-type" : "type",
33-
"ce-specversion" : "1.0",
34-
"ce-source" : "source",
35-
"ce-id" : "id",
36-
"ce-time" : "2019-06-16T11:42:00Z",
37-
"ce-dataschema" : "http://schema.registry/v1",
38-
"Content-Type" : "application/json",
39-
"ce-extension1" : extension1
35+
"ce-type": "type",
36+
"ce-specversion": "1.0",
37+
"ce-source": "source",
38+
"ce-id": "id",
39+
"ce-time": "2019-06-16T11:42:00Z",
40+
"ce-dataschema": "http://schema.registry/v1",
41+
"Content-Type": "application/json",
42+
"ce-extension1": "extension1"
4043
};
4144

42-
console.log(receiver.accept(attributes, data).toString());
45+
console.log("My binary event:", receiver.accept(attributes, data).toString());
46+
console.log("My binary event extensions:", receiver.accept(attributes, data).toString());
4347

4448
return true;
4549
}

examples/typescript-ex/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"extends": "./node_modules/gts/tsconfig-google.json",
33
"compilerOptions": {
4-
"rootDir": ".",
5-
"outDir": "build",
4+
"rootDir": "./src",
5+
"outDir": "./build/",
66
"lib": [
77
"es6",
88
"dom"

0 commit comments

Comments
 (0)