Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "eslint:recommended",
"env": {
"es6": true,
"node": true,
"mocha": true
},
"rules": {
"space-before-function-paren": ["error", "never"],
"standard/no-callback-literal": "off",
"arrow-spacing": "error",
"arrow-parens": ["error", "always"],
"arrow-body-style": ["error", "as-needed"],
"prefer-template": "error",
"max-len": ["warn", { "code": 80 }],
"no-unused-vars": ["warn", {
"argsIgnorePattern": "^_$|^e$|^reject$|^resolve$"
}],
"no-console": ["error", {
"allow": ["warn", "error"]
}],
"valid-jsdoc": "error",
"semi": ["error", "always"],
"quotes": ["error", "double", { "allowTemplateLiterals": true }]
}
}
84 changes: 42 additions & 42 deletions examples/express-ex/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

const express = require("express");
const app = express();

Expand All @@ -12,103 +14,101 @@ const structured1 = new v1.StructuredHTTPReceiver();
const binary1 = new v1.BinaryHTTPReceiver();

app.use((req, res, next) => {
let data="";
let data = "";

req.setEncoding("utf8");
req.on("data", function(chunk) {
data += chunk;
});
req.setEncoding("utf8");
req.on("data", function(chunk) {
data += chunk;
});

req.on("end", function() {
req.body = data;
next();
});
req.on("end", function() {
req.body = data;
next();
});
});

app.post("/v1", function (req, res) {
app.post("/v1", function(req, res) {
console.log(req.headers);
console.log(req.body);

try {
let myevent = structured1.parse(req.body, req.headers);
const myevent = structured1.parse(req.body, req.headers);
// pretty print
console.log("Accepted event:");
console.log(JSON.stringify(myevent.format(), null, 2));

res.status(201)
.json(myevent.format());

.json(myevent.format());
} catch (err) {
console.error(err);
res.status(415)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
}
});

app.post("/v1/binary", function (req, res) {
app.post("/v1/binary", function(req, res) {
console.log(req.headers);
console.log(req.body);

try {
let myevent = binary1.parse(req.body, req.headers);
const myevent = binary1.parse(req.body, req.headers);
// pretty print
console.log("Accepted event:");
console.log(JSON.stringify(myevent.format(), null, 2));

res.status(201)
.json(myevent.format());

.json(myevent.format());
} catch (err) {
console.error(err);
res.status(415)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
}
});

app.post("/v03", function (req, res) {
app.post("/v03", function(req, res) {
console.log(req.headers);
console.log(req.body);

unmarshaller03.unmarshall(req.body, req.headers)
.then(cloudevent => {
.then((cloudevent) => {
// pretty print
console.log("Accepted event:");
console.log(JSON.stringify(cloudevent.format(), null, 2));

res.status(201)
.json(cloudevent.format());
})
.catch(err => {
console.error(err);
res.status(415)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
});
.json(cloudevent.format());
})
.catch((err) => {
console.error(err);
res.status(415)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
});
});

app.post("/v02", function (req, res) {
app.post("/v02", function(req, res) {
console.log(req.headers);
console.log(req.body);

unmarshaller02.unmarshall(req.body, req.headers)
.then(cloudevent => {
.then((cloudevent) => {
// pretty print
console.log("Accepted event:");
console.log(JSON.stringify(cloudevent.format(), null, 2));

res.status(201)
.json(cloudevent.format());
})
.catch(err => {
console.error(err);
res.status(415)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
});
.json(cloudevent.format());
})
.catch((err) => {
console.error(err);
res.status(415)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
});
});

app.listen(3000, function () {
app.listen(3000, function() {
console.log("Example app listening on port 3000!");
});
2 changes: 1 addition & 1 deletion examples/typescript-ex/prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
trailingComma: "es5"
};
9 changes: 4 additions & 5 deletions lib/bindings/http/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ const Constants = require("./constants.js");

// Specific sanity for content-type header
function sanityContentType(contentType) {
if(contentType) {
if (contentType) {
return Array.of(contentType)
.map((c) => c.split(";"))
.map((c) => c.shift())
.shift();
.map((c) => c.split(";"))
.map((c) => c.shift())
.shift();
}

return contentType;
}

function sanityAndClone(headers) {

const sanityHeaders = {};

Array.from(Object.keys(headers))
Expand Down
146 changes: 73 additions & 73 deletions lib/bindings/http/constants.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
// Commons
module.exports = {
HEADERS : "headers",
CHARSET_DEFAULT : "utf-8",
HEADERS: "headers",
CHARSET_DEFAULT: "utf-8",

SPEC_V02 : "0.2",
SPEC_V03 : "0.3",
SPEC_V1 : "1.0",
SPEC_V02: "0.2",
SPEC_V03: "0.3",
SPEC_V1: "1.0",

DEFAULT_SPEC_VERSION_HEADER : "ce-specversion",
DEFAULT_SPEC_VERSION_HEADER: "ce-specversion",

ENCODING_BASE64 : "base64",
ENCODING_BASE64: "base64",

DATA_ATTRIBUTE : "data",
DATA_ATTRIBUTE: "data",

MIME_JSON : "application/json",
MIME_OCTET_STREAM : "application/octet-stream",
MIME_CE : "application/cloudevents",
MIME_CE_JSON : "application/cloudevents+json",
MIME_JSON: "application/json",
MIME_OCTET_STREAM: "application/octet-stream",
MIME_CE: "application/cloudevents",
MIME_CE_JSON: "application/cloudevents+json",

HEADER_CONTENT_TYPE : "content-type",
HEADER_CONTENT_TYPE: "content-type",

DEFAULT_CONTENT_TYPE : "application/json; charset=utf-8",
DEFAULT_CE_CONTENT_TYPE : "application/cloudevents+json; charset=utf-8",
DEFAULT_CONTENT_TYPE: "application/json; charset=utf-8",
DEFAULT_CE_CONTENT_TYPE: "application/cloudevents+json; charset=utf-8",

BINARY_HEADERS_02 : {
TYPE : "ce-type",
SPEC_VERSION : "ce-specversion",
SOURCE : "ce-source",
ID : "ce-id",
TIME : "ce-time",
SCHEMA_URL : "ce-schemaurl",
EXTENSIONS_PREFIX : "ce-"
BINARY_HEADERS_02: {
TYPE: "ce-type",
SPEC_VERSION: "ce-specversion",
SOURCE: "ce-source",
ID: "ce-id",
TIME: "ce-time",
SCHEMA_URL: "ce-schemaurl",
EXTENSIONS_PREFIX: "ce-"
},
STRUCTURED_ATTRS_02 : {
TYPE : "type",
SPEC_VERSION : "specversion",
SOURCE : "source",
ID : "id",
TIME : "time",
SCHEMA_URL : "schemaurl",
CONTENT_TYPE : "contenttype",
DATA : "data"
STRUCTURED_ATTRS_02: {
TYPE: "type",
SPEC_VERSION: "specversion",
SOURCE: "source",
ID: "id",
TIME: "time",
SCHEMA_URL: "schemaurl",
CONTENT_TYPE: "contenttype",
DATA: "data"
},

BINARY_HEADERS_03 : {
TYPE : "ce-type",
SPEC_VERSION : "ce-specversion",
SOURCE : "ce-source",
ID : "ce-id",
TIME : "ce-time",
SCHEMA_URL : "ce-schemaurl",
CONTENT_ENCONDING : "ce-datacontentencoding",
SUBJECT : "ce-subject",
EXTENSIONS_PREFIX : "ce-"
BINARY_HEADERS_03: {
TYPE: "ce-type",
SPEC_VERSION: "ce-specversion",
SOURCE: "ce-source",
ID: "ce-id",
TIME: "ce-time",
SCHEMA_URL: "ce-schemaurl",
CONTENT_ENCONDING: "ce-datacontentencoding",
SUBJECT: "ce-subject",
EXTENSIONS_PREFIX: "ce-"
},
STRUCTURED_ATTRS_03 : {
TYPE : "type",
SPEC_VERSION : "specversion",
SOURCE : "source",
ID : "id",
TIME : "time",
SCHEMA_URL : "schemaurl",
CONTENT_ENCONDING : "datacontentencoding",
CONTENT_TYPE : "datacontenttype",
SUBJECT : "subject",
DATA : "data"
STRUCTURED_ATTRS_03: {
TYPE: "type",
SPEC_VERSION: "specversion",
SOURCE: "source",
ID: "id",
TIME: "time",
SCHEMA_URL: "schemaurl",
CONTENT_ENCONDING: "datacontentencoding",
CONTENT_TYPE: "datacontenttype",
SUBJECT: "subject",
DATA: "data"
},

BINARY_HEADERS_1 : {
TYPE : "ce-type",
SPEC_VERSION : "ce-specversion",
SOURCE : "ce-source",
ID : "ce-id",
TIME : "ce-time",
DATA_SCHEMA : "ce-dataschema",
SUBJECT : "ce-subject",
EXTENSIONS_PREFIX : "ce-"
BINARY_HEADERS_1: {
TYPE: "ce-type",
SPEC_VERSION: "ce-specversion",
SOURCE: "ce-source",
ID: "ce-id",
TIME: "ce-time",
DATA_SCHEMA: "ce-dataschema",
SUBJECT: "ce-subject",
EXTENSIONS_PREFIX: "ce-"
},
STRUCTURED_ATTRS_1 : {
TYPE : "type",
SPEC_VERSION : "specversion",
SOURCE : "source",
ID : "id",
TIME : "time",
DATA_SCHEMA : "dataschema",
CONTENT_TYPE : "datacontenttype",
SUBJECT : "subject",
DATA : "data",
DATA_BASE64 : "data_base64"
STRUCTURED_ATTRS_1: {
TYPE: "type",
SPEC_VERSION: "specversion",
SOURCE: "source",
ID: "id",
TIME: "time",
DATA_SCHEMA: "dataschema",
CONTENT_TYPE: "datacontenttype",
SUBJECT: "subject",
DATA: "data",
DATA_BASE64: "data_base64"
}
};
Loading