chore: Update examples to use the latest sdk version(2.0.2) (#206)
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
This commit is contained in:
parent
42652819f3
commit
dcb3c4e98a
|
@ -1,7 +1,7 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const { HTTPReceiver } = require("../../src");
|
const { HTTPReceiver } = require("cloudevents-sdk");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const receiver = new HTTPReceiver();
|
const receiver = new HTTPReceiver();
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"author": "fabiojose@gmail.com",
|
"author": "fabiojose@gmail.com",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cloudevents-sdk": "~1.0.0",
|
"cloudevents-sdk": "~2.0.2",
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,3 @@ Then, start
|
||||||
```bash
|
```bash
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
See your event payload [here, at requestbin](https://requestbin.com/r/enu90y24i64jp)
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node build/src/index.js",
|
"start": "node build/index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"check": "gts check",
|
"check": "gts check",
|
||||||
"clean": "gts clean",
|
"clean": "gts clean",
|
||||||
|
@ -22,9 +22,9 @@
|
||||||
"posttest": "npm run check"
|
"posttest": "npm run check"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gts": "^1.1.0",
|
|
||||||
"typescript": "~3.5.0",
|
|
||||||
"@types/node": "^8.9.0",
|
"@types/node": "^8.9.0",
|
||||||
"cloudevents-sdk": "1.0.0"
|
"cloudevents-sdk": "~2.0.2",
|
||||||
|
"gts": "^1.1.0",
|
||||||
|
"typescript": "~3.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
singleQuote: true,
|
|
||||||
trailingComma: "es5"
|
|
||||||
};
|
|
|
@ -1,45 +1,49 @@
|
||||||
import { CloudEvent, HTTPREceiver } from '../../';
|
import { CloudEvent, HTTPReceiver } from "cloudevents-sdk";
|
||||||
|
import { CloudEventV1 } from "cloudevents-sdk/lib/v1";
|
||||||
|
|
||||||
export function doSomeStuff() {
|
export function doSomeStuff() {
|
||||||
const receiver = new HTTPREceiver();
|
const receiver = new HTTPReceiver();
|
||||||
|
|
||||||
const myevent: CloudEvent = new CloudEvent()
|
const myevent: CloudEventV1 = new CloudEvent({
|
||||||
.source('/source')
|
source: "/source",
|
||||||
.type('type')
|
type: "type",
|
||||||
.dataContentType('text/plain')
|
dataContentType: "text/plain",
|
||||||
.dataschema('http://d.schema.com/my.json')
|
dataSchema: "https://d.schema.com/my.json",
|
||||||
.subject('cha.json')
|
subject: "cha.json",
|
||||||
.data('my-data')
|
data: "my-data"
|
||||||
.addExtension("my-ext", "0x600");
|
});
|
||||||
|
myevent.addExtension("extension-1", "some extension data");
|
||||||
|
|
||||||
console.log(myevent.toString());
|
console.log("My structured event:", myevent.toString());
|
||||||
console.log(myevent.getExtensions());
|
console.log("My structured event extensions:", myevent.getExtensions());
|
||||||
|
|
||||||
// ------ receiver structured
|
// ------ receiver structured
|
||||||
const payload = myevent.toString();
|
// The header names should be standarized to use lowercase
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type":"application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(receiver.accept(headers, payload).toString());
|
// Typically used with an incoming HTTP request where myevent.format() is the actual
|
||||||
|
// body of the HTTP
|
||||||
|
console.log("Received structured event:", receiver.accept(headers, myevent.format()).toString());
|
||||||
|
|
||||||
// ------ receiver binary
|
// ------ receiver binary
|
||||||
const extension1 = "mycuston-ext1";
|
|
||||||
const data = {
|
const data = {
|
||||||
"data" : "dataString"
|
"data": "dataString"
|
||||||
};
|
};
|
||||||
const attributes = {
|
const attributes = {
|
||||||
"ce-type" : "type",
|
"ce-type": "type",
|
||||||
"ce-specversion" : "1.0",
|
"ce-specversion": "1.0",
|
||||||
"ce-source" : "source",
|
"ce-source": "source",
|
||||||
"ce-id" : "id",
|
"ce-id": "id",
|
||||||
"ce-time" : "2019-06-16T11:42:00Z",
|
"ce-time": "2019-06-16T11:42:00Z",
|
||||||
"ce-dataschema" : "http://schema.registry/v1",
|
"ce-dataschema": "http://schema.registry/v1",
|
||||||
"Content-Type" : "application/json",
|
"Content-Type": "application/json",
|
||||||
"ce-extension1" : extension1
|
"ce-extension1": "extension1"
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(receiver.accept(attributes, data).toString());
|
console.log("My binary event:", receiver.accept(attributes, data).toString());
|
||||||
|
console.log("My binary event extensions:", receiver.accept(attributes, data).toString());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"extends": "./node_modules/gts/tsconfig-google.json",
|
"extends": "./node_modules/gts/tsconfig-google.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": ".",
|
"rootDir": "./src",
|
||||||
"outDir": "build",
|
"outDir": "./build/",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es6",
|
"es6",
|
||||||
"dom"
|
"dom"
|
||||||
|
|
Loading…
Reference in New Issue