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:
Lucas Holmquist 2020-06-09 18:08:15 -04:00 committed by GitHub
parent 42652819f3
commit dcb3c4e98a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 40 deletions

View File

@ -1,7 +1,7 @@
/* eslint-disable no-console */
const express = require("express");
const { HTTPReceiver } = require("../../src");
const { HTTPReceiver } = require("cloudevents-sdk");
const app = express();
const receiver = new HTTPReceiver();

View File

@ -14,7 +14,7 @@
"author": "fabiojose@gmail.com",
"license": "Apache-2.0",
"dependencies": {
"cloudevents-sdk": "~1.0.0",
"cloudevents-sdk": "~2.0.2",
"express": "^4.17.1"
}
}

View File

@ -15,5 +15,3 @@ Then, start
```bash
npm start
```
See your event payload [here, at requestbin](https://requestbin.com/r/enu90y24i64jp)

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"keywords": [],
"scripts": {
"start": "node build/src/index.js",
"start": "node build/index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"check": "gts check",
"clean": "gts clean",
@ -22,9 +22,9 @@
"posttest": "npm run check"
},
"devDependencies": {
"gts": "^1.1.0",
"typescript": "~3.5.0",
"@types/node": "^8.9.0",
"cloudevents-sdk": "1.0.0"
"cloudevents-sdk": "~2.0.2",
"gts": "^1.1.0",
"typescript": "~3.9.5"
}
}

View File

@ -1,4 +0,0 @@
module.exports = {
singleQuote: true,
trailingComma: "es5"
};

View File

@ -1,45 +1,49 @@
import { CloudEvent, HTTPREceiver } from '../../';
import { CloudEvent, HTTPReceiver } from "cloudevents-sdk";
import { CloudEventV1 } from "cloudevents-sdk/lib/v1";
export function doSomeStuff() {
const receiver = new HTTPREceiver();
const receiver = new HTTPReceiver();
const myevent: CloudEvent = new CloudEvent()
.source('/source')
.type('type')
.dataContentType('text/plain')
.dataschema('http://d.schema.com/my.json')
.subject('cha.json')
.data('my-data')
.addExtension("my-ext", "0x600");
const myevent: CloudEventV1 = new CloudEvent({
source: "/source",
type: "type",
dataContentType: "text/plain",
dataSchema: "https://d.schema.com/my.json",
subject: "cha.json",
data: "my-data"
});
myevent.addExtension("extension-1", "some extension data");
console.log(myevent.toString());
console.log(myevent.getExtensions());
console.log("My structured event:", myevent.toString());
console.log("My structured event extensions:", myevent.getExtensions());
// ------ receiver structured
const payload = myevent.toString();
// The header names should be standarized to use lowercase
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
const extension1 = "mycuston-ext1";
const data = {
"data" : "dataString"
"data": "dataString"
};
const attributes = {
"ce-type" : "type",
"ce-specversion" : "1.0",
"ce-source" : "source",
"ce-id" : "id",
"ce-time" : "2019-06-16T11:42:00Z",
"ce-dataschema" : "http://schema.registry/v1",
"Content-Type" : "application/json",
"ce-extension1" : extension1
"ce-type": "type",
"ce-specversion": "1.0",
"ce-source": "source",
"ce-id": "id",
"ce-time": "2019-06-16T11:42:00Z",
"ce-dataschema": "http://schema.registry/v1",
"Content-Type": "application/json",
"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;
}

View File

@ -1,8 +1,8 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"rootDir": "./src",
"outDir": "./build/",
"lib": [
"es6",
"dom"