@1mill/cloudevents 2.0.1 → 4.0.1

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/README.md CHANGED
@@ -2,14 +2,24 @@
2
2
 
3
3
  ## Introduction
4
4
 
5
- This is an implementation and extention of the CloudEvents v1 specification to easily build cloudevents.
5
+ This is an implementation and extention of the [CloudEvents v1 specification](https://github.com/cloudevents/spec) to easily build cloudevents with origin history.
6
+
7
+
8
+ ## Install
9
+
10
+ ```html
11
+ <script src="https://unpkg.com/@1mill/cloudevents@4.0.0/dist/index.umd.js">
12
+ ```
13
+
14
+ or
6
15
 
7
16
  ```bash
8
- npm install @1mill/cloudevents@^2
17
+ npm install @1mill/cloudevents@^4
9
18
  ```
10
19
 
11
- ```js
12
- const { Cloudevent } = require('@1mill/cloudevents')
20
+ ```node
21
+ const { Cloudevent } = require('@1mill/cloudevents') // CommonJs
22
+ import { Cloudevent } from '@1mill/cloudevents' // EMS
13
23
 
14
24
  const cloudevent = new Cloudevent({
15
25
  data: JSON.stringify({
@@ -58,7 +68,7 @@ console.log(myReactionCloudevent)
58
68
  // subject: '123',
59
69
  // time: '2021-09-06T16:38:49.717Z',
60
70
  // origintime: '2021-09-06T16:29:26.527Z',
61
- // originid: 'pDScxm45M2-BnnIYHw4P3',
71
+ // originid: '-of0T1jfpvD7_lOXtynbb',
62
72
  // originsource: 'https://www.my-website.come/my/page/123',
63
73
  // origintype: 'cmd.do-this-command.v0'
64
74
  // }
@@ -69,7 +79,7 @@ console.log(myReactionCloudevent)
69
79
  | data | | Any | | |
70
80
  | datacontenttype | | String | | If "data" is present, defaults to "application/json" unless specified otherwise |
71
81
  | dataschema | | String | | |
72
- | source | yes | String | process.env.1MILL_CLOUDEVENTS_SOURCE | Recommended to use universal identifier (e.g. https://my-domain.com/my/feature/path/123) |
82
+ | source | yes | String | process.env.MILL_CLOUDEVENTS_SOURCE | Recommended to use universal identifier (e.g. https://my-domain.com/my/feature/path/123) |
73
83
  | specversion | yes | String | 1.0 | Cloudevent specification version |
74
84
  | subject | | String | | |
75
85
  | type | yes | String | | |
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ var t=require("nanoid"),i=function(t){return"undefined"!=typeof process&&process&&process.env&&process.env[t]};exports.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,p=e.subject,c=e.type;if(this.id=t.nanoid(i("MILL_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("MILL_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=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=p,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),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.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.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.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class 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('MILL_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('MILL_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.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.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.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"],"names":["fetchNodeEnv","name","process","env","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","nanoid","Error","time","Date","toISOString"],"mappings":"wBAEMA,EAAe,SAAAC,SAA4B,oBAAZC,SAA4BA,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,uBAGtG,gBACCG,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAIA,GADAC,KAAKC,GAAKC,SAAOjB,EAAa,mC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AUQ,MAAM"}
@@ -1,2 +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.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.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.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')}}});
1
+ const t=t=>"undefined"!=typeof process&&process&&process.env&&process.env[t];class e{constructor({data:e,datacontenttype:i,dataschema:r,originid:o,originsource:s,origintime:n,origintype:h,source:u,specversion:d,subject:a,type:g}){if(this.id=((t=21)=>{let e="",i=crypto.getRandomValues(new Uint8Array(t));for(;t--;){let r=63&i[t];e+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return e})(t("MILL_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=u||t("MILL_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=g,!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=d||"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=e,this.datacontenttype=void 0!==this.data?i||"application/json":i,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=r,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=a,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.origintime=n||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.originid=o||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=s||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.origintype=h||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')}}export{e as Cloudevent};
2
2
  //# sourceMappingURL=index.modern.js.map
@@ -1 +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.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.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.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,EAFWC,WAGXA,EAHWC,SAIXA,EAJWC,aAKXA,EALWC,WAMXA,EANWC,WAOXA,EAPWC,OAQXA,EARWC,YASXA,EATWC,QAUXA,EAVWC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KL,WAAY,UAAUO,MAAM,uCACtC,GAA+B,sBAAfP,WAAyB,UAAUO,MAAM"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/index.js","../node_modules/nanoid/index.prod.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class 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('MILL_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('MILL_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.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.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.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","import { urlAlphabet } from './url-alphabet/index.js'\nif (false) {\n if (\n typeof navigator !== 'undefined' &&\n navigator.product === 'ReactNative' &&\n typeof crypto === 'undefined'\n ) {\n throw new Error(\n 'React Native does not have a built-in secure random generator. ' +\n 'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +\n 'For secure IDs, import `react-native-get-random-values` ' +\n 'before Nano ID.'\n )\n }\n if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {\n throw new Error(\n 'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +\n ' before importing Nano ID to fix IE 11 support'\n )\n }\n if (typeof crypto === 'undefined') {\n throw new Error(\n 'Your browser does not have secure random generator. ' +\n 'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'\n )\n }\n}\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, size, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * size) / alphabet.length)\n return () => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)\nlet nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array(size))\n while (size--) {\n let byte = bytes[size] & 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte < 63) {\n id += '_'\n } else {\n id += '-'\n }\n }\n return id\n}\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","process","env","Cloudevent","constructor","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","size","bytes","crypto","getRandomValues","Uint8Array","byte","toString","toUpperCase","nanoid","Error","time","Date","toISOString"],"mappings":"AAEA,MAAMA,EAAeC,GAA4B,oBAAZC,SAA4BA,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,SAE1FG,EACZC,aAAYC,KACXA,EADWC,gBAEXA,EAFWC,WAGXA,EAHWC,SAIXA,EAJWC,aAKXA,EALWC,WAMXA,EANWC,WAOXA,EAPWC,OAQXA,EARWC,YASXA,EATWC,QAUXA,EAVWC,KAWXA,IAIA,GADAC,KAAKC,GCyBM,EAACC,EAAO,MACnB,IAAID,EAAK,GACLE,EAAQC,OAAOC,gBAAgB,IAAIC,WAAWJ,IAClD,KAAOA,KAAQ,CACb,IAAIK,EAAqB,GAAdJ,EAAMD,GAEfD,GADEM,EAAO,GACHA,EAAKC,SAAS,IACXD,EAAO,IACTA,EAA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ADAX,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUgB,MAAM,uCACtC,GAA+B,sBAAfhB,WAAyB,UAAUgB,MAAM"}
@@ -1,2 +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.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.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.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')}});
1
+ import{nanoid as t}from"nanoid";var i=function(t){return"undefined"!=typeof process&&process&&process.env&&process.env[t]},e=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,p=e.subject,c=e.type;if(this.id=t(i("MILL_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("MILL_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=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=p,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),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.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.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')};export{e as Cloudevent};
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +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.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.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.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,IAAAA,WACAC,IAAAA,W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AF,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUO,MAAM,uCACtC,GAA+B,sBAAfP,WAAyB,UAAUO,MAAM"}
1
+ {"version":3,"file":"index.module.js","sources":["../src/index.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class 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('MILL_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('MILL_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.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.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.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"],"names":["fetchNodeEnv","name","process","env","Cloudevent","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","nanoid","Error","time","Date","toISOString"],"mappings":"gCAEA,IAAMA,EAAe,SAAAC,SAA4B,oBAAZC,SAA4BA,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,IAE1FG,EACZ,gBACCC,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAIA,GADAC,KAAKC,GAAKC,EAAOlB,EAA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WAAyB,UAAUQ,MAAM"}
package/dist/index.umd.js CHANGED
@@ -1,2 +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.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.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.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')}})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).cloudevents={})}(this,function(t){var e=function(t){return"undefined"!=typeof process&&process&&process.env&&process.env[t]};t.Cloudevent=function(t){var i=t.data,r=t.datacontenttype,o=t.dataschema,s=t.originid,n=t.originsource,u=t.origintime,d=t.origintype,h=t.source,a=t.specversion,g=t.subject,p=t.type;if(this.id=((t=21)=>{let e="",i=crypto.getRandomValues(new Uint8Array(t));for(;t--;){let r=63&i[t];e+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return e})(e("MILL_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=h||e("MILL_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=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.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.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.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
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +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.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.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.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,EAAWC,QAAQ,UAAnBD,OAEFE,EAAe,SAAAC,UAAQC,SAAWA,QAAQC,KAAOD,Q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BAAbV,SAAuB,UAAUU,MAAM,0CAGvD,GADAF,KAAKP,aAAeA,GAAgBO,KAAKJ,QACpCI,KAAKP,aAAc,UAAUS,MAAM,yCACxC,GAAiC,sBAAjBT,aAA2B,UAAUS,MAAM,8CAG3D,GADAF,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUO,MAAM,uCACtC,GAA+B,sBAAfP,WAAyB,UAAUO,MAAM"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/index.js","../node_modules/nanoid/index.prod.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class 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('MILL_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('MILL_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.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.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.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","import { urlAlphabet } from './url-alphabet/index.js'\nif (false) {\n if (\n typeof navigator !== 'undefined' &&\n navigator.product === 'ReactNative' &&\n typeof crypto === 'undefined'\n ) {\n throw new Error(\n 'React Native does not have a built-in secure random generator. ' +\n 'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +\n 'For secure IDs, import `react-native-get-random-values` ' +\n 'before Nano ID.'\n )\n }\n if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {\n throw new Error(\n 'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +\n ' before importing Nano ID to fix IE 11 support'\n )\n }\n if (typeof crypto === 'undefined') {\n throw new Error(\n 'Your browser does not have secure random generator. ' +\n 'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'\n )\n }\n}\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, size, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * size) / alphabet.length)\n return () => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)\nlet nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array(size))\n while (size--) {\n let byte = bytes[size] & 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte < 63) {\n id += '_'\n } else {\n id += '-'\n }\n }\n return id\n}\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","process","env","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","size","bytes","crypto","getRandomValues","Uint8Array","byte","toString","toUpperCase","nanoid","Error","time","Date","toISOString"],"mappings":"qOAEA,IAAMA,EAAe,SAAAC,SAA4B,oBAAZC,SAA4BA,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,iBAGtG,gBACCG,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAIA,GADAC,KAAKC,GCyBM,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AM,qCACpC,GAA6B,sBAAbnB,SAAuB,UAAUmB,MAAM,0CAGvD,GADAX,KAAKP,aAAeA,GAAgBO,KAAKJ,QACpCI,KAAKP,aAAc,UAAUkB,MAAM,yCACxC,GAAiC,sBAAjBlB,aAA2B,UAAUkB,MAAM,8CAG3D,GADAX,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUgB,MAAM,uCACtC,GAA+B,sBAAfhB,WAAyB,UAAUgB,MAAM"}
package/package.json CHANGED
@@ -1,18 +1,22 @@
1
1
  {
2
2
  "name": "@1mill/cloudevents",
3
- "version": "2.0.1",
3
+ "version": "4.0.1",
4
4
  "description": "Node cloudevents specification and helper",
5
5
  "jsnext:main": "dist/index.module.js",
6
- "main": "dist/index.js",
6
+ "main": "dist/index.cjs",
7
7
  "module": "dist/index.module.js",
8
8
  "source": "src/index.js",
9
9
  "umd:main": "dist/index.umd.js",
10
+ "unpkg": "dist/index.umd.js",
11
+ "type": "module",
10
12
  "files": [
11
13
  "dist",
12
14
  "src"
13
15
  ],
14
16
  "scripts": {
15
- "build": "rm -rf ./dist && microbundle",
17
+ "build": "rm -rf ./dist && npm run build:browser && npm run build:node",
18
+ "build:browser": "microbundle --format modern,umd --external none",
19
+ "build:node": "microbundle --format cjs,esm",
16
20
  "deploy": "npm run build && npm publish",
17
21
  "dev": "microbundle watch"
18
22
  },
@@ -26,9 +30,9 @@
26
30
  "url": "https://github.com/1mill/cloudevents.git"
27
31
  },
28
32
  "dependencies": {
29
- "nanoid": "^3.1.25"
33
+ "nanoid": "^3.2.0"
30
34
  },
31
35
  "devDependencies": {
32
- "microbundle": "^0.13.3"
36
+ "microbundle": "^0.14.2"
33
37
  }
34
38
  }
package/src/index.js CHANGED
@@ -1,8 +1,8 @@
1
- const { nanoid } = require('nanoid')
1
+ import { nanoid } from 'nanoid'
2
2
 
3
- const fetchNodeEnv = name => process && process.env && process.env[name]
3
+ const fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]
4
4
 
5
- class Cloudevent {
5
+ export class Cloudevent {
6
6
  constructor({
7
7
  data,
8
8
  datacontenttype,
@@ -17,11 +17,11 @@ class Cloudevent {
17
17
  type,
18
18
  }) {
19
19
  // * Required fields by CloudEvent specification
20
- this.id = nanoid(fetchNodeEnv('1MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)
20
+ this.id = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)
21
21
  if (!this.id) throw new Error('Cloudevent "id" is required')
22
22
  if (typeof this.id !== 'string') throw new Error('Cloudevent "id" must be a string')
23
23
 
24
- this.source = source || fetchNodeEnv('1MILL_CLOUDEVENTS_SOURCE')
24
+ this.source = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')
25
25
  if (!this.source) throw new Error('Cloudevent "source" is required')
26
26
  if (typeof this.source !== 'string') throw new Error('Cloudevent "source" must be a string')
27
27
 
@@ -67,5 +67,3 @@ class Cloudevent {
67
67
  if (typeof this.origintype !== 'string') throw new Error('Cloudevent "origintype" must be a string')
68
68
  }
69
69
  }
70
-
71
- module.exports = Object.freeze({ Cloudevent })
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
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.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.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.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
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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.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.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.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,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAIA,GADAC,KAAKC,GAAKvB,EAAOE,EAAa,oCAAsC,KAC/DoB,KAAKC,GAAI,UAAUC,MAAM,+BAC9B,GAAuB,sBAAPD,GAAiB,UAAUC,MAAM,oCAGjD,GADAF,KAAKJ,OAASA,GAAUhB,EAAa,6BAChCoB,KAAKJ,OAAQ,UAAUM,MAAM,mCAClC,GAA2B,sBAAXN,OAAqB,UAAUM,MAAM,wCAGrD,GADAF,KAAKD,KAAOA,GACPC,KAAKD,KAAM,UAAUG,MAAM,iCAChC,GAAyB,sBAATH,KAAmB,UAAUG,MAAM,sCAGnD,GADAF,KAAKH,YAAcA,GAAe,OAC7BG,KAAKH,YAAa,UAAUK,MAAM,wCACvC,GAAgC,sBAAhBL,YAA0B,UAAUK,MAAM,6CAQ1D,GALAF,KAAKX,KAAOA,EAEZW,KAAKV,qBAAuC,SAATD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