@sequenceholdings/studio-cli 0.1.13 → 0.1.18
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 +94 -30
- package/dist/artifact/delegate.d.ts +2 -2
- package/dist/artifact/delegate.js +31 -73
- package/dist/atlas-client.js +52 -37
- package/dist/auth-cmds/commands.d.ts +1 -1
- package/dist/auth-cmds/commands.js +12 -7
- package/dist/auth.d.ts +97 -19
- package/dist/auth.js +376 -81
- package/dist/config.d.ts +3 -3
- package/dist/config.js +18 -13
- package/dist/env-catalog.js +13 -3
- package/dist/env-flags.d.ts +2 -0
- package/dist/env-flags.js +2 -0
- package/dist/env-registry.d.ts +27 -0
- package/dist/env-registry.js +204 -0
- package/dist/envs/commands.d.ts +1 -1
- package/dist/envs/commands.js +41 -3
- package/dist/file-lock.d.ts +5 -0
- package/dist/file-lock.js +187 -0
- package/dist/functions/commands.d.ts +9 -1
- package/dist/functions/commands.js +71 -29
- package/dist/functions/manifest.d.ts +1 -0
- package/dist/functions/manifest.js +36 -0
- package/dist/login.d.ts +8 -3
- package/dist/login.js +46 -34
- package/dist/main.d.ts +2 -1
- package/dist/main.js +35 -12
- package/dist/orm/delegate.js +15 -2
- package/dist/pat-hints.js +2 -2
- package/dist/pipeline/commands.d.ts +58 -0
- package/dist/pipeline/commands.js +330 -0
- package/dist/pipeline/lifecycle.d.ts +58 -0
- package/dist/pipeline/lifecycle.js +348 -0
- package/dist/pipeline/pinning.d.ts +5 -0
- package/dist/pipeline/pinning.js +9 -0
- package/dist/pipeline/templates.d.ts +11 -0
- package/dist/pipeline/templates.js +166 -0
- package/dist/process/build.d.ts +4 -0
- package/dist/process/build.js +31 -1
- package/dist/process/codegen.js +19 -1
- package/dist/process/commands.js +97 -47
- package/dist/process/compiler-subprocess.d.ts +29 -0
- package/dist/process/compiler-subprocess.js +99 -0
- package/dist/process/compiler-worker.d.ts +1 -0
- package/dist/process/compiler-worker.js +38 -0
- package/dist/process/lint.d.ts +8 -0
- package/dist/process/lint.js +76 -29
- package/dist/process/repo-install.js +18 -2
- package/dist/repos/commands.d.ts +1 -1
- package/dist/repos/commands.js +17 -12
- package/dist/secrets/commands.d.ts +1 -1
- package/dist/secrets/commands.js +18 -18
- package/package.json +8 -3
|
@@ -6,10 +6,11 @@ import { promisify } from 'node:util';
|
|
|
6
6
|
import { createInterface } from 'node:readline';
|
|
7
7
|
import { Writable } from 'node:stream';
|
|
8
8
|
import { load as parseYaml } from 'js-yaml';
|
|
9
|
-
import {
|
|
9
|
+
import { getAccessTokenWithMode, tryGetAccessTokenWithMode } from '../auth.js';
|
|
10
10
|
import { resolveEnvWithDiscovery } from '../config.js';
|
|
11
11
|
import { AtlasApiError, deleteJson, getJson, postJson } from '../atlas-client.js';
|
|
12
12
|
import { clarifyApplyFailureReason, printCliError } from '../cli-errors.js';
|
|
13
|
+
import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
|
|
13
14
|
import { confirmYes } from '../prompt.js';
|
|
14
15
|
import { collectBundleFiles, isDirectory, validateLocalBundle, } from './bundle.js';
|
|
15
16
|
import { managedFunctionManifestSchema, MF_MANIFEST_FILENAME, manifestEgressHosts, manifestEgressIpRanges, } from './manifest.js';
|
|
@@ -23,15 +24,48 @@ const POLL_TIMEOUT_MS = 20 * 60 * 1000;
|
|
|
23
24
|
export function flagBool(flags, ...keys) {
|
|
24
25
|
return keys.some((key) => flags[key] === true || flags[key] === 'true');
|
|
25
26
|
}
|
|
27
|
+
export function requestedEnvironment(args) {
|
|
28
|
+
return ((typeof args.flags.env === 'string' ? args.flags.env : undefined) ??
|
|
29
|
+
(typeof args.flags.e === 'string' ? args.flags.e : undefined));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve env + token for Atlas network commands. Requires an explicit
|
|
33
|
+
* `-e/--env` so partners never hit the built-in `local` default and get an
|
|
34
|
+
* opaque `fetch failed` (same contract as `functions deploy`).
|
|
35
|
+
*/
|
|
26
36
|
export async function buildContext(args) {
|
|
27
|
-
const requested = (
|
|
28
|
-
|
|
37
|
+
const requested = requestedEnvironment(args);
|
|
38
|
+
if (!requested) {
|
|
39
|
+
throw new Error(REQUIRE_EXPLICIT_ENV_MESSAGE);
|
|
40
|
+
}
|
|
29
41
|
const env = await resolveEnvWithDiscovery({ requested });
|
|
30
|
-
const
|
|
31
|
-
return { env, token };
|
|
42
|
+
const auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url });
|
|
43
|
+
return { authMode: auth.authMode, env, token: auth.token };
|
|
32
44
|
}
|
|
33
45
|
export function clientOptions(ctx) {
|
|
34
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
baseUrl: ctx.env.url,
|
|
48
|
+
token: ctx.token,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function sourceClientOptions(ctx) {
|
|
52
|
+
return {
|
|
53
|
+
...(ctx.authMode ? { authMode: ctx.authMode } : {}),
|
|
54
|
+
...clientOptions(ctx),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function buildSourceOptions({ args, spec, }) {
|
|
58
|
+
if (spec.kind === 'git-service') {
|
|
59
|
+
return sourceClientOptions(await buildContext(args));
|
|
60
|
+
}
|
|
61
|
+
if (spec.kind === 'git-url') {
|
|
62
|
+
const auth = await tryGetAccessTokenWithMode({
|
|
63
|
+
failClosedForM2m: true,
|
|
64
|
+
env: requestedEnvironment(args),
|
|
65
|
+
});
|
|
66
|
+
return auth ? { authMode: auth.authMode } : {};
|
|
67
|
+
}
|
|
68
|
+
return {};
|
|
35
69
|
}
|
|
36
70
|
export async function readManifestOptional(dir) {
|
|
37
71
|
const path = join(dir, MF_MANIFEST_FILENAME);
|
|
@@ -316,9 +350,10 @@ export async function functionsInitCommand(args) {
|
|
|
316
350
|
// ---------------------------------------------------------------------------
|
|
317
351
|
export async function functionsBuildCommand(args) {
|
|
318
352
|
const spec = parseFunctionsSourceSpec(args);
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
|
|
353
|
+
// A public git URL needs no bearer token, but optional auth resolution still
|
|
354
|
+
// identifies a selected M2M principal so policy can reject arbitrary CI
|
|
355
|
+
// input before cloning. Local builds remain completely offline.
|
|
356
|
+
const remote = await buildSourceOptions({ args, spec });
|
|
322
357
|
const source = await resolveArtifactSource(spec, remote);
|
|
323
358
|
try {
|
|
324
359
|
return await buildFromResolvedSource({ spec, source });
|
|
@@ -376,13 +411,19 @@ async function getFunctionDetail(ctx, functionId) {
|
|
|
376
411
|
}
|
|
377
412
|
}
|
|
378
413
|
export async function functionsDeployCommand(args) {
|
|
414
|
+
// Fail before source resolution / auth so a missing `-e` never becomes
|
|
415
|
+
// `fetch failed` against localhost. `buildContext` enforces the same rule.
|
|
416
|
+
if (!requestedEnvironment(args)) {
|
|
417
|
+
console.error(`${LOG} ${REQUIRE_EXPLICIT_ENV_MESSAGE}`);
|
|
418
|
+
return 1;
|
|
419
|
+
}
|
|
379
420
|
const spec = parseFunctionsSourceSpec(args);
|
|
380
|
-
//
|
|
381
|
-
//
|
|
382
|
-
// sources defer auth until after
|
|
383
|
-
//
|
|
384
|
-
const ctx = spec.kind
|
|
385
|
-
const source = await resolveArtifactSource(spec, ctx ?
|
|
421
|
+
// Remote deploys resolve auth up front: --repo needs it to fetch the tree,
|
|
422
|
+
// while --git-url must reject a selected M2M principal before cloning.
|
|
423
|
+
// Local sources still defer auth until after validation so malformed local
|
|
424
|
+
// input fails before any login/network work.
|
|
425
|
+
const ctx = spec.kind !== 'local' ? await buildContext(args) : null;
|
|
426
|
+
const source = await resolveArtifactSource(spec, ctx ? sourceClientOptions(ctx) : {});
|
|
386
427
|
try {
|
|
387
428
|
return await deployFromResolvedSource({ args, spec, ctx, source });
|
|
388
429
|
}
|
|
@@ -837,7 +878,7 @@ async function listVersions(ctx, functionId) {
|
|
|
837
878
|
export async function functionsPromoteCommand(args) {
|
|
838
879
|
const versionName = args.positional[0];
|
|
839
880
|
if (!versionName) {
|
|
840
|
-
console.error('usage: seq-studio functions promote <version>
|
|
881
|
+
console.error('usage: seq-studio functions promote <version> -e <env> [--fn slug]');
|
|
841
882
|
return 1;
|
|
842
883
|
}
|
|
843
884
|
const ctx = await buildContext(args);
|
|
@@ -932,32 +973,33 @@ export async function functionsDeleteCommand(args) {
|
|
|
932
973
|
export const FUNCTIONS_USAGE = `usage:
|
|
933
974
|
seq-studio functions init <dir> scaffold manifest + TypeScript hello-world handler
|
|
934
975
|
seq-studio functions build [--dir d] local pre-flight (manifest, lockfile, size)
|
|
935
|
-
seq-studio functions deploy
|
|
936
|
-
seq-studio functions list
|
|
937
|
-
seq-studio functions show
|
|
938
|
-
seq-studio functions logs
|
|
939
|
-
seq-studio functions promote <version>
|
|
940
|
-
seq-studio functions rollback [<version>]
|
|
941
|
-
seq-studio functions delete [--yes]
|
|
976
|
+
seq-studio functions deploy -e <env> [-m msg] preview + confirm secrets + upload and deploy
|
|
977
|
+
seq-studio functions list -e <env> [--match-local] functions visible on the environment
|
|
978
|
+
seq-studio functions show -e <env> [--fn slug] detail for one function (versions, secrets)
|
|
979
|
+
seq-studio functions logs -e <env> [--limit N] [--since t] Cloud Logging snapshot (reader-gated)
|
|
980
|
+
seq-studio functions promote <version> -e <env> make a version live
|
|
981
|
+
seq-studio functions rollback [<version>] -e <env> redeploy a prior version
|
|
982
|
+
seq-studio functions delete -e <env> [--yes] archive function + tear down GCP resources
|
|
942
983
|
(version history is retained)
|
|
943
984
|
|
|
944
|
-
Flags: -e/--env <env|preview:<slug>> (see: seq-studio envs list) · --fn <slug> · --dir <path>
|
|
985
|
+
Flags: -e/--env <env|preview:<slug>> (required for network commands; see: seq-studio envs list) · --fn <slug> · --dir <path>
|
|
945
986
|
--from-env-file <path> (default: .env) source file for secret values
|
|
946
987
|
--no-wait · --yes
|
|
947
988
|
--no-provision (deploy) update-only: error instead of registering a new
|
|
948
989
|
shell, writing secret values, or attaching secrets (CI sweep)
|
|
949
990
|
|
|
950
991
|
Source for build/deploy: a local --dir (default .), a platform git-service
|
|
951
|
-
repo (--repo <ns>/<name>), or
|
|
992
|
+
repo (--repo <ns>/<name>), or a public HTTPS git URL (--git-url <url>). --ref selects a
|
|
952
993
|
branch/tag/commit (default: the repo's default branch). Remote sources record
|
|
953
994
|
the pinned commit as provenance (never dirty) and NEVER read a repo-committed
|
|
954
995
|
.env for secret values — provision secrets server-side or pass a local
|
|
955
996
|
--from-env-file (resolved against your cwd).
|
|
956
997
|
|
|
957
|
-
--repo
|
|
958
|
-
|
|
959
|
-
Atlas → Settings → Tokens).
|
|
960
|
-
|
|
998
|
+
Interactive --repo builds clone over smart-HTTP and require a repo:read git
|
|
999
|
+
PAT in ATLAS_GIT_PAT (\`seq-studio auth pat create --scopes repo:read\`, or
|
|
1000
|
+
Atlas → Settings → Tokens). Headless M2M builds use JSON materialize and
|
|
1001
|
+
accept only platform-managed --repo sources. Interactive builds also need
|
|
1002
|
+
--env + seq-studio login to resolve the repo and deploy.
|
|
961
1003
|
`;
|
|
962
1004
|
export async function runFunctionsCommand(sub, args) {
|
|
963
1005
|
try {
|
|
@@ -57,6 +57,7 @@ export declare const managedFunctionManifestSchema: z.ZodObject<{
|
|
|
57
57
|
}, z.core.$strip>>;
|
|
58
58
|
secrets: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
59
59
|
egress: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
60
|
+
service_account: z.ZodOptional<z.ZodString>;
|
|
60
61
|
input_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
61
62
|
output_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
62
63
|
capabilities: z.ZodDefault<z.ZodObject<{
|
|
@@ -488,6 +488,11 @@ function validateCapabilityGates({ gates, uses, roles, }) {
|
|
|
488
488
|
}
|
|
489
489
|
return errors;
|
|
490
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Platform service-account reference: slug (strictly lowercase) or uuid id.
|
|
493
|
+
* Mirrors atlas/src/server/services/managed-functions/manifest.ts.
|
|
494
|
+
*/
|
|
495
|
+
const SERVICE_ACCOUNT_REF_RE = /^([a-z][a-z0-9-]{1,98}|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
491
496
|
export const managedFunctionManifestSchema = z.object({
|
|
492
497
|
schema_version: z.literal(1).default(1),
|
|
493
498
|
function: z.object({
|
|
@@ -538,6 +543,17 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
538
543
|
}
|
|
539
544
|
})
|
|
540
545
|
.default([]),
|
|
546
|
+
/**
|
|
547
|
+
* The platform service account this function ACTS AS for ORM data access
|
|
548
|
+
* (slug or id). Required whenever `capabilities.data` reaches a namespace,
|
|
549
|
+
* rejected otherwise. Resolved and authorized server-side at activation —
|
|
550
|
+
* the deploy actor must hold `actor` on the account when the attachment
|
|
551
|
+
* changes. Mirrors atlas/src/server/services/managed-functions/manifest.ts.
|
|
552
|
+
*/
|
|
553
|
+
service_account: z
|
|
554
|
+
.string()
|
|
555
|
+
.regex(SERVICE_ACCOUNT_REF_RE, 'service_account must be a platform service-account slug (lowercase alphanumeric with hyphens) or uuid')
|
|
556
|
+
.optional(),
|
|
541
557
|
input_schema: z.record(z.string(), z.unknown()).optional(),
|
|
542
558
|
output_schema: z.record(z.string(), z.unknown()).optional(),
|
|
543
559
|
/**
|
|
@@ -583,4 +599,24 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
583
599
|
})) {
|
|
584
600
|
ctx.addIssue({ code: 'custom', message, path: ['capabilities', 'gates'] });
|
|
585
601
|
}
|
|
602
|
+
// A namespace is "reached" when its block declares at least one table,
|
|
603
|
+
// action, or raw query — the same rule the server's floor reconciliation
|
|
604
|
+
// uses (readManifestDataNamespaces).
|
|
605
|
+
const reachesData = Object.values(manifest.capabilities.data).some((block) => block.tables.length > 0 || block.actions.length > 0 || block.query);
|
|
606
|
+
if (reachesData && manifest.service_account === undefined) {
|
|
607
|
+
ctx.addIssue({
|
|
608
|
+
code: 'custom',
|
|
609
|
+
message: 'capabilities.data requires a top-level service_account — the platform service ' +
|
|
610
|
+
'account this function acts as for ORM data access (a platform operator creates ' +
|
|
611
|
+
'the account; the deployer needs the actor role on it)',
|
|
612
|
+
path: ['service_account'],
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
if (!reachesData && manifest.service_account !== undefined) {
|
|
616
|
+
ctx.addIssue({
|
|
617
|
+
code: 'custom',
|
|
618
|
+
message: 'service_account is only used for ORM data access — declare capabilities.data or remove it',
|
|
619
|
+
path: ['service_account'],
|
|
620
|
+
});
|
|
621
|
+
}
|
|
586
622
|
});
|
package/dist/login.d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
import { type AuthRealm } from './auth.js';
|
|
1
2
|
interface LoginOptions {
|
|
2
3
|
port?: number;
|
|
3
4
|
timeoutMs?: number;
|
|
4
5
|
fetchImpl?: typeof fetch;
|
|
5
6
|
now?: () => number;
|
|
6
7
|
openBrowser?: (authorizationUrl: string) => void | Promise<void>;
|
|
8
|
+
/** Auth0 login context — the Sequence realm by default, or a registered
|
|
9
|
+
* OpCo environment's realm (`seq-studio envs add`), which pins the Auth0
|
|
10
|
+
* Organization so the token carries the org context tenant APIs require. */
|
|
11
|
+
realm?: AuthRealm;
|
|
7
12
|
}
|
|
8
13
|
export declare function openSystemBrowser(authorizationUrl: string): Promise<void>;
|
|
9
|
-
export declare function loginWithPkce({ fetchImpl, now, openBrowser, port, timeoutMs, }: LoginOptions): Promise<
|
|
14
|
+
export declare function loginWithPkce({ fetchImpl, now, openBrowser, port, realm, timeoutMs, }: LoginOptions): Promise<string>;
|
|
10
15
|
/**
|
|
11
16
|
* Best-effort catalog refresh after a successful login. Drop the old cache
|
|
12
17
|
* first so a prior identity's tier never lingers; discovery failures must not
|
|
13
18
|
* fail login. Exported for unit tests.
|
|
14
19
|
*/
|
|
15
20
|
export declare function refreshCatalogAfterLogin(): Promise<void>;
|
|
16
|
-
export declare function login(): Promise<void>;
|
|
17
|
-
export declare function logout(): Promise<void>;
|
|
21
|
+
export declare function login(envName?: string): Promise<void>;
|
|
22
|
+
export declare function logout(envName?: string): Promise<void>;
|
|
18
23
|
export {};
|
package/dist/login.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createServer } from 'node:http';
|
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
|
-
import {
|
|
7
|
+
import { deleteRealmTokens, realmForEnv, saveTokens, seqapiTokenPath, SEQUENCE_AUTH_REALM, SEQUENCE_REALM, verifyTokenMatchesRealm, } from './auth.js';
|
|
8
8
|
import { manualEnvConfigHint } from './config.js';
|
|
9
9
|
import { bootstrapUrl, clearCatalog, fetchCatalog } from './env-catalog.js';
|
|
10
10
|
const DEFAULT_REDIRECT_PORT = 5099;
|
|
@@ -22,16 +22,18 @@ function configuredPort() {
|
|
|
22
22
|
}
|
|
23
23
|
return port;
|
|
24
24
|
}
|
|
25
|
-
function authorizationUrl({ challenge, redirectUri, state, }) {
|
|
26
|
-
const url = new URL(`https://${
|
|
25
|
+
function authorizationUrl({ challenge, realm, redirectUri, state, }) {
|
|
26
|
+
const url = new URL(`https://${realm.domain}/authorize`);
|
|
27
27
|
url.searchParams.set('response_type', 'code');
|
|
28
|
-
url.searchParams.set('client_id',
|
|
28
|
+
url.searchParams.set('client_id', realm.clientId);
|
|
29
29
|
url.searchParams.set('redirect_uri', redirectUri);
|
|
30
|
-
url.searchParams.set('scope', 'openid profile email
|
|
31
|
-
url.searchParams.set('audience',
|
|
30
|
+
url.searchParams.set('scope', 'openid profile email');
|
|
31
|
+
url.searchParams.set('audience', realm.audience);
|
|
32
32
|
url.searchParams.set('code_challenge', challenge);
|
|
33
33
|
url.searchParams.set('code_challenge_method', 'S256');
|
|
34
34
|
url.searchParams.set('state', state);
|
|
35
|
+
if (realm.organization)
|
|
36
|
+
url.searchParams.set('organization', realm.organization);
|
|
35
37
|
return url.toString();
|
|
36
38
|
}
|
|
37
39
|
export async function openSystemBrowser(authorizationUrl) {
|
|
@@ -142,21 +144,16 @@ function parseTokenResponse(value) {
|
|
|
142
144
|
throw new Error('Auth0 token response was not an object.');
|
|
143
145
|
}
|
|
144
146
|
const accessToken = Reflect.get(value, 'access_token');
|
|
145
|
-
const refreshToken = Reflect.get(value, 'refresh_token');
|
|
146
147
|
const expiresIn = Reflect.get(value, 'expires_in');
|
|
147
148
|
if (typeof accessToken !== 'string' || !accessToken) {
|
|
148
149
|
throw new Error('Auth0 token response missing access_token.');
|
|
149
150
|
}
|
|
150
|
-
if (typeof refreshToken !== 'string' || !refreshToken) {
|
|
151
|
-
throw new Error('No refresh token returned. Ensure Auth0 offline access is enabled.');
|
|
152
|
-
}
|
|
153
151
|
return {
|
|
154
152
|
accessToken,
|
|
155
|
-
refreshToken,
|
|
156
153
|
expiresIn: typeof expiresIn === 'number' ? expiresIn : 86_400,
|
|
157
154
|
};
|
|
158
155
|
}
|
|
159
|
-
export async function loginWithPkce({ fetchImpl = fetch, now = Date.now, openBrowser = openSystemBrowser, port = configuredPort(), timeoutMs = DEFAULT_LOGIN_TIMEOUT_MS, }) {
|
|
156
|
+
export async function loginWithPkce({ fetchImpl = fetch, now = Date.now, openBrowser = openSystemBrowser, port = configuredPort(), realm = SEQUENCE_AUTH_REALM, timeoutMs = DEFAULT_LOGIN_TIMEOUT_MS, }) {
|
|
160
157
|
const verifier = base64Url(randomBytes(32));
|
|
161
158
|
const challenge = base64Url(createHash('sha256').update(verifier).digest());
|
|
162
159
|
const state = base64Url(randomBytes(32));
|
|
@@ -165,20 +162,21 @@ export async function loginWithPkce({ fetchImpl = fetch, now = Date.now, openBro
|
|
|
165
162
|
port,
|
|
166
163
|
timeoutMs,
|
|
167
164
|
onListening: (redirectUri) => {
|
|
168
|
-
const url = authorizationUrl({ challenge, redirectUri, state });
|
|
169
|
-
console.error(`Opening browser for Sequence login. If it does not open, visit:\n${url}`);
|
|
165
|
+
const url = authorizationUrl({ challenge, realm, redirectUri, state });
|
|
166
|
+
console.error(`Opening browser for Sequence login [${realm.name}]. If it does not open, visit:\n${url}`);
|
|
170
167
|
void Promise.resolve(openBrowser(url)).catch((error) => {
|
|
171
168
|
const message = error instanceof Error ? error.message : String(error);
|
|
172
169
|
console.error(`Could not open a browser automatically: ${message}`);
|
|
173
170
|
});
|
|
174
171
|
},
|
|
175
172
|
});
|
|
176
|
-
const tokenResponse = await fetchImpl(`https://${
|
|
173
|
+
const tokenResponse = await fetchImpl(`https://${realm.domain}/oauth/token`, {
|
|
177
174
|
method: 'POST',
|
|
175
|
+
redirect: 'manual',
|
|
178
176
|
headers: { 'Content-Type': 'application/json' },
|
|
179
177
|
body: JSON.stringify({
|
|
180
178
|
grant_type: 'authorization_code',
|
|
181
|
-
client_id:
|
|
179
|
+
client_id: realm.clientId,
|
|
182
180
|
code: callback.code,
|
|
183
181
|
redirect_uri: callback.redirectUri,
|
|
184
182
|
code_verifier: verifier,
|
|
@@ -188,11 +186,12 @@ export async function loginWithPkce({ fetchImpl = fetch, now = Date.now, openBro
|
|
|
188
186
|
throw new Error(`Auth0 token exchange failed (${tokenResponse.status}): ${await tokenResponse.text()}`);
|
|
189
187
|
}
|
|
190
188
|
const tokens = parseTokenResponse(await tokenResponse.json());
|
|
189
|
+
verifyTokenMatchesRealm({ accessToken: tokens.accessToken, realm });
|
|
191
190
|
await saveTokens({
|
|
192
191
|
access_token: tokens.accessToken,
|
|
193
|
-
refresh_token: tokens.refreshToken,
|
|
194
192
|
expires_at: now() / 1_000 + tokens.expiresIn,
|
|
195
|
-
});
|
|
193
|
+
}, realm.name);
|
|
194
|
+
return tokens.accessToken;
|
|
196
195
|
}
|
|
197
196
|
/**
|
|
198
197
|
* Best-effort catalog refresh after a successful login. Drop the old cache
|
|
@@ -216,26 +215,39 @@ export async function refreshCatalogAfterLogin() {
|
|
|
216
215
|
'run: seq-studio envs refresh');
|
|
217
216
|
console.log(manualEnvConfigHint());
|
|
218
217
|
}
|
|
219
|
-
export async function login() {
|
|
220
|
-
await
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
export async function login(envName) {
|
|
219
|
+
const realm = await realmForEnv(envName);
|
|
220
|
+
if (envName && realm.name === SEQUENCE_REALM && envName !== SEQUENCE_REALM) {
|
|
221
|
+
// A name that only exists in the Sequence catalog (staging, banksouth…)
|
|
222
|
+
// resolves to the Sequence realm — one login covers all of those. A typo'd
|
|
223
|
+
// OpCo name would silently do a Sequence login otherwise, so say which
|
|
224
|
+
// realm we're using.
|
|
225
|
+
console.error(`'${envName}' uses the shared Sequence login ` +
|
|
226
|
+
'(register OpCo environments with: seq-studio envs add <name> <url>).');
|
|
227
|
+
}
|
|
228
|
+
await loginWithPkce({ realm });
|
|
229
|
+
console.log(`Authenticated [${realm.name}]. Short-lived access token saved to ${seqapiTokenPath()}.`);
|
|
230
|
+
// The environment catalog is a Sequence-deployment surface; OpCo realm
|
|
231
|
+
// logins target a single known deployment and have nothing to discover.
|
|
232
|
+
if (realm.name === SEQUENCE_REALM) {
|
|
233
|
+
await refreshCatalogAfterLogin();
|
|
234
|
+
}
|
|
223
235
|
}
|
|
224
236
|
/**
|
|
225
|
-
* Pre-unification artifact-studio token file.
|
|
226
|
-
* still
|
|
227
|
-
* `readTokenConfig`, see shared/services/artifact-studio/src/config.ts), so
|
|
228
|
-
* logout must clear it too or artifact commands would stay authenticated
|
|
229
|
-
* after a successful logout.
|
|
237
|
+
* Pre-unification artifact-studio token file. New builds never read it, but
|
|
238
|
+
* logout still removes it so legacy bearer material does not linger on disk.
|
|
230
239
|
*/
|
|
231
240
|
function legacyArtifactTokenPath() {
|
|
232
241
|
return join(homedir(), '.config', 'sequence-artifact-studio', 'tokens.json');
|
|
233
242
|
}
|
|
234
|
-
export async function logout() {
|
|
235
|
-
|
|
236
|
-
await
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
243
|
+
export async function logout(envName) {
|
|
244
|
+
const realm = await realmForEnv(envName);
|
|
245
|
+
await deleteRealmTokens(realm.name);
|
|
246
|
+
if (realm.name === SEQUENCE_REALM) {
|
|
247
|
+
await rm(legacyArtifactTokenPath(), { force: true });
|
|
248
|
+
// The environment catalog belongs to the Sequence identity; tenant logout
|
|
249
|
+
// must not discard a still-authenticated Sequence user's cached tier.
|
|
250
|
+
await clearCatalog();
|
|
251
|
+
}
|
|
252
|
+
console.log(`Logged out [${realm.name}] from seq-studio and seqapi.`);
|
|
241
253
|
}
|
package/dist/main.d.ts
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* seq-studio functions <sub> manage Managed Functions
|
|
8
8
|
* seq-studio secrets <sub> manage org-owned Managed Secrets
|
|
9
9
|
* seq-studio repos <sub> manage platform git-service repos
|
|
10
|
+
* seq-studio pipeline <sub> author + validate Data Pipelines stage specs
|
|
10
11
|
* seq-studio auth <sub> manage git-service PATs
|
|
11
|
-
* seq-studio envs <sub> list/refresh
|
|
12
|
+
* seq-studio envs <sub> add/list/refresh environments
|
|
12
13
|
* seq-studio login authenticate interactively with Auth0
|
|
13
14
|
* seq-studio logout remove cached user tokens
|
|
14
15
|
* seq-studio doctor check token + env + writer gate
|
package/dist/main.js
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* seq-studio functions <sub> manage Managed Functions
|
|
8
8
|
* seq-studio secrets <sub> manage org-owned Managed Secrets
|
|
9
9
|
* seq-studio repos <sub> manage platform git-service repos
|
|
10
|
+
* seq-studio pipeline <sub> author + validate Data Pipelines stage specs
|
|
10
11
|
* seq-studio auth <sub> manage git-service PATs
|
|
11
|
-
* seq-studio envs <sub> list/refresh
|
|
12
|
+
* seq-studio envs <sub> add/list/refresh environments
|
|
12
13
|
* seq-studio login authenticate interactively with Auth0
|
|
13
14
|
* seq-studio logout remove cached user tokens
|
|
14
15
|
* seq-studio doctor check token + env + writer gate
|
|
@@ -24,11 +25,12 @@ const TOP_LEVEL_USAGE = `usage:
|
|
|
24
25
|
seq-studio functions <sub> [args] init | build | deploy | list | show | logs | promote | rollback | delete
|
|
25
26
|
seq-studio secrets <sub> [args] create | set | list | attach | detach | apply
|
|
26
27
|
seq-studio repos <sub> [args] list | namespaces | show | create | clone | pull | delete
|
|
28
|
+
seq-studio pipeline <sub> [args] init | validate — Data Pipelines stage specs
|
|
27
29
|
seq-studio auth <sub> [args] pat create | pat list | pat revoke
|
|
28
30
|
seq-studio orm <sub> [args] init | validate | plan | apply
|
|
29
|
-
seq-studio envs <sub> list | refresh
|
|
30
|
-
seq-studio login
|
|
31
|
-
seq-studio logout
|
|
31
|
+
seq-studio envs <sub> add | list | refresh environments
|
|
32
|
+
seq-studio login [--env <name>] authenticate in the browser
|
|
33
|
+
seq-studio logout [--env <name>] remove one realm's cached user tokens
|
|
32
34
|
seq-studio doctor [-e <env>] diagnose config, auth, and writer gate
|
|
33
35
|
seq-studio version print the installed version
|
|
34
36
|
seq-studio help show this message
|
|
@@ -87,13 +89,19 @@ export async function run(argv = process.argv.slice(2)) {
|
|
|
87
89
|
const { runOrmCommand } = await import('./orm/delegate.js');
|
|
88
90
|
return runOrmCommand(sub, rest);
|
|
89
91
|
}
|
|
92
|
+
case 'pipeline': {
|
|
93
|
+
// Lazy import keeps doctor/process from pulling in @sequenceholdings/pipeline-spec
|
|
94
|
+
// (an optional peer, same posture as @sequenceholdings/orm).
|
|
95
|
+
const { runPipelineCommand } = await import('./pipeline/commands.js');
|
|
96
|
+
return runPipelineCommand(sub, parseArgs(rest));
|
|
97
|
+
}
|
|
90
98
|
case 'envs': {
|
|
91
99
|
const { runEnvsCommand } = await import('./envs/commands.js');
|
|
92
100
|
return runEnvsCommand(sub, rest);
|
|
93
101
|
}
|
|
94
102
|
case 'login':
|
|
95
103
|
case 'logout':
|
|
96
|
-
return runSessionCommand({
|
|
104
|
+
return runSessionCommand({ args: [sub, ...rest].filter((a) => Boolean(a)), command: namespace });
|
|
97
105
|
case 'version':
|
|
98
106
|
case '--version':
|
|
99
107
|
case '-v': {
|
|
@@ -109,17 +117,32 @@ export async function run(argv = process.argv.slice(2)) {
|
|
|
109
117
|
return 1;
|
|
110
118
|
}
|
|
111
119
|
}
|
|
112
|
-
async function runSessionCommand({
|
|
113
|
-
|
|
114
|
-
|
|
120
|
+
async function runSessionCommand({ args, command, }) {
|
|
121
|
+
const usage = `usage: seq-studio ${command} [--env <name>]`;
|
|
122
|
+
if (args[0] === 'help' || args[0] === '--help' || args[0] === '-h') {
|
|
123
|
+
console.log(usage);
|
|
115
124
|
return 0;
|
|
116
125
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
let envName;
|
|
127
|
+
if (args.length > 0) {
|
|
128
|
+
const flags = parseArgs(args).flags;
|
|
129
|
+
envName =
|
|
130
|
+
(typeof flags.env === 'string' ? flags.env : undefined) ??
|
|
131
|
+
(typeof flags.e === 'string' ? flags.e : undefined);
|
|
132
|
+
if (!envName) {
|
|
133
|
+
console.error(usage);
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
120
136
|
}
|
|
121
137
|
const auth = await import('./login.js');
|
|
122
|
-
|
|
138
|
+
if (command === 'logout') {
|
|
139
|
+
await auth.logout(envName);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// An OpCo env name (registered via `seq-studio envs add` or `seqapi env add`)
|
|
143
|
+
// logs into that environment's Auth0 realm; omitted or a built-in name uses Sequence.
|
|
144
|
+
await auth.login(envName);
|
|
145
|
+
}
|
|
123
146
|
return 0;
|
|
124
147
|
}
|
|
125
148
|
async function runProcessNamespace(sub, rest) {
|
package/dist/orm/delegate.js
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
import { getAccessToken, tryGetAccessToken } from '../auth.js';
|
|
9
9
|
import { resolveEnvWithDiscovery } from '../config.js';
|
|
10
10
|
import { normalizeShortEnvFlag, readEnvFromArgv } from '../env-flags.js';
|
|
11
|
+
import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
|
|
12
|
+
/** ORM subcommands that talk to Atlas — must not silently target `local`. */
|
|
13
|
+
const ORM_NETWORK_SUBS = new Set(['plan', 'apply']);
|
|
11
14
|
const ORM_USAGE = `usage:
|
|
12
15
|
seq-studio orm init <dir> scaffold a namespace directory
|
|
13
16
|
seq-studio orm validate [dir] parse + validate definitions and verify committed migrations are in sync
|
|
@@ -38,11 +41,21 @@ export async function runOrmCommand(sub, rest) {
|
|
|
38
41
|
}
|
|
39
42
|
const normalized = normalizeShortEnvFlag(rest);
|
|
40
43
|
const requested = readEnvFromArgv(normalized);
|
|
44
|
+
if (ORM_NETWORK_SUBS.has(sub) && !requested) {
|
|
45
|
+
console.error(`[seq-studio] ${REQUIRE_EXPLICIT_ENV_MESSAGE}`);
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
let targetUrl;
|
|
41
49
|
if (requested) {
|
|
42
50
|
const resolved = await resolveEnvWithDiscovery({ requested });
|
|
51
|
+
targetUrl = resolved.url;
|
|
43
52
|
process.env['SEQUENCE_ORM_BASE_URL'] = resolved.url;
|
|
44
53
|
}
|
|
45
|
-
const token = await tryGetAccessToken({
|
|
54
|
+
const token = await tryGetAccessToken({
|
|
55
|
+
failClosedForM2m: true,
|
|
56
|
+
env: requested,
|
|
57
|
+
targetUrl,
|
|
58
|
+
});
|
|
46
59
|
if (token)
|
|
47
60
|
process.env['SEQUENCE_ORM_TOKEN'] = token;
|
|
48
61
|
// Lazy import keeps `process`/`doctor` from pulling in the orm package.
|
|
@@ -70,7 +83,7 @@ export async function runOrmCommand(sub, rest) {
|
|
|
70
83
|
const { runCli, setTokenProvider } = ormCli;
|
|
71
84
|
setTokenProvider(async () => {
|
|
72
85
|
try {
|
|
73
|
-
return await getAccessToken();
|
|
86
|
+
return await getAccessToken({ env: requested, targetUrl });
|
|
74
87
|
}
|
|
75
88
|
catch {
|
|
76
89
|
return null;
|
package/dist/pat-hints.js
CHANGED
|
@@ -21,7 +21,7 @@ export function formatPatSetupHint({ envUrl, envName, indent = ' ', }) {
|
|
|
21
21
|
`${indent} 2. New token → scopes repo:read (add repo:write for push) → copy once`,
|
|
22
22
|
`${indent} 3. export ATLAS_GIT_PAT=<token>`,
|
|
23
23
|
`${indent} 4. Copy the clone URL from Repositories → Clone, then:`,
|
|
24
|
-
`${indent} ATLAS_GIT_PAT=<token> seq-studio repos clone --url <https://…/repos/<id>/git
|
|
25
|
-
`${indent} (or: seq-studio repos clone <ns>/<name>)`,
|
|
24
|
+
`${indent} ATLAS_GIT_PAT=<token> seq-studio repos clone --url <https://…/repos/<id>/git> -e ${envName}`,
|
|
25
|
+
`${indent} (or: seq-studio repos clone <ns>/<name> -e ${envName})`,
|
|
26
26
|
];
|
|
27
27
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `seq-studio pipeline <sub>` — the Data Pipelines authoring interface.
|
|
3
|
+
*
|
|
4
|
+
* `init` scaffolds a typed stage spec (`<name>.stage.yml` + entrypoint stub);
|
|
5
|
+
* `validate` runs the full offline SDK gate (envelope + body + schema_ref
|
|
6
|
+
* resolution + graph validation) over a Pipeline directory. Both are also the
|
|
7
|
+
* CI gate for `pipelines/**` repos (`.github/workflows/pipeline-verify.yml`).
|
|
8
|
+
*
|
|
9
|
+
* All schema logic lives in @sequenceholdings/pipeline-spec (single source of truth) —
|
|
10
|
+
* this module only handles argv, filesystem scaffolding, and output shaping.
|
|
11
|
+
* The SDK is lazy-imported like `@sequenceholdings/orm` so public installs of
|
|
12
|
+
* the CLI without the package get a clear install hint instead of a crash.
|
|
13
|
+
*/
|
|
14
|
+
import type { ParsedArgs } from '../process/commands.js';
|
|
15
|
+
/**
|
|
16
|
+
* Same classification as the orm delegate: is the pipeline-spec package
|
|
17
|
+
* itself absent (installable) or did one of its dependencies fail to load?
|
|
18
|
+
*/
|
|
19
|
+
export declare function isPipelineSpecMissing(message: string): boolean;
|
|
20
|
+
export declare function pipelineInitCommand(args: ParsedArgs): Promise<number>;
|
|
21
|
+
interface ValidateReportFinding {
|
|
22
|
+
readonly severity: 'error' | 'warning';
|
|
23
|
+
readonly code: string;
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly stage?: string;
|
|
26
|
+
readonly asset?: string;
|
|
27
|
+
readonly consumers?: readonly string[];
|
|
28
|
+
readonly suggestions?: readonly string[];
|
|
29
|
+
readonly cycle_path?: readonly string[];
|
|
30
|
+
readonly file?: string;
|
|
31
|
+
readonly path?: string;
|
|
32
|
+
}
|
|
33
|
+
/** The stable machine shape `--json` emits (consumed by CI annotations). */
|
|
34
|
+
export interface ValidateReport {
|
|
35
|
+
readonly ok: boolean;
|
|
36
|
+
readonly dir: string;
|
|
37
|
+
readonly stages: readonly string[];
|
|
38
|
+
readonly findings: readonly ValidateReportFinding[];
|
|
39
|
+
}
|
|
40
|
+
interface ExternalAssetsRequest {
|
|
41
|
+
readonly url: string;
|
|
42
|
+
readonly init: {
|
|
43
|
+
readonly headers: Record<string, string>;
|
|
44
|
+
readonly redirect: 'manual';
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare function buildExternalAssetsRequest({ source, knownOrigins, token, }: {
|
|
48
|
+
source: string;
|
|
49
|
+
knownOrigins: readonly string[];
|
|
50
|
+
token: string | null;
|
|
51
|
+
}): ExternalAssetsRequest;
|
|
52
|
+
/** Trusted origins of every environment the CLI knows about. */
|
|
53
|
+
export declare function configuredEnvOrigins(envs: Readonly<Record<string, {
|
|
54
|
+
url: string;
|
|
55
|
+
}>>): string[];
|
|
56
|
+
export declare function pipelineValidateCommand(args: ParsedArgs): Promise<number>;
|
|
57
|
+
export declare function runPipelineCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
|
|
58
|
+
export {};
|