dock-spreadsheet 0.1.0 → 0.1.1
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.js +32 -2
- package/lib/types/index.d.ts +16 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2,7 +2,15 @@ import { open } from "node:fs/promises";
|
|
|
2
2
|
import { extname, isAbsolute, resolve } from "node:path";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
const name = "dock-spreadsheet";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Services required before mounting.
|
|
7
|
+
*
|
|
8
|
+
* The declared-authority list these routes fence with used to be injected here
|
|
9
|
+
* as `webRuntime`. DSH renamed that service to `webStartup` in 0.2.1, so the
|
|
10
|
+
* list is resolved lazily through `declaredTrustedHosts` instead: a renamed
|
|
11
|
+
* service can no longer park this plugin, and older hosts still mount.
|
|
12
|
+
*/
|
|
13
|
+
const inject = ["webServer"];
|
|
6
14
|
const MAX_FILE_BYTES = 20971520;
|
|
7
15
|
const MAX_REQUEST_BYTES = 8192;
|
|
8
16
|
const EXTENSIONS = /* @__PURE__ */ new Set([
|
|
@@ -21,6 +29,28 @@ var ReadError = class extends Error {
|
|
|
21
29
|
this.code = code;
|
|
22
30
|
}
|
|
23
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Authorities this deployment declared besides loopback.
|
|
34
|
+
*
|
|
35
|
+
* DSH publishes them as `trustedHosts` on `webStartup` (0.2.1+); `webRuntime`
|
|
36
|
+
* is the same service under its 0.1.x / 0.2.0 name, and a host that exposes
|
|
37
|
+
* only the connection RPC carries the list on `connection`. Probe all three
|
|
38
|
+
* lazily: a host with none of them keeps the loopback-only fence, and no
|
|
39
|
+
* rename can park this plugin on a missing service again.
|
|
40
|
+
*/
|
|
41
|
+
function declaredTrustedHosts(ctx) {
|
|
42
|
+
if (typeof ctx.get !== "function") return [];
|
|
43
|
+
for (const name of [
|
|
44
|
+
"webStartup",
|
|
45
|
+
"webRuntime",
|
|
46
|
+
"connection"
|
|
47
|
+
]) {
|
|
48
|
+
const declared = ctx.get(name)?.trustedHosts;
|
|
49
|
+
if (!Array.isArray(declared)) continue;
|
|
50
|
+
return declared.filter((entry) => typeof entry === "string");
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
24
54
|
function trusted(req, trustedHosts) {
|
|
25
55
|
const host = req.headers.host;
|
|
26
56
|
if (!host || req.headers["sec-fetch-site"] === "cross-site") return false;
|
|
@@ -94,7 +124,7 @@ function apply(ctx) {
|
|
|
94
124
|
kind: "prefix",
|
|
95
125
|
path: "/dock-spreadsheet",
|
|
96
126
|
handler: async (req, res) => {
|
|
97
|
-
if (!trusted(req, ctx
|
|
127
|
+
if (!trusted(req, declaredTrustedHosts(ctx))) return fail(res, 403, "forbidden", "forbidden");
|
|
98
128
|
if (req.method !== "POST" || new URL(req.url ?? "/", "http://dsh.internal").pathname !== "/dock-spreadsheet/read") return fail(res, 404, "not-found", "unknown route");
|
|
99
129
|
try {
|
|
100
130
|
const bytes = await readSpreadsheet(await requestPath(req));
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
export declare const name = "dock-spreadsheet";
|
|
3
|
+
/**
|
|
4
|
+
* Services required before mounting.
|
|
5
|
+
*
|
|
6
|
+
* The declared-authority list these routes fence with used to be injected here
|
|
7
|
+
* as `webRuntime`. DSH renamed that service to `webStartup` in 0.2.1, so the
|
|
8
|
+
* list is resolved lazily through `declaredTrustedHosts` instead: a renamed
|
|
9
|
+
* service can no longer park this plugin, and older hosts still mount.
|
|
10
|
+
*/
|
|
3
11
|
export declare const inject: string[];
|
|
4
12
|
export declare const MAX_FILE_BYTES: number;
|
|
5
13
|
interface Context {
|
|
@@ -10,9 +18,14 @@ interface Context {
|
|
|
10
18
|
handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
11
19
|
}): () => void;
|
|
12
20
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Read a service without declaring a hard dependency on it.
|
|
23
|
+
*
|
|
24
|
+
* Used for the optional `webStartup` / `webRuntime` / `connection` services:
|
|
25
|
+
* a host that provides none of them keeps the loopback-only fence instead of
|
|
26
|
+
* failing to mount.
|
|
27
|
+
*/
|
|
28
|
+
get?(name: string): unknown;
|
|
16
29
|
effect(fn: () => void | (() => void), label?: string): void;
|
|
17
30
|
}
|
|
18
31
|
export declare class ReadError extends Error {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dock-spreadsheet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Read-only XLSX, XLS, ODS, CSV and TSV viewer for the DSH dock workbench",
|
|
5
5
|
"keywords": ["deepseek-harness", "dsh", "dock", "spreadsheet", "xlsx", "csv", "viewer"],
|
|
6
6
|
"repository": {
|