@squiz/component-cli-lib 1.21.1-alpha.2 → 1.21.1-alpha.21
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/.gitlab-ci.yml +3 -2
- package/.npm/_logs/2023-03-17T05_06_37_319Z-debug-0.log +37 -0
- package/lib/component-dev.d.ts +1 -1
- package/lib/index.js +93 -93
- package/lib/index.js.map +4 -4
- package/package.json +10 -10
- package/src/component-dev.ts +4 -5
- package/src/integration-tests/__components__/matrix-asset-uri/main.js +7 -0
- package/src/integration-tests/__components__/matrix-asset-uri/manifest.json +42 -0
- package/src/integration-tests/helper.ts +1 -6
- package/src/integration-tests/upload-and-render-component.integration.spec.ts +89 -20
- package/src/upload-component-folder.ts +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/.npm/_logs/2023-03-02T03_27_28_236Z-debug-0.log +0 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/component-cli-lib",
|
|
3
|
-
"version": "1.21.1-alpha.
|
|
3
|
+
"version": "1.21.1-alpha.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@squiz/component-lib": "1.21.1-alpha.
|
|
17
|
-
"@squiz/component-web-api-lib": "1.21.1-alpha.
|
|
18
|
-
"@squiz/dx-common-lib": "1.21.1-alpha.
|
|
19
|
-
"@squiz/dx-json-schema-lib": "1.21.1-alpha.
|
|
20
|
-
"@squiz/dx-logger-lib": "1.21.1-alpha.
|
|
21
|
-
"@squiz/virus-scanner-lib": "1.21.1-alpha.
|
|
16
|
+
"@squiz/component-lib": "1.21.1-alpha.21",
|
|
17
|
+
"@squiz/component-web-api-lib": "1.21.1-alpha.21",
|
|
18
|
+
"@squiz/dx-common-lib": "1.21.1-alpha.21",
|
|
19
|
+
"@squiz/dx-json-schema-lib": "1.21.1-alpha.21",
|
|
20
|
+
"@squiz/dx-logger-lib": "1.21.1-alpha.21",
|
|
21
|
+
"@squiz/virus-scanner-lib": "1.21.1-alpha.21",
|
|
22
22
|
"@types/cli-color": "2.0.2",
|
|
23
23
|
"@types/express": "4.17.17",
|
|
24
24
|
"@types/jest": "28.1.8",
|
|
25
|
-
"@types/node": "
|
|
25
|
+
"@types/node": "18.15.2",
|
|
26
26
|
"@types/supertest": "2.0.12",
|
|
27
27
|
"dotenv": "16.0.3",
|
|
28
28
|
"jest": "29.4.1",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"typescript": "4.9.4"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@squiz/render-runtime-lib": "1.21.1-alpha.
|
|
35
|
+
"@squiz/render-runtime-lib": "1.21.1-alpha.21",
|
|
36
36
|
"archiver": "5.3.1",
|
|
37
37
|
"axios": "1.3.2",
|
|
38
38
|
"cli-color": "^2.0.2",
|
|
39
39
|
"open": "^8.4.0",
|
|
40
40
|
"supertest": "^6.2.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "b6a0d4e2501e58cb3c3ecd26741c447e2c3bc1db"
|
|
43
43
|
}
|
package/src/component-dev.ts
CHANGED
|
@@ -9,7 +9,6 @@ import path from 'path';
|
|
|
9
9
|
import { ComponentFunctionService, ComponentSetServiceForLocalDev, ManifestServiceForDev } from '@squiz/component-lib';
|
|
10
10
|
import open from 'open';
|
|
11
11
|
import { DevelopmentApiKeyService } from '@squiz/dx-common-lib';
|
|
12
|
-
import { JsonValidationService } from '@squiz/dx-json-schema-lib';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* startDevelopmentRender starts a dev-mode render stack for any
|
|
@@ -37,14 +36,14 @@ export function startDevelopmentRender(
|
|
|
37
36
|
dataMountPoint,
|
|
38
37
|
shouldCacheResponses: false,
|
|
39
38
|
workerTimeout: 5_000,
|
|
40
|
-
|
|
39
|
+
minWorkers: 2,
|
|
40
|
+
maxWorkers: 2,
|
|
41
41
|
},
|
|
42
42
|
logger,
|
|
43
43
|
);
|
|
44
|
-
const
|
|
45
|
-
const componentFunctionService = new ComponentFunctionService(rootUrl, jsonValidationService);
|
|
44
|
+
const componentFunctionService = new ComponentFunctionService(rootUrl);
|
|
46
45
|
const componentSetService = new ComponentSetServiceForLocalDev(logger);
|
|
47
|
-
const manifestService = new ManifestServiceForDev(dataMountPoint, logger
|
|
46
|
+
const manifestService = new ManifestServiceForDev(dataMountPoint, logger);
|
|
48
47
|
const contentItemService = undefined;
|
|
49
48
|
const renderInputService = new RenderInputService(
|
|
50
49
|
componentSetService,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://localhost:3000/schemas/v1.json#",
|
|
3
|
+
|
|
4
|
+
"name": "matrix-asset-uri",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"mainFunction": "main",
|
|
7
|
+
"displayName": "some-display-name",
|
|
8
|
+
"namespace": "smoke-test-components",
|
|
9
|
+
"description": "some-description",
|
|
10
|
+
"functions": [
|
|
11
|
+
{
|
|
12
|
+
"name": "main",
|
|
13
|
+
"entry": "main.js",
|
|
14
|
+
"input": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"properties": {
|
|
17
|
+
"text": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"format": "matrix-asset-uri",
|
|
20
|
+
"matrixAssetTypes": ["image"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"required": ["text"]
|
|
24
|
+
},
|
|
25
|
+
"output": { "responseType": "html" }
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"previews": {
|
|
29
|
+
"test-preview": {
|
|
30
|
+
"functionData": {
|
|
31
|
+
"main": {
|
|
32
|
+
"inputData": {
|
|
33
|
+
"type": "inline",
|
|
34
|
+
"value": {
|
|
35
|
+
"text": "matrix://canary.uat.matrix.squiz.cloud/abc123"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -9,7 +9,6 @@ import { ContentApi } from '@squiz/component-web-api-lib';
|
|
|
9
9
|
import { config } from 'dotenv';
|
|
10
10
|
import { execSync } from 'child_process';
|
|
11
11
|
import { getLogger } from '@squiz/dx-logger-lib';
|
|
12
|
-
import { JsonValidationService } from '@squiz/dx-json-schema-lib';
|
|
13
12
|
|
|
14
13
|
config();
|
|
15
14
|
|
|
@@ -112,11 +111,7 @@ export const ci_buildBranch = configObj.ci_buildBranch;
|
|
|
112
111
|
|
|
113
112
|
export async function getTestComponents() {
|
|
114
113
|
const componentsDir = path.join(__dirname, '/__components__/');
|
|
115
|
-
const manifestService = new ManifestServiceForDev(
|
|
116
|
-
componentsDir,
|
|
117
|
-
getLogger({ name: 'getTestComponents' }),
|
|
118
|
-
new JsonValidationService(),
|
|
119
|
-
);
|
|
114
|
+
const manifestService = new ManifestServiceForDev(componentsDir, getLogger({ name: 'getTestComponents' }));
|
|
120
115
|
return await manifestService.listAllComponentManifests();
|
|
121
116
|
}
|
|
122
117
|
export async function createFile(filePath: string, sizeInMB: number) {
|
|
@@ -19,6 +19,7 @@ import { logger } from '../upload-component-folder';
|
|
|
19
19
|
import { ComponentSetWebModelForCreate } from '@squiz/component-lib';
|
|
20
20
|
import fsp from 'fs/promises';
|
|
21
21
|
import { randomUUID } from 'crypto';
|
|
22
|
+
import { AxiosError } from 'axios';
|
|
22
23
|
|
|
23
24
|
const webPath = 'set-' + randomUUID();
|
|
24
25
|
const contentItemId = randomUUID();
|
|
@@ -101,17 +102,21 @@ describe('uploading a component', () => {
|
|
|
101
102
|
|
|
102
103
|
describe('Deploy a basic component having a input with multiline format', () => {
|
|
103
104
|
beforeAll(async () => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.delete(
|
|
105
|
+
try {
|
|
106
|
+
await deleteComponentSet(webPath);
|
|
107
|
+
await deleteContentItem(contentItemId);
|
|
108
|
+
for (const manifest of await getTestComponents()) {
|
|
109
|
+
await managementService.delete(`/component/${manifest.getName()}`);
|
|
110
|
+
await contentService.delete(
|
|
110
111
|
`/content-schema/${manifest.getName()}/${manifest.getVersion()}/${
|
|
111
112
|
manifest.getComponentFunctionByName().name
|
|
112
113
|
}`,
|
|
113
|
-
)
|
|
114
|
-
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
} catch (error: unknown) {
|
|
117
|
+
if ((error as AxiosError).response?.status !== 404) {
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
115
120
|
}
|
|
116
121
|
});
|
|
117
122
|
|
|
@@ -157,22 +162,90 @@ describe('uploading a component', () => {
|
|
|
157
162
|
});
|
|
158
163
|
});
|
|
159
164
|
|
|
165
|
+
describe('Deploy a basic component with input format matrix-asset-uri', () => {
|
|
166
|
+
beforeAll(async () => {
|
|
167
|
+
try {
|
|
168
|
+
await deleteComponentSet(webPath);
|
|
169
|
+
await deleteContentItem(contentItemId);
|
|
170
|
+
for (const manifest of await getTestComponents()) {
|
|
171
|
+
await managementService.delete(`/component/${manifest.getName()}`);
|
|
172
|
+
await contentService.delete(
|
|
173
|
+
`/content-schema/${manifest.getName()}/${manifest.getVersion()}/${
|
|
174
|
+
manifest.getComponentFunctionByName().name
|
|
175
|
+
}`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if ((error as AxiosError).response?.status !== 404) {
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
it('Should upload the component and return a valid url to preview', async () => {
|
|
185
|
+
const componentPath = path.join(__dirname, '/__components__/matrix-asset-uri');
|
|
186
|
+
await uploadComponentFolder(managementServiceRoot, configObj.managementServiceUrl, componentPath, testFilesDir);
|
|
187
|
+
const uploadedComponent =
|
|
188
|
+
'<a href="/r/smoke-test-components/matrix-asset-uri/1.0.0?_previewKey=test-preview">1.0.0</a>';
|
|
189
|
+
const get = await supertest(configObj.renderServiceUrl).get('/');
|
|
190
|
+
expect(get.status).toEqual(200);
|
|
191
|
+
expect((get as any)?.res?.text).toContain(uploadedComponent);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('Should render a component with matrix-asset-uri format string input with set and content item', async () => {
|
|
195
|
+
const componentSet: ComponentSetWebModelForCreate = {
|
|
196
|
+
webPath,
|
|
197
|
+
displayName: 'some-display-name',
|
|
198
|
+
description: 'Set description',
|
|
199
|
+
headers: {},
|
|
200
|
+
environmentVariables: {},
|
|
201
|
+
components: {
|
|
202
|
+
'smoke-test-components/matrix-asset-uri': [{ environmentVariables: {}, version: '1.0.0' }],
|
|
203
|
+
},
|
|
204
|
+
componentVersionRules: {
|
|
205
|
+
'smoke-test-components/matrix-asset-uri': {
|
|
206
|
+
renderableVersionPattern: '1.0.0',
|
|
207
|
+
editableVersions: [],
|
|
208
|
+
excludedVersions: [],
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
await addComponentSet(componentSet);
|
|
213
|
+
await addContentItem({
|
|
214
|
+
id: contentItemId,
|
|
215
|
+
schemaName: 'smoke-test-components/matrix-asset-uri/1.0.0/main',
|
|
216
|
+
content: {
|
|
217
|
+
text: 'matrix-asset://canary.uat.matrix.squiz.cloud/abc123',
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const response = await renderService.get(
|
|
222
|
+
`/r/smoke-test-components/matrix-asset-uri/1.0.0?_componentSet=${webPath}&_contentItemId=${contentItemId}`,
|
|
223
|
+
);
|
|
224
|
+
expect(response.status).toEqual(200);
|
|
225
|
+
expect(response.data).toEqual(`<div>Input: matrix-asset://canary.uat.matrix.squiz.cloud/abc123</div>`);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
160
229
|
describe('Deploy basic component having a static file', () => {
|
|
161
230
|
// component to deploy for this test
|
|
162
231
|
const componentPath = path.join(__dirname, '/__components__/cmp-static-file-test');
|
|
163
232
|
|
|
164
233
|
beforeAll(async () => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
.delete(
|
|
234
|
+
try {
|
|
235
|
+
await deleteComponentSet(webPath);
|
|
236
|
+
await deleteContentItem(contentItemId);
|
|
237
|
+
for (const manifest of await getTestComponents()) {
|
|
238
|
+
await managementService.delete(`/component/${manifest.getName()}`);
|
|
239
|
+
await contentService.delete(
|
|
171
240
|
`/content-schema/${manifest.getName()}/${manifest.getVersion()}/${
|
|
172
241
|
manifest.getComponentFunctionByName().name
|
|
173
242
|
}`,
|
|
174
|
-
)
|
|
175
|
-
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if ((error as AxiosError).response?.status !== 404) {
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
176
249
|
}
|
|
177
250
|
});
|
|
178
251
|
|
|
@@ -265,10 +338,6 @@ describe('uploading a component', () => {
|
|
|
265
338
|
},
|
|
266
339
|
});
|
|
267
340
|
|
|
268
|
-
console.log(
|
|
269
|
-
`/r/smoke-test-components/cmp-static-file-test/1.0.0/?_componentSet=${webPath}&_contentItemId=${contentItemId}`,
|
|
270
|
-
);
|
|
271
|
-
|
|
272
341
|
const response = await renderService.get(
|
|
273
342
|
`/r/smoke-test-components/cmp-static-file-test/1.0.0/?_componentSet=${webPath}&_contentItemId=${contentItemId}`,
|
|
274
343
|
);
|
|
@@ -7,7 +7,6 @@ import path from 'path';
|
|
|
7
7
|
import { AxiosResponse, AxiosError, AxiosInstance } from 'axios';
|
|
8
8
|
import color from 'cli-color';
|
|
9
9
|
import { getLogger, Logger } from '@squiz/dx-logger-lib';
|
|
10
|
-
import { JsonValidationService } from '@squiz/dx-json-schema-lib';
|
|
11
10
|
|
|
12
11
|
export const logger: Logger = getLogger({ name: 'upload-component', format: 'human' });
|
|
13
12
|
|
|
@@ -54,7 +53,7 @@ export async function uploadComponentFolder(
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
async function preUploadChecks(apiClient: AxiosInstance, managementURL: string, folderPath: string) {
|
|
57
|
-
const service = new ManifestServiceForDev(folderPath, logger
|
|
56
|
+
const service = new ManifestServiceForDev(folderPath, logger);
|
|
58
57
|
const manifestPath = path.join(folderPath, `manifest.json`);
|
|
59
58
|
|
|
60
59
|
const result = await service.readManifest(manifestPath);
|