@w6w/cli 0.9.13 → 0.9.16
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 +26 -15
- package/dist/bin/w6w.js +4 -0
- package/dist/bin/w6w.js.map +1 -1
- package/dist/mod.d.ts +20 -2
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +25 -13
- package/dist/mod.js.map +1 -1
- package/dist/src/client.d.ts +51 -4
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +83 -30
- package/dist/src/client.js.map +1 -1
- package/dist/src/commands/auth.d.ts +24 -0
- package/dist/src/commands/auth.d.ts.map +1 -0
- package/dist/src/commands/auth.js +112 -0
- package/dist/src/commands/auth.js.map +1 -0
- package/dist/src/commands/functions.d.ts.map +1 -1
- package/dist/src/commands/functions.js +12 -1
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/index.d.ts +1 -0
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +3 -0
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/workflows.js +1 -1
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/config-store.d.ts +86 -0
- package/dist/src/config-store.d.ts.map +1 -0
- package/dist/src/config-store.js +129 -0
- package/dist/src/config-store.js.map +1 -0
- package/dist/src/help.generated.d.ts.map +1 -1
- package/dist/src/help.generated.js +132 -4
- package/dist/src/help.generated.js.map +1 -1
- package/dist/src/store-fs.d.ts +34 -0
- package/dist/src/store-fs.d.ts.map +1 -0
- package/dist/src/store-fs.js +151 -0
- package/dist/src/store-fs.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,18 +23,30 @@ released together. A given version means the same set of operations in every lan
|
|
|
23
23
|
|
|
24
24
|
## Configuration
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
With nothing configured, `w6w` talks to **`https://api.w6w.io`**. Save a token once and later
|
|
27
|
+
commands use it:
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
```bash
|
|
30
|
+
printf '%s' "$W6W_TOKEN" | w6w auth login - # preferred: keeps the token out of shell history
|
|
31
|
+
w6w auth login <token> # also works, but the token lands in history and `ps`
|
|
32
|
+
w6w auth status # base URL, where it came from, masked token
|
|
33
|
+
w6w auth logout
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The token is stored per user (`~/.config/w6w/config.json`, or `$XDG_CONFIG_HOME/w6w/…`;
|
|
37
|
+
`%APPDATA%\w6w\…` on Windows), mode `0600`, and **bound to the base URL it was saved for** — it is
|
|
38
|
+
never sent to another host. Two environment variables and two flags override it:
|
|
39
|
+
|
|
40
|
+
| Variable | Meaning | Required |
|
|
41
|
+
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
42
|
+
| `W6W_BASE_URL` | The **origin** of your w6w server, e.g. `https://api.example.com`. Defaults to `https://api.w6w.io`. The API is served at the root of that host, so nothing is appended — and a stale `/api` suffix from `0.1.x` must be dropped. | No |
|
|
43
|
+
| `W6W_TOKEN` | Your API token, sent as `Authorization: Bearer <token>` on every request. Not needed after `w6w auth login`. | No |
|
|
32
44
|
|
|
33
|
-
Both have a flag equivalent, and **a flag always wins over the environment
|
|
34
|
-
`--token <token>`.
|
|
45
|
+
Both have a flag equivalent, and **a flag always wins over the environment, which wins over the
|
|
46
|
+
stored config**: `--base-url <url>` and `--token <token>`.
|
|
35
47
|
|
|
36
48
|
```bash
|
|
37
|
-
export W6W_BASE_URL=https://api.example.com
|
|
49
|
+
export W6W_BASE_URL=https://api.example.com # only for a self-hosted server
|
|
38
50
|
export W6W_TOKEN=…
|
|
39
51
|
w6w workflows list
|
|
40
52
|
```
|
|
@@ -88,7 +100,6 @@ A few flags that `--help` lists aren't applied yet:
|
|
|
88
100
|
- `functions run` / `endpoints run` read neither `--id-or-key` nor `--inputs` / `--input`, and
|
|
89
101
|
reject `--payload`. Pass the key positionally, and send input with
|
|
90
102
|
`w6w run fn:<key> --payload '…'` (or `ep:<key>`).
|
|
91
|
-
- `workflows update` ignores `--if-unmodified-since`, so the save always wins.
|
|
92
103
|
- `team --help` still says the routes return `404`; they are live and work.
|
|
93
104
|
- `functions delete` needs the Function archived first, which the CLI can't do yet.
|
|
94
105
|
|
|
@@ -109,12 +120,12 @@ root help and exits `0`.
|
|
|
109
120
|
|
|
110
121
|
## Exit codes
|
|
111
122
|
|
|
112
|
-
| Code | Meaning
|
|
113
|
-
| ---- |
|
|
114
|
-
| `0` | Success — including help, and including a _queued_ or _running_ workflow
|
|
115
|
-
| `1` | Usage or configuration error — unknown command, missing argument, bad flag or JSON, no
|
|
116
|
-
| `2` | API error — 4xx/5xx from the server, including auth failure, or the server could not be reached
|
|
117
|
-
| `3` | Run failure — `--wait` returned a run with status `failed`
|
|
123
|
+
| Code | Meaning |
|
|
124
|
+
| ---- | ------------------------------------------------------------------------------------------------------------------- |
|
|
125
|
+
| `0` | Success — including help, and including a _queued_ or _running_ workflow |
|
|
126
|
+
| `1` | Usage or configuration error — unknown command, missing argument, bad flag or JSON, no token, an empty `--base-url` |
|
|
127
|
+
| `2` | API error — 4xx/5xx from the server, including auth failure, or the server could not be reached |
|
|
128
|
+
| `3` | Run failure — `--wait` returned a run with status `failed` |
|
|
118
129
|
|
|
119
130
|
Code `3` exists so `w6w workflows run --wait` is usable in CI without parsing stdout. Keeping it
|
|
120
131
|
distinct from `2` matters: a failed workflow and an unreachable API demand opposite responses, and a
|
package/dist/bin/w6w.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import { main } from "../mod.js";
|
|
22
22
|
import { COMMANDS } from "../src/commands/index.js";
|
|
23
23
|
import { systemRuntime } from "../src/runtime.js";
|
|
24
|
+
import { fsConfigStore, readStdin, stdinIsTerminal } from "../src/store-fs.js";
|
|
24
25
|
/**
|
|
25
26
|
* The commands this build can run.
|
|
26
27
|
*
|
|
@@ -53,6 +54,9 @@ const code = await main(runtime.args, runtime, {
|
|
|
53
54
|
env: runtime.env,
|
|
54
55
|
isTty: stdoutIsTerminal(),
|
|
55
56
|
commands,
|
|
57
|
+
// The only place the real file store and real stdin are constructed.
|
|
58
|
+
store: fsConfigStore(runtime.env),
|
|
59
|
+
stdin: { isTerminal: stdinIsTerminal, read: readStdin },
|
|
56
60
|
});
|
|
57
61
|
runtime.exit(code);
|
|
58
62
|
//# sourceMappingURL=w6w.js.map
|
package/dist/bin/w6w.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"w6w.js","sourceRoot":"","sources":["../../bin/w6w.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"w6w.js","sourceRoot":"","sources":["../../bin/w6w.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE/E;;;;;;;;GAQG;AACH,MAAM,QAAQ,GAAoB,QAAQ,CAAC;AAE3C;;;;;;;;;GASG;AACH,SAAS,gBAAgB;IACvB,MAAM,IAAI,GAAG,UAGZ,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,IAAI,IAAI,EAAE,UAAU;QAAE,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC/C,OAAO,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,IAAI,CAAC;AAC9C,CAAC;AAED,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;AAChC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE;IAC7C,GAAG,EAAE,OAAO,CAAC,GAAG;IAChB,KAAK,EAAE,gBAAgB,EAAE;IACzB,QAAQ;IACR,qEAAqE;IACrE,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC;IACjC,KAAK,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE;CACxD,CAAC,CAAC;AACH,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -27,14 +27,17 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import type { Invocation } from "./src/args.ts";
|
|
29
29
|
import type { EnvReader } from "./src/client.ts";
|
|
30
|
+
import type { ConfigStore, StdinSource, StoredConfig } from "./src/config-store.ts";
|
|
30
31
|
import type { Output } from "./src/output.ts";
|
|
31
32
|
import type { HelpCommand } from "./src/help.generated.ts";
|
|
32
33
|
import type { CliIo } from "./src/runtime.ts";
|
|
33
34
|
import type { FetchLike, W6WClient } from "@w6w/sdk";
|
|
34
35
|
export { parse } from "./src/args.ts";
|
|
35
36
|
export type { FlagSpec, GlobalOptions, Invocation, ParseOptions, ParseResult } from "./src/args.ts";
|
|
36
|
-
export { createClient, ENV_BASE_URL, ENV_TOKEN, envValue, NO_ENV } from "./src/client.ts";
|
|
37
|
-
export type { ClientOptions, EnvReader } from "./src/client.ts";
|
|
37
|
+
export { createClient, DEFAULT_BASE_URL, ENV_BASE_URL, ENV_TOKEN, envValue, NO_ENV, resolveSettings, } from "./src/client.ts";
|
|
38
|
+
export type { ClientOptions, EnvReader, ResolvedSettings, Source } from "./src/client.ts";
|
|
39
|
+
export { configPath, loadConfig, NO_CONFIG, NO_STDIN, NO_STORE, parseConfig, serializeConfig, } from "./src/config-store.ts";
|
|
40
|
+
export type { ConfigStore, StdinSource, StoredConfig } from "./src/config-store.ts";
|
|
38
41
|
export { createOutput, ENV_NO_COLOR, useColor } from "./src/output.ts";
|
|
39
42
|
export type { Output, OutputOptions, Styles } from "./src/output.ts";
|
|
40
43
|
export { EXIT_API_ERROR, EXIT_RUN_FAILURE, EXIT_SUCCESS, EXIT_USAGE, exitCodeFor, } from "./src/exit.ts";
|
|
@@ -79,6 +82,14 @@ export interface CommandContext {
|
|
|
79
82
|
* @throws {ConfigError} When the base URL or token is missing or unusable.
|
|
80
83
|
*/
|
|
81
84
|
client(): W6WClient;
|
|
85
|
+
/** The environment seam this invocation runs with. */
|
|
86
|
+
readonly env: EnvReader;
|
|
87
|
+
/** The stored per-user config, read once before the handler runs (nothing stored by default). */
|
|
88
|
+
readonly stored: StoredConfig;
|
|
89
|
+
/** Where the config is persisted. Only the `auth` commands write through it. */
|
|
90
|
+
readonly store: ConfigStore;
|
|
91
|
+
/** Standard input, for `auth login -`. */
|
|
92
|
+
readonly stdin: StdinSource;
|
|
82
93
|
}
|
|
83
94
|
/**
|
|
84
95
|
* One command's implementation.
|
|
@@ -108,6 +119,13 @@ export interface CliOptions {
|
|
|
108
119
|
isTty?: boolean;
|
|
109
120
|
/** The commands that are wired up. Defaults to none. */
|
|
110
121
|
commands?: CommandRegistry;
|
|
122
|
+
/**
|
|
123
|
+
* The per-user config store. Defaults to {@linkcode NO_STORE}: nothing stored,
|
|
124
|
+
* no file I/O. Only `bin/w6w.ts` wires the real one.
|
|
125
|
+
*/
|
|
126
|
+
store?: ConfigStore;
|
|
127
|
+
/** Standard input. Defaults to {@linkcode NO_STDIN}: a terminal, never read. */
|
|
128
|
+
stdin?: StdinSource;
|
|
111
129
|
}
|
|
112
130
|
/**
|
|
113
131
|
* Runs a command line and returns its exit code. The whole CLI.
|
package/dist/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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C,MAAM,CAAC,CAI/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,MAAM,CASxD"}
|
package/dist/mod.js
CHANGED
|
@@ -27,12 +27,14 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { GLOBAL_FLAG_SPECS, parse } from "./src/args.js";
|
|
29
29
|
import { createClient, NO_ENV } from "./src/client.js";
|
|
30
|
+
import { loadConfig, NO_STDIN, NO_STORE } from "./src/config-store.js";
|
|
30
31
|
import { createOutput } from "./src/output.js";
|
|
31
32
|
import { EXIT_SUCCESS, EXIT_USAGE, exitCodeFor } from "./src/exit.js";
|
|
32
33
|
import { renderCommandHelp, renderGroupHelp, renderHelp, renderRootHelp, resolve, } from "./src/help.js";
|
|
33
34
|
import { HELP_TREE } from "./src/help.generated.js";
|
|
34
35
|
export { parse } from "./src/args.js";
|
|
35
|
-
export { createClient, ENV_BASE_URL, ENV_TOKEN, envValue, NO_ENV } from "./src/client.js";
|
|
36
|
+
export { createClient, DEFAULT_BASE_URL, ENV_BASE_URL, ENV_TOKEN, envValue, NO_ENV, resolveSettings, } from "./src/client.js";
|
|
37
|
+
export { configPath, loadConfig, NO_CONFIG, NO_STDIN, NO_STORE, parseConfig, serializeConfig, } from "./src/config-store.js";
|
|
36
38
|
export { createOutput, ENV_NO_COLOR, useColor } from "./src/output.js";
|
|
37
39
|
export { EXIT_API_ERROR, EXIT_RUN_FAILURE, EXIT_SUCCESS, EXIT_USAGE, exitCodeFor, } from "./src/exit.js";
|
|
38
40
|
export { renderCommandHelp, renderGroupHelp, renderHelp, renderRootHelp, resolve, } from "./src/help.js";
|
|
@@ -51,7 +53,7 @@ export { COMMAND_PATHS, EXIT_CODES, GLOBAL_FLAGS, HELP_TREE } from "./src/help.g
|
|
|
51
53
|
* The explicit `: string` annotation is required, not decorative: JSR publishes
|
|
52
54
|
* this file as TypeScript source and rejects inferred public types.
|
|
53
55
|
*/
|
|
54
|
-
export const VERSION = "0.9.
|
|
56
|
+
export const VERSION = "0.9.16";
|
|
55
57
|
/** `w6w help <command>` is accepted as an alias for `w6w <command> --help`. */
|
|
56
58
|
const HELP_COMMAND = "help";
|
|
57
59
|
/**
|
|
@@ -213,18 +215,28 @@ async function dispatch(routed, io, options) {
|
|
|
213
215
|
// Built on demand and remembered: a command that never asks for the API never
|
|
214
216
|
// needs a token, and one that asks twice gets one client, not two.
|
|
215
217
|
let client = null;
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
invocation: routed.invocation,
|
|
219
|
-
out,
|
|
220
|
-
client: () => {
|
|
221
|
-
if (client === null) {
|
|
222
|
-
client = createClient(globals, options.env ?? NO_ENV, { fetch: options.fetch });
|
|
223
|
-
}
|
|
224
|
-
return client;
|
|
225
|
-
},
|
|
226
|
-
};
|
|
218
|
+
const env = options.env ?? NO_ENV;
|
|
219
|
+
const store = options.store ?? NO_STORE;
|
|
227
220
|
try {
|
|
221
|
+
// Read once, before any handler: every dispatched command sees the same
|
|
222
|
+
// stored config, `createClient` stays synchronous, and a malformed file fails
|
|
223
|
+
// the command up front (help and `--version` never reach this point).
|
|
224
|
+
const stored = await loadConfig(store);
|
|
225
|
+
const context = {
|
|
226
|
+
command: routed.command,
|
|
227
|
+
invocation: routed.invocation,
|
|
228
|
+
out,
|
|
229
|
+
env,
|
|
230
|
+
stored,
|
|
231
|
+
store,
|
|
232
|
+
stdin: options.stdin ?? NO_STDIN,
|
|
233
|
+
client: () => {
|
|
234
|
+
if (client === null) {
|
|
235
|
+
client = createClient(globals, env, { fetch: options.fetch, stored });
|
|
236
|
+
}
|
|
237
|
+
return client;
|
|
238
|
+
},
|
|
239
|
+
};
|
|
228
240
|
return (await handler(context)) ?? EXIT_SUCCESS;
|
|
229
241
|
}
|
|
230
242
|
catch (error) {
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../mod.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AC,IAAc,EAAE,EAAS;IAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC/B,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,EAAE,CAAC,MAAM,CACP,GAAG,SAAS,CAAC,MAAM,OAAO,IAAI,2DAA2D;QACvF,SAAS,SAAS,CAAC,MAAM,IAAI,IAAI,YAAY,CAChD,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -9,9 +9,16 @@
|
|
|
9
9
|
* has a flag which outranks the environment variable.
|
|
10
10
|
*
|
|
11
11
|
* ```
|
|
12
|
-
* CLI flag (--base-url
|
|
12
|
+
* base URL CLI flag (--base-url) > W6W_BASE_URL > stored `baseUrl` > DEFAULT_BASE_URL
|
|
13
|
+
* token CLI flag (--token) > W6W_TOKEN > the stored token for the resolved base URL
|
|
13
14
|
* ```
|
|
14
15
|
*
|
|
16
|
+
* The stored tier is the per-user config `w6w auth login` writes (see
|
|
17
|
+
* `src/config-store.ts`). A stored token is **bound to the base URL it was saved
|
|
18
|
+
* for**: it is looked up by the canonical resolved base URL, exact match only, so
|
|
19
|
+
* pointing `--base-url` or `W6W_BASE_URL` at another host can never send it
|
|
20
|
+
* there. That is the trust boundary of this module.
|
|
21
|
+
*
|
|
15
22
|
* The resolved values are passed to the SDK **explicitly**, and the SDK is never
|
|
16
23
|
* left to read the environment on the CLI's behalf. That is a mechanism choice,
|
|
17
24
|
* not a stylistic one: the CLI has to be able to say *which* source it was
|
|
@@ -25,6 +32,11 @@
|
|
|
25
32
|
*/
|
|
26
33
|
import { type FetchLike, W6WClient } from "@w6w/sdk";
|
|
27
34
|
import type { GlobalOptions } from "./args.ts";
|
|
35
|
+
import { type StoredConfig } from "./config-store.ts";
|
|
36
|
+
/** The API every command targets unless told otherwise. Equals endpoints.json `defaultBaseUrl`. */
|
|
37
|
+
export declare const DEFAULT_BASE_URL = "https://api.w6w.io";
|
|
38
|
+
/** Where a resolved setting came from. */
|
|
39
|
+
export type Source = "flag" | "env" | "config" | "default";
|
|
28
40
|
/**
|
|
29
41
|
* Reads one environment variable, or `undefined` where the host has none.
|
|
30
42
|
*
|
|
@@ -43,8 +55,8 @@ export declare const NO_ENV: EnvReader;
|
|
|
43
55
|
* Read an environment variable, treating a blank value as **absent**.
|
|
44
56
|
*
|
|
45
57
|
* `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
|
|
47
|
-
*
|
|
58
|
+
* thing: all three fall through the precedence chain to the next source (the
|
|
59
|
+
* stored base URL, then the default).
|
|
48
60
|
*
|
|
49
61
|
* The check is a trim-and-emptiness test and deliberately **not** a nullish
|
|
50
62
|
* coalesce. `??` does not convert `""`, so a set-but-empty variable would
|
|
@@ -64,6 +76,17 @@ export declare const NO_ENV: EnvReader;
|
|
|
64
76
|
* @returns The value, or `undefined` when it is unset or blank.
|
|
65
77
|
*/
|
|
66
78
|
export declare function envValue(env: EnvReader, name: string): string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Characters that cannot be carried in an HTTP header value: the C0 controls,
|
|
81
|
+
* `DEL`, and anything above the single-byte range.
|
|
82
|
+
*
|
|
83
|
+
* A token is normally opaque ASCII, so this rejects almost nothing real — except
|
|
84
|
+
* the one thing that happens constantly, which is a trailing newline on a token
|
|
85
|
+
* read out of a file (`W6W_TOKEN=$(cat token.txt)`). Left unchecked that reaches
|
|
86
|
+
* the header builder and comes back as a bare `TypeError` from outside anyone's
|
|
87
|
+
* error model: a stack trace, for a typo.
|
|
88
|
+
*/
|
|
89
|
+
export declare function isUnsendable(token: string): boolean;
|
|
67
90
|
/** Anything the caller wants to hand the client beyond the global flags. */
|
|
68
91
|
export interface ClientOptions {
|
|
69
92
|
/**
|
|
@@ -73,7 +96,31 @@ export interface ClientOptions {
|
|
|
73
96
|
fetch?: FetchLike;
|
|
74
97
|
/** Default project id for the project-scoped operations. */
|
|
75
98
|
project?: string;
|
|
99
|
+
/** The stored per-user config, already read. Defaults to nothing stored. */
|
|
100
|
+
stored?: StoredConfig;
|
|
101
|
+
}
|
|
102
|
+
/** The base URL and token one invocation resolves to, with where each came from. */
|
|
103
|
+
export interface ResolvedSettings {
|
|
104
|
+
/** Canonical (the SDK's join: trailing slashes stripped); also the `hosts` key. */
|
|
105
|
+
readonly baseUrl: string;
|
|
106
|
+
readonly baseUrlSource: Source;
|
|
107
|
+
/** Absent when no source holds a token for {@linkcode baseUrl}. */
|
|
108
|
+
readonly token?: string;
|
|
109
|
+
readonly tokenSource?: Source;
|
|
76
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* The one resolver. `createClient` and every `auth` command use it, so what
|
|
113
|
+
* `auth status` reports is what a command will do.
|
|
114
|
+
*
|
|
115
|
+
* Base URL: flag (given, even empty) > env (blank = absent) > stored `baseUrl` >
|
|
116
|
+
* {@linkcode DEFAULT_BASE_URL}, validated, then canonicalised once. Token: flag >
|
|
117
|
+
* env > `stored.hosts[<canonical base URL>]` — exact key only.
|
|
118
|
+
*
|
|
119
|
+
* @throws {ConfigError} When the base URL is blank-by-flag, relative, or not http(s),
|
|
120
|
+
* or a resolved token cannot be sent in a header. A *missing* token is not an
|
|
121
|
+
* error here; `createClient` raises that.
|
|
122
|
+
*/
|
|
123
|
+
export declare function resolveSettings(globals: GlobalOptions, env?: EnvReader, stored?: StoredConfig): ResolvedSettings;
|
|
77
124
|
/**
|
|
78
125
|
* Build the API client for one invocation.
|
|
79
126
|
*
|
|
@@ -83,7 +130,7 @@ export interface ClientOptions {
|
|
|
83
130
|
*
|
|
84
131
|
* @param globals - The parsed global flags.
|
|
85
132
|
* @param env - The environment seam. Defaults to an empty environment.
|
|
86
|
-
* @param options - Transport and
|
|
133
|
+
* @param options - Transport, default project and the stored config.
|
|
87
134
|
* @returns A configured client.
|
|
88
135
|
* @throws {ConfigError} When the base URL or token is missing or unusable — a usage error.
|
|
89
136
|
*/
|
package/dist/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAe,KAAK,SAAS,EAAe,SAAS,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjE,mGAAmG;AACnG,eAAO,MAAM,gBAAgB,uBAAuB,CAAC;AAErD,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3D;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIzE;AAqDD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAMnD;AAcD,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,oFAAoF;AACpF,MAAM,WAAW,gBAAgB;IAC/B,mFAAmF;IACnF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,aAAa,EACtB,GAAG,GAAE,SAAkB,EACvB,MAAM,GAAE,YAAwB,GAC/B,gBAAgB,CAgDlB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,GAAG,GAAE,SAAkB,EACvB,OAAO,GAAE,aAAkB,GAC1B,SAAS,CAqBX"}
|
package/dist/src/client.js
CHANGED
|
@@ -9,9 +9,16 @@
|
|
|
9
9
|
* has a flag which outranks the environment variable.
|
|
10
10
|
*
|
|
11
11
|
* ```
|
|
12
|
-
* CLI flag (--base-url
|
|
12
|
+
* base URL CLI flag (--base-url) > W6W_BASE_URL > stored `baseUrl` > DEFAULT_BASE_URL
|
|
13
|
+
* token CLI flag (--token) > W6W_TOKEN > the stored token for the resolved base URL
|
|
13
14
|
* ```
|
|
14
15
|
*
|
|
16
|
+
* The stored tier is the per-user config `w6w auth login` writes (see
|
|
17
|
+
* `src/config-store.ts`). A stored token is **bound to the base URL it was saved
|
|
18
|
+
* for**: it is looked up by the canonical resolved base URL, exact match only, so
|
|
19
|
+
* pointing `--base-url` or `W6W_BASE_URL` at another host can never send it
|
|
20
|
+
* there. That is the trust boundary of this module.
|
|
21
|
+
*
|
|
15
22
|
* The resolved values are passed to the SDK **explicitly**, and the SDK is never
|
|
16
23
|
* left to read the environment on the CLI's behalf. That is a mechanism choice,
|
|
17
24
|
* not a stylistic one: the CLI has to be able to say *which* source it was
|
|
@@ -23,7 +30,10 @@
|
|
|
23
30
|
*
|
|
24
31
|
* @module
|
|
25
32
|
*/
|
|
26
|
-
import { ConfigError, W6WClient } from "@w6w/sdk";
|
|
33
|
+
import { ConfigError, joinBaseUrl, W6WClient } from "@w6w/sdk";
|
|
34
|
+
import { NO_CONFIG } from "./config-store.js";
|
|
35
|
+
/** The API every command targets unless told otherwise. Equals endpoints.json `defaultBaseUrl`. */
|
|
36
|
+
export const DEFAULT_BASE_URL = "https://api.w6w.io";
|
|
27
37
|
/** Environment variable holding the server **origin**. Falls behind `--base-url`. */
|
|
28
38
|
export const ENV_BASE_URL = "W6W_BASE_URL";
|
|
29
39
|
/** Environment variable holding the bearer token. Falls behind `--token`. */
|
|
@@ -34,8 +44,8 @@ export const NO_ENV = () => undefined;
|
|
|
34
44
|
* Read an environment variable, treating a blank value as **absent**.
|
|
35
45
|
*
|
|
36
46
|
* `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
|
|
38
|
-
*
|
|
47
|
+
* thing: all three fall through the precedence chain to the next source (the
|
|
48
|
+
* stored base URL, then the default).
|
|
39
49
|
*
|
|
40
50
|
* The check is a trim-and-emptiness test and deliberately **not** a nullish
|
|
41
51
|
* coalesce. `??` does not convert `""`, so a set-but-empty variable would
|
|
@@ -60,21 +70,6 @@ export function envValue(env, name) {
|
|
|
60
70
|
return undefined;
|
|
61
71
|
return value;
|
|
62
72
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Apply the precedence rule to one setting.
|
|
65
|
-
*
|
|
66
|
-
* A flag that was **given** wins outright, even when what it was given is empty:
|
|
67
|
-
* that is a value the user typed, and quietly consulting the environment behind
|
|
68
|
-
* an explicit `--token=` would be the CLI second-guessing them. (It still does
|
|
69
|
-
* not produce a usable value — an empty flag reaches the same error — but it
|
|
70
|
-
* gets there without a detour through the environment.) Only an **absent** flag
|
|
71
|
-
* falls through.
|
|
72
|
-
*/
|
|
73
|
-
function resolve(flag, env, name) {
|
|
74
|
-
if (flag !== undefined)
|
|
75
|
-
return flag;
|
|
76
|
-
return envValue(env, name);
|
|
77
|
-
}
|
|
78
73
|
/**
|
|
79
74
|
* A value the CLI cannot work with, phrased as a usage error.
|
|
80
75
|
*
|
|
@@ -123,7 +118,7 @@ function requireAbsolute(baseUrl) {
|
|
|
123
118
|
* the header builder and comes back as a bare `TypeError` from outside anyone's
|
|
124
119
|
* error model: a stack trace, for a typo.
|
|
125
120
|
*/
|
|
126
|
-
function isUnsendable(token) {
|
|
121
|
+
export function isUnsendable(token) {
|
|
127
122
|
for (const character of token) {
|
|
128
123
|
const code = character.codePointAt(0) ?? 0;
|
|
129
124
|
if (code < 0x20 || code === 0x7f || code > 0xff)
|
|
@@ -138,6 +133,67 @@ function requireSendableToken(token) {
|
|
|
138
133
|
throw configError("The w6w API token contains a character that cannot be sent in an HTTP header " +
|
|
139
134
|
"(a control character, such as a newline).", "--token", ENV_TOKEN, "A token read out of a file usually carries a trailing newline — strip it.");
|
|
140
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* The one resolver. `createClient` and every `auth` command use it, so what
|
|
138
|
+
* `auth status` reports is what a command will do.
|
|
139
|
+
*
|
|
140
|
+
* Base URL: flag (given, even empty) > env (blank = absent) > stored `baseUrl` >
|
|
141
|
+
* {@linkcode DEFAULT_BASE_URL}, validated, then canonicalised once. Token: flag >
|
|
142
|
+
* env > `stored.hosts[<canonical base URL>]` — exact key only.
|
|
143
|
+
*
|
|
144
|
+
* @throws {ConfigError} When the base URL is blank-by-flag, relative, or not http(s),
|
|
145
|
+
* or a resolved token cannot be sent in a header. A *missing* token is not an
|
|
146
|
+
* error here; `createClient` raises that.
|
|
147
|
+
*/
|
|
148
|
+
export function resolveSettings(globals, env = NO_ENV, stored = NO_CONFIG) {
|
|
149
|
+
let raw;
|
|
150
|
+
let baseUrlSource;
|
|
151
|
+
if (globals.baseUrl !== undefined) {
|
|
152
|
+
raw = globals.baseUrl;
|
|
153
|
+
baseUrlSource = "flag";
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const fromEnv = envValue(env, ENV_BASE_URL);
|
|
157
|
+
if (fromEnv !== undefined) {
|
|
158
|
+
raw = fromEnv;
|
|
159
|
+
baseUrlSource = "env";
|
|
160
|
+
}
|
|
161
|
+
else if (stored.baseUrl.trim().length > 0) {
|
|
162
|
+
raw = stored.baseUrl;
|
|
163
|
+
baseUrlSource = "config";
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
raw = DEFAULT_BASE_URL;
|
|
167
|
+
baseUrlSource = "default";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (raw.trim().length === 0) {
|
|
171
|
+
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 is served at its root, so no path is appended.");
|
|
172
|
+
}
|
|
173
|
+
// Validate for the CLI's own message, then canonicalise with the SDK's join —
|
|
174
|
+
// the single key used both to look a token up and to build the client.
|
|
175
|
+
const baseUrl = joinBaseUrl(requireAbsolute(raw.trim()));
|
|
176
|
+
let token;
|
|
177
|
+
let tokenSource;
|
|
178
|
+
if (globals.token !== undefined) {
|
|
179
|
+
token = globals.token;
|
|
180
|
+
tokenSource = "flag";
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const fromEnv = envValue(env, ENV_TOKEN);
|
|
184
|
+
if (fromEnv !== undefined) {
|
|
185
|
+
token = fromEnv;
|
|
186
|
+
tokenSource = "env";
|
|
187
|
+
}
|
|
188
|
+
else if (Object.hasOwn(stored.hosts, baseUrl)) {
|
|
189
|
+
token = stored.hosts[baseUrl].token;
|
|
190
|
+
tokenSource = "config";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (token === undefined || token.trim().length === 0)
|
|
194
|
+
return { baseUrl, baseUrlSource };
|
|
195
|
+
return { baseUrl, baseUrlSource, token: requireSendableToken(token), tokenSource };
|
|
196
|
+
}
|
|
141
197
|
/**
|
|
142
198
|
* Build the API client for one invocation.
|
|
143
199
|
*
|
|
@@ -147,25 +203,22 @@ function requireSendableToken(token) {
|
|
|
147
203
|
*
|
|
148
204
|
* @param globals - The parsed global flags.
|
|
149
205
|
* @param env - The environment seam. Defaults to an empty environment.
|
|
150
|
-
* @param options - Transport and
|
|
206
|
+
* @param options - Transport, default project and the stored config.
|
|
151
207
|
* @returns A configured client.
|
|
152
208
|
* @throws {ConfigError} When the base URL or token is missing or unusable — a usage error.
|
|
153
209
|
*/
|
|
154
210
|
export function createClient(globals, env = NO_ENV, options = {}) {
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
throw configError(
|
|
158
|
-
|
|
159
|
-
const token = resolve(globals.token, env, ENV_TOKEN);
|
|
160
|
-
if (token === undefined || token.trim().length === 0) {
|
|
161
|
-
throw configError("No w6w API token is configured.", "--token", ENV_TOKEN, "Every w6w API command is authenticated.");
|
|
211
|
+
const settings = resolveSettings(globals, env, options.stored);
|
|
212
|
+
if (settings.token === undefined) {
|
|
213
|
+
throw configError(`No w6w API token is configured for ${settings.baseUrl}.`, "--token", ENV_TOKEN, "Or save one with `w6w auth login` (a saved token only applies to the base URL it was saved for). " +
|
|
214
|
+
"Every w6w API command is authenticated.");
|
|
162
215
|
}
|
|
163
216
|
// The join rule (origin in, base path appended, never doubled) belongs to the
|
|
164
217
|
// SDK and is applied by the constructor. Nothing here re-derives it — read it
|
|
165
218
|
// back off `client.config.baseUrl` if you need to know where a request went.
|
|
166
219
|
return new W6WClient({
|
|
167
|
-
baseUrl:
|
|
168
|
-
token:
|
|
220
|
+
baseUrl: settings.baseUrl,
|
|
221
|
+
token: settings.token,
|
|
169
222
|
project: options.project,
|
|
170
223
|
fetch: options.fetch,
|
|
171
224
|
});
|
package/dist/src/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,WAAW,EAAkB,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,SAAS,EAAqB,MAAM,mBAAmB,CAAC;AAEjE,mGAAmG;AACnG,MAAM,CAAC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAcrD,qFAAqF;AACrF,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AAErC,uFAAuF;AACvF,MAAM,CAAC,MAAM,MAAM,GAAc,GAAG,EAAE,CAAC,SAAS,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAc,EAAE,IAAY;IACnD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvE,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,WAAW,CAAC,OAAe,EAAE,IAAY,EAAE,QAAgB,EAAE,IAAY;IAChF,OAAO,IAAI,WAAW,CACpB,GAAG,OAAO,gBAAgB,IAAI,WAAW,QAAQ,0BAA0B,IAAI,EAAE,CAClF,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,OAAe;IACtC,IAAI,MA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,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YAChD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;YACpC,WAAW,GAAG,QAAQ,CAAC;QACzB,CAAC;IACH,CAAC;IACD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACxF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,oBAAoB,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;AACrF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAsB,EACtB,MAAiB,MAAM,EACvB,UAAyB,EAAE;IAE3B,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,WAAW,CACf,sCAAsC,QAAQ,CAAC,OAAO,GAAG,EACzD,SAAS,EACT,SAAS,EACT,mGAAmG;YACjG,yCAAyC,CAC5C,CAAC;IACJ,CAAC;IAED,8EAA8E;IAC9E,8EAA8E;IAC9E,6EAA6E;IAC7E,OAAO,IAAI,SAAS,CAAC;QACnB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `w6w auth login | logout | status` — the stored API token.
|
|
3
|
+
*
|
|
4
|
+
* Declared in `endpoints.json` `cli.commands[]` (CLI-only: no API operation sits
|
|
5
|
+
* behind them) and routed like any other group. None of them touches the
|
|
6
|
+
* network, and none ever prints a token.
|
|
7
|
+
*
|
|
8
|
+
* The token is **bound to the base URL it is saved for**. All three commands
|
|
9
|
+
* resolve that URL through the one resolver in `src/client.ts`
|
|
10
|
+
* ({@linkcode resolveSettings}), the same code a real command uses, so
|
|
11
|
+
* `auth status` reports exactly what the next command will do.
|
|
12
|
+
*
|
|
13
|
+
* `login` takes the token as a positional (`w6w auth login <token>`) or from
|
|
14
|
+
* standard input (`w6w auth login -`, or no argument with piped input). The
|
|
15
|
+
* stdin form is the safer one: a positional lands in shell history and in the
|
|
16
|
+
* process list. `login` never stores the global `--token` or `W6W_TOKEN` — they
|
|
17
|
+
* are overrides, not credentials to save.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import type { CommandRegistry } from "../../mod.ts";
|
|
22
|
+
/** The three `w6w auth` commands. */
|
|
23
|
+
export declare const AUTH_COMMANDS: CommandRegistry;
|
|
24
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/commands/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAkC,eAAe,EAAE,MAAM,cAAc,CAAC;AAqHpF,qCAAqC;AACrC,eAAO,MAAM,aAAa,EAAE,eAI3B,CAAC"}
|