Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/TemplateArchiveProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class TemplateArchiveProcessor {
* @param {object} request - the request to send to the template logic
* @param {object} state - the current state of the template
* @param {[string]} currentTime - the current time, defaults to now
* @param {[number]} utcOffset - the UTC offer, defaults to zero
* @param {[number]} utcOffset - the UTC offset, defaults to zero
* @returns {Promise} the response and any events
*/
async trigger(data: any, request: any, state?: any, currentTime?: string, utcOffset?: number): Promise<TriggerResponse> {
Expand All @@ -112,14 +112,16 @@ export class TemplateArchiveProcessor {
compiledCode[tsFile.getIdentifier()] = result;
}
// console.log(compiledCode['logic/logic.ts'].code);
const resolvedTime = currentTime ?? new Date().toISOString();
const resolvedOffset = utcOffset ?? 0;
const evaluator = new JavaScriptEvaluator();
const evalResponse = await evaluator.evalDangerously( {
templateLogic: true,
verbose: false,
functionName: 'trigger',
code: compiledCode['logic/logic.ts'].code, // TODO DCS - how to find the code to run?
argumentNames: ['data', 'request', 'state'],
arguments: [data, request, state, currentTime, utcOffset]
arguments: [data, request, state, resolvedTime, resolvedOffset]
});
if(evalResponse.result) {
return evalResponse.result;
Expand All @@ -136,8 +138,8 @@ export class TemplateArchiveProcessor {
/**
* Init the logic of a template
* @param {[string]} currentTime - the current time, defaults to now
* @param {[number]} utcOffset - the UTC offer, defaults to zero
* @returns {Promise} the response and any events
* @param {[number]} utcOffset - the UTC offset, defaults to zero
* @returns {Promise<InitResponse>} the new state
*/
async init(data: any, currentTime?: string, utcOffset?: number): Promise<InitResponse> {
const logicManager = this.template.getLogicManager();
Expand All @@ -161,14 +163,16 @@ export class TemplateArchiveProcessor {
compiledCode[tsFile.getIdentifier()] = result;
}
// console.log(compiledCode['logic/logic.ts'].code);
const resolvedTime = currentTime ?? new Date().toISOString();
const resolvedOffset = utcOffset ?? 0;
const evaluator = new JavaScriptEvaluator();
const evalResponse = await evaluator.evalDangerously( {
templateLogic: true,
verbose: false,
functionName: 'init',
code: compiledCode['logic/logic.ts'].code, // TODO DCS - how to find the code to run?
argumentNames: ['data'],
arguments: [data, currentTime, utcOffset]
arguments: [data, resolvedTime, resolvedOffset]
});
if(evalResponse.result) {
return evalResponse.result;
Expand Down