@cortexkit/common-auth 0.44.0 → 0.46.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/dist/commands/builtins.d.ts +20 -1
- package/dist/commands/builtins.js +28 -12
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/menu.d.ts +6 -1
- package/dist/commands/menu.js +1 -0
- package/dist/fs/file-read-cache.d.ts +3 -0
- package/dist/fs/file-read-cache.js +9 -5
- package/dist/fs/refresh-file-lock.d.ts +11 -0
- package/dist/fs/refresh-file-lock.js +159 -11
- package/dist/fs/with-lock.d.ts +2 -0
- package/dist/fs/with-lock.js +1 -1
- package/dist/routing-accessor/index.d.ts +17 -0
- package/dist/routing-accessor/index.js +13 -0
- package/dist/settings/define.d.ts +35 -0
- package/dist/settings/define.js +52 -0
- package/dist/settings/descriptors.d.ts +97 -0
- package/dist/settings/descriptors.js +81 -0
- package/dist/settings/edit.d.ts +24 -0
- package/dist/settings/edit.js +229 -0
- package/dist/settings/fs.d.ts +6 -0
- package/dist/settings/fs.js +19 -0
- package/dist/settings/handle.d.ts +30 -0
- package/dist/settings/handle.js +228 -0
- package/dist/settings/index.d.ts +10 -0
- package/dist/settings/index.js +7 -0
- package/dist/settings/lock-errors.d.ts +2 -0
- package/dist/settings/lock-errors.js +15 -0
- package/dist/settings/move.d.ts +76 -0
- package/dist/settings/move.js +351 -0
- package/dist/settings/parse.d.ts +24 -0
- package/dist/settings/parse.js +65 -0
- package/dist/settings/paths.d.ts +12 -0
- package/dist/settings/paths.js +48 -0
- package/dist/settings/refusal.d.ts +7 -0
- package/dist/settings/refusal.js +15 -0
- package/dist/settings/resolve.d.ts +15 -0
- package/dist/settings/resolve.js +51 -0
- package/dist/settings/schema.d.ts +29 -0
- package/dist/settings/schema.js +81 -0
- package/dist/settings/snapshot.d.ts +24 -0
- package/dist/settings/snapshot.js +150 -0
- package/dist/settings/update.d.ts +6 -0
- package/dist/settings/update.js +139 -0
- package/dist/settings/write.d.ts +26 -0
- package/dist/settings/write.js +88 -0
- package/dist/setup/command-error.d.ts +1 -1
- package/dist/setup/command-error.js +3 -2
- package/dist/setup/command.js +5 -1
- package/dist/setup/enroll.js +3 -3
- package/dist/setup/enrollment-access.d.ts +1 -1
- package/dist/setup/enrollment-access.js +13 -4
- package/dist/setup/types.d.ts +4 -0
- package/dist/tui-prefs/watcher.d.ts +3 -1
- package/dist/tui-prefs/watcher.js +41 -18
- package/package.json +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Stats, watch } from 'node:fs';
|
|
2
2
|
import { PrivateFileError } from '../fs/private-files.js';
|
|
3
|
-
type Metadata = Pick<Stats, 'mtimeMs' | 'size' | 'ino' | 'dev'
|
|
3
|
+
type Metadata = Pick<Stats, 'mtimeMs' | 'size' | 'ino' | 'dev'> & Partial<Pick<Stats, 'ctimeMs'>>;
|
|
4
4
|
export interface TuiPreferencesWatchOptions {
|
|
5
5
|
/** Receives PrivateFileError instances for Windows access failures, never file contents. */
|
|
6
6
|
onError?: (error: PrivateFileError) => void;
|
|
@@ -22,4 +22,6 @@ export interface TuiPreferencesWatchOptions {
|
|
|
22
22
|
* disposable. The last unsubscribe stops both the native watcher and the poll.
|
|
23
23
|
*/
|
|
24
24
|
export declare function watchTuiPreferences(file: string, onChange: () => void, options?: TuiPreferencesWatchOptions): () => void;
|
|
25
|
+
/** @internal Settings use ordinary reads and observe removal of the user path. */
|
|
26
|
+
export declare function watchSettings(file: string, onChange: () => void, options?: TuiPreferencesWatchOptions): () => void;
|
|
25
27
|
export {};
|
|
@@ -18,8 +18,11 @@ function canonicalPath(file) {
|
|
|
18
18
|
return parent === path ? path : join(canonicalPath(parent), basename(path));
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
function identity(info) {
|
|
22
|
-
|
|
21
|
+
function identity(info, settings) {
|
|
22
|
+
if (!info)
|
|
23
|
+
return null;
|
|
24
|
+
const value = `${info.dev}:${info.ino}:${info.mtimeMs}:${info.size}`;
|
|
25
|
+
return settings ? `${value}:${info.ctimeMs}` : value;
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Share one directory watcher and metadata poll per canonical path, including
|
|
@@ -30,16 +33,25 @@ function identity(info) {
|
|
|
30
33
|
* disposable. The last unsubscribe stops both the native watcher and the poll.
|
|
31
34
|
*/
|
|
32
35
|
export function watchTuiPreferences(file, onChange, options = {}) {
|
|
36
|
+
return watchFile(file, onChange, options, false);
|
|
37
|
+
}
|
|
38
|
+
/** @internal Settings use ordinary reads and observe removal of the user path. */
|
|
39
|
+
export function watchSettings(file, onChange, options = {}) {
|
|
40
|
+
return watchFile(file, onChange, options, true);
|
|
41
|
+
}
|
|
42
|
+
function watchFile(file, onChange, options, settings) {
|
|
33
43
|
const globals = globalThis;
|
|
34
|
-
const key = Symbol.for(
|
|
44
|
+
const key = Symbol.for(settings
|
|
45
|
+
? 'cortexkit.common-auth.settings.watchers.v1'
|
|
46
|
+
: 'cortexkit.common-auth.tui-prefs.watchers.v1');
|
|
35
47
|
const registry = globals[key] ?? new Map();
|
|
36
48
|
globals[key] = registry;
|
|
37
|
-
const path = canonicalPath(file);
|
|
49
|
+
const path = settings ? resolve(file) : canonicalPath(file);
|
|
38
50
|
const shared = registry.get(path);
|
|
39
51
|
if (shared)
|
|
40
52
|
return shared.subscribe(onChange);
|
|
41
53
|
const name = basename(path);
|
|
42
|
-
const read = windowsPrivateFiles
|
|
54
|
+
const read = windowsPrivateFiles && !settings
|
|
43
55
|
? (file) => readPrivateText(file)
|
|
44
56
|
: (options.fs?.readFile ?? ((file) => readFile(file, 'utf8')));
|
|
45
57
|
const probe = options.fs?.stat ?? stat;
|
|
@@ -50,9 +62,9 @@ export function watchTuiPreferences(file, onChange, options = {}) {
|
|
|
50
62
|
// Seed synchronously so an immediate write cannot be absorbed as the baseline.
|
|
51
63
|
// The metadata is recorded only together with contents that were read, as in
|
|
52
64
|
// the probe below: if the first read fails, the probe keeps trying.
|
|
53
|
-
if (!windowsPrivateFiles)
|
|
65
|
+
if (settings || !windowsPrivateFiles)
|
|
54
66
|
try {
|
|
55
|
-
const metadata = identity((options.fs?.statSync ?? statSync)(path));
|
|
67
|
+
const metadata = identity((options.fs?.statSync ?? statSync)(path), settings);
|
|
56
68
|
lastSeen = (options.fs?.readFileSync ?? ((file) => readFileSync(file, 'utf8')))(path);
|
|
57
69
|
lastMetadata = metadata;
|
|
58
70
|
}
|
|
@@ -61,19 +73,39 @@ export function watchTuiPreferences(file, onChange, options = {}) {
|
|
|
61
73
|
}
|
|
62
74
|
let disposed = false;
|
|
63
75
|
const subscribers = new Set();
|
|
76
|
+
const notifySubscribers = () => {
|
|
77
|
+
for (const subscriber of [...subscribers]) {
|
|
78
|
+
if (!subscribers.has(subscriber))
|
|
79
|
+
continue;
|
|
80
|
+
try {
|
|
81
|
+
subscriber.notify();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// A broken subscriber must not prevent the others from observing a change.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
64
88
|
let checking = Promise.resolve();
|
|
65
89
|
const checkForChange = (native) => {
|
|
66
90
|
// Serialize native and poll checks so an older read cannot roll back state.
|
|
67
91
|
checking = checking.then(async () => {
|
|
68
92
|
if (disposed)
|
|
69
93
|
return;
|
|
70
|
-
const metadata = identity(await probe(path).catch(() => null));
|
|
94
|
+
const metadata = identity(await probe(path).catch(() => null), settings);
|
|
95
|
+
if (disposed)
|
|
96
|
+
return;
|
|
71
97
|
if (!native && metadata === lastMetadata)
|
|
72
98
|
return;
|
|
73
99
|
// A missing file has nothing to read; remember that so the probe stays
|
|
74
100
|
// quiet until it reappears.
|
|
75
101
|
if (metadata === null) {
|
|
102
|
+
const disappeared = lastMetadata !== null;
|
|
76
103
|
lastMetadata = null;
|
|
104
|
+
if (settings && disappeared) {
|
|
105
|
+
// Dropping the bytes makes recreation observable even with the old text.
|
|
106
|
+
lastSeen = null;
|
|
107
|
+
notifySubscribers();
|
|
108
|
+
}
|
|
77
109
|
return;
|
|
78
110
|
}
|
|
79
111
|
const text = await read(path).catch((error) => {
|
|
@@ -96,16 +128,7 @@ export function watchTuiPreferences(file, onChange, options = {}) {
|
|
|
96
128
|
if (text === lastSeen)
|
|
97
129
|
return;
|
|
98
130
|
lastSeen = text;
|
|
99
|
-
|
|
100
|
-
if (!subscribers.has(subscriber))
|
|
101
|
-
continue;
|
|
102
|
-
try {
|
|
103
|
-
subscriber.notify();
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
// A broken subscriber must not prevent the others from observing a change.
|
|
107
|
-
}
|
|
108
|
-
}
|
|
131
|
+
notifySubscribers();
|
|
109
132
|
});
|
|
110
133
|
return checking;
|
|
111
134
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/common-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,6 +48,10 @@
|
|
|
48
48
|
"types": "./dist/tui-prefs/index.d.ts",
|
|
49
49
|
"import": "./dist/tui-prefs/index.js"
|
|
50
50
|
},
|
|
51
|
+
"./settings": {
|
|
52
|
+
"types": "./dist/settings/index.d.ts",
|
|
53
|
+
"import": "./dist/settings/index.js"
|
|
54
|
+
},
|
|
51
55
|
"./tui-build": {
|
|
52
56
|
"types": "./dist/tui-build/index.d.ts",
|
|
53
57
|
"import": "./dist/tui-build/index.js"
|