Installations
npm install @cumulus/cumulus-message-adapter-js
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=20.12.2
Node Version
20.12.2
NPM Version
10.5.0
Score
64
Supply Chain
98.7
Quality
82
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (52.9%)
TypeScript (43.81%)
Shell (3.29%)
Developer
nasa
Download Statistics
Total Downloads
94,882
Last Day
9
Last Week
87
Last Month
312
Last Year
4,896
GitHub Statistics
5 Stars
291 Commits
8 Forks
15 Watching
14 Branches
33 Contributors
Package Meta Information
Latest Version
2.2.0
Package Id
@cumulus/cumulus-message-adapter-js@2.2.0
Unpacked Size
49.95 kB
Size
15.07 kB
File Count
23
NPM Version
10.5.0
Node Version
20.12.2
Publised On
29 Apr 2024
Total Downloads
Cumulative downloads
Total Downloads
94,882
Last day
-52.6%
9
Compared to previous day
Last week
-32%
87
Compared to previous week
Last month
-42.5%
312
Compared to previous month
Last year
-28.8%
4,896
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Dev Dependencies
25
@cumulus/cumulus-message-adapter-js
What is Cumulus
Cumulus is a cloud-based data ingest, archive, distribution and management prototype for NASA's future Earth science data streams.
Read the Cumulus Documentation
What is the Cumulus Message Adapter?
The Cumulus Message Adapter is a library that adapts incoming messages in the Cumulus protocol to a format more easily consumable by Cumulus tasks, invokes the tasks, and then adapts their response back to the Cumulus message protocol to be sent to the next task.
Installation
The cumulus-message-adapter-js can be installed via Node Package Manager (NPM) and the package is located here.
The package can be added to your project by running npm install @cumulus/cumulus-message-adapter-js --save
.
Task definition
In order to use the Cumulus Message Adapter, you will need to create two methods in your task module: a handler function and a business logic function.
The handler function is a standard Lambda handler function which takes three
parameters (as specified by AWS): event
, context
, and callback
.
The business logic function is where the actual work of your task occurs. It
should take two parameters: nestedEvent
and context
.
The nestedEvent
object contains two keys:
input
- the task's input, typically thepayload
of the message, produced at runtimeconfig
- the task's configuration, with any templated variables resolved
The context
parameter is the standard Lambda context as passed by AWS.
The return value of the business logic function will be placed in the
payload
of the resulting Cumulus message.
Expectations for input, config, and return values are all defined by the task, and should be well documented. Tasks should thoughtfully consider their inputs and return values, as breaking changes may have cascading effects on tasks throughout a workflow. Configuration changes are slightly less impactful, but must be communicated to those using the task.
Cumulus Message Adapter interface
The Cumulus Message adapter for Javascript provides one method:
runCumulusTask
. It takes five parameters:
taskFunction
- the function containing your business logic (as described above)cumulusMessage
- the event passed by Lambda, and should be a Cumulus Messagecontext
- the Lambda contextcallback
- the callback passed by Lambdaschemas
- JSON object with the locations of the task schemas
The schemas
JSON should contain input:
, output:
, and config:
with strings for each location. If the schema locations are not specified, the message adapter will look for schemas in a schemas directory at the root level for the files: input.json, output.json, or config.json. If the schema is not specified or missing, schema validation will not be performed.
Example Cumulus task
1const cumulusMessageAdapter = require('@cumulus/cumulus-message-adapter-js'); 2 3function myBusinessLogic(nestedEvent, context) { 4 console.log('Hello, example!'); 5 return { answer: 42 }; 6} 7 8// The handler function should rarely, if ever, contain more than this line 9function handler(event, context, callback) { 10 cumulusMessageAdapter.runCumulusTask(myBusinessLogic, event, context, callback, schemas); 11} 12exports.handler = handler;
Creating a deployment package
Tasks that use this library are just standard AWS Lambda tasks. Information on creating release packages is available here.
Usage in Cumulus Deployments
For documentation on how to utilize this package in a Cumulus Deployment, view the Cumulus Workflow Documenation.
Environment variables
There are two environment variables that can be used with this library:
CUMULUS_MESSAGE_ADAPTER_DISABLED=true
- Defaults to false. This env var disables Cumulus Message Adapter. This can be used to turn off the message adapter for tasks that adapt the message on their own, or for testing.
CUMULUS_MESSAGE_ADAPTER_DIR
- The default directory for Cumulus Message Adapter is the root directory of the lambda function.
Development
Running Tests
To run the tests for this package, run npm run lint && npm test
Why use this approach
This approach has a few major advantages:
- It explicitly prevents tasks from making assumptions about data structures
like
meta
andcumulus_meta
that are owned internally and may therefore be broken in future updates. To gain access to fields in these structures, tasks must be passed the data explicitly in the workflow configuration. - It provides clearer ownership of the various data structures. Operators own
meta
. Cumulus ownscumulus_meta
. Tasks define their ownconfig
,input
, andoutput
formats. - The Cumulus Message Adapter greatly simplifies running Lambda functions not explicitly created for Cumulus.
- The approach greatly simplifies testing for tasks, as tasks don't need to set up cumbersome structures to emulate the message protocol and can just test their business function.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
Found 10/14 approved changesets -- score normalized to 7
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 28 are checked with a SAST tool
Score
3.6
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More