Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
@mondaydotcomorg/node-execution-context
Advanced tools
Persistent execution context allowing you to get/set the context anywhere implemented using async hooks. Can be used to create request level execution context, a stack trace that persists through async resources, or anything else you need to survive the e
A simple, straightforward library that allows you to create persistent request-level execution context using the async_hooks module that will be accessible anywhere in the code scoped to the current request you're handling at any given moment.
$ npm install @mondaydotcomorg/node-execution-context
or with yarn:
$ yarn add @mondaydotcomorg/node-execution-context
Let's create a service that will use our library in order to create and get context.
const contextProvider = require('@mondaydotcomorg/node-execution-context');
function createExecutionContext(contextData) {
contextProvider.createExecutionContext(contextData);
};
function getExecutionContext() {
const context = contextProvider.getExecutionContext();
return context;
};
module.exports = {
getExecutionContext,
createExecutionContext
};
Now wherever we want in our code we can pass an object to createExecutionContext and it will be saved and accesible for any async resources descendant from that place forward.
For example let's do this in a middleware that is the first thing that runs on a new request.
const executionContextService = require('services/execution-context-service');
async function authenticationMiddleware(req, res, next) {
const { accountPermissions } = req.body
executionContextService.createExecutionContext({
accountPermissions,
method: req.method,
});
next();
}
Now we can use this context later and be certain that the request being handled is the same one for which we are getting our context.
const executionContextService = require('services/execution-context-service');
const eventModelService = require('services/event-model-service');
async function createNewEvent(eventData) {
const { accountPermissions } = executionContextService.getExecutionContext();
eventModelService.createEvent(accountPermissions, eventData);
}
Creates an execution context identified by the asyncId of the current asyncResource. This will be available anywhere in the execution that is inside the async chain of this resource. Context passed must be an object. You cannot create an execution context twice within the same async resource. If you want to update after creation use set ot update. This check will fail only in non-prod environments for performance purposes.
Optional Params: traceOptions can be passed if you want to set some initial trace data into the trace and have the context add a trace detailing async Id and resource type each time context is updated. If you do not pass this object the trace is never created. This can be used for debugging or for enriching logs, however should not be passed if not needed as this will be added fro every async resource created.
Returns only the context object given as the first param to createExecutionContext.
Returns only the trace array collected if enabled in traceOptions.
Returns entire context data including both context object and trace array.
Allows you to completly override context saved for current async resource.
Allows you update specific keys in the context saved for current async resource.
FAQs
Persistent execution context allowing you to get/set the context anywhere implemented using async hooks. Can be used to create request level execution context, a stack trace that persists through async resources, or anything else you need to survive the e
The npm package @mondaydotcomorg/node-execution-context receives a total of 426 weekly downloads. As such, @mondaydotcomorg/node-execution-context popularity was classified as not popular.
We found that @mondaydotcomorg/node-execution-context demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 51 open source maintainers 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
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.