@1mill/cloudevents 4.0.0 → 4.1.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/CHANGELOG.md +16 -0
- package/README.md +62 -55
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +10 -4
- package/src/index.js +42 -37
- package/src/tests/data.test.js +29 -0
- package/src/tests/datacontenttype.test.js +77 -0
- package/src/tests/dataschema.test.js +39 -0
- package/src/tests/id.test.js +45 -0
- package/src/tests/originatorid.test.js +39 -0
- package/src/tests/originid.test.js +40 -0
- package/src/tests/originsource.test.js +40 -0
- package/src/tests/origintime.test.js +39 -0
- package/src/tests/origintype.test.js +40 -0
- package/src/tests/source.test.js +63 -0
- package/src/tests/specversion.test.js +41 -0
- package/src/tests/subjest.test.js +39 -0
- package/src/tests/time.test.js +36 -0
- package/src/tests/type.test.js +39 -0
- package/src/unit.test.js +92 -0
- package/src/utils/fetchNodeEnv/index.js +4 -0
- package/src/utils/fetchNodeEnv/unit.test.js +55 -0
- package/src/utils/setAttribute/index.js +7 -0
- package/src/utils/setAttribute/unit.test.js +43 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog for @1mill/cloudevents
|
|
2
|
+
|
|
3
|
+
## 4.1.0
|
|
4
|
+
|
|
5
|
+
* Add new optional `originatorid` attribute.
|
|
6
|
+
* Add unit tests for every Cloudevent attribute (e.g. `id`, `data`, `originid`, etc.) using `mocha`, `sinon`, and `chai`.
|
|
7
|
+
|
|
8
|
+
## 4.0.1
|
|
9
|
+
|
|
10
|
+
* Check that `process.env` be defined before using it to fix compatability issue with browsers.
|
|
11
|
+
* Replace `require` with `import`.
|
|
12
|
+
|
|
13
|
+
## 4.0.0
|
|
14
|
+
|
|
15
|
+
* Bundle package with `microbundle@^0.14.2` to build Browser and Node compatable versions.
|
|
16
|
+
* Change pacakge to `"type": "module"`.
|
package/README.md
CHANGED
|
@@ -2,81 +2,88 @@
|
|
|
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@^
|
|
17
|
+
npm install @1mill/cloudevents@^4
|
|
9
18
|
```
|
|
10
19
|
|
|
11
|
-
```
|
|
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
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
source: 'https://www.my-website.com/my/page/123', // * Required
|
|
20
|
-
subject: '123',
|
|
21
|
-
type: 'cmd.do-this-command.v0', // * Required
|
|
24
|
+
const originCloudevent = new Cloudevent({
|
|
25
|
+
data: JSON.stringify({ some: 'payload' }),
|
|
26
|
+
source: 'https://github.com/1mill/cloudevents',
|
|
27
|
+
type: 'cmd.do-this-command.v0',
|
|
28
|
+
originatorid: 'user.id.1234',
|
|
22
29
|
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// source: 'https://www.my-website.come/my/page/123',
|
|
30
|
+
console.log(originCloudevent)
|
|
31
|
+
// {
|
|
32
|
+
// id: 'f_2R8OyOtfYW4YPs2SOdv',
|
|
33
|
+
// source: 'https://github.com/1mill/cloudevents',
|
|
28
34
|
// type: 'cmd.do-this-command.v0',
|
|
29
35
|
// specversion: '1.0',
|
|
30
|
-
//
|
|
36
|
+
// time: '2022-09-16T03:47:47.310Z',
|
|
37
|
+
// data: '{"some":"payload"}',
|
|
31
38
|
// datacontenttype: 'application/json',
|
|
32
39
|
// dataschema: undefined,
|
|
33
|
-
// subject:
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
40
|
+
// subject: undefined,
|
|
41
|
+
// origintime: '2022-09-16T03:47:47.310Z',
|
|
42
|
+
// originid: 'f_2R8OyOtfYW4YPs2SOdv',
|
|
43
|
+
// originsource: 'https://github.com/1mill/cloudevents',
|
|
44
|
+
// origintype: 'cmd.do-this-command.v0',
|
|
45
|
+
// originatorid: 'user.id.1234'
|
|
39
46
|
// }
|
|
40
47
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
type: 'fct.this-thing-happened.v0',
|
|
48
|
+
const enrichedCloudevent = new Cloudevent({
|
|
49
|
+
...originCloudevent,
|
|
50
|
+
data: JSON.stringify({ new: 'payload', value: true }),
|
|
51
|
+
source: 'https://www.erikekberg.com/',
|
|
52
|
+
type: 'fct.this-thing-happened.v0',
|
|
47
53
|
})
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
// source: 'arn:aws:lambda:us-east-1:123456789012:function:my-function',
|
|
54
|
+
console.log(enrichedCloudevent)
|
|
55
|
+
// {
|
|
56
|
+
// id: 'mux85XsamwvGkDFgeElQy',
|
|
57
|
+
// source: 'https://www.erikekberg.com/',
|
|
53
58
|
// type: 'fct.this-thing-happened.v0',
|
|
54
59
|
// specversion: '1.0',
|
|
55
|
-
//
|
|
60
|
+
// time: '2022-09-16T03:47:47.320Z',
|
|
61
|
+
// data: '{"new":"payload","value":true}',
|
|
56
62
|
// datacontenttype: 'application/json',
|
|
57
63
|
// dataschema: undefined,
|
|
58
|
-
// subject:
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
+
// subject: undefined,
|
|
65
|
+
// origintime: '2022-09-16T03:47:47.310Z',
|
|
66
|
+
// originid: 'f_2R8OyOtfYW4YPs2SOdv',
|
|
67
|
+
// originsource: 'https://github.com/1mill/cloudevents',
|
|
68
|
+
// origintype: 'cmd.do-this-command.v0',
|
|
69
|
+
// originatorid: 'user.id.1234'
|
|
64
70
|
// }
|
|
65
71
|
```
|
|
66
72
|
|
|
67
|
-
|
|
|
68
|
-
|
|
69
|
-
| data
|
|
70
|
-
| datacontenttype
|
|
71
|
-
| dataschema
|
|
72
|
-
| source
|
|
73
|
-
| specversion
|
|
74
|
-
| subject
|
|
75
|
-
| type
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
| origintype
|
|
73
|
+
| | Required | Type | Default | Notes |
|
|
74
|
+
|----------------- |---------- |-------- |------------------------------------- |------------------------------------------------------------------------------------------ |
|
|
75
|
+
| data | | Any | | |
|
|
76
|
+
| datacontenttype | | String | | If "data" is present, defaults to "application/json" unless specified otherwise |
|
|
77
|
+
| dataschema | | String | | |
|
|
78
|
+
| source | yes | String | process.env.MILL_CLOUDEVENTS_SOURCE | Recommended to use universal identifier (e.g. <https://my-domain.com/my/feature/path/123>)|
|
|
79
|
+
| specversion | yes | String | 1.0 | Cloudevent specification version |
|
|
80
|
+
| subject | | String | | |
|
|
81
|
+
| type | yes | String | | |
|
|
82
|
+
| originid | yes | String | "id" property | "id" property is internally generated as part of the package |
|
|
83
|
+
| originsource | yes | String | "source" property | |
|
|
84
|
+
| origintime | yes | String | "time" property | "time" property is internally generated as part of the package |
|
|
85
|
+
| origintype | yes | String | "type" property | |
|
|
86
|
+
| originatorid | | String | | |
|
|
80
87
|
|
|
81
88
|
## Release new version
|
|
82
89
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var e=require("nanoid"),n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,a=void 0===i?[]:i,o=e.value;if(a.length>0&&!a.includes(typeof o)){var r='Cloudevent "'+t+'" must be of type '+a.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(r)}n[t]=o};exports.Cloudevent=function(i){var a=i.data,o=i.datacontenttype,r=i.dataschema,u=i.originatorid,s=i.originid,v=i.originsource,d=i.origintime,c=i.origintype,l=i.source,p=i.specversion,g=i.subject,y=i.type,m=this,f=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:m,name:"id",types:["string"],value:f});var E=l||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:m,name:"source",types:["string"],value:E});var L=y;t({cloudevent:m,name:"type",types:["string"],value:L}),t({cloudevent:m,name:"specversion",types:["string"],value:p||"1.0"});var C=(new Date).toISOString();t({cloudevent:m,name:"time",types:["string"],value:C}),t({cloudevent:m,name:"data",value:a}),t({cloudevent:m,name:"datacontenttype",types:["string","undefined"],value:void 0!==a?o||"application/json":o}),t({cloudevent:m,name:"dataschema",types:["string","undefined"],value:r}),t({cloudevent:m,name:"subject",types:["string","undefined"],value:g}),t({cloudevent:m,name:"origintime",types:["string"],value:d||C}),t({cloudevent:m,name:"originid",types:["string"],value:s||f}),t({cloudevent:m,name:"originsource",types:["string"],value:v||E}),t({cloudevent:m,name:"origintype",types:["string"],value:c||L}),t({cloudevent:m,name:"originatorid",types:["string","undefined"],value:u})};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\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\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({ cloudevent, name: 'id', types: ['string'], value: idValue })\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({ cloudevent, name: 'source', types: ['string'], value: sourceValue })\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({ cloudevent, name: 'type', types: ['string'], value: typeValue })\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({ cloudevent, name: 'specversion', types: ['string'], value: specversionValue })\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({ cloudevent, name: 'time', types: ['string'], value: timeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({ cloudevent, name: 'data', value: data })\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({ cloudevent, name: 'datacontenttype', types: ['string', 'undefined'], value: datacontenttypeValue })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'dataschema', types: ['string', 'undefined'], value: dataschema })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'subject', types: ['string', 'undefined'], value: subject })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintime', types: ['string'], value: origintimeValue })\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({ cloudevent, name: 'originid', types: ['string'], value: originidValue })\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintype', types: ['string'], value: origintypeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({ cloudevent, name: 'originatorid', types: ['string', 'undefined'], value: originatorid })\r\n\t\t// *******\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"wBAAaA,EAAe,SAACC,EAAMC,G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Aa,CAAEC,WAAAA,EAAYL,KAAM,aAAcM,MAAO,CAAC,SAAU,aAAcC,MAAOY,IAEtFf,EAAa,CAAEC,WAAAA,EAAYL,KAAM,UAAWM,MAAO,CAAC,SAAU,aAAcC,MAAOoB,IAMnFvB,EAAa,CAAEC,WAAAA,EAAYL,KAAM,aAAcM,MAAO,CAAC,UAAWC,MAD1CgB,GAAcW,IAItC9B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,WAAYM,MAAO,CAAC,UAAWC,MAD1Cc,GAAYS,IAIlC1B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1Ce,GAAgBU,IAI1C5B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,aAAcM,MAAO,CAAC,UAAWC,MAD1CiB,GAAcS,IAMtC7B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,SAAU,aAAcC,MAAOa,GAExF"}
|
package/dist/index.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
1
|
+
const e=(e,t)=>{if("undefined"!=typeof process)return process.env[e]||t},t=({cloudevent:e,name:t,types:n=[],value:o})=>{if(n.length>0&&!n.includes(typeof o)){const e=`Cloudevent "${t}" must be of type ${n.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[t]=o};class n{constructor({data:n,datacontenttype:o,dataschema:i,originatorid:s,originid:a,originsource:r,origintime:u,origintype:c,source:d,specversion:l,subject:p,type:v}){const g=this,y=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,t)=>e+((t&=63)<36?t.toString(36):t<62?(t-26).toString(36).toUpperCase():t>62?"-":"_"),""))(e("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:g,name:"id",types:["string"],value:y});const m=d||e("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:g,name:"source",types:["string"],value:m});const f=v;t({cloudevent:g,name:"type",types:["string"],value:f}),t({cloudevent:g,name:"specversion",types:["string"],value:l||"1.0"});const E=(new Date).toISOString();t({cloudevent:g,name:"time",types:["string"],value:E}),t({cloudevent:g,name:"data",value:n}),t({cloudevent:g,name:"datacontenttype",types:["string","undefined"],value:void 0!==n?o||"application/json":o}),t({cloudevent:g,name:"dataschema",types:["string","undefined"],value:i}),t({cloudevent:g,name:"subject",types:["string","undefined"],value:p}),t({cloudevent:g,name:"origintime",types:["string"],value:u||E}),t({cloudevent:g,name:"originid",types:["string"],value:a||y}),t({cloudevent:g,name:"originsource",types:["string"],value:r||m}),t({cloudevent:g,name:"origintype",types:["string"],value:c||f}),t({cloudevent:g,name:"originatorid",types:["string","undefined"],value:s})}}export{n as Cloudevent};
|
|
2
2
|
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/index.js","../node_modules/nanoid/index.
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\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\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({ cloudevent, name: 'id', types: ['string'], value: idValue })\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({ cloudevent, name: 'source', types: ['string'], value: sourceValue })\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({ cloudevent, name: 'type', types: ['string'], value: typeValue })\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({ cloudevent, name: 'specversion', types: ['string'], value: specversionValue })\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({ cloudevent, name: 'time', types: ['string'], value: timeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({ cloudevent, name: 'data', value: data })\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({ cloudevent, name: 'datacontenttype', types: ['string', 'undefined'], value: datacontenttypeValue })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'dataschema', types: ['string', 'undefined'], value: dataschema })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'subject', types: ['string', 'undefined'], value: subject })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintime', types: ['string'], value: origintimeValue })\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({ cloudevent, name: 'originid', types: ['string'], value: originidValue })\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintype', types: ['string'], value: origintypeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({ cloudevent, name: 'originatorid', types: ['string', 'undefined'], value: originatorid })\r\n\t\t// *******\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\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 = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 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 > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","Cloudevent","constructor","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"MAAaA,EAAe,CAACC,EAAMC,KAClC,GAAuB,oBA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KhDf,EAAa,CAAEC,aAAYL,KAAM,kBAAmBM,MAAO,CAAC,SAAU,aAAcC,WAHvC,IAATY,EACjCC,GAAmB,mBACnBA,IAGHhB,EAAa,CAAEC,aAAYL,KAAM,aAAcM,MAAO,CAAC,SAAU,aAAcC,MAAOc,IAEtFjB,EAAa,CAAEC,aAAYL,KAAM,UAAWM,MAAO,CAAC,SAAU,aAAcC,MAAOsB,IAMnFzB,EAAa,CAAEC,aAAYL,KAAM,aAAcM,MAAO,CAAC,UAAWC,MAD1CkB,GAAcmB,IAItCxC,EAAa,CAAEC,aAAYL,KAAM,WAAYM,MAAO,CAAC,UAAWC,MAD1CgB,GAAYS,IAIlC5B,EAAa,CAAEC,aAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1CiB,GAAgBkB,IAI1CtC,EAAa,CAAEC,aAAYL,KAAM,aAAcM,MAAO,CAAC,UAAWC,MAD1CmB,GAAciB,IAMtCvC,EAAa,CAAEC,aAAYL,KAAM,eAAgBM,MAAO,CAAC,SAAU,aAAcC,MAAOe,GAExF"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{nanoid as
|
|
1
|
+
import{nanoid as e}from"nanoid";var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,o=void 0===i?[]:i,a=e.value;if(o.length>0&&!o.includes(typeof a)){var r='Cloudevent "'+t+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(r)}n[t]=a},i=function(i){var o=i.data,a=i.datacontenttype,r=i.dataschema,u=i.originatorid,s=i.originid,v=i.originsource,d=i.origintime,c=i.origintype,l=i.source,p=i.specversion,g=i.subject,m=i.type,y=this,f=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:y,name:"id",types:["string"],value:f});var E=l||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:y,name:"source",types:["string"],value:E});var L=m;t({cloudevent:y,name:"type",types:["string"],value:L}),t({cloudevent:y,name:"specversion",types:["string"],value:p||"1.0"});var h=(new Date).toISOString();t({cloudevent:y,name:"time",types:["string"],value:h}),t({cloudevent:y,name:"data",value:o}),t({cloudevent:y,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?a||"application/json":a}),t({cloudevent:y,name:"dataschema",types:["string","undefined"],value:r}),t({cloudevent:y,name:"subject",types:["string","undefined"],value:g}),t({cloudevent:y,name:"origintime",types:["string"],value:d||h}),t({cloudevent:y,name:"originid",types:["string"],value:s||f}),t({cloudevent:y,name:"originsource",types:["string"],value:v||E}),t({cloudevent:y,name:"origintype",types:["string"],value:c||L}),t({cloudevent:y,name:"originatorid",types:["string","undefined"],value:u})};export{i as Cloudevent};
|
|
2
2
|
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/index.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\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\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({ cloudevent, name: 'id', types: ['string'], value: idValue })\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({ cloudevent, name: 'source', types: ['string'], value: sourceValue })\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({ cloudevent, name: 'type', types: ['string'], value: typeValue })\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({ cloudevent, name: 'specversion', types: ['string'], value: specversionValue })\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({ cloudevent, name: 'time', types: ['string'], value: timeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({ cloudevent, name: 'data', value: data })\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({ cloudevent, name: 'datacontenttype', types: ['string', 'undefined'], value: datacontenttypeValue })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'dataschema', types: ['string', 'undefined'], value: dataschema })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'subject', types: ['string', 'undefined'], value: subject })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintime', types: ['string'], value: origintimeValue })\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({ cloudevent, name: 'originid', types: ['string'], value: originidValue })\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintype', types: ['string'], value: origintypeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({ cloudevent, name: 'originatorid', types: ['string', 'undefined'], value: originatorid })\r\n\t\t// *******\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","Cloudevent","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"oCAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,ECFYU,EACZ,gBACCC,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAEMxB,EAAayB,KAIbC,EAAUC,EAAOjC,EAAa,iCAAkC,KACtEK,EAAa,CAAEC,WAAAA,EAAYL,KAAM,KAAMM,MAAO,CAAC,UAAWC,MAAOwB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
|
|
|
1
|
-
!function(
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).cloudevents={})}(this,function(e){var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},t=function(e){var n=e.cloudevent,t=e.name,o=e.types,i=void 0===o?[]:o,a=e.value;if(i.length>0&&!i.includes(typeof a)){var r='Cloudevent "'+t+'" must be of type '+i.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(r)}n[t]=a};e.Cloudevent=function(e){var o=e.data,i=e.datacontenttype,a=e.dataschema,r=e.originatorid,u=e.originid,s=e.originsource,d=e.origintime,v=e.origintype,l=e.source,c=e.specversion,p=e.subject,g=e.type,y=this,f=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:y,name:"id",types:["string"],value:f});var m=l||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:y,name:"source",types:["string"],value:m});var h=g;t({cloudevent:y,name:"type",types:["string"],value:h}),t({cloudevent:y,name:"specversion",types:["string"],value:c||"1.0"});var C=(new Date).toISOString();t({cloudevent:y,name:"time",types:["string"],value:C}),t({cloudevent:y,name:"data",value:o}),t({cloudevent:y,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?i||"application/json":i}),t({cloudevent:y,name:"dataschema",types:["string","undefined"],value:a}),t({cloudevent:y,name:"subject",types:["string","undefined"],value:p}),t({cloudevent:y,name:"origintime",types:["string"],value:d||C}),t({cloudevent:y,name:"originid",types:["string"],value:u||f}),t({cloudevent:y,name:"originsource",types:["string"],value:s||m}),t({cloudevent:y,name:"origintype",types:["string"],value:v||h}),t({cloudevent:y,name:"originatorid",types:["string","undefined"],value:r})}});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/index.js","../node_modules/nanoid/index.
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\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\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({ cloudevent, name: 'id', types: ['string'], value: idValue })\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({ cloudevent, name: 'source', types: ['string'], value: sourceValue })\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({ cloudevent, name: 'type', types: ['string'], value: typeValue })\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({ cloudevent, name: 'specversion', types: ['string'], value: specversionValue })\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({ cloudevent, name: 'time', types: ['string'], value: timeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({ cloudevent, name: 'data', value: data })\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({ cloudevent, name: 'datacontenttype', types: ['string', 'undefined'], value: datacontenttypeValue })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'dataschema', types: ['string', 'undefined'], value: dataschema })\r\n\r\n\t\tsetAttribute({ cloudevent, name: 'subject', types: ['string', 'undefined'], value: subject })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintime', types: ['string'], value: origintimeValue })\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({ cloudevent, name: 'originid', types: ['string'], value: originidValue })\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({ cloudevent, name: 'origintype', types: ['string'], value: origintypeValue })\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({ cloudevent, name: 'originatorid', types: ['string', 'undefined'], value: originatorid })\r\n\t\t// *******\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\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 = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 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 > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"yOAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,eCDA,gBACCU,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAEMvB,E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cc,GAAYS,IAIlC1B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1Ce,GAAgBkB,IAI1CpC,EAAa,CAAEC,WAAAA,EAAYL,KAAM,aAAcM,MAAO,CAAC,UAAWC,MAD1CiB,GAAciB,IAMtCrC,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,SAAU,aAAcC,MAAOa,GAExF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1mill/cloudevents",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Node cloudevents specification and helper",
|
|
5
5
|
"jsnext:main": "dist/index.module.js",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"build:browser": "microbundle --format modern,umd --external none",
|
|
19
19
|
"build:node": "microbundle --format cjs,esm",
|
|
20
20
|
"deploy": "npm run build && npm publish",
|
|
21
|
-
"dev": "microbundle watch"
|
|
21
|
+
"dev": "microbundle watch",
|
|
22
|
+
"test:unit": "mocha \"src/**/*.test.js\" --recursive"
|
|
22
23
|
},
|
|
23
24
|
"homepage": "https://github.com/1mill/cloudevents",
|
|
24
25
|
"authors": [
|
|
@@ -30,9 +31,14 @@
|
|
|
30
31
|
"url": "https://github.com/1mill/cloudevents.git"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"nanoid": "^3.
|
|
34
|
+
"nanoid": "^3.3.4"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
+
"chai": "^4.3.6",
|
|
38
|
+
"chai-iso8601": "^1.0.0",
|
|
39
|
+
"chai-subset": "^1.6.0",
|
|
40
|
+
"microbundle": "^0.14.2",
|
|
41
|
+
"mocha": "^10.0.0",
|
|
42
|
+
"sinon": "^14.0.0"
|
|
37
43
|
}
|
|
38
44
|
}
|