@shardflux/cli 0.4.0 → 0.5.0

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.
@@ -1,5 +1,8 @@
1
- import type { RunResult, Shardflux, Workspace } from '@shardflux/sdk';
1
+ import type { AccountClientOptions, RunResult, Shardflux, ShardfluxAccount, Workspace } from '@shardflux/sdk';
2
2
  import type { Values } from './args.js';
3
+ import type { CredentialStore, StoredApiKey, StoredSession } from './credentials.js';
4
+ import type { Input, StdinLike } from './input.js';
5
+ import type { Distribution, UpdateView } from './update-check.js';
3
6
  import type { TimingRecorder } from './timing.js';
4
7
  export interface Writer {
5
8
  write(chunk: string | Uint8Array): boolean;
@@ -7,11 +10,17 @@ export interface Writer {
7
10
  export interface Io {
8
11
  stdout: Writer;
9
12
  stderr: Writer;
10
- stdin: AsyncIterable<Buffer | string> & {
11
- isTTY?: boolean;
12
- };
13
+ /** Data for files/secrets, and passwords (piped lines, or a no-echo prompt when it is a terminal with setRawMode). */
14
+ stdin: StdinLike;
13
15
  env: Record<string, string | undefined>;
14
16
  }
17
+ /** The project API key in use and where it came from. */
18
+ export interface ResolvedApiKey {
19
+ token: string;
20
+ source: 'env' | 'file';
21
+ /** The saved key's metadata, when it came from the credentials file. */
22
+ saved?: StoredApiKey;
23
+ }
15
24
  export interface Ctx {
16
25
  io: Io;
17
26
  json: boolean;
@@ -26,15 +35,68 @@ export interface Ctx {
26
35
  timing: boolean;
27
36
  /** Timings and the last observed operation of the traced SDK calls this command made (the client's onProgress). */
28
37
  traces: TimingRecorder;
38
+ /** The project API key client: SHARDFLUX_API_KEY, else the key saved for this API URL (`shard setup`). */
29
39
  cloud(): Shardflux;
40
+ /** The project API key without building a client (throws AuthConfigError when there is none). */
41
+ apiKey(): ResolvedApiKey;
42
+ /** The user session client: SHARDFLUX_SESSION_TOKEN, else the saved session (`shard auth login`). Rotations are saved. */
43
+ account(): ShardfluxAccount;
44
+ /** Where a session would come from, without loading it: 'env', 'file' or null (signed out). */
45
+ sessionSource(): 'env' | 'file' | null;
46
+ /** Client options for the SDK's pre-session calls (register, verify, login, reset): this API URL, fetch, user agent. */
47
+ accountOptions(): AccountClientOptions;
48
+ /**
49
+ * Saves a new session for this API URL. When it belongs to another person than the saved one (another user id, or
50
+ * `email` for a sign-in still waiting for its code), their default organization, project and key are dropped.
51
+ */
52
+ saveSession(session: StoredSession, email?: string): {
53
+ replaced: StoredSession | null;
54
+ switched: boolean;
55
+ };
56
+ /** A credential this command received (redacted from error output). */
57
+ addSecret(value: string): void;
58
+ /** The update status for `shard version` (forced: ask the API now). Null when unknown. */
59
+ versionStatus(force: boolean): Promise<UpdateView | null>;
60
+ /** The credentials file (config directory from the environment). */
61
+ store: CredentialStore;
62
+ /** Passwords and codes: piped lines, or no-echo prompts on a terminal. */
63
+ input: Input;
64
+ /** The package that runs the CLI (the version check's identity). */
65
+ distribution: Distribution;
66
+ /** This machine's name (default API key name of `shard setup`). */
67
+ hostname(): string;
30
68
  }
31
69
  export type Handler = (ctx: Ctx, values: Values, positionals: string[]) => Promise<number>;
70
+ export declare const str: (v: Values[string]) => string | undefined;
71
+ export declare const strs: (v: Values[string]) => string[];
72
+ export declare function out(ctx: Ctx, human: string, machine: unknown): void;
73
+ export declare function waitTimeout(values: Values): number;
32
74
  /**
33
75
  * `<id|key>`: a UUID is tried as an id first; anything else (or an unknown UUID) as an exact workspace key, across every
34
76
  * lifetime and purpose (sessions, drafts and test instances are hidden from the default list), preferring the live
35
77
  * workspace over tombstones of ended sessions that had the same key (contracts §19.11).
36
78
  */
37
79
  export declare function resolveWorkspace(ctx: Ctx, ref: string): Promise<Workspace>;
80
+ export declare function oneOf<T extends string>(values: Values, option: string, allowed: readonly T[]): T | undefined;
81
+ export declare function listLimit(values: Values, max: number): number | undefined;
82
+ /** `<slug>@<version>`. */
83
+ export declare function parseSlugVersion(text: string, what: string): {
84
+ slug: string;
85
+ version: number;
86
+ };
87
+ export declare function fileExists(path: string): Promise<boolean>;
88
+ export declare function readInput(ctx: Ctx, source: string, max: number, what: string): Promise<Uint8Array>;
89
+ export declare function principal(ctx: Ctx): Promise<{
90
+ api_url: string;
91
+ organization_id: string;
92
+ project_id: string;
93
+ api_key: {
94
+ id: string;
95
+ key_id: string;
96
+ };
97
+ tool_permissions: ("git" | "exec" | "files" | "pty" | "process" | "browser")[];
98
+ }>;
38
99
  /** The exit code `shard exec` returns for a finished command. */
39
100
  export declare function execExitCode(r: Pick<RunResult, 'exitCode' | 'termSignal' | 'timedOut'>): number;
40
- export declare const HANDLERS: Record<string, Handler>;
101
+ /** The project-key commands; handlers.ts adds the account plane's. */
102
+ export declare const KEY_HANDLERS: Record<string, Handler>;