@phreshos/server 0.1.15 → 0.1.17
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 +6 -1
- package/dist/domain.d.ts +4 -10
- package/dist/host.d.ts +3 -0
- package/dist/host.js +2 -0
- package/dist/main.d.ts +2 -1
- package/dist/main.js +1 -0
- package/dist/storage.d.ts +5 -3
- package/dist/storage.js +59 -15
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -113,12 +113,17 @@ waiter.
|
|
|
113
113
|
Server Program handles add `install()` and `fork()`. `install()` is an async
|
|
114
114
|
generator that opens immediately, yields ordered `stdout` and `stderr` command
|
|
115
115
|
chunks, completes only after installation succeeds, and throws the owning
|
|
116
|
-
System error when installation fails. Their
|
|
116
|
+
System error when installation fails. Their `Storage` values also expose
|
|
117
117
|
`path()` and traversal-safe `resolve()`, because filesystem work is performed
|
|
118
118
|
locally in the Server SDK after the Host supplies only the area root.
|
|
119
119
|
Object descriptions passed to `host.program.create()` therefore require an
|
|
120
120
|
explicit absolute storage root as well as at least one declared Endpoint.
|
|
121
121
|
|
|
122
|
+
`host.storage` implements that same refined `Storage` contract against the
|
|
123
|
+
native operating-system home directory. The System supplies the authoritative
|
|
124
|
+
root; traversal and symbolic-link escape remain rejected by the SDK before any
|
|
125
|
+
filesystem operation.
|
|
126
|
+
|
|
122
127
|
Host registries are separated by owner. Reads, commands, and the complete
|
|
123
128
|
subscription contract live on their relevant capability rather than directly
|
|
124
129
|
on `host`:
|
package/dist/domain.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import { Client as CoreClient, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, Server as CoreServer, type AnswerCapture, type AskCapture, type Cleanup, type ClientDeclaration, type Exit, type Launch, type Position, type ProgramCommandChunk, type ProgramPermission, type ProgramProcess as CoreProgramProcess, type
|
|
1
|
+
import { Client as CoreClient, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, Server as CoreServer, type AnswerCapture, type AskCapture, type Cleanup, type ClientDeclaration, type Exit, type Launch, type Position, type ProgramCommandChunk, type ProgramPermission, type ProgramProcess as CoreProgramProcess, type Size, type TrafficMessage, type Window as CoreWindow, type WindowState } from "@phreshos/core";
|
|
2
2
|
import Events from "./events.js";
|
|
3
|
+
import { type Storage } from "./storage.js";
|
|
3
4
|
import { type ProgramStartup } from "./startup.js";
|
|
4
5
|
import { type ClientServiceHandler, type ServerServiceHandler } from "./service.js";
|
|
5
6
|
export interface HandleAddress {
|
|
6
7
|
identity: string;
|
|
7
8
|
reference: string;
|
|
8
9
|
}
|
|
9
|
-
/** Server-side filesystem storage with access to its resolved host path. */
|
|
10
|
-
export interface ProgramArea extends CoreProgramArea {
|
|
11
|
-
/** Returns the absolute host path of this storage area. */
|
|
12
|
-
path(): Promise<string>;
|
|
13
|
-
/** Resolves path segments within this storage area without permitting escape. */
|
|
14
|
-
resolve(...path: string[]): Promise<string>;
|
|
15
|
-
}
|
|
16
10
|
/** Client-safe Program data transported by the authoritative host. */
|
|
17
11
|
export interface EndpointDeclarationRecord {
|
|
18
12
|
start: boolean;
|
|
@@ -54,9 +48,9 @@ export type WindowRecord = WindowState;
|
|
|
54
48
|
/** Server-visible Program handle and privileged Program operations. */
|
|
55
49
|
export interface Program<Events extends object = {}> extends Omit<CoreProgram<Events>, "process"> {
|
|
56
50
|
/** Persistent filesystem data shared by every Process of this Program. */
|
|
57
|
-
readonly data:
|
|
51
|
+
readonly data: Storage;
|
|
58
52
|
/** Disposable filesystem data shared by every Process of this Program. */
|
|
59
|
-
readonly cache:
|
|
53
|
+
readonly cache: Storage;
|
|
60
54
|
/** Persistent Process launch used when the system starts. */
|
|
61
55
|
readonly startup: ProgramStartup;
|
|
62
56
|
/** Persistent permission decisions owned by this Program. */
|
package/dist/host.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ServiceKey, Size, Subscribable, ThemeProperties, WritableTheme } from "@phreshos/core";
|
|
2
2
|
import type { ClientServiceHandler, ServerServiceHandler } from "./service.js";
|
|
3
3
|
import { type Client, type Process, type Program, type Server } from "./domain.js";
|
|
4
|
+
import { type Storage } from "./storage.js";
|
|
4
5
|
/** Resolved production description for a Program's Server. */
|
|
5
6
|
export type ServerDescription = Readonly<{
|
|
6
7
|
/** Absolute directory containing the production Server files. */
|
|
@@ -104,6 +105,8 @@ export interface HostProcess extends Subscribable<ProcessHostEvents, never> {
|
|
|
104
105
|
}
|
|
105
106
|
/** Authoritative system capabilities available to a Server endpoint. */
|
|
106
107
|
export interface Host {
|
|
108
|
+
/** Native operating-system home storage available to Server endpoints. */
|
|
109
|
+
readonly storage: Storage;
|
|
107
110
|
/** Observable system Theme authority. */
|
|
108
111
|
readonly theme: WritableTheme<ThemeProperties>;
|
|
109
112
|
/** Authoritative wallpaper visible before authentication. */
|
package/dist/host.js
CHANGED
|
@@ -5,7 +5,9 @@ import ServerTheme from "./theme.js";
|
|
|
5
5
|
import { ServerDesktopWallpaper, ServerSignInWallpaper } from "./wallpaper.js";
|
|
6
6
|
import wire from "./wire.js";
|
|
7
7
|
import { prepareService } from "./service.js";
|
|
8
|
+
import { hostStorage } from "./storage.js";
|
|
8
9
|
class ServerHost {
|
|
10
|
+
storage = hostStorage();
|
|
9
11
|
theme = new ServerTheme();
|
|
10
12
|
signInWallpaper = new ServerSignInWallpaper();
|
|
11
13
|
desktopWallpaper = new ServerDesktopWallpaper();
|
package/dist/main.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export { host, type Host, type HostProcess, type HostProgram, type ClientDescrip
|
|
|
2
2
|
export { current, type Current, type CurrentClient } from "./current.js";
|
|
3
3
|
export { type Answerer, type Channel } from "./channel.js";
|
|
4
4
|
export { type ProgramStartup } from "./startup.js";
|
|
5
|
+
export { type Storage } from "./storage.js";
|
|
5
6
|
export { ClientServiceHandler, ServerServiceHandler } from "./service.js";
|
|
6
7
|
export { ServiceHandler, type ClientServiceChannel, type ServerServiceChannel, type ServiceChannel, type ServiceKey, type ServiceLifecycleEvents } from "@phreshos/core";
|
|
7
|
-
export { Client, Endpoint, Process, Program, Server, type Window, type
|
|
8
|
+
export { Client, Endpoint, Process, Program, Server, type Window, type ProgramProcess } from "./domain.js";
|
|
8
9
|
export type { AnswerCapture, AnswerMessage, AnswerObserver, Askable, AskCapture, AskMessage, AskObserver, Capture, Captures, ChannelCapture, ChannelEvents, ChannelMessage, ClientTraffic, ClientDeclaration, Cleanup, DirectoryStat, EndpointDeclaration, EndpointTraffic, EntryStat, EventMessage, EventName, EventObserver, EventOptions, EventSubscriber, Exit, FileStat, Launch, LaunchClient, Layer, LogKind, LogRecord, LogSource, Message, OtherStat, Outcome, Position, ProgramEvents, ProgramPermission, ProgramProcessEvents, ProgramProcessExit, ProgramSql, ProgramStore, ProcessEvents, Publishable, ServedFile, ServerTraffic, Size, Subscribable, SubscribableEvents, SubscribableFallback, TimedAskable, TrafficCapture, TrafficEvents, TrafficMessage, Value, Theme, ThemeEvents, ThemeProperties, WallpaperLaunch, FileWallpaper, DesktopWallpaper, WritableTheme, WindowEvents, WindowGeometry, WindowLayer, WindowState } from "@phreshos/core";
|
package/dist/main.js
CHANGED
|
@@ -2,6 +2,7 @@ export { host } from "./host.js";
|
|
|
2
2
|
export { current } from "./current.js";
|
|
3
3
|
export {} from "./channel.js";
|
|
4
4
|
export {} from "./startup.js";
|
|
5
|
+
export {} from "./storage.js";
|
|
5
6
|
export { ClientServiceHandler, ServerServiceHandler } from "./service.js";
|
|
6
7
|
export { ServiceHandler } from "@phreshos/core";
|
|
7
8
|
export { Client, Endpoint, Process, Program, Server } from "./domain.js";
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProgramSql, ProgramStore, Storage as CoreStorage } from "@phreshos/core";
|
|
2
2
|
import type { HandleAddress } from "./domain.js";
|
|
3
|
-
export interface
|
|
3
|
+
export interface Storage extends CoreStorage {
|
|
4
4
|
path(): Promise<string>;
|
|
5
5
|
resolve(...path: string[]): Promise<string>;
|
|
6
6
|
}
|
|
7
7
|
/** Server-local implementation of one Program-owned filesystem area. */
|
|
8
|
-
export declare function area(program: HandleAddress, which: "data" | "cache"):
|
|
8
|
+
export declare function area(program: HandleAddress, which: "data" | "cache"): Storage;
|
|
9
|
+
/** Server-local access to the native home directory supplied by the System. */
|
|
10
|
+
export declare function hostStorage(): Storage;
|
|
9
11
|
export declare function store(program: HandleAddress): ProgramStore;
|
|
10
12
|
export declare function sql(kind: "database" | "logs", program: HandleAddress): ProgramSql;
|
|
11
13
|
export declare function content(value: unknown): {
|
package/dist/storage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { createReadStream, createWriteStream, mkdirSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { createReadStream, createWriteStream, mkdirSync, lstatSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
3
3
|
import { rm } from "node:fs/promises";
|
|
4
4
|
import { dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
5
5
|
import { Readable } from "node:stream";
|
|
@@ -7,31 +7,50 @@ import { pipeline } from "node:stream/promises";
|
|
|
7
7
|
import wire from "./wire.js";
|
|
8
8
|
/** Server-local implementation of one Program-owned filesystem area. */
|
|
9
9
|
export function area(program, which) {
|
|
10
|
-
async function
|
|
10
|
+
return createStorage(async function () {
|
|
11
11
|
const answer = await wire.request([which, program, "path"]);
|
|
12
12
|
return answer[0];
|
|
13
|
+
}, `this Program's ${which}`);
|
|
14
|
+
}
|
|
15
|
+
/** Server-local access to the native home directory supplied by the System. */
|
|
16
|
+
export function hostStorage() {
|
|
17
|
+
return createStorage(async function () {
|
|
18
|
+
const answer = await wire.request(["host-storage", "path"]);
|
|
19
|
+
return answer[0];
|
|
20
|
+
}, "the native home directory");
|
|
21
|
+
}
|
|
22
|
+
function createStorage(root, label) {
|
|
23
|
+
let resolvedRoot = null;
|
|
24
|
+
async function path() {
|
|
25
|
+
if (!resolvedRoot) {
|
|
26
|
+
const resolving = root().then(value => {
|
|
27
|
+
if (!isAbsolute(value))
|
|
28
|
+
throw new Error("The host returned an invalid Storage directory");
|
|
29
|
+
return value;
|
|
30
|
+
});
|
|
31
|
+
const retained = resolving.catch(error => {
|
|
32
|
+
if (resolvedRoot === retained)
|
|
33
|
+
resolvedRoot = null;
|
|
34
|
+
throw error;
|
|
35
|
+
});
|
|
36
|
+
resolvedRoot = retained;
|
|
37
|
+
}
|
|
38
|
+
return resolvedRoot;
|
|
13
39
|
}
|
|
14
40
|
async function resolve(...parts) {
|
|
15
41
|
const root = await path();
|
|
16
|
-
|
|
17
|
-
const step = relative(root, destination);
|
|
18
|
-
if (step === ".." || step.startsWith(`..${sep}`) || isAbsolute(step)) {
|
|
19
|
-
throw new Error("A storage path may not leave its area");
|
|
20
|
-
}
|
|
21
|
-
return destination;
|
|
42
|
+
return contained(root, parts);
|
|
22
43
|
}
|
|
23
44
|
async function stream(...parts) {
|
|
24
45
|
const destination = await resolve(...parts);
|
|
25
46
|
const found = describe(destination);
|
|
26
47
|
if (!found)
|
|
27
|
-
throw new Error(`There is no ${parts.join("/")} in
|
|
48
|
+
throw new Error(`There is no ${parts.join("/")} in ${label}`);
|
|
28
49
|
if (found.kind !== "file")
|
|
29
50
|
throw new Error(`${parts.join("/")} is not a file`);
|
|
30
51
|
return Readable.toWeb(createReadStream(destination));
|
|
31
52
|
}
|
|
32
53
|
async function write(...args) {
|
|
33
|
-
if (args.length < 2)
|
|
34
|
-
throw new Error("Writing takes a file name and what to write");
|
|
35
54
|
const parts = args.slice(0, -1);
|
|
36
55
|
const destination = await resolve(...parts);
|
|
37
56
|
const temporary = join(dirname(destination), `.${randomUUID()}.writing`);
|
|
@@ -70,13 +89,38 @@ export function area(program, which) {
|
|
|
70
89
|
throw new Error("Emptying a place is clear, not delete");
|
|
71
90
|
rmSync(await resolve(...parts), { recursive: true, force: true });
|
|
72
91
|
},
|
|
73
|
-
async clear() {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
async clear(...parts) {
|
|
93
|
+
const destination = await resolve(...parts);
|
|
94
|
+
const found = describe(destination);
|
|
95
|
+
if (found && found.kind !== "directory")
|
|
96
|
+
throw new Error("Only a storage directory can be cleared");
|
|
97
|
+
rmSync(destination, { recursive: true, force: true });
|
|
98
|
+
mkdirSync(destination, { recursive: true });
|
|
77
99
|
}
|
|
78
100
|
};
|
|
79
101
|
}
|
|
102
|
+
function contained(root, parts) {
|
|
103
|
+
const destination = join(root, ...parts);
|
|
104
|
+
const step = relative(root, destination);
|
|
105
|
+
if (step === ".." || step.startsWith(`..${sep}`) || isAbsolute(step)) {
|
|
106
|
+
throw new Error("A storage path may not leave its configured directory");
|
|
107
|
+
}
|
|
108
|
+
let current = root;
|
|
109
|
+
for (const part of step.split(sep).filter(Boolean)) {
|
|
110
|
+
current = join(current, part);
|
|
111
|
+
try {
|
|
112
|
+
if (lstatSync(current).isSymbolicLink()) {
|
|
113
|
+
throw new Error("A storage path may not pass through a symbolic link");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error.code === "ENOENT")
|
|
118
|
+
break;
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return destination;
|
|
123
|
+
}
|
|
80
124
|
export function store(program) {
|
|
81
125
|
async function ask(operation, ...values) {
|
|
82
126
|
const answer = await wire.request(["store", program, operation, ...values]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "The SDK used by a Program's server endpoint.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"prepack": "node --run build"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@phreshos/core": "^0.1.
|
|
49
|
+
"@phreshos/core": "^0.1.14"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@msgpack/msgpack": "^3.1.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@phreshos/core": "^0.1.
|
|
55
|
+
"@phreshos/core": "^0.1.14",
|
|
56
56
|
"@types/node": "^26.2.0",
|
|
57
57
|
"typescript": "^6.0.3"
|
|
58
58
|
}
|