@sequenceholdings/studio-cli 1.0.0 → 1.0.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 +3 -2
- package/dist/access/custom-role-hosts.js +8 -6
- package/dist/app/manifest-validation.js +4 -2
- package/dist/app/manifest.d.ts +2 -0
- package/dist/app/manifest.js +2 -0
- package/dist/app/paths.js +3 -0
- package/dist/app-preview/bundle-dependencies.d.ts +52 -0
- package/dist/app-preview/bundle-dependencies.js +121 -0
- package/dist/app-preview/commands.d.ts +2 -5
- package/dist/app-preview/commands.js +57 -62
- package/dist/app-preview/fork-setup.d.ts +66 -0
- package/dist/app-preview/fork-setup.js +123 -0
- package/dist/app-preview/fork.d.ts +171 -0
- package/dist/app-preview/fork.js +279 -0
- package/dist/app-preview/install.d.ts +23 -2
- package/dist/app-preview/install.js +67 -6
- package/dist/app-preview/orm-sdk.d.ts +31 -0
- package/dist/app-preview/orm-sdk.js +16 -0
- package/dist/app-preview/plan.d.ts +2 -0
- package/dist/app-preview/plan.js +2 -2
- package/dist/app-preview/report.d.ts +30 -0
- package/dist/app-preview/report.js +80 -0
- package/dist/app-preview/repository-manifest.d.ts +83 -0
- package/dist/app-preview/repository-manifest.js +179 -0
- package/dist/app-preview/runners.d.ts +14 -0
- package/dist/app-preview/runners.js +83 -23
- package/dist/app-preview/session-output.d.ts +5 -0
- package/dist/app-preview/session-output.js +28 -0
- package/dist/app-preview/source-includes.d.ts +12 -0
- package/dist/app-preview/source-includes.js +74 -0
- package/dist/app-preview/target.d.ts +8 -0
- package/dist/app-preview/target.js +4 -1
- package/dist/app-preview/usage.d.ts +7 -0
- package/dist/app-preview/usage.js +57 -0
- package/dist/envs/commands.js +2 -1
- package/dist/login.js +1 -1
- package/dist/orm/break-glass.d.ts +15 -0
- package/dist/orm/break-glass.js +22 -0
- package/dist/orm/delegate.js +10 -8
- package/dist/orm/version-guard.d.ts +6 -2
- package/dist/orm/version-guard.js +27 -7
- package/dist/registry/help.js +5 -6
- package/dist/repos/github-init.js +4 -1
- package/dist/repos/primitive-declaration.d.ts +27 -0
- package/dist/repos/primitive-declaration.js +22 -6
- package/dist/repos/seq-ci-release.d.ts +10 -0
- package/dist/repos/seq-ci-release.js +27 -0
- package/dist/sdk-source.d.ts +15 -0
- package/dist/sdk-source.js +30 -11
- package/package.json +5 -5
- package/release-summary.json +3 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The steps `seq-studio preview` adds on a devbox whose database is a copy of a hosted
|
|
3
|
+
* deployment's: decide them (`planFork`), run them before anything starts (`setUpFork`), and start
|
|
4
|
+
* the Next.js session with the chosen secret source. `fork.ts` holds the decisions and requests.
|
|
5
|
+
*/
|
|
6
|
+
import { UsageError } from '../exit-codes.js';
|
|
7
|
+
import { LOG } from '../prompt.js';
|
|
8
|
+
import { adoptDeclaredWorkspaces, admitProjectIdentities, bindingPruneReport, chooseSecretSource, declaredServerSecretNames, declaredWorkspaceNames, identityAdmissionReport, pruneStaleDevelopmentBindings, resolveUpstream, workspaceAdoptionReport, } from './fork.js';
|
|
9
|
+
/** Whether the session's secrets are read from the fork source, by default or by request. */
|
|
10
|
+
const readsUpstream = (source) => source?.args[1] === 'upstream';
|
|
11
|
+
function flagText(value, flag) {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
if (typeof value !== 'string' || !value)
|
|
15
|
+
throw new UsageError(`${flag} requires a value`);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
export async function planFork({ ctx, flags, artifacts, workspaces = [], next }) {
|
|
19
|
+
const fork = ctx.target.fork;
|
|
20
|
+
const declared = [...workspaces, ...artifacts.flatMap((artifact) => declaredWorkspaceNames(artifact.bundle))];
|
|
21
|
+
const workspaceNames = fork ? [...new Set(declared)].sort() : [];
|
|
22
|
+
const secretNames = next ? declaredServerSecretNames(next.bundle) : [];
|
|
23
|
+
const secretSource = next
|
|
24
|
+
? chooseSecretSource({
|
|
25
|
+
requested: flagText(flags['secret-source'], '--secret-source'),
|
|
26
|
+
requestedUpstream: flagText(flags['secret-upstream'], '--secret-upstream'),
|
|
27
|
+
secretNames,
|
|
28
|
+
fork,
|
|
29
|
+
upstream: await resolveUpstream(fork),
|
|
30
|
+
})
|
|
31
|
+
: undefined;
|
|
32
|
+
const handled = new Set([
|
|
33
|
+
...(workspaceNames.length ? ['storage'] : []),
|
|
34
|
+
...(readsUpstream(secretSource) ? ['secret'] : []),
|
|
35
|
+
...(fork && next ? ['service-account'] : []),
|
|
36
|
+
]);
|
|
37
|
+
return { fork, workspaceNames, next, secretNames, secretSource, secretArgs: secretSource?.args ?? [], handled };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Before anything starts on a devbox fork: adopt the declared workspaces from the database copy,
|
|
41
|
+
* admit the identities the copied Next.js project records, and drop the development bindings it
|
|
42
|
+
* records for resources the application no longer declares. None failing stops the preview; each
|
|
43
|
+
* says what it left undone, and the session start then reports the same gap by name.
|
|
44
|
+
*/
|
|
45
|
+
export async function setUpFork({ ctx, plan, say }) {
|
|
46
|
+
if (!plan.fork)
|
|
47
|
+
return undefined;
|
|
48
|
+
const failed = (error) => ({ ok: false, reason: error instanceof Error ? error.message : String(error) });
|
|
49
|
+
let workspaces = null;
|
|
50
|
+
if (plan.workspaceNames.length) {
|
|
51
|
+
workspaces = await adoptDeclaredWorkspaces({ ctx, names: plan.workspaceNames }).catch(failed);
|
|
52
|
+
for (const line of workspaceAdoptionReport({ outcome: workspaces, names: plan.workspaceNames }))
|
|
53
|
+
say(`${LOG} ${line}`);
|
|
54
|
+
}
|
|
55
|
+
let identities = null;
|
|
56
|
+
if (plan.next) {
|
|
57
|
+
const projectSlug = plan.next.projectId;
|
|
58
|
+
identities = await admitProjectIdentities({ ctx, projectSlug }).catch(failed);
|
|
59
|
+
for (const line of identityAdmissionReport({ outcome: identities, projectSlug }))
|
|
60
|
+
say(`${LOG} ${line}`);
|
|
61
|
+
}
|
|
62
|
+
let bindings = null;
|
|
63
|
+
if (plan.next) {
|
|
64
|
+
const projectSlug = plan.next.projectId;
|
|
65
|
+
bindings = await pruneStaleDevelopmentBindings({ ctx, projectSlug, bundle: plan.next.bundle }).catch(failed);
|
|
66
|
+
for (const line of bindingPruneReport({ outcome: bindings, projectSlug }))
|
|
67
|
+
say(`${LOG} ${line}`);
|
|
68
|
+
}
|
|
69
|
+
return { workspaces, identities, bindings };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What is still left to the operator once the fork steps have run: the result document lists a
|
|
73
|
+
* prerequisite unless this run really satisfied it. A workspace that was not adopted, secrets no
|
|
74
|
+
* source supplies, and identities that were not admitted all stay listed.
|
|
75
|
+
*/
|
|
76
|
+
export function outstandingPrerequisites({ prerequisites, plan, setup }) {
|
|
77
|
+
const adopted = new Set(setup?.workspaces?.ok
|
|
78
|
+
? setup.workspaces.adoption.workspaces.filter((workspace) => workspace.status === 'adopted' || workspace.status === 'already_adopted').map((workspace) => workspace.name)
|
|
79
|
+
: []);
|
|
80
|
+
const identities = setup?.identities;
|
|
81
|
+
const admitted = identities?.ok === true && identities.admission.ingress.every((entry) => entry.status !== 'skipped');
|
|
82
|
+
return prerequisites.filter((line) => {
|
|
83
|
+
if (line.kind === 'storage')
|
|
84
|
+
return !adopted.has(line.name);
|
|
85
|
+
if (line.kind === 'secret')
|
|
86
|
+
return !readsUpstream(plan.secretSource);
|
|
87
|
+
if (line.kind === 'service-account')
|
|
88
|
+
return !admitted;
|
|
89
|
+
return true;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** The `fork` member of the `--json` result, on a devbox fork only. Names and statuses; a secret value never reaches this command. */
|
|
93
|
+
export function forkResult({ plan, setup }) {
|
|
94
|
+
if (!plan.fork)
|
|
95
|
+
return {};
|
|
96
|
+
return {
|
|
97
|
+
fork: {
|
|
98
|
+
upstreamEnvironment: plan.fork.upstreamEnvironment,
|
|
99
|
+
workspaces: setup?.workspaces ?? null,
|
|
100
|
+
identities: setup?.identities ?? null,
|
|
101
|
+
developmentBindings: setup?.bindings ?? null,
|
|
102
|
+
secrets: plan.secretSource ? { source: plan.secretSource.source, names: plan.secretNames } : null,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Reading secrets from the fork source is implemented by this CLI's own Artifact Studio. A
|
|
108
|
+
* repository that runs its installed copy instead may predate it, so that one session uses the
|
|
109
|
+
* bundled copy. An explicit `--sdk` or SEQ_STUDIO_SDK is left alone, as everywhere else.
|
|
110
|
+
*/
|
|
111
|
+
export async function runNextSession({ run, dir, upstream }) {
|
|
112
|
+
const { SDK_ENV, sdkMode } = await import('../sdk-source.js');
|
|
113
|
+
if (!upstream || process.env[SDK_ENV]?.trim() || (await sdkMode({ cwd: dir })) !== 'project')
|
|
114
|
+
return run();
|
|
115
|
+
console.error(`${LOG} this repository runs its own installed Artifact Studio; this session uses the CLI's bundled copy, which can read secrets from the fork source`);
|
|
116
|
+
process.env[SDK_ENV] = 'bundled';
|
|
117
|
+
try {
|
|
118
|
+
return await run();
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
delete process.env[SDK_ENV];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a preview does on a devbox whose database is a copy of a hosted deployment's ("fork"): the
|
|
3
|
+
* local Atlas says so in its runtime report. A database copy carries platform rows but not what
|
|
4
|
+
* lives outside the database, so before a Next.js session starts the preview asks the local Atlas
|
|
5
|
+
* to adopt the workspaces the app declares and to admit the service identities the copied project
|
|
6
|
+
* records, and chooses where the session's server secrets come from.
|
|
7
|
+
*
|
|
8
|
+
* Decisions are pure functions here; `commands.ts` prints them and runs the session.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import type { PreviewContext } from './runners.js';
|
|
12
|
+
/** Every workspace a bundle declares by name (browser, server and each external ingress); ids are not names. */
|
|
13
|
+
export declare function declaredWorkspaceNames(bundle: unknown): string[];
|
|
14
|
+
/** The server.secrets a bundle declares, by environment name. */
|
|
15
|
+
export declare function declaredServerSecretNames(bundle: unknown): string[];
|
|
16
|
+
declare const adoptionSchema: z.ZodObject<{
|
|
17
|
+
environment: z.ZodString;
|
|
18
|
+
sourceEnvironment: z.ZodString;
|
|
19
|
+
bytes: z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
unavailable: "unavailable";
|
|
21
|
+
available: "available";
|
|
22
|
+
}>>;
|
|
23
|
+
workspaces: z.ZodArray<z.ZodObject<{
|
|
24
|
+
name: z.ZodString;
|
|
25
|
+
status: z.ZodEnum<{
|
|
26
|
+
adopted: "adopted";
|
|
27
|
+
already_adopted: "already_adopted";
|
|
28
|
+
not_found: "not_found";
|
|
29
|
+
forbidden: "forbidden";
|
|
30
|
+
}>;
|
|
31
|
+
id: z.ZodOptional<z.ZodString>;
|
|
32
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, z.core.$loose>>;
|
|
34
|
+
}, z.core.$loose>;
|
|
35
|
+
export type WorkspaceAdoption = z.infer<typeof adoptionSchema>;
|
|
36
|
+
export type WorkspaceAdoptionOutcome = {
|
|
37
|
+
ok: true;
|
|
38
|
+
adoption: WorkspaceAdoption;
|
|
39
|
+
}
|
|
40
|
+
/** The local Atlas has no adoption route, or refused: names resolve only if the workspaces already exist there. */
|
|
41
|
+
| {
|
|
42
|
+
ok: false;
|
|
43
|
+
reason: string;
|
|
44
|
+
};
|
|
45
|
+
/** Ask the local Atlas to re-home the declared workspaces from the database copy. Names only. */
|
|
46
|
+
export declare function adoptDeclaredWorkspaces({ ctx, names }: {
|
|
47
|
+
ctx: PreviewContext;
|
|
48
|
+
names: readonly string[];
|
|
49
|
+
}): Promise<WorkspaceAdoptionOutcome>;
|
|
50
|
+
/** One line per declared workspace, then what the fork can and cannot do with their files. */
|
|
51
|
+
export declare function workspaceAdoptionReport({ outcome, names }: {
|
|
52
|
+
outcome: WorkspaceAdoptionOutcome;
|
|
53
|
+
names: readonly string[];
|
|
54
|
+
}): string[];
|
|
55
|
+
declare const identitiesSchema: z.ZodObject<{
|
|
56
|
+
serviceAccount: z.ZodNullable<z.ZodObject<{
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
status: z.ZodEnum<{
|
|
59
|
+
approved: "approved";
|
|
60
|
+
already_approved: "already_approved";
|
|
61
|
+
}>;
|
|
62
|
+
}, z.core.$loose>>;
|
|
63
|
+
ingress: z.ZodArray<z.ZodObject<{
|
|
64
|
+
ingressId: z.ZodString;
|
|
65
|
+
accountId: z.ZodString;
|
|
66
|
+
status: z.ZodEnum<{
|
|
67
|
+
skipped: "skipped";
|
|
68
|
+
bound: "bound";
|
|
69
|
+
already_bound: "already_bound";
|
|
70
|
+
}>;
|
|
71
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, z.core.$loose>>;
|
|
73
|
+
}, z.core.$loose>;
|
|
74
|
+
export type IdentityAdmission = z.infer<typeof identitiesSchema>;
|
|
75
|
+
export type IdentityAdmissionOutcome = {
|
|
76
|
+
ok: true;
|
|
77
|
+
admission: IdentityAdmission;
|
|
78
|
+
} | {
|
|
79
|
+
ok: false;
|
|
80
|
+
reason: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Ask the local Atlas to admit the service identities the copied project already records, for
|
|
84
|
+
* this project only. The CLI names the project and nothing else: Atlas reads the identities from
|
|
85
|
+
* its own rows.
|
|
86
|
+
*/
|
|
87
|
+
export declare function admitProjectIdentities({ ctx, projectSlug }: {
|
|
88
|
+
ctx: PreviewContext;
|
|
89
|
+
projectSlug: string;
|
|
90
|
+
}): Promise<IdentityAdmissionOutcome>;
|
|
91
|
+
export declare function identityAdmissionReport({ outcome, projectSlug }: {
|
|
92
|
+
outcome: IdentityAdmissionOutcome;
|
|
93
|
+
projectSlug: string;
|
|
94
|
+
}): string[];
|
|
95
|
+
declare const developmentConfigSchema: z.ZodObject<{
|
|
96
|
+
developmentBindings: z.ZodObject<{
|
|
97
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
+
functions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
99
|
+
processes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
100
|
+
}, z.core.$loose>;
|
|
101
|
+
}, z.core.$loose>;
|
|
102
|
+
type DevelopmentBindings = z.infer<typeof developmentConfigSchema>['developmentBindings'];
|
|
103
|
+
/**
|
|
104
|
+
* The stored development bindings that name something the bundle no longer declares. Atlas refuses
|
|
105
|
+
* to start a session while one exists, and a copied project keeps whatever its source had bound
|
|
106
|
+
* when the application last renamed or dropped a resource. Declared as Atlas checks it: server data
|
|
107
|
+
* read and write, functions invoked, processes started, read or acted on.
|
|
108
|
+
*/
|
|
109
|
+
export declare function staleDevelopmentBindings({ bundle, bindings }: {
|
|
110
|
+
bundle: unknown;
|
|
111
|
+
bindings: DevelopmentBindings;
|
|
112
|
+
}): string[];
|
|
113
|
+
export type BindingPruneOutcome = {
|
|
114
|
+
ok: true;
|
|
115
|
+
removed: string[];
|
|
116
|
+
} | {
|
|
117
|
+
ok: false;
|
|
118
|
+
reason: string;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Remove, from this fork's copy of the project only, the development bindings the bundle no longer
|
|
122
|
+
* declares. A declared resource left unbound resolves to itself, so removing one opens nothing.
|
|
123
|
+
*/
|
|
124
|
+
export declare function pruneStaleDevelopmentBindings({ ctx, projectSlug, bundle }: {
|
|
125
|
+
ctx: PreviewContext;
|
|
126
|
+
projectSlug: string;
|
|
127
|
+
bundle: unknown;
|
|
128
|
+
}): Promise<BindingPruneOutcome>;
|
|
129
|
+
export declare function bindingPruneReport({ outcome, projectSlug }: {
|
|
130
|
+
outcome: BindingPruneOutcome;
|
|
131
|
+
projectSlug: string;
|
|
132
|
+
}): string[];
|
|
133
|
+
/** What the local Atlas's runtime report says about a devbox fork. */
|
|
134
|
+
export interface PreviewFork {
|
|
135
|
+
/** The `seq-studio` environment of the deployment the database was copied from, when Atlas resolves one. */
|
|
136
|
+
upstreamEnvironment: string | null;
|
|
137
|
+
/** Whether that deployment releases development secret values. A production deployment never does. */
|
|
138
|
+
upstreamSecrets: boolean;
|
|
139
|
+
}
|
|
140
|
+
export interface SecretSourceDecision {
|
|
141
|
+
/** Flags appended to `artifact dev`; empty keeps its own default (the local Atlas store). */
|
|
142
|
+
args: string[];
|
|
143
|
+
/** One line saying what was chosen and why, or null when there is nothing to say. */
|
|
144
|
+
line: string | null;
|
|
145
|
+
source: 'upstream' | 'default' | 'requested';
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Where a Next.js session's declared server.secrets come from. A flag the caller passed always
|
|
149
|
+
* wins. Otherwise values are read from the deployment the database was copied from only when all
|
|
150
|
+
* hold: the app declares secrets, this is a devbox fork of a deployment Atlas resolves, that
|
|
151
|
+
* deployment releases development secrets (staging does, production never), and this machine
|
|
152
|
+
* holds the owner's token for it. Nothing is sent to a deployment that fails any of these. Anything less keeps today's default
|
|
153
|
+
* and says which condition failed.
|
|
154
|
+
*/
|
|
155
|
+
export declare function chooseSecretSource({ requested, requestedUpstream, secretNames, fork, upstream }: {
|
|
156
|
+
requested: string | undefined;
|
|
157
|
+
requestedUpstream: string | undefined;
|
|
158
|
+
secretNames: readonly string[];
|
|
159
|
+
fork: PreviewFork | undefined;
|
|
160
|
+
/** The upstream environment as this CLI resolves it, or why it cannot. */
|
|
161
|
+
upstream: {
|
|
162
|
+
name: string;
|
|
163
|
+
host: string;
|
|
164
|
+
hasOwnerToken: boolean;
|
|
165
|
+
} | {
|
|
166
|
+
unresolved: string;
|
|
167
|
+
} | null;
|
|
168
|
+
}): SecretSourceDecision;
|
|
169
|
+
/** The fork source's environment as this machine can reach it: its registered URL and whether an owner token for it is live. */
|
|
170
|
+
export declare function resolveUpstream(fork: PreviewFork | undefined): Promise<Parameters<typeof chooseSecretSource>[0]['upstream']>;
|
|
171
|
+
export {};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a preview does on a devbox whose database is a copy of a hosted deployment's ("fork"): the
|
|
3
|
+
* local Atlas says so in its runtime report. A database copy carries platform rows but not what
|
|
4
|
+
* lives outside the database, so before a Next.js session starts the preview asks the local Atlas
|
|
5
|
+
* to adopt the workspaces the app declares and to admit the service identities the copied project
|
|
6
|
+
* records, and chooses where the session's server secrets come from.
|
|
7
|
+
*
|
|
8
|
+
* Decisions are pure functions here; `commands.ts` prints them and runs the session.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { getJson, patchJson, postJsonResponse } from '../atlas-client.js';
|
|
12
|
+
import { resolveConfiguredEnv } from '../config.js';
|
|
13
|
+
import { devboxHostToken } from '../host-token.js';
|
|
14
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
15
|
+
function at(value, ...keys) {
|
|
16
|
+
let current = value;
|
|
17
|
+
for (const key of keys)
|
|
18
|
+
current = typeof current === 'object' && current !== null ? Reflect.get(current, key) : undefined;
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
const keys = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) ? Object.keys(value) : [];
|
|
22
|
+
/** Every workspace a bundle declares by name (browser, server and each external ingress); ids are not names. */
|
|
23
|
+
export function declaredWorkspaceNames(bundle) {
|
|
24
|
+
const external = at(bundle, 'server', 'ingress', 'external');
|
|
25
|
+
const maps = [
|
|
26
|
+
at(bundle, 'capabilities', 'storage'),
|
|
27
|
+
at(bundle, 'server', 'capabilities', 'storage'),
|
|
28
|
+
...(Array.isArray(external) ? external.map((ingress) => at(ingress, 'capabilities', 'storage')) : []),
|
|
29
|
+
];
|
|
30
|
+
return [...new Set(maps.flatMap(keys))].filter((name) => !UUID.test(name)).sort();
|
|
31
|
+
}
|
|
32
|
+
/** The server.secrets a bundle declares, by environment name. */
|
|
33
|
+
export function declaredServerSecretNames(bundle) {
|
|
34
|
+
const secrets = at(bundle, 'server', 'secrets');
|
|
35
|
+
const names = (Array.isArray(secrets) ? secrets : []).map((secret) => (typeof secret === 'string' ? secret : at(secret, 'name')));
|
|
36
|
+
return [...new Set(names.filter((name) => typeof name === 'string' && name.length > 0))];
|
|
37
|
+
}
|
|
38
|
+
const adoptionSchema = z.looseObject({
|
|
39
|
+
environment: z.string(),
|
|
40
|
+
sourceEnvironment: z.string(),
|
|
41
|
+
bytes: z.enum(['available', 'unavailable']).optional(),
|
|
42
|
+
workspaces: z.array(z.looseObject({
|
|
43
|
+
name: z.string(),
|
|
44
|
+
status: z.enum(['adopted', 'already_adopted', 'not_found', 'forbidden']),
|
|
45
|
+
id: z.string().optional(),
|
|
46
|
+
detail: z.string().optional(),
|
|
47
|
+
})),
|
|
48
|
+
});
|
|
49
|
+
function detailOf(body) {
|
|
50
|
+
try {
|
|
51
|
+
const detail = at(JSON.parse(body), 'detail');
|
|
52
|
+
return typeof detail === 'string' && detail ? detail : null;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Ask the local Atlas to re-home the declared workspaces from the database copy. Names only. */
|
|
59
|
+
export async function adoptDeclaredWorkspaces({ ctx, names }) {
|
|
60
|
+
const response = await postJsonResponse({ ...ctx.client, path: '/api/platform/local-fork/storage-adoption', body: { names } });
|
|
61
|
+
if (response.status === 404)
|
|
62
|
+
return { ok: false, reason: 'this local Atlas cannot adopt copied workspaces (its checkout predates fork storage)' };
|
|
63
|
+
if (response.status < 200 || response.status >= 300) {
|
|
64
|
+
return { ok: false, reason: detailOf(response.body) ?? `the local Atlas answered HTTP ${response.status}` };
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const parsed = adoptionSchema.safeParse(JSON.parse(response.body));
|
|
68
|
+
return parsed.success ? { ok: true, adoption: parsed.data } : { ok: false, reason: 'the local Atlas sent an unrecognized adoption result; upgrade seq-studio or that Atlas' };
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return { ok: false, reason: 'the local Atlas sent an unreadable adoption result' };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const WORKSPACE_STATUS = {
|
|
75
|
+
adopted: 'adopted from the database copy',
|
|
76
|
+
already_adopted: 'already adopted',
|
|
77
|
+
not_found: 'not found on the fork',
|
|
78
|
+
forbidden: 'not adopted',
|
|
79
|
+
};
|
|
80
|
+
/** One line per declared workspace, then what the fork can and cannot do with their files. */
|
|
81
|
+
export function workspaceAdoptionReport({ outcome, names }) {
|
|
82
|
+
if (!outcome.ok) {
|
|
83
|
+
return [`workspaces ${names.join(', ')}: not adopted (${outcome.reason}); each must already exist on this Atlas`];
|
|
84
|
+
}
|
|
85
|
+
const { adoption } = outcome;
|
|
86
|
+
const lines = adoption.workspaces.map((workspace) => `workspace ${workspace.name}: ${WORKSPACE_STATUS[workspace.status]}${workspace.detail ? ` (${workspace.detail})` : ''}` +
|
|
87
|
+
(workspace.status === 'not_found' ? `; create it here, or the session start refuses the name` : ''));
|
|
88
|
+
if (adoption.workspaces.some((workspace) => workspace.status === 'adopted' || workspace.status === 'already_adopted')) {
|
|
89
|
+
lines.push(adoption.bytes === 'available'
|
|
90
|
+
? `files that existed in ${adoption.sourceEnvironment} are listed but not copied: opening one fails with "not copied to this fork"; new uploads work`
|
|
91
|
+
: `files are NOT available on this fork: folders and listings work, but opening a file from ${adoption.sourceEnvironment} or uploading a new one fails with a storage error (this fork has no file storage yet)`);
|
|
92
|
+
}
|
|
93
|
+
return lines;
|
|
94
|
+
}
|
|
95
|
+
const identitiesSchema = z.looseObject({
|
|
96
|
+
serviceAccount: z.looseObject({ id: z.string(), status: z.enum(['approved', 'already_approved']) }).nullable(),
|
|
97
|
+
ingress: z.array(z.looseObject({
|
|
98
|
+
ingressId: z.string(),
|
|
99
|
+
accountId: z.string(),
|
|
100
|
+
status: z.enum(['bound', 'already_bound', 'skipped']),
|
|
101
|
+
detail: z.string().optional(),
|
|
102
|
+
})),
|
|
103
|
+
});
|
|
104
|
+
/** The one project the database copy holds under this slug. */
|
|
105
|
+
async function copiedProject({ ctx, projectSlug }) {
|
|
106
|
+
const { projects } = await getJson({
|
|
107
|
+
...ctx.client,
|
|
108
|
+
path: `/api/artifact-studio/projects?slug=${encodeURIComponent(projectSlug)}`,
|
|
109
|
+
});
|
|
110
|
+
const matches = projects.filter((candidate) => candidate.slug === projectSlug);
|
|
111
|
+
if (matches.length === 0)
|
|
112
|
+
return { ok: false, reason: 'the database copy has no such project, so it records nothing for it (the app was never deployed where the copy came from)' };
|
|
113
|
+
if (matches.length > 1)
|
|
114
|
+
return { ok: false, reason: `the database copy has ${matches.length} projects with this slug; set the one you mean up by hand` };
|
|
115
|
+
return { ok: true, id: matches[0].id };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Ask the local Atlas to admit the service identities the copied project already records, for
|
|
119
|
+
* this project only. The CLI names the project and nothing else: Atlas reads the identities from
|
|
120
|
+
* its own rows.
|
|
121
|
+
*/
|
|
122
|
+
export async function admitProjectIdentities({ ctx, projectSlug }) {
|
|
123
|
+
const project = await copiedProject({ ctx, projectSlug });
|
|
124
|
+
if (!project.ok)
|
|
125
|
+
return project;
|
|
126
|
+
const response = await postJsonResponse({ ...ctx.client, path: '/api/platform/local-fork/artifact-identities', body: { projectId: project.id } });
|
|
127
|
+
if (response.status === 404)
|
|
128
|
+
return { ok: false, reason: 'this local Atlas cannot admit copied service identities (its checkout predates it)' };
|
|
129
|
+
if (response.status < 200 || response.status >= 300) {
|
|
130
|
+
return { ok: false, reason: detailOf(response.body) ?? `the local Atlas answered HTTP ${response.status}` };
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const parsed = identitiesSchema.safeParse(JSON.parse(response.body));
|
|
134
|
+
return parsed.success ? { ok: true, admission: parsed.data } : { ok: false, reason: 'the local Atlas sent an unrecognized identity result; upgrade seq-studio or that Atlas' };
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return { ok: false, reason: 'the local Atlas sent an unreadable identity result' };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function identityAdmissionReport({ outcome, projectSlug }) {
|
|
141
|
+
if (!outcome.ok)
|
|
142
|
+
return [`service identities of ${projectSlug}: not admitted (${outcome.reason}); a session that needs one is refused until it is approved by hand`];
|
|
143
|
+
const { serviceAccount, ingress } = outcome.admission;
|
|
144
|
+
const lines = [];
|
|
145
|
+
if (serviceAccount) {
|
|
146
|
+
lines.push(`application service identity ${serviceAccount.id}: ${serviceAccount.status === 'approved' ? 'approved for development sessions on this fork' : 'already approved'}`);
|
|
147
|
+
}
|
|
148
|
+
for (const entry of ingress) {
|
|
149
|
+
const state = entry.status === 'bound' ? 'bound and approved as its development identity'
|
|
150
|
+
: entry.status === 'already_bound' ? 'already bound'
|
|
151
|
+
: `not bound (${entry.detail ?? 'refused'})`;
|
|
152
|
+
lines.push(`external ingress ${entry.ingressId} identity ${entry.accountId}: ${state}`);
|
|
153
|
+
}
|
|
154
|
+
if (ingress.some((entry) => entry.status !== 'skipped')) {
|
|
155
|
+
lines.push('external callers are still not served here: the local identity-provider catalog is read when Atlas starts and must list this project');
|
|
156
|
+
}
|
|
157
|
+
return lines;
|
|
158
|
+
}
|
|
159
|
+
const bindingMap = z.record(z.string(), z.unknown()).optional();
|
|
160
|
+
const developmentConfigSchema = z.looseObject({
|
|
161
|
+
developmentBindings: z.looseObject({ data: bindingMap, functions: bindingMap, processes: bindingMap }),
|
|
162
|
+
});
|
|
163
|
+
const strings = (value) => (Array.isArray(value) ? value.filter((entry) => typeof entry === 'string') : []);
|
|
164
|
+
/**
|
|
165
|
+
* The stored development bindings that name something the bundle no longer declares. Atlas refuses
|
|
166
|
+
* to start a session while one exists, and a copied project keeps whatever its source had bound
|
|
167
|
+
* when the application last renamed or dropped a resource. Declared as Atlas checks it: server data
|
|
168
|
+
* read and write, functions invoked, processes started, read or acted on.
|
|
169
|
+
*/
|
|
170
|
+
export function staleDevelopmentBindings({ bundle, bindings }) {
|
|
171
|
+
const reach = at(bundle, 'server', 'capabilities');
|
|
172
|
+
const declared = [
|
|
173
|
+
['data', [...strings(at(reach, 'data', 'read')), ...strings(at(reach, 'data', 'write'))]],
|
|
174
|
+
['functions', strings(at(reach, 'functions', 'invoke'))],
|
|
175
|
+
['processes', [...strings(at(reach, 'processes', 'start')), ...strings(at(reach, 'processes', 'read')), ...strings(at(reach, 'processes', 'act'))]],
|
|
176
|
+
];
|
|
177
|
+
return declared.flatMap(([kind, refs]) => {
|
|
178
|
+
const known = new Set(refs);
|
|
179
|
+
return Object.keys(bindings[kind] ?? {}).filter((ref) => !known.has(ref)).map((ref) => `${kind}:${ref}`);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Remove, from this fork's copy of the project only, the development bindings the bundle no longer
|
|
184
|
+
* declares. A declared resource left unbound resolves to itself, so removing one opens nothing.
|
|
185
|
+
*/
|
|
186
|
+
export async function pruneStaleDevelopmentBindings({ ctx, projectSlug, bundle }) {
|
|
187
|
+
const project = await copiedProject({ ctx, projectSlug });
|
|
188
|
+
if (!project.ok)
|
|
189
|
+
return project;
|
|
190
|
+
const path = `/api/artifact-studio/projects/${project.id}/next/config`;
|
|
191
|
+
const parsed = developmentConfigSchema.safeParse(await getJson({ ...ctx.client, path }));
|
|
192
|
+
if (!parsed.success)
|
|
193
|
+
return { ok: false, reason: 'the local Atlas sent an unrecognized development configuration; upgrade seq-studio or that Atlas' };
|
|
194
|
+
const bindings = parsed.data.developmentBindings;
|
|
195
|
+
const removed = staleDevelopmentBindings({ bundle, bindings });
|
|
196
|
+
if (removed.length === 0)
|
|
197
|
+
return { ok: true, removed };
|
|
198
|
+
const stale = new Set(removed);
|
|
199
|
+
const kept = (kind) => Object.fromEntries(Object.entries(bindings[kind] ?? {}).filter(([ref]) => !stale.has(`${kind}:${ref}`)));
|
|
200
|
+
await patchJson({
|
|
201
|
+
...ctx.client,
|
|
202
|
+
path,
|
|
203
|
+
body: {
|
|
204
|
+
developmentBindings: {
|
|
205
|
+
...bindings,
|
|
206
|
+
...(bindings.data ? { data: kept('data') } : {}),
|
|
207
|
+
...(bindings.functions ? { functions: kept('functions') } : {}),
|
|
208
|
+
...(bindings.processes ? { processes: kept('processes') } : {}),
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
return { ok: true, removed };
|
|
213
|
+
}
|
|
214
|
+
export function bindingPruneReport({ outcome, projectSlug }) {
|
|
215
|
+
if (!outcome.ok)
|
|
216
|
+
return [`development bindings of ${projectSlug}: not checked (${outcome.reason}); a binding the application no longer declares stops the session`];
|
|
217
|
+
if (outcome.removed.length === 0)
|
|
218
|
+
return [];
|
|
219
|
+
return [`development bindings of ${projectSlug}: removed ${outcome.removed.join(', ')} from this fork's copy, which the application no longer declares`];
|
|
220
|
+
}
|
|
221
|
+
const WITHOUT = '--secret-source none starts the session without them';
|
|
222
|
+
/**
|
|
223
|
+
* Where a Next.js session's declared server.secrets come from. A flag the caller passed always
|
|
224
|
+
* wins. Otherwise values are read from the deployment the database was copied from only when all
|
|
225
|
+
* hold: the app declares secrets, this is a devbox fork of a deployment Atlas resolves, that
|
|
226
|
+
* deployment releases development secrets (staging does, production never), and this machine
|
|
227
|
+
* holds the owner's token for it. Nothing is sent to a deployment that fails any of these. Anything less keeps today's default
|
|
228
|
+
* and says which condition failed.
|
|
229
|
+
*/
|
|
230
|
+
export function chooseSecretSource({ requested, requestedUpstream, secretNames, fork, upstream }) {
|
|
231
|
+
if (requested !== undefined) {
|
|
232
|
+
return {
|
|
233
|
+
args: ['--secret-source', requested, ...(requestedUpstream !== undefined ? ['--secret-upstream', requestedUpstream] : [])],
|
|
234
|
+
line: null,
|
|
235
|
+
source: 'requested',
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
if (secretNames.length === 0)
|
|
239
|
+
return { args: [], line: null, source: 'default' };
|
|
240
|
+
const list = secretNames.join(', ');
|
|
241
|
+
const fallback = (why) => ({
|
|
242
|
+
args: [],
|
|
243
|
+
line: `server.secrets ${list}: read from this local Atlas's own store, because ${why}. Set each with seq-studio secret set <NAME> -e local, or ${WITHOUT}.`,
|
|
244
|
+
source: 'default',
|
|
245
|
+
});
|
|
246
|
+
if (!fork)
|
|
247
|
+
return fallback('this Atlas is not a devbox fork of a hosted deployment');
|
|
248
|
+
if (!fork.upstreamEnvironment)
|
|
249
|
+
return fallback('this fork was not copied from a deployment whose secrets a preview can read');
|
|
250
|
+
if (!fork.upstreamSecrets) {
|
|
251
|
+
return fallback(`this database was copied from ${fork.upstreamEnvironment}, a production deployment, and secret values are never read from one`);
|
|
252
|
+
}
|
|
253
|
+
if (!upstream)
|
|
254
|
+
return fallback('this fork was not copied from a deployment whose secrets a preview can read');
|
|
255
|
+
if ('unresolved' in upstream)
|
|
256
|
+
return fallback(upstream.unresolved);
|
|
257
|
+
if (!upstream.hasOwnerToken)
|
|
258
|
+
return fallback(`this machine holds no owner token for ${upstream.host} (${upstream.name})`);
|
|
259
|
+
return {
|
|
260
|
+
args: ['--secret-source', 'upstream', '--secret-upstream', upstream.name],
|
|
261
|
+
line: `server.secrets ${list}: will be read from ${upstream.name} (${upstream.host}) as you, into memory only. ${WITHOUT}.`,
|
|
262
|
+
source: 'upstream',
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/** The fork source's environment as this machine can reach it: its registered URL and whether an owner token for it is live. */
|
|
266
|
+
export async function resolveUpstream(fork) {
|
|
267
|
+
const name = fork?.upstreamEnvironment;
|
|
268
|
+
// A deployment that releases no secret values is not looked up at all.
|
|
269
|
+
if (!name || !fork?.upstreamSecrets)
|
|
270
|
+
return null;
|
|
271
|
+
let url;
|
|
272
|
+
try {
|
|
273
|
+
url = (await resolveConfiguredEnv({ requested: name })).url;
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return { unresolved: `the environment ${name} is not registered with seq-studio on this machine (seq-studio envs list)` };
|
|
277
|
+
}
|
|
278
|
+
return { name, host: new URL(url).host, hasOwnerToken: (await devboxHostToken(url)) !== null };
|
|
279
|
+
}
|
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
* it, so install with the lockfile's own value.
|
|
5
5
|
*/
|
|
6
6
|
export declare function lockfilePeerSetting(lockfile: string): boolean | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* A hosted build replaces an app's workspace file with the platform's own, which has no
|
|
9
|
+
* `overrides`, so an app built there commits a lockfile that does not record the overrides its
|
|
10
|
+
* workspace file declares. A frozen install with that workspace file is refused; installing as the
|
|
11
|
+
* hosted build does, without it, is not. Only for a workspace of the one package: without its
|
|
12
|
+
* workspace file a larger one would install its root alone.
|
|
13
|
+
*/
|
|
14
|
+
export declare function lockfileOmitsWorkspaceOverrides({ workspace, lockfile }: {
|
|
15
|
+
workspace: string | undefined;
|
|
16
|
+
lockfile: string;
|
|
17
|
+
}): boolean;
|
|
7
18
|
export type InstallDecision = {
|
|
8
19
|
install: false;
|
|
9
20
|
reason: 'installed' | 'no-package';
|
|
@@ -14,8 +25,8 @@ export type InstallDecision = {
|
|
|
14
25
|
};
|
|
15
26
|
/**
|
|
16
27
|
* A fresh clone has no node_modules, and an artifact cannot build without them. Install where the
|
|
17
|
-
* artifact resolves its dependencies from:
|
|
18
|
-
* lockfile, else the app root. A committed lockfile is installed exactly; one is never rewritten
|
|
28
|
+
* artifact resolves its dependencies from: the nearest directory, its own or one above it inside the
|
|
29
|
+
* app, that keeps its own workspace or lockfile, else the app root. A committed lockfile is installed exactly; one is never rewritten
|
|
19
30
|
* by a preview.
|
|
20
31
|
*/
|
|
21
32
|
export declare function decideInstall({ artifactDir, appRoot, exists, read }: {
|
|
@@ -24,6 +35,16 @@ export declare function decideInstall({ artifactDir, appRoot, exists, read }: {
|
|
|
24
35
|
exists?: (path: string) => boolean;
|
|
25
36
|
read?: (path: string) => string | undefined;
|
|
26
37
|
}): InstallDecision;
|
|
38
|
+
/**
|
|
39
|
+
* Where an artifact of a repository with no app manifest installs from, chosen as repository CI chooses it:
|
|
40
|
+
* the nearest directory at or above the artifact, no higher than the git root, that holds a lockfile; the
|
|
41
|
+
* artifact's own directory when there is none. Only pnpm's lockfile counts, since pnpm is what installs here.
|
|
42
|
+
*/
|
|
43
|
+
export declare function repositoryInstallRoot({ artifactDir, gitRoot, exists }: {
|
|
44
|
+
artifactDir: string;
|
|
45
|
+
gitRoot: string;
|
|
46
|
+
exists?: (path: string) => boolean;
|
|
47
|
+
}): string;
|
|
27
48
|
/** Progress goes to stderr so `--json` output stays a single document. */
|
|
28
49
|
export declare function installDependencies({ root, args }: {
|
|
29
50
|
root: string;
|