@joripspace/cli 0.5.4 → 0.5.7
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 +129 -118
- package/THIRD_PARTY_NOTICES.md +54 -2
- package/bin/joripspace.js +309 -71
- package/lib/checkpoint-client.js +40 -49
- package/lib/checkpoint-commands.js +52 -15
- package/lib/credential-store.js +148 -0
- package/lib/deploy-files.js +57 -3
- package/lib/deployment-error.js +14 -14
- package/lib/github-commands.js +79 -13
- package/lib/help.js +42 -15
- package/lib/locale.js +35 -0
- package/lib/mcp-config.js +7 -1
- package/lib/project-create-policy.js +116 -0
- package/lib/project-create.js +203 -0
- package/lib/project-env.js +10 -6
- package/lib/project-paths.js +23 -4
- package/lib/remote-commands.js +14 -3
- package/lib/start-command.js +10 -4
- package/lib/start.js +6 -6
- package/lib/template-commands.js +24 -20
- package/package.json +4 -2
- package/vendor/core/cli-onboarding.cjs +8 -6
- package/vendor/core/onboarding.cjs +9 -4
- 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/lib/installer-args.js +0 -28
- package/lib/installer-target.js +0 -134
package/lib/checkpoint-client.js
CHANGED
|
@@ -2,6 +2,7 @@ const crypto = require('node:crypto');
|
|
|
2
2
|
const fs = require('node:fs');
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const { unzipSync, zipSync } = require('fflate');
|
|
5
|
+
const ignore = require('ignore');
|
|
5
6
|
const {
|
|
6
7
|
assertNonOverlappingFilePlan,
|
|
7
8
|
backupAndRemoveProjectPaths,
|
|
@@ -139,7 +140,12 @@ async function restoreCheckpoint(options) {
|
|
|
139
140
|
'restore_safety'
|
|
140
141
|
);
|
|
141
142
|
const backupRoot = createExternalBackupRoot(options.workspaceDir, 'checkpoint-restore', options.dataDir);
|
|
142
|
-
backupAndRemoveProjectPaths(
|
|
143
|
+
backupAndRemoveProjectPaths(
|
|
144
|
+
options.workspaceDir,
|
|
145
|
+
[...conflictPaths, ...deletions],
|
|
146
|
+
backupRoot,
|
|
147
|
+
(relative) => hardExcluded(relative) || isLocalRestoreMarker(relative)
|
|
148
|
+
);
|
|
143
149
|
for (const [relative, bytes] of writable) {
|
|
144
150
|
const location = resolveProjectFileTarget(options.workspaceDir, relative, 'unsafe checkpoint path');
|
|
145
151
|
if (location.blockers.length) {
|
|
@@ -167,22 +173,29 @@ async function restoreCheckpoint(options) {
|
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
function projectFiles(root) {
|
|
170
|
-
const rules = ignoreRules(root);
|
|
171
176
|
const files = [];
|
|
172
|
-
function walk(directory) {
|
|
177
|
+
function walk(directory, inherited = []) {
|
|
178
|
+
const names = directory === root ? ['.gitignore', '.ignore', '.joripspaceignore'] : ['.gitignore'];
|
|
179
|
+
const rules = [...inherited, { directory, matcher: ignoreRules(directory, names) }];
|
|
173
180
|
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
174
181
|
const full = path.join(directory, entry.name);
|
|
175
182
|
let relative = toPosix(path.relative(root, full));
|
|
176
183
|
if (hardExcluded(relative)) continue;
|
|
177
|
-
|
|
178
|
-
|
|
184
|
+
let excluded = false;
|
|
185
|
+
for (const rule of rules) {
|
|
186
|
+
const candidate = toPosix(path.relative(rule.directory, full)) + (entry.isDirectory() ? '/' : '');
|
|
187
|
+
const result = rule.matcher.test(candidate);
|
|
188
|
+
if (result.ignored || result.unignored) excluded = result.ignored;
|
|
189
|
+
}
|
|
190
|
+
// Git cannot reinclude a child of an excluded directory without reopening the parent.
|
|
191
|
+
if (excluded) continue;
|
|
179
192
|
relative = safeProjectRelativePath(relative, 'unsafe checkpoint path');
|
|
180
193
|
const stat = fs.lstatSync(full);
|
|
181
194
|
if (stat.isSymbolicLink())
|
|
182
195
|
throw new Error(`symbolic links cannot be included in checkpoints: ${relative}`);
|
|
183
196
|
if (entry.isDirectory()) {
|
|
184
|
-
|
|
185
|
-
} else if (entry.isFile()
|
|
197
|
+
walk(full, rules);
|
|
198
|
+
} else if (entry.isFile()) {
|
|
186
199
|
files.push([relative, new Uint8Array(fs.readFileSync(full))]);
|
|
187
200
|
}
|
|
188
201
|
}
|
|
@@ -199,9 +212,9 @@ function hardExcluded(relative) {
|
|
|
199
212
|
HARD_FILES.has(base) ||
|
|
200
213
|
parts.some((part) => HARD_DIRS.has(part)) ||
|
|
201
214
|
parts.some((part) => AGENT_CONTROL_DIRS.has(part)) ||
|
|
202
|
-
AGENT_CONTROL_FILES.has(
|
|
215
|
+
parts.some((part) => AGENT_CONTROL_FILES.has(part)) ||
|
|
203
216
|
parts.includes('.joripspace') ||
|
|
204
|
-
|
|
217
|
+
parts.includes('.env.joripspace') ||
|
|
205
218
|
/\.(log|tmp|temp)$/i.test(base)
|
|
206
219
|
);
|
|
207
220
|
}
|
|
@@ -283,52 +296,30 @@ function upsertDeployManifest(files, workspaceDir, entrypoint) {
|
|
|
283
296
|
else files.push([TRANSIENT_DEPLOY_MANIFEST, bytes]);
|
|
284
297
|
}
|
|
285
298
|
|
|
286
|
-
function ignoreRules(
|
|
287
|
-
const
|
|
288
|
-
for (const name of
|
|
299
|
+
function ignoreRules(directory, names) {
|
|
300
|
+
const matcher = ignore({ ignorecase: false });
|
|
301
|
+
for (const name of names) {
|
|
302
|
+
const target = path.join(directory, name);
|
|
303
|
+
let stat;
|
|
289
304
|
try {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
function globRegex(pattern) {
|
|
300
|
-
const clean = pattern.replace(/^!/, '').replace(/^\//, '').replace(/\/$/, '/**');
|
|
301
|
-
const escaped = clean
|
|
302
|
-
.replace(/[.+^$(){}|[\]\\]/g, '\\$&')
|
|
303
|
-
.replace(/\*\*/g, '§§')
|
|
304
|
-
.replace(/\*/g, '[^/]*')
|
|
305
|
-
.replace(/§§/g, '.*')
|
|
306
|
-
.replace(/\?/g, '.');
|
|
307
|
-
return new RegExp(`^(?:${escaped})(?:/.*)?$`);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function ignored(relative, rules) {
|
|
311
|
-
if (hardExcluded(relative)) return true;
|
|
312
|
-
const normalized = toPosix(relative);
|
|
313
|
-
let result = false;
|
|
314
|
-
for (const rule of rules) {
|
|
315
|
-
if (globRegex(rule).test(normalized)) result = !rule.startsWith('!');
|
|
305
|
+
stat = fs.lstatSync(target);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
if (error?.code === 'ENOENT') continue;
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
311
|
+
throw new Error(`ignore rules must be a regular file: ${name}`);
|
|
312
|
+
matcher.add(fs.readFileSync(target, 'utf8'));
|
|
316
313
|
}
|
|
317
|
-
return
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function negatedRuleCanInclude(directory, rules) {
|
|
321
|
-
const prefix = `${toPosix(directory).replace(/\/$/, '')}/`;
|
|
322
|
-
return rules.some((rule) => {
|
|
323
|
-
if (!rule.startsWith('!')) return false;
|
|
324
|
-
const target = rule.slice(1).replace(/^\//, '').replace(/\*.*$/, '');
|
|
325
|
-
return target.startsWith(prefix) || prefix.startsWith(`${target.replace(/\/$/, '')}/`);
|
|
326
|
-
});
|
|
314
|
+
return matcher;
|
|
327
315
|
}
|
|
328
316
|
|
|
329
317
|
function safeRestorePath(name) {
|
|
330
318
|
const normalized = safeProjectRelativePath(name, 'unsafe checkpoint path');
|
|
331
|
-
if (
|
|
319
|
+
if (
|
|
320
|
+
(hardExcluded(normalized) && !isCheckpointMetadataFile(normalized)) ||
|
|
321
|
+
[...LOCAL_RESTORE_MARKERS].some((marker) => portablePathKey(normalized).startsWith(`${marker}/`))
|
|
322
|
+
) {
|
|
332
323
|
throw new Error(`protected file cannot be restored: ${normalized}`);
|
|
333
324
|
}
|
|
334
325
|
return normalized;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { message } = require('./locale');
|
|
1
2
|
const fs = require('node:fs');
|
|
2
3
|
const os = require('node:os');
|
|
3
4
|
const path = require('node:path');
|
|
@@ -27,10 +28,11 @@ function createCheckpointCommands(deps) {
|
|
|
27
28
|
deps.output(flags, body, (value) => {
|
|
28
29
|
for (const item of value.checkpoints || []) {
|
|
29
30
|
console.log(
|
|
30
|
-
`#${item.sequence}\t${item.checkpoint_id}\t${item.label || '(이름 없음)'}\t${item.status}\t${item.deployable ? '배포 가능' : '백업 전용'}`
|
|
31
|
+
`#${item.sequence}\t${item.checkpoint_id}\t${item.label || message('(unnamed)', '(이름 없음)')}\t${item.status}\t${item.deployable ? message('deployable', '배포 가능') : message('backup only', '백업 전용')}`
|
|
31
32
|
);
|
|
32
33
|
}
|
|
33
|
-
if (value.next_cursor)
|
|
34
|
+
if (value.next_cursor)
|
|
35
|
+
console.log(message(`Next cursor: ${value.next_cursor}`, `다음 cursor: ${value.next_cursor}`));
|
|
34
36
|
});
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
@@ -39,10 +41,12 @@ function createCheckpointCommands(deps) {
|
|
|
39
41
|
if (subcommand === 'get') {
|
|
40
42
|
const body = await deps.apiRequest(flags, itemPath, { method: 'GET', ...deps.projectAuth(flags) });
|
|
41
43
|
deps.output(flags, body, (value) => {
|
|
42
|
-
console.log(`#${value.sequence} ${value.label || '(이름 없음)'}`);
|
|
43
|
-
console.log(`상태: ${value.status}`);
|
|
44
|
-
console.log(
|
|
45
|
-
|
|
44
|
+
console.log(`#${value.sequence} ${value.label || message('(unnamed)', '(이름 없음)')}`);
|
|
45
|
+
console.log(message(`Status: ${value.status}`, `상태: ${value.status}`));
|
|
46
|
+
console.log(
|
|
47
|
+
`${message('Deployment', '배포')}: ${value.deployable ? message('available', '가능') : message('backup only', '백업 전용')}`
|
|
48
|
+
);
|
|
49
|
+
console.log(message(`Files: ${value.file_count || 0}`, `파일: ${value.file_count || 0}개`));
|
|
46
50
|
});
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
@@ -58,13 +62,17 @@ function createCheckpointCommands(deps) {
|
|
|
58
62
|
...deps.projectAuth(flags),
|
|
59
63
|
body: bodyInput,
|
|
60
64
|
});
|
|
61
|
-
deps.output(flags, body, (value) =>
|
|
65
|
+
deps.output(flags, body, (value) =>
|
|
66
|
+
console.log(
|
|
67
|
+
message(`Checkpoint #${value.sequence} updated.`, `저장본 #${value.sequence} 정보를 변경했습니다.`)
|
|
68
|
+
)
|
|
69
|
+
);
|
|
62
70
|
return;
|
|
63
71
|
}
|
|
64
72
|
if (subcommand === 'delete') {
|
|
65
73
|
if (!deps.booleanFlag(flags, 'yes')) throw new Error('checkpoint delete requires --yes');
|
|
66
74
|
const body = await deps.apiRequest(flags, itemPath, { method: 'DELETE', ...deps.projectAuth(flags) });
|
|
67
|
-
deps.output(flags, body, () => console.log('저장본을 삭제했습니다.'));
|
|
75
|
+
deps.output(flags, body, () => console.log(message('Checkpoint deleted.', '저장본을 삭제했습니다.')));
|
|
68
76
|
return;
|
|
69
77
|
}
|
|
70
78
|
if (subcommand === 'deploy') {
|
|
@@ -74,7 +82,12 @@ function createCheckpointCommands(deps) {
|
|
|
74
82
|
body: {},
|
|
75
83
|
});
|
|
76
84
|
deps.output(flags, body, (value) => {
|
|
77
|
-
console.log(
|
|
85
|
+
console.log(
|
|
86
|
+
message(
|
|
87
|
+
`Checkpoint deployed: ${value.url || project}`,
|
|
88
|
+
`저장본을 배포했습니다: ${value.url || project}`
|
|
89
|
+
)
|
|
90
|
+
);
|
|
78
91
|
console.log(`Deployment: ${value.deployment_id}`);
|
|
79
92
|
printCheckpointWarnings(value.warnings);
|
|
80
93
|
});
|
|
@@ -97,21 +110,43 @@ function createCheckpointCommands(deps) {
|
|
|
97
110
|
});
|
|
98
111
|
deps.output(flags, value, (result) => {
|
|
99
112
|
if (result.status === 'saved') {
|
|
100
|
-
console.log(
|
|
113
|
+
console.log(
|
|
114
|
+
message(
|
|
115
|
+
`Checkpoint #${result.checkpoint.sequence} created. Files: ${result.file_count}`,
|
|
116
|
+
`저장본 #${result.checkpoint.sequence}을 만들었습니다. 파일 ${result.file_count}개`
|
|
117
|
+
)
|
|
118
|
+
);
|
|
101
119
|
printCheckpointWarnings(result.checkpoint.warnings);
|
|
102
120
|
if (result.deployment) {
|
|
103
121
|
console.log(
|
|
104
|
-
|
|
122
|
+
message(
|
|
123
|
+
`Deployed the same checkpoint: ${result.deployment.url || result.checkpoint.checkpoint_id}`,
|
|
124
|
+
`같은 저장본으로 배포했습니다: ${result.deployment.url || result.checkpoint.checkpoint_id}`
|
|
125
|
+
)
|
|
105
126
|
);
|
|
106
127
|
}
|
|
107
128
|
return;
|
|
108
129
|
}
|
|
109
130
|
console.log(
|
|
110
|
-
|
|
131
|
+
message(
|
|
132
|
+
`Additions: ${result.additions.length}, overwrites: ${result.overwrites.length}, deletions: ${result.deletions.length}`,
|
|
133
|
+
`추가 ${result.additions.length}개, 덮어쓰기 ${result.overwrites.length}개, 삭제 ${result.deletions.length}개`
|
|
134
|
+
)
|
|
111
135
|
);
|
|
112
136
|
if (result.status === 'preview') {
|
|
113
|
-
console.log(
|
|
114
|
-
|
|
137
|
+
console.log(
|
|
138
|
+
message(
|
|
139
|
+
'Preview only. After approval, run again with --apply.',
|
|
140
|
+
'미리보기만 했습니다. 승인 후 --apply를 붙여 다시 실행하세요.'
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
} else
|
|
144
|
+
console.log(
|
|
145
|
+
message(
|
|
146
|
+
`Local files restored. Backup: ${result.backup_root}`,
|
|
147
|
+
`로컬 파일을 복원했습니다. 백업: ${result.backup_root}`
|
|
148
|
+
)
|
|
149
|
+
);
|
|
115
150
|
});
|
|
116
151
|
}
|
|
117
152
|
|
|
@@ -119,6 +154,7 @@ function createCheckpointCommands(deps) {
|
|
|
119
154
|
const staged = stageArchive(flags);
|
|
120
155
|
const connection = deps.resolveConnection(flags);
|
|
121
156
|
try {
|
|
157
|
+
deps.assertNoUnresolvedPackageImportsInDirectory(staged.root);
|
|
122
158
|
const result = await runCheckpointOperation('save', {
|
|
123
159
|
workspaceDir: staged.root,
|
|
124
160
|
projectId: project,
|
|
@@ -204,7 +240,8 @@ function createCheckpointCommands(deps) {
|
|
|
204
240
|
}
|
|
205
241
|
|
|
206
242
|
function printCheckpointWarnings(warnings) {
|
|
207
|
-
for (const warning of warnings || [])
|
|
243
|
+
for (const warning of warnings || [])
|
|
244
|
+
console.warn(message(`Warning: ${warning.message}`, `경고: ${warning.message}`));
|
|
208
245
|
}
|
|
209
246
|
|
|
210
247
|
module.exports = { createCheckpointCommands };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const { message } = require('./locale');
|
|
2
|
+
const { createHash } = require('node:crypto');
|
|
3
|
+
|
|
4
|
+
const SERVICE = 'com.joripspace.cli.v1';
|
|
5
|
+
|
|
6
|
+
function storeError(code = 'credential_store_unavailable') {
|
|
7
|
+
const error = new Error(
|
|
8
|
+
code === 'credential_store_invalid'
|
|
9
|
+
? message(
|
|
10
|
+
'The JoripSpace connection in the OS credential store is invalid. Reconnect with login --code.',
|
|
11
|
+
'OS 보안 저장소의 JoripSpace 연결 정보가 올바르지 않습니다. login --code로 다시 연결하세요.'
|
|
12
|
+
)
|
|
13
|
+
: message(
|
|
14
|
+
'The OS credential store is unavailable. Check Windows Credential Manager, macOS Keychain, or Linux Secret Service. No plaintext fallback is used. For automation, provide JORIPSPACE_API_TOKEN and its API URL through environment variables.',
|
|
15
|
+
'OS 보안 저장소를 사용할 수 없습니다. Windows 자격 증명 관리자, macOS Keychain 또는 Linux Secret Service를 확인하세요. 평문 파일에는 저장하지 않습니다. 자동화에서는 JORIPSPACE_API_TOKEN과 해당 API URL을 환경 변수로 제공할 수 있습니다.'
|
|
16
|
+
)
|
|
17
|
+
);
|
|
18
|
+
error.code = code;
|
|
19
|
+
return error;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeCredentialApiUrl(value) {
|
|
23
|
+
let url;
|
|
24
|
+
try {
|
|
25
|
+
url = new URL(value);
|
|
26
|
+
} catch {
|
|
27
|
+
throw storeError('credential_store_invalid');
|
|
28
|
+
}
|
|
29
|
+
const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
30
|
+
if (
|
|
31
|
+
(url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback)) ||
|
|
32
|
+
url.username ||
|
|
33
|
+
url.password ||
|
|
34
|
+
url.search ||
|
|
35
|
+
url.hash
|
|
36
|
+
) {
|
|
37
|
+
throw storeError('credential_store_invalid');
|
|
38
|
+
}
|
|
39
|
+
return url.href.replace(/\/+$/, '');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function digest(value) {
|
|
43
|
+
return createHash('sha256').update(value).digest('hex');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Injection is confined to this module's constructor for unit tests. The CLI always
|
|
47
|
+
// uses the native binding; there is no configurable plaintext backend or shell helper.
|
|
48
|
+
function createCredentialStore(loadBinding = () => require('@napi-rs/keyring'), platform = process.platform) {
|
|
49
|
+
function entry(apiBaseUrl, accountId) {
|
|
50
|
+
try {
|
|
51
|
+
if (!['win32', 'darwin', 'linux'].includes(platform)) throw storeError();
|
|
52
|
+
const { Entry } = loadBinding();
|
|
53
|
+
const key = `${digest(apiBaseUrl)}:${accountId ? digest(accountId) : 'default'}`;
|
|
54
|
+
// The library otherwise falls back to a nonpersistent kernel keyring on Linux.
|
|
55
|
+
return new Entry(SERVICE, key, { linux: { store: 'secret-service' } });
|
|
56
|
+
} catch {
|
|
57
|
+
throw storeError();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function read(entry) {
|
|
62
|
+
let value;
|
|
63
|
+
try {
|
|
64
|
+
value = entry.getPassword();
|
|
65
|
+
} catch {
|
|
66
|
+
throw storeError();
|
|
67
|
+
}
|
|
68
|
+
if (value === null || value === undefined) return null;
|
|
69
|
+
try {
|
|
70
|
+
const record = JSON.parse(value);
|
|
71
|
+
if (!record || record.version !== 1 || typeof record.account_id !== 'string' || !record.account_id) {
|
|
72
|
+
throw storeError();
|
|
73
|
+
}
|
|
74
|
+
return record;
|
|
75
|
+
} catch {
|
|
76
|
+
throw storeError('credential_store_invalid');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function load(apiUrl, requestedAccountId = '') {
|
|
81
|
+
const apiBaseUrl = normalizeCredentialApiUrl(apiUrl);
|
|
82
|
+
const accountId = requestedAccountId || read(entry(apiBaseUrl))?.account_id;
|
|
83
|
+
if (!accountId) return null;
|
|
84
|
+
const record = read(entry(apiBaseUrl, accountId));
|
|
85
|
+
if (!record) return null;
|
|
86
|
+
if (
|
|
87
|
+
record.api_base_url !== apiBaseUrl ||
|
|
88
|
+
record.account_id !== accountId ||
|
|
89
|
+
typeof record.api_token !== 'string' ||
|
|
90
|
+
!record.api_token.trim() ||
|
|
91
|
+
/[\r\n]/.test(record.api_token)
|
|
92
|
+
) {
|
|
93
|
+
throw storeError('credential_store_invalid');
|
|
94
|
+
}
|
|
95
|
+
return { apiBaseUrl, apiToken: record.api_token, accountId, source: 'os-credential-store' };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function save({ apiBaseUrl: apiUrl, apiToken, accountId }) {
|
|
99
|
+
const apiBaseUrl = normalizeCredentialApiUrl(apiUrl);
|
|
100
|
+
if (
|
|
101
|
+
typeof accountId !== 'string' ||
|
|
102
|
+
!accountId ||
|
|
103
|
+
typeof apiToken !== 'string' ||
|
|
104
|
+
!apiToken.trim() ||
|
|
105
|
+
/[\r\n]/.test(apiToken)
|
|
106
|
+
) {
|
|
107
|
+
throw storeError('credential_store_invalid');
|
|
108
|
+
}
|
|
109
|
+
const account = entry(apiBaseUrl, accountId);
|
|
110
|
+
const record = { version: 1, api_base_url: apiBaseUrl, account_id: accountId, api_token: apiToken };
|
|
111
|
+
try {
|
|
112
|
+
account.setPassword(JSON.stringify(record));
|
|
113
|
+
if (account.getPassword() !== JSON.stringify(record)) throw storeError();
|
|
114
|
+
const selected = entry(apiBaseUrl);
|
|
115
|
+
const pointer = JSON.stringify({ version: 1, account_id: accountId });
|
|
116
|
+
selected.setPassword(pointer);
|
|
117
|
+
if (selected.getPassword() !== pointer) throw storeError();
|
|
118
|
+
} catch {
|
|
119
|
+
// Native errors can contain secret values. Never propagate them to CLI output.
|
|
120
|
+
throw storeError();
|
|
121
|
+
}
|
|
122
|
+
return { apiBaseUrl, apiToken, accountId, source: 'os-credential-store' };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function remove(apiUrl, requestedAccountId = '') {
|
|
126
|
+
const apiBaseUrl = normalizeCredentialApiUrl(apiUrl);
|
|
127
|
+
const selected = entry(apiBaseUrl);
|
|
128
|
+
const selectedAccountId = read(selected)?.account_id;
|
|
129
|
+
const accountId = requestedAccountId || selectedAccountId;
|
|
130
|
+
if (!accountId) return false;
|
|
131
|
+
const account = entry(apiBaseUrl, accountId);
|
|
132
|
+
try {
|
|
133
|
+
account.deleteCredential();
|
|
134
|
+
if (account.getPassword() !== null) throw storeError();
|
|
135
|
+
if (selectedAccountId === accountId) {
|
|
136
|
+
selected.deleteCredential();
|
|
137
|
+
if (selected.getPassword() !== null) throw storeError();
|
|
138
|
+
}
|
|
139
|
+
} catch {
|
|
140
|
+
throw storeError();
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return { load, save, remove };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = { createCredentialStore, normalizeCredentialApiUrl };
|
package/lib/deploy-files.js
CHANGED
|
@@ -115,9 +115,57 @@ function buildInlineDeployPayload(entrypoint, sources) {
|
|
|
115
115
|
}
|
|
116
116
|
files[fileName] = text;
|
|
117
117
|
}
|
|
118
|
+
assertNoUnresolvedPackageImports(files);
|
|
118
119
|
return { entrypoint, files };
|
|
119
120
|
}
|
|
120
121
|
|
|
122
|
+
function assertNoUnresolvedPackageImports(files) {
|
|
123
|
+
const unresolved = findUnresolvedPackageImports(files);
|
|
124
|
+
if (!unresolved.length) return;
|
|
125
|
+
const error = new Error(
|
|
126
|
+
`package imports are not bundled: ${unresolved.join(', ')}. Run the project build and deploy the generated Worker entrypoint (for example dist/worker.js).`
|
|
127
|
+
);
|
|
128
|
+
error.code = 'unbundled_dependency';
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function assertNoUnresolvedPackageImportsInDirectory(root) {
|
|
133
|
+
const files = {};
|
|
134
|
+
for (const file of walkFiles(root)) {
|
|
135
|
+
if (!/\.(?:[cm]?[jt]sx?)$/i.test(file.path)) continue;
|
|
136
|
+
const relative = safeProjectRelativePath(toPosix(path.relative(root, file.path)));
|
|
137
|
+
files[relative] = fs.readFileSync(file.path, 'utf8');
|
|
138
|
+
}
|
|
139
|
+
assertNoUnresolvedPackageImports(files);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function findUnresolvedPackageImports(files) {
|
|
143
|
+
const fileNames = new Set(Object.keys(files).map((name) => name.replace(/\\/g, '/')));
|
|
144
|
+
const unresolved = new Set();
|
|
145
|
+
const patterns = [
|
|
146
|
+
/^\s*import\s+(?!type\b)(?:[^'"\n;]+?\s+from\s+)?["']([^"']+)["']/gm,
|
|
147
|
+
/^\s*export\s+(?:\*|\{[^}\n]*\})\s+from\s+["']([^"']+)["']/gm,
|
|
148
|
+
];
|
|
149
|
+
for (const [fileName, source] of Object.entries(files)) {
|
|
150
|
+
if (!/\.(?:[cm]?[jt]sx?)$/i.test(fileName)) continue;
|
|
151
|
+
for (const pattern of patterns) {
|
|
152
|
+
pattern.lastIndex = 0;
|
|
153
|
+
for (const match of source.matchAll(pattern)) {
|
|
154
|
+
const specifier = match[1];
|
|
155
|
+
if (
|
|
156
|
+
specifier &&
|
|
157
|
+
!specifier.startsWith('.') &&
|
|
158
|
+
!specifier.startsWith('/') &&
|
|
159
|
+
!/^[a-z][a-z0-9+.-]*:/i.test(specifier) &&
|
|
160
|
+
!fileNames.has(specifier)
|
|
161
|
+
)
|
|
162
|
+
unresolved.add(specifier);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return [...unresolved].sort();
|
|
167
|
+
}
|
|
168
|
+
|
|
121
169
|
function walkFiles(root, base = path.resolve(root)) {
|
|
122
170
|
const files = [];
|
|
123
171
|
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
@@ -182,7 +230,13 @@ function isProtectedSourcePath(value) {
|
|
|
182
230
|
const resolved = path.resolve(value);
|
|
183
231
|
const baseName = path.basename(resolved);
|
|
184
232
|
const parts = resolved.replace(/\\/g, '/').toLowerCase().split('/');
|
|
185
|
-
return
|
|
233
|
+
return (
|
|
234
|
+
isProtectedProjectPath(baseName) ||
|
|
235
|
+
parts.some(
|
|
236
|
+
(part) =>
|
|
237
|
+
PROTECTED_SOURCE_DIRS.has(part) || part === '.env.joripspace' || PROTECTED_FILE_NAMES.has(part)
|
|
238
|
+
)
|
|
239
|
+
);
|
|
186
240
|
}
|
|
187
241
|
|
|
188
242
|
function isContainedPath(root, target) {
|
|
@@ -202,8 +256,7 @@ function isProtectedProjectPath(value) {
|
|
|
202
256
|
const baseName = parts.at(-1) || '';
|
|
203
257
|
return (
|
|
204
258
|
parts.some((part) => IGNORED_DIRS.has(part)) ||
|
|
205
|
-
|
|
206
|
-
PROTECTED_FILE_NAMES.has(baseName) ||
|
|
259
|
+
parts.some((part) => part === '.env.joripspace' || PROTECTED_FILE_NAMES.has(part)) ||
|
|
207
260
|
baseName.endsWith('.log')
|
|
208
261
|
);
|
|
209
262
|
}
|
|
@@ -236,6 +289,7 @@ function toPosix(value) {
|
|
|
236
289
|
}
|
|
237
290
|
|
|
238
291
|
module.exports = {
|
|
292
|
+
assertNoUnresolvedPackageImportsInDirectory,
|
|
239
293
|
assertDeployableProjectPath,
|
|
240
294
|
assertDeployableSourceFilePath,
|
|
241
295
|
buildDeployPayload,
|
package/lib/deployment-error.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function formatDeploymentFailure(message, details) {
|
|
4
|
-
if (!details || typeof details !== 'object' || !details.deployment_id) return message;
|
|
5
|
-
const lines = [message, `Deployment: ${details.deployment_id}`];
|
|
6
|
-
if (details.error_stage) lines.push(`Stage: ${details.error_stage}`);
|
|
7
|
-
if (details.error_code) lines.push(`Error code: ${details.error_code}`);
|
|
8
|
-
if (details.error_details && details.error_details !== message) {
|
|
9
|
-
lines.push(`Details: ${details.error_details}`);
|
|
10
|
-
}
|
|
11
|
-
return lines.join('\n');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = { formatDeploymentFailure };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function formatDeploymentFailure(message, details) {
|
|
4
|
+
if (!details || typeof details !== 'object' || !details.deployment_id) return message;
|
|
5
|
+
const lines = [message, `Deployment: ${details.deployment_id}`];
|
|
6
|
+
if (details.error_stage) lines.push(`Stage: ${details.error_stage}`);
|
|
7
|
+
if (details.error_code) lines.push(`Error code: ${details.error_code}`);
|
|
8
|
+
if (details.error_details && details.error_details !== message) {
|
|
9
|
+
lines.push(`Details: ${details.error_details}`);
|
|
10
|
+
}
|
|
11
|
+
return lines.join('\n');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = { formatDeploymentFailure };
|