@deliverr/serverless-offline-step-functions
Version:
Serverless Offline Plugin to Support Step Functions for Local Development
50 lines (49 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LambdaWaitFotTokenPayloadTemplate = void 0;
const jsonpath_plus_1 = require("jsonpath-plus");
const ContextToJson_1 = require("../Context/ContextToJson");
const WaitForTokenPayloadTemplate_1 = require("./WaitForTokenPayloadTemplate");
class LambdaWaitFotTokenPayloadTemplate extends WaitForTokenPayloadTemplate_1.WaitFotTokenPayloadTemplate {
constructor(_payload, context) {
super();
this._payload = _payload;
this.context = context;
}
static create(payload, context) {
if (!payload.FunctionName) {
throw new Error(`The field 'FunctionName' is required but was missing`);
}
Object.keys(payload).forEach((key) => {
if (!this.acceptableParameterProperties.includes(key)) {
throw new Error(`The field "${key}" is not supported by Step Functions`);
}
});
return new LambdaWaitFotTokenPayloadTemplate(payload, context);
}
processPathKey(key, value, inputJson) {
if (typeof value !== 'string') {
throw new Error(`The value for the field '${key}' must be a STRING that contains a JSONPath but was an ${typeof value}`);
}
const newKey = key.substring(0, key.length - 2);
if (this.isContextObjectPath(value)) {
const result = jsonpath_plus_1.JSONPath({
path: value.substring(1),
json: ContextToJson_1.ContextToJson(this.context),
});
return { [newKey]: result[0] };
}
else {
const result = jsonpath_plus_1.JSONPath({
path: value === undefined ? '$' : value,
json: JSON.parse(inputJson),
});
return { [newKey]: result[0] };
}
}
process(inputJson) {
return this.processPayloadTemplate(inputJson, this._payload.Payload);
}
}
exports.LambdaWaitFotTokenPayloadTemplate = LambdaWaitFotTokenPayloadTemplate;
LambdaWaitFotTokenPayloadTemplate.acceptableParameterProperties = ['FunctionName', 'Payload'];