Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fbl

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fbl - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

1

dist/src/plugins/context/ContextValuesAssignment.d.ts

@@ -5,2 +5,3 @@ import { ActionHandler, ActionSnapshot, IHandlerMetadata } from '../../models';

export declare class ContextValuesAssignment extends ActionHandler {
private static ROOT_KEY;
private static metadata;

@@ -7,0 +8,0 @@ private static validationSchema;

14

dist/src/plugins/context/ContextValuesAssignment.js

@@ -27,4 +27,5 @@ "use strict";

const promises = names.map((name) => __awaiter(this, void 0, void 0, function* () {
let value = undefined;
if (options[name].inline) {
context.ctx[name] = options[name].inline;
value = options[name].inline;
}

@@ -34,4 +35,10 @@ if (options[name].file) {

snapshot.log(`Reading from file: ${file} into "ctx.${name}"`);
context.ctx[name] = yield flowService.readYamlFromFile(file);
value = yield flowService.readYamlFromFile(file);
}
if (name === ContextValuesAssignment.ROOT_KEY) {
Object.assign(context.ctx, value);
}
else {
context.ctx[name] = value;
}
}));

@@ -43,6 +50,7 @@ snapshot.setContext(context);

}
ContextValuesAssignment.ROOT_KEY = '.';
ContextValuesAssignment.metadata = {
id: 'com.fireblink.fbl.context.assignValues.inline',
version: '1.0.0',
description: 'Context values assignment. Either inline or from file for each key individually. Only top level keys are supported.',
description: 'Context values assignment. Either inline or from file for each key individually. Only top level keys are supported. Assignment directly to context is possible when "." key is provided.',
aliases: [

@@ -49,0 +57,0 @@ 'fbl.context.assign.inline',

@@ -29,2 +29,3 @@ "use strict";

const path_1 = require("path");
const ejsLint = require('ejs-lint');
let FlowService = class FlowService {

@@ -127,4 +128,22 @@ constructor() {

if (options) {
const tpl = js_yaml_1.dump(options);
const yaml = ejs_1.render(tpl, context);
let tpl = js_yaml_1.dump(options);
// fix template after dump
// while in yaml following string is fully valid '<%- ctx[''name''] %>'
// for EJS it is broken due to quotes escape
const lines = [];
const ejsTemplateRegEx = /<%([^%>]*)%>/g;
const doubleQuotesRegEx = /''/g;
tpl.split('\n').forEach(line => {
if (line.indexOf('\'\'') !== -1) {
// we only want to replace '' to ' inside the EJS template
line = line.replace(ejsTemplateRegEx, function (match, g1) {
return `<%${g1.replace(doubleQuotesRegEx, '\'')}%>`;
});
}
lines.push(line);
});
tpl = lines.join('\n');
// validate template
ejsLint(tpl);
const yaml = ejs_1.render(lines.join('\n'), context);
options = js_yaml_1.safeLoad(yaml);

@@ -131,0 +150,0 @@ }

@@ -6,2 +6,4 @@ export declare class FblTestSuite {

failedExecution(): Promise<void>;
ejsTemplateValidation(): Promise<void>;
templateProcessingStringEscape(): Promise<void>;
}

@@ -29,2 +29,3 @@ "use strict";

chai.use(chaiAsPromised);
const jsyaml = require('js-yaml');
class DummyActionHandler extends models_1.ActionHandler {

@@ -129,2 +130,51 @@ constructor(fn, skipExecution) {

}
ejsTemplateValidation() {
return __awaiter(this, void 0, void 0, function* () {
const fbl = typedi_1.Container.get(fbl_1.FireBlinkLogistics);
fbl.flowService.debug = true;
let result = null;
fbl.flowService.actionHandlersRegistry.register(new DummyActionHandler((opt) => __awaiter(this, void 0, void 0, function* () {
result = opt;
}), false));
const snapshot = yield fbl.execute('.', {
version: '1.0.0',
pipeline: {
[DummyActionHandler.ID]: `<%- ctx.t1`
}
}, {
ctx: {
t1: 'tst'
}
});
assert.strictEqual(snapshot.successful, false);
assert.strictEqual(snapshot.getSteps().find(s => s.type === 'failure').payload, 'Error: Could not find matching close tag for "<%-".');
assert.strictEqual(result, null);
});
}
templateProcessingStringEscape() {
return __awaiter(this, void 0, void 0, function* () {
const fbl = typedi_1.Container.get(fbl_1.FireBlinkLogistics);
fbl.flowService.debug = true;
let result = null;
fbl.flowService.actionHandlersRegistry.register(new DummyActionHandler((opt) => __awaiter(this, void 0, void 0, function* () {
result = opt;
}), false));
const snapshot = yield fbl.execute('.', {
version: '1.0.0',
pipeline: {
[DummyActionHandler.ID]: `<%- ctx['t1']["t2"].value %>`
}
}, {
ctx: {
t1: {
t2: {
value: 'tst'
}
}
}
});
assert.strictEqual(snapshot.successful, true);
assert.strictEqual(result, 'tst');
});
}
};

@@ -149,2 +199,14 @@ __decorate([

], FblTestSuite.prototype, "failedExecution", null);
__decorate([
mocha_typescript_1.test(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], FblTestSuite.prototype, "ejsTemplateValidation", null);
__decorate([
mocha_typescript_1.test(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], FblTestSuite.prototype, "templateProcessingStringEscape", null);
FblTestSuite = __decorate([

@@ -151,0 +213,0 @@ mocha_typescript_1.suite()

@@ -5,2 +5,3 @@ export declare class ContextValuesAssignmentTestSuite {

assignValues(): Promise<void>;
assignRootValues(): Promise<void>;
}

@@ -129,2 +129,50 @@ "use strict";

}
assignRootValues() {
return __awaiter(this, void 0, void 0, function* () {
const actionHandler = new ContextValuesAssignment_1.ContextValuesAssignment();
const context = {
ctx: {
existing: {
value: 'value'
}
}
};
const fileContent = {
file_content: 'ftpo'
};
const tmpFile = yield tmp.file();
// write to temp file
yield util_1.promisify(fs_1.writeFile)(tmpFile.path, js_yaml_1.dump(fileContent), 'utf8');
const options = {
test: {
inline: 123
},
'.': {
inline: {
other: 'other'
}
},
fromFile: {
file: tmpFile.path
}
};
const snapshot = new models_1.ActionSnapshot('.', '', 0);
yield actionHandler.validate(options, context, snapshot);
yield actionHandler.execute(options, context, snapshot);
assert.strictEqual(context.ctx.test, 123);
assert.strictEqual(context.ctx.existing.value, 'value');
assert.strictEqual(context.ctx.other, 'other');
assert.strictEqual(context.ctx.fromFile.file_content, fileContent.file_content);
console.log('->', tmpFile.path);
// do the same with relative path
options.fromFile.file = path_1.basename(tmpFile.path);
snapshot.wd = path_1.dirname(tmpFile.path);
yield actionHandler.validate(options, context, snapshot);
yield actionHandler.execute(options, context, snapshot);
assert.strictEqual(context.ctx.test, 123);
assert.strictEqual(context.ctx.existing.value, 'value');
assert.strictEqual(context.ctx.other, 'other');
assert.strictEqual(context.ctx.fromFile.file_content, fileContent.file_content);
});
}
};

@@ -149,2 +197,8 @@ __decorate([

], ContextValuesAssignmentTestSuite.prototype, "assignValues", null);
__decorate([
mocha_typescript_1.test(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ContextValuesAssignmentTestSuite.prototype, "assignRootValues", null);
ContextValuesAssignmentTestSuite = __decorate([

@@ -151,0 +205,0 @@ mocha_typescript_1.suite()

{
"name": "fbl",
"version": "0.0.3",
"version": "0.0.4",
"description": "",

@@ -15,3 +15,3 @@ "main": "dist/cli.js",

"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
"prepublish": "npm run build && npm run lint",
"prepublishOnly": "npm run build && npm run lint",
"precommit": "npm run lint"

@@ -26,5 +26,6 @@ },

"chai-as-promised": "7.1.1",
"colors": "1.3.0",
"colors": "1.3.1",
"commander": "2.16.0",
"ejs": "2.6.1",
"ejs-lint": "0.3.0",
"humanize-duration": "3.15.1",

@@ -31,0 +32,0 @@ "joi": "13.4.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc