![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
fastify-cloudevents
Advanced tools
Fastify Plugin to serialize events in the CloudEvents standard format
Fastify Plugin to serialize events in the CloudEvents standard format.
The purpose of this plugin is to let Fastify web applications create instances of CloudEvents in a simple way (with some useful defaults), or in a full way (all attributes). Optionally, it's possible to validate created instances to be sure they are compliant with the standard. Then, created instances can be serialized, for example to be sent (or saved/stored) somewhere.
Other features of the plugin: enable forwarding of Fastify events to given callbacks, and wrapping the original event in a specific CloudEvent instance.
Note that all CloudEvents features exposed here, by using the library cloudevent.js.
More features will follow in the plugin.
const fastify = require('fastify')()
// define functions to use in plugin configuration:
// idExample , callbackExample , etc ...
// register the plugin with some options, for example:
fastify.register(require('fastify-cloudevents'), {
serverUrl: 'http://0.0.0.0:3000',
idGenerator: idExample,
onRequestCallback: callbackExample,
cloudEventOptions: { }
})
// implementation ...
fastify.listen(3000)
In the example folder there are some simple server scripts
that uses the plugin (inline but it's the same using it from npm registry),
example
is a simple one, and example-enhanced
is a more complex sample
to show even how to raise own events (normal an errors).
Fastify ^1.1.0 . Node.js 8.14.x or later.
The plugin decorate Fastify and expose some functions:
CloudEvent
, the CloudEvent implementation used here, could be usefulcloudEventSerializeFast
, a serialize function implemented here, using fast-json-stringify
and not standard JSON serialization functionsPlugin options are:
serverUrl
, the URL (absolute, or relative) of the current webapp, to use as a base source
in generated CloudEventsserverUrlMode
, the mode to build the source
attribute in generated CloudEvents
(any non null value will cause this setting to be aded to the extension attribute):
serverUrl
serverUrl
and add the current request urlError
baseNamespace
, a base namespace for the eventType
, more specific suffix will be added in any CloudEventidGenerator
, a generator function that returns the id (if possible, unique) for any CloudEventincludeHeaders
, a boolean flag that when true
tells that request headers will be put in generated CloudEvents (but by default is false
)onRequestCallback
, callback who will handle the generated CloudEvents, in Fastify hook onRequest
preHandlerCallback
, callback who will handle the generated CloudEvents, in Fastify hook preHandler
onSendCallback
, callback who will handle the generated CloudEvents, in Fastify hook onSend
onResponseCallback
, callback who will handle the generated CloudEvents, in Fastify hook onResponse
onRouteCallback
, callback who will handle the generated CloudEvents, in Fastify hook onRoute
onCloseCallback
, callback who will handle the generated CloudEvents, in Fastify hook onClose
onReadyCallback
, callback who will handle the generated CloudEvents, in Fastify hook onReady
cloudEventOptions
, CloudEvent options commomn to all generated event instances; anyway objects are copied to not be shared between instancesall plugin options are optional, and have a default value.
For more info on the standard, see the CloudEvents Specification here.
Licensed under Apache-2.0.
0.2.0 (2018-12-17)
Summary Changelog:
serverUrlMode
(by default null) to specify in which mode source
must be constructed in generated CloudEvent instances; see in the README for related values to use.
As a sample, add in the example-enhanced
with a value to have the same behavior of its default,
but that way it will be put in CloudEvent extension object.FAQs
Fastify Plugin to serialize events in the CloudEvents standard format
The npm package fastify-cloudevents receives a total of 33 weekly downloads. As such, fastify-cloudevents popularity was classified as not popular.
We found that fastify-cloudevents demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.