@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/bin/joripspace.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
const { message } = require('../lib/locale');
|
|
2
3
|
|
|
3
4
|
const fs = require('node:fs');
|
|
4
5
|
const os = require('node:os');
|
|
@@ -16,9 +17,11 @@ const { createTemplateCommands } = require('../lib/template-commands');
|
|
|
16
17
|
const { createCheckpointCommands } = require('../lib/checkpoint-commands');
|
|
17
18
|
const { createRealtimeV2Commands } = require('../lib/realtime-v2-commands');
|
|
18
19
|
const { createGithubCommands } = require('../lib/github-commands');
|
|
20
|
+
const { createProjectCommand } = require('../lib/project-create');
|
|
19
21
|
const {
|
|
20
22
|
assertDeployableProjectPath,
|
|
21
23
|
assertDeployableSourceFilePath,
|
|
24
|
+
assertNoUnresolvedPackageImportsInDirectory,
|
|
22
25
|
buildDeployPayload,
|
|
23
26
|
isProtectedProjectPath,
|
|
24
27
|
resolveDeploySourceDirectory,
|
|
@@ -31,6 +34,8 @@ const {
|
|
|
31
34
|
safeProjectRelativePath,
|
|
32
35
|
} = require('../lib/project-paths');
|
|
33
36
|
const { ensureProjectEnvIgnored, readProjectEnv, updateDotEnvFile } = require('../lib/project-env');
|
|
37
|
+
const { createCredentialStore, normalizeCredentialApiUrl } = require('../lib/credential-store');
|
|
38
|
+
const credentialStore = createCredentialStore();
|
|
34
39
|
const { createStartProjectCommand } = require('../lib/start-command');
|
|
35
40
|
const { legacyCredentialSessionConnection, readProjectMarker } = require('../lib/start');
|
|
36
41
|
const { buildTemplateDeployRequest, listTemplates } = loadTemplatesPackage();
|
|
@@ -66,6 +71,7 @@ const checkpointCommands = createCheckpointCommands({
|
|
|
66
71
|
arrayFlag,
|
|
67
72
|
assertDeployableProjectPath,
|
|
68
73
|
assertDeployableSourceFilePath,
|
|
74
|
+
assertNoUnresolvedPackageImportsInDirectory,
|
|
69
75
|
booleanFlag,
|
|
70
76
|
output,
|
|
71
77
|
positiveIntegerFlag,
|
|
@@ -101,6 +107,13 @@ const githubCommand = createGithubCommands({
|
|
|
101
107
|
});
|
|
102
108
|
|
|
103
109
|
const DEFAULT_API_URL = 'https://api.joripspace.com';
|
|
110
|
+
const createProject = createProjectCommand({
|
|
111
|
+
apiRequest,
|
|
112
|
+
output,
|
|
113
|
+
requireApiToken,
|
|
114
|
+
resolveConnection,
|
|
115
|
+
stringFlag,
|
|
116
|
+
});
|
|
104
117
|
const GENERAL_REQUEST_TIMEOUT_MS = 25_000;
|
|
105
118
|
const SESSION_COOKIE_PREFIX = 'joripspace_session=';
|
|
106
119
|
function loadTemplatesPackage() {
|
|
@@ -153,6 +166,9 @@ async function main() {
|
|
|
153
166
|
case 'login':
|
|
154
167
|
await login(flags);
|
|
155
168
|
return;
|
|
169
|
+
case 'logout':
|
|
170
|
+
logout(flags);
|
|
171
|
+
return;
|
|
156
172
|
case 'me':
|
|
157
173
|
await getMe(flags);
|
|
158
174
|
return;
|
|
@@ -160,13 +176,13 @@ async function main() {
|
|
|
160
176
|
await listMyProjects(flags);
|
|
161
177
|
return;
|
|
162
178
|
case 'billing-projects':
|
|
163
|
-
webOnlyCommand('결제 프로젝트');
|
|
179
|
+
webOnlyCommand(message('Billing projects', '결제 프로젝트'));
|
|
164
180
|
return;
|
|
165
181
|
case 'billing-usage':
|
|
166
|
-
webOnlyCommand('결제 사용량');
|
|
182
|
+
webOnlyCommand(message('Billing usage', '결제 사용량'));
|
|
167
183
|
return;
|
|
168
184
|
case 'invoices':
|
|
169
|
-
webOnlyCommand('청구서');
|
|
185
|
+
webOnlyCommand(message('Invoices', '청구서'));
|
|
170
186
|
return;
|
|
171
187
|
case 'link':
|
|
172
188
|
await linkProject(flags);
|
|
@@ -175,7 +191,7 @@ async function main() {
|
|
|
175
191
|
await startProjectCommand(rest, flags);
|
|
176
192
|
return;
|
|
177
193
|
case 'create':
|
|
178
|
-
|
|
194
|
+
await createProject(flags);
|
|
179
195
|
return;
|
|
180
196
|
case 'get':
|
|
181
197
|
await getProject(flags);
|
|
@@ -240,7 +256,10 @@ async function main() {
|
|
|
240
256
|
await checkpointCommands.command(rest, flags);
|
|
241
257
|
return;
|
|
242
258
|
case 'realtime-v2':
|
|
243
|
-
await createRealtimeV2Commands({apiRequest,output,projectAuth,requireProjectId,stringFlag})(
|
|
259
|
+
await createRealtimeV2Commands({ apiRequest, output, projectAuth, requireProjectId, stringFlag })(
|
|
260
|
+
rest,
|
|
261
|
+
flags
|
|
262
|
+
);
|
|
244
263
|
return;
|
|
245
264
|
case 'github':
|
|
246
265
|
await githubCommand(rest, flags);
|
|
@@ -253,7 +272,7 @@ async function main() {
|
|
|
253
272
|
await listRuntimeEvents(flags);
|
|
254
273
|
return;
|
|
255
274
|
case 'usage':
|
|
256
|
-
webOnlyCommand('일일 사용량 상세');
|
|
275
|
+
webOnlyCommand(message('Daily usage details', '일일 사용량 상세'));
|
|
257
276
|
return;
|
|
258
277
|
case 'usage-summary':
|
|
259
278
|
await getUsageSummary(flags);
|
|
@@ -262,7 +281,7 @@ async function main() {
|
|
|
262
281
|
await getUsageBreakdown(flags);
|
|
263
282
|
return;
|
|
264
283
|
case 'tokens':
|
|
265
|
-
webOnlyCommand('API 토큰 관리');
|
|
284
|
+
webOnlyCommand(message('API token administration', 'API 토큰 관리'));
|
|
266
285
|
return;
|
|
267
286
|
case 'crons':
|
|
268
287
|
await remoteCommands.listCrons(flags);
|
|
@@ -277,10 +296,10 @@ async function main() {
|
|
|
277
296
|
await remoteCommands.mail(rest, flags);
|
|
278
297
|
return;
|
|
279
298
|
case 'webhooks':
|
|
280
|
-
webOnlyCommand('웹훅 관리');
|
|
299
|
+
webOnlyCommand(message('Webhook administration', '웹훅 관리'));
|
|
281
300
|
return;
|
|
282
301
|
case 'token':
|
|
283
|
-
webOnlyCommand('API 토큰 관리');
|
|
302
|
+
webOnlyCommand(message('API token administration', 'API 토큰 관리'));
|
|
284
303
|
return;
|
|
285
304
|
case 'secret':
|
|
286
305
|
await remoteCommands.secrets(rest, flags);
|
|
@@ -292,10 +311,10 @@ async function main() {
|
|
|
292
311
|
await remoteCommands.domains(rest, flags);
|
|
293
312
|
return;
|
|
294
313
|
case 'webhook':
|
|
295
|
-
webOnlyCommand('웹훅 관리');
|
|
314
|
+
webOnlyCommand(message('Webhook administration', '웹훅 관리'));
|
|
296
315
|
return;
|
|
297
316
|
case 'delete':
|
|
298
|
-
webOnlyCommand('프로젝트 삭제');
|
|
317
|
+
webOnlyCommand(message('Project deletion', '프로젝트 삭제'));
|
|
299
318
|
return;
|
|
300
319
|
default:
|
|
301
320
|
throw new Error(`Unknown command: ${command}`);
|
|
@@ -306,7 +325,7 @@ async function login(flags) {
|
|
|
306
325
|
const connectionCode = stringFlag(flags, 'code');
|
|
307
326
|
if (connectionCode) {
|
|
308
327
|
ensureProjectEnvIgnored(projectWorkspaceDir(flags, { discover: false }));
|
|
309
|
-
const exchangeApiBaseUrl = unauthenticatedApiBaseUrl(flags);
|
|
328
|
+
const exchangeApiBaseUrl = normalizeCredentialApiUrl(unauthenticatedApiBaseUrl(flags));
|
|
310
329
|
const exchange = await apiRequest(flags, '/v1/auth/connection-code/exchange', {
|
|
311
330
|
method: 'POST',
|
|
312
331
|
body: { code: normalizeConnectionCode(connectionCode) },
|
|
@@ -323,6 +342,21 @@ async function login(flags) {
|
|
|
323
342
|
await saveBrowserConnectToken(flags, normalizeConnectToken(connectToken));
|
|
324
343
|
return;
|
|
325
344
|
}
|
|
345
|
+
const existing = resolveConnection(flags);
|
|
346
|
+
if (existing.apiToken) {
|
|
347
|
+
await saveBrowserConnectToken(
|
|
348
|
+
flags,
|
|
349
|
+
normalizeConnectToken(existing.apiToken),
|
|
350
|
+
existing.source,
|
|
351
|
+
existing.apiBaseUrl
|
|
352
|
+
);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const enteredCode = await promptConnectionCode(flags);
|
|
356
|
+
if (enteredCode !== null) {
|
|
357
|
+
await login({ ...flags, code: normalizeConnectionCode(enteredCode) });
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
326
360
|
output(flags, browserConnectInstructions(), printBrowserConnectInstructions);
|
|
327
361
|
}
|
|
328
362
|
|
|
@@ -330,6 +364,67 @@ async function saveBrowserConnectToken(flags, apiToken, source = 'browser-connec
|
|
|
330
364
|
return saveBrowserConnectTokenWithOptions(flags, apiToken, source, selectedApiBaseUrl);
|
|
331
365
|
}
|
|
332
366
|
|
|
367
|
+
function logout(flags) {
|
|
368
|
+
if (
|
|
369
|
+
stringFlag(flags, 'token') ||
|
|
370
|
+
stringFlag(flags, 'api-token') ||
|
|
371
|
+
stringFlag(flags, 'connect-token') ||
|
|
372
|
+
process.env.JORIPSPACE_API_TOKEN ||
|
|
373
|
+
process.env.JORIPSPACE_CONNECT_TOKEN
|
|
374
|
+
) {
|
|
375
|
+
const error = new Error(
|
|
376
|
+
message(
|
|
377
|
+
'The CLI cannot remove tokens supplied through environment variables or command-line arguments. Unset those tokens, then run logout.',
|
|
378
|
+
'환경 변수나 명령행으로 제공한 토큰은 CLI에서 제거할 수 없습니다. 해당 토큰 설정을 해제한 뒤 logout을 실행하세요.'
|
|
379
|
+
)
|
|
380
|
+
);
|
|
381
|
+
error.code = 'logout_external_token';
|
|
382
|
+
throw error;
|
|
383
|
+
}
|
|
384
|
+
const workspaceDir = projectWorkspaceDir(flags);
|
|
385
|
+
const env = readProjectEnv(workspaceDir);
|
|
386
|
+
const legacyProject = readLegacyProjectSessionConnection(workspaceDir);
|
|
387
|
+
const legacyGlobal = readGlobalSession(flags);
|
|
388
|
+
const connection = resolveConnection(flags);
|
|
389
|
+
const apiUrl = normalizeCredentialApiUrl(connection.apiBaseUrl);
|
|
390
|
+
const stored = credentialStore.load(apiUrl, connection.accountId || env.JORIPSPACE_ACCOUNT_ID || '');
|
|
391
|
+
const token = connection.apiToken || stored?.apiToken;
|
|
392
|
+
const sameConnection = (candidate) =>
|
|
393
|
+
candidate?.apiToken === token && trimTrailingSlash(candidate.apiBaseUrl) === apiUrl;
|
|
394
|
+
const clearLegacyProject = token && sameConnection(legacyProject);
|
|
395
|
+
const globalToken = legacyGlobal?.api_token || legacyGlobal?.connect_token;
|
|
396
|
+
const clearLegacyGlobal =
|
|
397
|
+
token &&
|
|
398
|
+
globalToken === token &&
|
|
399
|
+
trimTrailingSlash(legacyGlobal.api_base_url || DEFAULT_API_URL) === apiUrl;
|
|
400
|
+
const legacyProjectPath = clearLegacyProject
|
|
401
|
+
? managedProjectFilePath(workspaceDir, '.joripspace/agent-session.json')
|
|
402
|
+
: null;
|
|
403
|
+
if (clearLegacyGlobal) managedProjectFilePath(os.homedir(), '.joripspace/session.json');
|
|
404
|
+
managedProjectFilePath(workspaceDir, '.env.joripspace');
|
|
405
|
+
const accountId =
|
|
406
|
+
connection.accountId || env.JORIPSPACE_ACCOUNT_ID || (stored?.apiToken === token ? stored.accountId : '');
|
|
407
|
+
if (accountId) credentialStore.remove(apiUrl, accountId);
|
|
408
|
+
else if (!connection.apiToken) credentialStore.remove(apiUrl);
|
|
409
|
+
updateDotEnvFile(path.join(workspaceDir, '.env.joripspace'), {
|
|
410
|
+
JORIPSPACE_API_BASE_URL: apiUrl,
|
|
411
|
+
JORIPSPACE_API_TOKEN: null,
|
|
412
|
+
JORIPSPACE_CONNECT_TOKEN: null,
|
|
413
|
+
JORIPSPACE_CONNECTION_SOURCE: 'logged-out',
|
|
414
|
+
JORIPSPACE_ACCOUNT_ID: accountId || undefined,
|
|
415
|
+
});
|
|
416
|
+
if (legacyProjectPath) fs.unlinkSync(legacyProjectPath);
|
|
417
|
+
if (clearLegacyGlobal) scrubGlobalSessionToken();
|
|
418
|
+
output(flags, { status: 'logged_out' }, () =>
|
|
419
|
+
console.log(
|
|
420
|
+
message(
|
|
421
|
+
'Logged out: the current saved connection was removed from this device.',
|
|
422
|
+
'로그아웃 완료: 이 기기에 저장된 현재 연결을 삭제했습니다.'
|
|
423
|
+
)
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
333
428
|
async function saveBrowserConnectTokenWithOptions(
|
|
334
429
|
flags,
|
|
335
430
|
apiToken,
|
|
@@ -338,8 +433,9 @@ async function saveBrowserConnectTokenWithOptions(
|
|
|
338
433
|
options = {}
|
|
339
434
|
) {
|
|
340
435
|
const connection = selectedApiBaseUrl
|
|
341
|
-
? { apiBaseUrl:
|
|
436
|
+
? { apiBaseUrl: normalizeCredentialApiUrl(selectedApiBaseUrl), apiToken, source }
|
|
342
437
|
: connectionForExplicitToken(flags, apiToken);
|
|
438
|
+
connection.apiBaseUrl = normalizeCredentialApiUrl(connection.apiBaseUrl);
|
|
343
439
|
const workspaceDir = projectWorkspaceDir(flags, { discover: false });
|
|
344
440
|
managedProjectFilePath(workspaceDir, '.env.joripspace');
|
|
345
441
|
managedProjectFilePath(workspaceDir, '.gitignore');
|
|
@@ -359,19 +455,36 @@ async function saveBrowserConnectTokenWithOptions(
|
|
|
359
455
|
? projects[0]
|
|
360
456
|
: null;
|
|
361
457
|
if (requestedProject && !selected) throw new Error(`project is not accessible: ${requestedProject}`);
|
|
458
|
+
credentialStore.save({ ...connection, accountId: body.account_id });
|
|
362
459
|
updateDotEnvFile(path.join(workspaceDir, '.env.joripspace'), {
|
|
363
460
|
JORIPSPACE_API_BASE_URL: connection.apiBaseUrl,
|
|
364
|
-
JORIPSPACE_API_TOKEN:
|
|
461
|
+
JORIPSPACE_API_TOKEN: null,
|
|
462
|
+
JORIPSPACE_CONNECT_TOKEN: null,
|
|
365
463
|
JORIPSPACE_ACCOUNT_ID: body.account_id,
|
|
366
|
-
JORIPSPACE_CONNECTION_SOURCE:
|
|
464
|
+
JORIPSPACE_CONNECTION_SOURCE: 'os-credential-store',
|
|
367
465
|
});
|
|
368
466
|
scrubGlobalSessionToken();
|
|
369
467
|
if (options.output !== false) {
|
|
370
468
|
output(flags, body, (value) => {
|
|
371
|
-
console.log(`연결 완료: ${value.account_id}`);
|
|
372
|
-
console.log(
|
|
373
|
-
|
|
374
|
-
|
|
469
|
+
console.log(message(`Connected: ${value.account_id}`, `연결 완료: ${value.account_id}`));
|
|
470
|
+
console.log(
|
|
471
|
+
message(
|
|
472
|
+
'Token storage: OS credential store (reused across project folders)',
|
|
473
|
+
'토큰 저장 위치: OS 보안 저장소 (다른 프로젝트 폴더에서도 재사용)'
|
|
474
|
+
)
|
|
475
|
+
);
|
|
476
|
+
console.log(
|
|
477
|
+
message(
|
|
478
|
+
'Run joripspace projects or joripspace start in this folder.',
|
|
479
|
+
'이 폴더에서 joripspace projects 또는 joripspace start 명령을 실행하세요.'
|
|
480
|
+
)
|
|
481
|
+
);
|
|
482
|
+
console.log(
|
|
483
|
+
message(
|
|
484
|
+
'Manage account details and API tokens in your web profile.',
|
|
485
|
+
'회원정보와 API 토큰 관리는 웹 프로필에서만 가능합니다.'
|
|
486
|
+
)
|
|
487
|
+
);
|
|
375
488
|
});
|
|
376
489
|
}
|
|
377
490
|
return body;
|
|
@@ -406,7 +519,10 @@ async function listMyProjects(flags) {
|
|
|
406
519
|
|
|
407
520
|
function webOnlyCommand(label) {
|
|
408
521
|
throw new Error(
|
|
409
|
-
|
|
522
|
+
message(
|
|
523
|
+
`${label} is available only in the web UI. Use the CLI for development, DB/storage operations, server deployment, usage, and logs.`,
|
|
524
|
+
`${label} 기능은 웹 화면에서만 사용할 수 있습니다. CLI는 개발, DB/스토리지 작업, 서버 배포, 사용량, 로그 조회용입니다.`
|
|
525
|
+
)
|
|
410
526
|
);
|
|
411
527
|
}
|
|
412
528
|
|
|
@@ -658,7 +774,8 @@ async function deployCode(flags, options = {}) {
|
|
|
658
774
|
}
|
|
659
775
|
|
|
660
776
|
function printDeploymentWarnings(warnings) {
|
|
661
|
-
for (const warning of warnings || [])
|
|
777
|
+
for (const warning of warnings || [])
|
|
778
|
+
console.warn(message(`Warning: ${warning.message}`, `경고: ${warning.message}`));
|
|
662
779
|
}
|
|
663
780
|
|
|
664
781
|
async function listDeployments(flags) {
|
|
@@ -678,8 +795,14 @@ async function listDeployments(flags) {
|
|
|
678
795
|
console.log(
|
|
679
796
|
`${deployment.version}\t${deployment.deployment_id}\t${deployment.status}\trollback=${deployment.rollback_available}\t${deployment.created_at}`
|
|
680
797
|
);
|
|
681
|
-
if (deployment.error_message)
|
|
682
|
-
|
|
798
|
+
if (deployment.error_message)
|
|
799
|
+
console.log(
|
|
800
|
+
`${deployment.error_stage || 'unknown'} / ${deployment.error_code || 'unknown'}: ${deployment.error_message}`
|
|
801
|
+
);
|
|
802
|
+
if (deployment.github)
|
|
803
|
+
console.log(
|
|
804
|
+
`GitHub: ${deployment.github.commit_sha} ${deployment.github.run_url} (${deployment.github.diagnostic_status || 'pending'})`
|
|
805
|
+
);
|
|
683
806
|
if (deployment.error_details) console.log(deployment.error_details);
|
|
684
807
|
}
|
|
685
808
|
});
|
|
@@ -957,16 +1080,29 @@ function printWebhookDelivery(delivery) {
|
|
|
957
1080
|
|
|
958
1081
|
async function listTokens(flags) {
|
|
959
1082
|
throw new Error(
|
|
960
|
-
|
|
1083
|
+
message(
|
|
1084
|
+
'Issue or disable API tokens in your web profile. CLI tokens are for project management.',
|
|
1085
|
+
'API 토큰은 웹 프로필에서 발급하거나 사용 중지해주세요. CLI 토큰은 프로젝트 관리 전용입니다.'
|
|
1086
|
+
)
|
|
961
1087
|
);
|
|
962
1088
|
}
|
|
963
1089
|
|
|
964
1090
|
async function createToken(flags) {
|
|
965
|
-
throw new Error(
|
|
1091
|
+
throw new Error(
|
|
1092
|
+
message(
|
|
1093
|
+
'Issue API tokens in your web profile. A CLI token cannot create new tokens.',
|
|
1094
|
+
'API 토큰은 웹 프로필에서 발급해주세요. CLI 토큰으로 새 토큰을 만들 수 없습니다.'
|
|
1095
|
+
)
|
|
1096
|
+
);
|
|
966
1097
|
}
|
|
967
1098
|
|
|
968
1099
|
async function revokeToken(flags) {
|
|
969
|
-
throw new Error(
|
|
1100
|
+
throw new Error(
|
|
1101
|
+
message(
|
|
1102
|
+
'Disable API tokens in your web profile. A CLI token cannot revoke tokens.',
|
|
1103
|
+
'API 토큰은 웹 프로필에서 사용 중지해주세요. CLI 토큰으로 토큰을 폐기할 수 없습니다.'
|
|
1104
|
+
)
|
|
1105
|
+
);
|
|
970
1106
|
}
|
|
971
1107
|
|
|
972
1108
|
async function deleteProject(flags) {
|
|
@@ -995,7 +1131,10 @@ async function apiRequest(flags, apiPath, options) {
|
|
|
995
1131
|
'X-Joripspace-Session-Context': 'cli',
|
|
996
1132
|
};
|
|
997
1133
|
|
|
998
|
-
const timeoutMs =
|
|
1134
|
+
const timeoutMs =
|
|
1135
|
+
options.timeoutMs === null
|
|
1136
|
+
? null
|
|
1137
|
+
: (options.timeoutMs ?? (isDeploymentRequest(apiPath) ? null : GENERAL_REQUEST_TIMEOUT_MS));
|
|
999
1138
|
const controller = new AbortController();
|
|
1000
1139
|
const timer = timeoutMs === null ? undefined : setTimeout(() => controller.abort(), timeoutMs);
|
|
1001
1140
|
let response;
|
|
@@ -1005,6 +1144,7 @@ async function apiRequest(flags, apiPath, options) {
|
|
|
1005
1144
|
headers,
|
|
1006
1145
|
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
1007
1146
|
signal: controller.signal,
|
|
1147
|
+
redirect: 'error',
|
|
1008
1148
|
});
|
|
1009
1149
|
} catch (error) {
|
|
1010
1150
|
if (error?.name === 'AbortError') {
|
|
@@ -1017,7 +1157,12 @@ async function apiRequest(flags, apiPath, options) {
|
|
|
1017
1157
|
timeoutError.code = 'request_timeout';
|
|
1018
1158
|
throw timeoutError;
|
|
1019
1159
|
}
|
|
1020
|
-
const requestError = new Error(
|
|
1160
|
+
const requestError = new Error(
|
|
1161
|
+
redactAuthError(error instanceof Error ? error.message : String(error), [
|
|
1162
|
+
options.apiToken,
|
|
1163
|
+
options.body?.code,
|
|
1164
|
+
])
|
|
1165
|
+
);
|
|
1021
1166
|
requestError.code = 'request_failed';
|
|
1022
1167
|
throw requestError;
|
|
1023
1168
|
} finally {
|
|
@@ -1027,11 +1172,13 @@ async function apiRequest(flags, apiPath, options) {
|
|
|
1027
1172
|
const body = text ? parseJson(text) : {};
|
|
1028
1173
|
|
|
1029
1174
|
if (!response.ok) {
|
|
1030
|
-
const
|
|
1031
|
-
const
|
|
1032
|
-
|
|
1175
|
+
const safe = redactAuthError(body, [options.apiToken, options.body?.code]);
|
|
1176
|
+
const message =
|
|
1177
|
+
safe?.error?.message || safe?.message || JSON.stringify(safe) || `HTTP ${response.status}`;
|
|
1178
|
+
const apiError = new Error(formatDeploymentFailure(message, safe?.error?.details));
|
|
1179
|
+
apiError.code = safe?.error?.code || 'http_error';
|
|
1033
1180
|
apiError.status = response.status;
|
|
1034
|
-
if (
|
|
1181
|
+
if (safe?.error?.details !== undefined) apiError.details = safe.error.details;
|
|
1035
1182
|
throw apiError;
|
|
1036
1183
|
}
|
|
1037
1184
|
|
|
@@ -1042,6 +1189,23 @@ async function apiRequest(flags, apiPath, options) {
|
|
|
1042
1189
|
return body;
|
|
1043
1190
|
}
|
|
1044
1191
|
|
|
1192
|
+
function redactAuthError(value, secrets) {
|
|
1193
|
+
if (typeof value === 'string') {
|
|
1194
|
+
for (const secret of secrets.filter(Boolean)) value = value.split(secret).join('[REDACTED]');
|
|
1195
|
+
return value;
|
|
1196
|
+
}
|
|
1197
|
+
if (Array.isArray(value)) return value.map((item) => redactAuthError(item, secrets));
|
|
1198
|
+
if (value && typeof value === 'object') {
|
|
1199
|
+
return Object.fromEntries(
|
|
1200
|
+
Object.entries(value).map(([key, item]) => [
|
|
1201
|
+
redactAuthError(key, secrets),
|
|
1202
|
+
redactAuthError(item, secrets),
|
|
1203
|
+
])
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
return value;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1045
1209
|
function isDeploymentRequest(apiPath) {
|
|
1046
1210
|
return /\/deploy(?:ments)?(?:[/?]|$)|\/checkpoints\/[^/]+\/deploy(?:[/?]|$)/.test(apiPath);
|
|
1047
1211
|
}
|
|
@@ -1054,17 +1218,34 @@ function browserConnectInstructions() {
|
|
|
1054
1218
|
return {
|
|
1055
1219
|
status: 'browser_connection_required',
|
|
1056
1220
|
connect_url: 'https://joripspace.com/connect/',
|
|
1057
|
-
message:
|
|
1058
|
-
'
|
|
1059
|
-
|
|
1221
|
+
message: message(
|
|
1222
|
+
'No email address is required. Sign in to JoripSpace in your browser, approve the connection, and copy the one-time code, valid for five minutes.',
|
|
1223
|
+
'이메일 주소는 필요 없습니다. 브라우저에서 JoripSpace에 로그인한 뒤 연결을 승인하고 5분 일회용 연결 코드를 복사하세요.'
|
|
1224
|
+
),
|
|
1225
|
+
save_command: 'joripspace login --code "CONNECTION_CODE"',
|
|
1060
1226
|
};
|
|
1061
1227
|
}
|
|
1062
1228
|
|
|
1063
1229
|
function printBrowserConnectInstructions(value) {
|
|
1064
|
-
console.log(
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1230
|
+
console.log(
|
|
1231
|
+
message(
|
|
1232
|
+
'Approve the JoripSpace connection in your browser.',
|
|
1233
|
+
'브라우저에서 JoripSpace 연결을 승인하세요.'
|
|
1234
|
+
)
|
|
1235
|
+
);
|
|
1236
|
+
console.log(
|
|
1237
|
+
message(
|
|
1238
|
+
'No email address or email verification is required.',
|
|
1239
|
+
'이메일 주소 입력이나 메일 확인은 필요 없습니다.'
|
|
1240
|
+
)
|
|
1241
|
+
);
|
|
1242
|
+
console.log(message(`Connection page: ${value.connect_url}`, `연결 페이지: ${value.connect_url}`));
|
|
1243
|
+
console.log(
|
|
1244
|
+
message(
|
|
1245
|
+
'After approval, exchange the displayed five-minute one-time code using this command.',
|
|
1246
|
+
'승인 후 화면에 표시되는 5분 일회용 연결 코드를 아래 명령으로 교환하세요.'
|
|
1247
|
+
)
|
|
1248
|
+
);
|
|
1068
1249
|
console.log(value.save_command);
|
|
1069
1250
|
}
|
|
1070
1251
|
|
|
@@ -1075,11 +1256,15 @@ function normalizeConnectToken(value) {
|
|
|
1075
1256
|
}
|
|
1076
1257
|
if (
|
|
1077
1258
|
token.startsWith(SESSION_COOKIE_PREFIX) ||
|
|
1259
|
+
/[\u0000-\u0020\u007f]/.test(token) ||
|
|
1078
1260
|
/^bearer\s+/i.test(token) ||
|
|
1079
1261
|
['dummy', 'test', 'token', 'undefined', 'null'].includes(token.toLowerCase())
|
|
1080
1262
|
) {
|
|
1081
1263
|
throw new Error(
|
|
1082
|
-
|
|
1264
|
+
message(
|
|
1265
|
+
'Browser cookies, Bearer strings, empty placeholders, and test values cannot be used as CLI connection tokens. Get a new connection token at /connect/.',
|
|
1266
|
+
'브라우저 쿠키, Bearer 문자열, 빈 자리표시자, 테스트 값은 CLI 연결 토큰으로 사용할 수 없습니다. /connect/에서 새 연결 토큰을 발급하세요.'
|
|
1267
|
+
)
|
|
1083
1268
|
);
|
|
1084
1269
|
}
|
|
1085
1270
|
return token;
|
|
@@ -1090,7 +1275,12 @@ function normalizeConnectionCode(value) {
|
|
|
1090
1275
|
.replace(/[\s-]+/g, '')
|
|
1091
1276
|
.toUpperCase();
|
|
1092
1277
|
if (!/^[0-9A-HJKMNP-TV-Z]{16}$/.test(normalized)) {
|
|
1093
|
-
throw new Error(
|
|
1278
|
+
throw new Error(
|
|
1279
|
+
message(
|
|
1280
|
+
'The connection code must be the 16-character alphanumeric value shown on the connection page.',
|
|
1281
|
+
'연결 코드는 화면에 표시된 16자리 영숫자 값이어야 합니다.'
|
|
1282
|
+
)
|
|
1283
|
+
);
|
|
1094
1284
|
}
|
|
1095
1285
|
return normalized.match(/.{1,4}/g).join('-');
|
|
1096
1286
|
}
|
|
@@ -1258,33 +1448,44 @@ function resolveConnection(flags) {
|
|
|
1258
1448
|
apiToken: projectEnv.JORIPSPACE_API_TOKEN,
|
|
1259
1449
|
apiBaseUrl: trimTrailingSlash(projectEnv.JORIPSPACE_API_BASE_URL || DEFAULT_API_URL),
|
|
1260
1450
|
source: 'project-env',
|
|
1451
|
+
accountId: projectEnv.JORIPSPACE_ACCOUNT_ID,
|
|
1261
1452
|
workspaceDir,
|
|
1262
1453
|
};
|
|
1263
1454
|
}
|
|
1264
1455
|
|
|
1265
|
-
const
|
|
1456
|
+
const managedOsConnection = ['os-credential-store', 'logged-out'].includes(
|
|
1457
|
+
projectEnv.JORIPSPACE_CONNECTION_SOURCE
|
|
1458
|
+
);
|
|
1459
|
+
const legacyProjectConnection = managedOsConnection
|
|
1460
|
+
? null
|
|
1461
|
+
: readLegacyProjectSessionConnection(workspaceDir);
|
|
1266
1462
|
if (legacyProjectConnection) return legacyProjectConnection;
|
|
1267
1463
|
|
|
1268
|
-
const legacy = readGlobalSession(flags);
|
|
1464
|
+
const legacy = managedOsConnection ? null : readGlobalSession(flags);
|
|
1269
1465
|
const legacyToken = legacy?.api_token || legacy?.connect_token;
|
|
1270
1466
|
if (legacyToken) {
|
|
1271
1467
|
return {
|
|
1272
1468
|
apiToken: legacyToken,
|
|
1273
1469
|
apiBaseUrl: trimTrailingSlash(legacy.api_base_url || DEFAULT_API_URL),
|
|
1274
1470
|
source: 'legacy-global-session',
|
|
1471
|
+
accountId: legacy.account?.account_id || legacy.account_id,
|
|
1275
1472
|
workspaceDir,
|
|
1276
1473
|
};
|
|
1277
1474
|
}
|
|
1278
1475
|
|
|
1476
|
+
const selectedApiBaseUrl = trimTrailingSlash(
|
|
1477
|
+
projectEnv.JORIPSPACE_API_BASE_URL ||
|
|
1478
|
+
stringFlag(flags, 'api-url') ||
|
|
1479
|
+
process.env.JORIPSPACE_API_URL ||
|
|
1480
|
+
process.env.JORIPSPACE_API_BASE_URL ||
|
|
1481
|
+
DEFAULT_API_URL
|
|
1482
|
+
);
|
|
1483
|
+
const stored = credentialStore.load(selectedApiBaseUrl, projectEnv.JORIPSPACE_ACCOUNT_ID || '');
|
|
1484
|
+
if (stored) return { ...stored, workspaceDir };
|
|
1485
|
+
|
|
1279
1486
|
return {
|
|
1280
1487
|
apiToken: '',
|
|
1281
|
-
apiBaseUrl:
|
|
1282
|
-
stringFlag(flags, 'api-url') ||
|
|
1283
|
-
process.env.JORIPSPACE_API_URL ||
|
|
1284
|
-
process.env.JORIPSPACE_API_BASE_URL ||
|
|
1285
|
-
projectEnv.JORIPSPACE_API_BASE_URL ||
|
|
1286
|
-
DEFAULT_API_URL
|
|
1287
|
-
),
|
|
1488
|
+
apiBaseUrl: selectedApiBaseUrl,
|
|
1288
1489
|
source: 'none',
|
|
1289
1490
|
workspaceDir,
|
|
1290
1491
|
};
|
|
@@ -1336,20 +1537,27 @@ function scrubGlobalSessionToken() {
|
|
|
1336
1537
|
return true;
|
|
1337
1538
|
}
|
|
1338
1539
|
|
|
1339
|
-
function persistStartConnection(flags, connection) {
|
|
1540
|
+
function persistStartConnection(flags, connection, context = {}) {
|
|
1340
1541
|
if (
|
|
1341
|
-
!['legacy-global-session', 'legacy-project-session'].includes(
|
|
1542
|
+
!['project-env', 'legacy-global-session', 'legacy-project-session', 'os-credential-store'].includes(
|
|
1543
|
+
connection?.source
|
|
1544
|
+
) ||
|
|
1342
1545
|
!connection.apiToken
|
|
1343
1546
|
) {
|
|
1344
1547
|
return false;
|
|
1345
1548
|
}
|
|
1346
1549
|
const workspaceDir = path.resolve(stringFlag(flags, 'cwd') || projectWorkspaceDir(flags));
|
|
1347
1550
|
ensureProjectEnvIgnored(workspaceDir);
|
|
1551
|
+
const stored =
|
|
1552
|
+
connection.source === 'os-credential-store'
|
|
1553
|
+
? connection
|
|
1554
|
+
: credentialStore.save({ ...connection, accountId: context.accountId || connection.accountId });
|
|
1348
1555
|
updateDotEnvFile(path.join(workspaceDir, '.env.joripspace'), {
|
|
1349
|
-
JORIPSPACE_API_BASE_URL:
|
|
1350
|
-
JORIPSPACE_API_TOKEN:
|
|
1351
|
-
|
|
1352
|
-
|
|
1556
|
+
JORIPSPACE_API_BASE_URL: stored.apiBaseUrl,
|
|
1557
|
+
JORIPSPACE_API_TOKEN: null,
|
|
1558
|
+
JORIPSPACE_CONNECT_TOKEN: null,
|
|
1559
|
+
JORIPSPACE_ACCOUNT_ID: stored.accountId,
|
|
1560
|
+
JORIPSPACE_CONNECTION_SOURCE: 'os-credential-store',
|
|
1353
1561
|
});
|
|
1354
1562
|
if (connection.source === 'legacy-global-session') scrubGlobalSessionToken();
|
|
1355
1563
|
return true;
|
|
@@ -1403,24 +1611,12 @@ function canonicalWorkspaceEntry(directory, expected) {
|
|
|
1403
1611
|
|
|
1404
1612
|
async function connectForStart(flags, context) {
|
|
1405
1613
|
let connectionCode = stringFlag(flags, 'code');
|
|
1406
|
-
const interactive = !flags.json && Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
1407
|
-
if (!connectionCode && !interactive) return resolveConnection(flags);
|
|
1408
|
-
|
|
1409
1614
|
if (!connectionCode) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
console.log(`연결 페이지: ${instructions.connect_url}`);
|
|
1413
|
-
console.log('승인 후 표시된 5분 일회용 연결 코드를 이 터미널에 붙여 넣으세요.');
|
|
1414
|
-
openExternalUrl(instructions.connect_url);
|
|
1415
|
-
const prompt = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1416
|
-
try {
|
|
1417
|
-
connectionCode = await prompt.question('연결 코드: ');
|
|
1418
|
-
} finally {
|
|
1419
|
-
prompt.close();
|
|
1420
|
-
}
|
|
1615
|
+
connectionCode = await promptConnectionCode(flags);
|
|
1616
|
+
if (connectionCode === null) return resolveConnection(flags);
|
|
1421
1617
|
}
|
|
1422
1618
|
|
|
1423
|
-
const exchangeApiBaseUrl = unauthenticatedApiBaseUrl(flags);
|
|
1619
|
+
const exchangeApiBaseUrl = normalizeCredentialApiUrl(unauthenticatedApiBaseUrl(flags));
|
|
1424
1620
|
ensureProjectEnvIgnored(context.cwd);
|
|
1425
1621
|
const exchange = await apiRequest(flags, '/v1/auth/connection-code/exchange', {
|
|
1426
1622
|
method: 'POST',
|
|
@@ -1438,6 +1634,48 @@ async function connectForStart(flags, context) {
|
|
|
1438
1634
|
return resolveConnection({ ...flags, cwd: context.cwd });
|
|
1439
1635
|
}
|
|
1440
1636
|
|
|
1637
|
+
async function promptConnectionCode(flags) {
|
|
1638
|
+
if (flags.json || !process.stdin.isTTY || !process.stdout.isTTY) return null;
|
|
1639
|
+
const instructions = browserConnectInstructions();
|
|
1640
|
+
console.log(
|
|
1641
|
+
message(
|
|
1642
|
+
'Approve the JoripSpace connection in your browser.',
|
|
1643
|
+
'브라우저에서 JoripSpace 연결을 승인하세요.'
|
|
1644
|
+
)
|
|
1645
|
+
);
|
|
1646
|
+
console.log(
|
|
1647
|
+
message(`Connection page: ${instructions.connect_url}`, `연결 페이지: ${instructions.connect_url}`)
|
|
1648
|
+
);
|
|
1649
|
+
console.log(
|
|
1650
|
+
message(
|
|
1651
|
+
'After approval, paste the displayed five-minute one-time code into this terminal.',
|
|
1652
|
+
'승인 후 표시된 5분 일회용 연결 코드를 이 터미널에 붙여 넣으세요.'
|
|
1653
|
+
)
|
|
1654
|
+
);
|
|
1655
|
+
openExternalUrl(instructions.connect_url);
|
|
1656
|
+
const prompt = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1657
|
+
const cancellation = new AbortController();
|
|
1658
|
+
prompt.once('close', () => cancellation.abort());
|
|
1659
|
+
try {
|
|
1660
|
+
return await prompt.question(message('Connection code: ', '연결 코드: '), {
|
|
1661
|
+
signal: cancellation.signal,
|
|
1662
|
+
});
|
|
1663
|
+
} catch (error) {
|
|
1664
|
+
if (error?.code !== 'ABORT_ERR') throw error;
|
|
1665
|
+
const cancelled = new Error(
|
|
1666
|
+
message(
|
|
1667
|
+
'Connection code entry was cancelled. Run login again.',
|
|
1668
|
+
'연결 코드 입력이 취소되었습니다. login을 다시 실행하세요.'
|
|
1669
|
+
)
|
|
1670
|
+
);
|
|
1671
|
+
cancelled.code = 'connection_required';
|
|
1672
|
+
cancelled.exitCode = 2;
|
|
1673
|
+
throw cancelled;
|
|
1674
|
+
} finally {
|
|
1675
|
+
prompt.close();
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1441
1679
|
function openExternalUrl(url) {
|
|
1442
1680
|
const command =
|
|
1443
1681
|
process.platform === 'win32'
|