@squiz/edge-dev-render-runtime-lib 2.5.2 → 2.5.4
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
CHANGED
|
@@ -80,125 +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
|
+
};
|
|
201
247
|
}
|
|
248
|
+
function getComponentIdFromComponentManifest(manifest) {
|
|
249
|
+
return `${manifest.getNamespace()}${SEPARATOR}${manifest.getModel().name}${SEPARATOR}${manifest.getVersion()}`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/webserver/controllers/utils/ReplaceWithMock.ts
|
|
253
|
+
var import_dx_json_schema_lib = require("@squiz/dx-json-schema-lib");
|
|
202
254
|
|
|
203
255
|
// src/webserver/controllers/mocks/mockResources.ts
|
|
204
256
|
var resources = [
|
|
@@ -1449,6 +1501,12 @@ var resources = [
|
|
|
1449
1501
|
];
|
|
1450
1502
|
|
|
1451
1503
|
// src/webserver/controllers/utils/ReplaceWithMock.ts
|
|
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 }) => {
|
|
1505
|
+
const resource = resources.find((resource2) => resource2.id == matrixAssetId);
|
|
1506
|
+
return {
|
|
1507
|
+
...resource["squizImage"]
|
|
1508
|
+
};
|
|
1509
|
+
}).build();
|
|
1452
1510
|
function hasSquizType(componentSchema) {
|
|
1453
1511
|
if (!componentSchema || typeof componentSchema !== "object") {
|
|
1454
1512
|
return false;
|
|
@@ -1461,7 +1519,7 @@ function hasSquizType(componentSchema) {
|
|
|
1461
1519
|
(prop) => prop.type === "SquizImage" || prop.type === "SquizLink"
|
|
1462
1520
|
);
|
|
1463
1521
|
}
|
|
1464
|
-
function
|
|
1522
|
+
async function resolveMock(componentSchema, data) {
|
|
1465
1523
|
if (!componentSchema || typeof componentSchema !== "object") {
|
|
1466
1524
|
return componentSchema;
|
|
1467
1525
|
}
|
|
@@ -1469,24 +1527,14 @@ function replaceWithMock(componentSchema, data) {
|
|
|
1469
1527
|
if (!inputSchema || typeof inputSchema !== "object" || !inputSchema.properties) {
|
|
1470
1528
|
return componentSchema;
|
|
1471
1529
|
}
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
squizImageKeys.forEach((key) => {
|
|
1476
|
-
if (data[key]) {
|
|
1477
|
-
const resourceToReplace = resources.find((resource) => resource.id = data[key]["matrixAssetId"]);
|
|
1478
|
-
data = {
|
|
1479
|
-
...data,
|
|
1480
|
-
[key]: resourceToReplace
|
|
1481
|
-
};
|
|
1482
|
-
}
|
|
1483
|
-
});
|
|
1484
|
-
return data;
|
|
1530
|
+
const jsonSchemaService = new import_dx_json_schema_lib.JSONSchemaService(typeResolver, import_dx_json_schema_lib.ComponentInputMetaSchema);
|
|
1531
|
+
const resolvedInput = await jsonSchemaService.resolveInput(data, inputSchema);
|
|
1532
|
+
return resolvedInput;
|
|
1485
1533
|
}
|
|
1486
1534
|
|
|
1487
1535
|
// src/webserver/controllers/DevelopmentController.ts
|
|
1488
1536
|
var UPPERCASE_REGEX = /[A-Z]/;
|
|
1489
|
-
var DevelopmentController = class extends
|
|
1537
|
+
var DevelopmentController = class extends import_tsoa2.Controller {
|
|
1490
1538
|
constructor(config, manifestService, componentRunnerService, renderInputService, componentPreviewService, componentFunctionService) {
|
|
1491
1539
|
super();
|
|
1492
1540
|
this.config = config;
|
|
@@ -1533,7 +1581,7 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
1533
1581
|
const componentManifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
1534
1582
|
const componentFunction = componentManifest.getComponentFunctionByName(functionName);
|
|
1535
1583
|
if (hasSquizType(componentFunction)) {
|
|
1536
|
-
data =
|
|
1584
|
+
data = await resolveMock(componentFunction, data);
|
|
1537
1585
|
}
|
|
1538
1586
|
const defaultPreviewKey = Object.keys(componentManifest.getModel()?.previews ?? {}).at(0) ?? void 0;
|
|
1539
1587
|
const componentTask = {
|
|
@@ -1683,51 +1731,51 @@ var DevelopmentController = class extends import_tsoa3.Controller {
|
|
|
1683
1731
|
}
|
|
1684
1732
|
};
|
|
1685
1733
|
__decorateClass([
|
|
1686
|
-
(0,
|
|
1734
|
+
(0, import_tsoa2.Get)("/all")
|
|
1687
1735
|
], DevelopmentController.prototype, "getComponents", 1);
|
|
1688
1736
|
__decorateClass([
|
|
1689
|
-
(0,
|
|
1690
|
-
__decorateParam(0, (0,
|
|
1737
|
+
(0, import_tsoa2.Get)("/manifest/:componentId"),
|
|
1738
|
+
__decorateParam(0, (0, import_tsoa2.Path)())
|
|
1691
1739
|
], DevelopmentController.prototype, "Manifest", 1);
|
|
1692
1740
|
__decorateClass([
|
|
1693
|
-
(0,
|
|
1694
|
-
__decorateParam(0, (0,
|
|
1741
|
+
(0, import_tsoa2.Get)("/schemas/:componentId"),
|
|
1742
|
+
__decorateParam(0, (0, import_tsoa2.Path)())
|
|
1695
1743
|
], DevelopmentController.prototype, "getContentSchema", 1);
|
|
1696
1744
|
__decorateClass([
|
|
1697
|
-
(0,
|
|
1698
|
-
(0,
|
|
1699
|
-
__decorateParam(0, (0,
|
|
1700
|
-
__decorateParam(1, (0,
|
|
1701
|
-
__decorateParam(2, (0,
|
|
1702
|
-
__decorateParam(3, (0,
|
|
1703
|
-
__decorateParam(4, (0,
|
|
1704
|
-
__decorateParam(5, (0,
|
|
1705
|
-
__decorateParam(6, (0,
|
|
1706
|
-
__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)())
|
|
1707
1755
|
], DevelopmentController.prototype, "TemporaryPreview", 1);
|
|
1708
1756
|
__decorateClass([
|
|
1709
|
-
(0,
|
|
1710
|
-
__decorateParam(0, (0,
|
|
1711
|
-
__decorateParam(1, (0,
|
|
1712
|
-
__decorateParam(2, (0,
|
|
1713
|
-
__decorateParam(3, (0,
|
|
1714
|
-
__decorateParam(4, (0,
|
|
1715
|
-
__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)())
|
|
1716
1764
|
], DevelopmentController.prototype, "getDefaultFunctionRendering", 1);
|
|
1717
1765
|
__decorateClass([
|
|
1718
|
-
(0,
|
|
1719
|
-
__decorateParam(0, (0,
|
|
1720
|
-
__decorateParam(1, (0,
|
|
1721
|
-
__decorateParam(2, (0,
|
|
1722
|
-
__decorateParam(3, (0,
|
|
1723
|
-
__decorateParam(4, (0,
|
|
1724
|
-
__decorateParam(5, (0,
|
|
1725
|
-
__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)())
|
|
1726
1774
|
], DevelopmentController.prototype, "getGivenFunctionRendering", 1);
|
|
1727
1775
|
DevelopmentController = __decorateClass([
|
|
1728
1776
|
(0, import_inversify_binding_decorators2.provide)(DevelopmentController),
|
|
1729
|
-
(0,
|
|
1730
|
-
(0,
|
|
1777
|
+
(0, import_tsoa2.Route)("/dev"),
|
|
1778
|
+
(0, import_tsoa2.Hidden)(),
|
|
1731
1779
|
__decorateParam(0, (0, import_inversify2.inject)("Config")),
|
|
1732
1780
|
__decorateParam(1, (0, import_inversify2.inject)("ManifestService")),
|
|
1733
1781
|
__decorateParam(2, (0, import_inversify2.inject)("DevelopmentComponentRunnerService")),
|
|
@@ -1736,137 +1784,88 @@ DevelopmentController = __decorateClass([
|
|
|
1736
1784
|
__decorateParam(5, (0, import_inversify2.inject)("ComponentFunctionService"))
|
|
1737
1785
|
], DevelopmentController);
|
|
1738
1786
|
|
|
1739
|
-
// src/webserver/controllers/
|
|
1787
|
+
// src/webserver/controllers/CoreController.ts
|
|
1740
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
|
|
1741
1796
|
var import_inversify_binding_decorators3 = require("inversify-binding-decorators");
|
|
1742
|
-
var import_dx_common_lib3 = require("@squiz/dx-common-lib");
|
|
1743
|
-
var import_path = __toESM(require("path"));
|
|
1744
1797
|
var import_inversify3 = require("inversify");
|
|
1745
|
-
var
|
|
1746
|
-
var
|
|
1747
|
-
|
|
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) {
|
|
1748
1802
|
super();
|
|
1749
1803
|
this.manifestService = manifestService;
|
|
1750
|
-
this.componentSetService = componentSetService;
|
|
1751
|
-
this.componentFunctionService = componentFunctionService;
|
|
1752
1804
|
}
|
|
1753
|
-
async
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
const manifest = await this.manifestService.loadManifest(namespace, componentName, version);
|
|
1758
|
-
const manifestModel = manifest.getModel();
|
|
1759
|
-
const response = req.res;
|
|
1760
|
-
(0, import_assert.default)(response);
|
|
1761
|
-
staticFile = import_path.default.join(staticFile, req.params[0]);
|
|
1762
|
-
if (manifestModel.staticFiles) {
|
|
1763
|
-
const componentStaticFileRoot = manifestModel.staticFiles.locationRoot;
|
|
1764
|
-
const manifestPath = await this.manifestService.getManifestPath(namespace, componentName, version);
|
|
1765
|
-
const staticFilePathRoot = import_path.default.join(import_path.default.dirname(manifestPath), componentStaticFileRoot);
|
|
1766
|
-
const headers = await this.getHeadersForInputType(_componentSet, _previewKey, manifest);
|
|
1767
|
-
this.setResponseHeaders(headers, response);
|
|
1768
|
-
response.sendFile(
|
|
1769
|
-
staticFile,
|
|
1770
|
-
{
|
|
1771
|
-
root: staticFilePathRoot,
|
|
1772
|
-
dotfiles: "deny",
|
|
1773
|
-
lastModified: false
|
|
1774
|
-
// handle in DEVX-386
|
|
1775
|
-
//
|
|
1776
|
-
// maxAge: "1y",
|
|
1777
|
-
// immutable: true,
|
|
1778
|
-
// cacheControl: true
|
|
1779
|
-
},
|
|
1780
|
-
(e) => {
|
|
1781
|
-
if (req.next) {
|
|
1782
|
-
if (e?.code == "ENOENT") {
|
|
1783
|
-
req.next(
|
|
1784
|
-
new import_dx_common_lib3.ResourceNotFoundError(
|
|
1785
|
-
`could not find ${e?.path.substr(
|
|
1786
|
-
e?.path.indexOf(componentStaticFileRoot) + componentStaticFileRoot.length
|
|
1787
|
-
)}`
|
|
1788
|
-
)
|
|
1789
|
-
);
|
|
1790
|
-
} else if (e) {
|
|
1791
|
-
req.next(e);
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
);
|
|
1796
|
-
await new Promise((resolve, _reject) => {
|
|
1797
|
-
response.on("finish", () => {
|
|
1798
|
-
response.end();
|
|
1799
|
-
resolve();
|
|
1800
|
-
});
|
|
1801
|
-
});
|
|
1802
|
-
} else {
|
|
1803
|
-
throw new import_dx_common_lib3.ResourceNotFoundError(`${componentName} ${version} doesn't expose any static resources`);
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
setResponseHeaders(headers, response) {
|
|
1807
|
-
setHeadersOnExpressResponse(headers, response);
|
|
1808
|
-
let cacheControl = response.getHeader("cache-control");
|
|
1809
|
-
if (typeof cacheControl != "string") {
|
|
1810
|
-
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("");
|
|
1811
1809
|
}
|
|
1812
|
-
|
|
1813
|
-
cacheControlObj = (0, import_dx_common_lib3.applyDefaultRulesToCacheControlObject)(cacheControlObj);
|
|
1814
|
-
cacheControlObj.immutable = true;
|
|
1815
|
-
cacheControlObj["max-age"] = 604800;
|
|
1816
|
-
response.setHeader("cache-control", (0, import_dx_common_lib3.cacheControlToString)(cacheControlObj));
|
|
1810
|
+
return schema;
|
|
1817
1811
|
}
|
|
1818
|
-
async
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
const previewDefinition = await this.getValidatedPreviewDefinition(_previewKey, manifest.getModel());
|
|
1825
|
-
const functionPreview = previewDefinition.functionData[manifest.getModel().mainFunction];
|
|
1826
|
-
const headers = functionPreview?.headers ? functionPreview.headers : {};
|
|
1827
|
-
return headers;
|
|
1828
|
-
}
|
|
1829
|
-
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);
|
|
1830
1818
|
}
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
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
|
+
}, {});
|
|
1838
1839
|
}
|
|
1839
|
-
|
|
1840
|
-
const
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
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;
|
|
1851
1854
|
}
|
|
1852
1855
|
};
|
|
1853
1856
|
__decorateClass([
|
|
1854
|
-
(0, import_tsoa4.Get)("/:
|
|
1855
|
-
__decorateParam(0, (0, import_tsoa4.Path)())
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
__decorateParam(
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
(0,
|
|
1865
|
-
|
|
1866
|
-
__decorateParam(0, (0, import_inversify3.inject)("ManifestService")),
|
|
1867
|
-
__decorateParam(1, (0, import_inversify3.inject)("ComponentSetService")),
|
|
1868
|
-
__decorateParam(2, (0, import_inversify3.inject)("ComponentFunctionService"))
|
|
1869
|
-
], 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);
|
|
1870
1869
|
|
|
1871
1870
|
// src/ioc.ts
|
|
1872
1871
|
var import_inversify4 = require("inversify");
|
|
@@ -2289,7 +2288,7 @@ var models = {
|
|
|
2289
2288
|
"additionalProperties": { "dataType": "any" }
|
|
2290
2289
|
},
|
|
2291
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
|
|
2292
|
-
"
|
|
2291
|
+
"ComponentManifest": {
|
|
2293
2292
|
"dataType": "refObject",
|
|
2294
2293
|
"properties": {
|
|
2295
2294
|
"$schema": { "dataType": "string", "required": true },
|
|
@@ -2311,9 +2310,9 @@ var models = {
|
|
|
2311
2310
|
"additionalProperties": false
|
|
2312
2311
|
},
|
|
2313
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
|
|
2314
|
-
"
|
|
2313
|
+
"ComponentManifestType": {
|
|
2315
2314
|
"dataType": "refAlias",
|
|
2316
|
-
"type": { "ref": "
|
|
2315
|
+
"type": { "ref": "ComponentManifest", "validators": {} }
|
|
2317
2316
|
},
|
|
2318
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
|
|
2319
2318
|
"ComponentSchema": {
|
|
@@ -2322,309 +2321,291 @@ var models = {
|
|
|
2322
2321
|
}
|
|
2323
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
|
|
2324
2323
|
};
|
|
2325
|
-
var
|
|
2324
|
+
var templateService = new import_runtime4.ExpressTemplateService(models, { "noImplicitAdditionalProperties": "throw-on-extras", "bodyCoercion": true });
|
|
2326
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
|
+
};
|
|
2327
2335
|
app.get(
|
|
2328
|
-
"/
|
|
2329
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2330
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2331
|
-
async function
|
|
2332
|
-
const args = {
|
|
2333
|
-
version: { "in": "path", "name": "version", "required": true, "dataType": "string" }
|
|
2334
|
-
};
|
|
2335
|
-
let validatedArgs = [];
|
|
2336
|
-
try {
|
|
2337
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2338
|
-
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2339
|
-
const controller = await container.get(CoreController);
|
|
2340
|
-
if (typeof controller["setStatus"] === "function") {
|
|
2341
|
-
controller.setStatus(void 0);
|
|
2342
|
-
}
|
|
2343
|
-
const promise = controller.getSchemaVersion.apply(controller, validatedArgs);
|
|
2344
|
-
promiseHandler(controller, promise, response, void 0, next);
|
|
2345
|
-
} catch (err) {
|
|
2346
|
-
return next(err);
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
);
|
|
2350
|
-
app.get(
|
|
2351
|
-
"/",
|
|
2352
|
-
...(0, import_runtime4.fetchMiddlewares)(CoreController),
|
|
2353
|
-
...(0, import_runtime4.fetchMiddlewares)(CoreController.prototype.getComponents),
|
|
2354
|
-
async function CoreController_getComponents(request, response, next) {
|
|
2355
|
-
const args = {
|
|
2356
|
-
req: { "in": "request", "name": "req", "required": true, "dataType": "object" }
|
|
2357
|
-
};
|
|
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) {
|
|
2358
2340
|
let validatedArgs = [];
|
|
2359
2341
|
try {
|
|
2360
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2342
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsStaticController_getPreview, request, response });
|
|
2361
2343
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2362
|
-
const controller = await container.get(
|
|
2344
|
+
const controller = await container.get(StaticController);
|
|
2363
2345
|
if (typeof controller["setStatus"] === "function") {
|
|
2364
2346
|
controller.setStatus(void 0);
|
|
2365
2347
|
}
|
|
2366
|
-
|
|
2367
|
-
|
|
2348
|
+
await templateService.apiHandler({
|
|
2349
|
+
methodName: "getPreview",
|
|
2350
|
+
controller,
|
|
2351
|
+
response,
|
|
2352
|
+
next,
|
|
2353
|
+
validatedArgs,
|
|
2354
|
+
successStatus: void 0
|
|
2355
|
+
});
|
|
2368
2356
|
} catch (err) {
|
|
2369
2357
|
return next(err);
|
|
2370
2358
|
}
|
|
2371
2359
|
}
|
|
2372
2360
|
);
|
|
2361
|
+
const argsDevelopmentController_getComponents = {};
|
|
2373
2362
|
app.get(
|
|
2374
2363
|
"/dev/all",
|
|
2375
2364
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2376
2365
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getComponents),
|
|
2377
2366
|
async function DevelopmentController_getComponents(request, response, next) {
|
|
2378
|
-
const args = {};
|
|
2379
2367
|
let validatedArgs = [];
|
|
2380
2368
|
try {
|
|
2381
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2369
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getComponents, request, response });
|
|
2382
2370
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2383
2371
|
const controller = await container.get(DevelopmentController);
|
|
2384
2372
|
if (typeof controller["setStatus"] === "function") {
|
|
2385
2373
|
controller.setStatus(void 0);
|
|
2386
2374
|
}
|
|
2387
|
-
|
|
2388
|
-
|
|
2375
|
+
await templateService.apiHandler({
|
|
2376
|
+
methodName: "getComponents",
|
|
2377
|
+
controller,
|
|
2378
|
+
response,
|
|
2379
|
+
next,
|
|
2380
|
+
validatedArgs,
|
|
2381
|
+
successStatus: void 0
|
|
2382
|
+
});
|
|
2389
2383
|
} catch (err) {
|
|
2390
2384
|
return next(err);
|
|
2391
2385
|
}
|
|
2392
2386
|
}
|
|
2393
2387
|
);
|
|
2388
|
+
const argsDevelopmentController_Manifest = {
|
|
2389
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2390
|
+
};
|
|
2394
2391
|
app.get(
|
|
2395
2392
|
"/dev/manifest/:componentId",
|
|
2396
2393
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2397
2394
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.Manifest),
|
|
2398
2395
|
async function DevelopmentController_Manifest(request, response, next) {
|
|
2399
|
-
const args = {
|
|
2400
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2401
|
-
};
|
|
2402
2396
|
let validatedArgs = [];
|
|
2403
2397
|
try {
|
|
2404
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2398
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_Manifest, request, response });
|
|
2405
2399
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2406
2400
|
const controller = await container.get(DevelopmentController);
|
|
2407
2401
|
if (typeof controller["setStatus"] === "function") {
|
|
2408
2402
|
controller.setStatus(void 0);
|
|
2409
2403
|
}
|
|
2410
|
-
|
|
2411
|
-
|
|
2404
|
+
await templateService.apiHandler({
|
|
2405
|
+
methodName: "Manifest",
|
|
2406
|
+
controller,
|
|
2407
|
+
response,
|
|
2408
|
+
next,
|
|
2409
|
+
validatedArgs,
|
|
2410
|
+
successStatus: void 0
|
|
2411
|
+
});
|
|
2412
2412
|
} catch (err) {
|
|
2413
2413
|
return next(err);
|
|
2414
2414
|
}
|
|
2415
2415
|
}
|
|
2416
2416
|
);
|
|
2417
|
+
const argsDevelopmentController_getContentSchema = {
|
|
2418
|
+
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2419
|
+
};
|
|
2417
2420
|
app.get(
|
|
2418
2421
|
"/dev/schemas/:componentId",
|
|
2419
2422
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2420
2423
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getContentSchema),
|
|
2421
2424
|
async function DevelopmentController_getContentSchema(request, response, next) {
|
|
2422
|
-
const args = {
|
|
2423
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" }
|
|
2424
|
-
};
|
|
2425
2425
|
let validatedArgs = [];
|
|
2426
2426
|
try {
|
|
2427
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2427
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getContentSchema, request, response });
|
|
2428
2428
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2429
2429
|
const controller = await container.get(DevelopmentController);
|
|
2430
2430
|
if (typeof controller["setStatus"] === "function") {
|
|
2431
2431
|
controller.setStatus(void 0);
|
|
2432
2432
|
}
|
|
2433
|
-
|
|
2434
|
-
|
|
2433
|
+
await templateService.apiHandler({
|
|
2434
|
+
methodName: "getContentSchema",
|
|
2435
|
+
controller,
|
|
2436
|
+
response,
|
|
2437
|
+
next,
|
|
2438
|
+
validatedArgs,
|
|
2439
|
+
successStatus: void 0
|
|
2440
|
+
});
|
|
2435
2441
|
} catch (err) {
|
|
2436
2442
|
return next(err);
|
|
2437
2443
|
}
|
|
2438
2444
|
}
|
|
2439
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
|
+
};
|
|
2440
2456
|
app.get(
|
|
2441
2457
|
"/dev/temp-preview/:componentId/:functionName",
|
|
2442
2458
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2443
2459
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.TemporaryPreview),
|
|
2444
2460
|
async function DevelopmentController_TemporaryPreview(request, response, next) {
|
|
2445
|
-
const args = {
|
|
2446
|
-
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
2447
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2448
|
-
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
2449
|
-
headers: { "in": "query", "name": "headers", "dataType": "any" },
|
|
2450
|
-
envVars: { "in": "query", "name": "envVars", "dataType": "any" },
|
|
2451
|
-
data: { "in": "query", "name": "data", "dataType": "any" },
|
|
2452
|
-
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2453
|
-
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2454
|
-
};
|
|
2455
2461
|
let validatedArgs = [];
|
|
2456
2462
|
try {
|
|
2457
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2463
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_TemporaryPreview, request, response });
|
|
2458
2464
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2459
2465
|
const controller = await container.get(DevelopmentController);
|
|
2460
2466
|
if (typeof controller["setStatus"] === "function") {
|
|
2461
2467
|
controller.setStatus(void 0);
|
|
2462
2468
|
}
|
|
2463
|
-
|
|
2464
|
-
|
|
2469
|
+
await templateService.apiHandler({
|
|
2470
|
+
methodName: "TemporaryPreview",
|
|
2471
|
+
controller,
|
|
2472
|
+
response,
|
|
2473
|
+
next,
|
|
2474
|
+
validatedArgs,
|
|
2475
|
+
successStatus: void 0
|
|
2476
|
+
});
|
|
2465
2477
|
} catch (err) {
|
|
2466
2478
|
return next(err);
|
|
2467
2479
|
}
|
|
2468
2480
|
}
|
|
2469
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
|
+
};
|
|
2470
2490
|
app.get(
|
|
2471
2491
|
"/dev/render/:componentId",
|
|
2472
2492
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2473
2493
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getDefaultFunctionRendering),
|
|
2474
2494
|
async function DevelopmentController_getDefaultFunctionRendering(request, response, next) {
|
|
2475
|
-
const args = {
|
|
2476
|
-
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
2477
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2478
|
-
componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2479
|
-
previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
2480
|
-
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2481
|
-
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2482
|
-
};
|
|
2483
2495
|
let validatedArgs = [];
|
|
2484
2496
|
try {
|
|
2485
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2497
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getDefaultFunctionRendering, request, response });
|
|
2486
2498
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2487
2499
|
const controller = await container.get(DevelopmentController);
|
|
2488
2500
|
if (typeof controller["setStatus"] === "function") {
|
|
2489
2501
|
controller.setStatus(void 0);
|
|
2490
2502
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2503
|
+
await templateService.apiHandler({
|
|
2504
|
+
methodName: "getDefaultFunctionRendering",
|
|
2505
|
+
controller,
|
|
2506
|
+
response,
|
|
2507
|
+
next,
|
|
2508
|
+
validatedArgs,
|
|
2509
|
+
successStatus: void 0
|
|
2510
|
+
});
|
|
2493
2511
|
} catch (err) {
|
|
2494
2512
|
return next(err);
|
|
2495
2513
|
}
|
|
2496
2514
|
}
|
|
2497
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
|
+
};
|
|
2498
2525
|
app.get(
|
|
2499
2526
|
"/dev/render/:componentId/:functionName",
|
|
2500
2527
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController),
|
|
2501
2528
|
...(0, import_runtime4.fetchMiddlewares)(DevelopmentController.prototype.getGivenFunctionRendering),
|
|
2502
2529
|
async function DevelopmentController_getGivenFunctionRendering(request, response, next) {
|
|
2503
|
-
const args = {
|
|
2504
|
-
expressRequest: { "in": "request", "name": "expressRequest", "required": true, "dataType": "object" },
|
|
2505
|
-
componentId: { "in": "path", "name": "componentId", "required": true, "dataType": "string" },
|
|
2506
|
-
functionName: { "in": "path", "name": "functionName", "required": true, "dataType": "string" },
|
|
2507
|
-
componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2508
|
-
previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" },
|
|
2509
|
-
contextMatrixAssetId: { "in": "query", "name": "contextMatrixAssetId", "dataType": "string" },
|
|
2510
|
-
contextMatrixUrl: { "in": "query", "name": "contextMatrixUrl", "dataType": "string" }
|
|
2511
|
-
};
|
|
2512
2530
|
let validatedArgs = [];
|
|
2513
2531
|
try {
|
|
2514
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2532
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDevelopmentController_getGivenFunctionRendering, request, response });
|
|
2515
2533
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2516
2534
|
const controller = await container.get(DevelopmentController);
|
|
2517
2535
|
if (typeof controller["setStatus"] === "function") {
|
|
2518
2536
|
controller.setStatus(void 0);
|
|
2519
2537
|
}
|
|
2520
|
-
|
|
2521
|
-
|
|
2538
|
+
await templateService.apiHandler({
|
|
2539
|
+
methodName: "getGivenFunctionRendering",
|
|
2540
|
+
controller,
|
|
2541
|
+
response,
|
|
2542
|
+
next,
|
|
2543
|
+
validatedArgs,
|
|
2544
|
+
successStatus: void 0
|
|
2545
|
+
});
|
|
2522
2546
|
} catch (err) {
|
|
2523
2547
|
return next(err);
|
|
2524
2548
|
}
|
|
2525
2549
|
}
|
|
2526
2550
|
);
|
|
2551
|
+
const argsCoreController_getSchemaVersion = {
|
|
2552
|
+
version: { "in": "path", "name": "version", "required": true, "dataType": "string" }
|
|
2553
|
+
};
|
|
2527
2554
|
app.get(
|
|
2528
|
-
"/
|
|
2529
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2530
|
-
...(0, import_runtime4.fetchMiddlewares)(
|
|
2531
|
-
async function
|
|
2532
|
-
const args = {
|
|
2533
|
-
namespace: { "in": "path", "name": "namespace", "required": true, "dataType": "string" },
|
|
2534
|
-
componentName: { "in": "path", "name": "componentName", "required": true, "dataType": "string" },
|
|
2535
|
-
version: { "in": "path", "name": "version", "required": true, "dataType": "string" },
|
|
2536
|
-
staticFile: { "in": "path", "name": "staticFile", "required": true, "dataType": "string" },
|
|
2537
|
-
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
2538
|
-
_componentSet: { "in": "query", "name": "_componentSet", "dataType": "string" },
|
|
2539
|
-
_previewKey: { "in": "query", "name": "_previewKey", "dataType": "string" }
|
|
2540
|
-
};
|
|
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) {
|
|
2541
2559
|
let validatedArgs = [];
|
|
2542
2560
|
try {
|
|
2543
|
-
validatedArgs = getValidatedArgs(args, request, response);
|
|
2561
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsCoreController_getSchemaVersion, request, response });
|
|
2544
2562
|
const container = typeof iocContainer === "function" ? iocContainer(request) : iocContainer;
|
|
2545
|
-
const controller = await container.get(
|
|
2563
|
+
const controller = await container.get(CoreController);
|
|
2546
2564
|
if (typeof controller["setStatus"] === "function") {
|
|
2547
2565
|
controller.setStatus(void 0);
|
|
2548
2566
|
}
|
|
2549
|
-
|
|
2550
|
-
|
|
2567
|
+
await templateService.apiHandler({
|
|
2568
|
+
methodName: "getSchemaVersion",
|
|
2569
|
+
controller,
|
|
2570
|
+
response,
|
|
2571
|
+
next,
|
|
2572
|
+
validatedArgs,
|
|
2573
|
+
successStatus: void 0
|
|
2574
|
+
});
|
|
2551
2575
|
} catch (err) {
|
|
2552
2576
|
return next(err);
|
|
2553
2577
|
}
|
|
2554
2578
|
}
|
|
2555
2579
|
);
|
|
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
|
-
|
|
2582
|
-
} else {
|
|
2583
|
-
response.status(statusCode || 204).end();
|
|
2584
|
-
}
|
|
2585
|
-
}
|
|
2586
|
-
function responder(response) {
|
|
2587
|
-
return function(status, data, headers) {
|
|
2588
|
-
returnHandler(response, status, data, headers);
|
|
2589
|
-
};
|
|
2590
|
-
}
|
|
2591
|
-
;
|
|
2592
|
-
function getValidatedArgs(args, request, response) {
|
|
2593
|
-
const fieldErrors = {};
|
|
2594
|
-
const values = Object.keys(args).map((key) => {
|
|
2595
|
-
const name = args[key].name;
|
|
2596
|
-
switch (args[key].in) {
|
|
2597
|
-
case "request":
|
|
2598
|
-
return request;
|
|
2599
|
-
case "query":
|
|
2600
|
-
return validationService.ValidateParam(args[key], request.query[name], name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2601
|
-
case "queries":
|
|
2602
|
-
return validationService.ValidateParam(args[key], request.query, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2603
|
-
case "path":
|
|
2604
|
-
return validationService.ValidateParam(args[key], request.params[name], name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2605
|
-
case "header":
|
|
2606
|
-
return validationService.ValidateParam(args[key], request.header(name), name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2607
|
-
case "body":
|
|
2608
|
-
return validationService.ValidateParam(args[key], request.body, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2609
|
-
case "body-prop":
|
|
2610
|
-
return validationService.ValidateParam(args[key], request.body[name], name, fieldErrors, "body.", { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2611
|
-
case "formData":
|
|
2612
|
-
if (args[key].dataType === "file") {
|
|
2613
|
-
return validationService.ValidateParam(args[key], request.file, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2614
|
-
} else if (args[key].dataType === "array" && args[key].array.dataType === "file") {
|
|
2615
|
-
return validationService.ValidateParam(args[key], request.files, name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2616
|
-
} else {
|
|
2617
|
-
return validationService.ValidateParam(args[key], request.body[name], name, fieldErrors, void 0, { "noImplicitAdditionalProperties": "throw-on-extras" });
|
|
2618
|
-
}
|
|
2619
|
-
case "res":
|
|
2620
|
-
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);
|
|
2621
2606
|
}
|
|
2622
|
-
});
|
|
2623
|
-
if (Object.keys(fieldErrors).length > 0) {
|
|
2624
|
-
throw new import_runtime4.ValidateError(fieldErrors, "");
|
|
2625
2607
|
}
|
|
2626
|
-
|
|
2627
|
-
}
|
|
2608
|
+
);
|
|
2628
2609
|
}
|
|
2629
2610
|
|
|
2630
2611
|
// src/webserver/app.ts
|
|
@@ -3394,26 +3375,24 @@ function generateRandomName() {
|
|
|
3394
3375
|
}
|
|
3395
3376
|
|
|
3396
3377
|
// src/webserver/controllers/test/render-route-tests.ts
|
|
3378
|
+
var import_dxp_session_lib = require("@squiz/dxp-session-lib");
|
|
3379
|
+
var mockedSession = (0, import_dxp_session_lib.buildDevelopmentSession)({
|
|
3380
|
+
version: import_dxp_session_lib.DxpSessionVersion.version1
|
|
3381
|
+
});
|
|
3397
3382
|
function renderRouteTests(request, _rootUrl) {
|
|
3398
3383
|
describe("GET /dev/render/unit-test-components__test-component__1.0.10/?_componentSet=set", () => {
|
|
3399
3384
|
it("should render the test component with html endpoint", async () => {
|
|
3400
|
-
const response = await request().get(
|
|
3401
|
-
"/dev/render/unit-test-components__test-component__1.0.10?_componentSet=set&something=unused"
|
|
3402
|
-
);
|
|
3385
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.10?_componentSet=set&something=unused").set({ "x-dxp-session": mockedSession });
|
|
3403
3386
|
expect(response.text).toEqual("<div>hello - {}</div>");
|
|
3404
3387
|
expect(response.statusCode).toEqual(200);
|
|
3405
3388
|
}, 2e4);
|
|
3406
3389
|
it("should render the test component promise endpoint with html endpoint", async () => {
|
|
3407
|
-
const response = await request().get(
|
|
3408
|
-
"/dev/render/unit-test-components__test-component__1.0.10/promise?_componentSet=set&something=unused"
|
|
3409
|
-
);
|
|
3390
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.10/promise?_componentSet=set&something=unused").set({ "x-dxp-session": mockedSession });
|
|
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(
|
|
3415
|
-
"/dev/render/unit-test-components__test-component__1.0.0?_componentSet=set&something=unused"
|
|
3416
|
-
);
|
|
3395
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.0?_componentSet=set&something=unused").set({ "x-dxp-session": mockedSession });
|
|
3417
3396
|
expect(response.statusCode).toEqual(400);
|
|
3418
3397
|
expect(response.body).toMatchInlineSnapshot(`
|
|
3419
3398
|
{
|
|
@@ -3424,7 +3403,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3424
3403
|
it("should 404 if requesting a non-existent function on an otherwise valid component", async () => {
|
|
3425
3404
|
const response = await request().get(
|
|
3426
3405
|
"/dev/render/unit-test-components__test-component__1.0.0/non-existent-entry-file?_componentSet=set&something=not-used"
|
|
3427
|
-
);
|
|
3406
|
+
).set({ "x-dxp-session": mockedSession });
|
|
3428
3407
|
expect(response.statusCode).toEqual(404);
|
|
3429
3408
|
expect(response.body).toMatchInlineSnapshot(`
|
|
3430
3409
|
{
|
|
@@ -3435,9 +3414,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3435
3414
|
});
|
|
3436
3415
|
describe("GET /dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set", () => {
|
|
3437
3416
|
it("should fail validation when requesting a function with a missing entry file", async () => {
|
|
3438
|
-
const response = await request().get(
|
|
3439
|
-
"/dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set&something=not-used"
|
|
3440
|
-
);
|
|
3417
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set&something=not-used").set({ "x-dxp-session": mockedSession });
|
|
3441
3418
|
expect(response.body).toEqual({
|
|
3442
3419
|
message: `"main's" entry file "missing-entry-file.js" is inaccessible`
|
|
3443
3420
|
});
|
|
@@ -3446,7 +3423,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3446
3423
|
});
|
|
3447
3424
|
describe("GET /dev/render/unit-test-components__test-component__1.0.4?_componentSet=set", () => {
|
|
3448
3425
|
it("should render a simple json endpoint", async () => {
|
|
3449
|
-
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4?_componentSet=set");
|
|
3426
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4?_componentSet=set").set({ "x-dxp-session": mockedSession });
|
|
3450
3427
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
3451
3428
|
expect(response.body).toEqual({
|
|
3452
3429
|
"my-prop": "test value for my-prop",
|
|
@@ -3459,9 +3436,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3459
3436
|
});
|
|
3460
3437
|
}, 2e4);
|
|
3461
3438
|
it("should report error if response does not match with the schema", async () => {
|
|
3462
|
-
const response = await request().get(
|
|
3463
|
-
"/dev/render/unit-test-components__test-component__1.0.4/render_json_invalid?_componentSet=set"
|
|
3464
|
-
);
|
|
3439
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4/render_json_invalid?_componentSet=set").set({ "x-dxp-session": mockedSession });
|
|
3465
3440
|
expect(response.statusCode).toEqual(500);
|
|
3466
3441
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
3467
3442
|
expect(response.body).toEqual({
|
|
@@ -3471,7 +3446,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3471
3446
|
it("should validate a complex json against a schema", async () => {
|
|
3472
3447
|
const response = await request().get(
|
|
3473
3448
|
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_valid?_componentSet=set"
|
|
3474
|
-
);
|
|
3449
|
+
).set({ "x-dxp-session": mockedSession });
|
|
3475
3450
|
const myObject = {
|
|
3476
3451
|
"my-object": {
|
|
3477
3452
|
"a-string": "this is a string",
|
|
@@ -3487,7 +3462,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3487
3462
|
it("should report errors if nested object json schema fails", async () => {
|
|
3488
3463
|
const response = await request().get(
|
|
3489
3464
|
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_invalid?_componentSet=set"
|
|
3490
|
-
);
|
|
3465
|
+
).set({ "x-dxp-session": mockedSession });
|
|
3491
3466
|
expect(response.statusCode).toEqual(500);
|
|
3492
3467
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
3493
3468
|
expect(response.body).toEqual({
|
|
@@ -3500,7 +3475,7 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3500
3475
|
it('should return input and info object with "query parameters"', async () => {
|
|
3501
3476
|
const response = await request().get(
|
|
3502
3477
|
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&something=hello-test&foo=foo-val&foo2=foo2-val"
|
|
3503
|
-
);
|
|
3478
|
+
).set({ "x-dxp-session": mockedSession });
|
|
3504
3479
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
3505
3480
|
const result = response.body;
|
|
3506
3481
|
expect(result).toEqual([
|
|
@@ -3578,18 +3553,14 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3578
3553
|
});
|
|
3579
3554
|
});
|
|
3580
3555
|
it("should throw error if required query parameter is missing", async () => {
|
|
3581
|
-
const response = await request().get(
|
|
3582
|
-
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo2=foo2-val"
|
|
3583
|
-
);
|
|
3556
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo2=foo2-val").set({ "x-dxp-session": mockedSession });
|
|
3584
3557
|
expect(response.body).toEqual({
|
|
3585
3558
|
message: "Required query parameter 'foo' is missing"
|
|
3586
3559
|
});
|
|
3587
3560
|
expect(response.statusCode).toEqual(400);
|
|
3588
3561
|
});
|
|
3589
3562
|
it("should throw error if query parameter is not a string", async () => {
|
|
3590
|
-
const response = await request().get(
|
|
3591
|
-
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo=123&foo2[]=array-val"
|
|
3592
|
-
);
|
|
3563
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo=123&foo2[]=array-val").set({ "x-dxp-session": mockedSession });
|
|
3593
3564
|
expect(response.body).toEqual({
|
|
3594
3565
|
message: "Value for query parameter 'foo2' must be a string"
|
|
3595
3566
|
});
|
|
@@ -3597,60 +3568,48 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3597
3568
|
});
|
|
3598
3569
|
describe("GET /dev/render/unit-test-components__test-headers__1.0.3?_componentSet=set", () => {
|
|
3599
3570
|
it("should make sure max-age header is clamped between max value", async () => {
|
|
3600
|
-
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/max_value?_componentSet=set").send().expect(200, "rendered");
|
|
3571
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/max_value?_componentSet=set").set({ "x-dxp-session": mockedSession }).send().expect(200, "rendered");
|
|
3601
3572
|
expect(response.headers["cache-control"]).toEqual("max-age=1800, immutable");
|
|
3602
3573
|
});
|
|
3603
3574
|
it("should make sure max-age header is clamped between min value", async () => {
|
|
3604
|
-
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/min_value?_componentSet=set").send().expect(200, "rendered");
|
|
3575
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/min_value?_componentSet=set").set({ "x-dxp-session": mockedSession }).send().expect(200, "rendered");
|
|
3605
3576
|
expect(response.headers["cache-control"]).toEqual("max-age=30, public");
|
|
3606
3577
|
});
|
|
3607
3578
|
});
|
|
3608
3579
|
describe("should be able to load external dependencies", () => {
|
|
3609
3580
|
it("should be able to make web requests out", async () => {
|
|
3610
|
-
const response = await request().get(
|
|
3611
|
-
"/dev/render/unit-test-components__test-npm-modules__3.0.0?_componentSet=set"
|
|
3612
|
-
);
|
|
3581
|
+
const response = await request().get("/dev/render/unit-test-components__test-npm-modules__3.0.0?_componentSet=set").set({ "x-dxp-session": mockedSession });
|
|
3613
3582
|
expect(response.statusCode).toEqual(200);
|
|
3614
3583
|
expect(response.text).toContain(`<h1>Example Domain</h1>`);
|
|
3615
3584
|
});
|
|
3616
3585
|
});
|
|
3617
3586
|
describe("GET /dev/render/unit-test-components__test-formatted-text__1.0.0", () => {
|
|
3618
3587
|
it("should render a component formattedText in preview inline", async () => {
|
|
3619
|
-
const response = await request().get(
|
|
3620
|
-
"/dev/render/unit-test-components__test-formatted-text__1.0.0?_previewKey=valid-inline-preview"
|
|
3621
|
-
);
|
|
3588
|
+
const response = await request().get("/dev/render/unit-test-components__test-formatted-text__1.0.0?_previewKey=valid-inline-preview").set({ "x-dxp-session": mockedSession });
|
|
3622
3589
|
expect(response.statusCode).toEqual(200);
|
|
3623
3590
|
expect(response.text).toMatchInlineSnapshot(`"This is a test"`);
|
|
3624
3591
|
});
|
|
3625
3592
|
});
|
|
3626
3593
|
describe("GET /dev/render/unit-test-components__test-npm-modules__3.1.0", () => {
|
|
3627
3594
|
it("should render a component with uuid", async () => {
|
|
3628
|
-
const response = await request().get(
|
|
3629
|
-
"/dev/render/unit-test-components__test-npm-modules__3.1.0/uuid?_componentSet=set"
|
|
3630
|
-
);
|
|
3595
|
+
const response = await request().get("/dev/render/unit-test-components__test-npm-modules__3.1.0/uuid?_componentSet=set").set({ "x-dxp-session": mockedSession });
|
|
3631
3596
|
expect(response.statusCode).toEqual(200);
|
|
3632
3597
|
});
|
|
3633
3598
|
it("should render a component with Buffer", async () => {
|
|
3634
|
-
const response = await request().get(
|
|
3635
|
-
"/dev/render/unit-test-components__test-npm-modules__3.1.0/buffer?_componentSet=set"
|
|
3636
|
-
);
|
|
3599
|
+
const response = await request().get("/dev/render/unit-test-components__test-npm-modules__3.1.0/buffer?_componentSet=set").set({ "x-dxp-session": mockedSession });
|
|
3637
3600
|
expect(response.statusCode).toEqual(200);
|
|
3638
3601
|
});
|
|
3639
3602
|
});
|
|
3640
3603
|
describe("GET /dev/render/unit-test-components__test-squiz-image__1.0.0", () => {
|
|
3641
3604
|
it("should render the preview", async () => {
|
|
3642
|
-
const response = await request().get(
|
|
3643
|
-
"/dev/render/unit-test-components__test-squiz-image__1.0.0?_previewKey=valid-inline-preview"
|
|
3644
|
-
);
|
|
3605
|
+
const response = await request().get("/dev/render/unit-test-components__test-squiz-image__1.0.0?_previewKey=valid-inline-preview").set({ "x-dxp-session": mockedSession });
|
|
3645
3606
|
expect(response.statusCode).toEqual(200);
|
|
3646
3607
|
expect(response.text).toMatchInlineSnapshot(`"My Image Component"`);
|
|
3647
3608
|
});
|
|
3648
3609
|
});
|
|
3649
3610
|
describe("GET /dev/render/unit-test-components__test-squiz-link__1.0.0", () => {
|
|
3650
3611
|
it("should render the preview", async () => {
|
|
3651
|
-
const response = await request().get(
|
|
3652
|
-
"/dev/render/unit-test-components__test-squiz-link__1.0.0?_previewKey=valid-inline-preview"
|
|
3653
|
-
);
|
|
3612
|
+
const response = await request().get("/dev/render/unit-test-components__test-squiz-link__1.0.0?_previewKey=valid-inline-preview").set({ "x-dxp-session": mockedSession });
|
|
3654
3613
|
expect(response.statusCode).toEqual(200);
|
|
3655
3614
|
expect(response.text).toMatchInlineSnapshot(`"{"link":{"text":"My Link","url":"https://some.link/foo"}}"`);
|
|
3656
3615
|
});
|
|
@@ -3658,16 +3617,20 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3658
3617
|
}
|
|
3659
3618
|
|
|
3660
3619
|
// src/webserver/controllers/test/preview-route-tests.ts
|
|
3620
|
+
var import_dxp_session_lib2 = require("@squiz/dxp-session-lib");
|
|
3621
|
+
var mockedSession2 = (0, import_dxp_session_lib2.buildDevelopmentSession)({
|
|
3622
|
+
version: import_dxp_session_lib2.DxpSessionVersion.version1
|
|
3623
|
+
});
|
|
3661
3624
|
function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
3662
3625
|
describe("preview routes", () => {
|
|
3663
3626
|
it("should render a preview of a component with no wrapper file", async () => {
|
|
3664
|
-
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");
|
|
3627
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=test-preview").set({ "x-dxp-session": mockedSession2 }).expect(200).expect("content-type", "text/html; charset=utf-8").expect("800 | this is nested content");
|
|
3665
3628
|
});
|
|
3666
3629
|
it("should render a preview of a component with a different preset", async () => {
|
|
3667
|
-
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");
|
|
3630
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=another-preview").set({ "x-dxp-session": mockedSession2 }).expect(200).expect("content-type", "text/html; charset=utf-8").expect("12300 | this is also nested content");
|
|
3668
3631
|
});
|
|
3669
3632
|
it("should render a preview of a component non-main function with a wrapper html file", async () => {
|
|
3670
|
-
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) => {
|
|
3633
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4/other?_previewKey=another-preview").set({ "x-dxp-session": mockedSession2 }).expect(200).expect("content-type", "text/html; charset=utf-8").expect((a) => {
|
|
3671
3634
|
expect(a.text).toMatchInlineSnapshot(`
|
|
3672
3635
|
"<!DOCTYPE html>
|
|
3673
3636
|
<html lang="en">
|
|
@@ -3686,30 +3649,24 @@ function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
|
3686
3649
|
});
|
|
3687
3650
|
});
|
|
3688
3651
|
it("should load the defined preview for a given preview key", async () => {
|
|
3689
|
-
const response = await request().get(
|
|
3690
|
-
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=second-preview"
|
|
3691
|
-
);
|
|
3652
|
+
const response = await request().get("/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=second-preview").set({ "x-dxp-session": mockedSession2 });
|
|
3692
3653
|
expect(response.text).toContain(`<p>Second Preview</p>`);
|
|
3693
3654
|
expect(response.statusCode).toEqual(200);
|
|
3694
3655
|
});
|
|
3695
3656
|
it("should give meaningful error when preview key is invalid", async () => {
|
|
3696
|
-
const response = await request().get(
|
|
3697
|
-
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=invalid"
|
|
3698
|
-
);
|
|
3657
|
+
const response = await request().get("/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=invalid").set({ "x-dxp-session": mockedSession2 });
|
|
3699
3658
|
expect(response.text).toEqual(
|
|
3700
3659
|
`{"message":"Component has not defined preview with key \\"invalid\\", the defined preview keys for this component are \\"first-preview, second-preview, test-preview\\""}`
|
|
3701
3660
|
);
|
|
3702
3661
|
expect(response.statusCode).toEqual(404);
|
|
3703
3662
|
});
|
|
3704
3663
|
it("should render inline preview data through to component", async () => {
|
|
3705
|
-
const response = await request().get(
|
|
3706
|
-
"/dev/render/unit-test-components__test-preview-component__1.0.4?_previewKey=test-preview"
|
|
3707
|
-
);
|
|
3664
|
+
const response = await request().get("/dev/render/unit-test-components__test-preview-component__1.0.4?_previewKey=test-preview").set({ "x-dxp-session": mockedSession2 });
|
|
3708
3665
|
expect(response.text).toContain(`this is a result | 123`);
|
|
3709
3666
|
expect(response.statusCode).toEqual(200);
|
|
3710
3667
|
}, 1e4);
|
|
3711
3668
|
it("should resolve URIs to mocked URI object in preview route", async () => {
|
|
3712
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.1.1?_previewKey=test-preview").expect(200).expect((a) => {
|
|
3669
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.1.1?_previewKey=test-preview").set({ "x-dxp-session": mockedSession2 }).expect(200).expect((a) => {
|
|
3713
3670
|
expect(a.text).toMatchInlineSnapshot(`
|
|
3714
3671
|
"
|
|
3715
3672
|
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":{}}
|