@squiz/component-cli-lib 1.16.0 → 1.21.1-alpha.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/component-cli-lib",
3
- "version": "1.16.0",
3
+ "version": "1.21.1-alpha.10",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -13,12 +13,12 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "devDependencies": {
16
- "@squiz/component-lib": "1.16.0",
17
- "@squiz/component-web-api-lib": "1.16.0",
18
- "@squiz/dx-common-lib": "1.16.0",
19
- "@squiz/dx-json-schema-lib": "1.16.0",
20
- "@squiz/dx-logger-lib": "1.16.0",
21
- "@squiz/virus-scanner-lib": "1.16.0",
16
+ "@squiz/component-lib": "1.21.1-alpha.10",
17
+ "@squiz/component-web-api-lib": "1.21.1-alpha.10",
18
+ "@squiz/dx-common-lib": "1.21.1-alpha.10",
19
+ "@squiz/dx-json-schema-lib": "1.21.1-alpha.10",
20
+ "@squiz/dx-logger-lib": "1.21.1-alpha.10",
21
+ "@squiz/virus-scanner-lib": "1.21.1-alpha.10",
22
22
  "@types/cli-color": "2.0.2",
23
23
  "@types/express": "4.17.17",
24
24
  "@types/jest": "28.1.8",
@@ -32,12 +32,12 @@
32
32
  "typescript": "4.9.4"
33
33
  },
34
34
  "dependencies": {
35
- "@squiz/render-runtime-lib": "1.16.0",
35
+ "@squiz/render-runtime-lib": "1.21.1-alpha.10",
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": "6fbf11b4507a80f8ef6dd09b489bbebf2bcfbac1"
42
+ "gitHead": "e4aaed9499051ca99e7f3e3bab76b3ffc1fd0f4b"
43
43
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param {object} input
3
+ * @param {ComponentInfo} info
4
+ */
5
+ module.exports = async function (input, info) {
6
+ return `<div>Input: ${input.text}</div>`;
7
+ };
@@ -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
+ }
@@ -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
- await deleteComponentSet(webPath);
105
- await deleteContentItem(contentItemId);
106
- for (const manifest of await getTestComponents()) {
107
- await managementService.delete(`/component/${manifest.getName()}`).catch(() => null);
108
- await contentService
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
- .catch(() => null);
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
- await deleteComponentSet(webPath);
166
- await deleteContentItem(contentItemId);
167
- for (const manifest of await getTestComponents()) {
168
- await managementService.delete(`/component/${manifest.getName()}`).catch(() => null);
169
- await contentService
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
- .catch(() => null);
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
  );