@tnnevol/dsh-fnos 0.1.1-rc.2.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/lib/index.d.ts ADDED
@@ -0,0 +1,125 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import { IncomingMessage } from "node:http";
3
+ import { Context } from "@deepseek-ai/cordis";
4
+ //#region src/authorized-directories-contract.d.ts
5
+ /** Browser/Host contract for fnOS shared-directory management. */
6
+ /** Settings namespace used to pair the Host namespace with the Client card. */
7
+ declare const FNOS_AUTHORIZED_DIRECTORIES_SETTINGS_NAMESPACE = "dsh-fnos-authorized-directories";
8
+ /** Same-origin route that lists the directories currently authorized for the app. */
9
+ declare const FNOS_AUTHORIZED_DIRECTORIES_PATH = "/plugins/dsh-fnos/authorized-directories";
10
+ /** Same-origin route that removes one application directory ACL. */
11
+ declare const FNOS_AUTHORIZED_DIRECTORIES_DELETE_PATH = "/plugins/dsh-fnos/authorized-directories/delete";
12
+ /** Same-origin route that converts internal fnOS paths to readable paths. */
13
+ declare const FNOS_PATH_CONVERSION_PATH = "/plugins/dsh-fnos/paths/convert";
14
+ /** Same-origin route that validates a DSH path before fnOS opens it. */
15
+ declare const FNOS_PATH_OPEN_VALIDATION_PATH = "/plugins/dsh-fnos/paths/open/validate";
16
+ /** Same-origin route that lists one level below an authorized NAS directory. */
17
+ declare const FNOS_AUTHORIZED_ENTRIES_PATH = "/plugins/dsh-fnos/authorized-directories/entries";
18
+ interface ReadablePath {
19
+ /** Internal fnOS path used by the Host and DSH reference codec. */
20
+ path: string;
21
+ /** User-facing path returned by trim.file.convertPath. */
22
+ semanticPath: string;
23
+ }
24
+ type AuthorizedEntryKind = 'file' | 'directory';
25
+ interface AuthorizedEntry {
26
+ /** Internal fnOS path used by DSH's reference codec. */
27
+ path: string;
28
+ /** User-facing path returned by trim.file.convertPath. */
29
+ semanticPath: string;
30
+ /** Whether the entry can be opened as a directory in the picker. */
31
+ kind: AuthorizedEntryKind;
32
+ /** Optional file size supplied by the Host for a lightweight listing. */
33
+ size?: number;
34
+ /** Optional modification timestamp in milliseconds. */
35
+ modifiedAt?: number;
36
+ }
37
+ interface AuthorizedEntriesResponse {
38
+ /** Directory represented by this listing; omitted for the authorized roots. */
39
+ directory?: ReadablePath;
40
+ entries: AuthorizedEntry[];
41
+ truncated?: boolean;
42
+ }
43
+ //#endregion
44
+ //#region src/authorized-directories.d.ts
45
+ /** fnOS supplies user-authorized application paths through this variable. */
46
+ declare const FNOS_ACCESSIBLE_PATHS_ENV = "TRIM_DATA_ACCESSIBLE_PATHS";
47
+ /** fnOS supplies the application's declared shared data paths through this variable. */
48
+ declare const FNOS_DATA_SHARE_PATHS_ENV = "TRIM_DATA_SHARE_PATHS";
49
+ interface UserAclResult {
50
+ /** Whether fnOS returned a usable ACL response for the current user. */
51
+ available: boolean;
52
+ /** Paths that fnOS says the current user can read. */
53
+ readable: Set<string>;
54
+ }
55
+ /** Injectable ACL checker used by the path validation tests. */
56
+ type UserAclChecker = (req: IncomingMessage | undefined, paths: readonly string[]) => Promise<UserAclResult>;
57
+ interface PathValidationOptions {
58
+ /** Override the application roots when validating in isolation. */
59
+ roots?: readonly string[];
60
+ /** Override the current-user ACL lookup when validating in isolation. */
61
+ checkUserAcl?: UserAclChecker;
62
+ }
63
+ type PathValidationFailure = 'fnos-path-not-authorized' | 'fnos-path-not-found' | 'fnos-path-not-readable' | 'fnos-user-permission-denied' | 'fnos-user-permission-unavailable';
64
+ interface PathValidationResult {
65
+ ok: boolean;
66
+ failure?: PathValidationFailure;
67
+ }
68
+ /**
69
+ * Read the user identity supplied by the fnOS unified gateway.
70
+ *
71
+ * `TRIM_UID` is the application service user and must not be used here. The
72
+ * current browser user is carried by `X-Trim-Userid` on gateway requests.
73
+ */
74
+ declare function gatewayUserId(req: IncomingMessage | undefined): number | undefined;
75
+ /** Normalize one fnOS volume path for display and exact delete matching. */
76
+ declare function normalizeAuthorizedPath(value: unknown): string | undefined;
77
+ /** Normalize a path used for the open authorization boundary. */
78
+ declare function normalizePathForAuthorization(value: unknown): string | undefined;
79
+ /** Check a target path against authorized roots without confusing path prefixes. */
80
+ declare function isPathWithinAuthorizedDirectory(pathValue: unknown, rootsValue: unknown): boolean;
81
+ /** Keep API order while removing malformed and duplicate paths. */
82
+ declare function normalizeAuthorizedPaths(value: unknown): string[];
83
+ /** Parse a fnOS colon-separated path environment variable. */
84
+ declare function splitPathEnvironment(value: unknown): string[];
85
+ /** Read user-authorized paths from the lifecycle environment and de-duplicate them. */
86
+ declare function accessiblePathsFromEnvironment(env?: NodeJS.ProcessEnv): string[];
87
+ /** Read declared application data shares for display and de-duplicate them. */
88
+ declare function dataSharePathsFromEnvironment(env?: NodeJS.ProcessEnv): string[];
89
+ /** Combine path sources without changing the first-seen order. */
90
+ declare function mergeAuthorizedPaths(...values: unknown[]): string[];
91
+ /** Keep a just-removed ACL out of the process-local merged configuration. */
92
+ declare function markAuthorizedPathRemoved(value: unknown): void;
93
+ /** Pair internal paths with fnOS semantic paths, falling back per entry. */
94
+ declare function convertPathsForDisplay(pathsValue: unknown, language?: string): Promise<ReadablePath[]>;
95
+ /**
96
+ * Validate a DSH file/directory target using all applicable permission layers:
97
+ * the app's real shared roots, the process's actual fs access, and the
98
+ * current NAS user ACL supplied by the unified gateway.
99
+ */
100
+ declare function validatePathForOpen(pathValue: unknown, req?: IncomingMessage, options?: PathValidationOptions): Promise<PathValidationResult>;
101
+ /** Backward-compatible boolean helper for callers that only need a verdict. */
102
+ declare function isAuthorizedPathForOpen(pathValue: unknown, req?: IncomingMessage): Promise<boolean>;
103
+ /**
104
+ * List only existing, readable authorized roots or one authorized directory
105
+ * level. The app ACL root is only the first boundary: every returned entry is
106
+ * also checked with the real filesystem and, when the request came through
107
+ * the fnOS gateway, the current user's ACL.
108
+ */
109
+ declare function loadAuthorizedEntries(req: IncomingMessage, pathValue?: string): Promise<AuthorizedEntriesResponse>;
110
+ //#endregion
111
+ //#region src/index.d.ts
112
+ /** Stable Host bundle name. */
113
+ declare const name = "@tnnevol/dsh-fnos";
114
+ /** Settings back the fnOS card and the cached pre-plugin theme bootstrap. */
115
+ declare const FnosSettingsSchema: z<Schemastery.ObjectS<{
116
+ systemTheme: z<"light" | "dark", "light" | "dark">;
117
+ }>, Schemastery.ObjectT<{
118
+ systemTheme: z<"light" | "dark", "light" | "dark">;
119
+ }>>;
120
+ declare const FNOS_AUTHORIZED_DIRECTORIES_SETTINGS_NS: import("@deepseek-ai/dsh-settings").SettingsNamespace;
121
+ /** Host services required by the fnOS settings namespace and Web routes. */
122
+ declare const inject: string[];
123
+ declare function apply(ctx: Context): void;
124
+ //#endregion
125
+ export { FNOS_ACCESSIBLE_PATHS_ENV, FNOS_AUTHORIZED_DIRECTORIES_DELETE_PATH, FNOS_AUTHORIZED_DIRECTORIES_PATH, FNOS_AUTHORIZED_DIRECTORIES_SETTINGS_NAMESPACE, FNOS_AUTHORIZED_DIRECTORIES_SETTINGS_NS, FNOS_AUTHORIZED_ENTRIES_PATH, FNOS_DATA_SHARE_PATHS_ENV, FNOS_PATH_CONVERSION_PATH, FNOS_PATH_OPEN_VALIDATION_PATH, FnosSettingsSchema, accessiblePathsFromEnvironment, apply, convertPathsForDisplay, dataSharePathsFromEnvironment, gatewayUserId, inject, isAuthorizedPathForOpen, isPathWithinAuthorizedDirectory, loadAuthorizedEntries, markAuthorizedPathRemoved, mergeAuthorizedPaths, name, normalizeAuthorizedPath, normalizeAuthorizedPaths, normalizePathForAuthorization, splitPathEnvironment, validatePathForOpen };