npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@1mill/cloudevents

v4.6.1

Published

Node cloudevents specification and helper

Downloads

177

Readme

@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'
// }

| Attribute | Required | Type | Default | Notes | |----------------- |---------- |-------- |------------------------------------- |------------------------------------------------------------------------------------------ | | data | | Any | | | | datacontenttype | | String | | If "data" is present, defaults to "application/json" unless specified otherwise | | dataschema | | String | | | | source | yes | String | process.env.MILL_CLOUDEVENTS_SOURCE | Recommended to use universal identifier (e.g. https://my-domain.com/my/feature/path/123)| | specversion | | String | 1.0 | Cloudevent specification version | | subject | | String | | | | type | yes | String | | | | originactor | | String | | | | originid | | String | "id" property | "id" property is internally generated as part of the package | | originsource | | String | "source" property | | | origintime | | String | "time" property | "time" property is internally generated as part of the package | | origintype | | String | "type" property | | | originatorid | | String | | Deprecated in favor of "originactor" | | wschannelid | | String | | |

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