@sequenceholdings/studio-cli 0.5.1 → 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 +86 -36
- 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 +57 -19
- 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 +17 -14
- 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 +31 -18
- 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/auth.d.ts +17 -0
- package/dist/auth.js +29 -0
- 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.js +1 -1
- package/dist/orm/delegate.js +5 -2
- package/dist/pipeline/clone-deploy.d.ts +1 -1
- package/dist/pipeline/clone-deploy.js +3 -2
- package/dist/pipeline/commands.js +3 -2
- package/dist/process/commands.d.ts +6 -3
- package/dist/process/commands.js +26 -10
- package/dist/repos/commands.js +1 -1
- package/dist/repos/pulls.d.ts +19 -1
- package/dist/repos/pulls.js +15 -2
- package/dist/templates/process/example-process/process.ts +2 -0
- package/dist/templates/process/package.json +1 -1
- package/package.json +8 -7
- package/templates/process/example-process/process.ts +2 -0
- package/templates/process/package.json +1 -1
package/dist/app/manifest.js
CHANGED
|
@@ -53,7 +53,7 @@ const primitiveEntrySchema = z
|
|
|
53
53
|
project_id: z.string().min(1).optional(),
|
|
54
54
|
target: z.string().min(1).optional(),
|
|
55
55
|
only: z.array(z.string().min(1)).min(1).optional(),
|
|
56
|
-
repo: z.string().regex(/^
|
|
56
|
+
repo: z.string().regex(/^[a-z][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/, 'repo must be <namespace>/<name>').optional(),
|
|
57
57
|
ref: z.string().min(1).refine((ref) => !ref.startsWith('-'), 'ref cannot start with -').optional(),
|
|
58
58
|
})
|
|
59
59
|
.strict()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official artifact deploys need committed, clean source on `main` (or
|
|
3
|
+
* `staging` for a staging target). A dry-run deploys nothing, so there it
|
|
4
|
+
* reports what a real deploy would refuse instead of failing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function checkOfficialArtifactSource({ dir, env, dryRun, }: {
|
|
7
|
+
dir: string;
|
|
8
|
+
env: string;
|
|
9
|
+
dryRun?: boolean;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ActiveDeployPolicyError, assertActiveDeployProvenance, } from '@sequenceholdings/artifact-studio/active-deploy-policy';
|
|
2
|
+
import { localGitMetadata } from '@sequenceholdings/artifact-studio/source-resolver';
|
|
3
|
+
const LOG = '[seq-studio]';
|
|
4
|
+
/**
|
|
5
|
+
* Official artifact deploys need committed, clean source on `main` (or
|
|
6
|
+
* `staging` for a staging target). A dry-run deploys nothing, so there it
|
|
7
|
+
* reports what a real deploy would refuse instead of failing.
|
|
8
|
+
*/
|
|
9
|
+
export function checkOfficialArtifactSource({ dir, env, dryRun = false, }) {
|
|
10
|
+
const provenance = localGitMetadata(dir);
|
|
11
|
+
try {
|
|
12
|
+
if (!provenance.gitCommit) {
|
|
13
|
+
throw new ActiveDeployPolicyError(`${dir} is not in a git repository with a commit. Official artifact deploys need committed ` +
|
|
14
|
+
'source on `main`: run `git init`, commit, then deploy, or use a preview deploy.');
|
|
15
|
+
}
|
|
16
|
+
assertActiveDeployProvenance({ ...provenance, environment: env });
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (!dryRun || !(error instanceof ActiveDeployPolicyError))
|
|
20
|
+
throw error;
|
|
21
|
+
console.warn(`${LOG} dry-run: a real deploy to ${env} would refuse: ${error.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AppManifest } from './manifest.js';
|
|
2
|
+
export type CommandRunner = (args: {
|
|
3
|
+
command: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
cwd: string;
|
|
6
|
+
}) => Promise<number>;
|
|
7
|
+
export type OrmRunner = (sub: string, rest: string[]) => Promise<number>;
|
|
8
|
+
/** The app root plus every primitive that keeps its own install root (a hosted Next.js artifact). */
|
|
9
|
+
export declare function installRoots({ appRoot, manifest }: {
|
|
10
|
+
appRoot: string;
|
|
11
|
+
manifest: AppManifest;
|
|
12
|
+
}): string[];
|
|
13
|
+
export declare class AppPreparationError extends Error {
|
|
14
|
+
readonly remaining: readonly string[];
|
|
15
|
+
constructor(message: string, remaining: readonly string[]);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Install dependencies, then generate each ORM namespace and author its first
|
|
19
|
+
* migration. On failure the scaffold stays in place; the error lists the
|
|
20
|
+
* commands still to run.
|
|
21
|
+
*/
|
|
22
|
+
export declare function prepareScaffoldedApp({ appRoot, manifest, run, orm, }: {
|
|
23
|
+
appRoot: string;
|
|
24
|
+
manifest: AppManifest;
|
|
25
|
+
run?: CommandRunner;
|
|
26
|
+
orm?: OrmRunner;
|
|
27
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make a fresh scaffold CI-ready: repository CI installs with
|
|
3
|
+
* `pnpm install --frozen-lockfile --offline`, so every install root needs a
|
|
4
|
+
* committed lockfile, and an ORM namespace deploys its committed migration.
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
const runCommand = ({ command, args, cwd }) => new Promise((resolvePromise, reject) => {
|
|
10
|
+
const child = spawn(command, args, { cwd, stdio: 'inherit', shell: false });
|
|
11
|
+
child.once('error', reject);
|
|
12
|
+
child.once('exit', (code) => resolvePromise(code ?? 1));
|
|
13
|
+
});
|
|
14
|
+
const runOrm = async (sub, rest) => {
|
|
15
|
+
const { runOrmCommand } = await import('../orm/delegate.js');
|
|
16
|
+
return runOrmCommand(sub, rest);
|
|
17
|
+
};
|
|
18
|
+
/** The app root plus every primitive that keeps its own install root (a hosted Next.js artifact). */
|
|
19
|
+
export function installRoots({ appRoot, manifest }) {
|
|
20
|
+
const standalone = manifest.primitives
|
|
21
|
+
.map((entry) => join(appRoot, entry.path))
|
|
22
|
+
.filter((directory) => existsSync(join(directory, 'pnpm-workspace.yaml')));
|
|
23
|
+
return [appRoot, ...standalone];
|
|
24
|
+
}
|
|
25
|
+
export class AppPreparationError extends Error {
|
|
26
|
+
remaining;
|
|
27
|
+
constructor(message, remaining) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.remaining = remaining;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Install dependencies, then generate each ORM namespace and author its first
|
|
34
|
+
* migration. On failure the scaffold stays in place; the error lists the
|
|
35
|
+
* commands still to run.
|
|
36
|
+
*/
|
|
37
|
+
export async function prepareScaffoldedApp({ appRoot, manifest, run = runCommand, orm = runOrm, }) {
|
|
38
|
+
const roots = installRoots({ appRoot, manifest });
|
|
39
|
+
const namespaces = manifest.primitives.filter((entry) => entry.kind === 'orm').map((entry) => join(appRoot, entry.path));
|
|
40
|
+
const steps = [
|
|
41
|
+
...roots.map((cwd) => ({ label: `pnpm install (in ${cwd})`, perform: () => run({ command: 'pnpm', args: ['install'], cwd }) })),
|
|
42
|
+
...namespaces.flatMap((directory) => [
|
|
43
|
+
{ label: `seq-studio orm generate ${directory}`, perform: () => orm('generate', [directory]) },
|
|
44
|
+
{ label: `seq-studio orm diff ${directory}`, perform: () => orm('diff', [directory]) },
|
|
45
|
+
]),
|
|
46
|
+
];
|
|
47
|
+
for (const [index, step] of steps.entries()) {
|
|
48
|
+
let code;
|
|
49
|
+
try {
|
|
50
|
+
code = await step.perform();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new AppPreparationError(`${step.label} could not start: ${error instanceof Error ? error.message : String(error)}`, steps.slice(index).map((item) => item.label));
|
|
54
|
+
}
|
|
55
|
+
if (code !== 0)
|
|
56
|
+
throw new AppPreparationError(`${step.label} failed (exit ${code})`, steps.slice(index).map((item) => item.label));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PrimitiveKind } from './manifest.js';
|
|
2
|
+
/** `name` plus its kind's suffix, unless the name already ends with it (`ui` stays `ui`, not `ui-ui`). */
|
|
3
|
+
export declare function primitiveIdFor({ kind, name }: {
|
|
4
|
+
kind: PrimitiveKind;
|
|
5
|
+
name: string;
|
|
6
|
+
}): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const PRIMITIVE_ID_SUFFIX = {
|
|
2
|
+
orm: 'orm',
|
|
3
|
+
artifact: 'ui',
|
|
4
|
+
function: null,
|
|
5
|
+
agent: 'agent',
|
|
6
|
+
process: 'process',
|
|
7
|
+
pipeline: 'pipeline',
|
|
8
|
+
workspace: 'workspace',
|
|
9
|
+
};
|
|
10
|
+
/** `name` plus its kind's suffix, unless the name already ends with it (`ui` stays `ui`, not `ui-ui`). */
|
|
11
|
+
export function primitiveIdFor({ kind, name }) {
|
|
12
|
+
const suffix = PRIMITIVE_ID_SUFFIX[kind];
|
|
13
|
+
if (!suffix || name === suffix || name.endsWith(`-${suffix}`))
|
|
14
|
+
return name;
|
|
15
|
+
return `${name}-${suffix}`;
|
|
16
|
+
}
|
|
@@ -2,10 +2,6 @@ import { type PrimitiveEntry, type PrimitiveKind } from './manifest.js';
|
|
|
2
2
|
export type AppPipelineType = 'ingestion' | 'transformation' | 'serving';
|
|
3
3
|
/** Same templates as `seq-studio artifact init --template`. */
|
|
4
4
|
export type AppArtifactTemplate = 'react-vite' | 'nextjs';
|
|
5
|
-
export declare function primitiveIdFor({ kind, name }: {
|
|
6
|
-
kind: PrimitiveKind;
|
|
7
|
-
name: string;
|
|
8
|
-
}): string;
|
|
9
5
|
export declare function relativePathFor({ kind, appId, name, }: {
|
|
10
6
|
kind: PrimitiveKind;
|
|
11
7
|
appId: string;
|
|
@@ -7,21 +7,7 @@ import { initCommand as processInitCommand, parseArgs } from '../process/command
|
|
|
7
7
|
import { agentsInitCommand } from '../agents/scaffold.js';
|
|
8
8
|
import { pipelineInitCommand } from '../pipeline/commands.js';
|
|
9
9
|
import { ormNamespaceFromAppId, titleizeSlug } from './manifest.js';
|
|
10
|
-
|
|
11
|
-
switch (kind) {
|
|
12
|
-
case 'orm':
|
|
13
|
-
return `${name}-orm`;
|
|
14
|
-
case 'artifact':
|
|
15
|
-
return `${name}-ui`;
|
|
16
|
-
case 'function':
|
|
17
|
-
return name;
|
|
18
|
-
case 'agent':
|
|
19
|
-
case 'process':
|
|
20
|
-
case 'pipeline':
|
|
21
|
-
case 'workspace':
|
|
22
|
-
return `${name}-${kind}`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
10
|
+
import { primitiveIdFor } from './primitive-ids.js';
|
|
25
11
|
export function relativePathFor({ kind, appId, name, }) {
|
|
26
12
|
switch (kind) {
|
|
27
13
|
case 'orm':
|
|
@@ -53,8 +39,11 @@ function buildPrimitiveEntry({ kind, appId, name, dependsOn, }) {
|
|
|
53
39
|
return { ...base, project_id: name };
|
|
54
40
|
case 'workspace':
|
|
55
41
|
return { ...base, name };
|
|
56
|
-
case 'agent':
|
|
57
42
|
case 'process':
|
|
43
|
+
// `process init` names the scaffolded process after its directory. Naming it
|
|
44
|
+
// here gives CI one exact process to register as an Application member.
|
|
45
|
+
return { ...base, only: [name] };
|
|
46
|
+
case 'agent':
|
|
58
47
|
case 'pipeline':
|
|
59
48
|
return base;
|
|
60
49
|
}
|
|
@@ -87,8 +76,8 @@ async function scaffoldOrm({ absPath }) {
|
|
|
87
76
|
const code = await runOrmCommand('init', [absPath]);
|
|
88
77
|
if (code !== 0) {
|
|
89
78
|
throw new Error(`orm init failed for ${absPath} (exit ${code}). ` +
|
|
90
|
-
'`seq-studio init --with orm` requires `@sequenceholdings/orm` ' +
|
|
91
|
-
'(
|
|
79
|
+
'`seq-studio init --with orm` requires `@sequenceholdings/orm` installed alongside the CLI ' +
|
|
80
|
+
'(`pnpm add -D @sequenceholdings/orm` in your app, then `pnpm exec seq-studio`).');
|
|
92
81
|
}
|
|
93
82
|
}
|
|
94
83
|
async function scaffoldArtifact({ absPath, appId, template, }) {
|
package/dist/app/readme.js
CHANGED
|
@@ -112,27 +112,30 @@ seq-studio login --env <environment-name>
|
|
|
112
112
|
seq-studio doctor -e <environment-name>
|
|
113
113
|
\`\`\`
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
For a fullstack app, scaffold with \`seq-studio init <app> --
|
|
118
|
-
Its Next.js artifact uses Node.js 24 and a separate install root
|
|
119
|
-
|
|
120
|
-
\`
|
|
121
|
-
|
|
122
|
-
output for the managed runtime. Run \`seq-studio repos ci init\`, commit the generated
|
|
123
|
-
\`.seq/pipeline.yml\`, and open or update a pull request to run checks with the
|
|
124
|
-
platform's managed defaults. \`sequence.app.yml\` supplies the resource inventory;
|
|
125
|
-
the pipeline needs no image digest or manual branch policy. Inspect the plan with
|
|
126
|
-
\`seq-studio repos ci show <namespace>/<repo> -e <environment> --pr <number>\`.
|
|
127
|
-
Deployment still needs authorized resource bindings and native permissions.
|
|
115
|
+
\`seq-studio init\` runs \`pnpm install\` for you and generates the first ORM migration. Commit the generated root \`pnpm-lock.yaml\` and \`migrations/\`; CI uses \`pnpm install --frozen-lockfile\`. App scaffolding consolidates the standalone templates' install configuration at the root. The root workspace retains the seven-day dependency age gate and explicit build-script allowlist.
|
|
116
|
+
|
|
117
|
+
For a fullstack app, scaffold with \`seq-studio init <app> --template nextjs\`.
|
|
118
|
+
Its Next.js artifact uses Node.js 24 and a separate install root with its own
|
|
119
|
+
\`artifact/pnpm-lock.yaml\` (also generated by \`init\`). Keep its \`lint\`, \`type-check\`,
|
|
120
|
+
\`test\` and \`build\` scripts; repository CI runs them and an SSR/API smoke test before
|
|
121
|
+
packaging the standalone output for the managed runtime.
|
|
128
122
|
Build-time values belong in \`build.public_env\` and must use \`NEXT_PUBLIC_*\` names.
|
|
129
123
|
Server secrets and resource credentials are attached only at runtime.
|
|
130
124
|
|
|
125
|
+
## Ship it: pull request → checks → merge → live
|
|
126
|
+
|
|
127
|
+
Inside a git-service repository (\`seq-studio repos create\` turns on deploy-on-merge for \`main\`),
|
|
128
|
+
push a branch and open a pull request. Checks run automatically; the pull request lists
|
|
129
|
+
what merging will create or update. Merging to \`main\` creates any new ORM namespace,
|
|
130
|
+
function, artifact and Lattice process as the person who merges, then deploys every change.
|
|
131
|
+
Nothing needs configuring in repository settings. Inspect a plan with
|
|
132
|
+
\`seq-studio repos ci show <namespace>/<repo> -e <environment> --pr <number>\`.
|
|
133
|
+
|
|
131
134
|
Use the environment name your administrator supplies. \`local\` means a real Atlas server at \`http://localhost:5001\`, not a standalone Vite server. Login proves identity; resource permissions are still required. ORM and pipeline commands require the matching \`@sequenceholdings/orm\` / \`@sequenceholdings/pipeline-spec\` SDK installed alongside the CLI.
|
|
132
135
|
|
|
133
136
|
## Shared packages
|
|
134
137
|
|
|
135
|
-
Export common types, validation, and helpers from \`packages/shared/src/index.ts\`.
|
|
138
|
+
Export common types, validation, and helpers from \`packages/shared/src/index.ts\`. Artifacts and processes depend on \`@${input.appId}/shared\` through \`workspace:*\`; ordinary imports work across the app. A function's dependencies ship as-is and a deployed bundle cannot follow a \`workspace:*\` link, so functions don't get one by default:
|
|
136
139
|
|
|
137
140
|
\`\`\`ts
|
|
138
141
|
import { /* your exports */ } from '@${input.appId}/shared'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const REPOSITORY_INDEX_PATH = ".seq/repository.yml";
|
|
2
|
+
/** One write to perform after the scaffold succeeds; validated before it starts. */
|
|
3
|
+
export interface RepositoryDeclaration {
|
|
4
|
+
indexPath: string;
|
|
5
|
+
appPath: string;
|
|
6
|
+
content: string;
|
|
7
|
+
created: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Plan the index change for an app about to be scaffolded at `appRoot`.
|
|
11
|
+
* Returns null when nothing needs declaring: no enclosing git repository, an
|
|
12
|
+
* app at the root of a repository without an index, or an app already listed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function planRepositoryDeclaration({ appRoot }: {
|
|
15
|
+
appRoot: string;
|
|
16
|
+
}): Promise<RepositoryDeclaration | null>;
|
|
17
|
+
export declare function writeRepositoryDeclaration({ declaration }: {
|
|
18
|
+
declaration: RepositoryDeclaration;
|
|
19
|
+
}): Promise<void>;
|
|
@@ -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';
|
|
@@ -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']) {
|
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;
|
package/dist/auth.js
CHANGED
|
@@ -70,6 +70,18 @@ const TRUSTED_LOOPBACK_AUTH0_AUDIENCES = new Set([
|
|
|
70
70
|
AUTH0_AUDIENCE,
|
|
71
71
|
SEQUENCE_STAGING_AUTH0_AUDIENCE,
|
|
72
72
|
]);
|
|
73
|
+
/**
|
|
74
|
+
* Reserved names for first-party deployments on the shared Sequence login
|
|
75
|
+
* (every built-in name except `local`). `envs add` saves them to config.toml
|
|
76
|
+
* after confirming the deployment really uses that login.
|
|
77
|
+
*/
|
|
78
|
+
export function isSharedLoginDeploymentName(envName) {
|
|
79
|
+
return envName !== 'local' && SEQUENCE_BUILTIN_ENVS.has(envName);
|
|
80
|
+
}
|
|
81
|
+
/** Whether a deployment's advertised Auth0 client is the shared Sequence login. */
|
|
82
|
+
export function usesSharedSequenceLogin({ clientId, audience }) {
|
|
83
|
+
return clientId === AUTH0_CLIENT_ID && audience === AUTH0_AUDIENCE;
|
|
84
|
+
}
|
|
73
85
|
export function isSequenceAuthEnvName(envName) {
|
|
74
86
|
return (envName === SEQUENCE_REALM ||
|
|
75
87
|
SEQUENCE_BUILTIN_ENVS.has(envName) ||
|
|
@@ -406,10 +418,27 @@ export class NotLoggedInError extends Error {
|
|
|
406
418
|
export class UnsafeAuthTargetError extends Error {
|
|
407
419
|
}
|
|
408
420
|
const AUTO_LOGIN_TIMEOUT_MS = 120_000;
|
|
421
|
+
let autoLoginSuppressed = 0;
|
|
409
422
|
function autoLoginEnabled() {
|
|
423
|
+
if (autoLoginSuppressed > 0)
|
|
424
|
+
return false;
|
|
410
425
|
const value = process.env.SEQAPI_AUTO_LOGIN?.trim().toLowerCase() ?? '1';
|
|
411
426
|
return !['0', 'false', 'no', 'off'].includes(value);
|
|
412
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* Run `fn` without opening a browser login: a missing or expired session
|
|
430
|
+
* raises `NotLoggedInError` instead. For commands such as `deploy --dry-run`
|
|
431
|
+
* that must never sign anyone in as a side effect.
|
|
432
|
+
*/
|
|
433
|
+
export async function withoutAutoLogin(fn) {
|
|
434
|
+
autoLoginSuppressed += 1;
|
|
435
|
+
try {
|
|
436
|
+
return await fn();
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
autoLoginSuppressed -= 1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
413
442
|
function autoLoginTimeoutMs() {
|
|
414
443
|
const raw = process.env.SEQAPI_AUTO_LOGIN_TIMEOUT?.trim();
|
|
415
444
|
if (!raw)
|