@squiz/edge-dev-render-runtime-lib 2.1.0 → 2.2.0
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/ComponentRunnerService.d.ts +14 -0
- package/lib/component-runner/index.d.ts +1 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js +320 -653
- package/lib/index.js.map +4 -4
- package/lib/ioc.d.ts +2 -2
- package/lib/public/docs.json +11 -261
- package/lib/webserver/controllers/DevelopmentController.d.ts +61 -0
- package/package.json +10 -10
- package/lib/component-runner/ComponentRunnerServiceWithWorkers.d.ts +0 -10
- package/lib/webserver/controllers/DefinitionController.d.ts +0 -19
- package/lib/webserver/controllers/DefinitionController.spec.d.ts +0 -1
- package/lib/webserver/controllers/RenderController.d.ts +0 -22
- package/lib/webserver/controllers/test/definition-route-tests.d.ts +0 -2
package/lib/index.js
CHANGED
|
@@ -40,7 +40,7 @@ var __decorateParam = (index, decorator) => (target, key) => decorator(target, k
|
|
|
40
40
|
var src_exports = {};
|
|
41
41
|
__export(src_exports, {
|
|
42
42
|
ComponentPreviewService: () => ComponentPreviewService,
|
|
43
|
-
|
|
43
|
+
DevelopmentComponentRunnerService: () => DevelopmentComponentRunnerService,
|
|
44
44
|
PREVIEW_COMPONENT_SET: () => PREVIEW_COMPONENT_SET,
|
|
45
45
|
RenderInputService: () => RenderInputService,
|
|
46
46
|
TestHelpers: () => test_exports,
|
|
@@ -75,10 +75,10 @@ var import_cors = __toESM(require("cors"));
|
|
|
75
75
|
var import_compression = __toESM(require("compression"));
|
|
76
76
|
var import_crypto = require("crypto");
|
|
77
77
|
var import_helmet = __toESM(require("helmet"));
|
|
78
|
-
var
|
|
78
|
+
var import_dx_common_lib3 = require("@squiz/dx-common-lib");
|
|
79
79
|
|
|
80
80
|
// src/webserver/routes/routes.ts
|
|
81
|
-
var
|
|
81
|
+
var import_runtime3 = require("@tsoa/runtime");
|
|
82
82
|
|
|
83
83
|
// src/webserver/controllers/CoreController.ts
|
|
84
84
|
var import_tsoa2 = require("tsoa");
|
|
@@ -96,10 +96,10 @@ var import_dx_json_schema_lib = require("@squiz/dx-json-schema-lib");
|
|
|
96
96
|
|
|
97
97
|
// src/utils/getComponentInfoFromComponentId.ts
|
|
98
98
|
var SEPARATOR = "__";
|
|
99
|
-
function getComponentInfoFromComponentId(
|
|
100
|
-
const parts =
|
|
99
|
+
function getComponentInfoFromComponentId(path6) {
|
|
100
|
+
const parts = path6.split(SEPARATOR);
|
|
101
101
|
if (parts.length !== 3) {
|
|
102
|
-
throw Error(`Invalid component identifier path: ${
|
|
102
|
+
throw Error(`Invalid component identifier path: ${path6}`);
|
|
103
103
|
}
|
|
104
104
|
return {
|
|
105
105
|
namespace: parts[0],
|
|
@@ -127,7 +127,7 @@ var CoreController = class extends BaseController {
|
|
|
127
127
|
async getComponents(req) {
|
|
128
128
|
const res = req.res;
|
|
129
129
|
const components = await this.manifestService.listAllComponentManifests();
|
|
130
|
-
const groupedComponents = this.createComponentMap(components
|
|
130
|
+
const groupedComponents = this.createComponentMap(components);
|
|
131
131
|
const returnHtml = this.createComponentMapHtml(groupedComponents);
|
|
132
132
|
res.send(returnHtml);
|
|
133
133
|
}
|
|
@@ -182,10 +182,11 @@ CoreController = __decorateClass([
|
|
|
182
182
|
__decorateParam(0, (0, import_inversify.inject)("ManifestService"))
|
|
183
183
|
], CoreController);
|
|
184
184
|
|
|
185
|
-
// src/webserver/controllers/
|
|
185
|
+
// src/webserver/controllers/DevelopmentController.ts
|
|
186
186
|
var import_tsoa3 = require("tsoa");
|
|
187
|
-
var import_inversify2 = require("inversify");
|
|
188
187
|
var import_inversify_binding_decorators2 = require("inversify-binding-decorators");
|
|
188
|
+
var import_inversify2 = require("inversify");
|
|
189
|
+
var import_component_lib = require("@squiz/component-lib");
|
|
189
190
|
var import_dx_common_lib2 = require("@squiz/dx-common-lib");
|
|
190
191
|
|
|
191
192
|
// src/utils/setHeadersOnExpressResponse.ts
|
|
@@ -199,179 +200,92 @@ function setHeadersOnExpressResponse(headers, response) {
|
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
|
|
202
|
-
// src/webserver/controllers/
|
|
203
|
-
var
|
|
204
|
-
|
|
203
|
+
// src/webserver/controllers/DevelopmentController.ts
|
|
204
|
+
var import_query_string = require("query-string");
|
|
205
|
+
var UPPERCASE_REGEX = /[A-Z]/;
|
|
206
|
+
var DevelopmentController = class extends import_tsoa3.Controller {
|
|
207
|
+
constructor(config, manifestService, componentRunnerService, renderInputService, componentPreviewService, componentFunctionService) {
|
|
205
208
|
super();
|
|
206
|
-
this.
|
|
209
|
+
this.config = config;
|
|
207
210
|
this.manifestService = manifestService;
|
|
211
|
+
this.componentRunnerService = componentRunnerService;
|
|
212
|
+
this.renderInputService = renderInputService;
|
|
213
|
+
this.componentPreviewService = componentPreviewService;
|
|
208
214
|
this.componentFunctionService = componentFunctionService;
|
|
209
|
-
this.componentRootUrlResolver = componentRootUrlResolver;
|
|
210
215
|
}
|
|
211
|
-
async
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
async getComponents() {
|
|
217
|
+
this.checkDevMode();
|
|
218
|
+
const components = await this.manifestService.listAllComponentManifests();
|
|
219
|
+
return components.map((component) => component.getModel());
|
|
220
|
+
}
|
|
221
|
+
async Manifest(componentId) {
|
|
222
|
+
this.checkDevMode();
|
|
216
223
|
const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
|
|
217
224
|
const manifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
218
|
-
if (_previewKey !== void 0) {
|
|
219
|
-
return this.componentFunctionService.prepareManifestForPreview(manifest, _previewKey, rootUrl);
|
|
220
|
-
}
|
|
221
|
-
if (_componentSet !== void 0) {
|
|
222
|
-
await this.setHeadersFromComponentSet(manifest, _componentSet, response);
|
|
223
|
-
return this.componentFunctionService.prepareManifestForWebResponse(manifest, _componentSet, rootUrl);
|
|
224
|
-
}
|
|
225
225
|
return manifest.getModel();
|
|
226
226
|
}
|
|
227
|
-
async
|
|
228
|
-
|
|
229
|
-
(0, import_dx_common_lib2.assertIsDefined)(response);
|
|
230
|
-
this.assertValidQueryParametersForDefinition(_previewKey, _componentSet);
|
|
231
|
-
const rootUrl = this.componentRootUrlResolver(request);
|
|
227
|
+
async getContentSchema(componentId) {
|
|
228
|
+
this.checkDevMode();
|
|
232
229
|
const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
if (_previewKey !== void 0) {
|
|
245
|
-
this.setHeadersFromPreview(manifest, _previewKey, manifestModel.mainFunction, response);
|
|
246
|
-
return this.componentFunctionService.prepareComponentFunctionForPreview(result, manifest, _previewKey, rootUrl);
|
|
247
|
-
}
|
|
248
|
-
if (_componentSet !== void 0) {
|
|
249
|
-
await this.setHeadersFromComponentSet(manifest, _componentSet, response);
|
|
250
|
-
return this.componentFunctionService.prepareComponentFunctionForWebResponse(
|
|
251
|
-
result,
|
|
252
|
-
manifest,
|
|
253
|
-
_componentSet,
|
|
254
|
-
rootUrl
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
return result;
|
|
230
|
+
const componentManifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
231
|
+
const inputSchemas = componentManifest.getInputSchemas();
|
|
232
|
+
const schemaResult = [];
|
|
233
|
+
inputSchemas.forEach((inputSchema) => {
|
|
234
|
+
if (inputSchema.schema && Object.keys(inputSchema.schema).length) {
|
|
235
|
+
schemaResult.push(inputSchema);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return schemaResult;
|
|
258
239
|
}
|
|
259
|
-
async
|
|
260
|
-
|
|
261
|
-
(0, import_dx_common_lib2.assertIsDefined)(response);
|
|
262
|
-
this.assertValidQueryParametersForDefinition(_previewKey, _componentSet);
|
|
263
|
-
const rootUrl = this.componentRootUrlResolver(request);
|
|
240
|
+
async TemporaryPreview(req, componentId, functionName, headers, envVars, data) {
|
|
241
|
+
this.checkDevMode();
|
|
264
242
|
const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
_previewKey,
|
|
298
|
-
manifest.getComponentFunctionByName(functionName)
|
|
299
|
-
);
|
|
300
|
-
this.setHeaders(previewConfig?.headers || {}, response);
|
|
301
|
-
}
|
|
302
|
-
setHeaders(headers, response) {
|
|
303
|
-
setHeadersOnExpressResponse(headers, response);
|
|
304
|
-
let cacheControl = response.getHeader("cache-control");
|
|
305
|
-
if (typeof cacheControl !== "string") {
|
|
306
|
-
cacheControl = void 0;
|
|
307
|
-
}
|
|
308
|
-
response.setHeader("cache-control", (0, import_dx_common_lib2.parseAndSanitiseCacheControlHeader)(cacheControl));
|
|
309
|
-
}
|
|
310
|
-
assertValidQueryParametersForDefinition(_previewKey, _componentSet) {
|
|
311
|
-
if (_previewKey !== void 0 && _componentSet !== void 0) {
|
|
312
|
-
throw new import_dx_common_lib2.BadRequestError("You can not have both a _componentSet and _previewKey");
|
|
243
|
+
const res = req.res;
|
|
244
|
+
const componentSet = {
|
|
245
|
+
environment: envVars ?? {},
|
|
246
|
+
displayName: componentName,
|
|
247
|
+
webPath: "mock-set"
|
|
248
|
+
};
|
|
249
|
+
const rootUrl = `http://${req.headers.host}`.replace(/\/+$/, "");
|
|
250
|
+
const componentManifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
251
|
+
const componentFunction = componentManifest.getComponentFunctionByName(functionName);
|
|
252
|
+
const componentTask = {
|
|
253
|
+
requestId: Date.now().toString(),
|
|
254
|
+
args: [data],
|
|
255
|
+
functionEntryFilePath: await componentManifest.getComponentFunctionEntryFilePath(componentFunction),
|
|
256
|
+
environment: componentSet.environment,
|
|
257
|
+
componentFullName: componentName,
|
|
258
|
+
componentFunction,
|
|
259
|
+
componentRootUrl: rootUrl,
|
|
260
|
+
manifest: componentManifest.getModel(),
|
|
261
|
+
runtimeSet: componentSet,
|
|
262
|
+
manifestPath: await componentManifest.getManifestPath(),
|
|
263
|
+
previewKey: void 0,
|
|
264
|
+
queryParameters: void 0
|
|
265
|
+
};
|
|
266
|
+
const result = componentManifest.type === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(componentTask) : await this.componentRunnerService.executeServerComponentFunction(componentTask);
|
|
267
|
+
const responseHeaders = headers ?? {};
|
|
268
|
+
switch (componentFunction.output.responseType) {
|
|
269
|
+
case "html":
|
|
270
|
+
responseHeaders["content-type"] = "text/html";
|
|
271
|
+
break;
|
|
272
|
+
case "json":
|
|
273
|
+
responseHeaders["content-type"] = "application/json";
|
|
274
|
+
break;
|
|
313
275
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
__decorateClass([
|
|
317
|
-
(0, import_tsoa3.Get)("/:componentId/manifest.json"),
|
|
318
|
-
__decorateParam(0, (0, import_tsoa3.Path)()),
|
|
319
|
-
__decorateParam(1, (0, import_tsoa3.Request)()),
|
|
320
|
-
__decorateParam(2, (0, import_tsoa3.Query)()),
|
|
321
|
-
__decorateParam(3, (0, import_tsoa3.Query)())
|
|
322
|
-
], DefinitionController.prototype, "getComponentVersionManifest", 1);
|
|
323
|
-
__decorateClass([
|
|
324
|
-
(0, import_tsoa3.Get)("/:componentId"),
|
|
325
|
-
__decorateParam(0, (0, import_tsoa3.Path)()),
|
|
326
|
-
__decorateParam(1, (0, import_tsoa3.Request)()),
|
|
327
|
-
__decorateParam(2, (0, import_tsoa3.Query)()),
|
|
328
|
-
__decorateParam(3, (0, import_tsoa3.Query)())
|
|
329
|
-
], DefinitionController.prototype, "getDefaultFunctionDefinition", 1);
|
|
330
|
-
__decorateClass([
|
|
331
|
-
(0, import_tsoa3.Get)("/:componentId/:functionName"),
|
|
332
|
-
__decorateParam(0, (0, import_tsoa3.Path)()),
|
|
333
|
-
__decorateParam(1, (0, import_tsoa3.Path)()),
|
|
334
|
-
__decorateParam(2, (0, import_tsoa3.Request)()),
|
|
335
|
-
__decorateParam(3, (0, import_tsoa3.Query)()),
|
|
336
|
-
__decorateParam(4, (0, import_tsoa3.Query)())
|
|
337
|
-
], DefinitionController.prototype, "getGivenFunctionDefinition", 1);
|
|
338
|
-
DefinitionController = __decorateClass([
|
|
339
|
-
(0, import_inversify_binding_decorators2.provide)(DefinitionController),
|
|
340
|
-
(0, import_tsoa3.Route)("/d"),
|
|
341
|
-
__decorateParam(0, (0, import_inversify2.inject)("ComponentSetService")),
|
|
342
|
-
__decorateParam(1, (0, import_inversify2.inject)("ManifestService")),
|
|
343
|
-
__decorateParam(2, (0, import_inversify2.inject)("ComponentFunctionService")),
|
|
344
|
-
__decorateParam(3, (0, import_inversify2.inject)("ComponentRootUrlResolver"))
|
|
345
|
-
], DefinitionController);
|
|
346
|
-
|
|
347
|
-
// src/webserver/controllers/RenderController.ts
|
|
348
|
-
var import_tsoa4 = require("tsoa");
|
|
349
|
-
var import_inversify_binding_decorators3 = require("inversify-binding-decorators");
|
|
350
|
-
var import_inversify3 = require("inversify");
|
|
351
|
-
var import_query_string = require("query-string");
|
|
352
|
-
var import_component_lib = require("@squiz/component-lib");
|
|
353
|
-
var import_dx_common_lib3 = require("@squiz/dx-common-lib");
|
|
354
|
-
var UPPERCASE_REGEX = /[A-Z]/;
|
|
355
|
-
var RenderController = class extends BaseController {
|
|
356
|
-
constructor(componentSetService, manifestService, componentFunctionService, componentRunnerService, renderInputService, componentPreviewService) {
|
|
357
|
-
super();
|
|
358
|
-
this.componentSetService = componentSetService;
|
|
359
|
-
this.manifestService = manifestService;
|
|
360
|
-
this.componentFunctionService = componentFunctionService;
|
|
361
|
-
this.componentRunnerService = componentRunnerService;
|
|
362
|
-
this.renderInputService = renderInputService;
|
|
363
|
-
this.componentPreviewService = componentPreviewService;
|
|
276
|
+
setHeadersOnExpressResponse(responseHeaders ?? {}, res);
|
|
277
|
+
res.send(result);
|
|
364
278
|
}
|
|
365
279
|
async getDefaultFunctionRendering(expressRequest, componentId, componentSet, previewKey) {
|
|
366
280
|
await this.getGivenFunctionRendering(expressRequest, componentId, "", componentSet, previewKey);
|
|
367
281
|
}
|
|
368
282
|
async getGivenFunctionRendering(expressRequest, componentId, functionName, componentSet, previewKey) {
|
|
369
283
|
const response = expressRequest.res;
|
|
370
|
-
(0,
|
|
371
|
-
const { path:
|
|
372
|
-
if (UPPERCASE_REGEX.test(
|
|
284
|
+
(0, import_dx_common_lib2.assertIsDefined)(response);
|
|
285
|
+
const { path: path6, query } = expressRequest;
|
|
286
|
+
if (UPPERCASE_REGEX.test(path6) || componentSet && UPPERCASE_REGEX.test(componentSet)) {
|
|
373
287
|
const url = (0, import_query_string.stringifyUrl)({
|
|
374
|
-
url:
|
|
288
|
+
url: path6.toLowerCase(),
|
|
375
289
|
query: {
|
|
376
290
|
...query,
|
|
377
291
|
_componentSet: componentSet?.toLowerCase()
|
|
@@ -398,7 +312,7 @@ var RenderController = class extends BaseController {
|
|
|
398
312
|
response.send(output);
|
|
399
313
|
}
|
|
400
314
|
async doFunctionRender(renderInput) {
|
|
401
|
-
let result = await this.renderAndValidateOutput(renderInput);
|
|
315
|
+
let result = await this.renderAndValidateOutput(renderInput, renderInput.manifest.type ?? "server");
|
|
402
316
|
if (renderInput.previewKey !== void 0) {
|
|
403
317
|
result = await this.componentPreviewService.dressRenderedOutputForPreview(
|
|
404
318
|
renderInput.manifest,
|
|
@@ -409,21 +323,14 @@ var RenderController = class extends BaseController {
|
|
|
409
323
|
}
|
|
410
324
|
return result;
|
|
411
325
|
}
|
|
412
|
-
async renderAndValidateOutput(renderInput) {
|
|
413
|
-
const
|
|
414
|
-
|
|
326
|
+
async renderAndValidateOutput(renderInput, componentType) {
|
|
327
|
+
const executeComponentTask = {
|
|
328
|
+
...renderInput,
|
|
415
329
|
args: [renderInput.input],
|
|
416
|
-
functionEntryFilePath: renderInput.functionEntryFilePath,
|
|
417
|
-
environment: renderInput.runtimeSet.environment,
|
|
418
|
-
componentFullName: renderInput.componentFullName,
|
|
419
|
-
componentFunction: renderInput.componentFunction,
|
|
420
|
-
componentRootUrl: renderInput.componentRootUrl,
|
|
421
330
|
manifest: renderInput.manifestForWeb,
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
queryParameters: renderInput.queryParameters
|
|
426
|
-
});
|
|
331
|
+
environment: renderInput.runtimeSet.environment
|
|
332
|
+
};
|
|
333
|
+
const result = componentType === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(executeComponentTask) : await this.componentRunnerService.executeServerComponentFunction(executeComponentTask);
|
|
427
334
|
try {
|
|
428
335
|
this.componentFunctionService.assertOutputValidForComponentFunction(result, renderInput.componentFunction);
|
|
429
336
|
} catch (e) {
|
|
@@ -454,47 +361,75 @@ var RenderController = class extends BaseController {
|
|
|
454
361
|
if (typeof cacheControl !== "string") {
|
|
455
362
|
cacheControl = void 0;
|
|
456
363
|
}
|
|
457
|
-
response.setHeader("cache-control", (0,
|
|
364
|
+
response.setHeader("cache-control", (0, import_dx_common_lib2.parseAndSanitiseCacheControlHeader)(cacheControl));
|
|
365
|
+
}
|
|
366
|
+
//This should be middle ware.
|
|
367
|
+
async checkDevMode() {
|
|
368
|
+
if (!this.config.enableDevMode) {
|
|
369
|
+
throw new import_dx_common_lib2.ResourceNotFoundError("Route does not exist.");
|
|
370
|
+
}
|
|
458
371
|
}
|
|
459
372
|
};
|
|
460
373
|
__decorateClass([
|
|
461
|
-
(0,
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
__decorateParam(
|
|
466
|
-
],
|
|
374
|
+
(0, import_tsoa3.Get)("/all")
|
|
375
|
+
], DevelopmentController.prototype, "getComponents", 1);
|
|
376
|
+
__decorateClass([
|
|
377
|
+
(0, import_tsoa3.Get)("/manifest/:componentId"),
|
|
378
|
+
__decorateParam(0, (0, import_tsoa3.Path)())
|
|
379
|
+
], DevelopmentController.prototype, "Manifest", 1);
|
|
380
|
+
__decorateClass([
|
|
381
|
+
(0, import_tsoa3.Get)("/schemas/:componentId"),
|
|
382
|
+
__decorateParam(0, (0, import_tsoa3.Path)())
|
|
383
|
+
], DevelopmentController.prototype, "getContentSchema", 1);
|
|
384
|
+
__decorateClass([
|
|
385
|
+
(0, import_tsoa3.Get)("/temp-preview/:componentId/:functionName"),
|
|
386
|
+
(0, import_tsoa3.Produces)("text/html"),
|
|
387
|
+
__decorateParam(0, (0, import_tsoa3.Request)()),
|
|
388
|
+
__decorateParam(1, (0, import_tsoa3.Path)()),
|
|
389
|
+
__decorateParam(2, (0, import_tsoa3.Path)()),
|
|
390
|
+
__decorateParam(3, (0, import_tsoa3.Query)()),
|
|
391
|
+
__decorateParam(4, (0, import_tsoa3.Query)()),
|
|
392
|
+
__decorateParam(5, (0, import_tsoa3.Query)())
|
|
393
|
+
], DevelopmentController.prototype, "TemporaryPreview", 1);
|
|
467
394
|
__decorateClass([
|
|
468
|
-
(0,
|
|
469
|
-
__decorateParam(0, (0,
|
|
470
|
-
__decorateParam(1, (0,
|
|
471
|
-
__decorateParam(2, (0,
|
|
472
|
-
__decorateParam(3, (0,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
(0,
|
|
477
|
-
(0,
|
|
478
|
-
__decorateParam(
|
|
479
|
-
__decorateParam(
|
|
480
|
-
__decorateParam(
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
395
|
+
(0, import_tsoa3.Get)("/render/:componentId"),
|
|
396
|
+
__decorateParam(0, (0, import_tsoa3.Request)()),
|
|
397
|
+
__decorateParam(1, (0, import_tsoa3.Path)()),
|
|
398
|
+
__decorateParam(2, (0, import_tsoa3.Query)("_componentSet")),
|
|
399
|
+
__decorateParam(3, (0, import_tsoa3.Query)("_previewKey"))
|
|
400
|
+
], DevelopmentController.prototype, "getDefaultFunctionRendering", 1);
|
|
401
|
+
__decorateClass([
|
|
402
|
+
(0, import_tsoa3.Get)("/render/:componentId/:functionName"),
|
|
403
|
+
__decorateParam(0, (0, import_tsoa3.Request)()),
|
|
404
|
+
__decorateParam(1, (0, import_tsoa3.Path)()),
|
|
405
|
+
__decorateParam(2, (0, import_tsoa3.Path)()),
|
|
406
|
+
__decorateParam(3, (0, import_tsoa3.Query)("_componentSet")),
|
|
407
|
+
__decorateParam(4, (0, import_tsoa3.Query)("_previewKey"))
|
|
408
|
+
], DevelopmentController.prototype, "getGivenFunctionRendering", 1);
|
|
409
|
+
DevelopmentController = __decorateClass([
|
|
410
|
+
(0, import_inversify_binding_decorators2.provide)(DevelopmentController),
|
|
411
|
+
(0, import_tsoa3.Route)("/dev"),
|
|
412
|
+
(0, import_tsoa3.Hidden)(),
|
|
413
|
+
__decorateParam(0, (0, import_inversify2.inject)("Config")),
|
|
414
|
+
__decorateParam(1, (0, import_inversify2.inject)("ManifestService")),
|
|
415
|
+
__decorateParam(2, (0, import_inversify2.inject)("DevelopmentComponentRunnerService")),
|
|
416
|
+
__decorateParam(3, (0, import_inversify2.inject)("RenderInputService")),
|
|
417
|
+
__decorateParam(4, (0, import_inversify2.inject)("ComponentPreviewService")),
|
|
418
|
+
__decorateParam(5, (0, import_inversify2.inject)("ComponentFunctionService"))
|
|
419
|
+
], DevelopmentController);
|
|
485
420
|
|
|
486
421
|
// src/ioc.ts
|
|
487
|
-
var
|
|
488
|
-
var
|
|
489
|
-
(0,
|
|
422
|
+
var import_inversify3 = require("inversify");
|
|
423
|
+
var import_inversify_binding_decorators3 = require("inversify-binding-decorators");
|
|
424
|
+
(0, import_inversify3.decorate)((0, import_inversify3.injectable)(), BaseController);
|
|
490
425
|
var iocContainer;
|
|
491
426
|
var initIocContainer = (services, config) => {
|
|
492
|
-
const container = new
|
|
493
|
-
container.load((0,
|
|
427
|
+
const container = new import_inversify3.Container({ skipBaseClassChecks: true });
|
|
428
|
+
container.load((0, import_inversify_binding_decorators3.buildProviderModule)());
|
|
494
429
|
container.bind("Config").toConstantValue(config);
|
|
495
430
|
container.bind("Logger").toConstantValue(services.logger);
|
|
496
431
|
container.bind("ComponentFunctionService").toConstantValue(services.componentFunctionService);
|
|
497
|
-
container.bind("
|
|
432
|
+
container.bind("DevelopmentComponentRunnerService").toConstantValue(services.developmentComponentRunnerService);
|
|
498
433
|
container.bind("ComponentSetService").toConstantValue(services.componentSetService);
|
|
499
434
|
container.bind("ManifestService").toConstantValue(services.manifestService);
|
|
500
435
|
container.bind("RenderInputService").toConstantValue(services.renderInputService);
|
|
@@ -912,35 +847,23 @@ var models = {
|
|
|
912
847
|
"additionalProperties": false
|
|
913
848
|
},
|
|
914
849
|
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
915
|
-
"
|
|
850
|
+
"ComponentManifest": {
|
|
916
851
|
"dataType": "refAlias",
|
|
917
852
|
"type": { "ref": "MANIFEST_MODELS.v1.ComponentManifest", "validators": {} }
|
|
918
853
|
},
|
|
919
854
|
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
920
|
-
"
|
|
855
|
+
"ComponentSchema": {
|
|
921
856
|
"dataType": "refAlias",
|
|
922
|
-
"type": { "
|
|
923
|
-
},
|
|
924
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
925
|
-
"MANIFEST_MODELS.v1.ComponentFunction": {
|
|
926
|
-
"dataType": "refObject",
|
|
927
|
-
"properties": {
|
|
928
|
-
"name": { "dataType": "string", "required": true },
|
|
929
|
-
"entry": { "dataType": "string", "required": true },
|
|
930
|
-
"input": { "ref": "DxComponentInputSchema", "required": true },
|
|
931
|
-
"output": { "dataType": "union", "subSchemas": [{ "ref": "HtmlResponse" }, { "ref": "JsonResponse" }], "required": true },
|
|
932
|
-
"queryParameters": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "ref": "QueryParameterValueType" } }
|
|
933
|
-
},
|
|
934
|
-
"additionalProperties": { "dataType": "any" }
|
|
857
|
+
"type": { "dataType": "nestedObjectLiteral", "nestedProperties": { "schema": { "dataType": "object", "required": true }, "name": { "dataType": "string", "required": true } }, "validators": {} }
|
|
935
858
|
}
|
|
936
859
|
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
937
860
|
};
|
|
938
|
-
var validationService = new
|
|
861
|
+
var validationService = new import_runtime3.ValidationService(models);
|
|
939
862
|
function RegisterRoutes(app) {
|
|
940
863
|
app.get(
|
|
941
864
|
"/schemas/:version.json",
|
|
942
|
-
...(0,
|
|
943
|
-
...(0,
|
|
865
|
+
...(0, import_runtime3.fetchMiddlewares)(CoreController),
|
|
866
|
+
...(0, import_runtime3.fetchMiddlewares)(CoreController.prototype.getSchemaVersion),
|
|
944
867
|
async function CoreController_getSchemaVersion(request, response, next) {
|
|
945
868
|
const args = {
|
|
946
869
|
version: { "in": "path", "name": "version", "required": true, "dataType": "string" }
|
|
@@ -962,8 +885,8 @@ function RegisterRoutes(app) {
|
|
|
962
885
|
);
|
|
963
886
|
app.get(
|
|
964
887
|
"/",
|
|
965
|
-
...(0,
|
|
966
|
-
...(0,
|
|
888
|
+
...(0, import_runtime3.fetchMiddlewares)(CoreController),
|
|
889
|
+
...(0, import_runtime3.fetchMiddlewares)(CoreController.prototype.getComponents),
|
|
967
890
|
async function CoreController_getComponents(request, response, next) {
|
|
968
891
|
const args = {
|
|
969
892
|
req: { "in": "request", "name": "req", "required": true, "dataType": "object" }
|
|
@@ -984,25 +907,43 @@ function RegisterRoutes(app) {
|
|
|
984
907
|
}
|
|
985
908
|
);
|
|
986
909
|
app.get(
|
|
987
|
-
"/
|
|
988
|
-
...(0,
|
|
989
|
-
...(0,
|
|
990
|
-
async function
|
|
910
|
+
"/dev/all",
|
|
911
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController),
|
|
912
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController.prototype.getComponents),
|
|
913
|
+
async function DevelopmentController_getComponents(request, response, next) {
|
|
914
|
+
const args = {};
|
|
915
|
+
let validatedArgs = [];
|
|
916
|
+
try {
|
|
917
|
+
validatedArgs = getValidatedArgs(args, request, response);
|
|
918
|
+
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
919
|
+
const controller = await container.get(DevelopmentController);
|
|
920
|
+
if (typeof controller["setStatus"] === "function") {
|
|
921
|
+
controller.setStatus(void 0);
|
|
922
|
+
}
|
|
923
|
+
const promise = controller.getComponents.apply(controller, validatedArgs);
|
|
924
|
+
promiseHandler(controller, promise, response, void 0, next);
|
|
925
|
+
} catch (err) {
|
|
926
|
+
return next(err);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
app.get(
|
|
931
|
+
"/dev/manifest/:componentId",
|
|
932
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController),
|
|
933
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController.prototype.Manifest),
|
|
934
|
+
async function DevelopmentController_Manifest(request, response, next) {
|
|
991
935
|
const args = {
|
|
992
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
993
|
-
request: { "in": "request", "name": "request", "required": true, "dataType": "object" },
|
|
994
|
-
_previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
995
|
-
_componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" }
|
|
936
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
996
937
|
};
|
|
997
938
|
let validatedArgs = [];
|
|
998
939
|
try {
|
|
999
940
|
validatedArgs = getValidatedArgs(args, request, response);
|
|
1000
941
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
1001
|
-
const controller = await container.get(
|
|
942
|
+
const controller = await container.get(DevelopmentController);
|
|
1002
943
|
if (typeof controller["setStatus"] === "function") {
|
|
1003
944
|
controller.setStatus(void 0);
|
|
1004
945
|
}
|
|
1005
|
-
const promise = controller.
|
|
946
|
+
const promise = controller.Manifest.apply(controller, validatedArgs);
|
|
1006
947
|
promiseHandler(controller, promise, response, void 0, next);
|
|
1007
948
|
} catch (err) {
|
|
1008
949
|
return next(err);
|
|
@@ -1010,25 +951,22 @@ function RegisterRoutes(app) {
|
|
|
1010
951
|
}
|
|
1011
952
|
);
|
|
1012
953
|
app.get(
|
|
1013
|
-
"/
|
|
1014
|
-
...(0,
|
|
1015
|
-
...(0,
|
|
1016
|
-
async function
|
|
954
|
+
"/dev/schemas/:componentId",
|
|
955
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController),
|
|
956
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController.prototype.getContentSchema),
|
|
957
|
+
async function DevelopmentController_getContentSchema(request, response, next) {
|
|
1017
958
|
const args = {
|
|
1018
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
1019
|
-
request: { "in": "request", "name": "request", "required": true, "dataType": "object" },
|
|
1020
|
-
_previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
1021
|
-
_componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" }
|
|
959
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
1022
960
|
};
|
|
1023
961
|
let validatedArgs = [];
|
|
1024
962
|
try {
|
|
1025
963
|
validatedArgs = getValidatedArgs(args, request, response);
|
|
1026
964
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
1027
|
-
const controller = await container.get(
|
|
965
|
+
const controller = await container.get(DevelopmentController);
|
|
1028
966
|
if (typeof controller["setStatus"] === "function") {
|
|
1029
967
|
controller.setStatus(void 0);
|
|
1030
968
|
}
|
|
1031
|
-
const promise = controller.
|
|
969
|
+
const promise = controller.getContentSchema.apply(controller, validatedArgs);
|
|
1032
970
|
promiseHandler(controller, promise, response, void 0, next);
|
|
1033
971
|
} catch (err) {
|
|
1034
972
|
return next(err);
|
|
@@ -1036,26 +974,27 @@ function RegisterRoutes(app) {
|
|
|
1036
974
|
}
|
|
1037
975
|
);
|
|
1038
976
|
app.get(
|
|
1039
|
-
"/
|
|
1040
|
-
...(0,
|
|
1041
|
-
...(0,
|
|
1042
|
-
async function
|
|
977
|
+
"/dev/temp-preview/:componentId/:functionName",
|
|
978
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController),
|
|
979
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController.prototype.TemporaryPreview),
|
|
980
|
+
async function DevelopmentController_TemporaryPreview(request, response, next) {
|
|
1043
981
|
const args = {
|
|
982
|
+
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
1044
983
|
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
1045
984
|
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
985
|
+
headers: { "in": "query", "name": "headers", "dataType": "any" },
|
|
986
|
+
envVars: { "in": "query", "name": "envVars", "dataType": "any" },
|
|
987
|
+
data: { "in": "query", "name": "data", "dataType": "any" }
|
|
1049
988
|
};
|
|
1050
989
|
let validatedArgs = [];
|
|
1051
990
|
try {
|
|
1052
991
|
validatedArgs = getValidatedArgs(args, request, response);
|
|
1053
992
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
1054
|
-
const controller = await container.get(
|
|
993
|
+
const controller = await container.get(DevelopmentController);
|
|
1055
994
|
if (typeof controller["setStatus"] === "function") {
|
|
1056
995
|
controller.setStatus(void 0);
|
|
1057
996
|
}
|
|
1058
|
-
const promise = controller.
|
|
997
|
+
const promise = controller.TemporaryPreview.apply(controller, validatedArgs);
|
|
1059
998
|
promiseHandler(controller, promise, response, void 0, next);
|
|
1060
999
|
} catch (err) {
|
|
1061
1000
|
return next(err);
|
|
@@ -1063,10 +1002,10 @@ function RegisterRoutes(app) {
|
|
|
1063
1002
|
}
|
|
1064
1003
|
);
|
|
1065
1004
|
app.get(
|
|
1066
|
-
"/
|
|
1067
|
-
...(0,
|
|
1068
|
-
...(0,
|
|
1069
|
-
async function
|
|
1005
|
+
"/dev/render/:componentId",
|
|
1006
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController),
|
|
1007
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController.prototype.getDefaultFunctionRendering),
|
|
1008
|
+
async function DevelopmentController_getDefaultFunctionRendering(request, response, next) {
|
|
1070
1009
|
const args = {
|
|
1071
1010
|
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
1072
1011
|
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
@@ -1077,7 +1016,7 @@ function RegisterRoutes(app) {
|
|
|
1077
1016
|
try {
|
|
1078
1017
|
validatedArgs = getValidatedArgs(args, request, response);
|
|
1079
1018
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
1080
|
-
const controller = await container.get(
|
|
1019
|
+
const controller = await container.get(DevelopmentController);
|
|
1081
1020
|
if (typeof controller["setStatus"] === "function") {
|
|
1082
1021
|
controller.setStatus(void 0);
|
|
1083
1022
|
}
|
|
@@ -1089,10 +1028,10 @@ function RegisterRoutes(app) {
|
|
|
1089
1028
|
}
|
|
1090
1029
|
);
|
|
1091
1030
|
app.get(
|
|
1092
|
-
"/
|
|
1093
|
-
...(0,
|
|
1094
|
-
...(0,
|
|
1095
|
-
async function
|
|
1031
|
+
"/dev/render/:componentId/:functionName",
|
|
1032
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController),
|
|
1033
|
+
...(0, import_runtime3.fetchMiddlewares)(DevelopmentController.prototype.getGivenFunctionRendering),
|
|
1034
|
+
async function DevelopmentController_getGivenFunctionRendering(request, response, next) {
|
|
1096
1035
|
const args = {
|
|
1097
1036
|
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
1098
1037
|
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
@@ -1104,7 +1043,7 @@ function RegisterRoutes(app) {
|
|
|
1104
1043
|
try {
|
|
1105
1044
|
validatedArgs = getValidatedArgs(args, request, response);
|
|
1106
1045
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
1107
|
-
const controller = await container.get(
|
|
1046
|
+
const controller = await container.get(DevelopmentController);
|
|
1108
1047
|
if (typeof controller["setStatus"] === "function") {
|
|
1109
1048
|
controller.setStatus(void 0);
|
|
1110
1049
|
}
|
|
@@ -1183,7 +1122,7 @@ function RegisterRoutes(app) {
|
|
|
1183
1122
|
}
|
|
1184
1123
|
});
|
|
1185
1124
|
if (Object.keys(fieldErrors).length > 0) {
|
|
1186
|
-
throw new
|
|
1125
|
+
throw new import_runtime3.ValidateError(fieldErrors, "");
|
|
1187
1126
|
}
|
|
1188
1127
|
return values;
|
|
1189
1128
|
}
|
|
@@ -1233,7 +1172,7 @@ function setupApp(services, config = {}) {
|
|
|
1233
1172
|
app.use((req, res, next) => {
|
|
1234
1173
|
req.accepts("json");
|
|
1235
1174
|
if (["POST", "PUT", "PATCH"].includes(req.method) && req.header("content-type") !== "application/json") {
|
|
1236
|
-
next(new
|
|
1175
|
+
next(new import_dx_common_lib3.BadRequestError("content-type must be application/json"));
|
|
1237
1176
|
return;
|
|
1238
1177
|
}
|
|
1239
1178
|
const id = (0, import_crypto.randomUUID)();
|
|
@@ -1254,14 +1193,14 @@ function setupApp(services, config = {}) {
|
|
|
1254
1193
|
})
|
|
1255
1194
|
);
|
|
1256
1195
|
RegisterRoutes(app);
|
|
1257
|
-
app.use(
|
|
1196
|
+
app.use(import_dx_common_lib3.errorMiddleware);
|
|
1258
1197
|
return app;
|
|
1259
1198
|
}
|
|
1260
1199
|
|
|
1261
1200
|
// src/test/helpers/stack.ts
|
|
1262
1201
|
var import_component_lib4 = require("@squiz/component-lib");
|
|
1263
1202
|
|
|
1264
|
-
// src/component-runner/
|
|
1203
|
+
// src/component-runner/ComponentRunnerService.ts
|
|
1265
1204
|
var import_component_lib3 = require("@squiz/component-lib");
|
|
1266
1205
|
|
|
1267
1206
|
// src/component-runner/ContentRuntimeService.ts
|
|
@@ -1277,21 +1216,17 @@ var ContentRuntimeService = class {
|
|
|
1277
1216
|
}
|
|
1278
1217
|
};
|
|
1279
1218
|
|
|
1280
|
-
// src/component-runner/
|
|
1219
|
+
// src/component-runner/ComponentRunnerService.ts
|
|
1281
1220
|
var import_events = require("events");
|
|
1282
1221
|
var import_fs = __toESM(require("fs"));
|
|
1283
1222
|
var esbuild = __toESM(require("esbuild"));
|
|
1284
1223
|
var import_crypto2 = __toESM(require("crypto"));
|
|
1285
|
-
var
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
const handleUriRequest = async (uri, requestId, id) => {
|
|
1290
|
-
const [result] = await Promise.allSettled([contentRuntimeService.getContentItemPreview(uri)]);
|
|
1291
|
-
webRequestEvents.emit("uri-response", result, requestId, id);
|
|
1292
|
-
};
|
|
1293
|
-
webRequestEvents.on("uri-request", handleUriRequest);
|
|
1224
|
+
var import_node_path = __toESM(require("node:path"));
|
|
1225
|
+
var import_node_vm = __toESM(require("node:vm"));
|
|
1226
|
+
var DevelopmentComponentRunnerService = class {
|
|
1227
|
+
async executeEdgeComponentFunction(task) {
|
|
1294
1228
|
const outputFile = this.getOutputLocation(task.functionEntryFilePath);
|
|
1229
|
+
const webRequestEvents = await this.setUpWebRequestEventForResolveUri(task);
|
|
1295
1230
|
if (!import_fs.default.existsSync(outputFile)) {
|
|
1296
1231
|
esbuild.buildSync({
|
|
1297
1232
|
entryPoints: [task.functionEntryFilePath],
|
|
@@ -1318,6 +1253,53 @@ var ComponentRunnerServiceWithWorkers = class {
|
|
|
1318
1253
|
`Function "${task.componentFunction.name}" not defined in the fn entry js file ${task.functionEntryFilePath}!`
|
|
1319
1254
|
);
|
|
1320
1255
|
}
|
|
1256
|
+
async executeServerComponentFunction(task) {
|
|
1257
|
+
const webRequestEvents = await this.setUpWebRequestEventForResolveUri(task);
|
|
1258
|
+
const transformedCode = await this.transformCode(task.functionEntryFilePath);
|
|
1259
|
+
if (transformedCode === void 0) {
|
|
1260
|
+
throw new Error(
|
|
1261
|
+
`Function "${task.componentFunction.name}" could not be transformed from fn entry js file ${task.functionEntryFilePath}!`
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
const script = new import_node_vm.default.Script(transformedCode, { filename: import_node_path.default.basename(task.functionEntryFilePath) });
|
|
1265
|
+
const context = import_node_vm.default.createContext({ module: {}, exports: {} });
|
|
1266
|
+
const componentContext = this.getComponentContext(task, webRequestEvents);
|
|
1267
|
+
script.runInContext(context);
|
|
1268
|
+
const func = context.module.exports;
|
|
1269
|
+
if (typeof func === "function") {
|
|
1270
|
+
const result = await func(task.args[0], componentContext.ctx);
|
|
1271
|
+
return result;
|
|
1272
|
+
}
|
|
1273
|
+
if (typeof func === "object") {
|
|
1274
|
+
const f = func.default[task.componentFunction.name];
|
|
1275
|
+
const result = await f(task.args[0], componentContext.ctx);
|
|
1276
|
+
return result;
|
|
1277
|
+
} else {
|
|
1278
|
+
throw new Error(`Function "${task.componentFunction.name}" could not be executed`);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
async setUpWebRequestEventForResolveUri(task) {
|
|
1282
|
+
const contentRuntimeService = new ContentRuntimeService(task.manifest, task.manifestPath);
|
|
1283
|
+
const webRequestEvents = new import_events.EventEmitter();
|
|
1284
|
+
const handleUriRequest = async (uri, requestId, id) => {
|
|
1285
|
+
const [result] = await Promise.allSettled([contentRuntimeService.getContentItemPreview(uri)]);
|
|
1286
|
+
webRequestEvents.emit("uri-response", result, requestId, id);
|
|
1287
|
+
};
|
|
1288
|
+
webRequestEvents.on("uri-request", handleUriRequest);
|
|
1289
|
+
return webRequestEvents;
|
|
1290
|
+
}
|
|
1291
|
+
async transformCode(filePath) {
|
|
1292
|
+
try {
|
|
1293
|
+
const code = import_fs.default.readFileSync(filePath, "utf-8");
|
|
1294
|
+
const result = await esbuild.transform(code, {
|
|
1295
|
+
format: "cjs",
|
|
1296
|
+
platform: "node"
|
|
1297
|
+
});
|
|
1298
|
+
return result.code;
|
|
1299
|
+
} catch (error) {
|
|
1300
|
+
console.error("Error during esbuild transformation:", error);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1321
1303
|
getComponentContext(task, webRequestEvents) {
|
|
1322
1304
|
const ctxInput = {
|
|
1323
1305
|
componentName: task.componentFullName,
|
|
@@ -1414,7 +1396,7 @@ function cssIncludeTagHtml(file) {
|
|
|
1414
1396
|
}
|
|
1415
1397
|
|
|
1416
1398
|
// src/PreviewComponentService.ts
|
|
1417
|
-
var
|
|
1399
|
+
var import_dx_common_lib4 = require("@squiz/dx-common-lib");
|
|
1418
1400
|
var PREVIEW_COMPONENT_SET = "unknown";
|
|
1419
1401
|
var ComponentPreviewService = class {
|
|
1420
1402
|
async dressRenderedOutputForPreview(componentManifest, functionDefinition, previewKey, componentOutput) {
|
|
@@ -1434,7 +1416,7 @@ var ComponentPreviewService = class {
|
|
|
1434
1416
|
async embedComponentIntoWrapper(componentDirectory, wrapper, functionDefinition, componentOutput) {
|
|
1435
1417
|
const wrapperFilePath = import_path2.default.resolve(componentDirectory, wrapper.path);
|
|
1436
1418
|
if (await (0, import_fs_extra.pathExists)(wrapperFilePath) === false) {
|
|
1437
|
-
throw new
|
|
1419
|
+
throw new import_dx_common_lib4.BadRequestError(`Preview wrapper file "${wrapper.path}" does not exist`);
|
|
1438
1420
|
}
|
|
1439
1421
|
const wrapperContent = await import_promises.default.readFile(wrapperFilePath, {
|
|
1440
1422
|
encoding: "utf-8"
|
|
@@ -1450,14 +1432,14 @@ var ComponentPreviewService = class {
|
|
|
1450
1432
|
case "json":
|
|
1451
1433
|
return componentOutput;
|
|
1452
1434
|
default:
|
|
1453
|
-
return (0,
|
|
1435
|
+
return (0, import_dx_common_lib4.never)(type);
|
|
1454
1436
|
}
|
|
1455
1437
|
}
|
|
1456
1438
|
};
|
|
1457
1439
|
|
|
1458
1440
|
// src/RenderInputService.ts
|
|
1459
1441
|
var import_strict = __toESM(require("assert/strict"));
|
|
1460
|
-
var
|
|
1442
|
+
var import_dx_common_lib5 = require("@squiz/dx-common-lib");
|
|
1461
1443
|
var PREVIEW_COMPONENT_SET2 = "unknown";
|
|
1462
1444
|
var RenderInputService = class {
|
|
1463
1445
|
constructor(componentSetService, manifestService, componentFunctionService, rootUrlResolver) {
|
|
@@ -1486,7 +1468,7 @@ var RenderInputService = class {
|
|
|
1486
1468
|
let webManifest;
|
|
1487
1469
|
let input = {};
|
|
1488
1470
|
if (request.previewKey && request.componentSet) {
|
|
1489
|
-
throw new
|
|
1471
|
+
throw new import_dx_common_lib5.BadRequestError("You cannot provide a previewKey and a componentSet as input");
|
|
1490
1472
|
}
|
|
1491
1473
|
if (request.previewKey) {
|
|
1492
1474
|
input = await this.getInputForPreview(request, manifest);
|
|
@@ -1501,7 +1483,7 @@ var RenderInputService = class {
|
|
|
1501
1483
|
}
|
|
1502
1484
|
} else {
|
|
1503
1485
|
if (!request.componentSet) {
|
|
1504
|
-
throw new
|
|
1486
|
+
throw new import_dx_common_lib5.BadRequestError("You must provide either previewKey or a componentSet as input");
|
|
1505
1487
|
}
|
|
1506
1488
|
const set = await this.componentSetService.getComponentSet(request.componentSet);
|
|
1507
1489
|
headers = this.componentSetService.getComponentRuntimeHeaders(set, componentFunction);
|
|
@@ -1536,13 +1518,13 @@ var RenderInputService = class {
|
|
|
1536
1518
|
const queryParameters = {};
|
|
1537
1519
|
for (const parameter of Object.keys(componentFunction.queryParameters)) {
|
|
1538
1520
|
if (componentFunction.queryParameters[parameter].required && request.expressRequest.query[parameter] === void 0) {
|
|
1539
|
-
throw new
|
|
1521
|
+
throw new import_dx_common_lib5.BadRequestError(`Required query parameter '${parameter}' is missing`);
|
|
1540
1522
|
}
|
|
1541
1523
|
if (request.expressRequest.query[parameter] === void 0) {
|
|
1542
1524
|
continue;
|
|
1543
1525
|
}
|
|
1544
1526
|
if (typeof request.expressRequest.query[parameter] !== "string") {
|
|
1545
|
-
throw new
|
|
1527
|
+
throw new import_dx_common_lib5.BadRequestError(`Value for query parameter '${parameter}' must be a string`);
|
|
1546
1528
|
}
|
|
1547
1529
|
queryParameters[parameter] = request.expressRequest.query[parameter];
|
|
1548
1530
|
}
|
|
@@ -1560,7 +1542,7 @@ var RenderInputService = class {
|
|
|
1560
1542
|
this.componentFunctionService.assertInputValidForComponentFunction(input, componentFunction);
|
|
1561
1543
|
} catch (e) {
|
|
1562
1544
|
if (e instanceof Error) {
|
|
1563
|
-
const error = new
|
|
1545
|
+
const error = new import_dx_common_lib5.BadRequestError(e.message);
|
|
1564
1546
|
error.stack = e.stack;
|
|
1565
1547
|
throw error;
|
|
1566
1548
|
}
|
|
@@ -1572,7 +1554,7 @@ var RenderInputService = class {
|
|
|
1572
1554
|
this.componentFunctionService.assertRenderInputValidForComponentFunction(input, componentFunction);
|
|
1573
1555
|
} catch (e) {
|
|
1574
1556
|
if (e instanceof Error) {
|
|
1575
|
-
const error = new
|
|
1557
|
+
const error = new import_dx_common_lib5.BadRequestError(e.message);
|
|
1576
1558
|
error.stack = e.stack;
|
|
1577
1559
|
throw error;
|
|
1578
1560
|
}
|
|
@@ -1630,7 +1612,7 @@ function getTestComponentFolder() {
|
|
|
1630
1612
|
function setupTestApp(services = {}, config = {}) {
|
|
1631
1613
|
const dataMount = getTestComponentFolder();
|
|
1632
1614
|
const componentRootUrlResolver = () => "http://localhost:3000";
|
|
1633
|
-
const
|
|
1615
|
+
const developmentComponentRunnerService = new DevelopmentComponentRunnerService();
|
|
1634
1616
|
const componentFunctionService = new import_component_lib4.ComponentFunctionService();
|
|
1635
1617
|
const componentSetService = new import_component_lib4.ComponentSetServiceForLocalDev(testLogger);
|
|
1636
1618
|
const manifestService = new import_component_lib4.ManifestServiceForProduction(dataMount, testLogger);
|
|
@@ -1645,7 +1627,7 @@ function setupTestApp(services = {}, config = {}) {
|
|
|
1645
1627
|
componentFunctionService,
|
|
1646
1628
|
componentSetService,
|
|
1647
1629
|
manifestService,
|
|
1648
|
-
|
|
1630
|
+
developmentComponentRunnerService,
|
|
1649
1631
|
renderInputService,
|
|
1650
1632
|
logger: testLogger,
|
|
1651
1633
|
componentPreviewService: new ComponentPreviewService(),
|
|
@@ -1835,348 +1817,26 @@ function generateRandomName() {
|
|
|
1835
1817
|
return "test-" + (0, import_crypto3.randomUUID)();
|
|
1836
1818
|
}
|
|
1837
1819
|
|
|
1838
|
-
// src/webserver/controllers/test/definition-route-tests.ts
|
|
1839
|
-
function definitionRouteTests(request, _rootUrl = "http://localhost:3000") {
|
|
1840
|
-
describe("definition routes", () => {
|
|
1841
|
-
it("should return the component manifest", async () => {
|
|
1842
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0/manifest.json");
|
|
1843
|
-
expect(response.statusCode).toEqual(200);
|
|
1844
|
-
expect(response.type).toEqual("application/json");
|
|
1845
|
-
const expected = {
|
|
1846
|
-
$schema: "http://localhost:3000/schemas/v1.json#",
|
|
1847
|
-
name: "test-component",
|
|
1848
|
-
namespace: "unit-test-components",
|
|
1849
|
-
description: "some-description",
|
|
1850
|
-
displayName: "some-display-name",
|
|
1851
|
-
version: "1.0.0",
|
|
1852
|
-
mainFunction: "main",
|
|
1853
|
-
type: "edge",
|
|
1854
|
-
functions: [
|
|
1855
|
-
{
|
|
1856
|
-
name: "main",
|
|
1857
|
-
entry: "main.js",
|
|
1858
|
-
input: {
|
|
1859
|
-
type: "object",
|
|
1860
|
-
properties: {
|
|
1861
|
-
something: {
|
|
1862
|
-
type: "string"
|
|
1863
|
-
}
|
|
1864
|
-
},
|
|
1865
|
-
required: ["something"]
|
|
1866
|
-
},
|
|
1867
|
-
output: {
|
|
1868
|
-
responseType: "html"
|
|
1869
|
-
}
|
|
1870
|
-
},
|
|
1871
|
-
{
|
|
1872
|
-
name: "promise",
|
|
1873
|
-
entry: "promise.js",
|
|
1874
|
-
input: {
|
|
1875
|
-
type: "object",
|
|
1876
|
-
properties: {
|
|
1877
|
-
something: {
|
|
1878
|
-
type: "string"
|
|
1879
|
-
}
|
|
1880
|
-
},
|
|
1881
|
-
required: ["something"]
|
|
1882
|
-
},
|
|
1883
|
-
output: {
|
|
1884
|
-
responseType: "html"
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
],
|
|
1888
|
-
previews: {
|
|
1889
|
-
preview1: {
|
|
1890
|
-
functionData: {
|
|
1891
|
-
main: {
|
|
1892
|
-
inputData: {
|
|
1893
|
-
type: "inline",
|
|
1894
|
-
value: {
|
|
1895
|
-
something: "something"
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
};
|
|
1903
|
-
expect(response.body).toEqual(expected);
|
|
1904
|
-
});
|
|
1905
|
-
it("should return the component main function definition when no fn specified in the route", async () => {
|
|
1906
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0");
|
|
1907
|
-
expect(response.statusCode).toEqual(200);
|
|
1908
|
-
expect(response.type).toEqual("application/json");
|
|
1909
|
-
const expected = {
|
|
1910
|
-
name: "main",
|
|
1911
|
-
entry: "main.js",
|
|
1912
|
-
input: {
|
|
1913
|
-
type: "object",
|
|
1914
|
-
properties: {
|
|
1915
|
-
something: {
|
|
1916
|
-
type: "string"
|
|
1917
|
-
}
|
|
1918
|
-
},
|
|
1919
|
-
required: ["something"]
|
|
1920
|
-
},
|
|
1921
|
-
output: {
|
|
1922
|
-
responseType: "html"
|
|
1923
|
-
}
|
|
1924
|
-
};
|
|
1925
|
-
expect(response.body).toEqual(expected);
|
|
1926
|
-
});
|
|
1927
|
-
it("should return the component main function definition when specified in the route", async () => {
|
|
1928
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0/main");
|
|
1929
|
-
expect(response.statusCode).toEqual(200);
|
|
1930
|
-
expect(response.type).toEqual("application/json");
|
|
1931
|
-
const expected = {
|
|
1932
|
-
name: "main",
|
|
1933
|
-
entry: "main.js",
|
|
1934
|
-
input: {
|
|
1935
|
-
type: "object",
|
|
1936
|
-
properties: {
|
|
1937
|
-
something: {
|
|
1938
|
-
type: "string"
|
|
1939
|
-
}
|
|
1940
|
-
},
|
|
1941
|
-
required: ["something"]
|
|
1942
|
-
},
|
|
1943
|
-
output: {
|
|
1944
|
-
responseType: "html"
|
|
1945
|
-
}
|
|
1946
|
-
};
|
|
1947
|
-
expect(response.body).toEqual(expected);
|
|
1948
|
-
});
|
|
1949
|
-
it("should return the function definition specified in the route", async () => {
|
|
1950
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0/promise");
|
|
1951
|
-
expect(response.statusCode).toEqual(200);
|
|
1952
|
-
expect(response.type).toEqual("application/json");
|
|
1953
|
-
const expected = {
|
|
1954
|
-
name: "promise",
|
|
1955
|
-
entry: "promise.js",
|
|
1956
|
-
input: {
|
|
1957
|
-
type: "object",
|
|
1958
|
-
properties: {
|
|
1959
|
-
something: {
|
|
1960
|
-
type: "string"
|
|
1961
|
-
}
|
|
1962
|
-
},
|
|
1963
|
-
required: ["something"]
|
|
1964
|
-
},
|
|
1965
|
-
output: {
|
|
1966
|
-
responseType: "html"
|
|
1967
|
-
}
|
|
1968
|
-
};
|
|
1969
|
-
expect(response.body).toEqual(expected);
|
|
1970
|
-
});
|
|
1971
|
-
it("should 404 if requesting on a non-existent component", async () => {
|
|
1972
|
-
const response = await request().get("/d/unit-test-components__bad-component__1.0.0");
|
|
1973
|
-
expect(response.statusCode).toEqual(404);
|
|
1974
|
-
expect(response.body).toEqual({
|
|
1975
|
-
message: "manifest for unit-test-components/bad-component 1.0.0 could not be found"
|
|
1976
|
-
});
|
|
1977
|
-
});
|
|
1978
|
-
it("should 404 if requesting on a non-existent component version", async () => {
|
|
1979
|
-
const response = await request().get("/d/unit-test-components__test-component__9.9.9");
|
|
1980
|
-
expect(response.statusCode).toEqual(404);
|
|
1981
|
-
expect(response.body).toEqual({
|
|
1982
|
-
message: "manifest for unit-test-components/test-component 9.9.9 could not be found"
|
|
1983
|
-
});
|
|
1984
|
-
});
|
|
1985
|
-
it("should 404 if requesting a non-existent function on a valid component", async () => {
|
|
1986
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0/non-existent-fn");
|
|
1987
|
-
expect(response.statusCode).toEqual(404);
|
|
1988
|
-
expect(response.body).toEqual({
|
|
1989
|
-
message: "non-existent-fn could not be found in test-component 1.0.0"
|
|
1990
|
-
});
|
|
1991
|
-
});
|
|
1992
|
-
});
|
|
1993
|
-
describe("definition route - invalid query params", () => {
|
|
1994
|
-
it("should throw an appropriate error message when both _componentSet and _previewKey are provided as query parameters", async () => {
|
|
1995
|
-
const response = await request().get(
|
|
1996
|
-
"/d/unit-test-components__test-static-files__1.0.0?_componentSet=set&_previewKey=test-preview"
|
|
1997
|
-
);
|
|
1998
|
-
expect(response.statusCode).toEqual(400);
|
|
1999
|
-
});
|
|
2000
|
-
});
|
|
2001
|
-
describe("definition routes - with component set", () => {
|
|
2002
|
-
it("should return the component manifest", async () => {
|
|
2003
|
-
const response = await request().get(
|
|
2004
|
-
"/d/unit-test-components__test-component__1.0.0/manifest.json?_componentSet=set"
|
|
2005
|
-
);
|
|
2006
|
-
expect(response.statusCode).toEqual(200);
|
|
2007
|
-
expect(response.type).toEqual("application/json");
|
|
2008
|
-
const expected = {
|
|
2009
|
-
$schema: "http://localhost:3000/schemas/v1.json#",
|
|
2010
|
-
name: "test-component",
|
|
2011
|
-
namespace: "unit-test-components",
|
|
2012
|
-
description: "some-description",
|
|
2013
|
-
displayName: "some-display-name",
|
|
2014
|
-
version: "1.0.0",
|
|
2015
|
-
mainFunction: "main",
|
|
2016
|
-
type: "edge",
|
|
2017
|
-
functions: [
|
|
2018
|
-
{
|
|
2019
|
-
name: "main",
|
|
2020
|
-
entry: "main.js",
|
|
2021
|
-
input: {
|
|
2022
|
-
type: "object",
|
|
2023
|
-
properties: {
|
|
2024
|
-
something: {
|
|
2025
|
-
type: "string"
|
|
2026
|
-
}
|
|
2027
|
-
},
|
|
2028
|
-
required: ["something"]
|
|
2029
|
-
},
|
|
2030
|
-
output: {
|
|
2031
|
-
responseType: "html"
|
|
2032
|
-
}
|
|
2033
|
-
},
|
|
2034
|
-
{
|
|
2035
|
-
name: "promise",
|
|
2036
|
-
entry: "promise.js",
|
|
2037
|
-
input: {
|
|
2038
|
-
type: "object",
|
|
2039
|
-
properties: {
|
|
2040
|
-
something: {
|
|
2041
|
-
type: "string"
|
|
2042
|
-
}
|
|
2043
|
-
},
|
|
2044
|
-
required: ["something"]
|
|
2045
|
-
},
|
|
2046
|
-
output: {
|
|
2047
|
-
responseType: "html"
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
],
|
|
2051
|
-
previews: {
|
|
2052
|
-
preview1: {
|
|
2053
|
-
functionData: {
|
|
2054
|
-
main: {
|
|
2055
|
-
inputData: {
|
|
2056
|
-
type: "inline",
|
|
2057
|
-
value: {
|
|
2058
|
-
something: "something"
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
};
|
|
2066
|
-
expect(response.body).toEqual(expected);
|
|
2067
|
-
});
|
|
2068
|
-
it("should return the component main function definition when no fn specified in the route", async () => {
|
|
2069
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0?_componentSet=set");
|
|
2070
|
-
expect(response.statusCode).toEqual(200);
|
|
2071
|
-
expect(response.type).toEqual("application/json");
|
|
2072
|
-
const expected = {
|
|
2073
|
-
name: "main",
|
|
2074
|
-
entry: "main.js",
|
|
2075
|
-
input: {
|
|
2076
|
-
type: "object",
|
|
2077
|
-
properties: {
|
|
2078
|
-
something: {
|
|
2079
|
-
type: "string"
|
|
2080
|
-
}
|
|
2081
|
-
},
|
|
2082
|
-
required: ["something"]
|
|
2083
|
-
},
|
|
2084
|
-
output: {
|
|
2085
|
-
responseType: "html"
|
|
2086
|
-
}
|
|
2087
|
-
};
|
|
2088
|
-
expect(response.body).toEqual(expected);
|
|
2089
|
-
});
|
|
2090
|
-
it("should return the component main function definition when specified in the route", async () => {
|
|
2091
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0/main?_componentSet=set");
|
|
2092
|
-
expect(response.statusCode).toEqual(200);
|
|
2093
|
-
expect(response.type).toEqual("application/json");
|
|
2094
|
-
const expected = {
|
|
2095
|
-
name: "main",
|
|
2096
|
-
entry: "main.js",
|
|
2097
|
-
input: {
|
|
2098
|
-
type: "object",
|
|
2099
|
-
properties: {
|
|
2100
|
-
something: {
|
|
2101
|
-
type: "string"
|
|
2102
|
-
}
|
|
2103
|
-
},
|
|
2104
|
-
required: ["something"]
|
|
2105
|
-
},
|
|
2106
|
-
output: {
|
|
2107
|
-
responseType: "html"
|
|
2108
|
-
}
|
|
2109
|
-
};
|
|
2110
|
-
expect(response.body).toEqual(expected);
|
|
2111
|
-
});
|
|
2112
|
-
it("should return the function definition specified in the route", async () => {
|
|
2113
|
-
const response = await request().get("/d/unit-test-components__test-component__1.0.0/promise?_componentSet=set");
|
|
2114
|
-
expect(response.statusCode).toEqual(200);
|
|
2115
|
-
expect(response.type).toEqual("application/json");
|
|
2116
|
-
const expected = {
|
|
2117
|
-
name: "promise",
|
|
2118
|
-
entry: "promise.js",
|
|
2119
|
-
input: {
|
|
2120
|
-
type: "object",
|
|
2121
|
-
properties: {
|
|
2122
|
-
something: {
|
|
2123
|
-
type: "string"
|
|
2124
|
-
}
|
|
2125
|
-
},
|
|
2126
|
-
required: ["something"]
|
|
2127
|
-
},
|
|
2128
|
-
output: {
|
|
2129
|
-
responseType: "html"
|
|
2130
|
-
}
|
|
2131
|
-
};
|
|
2132
|
-
expect(response.body).toEqual(expected);
|
|
2133
|
-
});
|
|
2134
|
-
it("should 404 if requesting on a non-existent component", async () => {
|
|
2135
|
-
const response = await request().get("/d/unit-test-components__bad-component__1.0.0?_componentSet=set");
|
|
2136
|
-
expect(response.statusCode).toEqual(404);
|
|
2137
|
-
expect(response.body).toEqual({
|
|
2138
|
-
message: "manifest for unit-test-components/bad-component 1.0.0 could not be found"
|
|
2139
|
-
});
|
|
2140
|
-
});
|
|
2141
|
-
it("should 404 if requesting on a non-existent component version", async () => {
|
|
2142
|
-
const response = await request().get("/d/unit-test-components__test-component__9.9.9?_componentSet=set");
|
|
2143
|
-
expect(response.statusCode).toEqual(404);
|
|
2144
|
-
expect(response.body).toEqual({
|
|
2145
|
-
message: "manifest for unit-test-components/test-component 9.9.9 could not be found"
|
|
2146
|
-
});
|
|
2147
|
-
});
|
|
2148
|
-
it("should 404 if requesting a non-existent function on a valid component", async () => {
|
|
2149
|
-
const response = await request().get(
|
|
2150
|
-
"/d/unit-test-components__test-component__1.0.0/non-existent-fn?_componentSet=set"
|
|
2151
|
-
);
|
|
2152
|
-
expect(response.statusCode).toEqual(404);
|
|
2153
|
-
expect(response.body).toEqual({
|
|
2154
|
-
message: "non-existent-fn could not be found in test-component 1.0.0"
|
|
2155
|
-
});
|
|
2156
|
-
});
|
|
2157
|
-
});
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
1820
|
// src/webserver/controllers/test/render-route-tests.ts
|
|
2161
1821
|
function renderRouteTests(request, _rootUrl) {
|
|
2162
|
-
describe("GET /
|
|
1822
|
+
describe("GET /dev/render/unit-test-components__test-component__1.0.10/?_componentSet=set", () => {
|
|
2163
1823
|
it("should render the test component with html endpoint", async () => {
|
|
2164
1824
|
const response = await request().get(
|
|
2165
|
-
"/
|
|
1825
|
+
"/dev/render/unit-test-components__test-component__1.0.10?_componentSet=set&something=unused"
|
|
2166
1826
|
);
|
|
2167
1827
|
expect(response.text).toEqual("<div>hello - {}</div>");
|
|
2168
1828
|
expect(response.statusCode).toEqual(200);
|
|
2169
1829
|
}, 2e4);
|
|
2170
1830
|
it("should render the test component promise endpoint with html endpoint", async () => {
|
|
2171
1831
|
const response = await request().get(
|
|
2172
|
-
"/
|
|
1832
|
+
"/dev/render/unit-test-components__test-component__1.0.10/promise?_componentSet=set&something=unused"
|
|
2173
1833
|
);
|
|
2174
1834
|
expect(response.statusCode).toEqual(200);
|
|
2175
1835
|
expect(response.text).toEqual("<h1>hello</h1>");
|
|
2176
1836
|
}, 2e4);
|
|
2177
1837
|
it("should fail validation if input contract is not met and helpful message returned", async () => {
|
|
2178
1838
|
const response = await request().get(
|
|
2179
|
-
"/
|
|
1839
|
+
"/dev/render/unit-test-components__test-component__1.0.0?_componentSet=set&something=unused"
|
|
2180
1840
|
);
|
|
2181
1841
|
expect(response.statusCode).toEqual(400);
|
|
2182
1842
|
expect(response.body).toMatchInlineSnapshot(`
|
|
@@ -2187,7 +1847,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
2187
1847
|
}, 2e4);
|
|
2188
1848
|
it("should 404 if requesting a non-existent function on an otherwise valid component", async () => {
|
|
2189
1849
|
const response = await request().get(
|
|
2190
|
-
"/
|
|
1850
|
+
"/dev/render/unit-test-components__test-component__1.0.0/non-existent-entry-file?_componentSet=set&something=not-used"
|
|
2191
1851
|
);
|
|
2192
1852
|
expect(response.statusCode).toEqual(404);
|
|
2193
1853
|
expect(response.body).toMatchInlineSnapshot(`
|
|
@@ -2197,10 +1857,10 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
2197
1857
|
`);
|
|
2198
1858
|
}, 2e4);
|
|
2199
1859
|
});
|
|
2200
|
-
describe("GET /
|
|
1860
|
+
describe("GET /dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set", () => {
|
|
2201
1861
|
it("should fail validation when requesting a function with a missing entry file", async () => {
|
|
2202
1862
|
const response = await request().get(
|
|
2203
|
-
"/
|
|
1863
|
+
"/dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set&something=not-used"
|
|
2204
1864
|
);
|
|
2205
1865
|
expect(response.body).toEqual({
|
|
2206
1866
|
message: `"main's" entry file "missing-entry-file.js" is inaccessible`
|
|
@@ -2208,9 +1868,9 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
2208
1868
|
expect(response.statusCode).toEqual(500);
|
|
2209
1869
|
}, 2e4);
|
|
2210
1870
|
});
|
|
2211
|
-
describe("GET /
|
|
1871
|
+
describe("GET /dev/render/unit-test-components__test-component__1.0.4?_componentSet=set", () => {
|
|
2212
1872
|
it("should render a simple json endpoint", async () => {
|
|
2213
|
-
const response = await request().get("/
|
|
1873
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4?_componentSet=set");
|
|
2214
1874
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
2215
1875
|
expect(response.body).toEqual({
|
|
2216
1876
|
"my-prop": "test value for my-prop",
|
|
@@ -2224,7 +1884,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
2224
1884
|
}, 2e4);
|
|
2225
1885
|
it("should report error if response does not match with the schema", async () => {
|
|
2226
1886
|
const response = await request().get(
|
|
2227
|
-
"/
|
|
1887
|
+
"/dev/render/unit-test-components__test-component__1.0.4/render_json_invalid?_componentSet=set"
|
|
2228
1888
|
);
|
|
2229
1889
|
expect(response.statusCode).toEqual(500);
|
|
2230
1890
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
@@ -2234,7 +1894,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
2234
1894
|
}, 2e4);
|
|
2235
1895
|
it("should validate a complex json against a schema", async () => {
|
|
2236
1896
|
const response = await request().get(
|
|
2237
|
-
"/
|
|
1897
|
+
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_valid?_componentSet=set"
|
|
2238
1898
|
);
|
|
2239
1899
|
const myObject = {
|
|
2240
1900
|
"my-object": {
|
|
@@ -2250,7 +1910,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
2250
1910
|
}, 2e4);
|
|
2251
1911
|
it("should report errors if nested object json schema fails", async () => {
|
|
2252
1912
|
const response = await request().get(
|
|
2253
|
-
"/
|
|
1913
|
+
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_invalid?_componentSet=set"
|
|
2254
1914
|
);
|
|
2255
1915
|
expect(response.statusCode).toEqual(500);
|
|
2256
1916
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
@@ -2260,10 +1920,10 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
2260
1920
|
});
|
|
2261
1921
|
}, 2e4);
|
|
2262
1922
|
});
|
|
2263
|
-
describe("GET /
|
|
1923
|
+
describe("GET /dev/render/unit-test-components__test-component__1.0.7?_componentSet=set", () => {
|
|
2264
1924
|
it('should return input and info object with "query parameters"', async () => {
|
|
2265
1925
|
const response = await request().get(
|
|
2266
|
-
"/
|
|
1926
|
+
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&something=hello-test&foo=foo-val&foo2=foo2-val"
|
|
2267
1927
|
);
|
|
2268
1928
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
2269
1929
|
const result = response.body;
|
|
@@ -2340,7 +2000,7 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
2340
2000
|
});
|
|
2341
2001
|
it("should throw error if required query parameter is missing", async () => {
|
|
2342
2002
|
const response = await request().get(
|
|
2343
|
-
"/
|
|
2003
|
+
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo2=foo2-val"
|
|
2344
2004
|
);
|
|
2345
2005
|
expect(response.body).toEqual({
|
|
2346
2006
|
message: "Required query parameter 'foo' is missing"
|
|
@@ -2349,66 +2009,74 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
2349
2009
|
});
|
|
2350
2010
|
it("should throw error if query parameter is not a string", async () => {
|
|
2351
2011
|
const response = await request().get(
|
|
2352
|
-
"/
|
|
2012
|
+
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo=123&foo2[]=array-val"
|
|
2353
2013
|
);
|
|
2354
2014
|
expect(response.body).toEqual({
|
|
2355
2015
|
message: "Value for query parameter 'foo2' must be a string"
|
|
2356
2016
|
});
|
|
2357
2017
|
expect(response.statusCode).toEqual(400);
|
|
2358
2018
|
});
|
|
2359
|
-
describe("GET /
|
|
2019
|
+
describe("GET /dev/render/unit-test-components__test-headers__1.0.3?_componentSet=set", () => {
|
|
2360
2020
|
it("should make sure max-age header is clamped between max value", async () => {
|
|
2361
|
-
const response = await request().get("/
|
|
2021
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/max_value?_componentSet=set").send().expect(200, "rendered");
|
|
2362
2022
|
expect(response.headers["cache-control"]).toEqual("max-age=1800, immutable");
|
|
2363
2023
|
});
|
|
2364
2024
|
it("should make sure max-age header is clamped between min value", async () => {
|
|
2365
|
-
const response = await request().get("/
|
|
2025
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/min_value?_componentSet=set").send().expect(200, "rendered");
|
|
2366
2026
|
expect(response.headers["cache-control"]).toEqual("max-age=30, public");
|
|
2367
2027
|
});
|
|
2368
2028
|
});
|
|
2369
2029
|
describe("should be able to load external dependencies", () => {
|
|
2370
2030
|
it("should be able to make web requests out", async () => {
|
|
2371
|
-
const response = await request().get(
|
|
2031
|
+
const response = await request().get(
|
|
2032
|
+
"/dev/render/unit-test-components__test-npm-modules__3.0.0?_componentSet=set"
|
|
2033
|
+
);
|
|
2372
2034
|
expect(response.statusCode).toEqual(200);
|
|
2373
2035
|
expect(response.text).toContain(`<h1>Example Domain</h1>`);
|
|
2374
2036
|
});
|
|
2375
2037
|
});
|
|
2376
|
-
describe("GET /
|
|
2038
|
+
describe("GET /dev/render/unit-test-components__test-formatted-text__1.0.0", () => {
|
|
2377
2039
|
it("should render a component formattedText in preview inline", async () => {
|
|
2378
2040
|
const response = await request().get(
|
|
2379
|
-
"/
|
|
2041
|
+
"/dev/render/unit-test-components__test-formatted-text__1.0.0?_previewKey=valid-inline-preview"
|
|
2380
2042
|
);
|
|
2381
2043
|
expect(response.statusCode).toEqual(200);
|
|
2382
2044
|
expect(response.text).toMatchInlineSnapshot(`"This is a test"`);
|
|
2383
2045
|
});
|
|
2384
2046
|
});
|
|
2385
|
-
describe("GET /
|
|
2047
|
+
describe("GET /dev/render/unit-test-components__test-npm-modules__3.1.0", () => {
|
|
2386
2048
|
it("should render a component with axios", async () => {
|
|
2387
|
-
const response = await request().get(
|
|
2049
|
+
const response = await request().get(
|
|
2050
|
+
"/dev/render/unit-test-components__test-npm-modules__3.1.0/axios?_componentSet=set"
|
|
2051
|
+
);
|
|
2388
2052
|
expect(response.statusCode).toEqual(200);
|
|
2389
2053
|
});
|
|
2390
2054
|
it("should render a component with uuid", async () => {
|
|
2391
|
-
const response = await request().get(
|
|
2055
|
+
const response = await request().get(
|
|
2056
|
+
"/dev/render/unit-test-components__test-npm-modules__3.1.0/uuid?_componentSet=set"
|
|
2057
|
+
);
|
|
2392
2058
|
expect(response.statusCode).toEqual(200);
|
|
2393
2059
|
});
|
|
2394
2060
|
it("should render a component with Buffer", async () => {
|
|
2395
|
-
const response = await request().get(
|
|
2061
|
+
const response = await request().get(
|
|
2062
|
+
"/dev/render/unit-test-components__test-npm-modules__3.1.0/buffer?_componentSet=set"
|
|
2063
|
+
);
|
|
2396
2064
|
expect(response.statusCode).toEqual(200);
|
|
2397
2065
|
});
|
|
2398
2066
|
});
|
|
2399
|
-
describe("GET /
|
|
2067
|
+
describe("GET /dev/render/unit-test-components__test-squiz-image__1.0.0", () => {
|
|
2400
2068
|
it("should render the preview", async () => {
|
|
2401
2069
|
const response = await request().get(
|
|
2402
|
-
"/
|
|
2070
|
+
"/dev/render/unit-test-components__test-squiz-image__1.0.0?_previewKey=valid-inline-preview"
|
|
2403
2071
|
);
|
|
2404
2072
|
expect(response.statusCode).toEqual(200);
|
|
2405
2073
|
expect(response.text).toMatchInlineSnapshot(`"My Image Component"`);
|
|
2406
2074
|
});
|
|
2407
2075
|
});
|
|
2408
|
-
describe("GET /
|
|
2076
|
+
describe("GET /dev/render/unit-test-components__test-squiz-link__1.0.0", () => {
|
|
2409
2077
|
it("should render the preview", async () => {
|
|
2410
2078
|
const response = await request().get(
|
|
2411
|
-
"/
|
|
2079
|
+
"/dev/render/unit-test-components__test-squiz-link__1.0.0?_previewKey=valid-inline-preview"
|
|
2412
2080
|
);
|
|
2413
2081
|
expect(response.statusCode).toEqual(200);
|
|
2414
2082
|
expect(response.text).toMatchInlineSnapshot(`"{"link":{"text":"My Link","url":"https://some.link/foo"}}"`);
|
|
@@ -2420,13 +2088,13 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
2420
2088
|
function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
2421
2089
|
describe("preview routes", () => {
|
|
2422
2090
|
it("should render a preview of a component with no wrapper file", async () => {
|
|
2423
|
-
await request().get("/
|
|
2091
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=test-preview").expect(200).expect("content-type", "text/html; charset=utf-8").expect("800 | this is nested content");
|
|
2424
2092
|
});
|
|
2425
2093
|
it("should render a preview of a component with a different preset", async () => {
|
|
2426
|
-
await request().get("/
|
|
2094
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=another-preview").expect(200).expect("content-type", "text/html; charset=utf-8").expect("12300 | this is also nested content");
|
|
2427
2095
|
});
|
|
2428
2096
|
it("should render a preview of a component non-main function with a wrapper html file", async () => {
|
|
2429
|
-
await request().get("/
|
|
2097
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4/other?_previewKey=another-preview").expect(200).expect("content-type", "text/html; charset=utf-8").expect((a) => {
|
|
2430
2098
|
expect(a.text).toMatchInlineSnapshot(`
|
|
2431
2099
|
"<!DOCTYPE html>
|
|
2432
2100
|
<html lang="en">
|
|
@@ -2446,14 +2114,14 @@ function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
|
2446
2114
|
});
|
|
2447
2115
|
it("should load the defined preview for a given preview key", async () => {
|
|
2448
2116
|
const response = await request().get(
|
|
2449
|
-
"/
|
|
2117
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=second-preview"
|
|
2450
2118
|
);
|
|
2451
2119
|
expect(response.text).toContain(`<p>Second Preview</p>`);
|
|
2452
2120
|
expect(response.statusCode).toEqual(200);
|
|
2453
2121
|
});
|
|
2454
2122
|
it("should give meaningful error when preview key is invalid", async () => {
|
|
2455
2123
|
const response = await request().get(
|
|
2456
|
-
"/
|
|
2124
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=invalid"
|
|
2457
2125
|
);
|
|
2458
2126
|
expect(response.text).toEqual(
|
|
2459
2127
|
`{"message":"Component has not defined preview with key \\"invalid\\", the defined preview keys for this component are \\"first-preview, second-preview, test-preview\\""}`
|
|
@@ -2462,13 +2130,13 @@ function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
|
2462
2130
|
});
|
|
2463
2131
|
it("should render inline preview data through to component", async () => {
|
|
2464
2132
|
const response = await request().get(
|
|
2465
|
-
"/
|
|
2133
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.4?_previewKey=test-preview"
|
|
2466
2134
|
);
|
|
2467
2135
|
expect(response.text).toContain(`this is a result | 123`);
|
|
2468
2136
|
expect(response.statusCode).toEqual(200);
|
|
2469
2137
|
}, 1e4);
|
|
2470
2138
|
it("should resolve URIs to mocked URI object in preview route", async () => {
|
|
2471
|
-
await request().get("/
|
|
2139
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.1.1?_previewKey=test-preview").expect(200).expect((a) => {
|
|
2472
2140
|
expect(a.text).toMatchInlineSnapshot(`
|
|
2473
2141
|
"
|
|
2474
2142
|
inline:{"id":"id-inline","type":"root_folder","type_name":"Root Folder","version":"0.0.1","name":"Root Folder","short_name":"/","status":{"id":2,"code":"under_construction"},"created":{"date":"2020-02-27T09:47:27+11:00","user_id":null},"updated":{"date":"2020-02-27T09:47:27+11:00","user_id":""},"published":{"date":"2020-02-27T09:47:27+11:00","user_id":"null"},"status_changed":{"date":"2020-02-27T09:47:27+11:00","user_id":"null"},"url":"xxx","urls":[],"attributes":{"test":"test"},"additional":{}}
|
|
@@ -2482,14 +2150,13 @@ function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
|
2482
2150
|
|
|
2483
2151
|
// src/index.ts
|
|
2484
2152
|
var routeTests = {
|
|
2485
|
-
definition: definitionRouteTests,
|
|
2486
2153
|
render: renderRouteTests,
|
|
2487
2154
|
preview: previewRouteTests
|
|
2488
2155
|
};
|
|
2489
2156
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2490
2157
|
0 && (module.exports = {
|
|
2491
2158
|
ComponentPreviewService,
|
|
2492
|
-
|
|
2159
|
+
DevelopmentComponentRunnerService,
|
|
2493
2160
|
PREVIEW_COMPONENT_SET,
|
|
2494
2161
|
RenderInputService,
|
|
2495
2162
|
TestHelpers,
|