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

@elastic.io/component-build-helper

Package Overview
Dependencies
Maintainers
12
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elastic.io/component-build-helper - npm Package Compare versions

Comparing version 2.0.0-alpha1 to 2.0.0-alpha2

5

dist/src/commands/validate.js

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

const utils_1 = require("../utils");
const ComponentContextLoader_1 = require("../ComponentContextLoader");
;

@@ -16,3 +17,5 @@ exports.command = 'validate <componentDirectoryPath>';

const getFileFunction = (0, utils_1.buildGetFileFunction)(componentDirectoryPath);
await (0, metaloader_1.validateComponentJSON)(getFileFunction);
const componentContextLoader = new ComponentContextLoader_1.ComponentContextLoader(getFileFunction);
await componentContextLoader.loadFilesToContext();
await (0, metaloader_1.validateComponentJSON)(componentContextLoader.context['component.json']);
process.exit(0);

@@ -19,0 +22,0 @@ }

6

dist/src/ComponentContextLoader.d.ts

@@ -6,11 +6,11 @@ /// <reference types="node" />

protected _context: {
[key: string]: string;
[key: string]: string | {};
};
protected listOfFilesToLoad: string[];
loadFilesToContext(): Promise<{
[key: string]: string;
[key: string]: string | {};
}>;
get context(): {
[p: string]: string;
[key: string]: string | {};
};
}

@@ -37,3 +37,3 @@ "use strict";

await (0, metaloader_1.resolveMetadataRefs)(component, this.getFileFunction);
this._context[filePath] = JSON.stringify(component);
this._context[filePath] = component;
}

@@ -40,0 +40,0 @@ else if (filePath === 'logo.png') {

@@ -20,3 +20,3 @@ "use strict";

this._icon = this.componentContextLoader.context['logo.png'] || index_1.DEFAULT_ICON;
this._componentJson = JSON.parse(this.componentContextLoader.context['component.json']);
this._componentJson = this.componentContextLoader.context['component.json'];
}

@@ -23,0 +23,0 @@ ;

@@ -5,9 +5,4 @@ /// <reference types="node" />

export declare function resolveMetadataRefs(component: Component, getFile: getFileType): Promise<[any[], any[]]>;
/**
*
* @param getFile function that returns String representation
* of the json file from the component repository
*/
export declare function validateComponentJSON(getFile: getFileType): Promise<any>;
export declare function validateComponentJSON(component: Component): Component;
export declare function getComponentLogo(pathToComponent: string): Promise<string>;
export {};

@@ -91,12 +91,3 @@ "use strict";

exports.resolveMetadataRefs = resolveMetadataRefs;
/**
*
* @param getFile function that returns String representation
* of the json file from the component repository
*/
async function validateComponentJSON(getFile) {
console.log('Reading incoming component.json');
const data = await getFile('./component.json');
console.log('Parsing incoming component.json');
const component = JSON.parse(data.toString());
function validateComponentJSON(component) {
validateComponentVersion(component.version);

@@ -106,3 +97,2 @@ validateFunctionsNames(component);

validateCredentials(component);
await resolveMetadataRefs(component, getFile);
return component;

@@ -109,0 +99,0 @@ }

{
"name": "@elastic.io/component-build-helper",
"version": "2.0.0-alpha1",
"version": "2.0.0-alpha2",
"description": "Helpers for the component build process",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

@@ -29,3 +29,3 @@ import sinon, { SinonSandbox } from 'sinon';

expect(contextLoader.context).to.deep.equal({
'component.json': nodejsComponentJson,
'component.json': JSON.parse(nodejsComponentJson),
'logo.png': logo,

@@ -42,3 +42,3 @@ 'package.json': packageJson

expect(contextLoader.context).to.deep.equal({
'component.json': componentJson,
'component.json': JSON.parse(componentJson),
'logo.png': logo,

@@ -45,0 +45,0 @@ 'build.gradle': buildGralde

@@ -5,3 +5,3 @@ /* eslint-disable @typescript-eslint/camelcase */

import chai from 'chai';
import { validateComponentJSON, getComponentLogo } from '../../src/metaloader';
import { validateComponentJSON, getComponentLogo, resolveMetadataRefs } from '../../src/metaloader';
import data from '../fixtures/metaloader.data';

@@ -70,36 +70,6 @@ import * as fs from 'fs';

it('should return promise', function () {
expect(validateComponentJSON(async () => (Buffer.from(''))).then).to.be.instanceof(Function);
});
it('should fail if file not found', async () => {
try {
await validateComponentJSON(getFileFunction('./hey/there-is-no-repo'));
} catch (err) {
expect(err).not.to.be.undefined;
expect(err.message).to.equal('File ./component.json is missing');
return;
}
throw new Error('should fail');
});
describe('inside repo', function () {
it('should return flat component file', async () => {
const component = await validateComponentJSON(getFileFunction('flat'));
expect(component.title).to.equal('flat');
});
it('should return "without triggers" component file', async () => {
const component = await validateComponentJSON(getFileFunction('withoutTriggers'));
expect(component.title).to.equal('withoutTriggers');
});
it('should return "without actions" component file', async () => {
const component = await validateComponentJSON(getFileFunction('withoutActions'));
expect(component.title).to.equal('withoutActions');
});
it('should fail if external metadata file is missing', async () => {
try {
await validateComponentJSON(getFileFunction('missing'));
await resolveMetadataRefs(components['missing./component.json'], getFileFunction('missing'));
} catch (err) {

@@ -114,3 +84,4 @@ expect(err).not.to.be.undefined;

it('should expand external metadata files', async () => {
const component = await validateComponentJSON(getFileFunction('recursive'));
const component = components['recursive./component.json'];
await resolveMetadataRefs(component, getFileFunction('recursive'));
expect(component.triggers.new_file.metadata.out.loaded).to.equal(true);

@@ -124,3 +95,3 @@ expect(component.actions.put.metadata.out.loaded).to.equal(true);

try {
await validateComponentJSON(getFileFunction('semicolonInActionName'));
await validateComponentJSON(components['semicolonInActionName./component.json']);
} catch (err) {

@@ -138,3 +109,3 @@ expect(err).not.to.be.undefined;

try {
await validateComponentJSON(getFileFunction('dollarSignInTriggerName'));
await validateComponentJSON(components['dollarSignInTriggerName./component.json']);
} catch (err) {

@@ -152,3 +123,3 @@ expect(err).not.to.be.undefined;

try {
await validateComponentJSON(getFileFunction('nonLetterFuncNamesBeginning'));
await validateComponentJSON(components['nonLetterFuncNamesBeginning./component.json']);
} catch (err) {

@@ -167,3 +138,3 @@ expect(err).not.to.be.undefined;

try {
await validateComponentJSON(getFileFunction('sameFuncNamesOneDuplicate'));
await validateComponentJSON(components['sameFuncNamesOneDuplicate./component.json']);
} catch (err) {

@@ -181,3 +152,3 @@ expect(err).not.to.be.undefined;

try {
await validateComponentJSON(getFileFunction('sameFuncNamesTwoDuplicates'));
await validateComponentJSON(components['sameFuncNamesTwoDuplicates./component.json']);
} catch (err) {

@@ -198,7 +169,7 @@ expect(err).not.to.be.undefined;

it('should pass if contain digits (not in the beginning)', async () => {
await validateComponentJSON(getFileFunction('underscoreInTheMiddleAndInTheEnd'));
await validateComponentJSON(components['underscoreInTheMiddleAndInTheEnd./component.json']);
});
it('should pass if contain underscore(not in the beginning)', async () => {
await validateComponentJSON(getFileFunction('digitsInTheMiddleAndInTheEnd'));
await validateComponentJSON(components['digitsInTheMiddleAndInTheEnd./component.json']);
});

@@ -210,3 +181,3 @@ });

try {
await validateComponentJSON(getFileFunction('auth-oauth-clients'));
await validateComponentJSON(components['auth-oauth-clients./component.json']);
} catch (err) {

@@ -221,3 +192,3 @@ expect(err).to.be.instanceof(Error);

try {
await validateComponentJSON(getFileFunction('empty-auth-types'));
await validateComponentJSON(components['empty-auth-types./component.json']);
} catch (err) {

@@ -233,8 +204,8 @@ expect(err).to.be.instanceof(Error);

it('should ignore if version is undefined', async () => {
await validateComponentJSON(getFileFunction('flat'));
await validateComponentJSON(components['flat./component.json']);
});
it('should throw an error if version is invalid semver', async () => {
await expect(validateComponentJSON(getFileFunction('invalidSemver'))).to.be
.rejectedWith('Invalid component version. Please specify the valid semantic version');
expect(() => (validateComponentJSON(components['invalidSemver./component.json'])))
.to.throw('Invalid component version. Please specify the valid semantic version');
});

@@ -241,0 +212,0 @@ });

import type { Arguments, CommandBuilder } from 'yargs';
import { validateComponentJSON } from '../metaloader';
import { buildGetFileFunction } from '../utils';
import { ComponentContextLoader } from '../ComponentContextLoader';
import { Component } from '../interfaces';

@@ -20,4 +22,6 @@ interface Options {

const getFileFunction = buildGetFileFunction(componentDirectoryPath as string);
await validateComponentJSON(getFileFunction);
const componentContextLoader = new ComponentContextLoader(getFileFunction);
await componentContextLoader.loadFilesToContext();
await validateComponentJSON(componentContextLoader.context['component.json'] as Component);
process.exit(0);
};

@@ -10,3 +10,3 @@ import logger from './logger';

}
protected _context: { [key: string]: string } = {}
protected _context: { [key: string]: string | {} } = {}

@@ -36,3 +36,3 @@ // List of files needed to be downloaded

await resolveMetadataRefs(component, this.getFileFunction);
this._context[filePath] = JSON.stringify(component);
this._context[filePath] = component;
} else if (filePath === 'logo.png') {

@@ -56,5 +56,5 @@ this._context[filePath] = buffer.toString('base64');

get context(): { [p: string]: string } {
get context() {
return this._context;
}
}

@@ -22,4 +22,4 @@ /* eslint-disable @typescript-eslint/no-use-before-define */

this.componentContextLoader = componentContextLoader;
this._icon = this.componentContextLoader.context['logo.png'] || DEFAULT_ICON;
this._componentJson = JSON.parse(this.componentContextLoader.context['component.json']);
this._icon = this.componentContextLoader.context['logo.png'] as string || DEFAULT_ICON;
this._componentJson = this.componentContextLoader.context['component.json'] as Component;
};

@@ -102,3 +102,3 @@

const { context } = this.componentContextLoader;
this.predefinedDockerfile = context['Dockerfile'];
this.predefinedDockerfile = context['Dockerfile'] as string;
if (this.predefinedDockerfile) {

@@ -235,3 +235,3 @@ this.predefinedDockerfile += `\n${this.getLabels().join('\n')}`;

// build.gradle is provided by component developer
const buildGradle = await g2js.parseText(context['build.gradle']);
const buildGradle = await g2js.parseText(context['build.gradle'] as string);
this.javaVersion = buildGradle.targetCompatibility || '17';

@@ -247,3 +247,3 @@ if (!this.SUPPORTED_JAVA_VERSIONS.includes(this.javaVersion)) {

// jdeps.info can be used to specify the list of needed for component runtime env java modules
this.predefinedJdeps = this.componentContextLoader.context['jdeps.info'];
this.predefinedJdeps = this.componentContextLoader.context['jdeps.info'] as string;
this.checkIsDockerfilePredefined();

@@ -313,3 +313,3 @@ this.initialized = true;

if (!this.initialized) {
const packageJson = JSON.parse(context['package.json']);
const packageJson = JSON.parse(context['package.json'] as string);
this.nodeVersion = await this.resolveRange(packageJson.engines?.node);

@@ -316,0 +316,0 @@ this._sailorVersion = packageJson.dependencies['elasticio-sailor-nodejs'];

@@ -106,13 +106,3 @@ import { Action, Component, Metadata } from './interfaces';

/**
*
* @param getFile function that returns String representation
* of the json file from the component repository
*/
export async function validateComponentJSON(getFile: getFileType) {
console.log('Reading incoming component.json');
const data = await getFile('./component.json');
console.log('Parsing incoming component.json');
const component = JSON.parse(data.toString());
export function validateComponentJSON(component: Component) {
validateComponentVersion(component.version);

@@ -122,3 +112,2 @@ validateFunctionsNames(component);

validateCredentials(component);
await resolveMetadataRefs(component, getFile);
return component;

@@ -125,0 +114,0 @@ }

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