@joripspace/cli 0.5.0 → 0.5.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 +1 -1
- package/bin/joripspace.js +1623 -1610
- package/lib/checkpoint-commands.js +210 -210
- package/lib/deploy-files.js +245 -245
- package/lib/deployment-error.js +14 -14
- package/lib/github-commands.js +185 -0
- package/lib/help.js +138 -137
- package/lib/installer-args.js +28 -28
- package/lib/installer-target.js +134 -134
- package/lib/mcp-config.js +981 -981
- package/lib/project-env.js +198 -198
- package/lib/project-paths.js +257 -257
- package/lib/remote-commands.js +392 -392
- package/lib/start-command.js +123 -123
- package/lib/start.js +1407 -1407
- package/lib/template-commands.js +812 -812
- package/package.json +1 -1
- package/vendor/core/github-workflow.cjs +199 -186
- package/vendor/core/onboarding.cjs +2404 -2403
- package/vendor/core/template-publish-workflow.cjs +169 -169
- package/vendor/templates/index.js +104 -104
- package/vendor/templates/templates/basic-worker/files/worker.js +9 -9
- package/vendor/templates/templates/basic-worker/manifest.json +14 -14
- package/vendor/templates/templates/r2-file-api/files/worker.js +42 -42
- package/vendor/templates/templates/r2-file-api/manifest.json +7 -7
package/package.json
CHANGED
|
@@ -1,197 +1,210 @@
|
|
|
1
|
-
function buildGithubWorkflow({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
function buildGithubWorkflow({
|
|
2
|
+
projectId,
|
|
3
|
+
branch,
|
|
4
|
+
triggerType = 'branch',
|
|
5
|
+
triggerRef = branch,
|
|
6
|
+
connectionId = 'legacy',
|
|
7
|
+
buildCommand,
|
|
8
|
+
artifactPath,
|
|
9
|
+
entrypoint,
|
|
10
|
+
}) {
|
|
11
|
+
const commands = String(buildCommand)
|
|
12
|
+
.split('\n')
|
|
13
|
+
.map((line) => ` ${line}`)
|
|
14
|
+
.join('\n');
|
|
15
|
+
const deployScript = `${inlineDeployMain.toString()}\n\nawait inlineDeployMain();`
|
|
16
|
+
.split('\n')
|
|
17
|
+
.map((line) => ` ${line}`)
|
|
18
|
+
.join('\n');
|
|
19
|
+
const trigger =
|
|
20
|
+
triggerType === 'release'
|
|
21
|
+
? ` release:\n types:\n - published`
|
|
22
|
+
: ` push:\n branches:\n - ${JSON.stringify(String(triggerRef || branch))}\n workflow_dispatch:`;
|
|
10
23
|
return `# joripspace-workflow-version: 8
|
|
11
|
-
name: JoripSpace Deploy
|
|
12
|
-
|
|
13
|
-
on:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
runs-on: ubuntu-latest
|
|
30
|
-
steps:
|
|
31
|
-
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
24
|
+
name: JoripSpace Deploy ${JSON.stringify(`(${connectionId})`)}
|
|
25
|
+
|
|
26
|
+
on:
|
|
27
|
+
${trigger}
|
|
28
|
+
|
|
29
|
+
permissions:
|
|
30
|
+
contents: read
|
|
31
|
+
id-token: write
|
|
32
|
+
|
|
33
|
+
concurrency:
|
|
34
|
+
group: ${JSON.stringify(`joripspace-${String(projectId)}-${String(connectionId)}`)}
|
|
35
|
+
cancel-in-progress: true
|
|
36
|
+
|
|
37
|
+
jobs:
|
|
38
|
+
deploy:
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
32
42
|
- name: Build
|
|
33
43
|
run: |
|
|
34
44
|
set -Eeuo pipefail
|
|
35
45
|
trap 'code=$?; echo "::error title=JoripSpace build failed::Build failed at line $LINENO (exit $code)"; exit "$code"' ERR
|
|
36
|
-
${commands}
|
|
37
|
-
- name: Deploy to JoripSpace
|
|
38
|
-
shell: bash
|
|
39
|
-
env:
|
|
40
|
-
JORIPSPACE_PROJECT_ID: ${JSON.stringify(String(projectId))}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
${commands}
|
|
47
|
+
- name: Deploy to JoripSpace
|
|
48
|
+
shell: bash
|
|
49
|
+
env:
|
|
50
|
+
JORIPSPACE_PROJECT_ID: ${JSON.stringify(String(projectId))}
|
|
51
|
+
JORIPSPACE_CONNECTION_ID: ${JSON.stringify(String(connectionId))}
|
|
52
|
+
JORIPSPACE_ARTIFACT_PATH: ${JSON.stringify(String(artifactPath))}
|
|
53
|
+
JORIPSPACE_ENTRYPOINT: ${JSON.stringify(String(entrypoint))}
|
|
54
|
+
JORIPSPACE_API_URL: "https://api.joripspace.com"
|
|
55
|
+
run: |
|
|
56
|
+
set -euo pipefail
|
|
57
|
+
source_dir="$JORIPSPACE_ARTIFACT_PATH"
|
|
58
|
+
if [[ ! -d "$source_dir" ]]; then
|
|
48
59
|
echo "::error title=JoripSpace artifact preparation failed::JoripSpace artifact directory does not exist: $source_dir" >&2
|
|
49
|
-
exit 1
|
|
50
|
-
fi
|
|
51
|
-
stage_dir="$RUNNER_TEMP/joripspace-artifact-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT"
|
|
52
|
-
archive_path="$RUNNER_TEMP/joripspace-artifact-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.zip"
|
|
53
|
-
rm -rf "$stage_dir"
|
|
54
|
-
mkdir -p "$stage_dir"
|
|
55
|
-
cp -R "$source_dir"/. "$stage_dir"/
|
|
56
|
-
JORIPSPACE_STAGE_DIR="$stage_dir" node --input-type=module -e '
|
|
57
|
-
import { writeFile } from "node:fs/promises";
|
|
58
|
-
import { join } from "node:path";
|
|
59
|
-
const root = process.env.JORIPSPACE_STAGE_DIR;
|
|
60
|
-
const entrypoint = process.env.JORIPSPACE_ENTRYPOINT;
|
|
61
|
-
await writeFile(join(root, ".joripspace-deploy.json"), JSON.stringify({ entrypoint }) + "\\n");
|
|
62
|
-
'
|
|
63
|
-
(cd "$stage_dir" && find . -type f -exec zip -q "$archive_path" -- {} +)
|
|
64
|
-
JORIPSPACE_ARCHIVE_PATH="$archive_path" node --input-type=module <<'JORIPSPACE_SCRIPT'
|
|
65
|
-
${deployScript}
|
|
66
|
-
JORIPSPACE_SCRIPT
|
|
67
|
-
`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function projectGithubActionsTemplateFile(projectConfig = {}) {
|
|
71
|
-
return buildGithubWorkflow({
|
|
72
|
-
projectId: String(projectConfig.project_id || '__JORIPSPACE_PROJECT_ID__'),
|
|
73
|
-
branch: '__JORIPSPACE_BRANCH__',
|
|
74
|
-
buildCommand: '__JORIPSPACE_BUILD_COMMAND__',
|
|
75
|
-
artifactPath: '__JORIPSPACE_ARTIFACT_PATH__',
|
|
76
|
-
entrypoint: '__JORIPSPACE_ENTRYPOINT__',
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function inlineDeployMain() {
|
|
81
|
-
const { open } = await import('node:fs/promises');
|
|
82
|
-
const audience = 'https://api.joripspace.com/v1/external-builds/github';
|
|
83
|
-
const projectId = requiredEnv('JORIPSPACE_PROJECT_ID');
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
let
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
60
|
+
exit 1
|
|
61
|
+
fi
|
|
62
|
+
stage_dir="$RUNNER_TEMP/joripspace-artifact-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT"
|
|
63
|
+
archive_path="$RUNNER_TEMP/joripspace-artifact-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.zip"
|
|
64
|
+
rm -rf "$stage_dir"
|
|
65
|
+
mkdir -p "$stage_dir"
|
|
66
|
+
cp -R "$source_dir"/. "$stage_dir"/
|
|
67
|
+
JORIPSPACE_STAGE_DIR="$stage_dir" node --input-type=module -e '
|
|
68
|
+
import { writeFile } from "node:fs/promises";
|
|
69
|
+
import { join } from "node:path";
|
|
70
|
+
const root = process.env.JORIPSPACE_STAGE_DIR;
|
|
71
|
+
const entrypoint = process.env.JORIPSPACE_ENTRYPOINT;
|
|
72
|
+
await writeFile(join(root, ".joripspace-deploy.json"), JSON.stringify({ entrypoint }) + "\\n");
|
|
73
|
+
'
|
|
74
|
+
(cd "$stage_dir" && find . -type f -exec zip -q "$archive_path" -- {} +)
|
|
75
|
+
JORIPSPACE_ARCHIVE_PATH="$archive_path" node --input-type=module <<'JORIPSPACE_SCRIPT'
|
|
76
|
+
${deployScript}
|
|
77
|
+
JORIPSPACE_SCRIPT
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function projectGithubActionsTemplateFile(projectConfig = {}) {
|
|
82
|
+
return buildGithubWorkflow({
|
|
83
|
+
projectId: String(projectConfig.project_id || '__JORIPSPACE_PROJECT_ID__'),
|
|
84
|
+
branch: '__JORIPSPACE_BRANCH__',
|
|
85
|
+
buildCommand: '__JORIPSPACE_BUILD_COMMAND__',
|
|
86
|
+
artifactPath: '__JORIPSPACE_ARTIFACT_PATH__',
|
|
87
|
+
entrypoint: '__JORIPSPACE_ENTRYPOINT__',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function inlineDeployMain() {
|
|
92
|
+
const { open } = await import('node:fs/promises');
|
|
93
|
+
const audience = 'https://api.joripspace.com/v1/external-builds/github';
|
|
94
|
+
const projectId = requiredEnv('JORIPSPACE_PROJECT_ID');
|
|
95
|
+
const connectionId = String(process.env.JORIPSPACE_CONNECTION_ID || '').trim();
|
|
96
|
+
const archivePath = requiredEnv('JORIPSPACE_ARCHIVE_PATH');
|
|
97
|
+
const apiUrl = requiredEnv('JORIPSPACE_API_URL').replace(/\/+$/, '');
|
|
98
|
+
const oidcToken = await requestOidcToken();
|
|
99
|
+
const create = await api(`/v1/projects/${encodeURIComponent(projectId)}/checkpoint-uploads`, {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
token: oidcToken,
|
|
102
|
+
json: { source_type: 'deployment' },
|
|
103
|
+
});
|
|
104
|
+
const file = await open(archivePath, 'r');
|
|
105
|
+
try {
|
|
106
|
+
const chunkSize = Number(create.chunk_size || 8 * 1024 * 1024);
|
|
107
|
+
const buffer = Buffer.alloc(chunkSize);
|
|
108
|
+
let partNumber = 1;
|
|
109
|
+
let position = 0;
|
|
110
|
+
while (true) {
|
|
111
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, position);
|
|
112
|
+
if (bytesRead === 0) break;
|
|
113
|
+
const partPath = String(create.upload_part_url_template).replace('{part_number}', String(partNumber));
|
|
114
|
+
await api(partPath, {
|
|
115
|
+
method: 'PUT',
|
|
116
|
+
token: oidcToken,
|
|
117
|
+
body: buffer.subarray(0, bytesRead),
|
|
118
|
+
contentType: 'application/octet-stream',
|
|
119
|
+
});
|
|
120
|
+
position += bytesRead;
|
|
121
|
+
partNumber += 1;
|
|
122
|
+
}
|
|
123
|
+
if (position === 0) throw new Error('Build artifact ZIP is empty.');
|
|
124
|
+
} finally {
|
|
125
|
+
await file.close();
|
|
126
|
+
}
|
|
127
|
+
await api(create.complete_url, { method: 'POST', token: oidcToken, json: {} });
|
|
128
|
+
const deployPath = `/v1/projects/${encodeURIComponent(projectId)}/checkpoints/${encodeURIComponent(create.checkpoint_id)}/deploy`;
|
|
129
|
+
for (let attempt = 1; attempt <= 150; attempt += 1) {
|
|
130
|
+
const deployToken = await requestOidcToken();
|
|
131
|
+
const result = await api(deployPath, {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
token: deployToken,
|
|
134
|
+
json: {},
|
|
135
|
+
allowedStatuses: [404, 409],
|
|
136
|
+
});
|
|
137
|
+
if (!result.__retry) {
|
|
138
|
+
process.stdout.write(
|
|
139
|
+
`JoripSpace deployment succeeded: ${result.url || result.default_url || result.deployment_id || projectId}\n`
|
|
140
|
+
);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (
|
|
144
|
+
!['checkpoint_not_found', 'checkpoint_not_ready', 'external_build_deploy_busy'].includes(
|
|
145
|
+
result.error?.code
|
|
146
|
+
)
|
|
147
|
+
) {
|
|
148
|
+
throw apiError(result.__status, result);
|
|
149
|
+
}
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
151
|
+
}
|
|
152
|
+
throw new Error('JoripSpace artifact processing did not finish within 5 minutes.');
|
|
153
|
+
|
|
154
|
+
async function requestOidcToken() {
|
|
155
|
+
const requestUrl = requiredEnv('ACTIONS_ID_TOKEN_REQUEST_URL');
|
|
156
|
+
const requestToken = requiredEnv('ACTIONS_ID_TOKEN_REQUEST_TOKEN');
|
|
157
|
+
const separator = requestUrl.includes('?') ? '&' : '?';
|
|
158
|
+
const response = await fetch(`${requestUrl}${separator}audience=${encodeURIComponent(audience)}`, {
|
|
159
|
+
headers: { Authorization: `Bearer ${requestToken}` },
|
|
160
|
+
});
|
|
161
|
+
const payload = await response.json().catch(() => ({}));
|
|
162
|
+
if (!response.ok || typeof payload.value !== 'string') {
|
|
163
|
+
throw new Error(`GitHub OIDC token request failed (${response.status}).`);
|
|
164
|
+
}
|
|
165
|
+
return payload.value;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function api(path, options) {
|
|
169
|
+
const url = path.startsWith('http') ? path : `${apiUrl}${path}`;
|
|
170
|
+
const headers = new Headers({ Authorization: `Bearer ${options.token}`, Accept: 'application/json' });
|
|
171
|
+
if (connectionId) headers.set('X-JoripSpace-Connection-ID', connectionId);
|
|
172
|
+
let body = options.body;
|
|
173
|
+
if (options.json !== undefined) {
|
|
174
|
+
headers.set('Content-Type', 'application/json');
|
|
175
|
+
body = JSON.stringify(options.json);
|
|
176
|
+
} else if (options.contentType) headers.set('Content-Type', options.contentType);
|
|
177
|
+
const response = await fetch(url, { method: options.method, headers, body });
|
|
178
|
+
const text = await response.text();
|
|
179
|
+
const payload = text ? safeJson(text) : {};
|
|
180
|
+
if (response.ok) return payload;
|
|
181
|
+
if ((options.allowedStatuses || []).includes(response.status)) {
|
|
182
|
+
return { ...payload, __retry: true, __status: response.status };
|
|
183
|
+
}
|
|
184
|
+
throw apiError(response.status, payload);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function apiError(status, payload) {
|
|
188
|
+
const error = new Error(payload?.error?.message || `JoripSpace request failed (${status}).`);
|
|
176
189
|
error.code = payload?.error?.code || 'joripspace_request_failed';
|
|
177
190
|
const diagnostic = JSON.stringify({ http_status: status, code: error.code, message: error.message, details: payload?.error?.details || null })
|
|
178
191
|
.replace(/((?:authorization|[\w-]*(?:key|token|secret|password|credential)[\w-]*)["']?\s*[:=]\s*["']?)[^"'\s,}]+/gi, '$1[REDACTED]')
|
|
179
192
|
.replace(/Bearer\s+[^\s"']+/gi, 'Bearer [REDACTED]').slice(0, 16000);
|
|
180
193
|
console.error(`JORIPSPACE_DIAGNOSTIC ${diagnostic}`);
|
|
181
|
-
return error;
|
|
182
|
-
}
|
|
183
|
-
function safeJson(value) {
|
|
184
|
-
try {
|
|
185
|
-
return JSON.parse(value);
|
|
186
|
-
} catch {
|
|
187
|
-
return { error: { code: 'invalid_response', message: value.slice(0, 500) } };
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
function requiredEnv(name) {
|
|
191
|
-
const value = process.env[name];
|
|
192
|
-
if (!value) throw new Error(`${name} is required.`);
|
|
193
|
-
return value;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
module.exports = { buildGithubWorkflow, projectGithubActionsTemplateFile };
|
|
194
|
+
return error;
|
|
195
|
+
}
|
|
196
|
+
function safeJson(value) {
|
|
197
|
+
try {
|
|
198
|
+
return JSON.parse(value);
|
|
199
|
+
} catch {
|
|
200
|
+
return { error: { code: 'invalid_response', message: value.slice(0, 500) } };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function requiredEnv(name) {
|
|
204
|
+
const value = process.env[name];
|
|
205
|
+
if (!value) throw new Error(`${name} is required.`);
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = { buildGithubWorkflow, projectGithubActionsTemplateFile };
|