@1mill/cloudevents 0.11.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +2 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +20 -8
- package/{index.js → src/index.js} +1 -6
- package/.editorconfig +0 -21
- package/v3/createCloudevent.js +0 -51
- package/v3/createEventStream.js +0 -36
- package/v3/enrichCloudevent.js +0 -15
- package/v3/index.js +0 -16
- package/v3/isEnriched.js +0 -5
- package/v3/kafka/convertFrom.js +0 -6
- package/v3/kafka/convertTo.js +0 -12
- package/v3/kafka/createAuthentication.js +0 -19
- package/v3/kafka/createEmit.js +0 -33
- package/v3/kafka/createListen.js +0 -75
- package/v3/kafka/index.js +0 -28
- package/v3/lambda/handler.js +0 -29
- package/v3/lambda/index.js +0 -7
- package/v3/lib/constants.js +0 -14
- package/v4/createCloudevent.js +0 -47
- package/v4/createEventStream.js +0 -36
- package/v4/index.js +0 -12
- package/v4/kafka/convertFrom.js +0 -6
- package/v4/kafka/convertTo.js +0 -12
- package/v4/kafka/createAuthentication.js +0 -19
- package/v4/kafka/createEmit.js +0 -33
- package/v4/kafka/createListen.js +0 -64
- package/v4/kafka/index.js +0 -28
- package/v4/lambda/handler.js +0 -9
- package/v4/lambda/index.js +0 -7
- package/v4/lib/constants.js +0 -14
- package/v5/createCloudevent.js +0 -47
- package/v5/createCloudeventStream.js +0 -42
- package/v5/index.js +0 -12
- package/v5/kafka/convertFrom.js +0 -6
- package/v5/kafka/convertTo.js +0 -12
- package/v5/kafka/createAuthentication.js +0 -19
- package/v5/kafka/createEmit.js +0 -33
- package/v5/kafka/createListen.js +0 -73
- package/v5/kafka/index.js +0 -28
- package/v5/lambda/handler.js +0 -9
- package/v5/lambda/index.js +0 -7
- package/v5/lib/constants.js +0 -14
- package/v6/index.js +0 -41
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=require("nanoid").nanoid,i=function(t){return process&&process.env&&process.env[t]};module.exports=Object.freeze({Cloudevent:function(e){var r=e.data,o=e.datacontenttype,s=e.dataschema,n=e.originid,h=e.originsource,u=e.origintime,d=e.origintype,a=e.source,g=e.specversion,c=e.subject,p=e.type;if(this.id=t(i("1MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=a||i("1MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=p,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=g||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=r,this.datacontenttype=void 0!==this.data?o||"application/json":o,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=s,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=c,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.originid=n||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=h||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintime=u||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.origintype=d||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')}});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["const { nanoid } = require('nanoid')\r\n\r\nconst fetchNodeEnv = name => process && process.env && process.env[name]\r\n\r\nclass Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('1MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('1MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n\r\nmodule.exports = Object.freeze({ Cloudevent })\r\n"],"names":["nanoid","require","fetchNodeEnv","name","process","env","module","exports","Object","freeze","Cloudevent","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","Error","time","Date","toISOString"],"mappings":"AAAA,IAAQA,EAAWC,QAAQ,UAAnBD,OAEFE,EAAe,SAAAC,UAAQC,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,IAoEnEG,OAAOC,QAAUC,OAAOC,OAAO,CAAEC,WAjEhC,gBACCC,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,SACAC,IAAAA,aACAC,IA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,MAAM,4CAGzD,GADAF,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUO,MAAM,uCACtC,GAA+B,sBAAfP,WAAyB,UAAUO,MAAM"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const{nanoid:t}=require("nanoid"),e=t=>process&&process.env&&process.env[t];module.exports=Object.freeze({Cloudevent:class{constructor({data:i,datacontenttype:r,dataschema:o,originid:s,originsource:n,origintime:h,origintype:u,source:d,specversion:a,subject:g,type:c}){if(this.id=t(e("1MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=d||e("1MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=c,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=a||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=i,this.datacontenttype=void 0!==this.data?r||"application/json":r,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=o,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=g,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.originid=s||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=n||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintime=h||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.origintype=u||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')}}});
|
|
2
|
+
//# sourceMappingURL=index.modern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/index.js"],"sourcesContent":["const { nanoid } = require('nanoid')\r\n\r\nconst fetchNodeEnv = name => process && process.env && process.env[name]\r\n\r\nclass Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('1MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('1MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n\r\nmodule.exports = Object.freeze({ Cloudevent })\r\n"],"names":["nanoid","require","fetchNodeEnv","name","process","env","module","exports","Object","freeze","Cloudevent","constructor","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","Error","time","Date","toISOString"],"mappings":"AAAA,MAAMA,OAAEA,GAAWC,QAAQ,UAErBC,EAAeC,GAAQC,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,GAoEnEG,OAAOC,QAAUC,OAAOC,OAAO,CAAEC,WAlEjC,MACCC,aAAYC,KACXA,EADWC,gBAEXA,EAF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AAUQ,MAAM,uCACtC,GAA+B,sBAAfR,WAAyB,UAAUQ,MAAM,4CAGzD,GADAF,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUO,MAAM,uCACtC,GAA+B,sBAAfP,WAAyB,UAAUO,MAAM"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=require("nanoid").nanoid,i=function(t){return process&&process.env&&process.env[t]};module.exports=Object.freeze({Cloudevent:function(e){var r=e.data,o=e.datacontenttype,s=e.dataschema,n=e.originid,h=e.originsource,u=e.origintime,d=e.origintype,a=e.source,g=e.specversion,c=e.subject,p=e.type;if(this.id=t(i("1MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=a||i("1MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=p,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=g||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=r,this.datacontenttype=void 0!==this.data?o||"application/json":o,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=s,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=c,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.originid=n||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=h||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintime=u||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.origintype=d||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')}});
|
|
2
|
+
//# sourceMappingURL=index.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/index.js"],"sourcesContent":["const { nanoid } = require('nanoid')\r\n\r\nconst fetchNodeEnv = name => process && process.env && process.env[name]\r\n\r\nclass Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('1MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('1MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n\r\nmodule.exports = Object.freeze({ Cloudevent })\r\n"],"names":["nanoid","require","fetchNodeEnv","name","process","env","module","exports","Object","freeze","Cloudevent","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","Error","time","Date","toISOString"],"mappings":"AAAA,IAAQA,EAAWC,QAAQ,UAAnBD,OAEFE,EAAe,SAAAC,UAAQC,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,IAoEnEG,OAAOC,Q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AG3D,GADAF,KAAKN,WAAaA,GAAcM,KAAKG,MAChCH,KAAKN,WAAY,UAAUQ,MAAM,uCACtC,GAA+B,sBAAfR,WAAyB,UAAUQ,MAAM,4CAGzD,GADAF,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUO,MAAM,uCACtC,GAA+B,sBAAfP,WAAyB,UAAUO,MAAM"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){var t=require("nanoid").nanoid,e=function(t){return process&&process.env&&process.env[t]};module.exports=Object.freeze({Cloudevent:function(i){var r=i.data,o=i.datacontenttype,n=i.dataschema,s=i.originid,u=i.originsource,h=i.origintime,d=i.origintype,a=i.source,g=i.specversion,c=i.subject,p=i.type;if(this.id=t(e("1MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=a||e("1MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=p,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=g||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=r,this.datacontenttype=void 0!==this.data?o||"application/json":o,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=n,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=c,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.originid=s||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=u||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintime=h||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.origintype=d||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')}})});
|
|
2
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/index.js"],"sourcesContent":["const { nanoid } = require('nanoid')\r\n\r\nconst fetchNodeEnv = name => process && process.env && process.env[name]\r\n\r\nclass Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('1MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('1MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n\r\nmodule.exports = Object.freeze({ Cloudevent })\r\n"],"names":["nanoid","require","fetchNodeEnv","name","process","env","module","exports","Object","freeze","Cloudevent","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","Error","time","Date","toISOString"],"mappings":"6EAAA,IAAQA,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aAAeA,GAAgBO,KAAKJ,QACpCI,KAAKP,aAAc,UAAUS,MAAM,yCACxC,GAAiC,sBAAjBT,aAA2B,UAAUS,MAAM,8CAG3D,GADAF,KAAKN,WAAaA,GAAcM,KAAKG,MAChCH,KAAKN,WAAY,UAAUQ,MAAM,uCACtC,GAA+B,sBAAfR,WAAyB,UAAUQ,MAAM,4CAGzD,GADAF,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUO,MAAM,uCACtC,GAA+B,sBAAfP,WAAyB,UAAUO,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1mill/cloudevents",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Node cloudevents specification and helper
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Node cloudevents specification and helper",
|
|
5
|
+
"jsnext:main": "dist/index.module.js",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.module.js",
|
|
8
|
+
"source": "src/index.js",
|
|
9
|
+
"umd:main": "dist/index.umd.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
6
14
|
"scripts": {
|
|
7
|
-
"
|
|
15
|
+
"build": "rm -rf ./dist && microbundle",
|
|
16
|
+
"deploy": "npm run build && npm publish",
|
|
17
|
+
"dev": "microbundle watch"
|
|
8
18
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
19
|
+
"homepage": "https://github.com/1mill/cloudevents",
|
|
20
|
+
"authors": [
|
|
21
|
+
"Erik Ekberg <nightw0lf@hotmail.com>"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
11
24
|
"repository": {
|
|
12
25
|
"type": "git",
|
|
13
26
|
"url": "https://github.com/1mill/cloudevents.git"
|
|
14
27
|
},
|
|
15
28
|
"dependencies": {
|
|
16
|
-
"kafkajs": "1.12.0",
|
|
17
29
|
"nanoid": "^3.1.25"
|
|
18
30
|
},
|
|
19
31
|
"devDependencies": {
|
|
20
|
-
"
|
|
32
|
+
"microbundle": "^0.13.3"
|
|
21
33
|
}
|
|
22
34
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
const { nanoid } = require('nanoid')
|
|
2
|
-
const { v3 } = require('./v3')
|
|
3
|
-
const { v4 } = require('./v4')
|
|
4
|
-
const { v5 } = require('./v5')
|
|
5
|
-
const { v6 } = require('./v6')
|
|
6
2
|
|
|
7
3
|
const fetchNodeEnv = name => process && process.env && process.env[name]
|
|
8
4
|
|
|
@@ -72,5 +68,4 @@ class Cloudevent {
|
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
module.exports = Object.freeze({ Cloudevent, v3, v4, v5, v6 })
|
|
71
|
+
module.exports = Object.freeze({ Cloudevent })
|
package/.editorconfig
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# editorconfig.org
|
|
2
|
-
root = true
|
|
3
|
-
|
|
4
|
-
[*]
|
|
5
|
-
charset = utf-8
|
|
6
|
-
end_of_line = crlf
|
|
7
|
-
indent_size = 8
|
|
8
|
-
indent_style = tab
|
|
9
|
-
insert_final_newline = true
|
|
10
|
-
trim_trailing_whitespace = true
|
|
11
|
-
|
|
12
|
-
[*.{yaml,yml,json}]
|
|
13
|
-
indent_size = 2
|
|
14
|
-
indent_style = space
|
|
15
|
-
|
|
16
|
-
[*.md]
|
|
17
|
-
indent_size = 2
|
|
18
|
-
indent_style = space
|
|
19
|
-
|
|
20
|
-
[*.{bash,bashrc,pem,sh}]
|
|
21
|
-
end_of_line = lf
|
package/v3/createCloudevent.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const createCloudevent = ({
|
|
2
|
-
data,
|
|
3
|
-
datacontenttype,
|
|
4
|
-
dlx = 'dlx',
|
|
5
|
-
enrichmentdata,
|
|
6
|
-
enrichmentdatacontenttype,
|
|
7
|
-
id,
|
|
8
|
-
source,
|
|
9
|
-
specversion = '1.0',
|
|
10
|
-
time,
|
|
11
|
-
type,
|
|
12
|
-
}) => {
|
|
13
|
-
if (!id) { throw new Error('Cloudevent "id" is as required') }
|
|
14
|
-
if (!source) { throw new Error('Cloudevent "source" is as required') }
|
|
15
|
-
if (!type) { throw new Error('Cloudevent "type" is as required') }
|
|
16
|
-
|
|
17
|
-
const isDataEncoded = data !== undefined && datacontenttype !== undefined
|
|
18
|
-
const isEnrichmentEncoded = enrichmentdata !== undefined && enrichmentdatacontenttype !== undefined
|
|
19
|
-
|
|
20
|
-
const cloudevent = {
|
|
21
|
-
// Required defaults
|
|
22
|
-
dlx,
|
|
23
|
-
id,
|
|
24
|
-
source,
|
|
25
|
-
specversion,
|
|
26
|
-
time: time || new Date().toISOString(),
|
|
27
|
-
type,
|
|
28
|
-
|
|
29
|
-
// Optional original data
|
|
30
|
-
data: isDataEncoded
|
|
31
|
-
? data
|
|
32
|
-
: JSON.stringify(data),
|
|
33
|
-
datacontenttype: isDataEncoded
|
|
34
|
-
? datacontenttype
|
|
35
|
-
: 'application/json',
|
|
36
|
-
|
|
37
|
-
// Optional enrichment data
|
|
38
|
-
enrichmentdata: isEnrichmentEncoded
|
|
39
|
-
? enrichmentdata
|
|
40
|
-
: JSON.stringify(enrichmentdata),
|
|
41
|
-
enrichmentdatacontenttype: isEnrichmentEncoded
|
|
42
|
-
? enrichmentcontenttype
|
|
43
|
-
: 'application/json',
|
|
44
|
-
enrichmenttime: enrichmentdata === undefined
|
|
45
|
-
? undefined
|
|
46
|
-
: new Date().toISOString(),
|
|
47
|
-
}
|
|
48
|
-
return cloudevent
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = { createCloudevent }
|
package/v3/createEventStream.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const { PROTOCOL_KAFKA, PROTOCOL_LAMBDA } = require('./lib/constants')
|
|
2
|
-
const { createInstance: kafkaCreateInstance } = require('./kafka')
|
|
3
|
-
const { createInstance: lambdaCreateInstance } = require('./lambda')
|
|
4
|
-
|
|
5
|
-
const SUPPORTED_PROTOCOLS = [
|
|
6
|
-
PROTOCOL_KAFKA,
|
|
7
|
-
PROTOCOL_LAMBDA,
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
const createEventStream = ({
|
|
11
|
-
id,
|
|
12
|
-
mechanism,
|
|
13
|
-
password,
|
|
14
|
-
protocol,
|
|
15
|
-
urls,
|
|
16
|
-
username,
|
|
17
|
-
}) => {
|
|
18
|
-
if (!protocol) { throw new Error('The "protocol" argument is required') }
|
|
19
|
-
if (!SUPPORTED_PROTOCOLS.includes(protocol)) { throw new Error(`The "${protocol}" protocol is not supported`) }
|
|
20
|
-
|
|
21
|
-
if (protocol === PROTOCOL_KAFKA) {
|
|
22
|
-
return kafkaCreateInstance({
|
|
23
|
-
id,
|
|
24
|
-
mechanism,
|
|
25
|
-
password,
|
|
26
|
-
urls,
|
|
27
|
-
username,
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (protocol === PROTOCOL_LAMBDA) {
|
|
32
|
-
return lambdaCreateInstance({})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = { createEventStream }
|
package/v3/enrichCloudevent.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const { createCloudevent } = require('./createCloudevent')
|
|
2
|
-
|
|
3
|
-
const enrichCloudevent = ({
|
|
4
|
-
cloudevent,
|
|
5
|
-
enrichmentdata,
|
|
6
|
-
enrichmentdatacontenttype,
|
|
7
|
-
}) => {
|
|
8
|
-
return createCloudevent({
|
|
9
|
-
...cloudevent,
|
|
10
|
-
enrichmentdata,
|
|
11
|
-
enrichmentdatacontenttype,
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = { enrichCloudevent }
|
package/v3/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const { PROTOCOL_KAFKA, PROTOCOL_LAMBDA } = require("./lib/constants");
|
|
2
|
-
const { createCloudevent } = require('./createCloudevent')
|
|
3
|
-
const { createEventStream } = require('./createEventStream')
|
|
4
|
-
const { enrichCloudevent } = require('./enrichCloudevent')
|
|
5
|
-
const { isEnriched } = require('./isEnriched')
|
|
6
|
-
|
|
7
|
-
const v3 = {
|
|
8
|
-
PROTOCOL_KAFKA,
|
|
9
|
-
PROTOCOL_LAMBDA,
|
|
10
|
-
createCloudevent,
|
|
11
|
-
createEventStream,
|
|
12
|
-
enrichCloudevent,
|
|
13
|
-
isEnriched,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = { v3 }
|
package/v3/isEnriched.js
DELETED
package/v3/kafka/convertFrom.js
DELETED
package/v3/kafka/convertTo.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const convertTo = ({ cloudevent }) => {
|
|
2
|
-
const message = {
|
|
3
|
-
headers: {
|
|
4
|
-
contentType: 'application/cloudevents+json;charset=UTF-8'
|
|
5
|
-
},
|
|
6
|
-
value: JSON.stringify(cloudevent),
|
|
7
|
-
}
|
|
8
|
-
const event = { messages: [message], topic: cloudevent.type }
|
|
9
|
-
return { event }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = { convertTo }
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Client Configuration for KafkaJS: https://kafka.js.org/docs/configuration
|
|
2
|
-
const SCRAM_MECHANISMS = [
|
|
3
|
-
'plain',
|
|
4
|
-
'scram-sha-256',
|
|
5
|
-
'scram-sha-512',
|
|
6
|
-
]
|
|
7
|
-
|
|
8
|
-
const createAuthentication = ({ mechanism, password, username }) => {
|
|
9
|
-
if (SCRAM_MECHANISMS.includes(mechanism)) {
|
|
10
|
-
return {
|
|
11
|
-
sasl: { mechanism, password, username },
|
|
12
|
-
ssl: true,
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return {}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = { createAuthentication }
|
package/v3/kafka/createEmit.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const { Kafka } = require('kafkajs')
|
|
2
|
-
const { convertTo } = require('./convertTo')
|
|
3
|
-
const { createAuthentication } = require('./createAuthentication')
|
|
4
|
-
|
|
5
|
-
const createEmit = ({
|
|
6
|
-
id,
|
|
7
|
-
mechanism,
|
|
8
|
-
password,
|
|
9
|
-
urls,
|
|
10
|
-
username,
|
|
11
|
-
}) => {
|
|
12
|
-
const authentication = createAuthentication({
|
|
13
|
-
mechanism,
|
|
14
|
-
password,
|
|
15
|
-
username,
|
|
16
|
-
})
|
|
17
|
-
const kafka = new Kafka({
|
|
18
|
-
...authentication,
|
|
19
|
-
brokers: urls,
|
|
20
|
-
clientId: id,
|
|
21
|
-
})
|
|
22
|
-
const { connect, disconnect, send } = kafka.producer()
|
|
23
|
-
|
|
24
|
-
const emit = async ({ cloudevent }) => {
|
|
25
|
-
await connect()
|
|
26
|
-
const { event } = convertTo({ cloudevent })
|
|
27
|
-
await send(event)
|
|
28
|
-
await disconnect()
|
|
29
|
-
}
|
|
30
|
-
return { emit }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = { createEmit }
|
package/v3/kafka/createListen.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
const { ERROR_TYPES, SIGNAL_TRAPS } = require('../lib/constants')
|
|
2
|
-
const { Kafka } = require('kafkajs')
|
|
3
|
-
const { convertFrom } = require('./convertFrom')
|
|
4
|
-
const { createAuthentication } = require('./createAuthentication')
|
|
5
|
-
const { isEnriched } = require('../isEnriched')
|
|
6
|
-
|
|
7
|
-
const createListen = ({
|
|
8
|
-
id,
|
|
9
|
-
mechanism,
|
|
10
|
-
password,
|
|
11
|
-
urls,
|
|
12
|
-
username,
|
|
13
|
-
}) => {
|
|
14
|
-
const authentication = createAuthentication({
|
|
15
|
-
mechanism,
|
|
16
|
-
password,
|
|
17
|
-
username,
|
|
18
|
-
})
|
|
19
|
-
const kafka = new Kafka({
|
|
20
|
-
...authentication,
|
|
21
|
-
brokers: urls,
|
|
22
|
-
clientId: id,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const { connect, disconnect, run, subscribe } = kafka.consumer({ groupId: id })
|
|
26
|
-
const listen = async ({ handler, types }) => {
|
|
27
|
-
await connect()
|
|
28
|
-
await Promise.all(types.map(type => consumer.subscribe({
|
|
29
|
-
fromBeginning: true,
|
|
30
|
-
topic: type,
|
|
31
|
-
})))
|
|
32
|
-
await run({
|
|
33
|
-
eachMessage: async (event) => {
|
|
34
|
-
const { cloudevent } = convertFrom({ event })
|
|
35
|
-
await handler({
|
|
36
|
-
...cloudevent,
|
|
37
|
-
cloudevent,
|
|
38
|
-
data: cloudevent.data
|
|
39
|
-
? JSON.parse(cloudevent.data)
|
|
40
|
-
: undefined,
|
|
41
|
-
enrichmentdata: isEnriched({ cloudevent })
|
|
42
|
-
? JSON.parse(cloudevent.enrichmentdata)
|
|
43
|
-
: undefined,
|
|
44
|
-
isEnriched: isEnriched({ cloudevent }),
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// Before server stop, close subscription connections to kafka
|
|
50
|
-
ERROR_TYPES.map(errorType => {
|
|
51
|
-
process.on(errorType, async (err) => {
|
|
52
|
-
try {
|
|
53
|
-
console.log(`process.on ${errorType}`)
|
|
54
|
-
console.error(err)
|
|
55
|
-
await disconnect()
|
|
56
|
-
process.exit(0)
|
|
57
|
-
} catch (_err) {
|
|
58
|
-
process.exit(1)
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
SIGNAL_TRAPS.map(signalTrap => {
|
|
63
|
-
process.once(signalTrap, async () => {
|
|
64
|
-
try {
|
|
65
|
-
await disconnect()
|
|
66
|
-
} finally {
|
|
67
|
-
process.kill(process.pid, signalTrap)
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
return { listen }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
module.exports = { createListen }
|
package/v3/kafka/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const { createEmit } = require('./createEmit')
|
|
2
|
-
const { createListen } = require('./createListen')
|
|
3
|
-
|
|
4
|
-
const createInstance = ({
|
|
5
|
-
id,
|
|
6
|
-
mechanism,
|
|
7
|
-
password,
|
|
8
|
-
urls,
|
|
9
|
-
username,
|
|
10
|
-
}) => {
|
|
11
|
-
const { emit } = createEmit({
|
|
12
|
-
id,
|
|
13
|
-
mechanism,
|
|
14
|
-
password,
|
|
15
|
-
urls,
|
|
16
|
-
username,
|
|
17
|
-
})
|
|
18
|
-
const { listen } = createListen({
|
|
19
|
-
id,
|
|
20
|
-
mechanism,
|
|
21
|
-
password,
|
|
22
|
-
urls,
|
|
23
|
-
username,
|
|
24
|
-
});
|
|
25
|
-
return { emit, listen }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = { createInstance }
|
package/v3/lambda/handler.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { isEnriched } = require('../isEnriched')
|
|
2
|
-
|
|
3
|
-
const handler = (func) => {
|
|
4
|
-
return async (event, _context, _callback) => {
|
|
5
|
-
const cloudevent = event
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
data,
|
|
9
|
-
datacontenttype,
|
|
10
|
-
enrichmentdata,
|
|
11
|
-
enrichmentdatacontenttype,
|
|
12
|
-
} = cloudevent
|
|
13
|
-
|
|
14
|
-
const payload = await func({
|
|
15
|
-
...cloudevent,
|
|
16
|
-
cloudevent,
|
|
17
|
-
data: datacontenttype === 'application/json'
|
|
18
|
-
? JSON.parse(data)
|
|
19
|
-
: data,
|
|
20
|
-
enrichmentdata: enrichmentdatacontenttype === 'application/json'
|
|
21
|
-
? JSON.parse(enrichmentdata)
|
|
22
|
-
: enrichmentdata,
|
|
23
|
-
isEnriched: isEnriched({ cloudevent })
|
|
24
|
-
})
|
|
25
|
-
return payload // * Returned to AWS invoker if 'RequestResponse' type
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = { handler }
|
package/v3/lambda/index.js
DELETED
package/v3/lib/constants.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const PROTOCOL_KAFKA = 'kafka'
|
|
2
|
-
const PROTOCOL_LAMBDA = 'lambda'
|
|
3
|
-
|
|
4
|
-
const ERROR_TYPES = ['unhandledRejection', 'uncaughtException']
|
|
5
|
-
const SIGNAL_TRAPS = ['SIGTERM', 'SIGINT', 'SIGUSR2']
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
// Supported protocols
|
|
9
|
-
PROTOCOL_KAFKA,
|
|
10
|
-
PROTOCOL_LAMBDA,
|
|
11
|
-
// Other constants
|
|
12
|
-
ERROR_TYPES,
|
|
13
|
-
SIGNAL_TRAPS,
|
|
14
|
-
};
|
package/v4/createCloudevent.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const createCloudevent = ({
|
|
2
|
-
data,
|
|
3
|
-
datacontenttype,
|
|
4
|
-
dataschema,
|
|
5
|
-
dlx = 'dlx',
|
|
6
|
-
id,
|
|
7
|
-
originid,
|
|
8
|
-
originsource,
|
|
9
|
-
origintype,
|
|
10
|
-
source,
|
|
11
|
-
specversion = '1.0',
|
|
12
|
-
subject,
|
|
13
|
-
type,
|
|
14
|
-
}) => {
|
|
15
|
-
if (!dlx) { throw new Error('Cloudevent "dlx" is as required') }
|
|
16
|
-
if (!id) { throw new Error('Cloudevent "id" is as required') }
|
|
17
|
-
if (!source) { throw new Error('Cloudevent "source" is as required') }
|
|
18
|
-
if (!type) { throw new Error('Cloudevent "type" is as required') }
|
|
19
|
-
|
|
20
|
-
const cloudevent = {
|
|
21
|
-
// * Defined in cloudevents specification
|
|
22
|
-
// Required defaults
|
|
23
|
-
id,
|
|
24
|
-
source,
|
|
25
|
-
specversion,
|
|
26
|
-
time: new Date().toISOString(),
|
|
27
|
-
type,
|
|
28
|
-
|
|
29
|
-
// Optional data
|
|
30
|
-
data,
|
|
31
|
-
datacontenttype,
|
|
32
|
-
dataschema,
|
|
33
|
-
subject,
|
|
34
|
-
|
|
35
|
-
// * In-house attribute extensions
|
|
36
|
-
// Required defaults
|
|
37
|
-
dlx,
|
|
38
|
-
|
|
39
|
-
// Origin data
|
|
40
|
-
originid: originid || id,
|
|
41
|
-
originsource: originsource || source,
|
|
42
|
-
origintype: origintype || type,
|
|
43
|
-
}
|
|
44
|
-
return cloudevent
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = { createCloudevent }
|
package/v4/createEventStream.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const { PROTOCOL_KAFKA, PROTOCOL_LAMBDA } = require('./lib/constants')
|
|
2
|
-
const { createInstance: kafkaCreateInstance } = require('./kafka')
|
|
3
|
-
const { createInstance: lambdaCreateInstance } = require('./lambda')
|
|
4
|
-
|
|
5
|
-
const SUPPORTED_PROTOCOLS = [
|
|
6
|
-
PROTOCOL_KAFKA,
|
|
7
|
-
PROTOCOL_LAMBDA,
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
const createEventStream = ({
|
|
11
|
-
id,
|
|
12
|
-
mechanism,
|
|
13
|
-
password,
|
|
14
|
-
protocol,
|
|
15
|
-
urls,
|
|
16
|
-
username,
|
|
17
|
-
}) => {
|
|
18
|
-
if (!protocol) { throw new Error('The "protocol" argument is required') }
|
|
19
|
-
if (!SUPPORTED_PROTOCOLS.includes(protocol)) { throw new Error(`The "${protocol}" protocol is not supported`) }
|
|
20
|
-
|
|
21
|
-
if (protocol === PROTOCOL_KAFKA) {
|
|
22
|
-
return kafkaCreateInstance({
|
|
23
|
-
id,
|
|
24
|
-
mechanism,
|
|
25
|
-
password,
|
|
26
|
-
urls,
|
|
27
|
-
username,
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (protocol === PROTOCOL_LAMBDA) {
|
|
32
|
-
return lambdaCreateInstance({})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = { createEventStream }
|
package/v4/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const { PROTOCOL_KAFKA, PROTOCOL_LAMBDA } = require('./lib/constants')
|
|
2
|
-
const { createCloudevent } = require('./createCloudevent')
|
|
3
|
-
const { createEventStream } = require('./createEventStream')
|
|
4
|
-
|
|
5
|
-
const v4 = {
|
|
6
|
-
PROTOCOL_KAFKA,
|
|
7
|
-
PROTOCOL_LAMBDA,
|
|
8
|
-
createCloudevent,
|
|
9
|
-
createEventStream,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = { v4 }
|
package/v4/kafka/convertFrom.js
DELETED
package/v4/kafka/convertTo.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const convertTo = ({ cloudevent }) => {
|
|
2
|
-
const message = {
|
|
3
|
-
headers: {
|
|
4
|
-
contentType: 'application/cloudevents+json;charset=UTF-8'
|
|
5
|
-
},
|
|
6
|
-
value: JSON.stringify(cloudevent),
|
|
7
|
-
}
|
|
8
|
-
const event = { messages: [message], topic: cloudevent.type }
|
|
9
|
-
return { event }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = { convertTo }
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Client Configuration for KafkaJS: https://kafka.js.org/docs/configuration
|
|
2
|
-
const SCRAM_MECHANISMS = [
|
|
3
|
-
'plain',
|
|
4
|
-
'scram-sha-256',
|
|
5
|
-
'scram-sha-512',
|
|
6
|
-
]
|
|
7
|
-
|
|
8
|
-
const createAuthentication = ({ mechanism, password, username }) => {
|
|
9
|
-
if (SCRAM_MECHANISMS.includes(mechanism)) {
|
|
10
|
-
return {
|
|
11
|
-
sasl: { mechanism, password, username },
|
|
12
|
-
ssl: true,
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return {}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = { createAuthentication }
|
package/v4/kafka/createEmit.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const { Kafka } = require('kafkajs')
|
|
2
|
-
const { convertTo } = require('./convertTo')
|
|
3
|
-
const { createAuthentication } = require('./createAuthentication')
|
|
4
|
-
|
|
5
|
-
const createEmit = ({
|
|
6
|
-
id,
|
|
7
|
-
mechanism,
|
|
8
|
-
password,
|
|
9
|
-
urls,
|
|
10
|
-
username,
|
|
11
|
-
}) => {
|
|
12
|
-
const authentication = createAuthentication({
|
|
13
|
-
mechanism,
|
|
14
|
-
password,
|
|
15
|
-
username,
|
|
16
|
-
})
|
|
17
|
-
const kafka = new Kafka({
|
|
18
|
-
...authentication,
|
|
19
|
-
brokers: urls,
|
|
20
|
-
clientId: id,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const emit = async ({ cloudevent }) => {
|
|
24
|
-
const producer = kafka.producer()
|
|
25
|
-
await producer.connect()
|
|
26
|
-
const { event } = convertTo({ cloudevent })
|
|
27
|
-
await producer.send(event)
|
|
28
|
-
await producer.disconnect()
|
|
29
|
-
}
|
|
30
|
-
return { emit }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = { createEmit }
|
package/v4/kafka/createListen.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const { ERROR_TYPES, SIGNAL_TRAPS } = require('../lib/constants')
|
|
2
|
-
const { Kafka } = require('kafkajs')
|
|
3
|
-
const { convertFrom } = require('./convertFrom')
|
|
4
|
-
const { createAuthentication } = require('./createAuthentication')
|
|
5
|
-
|
|
6
|
-
const createListen = ({
|
|
7
|
-
id,
|
|
8
|
-
mechanism,
|
|
9
|
-
password,
|
|
10
|
-
urls,
|
|
11
|
-
username,
|
|
12
|
-
}) => {
|
|
13
|
-
const authentication = createAuthentication({
|
|
14
|
-
mechanism,
|
|
15
|
-
password,
|
|
16
|
-
username,
|
|
17
|
-
})
|
|
18
|
-
const kafka = new Kafka({
|
|
19
|
-
...authentication,
|
|
20
|
-
brokers: urls,
|
|
21
|
-
clientId: id,
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const consumer = kafka.consumer({ groupId: id });
|
|
25
|
-
const listen = async ({ handler, types }) => {
|
|
26
|
-
await consumer.connect()
|
|
27
|
-
await Promise.all(types.map(type => consumer.subscribe({
|
|
28
|
-
fromBeginning: true,
|
|
29
|
-
topic: type,
|
|
30
|
-
})))
|
|
31
|
-
await consumer.run({
|
|
32
|
-
eachMessage: async (event) => {
|
|
33
|
-
const { cloudevent } = convertFrom({ event })
|
|
34
|
-
await handler({ ...cloudevent, cloudevent })
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// Before server stop, close subscription connections to kafka
|
|
39
|
-
ERROR_TYPES.map(errorType => {
|
|
40
|
-
process.on(errorType, async (err) => {
|
|
41
|
-
try {
|
|
42
|
-
console.log(`process.on ${errorType}`)
|
|
43
|
-
console.error(err)
|
|
44
|
-
await consumer.disconnect()
|
|
45
|
-
process.exit(0)
|
|
46
|
-
} catch (_err) {
|
|
47
|
-
process.exit(1)
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
SIGNAL_TRAPS.map(signalTrap => {
|
|
52
|
-
process.once(signalTrap, async () => {
|
|
53
|
-
try {
|
|
54
|
-
await consumer.disconnect()
|
|
55
|
-
} finally {
|
|
56
|
-
process.kill(process.pid, signalTrap)
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
return { listen }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
module.exports = { createListen }
|
package/v4/kafka/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const { createEmit } = require('./createEmit')
|
|
2
|
-
const { createListen } = require('./createListen')
|
|
3
|
-
|
|
4
|
-
const createInstance = ({
|
|
5
|
-
id,
|
|
6
|
-
mechanism,
|
|
7
|
-
password,
|
|
8
|
-
urls,
|
|
9
|
-
username,
|
|
10
|
-
}) => {
|
|
11
|
-
const { emit } = createEmit({
|
|
12
|
-
id,
|
|
13
|
-
mechanism,
|
|
14
|
-
password,
|
|
15
|
-
urls,
|
|
16
|
-
username,
|
|
17
|
-
})
|
|
18
|
-
const { listen } = createListen({
|
|
19
|
-
id,
|
|
20
|
-
mechanism,
|
|
21
|
-
password,
|
|
22
|
-
urls,
|
|
23
|
-
username,
|
|
24
|
-
});
|
|
25
|
-
return { emit, listen }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = { createInstance }
|
package/v4/lambda/handler.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const handler = (func) => {
|
|
2
|
-
return async (event, _context, _callback) => {
|
|
3
|
-
const cloudevent = event
|
|
4
|
-
const payload = await func ({ ...cloudevent, cloudevent })
|
|
5
|
-
return payload // * Returned to AWS invoker if 'RequestResponse' type
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports = { handler }
|
package/v4/lambda/index.js
DELETED
package/v4/lib/constants.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const PROTOCOL_KAFKA = 'kafka'
|
|
2
|
-
const PROTOCOL_LAMBDA = 'lambda'
|
|
3
|
-
|
|
4
|
-
const ERROR_TYPES = ['unhandledRejection', 'uncaughtException']
|
|
5
|
-
const SIGNAL_TRAPS = ['SIGTERM', 'SIGINT', 'SIGUSR2']
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
// Supported protocols
|
|
9
|
-
PROTOCOL_KAFKA,
|
|
10
|
-
PROTOCOL_LAMBDA,
|
|
11
|
-
// Other constants
|
|
12
|
-
ERROR_TYPES,
|
|
13
|
-
SIGNAL_TRAPS,
|
|
14
|
-
};
|
package/v5/createCloudevent.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const createCloudevent = ({
|
|
2
|
-
data,
|
|
3
|
-
datacontenttype,
|
|
4
|
-
dataschema,
|
|
5
|
-
dlx = 'dlx',
|
|
6
|
-
id,
|
|
7
|
-
originid,
|
|
8
|
-
originsource,
|
|
9
|
-
origintype,
|
|
10
|
-
source,
|
|
11
|
-
specversion = '1.0',
|
|
12
|
-
subject,
|
|
13
|
-
type,
|
|
14
|
-
}) => {
|
|
15
|
-
if (!dlx) { throw new Error('Cloudevent "dlx" is as required') }
|
|
16
|
-
if (!id) { throw new Error('Cloudevent "id" is as required') }
|
|
17
|
-
if (!source) { throw new Error('Cloudevent "source" is as required') }
|
|
18
|
-
if (!type) { throw new Error('Cloudevent "type" is as required') }
|
|
19
|
-
|
|
20
|
-
const cloudevent = {
|
|
21
|
-
// * Defined in cloudevents specification
|
|
22
|
-
// Required defaults
|
|
23
|
-
id,
|
|
24
|
-
source,
|
|
25
|
-
specversion,
|
|
26
|
-
time: new Date().toISOString(),
|
|
27
|
-
type,
|
|
28
|
-
|
|
29
|
-
// Optional data
|
|
30
|
-
data,
|
|
31
|
-
datacontenttype,
|
|
32
|
-
dataschema,
|
|
33
|
-
subject,
|
|
34
|
-
|
|
35
|
-
// * In-house attribute extensions
|
|
36
|
-
// Required defaults
|
|
37
|
-
dlx,
|
|
38
|
-
|
|
39
|
-
// Origin data
|
|
40
|
-
originid: originid || id,
|
|
41
|
-
originsource: originsource || source,
|
|
42
|
-
origintype: origintype || type,
|
|
43
|
-
}
|
|
44
|
-
return cloudevent
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = { createCloudevent }
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const { PROTOCOL_KAFKA, PROTOCOL_LAMBDA } = require('./lib/constants')
|
|
2
|
-
const { createInstance: kafkaCreateInstance } = require('./kafka')
|
|
3
|
-
const { createInstance: lambdaCreateInstance } = require('./lambda')
|
|
4
|
-
|
|
5
|
-
const SUPPORTED_PROTOCOLS = [
|
|
6
|
-
PROTOCOL_KAFKA,
|
|
7
|
-
PROTOCOL_LAMBDA,
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
const _throwRequired = (attribute) => {
|
|
11
|
-
throw new Error(`The ${attribute} argument is required`)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const createCloudeventStream = ({
|
|
15
|
-
id = process.env.CLOUDEVENT_STREAM_ID,
|
|
16
|
-
mechanism = process.env.CLOUDEVENT_STREAM_MECHANISM,
|
|
17
|
-
password = process.env.CLOUDEVENT_STREAM_PASSWORD,
|
|
18
|
-
protocol = process.env.CLOUDEVENT_STREAM_PROTOCOL,
|
|
19
|
-
urls = (process.env.CLOUDEVENT_STREAM_URLS || '').split(','),
|
|
20
|
-
username = process.env.CLOUDEVENT_STREAM_USERNAME,
|
|
21
|
-
}) => {
|
|
22
|
-
if (!protocol) { _throwRequired('protocol') }
|
|
23
|
-
if (!SUPPORTED_PROTOCOLS.includes(protocol)) { throw new Error(`The "${protocol}" protocol is not supported`) }
|
|
24
|
-
|
|
25
|
-
if (protocol === PROTOCOL_KAFKA) {
|
|
26
|
-
if (!id) { _throwRequired('id') }
|
|
27
|
-
if (!urls.length === 0) { _throwRequired('urls') }
|
|
28
|
-
return kafkaCreateInstance({
|
|
29
|
-
id,
|
|
30
|
-
mechanism,
|
|
31
|
-
password,
|
|
32
|
-
urls,
|
|
33
|
-
username,
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (protocol === PROTOCOL_LAMBDA) {
|
|
38
|
-
return lambdaCreateInstance({})
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
module.exports = { createCloudeventStream }
|
package/v5/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const { PROTOCOL_KAFKA, PROTOCOL_LAMBDA } = require('./lib/constants')
|
|
2
|
-
const { createCloudevent } = require('./createCloudevent')
|
|
3
|
-
const { createCloudeventStream } = require('./createCloudeventStream')
|
|
4
|
-
|
|
5
|
-
const v5 = {
|
|
6
|
-
PROTOCOL_KAFKA,
|
|
7
|
-
PROTOCOL_LAMBDA,
|
|
8
|
-
createCloudevent,
|
|
9
|
-
createCloudeventStream,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = { v5 }
|
package/v5/kafka/convertFrom.js
DELETED
package/v5/kafka/convertTo.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const convertTo = ({ cloudevent }) => {
|
|
2
|
-
const message = {
|
|
3
|
-
headers: {
|
|
4
|
-
contentType: 'application/cloudevents+json;charset=UTF-8'
|
|
5
|
-
},
|
|
6
|
-
value: JSON.stringify(cloudevent),
|
|
7
|
-
}
|
|
8
|
-
const event = { messages: [message], topic: cloudevent.type }
|
|
9
|
-
return { event }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = { convertTo }
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Client Configuration for KafkaJS: https://kafka.js.org/docs/configuration
|
|
2
|
-
const SCRAM_MECHANISMS = [
|
|
3
|
-
'plain',
|
|
4
|
-
'scram-sha-256',
|
|
5
|
-
'scram-sha-512',
|
|
6
|
-
]
|
|
7
|
-
|
|
8
|
-
const createAuthentication = ({ mechanism, password, username }) => {
|
|
9
|
-
if (SCRAM_MECHANISMS.includes(mechanism)) {
|
|
10
|
-
return {
|
|
11
|
-
sasl: { mechanism, password, username },
|
|
12
|
-
ssl: true,
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return {}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = { createAuthentication }
|
package/v5/kafka/createEmit.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const { Kafka } = require('kafkajs')
|
|
2
|
-
const { convertTo } = require('./convertTo')
|
|
3
|
-
const { createAuthentication } = require('./createAuthentication')
|
|
4
|
-
|
|
5
|
-
const createEmit = ({
|
|
6
|
-
id,
|
|
7
|
-
mechanism,
|
|
8
|
-
password,
|
|
9
|
-
urls,
|
|
10
|
-
username,
|
|
11
|
-
}) => {
|
|
12
|
-
const authentication = createAuthentication({
|
|
13
|
-
mechanism,
|
|
14
|
-
password,
|
|
15
|
-
username,
|
|
16
|
-
})
|
|
17
|
-
const kafka = new Kafka({
|
|
18
|
-
...authentication,
|
|
19
|
-
brokers: urls,
|
|
20
|
-
clientId: id,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const emit = async ({ cloudevent }) => {
|
|
24
|
-
const producer = kafka.producer()
|
|
25
|
-
await producer.connect()
|
|
26
|
-
const { event } = convertTo({ cloudevent })
|
|
27
|
-
await producer.send(event)
|
|
28
|
-
await producer.disconnect()
|
|
29
|
-
}
|
|
30
|
-
return { emit }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = { createEmit }
|
package/v5/kafka/createListen.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const { ERROR_TYPES, SIGNAL_TRAPS } = require('../lib/constants')
|
|
2
|
-
const { Kafka } = require('kafkajs')
|
|
3
|
-
const { convertFrom } = require('./convertFrom')
|
|
4
|
-
const { createAuthentication } = require('./createAuthentication')
|
|
5
|
-
|
|
6
|
-
const createListen = ({
|
|
7
|
-
id,
|
|
8
|
-
mechanism,
|
|
9
|
-
password,
|
|
10
|
-
urls,
|
|
11
|
-
username,
|
|
12
|
-
}) => {
|
|
13
|
-
const authentication = createAuthentication({
|
|
14
|
-
mechanism,
|
|
15
|
-
password,
|
|
16
|
-
username,
|
|
17
|
-
})
|
|
18
|
-
const kafka = new Kafka({
|
|
19
|
-
...authentication,
|
|
20
|
-
brokers: urls,
|
|
21
|
-
clientId: id,
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const listen = async ({ handler, types }) => {
|
|
25
|
-
const consumer = kafka.consumer({ groupId: id });
|
|
26
|
-
await consumer.connect()
|
|
27
|
-
|
|
28
|
-
const promises = types.map(type => {
|
|
29
|
-
consumer.subscribe({
|
|
30
|
-
fromBeginning: type.fromBeginning || false,
|
|
31
|
-
topic: type.type || type,
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
await Promise.all(promises)
|
|
35
|
-
|
|
36
|
-
await consumer.run({
|
|
37
|
-
eachMessage: async (event) => {
|
|
38
|
-
try {
|
|
39
|
-
const { cloudevent } = convertFrom({ event })
|
|
40
|
-
await handler({ cloudevent })
|
|
41
|
-
} catch (err) {
|
|
42
|
-
console.error(err)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// Before server stop, close subscription connections to kafka
|
|
48
|
-
ERROR_TYPES.map(errorType => {
|
|
49
|
-
process.on(errorType, async (err) => {
|
|
50
|
-
try {
|
|
51
|
-
console.log(`process.on ${errorType}`)
|
|
52
|
-
console.error(err)
|
|
53
|
-
await consumer.disconnect()
|
|
54
|
-
process.exit(0)
|
|
55
|
-
} catch (_err) {
|
|
56
|
-
process.exit(1)
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
SIGNAL_TRAPS.map(signalTrap => {
|
|
61
|
-
process.once(signalTrap, async () => {
|
|
62
|
-
try {
|
|
63
|
-
await consumer.disconnect()
|
|
64
|
-
} finally {
|
|
65
|
-
process.kill(process.pid, signalTrap)
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
return { listen }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
module.exports = { createListen }
|
package/v5/kafka/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const { createEmit } = require('./createEmit')
|
|
2
|
-
const { createListen } = require('./createListen')
|
|
3
|
-
|
|
4
|
-
const createInstance = ({
|
|
5
|
-
id,
|
|
6
|
-
mechanism,
|
|
7
|
-
password,
|
|
8
|
-
urls,
|
|
9
|
-
username,
|
|
10
|
-
}) => {
|
|
11
|
-
const { emit } = createEmit({
|
|
12
|
-
id,
|
|
13
|
-
mechanism,
|
|
14
|
-
password,
|
|
15
|
-
urls,
|
|
16
|
-
username,
|
|
17
|
-
})
|
|
18
|
-
const { listen } = createListen({
|
|
19
|
-
id,
|
|
20
|
-
mechanism,
|
|
21
|
-
password,
|
|
22
|
-
urls,
|
|
23
|
-
username,
|
|
24
|
-
});
|
|
25
|
-
return { emit, listen }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = { createInstance }
|
package/v5/lambda/handler.js
DELETED
package/v5/lambda/index.js
DELETED
package/v5/lib/constants.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const PROTOCOL_KAFKA = 'kafka'
|
|
2
|
-
const PROTOCOL_LAMBDA = 'lambda'
|
|
3
|
-
|
|
4
|
-
const ERROR_TYPES = ['unhandledRejection', 'uncaughtException']
|
|
5
|
-
const SIGNAL_TRAPS = ['SIGTERM', 'SIGINT', 'SIGUSR2']
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
// Supported protocols
|
|
9
|
-
PROTOCOL_KAFKA,
|
|
10
|
-
PROTOCOL_LAMBDA,
|
|
11
|
-
// Other constants
|
|
12
|
-
ERROR_TYPES,
|
|
13
|
-
SIGNAL_TRAPS,
|
|
14
|
-
};
|
package/v6/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const createCloudevent = ({
|
|
2
|
-
data,
|
|
3
|
-
datacontenttype,
|
|
4
|
-
dataschema,
|
|
5
|
-
id,
|
|
6
|
-
originid,
|
|
7
|
-
originsource,
|
|
8
|
-
origintype,
|
|
9
|
-
source,
|
|
10
|
-
specversion = '1.0',
|
|
11
|
-
subject,
|
|
12
|
-
type,
|
|
13
|
-
}) => {
|
|
14
|
-
if (!id) { throw new Error('Cloudevent "id" is as required') }
|
|
15
|
-
if (!source) { throw new Error('Cloudevent "source" is as required') }
|
|
16
|
-
if (!type) { throw new Error('Cloudevent "type" is as required') }
|
|
17
|
-
|
|
18
|
-
const cloudevent = {
|
|
19
|
-
// * Defined in cloudevents specification
|
|
20
|
-
// Required defaults
|
|
21
|
-
id,
|
|
22
|
-
source,
|
|
23
|
-
specversion,
|
|
24
|
-
time: new Date().toUTCString(),
|
|
25
|
-
type,
|
|
26
|
-
|
|
27
|
-
// Optional data
|
|
28
|
-
data,
|
|
29
|
-
datacontenttype,
|
|
30
|
-
dataschema,
|
|
31
|
-
subject,
|
|
32
|
-
|
|
33
|
-
// * In-house attribute extensions
|
|
34
|
-
originid: originid || id,
|
|
35
|
-
originsource: originsource || source,
|
|
36
|
-
origintype: origintype || type,
|
|
37
|
-
}
|
|
38
|
-
return cloudevent
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = { v6: { createCloudevent } }
|