hereya-cli 0.89.0 → 0.90.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/README.md +65 -65
- package/dist/backend/cloud/cloud-backend/apps-deploy.d.ts +69 -0
- package/dist/backend/cloud/cloud-backend/apps-deploy.js +94 -0
- package/dist/backend/cloud/cloud-backend/apps-versions.d.ts +69 -0
- package/dist/backend/cloud/cloud-backend/apps-versions.js +113 -0
- package/dist/backend/cloud/cloud-backend/executor-jobs.d.ts +75 -0
- package/dist/backend/cloud/cloud-backend/executor-jobs.js +110 -0
- package/dist/backend/cloud/cloud-backend/misc.d.ts +5 -0
- package/dist/backend/cloud/cloud-backend/misc.js +78 -0
- package/dist/backend/cloud/cloud-backend/packages-publish.d.ts +3 -0
- package/dist/backend/cloud/cloud-backend/packages-publish.js +99 -0
- package/dist/backend/cloud/cloud-backend/packages-registry.d.ts +6 -0
- package/dist/backend/cloud/cloud-backend/packages-registry.js +146 -0
- package/dist/backend/cloud/cloud-backend/packages-workspace.d.ts +4 -0
- package/dist/backend/cloud/cloud-backend/packages-workspace.js +50 -0
- package/dist/backend/cloud/cloud-backend/projects.d.ts +7 -0
- package/dist/backend/cloud/cloud-backend/projects.js +122 -0
- package/dist/backend/cloud/cloud-backend/state.d.ts +6 -0
- package/dist/backend/cloud/cloud-backend/state.js +86 -0
- package/dist/backend/cloud/cloud-backend/utils.d.ts +55 -0
- package/dist/backend/cloud/cloud-backend/utils.js +56 -0
- package/dist/backend/cloud/cloud-backend/workspace-env.d.ts +5 -0
- package/dist/backend/cloud/cloud-backend/workspace-env.js +63 -0
- package/dist/backend/cloud/cloud-backend/workspaces.d.ts +7 -0
- package/dist/backend/cloud/cloud-backend/workspaces.js +124 -0
- package/dist/backend/cloud/cloud-backend.d.ts +56 -126
- package/dist/backend/cloud/cloud-backend.js +95 -1089
- package/dist/backend/cloud/cloud-backend.test.setup.d.ts +13 -0
- package/dist/backend/cloud/cloud-backend.test.setup.js +14 -0
- package/dist/backend/local.setup.d.ts +10 -0
- package/dist/backend/local.setup.js +20 -0
- package/dist/commands/executor/start/index.d.ts +1 -11
- package/dist/commands/executor/start/index.js +13 -498
- package/dist/commands/import-repo/index.js +2 -2
- package/dist/lib/env/test.setup.d.ts +7 -0
- package/dist/lib/env/test.setup.js +18 -0
- package/dist/lib/executor-start/auth.d.ts +2 -0
- package/dist/lib/executor-start/auth.js +21 -0
- package/dist/lib/executor-start/execute-app-job.d.ts +13 -0
- package/dist/lib/executor-start/execute-app-job.js +146 -0
- package/dist/lib/executor-start/execute-deploy-job.d.ts +14 -0
- package/dist/lib/executor-start/execute-deploy-job.js +64 -0
- package/dist/lib/executor-start/execute-init-job.d.ts +14 -0
- package/dist/lib/executor-start/execute-init-job.js +135 -0
- package/dist/lib/executor-start/format.d.ts +13 -0
- package/dist/lib/executor-start/format.js +22 -0
- package/dist/lib/executor-start/job-dispatch.d.ts +15 -0
- package/dist/lib/executor-start/job-dispatch.js +89 -0
- package/dist/lib/package/index.d.ts +4 -4
- package/oclif.manifest.json +52 -52
- package/package.json +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { safeResponseJson } from './utils.js';
|
|
2
|
+
export async function getPackageByVersion(config, name, version) {
|
|
3
|
+
const response = await fetch(`${config.url}/api/registry/packages/${encodeURIComponent(name)}/${encodeURIComponent(version)}`, {
|
|
4
|
+
headers: {
|
|
5
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
6
|
+
},
|
|
7
|
+
method: 'GET',
|
|
8
|
+
});
|
|
9
|
+
const result = await safeResponseJson(response);
|
|
10
|
+
if (!response.ok) {
|
|
11
|
+
let errorMessage = result.error || 'Failed to get package';
|
|
12
|
+
switch (response.status) {
|
|
13
|
+
case 401: {
|
|
14
|
+
errorMessage = 'Authentication failed. Please run `hereya login` to refresh your credentials.';
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case 403: {
|
|
18
|
+
errorMessage = `Access denied: ${errorMessage}`;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case 404: {
|
|
22
|
+
errorMessage = `Package '${name}@${version}' not found`;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
reason: errorMessage,
|
|
28
|
+
success: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
package: result.package,
|
|
33
|
+
success: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export async function getPackageLatest(config, name) {
|
|
37
|
+
const response = await fetch(`${config.url}/api/registry/packages/${encodeURIComponent(name)}`, {
|
|
38
|
+
headers: {
|
|
39
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
40
|
+
},
|
|
41
|
+
method: 'GET',
|
|
42
|
+
});
|
|
43
|
+
const result = await safeResponseJson(response);
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
let errorMessage = result.error || 'Failed to get package';
|
|
46
|
+
switch (response.status) {
|
|
47
|
+
case 401: {
|
|
48
|
+
errorMessage = 'Authentication failed. Please run `hereya login` to refresh your credentials.';
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 403: {
|
|
52
|
+
errorMessage = `Access denied: ${errorMessage}`;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 404: {
|
|
56
|
+
errorMessage = `Package '${name}' not found`;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
reason: errorMessage,
|
|
62
|
+
success: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
package: result.package,
|
|
67
|
+
success: true,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export async function listPackageVersions(config, name) {
|
|
71
|
+
const response = await fetch(`${config.url}/api/registry/packages/${encodeURIComponent(name)}?versions=all`, {
|
|
72
|
+
headers: {
|
|
73
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
74
|
+
},
|
|
75
|
+
method: 'GET',
|
|
76
|
+
});
|
|
77
|
+
const result = await safeResponseJson(response);
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
let errorMessage = result.error || 'Failed to list package versions';
|
|
80
|
+
switch (response.status) {
|
|
81
|
+
case 401: {
|
|
82
|
+
errorMessage = 'Authentication failed. Please run `hereya login` to refresh your credentials.';
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 403: {
|
|
86
|
+
errorMessage = `Access denied: ${errorMessage}`;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case 404: {
|
|
90
|
+
errorMessage = `Package '${name}' not found`;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
reason: errorMessage,
|
|
96
|
+
success: false,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
packages: result.packages || [],
|
|
101
|
+
success: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export async function searchPackages(config, input) {
|
|
105
|
+
const url = new URL(`${config.url}/api/registry/packages/search`);
|
|
106
|
+
url.searchParams.append('q', input.query);
|
|
107
|
+
if (input.limit !== undefined) {
|
|
108
|
+
url.searchParams.append('limit', String(input.limit));
|
|
109
|
+
}
|
|
110
|
+
if (input.offset !== undefined) {
|
|
111
|
+
url.searchParams.append('offset', String(input.offset));
|
|
112
|
+
}
|
|
113
|
+
const response = await fetch(url, {
|
|
114
|
+
headers: {
|
|
115
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
116
|
+
},
|
|
117
|
+
method: 'GET',
|
|
118
|
+
});
|
|
119
|
+
const result = await safeResponseJson(response);
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
let errorMessage = result.error || 'Failed to search packages';
|
|
122
|
+
switch (response.status) {
|
|
123
|
+
case 400: {
|
|
124
|
+
errorMessage = `Invalid search query: ${errorMessage}`;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case 401: {
|
|
128
|
+
errorMessage = 'Authentication failed. Please run `hereya login` to refresh your credentials.';
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case 500: {
|
|
132
|
+
errorMessage = `Server error: ${errorMessage}`;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
reason: errorMessage,
|
|
138
|
+
success: false,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
hasMore: result.hasMore ?? false,
|
|
143
|
+
packages: result.packages || [],
|
|
144
|
+
success: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AddPackageToWorkspaceInput, AddPackageToWorkspaceOutput, RemovePackageFromWorkspaceInput, RemovePackageFromWorkspaceOutput } from '../../common.js';
|
|
2
|
+
import { CloudHttpConfig } from './utils.js';
|
|
3
|
+
export declare function addPackageToWorkspace(config: CloudHttpConfig, input: AddPackageToWorkspaceInput): Promise<AddPackageToWorkspaceOutput>;
|
|
4
|
+
export declare function removePackageFromWorkspace(config: CloudHttpConfig, input: RemovePackageFromWorkspaceInput): Promise<RemovePackageFromWorkspaceOutput>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { convertWorkspace, safeResponseJson } from './utils.js';
|
|
2
|
+
export async function addPackageToWorkspace(config, input) {
|
|
3
|
+
const formData = new FormData();
|
|
4
|
+
formData.append('package', input.package);
|
|
5
|
+
formData.append('infra', input.infra);
|
|
6
|
+
formData.append('env', JSON.stringify(input.env));
|
|
7
|
+
if (input.parameters) {
|
|
8
|
+
formData.append('parameters', JSON.stringify(input.parameters));
|
|
9
|
+
}
|
|
10
|
+
if (input.version) {
|
|
11
|
+
formData.append('version', input.version);
|
|
12
|
+
}
|
|
13
|
+
const response = await fetch(`${config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/packages`, {
|
|
14
|
+
body: formData,
|
|
15
|
+
headers: {
|
|
16
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
17
|
+
},
|
|
18
|
+
method: 'POST',
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
return {
|
|
22
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
23
|
+
success: false,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const result = await response.json();
|
|
27
|
+
return {
|
|
28
|
+
success: true,
|
|
29
|
+
workspace: convertWorkspace(result.workspace),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export async function removePackageFromWorkspace(config, input) {
|
|
33
|
+
const response = await fetch(`${config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/packages/${encodeURIComponent(input.package)}`, {
|
|
34
|
+
headers: {
|
|
35
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
36
|
+
},
|
|
37
|
+
method: 'DELETE',
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
return {
|
|
41
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
42
|
+
success: false,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const result = await response.json();
|
|
46
|
+
return {
|
|
47
|
+
success: true,
|
|
48
|
+
workspace: convertWorkspace(result.workspace),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GetProjectMetadataInput, GetProjectMetadataOutput, ImportProjectInput, ImportProjectOutput, InitProjectInput, InitProjectOutput, ListProjectsOutput, SaveProjectMetadataInput, SaveProjectMetadataOutput } from '../../common.js';
|
|
2
|
+
import { CloudHttpConfig } from './utils.js';
|
|
3
|
+
export declare function init(config: CloudHttpConfig, input: InitProjectInput): Promise<InitProjectOutput>;
|
|
4
|
+
export declare function getProjectMetadata(config: CloudHttpConfig, input: GetProjectMetadataInput): Promise<GetProjectMetadataOutput>;
|
|
5
|
+
export declare function saveProjectMetadata(config: CloudHttpConfig, input: SaveProjectMetadataInput): Promise<SaveProjectMetadataOutput>;
|
|
6
|
+
export declare function importProject(config: CloudHttpConfig, input: ImportProjectInput): Promise<ImportProjectOutput>;
|
|
7
|
+
export declare function listProjects(config: CloudHttpConfig): Promise<ListProjectsOutput>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { safeResponseJson } from './utils.js';
|
|
2
|
+
export async function init(config, input) {
|
|
3
|
+
const formData = new FormData();
|
|
4
|
+
formData.append('name', input.project);
|
|
5
|
+
formData.append('workspace', input.workspace);
|
|
6
|
+
const response = await fetch(`${config.url}/api/projects`, {
|
|
7
|
+
body: formData,
|
|
8
|
+
headers: {
|
|
9
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
10
|
+
},
|
|
11
|
+
method: 'POST',
|
|
12
|
+
});
|
|
13
|
+
if (!response.ok) {
|
|
14
|
+
throw new Error(JSON.stringify(await safeResponseJson(response)));
|
|
15
|
+
}
|
|
16
|
+
const result = await response.json();
|
|
17
|
+
return {
|
|
18
|
+
project: {
|
|
19
|
+
id: result.project.id,
|
|
20
|
+
name: result.project.name,
|
|
21
|
+
},
|
|
22
|
+
workspace: {
|
|
23
|
+
id: result.project.defaultWorkspace.id,
|
|
24
|
+
name: result.project.defaultWorkspace.name,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export async function getProjectMetadata(config, input) {
|
|
29
|
+
const response = await fetch(`${config.url}/api/projects/${encodeURIComponent(input.project)}/metadata`, {
|
|
30
|
+
headers: {
|
|
31
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
32
|
+
},
|
|
33
|
+
method: 'GET',
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
return {
|
|
37
|
+
found: false,
|
|
38
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const result = await safeResponseJson(response);
|
|
42
|
+
if (!result.metadata) {
|
|
43
|
+
return {
|
|
44
|
+
found: false,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
defaultWorkspace: result.defaultWorkspace,
|
|
49
|
+
found: true,
|
|
50
|
+
metadata: result.metadata,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export async function saveProjectMetadata(config, input) {
|
|
54
|
+
const formData = new FormData();
|
|
55
|
+
formData.append('metadata', JSON.stringify(input.metadata));
|
|
56
|
+
const response = await fetch(`${config.url}/api/projects/${encodeURIComponent(input.project)}/metadata`, {
|
|
57
|
+
body: formData,
|
|
58
|
+
headers: {
|
|
59
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
60
|
+
},
|
|
61
|
+
method: 'POST',
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
return {
|
|
65
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
66
|
+
success: false,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
success: true,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export async function importProject(config, input) {
|
|
74
|
+
const response = await fetch(`${config.url}/api/projects/${encodeURIComponent(input.project)}/import`, {
|
|
75
|
+
body: JSON.stringify({ repoUrl: input.repoUrl, workspace: input.workspace }),
|
|
76
|
+
headers: {
|
|
77
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
78
|
+
'Content-Type': 'application/json',
|
|
79
|
+
},
|
|
80
|
+
method: 'POST',
|
|
81
|
+
});
|
|
82
|
+
const result = await safeResponseJson(response);
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
const reason = typeof result?.error === 'string'
|
|
85
|
+
? result.error
|
|
86
|
+
: (result?.errors && typeof result.errors === 'object'
|
|
87
|
+
? JSON.stringify(result.errors)
|
|
88
|
+
: JSON.stringify(result));
|
|
89
|
+
return {
|
|
90
|
+
...(typeof result?.code === 'string' ? { code: result.code } : {}),
|
|
91
|
+
reason,
|
|
92
|
+
success: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (!result?.success || !result?.project) {
|
|
96
|
+
return {
|
|
97
|
+
reason: typeof result?.error === 'string' ? result.error : 'Unexpected response from server',
|
|
98
|
+
success: false,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
project: {
|
|
103
|
+
defaultWorkspace: result.project.defaultWorkspace,
|
|
104
|
+
name: result.project.name,
|
|
105
|
+
},
|
|
106
|
+
success: true,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export async function listProjects(config) {
|
|
110
|
+
const response = await fetch(`${config.url}/api/projects`, {
|
|
111
|
+
headers: { 'Authorization': `Bearer ${config.accessToken}` },
|
|
112
|
+
method: 'GET',
|
|
113
|
+
});
|
|
114
|
+
if (!response.ok) {
|
|
115
|
+
throw new Error(JSON.stringify(await safeResponseJson(response)));
|
|
116
|
+
}
|
|
117
|
+
const result = await response.json();
|
|
118
|
+
return (result.projects ?? []).map((p) => ({
|
|
119
|
+
defaultWorkspace: p.defaultWorkspace?.name ?? '-',
|
|
120
|
+
name: p.name,
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Config } from '../../../lib/config/common.js';
|
|
2
|
+
import { DeleteStateInput, DeleteStateOutput, GetStateInput, GetStateOutput } from '../../common.js';
|
|
3
|
+
import { CloudHttpConfig } from './utils.js';
|
|
4
|
+
export declare function deleteState(config: CloudHttpConfig, input: DeleteStateInput): Promise<DeleteStateOutput>;
|
|
5
|
+
export declare function getState(config: CloudHttpConfig, input: GetStateInput): Promise<GetStateOutput>;
|
|
6
|
+
export declare function saveState(config: CloudHttpConfig, stateConfig: Config, workspace?: string): Promise<void>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { safeResponseJson } from './utils.js';
|
|
2
|
+
export async function deleteState(config, input) {
|
|
3
|
+
const response = await fetch(`${config.url}/api/projects/${encodeURIComponent(input.project)}/state/${encodeURIComponent(input.workspace)}`, {
|
|
4
|
+
headers: {
|
|
5
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
6
|
+
},
|
|
7
|
+
method: 'DELETE',
|
|
8
|
+
});
|
|
9
|
+
if (!response.ok) {
|
|
10
|
+
return {
|
|
11
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
12
|
+
success: false,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
message: `State for project ${input.project} in workspace ${input.workspace} deleted successfully`,
|
|
17
|
+
success: true,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function getState(config, input) {
|
|
21
|
+
const url = new URL(`${config.url}/api/projects/${encodeURIComponent(input.project)}/state`);
|
|
22
|
+
url.searchParams.append('workspace', input.workspace);
|
|
23
|
+
const response = await fetch(url, {
|
|
24
|
+
headers: {
|
|
25
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
26
|
+
},
|
|
27
|
+
method: 'GET',
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
return {
|
|
31
|
+
found: false,
|
|
32
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const result = await response.json();
|
|
36
|
+
if (!result.success) {
|
|
37
|
+
return {
|
|
38
|
+
found: false,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const deploy = {};
|
|
42
|
+
for (const item of result.config.deploy) {
|
|
43
|
+
deploy[item.name] = { version: item.version };
|
|
44
|
+
}
|
|
45
|
+
const packages = {};
|
|
46
|
+
for (const item of result.config.packages) {
|
|
47
|
+
packages[item.name] = { version: item.version };
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
config: {
|
|
51
|
+
deploy,
|
|
52
|
+
packages,
|
|
53
|
+
project: input.project,
|
|
54
|
+
workspace: input.workspace,
|
|
55
|
+
},
|
|
56
|
+
found: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export async function saveState(config, stateConfig, workspace) {
|
|
60
|
+
const formData = new FormData();
|
|
61
|
+
if (workspace) {
|
|
62
|
+
formData.append('workspace', workspace);
|
|
63
|
+
}
|
|
64
|
+
if (stateConfig.deploy) {
|
|
65
|
+
const deployArray = Object.entries(stateConfig.deploy)
|
|
66
|
+
.map(([name, { version }]) => ({ name, version }))
|
|
67
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
68
|
+
formData.append('deploy', JSON.stringify(deployArray));
|
|
69
|
+
}
|
|
70
|
+
if (stateConfig.packages) {
|
|
71
|
+
const packagesArray = Object.entries(stateConfig.packages)
|
|
72
|
+
.map(([name, { version }]) => ({ name, version }))
|
|
73
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
74
|
+
formData.append('packages', JSON.stringify(packagesArray));
|
|
75
|
+
}
|
|
76
|
+
const response = await fetch(`${config.url}/api/projects/${encodeURIComponent(stateConfig.project)}/state`, {
|
|
77
|
+
body: formData,
|
|
78
|
+
headers: {
|
|
79
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
80
|
+
},
|
|
81
|
+
method: 'POST',
|
|
82
|
+
});
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
throw new Error(JSON.stringify(await safeResponseJson(response)));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { InfrastructureType } from '../../../infrastructure/common.js';
|
|
2
|
+
import { Workspace } from '../../common.js';
|
|
3
|
+
export interface CloudHttpConfig {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function safeResponseJson(response: {
|
|
8
|
+
text(): Promise<string>;
|
|
9
|
+
}): Promise<any>;
|
|
10
|
+
interface RawWorkspace {
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
env: {
|
|
13
|
+
id: string;
|
|
14
|
+
infrastructure: InfrastructureType;
|
|
15
|
+
key: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}[];
|
|
18
|
+
hasExecutor?: boolean;
|
|
19
|
+
id: string;
|
|
20
|
+
isDeploy?: boolean;
|
|
21
|
+
mirrorOf: null | {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
};
|
|
25
|
+
name: string;
|
|
26
|
+
ownerId: string;
|
|
27
|
+
ownPackages?: {
|
|
28
|
+
env?: {
|
|
29
|
+
id: string;
|
|
30
|
+
infrastructure: InfrastructureType;
|
|
31
|
+
key: string;
|
|
32
|
+
value: string;
|
|
33
|
+
}[];
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
parameters: Record<string, any>;
|
|
37
|
+
version: string;
|
|
38
|
+
}[];
|
|
39
|
+
packages: {
|
|
40
|
+
env: {
|
|
41
|
+
id: string;
|
|
42
|
+
infrastructure: InfrastructureType;
|
|
43
|
+
key: string;
|
|
44
|
+
value: string;
|
|
45
|
+
}[];
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
parameters: Record<string, any>;
|
|
49
|
+
version: string;
|
|
50
|
+
}[];
|
|
51
|
+
profile?: null | string;
|
|
52
|
+
updatedAt: Date;
|
|
53
|
+
}
|
|
54
|
+
export declare function convertWorkspace(workspace: RawWorkspace): Workspace;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export async function safeResponseJson(response) {
|
|
2
|
+
const text = await response.text();
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(text);
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return { error: text || 'Unknown error' };
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function convertWorkspace(workspace) {
|
|
11
|
+
const env = {};
|
|
12
|
+
if (workspace.packages) {
|
|
13
|
+
for (const pkg of workspace.packages) {
|
|
14
|
+
if (pkg.env) {
|
|
15
|
+
for (const e of pkg.env) {
|
|
16
|
+
env[e.key] = `${e.infrastructure}:${e.value}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (workspace.env) {
|
|
22
|
+
for (const e of workspace.env) {
|
|
23
|
+
env[e.key] = `${e.infrastructure}:${e.value}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const packages = {};
|
|
27
|
+
if (workspace.packages) {
|
|
28
|
+
for (const pkg of workspace.packages) {
|
|
29
|
+
packages[pkg.name] = {
|
|
30
|
+
parameters: pkg.parameters,
|
|
31
|
+
version: pkg.version,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let ownPackages;
|
|
36
|
+
if (workspace.ownPackages) {
|
|
37
|
+
ownPackages = {};
|
|
38
|
+
for (const pkg of workspace.ownPackages) {
|
|
39
|
+
ownPackages[pkg.name] = {
|
|
40
|
+
parameters: pkg.parameters,
|
|
41
|
+
version: pkg.version,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
env,
|
|
47
|
+
hasExecutor: workspace.hasExecutor ?? undefined,
|
|
48
|
+
id: workspace.id,
|
|
49
|
+
isDeploy: workspace.isDeploy,
|
|
50
|
+
mirrorOf: workspace.mirrorOf?.name,
|
|
51
|
+
name: workspace.name,
|
|
52
|
+
...(ownPackages === undefined ? {} : { ownPackages }),
|
|
53
|
+
packages,
|
|
54
|
+
profile: workspace.profile === null ? undefined : workspace.profile,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GetWorkspaceEnvInput, GetWorkspaceEnvOutput, SetEnvVarInput, SetEnvVarOutput, UnsetEnvVarInput, UnsetEnvVarOutput } from '../../common.js';
|
|
2
|
+
import { CloudHttpConfig } from './utils.js';
|
|
3
|
+
export declare function setEnvVar(config: CloudHttpConfig, input: SetEnvVarInput): Promise<SetEnvVarOutput>;
|
|
4
|
+
export declare function unsetEnvVar(config: CloudHttpConfig, input: UnsetEnvVarInput): Promise<UnsetEnvVarOutput>;
|
|
5
|
+
export declare function getWorkspaceEnv(config: CloudHttpConfig, input: GetWorkspaceEnvInput): Promise<GetWorkspaceEnvOutput>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { resolveWorkspaceName } from '../../../lib/workspace-utils.js';
|
|
2
|
+
import { safeResponseJson } from './utils.js';
|
|
3
|
+
import { getWorkspace } from './workspaces.js';
|
|
4
|
+
export async function setEnvVar(config, input) {
|
|
5
|
+
const formData = new FormData();
|
|
6
|
+
formData.append('key', input.name);
|
|
7
|
+
formData.append('value', input.value);
|
|
8
|
+
formData.append('infrastructure', input.infrastructure);
|
|
9
|
+
const response = await fetch(`${config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/env`, {
|
|
10
|
+
body: formData,
|
|
11
|
+
headers: {
|
|
12
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
13
|
+
},
|
|
14
|
+
method: 'POST',
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
return {
|
|
18
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
19
|
+
success: false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
success: true,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function unsetEnvVar(config, input) {
|
|
27
|
+
const response = await fetch(`${config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/env/${encodeURIComponent(input.name)}`, {
|
|
28
|
+
headers: {
|
|
29
|
+
'Authorization': `Bearer ${config.accessToken}`,
|
|
30
|
+
},
|
|
31
|
+
method: 'DELETE',
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
return {
|
|
35
|
+
reason: JSON.stringify(await safeResponseJson(response)),
|
|
36
|
+
success: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
success: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export async function getWorkspaceEnv(config, input) {
|
|
44
|
+
// Apply org prefix if project has one and workspace doesn't
|
|
45
|
+
const workspaceName = resolveWorkspaceName(input.workspace, input.project);
|
|
46
|
+
const workspace$ = await getWorkspace(config, workspaceName);
|
|
47
|
+
if (!workspace$.found) {
|
|
48
|
+
return {
|
|
49
|
+
reason: `Workspace ${input.workspace} not found`,
|
|
50
|
+
success: false,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (workspace$.hasError) {
|
|
54
|
+
return {
|
|
55
|
+
reason: workspace$.error,
|
|
56
|
+
success: false,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
env: workspace$.workspace.env ?? {},
|
|
61
|
+
success: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CreateWorkspaceInput, CreateWorkspaceOutput, DeleteWorkspaceInput, DeleteWorkspaceOutput, GetWorkspaceOutput, ListWorkspacesInput, UpdateWorkspaceInput, UpdateWorkspaceOutput } from '../../common.js';
|
|
2
|
+
import { CloudHttpConfig } from './utils.js';
|
|
3
|
+
export declare function createWorkspace(config: CloudHttpConfig, input: CreateWorkspaceInput): Promise<CreateWorkspaceOutput>;
|
|
4
|
+
export declare function deleteWorkspace(config: CloudHttpConfig, input: DeleteWorkspaceInput): Promise<DeleteWorkspaceOutput>;
|
|
5
|
+
export declare function getWorkspace(config: CloudHttpConfig, name: string): Promise<GetWorkspaceOutput>;
|
|
6
|
+
export declare function listWorkspaces(config: CloudHttpConfig, input?: ListWorkspacesInput): Promise<string[]>;
|
|
7
|
+
export declare function updateWorkspace(config: CloudHttpConfig, input: UpdateWorkspaceInput): Promise<UpdateWorkspaceOutput>;
|