@squiz/edge-dev-render-runtime-lib 2.5.6 → 2.5.8

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.
@@ -37,7 +37,7 @@ export declare class RenderInputService {
37
37
  constructor(componentSetService: ComponentSetService, manifestService: ManifestService, componentFunctionService: ComponentFunctionService, rootUrlResolver: ComponentRootUrlResolver);
38
38
  resolveInput(request: RenderRequestInput): Promise<ComponentExecutionInput>;
39
39
  protected getQueryParametersFromRequest(request: RenderRequestInput, componentFunction: MANIFEST_MODELS.v1.ComponentFunction): QueryParameters;
40
- protected getPreviewRuntimeSet(manifest: ManifestV1, previewEnvVars?: Record<string, string>): {
40
+ getPreviewRuntimeSet(manifest: ManifestV1, previewEnvVars?: Record<string, string>): {
41
41
  webPath: string;
42
42
  displayName: string;
43
43
  environment: {
package/lib/index.js CHANGED
@@ -208,7 +208,7 @@ var DevelopmentComponentRunnerService = class {
208
208
  //Update to match edge
209
209
  ctx: {
210
210
  url: contextAwareness?.matrixUrl,
211
- assetId: contextAwareness?.matrixUrl,
211
+ assetId: contextAwareness?.matrixAssetId,
212
212
  ...(0, import_component_lib2.createComponentContextualFunctions)(ctxInput)
213
213
  },
214
214
  fns: {
@@ -597,12 +597,15 @@ var StaticController = class extends import_tsoa2.Controller {
597
597
  {
598
598
  root: staticFilePathRoot,
599
599
  dotfiles: "deny",
600
- lastModified: false
601
- // handle in DEVX-386
602
- //
603
- // maxAge: "1y",
604
- // immutable: true,
605
- // cacheControl: true
600
+ lastModified: true,
601
+ maxAge: 0,
602
+ cacheControl: true,
603
+ etag: false,
604
+ headers: {
605
+ "Cache-Control": "no-store, no-cache, must-revalidate, proxy-revalidate",
606
+ Pragma: "no-cache",
607
+ Expires: "0"
608
+ }
606
609
  },
607
610
  (e) => {
608
611
  if (req.next) {
@@ -632,15 +635,6 @@ var StaticController = class extends import_tsoa2.Controller {
632
635
  }
633
636
  setResponseHeaders(headers, response) {
634
637
  setHeadersOnExpressResponse(headers, response);
635
- let cacheControl = response.getHeader("cache-control");
636
- if (typeof cacheControl != "string") {
637
- cacheControl = import_dx_common_lib3.DEFAULT_CACHE_CONTROL_HEADER;
638
- }
639
- let cacheControlObj = (0, import_dx_common_lib3.parseCacheControl)(cacheControl);
640
- cacheControlObj = (0, import_dx_common_lib3.applyDefaultRulesToCacheControlObject)(cacheControlObj);
641
- cacheControlObj.immutable = true;
642
- cacheControlObj["max-age"] = 604800;
643
- response.setHeader("cache-control", (0, import_dx_common_lib3.cacheControlToString)(cacheControlObj));
644
638
  }
645
639
  async getHeadersForInputType(_componentSet, _previewKey, manifest) {
646
640
  if (_componentSet) {
@@ -2038,17 +2032,13 @@ var DevelopmentController = class extends import_tsoa3.Controller {
2038
2032
  });
2039
2033
  return schemaResult;
2040
2034
  }
2041
- async TemporaryPreview(req, componentId, functionName, headers, envVars, data, contextMatrixAssetId, contextMatrixUrl) {
2035
+ async TemporaryPreview(req, componentId, functionName, headers, _previewEnvVars, data, contextMatrixAssetId, contextMatrixUrl) {
2042
2036
  this.checkDevMode();
2043
2037
  const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
2044
2038
  const res = req.res;
2045
- const componentSet = {
2046
- environment: envVars ?? {},
2047
- displayName: componentName,
2048
- webPath: "mock-set"
2049
- };
2050
2039
  const rootUrl = `http://${req.headers.host}`.replace(/\/+$/, "");
2051
2040
  const componentManifest = await this.manifestService.loadManifest(namespace, componentName, version);
2041
+ const runtimeSet = this.renderInputService.getPreviewRuntimeSet(componentManifest, _previewEnvVars);
2052
2042
  const componentFunction = componentManifest.getComponentFunctionByName(functionName);
2053
2043
  if (hasSquizType(componentFunction)) {
2054
2044
  data = await resolveMock(componentFunction, data);
@@ -2058,12 +2048,12 @@ var DevelopmentController = class extends import_tsoa3.Controller {
2058
2048
  requestId: Date.now().toString(),
2059
2049
  args: [data],
2060
2050
  functionEntryFilePath: await componentManifest.getComponentFunctionEntryFilePath(componentFunction),
2061
- environment: componentSet.environment,
2051
+ environment: runtimeSet.environment,
2062
2052
  componentFullName: componentName,
2063
2053
  componentFunction,
2064
2054
  componentRootUrl: rootUrl,
2065
2055
  manifest: componentManifest.getModel(),
2066
- runtimeSet: componentSet,
2056
+ runtimeSet,
2067
2057
  manifestPath: await componentManifest.getManifestPath(),
2068
2058
  previewKey: defaultPreviewKey,
2069
2059
  queryParameters: void 0
@@ -2073,7 +2063,11 @@ var DevelopmentController = class extends import_tsoa3.Controller {
2073
2063
  matrixUrl: contextMatrixUrl
2074
2064
  };
2075
2065
  let result = componentManifest.type === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(componentTask, ctx) : await this.componentRunnerService.executeServerComponentFunction(componentTask);
2076
- const responseHeaders = headers ?? {};
2066
+ const manifestHeaders = componentFunction?.output?.headers ?? {};
2067
+ const responseHeaders = {
2068
+ ...headers,
2069
+ manifestHeaders
2070
+ };
2077
2071
  switch (componentFunction.output.responseType) {
2078
2072
  case "html":
2079
2073
  responseHeaders["content-type"] = "text/html";
@@ -2093,6 +2087,10 @@ var DevelopmentController = class extends import_tsoa3.Controller {
2093
2087
  result
2094
2088
  );
2095
2089
  }
2090
+ responseHeaders["Cache-Control"] = "no-store, no-cache, must-revalidate, proxy-revalidate";
2091
+ responseHeaders["Pragma"] = "no-cache";
2092
+ responseHeaders["Expires"] = "0";
2093
+ responseHeaders["Surrogate-Control"] = "no-store";
2096
2094
  setHeadersOnExpressResponse(responseHeaders ?? {}, res);
2097
2095
  res.send(result);
2098
2096
  }
@@ -2134,8 +2132,16 @@ var DevelopmentController = class extends import_tsoa3.Controller {
2134
2132
  expressRequest,
2135
2133
  functionName
2136
2134
  });
2137
- const renderedOutput = await this.doFunctionRender(renderInput, ctx);
2138
- this.handleResponse(renderInput, renderedOutput, response);
2135
+ const inputHeaders = expressRequest.query["headers"];
2136
+ const renderInputWithHeaders = {
2137
+ ...renderInput,
2138
+ headers: {
2139
+ ...renderInput.headers,
2140
+ ...inputHeaders
2141
+ }
2142
+ };
2143
+ const renderedOutput = await this.doFunctionRender(renderInputWithHeaders, ctx);
2144
+ this.handleResponse(renderInputWithHeaders, renderedOutput, response);
2139
2145
  }
2140
2146
  handleResponse(input, output, response) {
2141
2147
  this.setHeadersOnResponse(input, response);
@@ -2178,6 +2184,10 @@ var DevelopmentController = class extends import_tsoa3.Controller {
2178
2184
  }
2179
2185
  setHeadersOnResponse(renderInput, response) {
2180
2186
  const headers = renderInput.headers || {};
2187
+ headers["Cache-Control"] = "no-store, no-cache, must-revalidate, proxy-revalidate";
2188
+ headers["Pragma"] = "no-cache";
2189
+ headers["Expires"] = "0";
2190
+ headers["Surrogate-Control"] = "no-store";
2181
2191
  switch (renderInput.componentFunction.output.responseType) {
2182
2192
  case "html":
2183
2193
  headers["content-type"] = "text/html";
@@ -2187,11 +2197,6 @@ var DevelopmentController = class extends import_tsoa3.Controller {
2187
2197
  break;
2188
2198
  }
2189
2199
  setHeadersOnExpressResponse(headers, response);
2190
- let cacheControl = response.getHeader("cache-control");
2191
- if (typeof cacheControl !== "string") {
2192
- cacheControl = void 0;
2193
- }
2194
- response.setHeader("cache-control", (0, import_dx_common_lib4.parseAndSanitiseCacheControlHeader)(cacheControl));
2195
2200
  }
2196
2201
  //This should be middle ware.
2197
2202
  async checkDevMode() {
@@ -2890,7 +2895,7 @@ function RegisterRoutes(app) {
2890
2895
  componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
2891
2896
  functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
2892
2897
  headers: { "in": "query", "name": "headers", "dataType": "any" },
2893
- envVars: { "in": "query", "name": "envVars", "dataType": "any" },
2898
+ _previewEnvVars: { "in": "query", "name": "_previewEnvVars", "dataType": "any" },
2894
2899
  data: { "in": "query", "name": "data", "dataType": "any" },
2895
2900
  contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
2896
2901
  contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }