@w6w/cli 0.1.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.
- package/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/bin/w6w.d.ts +22 -0
- package/dist/bin/w6w.d.ts.map +1 -0
- package/dist/bin/w6w.js +58 -0
- package/dist/bin/w6w.js.map +1 -0
- package/dist/mod.d.ts +131 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +257 -0
- package/dist/mod.js.map +1 -0
- package/dist/src/args.d.ts +79 -0
- package/dist/src/args.d.ts.map +1 -0
- package/dist/src/args.js +130 -0
- package/dist/src/args.js.map +1 -0
- package/dist/src/client.d.ts +90 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +172 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/commands/connections.d.ts +13 -0
- package/dist/src/commands/connections.d.ts.map +1 -0
- package/dist/src/commands/connections.js +30 -0
- package/dist/src/commands/connections.js.map +1 -0
- package/dist/src/commands/documents.d.ts +34 -0
- package/dist/src/commands/documents.d.ts.map +1 -0
- package/dist/src/commands/documents.js +179 -0
- package/dist/src/commands/documents.js.map +1 -0
- package/dist/src/commands/index.d.ts +27 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +39 -0
- package/dist/src/commands/index.js.map +1 -0
- package/dist/src/commands/me.d.ts +29 -0
- package/dist/src/commands/me.d.ts.map +1 -0
- package/dist/src/commands/me.js +52 -0
- package/dist/src/commands/me.js.map +1 -0
- package/dist/src/commands/run.d.ts +24 -0
- package/dist/src/commands/run.d.ts.map +1 -0
- package/dist/src/commands/run.js +78 -0
- package/dist/src/commands/run.js.map +1 -0
- package/dist/src/commands/shared.d.ts +117 -0
- package/dist/src/commands/shared.d.ts.map +1 -0
- package/dist/src/commands/shared.js +152 -0
- package/dist/src/commands/shared.js.map +1 -0
- package/dist/src/commands/vars.d.ts +59 -0
- package/dist/src/commands/vars.d.ts.map +1 -0
- package/dist/src/commands/vars.js +216 -0
- package/dist/src/commands/vars.js.map +1 -0
- package/dist/src/commands/workflows.d.ts +13 -0
- package/dist/src/commands/workflows.d.ts.map +1 -0
- package/dist/src/commands/workflows.js +75 -0
- package/dist/src/commands/workflows.js.map +1 -0
- package/dist/src/exit.d.ts +51 -0
- package/dist/src/exit.d.ts.map +1 -0
- package/dist/src/exit.js +94 -0
- package/dist/src/exit.js.map +1 -0
- package/dist/src/help.d.ts +48 -0
- package/dist/src/help.d.ts.map +1 -0
- package/dist/src/help.generated.d.ts +88 -0
- package/dist/src/help.generated.d.ts.map +1 -0
- package/dist/src/help.generated.js +988 -0
- package/dist/src/help.generated.js.map +1 -0
- package/dist/src/help.js +128 -0
- package/dist/src/help.js.map +1 -0
- package/dist/src/output.d.ts +84 -0
- package/dist/src/output.d.ts.map +1 -0
- package/dist/src/output.js +94 -0
- package/dist/src/output.js.map +1 -0
- package/dist/src/runtime.d.ts +37 -0
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/runtime.js +57 -0
- package/dist/src/runtime.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The argument parser.
|
|
3
|
+
*
|
|
4
|
+
* There is no CLI framework anywhere in this workspace, and this package takes no
|
|
5
|
+
* runtime dependency to get one. `parse()` is a **pure function**: it is handed an
|
|
6
|
+
* argument vector and returns a structured result. It never reads the real
|
|
7
|
+
* command line, never reads the environment, never writes output and never exits
|
|
8
|
+
* — that is `src/runtime.ts`'s job, and keeping the two apart is what makes every
|
|
9
|
+
* invocation in this file testable in-process, in any runtime.
|
|
10
|
+
*
|
|
11
|
+
* It also never throws on bad input. A wrong invocation is an ordinary outcome
|
|
12
|
+
* for a CLI, so a usage error comes back as a value (`{ ok: false }`) carrying the
|
|
13
|
+
* command path the user was aiming at, which is how the caller knows *which* help
|
|
14
|
+
* to print (root, group or command) before exiting 1.
|
|
15
|
+
*
|
|
16
|
+
* Flag names, aliases and the set of valid command paths all come from the
|
|
17
|
+
* generated module rather than being restated here, so the parser cannot drift
|
|
18
|
+
* from the surface contract the help text is built from.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
/** A flag the parser will accept. */
|
|
23
|
+
export interface FlagSpec {
|
|
24
|
+
/** The long name, with its leading dashes, e.g. `--base-url`. */
|
|
25
|
+
name: string;
|
|
26
|
+
/** The short alias, with its leading dash, e.g. `-h`. */
|
|
27
|
+
alias: string | null;
|
|
28
|
+
/** `boolean` flags take no value; `string` flags take one. */
|
|
29
|
+
type: string;
|
|
30
|
+
}
|
|
31
|
+
/** The six global flags, exactly as the surface contract declares them. */
|
|
32
|
+
export declare const GLOBAL_FLAG_SPECS: FlagSpec[];
|
|
33
|
+
/** The global flags, resolved. */
|
|
34
|
+
export interface GlobalOptions {
|
|
35
|
+
/** `--base-url`; falls back to `W6W_BASE_URL` later, in the client. */
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
/** `--token`; falls back to `W6W_TOKEN` later, in the client. */
|
|
38
|
+
token?: string;
|
|
39
|
+
json: boolean;
|
|
40
|
+
noColor: boolean;
|
|
41
|
+
version: boolean;
|
|
42
|
+
help: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** A successfully parsed command line. */
|
|
45
|
+
export interface Invocation {
|
|
46
|
+
/** The command path, e.g. `["documents", "create"]`. Empty for a bare `w6w`. */
|
|
47
|
+
command: string[];
|
|
48
|
+
/** Everything left over after the command path, in order. */
|
|
49
|
+
positionals: string[];
|
|
50
|
+
globals: GlobalOptions;
|
|
51
|
+
/** Non-global flags, keyed by camelCased name. Empty unless `flags` was passed. */
|
|
52
|
+
options: Record<string, string | boolean>;
|
|
53
|
+
}
|
|
54
|
+
/** What `parse()` returns: a parsed command line, or a usage error to report. */
|
|
55
|
+
export type ParseResult = {
|
|
56
|
+
ok: true;
|
|
57
|
+
invocation: Invocation;
|
|
58
|
+
} | {
|
|
59
|
+
ok: false;
|
|
60
|
+
message: string;
|
|
61
|
+
command: string[];
|
|
62
|
+
};
|
|
63
|
+
/** Optional extras, so a command group can add its own flags without a rewrite. */
|
|
64
|
+
export interface ParseOptions {
|
|
65
|
+
/** Command-specific flags, on top of the six global ones. */
|
|
66
|
+
flags?: readonly FlagSpec[];
|
|
67
|
+
/** The command paths that exist. Defaults to the generated contract's. */
|
|
68
|
+
commands?: readonly (readonly string[])[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Parses an argument vector.
|
|
72
|
+
*
|
|
73
|
+
* Accepted forms: `--flag`, `--flag value`, `--flag=value`, a short alias
|
|
74
|
+
* (`-h`, `-v`), and `--` to end flag parsing. A repeated flag keeps the last
|
|
75
|
+
* value. An unknown flag, a missing value, or a value handed to a boolean flag
|
|
76
|
+
* are all reported as usage errors.
|
|
77
|
+
*/
|
|
78
|
+
export declare function parse(argv: string[], options?: ParseOptions): ParseResult;
|
|
79
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,qCAAqC;AACrC,MAAM,WAAW,QAAQ;IACvB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;CACd;AAED,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,EAAE,QAAQ,EAIrC,CAAC;AAEJ,kCAAkC;AAClC,MAAM,WAAW,aAAa;IAC5B,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,0CAA0C;AAC1C,MAAM,WAAW,UAAU;IACzB,gFAAgF;IAChF,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,aAAa,CAAC;IACvB,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;CAC3C;AAED,iFAAiF;AACjF,MAAM,MAAM,WAAW,GACnB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GACpC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEtD,mFAAmF;AACnF,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,KAAK,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC5B,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;CAC3C;AAgCD;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CA6E7E"}
|
package/dist/src/args.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The argument parser.
|
|
3
|
+
*
|
|
4
|
+
* There is no CLI framework anywhere in this workspace, and this package takes no
|
|
5
|
+
* runtime dependency to get one. `parse()` is a **pure function**: it is handed an
|
|
6
|
+
* argument vector and returns a structured result. It never reads the real
|
|
7
|
+
* command line, never reads the environment, never writes output and never exits
|
|
8
|
+
* — that is `src/runtime.ts`'s job, and keeping the two apart is what makes every
|
|
9
|
+
* invocation in this file testable in-process, in any runtime.
|
|
10
|
+
*
|
|
11
|
+
* It also never throws on bad input. A wrong invocation is an ordinary outcome
|
|
12
|
+
* for a CLI, so a usage error comes back as a value (`{ ok: false }`) carrying the
|
|
13
|
+
* command path the user was aiming at, which is how the caller knows *which* help
|
|
14
|
+
* to print (root, group or command) before exiting 1.
|
|
15
|
+
*
|
|
16
|
+
* Flag names, aliases and the set of valid command paths all come from the
|
|
17
|
+
* generated module rather than being restated here, so the parser cannot drift
|
|
18
|
+
* from the surface contract the help text is built from.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { COMMAND_PATHS, GLOBAL_FLAGS } from "./help.generated.js";
|
|
23
|
+
/** The six global flags, exactly as the surface contract declares them. */
|
|
24
|
+
export const GLOBAL_FLAG_SPECS = GLOBAL_FLAGS.map((flag) => ({
|
|
25
|
+
name: flag.name,
|
|
26
|
+
alias: flag.alias,
|
|
27
|
+
type: flag.type,
|
|
28
|
+
}));
|
|
29
|
+
/** `--base-url` → `baseUrl`. */
|
|
30
|
+
function optionKey(flagName) {
|
|
31
|
+
return flagName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Splits the leftover operands into a command path and its positional arguments.
|
|
35
|
+
*
|
|
36
|
+
* Longest match wins, against the command paths the contract declares — which is
|
|
37
|
+
* what tells `w6w run conn_01H…` (a root command plus a positional) apart from
|
|
38
|
+
* `w6w documents get` (a two-token command path). An operand that matches nothing
|
|
39
|
+
* is still returned as a one-token command, so the caller can report it as an
|
|
40
|
+
* unknown command rather than as a stray argument.
|
|
41
|
+
*/
|
|
42
|
+
function splitCommand(operands, commands) {
|
|
43
|
+
if (operands.length === 0)
|
|
44
|
+
return { command: [], positionals: [] };
|
|
45
|
+
if (operands.length >= 2) {
|
|
46
|
+
const twoTokenMatch = commands.some((path) => path.length === 2 && path[0] === operands[0] && path[1] === operands[1]);
|
|
47
|
+
if (twoTokenMatch) {
|
|
48
|
+
return { command: operands.slice(0, 2), positionals: operands.slice(2) };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { command: operands.slice(0, 1), positionals: operands.slice(1) };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parses an argument vector.
|
|
55
|
+
*
|
|
56
|
+
* Accepted forms: `--flag`, `--flag value`, `--flag=value`, a short alias
|
|
57
|
+
* (`-h`, `-v`), and `--` to end flag parsing. A repeated flag keeps the last
|
|
58
|
+
* value. An unknown flag, a missing value, or a value handed to a boolean flag
|
|
59
|
+
* are all reported as usage errors.
|
|
60
|
+
*/
|
|
61
|
+
export function parse(argv, options = {}) {
|
|
62
|
+
const specs = [...GLOBAL_FLAG_SPECS, ...(options.flags ?? [])];
|
|
63
|
+
const commands = options.commands ?? COMMAND_PATHS;
|
|
64
|
+
const byName = new Map(specs.map((spec) => [spec.name, spec]));
|
|
65
|
+
const byAlias = new Map(specs.filter((spec) => spec.alias).map((spec) => [spec.alias, spec]));
|
|
66
|
+
const values = {};
|
|
67
|
+
const operands = [];
|
|
68
|
+
const fail = (message) => ({
|
|
69
|
+
ok: false,
|
|
70
|
+
message,
|
|
71
|
+
command: splitCommand(operands, commands).command,
|
|
72
|
+
});
|
|
73
|
+
for (let i = 0; i < argv.length; i++) {
|
|
74
|
+
const token = argv[i];
|
|
75
|
+
if (token === "--") {
|
|
76
|
+
operands.push(...argv.slice(i + 1));
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (!token.startsWith("-") || token === "-") {
|
|
80
|
+
operands.push(token);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const equals = token.indexOf("=");
|
|
84
|
+
const rawName = equals === -1 ? token : token.slice(0, equals);
|
|
85
|
+
const inlineValue = equals === -1 ? null : token.slice(equals + 1);
|
|
86
|
+
const spec = rawName.startsWith("--") ? byName.get(rawName) : byAlias.get(rawName);
|
|
87
|
+
if (!spec)
|
|
88
|
+
return fail(`unknown flag: ${rawName}`);
|
|
89
|
+
if (spec.type === "boolean") {
|
|
90
|
+
if (inlineValue !== null)
|
|
91
|
+
return fail(`flag ${spec.name} takes no value`);
|
|
92
|
+
values[optionKey(spec.name)] = true;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (inlineValue !== null) {
|
|
96
|
+
values[optionKey(spec.name)] = inlineValue;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const next = argv[i + 1];
|
|
100
|
+
if (next === undefined || (next.startsWith("-") && next !== "-")) {
|
|
101
|
+
return fail(`flag ${spec.name} requires a value`);
|
|
102
|
+
}
|
|
103
|
+
values[optionKey(spec.name)] = next;
|
|
104
|
+
i++;
|
|
105
|
+
}
|
|
106
|
+
const { command, positionals } = splitCommand(operands, commands);
|
|
107
|
+
const globalKeys = new Set(GLOBAL_FLAG_SPECS.map((spec) => optionKey(spec.name)));
|
|
108
|
+
const extras = {};
|
|
109
|
+
for (const [key, value] of Object.entries(values)) {
|
|
110
|
+
if (!globalKeys.has(key))
|
|
111
|
+
extras[key] = value;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
ok: true,
|
|
115
|
+
invocation: {
|
|
116
|
+
command,
|
|
117
|
+
positionals,
|
|
118
|
+
globals: {
|
|
119
|
+
baseUrl: typeof values.baseUrl === "string" ? values.baseUrl : undefined,
|
|
120
|
+
token: typeof values.token === "string" ? values.token : undefined,
|
|
121
|
+
json: values.json === true,
|
|
122
|
+
noColor: values.noColor === true,
|
|
123
|
+
version: values.version === true,
|
|
124
|
+
help: values.help === true,
|
|
125
|
+
},
|
|
126
|
+
options: extras,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM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I,EAAE,MAAM,CAAC,IAAI,KAAK,IAAI;gBAC1B,OAAO,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI;gBAChC,OAAO,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI;gBAChC,IAAI,EAAE,MAAM,CAAC,IAAI,KAAK,IAAI;aAC3B;YACD,OAAO,EAAE,MAAM;SAChB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flags and environment in, a configured `@w6w/sdk` client out.
|
|
3
|
+
*
|
|
4
|
+
* This module is the CLI's whole configuration story, and it is deliberately
|
|
5
|
+
* thin: **no transport, no base-path joining, no HTTP error mapping lives here**
|
|
6
|
+
* — all of that is the SDK's, and duplicating any of it in a second package is
|
|
7
|
+
* how two clients of one API start disagreeing about what a base URL means.
|
|
8
|
+
* What belongs here is the one thing the SDK cannot know: that a command line
|
|
9
|
+
* has a flag which outranks the environment variable.
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* CLI flag (--base-url / --token) > environment variable > nothing (an error)
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The resolved values are passed to the SDK **explicitly**, and the SDK is never
|
|
16
|
+
* left to read the environment on the CLI's behalf. That is a mechanism choice,
|
|
17
|
+
* not a stylistic one: the CLI has to be able to say *which* source it was
|
|
18
|
+
* looking at when it reports a missing or malformed value, and a library that
|
|
19
|
+
* reads the environment behind you cannot tell you that. It also means every
|
|
20
|
+
* environment-dependent behaviour in this package has one seam a test can
|
|
21
|
+
* substitute — {@linkcode EnvReader} — instead of a real process environment
|
|
22
|
+
* that only one test at a time can own.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { type FetchLike, W6wClient } from "@w6w/sdk";
|
|
27
|
+
import type { GlobalOptions } from "./args.ts";
|
|
28
|
+
/**
|
|
29
|
+
* Reads one environment variable, or `undefined` where the host has none.
|
|
30
|
+
*
|
|
31
|
+
* The same shape as `src/runtime.ts`'s `env`, which is the only thing in this
|
|
32
|
+
* package that reads a real process environment; everything downstream — this
|
|
33
|
+
* module included — receives it as a value.
|
|
34
|
+
*/
|
|
35
|
+
export type EnvReader = (name: string) => string | undefined;
|
|
36
|
+
/** Environment variable holding the server **origin**. Falls behind `--base-url`. */
|
|
37
|
+
export declare const ENV_BASE_URL = "W6W_BASE_URL";
|
|
38
|
+
/** Environment variable holding the bearer token. Falls behind `--token`. */
|
|
39
|
+
export declare const ENV_TOKEN = "W6W_TOKEN";
|
|
40
|
+
/** An environment with nothing in it. The default, so nothing leaks in by accident. */
|
|
41
|
+
export declare const NO_ENV: EnvReader;
|
|
42
|
+
/**
|
|
43
|
+
* Read an environment variable, treating a blank value as **absent**.
|
|
44
|
+
*
|
|
45
|
+
* `W6W_BASE_URL=`, `W6W_BASE_URL=" "` and an unset `W6W_BASE_URL` are the same
|
|
46
|
+
* thing: all three fall through the precedence chain to the next source, and
|
|
47
|
+
* ultimately to a usage error naming both sources.
|
|
48
|
+
*
|
|
49
|
+
* The check is a trim-and-emptiness test and deliberately **not** a nullish
|
|
50
|
+
* coalesce. `??` does not convert `""`, so a set-but-empty variable would
|
|
51
|
+
* survive as a value and be resolved into a base URL of `/api` — a relative URL,
|
|
52
|
+
* which fails much later with a message about a request instead of here with a
|
|
53
|
+
* message about configuration. A blank variable is not exotic: `export W6W_TOKEN=`,
|
|
54
|
+
* a Dockerfile `ENV` with no build argument behind it, and a CI variable whose
|
|
55
|
+
* template did not interpolate all produce exactly this, and all three look
|
|
56
|
+
* unset in every log line.
|
|
57
|
+
*
|
|
58
|
+
* The surviving value is returned **verbatim**; trimming applies to the test,
|
|
59
|
+
* not to the value.
|
|
60
|
+
*
|
|
61
|
+
* @param env - The environment seam to read through.
|
|
62
|
+
* @param name - The variable to read.
|
|
63
|
+
* @returns The value, or `undefined` when it is unset or blank.
|
|
64
|
+
*/
|
|
65
|
+
export declare function envValue(env: EnvReader, name: string): string | undefined;
|
|
66
|
+
/** Anything the caller wants to hand the client beyond the global flags. */
|
|
67
|
+
export interface ClientOptions {
|
|
68
|
+
/**
|
|
69
|
+
* Transport override, passed straight to the SDK. The seam the test suite
|
|
70
|
+
* runs against; nothing in normal operation sets it.
|
|
71
|
+
*/
|
|
72
|
+
fetch?: FetchLike;
|
|
73
|
+
/** Default project id for the project-scoped operations. */
|
|
74
|
+
project?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build the API client for one invocation.
|
|
78
|
+
*
|
|
79
|
+
* Call this **lazily**, when a command has decided it needs the API — never at
|
|
80
|
+
* module load, and never on the help or `--version` path, which must resolve
|
|
81
|
+
* with no token configured and no server reachable.
|
|
82
|
+
*
|
|
83
|
+
* @param globals - The parsed global flags.
|
|
84
|
+
* @param env - The environment seam. Defaults to an empty environment.
|
|
85
|
+
* @param options - Transport and default project.
|
|
86
|
+
* @returns A configured client.
|
|
87
|
+
* @throws {ConfigError} When the base URL or token is missing or unusable — a usage error.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createClient(globals: GlobalOptions, env?: EnvReader, options?: ClientOptions): W6wClient;
|
|
90
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAe,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE7D,qFAAqF;AACrF,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C,6EAA6E;AAC7E,eAAO,MAAM,SAAS,cAAc,CAAC;AAErC,uFAAuF;AACvF,eAAO,MAAM,MAAM,EAAE,SAA2B,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIzE;AAkGD,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,GAAG,GAAE,SAAkB,EACvB,OAAO,GAAE,aAAkB,GAC1B,SAAS,CA8BX"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flags and environment in, a configured `@w6w/sdk` client out.
|
|
3
|
+
*
|
|
4
|
+
* This module is the CLI's whole configuration story, and it is deliberately
|
|
5
|
+
* thin: **no transport, no base-path joining, no HTTP error mapping lives here**
|
|
6
|
+
* — all of that is the SDK's, and duplicating any of it in a second package is
|
|
7
|
+
* how two clients of one API start disagreeing about what a base URL means.
|
|
8
|
+
* What belongs here is the one thing the SDK cannot know: that a command line
|
|
9
|
+
* has a flag which outranks the environment variable.
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* CLI flag (--base-url / --token) > environment variable > nothing (an error)
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The resolved values are passed to the SDK **explicitly**, and the SDK is never
|
|
16
|
+
* left to read the environment on the CLI's behalf. That is a mechanism choice,
|
|
17
|
+
* not a stylistic one: the CLI has to be able to say *which* source it was
|
|
18
|
+
* looking at when it reports a missing or malformed value, and a library that
|
|
19
|
+
* reads the environment behind you cannot tell you that. It also means every
|
|
20
|
+
* environment-dependent behaviour in this package has one seam a test can
|
|
21
|
+
* substitute — {@linkcode EnvReader} — instead of a real process environment
|
|
22
|
+
* that only one test at a time can own.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { ConfigError, W6wClient } from "@w6w/sdk";
|
|
27
|
+
/** Environment variable holding the server **origin**. Falls behind `--base-url`. */
|
|
28
|
+
export const ENV_BASE_URL = "W6W_BASE_URL";
|
|
29
|
+
/** Environment variable holding the bearer token. Falls behind `--token`. */
|
|
30
|
+
export const ENV_TOKEN = "W6W_TOKEN";
|
|
31
|
+
/** An environment with nothing in it. The default, so nothing leaks in by accident. */
|
|
32
|
+
export const NO_ENV = () => undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Read an environment variable, treating a blank value as **absent**.
|
|
35
|
+
*
|
|
36
|
+
* `W6W_BASE_URL=`, `W6W_BASE_URL=" "` and an unset `W6W_BASE_URL` are the same
|
|
37
|
+
* thing: all three fall through the precedence chain to the next source, and
|
|
38
|
+
* ultimately to a usage error naming both sources.
|
|
39
|
+
*
|
|
40
|
+
* The check is a trim-and-emptiness test and deliberately **not** a nullish
|
|
41
|
+
* coalesce. `??` does not convert `""`, so a set-but-empty variable would
|
|
42
|
+
* survive as a value and be resolved into a base URL of `/api` — a relative URL,
|
|
43
|
+
* which fails much later with a message about a request instead of here with a
|
|
44
|
+
* message about configuration. A blank variable is not exotic: `export W6W_TOKEN=`,
|
|
45
|
+
* a Dockerfile `ENV` with no build argument behind it, and a CI variable whose
|
|
46
|
+
* template did not interpolate all produce exactly this, and all three look
|
|
47
|
+
* unset in every log line.
|
|
48
|
+
*
|
|
49
|
+
* The surviving value is returned **verbatim**; trimming applies to the test,
|
|
50
|
+
* not to the value.
|
|
51
|
+
*
|
|
52
|
+
* @param env - The environment seam to read through.
|
|
53
|
+
* @param name - The variable to read.
|
|
54
|
+
* @returns The value, or `undefined` when it is unset or blank.
|
|
55
|
+
*/
|
|
56
|
+
export function envValue(env, name) {
|
|
57
|
+
const value = env(name);
|
|
58
|
+
if (value === undefined || value.trim().length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Apply the precedence rule to one setting.
|
|
64
|
+
*
|
|
65
|
+
* A flag that was **given** wins outright, even when what it was given is empty:
|
|
66
|
+
* that is a value the user typed, and quietly consulting the environment behind
|
|
67
|
+
* an explicit `--token=` would be the CLI second-guessing them. (It still does
|
|
68
|
+
* not produce a usable value — an empty flag reaches the same error — but it
|
|
69
|
+
* gets there without a detour through the environment.) Only an **absent** flag
|
|
70
|
+
* falls through.
|
|
71
|
+
*/
|
|
72
|
+
function resolve(flag, env, name) {
|
|
73
|
+
if (flag !== undefined)
|
|
74
|
+
return flag;
|
|
75
|
+
return envValue(env, name);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A value the CLI cannot work with, phrased as a usage error.
|
|
79
|
+
*
|
|
80
|
+
* Every message names **both** sources, because "which one was I supposed to
|
|
81
|
+
* set?" is the only question the user has at this point, and the answer depends
|
|
82
|
+
* on whether they are typing a command or writing a deploy manifest.
|
|
83
|
+
*
|
|
84
|
+
* The type is the SDK's {@linkcode ConfigError}, not a new one: the split that
|
|
85
|
+
* matters is configuration-versus-API, and it already exists. A `ConfigError`
|
|
86
|
+
* means the request never left this machine — `src/exit.ts` maps it to the usage
|
|
87
|
+
* code. An `ApiError` means the server answered.
|
|
88
|
+
*/
|
|
89
|
+
function configError(problem, flag, variable, hint) {
|
|
90
|
+
return new ConfigError(`${problem} Set it with ${flag} or the ${variable} environment variable. ${hint}`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Reject a base URL the CLI cannot actually send a request to.
|
|
94
|
+
*
|
|
95
|
+
* A relative base (`/api`, `localhost:8080`) is a **usage** error and is caught
|
|
96
|
+
* here, at the point the user can still do something about it. Left alone it
|
|
97
|
+
* becomes a transport failure much later, reported as "the server may be down" —
|
|
98
|
+
* a misdiagnosis a user will act on, restarting a server that was never the
|
|
99
|
+
* problem. The scheme is required for the same reason: `localhost:8080` parses
|
|
100
|
+
* as a URL whose scheme is `localhost:`, not as a host.
|
|
101
|
+
*/
|
|
102
|
+
function requireAbsolute(baseUrl) {
|
|
103
|
+
let parsed;
|
|
104
|
+
try {
|
|
105
|
+
parsed = new URL(baseUrl);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw configError(`The w6w base URL must be an absolute origin, and \`${baseUrl}\` is not one.`, "--base-url", ENV_BASE_URL, "It looks like `https://api.example.com` — scheme and host, no path.");
|
|
109
|
+
}
|
|
110
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
111
|
+
throw configError(`The w6w base URL must be an http or https origin, and \`${baseUrl}\` is not one.`, "--base-url", ENV_BASE_URL, "It looks like `https://api.example.com` — scheme and host, no path.");
|
|
112
|
+
}
|
|
113
|
+
return baseUrl;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Characters that cannot be carried in an HTTP header value: the C0 controls,
|
|
117
|
+
* `DEL`, and anything above the single-byte range.
|
|
118
|
+
*
|
|
119
|
+
* A token is normally opaque ASCII, so this rejects almost nothing real — except
|
|
120
|
+
* the one thing that happens constantly, which is a trailing newline on a token
|
|
121
|
+
* read out of a file (`W6W_TOKEN=$(cat token.txt)`). Left unchecked that reaches
|
|
122
|
+
* the header builder and comes back as a bare `TypeError` from outside anyone's
|
|
123
|
+
* error model: a stack trace, for a typo.
|
|
124
|
+
*/
|
|
125
|
+
function isUnsendable(token) {
|
|
126
|
+
for (const character of token) {
|
|
127
|
+
const code = character.codePointAt(0) ?? 0;
|
|
128
|
+
if (code < 0x20 || code === 0x7f || code > 0xff)
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
/** The token, checked well enough that it can actually be put on the wire. */
|
|
134
|
+
function requireSendableToken(token) {
|
|
135
|
+
if (!isUnsendable(token))
|
|
136
|
+
return token;
|
|
137
|
+
throw configError("The w6w API token contains a character that cannot be sent in an HTTP header " +
|
|
138
|
+
"(a control character, such as a newline).", "--token", ENV_TOKEN, "A token read out of a file usually carries a trailing newline — strip it.");
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Build the API client for one invocation.
|
|
142
|
+
*
|
|
143
|
+
* Call this **lazily**, when a command has decided it needs the API — never at
|
|
144
|
+
* module load, and never on the help or `--version` path, which must resolve
|
|
145
|
+
* with no token configured and no server reachable.
|
|
146
|
+
*
|
|
147
|
+
* @param globals - The parsed global flags.
|
|
148
|
+
* @param env - The environment seam. Defaults to an empty environment.
|
|
149
|
+
* @param options - Transport and default project.
|
|
150
|
+
* @returns A configured client.
|
|
151
|
+
* @throws {ConfigError} When the base URL or token is missing or unusable — a usage error.
|
|
152
|
+
*/
|
|
153
|
+
export function createClient(globals, env = NO_ENV, options = {}) {
|
|
154
|
+
const baseUrl = resolve(globals.baseUrl, env, ENV_BASE_URL);
|
|
155
|
+
if (baseUrl === undefined || baseUrl.trim().length === 0) {
|
|
156
|
+
throw configError("No w6w base URL is configured.", "--base-url", ENV_BASE_URL, "It holds the server's origin, like `https://api.example.com`; the API base path is appended for you.");
|
|
157
|
+
}
|
|
158
|
+
const token = resolve(globals.token, env, ENV_TOKEN);
|
|
159
|
+
if (token === undefined || token.trim().length === 0) {
|
|
160
|
+
throw configError("No w6w API token is configured.", "--token", ENV_TOKEN, "Every w6w API command is authenticated.");
|
|
161
|
+
}
|
|
162
|
+
// The join rule (origin in, base path appended, never doubled) belongs to the
|
|
163
|
+
// SDK and is applied by the constructor. Nothing here re-derives it — read it
|
|
164
|
+
// back off `client.config.baseUrl` if you need to know where a request went.
|
|
165
|
+
return new W6wClient({
|
|
166
|
+
baseUrl: requireAbsolute(baseUrl.trim()),
|
|
167
|
+
token: requireSendableToken(token),
|
|
168
|
+
project: options.project,
|
|
169
|
+
fetch: options.fetch,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","s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ACvG,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,MAAM,WAAW,CACf,iCAAiC,EACjC,SAAS,EACT,SAAS,EACT,yCAAyC,CAC1C,CAAC;IACJ,CAAC;IAED,8EAA8E;IAC9E,8EAA8E;IAC9E,6EAA6E;IAC7E,OAAO,IAAI,SAAS,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACxC,KAAK,EAAE,oBAAoB,CAAC,KAAK,CAAC;QAClC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `w6w connections list` — discovery, and nothing more (D4).
|
|
3
|
+
*
|
|
4
|
+
* One command, one SDK call, no filters and no pagination: the operation
|
|
5
|
+
* exists so a caller can find a `conn_…` id to pass to `w6w run`, and nothing
|
|
6
|
+
* about creating, testing or reconnecting an app lives here — that is
|
|
7
|
+
* `outOfScope` in `endpoints.json` for this version.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import type { CommandRegistry } from "../../mod.ts";
|
|
12
|
+
export declare const CONNECTION_COMMANDS: CommandRegistry;
|
|
13
|
+
//# sourceMappingURL=connections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/commands/connections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,cAAc,CAAC;AAsBpE,eAAO,MAAM,mBAAmB,EAAE,eAEjC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `w6w connections list` — discovery, and nothing more (D4).
|
|
3
|
+
*
|
|
4
|
+
* One command, one SDK call, no filters and no pagination: the operation
|
|
5
|
+
* exists so a caller can find a `conn_…` id to pass to `w6w run`, and nothing
|
|
6
|
+
* about creating, testing or reconnecting an app lives here — that is
|
|
7
|
+
* `outOfScope` in `endpoints.json` for this version.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { noExtraArguments, table } from "./shared.js";
|
|
12
|
+
/** One connection, as a table row. */
|
|
13
|
+
function row(connection) {
|
|
14
|
+
return [connection.id, connection.appId, connection.state, connection.displayName];
|
|
15
|
+
}
|
|
16
|
+
/** The listing: one line per connection, or a line saying there are none. */
|
|
17
|
+
function renderList(connections, styles) {
|
|
18
|
+
if (connections.length === 0)
|
|
19
|
+
return styles.dim("No connections.");
|
|
20
|
+
return table(["ID", "APP", "STATE", "NAME"], connections.map(row), styles);
|
|
21
|
+
}
|
|
22
|
+
const list = async (context) => {
|
|
23
|
+
noExtraArguments(context, 0);
|
|
24
|
+
const connections = await context.client().connections.list();
|
|
25
|
+
context.out.emit(connections, (styles) => renderList(connections, styles));
|
|
26
|
+
};
|
|
27
|
+
export const CONNECTION_COMMANDS = {
|
|
28
|
+
"connections list": list,
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=connections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connections.js","sourceRoot":"","sources":["../../../src/commands/connections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEtD,sCAAsC;AACtC,SAAS,GAAG,CAAC,UAA6B;IACxC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;AACrF,CAAC;AAED,6EAA6E;AAC7E,SAAS,UAAU,CAAC,WAAgC,EAAE,MAAc;IAClE,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACnE,OAAO,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,IAAI,GAAmB,KAAK,EAAE,OAAO,EAAE,EAAE;IAC7C,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7B,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;AAC7E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAoB;IAClD,kBAAkB,EAAE,IAAI;CACzB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `w6w documents …` — the document store at the command line.
|
|
3
|
+
*
|
|
4
|
+
* Six commands, **one SDK call each**. Nothing here composes two requests,
|
|
5
|
+
* filters a list, sorts a result or resolves a key by scanning: a wrapper that
|
|
6
|
+
* has to compose two calls is describing an operation that belongs in the API
|
|
7
|
+
* (`README.md`, "What a wrapper is"), and the CLI is a wrapper like the other
|
|
8
|
+
* two. Addressing mirrors the server exactly — **create by `key`, read by id or
|
|
9
|
+
* by key, update and delete by id** (`docs/implementation.md` §7).
|
|
10
|
+
*
|
|
11
|
+
* Everything a handler does falls into four steps, in this order: read its own
|
|
12
|
+
* arguments, call one method on `client.documents`, render, return. Errors are
|
|
13
|
+
* not caught here — `main()` reports a throw once, on stderr, and maps it to an
|
|
14
|
+
* exit code through `src/exit.ts`, so an `ApiError` exits 2 and a usage error
|
|
15
|
+
* exits 1 without any command deciding that for itself.
|
|
16
|
+
*
|
|
17
|
+
* **`--project` belongs to this group and not to `w6w vars`.** Documents are
|
|
18
|
+
* project-scoped and every route below takes an optional `?project=`; variables
|
|
19
|
+
* are not, and `src/commands/vars.ts` refuses the flag rather than accepting one
|
|
20
|
+
* the server would ignore.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import type { CommandRegistry } from "../../mod.ts";
|
|
25
|
+
/**
|
|
26
|
+
* The six `w6w documents` commands, keyed by the canonical command path.
|
|
27
|
+
*
|
|
28
|
+
* The keys are the generated help tree's `path` values joined by a space, which
|
|
29
|
+
* are `endpoints.json`'s `naming.cli` spellings — `tests/cmd_documents_test.ts`
|
|
30
|
+
* asserts the two sets are the same, so a command cannot be registered under a
|
|
31
|
+
* name the help does not document, or documented under a name nothing runs.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DOCUMENT_COMMANDS: CommandRegistry;
|
|
34
|
+
//# sourceMappingURL=documents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../../src/commands/documents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAkC,eAAe,EAAE,MAAM,cAAc,CAAC;AA4JpF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAO/B,CAAC"}
|