@sequenceholdings/studio-cli 0.6.1 → 0.6.4
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 +186 -21
- package/dist/app/commands.d.ts +1 -1
- package/dist/app/commands.js +11 -6
- package/dist/app/deploy.js +4 -3
- package/dist/app/env-bindings.d.ts +3 -4
- package/dist/app/env-bindings.js +14 -77
- package/dist/app/readme.js +2 -2
- package/dist/app/repository-admission.d.ts +5 -0
- package/dist/app/repository-admission.js +32 -0
- package/dist/app/scaffold-files.js +8 -1
- package/dist/artifact/delegate.d.ts +4 -0
- package/dist/artifact/delegate.js +18 -8
- package/dist/artifact/sandbox.d.ts +29 -0
- package/dist/artifact/sandbox.js +109 -0
- package/dist/atlas-client.d.ts +1 -0
- package/dist/atlas-client.js +11 -2
- package/dist/auth-cmds/commands.js +3 -0
- package/dist/command-contract.d.ts +8 -2
- package/dist/command-contract.js +3 -2
- package/dist/command-help.d.ts +7 -4
- package/dist/command-help.js +43 -3
- package/dist/env-flags.d.ts +6 -0
- package/dist/env-flags.js +23 -1
- package/dist/envs/commands.js +30 -4
- package/dist/feedback/commands.d.ts +3 -0
- package/dist/feedback/commands.js +108 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +14 -16
- package/dist/orm/delegate.js +30 -11
- package/dist/orm/discover-schema.d.ts +196 -0
- package/dist/orm/discover-schema.js +84 -0
- package/dist/orm/discover.d.ts +13 -0
- package/dist/orm/discover.js +289 -0
- package/dist/pipeline/lifecycle.js +2 -1
- package/dist/pipeline/repin-orm.js +8 -1
- package/dist/pipeline/source.js +3 -0
- package/dist/repos/commands.js +9 -0
- package/dist/repos/identity-file.d.ts +17 -0
- package/dist/repos/identity-file.js +39 -0
- package/dist/repos/identity.d.ts +2 -0
- package/dist/repos/identity.js +69 -0
- package/dist/sandbox-auth.d.ts +11 -0
- package/dist/sandbox-auth.js +22 -0
- package/dist/update-check.d.ts +3 -1
- package/dist/update-check.js +38 -12
- package/package.json +3 -3
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `seq-studio orm namespaces` / `orm describe` — find the ORM data the caller
|
|
3
|
+
* can read before querying it with `orm read` / `orm sql`.
|
|
4
|
+
*
|
|
5
|
+
* Both are read-only views over Atlas's namespace registry, authorized as the
|
|
6
|
+
* caller: `namespaces` lists only namespaces the caller can read, and
|
|
7
|
+
* `describe` answers 404 for a namespace that is missing or unreadable alike.
|
|
8
|
+
* `describe` joins the active version's compiled schema with its active
|
|
9
|
+
* persisted-operation set.
|
|
10
|
+
*/
|
|
11
|
+
import { AtlasApiError, getJson } from '../atlas-client.js';
|
|
12
|
+
import { printCliError } from '../cli-errors.js';
|
|
13
|
+
import { validateCommandInput } from '../command-input.js';
|
|
14
|
+
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
15
|
+
import { table } from '../text-table.js';
|
|
16
|
+
import { namespaceListSchema, operationsPageSchema, parseResponse, schemaViewSchema, } from './discover-schema.js';
|
|
17
|
+
/** The server's maximum operations page; describe pages until it has them all. */
|
|
18
|
+
const OPERATIONS_PAGE_SIZE = 500;
|
|
19
|
+
const DESCRIPTION_WIDTH = 60;
|
|
20
|
+
function pageFlag({ args, key, min }) {
|
|
21
|
+
const raw = args.flags[key];
|
|
22
|
+
if (raw === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
const value = typeof raw === 'string' && /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
|
|
25
|
+
if (!Number.isSafeInteger(value) || value < min)
|
|
26
|
+
throw new Error(`--${key} must be an integer >= ${min}.`);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function truncate(text) {
|
|
30
|
+
const flat = (text ?? '').replace(/\s+/g, ' ').trim();
|
|
31
|
+
return flat.length > DESCRIPTION_WIDTH ? `${flat.slice(0, DESCRIPTION_WIDTH - 1)}…` : flat;
|
|
32
|
+
}
|
|
33
|
+
function formatLabel(format) {
|
|
34
|
+
return format === null ? 'not applied' : `v${format}`;
|
|
35
|
+
}
|
|
36
|
+
function requiresLabel(requires) {
|
|
37
|
+
if (!requires)
|
|
38
|
+
return '';
|
|
39
|
+
return [
|
|
40
|
+
...(requires.capability ? [`capability ${requires.capability}`] : []),
|
|
41
|
+
...(requires.role ? [`role ${requires.role}`] : []),
|
|
42
|
+
].join(', ');
|
|
43
|
+
}
|
|
44
|
+
export async function ormNamespacesCommand(args) {
|
|
45
|
+
try {
|
|
46
|
+
validateCommandInput({ args, flags: { limit: 'string', offset: 'string' }, positional: 0 });
|
|
47
|
+
const limit = pageFlag({ args, key: 'limit', min: 1 });
|
|
48
|
+
const offset = pageFlag({ args, key: 'offset', min: 0 });
|
|
49
|
+
const query = new URLSearchParams({
|
|
50
|
+
...(limit !== undefined ? { limit: String(limit) } : {}),
|
|
51
|
+
...(offset !== undefined ? { offset: String(offset) } : {}),
|
|
52
|
+
}).toString();
|
|
53
|
+
const options = clientOptions(await buildContext(args));
|
|
54
|
+
const page = parseResponse({
|
|
55
|
+
schema: namespaceListSchema,
|
|
56
|
+
body: await getJson({ ...options, path: `/api/orm/namespaces${query ? `?${query}` : ''}` }),
|
|
57
|
+
what: 'namespace list',
|
|
58
|
+
});
|
|
59
|
+
if (args.flags.json === true) {
|
|
60
|
+
console.log(JSON.stringify(page, null, 2));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
table({
|
|
64
|
+
headers: ['NAMESPACE', 'FORMAT', 'TABLES', 'OPERATIONS', 'DESCRIPTION'],
|
|
65
|
+
rows: page.namespaces.map((namespace) => [
|
|
66
|
+
namespace.id,
|
|
67
|
+
`${formatLabel(namespace.definition_format)}${namespace.archived_at ? ' (archived)' : ''}`,
|
|
68
|
+
String(namespace.table_count ?? 0),
|
|
69
|
+
String(namespace.operation_count ?? 0),
|
|
70
|
+
truncate(namespace.description),
|
|
71
|
+
]),
|
|
72
|
+
});
|
|
73
|
+
if (page.namespaces.length === 0)
|
|
74
|
+
console.error(`No readable namespaces at offset ${page.offset} (${page.total} total).`);
|
|
75
|
+
else {
|
|
76
|
+
console.error(`${page.offset + 1}-${page.offset + page.namespaces.length} of ${page.total} readable namespace(s)`);
|
|
77
|
+
console.error('Describe one: seq-studio orm describe <namespace>');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const next = page.offset + page.namespaces.length;
|
|
81
|
+
if (page.namespaces.length > 0 && next < page.total) {
|
|
82
|
+
console.error(`More namespaces exist. Next page: --offset ${next} --limit ${page.limit}`);
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
printCliError(error);
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function getNamespaceJson({ options, namespace, path }) {
|
|
92
|
+
try {
|
|
93
|
+
return await getJson({ ...options, path });
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Missing and unreadable are deliberately indistinguishable on the server.
|
|
97
|
+
if (error instanceof AtlasApiError && error.status === 404) {
|
|
98
|
+
throw new Error(`Namespace '${namespace}' was not found, has no applied version, or you cannot read it. ` +
|
|
99
|
+
'List the namespaces you can read: seq-studio orm namespaces');
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function listAllOperations({ options, namespace }) {
|
|
105
|
+
const operations = [];
|
|
106
|
+
for (;;) {
|
|
107
|
+
const query = new URLSearchParams({ limit: String(OPERATIONS_PAGE_SIZE), offset: String(operations.length) });
|
|
108
|
+
const page = parseResponse({
|
|
109
|
+
schema: operationsPageSchema,
|
|
110
|
+
body: await getNamespaceJson({
|
|
111
|
+
options,
|
|
112
|
+
namespace,
|
|
113
|
+
path: `/api/orm/namespaces/${encodeURIComponent(namespace)}/operations?${query.toString()}`,
|
|
114
|
+
}),
|
|
115
|
+
what: 'operations',
|
|
116
|
+
});
|
|
117
|
+
operations.push(...page.operations);
|
|
118
|
+
if (page.operations.length === 0 || operations.length >= page.total)
|
|
119
|
+
return operations;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function findRelation({ schema, name }) {
|
|
123
|
+
const found = schema.tables.find((relation) => relation.table === name);
|
|
124
|
+
if (found)
|
|
125
|
+
return { kind: 'table', name, relation: found };
|
|
126
|
+
const view = schema.views.find((relation) => relation.view === name);
|
|
127
|
+
return view ? { kind: 'view', name, relation: view } : null;
|
|
128
|
+
}
|
|
129
|
+
function columnType(column) {
|
|
130
|
+
return column.enum_name ? `enum ${column.enum_name}` : column.type;
|
|
131
|
+
}
|
|
132
|
+
function columnKey(column) {
|
|
133
|
+
if (column.primary_key)
|
|
134
|
+
return 'primary';
|
|
135
|
+
return column.unique ? 'unique' : '';
|
|
136
|
+
}
|
|
137
|
+
function printOperations({ operations, heading }) {
|
|
138
|
+
console.log('');
|
|
139
|
+
console.log(heading);
|
|
140
|
+
if (operations.length === 0) {
|
|
141
|
+
console.log(' (none)');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
table({
|
|
145
|
+
headers: ['OPERATION', 'KIND', 'REQUIRES'],
|
|
146
|
+
rows: operations.map((operation) => [operation.name, operation.kind, requiresLabel(operation.requires)]),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function printNamespace({ schema, operations }) {
|
|
150
|
+
console.log(`${schema.namespace} ${formatLabel(schema.definition_format)} version ${schema.version_id}`);
|
|
151
|
+
if (schema.description)
|
|
152
|
+
console.log(schema.description);
|
|
153
|
+
console.log('');
|
|
154
|
+
// Internal tables are system-owned backing storage with no query surface.
|
|
155
|
+
const relations = [
|
|
156
|
+
...schema.tables.filter((relation) => relation.internal !== true)
|
|
157
|
+
.map((relation) => ({ kind: 'table', name: relation.table, relation })),
|
|
158
|
+
...schema.views.map((relation) => ({ kind: 'view', name: relation.view, relation })),
|
|
159
|
+
];
|
|
160
|
+
table({
|
|
161
|
+
headers: ['TABLE', 'KIND', 'COLUMNS', 'ACTIONS', 'DESCRIPTION'],
|
|
162
|
+
rows: relations.map(({ kind, name, relation }) => [
|
|
163
|
+
name,
|
|
164
|
+
kind === 'table' && relation.source ? 'synced' : kind,
|
|
165
|
+
String(relation.columns.length),
|
|
166
|
+
kind === 'table' ? String(relation.actions.length) : '',
|
|
167
|
+
truncate(relation.description),
|
|
168
|
+
]),
|
|
169
|
+
});
|
|
170
|
+
printOperations({ operations, heading: 'Persisted operations:' });
|
|
171
|
+
}
|
|
172
|
+
function printRelation({ schema, found, operations }) {
|
|
173
|
+
const { relation } = found;
|
|
174
|
+
const key = relation.primary_key.length ? ` primary key: ${relation.primary_key.join(', ')}` : '';
|
|
175
|
+
console.log(`${schema.namespace}.${found.name} (${found.kind === 'table' && found.relation.source ? 'synced table' : found.kind})${key}`);
|
|
176
|
+
if (relation.description)
|
|
177
|
+
console.log(relation.description);
|
|
178
|
+
console.log('');
|
|
179
|
+
table({
|
|
180
|
+
headers: ['COLUMN', 'TYPE', 'NULLABLE', 'KEY', 'DESCRIPTION'],
|
|
181
|
+
rows: relation.columns.map((column) => [
|
|
182
|
+
column.deprecated ? `${column.name} (deprecated)` : column.name,
|
|
183
|
+
columnType(column),
|
|
184
|
+
column.nullable ? 'yes' : 'no',
|
|
185
|
+
columnKey(column),
|
|
186
|
+
truncate(column.description),
|
|
187
|
+
]),
|
|
188
|
+
});
|
|
189
|
+
const enumNames = new Set(relation.columns.flatMap((column) => (column.enum_name ? [column.enum_name] : [])));
|
|
190
|
+
const enums = schema.enums.filter((declared) => enumNames.has(declared.name));
|
|
191
|
+
if (enums.length > 0) {
|
|
192
|
+
console.log('');
|
|
193
|
+
console.log('Enums:');
|
|
194
|
+
for (const declared of enums)
|
|
195
|
+
console.log(` ${declared.name}: ${declared.values.join(', ')}`);
|
|
196
|
+
}
|
|
197
|
+
if (relation.links.length > 0) {
|
|
198
|
+
console.log('');
|
|
199
|
+
console.log('Links:');
|
|
200
|
+
table({
|
|
201
|
+
headers: ['LINK', 'KIND', 'TARGET', 'ON'],
|
|
202
|
+
rows: relation.links.map((link) => [
|
|
203
|
+
link.name,
|
|
204
|
+
link.kind ?? '',
|
|
205
|
+
link.target ? `${link.namespace ? `${link.namespace}.` : ''}${link.target}` : 'platform user',
|
|
206
|
+
link.on,
|
|
207
|
+
]),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (found.kind === 'table') {
|
|
211
|
+
console.log('');
|
|
212
|
+
console.log('Actions:');
|
|
213
|
+
if (found.relation.actions.length === 0)
|
|
214
|
+
console.log(' (none)');
|
|
215
|
+
else {
|
|
216
|
+
table({
|
|
217
|
+
headers: ['ACTION', 'PARAMS', 'REQUIRES', 'DESCRIPTION'],
|
|
218
|
+
rows: found.relation.actions.map((action) => [
|
|
219
|
+
action.name,
|
|
220
|
+
action.params.map((param) => `${param.name}: ${param.type}${param.nullable ? '?' : ''}`).join(', '),
|
|
221
|
+
action.requires ?? '',
|
|
222
|
+
truncate(action.description),
|
|
223
|
+
]),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
printOperations({ operations, heading: `Persisted operations that write ${found.name}:` });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** Operations whose mutation roots write the table; query operations name no roots here. */
|
|
230
|
+
function operationsWriting({ operations, name }) {
|
|
231
|
+
return operations.filter((operation) => operation.mutation_roots.some((root) => root.table === name));
|
|
232
|
+
}
|
|
233
|
+
export async function ormDescribeCommand(args) {
|
|
234
|
+
try {
|
|
235
|
+
const [namespace, tableName] = args.positional;
|
|
236
|
+
validateCommandInput({ args, flags: {}, positional: tableName === undefined ? 1 : 2 });
|
|
237
|
+
const options = clientOptions(await buildContext(args));
|
|
238
|
+
const encoded = encodeURIComponent(namespace);
|
|
239
|
+
const [schemaBody, operations] = await Promise.all([
|
|
240
|
+
getNamespaceJson({ options, namespace: namespace, path: `/api/orm/namespaces/${encoded}/schema` }),
|
|
241
|
+
listAllOperations({ options, namespace: namespace }),
|
|
242
|
+
]);
|
|
243
|
+
const schema = parseResponse({ schema: schemaViewSchema, body: schemaBody, what: 'schema' });
|
|
244
|
+
if (tableName === undefined) {
|
|
245
|
+
// The generated GraphQL SDL is large and restates the tables; leave it out.
|
|
246
|
+
const { sdl: _sdl, ...described } = schema;
|
|
247
|
+
if (args.flags.json === true)
|
|
248
|
+
console.log(JSON.stringify({ ...described, operations }, null, 2));
|
|
249
|
+
else {
|
|
250
|
+
printNamespace({ schema, operations });
|
|
251
|
+
console.error(`Describe a table: seq-studio orm describe ${schema.namespace} <table>`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const found = findRelation({ schema, name: tableName });
|
|
256
|
+
if (!found) {
|
|
257
|
+
const names = [...schema.tables.filter((relation) => relation.internal !== true).map((relation) => relation.table),
|
|
258
|
+
...schema.views.map((relation) => relation.view)];
|
|
259
|
+
throw new Error(`No table or view '${tableName}' in ${schema.namespace}. Available: ${names.join(', ') || '(none)'}.`);
|
|
260
|
+
}
|
|
261
|
+
const writing = found.kind === 'table' ? operationsWriting({ operations, name: found.name }) : [];
|
|
262
|
+
if (args.flags.json === true) {
|
|
263
|
+
console.log(JSON.stringify({
|
|
264
|
+
namespace: schema.namespace,
|
|
265
|
+
definition_format: schema.definition_format,
|
|
266
|
+
version_id: schema.version_id,
|
|
267
|
+
kind: found.kind,
|
|
268
|
+
[found.kind]: found.relation,
|
|
269
|
+
enums: schema.enums.filter((declared) => found.relation.columns.some((column) => column.enum_name === declared.name)),
|
|
270
|
+
operations: writing,
|
|
271
|
+
}, null, 2));
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
printRelation({ schema, found, operations: writing });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (schema.definition_format !== 2) {
|
|
278
|
+
console.error('This is a v1 (YAML) namespace; orm read and orm sql support v2 namespaces only.');
|
|
279
|
+
}
|
|
280
|
+
else if (args.flags.json !== true) {
|
|
281
|
+
console.error(`Read rows: seq-studio orm read ${schema.namespace} ${tableName ?? '<table>'} --limit 5`);
|
|
282
|
+
}
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
printCliError(error);
|
|
287
|
+
return 1;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { getAccessToken, getAccessTokenWithMode, NotLoggedInError } from '../auth.js';
|
|
6
6
|
import { AtlasApiError, getJson, postJson } from '../atlas-client.js';
|
|
7
7
|
import { resolveConfiguredEnv } from '../config.js';
|
|
8
|
+
import { explicitOrSandboxEnv } from '../env-flags.js';
|
|
8
9
|
import { parseDurationMs } from '@sequenceholdings/lattice';
|
|
9
10
|
import { assertCloneDeployAllowed, publishCloneForDeploy } from './clone-deploy.js';
|
|
10
11
|
import { printReconcileResult, reconcileStageCredentials } from './stage-secrets.js';
|
|
@@ -53,7 +54,7 @@ function deploymentStatusLabel(detail) {
|
|
|
53
54
|
return detail.status;
|
|
54
55
|
}
|
|
55
56
|
export async function envAndToken(args, options = {}) {
|
|
56
|
-
const requested = typeof args.flags.e === 'string' ? args.flags.e : typeof args.flags.env === 'string' ? args.flags.env : undefined;
|
|
57
|
+
const requested = explicitOrSandboxEnv(typeof args.flags.e === 'string' ? args.flags.e : typeof args.flags.env === 'string' ? args.flags.env : undefined);
|
|
57
58
|
if (!requested) {
|
|
58
59
|
throw new Error('missing -e/--env <environment>');
|
|
59
60
|
}
|
|
@@ -3,6 +3,8 @@ import { join, resolve } from 'node:path';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { getAccessToken } from '../auth.js';
|
|
5
5
|
import { resolveConfiguredEnv } from '../config.js';
|
|
6
|
+
import { explicitOrSandboxEnv } from '../env-flags.js';
|
|
7
|
+
import { isSandboxTokenMode } from '../sandbox-auth.js';
|
|
6
8
|
import { loadActiveOrmContracts } from './active-orm-contracts.js';
|
|
7
9
|
import { commitFileWrites } from './atomic-file-writes.js';
|
|
8
10
|
import { resolvePipelineTarget } from './lifecycle.js';
|
|
@@ -16,7 +18,7 @@ async function loadModules() {
|
|
|
16
18
|
}
|
|
17
19
|
function requestedEnvironment(args) {
|
|
18
20
|
const value = args.flags.e ?? args.flags.env;
|
|
19
|
-
return typeof value === 'string' ? value : undefined;
|
|
21
|
+
return explicitOrSandboxEnv(typeof value === 'string' ? value : undefined);
|
|
20
22
|
}
|
|
21
23
|
function hasOrmPin(stage) {
|
|
22
24
|
return stage.type === 'serving' && stage.satisfies !== undefined;
|
|
@@ -63,6 +65,11 @@ async function assertSharedStageContractsAgree({ contracts, orm, stages, target,
|
|
|
63
65
|
throw new Error(`cannot verify shared ORM pins for target '${otherTarget}'; ` +
|
|
64
66
|
'split multi-target stages or use environment-specific pins');
|
|
65
67
|
}
|
|
68
|
+
if (isSandboxTokenMode()) {
|
|
69
|
+
// Every name resolves to the sandbox deployment, which is not this target's.
|
|
70
|
+
throw new Error(`cannot verify shared ORM pins for target '${otherTarget}' from an agent sandbox; ` +
|
|
71
|
+
'it reaches only its own deployment');
|
|
72
|
+
}
|
|
66
73
|
const otherEnv = await resolveConfiguredEnv({ requested: environmentName });
|
|
67
74
|
const otherToken = await getAccessToken({ env: otherEnv.name, targetUrl: otherEnv.url });
|
|
68
75
|
const sharedStages = stages.filter((stage) => stage.environments.includes(otherTarget));
|
package/dist/pipeline/source.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { RepositoryIdentitySchema } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
2
3
|
import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
|
|
3
4
|
import { getAccessToken } from '../auth.js';
|
|
4
5
|
import { resolveConfiguredEnv } from '../config.js';
|
|
@@ -43,6 +44,7 @@ const sourcePlanSchema = z.object({
|
|
|
43
44
|
repo: z.string(),
|
|
44
45
|
sourceEnvironment: z.string(),
|
|
45
46
|
sourceRepositoryId: z.string(),
|
|
47
|
+
repositoryIdentity: RepositoryIdentitySchema,
|
|
46
48
|
commit: z.string().regex(/^[a-f0-9]{40}$/),
|
|
47
49
|
digest: z.string().regex(/^[a-f0-9]{64}$/),
|
|
48
50
|
bytes: z.number().int().positive(),
|
|
@@ -61,6 +63,7 @@ export function assertPipelineSourcePlan({ plan, request }) {
|
|
|
61
63
|
const receipt = parsed.data.sourceSnapshot;
|
|
62
64
|
if (receipt.sourceEnvironment === request.sourceEnvironment
|
|
63
65
|
&& receipt.sourceRepositoryId === request.sourceRepositoryId
|
|
66
|
+
&& receipt.repositoryIdentity.repositoryId === receipt.sourceRepositoryId
|
|
64
67
|
&& receipt.repo === repo
|
|
65
68
|
&& parsed.data.repo === repo
|
|
66
69
|
&& parsed.data.environment === request.environment
|
package/dist/repos/commands.js
CHANGED
|
@@ -247,6 +247,11 @@ export async function reposShowCommand(args) {
|
|
|
247
247
|
console.log(`${LOG} repo on ${ctx.env.name}:`);
|
|
248
248
|
console.log(` path: ${namespace}/${name}`);
|
|
249
249
|
console.log(` id: ${repo.id}`);
|
|
250
|
+
const identity = repo.repositoryIdentity;
|
|
251
|
+
const identityLabel = identity
|
|
252
|
+
? `${identity.tenantId}/${identity.repositoryId} (generation ${identity.generation})`
|
|
253
|
+
: identity === null ? 'legacy — not adopted' : 'not available on this Atlas release';
|
|
254
|
+
console.log(` identity: ${identityLabel}`);
|
|
250
255
|
console.log(` default branch: ${repo.defaultBranch}`);
|
|
251
256
|
if (repo.gitBackend) {
|
|
252
257
|
console.log(` git backend: ${repo.gitBackend}`);
|
|
@@ -789,6 +794,10 @@ export async function runReposCommand(sub, args) {
|
|
|
789
794
|
return await reposNamespacesCommand(args);
|
|
790
795
|
case 'show':
|
|
791
796
|
return await reposShowCommand(args);
|
|
797
|
+
case 'identity': {
|
|
798
|
+
const { reposIdentityCommand } = await import('./identity.js');
|
|
799
|
+
return await reposIdentityCommand(args);
|
|
800
|
+
}
|
|
792
801
|
case 'create':
|
|
793
802
|
return await reposCreateCommand(args);
|
|
794
803
|
case 'clone':
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RepositoryIdentity } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
2
|
+
export declare function readRepositoryIdentityFile({ directory }: {
|
|
3
|
+
directory: string;
|
|
4
|
+
}): Promise<{
|
|
5
|
+
schemaVersion: 1;
|
|
6
|
+
identity: {
|
|
7
|
+
tenantId: string;
|
|
8
|
+
repositoryId: string;
|
|
9
|
+
generation: number;
|
|
10
|
+
};
|
|
11
|
+
metadata: Record<string, import("zod").JSONType>;
|
|
12
|
+
} | null>;
|
|
13
|
+
/** Create-only: retain authored metadata and never silently rebind or overwrite a receipt. */
|
|
14
|
+
export declare function writeRepositoryIdentity({ directory, identity }: {
|
|
15
|
+
directory: string;
|
|
16
|
+
identity: RepositoryIdentity;
|
|
17
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { lstat, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { assertRepositoryIdentity, parseRepositoryReceipt, renderRepositoryReceipt } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
4
|
+
export async function readRepositoryIdentityFile({ directory }) {
|
|
5
|
+
const configurationDirectory = join(resolve(directory), '.seq');
|
|
6
|
+
try {
|
|
7
|
+
if (!(await lstat(configurationDirectory)).isDirectory())
|
|
8
|
+
throw new Error('.seq must be a regular directory');
|
|
9
|
+
const filename = join(configurationDirectory, 'identity.json');
|
|
10
|
+
const stat = await lstat(filename);
|
|
11
|
+
if (!stat.isFile())
|
|
12
|
+
throw new Error('.seq/identity.json must be a regular file');
|
|
13
|
+
if (stat.size > 65_536)
|
|
14
|
+
throw new Error('Repository identity exceeds 64 KiB');
|
|
15
|
+
return parseRepositoryReceipt({ text: await readFile(filename, 'utf8') });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
19
|
+
return null;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Create-only: retain authored metadata and never silently rebind or overwrite a receipt. */
|
|
24
|
+
export async function writeRepositoryIdentity({ directory, identity }) {
|
|
25
|
+
const root = resolve(directory);
|
|
26
|
+
if (!(await lstat(root)).isDirectory())
|
|
27
|
+
throw new Error('Identity installation requires a regular repository directory');
|
|
28
|
+
const existing = await readRepositoryIdentityFile({ directory: root });
|
|
29
|
+
const filename = join(root, '.seq/identity.json');
|
|
30
|
+
if (existing) {
|
|
31
|
+
assertRepositoryIdentity({ receipt: existing, expected: identity });
|
|
32
|
+
return filename;
|
|
33
|
+
}
|
|
34
|
+
await mkdir(join(root, '.seq'), { recursive: true });
|
|
35
|
+
if (!(await lstat(join(root, '.seq'))).isDirectory())
|
|
36
|
+
throw new Error('.seq must be a regular directory');
|
|
37
|
+
await writeFile(filename, renderRepositoryReceipt({ identity }), { flag: 'wx' });
|
|
38
|
+
return filename;
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
|
|
5
|
+
import { RepositoryIdentitySchema, assertRepositoryIdentity, renderRepositoryReceipt } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
6
|
+
import { getJson, patchJson } from '../atlas-client.js';
|
|
7
|
+
import { clientOptions, flagBool } from '../functions/commands.js';
|
|
8
|
+
import { cloneUrl, parseRepoPath, reposContext, stringFlag } from './commands.js';
|
|
9
|
+
import { readRepositoryIdentityFile, writeRepositoryIdentity } from './identity-file.js';
|
|
10
|
+
/** A local receipt may only be installed into the clone explicitly addressed by this command. */
|
|
11
|
+
function assertCloneOrigin({ directory, expected }) {
|
|
12
|
+
let origin;
|
|
13
|
+
let root;
|
|
14
|
+
try {
|
|
15
|
+
const options = { cwd: directory, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] };
|
|
16
|
+
root = execFileSync('git', ['rev-parse', '--show-toplevel'], options).trim();
|
|
17
|
+
origin = execFileSync('git', ['remote', 'get-url', 'origin'], options).trim();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new Error('Run identity --write in a git-service clone with an origin remote');
|
|
21
|
+
}
|
|
22
|
+
if (realpathSync(directory) !== realpathSync(root))
|
|
23
|
+
throw new Error('Identity installation requires the Git worktree root; run from that directory or pass it with --dir');
|
|
24
|
+
// Do not echo a remote: old checkouts may still contain credentials in it.
|
|
25
|
+
const normalize = (url) => url.replace(/\/$/, '').replace(/\.git$/, '');
|
|
26
|
+
if (normalize(origin) !== normalize(expected))
|
|
27
|
+
throw new Error('Clone origin does not match this repository/environment; refusing to install identity');
|
|
28
|
+
}
|
|
29
|
+
export async function reposIdentityCommand(args) {
|
|
30
|
+
if (args.positional.length !== 1)
|
|
31
|
+
throw new Error('Expected exactly one repository: repos identity <namespace/name> -e <env>');
|
|
32
|
+
for (const key of Object.keys(args.flags)) {
|
|
33
|
+
if (!['e', 'env', 'dir', 'write', 'adopt', 'yes', 'json'].includes(key))
|
|
34
|
+
throw new Error(`Unknown identity flag --${key}`);
|
|
35
|
+
}
|
|
36
|
+
const { namespace, name } = parseRepoPath(args.positional[0]);
|
|
37
|
+
const adopt = flagBool(args.flags, 'adopt');
|
|
38
|
+
const write = flagBool(args.flags, 'write');
|
|
39
|
+
if (adopt && (!write || !flagBool(args.flags, 'yes')))
|
|
40
|
+
throw new Error('Legacy adoption requires --write --yes; inspect repos show first. Adoption binds ownership but does not deploy anything.');
|
|
41
|
+
const directory = resolve(stringFlag(args.flags, 'dir') ?? '.');
|
|
42
|
+
const ctx = await reposContext(args);
|
|
43
|
+
const resolved = await resolveRepo({ ...clientOptions(ctx), namespace, name });
|
|
44
|
+
const path = `/api/git-service/repos/${resolved.id}`;
|
|
45
|
+
let repo = await getJson({ ...clientOptions(ctx), path });
|
|
46
|
+
if (repo.repositoryIdentity === undefined)
|
|
47
|
+
throw new Error('This Atlas release does not expose repository identities; upgrade Atlas before adoption');
|
|
48
|
+
if (write)
|
|
49
|
+
assertCloneOrigin({ directory, expected: cloneUrl(ctx, resolved.id) });
|
|
50
|
+
const existing = write ? await readRepositoryIdentityFile({ directory }) : null;
|
|
51
|
+
if (repo.repositoryIdentity === null) {
|
|
52
|
+
if (!adopt)
|
|
53
|
+
throw new Error('Legacy repository has no identity. An administrator can run repos identity <namespace/name> -e <env> --write --adopt --yes in its clone, then submit the file through a pull request.');
|
|
54
|
+
if (existing)
|
|
55
|
+
throw new Error('Unadopted repository already has an identity file; investigate its provenance before adoption');
|
|
56
|
+
repo = await patchJson({ ...clientOptions(ctx), path, body: { adoptIdentity: true } });
|
|
57
|
+
}
|
|
58
|
+
const identity = RepositoryIdentitySchema.parse(repo.repositoryIdentity);
|
|
59
|
+
if (identity.repositoryId !== resolved.id)
|
|
60
|
+
throw new Error('Platform identity does not match the addressed repository');
|
|
61
|
+
if (existing)
|
|
62
|
+
assertRepositoryIdentity({ receipt: existing, expected: identity });
|
|
63
|
+
if (write) {
|
|
64
|
+
const filename = await writeRepositoryIdentity({ directory, identity });
|
|
65
|
+
console.error(`[seq-studio] Identity retained at ${filename}. Commit and review it normally; no source was pushed or deployed.`);
|
|
66
|
+
}
|
|
67
|
+
console.log(renderRepositoryReceipt({ identity, metadata: existing?.metadata }).trimEnd());
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
package/dist/sandbox-auth.d.ts
CHANGED
|
@@ -38,6 +38,17 @@ export declare class SandboxAuthError extends Error {
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function sandboxTarget(env?: NodeJS.ProcessEnv): SandboxTarget | null;
|
|
40
40
|
export declare function isSandboxTokenMode(env?: NodeJS.ProcessEnv): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* One line naming the deployment a sandbox is pinned to, for help, envs and
|
|
43
|
+
* whoami. An agent reads it to learn where its commands go and that `-e` and
|
|
44
|
+
* `envs add` cannot point them anywhere else.
|
|
45
|
+
*/
|
|
46
|
+
export declare function describeSandboxTarget(target: SandboxTarget): string;
|
|
47
|
+
/**
|
|
48
|
+
* Lines appended to top-level help: the pinned deployment in sandbox token
|
|
49
|
+
* mode, the misconfiguration when only one variable is set, else nothing.
|
|
50
|
+
*/
|
|
51
|
+
export declare function sandboxUsageFooter(): string;
|
|
41
52
|
/** Read the current bearer. Never cached: Atlas rotates the file between requests. */
|
|
42
53
|
export declare function readSandboxToken(target: SandboxTarget): Promise<string>;
|
|
43
54
|
export declare function isSandboxOrigin({ target, url }: {
|
package/dist/sandbox-auth.js
CHANGED
|
@@ -59,6 +59,28 @@ export function sandboxTarget(env = process.env) {
|
|
|
59
59
|
export function isSandboxTokenMode(env = process.env) {
|
|
60
60
|
return sandboxTarget(env) !== null;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* One line naming the deployment a sandbox is pinned to, for help, envs and
|
|
64
|
+
* whoami. An agent reads it to learn where its commands go and that `-e` and
|
|
65
|
+
* `envs add` cannot point them anywhere else.
|
|
66
|
+
*/
|
|
67
|
+
export function describeSandboxTarget(target) {
|
|
68
|
+
return (`Sandbox token mode: ${SANDBOX_BASE_URL_ENV} and ${SANDBOX_TOKEN_FILE_ENV} pin every command to ` +
|
|
69
|
+
`${target.baseUrl} (environment "${SANDBOX_ENV_NAME}"). -e is optional; any value resolves to this deployment.`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Lines appended to top-level help: the pinned deployment in sandbox token
|
|
73
|
+
* mode, the misconfiguration when only one variable is set, else nothing.
|
|
74
|
+
*/
|
|
75
|
+
export function sandboxUsageFooter() {
|
|
76
|
+
try {
|
|
77
|
+
const target = sandboxTarget();
|
|
78
|
+
return target ? `\n ${describeSandboxTarget(target)}\n` : '';
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return `\n ${error instanceof Error ? error.message : String(error)}\n`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
62
84
|
/** Read the current bearer. Never cached: Atlas rotates the file between requests. */
|
|
63
85
|
export async function readSandboxToken(target) {
|
|
64
86
|
let text;
|
package/dist/update-check.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare function currentVersion(): string;
|
|
|
3
3
|
export declare function updateCheckCachePath(): string;
|
|
4
4
|
/** Exclusive-create marker that makes "who spawns the refresh?" atomic. */
|
|
5
5
|
export declare function updateCheckClaimPath(): string;
|
|
6
|
+
/** Receipt is scoped to the local user cache and installed/available pair. */
|
|
7
|
+
export declare function updateNoticeReceiptPath(installed: string, available: string): string;
|
|
6
8
|
/**
|
|
7
9
|
* True when `candidate` is a strictly newer semver than `current`.
|
|
8
10
|
* Prerelease suffixes are ignored — the published channel is plain
|
|
@@ -19,7 +21,7 @@ export declare function isNewerVersion(candidate: string, current: string): bool
|
|
|
19
21
|
*/
|
|
20
22
|
export declare function refreshUpdateCache(): Promise<void>;
|
|
21
23
|
/**
|
|
22
|
-
* Print
|
|
24
|
+
* Print one structured upgrade notice to stderr when the cached registry
|
|
23
25
|
* state says a newer version is published, and kick off a detached refresh
|
|
24
26
|
* when the cache is stale. Reads only local state — adds no network latency
|
|
25
27
|
* to the command. Never throws.
|