@squiz/component-cli-lib 1.69.1 → 1.70.1
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 +63 -63
- package/lib/index.js.map +2 -2
- package/package.json +10 -7
- package/.env.example +0 -11
- package/.gitlab-ci.yml +0 -141
- package/CHANGELOG.md +0 -664
- package/build.js +0 -28
- package/jest.config.ts +0 -28
- package/jest.integration.config.ts +0 -27
- package/job-runner-lib.tgz +0 -0
- package/lib/job-runner-lib.tgz +0 -0
- package/localStart.ts +0 -11
- package/src/component-dev-folder-structures.integration.spec.ts +0 -91
- package/src/component-dev.integration.spec.ts +0 -71
- package/src/component-dev.ts +0 -102
- package/src/component-edge-dev.ts +0 -75
- package/src/component-init.spec.ts +0 -258
- package/src/component-init.ts +0 -81
- package/src/index.ts +0 -5
- package/src/integration-tests/__components__/big-package/manifest.json +0 -36
- package/src/integration-tests/__components__/big-package/render-json.js +0 -5
- package/src/integration-tests/__components__/cmp-format-string/main.js +0 -7
- package/src/integration-tests/__components__/cmp-format-string/manifest.json +0 -41
- package/src/integration-tests/__components__/cmp-no-api-key/main.js +0 -25
- package/src/integration-tests/__components__/cmp-no-api-key/manifest.json +0 -41
- package/src/integration-tests/__components__/cmp-property-order/main.js +0 -6
- package/src/integration-tests/__components__/cmp-property-order/manifest.json +0 -60
- package/src/integration-tests/__components__/cmp-static-file-test/main.js +0 -6
- package/src/integration-tests/__components__/cmp-static-file-test/manifest.json +0 -42
- package/src/integration-tests/__components__/cmp-static-file-test/public/static-library-file.js +0 -1
- package/src/integration-tests/__components__/invalid-manifest/main.js +0 -3
- package/src/integration-tests/__components__/invalid-manifest/manifest.json +0 -29
- package/src/integration-tests/__components__/invalid-upload/main.js +0 -3
- package/src/integration-tests/__components__/matrix-asset-uri/main.js +0 -7
- package/src/integration-tests/__components__/matrix-asset-uri/manifest.json +0 -42
- package/src/integration-tests/__components__/test-page-render/main.js +0 -3
- package/src/integration-tests/__components__/test-page-render/manifest.json +0 -46
- package/src/integration-tests/__components__/test-page-render/public/static-library-script.js +0 -1
- package/src/integration-tests/__components__/test-page-render/public/static-library-styles.css +0 -3
- package/src/integration-tests/__jobs__/invalid-manifest/main.js +0 -3
- package/src/integration-tests/__jobs__/invalid-manifest/manifest.json +0 -28
- package/src/integration-tests/__jobs__/invalid-upload/main.js +0 -3
- package/src/integration-tests/__jobs__/simple-job/main.js +0 -3
- package/src/integration-tests/__jobs__/simple-job/manifest.json +0 -25
- package/src/integration-tests/helper.ts +0 -227
- package/src/integration-tests/service-deployment.integration.spec.ts +0 -74
- package/src/integration-tests/test-setup.ts +0 -1
- package/src/upload-component-folder.ts +0 -130
- package/src/upload-job.ts +0 -101
- package/src/utils.spec.ts +0 -370
- package/src/utils.ts +0 -149
- package/templates/advanced/build.js +0 -43
- package/templates/advanced/main.js +0 -3
- package/templates/advanced/manifest.json +0 -60
- package/templates/advanced/package-lock.json +0 -916
- package/templates/advanced/package.json +0 -11
- package/templates/advanced/previews/example.data.json +0 -1
- package/templates/advanced/previews/preview.html +0 -9
- package/templates/advanced/static/default.js +0 -1
- package/templates/advanced/static/default.scss +0 -1
- package/templates/basic/main.js +0 -3
- package/templates/basic/manifest.json +0 -62
- package/templates/basic/previews/example.data.json +0 -1
- package/templates/basic/previews/preview.html +0 -9
- package/templates/basic/static/default.css +0 -1
- package/templates/basic/static/default.js +0 -1
- package/tsconfig.json +0 -26
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,42 +0,0 @@
|
|
|
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-asset://canary.uat.matrix.squiz.cloud/123"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://localhost:3000/schemas/v1.json#",
|
|
3
|
-
"name": "test-page-render",
|
|
4
|
-
"version": "1.0.0",
|
|
5
|
-
"mainFunction": "main",
|
|
6
|
-
"displayName": "some-display-name",
|
|
7
|
-
"namespace": "unit-test-components",
|
|
8
|
-
"description": "some-description",
|
|
9
|
-
"functions": [
|
|
10
|
-
{
|
|
11
|
-
"name": "main",
|
|
12
|
-
"entry": "main.js",
|
|
13
|
-
"input": {
|
|
14
|
-
"type": "object",
|
|
15
|
-
"properties": {
|
|
16
|
-
"text ": {
|
|
17
|
-
"type": "string"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"required": []
|
|
21
|
-
},
|
|
22
|
-
"output": {
|
|
23
|
-
"responseType": "html",
|
|
24
|
-
"staticFiles": [
|
|
25
|
-
{
|
|
26
|
-
"location": "header",
|
|
27
|
-
"file": {
|
|
28
|
-
"filepath": "static-library-styles.css",
|
|
29
|
-
"type": "css"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"location": "footer",
|
|
34
|
-
"file": {
|
|
35
|
-
"filepath": "static-library-script.js",
|
|
36
|
-
"type": "js"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
|
-
"staticFiles": {
|
|
44
|
-
"locationRoot": "public"
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/integration-tests/__components__/test-page-render/public/static-library-script.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// static library frontend js
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://localhost:3040/schemas/JobV1.json#",
|
|
3
|
-
"name": "invalid manif@st",
|
|
4
|
-
"version": "1.0.0",
|
|
5
|
-
"mainFunction": "main",
|
|
6
|
-
"displayName": "some-displayName",
|
|
7
|
-
"description": "some-description",
|
|
8
|
-
"concurrency": 1,
|
|
9
|
-
"timeout": 10000,
|
|
10
|
-
"functions": [
|
|
11
|
-
{
|
|
12
|
-
"entry": "main.js",
|
|
13
|
-
"name": "main",
|
|
14
|
-
"input": {
|
|
15
|
-
"type": "object",
|
|
16
|
-
"properties": {
|
|
17
|
-
"something": {
|
|
18
|
-
"type": "string"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"required": ["something"]
|
|
22
|
-
},
|
|
23
|
-
"output": {
|
|
24
|
-
"responseType": "html"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://localhost:3040/schemas/JobV1.json#",
|
|
3
|
-
"name": "simple-job",
|
|
4
|
-
"displayName": "Simple Job",
|
|
5
|
-
"version": "1.0.2",
|
|
6
|
-
"mainFunction": "main",
|
|
7
|
-
"description": "some-description",
|
|
8
|
-
"concurrency": 1,
|
|
9
|
-
"timeout": 10000,
|
|
10
|
-
"functions": [
|
|
11
|
-
{
|
|
12
|
-
"entry": "main.js",
|
|
13
|
-
"name": "main",
|
|
14
|
-
"input": {
|
|
15
|
-
"type": "object",
|
|
16
|
-
"properties": {
|
|
17
|
-
"something": {
|
|
18
|
-
"type": "string"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"required": ["something"]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosError } from 'axios';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import fsp from 'fs/promises';
|
|
5
|
-
import { randomBytes } from 'crypto';
|
|
6
|
-
import { ComponentSetWebModelForCreate, Manifest, ManifestServiceForDev } from '@squiz/component-lib';
|
|
7
|
-
import { parseEnvVarForVar } from '@squiz/dx-common-lib';
|
|
8
|
-
import { ContentApi } from '@squiz/component-web-api-lib';
|
|
9
|
-
import { config } from 'dotenv';
|
|
10
|
-
import { execSync } from 'child_process';
|
|
11
|
-
import { getLogger } from '@squiz/dx-logger-lib';
|
|
12
|
-
import { uploadComponentFolder } from '../upload-component-folder';
|
|
13
|
-
import { buildDevelopmentJwt, DxpServiceId } from '@squiz/dxp-auth-lib';
|
|
14
|
-
|
|
15
|
-
config();
|
|
16
|
-
|
|
17
|
-
interface Config {
|
|
18
|
-
managementServiceUrl: string;
|
|
19
|
-
renderServiceUrl: string;
|
|
20
|
-
pageRenderServiceUrl: string;
|
|
21
|
-
contentServiceUrl: string;
|
|
22
|
-
tenantId: string;
|
|
23
|
-
jobServiceUrl: string;
|
|
24
|
-
ci_buildVersion: string;
|
|
25
|
-
ci_buildBranch: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const configObj: Config = {
|
|
29
|
-
managementServiceUrl: parseEnvVarForVar('COMPONENT_MANAGEMENT_SERVICE_URL').replace(/\/+$/, ''),
|
|
30
|
-
pageRenderServiceUrl: parseEnvVarForVar('PAGE_RENDER_SERVICE_URL').replace(/\/+$/, ''),
|
|
31
|
-
renderServiceUrl: parseEnvVarForVar('COMPONENT_RENDER_SERVICE_URL').replace(/\/+$/, ''),
|
|
32
|
-
contentServiceUrl: parseEnvVarForVar('CONTENT_API_URL').replace(/\/+$/, ''),
|
|
33
|
-
tenantId: parseEnvVarForVar('TENANT_ID'),
|
|
34
|
-
jobServiceUrl: parseEnvVarForVar('JOB_SERVICE_URL').replace(/\/+$/, ''),
|
|
35
|
-
ci_buildVersion: parseEnvVarForVar('CI_COMMIT_SHORT_SHA'),
|
|
36
|
-
ci_buildBranch: parseEnvVarForVar('CI_COMMIT_REF_NAME'),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
if (!configObj.ci_buildVersion || configObj.ci_buildVersion === `undefined`) {
|
|
40
|
-
configObj.ci_buildVersion = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!configObj.ci_buildBranch || configObj.ci_buildBranch === `undefined`) {
|
|
44
|
-
configObj.ci_buildBranch = execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default configObj;
|
|
48
|
-
|
|
49
|
-
const authToken =
|
|
50
|
-
'Bearer ' +
|
|
51
|
-
buildDevelopmentJwt({
|
|
52
|
-
service: {
|
|
53
|
-
[DxpServiceId.contentStore]: {
|
|
54
|
-
privileges: [
|
|
55
|
-
'CONTENT_SCHEMA_READ',
|
|
56
|
-
'CONTENT_SCHEMA_WRITE',
|
|
57
|
-
'CONTENT_ITEM_READ',
|
|
58
|
-
'CONTENT_ITEM_WRITE',
|
|
59
|
-
'SETTINGS_READ',
|
|
60
|
-
'SETTINGS_WRITE',
|
|
61
|
-
'PAGE_CONTENTS_WRITE',
|
|
62
|
-
'PAGE_CONTENTS_READ',
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
[DxpServiceId.components]: {
|
|
66
|
-
privileges: [
|
|
67
|
-
'COMPONENT_READ',
|
|
68
|
-
'COMPONENT_WRITE',
|
|
69
|
-
'COMPONENT_DEPLOY',
|
|
70
|
-
'COMPONENT_SET_WRITE',
|
|
71
|
-
'COMPONENT_DELETE',
|
|
72
|
-
'COMPONENT_SET_WRITE',
|
|
73
|
-
'COMPONENT_SET_READ',
|
|
74
|
-
'COMPONENT_SET_ENVIRONMENT_READ',
|
|
75
|
-
'COMPONENT_SET_ENVIRONMENT_WRITE',
|
|
76
|
-
],
|
|
77
|
-
},
|
|
78
|
-
[DxpServiceId.segmentation]: {
|
|
79
|
-
privileges: ['SEGMENT_READ'],
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export const managementService = axios.create({
|
|
85
|
-
baseURL: configObj.managementServiceUrl + '/v1',
|
|
86
|
-
headers: {
|
|
87
|
-
Authorization: authToken,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export const managementServiceRoot = axios.create({
|
|
92
|
-
baseURL: configObj.managementServiceUrl,
|
|
93
|
-
headers: {
|
|
94
|
-
Authorization: authToken,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
export const renderService = axios.create({
|
|
99
|
-
baseURL: configObj.renderServiceUrl,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
export const contentService = axios.create({
|
|
103
|
-
baseURL: configObj.contentServiceUrl,
|
|
104
|
-
headers: {
|
|
105
|
-
Authorization: authToken,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
export const pageRenderService = axios.create({
|
|
110
|
-
baseURL: configObj.pageRenderServiceUrl,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
export const jobService = axios.create({
|
|
114
|
-
baseURL: configObj.jobServiceUrl,
|
|
115
|
-
headers: {
|
|
116
|
-
Authorization: authToken,
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
export const ci_buildVersion = configObj.ci_buildVersion;
|
|
121
|
-
export const ci_buildBranch = configObj.ci_buildBranch;
|
|
122
|
-
|
|
123
|
-
export async function getTestComponents() {
|
|
124
|
-
const componentsDir = path.join(__dirname, '/__components__/');
|
|
125
|
-
const manifestService = new ManifestServiceForDev(componentsDir, getLogger({ name: 'getTestComponents' }));
|
|
126
|
-
return await manifestService.listAllComponentManifests();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export async function getTestComponent(componentFolderName: string) {
|
|
130
|
-
const componentsDir = path.join(__dirname, '/__components__/', componentFolderName);
|
|
131
|
-
const manifestService = new ManifestServiceForDev(componentsDir, getLogger({ name: 'getTestComponents' }));
|
|
132
|
-
return await manifestService.listAllComponentManifests();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export async function getTestJobs() {
|
|
136
|
-
const jobsDir = path.join(__dirname, '/__jobs__/');
|
|
137
|
-
const manifestService = new ManifestServiceForDev(jobsDir, getLogger({ name: 'getTestJobs' }));
|
|
138
|
-
return await manifestService.listAllComponentManifests();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export async function createFile(filePath: string, sizeInMB: number) {
|
|
142
|
-
const content = randomBytes(sizeInMB * 1000000);
|
|
143
|
-
await fsp.writeFile(`${filePath}`, content);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function removeFile(filePath: string) {
|
|
147
|
-
fsp.unlink(filePath);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export async function deleteComponentSet(webPath: string) {
|
|
151
|
-
try {
|
|
152
|
-
await managementService.delete(`/component-set/${webPath}`);
|
|
153
|
-
} catch (error) {
|
|
154
|
-
// no ops
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export async function addComponentSet(componentSet: ComponentSetWebModelForCreate) {
|
|
159
|
-
try {
|
|
160
|
-
await managementService.post(`/component-set`, componentSet);
|
|
161
|
-
} catch (error) {
|
|
162
|
-
//no ops
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export async function addContentItem(contentItem: ContentApi.ContentItemWebModel) {
|
|
167
|
-
try {
|
|
168
|
-
await contentService.post(`/content-item`, contentItem);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
//no ops
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export async function deleteContentItem(contentItemId: string) {
|
|
175
|
-
try {
|
|
176
|
-
await contentService.delete(`/content-item/${contentItemId}`);
|
|
177
|
-
} catch (error) {
|
|
178
|
-
//no ops
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export async function deleteContentSchema(contentSchemaName: string) {
|
|
183
|
-
try {
|
|
184
|
-
await contentService.delete(`/content-item/${contentSchemaName}`);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
//no ops
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export async function deleteComponent(manifest: Manifest) {
|
|
191
|
-
try {
|
|
192
|
-
await managementService.delete(`/component/${manifest.getName()}`);
|
|
193
|
-
await contentService.delete(
|
|
194
|
-
`/content-schema/${manifest.getName()}/${manifest.getVersion()}/${manifest.getComponentFunctionByName().name}`,
|
|
195
|
-
);
|
|
196
|
-
} catch (error) {
|
|
197
|
-
if ((error as AxiosError).response?.status !== 404) {
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export async function deleteComponents(manifests: Manifest[]) {
|
|
204
|
-
await Promise.all(manifests.map((manifest) => deleteComponent(manifest)));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export async function uploadTestComponent(componentFolderPath: string, tempFolderPath: string): Promise<void> {
|
|
208
|
-
const componentPath = path.join(__dirname, componentFolderPath);
|
|
209
|
-
await uploadComponentFolder(managementServiceRoot, configObj.managementServiceUrl, componentPath, tempFolderPath);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export async function deleteJob(manifest: Manifest) {
|
|
213
|
-
try {
|
|
214
|
-
await jobService.delete(`/job/${manifest.getName()}/${manifest.getVersion()}`);
|
|
215
|
-
} catch (error) {
|
|
216
|
-
if ((error as AxiosError).response?.status === 404) {
|
|
217
|
-
const logger = getLogger({ name: 'delete job' });
|
|
218
|
-
logger.info('job not found');
|
|
219
|
-
} else {
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export async function deleteJobs(manifests: Manifest[]) {
|
|
226
|
-
await Promise.all(manifests.map((manifest) => deleteJob(manifest)));
|
|
227
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
renderService,
|
|
3
|
-
managementService,
|
|
4
|
-
contentService,
|
|
5
|
-
managementServiceRoot,
|
|
6
|
-
ci_buildVersion,
|
|
7
|
-
ci_buildBranch,
|
|
8
|
-
} from './helper';
|
|
9
|
-
|
|
10
|
-
interface HealthInfo {
|
|
11
|
-
status: string;
|
|
12
|
-
buildVersion: string;
|
|
13
|
-
buildBranch: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe('Verify latest services deployments', () => {
|
|
17
|
-
it.skip('Should have latest Management API service', async () => {
|
|
18
|
-
const response: HealthInfo = (await managementServiceRoot.get('/health')).data;
|
|
19
|
-
expect(response.buildVersion).toBe(ci_buildVersion);
|
|
20
|
-
expect(response.buildBranch).toBe(ci_buildBranch);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('Should return 200 for Management API docs', async () => {
|
|
24
|
-
const req = await managementService.get('/v1/docs', {
|
|
25
|
-
baseURL: managementService.defaults.baseURL?.replace(/v1\/?/, ''),
|
|
26
|
-
});
|
|
27
|
-
expect(req.status).toBe(200);
|
|
28
|
-
expect(req.headers['content-type']).toEqual('text/html; charset=utf-8');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('Should return 200 for Management API docs.json', async () => {
|
|
32
|
-
const req = await managementService.get('/v1/docs.json', {
|
|
33
|
-
baseURL: managementService.defaults.baseURL?.replace(/v1\/?/, ''),
|
|
34
|
-
});
|
|
35
|
-
expect(req.status).toBe(200);
|
|
36
|
-
expect(req.headers['content-type']).toEqual('application/json; charset=UTF-8');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it.skip('Should have latest Render Runtime service', async () => {
|
|
40
|
-
const response: HealthInfo = (await renderService.get('/health')).data;
|
|
41
|
-
expect(response.buildVersion).toBe(ci_buildVersion);
|
|
42
|
-
expect(response.buildBranch).toBe(ci_buildBranch);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('Should return 200 for Render Runtime API docs', async () => {
|
|
46
|
-
const req = await renderService.get('/docs');
|
|
47
|
-
expect(req.status).toBe(200);
|
|
48
|
-
expect(req.headers['content-type']).toEqual('text/html; charset=utf-8');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('Should return 200 for Render Runtime API docs.json', async () => {
|
|
52
|
-
const req = await renderService.get('/docs.json');
|
|
53
|
-
expect(req.status).toBe(200);
|
|
54
|
-
expect(req.headers['content-type']).toEqual('application/json; charset=UTF-8');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it.skip('Should have latest Content API service', async () => {
|
|
58
|
-
const response: HealthInfo = (await contentService.get('/health')).data;
|
|
59
|
-
expect(response.buildVersion).toBe(ci_buildVersion);
|
|
60
|
-
expect(response.buildBranch).toBe(ci_buildBranch);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('Should return 200 for Content API docs', async () => {
|
|
64
|
-
const req = await contentService.get('/docs');
|
|
65
|
-
expect(req.status).toBe(200);
|
|
66
|
-
expect(req.headers['content-type']).toEqual('text/html; charset=utf-8');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('Should return 200 for Content API docs.json', async () => {
|
|
70
|
-
const req = await contentService.get('/docs.json');
|
|
71
|
-
expect(req.status).toBe(200);
|
|
72
|
-
expect(req.headers['content-type']).toEqual('application/json; charset=UTF-8');
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
jest.setTimeout(60_000);
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { uploadFile } from '@squiz/virus-scanner-lib';
|
|
2
|
-
|
|
3
|
-
import { zipDirectory } from '@squiz/dx-common-lib';
|
|
4
|
-
import { ManifestServiceForDev } from '@squiz/component-lib';
|
|
5
|
-
import fsp from 'fs/promises';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import { AxiosInstance } from 'axios';
|
|
8
|
-
import color from 'cli-color';
|
|
9
|
-
import { getLogger, Logger } from '@squiz/dx-logger-lib';
|
|
10
|
-
import {
|
|
11
|
-
watchAndWaitForUploadAndScanComplete,
|
|
12
|
-
checkIfVersionExists,
|
|
13
|
-
handleResponse,
|
|
14
|
-
isAxiosResponse,
|
|
15
|
-
isUserInOrganization,
|
|
16
|
-
assertComponentTypeAllowed,
|
|
17
|
-
} from './utils';
|
|
18
|
-
|
|
19
|
-
export const logger: Logger = getLogger({ name: 'upload-component', format: 'human' });
|
|
20
|
-
|
|
21
|
-
export async function uploadComponentFolder(
|
|
22
|
-
apiClient: AxiosInstance,
|
|
23
|
-
componentServiceManagementUrl: string,
|
|
24
|
-
folderPath: string,
|
|
25
|
-
baseTempDir: string = '',
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
if (folderPath === '.') {
|
|
28
|
-
// Ensures that the cmp-upload folder and zipping process is consistent,
|
|
29
|
-
// whether the deploy was called outside or inside the component folder.
|
|
30
|
-
// eg: dxp-next-cli cmp deploy [componentFolder] || dxp-next-cli cmp deploy .
|
|
31
|
-
baseTempDir = '../';
|
|
32
|
-
}
|
|
33
|
-
const tmpDir = await fsp.mkdtemp(path.resolve(baseTempDir, 'cmp-upload'));
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const manifestService = new ManifestServiceForDev(folderPath, logger);
|
|
37
|
-
const manifestPath = path.join(folderPath, `manifest.json`);
|
|
38
|
-
const manifest = await manifestService.readManifest(manifestPath);
|
|
39
|
-
|
|
40
|
-
await assertComponentTypeAllowed(manifest.type, apiClient, '/health', componentServiceManagementUrl);
|
|
41
|
-
|
|
42
|
-
const shouldValidateNamespace = !isUserInOrganization();
|
|
43
|
-
await manifestService.assertManifestIsValid(manifestPath, manifest.getModel(), {
|
|
44
|
-
validateNamespace: shouldValidateNamespace,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
await checkIfVersionExists(
|
|
49
|
-
apiClient,
|
|
50
|
-
`/v1/component/${manifest.getName()}/${manifest.getVersion()}`,
|
|
51
|
-
componentServiceManagementUrl,
|
|
52
|
-
)
|
|
53
|
-
) {
|
|
54
|
-
throw new Error(`Cannot upload component version, ${manifest.getName()} ${manifest.getVersion()} already exists`);
|
|
55
|
-
}
|
|
56
|
-
logger.info('Initial scanning');
|
|
57
|
-
const zip = await zipDirectory(folderPath, tmpDir);
|
|
58
|
-
|
|
59
|
-
const initialUpload = await handleResponse<any>(
|
|
60
|
-
apiClient.post('/v1/upload-component', {}, { baseURL: componentServiceManagementUrl }),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
logger.info(`deployment id: ${initialUpload.id} status: transferring`);
|
|
64
|
-
await uploadFile(initialUpload, zip);
|
|
65
|
-
|
|
66
|
-
await watchAndWaitForUploadAndScanComplete(
|
|
67
|
-
apiClient,
|
|
68
|
-
'/v1/upload-component/status/',
|
|
69
|
-
initialUpload.id,
|
|
70
|
-
componentServiceManagementUrl,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
logger.info(`deployment id: ${initialUpload.id} status: deploying component folder`);
|
|
74
|
-
|
|
75
|
-
//Rarely this call will return 504, while successfully uploading the component - the cause is currently unknown
|
|
76
|
-
let result = await handleResponse<any>(
|
|
77
|
-
apiClient.post(`/v1/upload-component/next/${initialUpload.id}`, {}, { baseURL: componentServiceManagementUrl }),
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
if (!isAxiosResponse(result)) {
|
|
81
|
-
let retriesAllowed = 12;
|
|
82
|
-
while (retriesAllowed > 0) {
|
|
83
|
-
logger.info(
|
|
84
|
-
`deployment id: ${initialUpload.id} status: ${color.yellow(
|
|
85
|
-
`unknown, retrying to check the upload status ${retriesAllowed} more times`,
|
|
86
|
-
)}`,
|
|
87
|
-
);
|
|
88
|
-
if (
|
|
89
|
-
await checkIfVersionExists(
|
|
90
|
-
apiClient,
|
|
91
|
-
`/v1/component/${manifest.getName()}/${manifest.getVersion()}`,
|
|
92
|
-
componentServiceManagementUrl,
|
|
93
|
-
)
|
|
94
|
-
) {
|
|
95
|
-
result = {
|
|
96
|
-
status: 'successful',
|
|
97
|
-
accessLink: 'unknown',
|
|
98
|
-
};
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
await new Promise((r) => setTimeout(r, 10000));
|
|
102
|
-
retriesAllowed--;
|
|
103
|
-
}
|
|
104
|
-
if (retriesAllowed === 0) {
|
|
105
|
-
logger.error(`deployment id: ${initialUpload.id} status: ${color.red('failed to check the upload status')}`);
|
|
106
|
-
throw new Error(result.toString());
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
await fsp.rm(tmpDir, { force: true, recursive: true }).catch((error: any) => {
|
|
111
|
-
logger.error('failed to remove temp directory', error);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
if (result.status === 'successful') {
|
|
115
|
-
logger.info(`deployment id: ${initialUpload.id} status: ${color.green('success')}`);
|
|
116
|
-
logger.info(`uploaded location: ${result.accessLink}`);
|
|
117
|
-
} else {
|
|
118
|
-
const message = result?.message ?? 'unknown';
|
|
119
|
-
logger.error(`failed due an unexpected reason: ${message}`);
|
|
120
|
-
await fsp.rm(tmpDir, { force: true, recursive: true }).catch((error: any) => {
|
|
121
|
-
logger.error('failed to remove temp directory', error);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
} catch (e) {
|
|
125
|
-
await fsp.rm(tmpDir, { force: true, recursive: true }).catch((error: any) => {
|
|
126
|
-
logger.error('failed to remove temp directory', error);
|
|
127
|
-
});
|
|
128
|
-
throw e;
|
|
129
|
-
}
|
|
130
|
-
}
|