@squiz/render-runtime-lib 1.2.1-alpha.87 → 1.2.1-alpha.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/component-runner/index.d.ts +2 -1
- package/lib/component-runner/worker/WorkerPool.d.ts +1 -1
- package/lib/index.js +20530 -20042
- package/lib/index.js.map +3 -3
- package/lib/utils/getFunctionDefinitionFromManifest.d.ts +2 -0
- package/lib/utils/getPreviewFilePath.d.ts +1 -0
- package/lib/utils/getPreviewFilePath.spec.d.ts +1 -0
- package/lib/utils/resolvePreviewOutput.d.ts +2 -0
- package/lib/utils/resolvePreviewOutput.spec.d.ts +1 -0
- package/lib/webserver/app.d.ts +2 -2
- package/lib/webserver/index.d.ts +2 -2
- package/lib/worker/worker-root.js +518 -30
- package/lib/worker/worker-root.js.map +3 -3
- package/package.json +4 -4
|
@@ -1234,6 +1234,9 @@ var require_acorn = __commonJS({
|
|
|
1234
1234
|
if (options.allowReserved == null) {
|
|
1235
1235
|
options.allowReserved = options.ecmaVersion < 5;
|
|
1236
1236
|
}
|
|
1237
|
+
if (opts.allowHashBang == null) {
|
|
1238
|
+
options.allowHashBang = options.ecmaVersion >= 14;
|
|
1239
|
+
}
|
|
1237
1240
|
if (isArray(options.onToken)) {
|
|
1238
1241
|
var tokens = options.onToken;
|
|
1239
1242
|
options.onToken = function(token) {
|
|
@@ -1480,7 +1483,7 @@ var require_acorn = __commonJS({
|
|
|
1480
1483
|
}
|
|
1481
1484
|
var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
|
|
1482
1485
|
if (parens > -1) {
|
|
1483
|
-
this.raiseRecoverable(parens, "Parenthesized pattern");
|
|
1486
|
+
this.raiseRecoverable(parens, isAssign ? "Assigning to rvalue" : "Parenthesized pattern");
|
|
1484
1487
|
}
|
|
1485
1488
|
};
|
|
1486
1489
|
pp$9.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
|
|
@@ -2481,7 +2484,7 @@ var require_acorn = __commonJS({
|
|
|
2481
2484
|
}
|
|
2482
2485
|
};
|
|
2483
2486
|
pp$8.isDirectiveCandidate = function(statement) {
|
|
2484
|
-
return statement.type === "ExpressionStatement" && statement.expression.type === "Literal" && typeof statement.expression.value === "string" && (this.input[statement.start] === '"' || this.input[statement.start] === "'");
|
|
2487
|
+
return this.options.ecmaVersion >= 5 && statement.type === "ExpressionStatement" && statement.expression.type === "Literal" && typeof statement.expression.value === "string" && (this.input[statement.start] === '"' || this.input[statement.start] === "'");
|
|
2485
2488
|
};
|
|
2486
2489
|
var pp$7 = Parser.prototype;
|
|
2487
2490
|
pp$7.toAssignable = function(node, isBinding, refDestructuringErrors) {
|
|
@@ -3545,14 +3548,6 @@ var require_acorn = __commonJS({
|
|
|
3545
3548
|
}
|
|
3546
3549
|
return this.finishNode(prop, "RestElement");
|
|
3547
3550
|
}
|
|
3548
|
-
if (this.type === types$1.parenL && refDestructuringErrors) {
|
|
3549
|
-
if (refDestructuringErrors.parenthesizedAssign < 0) {
|
|
3550
|
-
refDestructuringErrors.parenthesizedAssign = this.start;
|
|
3551
|
-
}
|
|
3552
|
-
if (refDestructuringErrors.parenthesizedBind < 0) {
|
|
3553
|
-
refDestructuringErrors.parenthesizedBind = this.start;
|
|
3554
|
-
}
|
|
3555
|
-
}
|
|
3556
3551
|
prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
|
|
3557
3552
|
if (this.type === types$1.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
|
|
3558
3553
|
refDestructuringErrors.trailingComma = this.start;
|
|
@@ -5627,7 +5622,7 @@ var require_acorn = __commonJS({
|
|
|
5627
5622
|
}
|
|
5628
5623
|
return this.finishToken(type, word);
|
|
5629
5624
|
};
|
|
5630
|
-
var version = "8.
|
|
5625
|
+
var version = "8.8.0";
|
|
5631
5626
|
Parser.acorn = {
|
|
5632
5627
|
Parser,
|
|
5633
5628
|
version,
|
|
@@ -8084,6 +8079,12 @@ var require_v1 = __commonJS({
|
|
|
8084
8079
|
maxLength: 14,
|
|
8085
8080
|
pattern: "^(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)$"
|
|
8086
8081
|
},
|
|
8082
|
+
environment: {
|
|
8083
|
+
type: "array",
|
|
8084
|
+
items: {
|
|
8085
|
+
type: "string"
|
|
8086
|
+
}
|
|
8087
|
+
},
|
|
8087
8088
|
"static-files": {
|
|
8088
8089
|
type: "object",
|
|
8089
8090
|
properties: {
|
|
@@ -8107,12 +8108,6 @@ var require_v1 = __commonJS({
|
|
|
8107
8108
|
description: "Function name, this will be used as part of the url to access this function. It must be a valid url"
|
|
8108
8109
|
},
|
|
8109
8110
|
entry: { type: "string" },
|
|
8110
|
-
environment: {
|
|
8111
|
-
type: "array",
|
|
8112
|
-
items: {
|
|
8113
|
-
type: "string"
|
|
8114
|
-
}
|
|
8115
|
-
},
|
|
8116
8111
|
input: {
|
|
8117
8112
|
type: "object"
|
|
8118
8113
|
},
|
|
@@ -8132,8 +8127,59 @@ var require_v1 = __commonJS({
|
|
|
8132
8127
|
additionalProperties: false,
|
|
8133
8128
|
properties: {
|
|
8134
8129
|
location: { oneOf: [{ const: "header" }, { const: "footer" }] },
|
|
8135
|
-
file: {
|
|
8136
|
-
|
|
8130
|
+
file: {
|
|
8131
|
+
oneOf: [
|
|
8132
|
+
{
|
|
8133
|
+
type: "object",
|
|
8134
|
+
title: "JsFile",
|
|
8135
|
+
additionalProperties: false,
|
|
8136
|
+
properties: {
|
|
8137
|
+
type: { const: "js" },
|
|
8138
|
+
filepath: { type: "string" },
|
|
8139
|
+
defer: { type: "boolean" },
|
|
8140
|
+
async: { type: "boolean" },
|
|
8141
|
+
integrity: { type: "string" },
|
|
8142
|
+
crossorigin: { oneOf: [{ const: "anonymous" }, { const: "use-credentials" }] },
|
|
8143
|
+
referrerpolicy: {
|
|
8144
|
+
oneOf: [
|
|
8145
|
+
{ const: "no-referrer" },
|
|
8146
|
+
{ const: "no-referrer-when-downgrade" },
|
|
8147
|
+
{ const: "origin" },
|
|
8148
|
+
{ const: "origin-when-cross-origin" },
|
|
8149
|
+
{ const: "same-origin" },
|
|
8150
|
+
{ const: "strict-origin" },
|
|
8151
|
+
{ const: "strict-origin-when-cross-origin" },
|
|
8152
|
+
{ const: "unsafe-url" }
|
|
8153
|
+
]
|
|
8154
|
+
}
|
|
8155
|
+
},
|
|
8156
|
+
required: ["filepath", "type"]
|
|
8157
|
+
},
|
|
8158
|
+
{
|
|
8159
|
+
type: "object",
|
|
8160
|
+
title: "CssFile",
|
|
8161
|
+
additionalProperties: false,
|
|
8162
|
+
properties: {
|
|
8163
|
+
type: { const: "css" },
|
|
8164
|
+
filepath: { type: "string" },
|
|
8165
|
+
crossorigin: { oneOf: [{ const: "anonymous" }, { const: "use-credentials" }] },
|
|
8166
|
+
referrerpolicy: {
|
|
8167
|
+
oneOf: [
|
|
8168
|
+
{ const: "no-referrer" },
|
|
8169
|
+
{ const: "no-referrer-when-downgrade" },
|
|
8170
|
+
{ const: "origin" },
|
|
8171
|
+
{ const: "origin-when-cross-origin" },
|
|
8172
|
+
{ const: "same-origin" },
|
|
8173
|
+
{ const: "strict-origin" },
|
|
8174
|
+
{ const: "strict-origin-when-cross-origin" },
|
|
8175
|
+
{ const: "unsafe-url" }
|
|
8176
|
+
]
|
|
8177
|
+
}
|
|
8178
|
+
},
|
|
8179
|
+
required: ["filepath"]
|
|
8180
|
+
}
|
|
8181
|
+
]
|
|
8182
|
+
}
|
|
8137
8183
|
},
|
|
8138
8184
|
required: ["location", "file"]
|
|
8139
8185
|
}
|
|
@@ -8160,7 +8206,10 @@ var require_v1 = __commonJS({
|
|
|
8160
8206
|
},
|
|
8161
8207
|
required: ["name", "version", "functions", "$schema", "main-function"],
|
|
8162
8208
|
$defs: {
|
|
8163
|
-
"name-pattern": {
|
|
8209
|
+
"name-pattern": {
|
|
8210
|
+
type: "string",
|
|
8211
|
+
pattern: "^[a-zA-Z0-9_\\-]+$"
|
|
8212
|
+
}
|
|
8164
8213
|
}
|
|
8165
8214
|
};
|
|
8166
8215
|
}
|
|
@@ -14821,7 +14870,7 @@ var require_schemas = __commonJS({
|
|
|
14821
14870
|
exports.schemaVersions = exports.schemaVersionRegex = void 0;
|
|
14822
14871
|
var v1_json_1 = __importDefault(require_v1());
|
|
14823
14872
|
var ajv_1 = __importDefault(require_ajv());
|
|
14824
|
-
var ajv = new ajv_1.default();
|
|
14873
|
+
var ajv = new ajv_1.default({ allErrors: true });
|
|
14825
14874
|
exports.schemaVersionRegex = /\/(?<schema>\w+)\.json#?$/i;
|
|
14826
14875
|
exports.schemaVersions = { v1: v1_json_1.default };
|
|
14827
14876
|
for (const [version, schema] of Object.entries(exports.schemaVersions)) {
|
|
@@ -22820,6 +22869,7 @@ var require_LoadedComponent = __commonJS({
|
|
|
22820
22869
|
var isValidationFailure_1 = require_isValidationFailure();
|
|
22821
22870
|
var never_1 = require_never();
|
|
22822
22871
|
var types_1 = require("util/types");
|
|
22872
|
+
var ajv = new ajv_1.default({ allErrors: true, strict: true, strictTypes: true });
|
|
22823
22873
|
var LoadedComponent = class {
|
|
22824
22874
|
constructor(manifest, componentFilesRoot, componentRootUrl, componentExecutor) {
|
|
22825
22875
|
this.manifest = manifest;
|
|
@@ -22827,12 +22877,17 @@ var require_LoadedComponent = __commonJS({
|
|
|
22827
22877
|
this.componentRootUrl = componentRootUrl;
|
|
22828
22878
|
this.componentExecutor = componentExecutor;
|
|
22829
22879
|
this.mainFunction = manifest["main-function"];
|
|
22830
|
-
this.ajv = new ajv_1.default({ allErrors: true });
|
|
22831
22880
|
for (const func of manifest.functions) {
|
|
22832
22881
|
const slug = this.getFunctionComponentSlug(func.name);
|
|
22833
22882
|
const output = this.getOutputValidationSchema(func.output, manifest);
|
|
22834
|
-
|
|
22835
|
-
|
|
22883
|
+
const inputSchemaName = `${slug}-input`;
|
|
22884
|
+
const outputSchemaName = `${slug}-output`;
|
|
22885
|
+
if (ajv.schemas[inputSchemaName] === void 0) {
|
|
22886
|
+
ajv.addSchema(func.input, inputSchemaName);
|
|
22887
|
+
}
|
|
22888
|
+
if (ajv.schemas[outputSchemaName] === void 0) {
|
|
22889
|
+
ajv.addSchema(output, outputSchemaName);
|
|
22890
|
+
}
|
|
22836
22891
|
}
|
|
22837
22892
|
}
|
|
22838
22893
|
componentHasFunction(functionName) {
|
|
@@ -22889,7 +22944,7 @@ var require_LoadedComponent = __commonJS({
|
|
|
22889
22944
|
throw new Error(`input value for ${functionName} cannot be undefined`);
|
|
22890
22945
|
}
|
|
22891
22946
|
const slug = this.getFunctionComponentSlug(functionName);
|
|
22892
|
-
const validator =
|
|
22947
|
+
const validator = ajv.getSchema(`${slug}-input`);
|
|
22893
22948
|
if (!validator) {
|
|
22894
22949
|
throw new Error(`${functionName} has no input schema registered`);
|
|
22895
22950
|
}
|
|
@@ -22898,7 +22953,7 @@ var require_LoadedComponent = __commonJS({
|
|
|
22898
22953
|
}
|
|
22899
22954
|
validateOutput(functionName, output) {
|
|
22900
22955
|
const slug = this.getFunctionComponentSlug(functionName);
|
|
22901
|
-
const validator =
|
|
22956
|
+
const validator = ajv.getSchema(`${slug}-output`);
|
|
22902
22957
|
if (!validator) {
|
|
22903
22958
|
throw new Error(`${functionName} has no output schema registered`);
|
|
22904
22959
|
}
|
|
@@ -23207,11 +23262,11 @@ var require_loadComponent = __commonJS({
|
|
|
23207
23262
|
const staticFileRoot = path_1.default.join(componentRoot, staticFileLocationRoot);
|
|
23208
23263
|
const staticFiles = func.output["static-files"] || [];
|
|
23209
23264
|
for (const staticFile of staticFiles) {
|
|
23210
|
-
if (staticFile.file.startsWith("http://") || staticFile.file.startsWith("https://")) {
|
|
23265
|
+
if (staticFile.file.filepath.startsWith("http://") || staticFile.file.filepath.startsWith("https://")) {
|
|
23211
23266
|
continue;
|
|
23212
23267
|
}
|
|
23213
|
-
if ((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)(staticFileRoot, staticFile.file) || !await isReadable(staticFileRoot, staticFile.file)) {
|
|
23214
|
-
throw new Error(`access to a static file "${staticFile.file}" for "${func.name}" outside the parent directory in "${manifest.name} ${manifest.version}" is not alllowed`);
|
|
23268
|
+
if ((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)(staticFileRoot, staticFile.file.filepath) || !await isReadable(staticFileRoot, staticFile.file.filepath)) {
|
|
23269
|
+
throw new Error(`access to a static file "${staticFile.file.filepath}" for "${func.name}" outside the parent directory in "${manifest.name} ${manifest.version}" is not alllowed`);
|
|
23215
23270
|
}
|
|
23216
23271
|
}
|
|
23217
23272
|
}
|
|
@@ -40704,6 +40759,432 @@ var require_getNodeEnv = __commonJS({
|
|
|
40704
40759
|
}
|
|
40705
40760
|
});
|
|
40706
40761
|
|
|
40762
|
+
// ../component-lib/lib/component-service/services/ComponentService.js
|
|
40763
|
+
var require_ComponentService = __commonJS({
|
|
40764
|
+
"../component-lib/lib/component-service/services/ComponentService.js"(exports) {
|
|
40765
|
+
"use strict";
|
|
40766
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
40767
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
40768
|
+
};
|
|
40769
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40770
|
+
exports.ComponentService = void 0;
|
|
40771
|
+
var path_1 = __importDefault(require("path"));
|
|
40772
|
+
var fs_extra_1 = __importDefault(require_lib4());
|
|
40773
|
+
var error_1 = require_error();
|
|
40774
|
+
var validateManifest_1 = require_validateManifest();
|
|
40775
|
+
var ComponentService = class {
|
|
40776
|
+
constructor(db, logger, dataMountPoint) {
|
|
40777
|
+
this.db = db;
|
|
40778
|
+
this.logger = logger;
|
|
40779
|
+
this.dataMountPoint = dataMountPoint;
|
|
40780
|
+
}
|
|
40781
|
+
async saveComponent(componentLocation) {
|
|
40782
|
+
const manifest = await this.readManifest(componentLocation);
|
|
40783
|
+
this.assertManifestIsValid(manifest);
|
|
40784
|
+
if (await this.componentVersionExists(manifest.name, manifest.version)) {
|
|
40785
|
+
throw new error_1.BadRequestError(`Component ${manifest.name} ${manifest.version} already exists`);
|
|
40786
|
+
}
|
|
40787
|
+
const destPath = await this.getValidComponentDestinationPath(manifest);
|
|
40788
|
+
await this.moveFilesAndUpdateDb(manifest, componentLocation, destPath);
|
|
40789
|
+
}
|
|
40790
|
+
async componentVersionExists(name, version) {
|
|
40791
|
+
const componentVersion = await this.db.repositories.componentVersion.getComponentByNameAndVersion(name, version);
|
|
40792
|
+
return componentVersion !== void 0;
|
|
40793
|
+
}
|
|
40794
|
+
async deleteComponent(componentName) {
|
|
40795
|
+
this.assertValidComponentName(componentName);
|
|
40796
|
+
await this.assertComponentExists(componentName);
|
|
40797
|
+
const compPath = path_1.default.join(this.dataMountPoint, componentName);
|
|
40798
|
+
try {
|
|
40799
|
+
await this.db.repositories.componentVersion.delete({ componentName });
|
|
40800
|
+
} catch (e) {
|
|
40801
|
+
this.logger.error(e);
|
|
40802
|
+
}
|
|
40803
|
+
try {
|
|
40804
|
+
await this.db.repositories.component.delete({ name: componentName });
|
|
40805
|
+
} catch (e) {
|
|
40806
|
+
this.logger.error(e);
|
|
40807
|
+
}
|
|
40808
|
+
try {
|
|
40809
|
+
await fs_extra_1.default.rm(compPath, { force: true, recursive: true });
|
|
40810
|
+
} catch (e) {
|
|
40811
|
+
this.logger.error(e);
|
|
40812
|
+
}
|
|
40813
|
+
const componentExists = await this.db.repositories.component.componentExists(componentName);
|
|
40814
|
+
const filesExist = await fs_extra_1.default.pathExists(compPath);
|
|
40815
|
+
if (componentExists) {
|
|
40816
|
+
throw new Error(`failed to remove ${componentName} from DB`);
|
|
40817
|
+
}
|
|
40818
|
+
if (filesExist) {
|
|
40819
|
+
throw new Error(`failed to remove ${componentName} files from the disk`);
|
|
40820
|
+
}
|
|
40821
|
+
}
|
|
40822
|
+
async deleteComponentVersion(componentName, version) {
|
|
40823
|
+
this.assertValidComponentVersion(componentName, version);
|
|
40824
|
+
await this.assertComponentVersionExists(componentName, version);
|
|
40825
|
+
const compVersionPath = path_1.default.join(this.dataMountPoint, componentName, version);
|
|
40826
|
+
try {
|
|
40827
|
+
await this.db.repositories.componentVersion.delete({ componentName, version });
|
|
40828
|
+
await fs_extra_1.default.rm(compVersionPath, { force: true, recursive: true });
|
|
40829
|
+
} catch (e) {
|
|
40830
|
+
this.logger.error(e);
|
|
40831
|
+
}
|
|
40832
|
+
const componentVersionExists = await this.db.repositories.componentVersion.componentVersionExists(componentName, version);
|
|
40833
|
+
const filesExist = await fs_extra_1.default.pathExists(compVersionPath);
|
|
40834
|
+
if (componentVersionExists) {
|
|
40835
|
+
throw new Error(`failed to remove ${componentName} from DB`);
|
|
40836
|
+
}
|
|
40837
|
+
if (filesExist) {
|
|
40838
|
+
throw new Error(`failed to remove ${componentName} files from the disk`);
|
|
40839
|
+
}
|
|
40840
|
+
}
|
|
40841
|
+
assertValidComponentName(componentName) {
|
|
40842
|
+
const rootDir = path_1.default.resolve(this.dataMountPoint);
|
|
40843
|
+
const compPath = path_1.default.join(this.dataMountPoint, componentName);
|
|
40844
|
+
const checkPath = path_1.default.resolve(this.dataMountPoint) + path_1.default.sep + componentName;
|
|
40845
|
+
if (checkPath !== compPath || rootDir === compPath) {
|
|
40846
|
+
throw new error_1.ResourceNotFoundError(`component name ${componentName} is invalid`);
|
|
40847
|
+
}
|
|
40848
|
+
}
|
|
40849
|
+
assertValidComponentVersion(componentName, version) {
|
|
40850
|
+
const versionPath = path_1.default.join(this.dataMountPoint, componentName, version);
|
|
40851
|
+
const checkPath = [path_1.default.resolve(this.dataMountPoint), componentName, version].join(path_1.default.sep);
|
|
40852
|
+
if (checkPath !== versionPath) {
|
|
40853
|
+
throw new error_1.ResourceNotFoundError(`Component version ${version} is invalid`);
|
|
40854
|
+
}
|
|
40855
|
+
}
|
|
40856
|
+
async assertComponentExists(componentName) {
|
|
40857
|
+
const compPath = path_1.default.join(this.dataMountPoint, componentName);
|
|
40858
|
+
if (!await this.db.repositories.component.componentExists(componentName) && !await fs_extra_1.default.pathExists(compPath)) {
|
|
40859
|
+
throw new error_1.ResourceNotFoundError(`Component ${componentName} not found`);
|
|
40860
|
+
}
|
|
40861
|
+
}
|
|
40862
|
+
async assertComponentVersionExists(componentName, version) {
|
|
40863
|
+
await this.assertComponentExists(componentName);
|
|
40864
|
+
const compVersionPath = path_1.default.join(this.dataMountPoint, componentName, version);
|
|
40865
|
+
if (!await this.db.repositories.componentVersion.componentVersionExists(componentName, version) && !await fs_extra_1.default.pathExists(compVersionPath)) {
|
|
40866
|
+
throw new error_1.ResourceNotFoundError(`Component version ${version} for component ${componentName} not found`);
|
|
40867
|
+
}
|
|
40868
|
+
}
|
|
40869
|
+
async moveFilesAndUpdateDb(manifest, location, destPath) {
|
|
40870
|
+
try {
|
|
40871
|
+
await fs_extra_1.default.move(location, destPath, {
|
|
40872
|
+
overwrite: false
|
|
40873
|
+
});
|
|
40874
|
+
await fs_extra_1.default.chmod(destPath, "755");
|
|
40875
|
+
} catch (e) {
|
|
40876
|
+
fs_extra_1.default.rm(location, { force: true, recursive: true });
|
|
40877
|
+
throw e;
|
|
40878
|
+
}
|
|
40879
|
+
try {
|
|
40880
|
+
await this.addComponentVersion(manifest);
|
|
40881
|
+
} catch (e) {
|
|
40882
|
+
fs_extra_1.default.rm(destPath, { force: true, recursive: true });
|
|
40883
|
+
throw e;
|
|
40884
|
+
}
|
|
40885
|
+
}
|
|
40886
|
+
async addComponentVersion(manifest) {
|
|
40887
|
+
if (await this.db.repositories.component.componentExists(manifest.name) === false) {
|
|
40888
|
+
await this.db.repositories.component.addComponent(manifest.name);
|
|
40889
|
+
}
|
|
40890
|
+
await this.db.repositories.componentVersion.addComponentVersion(manifest.name, manifest.version);
|
|
40891
|
+
}
|
|
40892
|
+
async getValidComponentDestinationPath(manifest) {
|
|
40893
|
+
const destPath = path_1.default.join(this.dataMountPoint, manifest.name, manifest.version);
|
|
40894
|
+
const pathExists = await fs_extra_1.default.pathExists(destPath);
|
|
40895
|
+
if (pathExists) {
|
|
40896
|
+
throw new error_1.BadRequestError(`${manifest.name} version ${manifest.version} already exists and cannot be uploaded`);
|
|
40897
|
+
}
|
|
40898
|
+
return destPath;
|
|
40899
|
+
}
|
|
40900
|
+
assertManifestIsValid(manifest) {
|
|
40901
|
+
const manifestValidationResult = (0, validateManifest_1.validateManifest)(manifest);
|
|
40902
|
+
if (manifestValidationResult.isValid == false) {
|
|
40903
|
+
throw new error_1.BadRequestError(`uploaded manifest is invalid, "${manifestValidationResult.message}"`);
|
|
40904
|
+
}
|
|
40905
|
+
}
|
|
40906
|
+
async readManifest(location) {
|
|
40907
|
+
const manifest = await fs_extra_1.default.readJson(path_1.default.join(location, "manifest.json"), { encoding: "utf-8" });
|
|
40908
|
+
return manifest;
|
|
40909
|
+
}
|
|
40910
|
+
};
|
|
40911
|
+
exports.ComponentService = ComponentService;
|
|
40912
|
+
}
|
|
40913
|
+
});
|
|
40914
|
+
|
|
40915
|
+
// ../component-lib/lib/component-service/services/ComponentSetService.js
|
|
40916
|
+
var require_ComponentSetService = __commonJS({
|
|
40917
|
+
"../component-lib/lib/component-service/services/ComponentSetService.js"(exports) {
|
|
40918
|
+
"use strict";
|
|
40919
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40920
|
+
exports.ComponentSetService = void 0;
|
|
40921
|
+
var error_1 = require_error();
|
|
40922
|
+
var ComponentSetService = class {
|
|
40923
|
+
constructor(db, logger) {
|
|
40924
|
+
this.db = db;
|
|
40925
|
+
this.logger = logger;
|
|
40926
|
+
}
|
|
40927
|
+
async addComponentSet(componentSet) {
|
|
40928
|
+
await this.assertValidCreateComponentSet(componentSet);
|
|
40929
|
+
try {
|
|
40930
|
+
const createdSet = await this.db.executeInTransaction(async (client) => {
|
|
40931
|
+
const set = await this.db.repositories.componentSet.create({
|
|
40932
|
+
webPath: componentSet.webPath,
|
|
40933
|
+
displayName: componentSet.displayName,
|
|
40934
|
+
description: componentSet.description,
|
|
40935
|
+
envVars: componentSet.envVars,
|
|
40936
|
+
headers: componentSet.headers
|
|
40937
|
+
}, client);
|
|
40938
|
+
await this.saveComponentSetComponets(componentSet.webPath, componentSet.components, client);
|
|
40939
|
+
return set;
|
|
40940
|
+
});
|
|
40941
|
+
const savedSet = await this.getComponentSet(createdSet.webPath);
|
|
40942
|
+
return savedSet;
|
|
40943
|
+
} catch (e) {
|
|
40944
|
+
this.logger.error(`Error occurred when updating component set ${componentSet.webPath}: ${e}`);
|
|
40945
|
+
throw e;
|
|
40946
|
+
}
|
|
40947
|
+
}
|
|
40948
|
+
async updateComponentSet(webPath, data) {
|
|
40949
|
+
const existing = await this.db.repositories.componentSet.getComponentSetByWebPath(webPath);
|
|
40950
|
+
if (!existing) {
|
|
40951
|
+
throw new error_1.ResourceNotFoundError(`Component set with web path ${webPath} does not exist`);
|
|
40952
|
+
}
|
|
40953
|
+
await this.assertValidComponentSet(data, this.normalise(existing, await this.getExistingComponents(webPath)));
|
|
40954
|
+
const values = {};
|
|
40955
|
+
if (data.displayName !== void 0) {
|
|
40956
|
+
values.displayName = data.displayName;
|
|
40957
|
+
}
|
|
40958
|
+
if (data.description !== void 0) {
|
|
40959
|
+
values.description = data.description;
|
|
40960
|
+
}
|
|
40961
|
+
if (data.headers !== void 0) {
|
|
40962
|
+
values.headers = data.headers;
|
|
40963
|
+
}
|
|
40964
|
+
if (data.envVars !== void 0) {
|
|
40965
|
+
values.envVars = data.envVars;
|
|
40966
|
+
}
|
|
40967
|
+
try {
|
|
40968
|
+
await this.db.executeInTransaction(async (client) => {
|
|
40969
|
+
if (Object.keys(values).length > 0) {
|
|
40970
|
+
await this.db.repositories.componentSet.update({ webPath }, values, client);
|
|
40971
|
+
}
|
|
40972
|
+
if (data.components !== void 0) {
|
|
40973
|
+
await this.saveComponentSetComponets(webPath, data.components, client);
|
|
40974
|
+
}
|
|
40975
|
+
});
|
|
40976
|
+
return this.getComponentSet(webPath);
|
|
40977
|
+
} catch (e) {
|
|
40978
|
+
this.logger.error(`Error occurred when updating component set ${webPath}: ${e}`);
|
|
40979
|
+
throw e;
|
|
40980
|
+
}
|
|
40981
|
+
}
|
|
40982
|
+
async getComponentSet(webPath) {
|
|
40983
|
+
const set = await this.db.repositories.componentSet.getComponentSetByWebPath(webPath);
|
|
40984
|
+
if (set === void 0) {
|
|
40985
|
+
throw new error_1.ResourceNotFoundError(`Component set with web path ${webPath} does not exist`);
|
|
40986
|
+
}
|
|
40987
|
+
return this.normalise(set, await this.getExistingComponents(webPath));
|
|
40988
|
+
}
|
|
40989
|
+
async deleteComponentSet(webPath) {
|
|
40990
|
+
if (!await this.db.repositories.componentSet.componentSetExists(webPath)) {
|
|
40991
|
+
throw new error_1.ResourceNotFoundError(`Component set with web path ${webPath} does not exist`);
|
|
40992
|
+
}
|
|
40993
|
+
return await this.db.repositories.componentSet.delete({ webPath });
|
|
40994
|
+
}
|
|
40995
|
+
normalise(set, components) {
|
|
40996
|
+
var _a, _b, _c, _d, _e;
|
|
40997
|
+
return {
|
|
40998
|
+
webPath: (_a = set.webPath) !== null && _a !== void 0 ? _a : "",
|
|
40999
|
+
displayName: (_b = set.displayName) !== null && _b !== void 0 ? _b : "",
|
|
41000
|
+
description: (_c = set.description) !== null && _c !== void 0 ? _c : "",
|
|
41001
|
+
envVars: (_d = set.envVars) !== null && _d !== void 0 ? _d : {},
|
|
41002
|
+
headers: (_e = set.headers) !== null && _e !== void 0 ? _e : {},
|
|
41003
|
+
components: components !== null && components !== void 0 ? components : {}
|
|
41004
|
+
};
|
|
41005
|
+
}
|
|
41006
|
+
async saveComponentSetComponets(webPath, components, client = null) {
|
|
41007
|
+
const existingComponents = [];
|
|
41008
|
+
Object.entries(await this.getExistingComponents(webPath)).forEach(([cn, cvs]) => {
|
|
41009
|
+
cvs.forEach((cv) => {
|
|
41010
|
+
existingComponents.push({ componentName: cn, info: cv });
|
|
41011
|
+
});
|
|
41012
|
+
});
|
|
41013
|
+
const inputComponents = [];
|
|
41014
|
+
Object.entries(components).forEach(([cn, cvs]) => {
|
|
41015
|
+
cvs.forEach((cv) => {
|
|
41016
|
+
inputComponents.push({ componentName: cn, info: cv });
|
|
41017
|
+
});
|
|
41018
|
+
});
|
|
41019
|
+
const toDelete = existingComponents.filter((ec) => !inputComponents.find((c) => ec.componentName === c.componentName && ec.info.version === c.info.version));
|
|
41020
|
+
const toCreate = inputComponents.filter((c) => !existingComponents.find((ec) => ec.componentName === c.componentName && ec.info.version === c.info.version));
|
|
41021
|
+
const toUpdate = inputComponents.filter((c) => existingComponents.find((ec) => ec.componentName === c.componentName && ec.info.version === c.info.version && JSON.stringify(ec.info.envVars) !== JSON.stringify(c.info.envVars)));
|
|
41022
|
+
const repo = this.db.repositories.componentSetComponentVersion;
|
|
41023
|
+
const toDeletePromises = toDelete.map((c) => repo.delete({
|
|
41024
|
+
componentSetWebPath: webPath,
|
|
41025
|
+
componentName: c.componentName,
|
|
41026
|
+
componentVersion: c.info.version
|
|
41027
|
+
}, client));
|
|
41028
|
+
const toCreatePromises = toCreate.map((c) => {
|
|
41029
|
+
var _a;
|
|
41030
|
+
return repo.create({
|
|
41031
|
+
componentSetWebPath: webPath,
|
|
41032
|
+
componentName: c.componentName,
|
|
41033
|
+
componentVersion: c.info.version,
|
|
41034
|
+
envVars: (_a = c.info.envVars) !== null && _a !== void 0 ? _a : {}
|
|
41035
|
+
}, client);
|
|
41036
|
+
});
|
|
41037
|
+
const toUpdatePromises = toUpdate.map((c) => {
|
|
41038
|
+
var _a;
|
|
41039
|
+
return repo.update({
|
|
41040
|
+
componentSetWebPath: webPath,
|
|
41041
|
+
componentName: c.componentName,
|
|
41042
|
+
componentVersion: c.info.version
|
|
41043
|
+
}, {
|
|
41044
|
+
envVars: (_a = c.info.envVars) !== null && _a !== void 0 ? _a : {}
|
|
41045
|
+
}, client);
|
|
41046
|
+
});
|
|
41047
|
+
await Promise.all([...toDeletePromises, ...toCreatePromises, ...toUpdatePromises]);
|
|
41048
|
+
}
|
|
41049
|
+
async getExistingComponents(webPath) {
|
|
41050
|
+
const dbEntries = await this.db.repositories.componentSetComponentVersion.find({ componentSetWebPath: webPath });
|
|
41051
|
+
const components = {};
|
|
41052
|
+
dbEntries.forEach((row) => {
|
|
41053
|
+
var _a;
|
|
41054
|
+
if (components[row.componentName] === void 0) {
|
|
41055
|
+
components[row.componentName] = [];
|
|
41056
|
+
}
|
|
41057
|
+
components[row.componentName].push({
|
|
41058
|
+
version: row.componentVersion,
|
|
41059
|
+
envVars: (_a = row.envVars) !== null && _a !== void 0 ? _a : {}
|
|
41060
|
+
});
|
|
41061
|
+
});
|
|
41062
|
+
Object.entries(components).forEach(([key, versions]) => {
|
|
41063
|
+
components[key] = versions.sort((a, b) => {
|
|
41064
|
+
if (a.version < b.version)
|
|
41065
|
+
return -1;
|
|
41066
|
+
if (a.version > b.version)
|
|
41067
|
+
return 1;
|
|
41068
|
+
return 0;
|
|
41069
|
+
});
|
|
41070
|
+
});
|
|
41071
|
+
return components;
|
|
41072
|
+
}
|
|
41073
|
+
async assertValidCreateComponentSet(componentSet) {
|
|
41074
|
+
if (!componentSet.webPath) {
|
|
41075
|
+
throw new error_1.BadRequestError("Component set 'webPath' must be specificed and non-empty");
|
|
41076
|
+
}
|
|
41077
|
+
if (!componentSet.displayName) {
|
|
41078
|
+
throw new error_1.BadRequestError("Component set 'displayName' must be specificed and non-empty");
|
|
41079
|
+
}
|
|
41080
|
+
this.assertValidWebPath(componentSet.webPath);
|
|
41081
|
+
if (await this.db.repositories.componentSet.componentSetExists(componentSet.webPath)) {
|
|
41082
|
+
throw new error_1.BadRequestError(`Component set with web path ${componentSet.webPath} already exists`);
|
|
41083
|
+
}
|
|
41084
|
+
await this.assertValidComponentSet(componentSet);
|
|
41085
|
+
}
|
|
41086
|
+
async assertValidComponentSet(componentSet, currentComponentSet = void 0) {
|
|
41087
|
+
var _a;
|
|
41088
|
+
if (componentSet.envVars !== void 0) {
|
|
41089
|
+
this.assertValidEnvVars(componentSet.envVars);
|
|
41090
|
+
}
|
|
41091
|
+
if (componentSet.headers !== void 0) {
|
|
41092
|
+
this.assertValidHeaders(componentSet.headers);
|
|
41093
|
+
}
|
|
41094
|
+
if (componentSet.components !== void 0) {
|
|
41095
|
+
const csEnvVars = (_a = componentSet.envVars) !== null && _a !== void 0 ? _a : currentComponentSet ? currentComponentSet.envVars : {};
|
|
41096
|
+
await this.assertValidComponents(componentSet.components, csEnvVars);
|
|
41097
|
+
}
|
|
41098
|
+
}
|
|
41099
|
+
assertValidWebPath(webPath) {
|
|
41100
|
+
if (webPath.replace(/[^a-z0-9\-_.]/i, "") !== webPath) {
|
|
41101
|
+
throw new error_1.BadRequestError("Invalid Component Set web path. Only [A-Za-z0-9_-.] chars are allowed");
|
|
41102
|
+
}
|
|
41103
|
+
}
|
|
41104
|
+
assertValidEnvVars(envVars) {
|
|
41105
|
+
Object.entries(envVars).forEach(([envVarName, envVarValue]) => {
|
|
41106
|
+
if (envVarName.replace(/[^a-z0-9\-_.]/i, "") !== envVarName) {
|
|
41107
|
+
throw new error_1.BadRequestError(`Invalid env var '${envVarName}'. Only [A-Za-z0-9_-.] chars are allowed`);
|
|
41108
|
+
}
|
|
41109
|
+
if (typeof envVarValue !== "string") {
|
|
41110
|
+
throw new error_1.BadRequestError(`Env var '${envVarName}' value must be a string`);
|
|
41111
|
+
}
|
|
41112
|
+
});
|
|
41113
|
+
}
|
|
41114
|
+
assertValidHeaders(_headers) {
|
|
41115
|
+
}
|
|
41116
|
+
async assertValidComponents(components, componentSetEnvVars) {
|
|
41117
|
+
const repo = this.db.repositories.componentVersion;
|
|
41118
|
+
for (const [componentName, versions] of Object.entries(components)) {
|
|
41119
|
+
if (!componentName) {
|
|
41120
|
+
throw new error_1.BadRequestError(`Component name must be non-empty`);
|
|
41121
|
+
}
|
|
41122
|
+
const setVersions = [];
|
|
41123
|
+
for (const v of versions) {
|
|
41124
|
+
if (!v.version) {
|
|
41125
|
+
throw new error_1.BadRequestError(`Component version must set and be non-empty`);
|
|
41126
|
+
}
|
|
41127
|
+
if (setVersions.includes(v.version)) {
|
|
41128
|
+
throw new error_1.BadRequestError(`Multiple componet version entries for component ${componentName} with version ${v.version}`);
|
|
41129
|
+
}
|
|
41130
|
+
setVersions.push(v.version);
|
|
41131
|
+
if (v.envVars !== void 0) {
|
|
41132
|
+
this.assertValidEnvVars(v.envVars);
|
|
41133
|
+
const unknownEnvVars = Object.keys(v.envVars).filter((ev) => !Object.keys(componentSetEnvVars).includes(ev));
|
|
41134
|
+
if (unknownEnvVars.length) {
|
|
41135
|
+
throw new error_1.BadRequestError(`Env var(s) '${unknownEnvVars.join("', '")}' defined on component ${componentName} with version ${v.version} is/are not defined on the component set`);
|
|
41136
|
+
}
|
|
41137
|
+
}
|
|
41138
|
+
if (!await repo.componentVersionExists(componentName, v.version)) {
|
|
41139
|
+
throw new error_1.BadRequestError(`Component ${componentName} with version ${v.version} does not exists`);
|
|
41140
|
+
}
|
|
41141
|
+
}
|
|
41142
|
+
}
|
|
41143
|
+
}
|
|
41144
|
+
async getAllComponentSets() {
|
|
41145
|
+
const rows = await this.db.repositories.componentSet.findAll();
|
|
41146
|
+
const componentSets = [];
|
|
41147
|
+
for (const row of rows) {
|
|
41148
|
+
const components = await this.getExistingComponents(row.webPath);
|
|
41149
|
+
componentSets.push(this.normalise(row, components));
|
|
41150
|
+
}
|
|
41151
|
+
return componentSets;
|
|
41152
|
+
}
|
|
41153
|
+
};
|
|
41154
|
+
exports.ComponentSetService = ComponentSetService;
|
|
41155
|
+
}
|
|
41156
|
+
});
|
|
41157
|
+
|
|
41158
|
+
// ../component-lib/lib/component-service/services/index.js
|
|
41159
|
+
var require_services = __commonJS({
|
|
41160
|
+
"../component-lib/lib/component-service/services/index.js"(exports) {
|
|
41161
|
+
"use strict";
|
|
41162
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
41163
|
+
if (k2 === void 0)
|
|
41164
|
+
k2 = k;
|
|
41165
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
41166
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
41167
|
+
desc = { enumerable: true, get: function() {
|
|
41168
|
+
return m[k];
|
|
41169
|
+
} };
|
|
41170
|
+
}
|
|
41171
|
+
Object.defineProperty(o, k2, desc);
|
|
41172
|
+
} : function(o, m, k, k2) {
|
|
41173
|
+
if (k2 === void 0)
|
|
41174
|
+
k2 = k;
|
|
41175
|
+
o[k2] = m[k];
|
|
41176
|
+
});
|
|
41177
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
41178
|
+
for (var p in m)
|
|
41179
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
41180
|
+
__createBinding(exports2, m, p);
|
|
41181
|
+
};
|
|
41182
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41183
|
+
__exportStar(require_ComponentService(), exports);
|
|
41184
|
+
__exportStar(require_ComponentSetService(), exports);
|
|
41185
|
+
}
|
|
41186
|
+
});
|
|
41187
|
+
|
|
40707
41188
|
// ../component-lib/lib/index.js
|
|
40708
41189
|
var require_lib6 = __commonJS({
|
|
40709
41190
|
"../component-lib/lib/index.js"(exports) {
|
|
@@ -40729,7 +41210,7 @@ var require_lib6 = __commonJS({
|
|
|
40729
41210
|
__createBinding(exports2, m, p);
|
|
40730
41211
|
};
|
|
40731
41212
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40732
|
-
exports.transformResponseForLogging = exports.transformRequestForLogging = exports.errorMiddleware = exports.schemaVersions = void 0;
|
|
41213
|
+
exports.ComponentSetService = exports.ComponentService = exports.transformResponseForLogging = exports.transformRequestForLogging = exports.errorMiddleware = exports.schemaVersions = void 0;
|
|
40733
41214
|
__exportStar(require_validateManifest(), exports);
|
|
40734
41215
|
var schemas_1 = require_schemas();
|
|
40735
41216
|
Object.defineProperty(exports, "schemaVersions", { enumerable: true, get: function() {
|
|
@@ -40762,6 +41243,13 @@ var require_lib6 = __commonJS({
|
|
|
40762
41243
|
__exportStar(require_parseEnvVarForVar(), exports);
|
|
40763
41244
|
__exportStar(require_getNodeEnv(), exports);
|
|
40764
41245
|
__exportStar(require_isPathTryingToAccessOutsideOfRoot(), exports);
|
|
41246
|
+
var services_1 = require_services();
|
|
41247
|
+
Object.defineProperty(exports, "ComponentService", { enumerable: true, get: function() {
|
|
41248
|
+
return services_1.ComponentService;
|
|
41249
|
+
} });
|
|
41250
|
+
Object.defineProperty(exports, "ComponentSetService", { enumerable: true, get: function() {
|
|
41251
|
+
return services_1.ComponentSetService;
|
|
41252
|
+
} });
|
|
40765
41253
|
}
|
|
40766
41254
|
});
|
|
40767
41255
|
|