@squiz/edge-dev-render-runtime-lib 2.3.1 → 2.4.1

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.
@@ -4,8 +4,12 @@ export interface ComponentRunnerService {
4
4
  executeServerComponentFunction(task: ExecuteComponentTask): Promise<FunctionReturnTypes>;
5
5
  executeEdgeComponentFunction(task: ExecuteComponentTask): Promise<FunctionReturnTypes>;
6
6
  }
7
+ export type ContextAwareness = {
8
+ matrixUrl?: string;
9
+ matrixAssetId?: string;
10
+ };
7
11
  export declare class DevelopmentComponentRunnerService implements ComponentRunnerService {
8
- executeEdgeComponentFunction(task: ExecuteComponentTask): Promise<FunctionReturnTypes>;
12
+ executeEdgeComponentFunction(task: ExecuteComponentTask, contextAwareness?: ContextAwareness): Promise<FunctionReturnTypes>;
9
13
  executeServerComponentFunction(task: ExecuteComponentTask): Promise<FunctionReturnTypes>;
10
14
  private setUpWebRequestEventForResolveUri;
11
15
  private transformCode;
package/lib/index.js CHANGED
@@ -237,7 +237,7 @@ var DevelopmentController = class extends import_tsoa3.Controller {
237
237
  });
238
238
  return schemaResult;
239
239
  }
240
- async TemporaryPreview(req, componentId, functionName, headers, envVars, data) {
240
+ async TemporaryPreview(req, componentId, functionName, headers, envVars, data, contextMatrixAssetId, contextMatrixUrl) {
241
241
  this.checkDevMode();
242
242
  const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
243
243
  const res = req.res;
@@ -263,7 +263,11 @@ var DevelopmentController = class extends import_tsoa3.Controller {
263
263
  previewKey: void 0,
264
264
  queryParameters: void 0
265
265
  };
266
- const result = componentManifest.type === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(componentTask) : await this.componentRunnerService.executeServerComponentFunction(componentTask);
266
+ const ctx = {
267
+ matrixAssetId: contextMatrixAssetId,
268
+ matrixUrl: contextMatrixUrl
269
+ };
270
+ let result = componentManifest.type === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(componentTask, ctx) : await this.componentRunnerService.executeServerComponentFunction(componentTask);
267
271
  const responseHeaders = headers ?? {};
268
272
  switch (componentFunction.output.responseType) {
269
273
  case "html":
@@ -273,13 +277,30 @@ var DevelopmentController = class extends import_tsoa3.Controller {
273
277
  responseHeaders["content-type"] = "application/json";
274
278
  break;
275
279
  }
280
+ const defaultPreviewKey = Object.keys(componentManifest.getModel()?.previews ?? {}).at(0) ?? void 0;
281
+ if (defaultPreviewKey) {
282
+ result = await this.componentPreviewService.dressRenderedOutputForPreview(
283
+ componentManifest,
284
+ componentFunction,
285
+ defaultPreviewKey,
286
+ result
287
+ );
288
+ }
276
289
  setHeadersOnExpressResponse(responseHeaders ?? {}, res);
277
290
  res.send(result);
278
291
  }
279
- async getDefaultFunctionRendering(expressRequest, componentId, componentSet, previewKey) {
280
- await this.getGivenFunctionRendering(expressRequest, componentId, "", componentSet, previewKey);
292
+ async getDefaultFunctionRendering(expressRequest, componentId, componentSet, previewKey, contextMatrixAssetId, contextMatrixUrl) {
293
+ await this.getGivenFunctionRendering(
294
+ expressRequest,
295
+ componentId,
296
+ "",
297
+ componentSet,
298
+ previewKey,
299
+ contextMatrixAssetId,
300
+ contextMatrixUrl
301
+ );
281
302
  }
282
- async getGivenFunctionRendering(expressRequest, componentId, functionName, componentSet, previewKey) {
303
+ async getGivenFunctionRendering(expressRequest, componentId, functionName, componentSet, previewKey, contextMatrixAssetId, contextMatrixUrl) {
283
304
  const response = expressRequest.res;
284
305
  (0, import_dx_common_lib2.assertIsDefined)(response);
285
306
  const { path: path6, query } = expressRequest;
@@ -294,6 +315,10 @@ var DevelopmentController = class extends import_tsoa3.Controller {
294
315
  response.redirect(url);
295
316
  return;
296
317
  }
318
+ const ctx = {
319
+ matrixAssetId: contextMatrixAssetId,
320
+ matrixUrl: contextMatrixUrl
321
+ };
297
322
  const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
298
323
  const renderInput = await this.renderInputService.resolveInput({
299
324
  componentSet,
@@ -304,15 +329,15 @@ var DevelopmentController = class extends import_tsoa3.Controller {
304
329
  expressRequest,
305
330
  functionName
306
331
  });
307
- const renderedOutput = await this.doFunctionRender(renderInput);
332
+ const renderedOutput = await this.doFunctionRender(renderInput, ctx);
308
333
  this.handleResponse(renderInput, renderedOutput, response);
309
334
  }
310
335
  handleResponse(input, output, response) {
311
336
  this.setHeadersOnResponse(input, response);
312
337
  response.send(output);
313
338
  }
314
- async doFunctionRender(renderInput) {
315
- let result = await this.renderAndValidateOutput(renderInput, renderInput.manifest.type ?? "server");
339
+ async doFunctionRender(renderInput, ctx) {
340
+ let result = await this.renderAndValidateOutput(renderInput, renderInput.manifest.type ?? "server", ctx);
316
341
  if (renderInput.previewKey !== void 0) {
317
342
  result = await this.componentPreviewService.dressRenderedOutputForPreview(
318
343
  renderInput.manifest,
@@ -323,14 +348,14 @@ var DevelopmentController = class extends import_tsoa3.Controller {
323
348
  }
324
349
  return result;
325
350
  }
326
- async renderAndValidateOutput(renderInput, componentType) {
351
+ async renderAndValidateOutput(renderInput, componentType, ctx) {
327
352
  const executeComponentTask = {
328
353
  ...renderInput,
329
354
  args: [renderInput.input],
330
355
  manifest: renderInput.manifestForWeb,
331
356
  environment: renderInput.runtimeSet.environment
332
357
  };
333
- const result = componentType === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(executeComponentTask) : await this.componentRunnerService.executeServerComponentFunction(executeComponentTask);
358
+ const result = componentType === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(executeComponentTask, ctx) : await this.componentRunnerService.executeServerComponentFunction(executeComponentTask);
334
359
  try {
335
360
  this.componentFunctionService.assertOutputValidForComponentFunction(result, renderInput.componentFunction);
336
361
  } catch (e) {
@@ -389,14 +414,18 @@ __decorateClass([
389
414
  __decorateParam(2, (0, import_tsoa3.Path)()),
390
415
  __decorateParam(3, (0, import_tsoa3.Query)()),
391
416
  __decorateParam(4, (0, import_tsoa3.Query)()),
392
- __decorateParam(5, (0, import_tsoa3.Query)())
417
+ __decorateParam(5, (0, import_tsoa3.Query)()),
418
+ __decorateParam(6, (0, import_tsoa3.Query)()),
419
+ __decorateParam(7, (0, import_tsoa3.Query)())
393
420
  ], DevelopmentController.prototype, "TemporaryPreview", 1);
394
421
  __decorateClass([
395
422
  (0, import_tsoa3.Get)("/render/:componentId"),
396
423
  __decorateParam(0, (0, import_tsoa3.Request)()),
397
424
  __decorateParam(1, (0, import_tsoa3.Path)()),
398
425
  __decorateParam(2, (0, import_tsoa3.Query)("_componentSet")),
399
- __decorateParam(3, (0, import_tsoa3.Query)("_previewKey"))
426
+ __decorateParam(3, (0, import_tsoa3.Query)("_previewKey")),
427
+ __decorateParam(4, (0, import_tsoa3.Query)()),
428
+ __decorateParam(5, (0, import_tsoa3.Query)())
400
429
  ], DevelopmentController.prototype, "getDefaultFunctionRendering", 1);
401
430
  __decorateClass([
402
431
  (0, import_tsoa3.Get)("/render/:componentId/:functionName"),
@@ -404,7 +433,9 @@ __decorateClass([
404
433
  __decorateParam(1, (0, import_tsoa3.Path)()),
405
434
  __decorateParam(2, (0, import_tsoa3.Path)()),
406
435
  __decorateParam(3, (0, import_tsoa3.Query)("_componentSet")),
407
- __decorateParam(4, (0, import_tsoa3.Query)("_previewKey"))
436
+ __decorateParam(4, (0, import_tsoa3.Query)("_previewKey")),
437
+ __decorateParam(5, (0, import_tsoa3.Query)()),
438
+ __decorateParam(6, (0, import_tsoa3.Query)())
408
439
  ], DevelopmentController.prototype, "getGivenFunctionRendering", 1);
409
440
  DevelopmentController = __decorateClass([
410
441
  (0, import_inversify_binding_decorators2.provide)(DevelopmentController),
@@ -468,6 +499,11 @@ var models = {
468
499
  "additionalProperties": false
469
500
  },
470
501
  // 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
502
+ "UiMetadata": {
503
+ "dataType": "refAlias",
504
+ "type": { "dataType": "intersection", "subSchemas": [{ "dataType": "nestedObjectLiteral", "nestedProperties": { "autoReload": { "dataType": "boolean" } }, "additionalProperties": { "dataType": "any" } }, { "dataType": "union", "subSchemas": [{ "dataType": "nestedObjectLiteral", "nestedProperties": { "collapsedByDefault": { "dataType": "boolean" } } }, { "dataType": "nestedObjectLiteral", "nestedProperties": { "quickOption": { "dataType": "boolean" }, "inlineEditable": { "dataType": "boolean" } } }] }], "validators": {} }
505
+ },
506
+ // 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
471
507
  "CoreSchemaMetaSchema2": {
472
508
  "dataType": "refAlias",
473
509
  "type": { "dataType": "union", "subSchemas": [{ "dataType": "nestedObjectLiteral", "nestedProperties": { "not": { "ref": "CoreSchemaMetaSchema2" }, "oneOf": { "ref": "SchemaArray" }, "anyOf": { "ref": "SchemaArray" }, "allOf": { "ref": "SchemaArray" }, "else": { "ref": "CoreSchemaMetaSchema2" }, "then": { "ref": "CoreSchemaMetaSchema2" }, "if": { "ref": "CoreSchemaMetaSchema2" }, "contentEncoding": { "dataType": "string" }, "contentMediaType": { "dataType": "string" }, "matrixAssetTypes": { "dataType": "array", "array": { "dataType": "union", "subSchemas": [{ "dataType": "enum", "enums": ["audioFile"] }, { "dataType": "enum", "enums": ["bodycopyContainer"] }, { "dataType": "enum", "enums": ["bodycopyDiv"] }, { "dataType": "enum", "enums": ["calendarEventsSearchPage"] }, { "dataType": "enum", "enums": ["contentContainerTemplate"] }, { "dataType": "enum", "enums": ["contentTypeMarkdown"] }, { "dataType": "enum", "enums": ["contentTypeNestContent"] }, { "dataType": "enum", "enums": ["contentTypeRawHtml"] }, { "dataType": "enum", "enums": ["contentTypeSnippet"] }, { "dataType": "enum", "enums": ["contentTypeWysiwyg"] }, { "dataType": "enum", "enums": ["cssFileFolder"] }, { "dataType": "enum", "enums": ["cssFile"] }, { "dataType": "enum", "enums": ["customForm"] }, { "dataType": "enum", "enums": ["dataRecord"] }, { "dataType": "enum", "enums": ["designAreaAssetLineage"] }, { "dataType": "enum", "enums": ["designAreaBody"] }, { "dataType": "enum", "enums": ["designAreaMenuNormal"] }, { "dataType": "enum", "enums": ["designAreaNestContent"] }, { "dataType": "enum", "enums": ["designCssCustomisation"] }, { "dataType": "enum", "enums": ["designCss"] }, { "dataType": "enum", "enums": ["designCustomisation"] }, { "dataType": "enum", "enums": ["designScss"] }, { "dataType": "enum", "enums": ["design"] }, { "dataType": "enum", "enums": ["docx"] }, { "dataType": "enum", "enums": ["excelDoc"] }, { "dataType": "enum", "enums": ["file"] }, { "dataType": "enum", "enums": ["folder"] }, { "dataType": "enum", "enums": ["gitBridge"] }, { "dataType": "enum", "enums": ["googleAnalyticsConnector"] }, { "dataType": "enum", "enums": ["googleAnalyticsView"] }, { "dataType": "enum", "enums": ["image"] }, { "dataType": "enum", "enums": ["jsFileFolder"] }, { "dataType": "enum", "enums": ["jsFile"] }, { "dataType": "enum", "enums": ["jsonWebToken"] }, { "dataType": "enum", "enums": ["layoutManager"] }, { "dataType": "enum", "enums": ["layout"] }, { "dataType": "enum", "enums": ["link"] }, { "dataType": "enum", "enums": ["metadataFieldDate"] }, { "dataType": "enum", "enums": ["metadataFieldRelatedAsset"] }, { "dataType": "enum", "enums": ["metadataFieldSelect"] }, { "dataType": "enum", "enums": ["metadataFieldText"] }, { "dataType": "enum", "enums": ["metadataFieldWysiwyg"] }, { "dataType": "enum", "enums": ["metadataSchema"] }, { "dataType": "enum", "enums": ["metadataSection"] }, { "dataType": "enum", "enums": ["newsItem"] }, { "dataType": "enum", "enums": ["oauthAccountManager"] }, { "dataType": "enum", "enums": ["pageAccountManager"] }, { "dataType": "enum", "enums": ["pageAssetListing"] }, { "dataType": "enum", "enums": ["pageCalendarEventsSearch"] }, { "dataType": "enum", "enums": ["pageCalendar"] }, { "dataType": "enum", "enums": ["pagePasswordReset"] }, { "dataType": "enum", "enums": ["pageRemoteContent"] }, { "dataType": "enum", "enums": ["pageRestResourceJs"] }, { "dataType": "enum", "enums": ["pageRestResourceOauthSession"] }, { "dataType": "enum", "enums": ["pageRestResourceOauthTwoLegged"] }, { "dataType": "enum", "enums": ["pageRestResource"] }, { "dataType": "enum", "enums": ["pageSiteMap"] }, { "dataType": "enum", "enums": ["pageStandard"] }, { "dataType": "enum", "enums": ["paintLayoutBodycopy"] }, { "dataType": "enum", "enums": ["paintLayoutPage"] }, { "dataType": "enum", "enums": ["pdfFile"] }, { "dataType": "enum", "enums": ["pdf"] }, { "dataType": "enum", "enums": ["persona"] }, { "dataType": "enum", "enums": ["powerpointDoc"] }, { "dataType": "enum", "enums": ["pptx"] }, { "dataType": "enum", "enums": ["redirectPage"] }, { "dataType": "enum", "enums": ["regex"] }, { "dataType": "enum", "enums": ["regularExpression"] }, { "dataType": "enum", "enums": ["rtfFile"] }, { "dataType": "enum", "enums": ["samlAccountManager"] }, { "dataType": "enum", "enums": ["saml2Acs"] }, { "dataType": "enum", "enums": ["saml2Sls"] }, { "dataType": "enum", "enums": ["searchPage"] }, { "dataType": "enum", "enums": ["site"] }, { "dataType": "enum", "enums": ["textFile"] }, { "dataType": "enum", "enums": ["TriggerTypes?"] }, { "dataType": "enum", "enums": ["userGroup"] }, { "dataType": "enum", "enums": ["wordDoc"] }, { "dataType": "enum", "enums": ["workflowSchema"] }, { "dataType": "enum", "enums": ["workflowStepCondition"] }, { "dataType": "enum", "enums": ["workflowStep"] }, { "dataType": "enum", "enums": ["workflowStream"] }, { "dataType": "enum", "enums": ["xlsx"] }, { "dataType": "enum", "enums": ["xmlFile"] }] } }, "format": { "dataType": "union", "subSchemas": [{ "dataType": "enum", "enums": ["date-time"] }, { "dataType": "enum", "enums": ["email"] }, { "dataType": "enum", "enums": ["hostname"] }, { "dataType": "enum", "enums": ["ipv4"] }, { "dataType": "enum", "enums": ["ipv6"] }, { "dataType": "enum", "enums": ["json-pointer"] }, { "dataType": "enum", "enums": ["matrix-asset-uri"] }, { "dataType": "enum", "enums": ["multi-line"] }, { "dataType": "enum", "enums": ["password"] }, { "dataType": "enum", "enums": ["phone"] }, { "dataType": "enum", "enums": ["regex"] }, { "dataType": "enum", "enums": ["relative-json-pointer"] }, { "dataType": "enum", "enums": ["uri-reference"] }, { "dataType": "enum", "enums": ["uri-template"] }, { "dataType": "enum", "enums": ["uri"] }, { "dataType": "enum", "enums": ["uuid"] }] }, "type": { "dataType": "union", "subSchemas": [{ "dataType": "union", "subSchemas": [{ "dataType": "enum", "enums": ["array"] }, { "dataType": "enum", "enums": ["boolean"] }, { "dataType": "enum", "enums": ["integer"] }, { "dataType": "enum", "enums": ["null"] }, { "dataType": "enum", "enums": ["number"] }, { "dataType": "enum", "enums": ["object"] }, { "dataType": "enum", "enums": ["string"] }, { "dataType": "enum", "enums": ["FormattedText"] }, { "dataType": "enum", "enums": ["SquizImage"] }, { "dataType": "enum", "enums": ["SquizLink"] }] }, { "dataType": "array", "array": { "dataType": "union", "subSchemas": [{ "dataType": "enum", "enums": ["array"] }, { "dataType": "enum", "enums": ["boolean"] }, { "dataType": "enum", "enums": ["integer"] }, { "dataType": "enum", "enums": ["null"] }, { "dataType": "enum", "enums": ["number"] }, { "dataType": "enum", "enums": ["object"] }, { "dataType": "enum", "enums": ["string"] }, { "dataType": "enum", "enums": ["FormattedText"] }, { "dataType": "enum", "enums": ["SquizImage"] }, { "dataType": "enum", "enums": ["SquizLink"] }] } }] }, "enum": { "dataType": "array", "array": { "dataType": "enum", "enums": [true] }, "validators": { "minItems": { "value": 1 } } }, "const": { "dataType": "enum", "enums": [true] }, "propertyNames": { "ref": "CoreSchemaMetaSchema2" }, "dependencies": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "dataType": "union", "subSchemas": [{ "ref": "CoreSchemaMetaSchema2" }, { "ref": "StringArray" }] } }, "patternProperties": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "ref": "CoreSchemaMetaSchema2" } }, "properties": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "ref": "CoreSchemaMetaSchema2" } }, "definitions": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "ref": "CoreSchemaMetaSchema2" } }, "additionalProperties": { "ref": "CoreSchemaMetaSchema2" }, "required": { "ref": "StringArray" }, "minProperties": { "dataType": "intersection", "subSchemas": [{ "dataType": "double" }, { "dataType": "double" }] }, "maxProperties": { "dataType": "double" }, "contains": { "ref": "CoreSchemaMetaSchema2" }, "uniqueItems": { "dataType": "boolean" }, "minItems": { "dataType": "intersection", "subSchemas": [{ "dataType": "double" }, { "dataType": "double" }] }, "maxItems": { "dataType": "double" }, "items": { "dataType": "union", "subSchemas": [{ "ref": "CoreSchemaMetaSchema2" }, { "ref": "SchemaArray" }] }, "additionalItems": { "ref": "CoreSchemaMetaSchema2" }, "pattern": { "dataType": "string" }, "minLength": { "dataType": "intersection", "subSchemas": [{ "dataType": "double" }, { "dataType": "double" }] }, "maxLength": { "dataType": "double" }, "exclusiveMinimum": { "dataType": "double" }, "minimum": { "dataType": "double" }, "exclusiveMaximum": { "dataType": "double" }, "maximum": { "dataType": "double" }, "multipleOf": { "dataType": "double" }, "examples": { "dataType": "array", "array": { "dataType": "enum", "enums": [true] } }, "writeOnly": { "dataType": "boolean" }, "readOnly": { "dataType": "boolean" }, "default": { "dataType": "enum", "enums": [true] }, "description": { "dataType": "string" }, "title": { "dataType": "string" }, "$comment": { "dataType": "string" }, "$ref": { "dataType": "string" }, "$schema": { "dataType": "string" }, "ui:metadata": { "dataType": "union", "subSchemas": [{ "dataType": "nestedObjectLiteral", "nestedProperties": { "collapsedByDefault": { "dataType": "boolean" } } }, { "dataType": "nestedObjectLiteral", "nestedProperties": { "quickOption": { "dataType": "boolean" }, "inlineEditable": { "dataType": "boolean" } } }] }, "$id": { "dataType": "string" } } }, { "dataType": "boolean" }], "validators": {} }
@@ -487,7 +523,7 @@ var models = {
487
523
  "dataType": "refObject",
488
524
  "properties": {
489
525
  "$id": { "dataType": "string" },
490
- "ui:metadata": { "dataType": "union", "subSchemas": [{ "dataType": "nestedObjectLiteral", "nestedProperties": { "collapsedByDefault": { "dataType": "boolean" } } }, { "dataType": "nestedObjectLiteral", "nestedProperties": { "quickOption": { "dataType": "boolean" }, "inlineEditable": { "dataType": "boolean" } } }] },
526
+ "ui:metadata": { "ref": "UiMetadata" },
491
527
  "$schema": { "dataType": "string" },
492
528
  "$ref": { "dataType": "string" },
493
529
  "$comment": { "dataType": "string" },
@@ -843,7 +879,8 @@ var models = {
843
879
  "staticFiles": { "dataType": "nestedObjectLiteral", "nestedProperties": { "locationRoot": { "dataType": "string", "required": true } }, "additionalProperties": { "dataType": "any" } },
844
880
  "functions": { "dataType": "array", "array": { "dataType": "refObject", "ref": "ComponentFunction" }, "required": true, "validators": { "minItems": { "value": 0 } } },
845
881
  "previews": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "ref": "PreviewDefinition" } },
846
- "mockedUris": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "dataType": "union", "subSchemas": [{ "dataType": "nestedObjectLiteral", "nestedProperties": { "path": { "dataType": "string", "required": true }, "type": { "dataType": "enum", "enums": ["file"], "required": true } }, "additionalProperties": { "dataType": "any" } }, { "dataType": "nestedObjectLiteral", "nestedProperties": { "value": { "ref": "MatrixAssetSchema", "required": true }, "type": { "dataType": "enum", "enums": ["inline"], "required": true } }, "additionalProperties": { "dataType": "any" } }] } }
882
+ "mockedUris": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "additionalProperties": { "dataType": "union", "subSchemas": [{ "dataType": "nestedObjectLiteral", "nestedProperties": { "path": { "dataType": "string", "required": true }, "type": { "dataType": "enum", "enums": ["file"], "required": true } }, "additionalProperties": { "dataType": "any" } }, { "dataType": "nestedObjectLiteral", "nestedProperties": { "value": { "ref": "MatrixAssetSchema", "required": true }, "type": { "dataType": "enum", "enums": ["inline"], "required": true } }, "additionalProperties": { "dataType": "any" } }] } },
883
+ "ui:metadata": { "dataType": "nestedObjectLiteral", "nestedProperties": { "autoReload": { "dataType": "intersection", "subSchemas": [{ "dataType": "boolean" }, { "dataType": "string" }], "required": true } }, "additionalProperties": { "dataType": "any" } }
847
884
  },
848
885
  "additionalProperties": false
849
886
  },
@@ -985,7 +1022,9 @@ function RegisterRoutes(app) {
985
1022
  functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
986
1023
  headers: { "in": "query", "name": "headers", "dataType": "any" },
987
1024
  envVars: { "in": "query", "name": "envVars", "dataType": "any" },
988
- data: { "in": "query", "name": "data", "dataType": "any" }
1025
+ data: { "in": "query", "name": "data", "dataType": "any" },
1026
+ contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
1027
+ contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
989
1028
  };
990
1029
  let validatedArgs = [];
991
1030
  try {
@@ -1011,7 +1050,9 @@ function RegisterRoutes(app) {
1011
1050
  expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
1012
1051
  componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
1013
1052
  componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
1014
- previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" }
1053
+ previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
1054
+ contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
1055
+ contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
1015
1056
  };
1016
1057
  let validatedArgs = [];
1017
1058
  try {
@@ -1038,7 +1079,9 @@ function RegisterRoutes(app) {
1038
1079
  componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
1039
1080
  functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
1040
1081
  componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
1041
- previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" }
1082
+ previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
1083
+ contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
1084
+ contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
1042
1085
  };
1043
1086
  let validatedArgs = [];
1044
1087
  try {
@@ -1227,7 +1270,7 @@ var import_node_vm = __toESM(require("node:vm"));
1227
1270
  var import_os = require("os");
1228
1271
  var import_module = require("module");
1229
1272
  var DevelopmentComponentRunnerService = class {
1230
- async executeEdgeComponentFunction(task) {
1273
+ async executeEdgeComponentFunction(task, contextAwareness) {
1231
1274
  const webRequestEvents = await this.setUpWebRequestEventForResolveUri(task);
1232
1275
  const builtComponent = await esbuild.build({
1233
1276
  entryPoints: [task.functionEntryFilePath],
@@ -1245,7 +1288,7 @@ var DevelopmentComponentRunnerService = class {
1245
1288
  }
1246
1289
  throw new Error("Failed to build component");
1247
1290
  }
1248
- const componentContext = this.getComponentContext(task, webRequestEvents);
1291
+ const componentContext = this.getComponentContext(task, webRequestEvents, contextAwareness);
1249
1292
  const vmContext = import_node_vm.default.createContext({
1250
1293
  ...globalThis,
1251
1294
  module: {},
@@ -1314,7 +1357,7 @@ var DevelopmentComponentRunnerService = class {
1314
1357
  console.error("Error during esbuild transformation:", error);
1315
1358
  }
1316
1359
  }
1317
- getComponentContext(task, webRequestEvents) {
1360
+ getComponentContext(task, webRequestEvents, contextAwareness) {
1318
1361
  const ctxInput = {
1319
1362
  componentName: task.componentFullName,
1320
1363
  manifest: task.manifest,
@@ -1334,7 +1377,71 @@ var DevelopmentComponentRunnerService = class {
1334
1377
  previewKey: task.previewKey,
1335
1378
  queryParameters: task.queryParameters,
1336
1379
  ctx: (0, import_component_lib3.createComponentContextualFunctions)(ctxInput),
1337
- fns: (0, import_component_lib3.createComponentContextualFunctions)(ctxInput),
1380
+ fns: {
1381
+ ...(0, import_component_lib3.createComponentContextualFunctions)(ctxInput),
1382
+ resolveMatrixAssetById: function(assetId, attributes) {
1383
+ const mockAsset = {
1384
+ id: contextAwareness?.matrixAssetId ?? assetId,
1385
+ type: "page",
1386
+ type_name: "page",
1387
+ version: "1.0.0",
1388
+ name: "Mock Asset",
1389
+ short_name: "page",
1390
+ status: {
1391
+ code: "archived",
1392
+ id: 1
1393
+ },
1394
+ created: {
1395
+ user_id: "123",
1396
+ date: "2019-08-24T14:15:22Z"
1397
+ },
1398
+ updated: {
1399
+ user_id: "123",
1400
+ date: "2019-08-24T14:15:22Z"
1401
+ },
1402
+ published: {
1403
+ user_id: "123",
1404
+ date: "2019-08-24T14:15:22Z"
1405
+ },
1406
+ url: "",
1407
+ urls: [],
1408
+ attributes,
1409
+ additional: []
1410
+ };
1411
+ return mockAsset;
1412
+ },
1413
+ resolveMatrixAssetByUrl: function(url, attributes) {
1414
+ const mockAsset = {
1415
+ id: contextAwareness?.matrixUrl ?? url,
1416
+ type: "page",
1417
+ type_name: "page",
1418
+ version: "1.0.0",
1419
+ name: "Mock Asset",
1420
+ short_name: "page",
1421
+ status: {
1422
+ code: "archived",
1423
+ id: 1
1424
+ },
1425
+ created: {
1426
+ user_id: "123",
1427
+ date: "2019-08-24T14:15:22Z"
1428
+ },
1429
+ updated: {
1430
+ user_id: "123",
1431
+ date: "2019-08-24T14:15:22Z"
1432
+ },
1433
+ published: {
1434
+ user_id: "123",
1435
+ date: "2019-08-24T14:15:22Z"
1436
+ },
1437
+ url,
1438
+ urls: [],
1439
+ attributes,
1440
+ additional: {}
1441
+ };
1442
+ return mockAsset;
1443
+ }
1444
+ },
1338
1445
  env: task.runtimeSet.environment
1339
1446
  };
1340
1447
  return componentContext;