Custom functions context
Hooks, cronjobs and message handlers have a similar context being injected to a customised function. If your project is targeting stack9 greather than 3.0, you can install stack9-sdk package and take advantage of the type definition available for each one of these methods.
Base Context
All customised function share this properties in the context:
@prop db
- object - core repositories and database transaction;
@prop services
- object - core services;
@prop logger
- object - to write logs in splunk or seq;
@prop environmentType
- string - local, Development, UAT, Pre Production, Production.
Extended contexts for each customisation method
Custom api
@prop user
- object - user in context of the operation;
@prop url
- string - request URL;
@prop body
- json - body payload when received a PUT or POST method;
@prop query
- json - querystring parameters serialised in json.
Custom function
@prop user
- object - user in context of the operation;
@prop hookType
- string - ValidateAndTransformInput or AfterChange;
@prop operation
- string - defaults: create, update, delete workflow: proceedToStep, returnStep, approveWorkflow, takeOwnership, rejectWorkflow;
@prop entity
- object - entity recevied;
@prop oldEntity
- object - entity before save;
@prop workflowData
- object - extra information about the workflow;
@prop entityName
- string - entity name persisted.
Cron job
Document function
Message handler
Receives the base context but it also has the companion of message
object described bellow:
@prop queue
- string - queue name, must be the same configured in message-handler;
@prop userId
- string - optional: id of the user executing the action;
@prop entityType
- string - optional: entity name;
@prop entityId
- number - optional: id of the entity being processed;
@prop action
- string optional: workflow action;
@prop operation
- string - optional: workflow operation;
@prop body
- string - body payload passed to the message.