Fix StartOS 0.4 TypeScript packaging to match SDK API
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTask = exports.runAction = void 0;
|
||||
const runAction = async (options) => {
|
||||
if (options.input) {
|
||||
if (options.input instanceof Function) {
|
||||
const prev = await options.effects.action.getInput({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
});
|
||||
const input = options.input(prev
|
||||
? { spec: prev.spec, value: prev.value }
|
||||
: undefined);
|
||||
return options.effects.action.run({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
input,
|
||||
});
|
||||
}
|
||||
else {
|
||||
return options.effects.action.run({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
input: options.input,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
return options.effects.action.run({
|
||||
// packageId: options.packageId,
|
||||
actionId: options.actionId,
|
||||
});
|
||||
}
|
||||
};
|
||||
exports.runAction = runAction;
|
||||
const _validate = {};
|
||||
/** Recursively converts undefined values to null so they survive JSON serialization */
|
||||
function undefinedToNull(obj) {
|
||||
if (obj === undefined)
|
||||
return null;
|
||||
if (obj === null || typeof obj !== 'object')
|
||||
return obj;
|
||||
if (Array.isArray(obj))
|
||||
return obj.map(undefinedToNull);
|
||||
const result = {};
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
result[k] = undefinedToNull(v);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
const createTask = (options) => {
|
||||
const request = options.options || {};
|
||||
const actionId = options.action.id;
|
||||
const input = 'input' in request && request.input
|
||||
? { ...request.input, value: undefinedToNull(request.input.value) }
|
||||
: request.input;
|
||||
const req = {
|
||||
...request,
|
||||
input,
|
||||
actionId,
|
||||
packageId: options.packageId,
|
||||
action: undefined,
|
||||
severity: options.severity,
|
||||
replayId: request.replayId || `${options.packageId}:${actionId}`,
|
||||
};
|
||||
delete req.action;
|
||||
return options.effects.action.createTask(req);
|
||||
};
|
||||
exports.createTask = createTask;
|
||||
//# sourceMappingURL=index.js.map
|
||||
Reference in New Issue
Block a user