@cortexkit/anthropic-auth-core 2.11.4 → 2.12.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/index.js +1341 -767
- package/dist/internal-types/fs/canonical-file-path.d.ts +17 -0
- package/dist/internal-types/fs/index.d.ts +1 -0
- package/dist/internal-types/settings/edit.d.ts +1 -0
- package/dist/internal-types/settings/handle.d.ts +2 -1
- package/dist/internal-types/settings/index.d.ts +1 -0
- package/dist/internal-types/settings/update.d.ts +14 -0
- package/dist/native-runtime-settings.d.ts +16 -5
- package/dist/native-settings-write.d.ts +4 -16
- package/dist/settings-definition.d.ts +11 -0
- package/dist/settings-host-import.d.ts +18 -4
- package/dist/settings-mode.d.ts +22 -0
- package/dist/settings-move-run.d.ts +60 -1
- package/dist/settings-move-sources.d.ts +15 -6
- package/dist/settings-protection-copy.d.ts +7 -1
- package/dist/settings-service.d.ts +64 -37
- package/dist/settings-start.d.ts +46 -6
- package/package.json +2 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as syncFs from 'node:fs';
|
|
2
|
+
import type * as fs from 'node:fs/promises';
|
|
3
|
+
type FilePathFs = Pick<typeof fs, 'lstat' | 'readlink' | 'realpath'>;
|
|
4
|
+
type FilePathSyncFs = Pick<typeof syncFs, 'lstatSync' | 'readlinkSync' | 'realpathSync'>;
|
|
5
|
+
/**
|
|
6
|
+
* Canonical path of a file that other processes may replace by write-and-rename.
|
|
7
|
+
*
|
|
8
|
+
* On Linux, Bun's realpath on such a file can answer "<file> (deleted)" (Bun
|
|
9
|
+
* 1.3) or ENOENT (Bun 1.4) during the rename. So this resolves the folder with
|
|
10
|
+
* realpath and appends the name, then follows a file symlink one readlink hop at
|
|
11
|
+
* a time, at most 40 hops. A missing file resolves to its would-be path; a
|
|
12
|
+
* dangling link or a loop throws. Pass `node:fs/promises` (or a test double).
|
|
13
|
+
*/
|
|
14
|
+
export declare function canonicalFilePath(file: string, fs: FilePathFs): Promise<string>;
|
|
15
|
+
/** Synchronous counterpart of canonicalFilePath; pass `node:fs`. */
|
|
16
|
+
export declare function canonicalFilePathSync(file: string, fs: FilePathSyncFs): string;
|
|
17
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { AtomicWriteOptions } from './atomic-write.js';
|
|
2
2
|
export { writeJsonAtomic } from './atomic-write.js';
|
|
3
|
+
export { canonicalFilePath, canonicalFilePathSync, } from './canonical-file-path.js';
|
|
3
4
|
export { WRITER_LOCK_CONSTANTS } from './lock-constants.js';
|
|
4
5
|
export type { PrivateWriteOutcome } from './private-files.js';
|
|
5
6
|
export { PrivateFileError } from './private-files.js';
|
|
@@ -4,6 +4,7 @@ import { type ValueOf } from './descriptors.js';
|
|
|
4
4
|
import type { SettingsEdit, UpdateResult } from './edit.js';
|
|
5
5
|
import { type GetOptions } from './resolve.js';
|
|
6
6
|
import { type ReportEntry } from './snapshot.js';
|
|
7
|
+
import { type SettingsUpdatePlan } from './update.js';
|
|
7
8
|
export interface LegacyProjectSource {
|
|
8
9
|
readonly path: string;
|
|
9
10
|
read(text: string): unknown;
|
|
@@ -22,7 +23,7 @@ export interface SettingsHandle<S extends Readonly<Record<string, SettingDeclara
|
|
|
22
23
|
}): Promise<void>;
|
|
23
24
|
get<K extends keyof S & string>(name: K, options: GetOptions): Promise<ValueOf<S[K]['value']>>;
|
|
24
25
|
report(): ReportEntry[];
|
|
25
|
-
update(edits: readonly SettingsEdit[], options: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
|
26
|
+
update(edits: readonly SettingsEdit[] | SettingsUpdatePlan, options: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
|
26
27
|
watch(onChange: () => void): () => void;
|
|
27
28
|
}
|
|
28
29
|
/** Internal test hook; not part of the settings package exports. */
|
|
@@ -8,3 +8,4 @@ export { SETTINGS_REFUSAL_CODES, SettingsRefusal, type SettingsRefusalCode, } fr
|
|
|
8
8
|
export type { GetOptions } from './resolve.js';
|
|
9
9
|
export { settingsJsonSchema } from './schema.js';
|
|
10
10
|
export type { ReportEntry, ReportReason } from './snapshot.js';
|
|
11
|
+
export type { SettingsCurrent, SettingsUpdatePlan } from './update.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SettingsDefinition } from './define.js';
|
|
2
|
+
import { type SettingsEdit, type UpdateResult } from './edit.js';
|
|
3
|
+
import type { OpenSettingsOptions } from './handle.js';
|
|
4
|
+
import type { GetOptions } from './resolve.js';
|
|
5
|
+
export type SettingsCurrent = {
|
|
6
|
+
readonly status: 'missing';
|
|
7
|
+
} | {
|
|
8
|
+
readonly status: 'ready';
|
|
9
|
+
readonly document: Readonly<Record<string, unknown>>;
|
|
10
|
+
};
|
|
11
|
+
/** Compute edits synchronously from an immutable copy read under the write lock. */
|
|
12
|
+
export type SettingsUpdatePlan = (current: SettingsCurrent) => readonly SettingsEdit[];
|
|
13
|
+
/** Lock the canonical user file so symlink aliases serialize the same edits. */
|
|
14
|
+
export declare function updateSettings(definition: SettingsDefinition, options: OpenSettingsOptions, edits: readonly SettingsEdit[] | SettingsUpdatePlan, context: Pick<GetOptions, 'host' | 'model'>): Promise<UpdateResult>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { SettingsEdit } from "./internal-types/settings/index.js";
|
|
2
1
|
import type { AccountStorage } from './accounts.ts';
|
|
3
2
|
import { type SettingsKey } from './settings-definition.ts';
|
|
4
3
|
import { type SettingsMode, type SettingsModeOptions } from './settings-mode.ts';
|
|
5
4
|
import type { SettingsHost } from './settings-paths.ts';
|
|
6
|
-
import type
|
|
7
|
-
import type { SettingsProtectionFallback } from './settings-start.ts';
|
|
5
|
+
import { type SettingsFileStatus, type SettingsService, type SettingsUpdate, type SettingsValues } from './settings-service.ts';
|
|
6
|
+
import type { SettingsProtectionFallback, SettingsReopen } from './settings-start.ts';
|
|
8
7
|
export interface NativeRuntimeSettingsOptions {
|
|
9
8
|
settingsService?: SettingsService;
|
|
10
9
|
/** Return the cached settings mode; this callback must not read the filesystem. */
|
|
@@ -26,7 +25,7 @@ export interface NativeRuntimeSettingsOptions {
|
|
|
26
25
|
* authority timer and menu actions open it again off the request path, so a
|
|
27
26
|
* move another host publishes later is still noticed.
|
|
28
27
|
*/
|
|
29
|
-
settingsReopen?:
|
|
28
|
+
settingsReopen?: SettingsReopen;
|
|
30
29
|
}
|
|
31
30
|
export interface NativeRuntimeSettingsStatus {
|
|
32
31
|
file: SettingsFileStatus;
|
|
@@ -55,6 +54,18 @@ export declare function createNativeRuntimeSettings(options: NativeRuntimeSettin
|
|
|
55
54
|
prepareAction(): Promise<void>;
|
|
56
55
|
/** The settings file while the protection fallback is in use, else undefined. */
|
|
57
56
|
fallbackFile: () => string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* The settings file while it is open but this host does not use it yet
|
|
59
|
+
* (its import check has not passed), else undefined.
|
|
60
|
+
*/
|
|
61
|
+
checkingFile: () => string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Why a menu write is refused while `checkingFile` is set. A file that
|
|
64
|
+
* can't be used stays held until the user fixes it, so the text names its
|
|
65
|
+
* problem; any other hold (the check running, a busy lock, an unreadable
|
|
66
|
+
* legacy store) clears by itself.
|
|
67
|
+
*/
|
|
68
|
+
checkingRefusal(): string;
|
|
58
69
|
/**
|
|
59
70
|
* Called under the legacy store's locks by a write that chose the legacy
|
|
60
71
|
* store: true when the user file became authoritative meanwhile (a move
|
|
@@ -67,6 +78,6 @@ export declare function createNativeRuntimeSettings(options: NativeRuntimeSettin
|
|
|
67
78
|
/** Recheck authority on the menu path before choosing a write target. */
|
|
68
79
|
prepareWrite(): Promise<SettingsService | undefined>;
|
|
69
80
|
legacyWriteCommitted(source: string, stored: Record<string, unknown>): Promise<void>;
|
|
70
|
-
update(edits:
|
|
81
|
+
update(edits: SettingsUpdate, before: Record<string, unknown>): Promise<void>;
|
|
71
82
|
close: () => Promise<void>;
|
|
72
83
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SettingsEdit } from "./internal-types/settings/index.js";
|
|
2
2
|
import type { SettingsHost } from './settings-paths.ts';
|
|
3
|
-
import { type SettingsGeneration, type SettingsValues } from './settings-service.ts';
|
|
3
|
+
import { type SettingsGeneration, type SettingsUpdatePlan, type SettingsValues } from './settings-service.ts';
|
|
4
4
|
type Settings = Record<string, unknown>;
|
|
5
5
|
interface StoreChange {
|
|
6
6
|
path: string[];
|
|
@@ -11,16 +11,7 @@ export declare function planNativeSettingsWrite(before: Settings, after: Setting
|
|
|
11
11
|
edits: SettingsEdit[];
|
|
12
12
|
storeChanges: StoreChange[];
|
|
13
13
|
refusal: string | undefined;
|
|
14
|
-
|
|
15
|
-
* What a floor-list edit was planned from: the file text, or a missing
|
|
16
|
-
* file. The write is refused as busy if the file is no longer that.
|
|
17
|
-
*/
|
|
18
|
-
floorsFrom: {
|
|
19
|
-
status: 'missing';
|
|
20
|
-
} | {
|
|
21
|
-
status: 'ready';
|
|
22
|
-
source: string;
|
|
23
|
-
} | undefined;
|
|
14
|
+
update: SettingsUpdatePlan | undefined;
|
|
24
15
|
};
|
|
25
16
|
/**
|
|
26
17
|
* The acting host's floor-list edit, as a pure function of the file it
|
|
@@ -29,11 +20,8 @@ export declare function planNativeSettingsWrite(before: Settings, after: Setting
|
|
|
29
20
|
* accounts change; a `both` entry for such an account is split first so the
|
|
30
21
|
* other host keeps its floor. Returns undefined when the list is unchanged.
|
|
31
22
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* since (see `SettingsUpdateOptions.expectedSource`); that leaves a small
|
|
35
|
-
* window before the lock. common-auth 0.49's planned update will pass this
|
|
36
|
-
* function the document read under the lock, closing it.
|
|
23
|
+
* The caller passes the document read under the settings writer lock, so
|
|
24
|
+
* concurrent writers retain each other's entries.
|
|
37
25
|
*/
|
|
38
26
|
export declare function planSettingsAccountFloors(current: {
|
|
39
27
|
status: 'missing';
|
|
@@ -596,6 +596,17 @@ export declare function malformedSettingsText(file: string): string;
|
|
|
596
596
|
export declare function refusedSettingsWriteText(key: SettingsKey, file: string): string;
|
|
597
597
|
export declare function refusedSettingsRecreationText(file: string): string;
|
|
598
598
|
export declare function invalidSettingsWriteText(key: SettingsKey, file: string): string;
|
|
599
|
+
/**
|
|
600
|
+
* A menu write while this host still checks the settings file against its
|
|
601
|
+
* legacy settings before using it: neither source can take the write yet.
|
|
602
|
+
*/
|
|
603
|
+
export declare function settingsCheckPendingText(file?: string): string;
|
|
604
|
+
/**
|
|
605
|
+
* A menu write while this host can't use the settings file until the user
|
|
606
|
+
* fixes it. `problem` says what is wrong in plain words, such as "is empty";
|
|
607
|
+
* it never quotes a value from the file.
|
|
608
|
+
*/
|
|
609
|
+
export declare function settingsFileUnusableText(problem: string, file?: string): string;
|
|
599
610
|
/** Only fixed, local text is shown; dependency errors can contain file contents. */
|
|
600
611
|
export declare const SETTINGS_WRITE_FAILURES: {
|
|
601
612
|
readonly 'settings-unparseable': {
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import type { SettingsHost } from './settings-paths.ts';
|
|
2
2
|
import { SETTINGS_PROTECTION_KEYS, type SettingsFileLevels, type SettingsLevelEdit, type SettingsProtectionValues } from './settings-service.ts';
|
|
3
3
|
type ProtectionKey = (typeof SETTINGS_PROTECTION_KEYS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* The killswitch's default floors. They hold accounts back only while the
|
|
6
|
+
* killswitch is on, so a host whose legacy killswitch was off contributes
|
|
7
|
+
* none of them.
|
|
8
|
+
*/
|
|
9
|
+
export declare const KILLSWITCH_FLOOR_KEYS: ReadonlySet<string>;
|
|
10
|
+
/**
|
|
11
|
+
* True when `legacy` protects more than `file` for one scalar protection key.
|
|
12
|
+
* Both sides are effective values: an unset legacy key counts as the value
|
|
13
|
+
* its legacy reader returns (the killswitch floors 5/10/0, `default` for the
|
|
14
|
+
* unknown-quota policy, `15m` for the same-account wait), never as absent.
|
|
15
|
+
*/
|
|
16
|
+
export declare function settingsProtectionStricter(key: ProtectionKey, legacy: unknown, file: unknown): boolean;
|
|
4
17
|
/**
|
|
5
18
|
* The import a host owes the settings file when its legacy store was never
|
|
6
19
|
* imported: for each protection key the file sets for this host no value of
|
|
7
20
|
* its own (fill-only), the host's legacy value where it protects more than
|
|
8
|
-
* what the host now resolves from the file.
|
|
21
|
+
* what the host now resolves from the file. Killswitch floors count only
|
|
22
|
+
* when the host's legacy killswitch was on. A pure function of the host's
|
|
9
23
|
* legacy set, its resolved set and the file's explicit levels.
|
|
10
24
|
*
|
|
11
25
|
* `edits` writes those values at the host's own level; account floors need
|
|
12
|
-
* no level, since each list entry names its host.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
26
|
+
* no level, since each list entry names its host. The caller verifies that
|
|
27
|
+
* the validated protection fields still match the document under the lock
|
|
28
|
+
* before returning these edits from its writer plan.
|
|
15
29
|
*/
|
|
16
30
|
export declare function planSettingsHostImport(input: {
|
|
17
31
|
host: SettingsHost;
|
package/dist/settings-mode.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type OwnerOnlyOptions } from './owner-only.ts';
|
|
2
2
|
import { type PathResolutionOptions } from './path-options.ts';
|
|
3
3
|
import type { SettingsHost, SettingsPaths } from './settings-paths.ts';
|
|
4
|
+
import type { SettingsService } from './settings-service.ts';
|
|
4
5
|
export type SettingsMode = 'separate' | 'user-file' | 'legacy';
|
|
5
6
|
/** Injectable filesystem operations for authority checks and marker publication. */
|
|
6
7
|
export interface SettingsModeFs {
|
|
@@ -34,3 +35,24 @@ export declare function hasSettingsImportRecord(target: string, host: SettingsHo
|
|
|
34
35
|
export declare function writeSettingsImportRecord(target: string, host: SettingsHost, options?: SettingsModeOptions): Promise<void>;
|
|
35
36
|
/** Startup/menu/watch/timer work only: request readers consume the cached mode. */
|
|
36
37
|
export declare function resolveSettingsMode(paths: Pick<SettingsPaths, 'target' | 'separate'>, options?: SettingsModeOptions): Promise<SettingsMode>;
|
|
38
|
+
/**
|
|
39
|
+
* Decides, off the request path, whether a running host may start using the
|
|
40
|
+
* settings file through `service` (its own handle on that file). It runs the
|
|
41
|
+
* host's import check, and returns false to keep the host's current
|
|
42
|
+
* authority and ask again at the next check. 'pending' lets the host use a
|
|
43
|
+
* missing file, whose protection comes from the host's own recovery, but
|
|
44
|
+
* the host must pass the check again before it uses a file that appears.
|
|
45
|
+
*/
|
|
46
|
+
export type SettingsAdoptionCheck = (service: SettingsService) => Promise<boolean | 'pending'>;
|
|
47
|
+
/** Attach the check a runtime must pass before adopting the file `service` reads. */
|
|
48
|
+
export declare function setSettingsAdoptionCheck(service: object, check: SettingsAdoptionCheck): void;
|
|
49
|
+
/** The check attached to `service`, if any; read it before retaining the handle. */
|
|
50
|
+
export declare function getSettingsAdoptionCheck(service: object | undefined): SettingsAdoptionCheck | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Record that the host uses `service`'s missing file without having imported
|
|
53
|
+
* its legacy store, so its runtime runs the import check before it uses a
|
|
54
|
+
* file that appears.
|
|
55
|
+
*/
|
|
56
|
+
export declare function markSettingsImportPending(service: object): void;
|
|
57
|
+
/** Whether `service` was marked; read it before retaining the handle. */
|
|
58
|
+
export declare function isSettingsImportPending(service: object | undefined): boolean;
|
|
@@ -3,6 +3,7 @@ import { type SettingsMode, type SettingsModeOptions } from './settings-mode.ts'
|
|
|
3
3
|
import { type SettingsMoveFenceOptions } from './settings-move-fence.ts';
|
|
4
4
|
import { prepareSettingsMoveSources, type SettingsMoveSourcesOptions } from './settings-move-sources.ts';
|
|
5
5
|
import { type SettingsPaths } from './settings-paths.ts';
|
|
6
|
+
import { type SettingsService } from './settings-service.ts';
|
|
6
7
|
export interface SettingsMoveStartupOptions extends SettingsMoveSourcesOptions {
|
|
7
8
|
fence: Pick<SettingsMoveFenceOptions, 'registration' | 'floor' | 'self' | 'liveness' | 'artifacts' | 'readHolders'>;
|
|
8
9
|
authority?: Pick<SettingsModeOptions, 'fs' | 'ownership' | 'now'>;
|
|
@@ -18,9 +19,67 @@ export interface SettingsMoveStartupResult {
|
|
|
18
19
|
mayOpenService: boolean;
|
|
19
20
|
outcome: MoveOutcome | 'marker-present' | 'source-unavailable'
|
|
20
21
|
/** The file is in charge, but this host's legacy store protects more. */
|
|
21
|
-
| 'import-refused'
|
|
22
|
+
| 'import-refused'
|
|
23
|
+
/**
|
|
24
|
+
* The file is in charge, but this host's legacy store could not be read
|
|
25
|
+
* to check it. The host stays legacy, and its runtime checks again.
|
|
26
|
+
*/
|
|
27
|
+
| 'import-unknown'
|
|
28
|
+
/**
|
|
29
|
+
* The file is in charge, but this host's legacy store was never imported
|
|
30
|
+
* and the file can't be checked against it yet: it is empty, unparseable,
|
|
31
|
+
* unreadable, or holds an invalid protection value. The host stays
|
|
32
|
+
* legacy, and its runtime runs the import check again.
|
|
33
|
+
*/
|
|
34
|
+
| 'import-pending';
|
|
22
35
|
move?: MoveResult;
|
|
36
|
+
/**
|
|
37
|
+
* In user-file mode: the file is missing and this host's legacy store was
|
|
38
|
+
* never imported. The host uses the file (its protection comes from this
|
|
39
|
+
* host's own recovery while it is missing), but its runtime must pass the
|
|
40
|
+
* import check before it uses a file that appears.
|
|
41
|
+
*/
|
|
42
|
+
importPending?: boolean;
|
|
23
43
|
}
|
|
44
|
+
/** What a host's import check decided about using the settings file. */
|
|
45
|
+
export type SettingsHostImportOutcome =
|
|
46
|
+
/** The file holds this host's legacy protection. */
|
|
47
|
+
'adopt'
|
|
48
|
+
/**
|
|
49
|
+
* The file is missing and this host's legacy store was never imported. The
|
|
50
|
+
* host may use the file's service now: while the file is missing, its
|
|
51
|
+
* protection comes from this host's applied copy or legacy store, and its
|
|
52
|
+
* own menu write recreates the file carrying that set. Once a file appears
|
|
53
|
+
* again, the host must pass this check before it uses that file's values.
|
|
54
|
+
*/
|
|
55
|
+
| 'pending'
|
|
56
|
+
/**
|
|
57
|
+
* The file exists but can't be checked yet: it is empty, unparseable,
|
|
58
|
+
* unreadable, or holds an invalid protection value. Its protection would
|
|
59
|
+
* replace this host's legacy set as soon as it became usable, so the host
|
|
60
|
+
* keeps its legacy settings and runs the check again later.
|
|
61
|
+
*/
|
|
62
|
+
| 'retry'
|
|
63
|
+
/** Writing the stricter legacy values failed or raced a protection change. */
|
|
64
|
+
| 'refused'
|
|
65
|
+
/** This host's legacy store could not be read, so its protection is unknown. */
|
|
66
|
+
| 'unknown';
|
|
67
|
+
/**
|
|
68
|
+
* The one check a host passes before it starts using a settings file it did
|
|
69
|
+
* not move itself, at startup and when a running legacy host notices the
|
|
70
|
+
* file later. A move under an explicit target imports only the mover's
|
|
71
|
+
* store, and a hand-made file imports none, so the host's legacy store may
|
|
72
|
+
* protect more than the file. For each protection key the file sets no value
|
|
73
|
+
* for this host, a stricter legacy value is written at the host's level
|
|
74
|
+
* first; then the host's import record is written.
|
|
75
|
+
*
|
|
76
|
+
* Never call it on the request path: it reads the legacy store and may write
|
|
77
|
+
* the file. `retry` ends the warnings and says when the check runs again.
|
|
78
|
+
*/
|
|
79
|
+
export declare function importSettingsHostStore(options: SettingsMoveSourcesOptions & {
|
|
80
|
+
paths: SettingsPaths;
|
|
81
|
+
authority?: SettingsMoveStartupOptions['authority'];
|
|
82
|
+
}, service: SettingsService, warn: (message: string) => void, retry: string): Promise<SettingsHostImportOutcome>;
|
|
24
83
|
/**
|
|
25
84
|
* Await once at host startup, before opening the settings service's first resolve.
|
|
26
85
|
* Menu, watch and timer authority checks must not call the mover or retry a failed
|
|
@@ -32,12 +32,21 @@ export type SettingsMoveSourcesResult = {
|
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
34
|
* Read the other host's legacy protection for recreating a missing settings
|
|
35
|
-
* file
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
35
|
+
* file, from the store a default-target move would read for it: its default
|
|
36
|
+
* store, through its current custody and state layout, without seeding a
|
|
37
|
+
* vault, taking locks or writing anything. Under the default target, a local
|
|
38
|
+
* store that doesn't exist returns undefined: that host never ran here and
|
|
39
|
+
* has no set to keep.
|
|
40
|
+
*
|
|
41
|
+
* Anything else that can't name or read the peer's set throws, so the
|
|
42
|
+
* caller treats it as unknown and never as "no set":
|
|
43
|
+
* - a store that exists but can't be read, including an unreadable custody
|
|
44
|
+
* or layout, and vault settings that were never seeded;
|
|
45
|
+
* - a private XDG_CONFIG_HOME, for which a move reads only its own store;
|
|
46
|
+
* - the peer's own path overrides set in this process, since the peer may
|
|
47
|
+
* run with them or without them;
|
|
48
|
+
* - under an explicit target, a default store that doesn't exist: a peer
|
|
49
|
+
* sharing that file may keep a private store this process can't see.
|
|
41
50
|
*/
|
|
42
51
|
export declare function readPeerLegacySettingsProtection(options: SettingsPathOptions & {
|
|
43
52
|
host: SettingsHost;
|
|
@@ -6,7 +6,13 @@ export interface SettingsProtectionCopyEntry {
|
|
|
6
6
|
readAt: number;
|
|
7
7
|
values: SettingsProtectionValues;
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* This host's complete set from the applied copy. A copy file that doesn't
|
|
11
|
+
* exist, or one without an entry for this host, returns undefined: there is
|
|
12
|
+
* no saved set. A copy that exists but can't be read, isn't valid JSON, or
|
|
13
|
+
* holds an invalid entry for this host throws instead, so callers can tell an
|
|
14
|
+
* unknown set from an absent one. Never returns a partial protection set.
|
|
15
|
+
*/
|
|
10
16
|
export declare function readSettingsProtectionCopy(file: string, host: SettingsHost): Promise<SettingsProtectionValues | undefined>;
|
|
11
17
|
/** Merge only the writer's host while holding the copy's cross-process lock. */
|
|
12
18
|
export declare function writeSettingsProtectionCopy(file: string, host: SettingsHost, entry: SettingsProtectionCopyEntry, lockTimeoutMs?: number, publicationOptions?: PublicationOptions): Promise<void>;
|
|
@@ -11,38 +11,38 @@ export type SettingsProtectionRung = 0 | 1 | 2 | 3;
|
|
|
11
11
|
export declare class SettingsRecreationRefusal extends Error {
|
|
12
12
|
constructor(file: string);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* A write into an existing settings file by a host that has not adopted it
|
|
16
|
+
* (its import check has not passed). The file may protect less than the
|
|
17
|
+
* host's legacy store, so the write is refused under the writer lock; the
|
|
18
|
+
* caller reports the same refusal as while the host is held by that check.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SettingsAdoptionRefusal extends Error {
|
|
21
|
+
readonly file: string;
|
|
22
|
+
constructor(file: string);
|
|
23
|
+
}
|
|
14
24
|
export interface SettingsUpdateOptions {
|
|
15
25
|
/** Only menu writes and setup with a <target>.moved marker and no user file may create it. */
|
|
16
26
|
createMissing?: boolean;
|
|
17
27
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The edits were planned from a missing file (a floor list started from
|
|
24
|
-
* the recreation's list). The write is refused as busy if a file exists.
|
|
25
|
-
*/
|
|
26
|
-
expectMissing?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Setup runs while every host is stopped. When the other host then has no
|
|
29
|
-
* recoverable protection set (no applied copy and no legacy store, rather
|
|
30
|
-
* than an unreadable one), recreation carries the writer's set instead of
|
|
31
|
-
* refusing. Running hosts never pass it: a running peer at the strictest
|
|
32
|
-
* set would be loosened.
|
|
28
|
+
* This write is the host's import into the file (the import check, or
|
|
29
|
+
* setup filling the file from the legacy store), which by design runs
|
|
30
|
+
* before the host adopts the file. Every other write by a host lease that
|
|
31
|
+
* has not adopted the file is refused when the file exists.
|
|
33
32
|
*/
|
|
34
|
-
|
|
33
|
+
importing?: boolean;
|
|
35
34
|
}
|
|
36
35
|
export interface SettingsProtectionRecovery {
|
|
37
|
-
/** Return only this host's complete set; missing
|
|
36
|
+
/** Return only this host's complete set; a missing copy returns undefined, an unreadable or corrupt one throws. */
|
|
38
37
|
readAppliedCopy?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
|
|
39
38
|
/** Read this runtime's local or vault settings store, as selected by its current enrollment mode. */
|
|
40
39
|
readLegacyProtection?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
|
|
41
40
|
/**
|
|
42
41
|
* Read the other host's own legacy store through that host's current custody
|
|
43
42
|
* (see `readPeerLegacySettingsProtection`). Recreating a missing file uses it
|
|
44
|
-
* to learn the other host's protection
|
|
45
|
-
*
|
|
43
|
+
* to learn the other host's protection. Without it, that host's set is
|
|
44
|
+
* unknown and recreation is refused: an absent reader never means the
|
|
45
|
+
* other host has nothing to protect.
|
|
46
46
|
*/
|
|
47
47
|
readPeerLegacyProtection?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
|
|
48
48
|
}
|
|
@@ -97,7 +97,15 @@ export interface SettingsService {
|
|
|
97
97
|
/** Every underlying user-file watch callback, even if resolved values stay identical. */
|
|
98
98
|
onFileEvent?(listener: () => void): () => void;
|
|
99
99
|
refresh(): Promise<void>;
|
|
100
|
-
update(edits:
|
|
100
|
+
update(edits: SettingsUpdate, host: SettingsHost, options?: SettingsUpdateOptions): Promise<UpdateResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Called once the acting host has passed its import check for this file
|
|
103
|
+
* (after its `adopted` option turned true): the lease records the
|
|
104
|
+
* generation it holds as that host's last-good set at once, before the
|
|
105
|
+
* applied copy is saved, so a failed copy write leaves no stale window.
|
|
106
|
+
* Does nothing while `adopted` still returns false.
|
|
107
|
+
*/
|
|
108
|
+
noteAdoption?(): void;
|
|
101
109
|
dispose(): Promise<void>;
|
|
102
110
|
}
|
|
103
111
|
export type SettingsChangeListener = (generation: SettingsGeneration) => void | Promise<void>;
|
|
@@ -109,6 +117,18 @@ export interface SettingsServiceOptions {
|
|
|
109
117
|
separateInstall?: boolean;
|
|
110
118
|
lockTimeoutMs?: number;
|
|
111
119
|
protection?: SettingsProtectionRecovery;
|
|
120
|
+
/**
|
|
121
|
+
* False while the acting host has not passed its import check for this
|
|
122
|
+
* file (see `importSettingsHostStore`), so it does not use the file yet.
|
|
123
|
+
* Until then the file's values are never this host's last-good protection:
|
|
124
|
+
* a file it has not imported may protect less than its legacy store, so a
|
|
125
|
+
* missing or unusable file recovers this host's set from the ladder (its
|
|
126
|
+
* applied copy, then its legacy store, then the strictest set). Nor does
|
|
127
|
+
* the lease save an applied copy from it, and a write into the existing
|
|
128
|
+
* file is refused unless it is the host's import. Omitted means the host
|
|
129
|
+
* has not adopted the file: every production caller passes it explicitly.
|
|
130
|
+
*/
|
|
131
|
+
adopted?: () => boolean;
|
|
112
132
|
/** Dependency seams for deterministic file-race and no-I/O tests. */
|
|
113
133
|
dependencies?: {
|
|
114
134
|
open?: (options: OpenSettingsOptions) => CoreSettingsHandle;
|
|
@@ -118,19 +138,15 @@ export interface SettingsServiceOptions {
|
|
|
118
138
|
schedule?: (callback: () => void, delayMs: number) => () => void;
|
|
119
139
|
};
|
|
120
140
|
}
|
|
141
|
+
/** The levels at which a parsed settings document sets each key; values and their validity remain common-auth's responsibility. */
|
|
142
|
+
export declare function settingsFileLevels(raw: Record<string, unknown>): SettingsFileLevels;
|
|
121
143
|
/** One host's whole protection set, as the recreation planner receives it. */
|
|
122
144
|
export interface SettingsRecreationSide {
|
|
123
145
|
host: SettingsHost;
|
|
124
146
|
values: SettingsProtectionValues;
|
|
125
147
|
}
|
|
126
|
-
/**
|
|
127
|
-
|
|
128
|
-
* has no `level`; 0.49 adds it, and only then can a recreation write a value
|
|
129
|
-
* for one host. Until then recreation accepts plans whose edits carry none.
|
|
130
|
-
*/
|
|
131
|
-
export type SettingsLevelEdit = SettingsEdit & {
|
|
132
|
-
level?: 'default' | SettingsHost;
|
|
133
|
-
};
|
|
148
|
+
/** A shared-settings edit, including an explicit default or host level. */
|
|
149
|
+
export type SettingsLevelEdit = SettingsEdit;
|
|
134
150
|
/**
|
|
135
151
|
* The protection edits for a recreated file, as a pure function of both
|
|
136
152
|
* hosts' whole sets, so each host resolves exactly its own set from the new
|
|
@@ -157,7 +173,7 @@ export declare function planSettingsRecreation(writer: SettingsRecreationSide, p
|
|
|
157
173
|
export declare function settingsRecreationForWriter(values: SettingsProtectionValues, host: SettingsHost): SettingsLevelEdit[];
|
|
158
174
|
/**
|
|
159
175
|
* The floor list a recreation writes when the other host applies the same
|
|
160
|
-
* floors as `host
|
|
176
|
+
* floors as `host`.
|
|
161
177
|
*/
|
|
162
178
|
export declare function settingsRecreationFloors(values: SettingsProtectionValues, host: SettingsHost): SettingsProtectionValues['killswitch_account_floors'];
|
|
163
179
|
/** One host's protection set and where it came from, for planning a recreation. */
|
|
@@ -173,16 +189,17 @@ export interface SettingsRecreationInput {
|
|
|
173
189
|
*/
|
|
174
190
|
none?: boolean;
|
|
175
191
|
}
|
|
176
|
-
export type SettingsRecreationRefusalReason = 'own-unknown' | 'peer-unknown'
|
|
192
|
+
export type SettingsRecreationRefusalReason = 'own-unknown' | 'peer-unknown';
|
|
177
193
|
/**
|
|
178
|
-
* What a menu write that finds the file missing does, as a pure
|
|
179
|
-
* both hosts' sets: the protection edits it carries, or why it
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
194
|
+
* What a menu write or setup that finds the file missing does, as a pure
|
|
195
|
+
* function of both hosts' sets: the protection edits it carries, or why it
|
|
196
|
+
* is refused. Only a peer known to have no set (it never ran) takes the
|
|
197
|
+
* writer's. A peer whose set is unknown refuses the write, whether or not
|
|
198
|
+
* the hosts are running, so its protection is never replaced by the
|
|
199
|
+
* writer's. Otherwise both known sets are carried together, with host levels
|
|
200
|
+
* preserving any differing values.
|
|
184
201
|
*/
|
|
185
|
-
export declare function planSettingsFileRecreation(writer: SettingsRecreationInput, peer: SettingsRecreationInput
|
|
202
|
+
export declare function planSettingsFileRecreation(writer: SettingsRecreationInput, peer: SettingsRecreationInput): {
|
|
186
203
|
edits: SettingsLevelEdit[];
|
|
187
204
|
} | {
|
|
188
205
|
refused: SettingsRecreationRefusalReason;
|
|
@@ -192,13 +209,23 @@ export type SettingsWriteState = {
|
|
|
192
209
|
status: 'missing';
|
|
193
210
|
} | {
|
|
194
211
|
status: 'ready';
|
|
212
|
+
document: unknown;
|
|
195
213
|
};
|
|
214
|
+
/** Menu edits run under the writer lock; a missing file also supplies its protection carry. */
|
|
215
|
+
export type SettingsUpdatePlan = (current: SettingsWriteState, carry?: readonly SettingsEdit[]) => readonly SettingsEdit[];
|
|
216
|
+
export type SettingsUpdate = readonly SettingsEdit[] | SettingsUpdatePlan;
|
|
196
217
|
/**
|
|
197
218
|
* The edits for one menu write, as a pure function of the file it finds:
|
|
198
219
|
* protection is carried only into a missing file, and an existing file keeps
|
|
199
220
|
* its own. `carry` throws when recreation must be refused.
|
|
200
221
|
*/
|
|
201
222
|
export declare function planSettingsMenuWrite(current: SettingsWriteState, edits: readonly SettingsEdit[], carry: () => readonly SettingsEdit[]): readonly SettingsEdit[];
|
|
223
|
+
/**
|
|
224
|
+
* Why `host` can't use the file, in plain words for a refused menu write, or
|
|
225
|
+
* undefined when it can (or the file is missing). It names at most a
|
|
226
|
+
* declared setting, never a value: file contents may hold secrets.
|
|
227
|
+
*/
|
|
228
|
+
export declare function settingsFileProblem(generation: SettingsGeneration, host: SettingsHost): string | undefined;
|
|
202
229
|
export declare function mostRestrictiveSettingsProtection(): SettingsProtectionValues;
|
|
203
230
|
/**
|
|
204
231
|
* Rungs 1-3 of the protection ladder, which need no open settings handle:
|
package/dist/settings-start.d.ts
CHANGED
|
@@ -21,8 +21,22 @@ export interface SettingsProtectionFallback {
|
|
|
21
21
|
readonly file: string;
|
|
22
22
|
readonly rung: 1 | 2 | 3;
|
|
23
23
|
readonly values: SettingsProtectionValues;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Off the request path: open the service again and run this host's import
|
|
26
|
+
* check; undefined while either still fails.
|
|
27
|
+
*/
|
|
25
28
|
reopen(): Promise<SettingsService | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* True when the service the last `reopen` returned was adopted for a
|
|
31
|
+
* missing file whose import is still owed: the runtime must pass the
|
|
32
|
+
* import check again before it uses a file that appears.
|
|
33
|
+
*/
|
|
34
|
+
importPending?(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Present with `resolveAuthority`: once it finds legacy mode, open the
|
|
37
|
+
* service only to notice a later move, without adopting the file.
|
|
38
|
+
*/
|
|
39
|
+
reopenLegacy?(): Promise<SettingsService | undefined>;
|
|
26
40
|
/**
|
|
27
41
|
* Present only when startup could not tell which source is in charge and
|
|
28
42
|
* fell back to the file as a precaution. Off the request path, asks again;
|
|
@@ -33,17 +47,35 @@ export interface SettingsProtectionFallback {
|
|
|
33
47
|
}
|
|
34
48
|
export interface StartedSettings {
|
|
35
49
|
mode: SettingsMode;
|
|
36
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* The settings file; empty only when no path could be resolved, which the
|
|
52
|
+
* shared-runtime key treats as "no settings file".
|
|
53
|
+
*/
|
|
37
54
|
file: string;
|
|
38
55
|
/** Open in user-file mode, and in legacy mode to notice another host's move. */
|
|
39
56
|
service?: SettingsService;
|
|
40
57
|
/** Set instead of `service` when the file is in charge but could not open. */
|
|
41
58
|
fallback?: SettingsProtectionFallback;
|
|
42
59
|
/**
|
|
43
|
-
* Set in legacy mode when the service could not open
|
|
44
|
-
*
|
|
60
|
+
* Set in legacy mode when the service could not open, or the enrollment or
|
|
61
|
+
* migration preflight refused: open it again off the request path, so a
|
|
62
|
+
* move another host publishes later is noticed.
|
|
63
|
+
*/
|
|
64
|
+
reopen?: SettingsReopen;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Opens the settings service again off the request path; undefined while it
|
|
68
|
+
* still cannot. `retryDelaysMs` asks the runtime to try sooner than its
|
|
69
|
+
* normal interval, one delay per attempt, before falling back to it.
|
|
70
|
+
*/
|
|
71
|
+
export interface SettingsReopen {
|
|
72
|
+
(): Promise<SettingsService | undefined>;
|
|
73
|
+
readonly retryDelaysMs?: readonly number[];
|
|
74
|
+
/**
|
|
75
|
+
* True once a reopen found that this host is a separate install: it never
|
|
76
|
+
* opens the shared settings file, and the runtime treats it as separate.
|
|
45
77
|
*/
|
|
46
|
-
|
|
78
|
+
readonly separate?: () => boolean;
|
|
47
79
|
}
|
|
48
80
|
/** Tests only: let the next failed start log its one warning again. */
|
|
49
81
|
export declare function __resetSettingsStartWarningForTest(): void;
|
|
@@ -52,6 +84,14 @@ export declare function __resetSettingsStartWarningForTest(): void;
|
|
|
52
84
|
* move, then opens the service. When either fails, a file that is (or may
|
|
53
85
|
* be) in charge gets the protection fallback, never plain legacy values,
|
|
54
86
|
* which may predate protection the user tightened in the file. Only a check
|
|
55
|
-
* that proves no move happened (no file, no marker) returns legacy mode
|
|
87
|
+
* that proves no move happened (no file, no marker) returns legacy mode, or
|
|
88
|
+
* a refused enrollment or migration preflight, while requests are refused.
|
|
89
|
+
*
|
|
90
|
+
* Every service it opens carries the import check (see
|
|
91
|
+
* `setSettingsAdoptionCheck`): a runtime that starts in legacy mode adopts
|
|
92
|
+
* a file that appears later only after that check passes. Until this host
|
|
93
|
+
* has adopted the file, its applied protection copy is not written from the
|
|
94
|
+
* file, so a file whose import is still owed never becomes the copy that
|
|
95
|
+
* recovery trusts.
|
|
56
96
|
*/
|
|
57
97
|
export declare function startSettings(options: StartSettingsOptions): Promise<StartedSettings>;
|