@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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declare a newly scaffolded app in its git repository's `.seq/repository.yml`,
|
|
3
|
+
* so repository CI checks and deploys it. CI treats an undeclared
|
|
4
|
+
* `sequence.app.yml` in an indexed repository as an error, and a repository
|
|
5
|
+
* without an index only reads a root manifest.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
10
|
+
import { isSeq, parseDocument } from 'yaml';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { APP_MANIFEST_FILENAME } from './manifest.js';
|
|
13
|
+
export const REPOSITORY_INDEX_PATH = '.seq/repository.yml';
|
|
14
|
+
const indexSchema = z.looseObject({
|
|
15
|
+
schema_version: z.literal(1),
|
|
16
|
+
applications: z.array(z.looseObject({ path: z.string().min(1) })).nullish(),
|
|
17
|
+
ignore: z.array(z.string().min(1)).nullish(),
|
|
18
|
+
});
|
|
19
|
+
function findGitRoot(start) {
|
|
20
|
+
for (let directory = resolve(start);; directory = dirname(directory)) {
|
|
21
|
+
if (existsSync(join(directory, '.git')))
|
|
22
|
+
return directory;
|
|
23
|
+
if (dirname(directory) === directory)
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Same containment rule as repository CI: equal, or a descendant of a non-root path. */
|
|
28
|
+
function under({ path, root }) {
|
|
29
|
+
return root === '.' || path === root || path.startsWith(`${root}/`);
|
|
30
|
+
}
|
|
31
|
+
const NEW_INDEX_HEADER = '# Repository CI checks every application listed here and deploys it when changes merge to main.\n';
|
|
32
|
+
/**
|
|
33
|
+
* Plan the index change for an app about to be scaffolded at `appRoot`.
|
|
34
|
+
* Returns null when nothing needs declaring: no enclosing git repository, an
|
|
35
|
+
* app at the root of a repository without an index, or an app already listed.
|
|
36
|
+
*/
|
|
37
|
+
export async function planRepositoryDeclaration({ appRoot }) {
|
|
38
|
+
const gitRoot = findGitRoot(appRoot);
|
|
39
|
+
if (gitRoot === null)
|
|
40
|
+
return null;
|
|
41
|
+
const appPath = relative(gitRoot, resolve(appRoot)).split(sep).join('/') || '.';
|
|
42
|
+
if (appPath.startsWith('..'))
|
|
43
|
+
return null;
|
|
44
|
+
const indexPath = join(gitRoot, REPOSITORY_INDEX_PATH);
|
|
45
|
+
if (!existsSync(indexPath)) {
|
|
46
|
+
if (appPath === '.')
|
|
47
|
+
return null;
|
|
48
|
+
const applications = [
|
|
49
|
+
...(existsSync(join(gitRoot, APP_MANIFEST_FILENAME)) ? ['.'] : []),
|
|
50
|
+
appPath,
|
|
51
|
+
];
|
|
52
|
+
const content = `${NEW_INDEX_HEADER}schema_version: 1\napplications:\n${applications.map((path) => ` - path: ${path}\n`).join('')}`;
|
|
53
|
+
return { indexPath, appPath, content, created: true };
|
|
54
|
+
}
|
|
55
|
+
const text = await readFile(indexPath, 'utf8');
|
|
56
|
+
const document = parseDocument(text);
|
|
57
|
+
if (document.errors.length > 0) {
|
|
58
|
+
throw new Error(`${REPOSITORY_INDEX_PATH} is not valid YAML: ${document.errors[0]?.message ?? 'parse error'}`);
|
|
59
|
+
}
|
|
60
|
+
const parsed = indexSchema.safeParse(document.toJS());
|
|
61
|
+
if (!parsed.success) {
|
|
62
|
+
throw new Error(`${REPOSITORY_INDEX_PATH} is not a schema_version 1 repository index; fix it before adding ${appPath}`);
|
|
63
|
+
}
|
|
64
|
+
const existing = (parsed.data.applications ?? []).map((application) => application.path);
|
|
65
|
+
if (existing.includes(appPath))
|
|
66
|
+
return null;
|
|
67
|
+
const ignored = (parsed.data.ignore ?? []).find((path) => under({ path: appPath, root: path }) || under({ path, root: appPath }));
|
|
68
|
+
if (ignored !== undefined) {
|
|
69
|
+
throw new Error(`${REPOSITORY_INDEX_PATH} ignores "${ignored}", which overlaps ${appPath}; remove that ignore entry or scaffold somewhere else`);
|
|
70
|
+
}
|
|
71
|
+
const enclosing = existing.find((path) => path !== '.' && under({ path: appPath, root: path }));
|
|
72
|
+
if (enclosing !== undefined) {
|
|
73
|
+
throw new Error(`${appPath} is inside the declared application ${enclosing}; scaffold a new app beside it, or use \`seq-studio add\` inside it`);
|
|
74
|
+
}
|
|
75
|
+
// The schema above admits only a list or an empty value here.
|
|
76
|
+
const applications = document.get('applications');
|
|
77
|
+
if (isSeq(applications))
|
|
78
|
+
applications.add(document.createNode({ path: appPath }));
|
|
79
|
+
else
|
|
80
|
+
document.set('applications', [{ path: appPath }]);
|
|
81
|
+
return { indexPath, appPath, content: document.toString(), created: false };
|
|
82
|
+
}
|
|
83
|
+
export async function writeRepositoryDeclaration({ declaration }) {
|
|
84
|
+
await mkdir(dirname(declaration.indexPath), { recursive: true });
|
|
85
|
+
await writeFile(declaration.indexPath, declaration.content, 'utf8');
|
|
86
|
+
}
|
package/dist/app/scaffold.d.ts
CHANGED
|
@@ -29,10 +29,21 @@ export declare function addPrimitiveToApp({ rootDir, kind, name, pipelineType, a
|
|
|
29
29
|
manifest: AppManifest;
|
|
30
30
|
entry: PrimitiveEntry;
|
|
31
31
|
}>;
|
|
32
|
+
/**
|
|
33
|
+
* The topmost directory on the way from `appRoot` to `absPath` that does not
|
|
34
|
+
* exist yet: what rolling back a failed scaffold must remove so it leaves no
|
|
35
|
+
* empty parent (e.g. `orm/`) behind.
|
|
36
|
+
*/
|
|
37
|
+
export declare function firstMissingDirectory({ appRoot, absPath }: {
|
|
38
|
+
appRoot: string;
|
|
39
|
+
absPath: string;
|
|
40
|
+
}): string;
|
|
32
41
|
export declare function printOrmPreparation({ primitives }: {
|
|
33
42
|
primitives: readonly PrimitiveEntry[];
|
|
34
43
|
}): void;
|
|
35
|
-
export declare function printInitNextSteps({ appRoot, manifest, }: {
|
|
44
|
+
export declare function printInitNextSteps({ appRoot, manifest, prepared, }: {
|
|
36
45
|
appRoot: string;
|
|
37
46
|
manifest: AppManifest;
|
|
47
|
+
/** true: dependencies installed and migrations authored; false: skipped; 'failed': partly done. */
|
|
48
|
+
prepared: boolean | 'failed';
|
|
38
49
|
}): void;
|
package/dist/app/scaffold.js
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
6
6
|
import { existsSync } from 'node:fs';
|
|
7
|
-
import { join, relative, resolve } from 'node:path';
|
|
7
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
8
8
|
import { currentVersion, isNewerVersion } from '../update-check.js';
|
|
9
9
|
import { extendDeployOrder, loadAppManifest, titleizeSlug, writeAppManifest, } from './manifest.js';
|
|
10
10
|
import { inspectScaffoldTarget, mergeGitignore, rollbackAppScaffold } from './scaffold-files.js';
|
|
11
11
|
import { readGitServiceSeedAtlasOrigin, renderAppReadme } from './readme.js';
|
|
12
12
|
import { writeScaffoldGuidance } from '../scaffold-guidance.js';
|
|
13
|
-
import { primitiveIdFor
|
|
13
|
+
import { primitiveIdFor } from './primitive-ids.js';
|
|
14
|
+
import { relativePathFor, scaffoldKind } from './primitive-scaffold.js';
|
|
14
15
|
import { joinAppWorkspace, scaffoldAppWorkspace, scaffoldSharedPackage } from './workspace-scaffold.js';
|
|
15
16
|
const LOG = '[seq-studio]';
|
|
16
17
|
const APP_MANIFEST_LABEL = 'sequence.app.yml';
|
|
@@ -52,7 +53,7 @@ export async function initAppMonorepo({ rootDir, appId, kinds, names = defaultSc
|
|
|
52
53
|
const withDeps = applyDefaultDependsOn(primitives);
|
|
53
54
|
const shared = await scaffoldSharedPackage({ rootDir: appRoot, appId, name: 'shared' });
|
|
54
55
|
const manifest = {
|
|
55
|
-
schema_version:
|
|
56
|
+
schema_version: 3,
|
|
56
57
|
app: {
|
|
57
58
|
id: appId,
|
|
58
59
|
title: titleizeSlug(appId),
|
|
@@ -117,6 +118,7 @@ export async function addPrimitiveToApp({ rootDir, kind, name, pipelineType, art
|
|
|
117
118
|
}
|
|
118
119
|
const workspacePath = join(appRoot, 'pnpm-workspace.yaml');
|
|
119
120
|
const previousWorkspace = existsSync(workspacePath) ? await readFile(workspacePath, 'utf8') : null;
|
|
121
|
+
const createdRoot = firstMissingDirectory({ appRoot, absPath });
|
|
120
122
|
try {
|
|
121
123
|
let entry = await scaffoldKind({ kind, appRoot, appId, name, pipelineType, artifactTemplate });
|
|
122
124
|
const orm = manifest.primitives.find((item) => item.kind === 'orm');
|
|
@@ -158,13 +160,28 @@ export async function addPrimitiveToApp({ rootDir, kind, name, pipelineType, art
|
|
|
158
160
|
catch (error) {
|
|
159
161
|
if (previousWorkspace !== null)
|
|
160
162
|
await writeFile(workspacePath, previousWorkspace, 'utf8');
|
|
161
|
-
// Safe: absPath
|
|
162
|
-
|
|
163
|
+
// Safe: createdRoot (absPath, or a parent such as orm/ that scaffolding
|
|
164
|
+
// created for it) did not exist before this invocation.
|
|
165
|
+
await rm(createdRoot, { recursive: true, force: true }).catch(() => {
|
|
163
166
|
/* best-effort */
|
|
164
167
|
});
|
|
165
168
|
throw error;
|
|
166
169
|
}
|
|
167
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* The topmost directory on the way from `appRoot` to `absPath` that does not
|
|
173
|
+
* exist yet: what rolling back a failed scaffold must remove so it leaves no
|
|
174
|
+
* empty parent (e.g. `orm/`) behind.
|
|
175
|
+
*/
|
|
176
|
+
export function firstMissingDirectory({ appRoot, absPath }) {
|
|
177
|
+
const segments = relative(appRoot, absPath).split(sep).filter(Boolean);
|
|
178
|
+
for (let depth = 1; depth <= segments.length; depth++) {
|
|
179
|
+
const candidate = join(appRoot, ...segments.slice(0, depth));
|
|
180
|
+
if (!existsSync(candidate))
|
|
181
|
+
return candidate;
|
|
182
|
+
}
|
|
183
|
+
return absPath;
|
|
184
|
+
}
|
|
168
185
|
export function printOrmPreparation({ primitives }) {
|
|
169
186
|
for (const entry of primitives.filter((item) => item.kind === 'orm')) {
|
|
170
187
|
console.log(` seq-studio orm generate ${entry.path}`);
|
|
@@ -172,7 +189,7 @@ export function printOrmPreparation({ primitives }) {
|
|
|
172
189
|
console.log(` # review and commit ${entry.path}/migrations/ before deploying`);
|
|
173
190
|
}
|
|
174
191
|
}
|
|
175
|
-
export function printInitNextSteps({ appRoot, manifest, }) {
|
|
192
|
+
export function printInitNextSteps({ appRoot, manifest, prepared, }) {
|
|
176
193
|
const rel = relative(process.cwd(), appRoot);
|
|
177
194
|
const display = !rel || rel.startsWith('..') ? appRoot : rel;
|
|
178
195
|
console.log(`${LOG} scaffolded app "${manifest.app.id}" in ${display}`);
|
|
@@ -181,22 +198,18 @@ export function printInitNextSteps({ appRoot, manifest, }) {
|
|
|
181
198
|
for (const entry of manifest.primitives) {
|
|
182
199
|
console.log(`${LOG} - ${entry.kind.padEnd(9)} ${entry.id} (${entry.path})`);
|
|
183
200
|
}
|
|
201
|
+
if (prepared === true)
|
|
202
|
+
console.log(`${LOG} installed dependencies and authored the first migration; commit pnpm-lock.yaml and migrations/`);
|
|
184
203
|
console.log('');
|
|
185
204
|
console.log('Next:');
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
console.log(' # or targeted:');
|
|
192
|
-
const fn = manifest.primitives.find((entry) => entry.kind === 'function');
|
|
193
|
-
if (fn) {
|
|
194
|
-
console.log(` seq-studio deploy --only ${fn.id} -e local --yes`);
|
|
195
|
-
}
|
|
196
|
-
const artifact = manifest.primitives.find((entry) => entry.kind === 'artifact');
|
|
197
|
-
if (artifact) {
|
|
198
|
-
console.log(` seq-studio deploy --only ${artifact.id} -e local --yes`);
|
|
205
|
+
if (display !== '.')
|
|
206
|
+
console.log(` cd ${display}`);
|
|
207
|
+
if (prepared === false) {
|
|
208
|
+
console.log(' pnpm install');
|
|
209
|
+
printOrmPreparation({ primitives: manifest.primitives });
|
|
199
210
|
}
|
|
211
|
+
console.log(' Push a branch and open a PR; checks run automatically, and merging to main publishes the app.');
|
|
212
|
+
console.log(` No repository yet? seq-studio repos create artifacts/${manifest.app.id} -e <env>, then push this app to it.`);
|
|
200
213
|
console.log(' # add another primitive later:');
|
|
201
214
|
console.log(' seq-studio add function list-types');
|
|
202
215
|
console.log(' seq-studio add package contracts');
|
|
@@ -6,6 +6,15 @@ interface CompileOptions {
|
|
|
6
6
|
packages: ReadonlyMap<string, WorkspacePackage>;
|
|
7
7
|
closure: readonly WorkspacePackage[];
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether esbuild is resolving a package import (`react`, `@scope/pkg`) rather
|
|
11
|
+
* than a file. An entry point or absolute path is a file even when it starts
|
|
12
|
+
* with a letter, as Windows paths (`C:\\app\\index.ts`) do.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isPackageImport({ path, kind }: {
|
|
15
|
+
path: string;
|
|
16
|
+
kind: string;
|
|
17
|
+
}): boolean;
|
|
9
18
|
export declare function compileWorkspaceFunction(options: CompileOptions): Promise<void>;
|
|
10
19
|
/**
|
|
11
20
|
* Rewrite only workspace imports in the artifact's own modules, then compile
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { mkdir, readFile, realpath, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { basename, dirname, extname, join, posix, relative, resolve, sep, win32 } from 'node:path';
|
|
5
5
|
import { build, transform } from 'esbuild';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { containedPath, isWithin, resolveWorkspaceImport } from './workspace-model.js';
|
|
@@ -10,12 +10,24 @@ const relativeImport = ({ from, to }) => {
|
|
|
10
10
|
const path = slash(relative(dirname(from), to));
|
|
11
11
|
return path.startsWith('.') ? path : `./${path}`;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Whether esbuild is resolving a package import (`react`, `@scope/pkg`) rather
|
|
15
|
+
* than a file. An entry point or absolute path is a file even when it starts
|
|
16
|
+
* with a letter, as Windows paths (`C:\\app\\index.ts`) do.
|
|
17
|
+
*/
|
|
18
|
+
export function isPackageImport({ path, kind }) {
|
|
19
|
+
if (kind === 'entry-point' || posix.isAbsolute(path) || win32.isAbsolute(path))
|
|
20
|
+
return false;
|
|
21
|
+
return /^[^./]|^@/.test(path);
|
|
22
|
+
}
|
|
13
23
|
function workspaceCompilerPlugin({ sourceDir, packages, closure, browser, runtimeEntry, runtimeMain }) {
|
|
14
24
|
const allowed = [...(browser ? [] : [sourceDir]), ...closure.map((entry) => entry.dir)];
|
|
15
25
|
return {
|
|
16
26
|
name: 'sequence-app-workspace-source',
|
|
17
27
|
setup(builder) {
|
|
18
28
|
builder.onResolve({ filter: /^[^./]|^@/ }, async (args) => {
|
|
29
|
+
if (!isPackageImport(args))
|
|
30
|
+
return undefined;
|
|
19
31
|
const path = await resolveWorkspaceImport({ specifier: args.path, packages, browser, requireImport: args.kind === 'require-call' || args.kind === 'require-resolve' });
|
|
20
32
|
if (path)
|
|
21
33
|
return { path };
|
|
@@ -66,12 +66,16 @@ export async function joinAppWorkspace({ rootDir, manifest, entries, }) {
|
|
|
66
66
|
const pkg = packageSchema.parse(JSON.parse(await readFile(packagePath, 'utf8')));
|
|
67
67
|
const { pnpm, ...packageFields } = pkg;
|
|
68
68
|
mergeOverrides({ existing: overrides, incoming: pnpm?.overrides ?? {} });
|
|
69
|
+
// A function's packaged dependencies ship as-is and a deployed bundle cannot
|
|
70
|
+
// resolve a workspace: link, so functions opt in to shared packages explicitly.
|
|
71
|
+
// Artifacts and processes are bundled at build time, so the link is safe there.
|
|
72
|
+
const shared = entry.kind === 'function' ? [] : manifest.packages ?? [];
|
|
69
73
|
await writeFile(packagePath, `${JSON.stringify({
|
|
70
74
|
...packageFields,
|
|
71
75
|
name: `@${manifest.app.id}/primitive-${entry.id}`,
|
|
72
76
|
dependencies: {
|
|
73
77
|
...pkg.dependencies,
|
|
74
|
-
...Object.fromEntries(
|
|
78
|
+
...Object.fromEntries(shared.map((item) => [item.name, 'workspace:*'])),
|
|
75
79
|
},
|
|
76
80
|
}, null, 2)}\n`);
|
|
77
81
|
for (const name of ['pnpm-workspace.yaml', 'pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', '.npmrc']) {
|
|
@@ -41,10 +41,10 @@ const ARTIFACT_USAGE = `usage:
|
|
|
41
41
|
branch/tag/commit (default: the repo's default branch). --path <dir> selects the
|
|
42
42
|
application directory inside that repository (default: its root).
|
|
43
43
|
|
|
44
|
-
Interactive --repo builds clone over smart-HTTP
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
Interactive --repo builds clone over smart-HTTP using your seq-studio login
|
|
45
|
+
and repository read access. No PAT is needed. Headless M2M builds use JSON
|
|
46
|
+
materialize and accept only platform-managed --repo sources. Use --env to
|
|
47
|
+
select the same environment for source and deployment.
|
|
48
48
|
|
|
49
49
|
Next.js applications require Node.js 24 and application-local dependencies
|
|
50
50
|
(pnpm install). dev runs Next locally with native Fast Refresh through an
|
|
@@ -1,15 +1,3 @@
|
|
|
1
1
|
import type { ParsedArgs } from '../process/commands.js';
|
|
2
|
-
declare const
|
|
3
|
-
type PatScope = (typeof PAT_SCOPES)[number];
|
|
4
|
-
export declare const AUTH_USAGE = "usage:\n seq-studio auth whoami -e <env> [--json] server-verified identity and target (no tokens)\n seq-studio auth pat create --name <n> -e <env> [--scopes repo:read,repo:write]\n [--expires 1d|7d|30d|90d|1y|never] [--store-credentials]\n seq-studio auth pat list -e <env>\n seq-studio auth pat revoke <id> -e <env> [--yes]\n\n Issue a personal access token for git clone / git push against the platform\n git service.\n\n Authenticate with `seq-studio login`, then run `auth pat create -e <env>`.\n Alternatively, open Atlas \u2192 Settings \u2192 Tokens:\n https://<atlas-host>/settings/tokens\n Sign in, create a token (repo:read / repo:write), copy once, then:\n export ATLAS_GIT_PAT=<token>\n repo:write covers push and PR open; merging a PR requires an FGA Merge\n (or Admin) grant on the repository, not a PAT scope.\n\n On create the raw token is printed ONCE \u2014 store it; Atlas cannot re-show it.\n Git Basic auth: any username (e.g. git), PAT as the password.\n\n Flags: -e/--env <env> (required; see: seq-studio envs list)\n";
|
|
5
|
-
export declare function parsePatScopes(raw: string | undefined): PatScope[];
|
|
6
|
-
/**
|
|
7
|
-
* Map UI-style duration choices to an absolute ISO-8601 expiresAt, or undefined
|
|
8
|
-
* for never. Matches Settings Tokens dialog choices.
|
|
9
|
-
*/
|
|
10
|
-
export declare function resolveExpiresAt(choice: string | undefined): string | undefined;
|
|
11
|
-
export declare function authPatCreateCommand(args: ParsedArgs): Promise<number>;
|
|
12
|
-
export declare function authPatListCommand(args: ParsedArgs): Promise<number>;
|
|
13
|
-
export declare function authPatRevokeCommand(args: ParsedArgs): Promise<number>;
|
|
2
|
+
export declare const AUTH_USAGE = "usage:\n seq-studio auth whoami -e <env> [--json]\n seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>\n Git authentication uses seq-studio login. repos clone installs the helper.\n";
|
|
14
3
|
export declare function runAuthCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
|
|
15
|
-
export {};
|
|
@@ -1,228 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `seq-studio auth <sub>` — PAT management for the platform git service.
|
|
3
|
-
*
|
|
4
|
-
* Issues / lists / revokes Personal Access Tokens via Auth0 bearer auth.
|
|
5
|
-
* Users authenticate with `seq-studio login`; the Atlas UI at
|
|
6
|
-
* `/settings/tokens` remains an alternative.
|
|
7
|
-
*
|
|
8
|
-
* The raw token is printed exactly once on create; use it as the Basic-auth
|
|
9
|
-
* password for `git clone` / `git push` (username is ignored).
|
|
10
|
-
*/
|
|
11
1
|
import { validateCommandInput, wantsHelp } from '../command-input.js';
|
|
12
|
-
import {
|
|
2
|
+
import { getJson } from '../atlas-client.js';
|
|
13
3
|
import { printCliError } from '../cli-errors.js';
|
|
14
|
-
import {
|
|
15
|
-
import { buildContext, clientOptions, flagBool, LOG, } from '../functions/commands.js';
|
|
16
|
-
import { readConfig } from '../config.js';
|
|
17
|
-
import { confirmYes } from '../prompt.js';
|
|
18
|
-
import { storeGitCredentials } from '../repos/git-clone.js';
|
|
19
|
-
import { formatPatSetupHint, settingsTokensUrl } from '../pat-hints.js';
|
|
20
|
-
/**
|
|
21
|
-
* Tokens-page URLs rendered from the configured environments (config.toml +
|
|
22
|
-
* registered deployments). With none configured, print a generic pointer
|
|
23
|
-
* instead of a hardcoded list of internal hosts.
|
|
24
|
-
*/
|
|
25
|
-
async function settingsTokensLines() {
|
|
26
|
-
const config = await readConfig().catch(() => null);
|
|
27
|
-
const remote = Object.entries(config?.envs ?? {}).filter(([name]) => name !== 'local');
|
|
28
|
-
if (remote.length === 0) {
|
|
29
|
-
return ['Tokens page: <your Atlas deployment URL>/settings/tokens'];
|
|
30
|
-
}
|
|
31
|
-
return remote.map(([name, { url }]) => `${name}: ${settingsTokensUrl(url)}`);
|
|
32
|
-
}
|
|
33
|
-
const PAT_SCOPES = ['repo:read', 'repo:write', 'repo:admin'];
|
|
34
|
-
function stringFlag(flags, key) {
|
|
35
|
-
const value = flags[key];
|
|
36
|
-
if (value === undefined)
|
|
37
|
-
return undefined;
|
|
38
|
-
if (typeof value !== 'string')
|
|
39
|
-
throw new Error(`--${key} requires a value.`);
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
4
|
+
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
42
5
|
export const AUTH_USAGE = `usage:
|
|
43
|
-
seq-studio auth whoami -e <env> [--json]
|
|
44
|
-
seq-studio auth
|
|
45
|
-
|
|
46
|
-
seq-studio auth pat list -e <env>
|
|
47
|
-
seq-studio auth pat revoke <id> -e <env> [--yes]
|
|
48
|
-
|
|
49
|
-
Issue a personal access token for git clone / git push against the platform
|
|
50
|
-
git service.
|
|
51
|
-
|
|
52
|
-
Authenticate with \`seq-studio login\`, then run \`auth pat create -e <env>\`.
|
|
53
|
-
Alternatively, open Atlas → Settings → Tokens:
|
|
54
|
-
https://<atlas-host>/settings/tokens
|
|
55
|
-
Sign in, create a token (repo:read / repo:write), copy once, then:
|
|
56
|
-
export ATLAS_GIT_PAT=<token>
|
|
57
|
-
repo:write covers push and PR open; merging a PR requires an FGA Merge
|
|
58
|
-
(or Admin) grant on the repository, not a PAT scope.
|
|
59
|
-
|
|
60
|
-
On create the raw token is printed ONCE — store it; Atlas cannot re-show it.
|
|
61
|
-
Git Basic auth: any username (e.g. git), PAT as the password.
|
|
62
|
-
|
|
63
|
-
Flags: -e/--env <env> (required; see: seq-studio envs list)
|
|
6
|
+
seq-studio auth whoami -e <env> [--json]
|
|
7
|
+
seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>
|
|
8
|
+
Git authentication uses seq-studio login. repos clone installs the helper.
|
|
64
9
|
`;
|
|
65
|
-
async function authContext(args) {
|
|
66
|
-
if (args.flags.env === true || args.flags.e === true) {
|
|
67
|
-
throw new Error('-e/--env requires a value — see: seq-studio envs list.');
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
return await buildContext(args);
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
74
|
-
// Missing `-e` is actionable on its own — don't bury it under login/PAT
|
|
75
|
-
// setup advice (that wrap is for real auth/token failures).
|
|
76
|
-
if (message === REQUIRE_EXPLICIT_ENV_MESSAGE)
|
|
77
|
-
throw err;
|
|
78
|
-
// buildContext failed before we know the env URL; offer CLI login and
|
|
79
|
-
// render the tokens-page URLs from the environments visible to this
|
|
80
|
-
// identity (third-party / OpCo developers only see their own hosts).
|
|
81
|
-
const tokenUrls = await settingsTokensLines();
|
|
82
|
-
throw new Error(`${message}\n` +
|
|
83
|
-
` Run \`seq-studio login\`, then retry \`auth pat create\`.\n` +
|
|
84
|
-
` Or mint a PAT in the Atlas UI (Settings → Tokens), then:\n` +
|
|
85
|
-
` export ATLAS_GIT_PAT=<token>\n` +
|
|
86
|
-
tokenUrls.map((line) => ` ${line}`).join('\n'));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export function parsePatScopes(raw) {
|
|
90
|
-
if (raw === undefined || raw.trim() === '')
|
|
91
|
-
return ['repo:read'];
|
|
92
|
-
const parts = raw.split(',').map((s) => s.trim()).filter(Boolean);
|
|
93
|
-
if (parts.length === 0) {
|
|
94
|
-
throw new Error('--scopes requires at least one of: repo:read, repo:write, repo:admin');
|
|
95
|
-
}
|
|
96
|
-
const out = [];
|
|
97
|
-
for (const part of parts) {
|
|
98
|
-
if (!PAT_SCOPES.includes(part)) {
|
|
99
|
-
throw new Error(`unknown scope "${part}" — expected repo:read, repo:write, or repo:admin`);
|
|
100
|
-
}
|
|
101
|
-
// Deduplicate while preserving order.
|
|
102
|
-
if (!out.includes(part))
|
|
103
|
-
out.push(part);
|
|
104
|
-
}
|
|
105
|
-
return out;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Map UI-style duration choices to an absolute ISO-8601 expiresAt, or undefined
|
|
109
|
-
* for never. Matches Settings Tokens dialog choices.
|
|
110
|
-
*/
|
|
111
|
-
export function resolveExpiresAt(choice) {
|
|
112
|
-
if (choice === undefined || choice === 'never')
|
|
113
|
-
return undefined;
|
|
114
|
-
const now = Date.now();
|
|
115
|
-
const day = 24 * 60 * 60 * 1000;
|
|
116
|
-
const map = {
|
|
117
|
-
'1d': 1 * day,
|
|
118
|
-
'7d': 7 * day,
|
|
119
|
-
'30d': 30 * day,
|
|
120
|
-
'90d': 90 * day,
|
|
121
|
-
'1y': 365 * day,
|
|
122
|
-
};
|
|
123
|
-
const delta = map[choice];
|
|
124
|
-
if (delta === undefined) {
|
|
125
|
-
throw new Error(`--expires must be one of: 1d, 7d, 30d, 90d, 1y, never (got "${choice}")`);
|
|
126
|
-
}
|
|
127
|
-
return new Date(now + delta).toISOString();
|
|
128
|
-
}
|
|
129
|
-
export async function authPatCreateCommand(args) {
|
|
130
|
-
const name = stringFlag(args.flags, 'name');
|
|
131
|
-
if (!name) {
|
|
132
|
-
console.error('usage: seq-studio auth pat create --name <n> -e <env> [--scopes ...]');
|
|
133
|
-
return 1;
|
|
134
|
-
}
|
|
135
|
-
if (name.length < 3) {
|
|
136
|
-
throw new Error('--name must be at least 3 characters (e.g. laptop-cli)');
|
|
137
|
-
}
|
|
138
|
-
const scopes = parsePatScopes(stringFlag(args.flags, 'scopes'));
|
|
139
|
-
const expiresAt = resolveExpiresAt(stringFlag(args.flags, 'expires') ?? '30d');
|
|
140
|
-
const ctx = await authContext(args);
|
|
141
|
-
const issued = await postJson({
|
|
142
|
-
...clientOptions(ctx),
|
|
143
|
-
path: '/api/git-service/pats',
|
|
144
|
-
body: {
|
|
145
|
-
name,
|
|
146
|
-
scopes,
|
|
147
|
-
...(expiresAt ? { expiresAt } : {}),
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
console.log(`${LOG} issued PAT on ${ctx.env.name}:`);
|
|
151
|
-
console.log(` id: ${issued.id}`);
|
|
152
|
-
console.log(` name: ${issued.name}`);
|
|
153
|
-
console.log(` prefix: ${issued.tokenPrefix}`);
|
|
154
|
-
console.log(` scopes: ${issued.scopes.join(', ')}`);
|
|
155
|
-
console.log(` expires:${issued.expiresAt ? ` ${issued.expiresAt}` : ' never'}`);
|
|
156
|
-
console.log('');
|
|
157
|
-
console.log(' ── copy this token now; it will not be shown again ──');
|
|
158
|
-
console.log(` ${issued.token}`);
|
|
159
|
-
console.log(' ────────────────────────────────────────────────────');
|
|
160
|
-
console.log('');
|
|
161
|
-
console.log(' Git Basic auth: any username (e.g. git), this token as the password.');
|
|
162
|
-
console.log(` UI: ${settingsTokensUrl(ctx.env.url)}`);
|
|
163
|
-
console.log(` Clone with: ATLAS_GIT_PAT=<token> seq-studio repos clone <ns>/<name> -e ${ctx.env.name}`);
|
|
164
|
-
if (flagBool(args.flags, 'store-credentials')) {
|
|
165
|
-
// Store against the env origin so any repo under /api/git-service/repos/*
|
|
166
|
-
// can reuse the helper entry. Path is the git-service API prefix.
|
|
167
|
-
const credentialUrl = `${ctx.env.url.replace(/\/$/, '')}/api/git-service/repos/`;
|
|
168
|
-
try {
|
|
169
|
-
await storeGitCredentials({ cloneUrl: credentialUrl, pat: issued.token });
|
|
170
|
-
console.log(`${LOG} stored credentials via git credential approve for ${ctx.env.url}`);
|
|
171
|
-
}
|
|
172
|
-
catch (err) {
|
|
173
|
-
console.error(`${LOG} --store-credentials failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
174
|
-
console.error(`${LOG} token was still issued — copy it from above and store manually.`);
|
|
175
|
-
// Exit 0: the PAT exists; a non-zero exit would encourage retries that mint duplicates.
|
|
176
|
-
return 0;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return 0;
|
|
180
|
-
}
|
|
181
|
-
export async function authPatListCommand(args) {
|
|
182
|
-
const ctx = await authContext(args);
|
|
183
|
-
const data = await getJson({
|
|
184
|
-
...clientOptions(ctx),
|
|
185
|
-
path: '/api/git-service/pats',
|
|
186
|
-
});
|
|
187
|
-
if (data.items.length === 0) {
|
|
188
|
-
console.log(`${LOG} no PATs on ${ctx.env.name}.`);
|
|
189
|
-
for (const line of formatPatSetupHint({ envUrl: ctx.env.url, envName: ctx.env.name })) {
|
|
190
|
-
console.log(line);
|
|
191
|
-
}
|
|
192
|
-
return 0;
|
|
193
|
-
}
|
|
194
|
-
console.log(`${LOG} ${data.items.length} PAT${data.items.length === 1 ? '' : 's'} on ${ctx.env.name}:`);
|
|
195
|
-
const width = Math.max(...data.items.map((p) => p.name.length));
|
|
196
|
-
for (const pat of data.items) {
|
|
197
|
-
const expires = pat.expiresAt ? pat.expiresAt.slice(0, 10) : 'never';
|
|
198
|
-
const lastUsed = pat.lastUsedAt ? pat.lastUsedAt.slice(0, 10) : 'never';
|
|
199
|
-
console.log(` ${pat.name.padEnd(width)} ${pat.tokenPrefix}… ${pat.scopes.join(',')} expires=${expires} lastUsed=${lastUsed} id=${pat.id}`);
|
|
200
|
-
}
|
|
201
|
-
return 0;
|
|
202
|
-
}
|
|
203
|
-
export async function authPatRevokeCommand(args) {
|
|
204
|
-
const id = args.positional[0];
|
|
205
|
-
if (!id) {
|
|
206
|
-
console.error('usage: seq-studio auth pat revoke <id> -e <env> [--yes]');
|
|
207
|
-
return 1;
|
|
208
|
-
}
|
|
209
|
-
const ctx = await authContext(args);
|
|
210
|
-
const ok = await confirmYes({
|
|
211
|
-
preview: [
|
|
212
|
-
`${LOG} about to REVOKE PAT ${id} on ${ctx.env.name}.`,
|
|
213
|
-
`${LOG} any git clone/push using it will start failing immediately.`,
|
|
214
|
-
],
|
|
215
|
-
confirmed: flagBool(args.flags, 'yes'),
|
|
216
|
-
});
|
|
217
|
-
if (!ok)
|
|
218
|
-
return 1;
|
|
219
|
-
await deleteNoContent({
|
|
220
|
-
...clientOptions(ctx),
|
|
221
|
-
path: `/api/git-service/pats/${encodeURIComponent(id)}`,
|
|
222
|
-
});
|
|
223
|
-
console.log(`${LOG} revoked PAT ${id} on ${ctx.env.name}`);
|
|
224
|
-
return 0;
|
|
225
|
-
}
|
|
226
10
|
export async function runAuthCommand(sub, args) {
|
|
227
11
|
try {
|
|
228
12
|
if (wantsHelp({ sub, args })) {
|
|
@@ -230,6 +14,10 @@ export async function runAuthCommand(sub, args) {
|
|
|
230
14
|
return 0;
|
|
231
15
|
}
|
|
232
16
|
switch (sub) {
|
|
17
|
+
case 'git-credential': {
|
|
18
|
+
const { gitCredentialCommand } = await import('../repos/git-credential.js');
|
|
19
|
+
return await gitCredentialCommand(args);
|
|
20
|
+
}
|
|
233
21
|
case 'whoami': {
|
|
234
22
|
validateCommandInput({ args, flags: {}, positional: 0 });
|
|
235
23
|
const ctx = await buildContext(args);
|
|
@@ -240,31 +28,8 @@ export async function runAuthCommand(sub, args) {
|
|
|
240
28
|
}, null, 2));
|
|
241
29
|
return 0;
|
|
242
30
|
}
|
|
243
|
-
case 'pat':
|
|
244
|
-
|
|
245
|
-
const nested = {
|
|
246
|
-
positional: args.positional.slice(1),
|
|
247
|
-
flags: args.flags,
|
|
248
|
-
};
|
|
249
|
-
switch (action) {
|
|
250
|
-
case 'create':
|
|
251
|
-
return await authPatCreateCommand(nested);
|
|
252
|
-
case 'list':
|
|
253
|
-
return await authPatListCommand(nested);
|
|
254
|
-
case 'revoke':
|
|
255
|
-
return await authPatRevokeCommand(nested);
|
|
256
|
-
case 'help':
|
|
257
|
-
case '--help':
|
|
258
|
-
case '-h':
|
|
259
|
-
case undefined:
|
|
260
|
-
console.log(AUTH_USAGE);
|
|
261
|
-
return action ? 0 : 1;
|
|
262
|
-
default:
|
|
263
|
-
console.error(`unknown auth pat command: ${action}`);
|
|
264
|
-
console.error(AUTH_USAGE);
|
|
265
|
-
return 1;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
31
|
+
case 'pat':
|
|
32
|
+
throw new Error('Personal access tokens are retired. Run seq-studio login --env <environment>, then repos clone to configure Git.');
|
|
268
33
|
case 'help':
|
|
269
34
|
case '--help':
|
|
270
35
|
case '-h':
|
package/dist/auth.d.ts
CHANGED
|
@@ -31,6 +31,17 @@ export declare const AUTH0_AUDIENCE = "https://api.studio.com";
|
|
|
31
31
|
/** The realm name the built-in Sequence environments' tokens live under —
|
|
32
32
|
* also the implicit realm of the legacy flat fields in tokens.json. */
|
|
33
33
|
export declare const SEQUENCE_REALM = "sequence";
|
|
34
|
+
/**
|
|
35
|
+
* Reserved names for first-party deployments on the shared Sequence login
|
|
36
|
+
* (every built-in name except `local`). `envs add` saves them to config.toml
|
|
37
|
+
* after confirming the deployment really uses that login.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isSharedLoginDeploymentName(envName: string): boolean;
|
|
40
|
+
/** Whether a deployment's advertised Auth0 client is the shared Sequence login. */
|
|
41
|
+
export declare function usesSharedSequenceLogin({ clientId, audience }: {
|
|
42
|
+
clientId: string;
|
|
43
|
+
audience: string;
|
|
44
|
+
}): boolean;
|
|
34
45
|
export declare function isSequenceAuthEnvName(envName: string): boolean;
|
|
35
46
|
/**
|
|
36
47
|
* One Auth0 login context. Mirrors seqapi's `AuthRealm`
|
|
@@ -103,6 +114,12 @@ export declare class NotLoggedInError extends Error {
|
|
|
103
114
|
*/
|
|
104
115
|
export declare class UnsafeAuthTargetError extends Error {
|
|
105
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Run `fn` without opening a browser login: a missing or expired session
|
|
119
|
+
* raises `NotLoggedInError` instead. For commands such as `deploy --dry-run`
|
|
120
|
+
* that must never sign anyone in as a side effect.
|
|
121
|
+
*/
|
|
122
|
+
export declare function withoutAutoLogin<T>(fn: () => Promise<T>): Promise<T>;
|
|
106
123
|
export type AuthMode = 'm2m' | 'user';
|
|
107
124
|
export interface ResolvedAccessToken {
|
|
108
125
|
authMode: AuthMode;
|