@squiz/render-runtime-lib 1.74.0 → 1.75.0

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.
Files changed (122) hide show
  1. package/lib/PreviewComponentService.js +43 -0
  2. package/lib/PreviewComponentService.js.map +1 -0
  3. package/lib/PreviewComponentService.spec.js +64 -0
  4. package/lib/PreviewComponentService.spec.js.map +1 -0
  5. package/lib/RenderInputService.js +286 -0
  6. package/lib/RenderInputService.js.map +1 -0
  7. package/lib/RenderInputService.spec.js +645 -0
  8. package/lib/RenderInputService.spec.js.map +1 -0
  9. package/lib/component-runner/ComponentRootUrlResolver.js +3 -0
  10. package/lib/component-runner/ComponentRootUrlResolver.js.map +1 -0
  11. package/lib/component-runner/ComponentRunnerServiceWithWorkers.js +91 -0
  12. package/lib/component-runner/ComponentRunnerServiceWithWorkers.js.map +1 -0
  13. package/lib/component-runner/ComponentRunnerServiceWithWorkers.spec.js +104 -0
  14. package/lib/component-runner/ComponentRunnerServiceWithWorkers.spec.js.map +1 -0
  15. package/lib/component-runner/ComponentRuntimeContext.d.ts +1 -8
  16. package/lib/component-runner/ComponentRuntimeContext.js +3 -0
  17. package/lib/component-runner/ComponentRuntimeContext.js.map +1 -0
  18. package/lib/component-runner/ContentRuntimeService.js +31 -0
  19. package/lib/component-runner/ContentRuntimeService.js.map +1 -0
  20. package/lib/component-runner/ExecuteComponentTask.d.ts +1 -9
  21. package/lib/component-runner/ExecuteComponentTask.js +8 -0
  22. package/lib/component-runner/ExecuteComponentTask.js.map +1 -0
  23. package/lib/component-runner/FunctionReturnTypes.js +3 -0
  24. package/lib/component-runner/FunctionReturnTypes.js.map +1 -0
  25. package/lib/component-runner/index.js +23 -0
  26. package/lib/component-runner/index.js.map +1 -0
  27. package/lib/component-runner/worker/component-bootstrapper.js +63 -0
  28. package/lib/component-runner/worker/component-bootstrapper.js.map +1 -0
  29. package/lib/health-check-service.js +3 -0
  30. package/lib/health-check-service.js.map +1 -0
  31. package/lib/index.d.ts +0 -16
  32. package/lib/index.js +23 -4610
  33. package/lib/index.js.map +1 -7
  34. package/lib/ioc.js +37 -0
  35. package/lib/ioc.js.map +1 -0
  36. package/lib/test/helpers/fixtures.js +152 -0
  37. package/lib/test/helpers/fixtures.js.map +1 -0
  38. package/lib/test/helpers/stack.js +121 -0
  39. package/lib/test/helpers/stack.js.map +1 -0
  40. package/lib/test/index.js +21 -0
  41. package/lib/test/index.js.map +1 -0
  42. package/lib/test/mock-services/MockedComponentSetService.js +413 -0
  43. package/lib/test/mock-services/MockedComponentSetService.js.map +1 -0
  44. package/lib/test/mock-services/MockedContentItemService.js +37 -0
  45. package/lib/test/mock-services/MockedContentItemService.js.map +1 -0
  46. package/lib/test-helpers.d.ts +16 -0
  47. package/lib/test-helpers.js +44 -0
  48. package/lib/test-helpers.js.map +1 -0
  49. package/lib/utils/getContentItemIdFromInput.js +13 -0
  50. package/lib/utils/getContentItemIdFromInput.js.map +1 -0
  51. package/lib/utils/getContentItemIdFromInput.spec.js +18 -0
  52. package/lib/utils/getContentItemIdFromInput.spec.js.map +1 -0
  53. package/lib/utils/resolvePreviewOutput.js +71 -0
  54. package/lib/utils/resolvePreviewOutput.js.map +1 -0
  55. package/lib/utils/resolvePreviewOutput.spec.js +168 -0
  56. package/lib/utils/resolvePreviewOutput.spec.js.map +1 -0
  57. package/lib/utils/setHeadersOnExpressResponse.js +15 -0
  58. package/lib/utils/setHeadersOnExpressResponse.js.map +1 -0
  59. package/lib/utils/setHeadersOnExpressResponse.sepc.js +21 -0
  60. package/lib/utils/setHeadersOnExpressResponse.sepc.js.map +1 -0
  61. package/lib/webserver/app.js +78 -0
  62. package/lib/webserver/app.js.map +1 -0
  63. package/lib/webserver/controllers/CoreController.js +116 -0
  64. package/lib/webserver/controllers/CoreController.js.map +1 -0
  65. package/lib/webserver/controllers/CoreController.spec.js +132 -0
  66. package/lib/webserver/controllers/CoreController.spec.js.map +1 -0
  67. package/lib/webserver/controllers/DefinitionController.js +162 -0
  68. package/lib/webserver/controllers/DefinitionController.js.map +1 -0
  69. package/lib/webserver/controllers/DefinitionController.spec.js +16 -0
  70. package/lib/webserver/controllers/DefinitionController.spec.js.map +1 -0
  71. package/lib/webserver/controllers/DevelopmentController.js +149 -0
  72. package/lib/webserver/controllers/DevelopmentController.js.map +1 -0
  73. package/lib/webserver/controllers/DevelopmentController.spec.js +29 -0
  74. package/lib/webserver/controllers/DevelopmentController.spec.js.map +1 -0
  75. package/lib/webserver/controllers/PreviewController.spec.js +124 -0
  76. package/lib/webserver/controllers/PreviewController.spec.js.map +1 -0
  77. package/lib/webserver/controllers/RenderController.d.ts +3 -2
  78. package/lib/webserver/controllers/RenderController.js +221 -0
  79. package/lib/webserver/controllers/RenderController.js.map +1 -0
  80. package/lib/webserver/controllers/RenderController.spec.js +441 -0
  81. package/lib/webserver/controllers/RenderController.spec.js.map +1 -0
  82. package/lib/webserver/controllers/StaticController.js +149 -0
  83. package/lib/webserver/controllers/StaticController.js.map +1 -0
  84. package/lib/webserver/controllers/StaticController.spec.js +28 -0
  85. package/lib/webserver/controllers/StaticController.spec.js.map +1 -0
  86. package/lib/webserver/controllers/test/definition-route-tests.js +627 -0
  87. package/lib/webserver/controllers/test/definition-route-tests.js.map +1 -0
  88. package/lib/webserver/controllers/test/development-route-tests.js +110 -0
  89. package/lib/webserver/controllers/test/development-route-tests.js.map +1 -0
  90. package/lib/webserver/controllers/test/preview-route-tests.js +122 -0
  91. package/lib/webserver/controllers/test/preview-route-tests.js.map +1 -0
  92. package/lib/webserver/controllers/test/render-route-sandbox-tests.js +194 -0
  93. package/lib/webserver/controllers/test/render-route-sandbox-tests.js.map +1 -0
  94. package/lib/webserver/controllers/test/render-route-tests.js +422 -0
  95. package/lib/webserver/controllers/test/render-route-tests.js.map +1 -0
  96. package/lib/webserver/controllers/test/static-route-tests.js +96 -0
  97. package/lib/webserver/controllers/test/static-route-tests.js.map +1 -0
  98. package/lib/webserver/index.js +6 -0
  99. package/lib/webserver/index.js.map +1 -0
  100. package/lib/webserver/routes/routes.js +902 -0
  101. package/lib/webserver/routes/routes.js.map +1 -0
  102. package/package.json +13 -6
  103. package/lib/migrations/20220704054051_initial.sql +0 -19
  104. package/lib/migrations/20220718172237_adding_component_sets.sql +0 -23
  105. package/lib/migrations/20220728113941_add_env_vars_field.sql +0 -1
  106. package/lib/migrations/20220817113300_removing_null_props_from_jsonb.sql +0 -41
  107. package/lib/migrations/20221027151225_dummy.sql +0 -2
  108. package/lib/migrations/20221117151200_add_detail_columns_to_component_version.js +0 -40
  109. package/lib/migrations/20221220151200_add_required_to_manifests.js +0 -7794
  110. package/lib/migrations/20221222151200_add_required_to_manifests.js +0 -7856
  111. package/lib/migrations/20223525103556_component_set_rule.sql +0 -19
  112. package/lib/migrations/20230111095522_update_environment_property.js +0 -7802
  113. package/lib/migrations/20230203084900_ensure_static_root_exists.js +0 -47
  114. package/lib/migrations/20230210143300_lowercase_all_uri_names.js +0 -88
  115. package/lib/migrations/20230217151212_component_set_component_version_updates.sql +0 -38
  116. package/lib/migrations/20230218121212_add_component_set_rules.js +0 -24
  117. package/lib/migrations/202406061447_edge_component_type.sql +0 -1
  118. package/lib/migrations/202407111308_component_version_type.sql +0 -1
  119. package/lib/migrations/202408061132_update_type_to_server.sql +0 -1
  120. package/lib/public/docs.json +0 -5509
  121. package/lib/worker/component-bootstrapper.js +0 -170132
  122. package/lib/worker/component-bootstrapper.js.map +0 -7
@@ -0,0 +1,422 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.renderRouteTests = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ function renderRouteTests(request, rootUrl) {
9
+ describe('GET /r/unit-test-components/test-component/1.0.10/?_componentSet=set', () => {
10
+ it('should render the test component with html endpoint', async () => {
11
+ const response = await request().get('/r/unit-test-components/test-component/1.0.10?_componentSet=set&something=unused');
12
+ expect(response.text).toEqual('<div>hello - {}</div>');
13
+ expect(response.statusCode).toEqual(200);
14
+ }, 20000);
15
+ it('should render the test component promise endpoint with html endpoint', async () => {
16
+ const response = await request().get('/r/unit-test-components/test-component/1.0.10/promise-func?_componentSet=set&something=unused');
17
+ expect(response.statusCode).toEqual(200);
18
+ expect(response.text).toEqual('<h1>hello</h1>');
19
+ }, 20000);
20
+ it('should fail validation if input contract is not met and helpful message returned', async () => {
21
+ // passing input parameter "something" via query parameter won't do it
22
+ const response = await request().get('/r/unit-test-components/test-component/1.0.0?_componentSet=set&something=unused');
23
+ expect(response.statusCode).toEqual(400);
24
+ expect(response.body).toMatchInlineSnapshot(`
25
+ {
26
+ "message": "failed validation: The required property \`something\` is missing at \`#\`",
27
+ }
28
+ `);
29
+ }, 20000);
30
+ it('should 404 if requesting a non-existent function on an otherwise valid component', async () => {
31
+ const response = await request().get('/r/unit-test-components/test-component/1.0.0/non-existent-entry-file?_componentSet=set&something=not-used');
32
+ expect(response.statusCode).toEqual(404);
33
+ expect(response.body).toMatchInlineSnapshot(`
34
+ {
35
+ "message": ""non-existent-entry-file" function for unit-test-components/test-component 1.0.0 could not be found",
36
+ }
37
+ `);
38
+ }, 20000);
39
+ });
40
+ describe('GET /r/unit-test-components/test-component/1.0.3/main?_componentSet=set', () => {
41
+ // this scenario shouldn't happen in practice, but should be tested for
42
+ it('should fail validation when requesting a function with a missing entry file', async () => {
43
+ const response = await request().get('/r/unit-test-components/test-component/1.0.3/main?_componentSet=set&something=not-used');
44
+ expect(response.body).toEqual({
45
+ message: '"main\'s" entry file "missing-entry-file.js" is inaccessible',
46
+ });
47
+ expect(response.statusCode).toEqual(500);
48
+ }, 20000);
49
+ });
50
+ describe('GET /r/unit-test-components/test-component/1.0.4?_componentSet=set', () => {
51
+ it('should render a simple json endpoint', async () => {
52
+ const response = await request().get('/r/unit-test-components/test-component/1.0.4?_componentSet=set');
53
+ // expect(response.statusCode).toEqual(200);
54
+ expect(response.headers['content-type']).toContain('application/json');
55
+ expect(response.body).toEqual({
56
+ 'my-prop': 'test value for my-prop',
57
+ 'my-array': [
58
+ {
59
+ 'a-string': 'hello',
60
+ 'a-number': 3,
61
+ },
62
+ ],
63
+ });
64
+ }, 20000);
65
+ it('should report error if response does not match with the schema', async () => {
66
+ const response = await request().get('/r/unit-test-components/test-component/1.0.4/render-json-invalid?_componentSet=set');
67
+ expect(response.statusCode).toEqual(500);
68
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
69
+ expect(response.body).toEqual({
70
+ message: 'failed validation: Expected `3` (string) in `#/my-array/0/a-number` to be of type `number`',
71
+ });
72
+ }, 20000);
73
+ it('should validate a complex json against a schema', async () => {
74
+ const response = await request().get('/r/unit-test-components/test-component/1.0.4/render-json-nested-object-valid?_componentSet=set');
75
+ const myObject = {
76
+ 'my-object': {
77
+ 'a-string': 'this is a string',
78
+ 'an-enum': 'B',
79
+ 'a-nested-object': { 'an-array': ['item 1', 'item 2'] },
80
+ },
81
+ 'my-array': [1, 4],
82
+ };
83
+ expect(response.statusCode).toEqual(200);
84
+ expect(response.headers['content-type']).toContain('application/json');
85
+ expect(response.body).toEqual(myObject);
86
+ }, 20000);
87
+ it('should report errors if nested object json schema fails', async () => {
88
+ const response = await request().get('/r/unit-test-components/test-component/1.0.4/render-json-nested-object-invalid?_componentSet=set');
89
+ expect(response.statusCode).toEqual(500);
90
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
91
+ expect(response.body).toEqual({
92
+ message: `failed validation: Expected \`false\` (string) in \`#/my-object/a-boolean\` to be of type \`boolean\`,\nExpected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of \`[Y, E, S]\``,
93
+ });
94
+ }, 20000);
95
+ });
96
+ describe('GET /r/unit-test-components/test-component/1.0.7?_componentSet=set', () => {
97
+ it('should return input and info object with "query parameters"', async () => {
98
+ const response = await request().get('/r/unit-test-components/test-component/1.0.7?_componentSet=set&something=hello-test&foo=foo-val&foo2=foo2-val');
99
+ expect(response.statusCode).toEqual(200);
100
+ expect(response.headers['content-type']).toContain('application/json');
101
+ const result = response.body;
102
+ // this is being removed because the shared tests between local dev
103
+ // and the server cause issues. The set name for local dev is a hard coded
104
+ // 'display name' and is 'some-display-name' depending upn what test suite
105
+ // ran. Instead of keeping these values in alignment across the packages
106
+ // I am removing the value from the assertion and adding in additional tests
107
+ // that are specific in each of the packages asserting the different expected values
108
+ // delete result[1].set.displayName
109
+ expect(result).toEqual([
110
+ {},
111
+ {
112
+ functionName: 'inputs-exist',
113
+ componentName: 'unit-test-components/test-component',
114
+ version: '1.0.7',
115
+ manifest: {
116
+ $schema: 'http://localhost:3000/schemas/v1.json#',
117
+ name: 'test-component',
118
+ version: '1.0.7',
119
+ mainFunction: 'inputs-exist',
120
+ description: 'some-description',
121
+ displayName: 'some-display-name',
122
+ namespace: 'unit-test-components',
123
+ functions: [
124
+ {
125
+ name: 'inputs-exist',
126
+ entry: 'inputs-exist.js',
127
+ input: {
128
+ type: 'object',
129
+ properties: {
130
+ something: {
131
+ type: 'string',
132
+ },
133
+ },
134
+ required: [],
135
+ },
136
+ output: {
137
+ responseType: 'json',
138
+ definition: {
139
+ type: 'array',
140
+ items: {
141
+ oneOf: [
142
+ {
143
+ type: 'string',
144
+ },
145
+ {
146
+ type: 'object',
147
+ additionalProperties: true,
148
+ },
149
+ ],
150
+ },
151
+ },
152
+ },
153
+ queryParameters: {
154
+ foo: {
155
+ required: true,
156
+ },
157
+ foo2: {
158
+ required: false,
159
+ },
160
+ },
161
+ },
162
+ ],
163
+ },
164
+ ctx: {},
165
+ set: {
166
+ displayName: 'set',
167
+ environment: {},
168
+ webPath: 'set',
169
+ },
170
+ queryParameters: {
171
+ foo: 'foo-val',
172
+ foo2: 'foo2-val',
173
+ },
174
+ },
175
+ ]);
176
+ });
177
+ });
178
+ it('should throw error if required query parameter is missing', async () => {
179
+ const response = await request().get('/r/unit-test-components/test-component/1.0.7?_componentSet=set&foo2=foo2-val');
180
+ expect(response.body).toEqual({
181
+ message: "Required query parameter 'foo' is missing",
182
+ });
183
+ expect(response.statusCode).toEqual(400);
184
+ });
185
+ it('should throw error if query parameter is not a string', async () => {
186
+ const response = await request().get('/r/unit-test-components/test-component/1.0.7?_componentSet=set&foo=123&foo2[]=array-val');
187
+ expect(response.body).toEqual({
188
+ message: "Value for query parameter 'foo2' must be a string",
189
+ });
190
+ expect(response.statusCode).toEqual(400);
191
+ });
192
+ describe('GET /r/unit-test-components/test-component/1.0.8?_componentSet=set -- Error handling', () => {
193
+ it('should throw an error if trying to use modules in the js', async () => {
194
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/module-js?_componentSet=set');
195
+ expect(response.statusCode).toEqual(500);
196
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
197
+ expect(response.body).toEqual({
198
+ message: 'ESM style modules are not supported.',
199
+ });
200
+ });
201
+ it('should throw an error if the component uploaded does not export a function', async () => {
202
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/no-module-export?_componentSet=set');
203
+ expect(response.statusCode).toEqual(500);
204
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
205
+ expect(response.body).toEqual({
206
+ message: 'script is not a function',
207
+ });
208
+ });
209
+ it('should throw an error if the component is not async and throws and error object', async () => {
210
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/no-promise-throws-error?_componentSet=set');
211
+ expect(response.statusCode).toEqual(500);
212
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
213
+ expect(response.body).toEqual({
214
+ message: 'throw error',
215
+ });
216
+ });
217
+ it('throw an error if the component is not async and throws an arbitrary value', async () => {
218
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/no-promise-throws-string?_componentSet=set');
219
+ expect(response.statusCode).toEqual(500);
220
+ expect(response.headers['cache-control']).toEqual('no-cache, no-store, max-age=0');
221
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
222
+ expect(response.body).toEqual({
223
+ message: 'An error occurred with no additional information available',
224
+ });
225
+ });
226
+ it('throw an error if the component is not async and throws undefined', async () => {
227
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/no-promise-throws-undefined?_componentSet=set');
228
+ expect(response.statusCode).toEqual(500);
229
+ expect(response.headers['cache-control']).toEqual('no-cache, no-store, max-age=0');
230
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
231
+ expect(response.body).toEqual({
232
+ message: 'An error occurred with no additional information available',
233
+ });
234
+ });
235
+ it('should throw an error if the component is async/returns a promise but rejects', async () => {
236
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/promise-rejects?_componentSet=set');
237
+ expect(response.statusCode).toEqual(500);
238
+ expect(response.headers['cache-control']).toEqual('no-cache, no-store, max-age=0');
239
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
240
+ expect(response.body).toEqual({
241
+ message: 'An error occurred with no additional information available',
242
+ });
243
+ });
244
+ it('should throw an error if the component is async/returns a promise and throws and error object', async () => {
245
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/promise-throws-error?_componentSet=set');
246
+ expect(response.statusCode).toEqual(500);
247
+ expect(response.headers['cache-control']).toEqual('no-cache, no-store, max-age=0');
248
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
249
+ expect(response.body).toEqual({
250
+ message: 'throws error',
251
+ });
252
+ });
253
+ it('throw an error if the component is async/returns a promise and throws an arbitrary value', async () => {
254
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/promise-throws-string?_componentSet=set');
255
+ expect(response.statusCode).toEqual(500);
256
+ expect(response.headers['cache-control']).toEqual('no-cache, no-store, max-age=0');
257
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
258
+ expect(response.body).toEqual({
259
+ message: 'An error occurred with no additional information available',
260
+ });
261
+ });
262
+ it('throw an error if the component is async/returns a promise and throws undefined', async () => {
263
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/promise-throws-undefined?_componentSet=set');
264
+ expect(response.statusCode).toEqual(500);
265
+ expect(response.headers['cache-control']).toEqual('no-cache, no-store, max-age=0');
266
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
267
+ expect(response.body).toEqual({
268
+ message: 'An error occurred with no additional information available',
269
+ });
270
+ });
271
+ it('throw an error if the component has a syntax error', async () => {
272
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/syntax-error?_componentSet=set');
273
+ expect(response.statusCode).toEqual(500);
274
+ expect(response.headers['content-type']).toEqual('application/json; charset=utf-8');
275
+ expect(response.body).toEqual({
276
+ message: "Unexpected token '}'",
277
+ });
278
+ });
279
+ it('should return the error as a HTML comment if the response type is HTML', async () => {
280
+ const response = await request().get('/r/unit-test-components/test-component/1.0.8/html-no-promise-throws-error?_componentSet=set');
281
+ expect(response.statusCode).toEqual(500);
282
+ expect(response.headers['content-type']).toEqual('text/html; charset=utf-8');
283
+ expect(response.text).toEqual('<!-- throw error -->');
284
+ });
285
+ });
286
+ describe('GET /r/unit-test-components/test-static-files/1.0.0?_componentSet=set', () => {
287
+ let response;
288
+ beforeAll(async () => {
289
+ response = await request().get('/r/unit-test-components/test-static-files/1.0.0?_componentSet=set');
290
+ });
291
+ it('should render a function with references to static resources', async () => {
292
+ // expect(response.statusCode).toEqual(200);
293
+ expect(response.text.replace(new RegExp(rootUrl, 'g'), '')).toMatchInlineSnapshot(`"<div>unit-test-components/test-static-files 1.0.0 /s/unit-test-components/test-static-files/1.0.0/birthday-cake.png?_componentSet=set /s/unit-test-components/test-static-files/1.0.0/sub/dir/static-library-file.js?_componentSet=set</div>"`);
294
+ });
295
+ it('should also host the static resources and they should be resolvable', async () => {
296
+ const raw = response.text.replace('<div>', '').replace('</div>', '').split(' ');
297
+ const pngUrl = raw[2].replace(rootUrl, '');
298
+ const jsUrl = raw[3].replace(rootUrl, '');
299
+ expect(pngUrl).toEqual(`/s/unit-test-components/test-static-files/1.0.0/birthday-cake.png?_componentSet=set`);
300
+ expect(jsUrl).toEqual(`/s/unit-test-components/test-static-files/1.0.0/sub/dir/static-library-file.js?_componentSet=set`);
301
+ const pngResponse = await request().get(pngUrl);
302
+ expect(pngResponse.statusCode).toBe(200);
303
+ expect(pngResponse.headers['content-type']).toBe('image/png');
304
+ const jsResponse = await request().get(jsUrl);
305
+ expect(jsResponse.statusCode).toBe(200);
306
+ expect(jsResponse.headers['content-type']).toBe('application/javascript; charset=UTF-8');
307
+ });
308
+ });
309
+ describe('GET /r/unit-test-components/test-static-files/1.0.1?_componentSet=set', () => {
310
+ let response;
311
+ beforeAll(async () => {
312
+ response = await request().get('/r/unit-test-components/test-static-files/1.0.1?_componentSet=set');
313
+ });
314
+ it('should render a function with references to its own function', async () => {
315
+ expect(response.statusCode).toEqual(200);
316
+ expect(response.text.replace(new RegExp(rootUrl, 'g'), '')).toMatchInlineSnapshot(`
317
+ "<div id="my-comp" data-data-url="/r/unit-test-components/test-static-files/1.0.1/data?_componentSet=set&input=1234">
318
+
319
+ <script type="text/javascript" defer src="/s/unit-test-components/test-static-files/1.0.1/sub/dir/static-library-file.js?_componentSet=set"></script>
320
+ </div>"
321
+ `);
322
+ });
323
+ it('should also provide valid function urls that are resolvable', async () => {
324
+ var _a;
325
+ const url = (_a = response.text.match(/data-data-url="(.+)"/)) === null || _a === void 0 ? void 0 : _a[1].replace(new RegExp(rootUrl, 'g'), '');
326
+ expect(url).toEqual('/r/unit-test-components/test-static-files/1.0.1/data?_componentSet=set&input=1234');
327
+ const functionResult = await request().get(url);
328
+ expect(functionResult.status).toEqual(200);
329
+ expect(functionResult.text).toEqual('123456789');
330
+ });
331
+ });
332
+ describe('GET /r/unit-test-components/test-headers/1.0.3?_componentSet=set', () => {
333
+ it('should make sure max-age header is clamped between max value', async () => {
334
+ const response = await request()
335
+ .get('/r/unit-test-components/test-headers/1.0.3/max-value?_componentSet=set')
336
+ .send()
337
+ .expect(200, 'rendered');
338
+ expect(response.headers['cache-control']).toEqual('max-age=1800, immutable');
339
+ });
340
+ it('should make sure max-age header is clamped between min value', async () => {
341
+ const response = await request()
342
+ .get('/r/unit-test-components/test-headers/1.0.3/min-value?_componentSet=set')
343
+ .send()
344
+ .expect(200, 'rendered');
345
+ expect(response.headers['cache-control']).toEqual('max-age=30, public');
346
+ });
347
+ });
348
+ describe('should be able to load external dependencies', () => {
349
+ it('GET /r/unit-test-components/test-npm-modules/1.0.0?_componentSet=set should be able to render a component using react', async () => {
350
+ const response = await request().get('/r/unit-test-components/test-npm-modules/1.0.0?_componentSet=set');
351
+ expect(response.statusCode).toEqual(200);
352
+ expect(response.text).toMatchInlineSnapshot(`"<div data-reactroot=""><h1>Hello World</h1><a>16.0.0</a></div>"`);
353
+ });
354
+ it('should be able to load conflicting npm dependencies', async () => {
355
+ const response = await request().get('/r/unit-test-components/test-npm-modules/2.0.0?_componentSet=set');
356
+ expect(response.statusCode).toEqual(200);
357
+ expect(response.text).toMatchInlineSnapshot(`"<div data-reactroot=""><h1>Hello World</h1><a>17.0.2</a></div>"`);
358
+ });
359
+ it('should be able to make web requests out', async () => {
360
+ const response = await request().get('/r/unit-test-components/test-npm-modules/3.0.0?_componentSet=set');
361
+ expect(response.statusCode).toEqual(200);
362
+ expect(response.text).toContain(`Google`);
363
+ });
364
+ // https://squiz.slack.com/archives/C01PAUWCU20/p1678229946851689
365
+ it.skip('should be able to load conflicting npm dependencies while being overloaded with requests', async () => {
366
+ const promises = [];
367
+ // thread pool is sized by number of cpus available. We want more than the available cpus.
368
+ // this loop will generate 6x the number of tasks for the available processors. This is
369
+ // to ensure that we're overloading the worker pool
370
+ for (let i = 0; i < os_1.default.cpus().length * 4; i++) {
371
+ promises.push(request().get('/r/unit-test-components/test-npm-modules/1.0.0?_componentSet=set')); // react v16
372
+ promises.push(request().get('/r/unit-test-components/test-npm-modules/2.0.0?_componentSet=set')); // react v17
373
+ }
374
+ const result = await Promise.all(promises);
375
+ for (let i = 0; i < result.length; i += 2) {
376
+ const reactv16 = result[i + 0];
377
+ const reactv17 = result[i + 1];
378
+ expect(reactv16.text).toEqual('<div data-reactroot=""><h1>Hello World</h1><a>16.0.0</a></div>');
379
+ expect(reactv16.statusCode).toEqual(200);
380
+ expect(reactv17.statusCode).toEqual(200);
381
+ expect(reactv17.text).toEqual('<div data-reactroot=""><h1>Hello World</h1><a>17.0.2</a></div>');
382
+ }
383
+ }, 240000);
384
+ });
385
+ describe('GET /r/unit-test-components/test-formatted-text/1.0.0', () => {
386
+ it('should render a component formattedText in preview inline', async () => {
387
+ const response = await request().get('/r/unit-test-components/test-formatted-text/1.0.0?_previewKey=valid-inline-preview');
388
+ expect(response.statusCode).toEqual(200);
389
+ expect(response.text).toMatchInlineSnapshot(`"This is a test"`);
390
+ });
391
+ });
392
+ describe('GET /r/unit-test-components/test-npm-modules/3.1.0', () => {
393
+ it('should render a component with axios', async () => {
394
+ const response = await request().get('/r/unit-test-components/test-npm-modules/3.1.0/axios?_componentSet=set');
395
+ expect(response.statusCode).toEqual(200);
396
+ });
397
+ it('should render a component with uuid', async () => {
398
+ const response = await request().get('/r/unit-test-components/test-npm-modules/3.1.0/uuid?_componentSet=set');
399
+ expect(response.statusCode).toEqual(200);
400
+ });
401
+ it('should render a component with Buffer', async () => {
402
+ const response = await request().get('/r/unit-test-components/test-npm-modules/3.1.0/buffer?_componentSet=set');
403
+ expect(response.statusCode).toEqual(200);
404
+ });
405
+ });
406
+ describe('GET /r/unit-test-components/test-squiz-image/1.0.0', () => {
407
+ it('should render the preview', async () => {
408
+ const response = await request().get('/r/unit-test-components/test-squiz-image/1.0.0?_previewKey=valid-inline-preview');
409
+ expect(response.statusCode).toEqual(200);
410
+ expect(response.text).toMatchInlineSnapshot(`"My Image Component"`);
411
+ });
412
+ });
413
+ describe('GET /r/unit-test-components/test-squiz-link/1.0.0', () => {
414
+ it('should render the preview', async () => {
415
+ const response = await request().get('/r/unit-test-components/test-squiz-link/1.0.0?_previewKey=valid-inline-preview');
416
+ expect(response.statusCode).toEqual(200);
417
+ expect(response.text).toMatchInlineSnapshot(`"{"link":{"text":"My Link","url":"https://some.link/foo"}}"`);
418
+ });
419
+ });
420
+ }
421
+ exports.renderRouteTests = renderRouteTests;
422
+ //# sourceMappingURL=render-route-tests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-route-tests.js","sourceRoot":"","sources":["../../../../src/webserver/controllers/test/render-route-tests.ts"],"names":[],"mappings":";;;;;;AACA,4CAAoB;AAEpB,SAAgB,gBAAgB,CAAC,OAAkD,EAAE,OAAe;IAClG,QAAQ,CAAC,sEAAsE,EAAE,GAAG,EAAE;QACpF,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;YACnE,MAAM,QAAQ,GAAG,MAAM,OAAO,EAAE,CAAC,GAAG,CAClC,kFAAkF,CACnF,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;YACvD,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3C,CAAC,EAAE,KAAM,CAAC,CAAC;QAEX,EAAE,CAAC,sEAAsE,EAAE,KAAK,IAAI,EAAE;YACpF,MAAM,QAAQ,GAAG,MAAM,OAAO,EAAE,CAAC,GAAG,CAClC,+FAA+F,CAChG,CAAC;YAEF,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACzC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAClD,CAAC,EAAE,KAAM,CAAC,CAAC;QAEX,EAAE,CAAC,kFAAkF,EAAE,KAAK,IAAI,EAAE;YAChG,sEAAsE;YACtE,MAAM,QAAQ,GAAG,MAAM,OAAO,EAAE,CAAC,GAAG,CAClC,iFAAiF,CAClF,CAAC;YAEF,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACzC,MAAM,CAAC,QAAQ,CAAC,I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AC,6DAA6D,CAAC,CAAC;QAC7G,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA3iBD,4CA2iBC"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.staticRouteTests = void 0;
4
+ function staticRouteTests(request) {
5
+ describe('GET /s/set/unit-test-components/test-static-files/1.0.0/', () => {
6
+ it('should return the test static component image', async () => {
7
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/birthday-cake.png?_componentSet=set');
8
+ expect(response.statusCode).toEqual(200);
9
+ expect(response.type).toEqual('image/png');
10
+ expect(response.body.byteLength).toEqual(4251);
11
+ expect(response.headers['accept-ranges']).toEqual('bytes');
12
+ expect(response.headers['cache-control']).toEqual('public, max-age=604800, immutable');
13
+ expect(response.headers['content-length']).toEqual('4251');
14
+ expect(response.headers['content-type']).toEqual('image/png');
15
+ });
16
+ it('should allow for sub directories', async () => {
17
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/sub/dir/static-library-file.js?_componentSet=set');
18
+ expect(response.statusCode).toEqual(200);
19
+ expect(response.type).toEqual('application/javascript');
20
+ expect(response.headers['accept-ranges']).toEqual('bytes');
21
+ expect(response.headers['cache-control']).toEqual('public, max-age=604800, immutable');
22
+ expect(response.headers['content-length']).toEqual('55');
23
+ expect(response.headers['content-type']).toEqual('application/javascript; charset=UTF-8');
24
+ });
25
+ it('should 404 on missing files', async () => {
26
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/sub/does-not-exist.js?_componentSet=set');
27
+ expect(response.statusCode).toEqual(404);
28
+ expect(response.type).toEqual('application/json');
29
+ expect(response.body).toEqual({ message: 'could not find /sub/does-not-exist.js' });
30
+ });
31
+ it('should 404 on when no root provided', async () => {
32
+ const response = await request().get('/s/unit-test-components/test-component/1.0.0/sub/does-not-exist.js?_componentSet=set');
33
+ expect(response.statusCode).toEqual(404);
34
+ expect(response.type).toEqual('application/json');
35
+ expect(response.body).toEqual({ message: "test-component 1.0.0 doesn't expose any static resources" });
36
+ });
37
+ it('should not allow relative path walking above the defined component root', async () => {
38
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/../test-component/1.0.0/main.js?_componentSet=set');
39
+ expect(response.statusCode).toEqual(403);
40
+ expect(response.type).toEqual('application/json');
41
+ expect(response.body).toEqual({ message: 'Forbidden' });
42
+ });
43
+ it('should not leak the existence of files', async () => {
44
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/../test-component/1.0.0/does-not-exist.js?_componentSet=set');
45
+ // make sure we dont 404 for missing files outside of the allowed scope
46
+ expect(response.statusCode).toEqual(403);
47
+ expect(response.type).toEqual('application/json');
48
+ expect(response.body).toEqual({ message: 'Forbidden' });
49
+ });
50
+ });
51
+ describe('preview routes - /s/ routes', () => {
52
+ it('should return the test static component file', async () => {
53
+ const response = await request().get('/s/unit-test-components/test-preview-component/1.0.1/css-file.css?_previewKey=test-preview');
54
+ expect(response.text).toMatchInlineSnapshot(`
55
+ ".main,
56
+ p {
57
+ display: block;
58
+ background-color: rebeccapurple;
59
+ }
60
+ "
61
+ `);
62
+ expect(response.statusCode).toEqual(200);
63
+ expect(response.type).toEqual('text/css');
64
+ });
65
+ it('should 404 on missing files', async () => {
66
+ const response = await request().get('/s/unit-test-components/test-preview-component/1.0.1/bad-css-file.css?_previewKey=test-preview');
67
+ expect(response.statusCode).toEqual(404);
68
+ expect(response.type).toEqual('application/json');
69
+ expect(response.body).toEqual({ message: 'could not find /bad-css-file.css' });
70
+ });
71
+ it('should 404 on when no root provided', async () => {
72
+ const response = await request().get('/s/unit-test-components/test-component/1.0.0/sub/does-not-exist.js?_previewKey=test-preview');
73
+ expect(response.statusCode).toEqual(404);
74
+ expect(response.type).toEqual('application/json');
75
+ expect(response.body).toEqual({ message: "test-component 1.0.0 doesn't expose any static resources" });
76
+ });
77
+ it('should not allow relative path walking above the defined component root', async () => {
78
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/../test-component/1.0.0/main.js?_previewKey=test-preview');
79
+ expect(response.statusCode).toEqual(403);
80
+ expect(response.type).toEqual('application/json');
81
+ expect(response.body).toEqual({ message: 'Forbidden' });
82
+ });
83
+ it('should not leak the existence of files with relative path walking', async () => {
84
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/../test-component/1.0.0/does-not-exist.js?_previewKey=test-preview');
85
+ expect(response.statusCode).toEqual(403);
86
+ expect(response.type).toEqual('application/json');
87
+ expect(response.body).toEqual({ message: 'Forbidden' });
88
+ });
89
+ it('should provide meaningful error message when componentSet and previewKey are provided', async () => {
90
+ const response = await request().get('/s/unit-test-components/test-static-files/1.0.0/birthday-cake.png?_previewKey=test-preview&_componentSet=set');
91
+ expect(response.body).toEqual({ message: 'You can not have both _componentSet and _previewKey' });
92
+ });
93
+ });
94
+ }
95
+ exports.staticRouteTests = staticRouteTests;
96
+ //# sourceMappingURL=static-route-tests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-route-tests.js","sourceRoot":"","sources":["../../../../src/webserver/controllers/test/static-route-tests.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAAC,OAAkD;IACjF,QAAQ,CAAC,0DAA0D,EAAE,GAAG,EAAE;QACxE,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;YAC7D,MAAM,QAAQ,GAAG,MAAM,OAAO,EAAE,CAAC,GAAG,CAClC,qFAAqF,CACtF,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACzC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC3C,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAE/C,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAA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CAAC,CAAC;QAEH,EAAE,CAAC,uFAAuF,EAAE,KAAK,IAAI,EAAE;YACrG,MAAM,QAAQ,GAAG,MAAM,OAAO,EAAE,CAAC,GAAG,CAClC,8GAA8G,CAC/G,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,qDAAqD,EAAE,CAAC,CAAC;QACpG,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAtID,4CAsIC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupApp = void 0;
4
+ var app_1 = require("./app");
5
+ Object.defineProperty(exports, "setupApp", { enumerable: true, get: function () { return app_1.setupApp; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/webserver/index.ts"],"names":[],"mappings":";;;AAAA,6BAAiC;AAAxB,+FAAA,QAAQ,OAAA"}