@squiz/edge-dev-render-runtime-lib 2.5.3 → 2.5.5
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/index.js +475 -471
- package/lib/index.js.map +4 -4
- package/lib/public/docs.json +43 -43
- package/lib/webserver/controllers/DevelopmentController.d.ts +3 -3
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -80,128 +80,177 @@ var import_dx_common_lib4 = require("@squiz/dx-common-lib");
|
|
|
80
80
|
// src/webserver/routes/routes.ts
|
|
81
81
|
var import_runtime4 = require("@tsoa/runtime");
|
|
82
82
|
|
|
83
|
-
// src/webserver/controllers/
|
|
84
|
-
var import_tsoa2 = require("tsoa");
|
|
85
|
-
|
|
86
|
-
// src/webserver/controllers/BaseController.ts
|
|
83
|
+
// src/webserver/controllers/StaticController.ts
|
|
87
84
|
var import_tsoa = require("tsoa");
|
|
88
|
-
var BaseController = class extends import_tsoa.Controller {
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// src/webserver/controllers/CoreController.ts
|
|
92
85
|
var import_inversify_binding_decorators = require("inversify-binding-decorators");
|
|
93
|
-
var import_inversify = require("inversify");
|
|
94
86
|
var import_dx_common_lib = require("@squiz/dx-common-lib");
|
|
95
|
-
var
|
|
87
|
+
var import_path = __toESM(require("path"));
|
|
88
|
+
var import_inversify = require("inversify");
|
|
89
|
+
var import_assert = __toESM(require("assert"));
|
|
96
90
|
|
|
97
|
-
// src/utils/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
// src/utils/setHeadersOnExpressResponse.ts
|
|
92
|
+
function setHeadersOnExpressResponse(headers, response) {
|
|
93
|
+
for (const [headerName, headerValue] of Object.entries(headers)) {
|
|
94
|
+
if (headerValue) {
|
|
95
|
+
response.setHeader(headerName, headerValue);
|
|
96
|
+
} else {
|
|
97
|
+
response.removeHeader(headerName);
|
|
98
|
+
}
|
|
103
99
|
}
|
|
104
|
-
return {
|
|
105
|
-
namespace: parts[0],
|
|
106
|
-
componentName: parts[1],
|
|
107
|
-
version: parts[2]
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function getComponentIdFromComponentManifest(manifest) {
|
|
111
|
-
return `${manifest.getNamespace()}${SEPARATOR}${manifest.getModel().name}${SEPARATOR}${manifest.getVersion()}`;
|
|
112
100
|
}
|
|
113
101
|
|
|
114
|
-
// src/webserver/controllers/
|
|
115
|
-
var
|
|
116
|
-
constructor(manifestService) {
|
|
102
|
+
// src/webserver/controllers/StaticController.ts
|
|
103
|
+
var StaticController = class extends import_tsoa.Controller {
|
|
104
|
+
constructor(manifestService, componentSetService, componentFunctionService) {
|
|
117
105
|
super();
|
|
118
106
|
this.manifestService = manifestService;
|
|
107
|
+
this.componentSetService = componentSetService;
|
|
108
|
+
this.componentFunctionService = componentFunctionService;
|
|
119
109
|
}
|
|
120
|
-
async
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
async getPreview(namespace, componentName, version, staticFile, req, _componentSet, _previewKey) {
|
|
111
|
+
if (_componentSet !== void 0 && _previewKey !== void 0) {
|
|
112
|
+
throw new import_dx_common_lib.BadRequestError("You can not have both _componentSet and _previewKey");
|
|
113
|
+
}
|
|
114
|
+
const manifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
115
|
+
const manifestModel = manifest.getModel();
|
|
116
|
+
const response = req.res;
|
|
117
|
+
(0, import_assert.default)(response);
|
|
118
|
+
staticFile = import_path.default.join(staticFile, req.params[0]);
|
|
119
|
+
if (manifestModel.staticFiles) {
|
|
120
|
+
const componentStaticFileRoot = manifestModel.staticFiles.locationRoot;
|
|
121
|
+
const manifestPath = await this.manifestService.getManifestPath(namespace, componentName, version);
|
|
122
|
+
const staticFilePathRoot = import_path.default.join(import_path.default.dirname(manifestPath), componentStaticFileRoot);
|
|
123
|
+
const headers = await this.getHeadersForInputType(_componentSet, _previewKey, manifest);
|
|
124
|
+
this.setResponseHeaders(headers, response);
|
|
125
|
+
response.sendFile(
|
|
126
|
+
staticFile,
|
|
127
|
+
{
|
|
128
|
+
root: staticFilePathRoot,
|
|
129
|
+
dotfiles: "deny",
|
|
130
|
+
lastModified: false
|
|
131
|
+
// handle in DEVX-386
|
|
132
|
+
//
|
|
133
|
+
// maxAge: "1y",
|
|
134
|
+
// immutable: true,
|
|
135
|
+
// cacheControl: true
|
|
136
|
+
},
|
|
137
|
+
(e) => {
|
|
138
|
+
if (req.next) {
|
|
139
|
+
if (e?.code == "ENOENT") {
|
|
140
|
+
req.next(
|
|
141
|
+
new import_dx_common_lib.ResourceNotFoundError(
|
|
142
|
+
`could not find ${e?.path.substr(
|
|
143
|
+
e?.path.indexOf(componentStaticFileRoot) + componentStaticFileRoot.length
|
|
144
|
+
)}`
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
} else if (e) {
|
|
148
|
+
req.next(e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
await new Promise((resolve, _reject) => {
|
|
154
|
+
response.on("finish", () => {
|
|
155
|
+
response.end();
|
|
156
|
+
resolve();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
throw new import_dx_common_lib.ResourceNotFoundError(`${componentName} ${version} doesn't expose any static resources`);
|
|
124
161
|
}
|
|
125
|
-
return schema;
|
|
126
162
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
163
|
+
setResponseHeaders(headers, response) {
|
|
164
|
+
setHeadersOnExpressResponse(headers, response);
|
|
165
|
+
let cacheControl = response.getHeader("cache-control");
|
|
166
|
+
if (typeof cacheControl != "string") {
|
|
167
|
+
cacheControl = import_dx_common_lib.DEFAULT_CACHE_CONTROL_HEADER;
|
|
168
|
+
}
|
|
169
|
+
let cacheControlObj = (0, import_dx_common_lib.parseCacheControl)(cacheControl);
|
|
170
|
+
cacheControlObj = (0, import_dx_common_lib.applyDefaultRulesToCacheControlObject)(cacheControlObj);
|
|
171
|
+
cacheControlObj.immutable = true;
|
|
172
|
+
cacheControlObj["max-age"] = 604800;
|
|
173
|
+
response.setHeader("cache-control", (0, import_dx_common_lib.cacheControlToString)(cacheControlObj));
|
|
133
174
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
groups[componentName].components.push({
|
|
148
|
-
id: getComponentIdFromComponentManifest(manifest),
|
|
149
|
-
version: manifest.getVersion(),
|
|
150
|
-
previewKey: currentPrimaryKey
|
|
151
|
-
});
|
|
152
|
-
return groups;
|
|
153
|
-
}, {});
|
|
175
|
+
async getHeadersForInputType(_componentSet, _previewKey, manifest) {
|
|
176
|
+
if (_componentSet) {
|
|
177
|
+
const set = await this.getValidatedSet(_componentSet, manifest);
|
|
178
|
+
return set.headers;
|
|
179
|
+
}
|
|
180
|
+
if (_previewKey) {
|
|
181
|
+
const previewDefinition = await this.getValidatedPreviewDefinition(_previewKey, manifest.getModel());
|
|
182
|
+
const functionPreview = previewDefinition.functionData[manifest.getModel().mainFunction];
|
|
183
|
+
const headers = functionPreview?.headers ? functionPreview.headers : {};
|
|
184
|
+
return headers;
|
|
185
|
+
}
|
|
186
|
+
throw new import_dx_common_lib.BadRequestError(`neither componentSet or previewKey set`);
|
|
154
187
|
}
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
async getValidatedSet(_componentSet, manifest) {
|
|
189
|
+
const set = await this.componentSetService.getComponentSet(_componentSet);
|
|
190
|
+
const isCompVersionInSet = this.componentSetService.componentVersionInSet(manifest, set.webPath);
|
|
191
|
+
if (!isCompVersionInSet) {
|
|
192
|
+
throw new import_dx_common_lib.ResourceNotFoundError(`${manifest.getName()} ${manifest.getVersion()} not in set ${set.webPath}`);
|
|
193
|
+
}
|
|
194
|
+
return set;
|
|
195
|
+
}
|
|
196
|
+
async getValidatedPreviewDefinition(_previewKey, manifestModel) {
|
|
197
|
+
const { previews = {} } = manifestModel;
|
|
198
|
+
const previewDefinition = previews[_previewKey];
|
|
199
|
+
if (previewDefinition === void 0) {
|
|
200
|
+
const validPreviewKeys = Object.keys(previews);
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Component has not defined preview with key "${_previewKey}", the defined preview keys for this component are "${validPreviewKeys.join(
|
|
203
|
+
", "
|
|
204
|
+
)}"`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return previewDefinition;
|
|
169
208
|
}
|
|
170
209
|
};
|
|
171
210
|
__decorateClass([
|
|
172
|
-
(0,
|
|
173
|
-
__decorateParam(0, (0,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
(0,
|
|
177
|
-
__decorateParam(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
211
|
+
(0, import_tsoa.Get)("/:namespace/:componentName/:version/:staticFile*"),
|
|
212
|
+
__decorateParam(0, (0, import_tsoa.Path)()),
|
|
213
|
+
__decorateParam(1, (0, import_tsoa.Path)()),
|
|
214
|
+
__decorateParam(2, (0, import_tsoa.Path)()),
|
|
215
|
+
__decorateParam(3, (0, import_tsoa.Path)()),
|
|
216
|
+
__decorateParam(4, (0, import_tsoa.Request)()),
|
|
217
|
+
__decorateParam(5, (0, import_tsoa.Query)()),
|
|
218
|
+
__decorateParam(6, (0, import_tsoa.Query)())
|
|
219
|
+
], StaticController.prototype, "getPreview", 1);
|
|
220
|
+
StaticController = __decorateClass([
|
|
221
|
+
(0, import_inversify_binding_decorators.provide)(StaticController),
|
|
222
|
+
(0, import_tsoa.Route)("/s"),
|
|
223
|
+
__decorateParam(0, (0, import_inversify.inject)("ManifestService")),
|
|
224
|
+
__decorateParam(1, (0, import_inversify.inject)("ComponentSetService")),
|
|
225
|
+
__decorateParam(2, (0, import_inversify.inject)("ComponentFunctionService"))
|
|
226
|
+
], StaticController);
|
|
184
227
|
|
|
185
228
|
// src/webserver/controllers/DevelopmentController.ts
|
|
186
|
-
var
|
|
229
|
+
var import_tsoa2 = require("tsoa");
|
|
187
230
|
var import_inversify_binding_decorators2 = require("inversify-binding-decorators");
|
|
188
231
|
var import_inversify2 = require("inversify");
|
|
189
232
|
var import_component_lib = require("@squiz/component-lib");
|
|
190
233
|
var import_dx_common_lib2 = require("@squiz/dx-common-lib");
|
|
191
234
|
|
|
192
|
-
// src/utils/
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
response.removeHeader(headerName);
|
|
199
|
-
}
|
|
235
|
+
// src/utils/getComponentInfoFromComponentId.ts
|
|
236
|
+
var SEPARATOR = "__";
|
|
237
|
+
function getComponentInfoFromComponentId(path7) {
|
|
238
|
+
const parts = path7.split(SEPARATOR);
|
|
239
|
+
if (parts.length !== 3) {
|
|
240
|
+
throw Error(`Invalid component identifier path: ${path7}`);
|
|
200
241
|
}
|
|
242
|
+
return {
|
|
243
|
+
namespace: parts[0],
|
|
244
|
+
componentName: parts[1],
|
|
245
|
+
version: parts[2]
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function getComponentIdFromComponentManifest(manifest) {
|
|
249
|
+
return `${manifest.getNamespace()}${SEPARATOR}${manifest.getModel().name}${SEPARATOR}${manifest.getVersion()}`;
|
|
201
250
|
}
|
|
202
251
|
|
|
203
252
|
// src/webserver/controllers/utils/ReplaceWithMock.ts
|
|
204
|
-
var
|
|
253
|
+
var import_dx_json_schema_lib = require("@squiz/dx-json-schema-lib");
|
|
205
254
|
|
|
206
255
|
// src/webserver/controllers/mocks/mockResources.ts
|
|
207
256
|
var resources = [
|
|
@@ -1452,7 +1501,7 @@ var resources = [
|
|
|
1452
1501
|
];
|
|
1453
1502
|
|
|
1454
1503
|
// src/webserver/controllers/utils/ReplaceWithMock.ts
|
|
1455
|
-
var typeResolver =
|
|
1504
|
+
var typeResolver = import_dx_json_schema_lib.TypeResolverBuilder.new().addPrimitive(import_dx_json_schema_lib.SquizImageType).addPrimitive(import_dx_json_schema_lib.SquizLinkType).addPrimitive(import_dx_json_schema_lib.FormattedTextType).addResolver(import_dx_json_schema_lib.SquizImageType, import_dx_json_schema_lib.MatrixAssetType, ({ matrixAssetId }) => {
|
|
1456
1505
|
const resource = resources.find((resource2) => resource2.id == matrixAssetId);
|
|
1457
1506
|
return {
|
|
1458
1507
|
...resource["squizImage"]
|
|
@@ -1478,14 +1527,14 @@ async function resolveMock(componentSchema, data) {
|
|
|
1478
1527
|
if (!inputSchema || typeof inputSchema !== "object" || !inputSchema.properties) {
|
|
1479
1528
|
return componentSchema;
|
|
1480
1529
|
}
|
|
1481
|
-
const jsonSchemaService = new
|
|
1530
|
+
const jsonSchemaService = new import_dx_json_schema_lib.JSONSchemaService(typeResolver, import_dx_json_schema_lib.ComponentInputMetaSchema);
|
|
1482
1531
|
const resolvedInput = await jsonSchemaService.resolveInput(data, inputSchema);
|
|
1483
1532
|
return resolvedInput;
|
|
1484
1533
|
}
|
|
1485
1534
|
|
|
1486
1535
|
// src/webserver/controllers/DevelopmentController.ts
|
|
1487
1536
|
var UPPERCASE_REGEX = /[A-Z]/;
|
|
1488
|
-
var DevelopmentController = class extends
|
|
1537
|
+
var DevelopmentController = class extends import_tsoa2.Controller {
|
|
1489
1538
|
constructor(config, manifestService, componentRunnerService, renderInputService, componentPreviewService, componentFunctionService) {
|
|
1490
1539
|
super();
|
|
1491
1540
|
this.config = config;
|
|
@@ -1519,7 +1568,7 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
1519
1568
|
});
|
|
1520
1569
|
return schemaResult;
|
|
1521
1570
|
}
|
|
1522
|
-
async TemporaryPreview(req, componentId, functionName,
|
|
1571
|
+
async TemporaryPreview(req, componentId, functionName, headers, envVars, data, contextMatrixAssetId, contextMatrixUrl) {
|
|
1523
1572
|
this.checkDevMode();
|
|
1524
1573
|
const { namespace, componentName, version } = getComponentInfoFromComponentId(componentId);
|
|
1525
1574
|
const res = req.res;
|
|
@@ -1554,7 +1603,7 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
1554
1603
|
matrixUrl: contextMatrixUrl
|
|
1555
1604
|
};
|
|
1556
1605
|
let result = componentManifest.type === "edge" ? await this.componentRunnerService.executeEdgeComponentFunction(componentTask, ctx) : await this.componentRunnerService.executeServerComponentFunction(componentTask);
|
|
1557
|
-
const responseHeaders =
|
|
1606
|
+
const responseHeaders = headers ?? {};
|
|
1558
1607
|
switch (componentFunction.output.responseType) {
|
|
1559
1608
|
case "html":
|
|
1560
1609
|
responseHeaders["content-type"] = "text/html";
|
|
@@ -1658,16 +1707,16 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
1658
1707
|
return result;
|
|
1659
1708
|
}
|
|
1660
1709
|
setHeadersOnResponse(renderInput, response) {
|
|
1661
|
-
const
|
|
1710
|
+
const headers = renderInput.headers || {};
|
|
1662
1711
|
switch (renderInput.componentFunction.output.responseType) {
|
|
1663
1712
|
case "html":
|
|
1664
|
-
|
|
1713
|
+
headers["content-type"] = "text/html";
|
|
1665
1714
|
break;
|
|
1666
1715
|
case "json":
|
|
1667
|
-
|
|
1716
|
+
headers["content-type"] = "application/json";
|
|
1668
1717
|
break;
|
|
1669
1718
|
}
|
|
1670
|
-
setHeadersOnExpressResponse(
|
|
1719
|
+
setHeadersOnExpressResponse(headers, response);
|
|
1671
1720
|
let cacheControl = response.getHeader("cache-control");
|
|
1672
1721
|
if (typeof cacheControl !== "string") {
|
|
1673
1722
|
cacheControl = void 0;
|
|
@@ -1682,51 +1731,51 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
1682
1731
|
}
|
|
1683
1732
|
};
|
|
1684
1733
|
__decorateClass([
|
|
1685
|
-
(0,
|
|
1734
|
+
(0, import_tsoa2.Get)("/all")
|
|
1686
1735
|
], DevelopmentController.prototype, "getComponents", 1);
|
|
1687
1736
|
__decorateClass([
|
|
1688
|
-
(0,
|
|
1689
|
-
__decorateParam(0, (0,
|
|
1737
|
+
(0, import_tsoa2.Get)("/manifest/:componentId"),
|
|
1738
|
+
__decorateParam(0, (0, import_tsoa2.Path)())
|
|
1690
1739
|
], DevelopmentController.prototype, "Manifest", 1);
|
|
1691
1740
|
__decorateClass([
|
|
1692
|
-
(0,
|
|
1693
|
-
__decorateParam(0, (0,
|
|
1741
|
+
(0, import_tsoa2.Get)("/schemas/:componentId"),
|
|
1742
|
+
__decorateParam(0, (0, import_tsoa2.Path)())
|
|
1694
1743
|
], DevelopmentController.prototype, "getContentSchema", 1);
|
|
1695
1744
|
__decorateClass([
|
|
1696
|
-
(0,
|
|
1697
|
-
(0,
|
|
1698
|
-
__decorateParam(0, (0,
|
|
1699
|
-
__decorateParam(1, (0,
|
|
1700
|
-
__decorateParam(2, (0,
|
|
1701
|
-
__decorateParam(3, (0,
|
|
1702
|
-
__decorateParam(4, (0,
|
|
1703
|
-
__decorateParam(5, (0,
|
|
1704
|
-
__decorateParam(6, (0,
|
|
1705
|
-
__decorateParam(7, (0,
|
|
1745
|
+
(0, import_tsoa2.Get)("/temp-preview/:componentId/:functionName"),
|
|
1746
|
+
(0, import_tsoa2.Produces)("text/html"),
|
|
1747
|
+
__decorateParam(0, (0, import_tsoa2.Request)()),
|
|
1748
|
+
__decorateParam(1, (0, import_tsoa2.Path)()),
|
|
1749
|
+
__decorateParam(2, (0, import_tsoa2.Path)()),
|
|
1750
|
+
__decorateParam(3, (0, import_tsoa2.Query)()),
|
|
1751
|
+
__decorateParam(4, (0, import_tsoa2.Query)()),
|
|
1752
|
+
__decorateParam(5, (0, import_tsoa2.Query)()),
|
|
1753
|
+
__decorateParam(6, (0, import_tsoa2.Query)()),
|
|
1754
|
+
__decorateParam(7, (0, import_tsoa2.Query)())
|
|
1706
1755
|
], DevelopmentController.prototype, "TemporaryPreview", 1);
|
|
1707
1756
|
__decorateClass([
|
|
1708
|
-
(0,
|
|
1709
|
-
__decorateParam(0, (0,
|
|
1710
|
-
__decorateParam(1, (0,
|
|
1711
|
-
__decorateParam(2, (0,
|
|
1712
|
-
__decorateParam(3, (0,
|
|
1713
|
-
__decorateParam(4, (0,
|
|
1714
|
-
__decorateParam(5, (0,
|
|
1757
|
+
(0, import_tsoa2.Get)("/render/:componentId"),
|
|
1758
|
+
__decorateParam(0, (0, import_tsoa2.Request)()),
|
|
1759
|
+
__decorateParam(1, (0, import_tsoa2.Path)()),
|
|
1760
|
+
__decorateParam(2, (0, import_tsoa2.Query)("_componentSet")),
|
|
1761
|
+
__decorateParam(3, (0, import_tsoa2.Query)("_previewKey")),
|
|
1762
|
+
__decorateParam(4, (0, import_tsoa2.Query)()),
|
|
1763
|
+
__decorateParam(5, (0, import_tsoa2.Query)())
|
|
1715
1764
|
], DevelopmentController.prototype, "getDefaultFunctionRendering", 1);
|
|
1716
1765
|
__decorateClass([
|
|
1717
|
-
(0,
|
|
1718
|
-
__decorateParam(0, (0,
|
|
1719
|
-
__decorateParam(1, (0,
|
|
1720
|
-
__decorateParam(2, (0,
|
|
1721
|
-
__decorateParam(3, (0,
|
|
1722
|
-
__decorateParam(4, (0,
|
|
1723
|
-
__decorateParam(5, (0,
|
|
1724
|
-
__decorateParam(6, (0,
|
|
1766
|
+
(0, import_tsoa2.Get)("/render/:componentId/:functionName"),
|
|
1767
|
+
__decorateParam(0, (0, import_tsoa2.Request)()),
|
|
1768
|
+
__decorateParam(1, (0, import_tsoa2.Path)()),
|
|
1769
|
+
__decorateParam(2, (0, import_tsoa2.Path)()),
|
|
1770
|
+
__decorateParam(3, (0, import_tsoa2.Query)("_componentSet")),
|
|
1771
|
+
__decorateParam(4, (0, import_tsoa2.Query)("_previewKey")),
|
|
1772
|
+
__decorateParam(5, (0, import_tsoa2.Query)()),
|
|
1773
|
+
__decorateParam(6, (0, import_tsoa2.Query)())
|
|
1725
1774
|
], DevelopmentController.prototype, "getGivenFunctionRendering", 1);
|
|
1726
1775
|
DevelopmentController = __decorateClass([
|
|
1727
1776
|
(0, import_inversify_binding_decorators2.provide)(DevelopmentController),
|
|
1728
|
-
(0,
|
|
1729
|
-
(0,
|
|
1777
|
+
(0, import_tsoa2.Route)("/dev"),
|
|
1778
|
+
(0, import_tsoa2.Hidden)(),
|
|
1730
1779
|
__decorateParam(0, (0, import_inversify2.inject)("Config")),
|
|
1731
1780
|
__decorateParam(1, (0, import_inversify2.inject)("ManifestService")),
|
|
1732
1781
|
__decorateParam(2, (0, import_inversify2.inject)("DevelopmentComponentRunnerService")),
|
|
@@ -1735,137 +1784,88 @@ DevelopmentController = __decorateClass([
|
|
|
1735
1784
|
__decorateParam(5, (0, import_inversify2.inject)("ComponentFunctionService"))
|
|
1736
1785
|
], DevelopmentController);
|
|
1737
1786
|
|
|
1738
|
-
// src/webserver/controllers/
|
|
1787
|
+
// src/webserver/controllers/CoreController.ts
|
|
1739
1788
|
var import_tsoa4 = require("tsoa");
|
|
1789
|
+
|
|
1790
|
+
// src/webserver/controllers/BaseController.ts
|
|
1791
|
+
var import_tsoa3 = require("tsoa");
|
|
1792
|
+
var BaseController = class extends import_tsoa3.Controller {
|
|
1793
|
+
};
|
|
1794
|
+
|
|
1795
|
+
// src/webserver/controllers/CoreController.ts
|
|
1740
1796
|
var import_inversify_binding_decorators3 = require("inversify-binding-decorators");
|
|
1741
|
-
var import_dx_common_lib3 = require("@squiz/dx-common-lib");
|
|
1742
|
-
var import_path = __toESM(require("path"));
|
|
1743
1797
|
var import_inversify3 = require("inversify");
|
|
1744
|
-
var
|
|
1745
|
-
var
|
|
1746
|
-
|
|
1798
|
+
var import_dx_common_lib3 = require("@squiz/dx-common-lib");
|
|
1799
|
+
var import_dx_json_schema_lib2 = require("@squiz/dx-json-schema-lib");
|
|
1800
|
+
var CoreController = class extends BaseController {
|
|
1801
|
+
constructor(manifestService) {
|
|
1747
1802
|
super();
|
|
1748
1803
|
this.manifestService = manifestService;
|
|
1749
|
-
this.componentSetService = componentSetService;
|
|
1750
|
-
this.componentFunctionService = componentFunctionService;
|
|
1751
1804
|
}
|
|
1752
|
-
async
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
const manifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
1757
|
-
const manifestModel = manifest.getModel();
|
|
1758
|
-
const response = req.res;
|
|
1759
|
-
(0, import_assert.default)(response);
|
|
1760
|
-
staticFile = import_path.default.join(staticFile, req.params[0]);
|
|
1761
|
-
if (manifestModel.staticFiles) {
|
|
1762
|
-
const componentStaticFileRoot = manifestModel.staticFiles.locationRoot;
|
|
1763
|
-
const manifestPath = await this.manifestService.getManifestPath(namespace, componentName, version);
|
|
1764
|
-
const staticFilePathRoot = import_path.default.join(import_path.default.dirname(manifestPath), componentStaticFileRoot);
|
|
1765
|
-
const headers3 = await this.getHeadersForInputType(_componentSet, _previewKey, manifest);
|
|
1766
|
-
this.setResponseHeaders(headers3, response);
|
|
1767
|
-
response.sendFile(
|
|
1768
|
-
staticFile,
|
|
1769
|
-
{
|
|
1770
|
-
root: staticFilePathRoot,
|
|
1771
|
-
dotfiles: "deny",
|
|
1772
|
-
lastModified: false
|
|
1773
|
-
// handle in DEVX-386
|
|
1774
|
-
//
|
|
1775
|
-
// maxAge: "1y",
|
|
1776
|
-
// immutable: true,
|
|
1777
|
-
// cacheControl: true
|
|
1778
|
-
},
|
|
1779
|
-
(e) => {
|
|
1780
|
-
if (req.next) {
|
|
1781
|
-
if (e?.code == "ENOENT") {
|
|
1782
|
-
req.next(
|
|
1783
|
-
new import_dx_common_lib3.ResourceNotFoundError(
|
|
1784
|
-
`could not find ${e?.path.substr(
|
|
1785
|
-
e?.path.indexOf(componentStaticFileRoot) + componentStaticFileRoot.length
|
|
1786
|
-
)}`
|
|
1787
|
-
)
|
|
1788
|
-
);
|
|
1789
|
-
} else if (e) {
|
|
1790
|
-
req.next(e);
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
);
|
|
1795
|
-
await new Promise((resolve, _reject) => {
|
|
1796
|
-
response.on("finish", () => {
|
|
1797
|
-
response.end();
|
|
1798
|
-
resolve();
|
|
1799
|
-
});
|
|
1800
|
-
});
|
|
1801
|
-
} else {
|
|
1802
|
-
throw new import_dx_common_lib3.ResourceNotFoundError(`${componentName} ${version} doesn't expose any static resources`);
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
setResponseHeaders(headers3, response) {
|
|
1806
|
-
setHeadersOnExpressResponse(headers3, response);
|
|
1807
|
-
let cacheControl = response.getHeader("cache-control");
|
|
1808
|
-
if (typeof cacheControl != "string") {
|
|
1809
|
-
cacheControl = import_dx_common_lib3.DEFAULT_CACHE_CONTROL_HEADER;
|
|
1805
|
+
async getSchemaVersion(version) {
|
|
1806
|
+
const schema = import_dx_json_schema_lib2.MANIFEST_SCHEMAS[version] || import_dx_json_schema_lib2.SUB_SCHEMAS[version];
|
|
1807
|
+
if (!schema) {
|
|
1808
|
+
throw new import_dx_common_lib3.ResourceNotFoundError("");
|
|
1810
1809
|
}
|
|
1811
|
-
|
|
1812
|
-
cacheControlObj = (0, import_dx_common_lib3.applyDefaultRulesToCacheControlObject)(cacheControlObj);
|
|
1813
|
-
cacheControlObj.immutable = true;
|
|
1814
|
-
cacheControlObj["max-age"] = 604800;
|
|
1815
|
-
response.setHeader("cache-control", (0, import_dx_common_lib3.cacheControlToString)(cacheControlObj));
|
|
1810
|
+
return schema;
|
|
1816
1811
|
}
|
|
1817
|
-
async
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
const previewDefinition = await this.getValidatedPreviewDefinition(_previewKey, manifest.getModel());
|
|
1824
|
-
const functionPreview = previewDefinition.functionData[manifest.getModel().mainFunction];
|
|
1825
|
-
const headers3 = functionPreview?.headers ? functionPreview.headers : {};
|
|
1826
|
-
return headers3;
|
|
1827
|
-
}
|
|
1828
|
-
throw new import_dx_common_lib3.BadRequestError(`neither componentSet or previewKey set`);
|
|
1812
|
+
async getComponents(req) {
|
|
1813
|
+
const res = req.res;
|
|
1814
|
+
const components = await this.manifestService.listAllComponentManifests();
|
|
1815
|
+
const groupedComponents = this.createComponentMap(components);
|
|
1816
|
+
const returnHtml = this.createComponentMapHtml(groupedComponents);
|
|
1817
|
+
res.send(returnHtml);
|
|
1829
1818
|
}
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1819
|
+
createComponentMap(components) {
|
|
1820
|
+
return components.reduce((groups, manifest, index) => {
|
|
1821
|
+
const previewObject = components[index].getModel().previews;
|
|
1822
|
+
let currentPrimaryKey;
|
|
1823
|
+
if (previewObject !== void 0) {
|
|
1824
|
+
currentPrimaryKey = Object.keys(previewObject)[0];
|
|
1825
|
+
}
|
|
1826
|
+
const componentName = manifest.getName();
|
|
1827
|
+
if (groups[componentName] === void 0) {
|
|
1828
|
+
groups[componentName] = {
|
|
1829
|
+
components: []
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
groups[componentName].components.push({
|
|
1833
|
+
id: getComponentIdFromComponentManifest(manifest),
|
|
1834
|
+
version: manifest.getVersion(),
|
|
1835
|
+
previewKey: currentPrimaryKey
|
|
1836
|
+
});
|
|
1837
|
+
return groups;
|
|
1838
|
+
}, {});
|
|
1837
1839
|
}
|
|
1838
|
-
|
|
1839
|
-
const
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1840
|
+
createComponentMapHtml(groupedComponents) {
|
|
1841
|
+
const renderComponentList = Object.entries(groupedComponents).map(
|
|
1842
|
+
([name, entry]) => [
|
|
1843
|
+
name,
|
|
1844
|
+
entry.components.map((component) => {
|
|
1845
|
+
if (component.previewKey !== void 0) {
|
|
1846
|
+
return `<a href="/dev/render/${component.id}?_previewKey=${component.previewKey}">${component.version}</a>`;
|
|
1847
|
+
}
|
|
1848
|
+
return `<a href="/dev/render/${component.id}?_componentSet=local-development-only">${component.version}</a>`;
|
|
1849
|
+
})
|
|
1850
|
+
]
|
|
1851
|
+
).map(([name, versionLinks]) => `${name}: ${versionLinks.join(", ")}`);
|
|
1852
|
+
const html = `<body><div>count of components: ${Object.keys(groupedComponents).length}</div>${renderComponentList.join("<br/>")}</body>`;
|
|
1853
|
+
return html;
|
|
1850
1854
|
}
|
|
1851
1855
|
};
|
|
1852
1856
|
__decorateClass([
|
|
1853
|
-
(0, import_tsoa4.Get)("/:
|
|
1854
|
-
__decorateParam(0, (0, import_tsoa4.Path)())
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
__decorateParam(
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
(0,
|
|
1864
|
-
|
|
1865
|
-
__decorateParam(0, (0, import_inversify3.inject)("ManifestService")),
|
|
1866
|
-
__decorateParam(1, (0, import_inversify3.inject)("ComponentSetService")),
|
|
1867
|
-
__decorateParam(2, (0, import_inversify3.inject)("ComponentFunctionService"))
|
|
1868
|
-
], StaticController);
|
|
1857
|
+
(0, import_tsoa4.Get)("/schemas/:version.json"),
|
|
1858
|
+
__decorateParam(0, (0, import_tsoa4.Path)())
|
|
1859
|
+
], CoreController.prototype, "getSchemaVersion", 1);
|
|
1860
|
+
__decorateClass([
|
|
1861
|
+
(0, import_tsoa4.Get)("/"),
|
|
1862
|
+
__decorateParam(0, (0, import_tsoa4.Request)())
|
|
1863
|
+
], CoreController.prototype, "getComponents", 1);
|
|
1864
|
+
CoreController = __decorateClass([
|
|
1865
|
+
(0, import_inversify_binding_decorators3.provide)(CoreController),
|
|
1866
|
+
(0, import_tsoa4.Route)("/"),
|
|
1867
|
+
__decorateParam(0, (0, import_inversify3.inject)("ManifestService"))
|
|
1868
|
+
], CoreController);
|
|
1869
1869
|
|
|
1870
1870
|
// src/ioc.ts
|
|
1871
1871
|
var import_inversify4 = require("inversify");
|
|
@@ -2288,7 +2288,7 @@ var models = {
|
|
|
2288
2288
|
"additionalProperties": { "dataType": "any" }
|
|
2289
2289
|
},
|
|
2290
2290
|
// 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
|
|
2291
|
-
"
|
|
2291
|
+
"ComponentManifest": {
|
|
2292
2292
|
"dataType": "refObject",
|
|
2293
2293
|
"properties": {
|
|
2294
2294
|
"$schema": { "dataType": "string", "required": true },
|
|
@@ -2310,9 +2310,9 @@ var models = {
|
|
|
2310
2310
|
"additionalProperties": false
|
|
2311
2311
|
},
|
|
2312
2312
|
// 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
|
|
2313
|
-
"
|
|
2313
|
+
"ComponentManifestType": {
|
|
2314
2314
|
"dataType": "refAlias",
|
|
2315
|
-
"type": { "ref": "
|
|
2315
|
+
"type": { "ref": "ComponentManifest", "validators": {} }
|
|
2316
2316
|
},
|
|
2317
2317
|
// 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
|
|
2318
2318
|
"ComponentSchema": {
|
|
@@ -2321,309 +2321,291 @@ var models = {
|
|
|
2321
2321
|
}
|
|
2322
2322
|
// 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
|
|
2323
2323
|
};
|
|
2324
|
-
var
|
|
2324
|
+
var templateService = new import_runtime4.ExpressTemplateService(models, { "noImplicitAdditionalProperties": "throw-on-extras", "bodyCoercion": true });
|
|
2325
2325
|
function RegisterRoutes(app) {
|
|
2326
|
+
const argsStaticController_getPreview = {
|
|
2327
|
+
namespace: { "in": "path", "name": "namespace", "required": true, "dataType": "string" },
|
|
2328
|
+
componentName: { "in": "path", "name": "componentName", "required": true, "dataType": "string" },
|
|
2329
|
+
version: { "in": "path", "name": "version", "required": true, "dataType": "string" },
|
|
2330
|
+
staticFile: { "in": "path", "name": "staticFile", "required": true, "dataType": "string" },
|
|
2331
|
+
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
2332
|
+
_componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2333
|
+
_previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" }
|
|
2334
|
+
};
|
|
2326
2335
|
app.get(
|
|
2327
|
-
"/
|
|
2328
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2329
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2330
|
-
async function
|
|
2331
|
-
const args = {
|
|
2332
|
-
version: { "in": "path", "name": "version", "required": true, "dataType": "string" }
|
|
2333
|
-
};
|
|
2334
|
-
let validatedArgs = [];
|
|
2335
|
-
try {
|
|
2336
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2337
|
-
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2338
|
-
const controller = await container.get(CoreController);
|
|
2339
|
-
if (typeof controller["setStatus"] === "function") {
|
|
2340
|
-
controller.setStatus(void 0);
|
|
2341
|
-
}
|
|
2342
|
-
const promise = controller.getSchemaVersion.apply(controller, validatedArgs);
|
|
2343
|
-
promiseHandler(controller, promise, response, void 0, next);
|
|
2344
|
-
} catch (err) {
|
|
2345
|
-
return next(err);
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
);
|
|
2349
|
-
app.get(
|
|
2350
|
-
"/",
|
|
2351
|
-
...(0, import_runtime4.fetchMiddlewares)(CoreController),
|
|
2352
|
-
...(0, import_runtime4.fetchMiddlewares)(CoreController.prototype.getComponents),
|
|
2353
|
-
async function CoreController_getComponents(request, response, next) {
|
|
2354
|
-
const args = {
|
|
2355
|
-
req: { "in": "request", "name": "req", "required": true, "dataType": "object" }
|
|
2356
|
-
};
|
|
2336
|
+
"/s/:namespace/:componentName/:version/:staticFile*",
|
|
2337
|
+
...(0, import_runtime4.fetchMiddlewares)(StaticController),
|
|
2338
|
+
...(0, import_runtime4.fetchMiddlewares)(StaticController.prototype.getPreview),
|
|
2339
|
+
async function StaticController_getPreview(request, response, next) {
|
|
2357
2340
|
let validatedArgs = [];
|
|
2358
2341
|
try {
|
|
2359
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2342
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsStaticController_getPreview, request, response });
|
|
2360
2343
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2361
|
-
const controller = await container.get(
|
|
2344
|
+
const controller = await container.get(StaticController);
|
|
2362
2345
|
if (typeof controller["setStatus"] === "function") {
|
|
2363
2346
|
controller.setStatus(void 0);
|
|
2364
2347
|
}
|
|
2365
|
-
|
|
2366
|
-
|
|
2348
|
+
await templateService.apiHandler({
|
|
2349
|
+
methodName: "getPreview",
|
|
2350
|
+
controller,
|
|
2351
|
+
response,
|
|
2352
|
+
next,
|
|
2353
|
+
validatedArgs,
|
|
2354
|
+
successStatus: void 0
|
|
2355
|
+
});
|
|
2367
2356
|
} catch (err) {
|
|
2368
2357
|
return next(err);
|
|
2369
2358
|
}
|
|
2370
2359
|
}
|
|
2371
2360
|
);
|
|
2361
|
+
const argsDevelopmentController_getComponents = {};
|
|
2372
2362
|
app.get(
|
|
2373
2363
|
"/dev/all",
|
|
2374
2364
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2375
2365
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getComponents),
|
|
2376
2366
|
async function DevelopmentController_getComponents(request, response, next) {
|
|
2377
|
-
const args = {};
|
|
2378
2367
|
let validatedArgs = [];
|
|
2379
2368
|
try {
|
|
2380
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2369
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getComponents, request, response });
|
|
2381
2370
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2382
2371
|
const controller = await container.get(DevelopmentController);
|
|
2383
2372
|
if (typeof controller["setStatus"] === "function") {
|
|
2384
2373
|
controller.setStatus(void 0);
|
|
2385
2374
|
}
|
|
2386
|
-
|
|
2387
|
-
|
|
2375
|
+
await templateService.apiHandler({
|
|
2376
|
+
methodName: "getComponents",
|
|
2377
|
+
controller,
|
|
2378
|
+
response,
|
|
2379
|
+
next,
|
|
2380
|
+
validatedArgs,
|
|
2381
|
+
successStatus: void 0
|
|
2382
|
+
});
|
|
2388
2383
|
} catch (err) {
|
|
2389
2384
|
return next(err);
|
|
2390
2385
|
}
|
|
2391
2386
|
}
|
|
2392
2387
|
);
|
|
2388
|
+
const argsDevelopmentController_Manifest = {
|
|
2389
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2390
|
+
};
|
|
2393
2391
|
app.get(
|
|
2394
2392
|
"/dev/manifest/:componentId",
|
|
2395
2393
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2396
2394
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.Manifest),
|
|
2397
2395
|
async function DevelopmentController_Manifest(request, response, next) {
|
|
2398
|
-
const args = {
|
|
2399
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2400
|
-
};
|
|
2401
2396
|
let validatedArgs = [];
|
|
2402
2397
|
try {
|
|
2403
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2398
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_Manifest, request, response });
|
|
2404
2399
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2405
2400
|
const controller = await container.get(DevelopmentController);
|
|
2406
2401
|
if (typeof controller["setStatus"] === "function") {
|
|
2407
2402
|
controller.setStatus(void 0);
|
|
2408
2403
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2404
|
+
await templateService.apiHandler({
|
|
2405
|
+
methodName: "Manifest",
|
|
2406
|
+
controller,
|
|
2407
|
+
response,
|
|
2408
|
+
next,
|
|
2409
|
+
validatedArgs,
|
|
2410
|
+
successStatus: void 0
|
|
2411
|
+
});
|
|
2411
2412
|
} catch (err) {
|
|
2412
2413
|
return next(err);
|
|
2413
2414
|
}
|
|
2414
2415
|
}
|
|
2415
2416
|
);
|
|
2417
|
+
const argsDevelopmentController_getContentSchema = {
|
|
2418
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2419
|
+
};
|
|
2416
2420
|
app.get(
|
|
2417
2421
|
"/dev/schemas/:componentId",
|
|
2418
2422
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2419
2423
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getContentSchema),
|
|
2420
2424
|
async function DevelopmentController_getContentSchema(request, response, next) {
|
|
2421
|
-
const args = {
|
|
2422
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2423
|
-
};
|
|
2424
2425
|
let validatedArgs = [];
|
|
2425
2426
|
try {
|
|
2426
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2427
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getContentSchema, request, response });
|
|
2427
2428
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2428
2429
|
const controller = await container.get(DevelopmentController);
|
|
2429
2430
|
if (typeof controller["setStatus"] === "function") {
|
|
2430
2431
|
controller.setStatus(void 0);
|
|
2431
2432
|
}
|
|
2432
|
-
|
|
2433
|
-
|
|
2433
|
+
await templateService.apiHandler({
|
|
2434
|
+
methodName: "getContentSchema",
|
|
2435
|
+
controller,
|
|
2436
|
+
response,
|
|
2437
|
+
next,
|
|
2438
|
+
validatedArgs,
|
|
2439
|
+
successStatus: void 0
|
|
2440
|
+
});
|
|
2434
2441
|
} catch (err) {
|
|
2435
2442
|
return next(err);
|
|
2436
2443
|
}
|
|
2437
2444
|
}
|
|
2438
2445
|
);
|
|
2446
|
+
const argsDevelopmentController_TemporaryPreview = {
|
|
2447
|
+
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
2448
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2449
|
+
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
2450
|
+
headers: { "in": "query", "name": "headers", "dataType": "any" },
|
|
2451
|
+
envVars: { "in": "query", "name": "envVars", "dataType": "any" },
|
|
2452
|
+
data: { "in": "query", "name": "data", "dataType": "any" },
|
|
2453
|
+
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2454
|
+
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2455
|
+
};
|
|
2439
2456
|
app.get(
|
|
2440
2457
|
"/dev/temp-preview/:componentId/:functionName",
|
|
2441
2458
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2442
2459
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.TemporaryPreview),
|
|
2443
2460
|
async function DevelopmentController_TemporaryPreview(request, response, next) {
|
|
2444
|
-
const args = {
|
|
2445
|
-
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
2446
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2447
|
-
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
2448
|
-
headers: { "in": "query", "name": "headers", "dataType": "any" },
|
|
2449
|
-
envVars: { "in": "query", "name": "envVars", "dataType": "any" },
|
|
2450
|
-
data: { "in": "query", "name": "data", "dataType": "any" },
|
|
2451
|
-
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2452
|
-
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2453
|
-
};
|
|
2454
2461
|
let validatedArgs = [];
|
|
2455
2462
|
try {
|
|
2456
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2463
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_TemporaryPreview, request, response });
|
|
2457
2464
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2458
2465
|
const controller = await container.get(DevelopmentController);
|
|
2459
2466
|
if (typeof controller["setStatus"] === "function") {
|
|
2460
2467
|
controller.setStatus(void 0);
|
|
2461
2468
|
}
|
|
2462
|
-
|
|
2463
|
-
|
|
2469
|
+
await templateService.apiHandler({
|
|
2470
|
+
methodName: "TemporaryPreview",
|
|
2471
|
+
controller,
|
|
2472
|
+
response,
|
|
2473
|
+
next,
|
|
2474
|
+
validatedArgs,
|
|
2475
|
+
successStatus: void 0
|
|
2476
|
+
});
|
|
2464
2477
|
} catch (err) {
|
|
2465
2478
|
return next(err);
|
|
2466
2479
|
}
|
|
2467
2480
|
}
|
|
2468
2481
|
);
|
|
2482
|
+
const argsDevelopmentController_getDefaultFunctionRendering = {
|
|
2483
|
+
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
2484
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2485
|
+
componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2486
|
+
previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
2487
|
+
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2488
|
+
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2489
|
+
};
|
|
2469
2490
|
app.get(
|
|
2470
2491
|
"/dev/render/:componentId",
|
|
2471
2492
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2472
2493
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getDefaultFunctionRendering),
|
|
2473
2494
|
async function DevelopmentController_getDefaultFunctionRendering(request, response, next) {
|
|
2474
|
-
const args = {
|
|
2475
|
-
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
2476
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2477
|
-
componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2478
|
-
previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
2479
|
-
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2480
|
-
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2481
|
-
};
|
|
2482
2495
|
let validatedArgs = [];
|
|
2483
2496
|
try {
|
|
2484
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2497
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getDefaultFunctionRendering, request, response });
|
|
2485
2498
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2486
2499
|
const controller = await container.get(DevelopmentController);
|
|
2487
2500
|
if (typeof controller["setStatus"] === "function") {
|
|
2488
2501
|
controller.setStatus(void 0);
|
|
2489
2502
|
}
|
|
2490
|
-
|
|
2491
|
-
|
|
2503
|
+
await templateService.apiHandler({
|
|
2504
|
+
methodName: "getDefaultFunctionRendering",
|
|
2505
|
+
controller,
|
|
2506
|
+
response,
|
|
2507
|
+
next,
|
|
2508
|
+
validatedArgs,
|
|
2509
|
+
successStatus: void 0
|
|
2510
|
+
});
|
|
2492
2511
|
} catch (err) {
|
|
2493
2512
|
return next(err);
|
|
2494
2513
|
}
|
|
2495
2514
|
}
|
|
2496
2515
|
);
|
|
2516
|
+
const argsDevelopmentController_getGivenFunctionRendering = {
|
|
2517
|
+
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
2518
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2519
|
+
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
2520
|
+
componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2521
|
+
previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
2522
|
+
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2523
|
+
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2524
|
+
};
|
|
2497
2525
|
app.get(
|
|
2498
2526
|
"/dev/render/:componentId/:functionName",
|
|
2499
2527
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2500
2528
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getGivenFunctionRendering),
|
|
2501
2529
|
async function DevelopmentController_getGivenFunctionRendering(request, response, next) {
|
|
2502
|
-
const args = {
|
|
2503
|
-
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
2504
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2505
|
-
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
2506
|
-
componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2507
|
-
previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
2508
|
-
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2509
|
-
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2510
|
-
};
|
|
2511
2530
|
let validatedArgs = [];
|
|
2512
2531
|
try {
|
|
2513
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2532
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getGivenFunctionRendering, request, response });
|
|
2514
2533
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2515
2534
|
const controller = await container.get(DevelopmentController);
|
|
2516
2535
|
if (typeof controller["setStatus"] === "function") {
|
|
2517
2536
|
controller.setStatus(void 0);
|
|
2518
2537
|
}
|
|
2519
|
-
|
|
2520
|
-
|
|
2538
|
+
await templateService.apiHandler({
|
|
2539
|
+
methodName: "getGivenFunctionRendering",
|
|
2540
|
+
controller,
|
|
2541
|
+
response,
|
|
2542
|
+
next,
|
|
2543
|
+
validatedArgs,
|
|
2544
|
+
successStatus: void 0
|
|
2545
|
+
});
|
|
2521
2546
|
} catch (err) {
|
|
2522
2547
|
return next(err);
|
|
2523
2548
|
}
|
|
2524
2549
|
}
|
|
2525
2550
|
);
|
|
2551
|
+
const argsCoreController_getSchemaVersion = {
|
|
2552
|
+
version: { "in": "path", "name": "version", "required": true, "dataType": "string" }
|
|
2553
|
+
};
|
|
2526
2554
|
app.get(
|
|
2527
|
-
"/
|
|
2528
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2529
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2530
|
-
async function
|
|
2531
|
-
const args = {
|
|
2532
|
-
namespace: { "in": "path", "name": "namespace", "required": true, "dataType": "string" },
|
|
2533
|
-
componentName: { "in": "path", "name": "componentName", "required": true, "dataType": "string" },
|
|
2534
|
-
version: { "in": "path", "name": "version", "required": true, "dataType": "string" },
|
|
2535
|
-
staticFile: { "in": "path", "name": "staticFile", "required": true, "dataType": "string" },
|
|
2536
|
-
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
2537
|
-
_componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2538
|
-
_previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" }
|
|
2539
|
-
};
|
|
2555
|
+
"/schemas/:version.json",
|
|
2556
|
+
...(0, import_runtime4.fetchMiddlewares)(CoreController),
|
|
2557
|
+
...(0, import_runtime4.fetchMiddlewares)(CoreController.prototype.getSchemaVersion),
|
|
2558
|
+
async function CoreController_getSchemaVersion(request, response, next) {
|
|
2540
2559
|
let validatedArgs = [];
|
|
2541
2560
|
try {
|
|
2542
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2561
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsCoreController_getSchemaVersion, request, response });
|
|
2543
2562
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2544
|
-
const controller = await container.get(
|
|
2563
|
+
const controller = await container.get(CoreController);
|
|
2545
2564
|
if (typeof controller["setStatus"] === "function") {
|
|
2546
2565
|
controller.setStatus(void 0);
|
|
2547
2566
|
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2567
|
+
await templateService.apiHandler({
|
|
2568
|
+
methodName: "getSchemaVersion",
|
|
2569
|
+
controller,
|
|
2570
|
+
response,
|
|
2571
|
+
next,
|
|
2572
|
+
validatedArgs,
|
|
2573
|
+
successStatus: void 0
|
|
2574
|
+
});
|
|
2550
2575
|
} catch (err) {
|
|
2551
2576
|
return next(err);
|
|
2552
2577
|
}
|
|
2553
2578
|
}
|
|
2554
2579
|
);
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
} else {
|
|
2582
|
-
response.status(statusCode || 204).end();
|
|
2583
|
-
}
|
|
2584
|
-
}
|
|
2585
|
-
function responder(response) {
|
|
2586
|
-
return function(status, data, headers3) {
|
|
2587
|
-
returnHandler(response, status, data, headers3);
|
|
2588
|
-
};
|
|
2589
|
-
}
|
|
2590
|
-
;
|
|
2591
|
-
function getValidatedArgs(args, request, response) {
|
|
2592
|
-
const fieldErrors = {};
|
|
2593
|
-
const values = Object.keys(args).map((key) => {
|
|
2594
|
-
const name = args[key].name;
|
|
2595
|
-
switch (args[key].in) {
|
|
2596
|
-
case "request":
|
|
2597
|
-
return request;
|
|
2598
|
-
case "query":
|
|
2599
|
-
return validationService.ValidateParam(args[key], request.query[name], name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2600
|
-
case "queries":
|
|
2601
|
-
return validationService.ValidateParam(args[key], request.query, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2602
|
-
case "path":
|
|
2603
|
-
return validationService.ValidateParam(args[key], request.params[name], name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2604
|
-
case "header":
|
|
2605
|
-
return validationService.ValidateParam(args[key], request.header(name), name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2606
|
-
case "body":
|
|
2607
|
-
return validationService.ValidateParam(args[key], request.body, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2608
|
-
case "body-prop":
|
|
2609
|
-
return validationService.ValidateParam(args[key], request.body[name], name, fieldErrors, "body.", { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2610
|
-
case "formData":
|
|
2611
|
-
if (args[key].dataType === "file") {
|
|
2612
|
-
return validationService.ValidateParam(args[key], request.file, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2613
|
-
} else if (args[key].dataType === "array" && args[key].array.dataType === "file") {
|
|
2614
|
-
return validationService.ValidateParam(args[key], request.files, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2615
|
-
} else {
|
|
2616
|
-
return validationService.ValidateParam(args[key], request.body[name], name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2617
|
-
}
|
|
2618
|
-
case "res":
|
|
2619
|
-
return responder(response);
|
|
2580
|
+
const argsCoreController_getComponents = {
|
|
2581
|
+
req: { "in": "request", "name": "req", "required": true, "dataType": "object" }
|
|
2582
|
+
};
|
|
2583
|
+
app.get(
|
|
2584
|
+
"/",
|
|
2585
|
+
...(0, import_runtime4.fetchMiddlewares)(CoreController),
|
|
2586
|
+
...(0, import_runtime4.fetchMiddlewares)(CoreController.prototype.getComponents),
|
|
2587
|
+
async function CoreController_getComponents(request, response, next) {
|
|
2588
|
+
let validatedArgs = [];
|
|
2589
|
+
try {
|
|
2590
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsCoreController_getComponents, request, response });
|
|
2591
|
+
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2592
|
+
const controller = await container.get(CoreController);
|
|
2593
|
+
if (typeof controller["setStatus"] === "function") {
|
|
2594
|
+
controller.setStatus(void 0);
|
|
2595
|
+
}
|
|
2596
|
+
await templateService.apiHandler({
|
|
2597
|
+
methodName: "getComponents",
|
|
2598
|
+
controller,
|
|
2599
|
+
response,
|
|
2600
|
+
next,
|
|
2601
|
+
validatedArgs,
|
|
2602
|
+
successStatus: void 0
|
|
2603
|
+
});
|
|
2604
|
+
} catch (err) {
|
|
2605
|
+
return next(err);
|
|
2620
2606
|
}
|
|
2621
|
-
});
|
|
2622
|
-
if (Object.keys(fieldErrors).length > 0) {
|
|
2623
|
-
throw new import_runtime4.ValidateError(fieldErrors, "");
|
|
2624
2607
|
}
|
|
2625
|
-
|
|
2626
|
-
}
|
|
2608
|
+
);
|
|
2627
2609
|
}
|
|
2628
2610
|
|
|
2629
2611
|
// src/webserver/app.ts
|
|
@@ -3039,7 +3021,7 @@ var RenderInputService = class {
|
|
|
3039
3021
|
request.expressRequest.query["_previewEnvVars"]
|
|
3040
3022
|
);
|
|
3041
3023
|
const publicFacingUrl = this.rootUrlResolver(request.expressRequest, true);
|
|
3042
|
-
let
|
|
3024
|
+
let headers = {};
|
|
3043
3025
|
let webManifest;
|
|
3044
3026
|
let input = {};
|
|
3045
3027
|
if (request.previewKey && request.componentSet) {
|
|
@@ -3054,14 +3036,14 @@ var RenderInputService = class {
|
|
|
3054
3036
|
);
|
|
3055
3037
|
const previewFunctionConfig = manifest.getFunctionPreviewConfiguration(request.previewKey, componentFunction);
|
|
3056
3038
|
if (previewFunctionConfig && previewFunctionConfig.headers) {
|
|
3057
|
-
|
|
3039
|
+
headers = previewFunctionConfig.headers;
|
|
3058
3040
|
}
|
|
3059
3041
|
} else {
|
|
3060
3042
|
if (!request.componentSet) {
|
|
3061
3043
|
throw new import_dx_common_lib6.BadRequestError("You must provide either previewKey or a componentSet as input");
|
|
3062
3044
|
}
|
|
3063
3045
|
const set = await this.componentSetService.getComponentSet(request.componentSet);
|
|
3064
|
-
|
|
3046
|
+
headers = this.componentSetService.getComponentRuntimeHeaders(set, componentFunction);
|
|
3065
3047
|
webManifest = this.componentFunctionService.prepareManifestForWebResponse(
|
|
3066
3048
|
manifest,
|
|
3067
3049
|
runtimeSet.webPath,
|
|
@@ -3080,7 +3062,7 @@ var RenderInputService = class {
|
|
|
3080
3062
|
manifest,
|
|
3081
3063
|
manifestForWeb: webManifest,
|
|
3082
3064
|
componentFullName: manifest.getName(),
|
|
3083
|
-
headers
|
|
3065
|
+
headers,
|
|
3084
3066
|
runtimeSet,
|
|
3085
3067
|
manifestPath: await manifest.getManifestPath(),
|
|
3086
3068
|
queryParameters: this.getQueryParametersFromRequest(request, componentFunction)
|
|
@@ -3393,25 +3375,26 @@ function generateRandomName() {
|
|
|
3393
3375
|
}
|
|
3394
3376
|
|
|
3395
3377
|
// src/webserver/controllers/test/render-route-tests.ts
|
|
3396
|
-
var CLOUDFLARE_X_API_KEY_HEADER = "x-cloudflare-key";
|
|
3397
|
-
var CLOUDFLARE_X_API_KEY = "x-cloudflare-key";
|
|
3398
|
-
var headers = {
|
|
3399
|
-
[CLOUDFLARE_X_API_KEY_HEADER]: CLOUDFLARE_X_API_KEY
|
|
3400
|
-
};
|
|
3401
3378
|
function renderRouteTests(request, _rootUrl) {
|
|
3402
3379
|
describe("GET /dev/render/unit-test-components__test-component__1.0.10/?_componentSet=set", () => {
|
|
3403
3380
|
it("should render the test component with html endpoint", async () => {
|
|
3404
|
-
const response = await request().get(
|
|
3381
|
+
const response = await request().get(
|
|
3382
|
+
"/dev/render/unit-test-components__test-component__1.0.10?_componentSet=set&something=unused"
|
|
3383
|
+
);
|
|
3405
3384
|
expect(response.text).toEqual("<div>hello - {}</div>");
|
|
3406
3385
|
expect(response.statusCode).toEqual(200);
|
|
3407
3386
|
}, 2e4);
|
|
3408
3387
|
it("should render the test component promise endpoint with html endpoint", async () => {
|
|
3409
|
-
const response = await request().get(
|
|
3388
|
+
const response = await request().get(
|
|
3389
|
+
"/dev/render/unit-test-components__test-component__1.0.10/promise?_componentSet=set&something=unused"
|
|
3390
|
+
);
|
|
3410
3391
|
expect(response.statusCode).toEqual(200);
|
|
3411
3392
|
expect(response.text).toEqual("<h1>hello</h1>");
|
|
3412
3393
|
}, 2e4);
|
|
3413
3394
|
it("should fail validation if input contract is not met and helpful message returned", async () => {
|
|
3414
|
-
const response = await request().get(
|
|
3395
|
+
const response = await request().get(
|
|
3396
|
+
"/dev/render/unit-test-components__test-component__1.0.0?_componentSet=set&something=unused"
|
|
3397
|
+
);
|
|
3415
3398
|
expect(response.statusCode).toEqual(400);
|
|
3416
3399
|
expect(response.body).toMatchInlineSnapshot(`
|
|
3417
3400
|
{
|
|
@@ -3422,7 +3405,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3422
3405
|
it("should 404 if requesting a non-existent function on an otherwise valid component", async () => {
|
|
3423
3406
|
const response = await request().get(
|
|
3424
3407
|
"/dev/render/unit-test-components__test-component__1.0.0/non-existent-entry-file?_componentSet=set&something=not-used"
|
|
3425
|
-
)
|
|
3408
|
+
);
|
|
3426
3409
|
expect(response.statusCode).toEqual(404);
|
|
3427
3410
|
expect(response.body).toMatchInlineSnapshot(`
|
|
3428
3411
|
{
|
|
@@ -3433,7 +3416,9 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3433
3416
|
});
|
|
3434
3417
|
describe("GET /dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set", () => {
|
|
3435
3418
|
it("should fail validation when requesting a function with a missing entry file", async () => {
|
|
3436
|
-
const response = await request().get(
|
|
3419
|
+
const response = await request().get(
|
|
3420
|
+
"/dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set&something=not-used"
|
|
3421
|
+
);
|
|
3437
3422
|
expect(response.body).toEqual({
|
|
3438
3423
|
message: `"main's" entry file "missing-entry-file.js" is inaccessible`
|
|
3439
3424
|
});
|
|
@@ -3442,7 +3427,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3442
3427
|
});
|
|
3443
3428
|
describe("GET /dev/render/unit-test-components__test-component__1.0.4?_componentSet=set", () => {
|
|
3444
3429
|
it("should render a simple json endpoint", async () => {
|
|
3445
|
-
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4?_componentSet=set")
|
|
3430
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4?_componentSet=set");
|
|
3446
3431
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
3447
3432
|
expect(response.body).toEqual({
|
|
3448
3433
|
"my-prop": "test value for my-prop",
|
|
@@ -3455,7 +3440,9 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3455
3440
|
});
|
|
3456
3441
|
}, 2e4);
|
|
3457
3442
|
it("should report error if response does not match with the schema", async () => {
|
|
3458
|
-
const response = await request().get(
|
|
3443
|
+
const response = await request().get(
|
|
3444
|
+
"/dev/render/unit-test-components__test-component__1.0.4/render_json_invalid?_componentSet=set"
|
|
3445
|
+
);
|
|
3459
3446
|
expect(response.statusCode).toEqual(500);
|
|
3460
3447
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
3461
3448
|
expect(response.body).toEqual({
|
|
@@ -3465,7 +3452,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3465
3452
|
it("should validate a complex json against a schema", async () => {
|
|
3466
3453
|
const response = await request().get(
|
|
3467
3454
|
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_valid?_componentSet=set"
|
|
3468
|
-
)
|
|
3455
|
+
);
|
|
3469
3456
|
const myObject = {
|
|
3470
3457
|
"my-object": {
|
|
3471
3458
|
"a-string": "this is a string",
|
|
@@ -3481,7 +3468,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3481
3468
|
it("should report errors if nested object json schema fails", async () => {
|
|
3482
3469
|
const response = await request().get(
|
|
3483
3470
|
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_invalid?_componentSet=set"
|
|
3484
|
-
)
|
|
3471
|
+
);
|
|
3485
3472
|
expect(response.statusCode).toEqual(500);
|
|
3486
3473
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
3487
3474
|
expect(response.body).toEqual({
|
|
@@ -3494,7 +3481,7 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3494
3481
|
it('should return input and info object with "query parameters"', async () => {
|
|
3495
3482
|
const response = await request().get(
|
|
3496
3483
|
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&something=hello-test&foo=foo-val&foo2=foo2-val"
|
|
3497
|
-
)
|
|
3484
|
+
);
|
|
3498
3485
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
3499
3486
|
const result = response.body;
|
|
3500
3487
|
expect(result).toEqual([
|
|
@@ -3572,14 +3559,18 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3572
3559
|
});
|
|
3573
3560
|
});
|
|
3574
3561
|
it("should throw error if required query parameter is missing", async () => {
|
|
3575
|
-
const response = await request().get(
|
|
3562
|
+
const response = await request().get(
|
|
3563
|
+
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo2=foo2-val"
|
|
3564
|
+
);
|
|
3576
3565
|
expect(response.body).toEqual({
|
|
3577
3566
|
message: "Required query parameter 'foo' is missing"
|
|
3578
3567
|
});
|
|
3579
3568
|
expect(response.statusCode).toEqual(400);
|
|
3580
3569
|
});
|
|
3581
3570
|
it("should throw error if query parameter is not a string", async () => {
|
|
3582
|
-
const response = await request().get(
|
|
3571
|
+
const response = await request().get(
|
|
3572
|
+
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo=123&foo2[]=array-val"
|
|
3573
|
+
);
|
|
3583
3574
|
expect(response.body).toEqual({
|
|
3584
3575
|
message: "Value for query parameter 'foo2' must be a string"
|
|
3585
3576
|
});
|
|
@@ -3587,48 +3578,60 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3587
3578
|
});
|
|
3588
3579
|
describe("GET /dev/render/unit-test-components__test-headers__1.0.3?_componentSet=set", () => {
|
|
3589
3580
|
it("should make sure max-age header is clamped between max value", async () => {
|
|
3590
|
-
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/max_value?_componentSet=set").
|
|
3581
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/max_value?_componentSet=set").send().expect(200, "rendered");
|
|
3591
3582
|
expect(response.headers["cache-control"]).toEqual("max-age=1800, immutable");
|
|
3592
3583
|
});
|
|
3593
3584
|
it("should make sure max-age header is clamped between min value", async () => {
|
|
3594
|
-
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/min_value?_componentSet=set").
|
|
3585
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/min_value?_componentSet=set").send().expect(200, "rendered");
|
|
3595
3586
|
expect(response.headers["cache-control"]).toEqual("max-age=30, public");
|
|
3596
3587
|
});
|
|
3597
3588
|
});
|
|
3598
3589
|
describe("should be able to load external dependencies", () => {
|
|
3599
3590
|
it("should be able to make web requests out", async () => {
|
|
3600
|
-
const response = await request().get(
|
|
3591
|
+
const response = await request().get(
|
|
3592
|
+
"/dev/render/unit-test-components__test-npm-modules__3.0.0?_componentSet=set"
|
|
3593
|
+
);
|
|
3601
3594
|
expect(response.statusCode).toEqual(200);
|
|
3602
3595
|
expect(response.text).toContain(`<h1>Example Domain</h1>`);
|
|
3603
3596
|
});
|
|
3604
3597
|
});
|
|
3605
3598
|
describe("GET /dev/render/unit-test-components__test-formatted-text__1.0.0", () => {
|
|
3606
3599
|
it("should render a component formattedText in preview inline", async () => {
|
|
3607
|
-
const response = await request().get(
|
|
3600
|
+
const response = await request().get(
|
|
3601
|
+
"/dev/render/unit-test-components__test-formatted-text__1.0.0?_previewKey=valid-inline-preview"
|
|
3602
|
+
);
|
|
3608
3603
|
expect(response.statusCode).toEqual(200);
|
|
3609
3604
|
expect(response.text).toMatchInlineSnapshot(`"This is a test"`);
|
|
3610
3605
|
});
|
|
3611
3606
|
});
|
|
3612
3607
|
describe("GET /dev/render/unit-test-components__test-npm-modules__3.1.0", () => {
|
|
3613
3608
|
it("should render a component with uuid", async () => {
|
|
3614
|
-
const response = await request().get(
|
|
3609
|
+
const response = await request().get(
|
|
3610
|
+
"/dev/render/unit-test-components__test-npm-modules__3.1.0/uuid?_componentSet=set"
|
|
3611
|
+
);
|
|
3615
3612
|
expect(response.statusCode).toEqual(200);
|
|
3616
3613
|
});
|
|
3617
3614
|
it("should render a component with Buffer", async () => {
|
|
3618
|
-
const response = await request().get(
|
|
3615
|
+
const response = await request().get(
|
|
3616
|
+
"/dev/render/unit-test-components__test-npm-modules__3.1.0/buffer?_componentSet=set"
|
|
3617
|
+
);
|
|
3619
3618
|
expect(response.statusCode).toEqual(200);
|
|
3620
3619
|
});
|
|
3621
3620
|
});
|
|
3622
3621
|
describe("GET /dev/render/unit-test-components__test-squiz-image__1.0.0", () => {
|
|
3623
3622
|
it("should render the preview", async () => {
|
|
3624
|
-
const response = await request().get(
|
|
3623
|
+
const response = await request().get(
|
|
3624
|
+
"/dev/render/unit-test-components__test-squiz-image__1.0.0?_previewKey=valid-inline-preview"
|
|
3625
|
+
);
|
|
3625
3626
|
expect(response.statusCode).toEqual(200);
|
|
3626
3627
|
expect(response.text).toMatchInlineSnapshot(`"My Image Component"`);
|
|
3627
3628
|
});
|
|
3628
3629
|
});
|
|
3629
3630
|
describe("GET /dev/render/unit-test-components__test-squiz-link__1.0.0", () => {
|
|
3630
3631
|
it("should render the preview", async () => {
|
|
3631
|
-
const response = await request().get(
|
|
3632
|
+
const response = await request().get(
|
|
3633
|
+
"/dev/render/unit-test-components__test-squiz-link__1.0.0?_previewKey=valid-inline-preview"
|
|
3634
|
+
);
|
|
3632
3635
|
expect(response.statusCode).toEqual(200);
|
|
3633
3636
|
expect(response.text).toMatchInlineSnapshot(`"{"link":{"text":"My Link","url":"https://some.link/foo"}}"`);
|
|
3634
3637
|
});
|
|
@@ -3636,21 +3639,16 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3636
3639
|
}
|
|
3637
3640
|
|
|
3638
3641
|
// src/webserver/controllers/test/preview-route-tests.ts
|
|
3639
|
-
var CLOUDFLARE_X_API_KEY_HEADER2 = "x-cloudflare-key";
|
|
3640
|
-
var CLOUDFLARE_X_API_KEY2 = "x-cloudflare-key";
|
|
3641
|
-
var headers2 = {
|
|
3642
|
-
[CLOUDFLARE_X_API_KEY_HEADER2]: CLOUDFLARE_X_API_KEY2
|
|
3643
|
-
};
|
|
3644
3642
|
function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
3645
3643
|
describe("preview routes", () => {
|
|
3646
3644
|
it("should render a preview of a component with no wrapper file", async () => {
|
|
3647
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=test-preview").
|
|
3645
|
+
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");
|
|
3648
3646
|
});
|
|
3649
3647
|
it("should render a preview of a component with a different preset", async () => {
|
|
3650
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=another-preview").
|
|
3648
|
+
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");
|
|
3651
3649
|
});
|
|
3652
3650
|
it("should render a preview of a component non-main function with a wrapper html file", async () => {
|
|
3653
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4/other?_previewKey=another-preview").
|
|
3651
|
+
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) => {
|
|
3654
3652
|
expect(a.text).toMatchInlineSnapshot(`
|
|
3655
3653
|
"<!DOCTYPE html>
|
|
3656
3654
|
<html lang="en">
|
|
@@ -3669,24 +3667,30 @@ function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
|
3669
3667
|
});
|
|
3670
3668
|
});
|
|
3671
3669
|
it("should load the defined preview for a given preview key", async () => {
|
|
3672
|
-
const response = await request().get(
|
|
3670
|
+
const response = await request().get(
|
|
3671
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=second-preview"
|
|
3672
|
+
);
|
|
3673
3673
|
expect(response.text).toContain(`<p>Second Preview</p>`);
|
|
3674
3674
|
expect(response.statusCode).toEqual(200);
|
|
3675
3675
|
});
|
|
3676
3676
|
it("should give meaningful error when preview key is invalid", async () => {
|
|
3677
|
-
const response = await request().get(
|
|
3677
|
+
const response = await request().get(
|
|
3678
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=invalid"
|
|
3679
|
+
);
|
|
3678
3680
|
expect(response.text).toEqual(
|
|
3679
3681
|
`{"message":"Component has not defined preview with key \\"invalid\\", the defined preview keys for this component are \\"first-preview, second-preview, test-preview\\""}`
|
|
3680
3682
|
);
|
|
3681
3683
|
expect(response.statusCode).toEqual(404);
|
|
3682
3684
|
});
|
|
3683
3685
|
it("should render inline preview data through to component", async () => {
|
|
3684
|
-
const response = await request().get(
|
|
3686
|
+
const response = await request().get(
|
|
3687
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.4?_previewKey=test-preview"
|
|
3688
|
+
);
|
|
3685
3689
|
expect(response.text).toContain(`this is a result | 123`);
|
|
3686
3690
|
expect(response.statusCode).toEqual(200);
|
|
3687
3691
|
}, 1e4);
|
|
3688
3692
|
it("should resolve URIs to mocked URI object in preview route", async () => {
|
|
3689
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.1.1?_previewKey=test-preview").
|
|
3693
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.1.1?_previewKey=test-preview").expect(200).expect((a) => {
|
|
3690
3694
|
expect(a.text).toMatchInlineSnapshot(`
|
|
3691
3695
|
"
|
|
3692
3696
|
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":{}}
|