@squiz/edge-dev-render-runtime-lib 2.5.7 → 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
|
-
|
|
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?.
|
|
211
|
+
assetId: contextAwareness?.matrixAssetId,
|
|
212
212
|
...(0, import_component_lib2.createComponentContextualFunctions)(ctxInput)
|
|
213
213
|
},
|
|
214
214
|
fns: {
|
|
@@ -2032,17 +2032,13 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
2032
2032
|
});
|
|
2033
2033
|
return schemaResult;
|
|
2034
2034
|
}
|
|
2035
|
-
async TemporaryPreview(req, componentId, functionName, headers,
|
|
2035
|
+
async TemporaryPreview(req, componentId, functionName, headers, _previewEnvVars, data, contextMatrixAssetId, contextMatrixUrl) {
|
|
2036
2036
|
this.checkDevMode();
|
|
2037
2037
|
const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
|
|
2038
2038
|
const res = req.res;
|
|
2039
|
-
const componentSet = {
|
|
2040
|
-
environment: envVars ?? {},
|
|
2041
|
-
displayName: componentName,
|
|
2042
|
-
webPath: "mock-set"
|
|
2043
|
-
};
|
|
2044
2039
|
const rootUrl = `http://${req.headers.host}`.replace(/\/+$/, "");
|
|
2045
2040
|
const componentManifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
2041
|
+
const runtimeSet = this.renderInputService.getPreviewRuntimeSet(componentManifest, _previewEnvVars);
|
|
2046
2042
|
const componentFunction = componentManifest.getComponentFunctionByName(functionName);
|
|
2047
2043
|
if (hasSquizType(componentFunction)) {
|
|
2048
2044
|
data = await resolveMock(componentFunction, data);
|
|
@@ -2052,12 +2048,12 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
2052
2048
|
requestId: Date.now().toString(),
|
|
2053
2049
|
args: [data],
|
|
2054
2050
|
functionEntryFilePath: await componentManifest.getComponentFunctionEntryFilePath(componentFunction),
|
|
2055
|
-
environment:
|
|
2051
|
+
environment: runtimeSet.environment,
|
|
2056
2052
|
componentFullName: componentName,
|
|
2057
2053
|
componentFunction,
|
|
2058
2054
|
componentRootUrl: rootUrl,
|
|
2059
2055
|
manifest: componentManifest.getModel(),
|
|
2060
|
-
runtimeSet
|
|
2056
|
+
runtimeSet,
|
|
2061
2057
|
manifestPath: await componentManifest.getManifestPath(),
|
|
2062
2058
|
previewKey: defaultPreviewKey,
|
|
2063
2059
|
queryParameters: void 0
|
|
@@ -2067,7 +2063,11 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
2067
2063
|
matrixUrl: contextMatrixUrl
|
|
2068
2064
|
};
|
|
2069
2065
|
let result = componentManifest.type === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(componentTask, ctx) : await this.componentRunnerService.executeServerComponentFunction(componentTask);
|
|
2070
|
-
const
|
|
2066
|
+
const manifestHeaders = componentFunction?.output?.headers ?? {};
|
|
2067
|
+
const responseHeaders = {
|
|
2068
|
+
...headers,
|
|
2069
|
+
manifestHeaders
|
|
2070
|
+
};
|
|
2071
2071
|
switch (componentFunction.output.responseType) {
|
|
2072
2072
|
case "html":
|
|
2073
2073
|
responseHeaders["content-type"] = "text/html";
|
|
@@ -2132,8 +2132,16 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
2132
2132
|
expressRequest,
|
|
2133
2133
|
functionName
|
|
2134
2134
|
});
|
|
2135
|
-
const
|
|
2136
|
-
|
|
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);
|
|
2137
2145
|
}
|
|
2138
2146
|
handleResponse(input, output, response) {
|
|
2139
2147
|
this.setHeadersOnResponse(input, response);
|
|
@@ -2887,7 +2895,7 @@ function RegisterRoutes(app) {
|
|
|
2887
2895
|
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2888
2896
|
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
2889
2897
|
headers: { "in": "query", "name": "headers", "dataType": "any" },
|
|
2890
|
-
|
|
2898
|
+
_previewEnvVars: { "in": "query", "name": "_previewEnvVars", "dataType": "any" },
|
|
2891
2899
|
data: { "in": "query", "name": "data", "dataType": "any" },
|
|
2892
2900
|
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2893
2901
|
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|