@sequenceholdings/studio-cli 0.4.7 → 0.5.2
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 +162 -84
- package/dist/agents/commands.js +7 -0
- package/dist/app/adapters.d.ts +2 -2
- package/dist/app/adapters.js +15 -14
- package/dist/app/commands.d.ts +1 -1
- package/dist/app/commands.js +77 -14
- package/dist/app/deploy.d.ts +2 -0
- package/dist/app/deploy.js +25 -13
- package/dist/app/kinds.d.ts +6 -0
- package/dist/app/kinds.js +6 -0
- package/dist/app/manifest.js +1 -1
- package/dist/app/official-source.d.ts +10 -0
- package/dist/app/official-source.js +23 -0
- package/dist/app/prepare.d.ts +27 -0
- package/dist/app/prepare.js +58 -0
- package/dist/app/primitive-ids.d.ts +6 -0
- package/dist/app/primitive-ids.js +16 -0
- package/dist/app/primitive-scaffold.d.ts +0 -4
- package/dist/app/primitive-scaffold.js +7 -18
- package/dist/app/readme.js +23 -16
- package/dist/app/repository-index.d.ts +19 -0
- package/dist/app/repository-index.js +86 -0
- package/dist/app/scaffold.d.ts +12 -1
- package/dist/app/scaffold.js +32 -19
- package/dist/app/workspace-compile.d.ts +9 -0
- package/dist/app/workspace-compile.js +13 -1
- package/dist/app/workspace-scaffold.js +5 -1
- package/dist/artifact/delegate.js +4 -4
- package/dist/auth-cmds/commands.d.ts +1 -13
- package/dist/auth-cmds/commands.js +11 -246
- package/dist/auth.d.ts +17 -0
- package/dist/auth.js +29 -0
- package/dist/bin.js +1 -1
- package/dist/command-contract.d.ts +11 -5
- package/dist/command-contract.js +4 -3
- package/dist/command-help.d.ts +2 -2
- package/dist/command-help.js +14 -16
- package/dist/config.d.ts +16 -0
- package/dist/config.js +38 -5
- package/dist/env-registry.d.ts +8 -0
- package/dist/env-registry.js +9 -1
- package/dist/envs/commands.js +14 -1
- package/dist/functions/manifest.d.ts +4 -1
- package/dist/functions/manifest.js +8 -2
- package/dist/main.d.ts +3 -2
- package/dist/main.js +12 -6
- package/dist/orm/delegate.js +5 -2
- package/dist/pipeline/clone-deploy.d.ts +2 -3
- package/dist/pipeline/clone-deploy.js +9 -10
- package/dist/pipeline/commands.js +4 -3
- package/dist/pipeline/lifecycle.d.ts +3 -1
- package/dist/pipeline/lifecycle.js +12 -4
- package/dist/process/commands.d.ts +6 -3
- package/dist/process/commands.js +26 -10
- package/dist/repos/commands.d.ts +2 -11
- package/dist/repos/commands.js +71 -157
- package/dist/repos/git-clone.d.ts +1 -10
- package/dist/repos/git-clone.js +1 -49
- package/dist/repos/git-credential.d.ts +15 -0
- package/dist/repos/git-credential.js +91 -0
- package/dist/repos/pulls.d.ts +19 -1
- package/dist/repos/pulls.js +15 -2
- package/dist/templates/catalog.d.ts +69 -0
- package/dist/templates/catalog.js +68 -0
- package/dist/templates/commands.d.ts +29 -0
- package/dist/templates/commands.js +443 -0
- package/dist/templates/process/example-process/process.ts +2 -0
- package/dist/templates/process/package.json +1 -1
- package/package.json +13 -11
- package/templates/process/example-process/process.ts +2 -0
- package/templates/process/package.json +1 -1
- package/dist/pat-hints.d.ts +0 -15
- package/dist/pat-hints.js +0 -28
|
@@ -70,7 +70,7 @@ ${PIPELINE_DISCOVERY_USAGE}
|
|
|
70
70
|
publish a clean local checkout into that environment's git service, then
|
|
71
71
|
deploy the published commit. Only targets that do not require approval
|
|
72
72
|
(dev, staging). BankSouth and production still deploy a commit that
|
|
73
|
-
already exists in that environment's git service.
|
|
73
|
+
already exists in that environment's git service. Uses your seq-studio login (human session required).
|
|
74
74
|
plan (attaching missing credentials as for plan) then enqueue Trigger deploy (DAB bundle validate hard-gates before
|
|
75
75
|
bundle deploy). Default is plant-only: jobs/pipelines are created, not
|
|
76
76
|
run. Pass --run-now to run in-unit producer roots after bundle deploy.
|
|
@@ -147,8 +147,9 @@ async function importPipelineSpec() {
|
|
|
147
147
|
if (err.code === 'ERR_MODULE_NOT_FOUND') {
|
|
148
148
|
const message = err instanceof Error ? err.message : String(err);
|
|
149
149
|
if (isPipelineSpecMissing(message)) {
|
|
150
|
-
console.error('seq-studio pipeline needs the @sequenceholdings/pipeline-spec package.
|
|
151
|
-
'
|
|
150
|
+
console.error('seq-studio pipeline needs the @sequenceholdings/pipeline-spec package. Add it to your app, then run the app\'s CLI:\n' +
|
|
151
|
+
' pnpm add -D @sequenceholdings/pipeline-spec\n' +
|
|
152
|
+
' pnpm exec seq-studio pipeline …');
|
|
152
153
|
}
|
|
153
154
|
else {
|
|
154
155
|
console.error('@sequenceholdings/pipeline-spec is installed but a dependency failed to load. Reinstall dependencies, then retry.\n' +
|
|
@@ -61,7 +61,9 @@ export interface PipelineTarget {
|
|
|
61
61
|
label: string;
|
|
62
62
|
requiresApproval: boolean;
|
|
63
63
|
}
|
|
64
|
-
export declare function envAndToken(args: ParsedArgs
|
|
64
|
+
export declare function envAndToken(args: ParsedArgs, options?: {
|
|
65
|
+
human?: boolean;
|
|
66
|
+
}): Promise<{
|
|
65
67
|
env: ResolvedEnv;
|
|
66
68
|
token: string;
|
|
67
69
|
}>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Deploy lifecycle verbs for `seq-studio pipeline plan|deploy|promote|rollback`
|
|
3
3
|
* (SEQ-2450). Wraps the /api/data-pipelines plan/deploy APIs.
|
|
4
4
|
*/
|
|
5
|
-
import { getAccessToken, NotLoggedInError } from '../auth.js';
|
|
5
|
+
import { getAccessToken, getAccessTokenWithMode, NotLoggedInError } from '../auth.js';
|
|
6
6
|
import { AtlasApiError, getJson, postJson } from '../atlas-client.js';
|
|
7
7
|
import { resolveConfiguredEnv } from '../config.js';
|
|
8
8
|
import { parseDurationMs } from '@sequenceholdings/lattice';
|
|
@@ -51,7 +51,7 @@ function deploymentStatusLabel(detail) {
|
|
|
51
51
|
return `${detail.status} — ${detail.statusDetail}`;
|
|
52
52
|
return detail.status;
|
|
53
53
|
}
|
|
54
|
-
export async function envAndToken(args) {
|
|
54
|
+
export async function envAndToken(args, options = {}) {
|
|
55
55
|
const requested = typeof args.flags.e === 'string' ? args.flags.e : typeof args.flags.env === 'string' ? args.flags.env : undefined;
|
|
56
56
|
if (!requested) {
|
|
57
57
|
throw new Error('missing -e/--env <environment>');
|
|
@@ -59,7 +59,15 @@ export async function envAndToken(args) {
|
|
|
59
59
|
const env = await resolveConfiguredEnv({ requested });
|
|
60
60
|
let token;
|
|
61
61
|
try {
|
|
62
|
-
|
|
62
|
+
if (options.human) {
|
|
63
|
+
const auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url });
|
|
64
|
+
if (auth.authMode !== 'user')
|
|
65
|
+
throw new Error('Publishing a local clone requires a user login. Run seq-studio login for this environment, then retry.');
|
|
66
|
+
token = auth.token;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
token = await getAccessToken({ env: env.name, targetUrl: env.url });
|
|
70
|
+
}
|
|
63
71
|
}
|
|
64
72
|
catch (error) {
|
|
65
73
|
if (error instanceof NotLoggedInError)
|
|
@@ -201,7 +209,7 @@ export async function pipelineDeployCommand(args) {
|
|
|
201
209
|
const runNow = flagOn(args.flags, 'run-now');
|
|
202
210
|
const waitTimeoutMs = deploymentWaitTimeoutMs(args);
|
|
203
211
|
const allowDestructiveResourceKeys = repeatedFlagStrings(args, 'allow-destructive');
|
|
204
|
-
const { env, token } = await envAndToken(args);
|
|
212
|
+
const { env, token } = await envAndToken(args, { human: Boolean(dir) });
|
|
205
213
|
let target;
|
|
206
214
|
try {
|
|
207
215
|
target = await resolvePipelineTarget({ args, env, token });
|
|
@@ -16,16 +16,19 @@ export type ProcessSourceSpec = {
|
|
|
16
16
|
ref?: string;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* Parse the process-apply source flags. `--repo
|
|
19
|
+
* Parse the process-apply source flags. `--repo <namespace>/<name>` materializes
|
|
20
20
|
* from the platform git service; absent means local (cwd / LATTICE_PROCESSES_ROOT).
|
|
21
21
|
* `--git-url` is passed through to the underlying `resolveArtifactSource` when
|
|
22
22
|
* the repo flag is a full ns/name pair (future); today only git-service is
|
|
23
23
|
* supported.
|
|
24
24
|
*
|
|
25
|
-
* Process repos live
|
|
26
|
-
*
|
|
25
|
+
* Process repos live in `processes`, an `apps` monorepo, or a builder's own
|
|
26
|
+
* namespace. Platform namespaces that hold another kind are rejected to avoid
|
|
27
|
+
* cross-kind accidents.
|
|
27
28
|
*/
|
|
28
29
|
export declare function parseProcessSourceSpec(flags: Record<string, string | true>): ProcessSourceSpec;
|
|
30
|
+
/** The last segment of a directory path, whichever separator the platform uses. */
|
|
31
|
+
export declare function scaffoldName(dir: string): string;
|
|
29
32
|
export declare function initCommand(args: ParsedArgs): Promise<number>;
|
|
30
33
|
export declare function lintCommand(args: ParsedArgs): Promise<number>;
|
|
31
34
|
export declare function planCommand(args: ParsedArgs): Promise<number>;
|
package/dist/process/commands.js
CHANGED
|
@@ -14,6 +14,7 @@ import { getJson, getJsonOr404, postJson, AtlasApiError } from '../atlas-client.
|
|
|
14
14
|
import { generateProcessFiles } from './codegen.js';
|
|
15
15
|
import { getAccessToken, getAccessTokenWithMode, inspectAuthPreflight, AuthTokenStoreError, NotLoggedInError, } from '../auth.js';
|
|
16
16
|
import { readConfig, resolveEnv, resolveConfiguredEnv } from '../config.js';
|
|
17
|
+
import { currentVersion } from '../update-check.js';
|
|
17
18
|
import { writeScaffoldGuidance } from '../scaffold-guidance.js';
|
|
18
19
|
import { finalizeCompiledBundle, summarizeBundle } from './build.js';
|
|
19
20
|
import { buildResolveProcessPinFromEnv } from './resolve-process-pin.js';
|
|
@@ -48,21 +49,31 @@ async function getEnvAndAuth(args) {
|
|
|
48
49
|
const auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url });
|
|
49
50
|
return { authMode: auth.authMode, env, token: auth.token };
|
|
50
51
|
}
|
|
52
|
+
/** Platform namespaces reserved for primitives other than processes. */
|
|
53
|
+
const OTHER_KIND_NAMESPACES = new Set([
|
|
54
|
+
'agents',
|
|
55
|
+
'artifacts',
|
|
56
|
+
'external-systems',
|
|
57
|
+
'managed-functions',
|
|
58
|
+
'pipelines',
|
|
59
|
+
'templates',
|
|
60
|
+
]);
|
|
51
61
|
/**
|
|
52
|
-
* Parse the process-apply source flags. `--repo
|
|
62
|
+
* Parse the process-apply source flags. `--repo <namespace>/<name>` materializes
|
|
53
63
|
* from the platform git service; absent means local (cwd / LATTICE_PROCESSES_ROOT).
|
|
54
64
|
* `--git-url` is passed through to the underlying `resolveArtifactSource` when
|
|
55
65
|
* the repo flag is a full ns/name pair (future); today only git-service is
|
|
56
66
|
* supported.
|
|
57
67
|
*
|
|
58
|
-
* Process repos live
|
|
59
|
-
*
|
|
68
|
+
* Process repos live in `processes`, an `apps` monorepo, or a builder's own
|
|
69
|
+
* namespace. Platform namespaces that hold another kind are rejected to avoid
|
|
70
|
+
* cross-kind accidents.
|
|
60
71
|
*/
|
|
61
72
|
export function parseProcessSourceSpec(flags) {
|
|
62
73
|
const repo = typeof flags.repo === 'string' ? flags.repo : undefined;
|
|
63
74
|
const ref = typeof flags.ref === 'string' ? flags.ref : undefined;
|
|
64
75
|
if (flags.repo === true)
|
|
65
|
-
throw new Error('--repo requires a value: --repo
|
|
76
|
+
throw new Error('--repo requires a value: --repo <namespace>/<name>');
|
|
66
77
|
if (flags.ref === true)
|
|
67
78
|
throw new Error('--ref requires a value.');
|
|
68
79
|
if (flags.dir === true)
|
|
@@ -77,17 +88,21 @@ export function parseProcessSourceSpec(flags) {
|
|
|
77
88
|
return { kind: 'local' };
|
|
78
89
|
const parts = repo.split('/');
|
|
79
90
|
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
80
|
-
throw new Error(`--repo must be "processes/<name>
|
|
91
|
+
throw new Error(`--repo must be "<namespace>/<name>", such as processes/<name> or your app's namespace (got "${repo}").`);
|
|
81
92
|
}
|
|
82
|
-
if (parts[0]
|
|
83
|
-
throw new Error(`
|
|
84
|
-
`Use --repo processes/<name
|
|
93
|
+
if (OTHER_KIND_NAMESPACES.has(parts[0])) {
|
|
94
|
+
throw new Error(`The "${parts[0]}" namespace holds another kind of primitive, not processes. ` +
|
|
95
|
+
`Use --repo processes/<name> or your app's namespace.`);
|
|
85
96
|
}
|
|
86
97
|
return { kind: 'git-service', namespace: parts[0], name: parts[1], ref };
|
|
87
98
|
}
|
|
88
99
|
// ---------------------------------------------------------------------------
|
|
89
100
|
// init
|
|
90
101
|
// ---------------------------------------------------------------------------
|
|
102
|
+
/** The last segment of a directory path, whichever separator the platform uses. */
|
|
103
|
+
export function scaffoldName(dir) {
|
|
104
|
+
return dir.split(/[\\/]/).filter(Boolean).at(-1) ?? 'my-process';
|
|
105
|
+
}
|
|
91
106
|
export async function initCommand(args) {
|
|
92
107
|
const target = args.positional[0];
|
|
93
108
|
if (!target) {
|
|
@@ -95,7 +110,7 @@ export async function initCommand(args) {
|
|
|
95
110
|
return 1;
|
|
96
111
|
}
|
|
97
112
|
const dir = resolve(target);
|
|
98
|
-
const name = dir
|
|
113
|
+
const name = scaffoldName(dir);
|
|
99
114
|
if (existsSync(dir)) {
|
|
100
115
|
console.error(`${dir} already exists`);
|
|
101
116
|
return 1;
|
|
@@ -129,7 +144,8 @@ export async function initCommand(args) {
|
|
|
129
144
|
if (existsSync(path)) {
|
|
130
145
|
const body = (await readFile(path, 'utf8'))
|
|
131
146
|
.replace(/\{\{name\}\}/g, name)
|
|
132
|
-
.replace(/\{\{slug\}\}/g, slug)
|
|
147
|
+
.replace(/\{\{slug\}\}/g, slug)
|
|
148
|
+
.replace(/\{\{cliVersion\}\}/g, currentVersion());
|
|
133
149
|
await writeFile(path, body, 'utf8');
|
|
134
150
|
}
|
|
135
151
|
}
|
package/dist/repos/commands.d.ts
CHANGED
|
@@ -45,22 +45,13 @@ export declare function reposListCommand(args: ParsedArgs): Promise<number>;
|
|
|
45
45
|
export declare function reposShowCommand(args: ParsedArgs): Promise<number>;
|
|
46
46
|
export declare function reposCreateCommand(args: ParsedArgs): Promise<number>;
|
|
47
47
|
export declare function reposPullCommand(args: ParsedArgs): Promise<number>;
|
|
48
|
-
/**
|
|
49
|
-
* Preferred clone verb.
|
|
50
|
-
*
|
|
51
|
-
* With `ATLAS_GIT_PAT`:
|
|
52
|
-
* - `--url <clone-url>` or `--id <repo-uuid>` → smart-HTTP clone with no seqapi
|
|
53
|
-
* - `<ns>/<name>` → needs Auth0 to resolve the UUID, then smart-HTTP clone
|
|
54
|
-
* Without a PAT: JSON materialize (needs Auth0) + PAT setup hints.
|
|
55
|
-
*
|
|
56
|
-
* `gitClone` is injectable for tests.
|
|
57
|
-
*/
|
|
48
|
+
/** Git clone always uses the selected human login, never an ambient PAT. */
|
|
58
49
|
export declare function reposCloneCommand(args: ParsedArgs, deps?: {
|
|
59
50
|
gitClone?: RunGitClone;
|
|
60
51
|
}): Promise<number>;
|
|
61
52
|
/**
|
|
62
53
|
* Validate clone URL shape and that the origin matches the resolved Atlas env
|
|
63
|
-
* so askpass never sends
|
|
54
|
+
* so askpass never sends a login token to an attacker-controlled host.
|
|
64
55
|
*/
|
|
65
56
|
export declare function normalizeCloneUrl(raw: string, env: ResolvedEnv): string;
|
|
66
57
|
type DiscoveredCliCheck = {
|
package/dist/repos/commands.js
CHANGED
|
@@ -5,9 +5,8 @@ import { REPOS_USAGE } from '../command-help.js';
|
|
|
5
5
|
*
|
|
6
6
|
* Everything here is API-driven (Auth0 bearer via seq-studio login), matching the
|
|
7
7
|
* rest of seq-studio. `pull` materializes a tree over the JSON API; `clone`
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* at `seq-studio auth pat create`.
|
|
8
|
+
* uses a real Git checkout and a login credential helper by default.
|
|
9
|
+
* Explicit JSON transport downloads files without a Git checkout.
|
|
11
10
|
*
|
|
12
11
|
* Repo addressing is `<namespace>/<name>` everywhere; the API is id-addressed,
|
|
13
12
|
* so commands resolve the path via the namespaces + repos endpoints (the same
|
|
@@ -26,11 +25,8 @@ import { printCliError } from '../cli-errors.js';
|
|
|
26
25
|
import { PREVIEW_DOMAIN } from '../preview.js';
|
|
27
26
|
import { confirmYes } from '../prompt.js';
|
|
28
27
|
import { buildContext, clientOptions, flagBool, LOG, } from '../functions/commands.js';
|
|
29
|
-
import { looksLikeCommitSha,
|
|
30
|
-
import {
|
|
31
|
-
import { tryGetAccessToken } from '../auth.js';
|
|
32
|
-
import { resolveConfiguredEnv } from '../config.js';
|
|
33
|
-
import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
|
|
28
|
+
import { looksLikeCommitSha, runGitClone, } from './git-clone.js';
|
|
29
|
+
import { configureGitLogin } from './git-credential.js';
|
|
34
30
|
const PAGE_SIZE = 200;
|
|
35
31
|
// ---------------------------------------------------------------------------
|
|
36
32
|
// Helpers
|
|
@@ -177,7 +173,7 @@ export async function reposNamespacesCommand(args) {
|
|
|
177
173
|
const ctx = await reposContext(args);
|
|
178
174
|
if (action === 'create') {
|
|
179
175
|
if (!slug) {
|
|
180
|
-
console.error('usage: seq-studio repos namespaces create <slug> -e <env>');
|
|
176
|
+
console.error('usage: seq-studio repos namespaces create <slug> -e <env> (needs Can create on Repositories)');
|
|
181
177
|
return 1;
|
|
182
178
|
}
|
|
183
179
|
const created = await postJson({
|
|
@@ -256,7 +252,7 @@ export async function reposShowCommand(args) {
|
|
|
256
252
|
}
|
|
257
253
|
console.log(` created: ${shortDate(repo.createdAt)} by ${repo.createdBy}`);
|
|
258
254
|
console.log(` updated: ${shortDate(repo.updatedAt)}`);
|
|
259
|
-
console.log(` clone (
|
|
255
|
+
console.log(` clone (seq-studio login): ${cloneUrl(ctx, repo.id)}`);
|
|
260
256
|
// Best-effort cross-link to a matching Artifact Studio project on this env
|
|
261
257
|
// (same slug as the repo name). Failures are silent — not every repo is an
|
|
262
258
|
// artifact, and the projects endpoint may 403 for some principals.
|
|
@@ -348,166 +344,83 @@ export async function reposPullCommand(args) {
|
|
|
348
344
|
verb: 'pulled',
|
|
349
345
|
});
|
|
350
346
|
}
|
|
351
|
-
|
|
352
|
-
* Preferred clone verb.
|
|
353
|
-
*
|
|
354
|
-
* With `ATLAS_GIT_PAT`:
|
|
355
|
-
* - `--url <clone-url>` or `--id <repo-uuid>` → smart-HTTP clone with no seqapi
|
|
356
|
-
* - `<ns>/<name>` → needs Auth0 to resolve the UUID, then smart-HTTP clone
|
|
357
|
-
* Without a PAT: JSON materialize (needs Auth0) + PAT setup hints.
|
|
358
|
-
*
|
|
359
|
-
* `gitClone` is injectable for tests.
|
|
360
|
-
*/
|
|
361
|
-
export async function reposCloneCommand(args, deps = {}) {
|
|
347
|
+
function parseCloneOptions(args) {
|
|
362
348
|
const force = flagBool(args.flags, 'force');
|
|
363
|
-
const full = flagBool(args.flags, 'full');
|
|
364
349
|
const ref = stringFlag(args.flags, 'ref');
|
|
365
|
-
const depth = smartHttpCloneDepth({ ref, full });
|
|
350
|
+
const depth = smartHttpCloneDepth({ ref, full: flagBool(args.flags, 'full') });
|
|
366
351
|
const outputFlag = stringFlag(args.flags, 'output');
|
|
367
352
|
const outFlag = stringFlag(args.flags, 'out');
|
|
368
|
-
if (outputFlag !== undefined && outFlag !== undefined)
|
|
353
|
+
if (outputFlag !== undefined && outFlag !== undefined)
|
|
369
354
|
throw new Error('Pass only one of --output or --out.');
|
|
370
|
-
}
|
|
371
355
|
const output = outputFlag ?? outFlag;
|
|
372
|
-
const pat = resolveGitPatFromEnv();
|
|
373
|
-
const transportFlag = stringFlag(args.flags, 'transport') ?? 'auto';
|
|
374
|
-
if (!['auto', 'git', 'json'].includes(transportFlag)) {
|
|
375
|
-
throw new Error('--transport must be one of: auto, git, json.');
|
|
376
|
-
}
|
|
377
|
-
const transport = transportFlag;
|
|
378
356
|
const urlFlag = stringFlag(args.flags, 'url');
|
|
379
357
|
const idFlag = stringFlag(args.flags, 'id');
|
|
380
358
|
const positional = args.positional[0];
|
|
381
|
-
if (urlFlag && idFlag)
|
|
359
|
+
if (urlFlag && idFlag)
|
|
382
360
|
throw new Error('Pass only one of --url or --id.');
|
|
383
|
-
|
|
384
|
-
if ((urlFlag || idFlag) && positional) {
|
|
361
|
+
if ((urlFlag || idFlag) && positional)
|
|
385
362
|
throw new Error('Pass either <ns>/<name> or --url/--id, not both.');
|
|
363
|
+
const transport = stringFlag(args.flags, 'transport') ?? 'auto';
|
|
364
|
+
if (!['auto', 'git', 'json'].includes(transport))
|
|
365
|
+
throw new Error('--transport must be one of: auto, git, json.');
|
|
366
|
+
if (transport === 'json' && !positional)
|
|
367
|
+
throw new Error('--transport json requires <namespace>/<name>.');
|
|
368
|
+
return { force, ref, depth, output, urlFlag, idFlag, positional, transport };
|
|
369
|
+
}
|
|
370
|
+
async function gitCloneContext(args) {
|
|
371
|
+
const ctx = await reposContext(args);
|
|
372
|
+
if (ctx.authMode === 'm2m') {
|
|
373
|
+
throw new Error(`Git clone requires a user login: seq-studio login --env ${ctx.env.name}. Use repos pull for M2M JSON materialization.`);
|
|
386
374
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
];
|
|
394
|
-
throw new Error(lines.join('\n'));
|
|
395
|
-
}
|
|
396
|
-
if (transport === 'git' && !pat) {
|
|
397
|
-
const env = await resolveEnvOnly(args);
|
|
398
|
-
throw new Error([
|
|
399
|
-
`${LOG} --transport git requires ATLAS_GIT_PAT with repo:read access for ${env.name}.`,
|
|
400
|
-
...formatPatSetupHint({ envUrl: env.url, envName: env.name }),
|
|
401
|
-
].join('\n'));
|
|
402
|
-
}
|
|
403
|
-
// PAT-only path: clone by URL or repo UUID without seqapi/Auth0.
|
|
404
|
-
if (pat && (urlFlag || idFlag)) {
|
|
405
|
-
const env = await resolveEnvOnly(args);
|
|
406
|
-
const targetUrl = urlFlag
|
|
407
|
-
? normalizeCloneUrl(urlFlag, env)
|
|
408
|
-
: cloneUrl({ env, token: '' }, idFlag);
|
|
409
|
-
const destDir = resolve(output ?? defaultOutFromCloneTarget({ url: targetUrl, id: idFlag }));
|
|
410
|
-
prepareCloneDest({ destDir, force });
|
|
411
|
-
const clone = deps.gitClone ?? runGitClone;
|
|
412
|
-
await clone({
|
|
413
|
-
cloneUrl: targetUrl,
|
|
414
|
-
destDir,
|
|
415
|
-
pat,
|
|
416
|
-
...(ref ? { ref } : {}),
|
|
417
|
-
...(depth != null ? { depth } : {}),
|
|
418
|
-
}).catch((error) => {
|
|
419
|
-
throw withGitAuthHint({ error, envName: env.name });
|
|
420
|
-
});
|
|
421
|
-
console.log(`${LOG} cloned ${targetUrl} → ${destDir}` +
|
|
422
|
-
(ref ? ` (ref ${ref})` : '') +
|
|
423
|
-
` via smart-HTTP${depth != null ? ` (depth ${depth})` : ''}`);
|
|
424
|
-
return 0;
|
|
425
|
-
}
|
|
426
|
-
// <ns>/<name> path — needs Auth0 for resolveRepo (JSON API) whether or not
|
|
427
|
-
// we then use smart-HTTP. Without Auth0, point users at --url from the UI.
|
|
428
|
-
if (!positional) {
|
|
375
|
+
return ctx;
|
|
376
|
+
}
|
|
377
|
+
/** Git clone always uses the selected human login, never an ambient PAT. */
|
|
378
|
+
export async function reposCloneCommand(args, deps = {}) {
|
|
379
|
+
const { force, ref, depth, output, urlFlag, idFlag, positional, transport } = parseCloneOptions(args);
|
|
380
|
+
if (!positional && !urlFlag && !idFlag) {
|
|
429
381
|
console.error('usage: seq-studio repos clone <ns>/<name> | --url <clone-url> | --id <uuid> -e <env> [--ref r] [--output dir] [--full]');
|
|
430
382
|
return 1;
|
|
431
383
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
` Then: seq-studio repos clone ${namespace}/${name} -e ${env.name}`,
|
|
447
|
-
];
|
|
448
|
-
throw new Error(lines.join('\n'));
|
|
449
|
-
}
|
|
450
|
-
const ctx = await reposContext(args);
|
|
451
|
-
const destDir = resolve(output ?? name);
|
|
452
|
-
if (pat && transport !== 'json') {
|
|
453
|
-
prepareCloneDest({ destDir, force });
|
|
384
|
+
if (transport === 'json') {
|
|
385
|
+
const { namespace, name } = parseRepoPath(positional);
|
|
386
|
+
const ctx = await reposContext(args);
|
|
387
|
+
const destDir = resolve(output ?? name);
|
|
388
|
+
assertDestWritable({ destDir, force });
|
|
389
|
+
console.log(`${LOG} materializing via JSON API as the signed-in Atlas identity (no .git dir; ignoring ATLAS_GIT_PAT).`);
|
|
390
|
+
return materializeTree({ ctx, namespace, name, destDir, ref, verb: 'cloned' });
|
|
391
|
+
}
|
|
392
|
+
const ctx = await gitCloneContext(args);
|
|
393
|
+
const env = ctx.env;
|
|
394
|
+
let targetUrl;
|
|
395
|
+
let defaultOut;
|
|
396
|
+
if (positional) {
|
|
397
|
+
const { namespace, name } = parseRepoPath(positional);
|
|
454
398
|
const resolved = await resolveRepo({ ...clientOptions(ctx), namespace, name });
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return 0;
|
|
470
|
-
}
|
|
471
|
-
assertDestWritable({ destDir, force });
|
|
472
|
-
console.log(transport === 'json'
|
|
473
|
-
? `${LOG} materializing via JSON API as the signed-in Atlas identity (no .git dir; ignoring ATLAS_GIT_PAT).`
|
|
474
|
-
: `${LOG} no ATLAS_GIT_PAT — materializing via JSON API (no .git dir).`);
|
|
475
|
-
for (const line of formatPatSetupHint({ envUrl: ctx.env.url, envName: ctx.env.name })) {
|
|
476
|
-
console.log(line);
|
|
477
|
-
}
|
|
478
|
-
return materializeTree({
|
|
479
|
-
ctx,
|
|
480
|
-
namespace,
|
|
481
|
-
name,
|
|
482
|
-
destDir,
|
|
483
|
-
ref,
|
|
484
|
-
verb: 'cloned',
|
|
399
|
+
targetUrl = cloneUrl(ctx, resolved.id);
|
|
400
|
+
defaultOut = name;
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
targetUrl = urlFlag ?? cloneUrl({ env, token: '' }, idFlag);
|
|
404
|
+
defaultOut = defaultOutFromCloneTarget({ url: targetUrl, id: idFlag });
|
|
405
|
+
}
|
|
406
|
+
targetUrl = normalizeCloneUrl(targetUrl, env);
|
|
407
|
+
const destDir = resolve(output ?? defaultOut);
|
|
408
|
+
prepareCloneDest({ destDir, force });
|
|
409
|
+
await (deps.gitClone ?? runGitClone)({
|
|
410
|
+
cloneUrl: targetUrl, destDir, pat: ctx.token,
|
|
411
|
+
...(ref ? { ref } : {}),
|
|
412
|
+
...(depth != null ? { depth } : {}),
|
|
485
413
|
});
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
return new Error(`${message}\n${LOG} Git-service rejected ATLAS_GIT_PAT for ${envName}. Check that it is current and has repo:read access for this environment. ` +
|
|
493
|
-
`If your signed-in Atlas account can read the repo, retry with --transport json to materialize without using the ambient PAT (this creates no .git directory).`, { cause: error });
|
|
494
|
-
}
|
|
495
|
-
/** Resolve -e/--env without requiring Auth0 (for PAT-only --url/--id clones). */
|
|
496
|
-
async function resolveEnvOnly(args) {
|
|
497
|
-
if (args.flags.env === true || args.flags.e === true) {
|
|
498
|
-
throw new Error('-e/--env requires a value — see: seq-studio envs list.');
|
|
499
|
-
}
|
|
500
|
-
const requested = (typeof args.flags.env === 'string' ? args.flags.env : undefined) ??
|
|
501
|
-
(typeof args.flags.e === 'string' ? args.flags.e : undefined);
|
|
502
|
-
// Same contract as buildContext: never silently fall back to `local`.
|
|
503
|
-
if (!requested) {
|
|
504
|
-
throw new Error(REQUIRE_EXPLICIT_ENV_MESSAGE);
|
|
505
|
-
}
|
|
506
|
-
return resolveConfiguredEnv({ requested });
|
|
414
|
+
await configureGitLogin({ destDir, envName: env.name, cloneUrl: targetUrl });
|
|
415
|
+
console.log(`${LOG} cloned ${positional ?? targetUrl} → ${destDir}` +
|
|
416
|
+
(ref ? ` (ref ${ref})` : '') +
|
|
417
|
+
` via smart-HTTP${depth != null ? ` (depth ${depth})` : ''}`);
|
|
418
|
+
console.log(`${LOG} git pull/push now use your seq-studio login. After expiry: seq-studio login --env ${env.name}`);
|
|
419
|
+
return 0;
|
|
507
420
|
}
|
|
508
421
|
/**
|
|
509
422
|
* Validate clone URL shape and that the origin matches the resolved Atlas env
|
|
510
|
-
* so askpass never sends
|
|
423
|
+
* so askpass never sends a login token to an attacker-controlled host.
|
|
511
424
|
*/
|
|
512
425
|
export function normalizeCloneUrl(raw, env) {
|
|
513
426
|
let url;
|
|
@@ -515,18 +428,19 @@ export function normalizeCloneUrl(raw, env) {
|
|
|
515
428
|
url = new URL(raw);
|
|
516
429
|
}
|
|
517
430
|
catch {
|
|
518
|
-
throw new Error(
|
|
431
|
+
throw new Error('--url must be a valid HTTPS clone URL.');
|
|
519
432
|
}
|
|
520
433
|
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
521
434
|
throw new Error(`--url must be http(s) (got ${url.protocol}).`);
|
|
522
435
|
}
|
|
523
|
-
//
|
|
524
|
-
if (
|
|
436
|
+
// Permit HTTP only on loopback, including registered local worktree servers.
|
|
437
|
+
if (url.protocol !== 'https:' && !['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) {
|
|
525
438
|
throw new Error(`--url must use HTTPS for ${env.name} (got ${url.protocol}).`);
|
|
526
439
|
}
|
|
527
|
-
url.username
|
|
528
|
-
|
|
529
|
-
|
|
440
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
441
|
+
throw new Error('--url must not contain credentials, query parameters, or a fragment.');
|
|
442
|
+
}
|
|
443
|
+
if (!/^\/api\/git-service\/repos\/[\w-]+(?:\/git|\.git)\/?$/.test(url.pathname)) {
|
|
530
444
|
throw new Error(`--url must look like …/api/git-service/repos/<id>/git (got ${url.pathname}).`);
|
|
531
445
|
}
|
|
532
446
|
let expected;
|
|
@@ -545,7 +459,7 @@ export function normalizeCloneUrl(raw, env) {
|
|
|
545
459
|
function defaultOutFromCloneTarget({ url, id, }) {
|
|
546
460
|
if (id)
|
|
547
461
|
return id;
|
|
548
|
-
const match = /\/repos\/([^/]
|
|
462
|
+
const match = /\/repos\/([^/]+?)(?:\/git|\.git)\/?$/.exec(new URL(url).pathname);
|
|
549
463
|
return match?.[1] ?? 'repo';
|
|
550
464
|
}
|
|
551
465
|
/**
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
export { looksLikeCommitSha, redactCloneUrl,
|
|
2
|
-
/**
|
|
3
|
-
* Write a credential via `git credential approve` so subsequent clones against
|
|
4
|
-
* the same host can authenticate without embedding the PAT in the URL.
|
|
5
|
-
*/
|
|
6
|
-
export declare function storeGitCredentials({ cloneUrl, pat, username, }: {
|
|
7
|
-
cloneUrl: string;
|
|
8
|
-
pat: string;
|
|
9
|
-
username?: string;
|
|
10
|
-
}): Promise<void>;
|
|
1
|
+
export { looksLikeCommitSha, redactCloneUrl, runGitClone, withGitAskpass, type RunGitClone, } from '@sequenceholdings/artifact-studio/git-clone';
|
package/dist/repos/git-clone.js
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Smart-HTTP git clone helpers for platform git-service.
|
|
3
|
-
*
|
|
4
|
-
* The clone primitives (askpass, runGitClone, PAT/URL helpers) are the
|
|
5
|
-
* canonical implementation in `@sequenceholdings/artifact-studio/git-clone` so
|
|
6
|
-
* the `repos` tool and the artifact `--repo` deploy path share one code path.
|
|
7
|
-
* We re-export them here to keep the historical import site stable, and add
|
|
8
|
-
* `storeGitCredentials` (git credential-helper writer) which is studio-cli
|
|
9
|
-
* specific.
|
|
10
|
-
*/
|
|
11
|
-
import { spawn } from 'node:child_process';
|
|
12
|
-
export { looksLikeCommitSha, redactCloneUrl, resolveGitPatFromEnv, runGitClone, withGitAskpass, } from '@sequenceholdings/artifact-studio/git-clone';
|
|
13
|
-
/**
|
|
14
|
-
* Write a credential via `git credential approve` so subsequent clones against
|
|
15
|
-
* the same host can authenticate without embedding the PAT in the URL.
|
|
16
|
-
*/
|
|
17
|
-
export async function storeGitCredentials({ cloneUrl, pat, username = 'git', }) {
|
|
18
|
-
const parsed = new URL(cloneUrl);
|
|
19
|
-
const protocol = parsed.protocol.replace(/:$/, '');
|
|
20
|
-
const host = parsed.host;
|
|
21
|
-
const path = parsed.pathname;
|
|
22
|
-
const payload = [
|
|
23
|
-
`protocol=${protocol}`,
|
|
24
|
-
`host=${host}`,
|
|
25
|
-
`path=${path}`,
|
|
26
|
-
`username=${username}`,
|
|
27
|
-
`password=${pat}`,
|
|
28
|
-
'',
|
|
29
|
-
].join('\n');
|
|
30
|
-
await new Promise((resolve, reject) => {
|
|
31
|
-
const child = spawn('git', ['credential', 'approve'], {
|
|
32
|
-
stdio: ['pipe', 'ignore', 'pipe'],
|
|
33
|
-
});
|
|
34
|
-
let stderr = '';
|
|
35
|
-
child.stderr?.on('data', (chunk) => {
|
|
36
|
-
stderr += chunk.toString();
|
|
37
|
-
});
|
|
38
|
-
child.on('error', (err) => reject(err));
|
|
39
|
-
child.on('close', (code) => {
|
|
40
|
-
if (code === 0) {
|
|
41
|
-
resolve();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
reject(new Error(`git credential approve failed (exit ${code ?? 'null'}): ${stderr.trim() || 'no stderr'}`));
|
|
45
|
-
});
|
|
46
|
-
child.stdin?.write(payload);
|
|
47
|
-
child.stdin?.end();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
1
|
+
export { looksLikeCommitSha, redactCloneUrl, runGitClone, withGitAskpass, } from '@sequenceholdings/artifact-studio/git-clone';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ParsedArgs } from '../process/commands.js';
|
|
2
|
+
/** Only send a login credential to the exact repository pinned at clone time. */
|
|
3
|
+
export declare function gitCredentialResponse({ input, operation, envName, cloneUrl, }: {
|
|
4
|
+
input: string;
|
|
5
|
+
operation: string;
|
|
6
|
+
envName: string;
|
|
7
|
+
cloneUrl: string;
|
|
8
|
+
}): Promise<string>;
|
|
9
|
+
/** Store only a helper command, bound to this environment and repository URL. */
|
|
10
|
+
export declare function configureGitLogin({ destDir, envName, cloneUrl, }: {
|
|
11
|
+
destDir: string;
|
|
12
|
+
envName: string;
|
|
13
|
+
cloneUrl: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
export declare function gitCredentialCommand(args: ParsedArgs): Promise<number>;
|