@owlmeans/cli-auth 0.1.18-rc.14 → 0.1.18-rc.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 +1 -1
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/cli-auth/SKILL.md +17 -15
- package/build/consts.local.d.ts +2 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +6 -0
- package/build/consts.local.js.map +1 -0
- package/build/env-file/types.d.ts +45 -0
- package/build/env-file/types.d.ts.map +1 -0
- package/build/env-file/types.js +2 -0
- package/build/env-file/types.js.map +1 -0
- package/build/env-file.d.ts +4 -40
- package/build/env-file.d.ts.map +1 -1
- package/build/env-file.js +71 -99
- package/build/env-file.js.map +1 -1
- package/build/holder.d.ts +1 -36
- package/build/holder.d.ts.map +1 -1
- package/build/holder.js +19 -19
- package/build/holder.js.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/lock/types.d.ts +28 -0
- package/build/lock/types.d.ts.map +1 -0
- package/build/lock/types.js +2 -0
- package/build/lock/types.js.map +1 -0
- package/build/lock.d.ts +2 -37
- package/build/lock.d.ts.map +1 -1
- package/build/lock.js +35 -43
- package/build/lock.js.map +1 -1
- package/build/open-browser.d.ts.map +1 -1
- package/build/open-browser.js +1 -5
- package/build/open-browser.js.map +1 -1
- package/build/types.d.ts +57 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +4 -4
- package/src/consts.local.ts +5 -0
- package/src/env-file/types.ts +45 -0
- package/src/env-file.ts +87 -110
- package/src/holder.ts +20 -62
- package/src/index.ts +3 -0
- package/src/lock/types.ts +29 -0
- package/src/lock.ts +33 -61
- package/src/open-browser.ts +1 -6
- package/src/types.ts +58 -0
- package/tests/env-file.spec.ts +18 -18
- package/tests/holder.spec.ts +4 -6
- package/tests/lock.spec.ts +22 -19
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
6
6
|
your project's skill store (`.agents/skills/`):
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npx @owlmeans/agent-skills@^0.1.18-rc.
|
|
9
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.49
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/cli-auth",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-10-
|
|
4
|
+
"version": "0.1.18-rc.16",
|
|
5
|
+
"generatedAt": "2026-10-05T21:03:06.419Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/cli-auth
|
|
9
9
|
|
|
10
10
|
**Layer:** Tooling (Node/Bun — no React, no DOM, no framework runtime)
|
|
11
|
-
**Install:** `"@owlmeans/cli-auth": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/cli-auth": "^0.1.18-rc.16"` in `dependencies`
|
|
12
12
|
**Contracts:** `@owlmeans/oauth` (discovery, device authorization, polling, revoke, `SignInRequired`)
|
|
13
13
|
**Server half:** any API built on `@owlmeans/server-oauth`; **consumers:** `@owlmeans/viable-mcp`
|
|
14
14
|
|
|
@@ -17,13 +17,13 @@ user-invocable: false
|
|
|
17
17
|
| Export | Description |
|
|
18
18
|
|--------|-------------|
|
|
19
19
|
| `makeCliCredentials(opts)` | The holder: `token()` · `require(waitMs?)` · `invalidate(rejected)` · `signOut()` |
|
|
20
|
-
| `resolveEnvFile(env?)` | `OWLMEANS_CREDENTIALS`, else `~/.owlmeans` |
|
|
21
|
-
| `parseEnv(content)` | `KEY=value`, optional `export `, `#` comments, one level of quotes |
|
|
22
|
-
| `readCredentialsFile(env?)` | The file's values alone — what a token is *bound* to |
|
|
23
|
-
| `loadOwlmeansEnv(env?)` | File overlaid by the process environment (below) |
|
|
24
|
-
| `setEnvValues(path, values)` | Replace named keys, keep every other line; atomic, `0600`; returns `{ insecurePermissions }` |
|
|
20
|
+
| `envFileHelper.resolveEnvFile(env?)` | `OWLMEANS_CREDENTIALS`, else `~/.owlmeans` |
|
|
21
|
+
| `envFileHelper.parseEnv(content)` | `KEY=value`, optional `export `, `#` comments, one level of quotes |
|
|
22
|
+
| `envFileHelper.readCredentialsFile(env?)` | The file's values alone — what a token is *bound* to |
|
|
23
|
+
| `envFileHelper.loadOwlmeansEnv(env?)` | File overlaid by the process environment (below) |
|
|
24
|
+
| `envFileHelper.setEnvValues(path, values)` | Replace named keys, keep every other line; atomic, `0600`; returns `{ insecurePermissions }` |
|
|
25
25
|
| `openBrowser(url, env?)` | Best-effort detached opener; `false` on any refusal |
|
|
26
|
-
| `claimOrJoinLock` ·
|
|
26
|
+
| `makeSignInLockHelper(lockPathFor(file))` → `.claimOrJoinLock` · `.readLock` · `.releaseLock`; `SignInLockInfo` | The sign-in lock |
|
|
27
27
|
| `ENV_CREDENTIALS_FILE` · `DEFAULT_CREDENTIALS_FILENAME` · `DEFAULT_WAIT_MS` (20 s) · `MAX_SIGN_IN_WAIT_MS` (15 min) | Constants |
|
|
28
28
|
|
|
29
29
|
`CliCredentialsOptions`: `apiUrl`, `clientId` (a static client the server declared, or a CIMD URL),
|
|
@@ -36,7 +36,8 @@ names), `deviceName?` (defaults to `host · user`), `resource?` (defaults to `ap
|
|
|
36
36
|
Dotenv-style `KEY=VALUE`, e.g. `VIABLE_API_URL=…` and `VIABLE_API_TOKEN=…`. Never merged with another
|
|
37
37
|
file; a CLI that serves several deployments points `OWLMEANS_CREDENTIALS` at one file each.
|
|
38
38
|
|
|
39
|
-
- **The environment wins over the file** (`loadOwlmeansEnv` →
|
|
39
|
+
- **The environment wins over the file** (`envFileHelper.loadOwlmeansEnv` →
|
|
40
|
+
`{ ...file, ...envWithoutEmpty }`).
|
|
40
41
|
- **An empty environment value counts as unset.** A harness config that expands an unset variable
|
|
41
42
|
(`${VIABLE_API_TOKEN:-}`) produces `''`, which must not shadow the file — "I did not set it" and
|
|
42
43
|
"set it to nothing" are not the same, and the file is the more deliberate of the two.
|
|
@@ -52,12 +53,12 @@ file; a CLI that serves several deployments points `OWLMEANS_CREDENTIALS` at one
|
|
|
52
53
|
|
|
53
54
|
- **`token()`** — the environment value, else the bound file value, else `null`.
|
|
54
55
|
- **`require(waitMs = DEFAULT_WAIT_MS)`** — returns a token, starting or joining ONE device sign-in
|
|
55
|
-
per API URL: discover → `requestDeviceAuthorization` → claim/join the lock →
|
|
56
|
-
<url> with code <code>")` → open the browser (owner only) →
|
|
57
|
-
`{tokenEnvKey, apiUrlEnvKey}` → resolve. If `waitMs` runs out first it throws
|
|
58
|
-
(`url`, `code`, `expiresAt` from the lock) and **polling continues in the
|
|
59
|
-
`require()` joins it instead of starting over. `denied`/`expired`/`aborted`
|
|
60
|
-
`OAuthAccessDenied` / `OAuthError`.
|
|
56
|
+
per API URL: discover → `oauthClientHelper.requestDeviceAuthorization` → claim/join the lock →
|
|
57
|
+
`notify("Sign in at <url> with code <code>")` → open the browser (owner only) → `.pollDeviceToken`
|
|
58
|
+
→ persist `{tokenEnvKey, apiUrlEnvKey}` → resolve. If `waitMs` runs out first it throws
|
|
59
|
+
`signInRequired` (`url`, `code`, `expiresAt` from the lock) and **polling continues in the
|
|
60
|
+
background**; the next `require()` joins it instead of starting over. `denied`/`expired`/`aborted`
|
|
61
|
+
become `OAuthAccessDenied` / `OAuthError`.
|
|
61
62
|
- **The `waitMs` ceiling is a timer that is cleared** when the race is decided. A pending timer keeps
|
|
62
63
|
a Node process alive, so an uncleared one made `viable-mcp login` (ceiling 15 minutes) hang after
|
|
63
64
|
it had signed in. Any new timeout in this package clears its timer the same way.
|
|
@@ -74,7 +75,8 @@ file; a CLI that serves several deployments points `OWLMEANS_CREDENTIALS` at one
|
|
|
74
75
|
(next `require()` signs in); an **environment** token is never silently replaced — it throws
|
|
75
76
|
`TokenRejected(tokenEnvKey)` so the operator hears "VIABLE_API_TOKEN was refused" instead of the
|
|
76
77
|
tool quietly becoming another identity.
|
|
77
|
-
- **`signOut()`** — best-effort `revokeToken` at the server, then remove the file
|
|
78
|
+
- **`signOut()`** — best-effort `oauthClientHelper.revokeToken` at the server, then remove the file
|
|
79
|
+
token.
|
|
78
80
|
|
|
79
81
|
## Opening the browser
|
|
80
82
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.d.ts","sourceRoot":"","sources":["../src/consts.local.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAItD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.js","sourceRoot":"","sources":["../src/consts.local.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAA2B;IACzD,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,UAAU;CAClB,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface SetEnvValuesResult {
|
|
2
|
+
/** The file is readable by somebody other than its owner — reported, never silently tightened. */
|
|
3
|
+
insecurePermissions: boolean;
|
|
4
|
+
}
|
|
5
|
+
/** The dotenv-style `~/.owlmeans` credentials file, with the process environment layered over it. */
|
|
6
|
+
export interface EnvFileHelper {
|
|
7
|
+
/**
|
|
8
|
+
* Where the credentials file lives: `OWLMEANS_CREDENTIALS`, or `~/.owlmeans`.
|
|
9
|
+
*
|
|
10
|
+
* A CLI that talks to more than one deployment (a staging environment, a self-hosted instance)
|
|
11
|
+
* points this at a different file per deployment — the file is never merged with another one, and
|
|
12
|
+
* a token it holds is meaningless anywhere but the API URL it was signed in against.
|
|
13
|
+
*/
|
|
14
|
+
resolveEnvFile: (env?: NodeJS.ProcessEnv) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Parse a dotenv-shaped body: `KEY=value`, an optional `export ` prefix, `#` comments, one level
|
|
17
|
+
* of quoting. Deliberately small — a dotenv library would add a dependency for a format this
|
|
18
|
+
* package itself writes, and this is the one shape it ever needs to read back.
|
|
19
|
+
*/
|
|
20
|
+
parseEnv: (content: string) => Record<string, string>;
|
|
21
|
+
/** The credentials file's values alone, with no environment overlay — what a token is bound to. */
|
|
22
|
+
readCredentialsFile: (env?: NodeJS.ProcessEnv) => Promise<Record<string, string>>;
|
|
23
|
+
/**
|
|
24
|
+
* The file, with the process environment layered over it — environment wins, but an environment
|
|
25
|
+
* value that is the EMPTY STRING is treated as unset.
|
|
26
|
+
*
|
|
27
|
+
* The empty-string rule exists because a harness config commonly expands an unset shell variable
|
|
28
|
+
* to `''` (`${VIABLE_API_TOKEN:-}`), and a literal empty override must not shadow a real value the
|
|
29
|
+
* file holds — that would make "I have not set this" indistinguishable from "I am overriding this
|
|
30
|
+
* to nothing", and the file is always the more deliberate of the two.
|
|
31
|
+
*/
|
|
32
|
+
loadOwlmeansEnv: (env?: NodeJS.ProcessEnv) => Promise<Record<string, string>>;
|
|
33
|
+
/**
|
|
34
|
+
* Replace the named keys in the credentials file, keeping every other line — comments, a key this
|
|
35
|
+
* call did not touch, blank lines — exactly where they were. An `undefined` value removes the key.
|
|
36
|
+
*
|
|
37
|
+
* Written atomically (a temp file in the same directory, then a rename) so a process killed
|
|
38
|
+
* mid-write never leaves a half-written credentials file behind, and created with mode `0600`
|
|
39
|
+
* because this file can hold a live access token. An existing file that is readable by anyone but
|
|
40
|
+
* its owner is reported back rather than silently tightened — permissions someone else set on
|
|
41
|
+
* purpose are theirs to change.
|
|
42
|
+
*/
|
|
43
|
+
setEnvValues: (path: string, values: Record<string, string | undefined>) => Promise<SetEnvValuesResult>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/env-file/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,kGAAkG;IAClG,mBAAmB,EAAE,OAAO,CAAA;CAC7B;AAED,qGAAqG;AACrG,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,cAAc,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,KAAK,MAAM,CAAA;IACnD;;;;OAIG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrD,mGAAmG;IACnG,mBAAmB,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACjF;;;;;;;;OAQG;IACH,eAAe,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAC7E;;;;;;;;;OASG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACxG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/env-file/types.ts"],"names":[],"mappings":""}
|
package/build/env-file.d.ts
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* points this at a different file per deployment — the file is never merged with another one, and
|
|
6
|
-
* a token it holds is meaningless anywhere but the API URL it was signed in against.
|
|
7
|
-
*/
|
|
8
|
-
export declare const resolveEnvFile: (env?: NodeJS.ProcessEnv) => string;
|
|
9
|
-
/**
|
|
10
|
-
* Parse a dotenv-shaped body: `KEY=value`, an optional `export ` prefix, `#` comments, one level
|
|
11
|
-
* of quoting. Deliberately small — a dotenv library would add a dependency for a format this
|
|
12
|
-
* package itself writes, and this is the one shape it ever needs to read back.
|
|
13
|
-
*/
|
|
14
|
-
export declare const parseEnv: (content: string) => Record<string, string>;
|
|
15
|
-
/**
|
|
16
|
-
* The credentials file's values alone, with no environment overlay — what a token is bound to.
|
|
17
|
-
*/
|
|
18
|
-
export declare const readCredentialsFile: (env?: NodeJS.ProcessEnv) => Promise<Record<string, string>>;
|
|
19
|
-
/**
|
|
20
|
-
* The file, with the process environment layered over it — environment wins, but an environment
|
|
21
|
-
* value that is the EMPTY STRING is treated as unset.
|
|
22
|
-
*
|
|
23
|
-
* The empty-string rule exists because a harness config commonly expands an unset shell variable
|
|
24
|
-
* to `''` (`${VIABLE_API_TOKEN:-}`), and a literal empty override must not shadow a real value the
|
|
25
|
-
* file holds — that would make "I have not set this" indistinguishable from "I am overriding this
|
|
26
|
-
* to nothing", and the file is always the more deliberate of the two.
|
|
27
|
-
*/
|
|
1
|
+
import type { EnvFileHelper } from './env-file/types.js';
|
|
2
|
+
export declare const createEnvFileHelper: () => EnvFileHelper;
|
|
3
|
+
export declare const envFileHelper: EnvFileHelper;
|
|
4
|
+
/** @deprecated compat:factory-refactor — use `envFileHelper.loadOwlmeansEnv(…)` */
|
|
28
5
|
export declare const loadOwlmeansEnv: (env?: NodeJS.ProcessEnv) => Promise<Record<string, string>>;
|
|
29
|
-
/**
|
|
30
|
-
* Replace the named keys in the credentials file, keeping every other line — comments, a key this
|
|
31
|
-
* call did not touch, blank lines — exactly where they were.
|
|
32
|
-
*
|
|
33
|
-
* Written atomically (a temp file in the same directory, then a rename) so a process killed
|
|
34
|
-
* mid-write never leaves a half-written credentials file behind, and created with mode `0600`
|
|
35
|
-
* because this file can hold a live access token. An existing file that is readable by anyone but
|
|
36
|
-
* its owner is reported back rather than silently tightened — permissions someone else set on
|
|
37
|
-
* purpose are theirs to change.
|
|
38
|
-
*/
|
|
39
|
-
export declare const setEnvValues: (path: string, values: Record<string, string | undefined>) => Promise<{
|
|
40
|
-
insecurePermissions: boolean;
|
|
41
|
-
}>;
|
|
42
6
|
//# sourceMappingURL=env-file.d.ts.map
|
package/build/env-file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../src/env-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../src/env-file.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAsB,MAAM,qBAAqB,CAAA;AAE5E,eAAO,MAAM,mBAAmB,QAAO,aAsFtC,CAAA;AAED,eAAO,MAAM,aAAa,eAAwB,CAAA;AAElD,mFAAmF;AACnF,eAAO,MAAM,eAAe,SAAe,MAAM,CAAC,UAAU,KAAiB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACjE,CAAA"}
|
package/build/env-file.js
CHANGED
|
@@ -3,105 +3,77 @@ import { chmod, mkdir, readFile, rename, stat, writeFile } from 'node:fs/promise
|
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { DEFAULT_CREDENTIALS_FILENAME, ENV_CREDENTIALS_FILE } from './consts.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (line === '' || line.startsWith('#'))
|
|
26
|
-
continue;
|
|
27
|
-
const match = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
|
|
28
|
-
if (match == null)
|
|
29
|
-
continue;
|
|
30
|
-
let value = match[2].trim();
|
|
31
|
-
if ((value.startsWith('"') && value.endsWith('"') && value.length > 1)
|
|
32
|
-
|| (value.startsWith("'") && value.endsWith("'") && value.length > 1)) {
|
|
33
|
-
value = value.slice(1, -1);
|
|
6
|
+
export const createEnvFileHelper = () => {
|
|
7
|
+
const resolveEnvFile = (env = process.env) => env[ENV_CREDENTIALS_FILE] != null && env[ENV_CREDENTIALS_FILE] !== ''
|
|
8
|
+
? env[ENV_CREDENTIALS_FILE]
|
|
9
|
+
: join(homedir(), DEFAULT_CREDENTIALS_FILENAME);
|
|
10
|
+
const parseEnv = (content) => {
|
|
11
|
+
const values = {};
|
|
12
|
+
for (const raw of content.split('\n')) {
|
|
13
|
+
const line = raw.trim();
|
|
14
|
+
if (line === '' || line.startsWith('#'))
|
|
15
|
+
continue;
|
|
16
|
+
const match = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
|
|
17
|
+
if (match == null)
|
|
18
|
+
continue;
|
|
19
|
+
let value = match[2].trim();
|
|
20
|
+
if ((value.startsWith('"') && value.endsWith('"') && value.length > 1)
|
|
21
|
+
|| (value.startsWith("'") && value.endsWith("'") && value.length > 1)) {
|
|
22
|
+
value = value.slice(1, -1);
|
|
23
|
+
}
|
|
24
|
+
values[match[1]] = value;
|
|
34
25
|
}
|
|
35
|
-
values
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}).filter((line) => line != null);
|
|
85
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
86
|
-
if (claimed.has(key) || value == null)
|
|
87
|
-
return;
|
|
88
|
-
rewritten.push(`${key}=${value}`);
|
|
89
|
-
});
|
|
90
|
-
const body = `${rewritten.join('\n').replace(/\n+$/, '')}\n`;
|
|
91
|
-
await mkdir(dirname(path), { recursive: true });
|
|
92
|
-
const tmp = join(dirname(path), `.${DEFAULT_CREDENTIALS_FILENAME}.${randomBytes(6).toString('hex')}.tmp`);
|
|
93
|
-
await writeFile(tmp, body, { mode: 0o600 });
|
|
94
|
-
await rename(tmp, path);
|
|
95
|
-
await chmod(path, 0o600).catch(() => undefined);
|
|
96
|
-
let insecurePermissions = false;
|
|
97
|
-
try {
|
|
98
|
-
const info = await stat(path);
|
|
99
|
-
insecurePermissions = (info.mode & 0o077) !== 0;
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
// Nothing to report if the stat itself fails right after a successful write — unusual enough
|
|
103
|
-
// that guessing at a permission problem would be noise.
|
|
104
|
-
}
|
|
105
|
-
return { insecurePermissions };
|
|
26
|
+
return values;
|
|
27
|
+
};
|
|
28
|
+
const readFileIfPresent = async (path) => await readFile(path, 'utf-8').catch(() => '');
|
|
29
|
+
const readCredentialsFile = async (env = process.env) => parseEnv(await readFileIfPresent(resolveEnvFile(env)));
|
|
30
|
+
const loadOwlmeansEnv = async (env = process.env) => {
|
|
31
|
+
const file = await readCredentialsFile(env);
|
|
32
|
+
const fromEnv = {};
|
|
33
|
+
Object.entries(env).forEach(([key, value]) => {
|
|
34
|
+
if (value != null && value !== '')
|
|
35
|
+
fromEnv[key] = value;
|
|
36
|
+
});
|
|
37
|
+
return { ...file, ...fromEnv };
|
|
38
|
+
};
|
|
39
|
+
const setEnvValues = async (path, values) => {
|
|
40
|
+
const existing = await readFileIfPresent(path);
|
|
41
|
+
const lines = existing === '' ? [] : existing.split('\n');
|
|
42
|
+
const claimed = new Set();
|
|
43
|
+
const rewritten = lines.map(line => {
|
|
44
|
+
const trimmed = line.trim();
|
|
45
|
+
const match = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(trimmed);
|
|
46
|
+
if (match == null || !(match[1] in values))
|
|
47
|
+
return line;
|
|
48
|
+
claimed.add(match[1]);
|
|
49
|
+
const value = values[match[1]];
|
|
50
|
+
return value == null ? null : `${match[1]}=${value}`;
|
|
51
|
+
}).filter((line) => line != null);
|
|
52
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
53
|
+
if (claimed.has(key) || value == null)
|
|
54
|
+
return;
|
|
55
|
+
rewritten.push(`${key}=${value}`);
|
|
56
|
+
});
|
|
57
|
+
const body = `${rewritten.join('\n').replace(/\n+$/, '')}\n`;
|
|
58
|
+
await mkdir(dirname(path), { recursive: true });
|
|
59
|
+
const tmp = join(dirname(path), `.${DEFAULT_CREDENTIALS_FILENAME}.${randomBytes(6).toString('hex')}.tmp`);
|
|
60
|
+
await writeFile(tmp, body, { mode: 0o600 });
|
|
61
|
+
await rename(tmp, path);
|
|
62
|
+
await chmod(path, 0o600).catch(() => undefined);
|
|
63
|
+
let insecurePermissions = false;
|
|
64
|
+
try {
|
|
65
|
+
const info = await stat(path);
|
|
66
|
+
insecurePermissions = (info.mode & 0o077) !== 0;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Nothing to report if the stat itself fails right after a successful write — unusual enough
|
|
70
|
+
// that guessing at a permission problem would be noise.
|
|
71
|
+
}
|
|
72
|
+
return { insecurePermissions };
|
|
73
|
+
};
|
|
74
|
+
return { resolveEnvFile, parseEnv, readCredentialsFile, loadOwlmeansEnv, setEnvValues };
|
|
106
75
|
};
|
|
76
|
+
export const envFileHelper = createEnvFileHelper();
|
|
77
|
+
/** @deprecated compat:factory-refactor — use `envFileHelper.loadOwlmeansEnv(…)` */
|
|
78
|
+
export const loadOwlmeansEnv = async (env = process.env) => await envFileHelper.loadOwlmeansEnv(env);
|
|
107
79
|
//# sourceMappingURL=env-file.js.map
|
package/build/env-file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-file.js","sourceRoot":"","sources":["../src/env-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"env-file.js","sourceRoot":"","sources":["../src/env-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGhF,MAAM,CAAC,MAAM,mBA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,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACzG,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAC3C,MAAM,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACvB,MAAM,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAE/C,IAAI,mBAAmB,GAAG,KAAK,CAAA;QAC/B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAA;YAC7B,mBAAmB,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;QACjD,CAAC;QAAC,MAAM,CAAC;YACP,6FAA6F;YAC7F,wDAAwD;QAC1D,CAAC;QAED,OAAO,EAAE,mBAAmB,EAAE,CAAA;IAChC,CAAC,CAAA;IAED,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,CAAA;AACzF,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,EAAE,CAAA;AAElD,mFAAmF;AACnF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,GAAG,GAAsB,OAAO,CAAC,GAAG,EAAmC,EAAE,CAC7G,MAAM,aAAa,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA"}
|
package/build/holder.d.ts
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/** The API origin this credential set is for, and the OAuth `resource` it is scoped to unless
|
|
3
|
-
* `resource` says otherwise. */
|
|
4
|
-
apiUrl: string;
|
|
5
|
-
/** This CLI's OAuth `client_id` — a static one the authorization server declared, or an https
|
|
6
|
-
* Client ID Metadata Document URL. */
|
|
7
|
-
clientId: string;
|
|
8
|
-
deviceName?: string;
|
|
9
|
-
resource?: string;
|
|
10
|
-
scope?: string;
|
|
11
|
-
/** Which key in `~/.owlmeans` (and the environment) carries the token. */
|
|
12
|
-
tokenEnvKey: string;
|
|
13
|
-
/** Which key records the URL a stored token belongs to. A file naming no URL at all is treated
|
|
14
|
-
* as belonging to whichever `apiUrl` is asked for — only an explicit MISMATCH refuses it. */
|
|
15
|
-
apiUrlEnvKey: string;
|
|
16
|
-
env?: NodeJS.ProcessEnv;
|
|
17
|
-
/** Best-effort progress — "open this URL and enter this code", "signed in", a failure. A host
|
|
18
|
-
* wires this to stderr, an MCP `notifications/message`, or nothing at all. */
|
|
19
|
-
onNotify?: (message: string) => void;
|
|
20
|
-
}
|
|
21
|
-
export interface CliCredentials {
|
|
22
|
-
/** The token this call site should use right now: the environment, then the bound file value,
|
|
23
|
-
* or `null` when neither has one. */
|
|
24
|
-
token: () => Promise<string | null>;
|
|
25
|
-
/** Ensure a usable token exists. Starts or joins a device sign-in when there is none, waits up
|
|
26
|
-
* to `waitMs` for it to be approved, and returns the token. The sign-in keeps running in the
|
|
27
|
-
* background past that wait — a later `require()` call picks up wherever it left off, rather
|
|
28
|
-
* than starting over. */
|
|
29
|
-
require: (waitMs?: number) => Promise<string>;
|
|
30
|
-
/** A 401 happened while presenting `rejectedToken`. A token that came from the FILE is forgotten
|
|
31
|
-
* so the next `require()` signs in again; a token that came from the ENVIRONMENT is reported —
|
|
32
|
-
* silently trying another identity behind an operator's back is worse than failing loudly. */
|
|
33
|
-
invalidate: (rejectedToken: string) => Promise<void>;
|
|
34
|
-
/** Revoke the current token at the server and remove it from the file. */
|
|
35
|
-
signOut: () => Promise<void>;
|
|
36
|
-
}
|
|
1
|
+
import type { CliCredentials, CliCredentialsOptions } from './types.js';
|
|
37
2
|
export declare const makeCliCredentials: (opts: CliCredentialsOptions) => CliCredentials;
|
|
38
3
|
//# sourceMappingURL=holder.d.ts.map
|
package/build/holder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"holder.d.ts","sourceRoot":"","sources":["../src/holder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"holder.d.ts","sourceRoot":"","sources":["../src/holder.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAkB,cAAc,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAmBvF,eAAO,MAAM,kBAAkB,SAAU,qBAAqB,KAAG,cAoJhE,CAAA"}
|
package/build/holder.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { hostname, userInfo } from 'node:os';
|
|
2
|
-
import {
|
|
2
|
+
import { OAuthAccessDenied, OAuthError, OAUTH_DEVICE_NAME_MAX, signInRequired, TokenRejected, oauthClientHelper } from '@owlmeans/oauth';
|
|
3
3
|
import { DEFAULT_WAIT_MS } from './consts.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { envFileHelper } from './env-file.js';
|
|
5
|
+
import { lockPathFor, makeSignInLockHelper } from './lock.js';
|
|
6
6
|
import { openBrowser } from './open-browser.js';
|
|
7
7
|
const defaultDeviceName = () => {
|
|
8
8
|
let who = 'cli';
|
|
@@ -20,13 +20,13 @@ const inFlightByApiUrl = new Map();
|
|
|
20
20
|
export const makeCliCredentials = (opts) => {
|
|
21
21
|
const env = opts.env ?? process.env;
|
|
22
22
|
const notify = (message) => opts.onNotify?.(message);
|
|
23
|
-
const credentialsPath = resolveEnvFile(env);
|
|
24
|
-
const
|
|
23
|
+
const credentialsPath = envFileHelper.resolveEnvFile(env);
|
|
24
|
+
const lock = makeSignInLockHelper(lockPathFor(credentialsPath));
|
|
25
25
|
const token = async () => {
|
|
26
26
|
const envValue = env[opts.tokenEnvKey];
|
|
27
27
|
if (envValue != null && envValue !== '')
|
|
28
28
|
return envValue;
|
|
29
|
-
const file = await readCredentialsFile(env);
|
|
29
|
+
const file = await envFileHelper.readCredentialsFile(env);
|
|
30
30
|
const boundUrl = file[opts.apiUrlEnvKey];
|
|
31
31
|
if (boundUrl != null && boundUrl !== '' && boundUrl !== opts.apiUrl)
|
|
32
32
|
return null;
|
|
@@ -36,11 +36,11 @@ export const makeCliCredentials = (opts) => {
|
|
|
36
36
|
/** Start a fresh device authorization, or adopt another live process's own — either way, claim
|
|
37
37
|
* or join the lock BEFORE requesting one, so the decision and the request agree. */
|
|
38
38
|
const claimJoinOrStart = async (server) => {
|
|
39
|
-
const authorization = await requestDeviceAuthorization(server, {
|
|
39
|
+
const authorization = await oauthClientHelper.requestDeviceAuthorization(server, {
|
|
40
40
|
client_id: opts.clientId, scope: opts.scope, resource: opts.resource ?? opts.apiUrl,
|
|
41
41
|
device_name: opts.deviceName ?? defaultDeviceName(),
|
|
42
42
|
});
|
|
43
|
-
return await claimOrJoinLock(
|
|
43
|
+
return await lock.claimOrJoinLock(opts.apiUrl, {
|
|
44
44
|
verificationUri: authorization.verification_uri,
|
|
45
45
|
verificationUriComplete: authorization.verification_uri_complete,
|
|
46
46
|
userCode: authorization.user_code,
|
|
@@ -60,7 +60,7 @@ export const makeCliCredentials = (opts) => {
|
|
|
60
60
|
if (existing != null)
|
|
61
61
|
return existing;
|
|
62
62
|
const promise = (async () => {
|
|
63
|
-
const server = await discoverAuthorizationServer(opts.apiUrl);
|
|
63
|
+
const server = await oauthClientHelper.discoverAuthorizationServer(opts.apiUrl);
|
|
64
64
|
const claim = await claimJoinOrStart(server);
|
|
65
65
|
notify(claim.info.userCode != null
|
|
66
66
|
? `Sign in at ${claim.info.verificationUri} with code ${claim.info.userCode}`
|
|
@@ -72,12 +72,12 @@ export const makeCliCredentials = (opts) => {
|
|
|
72
72
|
openBrowser(claim.info.verificationUriComplete ?? claim.info.verificationUri);
|
|
73
73
|
}
|
|
74
74
|
try {
|
|
75
|
-
const outcome = await pollDeviceToken(server, {
|
|
75
|
+
const outcome = await oauthClientHelper.pollDeviceToken(server, {
|
|
76
76
|
clientId: opts.clientId, deviceCode: claim.info.deviceCode, interval: claim.info.interval,
|
|
77
77
|
expiresAt: claim.info.expiresAt,
|
|
78
78
|
});
|
|
79
79
|
if (outcome.status === 'authorized') {
|
|
80
|
-
await setEnvValues(credentialsPath, { [opts.tokenEnvKey]: outcome.token, [opts.apiUrlEnvKey]: opts.apiUrl });
|
|
80
|
+
await envFileHelper.setEnvValues(credentialsPath, { [opts.tokenEnvKey]: outcome.token, [opts.apiUrlEnvKey]: opts.apiUrl });
|
|
81
81
|
notify('Signed in.');
|
|
82
82
|
}
|
|
83
83
|
return outcome;
|
|
@@ -85,7 +85,7 @@ export const makeCliCredentials = (opts) => {
|
|
|
85
85
|
finally {
|
|
86
86
|
inFlightByApiUrl.delete(opts.apiUrl);
|
|
87
87
|
if (claim.owner)
|
|
88
|
-
await releaseLock(
|
|
88
|
+
await lock.releaseLock(claim.info.nonce);
|
|
89
89
|
}
|
|
90
90
|
})();
|
|
91
91
|
inFlightByApiUrl.set(opts.apiUrl, promise);
|
|
@@ -111,9 +111,9 @@ export const makeCliCredentials = (opts) => {
|
|
|
111
111
|
}),
|
|
112
112
|
]).finally(() => clearTimeout(ceiling));
|
|
113
113
|
if (!raced.settled) {
|
|
114
|
-
const
|
|
114
|
+
const pending = await lock.readLock();
|
|
115
115
|
throw signInRequired({
|
|
116
|
-
url:
|
|
116
|
+
url: pending?.verificationUri ?? opts.apiUrl, code: pending?.userCode, expiresAt: pending?.expiresAt,
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
switch (raced.outcome.status) {
|
|
@@ -128,9 +128,9 @@ export const makeCliCredentials = (opts) => {
|
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
invalidate: async (rejectedToken) => {
|
|
131
|
-
const file = await readCredentialsFile(env);
|
|
131
|
+
const file = await envFileHelper.readCredentialsFile(env);
|
|
132
132
|
if (file[opts.tokenEnvKey] === rejectedToken) {
|
|
133
|
-
await setEnvValues(credentialsPath, { [opts.tokenEnvKey]: undefined });
|
|
133
|
+
await envFileHelper.setEnvValues(credentialsPath, { [opts.tokenEnvKey]: undefined });
|
|
134
134
|
notify('The stored token was refused. Signing in again.');
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
@@ -142,11 +142,11 @@ export const makeCliCredentials = (opts) => {
|
|
|
142
142
|
const current = await token();
|
|
143
143
|
if (current == null)
|
|
144
144
|
return;
|
|
145
|
-
const server = await discoverAuthorizationServer(opts.apiUrl).catch(() => null);
|
|
145
|
+
const server = await oauthClientHelper.discoverAuthorizationServer(opts.apiUrl).catch(() => null);
|
|
146
146
|
if (server != null) {
|
|
147
|
-
await revokeToken(server, { token: current, clientId: opts.clientId }).catch(() => undefined);
|
|
147
|
+
await oauthClientHelper.revokeToken(server, { token: current, clientId: opts.clientId }).catch(() => undefined);
|
|
148
148
|
}
|
|
149
|
-
await setEnvValues(credentialsPath, { [opts.tokenEnvKey]: undefined });
|
|
149
|
+
await envFileHelper.setEnvValues(credentialsPath, { [opts.tokenEnvKey]: undefined });
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
};
|