4.6.1 • Published 2 years ago

@1mill/cloudevents v4.6.1

Weekly downloads
60
License
MIT
Repository
github
Last release
2 years ago

@1mill/cloudevents

Introduction

This is an implementation and extention of the CloudEvents v1 specification to easily build cloudevents with origin history.

Install

<script src="https://unpkg.com/@1mill/cloudevents@4/dist/index.umd.js">

or

npm install @1mill/cloudevents
const { Cloudevent } = require('@1mill/cloudevents') // CommonJs
import { Cloudevent } from '@1mill/cloudevents' // EMS

const cloudevent = new Cloudevent({
  data: JSON.stringify({ some: 'payload' }),
  source: 'https://github.com/1mill/cloudevents',
  type: 'cmd.do-this-command.v0',
  originactor: 'user:admin#id=1234',
})

console.log(cloudevent)
// {
//   id: 'v76ZvDVhbcCwD5M_NQ1FS',
//   source: 'https://github.com/1mill/cloudevents',
//   type: 'cmd.do-this-command.v0',
//   specversion: '1.0',
//   time: '2022-09-22T01:44:31.717Z',
//   data: '{"some":"payload"}',
//   datacontenttype: 'application/json',
//   dataschema: undefined,
//   subject: undefined,
//   originactor: 'user:admin#id=1234',
//   originid: 'v76ZvDVhbcCwD5M_NQ1FS',
//   originsource: 'https://github.com/1mill/cloudevents',
//   origintime: '2022-09-22T01:44:31.717Z',
//   origintype: 'cmd.do-this-command.v0',
//   originatorid: undefined,
//   wschannelid: undefined
// }

const enrichedCloudevent = new Cloudevent({
  data: JSON.stringify({ new: 'payload', value: true }),
  source: 'https://www.erikekberg.com/',
  type: 'fct.this-thing-happened.v0',
})
.origin({ cloudevent })
.wschannel({ wschannelid: 'some-prefix:my-resource-name#id=12345' })

console.log(enrichedCloudevent)
// {
//   id: '-RIl1_Dr_uNh6Q4Oa3Ifq',
//   source: 'https://www.erikekberg.com/',
//   type: 'fct.this-thing-happened.v0',
//   specversion: '1.0',
//   time: '2022-09-22T01:44:31.747Z',
//   data: '{"new":"payload","value":true}',
//   datacontenttype: 'application/json',
//   dataschema: undefined,
//   subject: undefined,
//   originactor: 'user:admin#id=1234',
//   originid: 'v76ZvDVhbcCwD5M_NQ1FS',
//   originsource: 'https://github.com/1mill/cloudevents',
//   origintime: '2022-09-22T01:44:31.717Z',
//   origintype: 'cmd.do-this-command.v0',
//   originatorid: undefined,
//   wschannelid: 'some-prefix:my-resource-name#id=12345'
// }
AttributeRequiredTypeDefaultNotes
dataAny
datacontenttypeStringIf "data" is present, defaults to "application/json" unless specified otherwise
dataschemaString
sourceyesStringprocess.env.MILL_CLOUDEVENTS_SOURCERecommended to use universal identifier (e.g. https://my-domain.com/my/feature/path/123)
specversionString1.0Cloudevent specification version
subjectString
typeyesString
originactorString
originidString"id" property"id" property is internally generated as part of the package
originsourceString"source" property
origintimeString"time" property"time" property is internally generated as part of the package
origintypeString"type" property
originatoridStringDeprecated in favor of "originactor"
wschannelidString

origin

Add origin attributes to a Cloudevent manually

const cloudevent = new Cloudevent({
  source: 'my-source',
  type: 'my-type',
})
.origin({
  originactor: 'my-origin-actor',
  originid: 'my-origin-id',
  originsource: 'my-origin-source',
  origintime: 'my-origin-time',
  origintype: 'my-origin-type',
})

or populate them automatically by passing in an existing Cloudevent

const originCloudevent = new Cloudevent({
  source: 'my-origin-cloudevent',
  type: 'cmd.say-hello.v0',
  originactor: 'my-origin-actor',
})

const cloudevent = new Cloudevent({
  data: JSON.stringify({ message: 'Hello world!' }),
  source: 'my-enrichment-service',
  type: 'fct.said-hello.v0',
}).origin({ cloudevent: originCloudevent })

wschannel

Add wschannel attributes to a Cloudevent manually

const cloudevent = new Cloudevent({
    source: 'my-source',
    type: 'my-type',
  })
  .wschannel({ wschannelid: 'my-unique-channel-name })

or populate them automatically by passing in an existing Cloudevent

const originCloudevent = new Cloudevent({
  source: 'my-origin-cloudevent',
  type: 'cmd.say-hello.v0'
})
.wschannel({ wschannelid: 'my-unique-channel-name })

const cloudevent = new Cloudevent({
  data: JSON.stringify({ message: 'Hello world!' }),
  source: 'my-enrichment-service',
  type: 'fct.said-hello.v0',
}).wschannel({ cloudevent: originCloudevent })

Release new version

npm version <major|minor|patch>
npm run depoy
4.4.1

2 years ago

4.4.0

2 years ago

4.6.1

2 years ago

4.6.0

2 years ago

4.2.1

2 years ago

4.2.0

2 years ago

4.5.0

2 years ago

4.1.0

2 years ago

4.3.0

2 years ago

4.1.1

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.0.1

3 years ago

3.0.0

3 years ago

0.11.3

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

0.11.1

3 years ago

0.11.2

3 years ago

0.11.0

3 years ago

0.10.11

3 years ago

0.10.10

3 years ago

0.10.9

3 years ago

0.10.8

3 years ago

0.10.7

3 years ago

0.10.6

3 years ago

0.10.5

3 years ago

0.10.4

4 years ago

0.10.3

4 years ago

0.10.1

4 years ago

0.10.2

4 years ago

0.10.0

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.8.9

4 years ago

0.9.0

4 years ago

0.8.8

4 years ago

0.8.7

4 years ago

0.8.6

4 years ago

0.8.5

4 years ago

0.8.4

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.10

4 years ago

0.5.9

4 years ago

0.5.8

4 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.4

4 years ago

0.5.5

4 years ago

0.5.3

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.0

4 years ago

0.1.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago