New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fastify-cloudevents

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-cloudevents - npm Package Compare versions

Comparing version 2.0.0 to 2.2.0

11

CHANGELOG.md
# Change Log
## [2.2.0](https://github.com/smartiniOnGitHub/fastify-cloudevents/releases/tag/2.2.0) (2019-05-02)
[Full Changelog](https://github.com/smartiniOnGitHub/fastify-cloudevents/compare/2.0.0...2.2.0)
Summary Changelog:
- Update dependency on cloudevent to '0.5.x' which implements the
[v0.2 - CloudEvents Spec](https://github.com/cloudevents/spec/releases/tag/v0.2)
with all breaking changes since its v0.1
- Updated dependencies for the development environment
- Updated documentation and samples to describe/show changes and the new behavior
- Updated Tap unit tests to always run in strict mode, and some refactoring
- Clarify which CloudEvents Spec version is implemented in the current release
## [2.0.0](https://github.com/smartiniOnGitHub/fastify-cloudevents/releases/tag/2.0.0) (2019-04-08)

@@ -4,0 +15,0 @@ [Full Changelog](https://github.com/smartiniOnGitHub/fastify-cloudevents/compare/1.0.0...2.0.0)

39

example/example-enhanced.js

@@ -23,2 +23,5 @@ /*

const pluginName = require('../package.json').name // get plugin name
const pluginVersion = require('../package.json').version // get plugin version
const k = {

@@ -29,3 +32,3 @@ protocol: 'http',

serverUrlMode: 'pluginAndRequestSimplified', // same behavior as default value, but in this way set in CloudEvent extension object
baseNamespace: 'com.github.smartiniOnGitHub.fastify-cloudevents.example-enhanced',
baseNamespace: `com.github.smartiniOnGitHub.${pluginName}-v${pluginVersion}.example-enhanced`,
includeHeaders: true, // change from default value, as a sample

@@ -61,2 +64,3 @@ cloudEventOptions: {

serverUrlMode: k.serverUrlMode,
baseNamespace: k.baseNamespace,
idGenerator: gen,

@@ -90,17 +94,20 @@ includeHeaders: k.includeHeaders,

// example to get exposed functions of the plugin, before/without registering it ...
const ce = new CloudEventUtilityConstructor.CloudEvent(gen.next().value,
`${k.baseNamespace}.server-script.start`,
k.source,
{
timestamp: Date.now(),
description: 'Fastify server startup begin',
version: fastifyVersion,
status: 'starting',
hostname: hostname,
pid: pid
}, // data
k.cloudEventOptions
)
console.log(`console - server-script.start: created CloudEvent ${CloudEventUtilityConstructor.CloudEventTransformer.dumpObject(ce, 'ce')}`)
// note that in this case still I can't use some features exposed by the plugin, and some fields take a default value in the plugin so here could be missing (like eventTypeVersion)
if (CloudEventUtilityConstructor) {
// with local, relative path could not be available
const ce = new CloudEventUtilityConstructor.CloudEvent(gen.next().value,
`${k.baseNamespace}.server-script.start`,
k.source,
{
timestamp: Date.now(),
description: 'Fastify server startup begin',
version: fastifyVersion,
status: 'starting',
hostname: hostname,
pid: pid
}, // data
k.cloudEventOptions
)
console.log(`console - server-script.start: created CloudEvent ${CloudEventUtilityConstructor.CloudEventTransformer.dumpObject(ce, 'ce')}`)
// note that in this case still I can't use some features exposed by the plugin, and some fields take a default value in the plugin so here could be missing
}
}

@@ -107,0 +114,0 @@

@@ -48,2 +48,3 @@ /*

serverUrl: k.serverUrl,
baseNamespace: k.baseNamespace,
idGenerator: gen,

@@ -50,0 +51,0 @@ onRequestCallback: loggingCallback,

{
"name": "fastify-cloudevents",
"version": "2.0.0",
"version": "2.2.0",
"description": "Fastify Plugin to serialize events in the CloudEvents standard format",

@@ -11,4 +11,4 @@ "main": "src/plugin",

"lint": "standard \"./*.js\" \"./src/**/*.js\" \"./test/**/*.test.js\" \"./example/**/*.js\"",
"test:unit": "tap -J test/*.test.js test/*/*.test.js",
"test:unit:debug": "tap -T --strict --node-arg=--inspect-brk test/*.test.js test/*/*.test.js",
"test:unit": "tap -J --comments --strict test/*.test.js",
"test:unit:debug": "tap -T --node-arg=--inspect-brk --comments --strict test/*.test.js",
"test:coverage": "npm run test:unit -- --cov --coverage-report=html",

@@ -19,4 +19,4 @@ "test": "npm run lint && npm run test:unit"

"fastify-plugin": "^1.5.0",
"fast-json-stringify": "^1.14.0",
"cloudevent": "~0.4.0"
"fast-json-stringify": "^1.15.2",
"cloudevent": "~0.5.0"
},

@@ -26,7 +26,7 @@ "devDependencies": {

"standard": "^12.0.1",
"tap": "^12.6.1"
"tap": "^12.7.0"
},
"peerDependencies": {},
"engines": {
"node": ">=8.15.0"
"node": ">=8.16.0"
},

@@ -33,0 +33,0 @@ "homepage": "https://github.com/smartiniOnGitHub/fastify-cloudevents#readme",

@@ -12,2 +12,4 @@ # fastify-cloudevents

Current release implements the v0.2 of the CloudEvents Spec.
The purpose of this plugin is to let Fastify web applications create instances of CloudEvents

@@ -59,3 +61,3 @@ in a simple way (with some useful defaults), or in a full way (all attributes).

Fastify ^2.1.0 , Node.js 8.15.x or later.
Fastify ^2.1.0 , Node.js 8.16.x or later.
Note that plugin releases 2.x are for Fastify 2.x, etc.

@@ -85,3 +87,3 @@

- anything other, will raise an `Error`
- `baseNamespace`, a base namespace for the `eventType`; more specific suffix
- `baseNamespace`, a base namespace for the `type`; more specific suffix
should be added to it in any CloudEvent

@@ -112,3 +114,10 @@ - `idGenerator`, a generator function that returns the id (if possible, unique) for any CloudEvent

Since v0.2 of the spec, there is no more a standard attribute to specify the version
of any specific event type, so the best if to follow their recommendations,
and for example add a version in the 'type' attribute
(for example '-v1.0.0' at the end of its base value, or at the end of its full value) ,
or into the 'schemaurl' attribute but only its major version
(like '-v1' or '/v1/' at the end).
For more info on the standard, see the [CloudEvents Specification](https://github.com/cloudevents/spec).

@@ -115,0 +124,0 @@

@@ -21,2 +21,5 @@ /*

const pluginName = require('../package.json').name // get plugin name
const pluginVersion = require('../package.json').version // get plugin version
function fastifyCloudEvents (fastify, options, next) {

@@ -26,3 +29,3 @@ const {

serverUrlMode = null,
baseNamespace = 'com.github.fastify.plugins.fastify-cloudevents',
baseNamespace = `com.github.fastify.plugins.${pluginName}-v${pluginVersion}`,
idGenerator = idMaker(),

@@ -76,3 +79,3 @@ includeHeaders = false,

* encoder (function, no default) a function that takes data and returns encoded data,
* encodedData (string, no default) already encoded data (but consistency with the contentType is not checked),
* encodedData (string, no default) already encoded data (but consistency with the contenttype is not checked),
* onlyValid (boolean, default false) to serialize only if it's a valid instance,

@@ -86,3 +89,3 @@ * @return {string} the serialized event, as a string

if (event.contentType === CloudEvent.contentTypeDefault()) {
if (event.contenttype === CloudEvent.contenttypeDefault()) {
if ((onlyValid === false) || (onlyValid === true && CloudEvent.isValidEvent(event) === true)) {

@@ -97,3 +100,3 @@ return stringify(event)

if (typeof encoder !== 'function') {
throw new Error(`Missing or wrong encoder function: '${encoder}' for the given content type: '${event.contentType}'.`)
throw new Error(`Missing or wrong encoder function: '${encoder}' for the given content type: '${event.contenttype}'.`)
}

@@ -104,7 +107,7 @@ encodedData = encoder(event.payload)

if (encodedData === undefined || encodedData === null) {
throw new Error(`Missing encoder function: use encoder function or already encoded data with the given content type: '${event.contentType}'.`)
throw new Error(`Missing encoder function: use encoder function or already encoded data with the given content type: '${event.contenttype}'.`)
}
}
if (typeof encodedData !== 'string') {
throw new Error(`Missing or wrong encoded data: '${encodedData}' for the given content type: '${event.contentType}'.`)
throw new Error(`Missing or wrong encoded data: '${encodedData}' for the given content type: '${event.contenttype}'.`)
}

@@ -120,6 +123,2 @@ const newEvent = CloudEventTransformer.mergeObjects(event, { data: encodedData })

// check/finish to setup cloudEventOptions
const pluginName = require('../package.json').name // get plugin name
const pluginVersion = require('../package.json').version // get plugin version
// execute plugin code

@@ -130,6 +129,2 @@ fastify.decorate('CloudEvent', CloudEvent)

// then set as eventTypeVersion if not already specified, could be useful
if (cloudEventOptions.eventTypeVersion === null || typeof cloudEventOptions.eventTypeVersion !== 'string') {
cloudEventOptions.eventTypeVersion = pluginVersion
}
// add to extensions the serverUrlMode defined, if set

@@ -136,0 +131,0 @@ if (serverUrlMode !== null) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc