@aiquants/markdown-explorer 0.36.0 → 0.37.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/CHANGELOG.md +72 -0
- package/README.md +74 -11
- package/dist/{EditSurface-BCFJRyIM.js → EditSurface-BQgwRUrR.js} +250 -245
- package/dist/EditSurface-Xvk5wZu7.cjs +6 -0
- package/dist/ExplorerSplit-C_3FChSt.cjs +2 -0
- package/dist/ExplorerSplit-C_kaEnyM.js +1619 -0
- package/dist/{MultiLayout-Bo9LAXiY.cjs → MultiLayout-BZNj1GYo.cjs} +1 -1
- package/dist/{MultiLayout-Dy5TIC2t.js → MultiLayout-DROxkTdD.js} +22 -22
- package/dist/{NativeScrollBar-Bj-LKej0.cjs → NativeScrollBar-BDF9A1sc.cjs} +1 -1
- package/dist/{NativeScrollBar-DpZMYhmf.js → NativeScrollBar-DvdOpwIW.js} +2 -2
- package/dist/{TreeLayout-DsSKW_Qj.js → TreeLayout-Cc-ykewY.js} +2 -2
- package/dist/{TreeLayout-T8sc_wg7.cjs → TreeLayout-D_DYV64_.cjs} +1 -1
- package/dist/client/MarkdownExplorer.d.cts +4 -5
- package/dist/client/MarkdownExplorer.d.ts +4 -5
- package/dist/client/hostContract.d.cts +1 -8
- package/dist/client/hostContract.d.ts +1 -8
- package/dist/core/labels.d.cts +0 -9
- package/dist/core/labels.d.ts +0 -9
- package/dist/explorerCore-DivWkFQF.cjs +1 -0
- package/dist/{explorerCore-B3RGmMG6.js → explorerCore-EkU0mwdW.js} +310 -308
- package/dist/index-BmOU3xcK.cjs +18 -0
- package/dist/{index-D0l_BJqb.js → index-dtjghDWY.js} +2451 -2434
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -55
- package/dist/{merge-Dckw7r9T.cjs → merge-BCFCL1cF.cjs} +1 -1
- package/dist/{merge-BwcqBd4c.js → merge-DC_h-t31.js} +1 -1
- package/dist/server/anonymous.d.cts +2 -2
- package/dist/server/anonymous.d.ts +2 -2
- package/dist/server/ports.d.cts +5 -2
- package/dist/server/ports.d.ts +5 -2
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +12 -12
- package/dist/serverCore.cjs +1 -1
- package/dist/serverCore.d.cts +1 -1
- package/dist/serverCore.d.ts +1 -1
- package/dist/serverCore.js +1 -1
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/{tapScrollCircle-smKLgRa2.js → tapScrollCircle-CqMZzWjo.js} +1 -1
- package/dist/{tapScrollCircle-DyLInGck.cjs → tapScrollCircle-DVNlszeF.cjs} +1 -1
- package/docs/behavior/dom-hooks.md +8 -1
- package/docs/behavior/hosting.md +1 -1
- package/docs/behavior/localization.md +2 -2
- package/docs/behavior/security.md +1 -1
- package/docs/behavior/url-contract.md +2 -2
- package/package.json +6 -4
- package/dist/EditSurface-B70iRFkG.cjs +0 -6
- package/dist/ExplorerSplit-BNrHrIus.cjs +0 -2
- package/dist/ExplorerSplit-Bgccz2nm.js +0 -1589
- package/dist/explorerCore-CUkyKtm8.cjs +0 -1
- package/dist/index-lpL7GltU.cjs +0 -18
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./index-BmOU3xcK.cjs"),e=require("./storage-BpYsprog.cjs"),E=require("./location-DrOP6t1F.cjs"),_=require("./ownUrls-BTPGNhBt.cjs");exports.DEFAULT_MARKDOWN_EXPLORER_LOCALE=L.DEFAULT_MARKDOWN_EXPLORER_LOCALE;exports.EXPLORER_HOST_CHANGE_POLICIES=L.EXPLORER_HOST_CHANGE_POLICIES;exports.EXPLORER_THEMES=L.EXPLORER_THEMES;exports.MARKDOWN_EXPLORER_LABEL_CATALOGS=L.MARKDOWN_EXPLORER_LABEL_CATALOGS;exports.MARKDOWN_EXPLORER_LABEL_KEYS=L.MARKDOWN_EXPLORER_LABEL_KEYS;exports.MARKDOWN_EXPLORER_LABEL_TEMPLATES=L.MARKDOWN_EXPLORER_LABEL_TEMPLATES;exports.MARKDOWN_EXPLORER_LOCALES=L.MARKDOWN_EXPLORER_LOCALES;exports.MarkdownExplorer=L.MarkdownExplorer;exports.draftAnswerOf=L.draftAnswerOf;exports.draftConversionOf=L.draftConversionOf;exports.resolveMarkdownExplorerLabels=L.resolveMarkdownExplorerLabels;exports.shouldRevalidateExplorer=L.shouldRevalidateExplorer;exports.clearExplorerStorage=e.clearExplorerStorage;exports.COLUMN_MIN_MEASURE=E.COLUMN_MIN_MEASURE;exports.DEFAULT_TREE_SETTINGS=E.DEFAULT_TREE_SETTINGS;exports.DEFAULT_VIEW_SLUGS=E.DEFAULT_VIEW_SLUGS;exports.EXPAND_ALL_DEPTH_LIMITS=E.EXPAND_ALL_DEPTH_LIMITS;exports.EXPAND_ALL_FOLDER_LIMITS=E.EXPAND_ALL_FOLDER_LIMITS;exports.EXPLORER_DEFAULT_PERCENT=E.EXPLORER_DEFAULT_PERCENT;exports.EXPLORER_MAX_PERCENT=E.EXPLORER_MAX_PERCENT;exports.EXPLORER_MIN_REM=E.EXPLORER_MIN_REM;exports.EXPLORER_MULTI_DEFAULT_PERCENT=E.EXPLORER_MULTI_DEFAULT_PERCENT;exports.GOLDEN_RATIO=E.GOLDEN_RATIO;exports.MULTI_VIEW_COLUMN_LIMITS=E.MULTI_VIEW_COLUMN_LIMITS;exports.MULTI_VIEW_PANEL_LIMITS=E.MULTI_VIEW_PANEL_LIMITS;exports.REVEAL_DOCUMENT_DEPTH_LIMITS=E.REVEAL_DOCUMENT_DEPTH_LIMITS;exports.SPREADSHEET_BYTE_LIMITS=E.SPREADSHEET_BYTE_LIMITS;exports.WORKBOOK_BYTE_LIMITS=E.WORKBOOK_BYTE_LIMITS;exports.defineExplorerConfig=E.defineExplorerConfig;exports.explorerHref=E.explorerHref;exports.isExplorerSourceId=E.isExplorerSourceId;exports.resolveExplorerLocation=E.resolveExplorerLocation;exports.withExplorerSources=E.withExplorerSources;exports.DEFAULT_DENIED_PATH_SEGMENTS=_.DEFAULT_DENIED_PATH_SEGMENTS;exports.DOCUMENT_ID_ALPHABET=_.DOCUMENT_ID_ALPHABET;exports.DOCUMENT_ID_LENGTH=_.DOCUMENT_ID_LENGTH;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_.EXPLORER_EDIT_TOKEN_MAX_LENGTH;exports.EXPLORER_FAILURE_REASONS=_.EXPLORER_FAILURE_REASONS;exports.EXPLORER_MAX_HEADINGS=_.EXPLORER_MAX_HEADINGS;exports.MAX_DOCUMENT_PATH_LENGTH=_.MAX_DOCUMENT_PATH_LENGTH;exports.failureDocument=_.failureDocument;exports.failureOf=_.failureOf;exports.groupDocumentId=_.groupDocumentId;exports.isAcceptableDocumentPath=_.isAcceptableDocumentPath;exports.isCanonicalDocumentId=_.isCanonicalDocumentId;exports.isDeniedPath=_.isDeniedPath;exports.isExplorerChildrenResult=_.isExplorerChildrenResult;exports.isExplorerDocumentLang=_.isExplorerDocumentLang;exports.isExplorerFailureCode=_.isExplorerFailureCode;exports.isExplorerFailureReason=_.isExplorerFailureReason;exports.parseDocumentId=_.parseDocumentId;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { LineEnding } from "./client/edit/lineEndings.cjs";
|
|
2
|
-
export {
|
|
2
|
+
export { EXPLORER_HOST_CHANGE_POLICIES, type ExplorerDraftChange, type ExplorerDraftRestore, type ExplorerHostChange, type ExplorerHostChangePolicy, type ExplorerMediaFailure, type ExplorerUnsavedDraft, type MarkdownExplorerHandle, } from "./client/hostContract.cjs";
|
|
3
3
|
export { type ExplorerFrameRenderer, MarkdownExplorer, type MarkdownExplorerProps } from "./client/MarkdownExplorer.cjs";
|
|
4
4
|
export { clearExplorerStorage } from "./client/storage.cjs";
|
|
5
5
|
export { DEFAULT_VIEW_SLUGS, defineExplorerConfig, EXPAND_ALL_DEPTH_LIMITS, EXPAND_ALL_FOLDER_LIMITS, type ExplorerConfig, type ExplorerConfigInput, type ExplorerDocumentStyle, type ExplorerLocationConfig, type ExplorerView, type ExplorerViewSlugs, isExplorerSourceId, MULTI_VIEW_COLUMN_LIMITS, MULTI_VIEW_PANEL_LIMITS, REVEAL_DOCUMENT_DEPTH_LIMITS, SPREADSHEET_BYTE_LIMITS, WORKBOOK_BYTE_LIMITS, withExplorerSources, } from "./core/config.cjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { LineEnding } from "./client/edit/lineEndings.js";
|
|
2
|
-
export {
|
|
2
|
+
export { EXPLORER_HOST_CHANGE_POLICIES, type ExplorerDraftChange, type ExplorerDraftRestore, type ExplorerHostChange, type ExplorerHostChangePolicy, type ExplorerMediaFailure, type ExplorerUnsavedDraft, type MarkdownExplorerHandle, } from "./client/hostContract.js";
|
|
3
3
|
export { type ExplorerFrameRenderer, MarkdownExplorer, type MarkdownExplorerProps } from "./client/MarkdownExplorer.js";
|
|
4
4
|
export { clearExplorerStorage } from "./client/storage.js";
|
|
5
5
|
export { DEFAULT_VIEW_SLUGS, defineExplorerConfig, EXPAND_ALL_DEPTH_LIMITS, EXPAND_ALL_FOLDER_LIMITS, type ExplorerConfig, type ExplorerConfigInput, type ExplorerDocumentStyle, type ExplorerLocationConfig, type ExplorerView, type ExplorerViewSlugs, isExplorerSourceId, MULTI_VIEW_COLUMN_LIMITS, MULTI_VIEW_PANEL_LIMITS, REVEAL_DOCUMENT_DEPTH_LIMITS, SPREADSHEET_BYTE_LIMITS, WORKBOOK_BYTE_LIMITS, withExplorerSources, } from "./core/config.js";
|
package/dist/index.js
CHANGED
|
@@ -1,58 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as
|
|
3
|
-
import { a0 as
|
|
4
|
-
import { D as
|
|
1
|
+
import { ak as _, al as s, am as L, an as e, ao as r, ap as R, aq as T, ar as o, as as A, at as O, au as I, av as D } from "./index-dtjghDWY.js";
|
|
2
|
+
import { c as N } from "./storage-D1uSw-xj.js";
|
|
3
|
+
import { a0 as S, a1 as l, a2 as i, a3 as n, a4 as p, I as t, H as X, a5 as C, J as U, R as x, a6 as u, a7 as c, a8 as d, a9 as f, aa as H, ab as m, e as F, i as G, h as K, w as W } from "./location-Dh6K-y7w.js";
|
|
4
|
+
import { D as B, ac as g, ad as v, ae as w, af as b, E as k, M as V, g as Y, k as j, Y as q, i as J, K as y, a as z, a2 as Q, b as Z, j as $, h as EE, T as aE } from "./ownUrls-DD0cSCsF.js";
|
|
5
5
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
S as COLUMN_MIN_MEASURE,
|
|
7
|
+
B as DEFAULT_DENIED_PATH_SEGMENTS,
|
|
8
8
|
_ as DEFAULT_MARKDOWN_EXPLORER_LOCALE,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
U as
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
r as
|
|
27
|
-
R as
|
|
28
|
-
T as
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
c as
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
H as
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
O as
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
j as
|
|
43
|
-
q as
|
|
44
|
-
J as
|
|
45
|
-
y as
|
|
46
|
-
z as
|
|
47
|
-
Q as
|
|
48
|
-
Z as
|
|
49
|
-
$ as
|
|
50
|
-
EE as
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
D as
|
|
56
|
-
|
|
57
|
-
h as withExplorerSources
|
|
9
|
+
l as DEFAULT_TREE_SETTINGS,
|
|
10
|
+
i as DEFAULT_VIEW_SLUGS,
|
|
11
|
+
g as DOCUMENT_ID_ALPHABET,
|
|
12
|
+
v as DOCUMENT_ID_LENGTH,
|
|
13
|
+
n as EXPAND_ALL_DEPTH_LIMITS,
|
|
14
|
+
p as EXPAND_ALL_FOLDER_LIMITS,
|
|
15
|
+
t as EXPLORER_DEFAULT_PERCENT,
|
|
16
|
+
w as EXPLORER_EDIT_TOKEN_MAX_LENGTH,
|
|
17
|
+
b as EXPLORER_FAILURE_REASONS,
|
|
18
|
+
s as EXPLORER_HOST_CHANGE_POLICIES,
|
|
19
|
+
k as EXPLORER_MAX_HEADINGS,
|
|
20
|
+
X as EXPLORER_MAX_PERCENT,
|
|
21
|
+
C as EXPLORER_MIN_REM,
|
|
22
|
+
U as EXPLORER_MULTI_DEFAULT_PERCENT,
|
|
23
|
+
L as EXPLORER_THEMES,
|
|
24
|
+
x as GOLDEN_RATIO,
|
|
25
|
+
e as MARKDOWN_EXPLORER_LABEL_CATALOGS,
|
|
26
|
+
r as MARKDOWN_EXPLORER_LABEL_KEYS,
|
|
27
|
+
R as MARKDOWN_EXPLORER_LABEL_TEMPLATES,
|
|
28
|
+
T as MARKDOWN_EXPLORER_LOCALES,
|
|
29
|
+
V as MAX_DOCUMENT_PATH_LENGTH,
|
|
30
|
+
u as MULTI_VIEW_COLUMN_LIMITS,
|
|
31
|
+
c as MULTI_VIEW_PANEL_LIMITS,
|
|
32
|
+
o as MarkdownExplorer,
|
|
33
|
+
d as REVEAL_DOCUMENT_DEPTH_LIMITS,
|
|
34
|
+
f as SPREADSHEET_BYTE_LIMITS,
|
|
35
|
+
H as WORKBOOK_BYTE_LIMITS,
|
|
36
|
+
N as clearExplorerStorage,
|
|
37
|
+
m as defineExplorerConfig,
|
|
38
|
+
A as draftAnswerOf,
|
|
39
|
+
O as draftConversionOf,
|
|
40
|
+
F as explorerHref,
|
|
41
|
+
Y as failureDocument,
|
|
42
|
+
j as failureOf,
|
|
43
|
+
q as groupDocumentId,
|
|
44
|
+
J as isAcceptableDocumentPath,
|
|
45
|
+
y as isCanonicalDocumentId,
|
|
46
|
+
z as isDeniedPath,
|
|
47
|
+
Q as isExplorerChildrenResult,
|
|
48
|
+
Z as isExplorerDocumentLang,
|
|
49
|
+
$ as isExplorerFailureCode,
|
|
50
|
+
EE as isExplorerFailureReason,
|
|
51
|
+
G as isExplorerSourceId,
|
|
52
|
+
aE as parseDocumentId,
|
|
53
|
+
K as resolveExplorerLocation,
|
|
54
|
+
I as resolveMarkdownExplorerLabels,
|
|
55
|
+
D as shouldRevalidateExplorer,
|
|
56
|
+
W as withExplorerSources
|
|
58
57
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node-diff3"),r=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node-diff3"),r=require("./index-BmOU3xcK.cjs"),R=(n,t,i,l)=>{if(t===n||t===i)return{kind:"clean",text:i};if(i===n)return{kind:"clean",text:t};const d=g.diff3Merge(t.split(`
|
|
2
2
|
`),n.split(`
|
|
3
3
|
`),i.split(`
|
|
4
4
|
`),{excludeFalseConflicts:!0}),o=[];let c=0;const u=s(l.ours),a=s(l.theirs);for(const e of d)e.ok!==void 0?o.push(...e.ok):e.conflict!==void 0&&(c+=1,o.push(`${r.CONFLICT_OURS_MARKER} ${u}`,...e.conflict.a,r.CONFLICT_SEPARATOR,...e.conflict.b,`${r.CONFLICT_THEIRS_MARKER} ${a}`));const f=o.join(`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { diff3Merge as d } from "node-diff3";
|
|
2
|
-
import { C, a as R, b as u } from "./index-
|
|
2
|
+
import { C, a as R, b as u } from "./index-dtjghDWY.js";
|
|
3
3
|
const g = (n, o, e, l) => {
|
|
4
4
|
if (o === n || o === e) return { kind: "clean", text: e };
|
|
5
5
|
if (e === n) return { kind: "clean", text: o };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ExplorerAuthentication, ExplorerAuthenticationMode } from "./ports.cjs";
|
|
1
|
+
import { ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerPageRouteArgs } from "./ports.cjs";
|
|
2
2
|
export type AnonymousPrincipal = {
|
|
3
3
|
readonly kind: "anonymous";
|
|
4
4
|
};
|
|
5
5
|
export type AnonymousAccess = {
|
|
6
6
|
readonly authenticate: (request: Request, mode: ExplorerAuthenticationMode) => Promise<ExplorerAuthentication<AnonymousPrincipal>>;
|
|
7
7
|
readonly principalKey: (principal: AnonymousPrincipal) => string;
|
|
8
|
-
readonly signedOutPage: (
|
|
8
|
+
readonly signedOutPage: (args: ExplorerPageRouteArgs, headers: Headers) => Response;
|
|
9
9
|
};
|
|
10
10
|
export declare const anonymousAccess: AnonymousAccess;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ExplorerAuthentication, ExplorerAuthenticationMode } from "./ports.js";
|
|
1
|
+
import { ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerPageRouteArgs } from "./ports.js";
|
|
2
2
|
export type AnonymousPrincipal = {
|
|
3
3
|
readonly kind: "anonymous";
|
|
4
4
|
};
|
|
5
5
|
export type AnonymousAccess = {
|
|
6
6
|
readonly authenticate: (request: Request, mode: ExplorerAuthenticationMode) => Promise<ExplorerAuthentication<AnonymousPrincipal>>;
|
|
7
7
|
readonly principalKey: (principal: AnonymousPrincipal) => string;
|
|
8
|
-
readonly signedOutPage: (
|
|
8
|
+
readonly signedOutPage: (args: ExplorerPageRouteArgs, headers: Headers) => Response;
|
|
9
9
|
};
|
|
10
10
|
export declare const anonymousAccess: AnonymousAccess;
|
package/dist/server/ports.d.cts
CHANGED
|
@@ -20,6 +20,10 @@ export type ExplorerAuthentication<P> = {
|
|
|
20
20
|
export type ExplorerAuthenticationMode = {
|
|
21
21
|
readonly readOnly: boolean;
|
|
22
22
|
};
|
|
23
|
+
export type ExplorerPageRouteArgs = {
|
|
24
|
+
readonly request: Request;
|
|
25
|
+
readonly url: URL;
|
|
26
|
+
};
|
|
23
27
|
export type ExplorerSourceContext<P> = {
|
|
24
28
|
readonly principal: P;
|
|
25
29
|
readonly request: Request;
|
|
@@ -164,8 +168,7 @@ export type ExplorerServerSharedConfig<P> = {
|
|
|
164
168
|
readonly sources: readonly ExplorerSource<P>[];
|
|
165
169
|
readonly document: (context: ExplorerSourceContext<P>, path: string, readPath: string) => Promise<ExplorerHostDocument>;
|
|
166
170
|
readonly asset: (context: ExplorerSourceContext<P>, path: string, readPath: string, options: ExplorerAssetOptions) => Promise<ExplorerAssetFile | ExplorerAssetRedirect>;
|
|
167
|
-
readonly signedOutPage: (
|
|
168
|
-
readonly forbiddenPage?: (request: Request, headers: Headers) => Response;
|
|
171
|
+
readonly signedOutPage: (args: ExplorerPageRouteArgs, headers: Headers) => Response;
|
|
169
172
|
readonly notices?: (context: ExplorerSourceContext<P>) => Promise<readonly ExplorerNotice[]>;
|
|
170
173
|
readonly deny?: ExplorerPathRules | false;
|
|
171
174
|
readonly treeCache?: {
|
package/dist/server/ports.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export type ExplorerAuthentication<P> = {
|
|
|
20
20
|
export type ExplorerAuthenticationMode = {
|
|
21
21
|
readonly readOnly: boolean;
|
|
22
22
|
};
|
|
23
|
+
export type ExplorerPageRouteArgs = {
|
|
24
|
+
readonly request: Request;
|
|
25
|
+
readonly url: URL;
|
|
26
|
+
};
|
|
23
27
|
export type ExplorerSourceContext<P> = {
|
|
24
28
|
readonly principal: P;
|
|
25
29
|
readonly request: Request;
|
|
@@ -164,8 +168,7 @@ export type ExplorerServerSharedConfig<P> = {
|
|
|
164
168
|
readonly sources: readonly ExplorerSource<P>[];
|
|
165
169
|
readonly document: (context: ExplorerSourceContext<P>, path: string, readPath: string) => Promise<ExplorerHostDocument>;
|
|
166
170
|
readonly asset: (context: ExplorerSourceContext<P>, path: string, readPath: string, options: ExplorerAssetOptions) => Promise<ExplorerAssetFile | ExplorerAssetRedirect>;
|
|
167
|
-
readonly signedOutPage: (
|
|
168
|
-
readonly forbiddenPage?: (request: Request, headers: Headers) => Response;
|
|
171
|
+
readonly signedOutPage: (args: ExplorerPageRouteArgs, headers: Headers) => Response;
|
|
169
172
|
readonly notices?: (context: ExplorerSourceContext<P>) => Promise<readonly ExplorerNotice[]>;
|
|
170
173
|
readonly deny?: ExplorerPathRules | false;
|
|
171
174
|
readonly treeCache?: {
|
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./ownUrls-BTPGNhBt.cjs"),v=require("./location-DrOP6t1F.cjs"),P=require("./explorerCore-CUkyKtm8.cjs"),ne=require("node:crypto"),ye=require("@aiquants/markdown/server"),N=require("node:fs"),S=require("node:path"),U=require("node:url"),O=require("./describeValue-Ccvhbt36.cjs"),i=require("./sanitizerService-DomN7lwC.cjs"),q=require("./lru-SGmUyBQU.cjs"),be=require("node:worker_threads"),R=require("node:fs/promises"),xe=require("node:stream");var G=typeof document<"u"?document.currentScript:null;const J=Object.freeze({kind:"anonymous"}),Se=Object.freeze({authenticate:async()=>({status:"signed-in",principal:J}),principalKey:()=>J.kind,signedOutPage:(e,t)=>new Response(null,{status:401,headers:t})}),ke=(e,t)=>{const r=new be.Worker(e,{resourceLimits:t});return{postMessage:o=>{r.postMessage(o)},terminate:()=>r.terminate(),ref:()=>{r.ref()},unref:()=>{r.unref()},listen:({message:o,failure:a})=>{r.on("message",o),r.on("error",a),r.on("messageerror",a),r.on("exit",p=>{a(new Error(`[markdown-explorer] a worker exited with code ${String(p)}`))})}}},Te=({url:e,size:t,deadlineMs:r,jobsPerScope:o,maxQueuedJobs:a,heapLimits:p})=>{i.assertPoolLimit("size",t,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("deadline",r,q.MAX_TIMER_MILLISECONDS),i.assertPoolLimit("jobsPerScope",o,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("maxQueuedJobs",a,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("maxOldGenerationSizeMb",p.maxOldGenerationSizeMb,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("maxYoungGenerationSizeMb",p.maxYoungGenerationSizeMb,Number.MAX_SAFE_INTEGER);const x=Object.freeze({maxOldGenerationSizeMb:p.maxOldGenerationSizeMb,maxYoungGenerationSizeMb:p.maxYoungGenerationSizeMb});return i.createWorkerPoolCore({start:()=>ke(e,x),size:t,deadlineMs:r,jobsPerScope:o,maxQueuedJobs:a})},_e=2,Oe=32,se=({workerHeapMb:e,maxHtmlBytes:t})=>i.htmlNodeBudgetOf(t,e),Ne=64,Me=1024*1024,ve=(e,t)=>{if(e!==void 0&&!O.isPlainObject(e))throw new TypeError("[markdown-explorer] sanitizer must be a plain object of { workers, deadlineMs, maxHtmlBytes, cacheBytes, workerHeapMb, jobsPerScope, maxQueuedJobs }");const{workers:r,deadlineMs:o,maxHtmlBytes:a,cacheBytes:p,workerHeapMb:x,jobsPerScope:l,maxQueuedJobs:w}=e??{},L=i.readLimit("workers",r,_e,Ne),I=i.readLimit("jobsPerScope",l,i.defaultSanitizerJobsPerScope(t,L),Number.MAX_SAFE_INTEGER),k=Object.freeze({workers:L,deadlineMs:i.readLimit("deadlineMs",o,i.DEFAULT_SANITIZER_DEADLINE_MS,q.MAX_TIMER_MILLISECONDS),maxHtmlBytes:i.readLimit("maxHtmlBytes",a,i.DEFAULT_SANITIZER_MAX_HTML_BYTES,i.MAX_HTML_BYTES),cacheBytes:i.readLimit("cacheBytes",p,i.DEFAULT_SANITIZER_CACHE_BYTES,Number.MAX_SAFE_INTEGER),workerHeapMb:i.readLimit("workerHeapMb",x,i.DEFAULT_SANITIZER_WORKER_HEAP_MB,Me),jobsPerScope:I,maxQueuedJobs:i.readLimit("maxQueuedJobs",w,i.SANITIZER_QUEUED_READERS*I,Number.MAX_SAFE_INTEGER)});if(i.assertAdmissionCoversPanels(k,t),se(k)<i.MIN_HTML_NODE_BUDGET)throw new RangeError(`[markdown-explorer] sanitizer.workerHeapMb (${String(k.workerHeapMb)} MiB) must leave room for ${String(i.MIN_HTML_NODE_BUDGET)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(k.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`);return k},Le=()=>{const e=typeof document>"u"?require("url").pathToFileURL(__filename).href:G&&G.tagName.toUpperCase()==="SCRIPT"&&G.src||new URL("server.cjs",document.baseURI).href,t=new URL(`./sanitizeWorker${S.extname(U.fileURLToPath(e))}`,e);if(!N.existsSync(U.fileURLToPath(t)))throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${U.fileURLToPath(t)}`);return t},Q=new Map,Ae=(e,t)=>{const r=[e.href,t.workers,t.deadlineMs,t.workerHeapMb,t.jobsPerScope,t.maxQueuedJobs].map(String).join("\0");let o=Q.get(r);return o===void 0&&(o=Te({url:e,size:t.workers,deadlineMs:t.deadlineMs,jobsPerScope:t.jobsPerScope,maxQueuedJobs:t.maxQueuedJobs,heapLimits:{maxOldGenerationSizeMb:t.workerHeapMb,maxYoungGenerationSizeMb:Oe}}),Q.set(r,o)),o},Re=e=>e instanceof Error&&e.code==="ERR_WORKER_OUT_OF_MEMORY",Pe=e=>({utf8Bytes:Buffer.byteLength(e,"utf8"),hash:ne.createHash("sha256").update(e,"utf8").digest("base64")}),Ie=e=>t=>Re(t)?{reason:"too-large",message:`[markdown-explorer] the HTML sanitizer ran out of its ${String(e)} MiB worker heap`}:null,Z=32,De=e=>{if(typeof e!="string")throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);if(e.length<Z)throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(Z)} characters; got ${String(e.length)}`);return e},je=({scopeSecret:e})=>Object.freeze({prepareScope:()=>{const r=De(e);return o=>ne.createHmac("sha256",r).update(o,"utf8").digest("base64url").slice(0,q.EXPLORER_SCOPE_LENGTH)},createSanitizer:({options:r,maxPanels:o,iframeHosts:a,dataPath:p,ownUrls:x})=>{const l=ve(r,o);return i.createHtmlSanitizerService({iframeHosts:a,dataPath:p,ownUrls:x,limits:l,nodeBudget:se(l),measureHtml:Pe,classifyCrash:Ie(l.workerHeapMb),pool:Ae(Le(),l)})},createLinkCardHandler:r=>ye.createLinkCardHandler(r)}),Be=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] the server configuration must be an object");const{scopeSecret:t,...r}=e;return P.createExplorerServer({...r,readSettings:o=>v.readCookieValue(o.headers.get("Cookie"),e.config.settingsCookie),assetMaxRangeBytes:null},je({scopeSecret:t}))},z=Object.freeze({maxEntries:2e4,maxDocumentBytes:2*1024*1024,textPreviewBytes:8*1024,walkConcurrency:8}),Ce=new Set(["md","markdown","mdx"]),ee="image/svg+xml",ae=new Map([...[["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"],["svg",ee],["webp","image/webp"],["ico","image/x-icon"],["bmp","image/bmp"],["tif","image/tiff"],["tiff","image/tiff"],["avif","image/avif"]].map(([e,t])=>[e,{kind:"image",imageType:t===ee?"svg":"raster",contentType:t}]),...[["mp4","video/mp4"],["m4v","video/mp4"],["webm","video/webm"],["mov","video/quicktime"],["avi","video/x-msvideo"],["mkv","video/x-matroska"],["ogv","video/ogg"]].map(([e,t])=>[e,{kind:"media",mediaType:"video",contentType:t}]),...[["mp3","audio/mpeg"],["wav","audio/wav"],["ogg","audio/ogg"],["oga","audio/ogg"],["opus","audio/ogg"],["m4a","audio/mp4"],["flac","audio/flac"],["aac","audio/aac"],["wma","audio/x-ms-wma"]].map(([e,t])=>[e,{kind:"media",mediaType:"audio",contentType:t}]),["pdf",{kind:"media",mediaType:"pdf",contentType:"application/pdf"}]]),ze=new Map([["csv","csv"],["tsv","tsv"],["tab","tsv"],["xlsx","workbook"],["xlsm","workbook"],["ods","workbook"]]),He=new Set(["txt","text","log","json","jsonc","json5","ndjson","yaml","yml","toml","ini","cfg","conf","properties","xml","xsl","xsd","dtd","html","htm","xhtml","css","scss","sass","less","styl","js","mjs","cjs","jsx","ts","mts","cts","tsx","vue","svelte","astro","py","pyi","rb","go","rs","java","kt","kts","scala","groovy","gradle","c","h","cc","cpp","cxx","hpp","hh","hxx","cs","fs","vb","swift","m","mm","php","pl","pm","r","jl","lua","dart","ex","exs","erl","hrl","hs","ml","mli","clj","cljs","elm","nim","zig","v","sol","tf","hcl","nix","sh","bash","zsh","fish","ps1","psm1","bat","cmd","sql","graphql","gql","proto","thrift","avsc","rst","adoc","asciidoc","tex","bib","org","textile","diff","patch","srt","vtt","ics","vcf","gitignore","gitattributes","editorconfig","dockerignore","npmignore","prettierrc","eslintrc","babelrc","mailmap"]),Fe=new Set(["readme","license","licence","copying","notice","authors","contributors","changelog","changes","todo","makefile","dockerfile","containerfile","procfile","gemfile","rakefile","vagrantfile","jenkinsfile","brewfile","codeowners"]),ie=typeof N.constants.O_NOFOLLOW=="number"?N.constants.O_NOFOLLOW:0,ce=typeof N.constants.O_NONBLOCK=="number"?N.constants.O_NONBLOCK:0,te=e=>`${e.size}-${e.mtimeNs}`,$e=e=>e!==""&&e!=="."&&e!==".."&&!e.includes(":")&&!e.endsWith(".")&&!e.endsWith(" "),re=e=>g.isAcceptableDocumentPath(e)&&e===e.normalize("NFC")&&e.split("/").every($e),le=e=>{const t=e.toLowerCase(),r=t.lastIndexOf(".");return r<0?"":t.slice(r+1)},Ue=e=>{const t=le(e);if(Ce.has(t))return{kind:"markdown"};const r=ae.get(t);if(r!==void 0)return r.kind==="image"?{kind:"image",imageType:r.imageType}:{kind:"media",mediaType:r.mediaType};const o=ze.get(t);if(o!==void 0)return{kind:"spreadsheet",format:o};const a=e.toLowerCase();return He.has(t)||!a.includes(".")&&Fe.has(a)?{kind:"text"}:{kind:"file"}},W=e=>{switch(typeof e=="object"&&e!==null?e.code:void 0){case"ENOENT":case"ENOTDIR":return"not-found";case"ELOOP":case"EACCES":case"EPERM":return"forbidden";case"ENAMETOOLONG":return"invalid";case"EISDIR":return"unsupported";default:return null}},de=e=>{const t=W(e);return t===null?e:new P.ExplorerError(t)},ue=e=>{const t=typeof e=="object"&&e!==null?e.code:void 0;return t==="EACCES"||t==="EPERM"||t==="ENOENT"||t==="ENOTDIR"},Ge=async e=>{try{return Math.trunc((await R.lstat(e)).mtimeMs)}catch(t){if(ue(t))return;throw t}},oe=async(e,t)=>{const r=[];for await(const o of e.createReadStream({start:0,end:t-1,autoClose:!1}))r.push(o);return Buffer.concat(r)},We=(e,t)=>e!==null?{start:e.offset,end:e.offset+e.length-1}:t===0n?{}:{start:0,end:Number(t)-1},qe=async(e,t,r,o)=>{let a;try{a=await R.open(e,N.constants.O_RDONLY|ie|ce);const w=await a.stat({bigint:!0});if(!w.isFile()||w.ino!==t.ino||w.dev!==t.dev||w.size!==t.size||w.mtimeNs!==t.mtimeNs)throw new P.ExplorerError("not-found")}catch(w){throw await a?.close(),de(w)}const p=a.createReadStream(We(r,t.size)),x=xe.Readable.toWeb(p),l=()=>{p.destroy(o.reason)};return o.aborted?l():o.addEventListener("abort",l,{once:!0}),x},Xe=(e,t)=>{const r=v.NAME_COLLATOR.compare(e,t);return r!==0?r:e===t?0:e<t?-1:1},Ye=e=>{let t=0;const r=[];return async o=>{t<e?t+=1:await new Promise(a=>r.push(a));try{return await o()}finally{const a=r.shift();a===void 0?t-=1:a()}}},Ve=(e,t)=>{if(e.isSymbolicLink())return"symbolic-link";if(!(e.isDirectory()||e.isFile()))return"special-file";const{name:r}=e;return r!==r.normalize("NFC")?"not-nfc":r.includes(":")?"colon":r.endsWith(".")||r.endsWith(" ")?"trailing-dot-or-space":g.isAcceptableDocumentPath(r)?g.isAcceptableDocumentPath(t)?null:"path-too-long":"control-character-or-backslash"},Ke=new Set(["id","label","root","pathPrefix","lang","parse","deny","maxEntries","maxDocumentBytes","textPreviewBytes","legacyTextEncoding","walkConcurrency","cacheScope","reportSkipped"]),H=(e,t,r)=>{if(t===void 0)return r;if(typeof t!="number"||!Number.isSafeInteger(t)||t<=0)throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${O.describeValue(t)}`);return t},Je=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");for(const n of Object.keys(e))if(!Ke.has(n))throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${O.describeValue(n)}`);const{id:t,label:r,root:o,parse:a}=e;if(typeof t!="string"||t==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");if(typeof r!="string"||r.trim()==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");if(typeof a!="function")throw new TypeError("[markdown-explorer] a file-system source needs a parse function");if(typeof o!="string"||!S.isAbsolute(o))throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${O.describeValue(o)}`);let p;try{p=N.statSync(o).isDirectory()}catch(n){throw new RangeError(`[markdown-explorer] root does not exist: ${o}`,{cause:n})}if(!p)throw new RangeError(`[markdown-explorer] root is not a directory: ${o}`);const x=N.realpathSync(o),l=e.pathPrefix;if(typeof l!="string")throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');if(l!==""&&!(l.endsWith("/")&&re(l.slice(0,-1))))throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${O.describeValue(l)}`);const w=e.lang;if(typeof w!="string")throw new TypeError('[markdown-explorer] lang is required: the language of the documents, a canonical BCP 47 language tag such as "ja" or "en-US"');if(!g.isExplorerDocumentLang(w))throw new RangeError(`[markdown-explorer] lang must be a canonical BCP 47 language tag (such as "ja" or "en-US"); got ${O.describeValue(w)}`);const L=g.resolvePathRules(e.deny),I=H("maxEntries",e.maxEntries,z.maxEntries),k=H("maxDocumentBytes",e.maxDocumentBytes,z.maxDocumentBytes),X=H("textPreviewBytes",e.textPreviewBytes,z.textPreviewBytes),D=e.legacyTextEncoding;if(D!=null&&typeof D!="string")throw new TypeError("[markdown-explorer] legacyTextEncoding must be a string or null");const Y=typeof D=="string"?v.legacyTextEncodingOf(D):null,me=H("walkConcurrency",e.walkConcurrency,z.walkConcurrency),B=e.cacheScope===void 0?"principal":e.cacheScope;if(B!=="principal"&&B!=="shared")throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${O.describeValue(B)}`);const C=e.reportSkipped;if(C!==void 0&&typeof C!="function")throw new TypeError("[markdown-explorer] reportSkipped must be a function");const fe=C===void 0?n=>{console.warn(`[markdown-explorer] the file-system source ${O.describeValue(n.sourceId)} does not list ${O.describeValue(n.path)}: ${n.reason}`)}:C,F=new Set,pe=n=>{const d=S.resolve(x,...n.split("/")),c=S.relative(x,d);return c===""||c===".."||c.startsWith(`..${S.sep}`)||S.isAbsolute(c)?null:d},V=(n,d)=>{const c=`${d}\0${n}`;F.has(c)||F.size>=I||(F.add(c),fe({sourceId:t,path:n,reason:d}))},we=async({signal:n})=>{n.throwIfAborted();const d=new AbortController,c=()=>{d.abort(n.reason)};n.addEventListener("abort",c,{once:!0});const m=Ye(me);let f=0;const h=async(s,y)=>{const b=await m(async()=>{d.signal.throwIfAborted();try{return await R.readdir(s,{withFileTypes:!0})}catch(u){if(y===""||!ue(u))throw u;return null}});if(d.signal.throwIfAborted(),b===null)return V(`${l}${y}`,"unreadable-directory"),null;const E=[];for(const u of b){if(L.deniesName(u.name))continue;const T=y===""?u.name:`${y}/${u.name}`,_=`${l}${T}`,M=Ve(u,_);if(M!==null){V(_,M);continue}E.push({dirent:u,relativePath:T,path:_})}if(f+=E.length,f>I)throw new P.ExplorerError("too-large");return E.sort((u,T)=>Xe(u.dirent.name,T.dirent.name)),(await Promise.all(E.map(async({dirent:u,relativePath:T,path:_})=>{const M=await Ge(S.join(s,u.name)),j=M===void 0?{}:{modifiedAt:M};if(!u.isDirectory())return{name:u.name,path:_,type:"file",...j};const K=await h(S.join(s,u.name),T);return K===null?null:{name:u.name,path:_,type:"directory",...j,children:K}}))).filter(u=>u!==null)};try{const s=await h(x,"");if(s===null)throw new Error("[markdown-explorer] the source's root could not be listed");return s}catch(s){throw d.abort(),s}finally{n.removeEventListener("abort",c)}},$=async n=>{if(!n.startsWith(l))return{status:"refused",reason:"not-found"};const d=n.slice(l.length);if(!re(d))return{status:"refused",reason:"invalid"};if(L.deniesPath(d))return{status:"refused",reason:"forbidden"};const c=pe(d);if(c===null)return{status:"refused",reason:"forbidden"};const m=await R.lstat(c,{bigint:!0});if(m.isSymbolicLink())return{status:"refused",reason:"forbidden"};if(!m.isFile())return{status:"refused",reason:"unsupported"};const f=await R.realpath(c);return f!==c||L.deniesPath(S.relative(x,f).split(S.sep).join("/"))?{status:"refused",reason:"forbidden"}:{status:"file",target:c,name:d.slice(d.lastIndexOf("/")+1),stats:m}},Ee=async(n,d,c)=>{let m;try{const f=await $(c);if(f.status==="refused")return g.failureDocument(f.reason);const{target:h,name:s,stats:y}=f,b=Ue(s),E=te(y);if(b.kind==="image")return{kind:"image",name:s,imageType:b.imageType,version:E};if(b.kind==="media")return{kind:"media",name:s,mediaType:b.mediaType,version:E};if(b.kind==="spreadsheet")return{kind:"spreadsheet",name:s,format:b.format,firstSheetText:null,edit:null,version:E};if(b.kind==="file")return{kind:"file",name:s,version:E};m=await R.open(h,N.constants.O_RDONLY|ie|ce);const A=await m.stat({bigint:!0});if(!A.isFile()||A.ino!==y.ino||A.dev!==y.dev)return g.failureDocument("forbidden");if(b.kind==="markdown"){if(A.size>BigInt(k))return g.failureDocument("too-large");const M=await oe(m,k+1);if(M.length>k)return g.failureDocument("too-large");const j=await a(v.decodeTextLeniently(M,!0,Y),d);return{kind:"markdown",name:s,htmlContent:j.htmlContent,headings:j.headings,lang:w,edit:null}}const u=await oe(m,X),T=A.size>BigInt(X),_=v.decodeTextLeniently(u,!T,Y);return _.includes("\0")?{kind:"file",name:s,version:E}:{kind:"text",name:s,text:_,truncated:T,lang:w,version:E}}catch(f){const h=W(f);if(h===null)throw f;return g.failureDocument(h)}finally{await m?.close()}},ge=async(n,d,c)=>{let m;try{m=await $(c)}catch(E){throw de(E)}if(m.status==="refused")throw new P.ExplorerError(m.reason);const{target:f,name:h,stats:s}=m,y=ae.get(le(h)),b=y===void 0?"":y.contentType;return{name:h,contentType:b,size:Number(s.size),version:te(s),open:E=>qe(f,s,E,n.signal)}},he=async(n,d,c)=>{let m;try{m=await $(c)}catch(s){if(W(s)!==null)return null;throw s}if(m.status==="refused")return null;const f=c.slice(l.length).split("/");if(f.some(s=>L.deniesName(s)))return null;const h=f.slice(0,-1);return h.map((s,y)=>`${l}${h.slice(0,y+1).join("/")}`)};return Object.freeze({id:t,label:r,cacheScope:B,boundary:Object.freeze({contains:n=>n.startsWith(l)}),tree:we,ancestors:he,document:Ee,asset:ge})};exports.DEFAULT_DENIED_PATH_SEGMENTS=g.DEFAULT_DENIED_PATH_SEGMENTS;exports.MAX_DOCUMENT_PATH_LENGTH=g.MAX_DOCUMENT_PATH_LENGTH;exports.isAcceptableDocumentPath=g.isAcceptableDocumentPath;exports.isDeniedPath=g.isDeniedPath;exports.decodeText=v.decodeText;exports.decodeTextLeniently=v.decodeTextLeniently;exports.legacyTextEncodingOf=v.legacyTextEncodingOf;exports.ExplorerError=P.ExplorerError;exports.anonymousAccess=Se;exports.createFileSystemSource=Je;exports.createMarkdownExplorer=Be;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./ownUrls-BTPGNhBt.cjs"),v=require("./location-DrOP6t1F.cjs"),P=require("./explorerCore-DivWkFQF.cjs"),ne=require("node:crypto"),ye=require("@aiquants/markdown/server"),N=require("node:fs"),S=require("node:path"),U=require("node:url"),O=require("./describeValue-Ccvhbt36.cjs"),i=require("./sanitizerService-DomN7lwC.cjs"),X=require("./lru-SGmUyBQU.cjs"),be=require("node:worker_threads"),R=require("node:fs/promises"),xe=require("node:stream");var G=typeof document<"u"?document.currentScript:null;const J=Object.freeze({kind:"anonymous"}),Se=Object.freeze({authenticate:async()=>({status:"signed-in",principal:J}),principalKey:()=>J.kind,signedOutPage:(e,t)=>new Response(null,{status:401,headers:t})}),ke=(e,t)=>{const r=new be.Worker(e,{resourceLimits:t});return{postMessage:o=>{r.postMessage(o)},terminate:()=>r.terminate(),ref:()=>{r.ref()},unref:()=>{r.unref()},listen:({message:o,failure:a})=>{r.on("message",o),r.on("error",a),r.on("messageerror",a),r.on("exit",p=>{a(new Error(`[markdown-explorer] a worker exited with code ${String(p)}`))})}}},Te=({url:e,size:t,deadlineMs:r,jobsPerScope:o,maxQueuedJobs:a,heapLimits:p})=>{i.assertPoolLimit("size",t,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("deadline",r,X.MAX_TIMER_MILLISECONDS),i.assertPoolLimit("jobsPerScope",o,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("maxQueuedJobs",a,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("maxOldGenerationSizeMb",p.maxOldGenerationSizeMb,Number.MAX_SAFE_INTEGER),i.assertPoolLimit("maxYoungGenerationSizeMb",p.maxYoungGenerationSizeMb,Number.MAX_SAFE_INTEGER);const x=Object.freeze({maxOldGenerationSizeMb:p.maxOldGenerationSizeMb,maxYoungGenerationSizeMb:p.maxYoungGenerationSizeMb});return i.createWorkerPoolCore({start:()=>ke(e,x),size:t,deadlineMs:r,jobsPerScope:o,maxQueuedJobs:a})},_e=2,Oe=32,se=({workerHeapMb:e,maxHtmlBytes:t})=>i.htmlNodeBudgetOf(t,e),Ne=64,Me=1024*1024,ve=(e,t)=>{if(e!==void 0&&!O.isPlainObject(e))throw new TypeError("[markdown-explorer] sanitizer must be a plain object of { workers, deadlineMs, maxHtmlBytes, cacheBytes, workerHeapMb, jobsPerScope, maxQueuedJobs }");const{workers:r,deadlineMs:o,maxHtmlBytes:a,cacheBytes:p,workerHeapMb:x,jobsPerScope:l,maxQueuedJobs:w}=e??{},L=i.readLimit("workers",r,_e,Ne),I=i.readLimit("jobsPerScope",l,i.defaultSanitizerJobsPerScope(t,L),Number.MAX_SAFE_INTEGER),k=Object.freeze({workers:L,deadlineMs:i.readLimit("deadlineMs",o,i.DEFAULT_SANITIZER_DEADLINE_MS,X.MAX_TIMER_MILLISECONDS),maxHtmlBytes:i.readLimit("maxHtmlBytes",a,i.DEFAULT_SANITIZER_MAX_HTML_BYTES,i.MAX_HTML_BYTES),cacheBytes:i.readLimit("cacheBytes",p,i.DEFAULT_SANITIZER_CACHE_BYTES,Number.MAX_SAFE_INTEGER),workerHeapMb:i.readLimit("workerHeapMb",x,i.DEFAULT_SANITIZER_WORKER_HEAP_MB,Me),jobsPerScope:I,maxQueuedJobs:i.readLimit("maxQueuedJobs",w,i.SANITIZER_QUEUED_READERS*I,Number.MAX_SAFE_INTEGER)});if(i.assertAdmissionCoversPanels(k,t),se(k)<i.MIN_HTML_NODE_BUDGET)throw new RangeError(`[markdown-explorer] sanitizer.workerHeapMb (${String(k.workerHeapMb)} MiB) must leave room for ${String(i.MIN_HTML_NODE_BUDGET)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(k.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`);return k},Le=()=>{const e=typeof document>"u"?require("url").pathToFileURL(__filename).href:G&&G.tagName.toUpperCase()==="SCRIPT"&&G.src||new URL("server.cjs",document.baseURI).href,t=new URL(`./sanitizeWorker${S.extname(U.fileURLToPath(e))}`,e);if(!N.existsSync(U.fileURLToPath(t)))throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${U.fileURLToPath(t)}`);return t},Q=new Map,Ae=(e,t)=>{const r=[e.href,t.workers,t.deadlineMs,t.workerHeapMb,t.jobsPerScope,t.maxQueuedJobs].map(String).join("\0");let o=Q.get(r);return o===void 0&&(o=Te({url:e,size:t.workers,deadlineMs:t.deadlineMs,jobsPerScope:t.jobsPerScope,maxQueuedJobs:t.maxQueuedJobs,heapLimits:{maxOldGenerationSizeMb:t.workerHeapMb,maxYoungGenerationSizeMb:Oe}}),Q.set(r,o)),o},Re=e=>e instanceof Error&&e.code==="ERR_WORKER_OUT_OF_MEMORY",Pe=e=>({utf8Bytes:Buffer.byteLength(e,"utf8"),hash:ne.createHash("sha256").update(e,"utf8").digest("base64")}),Ie=e=>t=>Re(t)?{reason:"too-large",message:`[markdown-explorer] the HTML sanitizer ran out of its ${String(e)} MiB worker heap`}:null,Z=32,De=e=>{if(typeof e!="string")throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);if(e.length<Z)throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(Z)} characters; got ${String(e.length)}`);return e},je=({scopeSecret:e})=>Object.freeze({prepareScope:()=>{const r=De(e);return o=>ne.createHmac("sha256",r).update(o,"utf8").digest("base64url").slice(0,X.EXPLORER_SCOPE_LENGTH)},createSanitizer:({options:r,maxPanels:o,iframeHosts:a,dataPath:p,ownUrls:x})=>{const l=ve(r,o);return i.createHtmlSanitizerService({iframeHosts:a,dataPath:p,ownUrls:x,limits:l,nodeBudget:se(l),measureHtml:Pe,classifyCrash:Ie(l.workerHeapMb),pool:Ae(Le(),l)})},createLinkCardHandler:r=>ye.createLinkCardHandler(r)}),Be=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] the server configuration must be an object");const{scopeSecret:t,...r}=e;return P.createExplorerServer({...r,readSettings:o=>v.readCookieValue(o.headers.get("Cookie"),e.config.settingsCookie),assetMaxRangeBytes:null},je({scopeSecret:t}))},z=Object.freeze({maxEntries:2e4,maxDocumentBytes:2*1024*1024,textPreviewBytes:8*1024,walkConcurrency:8}),Ce=new Set(["md","markdown","mdx"]),ee="image/svg+xml",ae=new Map([...[["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"],["svg",ee],["webp","image/webp"],["ico","image/x-icon"],["bmp","image/bmp"],["tif","image/tiff"],["tiff","image/tiff"],["avif","image/avif"]].map(([e,t])=>[e,{kind:"image",imageType:t===ee?"svg":"raster",contentType:t}]),...[["mp4","video/mp4"],["m4v","video/mp4"],["webm","video/webm"],["mov","video/quicktime"],["avi","video/x-msvideo"],["mkv","video/x-matroska"],["ogv","video/ogg"]].map(([e,t])=>[e,{kind:"media",mediaType:"video",contentType:t}]),...[["mp3","audio/mpeg"],["wav","audio/wav"],["ogg","audio/ogg"],["oga","audio/ogg"],["opus","audio/ogg"],["m4a","audio/mp4"],["flac","audio/flac"],["aac","audio/aac"],["wma","audio/x-ms-wma"]].map(([e,t])=>[e,{kind:"media",mediaType:"audio",contentType:t}]),["pdf",{kind:"media",mediaType:"pdf",contentType:"application/pdf"}]]),ze=new Map([["csv","csv"],["tsv","tsv"],["tab","tsv"],["xlsx","workbook"],["xlsm","workbook"],["ods","workbook"]]),He=new Set(["txt","text","log","json","jsonc","json5","ndjson","yaml","yml","toml","ini","cfg","conf","properties","xml","xsl","xsd","dtd","html","htm","xhtml","css","scss","sass","less","styl","js","mjs","cjs","jsx","ts","mts","cts","tsx","vue","svelte","astro","py","pyi","rb","go","rs","java","kt","kts","scala","groovy","gradle","c","h","cc","cpp","cxx","hpp","hh","hxx","cs","fs","vb","swift","m","mm","php","pl","pm","r","jl","lua","dart","ex","exs","erl","hrl","hs","ml","mli","clj","cljs","elm","nim","zig","v","sol","tf","hcl","nix","sh","bash","zsh","fish","ps1","psm1","bat","cmd","sql","graphql","gql","proto","thrift","avsc","rst","adoc","asciidoc","tex","bib","org","textile","diff","patch","srt","vtt","ics","vcf","gitignore","gitattributes","editorconfig","dockerignore","npmignore","prettierrc","eslintrc","babelrc","mailmap"]),Fe=new Set(["readme","license","licence","copying","notice","authors","contributors","changelog","changes","todo","makefile","dockerfile","containerfile","procfile","gemfile","rakefile","vagrantfile","jenkinsfile","brewfile","codeowners"]),ie=typeof N.constants.O_NOFOLLOW=="number"?N.constants.O_NOFOLLOW:0,ce=typeof N.constants.O_NONBLOCK=="number"?N.constants.O_NONBLOCK:0,te=e=>`${e.size}-${e.mtimeNs}`,$e=e=>e!==""&&e!=="."&&e!==".."&&!e.includes(":")&&!e.endsWith(".")&&!e.endsWith(" "),re=e=>g.isAcceptableDocumentPath(e)&&e===e.normalize("NFC")&&e.split("/").every($e),le=e=>{const t=e.toLowerCase(),r=t.lastIndexOf(".");return r<0?"":t.slice(r+1)},Ue=e=>{const t=le(e);if(Ce.has(t))return{kind:"markdown"};const r=ae.get(t);if(r!==void 0)return r.kind==="image"?{kind:"image",imageType:r.imageType}:{kind:"media",mediaType:r.mediaType};const o=ze.get(t);if(o!==void 0)return{kind:"spreadsheet",format:o};const a=e.toLowerCase();return He.has(t)||!a.includes(".")&&Fe.has(a)?{kind:"text"}:{kind:"file"}},W=e=>{switch(typeof e=="object"&&e!==null?e.code:void 0){case"ENOENT":case"ENOTDIR":return"not-found";case"ELOOP":case"EACCES":case"EPERM":return"forbidden";case"ENAMETOOLONG":return"invalid";case"EISDIR":return"unsupported";default:return null}},de=e=>{const t=W(e);return t===null?e:new P.ExplorerError(t)},ue=e=>{const t=typeof e=="object"&&e!==null?e.code:void 0;return t==="EACCES"||t==="EPERM"||t==="ENOENT"||t==="ENOTDIR"},Ge=async e=>{try{return Math.trunc((await R.lstat(e)).mtimeMs)}catch(t){if(ue(t))return;throw t}},oe=async(e,t)=>{const r=[];for await(const o of e.createReadStream({start:0,end:t-1,autoClose:!1}))r.push(o);return Buffer.concat(r)},We=(e,t)=>e!==null?{start:e.offset,end:e.offset+e.length-1}:t===0n?{}:{start:0,end:Number(t)-1},Xe=async(e,t,r,o)=>{let a;try{a=await R.open(e,N.constants.O_RDONLY|ie|ce);const w=await a.stat({bigint:!0});if(!w.isFile()||w.ino!==t.ino||w.dev!==t.dev||w.size!==t.size||w.mtimeNs!==t.mtimeNs)throw new P.ExplorerError("not-found")}catch(w){throw await a?.close(),de(w)}const p=a.createReadStream(We(r,t.size)),x=xe.Readable.toWeb(p),l=()=>{p.destroy(o.reason)};return o.aborted?l():o.addEventListener("abort",l,{once:!0}),x},qe=(e,t)=>{const r=v.NAME_COLLATOR.compare(e,t);return r!==0?r:e===t?0:e<t?-1:1},Ye=e=>{let t=0;const r=[];return async o=>{t<e?t+=1:await new Promise(a=>r.push(a));try{return await o()}finally{const a=r.shift();a===void 0?t-=1:a()}}},Ve=(e,t)=>{if(e.isSymbolicLink())return"symbolic-link";if(!(e.isDirectory()||e.isFile()))return"special-file";const{name:r}=e;return r!==r.normalize("NFC")?"not-nfc":r.includes(":")?"colon":r.endsWith(".")||r.endsWith(" ")?"trailing-dot-or-space":g.isAcceptableDocumentPath(r)?g.isAcceptableDocumentPath(t)?null:"path-too-long":"control-character-or-backslash"},Ke=new Set(["id","label","root","pathPrefix","lang","parse","deny","maxEntries","maxDocumentBytes","textPreviewBytes","legacyTextEncoding","walkConcurrency","cacheScope","reportSkipped"]),H=(e,t,r)=>{if(t===void 0)return r;if(typeof t!="number"||!Number.isSafeInteger(t)||t<=0)throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${O.describeValue(t)}`);return t},Je=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");for(const n of Object.keys(e))if(!Ke.has(n))throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${O.describeValue(n)}`);const{id:t,label:r,root:o,parse:a}=e;if(typeof t!="string"||t==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");if(typeof r!="string"||r.trim()==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");if(typeof a!="function")throw new TypeError("[markdown-explorer] a file-system source needs a parse function");if(typeof o!="string"||!S.isAbsolute(o))throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${O.describeValue(o)}`);let p;try{p=N.statSync(o).isDirectory()}catch(n){throw new RangeError(`[markdown-explorer] root does not exist: ${o}`,{cause:n})}if(!p)throw new RangeError(`[markdown-explorer] root is not a directory: ${o}`);const x=N.realpathSync(o),l=e.pathPrefix;if(typeof l!="string")throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');if(l!==""&&!(l.endsWith("/")&&re(l.slice(0,-1))))throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${O.describeValue(l)}`);const w=e.lang;if(typeof w!="string")throw new TypeError('[markdown-explorer] lang is required: the language of the documents, a canonical BCP 47 language tag such as "ja" or "en-US"');if(!g.isExplorerDocumentLang(w))throw new RangeError(`[markdown-explorer] lang must be a canonical BCP 47 language tag (such as "ja" or "en-US"); got ${O.describeValue(w)}`);const L=g.resolvePathRules(e.deny),I=H("maxEntries",e.maxEntries,z.maxEntries),k=H("maxDocumentBytes",e.maxDocumentBytes,z.maxDocumentBytes),q=H("textPreviewBytes",e.textPreviewBytes,z.textPreviewBytes),D=e.legacyTextEncoding;if(D!=null&&typeof D!="string")throw new TypeError("[markdown-explorer] legacyTextEncoding must be a string or null");const Y=typeof D=="string"?v.legacyTextEncodingOf(D):null,me=H("walkConcurrency",e.walkConcurrency,z.walkConcurrency),B=e.cacheScope===void 0?"principal":e.cacheScope;if(B!=="principal"&&B!=="shared")throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${O.describeValue(B)}`);const C=e.reportSkipped;if(C!==void 0&&typeof C!="function")throw new TypeError("[markdown-explorer] reportSkipped must be a function");const fe=C===void 0?n=>{console.warn(`[markdown-explorer] the file-system source ${O.describeValue(n.sourceId)} does not list ${O.describeValue(n.path)}: ${n.reason}`)}:C,F=new Set,pe=n=>{const d=S.resolve(x,...n.split("/")),c=S.relative(x,d);return c===""||c===".."||c.startsWith(`..${S.sep}`)||S.isAbsolute(c)?null:d},V=(n,d)=>{const c=`${d}\0${n}`;F.has(c)||F.size>=I||(F.add(c),fe({sourceId:t,path:n,reason:d}))},we=async({signal:n})=>{n.throwIfAborted();const d=new AbortController,c=()=>{d.abort(n.reason)};n.addEventListener("abort",c,{once:!0});const m=Ye(me);let f=0;const h=async(s,y)=>{const b=await m(async()=>{d.signal.throwIfAborted();try{return await R.readdir(s,{withFileTypes:!0})}catch(u){if(y===""||!ue(u))throw u;return null}});if(d.signal.throwIfAborted(),b===null)return V(`${l}${y}`,"unreadable-directory"),null;const E=[];for(const u of b){if(L.deniesName(u.name))continue;const T=y===""?u.name:`${y}/${u.name}`,_=`${l}${T}`,M=Ve(u,_);if(M!==null){V(_,M);continue}E.push({dirent:u,relativePath:T,path:_})}if(f+=E.length,f>I)throw new P.ExplorerError("too-large");return E.sort((u,T)=>qe(u.dirent.name,T.dirent.name)),(await Promise.all(E.map(async({dirent:u,relativePath:T,path:_})=>{const M=await Ge(S.join(s,u.name)),j=M===void 0?{}:{modifiedAt:M};if(!u.isDirectory())return{name:u.name,path:_,type:"file",...j};const K=await h(S.join(s,u.name),T);return K===null?null:{name:u.name,path:_,type:"directory",...j,children:K}}))).filter(u=>u!==null)};try{const s=await h(x,"");if(s===null)throw new Error("[markdown-explorer] the source's root could not be listed");return s}catch(s){throw d.abort(),s}finally{n.removeEventListener("abort",c)}},$=async n=>{if(!n.startsWith(l))return{status:"refused",reason:"not-found"};const d=n.slice(l.length);if(!re(d))return{status:"refused",reason:"invalid"};if(L.deniesPath(d))return{status:"refused",reason:"forbidden"};const c=pe(d);if(c===null)return{status:"refused",reason:"forbidden"};const m=await R.lstat(c,{bigint:!0});if(m.isSymbolicLink())return{status:"refused",reason:"forbidden"};if(!m.isFile())return{status:"refused",reason:"unsupported"};const f=await R.realpath(c);return f!==c||L.deniesPath(S.relative(x,f).split(S.sep).join("/"))?{status:"refused",reason:"forbidden"}:{status:"file",target:c,name:d.slice(d.lastIndexOf("/")+1),stats:m}},Ee=async(n,d,c)=>{let m;try{const f=await $(c);if(f.status==="refused")return g.failureDocument(f.reason);const{target:h,name:s,stats:y}=f,b=Ue(s),E=te(y);if(b.kind==="image")return{kind:"image",name:s,imageType:b.imageType,version:E};if(b.kind==="media")return{kind:"media",name:s,mediaType:b.mediaType,version:E};if(b.kind==="spreadsheet")return{kind:"spreadsheet",name:s,format:b.format,firstSheetText:null,edit:null,version:E};if(b.kind==="file")return{kind:"file",name:s,version:E};m=await R.open(h,N.constants.O_RDONLY|ie|ce);const A=await m.stat({bigint:!0});if(!A.isFile()||A.ino!==y.ino||A.dev!==y.dev)return g.failureDocument("forbidden");if(b.kind==="markdown"){if(A.size>BigInt(k))return g.failureDocument("too-large");const M=await oe(m,k+1);if(M.length>k)return g.failureDocument("too-large");const j=await a(v.decodeTextLeniently(M,!0,Y),d);return{kind:"markdown",name:s,htmlContent:j.htmlContent,headings:j.headings,lang:w,edit:null}}const u=await oe(m,q),T=A.size>BigInt(q),_=v.decodeTextLeniently(u,!T,Y);return _.includes("\0")?{kind:"file",name:s,version:E}:{kind:"text",name:s,text:_,truncated:T,lang:w,version:E}}catch(f){const h=W(f);if(h===null)throw f;return g.failureDocument(h)}finally{await m?.close()}},ge=async(n,d,c)=>{let m;try{m=await $(c)}catch(E){throw de(E)}if(m.status==="refused")throw new P.ExplorerError(m.reason);const{target:f,name:h,stats:s}=m,y=ae.get(le(h)),b=y===void 0?"":y.contentType;return{name:h,contentType:b,size:Number(s.size),version:te(s),open:E=>Xe(f,s,E,n.signal)}},he=async(n,d,c)=>{let m;try{m=await $(c)}catch(s){if(W(s)!==null)return null;throw s}if(m.status==="refused")return null;const f=c.slice(l.length).split("/");if(f.some(s=>L.deniesName(s)))return null;const h=f.slice(0,-1);return h.map((s,y)=>`${l}${h.slice(0,y+1).join("/")}`)};return Object.freeze({id:t,label:r,cacheScope:B,boundary:Object.freeze({contains:n=>n.startsWith(l)}),tree:we,ancestors:he,document:Ee,asset:ge})};exports.DEFAULT_DENIED_PATH_SEGMENTS=g.DEFAULT_DENIED_PATH_SEGMENTS;exports.MAX_DOCUMENT_PATH_LENGTH=g.MAX_DOCUMENT_PATH_LENGTH;exports.isAcceptableDocumentPath=g.isAcceptableDocumentPath;exports.isDeniedPath=g.isDeniedPath;exports.decodeText=v.decodeText;exports.decodeTextLeniently=v.decodeTextLeniently;exports.legacyTextEncodingOf=v.legacyTextEncodingOf;exports.ExplorerError=P.ExplorerError;exports.anonymousAccess=Se;exports.createFileSystemSource=Je;exports.createMarkdownExplorer=Be;
|
package/dist/server.d.cts
CHANGED
|
@@ -5,6 +5,6 @@ export { type AnonymousAccess, type AnonymousPrincipal, anonymousAccess } from "
|
|
|
5
5
|
export { createMarkdownExplorer } from "./server/createMarkdownExplorer.cjs";
|
|
6
6
|
export { ExplorerError, type ExplorerLogDetail, type ExplorerLogger, type ExplorerOperation } from "./server/errors.cjs";
|
|
7
7
|
export { createFileSystemSource, type FileSystemSkippedEntry, type FileSystemSkipReason, type FileSystemSource, type FileSystemSourceOptions } from "./server/fileSystemSource.cjs";
|
|
8
|
-
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, MarkdownExplorerServerConfig, } from "./server/ports.cjs";
|
|
8
|
+
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerPageRouteArgs, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, MarkdownExplorerServerConfig, } from "./server/ports.cjs";
|
|
9
9
|
export type { HtmlSanitizerOptions } from "./server/sanitizer.cjs";
|
|
10
10
|
export type { SanitizerLimitsInput } from "./server/sanitizerOptions.cjs";
|
package/dist/server.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export { type AnonymousAccess, type AnonymousPrincipal, anonymousAccess } from "
|
|
|
5
5
|
export { createMarkdownExplorer } from "./server/createMarkdownExplorer.js";
|
|
6
6
|
export { ExplorerError, type ExplorerLogDetail, type ExplorerLogger, type ExplorerOperation } from "./server/errors.js";
|
|
7
7
|
export { createFileSystemSource, type FileSystemSkippedEntry, type FileSystemSkipReason, type FileSystemSource, type FileSystemSourceOptions } from "./server/fileSystemSource.js";
|
|
8
|
-
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, MarkdownExplorerServerConfig, } from "./server/ports.js";
|
|
8
|
+
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerPageRouteArgs, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, MarkdownExplorerServerConfig, } from "./server/ports.js";
|
|
9
9
|
export type { HtmlSanitizerOptions } from "./server/sanitizer.js";
|
|
10
10
|
export type { SanitizerLimitsInput } from "./server/sanitizerOptions.js";
|
package/dist/server.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { b as Te, f as _e, i as $, g as I } from "./ownUrls-DD0cSCsF.js";
|
|
2
2
|
import { D as Yt, M as Kt, a as Jt } from "./ownUrls-DD0cSCsF.js";
|
|
3
3
|
import { r as Oe, l as Ne, b as K, N as Me } from "./location-Dh6K-y7w.js";
|
|
4
|
-
import { d as
|
|
5
|
-
import { c as ve, E as C } from "./explorerCore-
|
|
4
|
+
import { d as Zt } from "./location-Dh6K-y7w.js";
|
|
5
|
+
import { c as ve, E as C } from "./explorerCore-EkU0mwdW.js";
|
|
6
6
|
import { createHash as Re, createHmac as Ae } from "node:crypto";
|
|
7
7
|
import { createLinkCardHandler as Le } from "@aiquants/markdown/server";
|
|
8
8
|
import { existsSync as Ie, statSync as Pe, realpathSync as je, constants as v } from "node:fs";
|
|
9
|
-
import { extname as Be, isAbsolute as J, relative as Q, sep as
|
|
9
|
+
import { extname as Be, isAbsolute as J, relative as Q, sep as Z, join as q, resolve as ze } from "node:path";
|
|
10
10
|
import { fileURLToPath as F } from "node:url";
|
|
11
11
|
import { i as Ce, d as T } from "./describeValue-CLlVRO8d.js";
|
|
12
12
|
import { b as M, c as He, d as O, e as De, S as Fe, D as $e, f as Ge, M as We, g as Ue, j as Xe, k as Ye, l as V, h as Ke, a as Je } from "./sanitizerService-B8v4ap9t.js";
|
|
13
13
|
import { M as ie, E as Qe } from "./lru-DC8GBmkX.js";
|
|
14
|
-
import { Worker as
|
|
15
|
-
import { open as ce, lstat as le, realpath as
|
|
14
|
+
import { Worker as Ze } from "node:worker_threads";
|
|
15
|
+
import { open as ce, lstat as le, realpath as qe, readdir as Ve } from "node:fs/promises";
|
|
16
16
|
import { Readable as et } from "node:stream";
|
|
17
17
|
const ee = Object.freeze({ kind: "anonymous" }), $t = Object.freeze({
|
|
18
18
|
authenticate: async () => ({ status: "signed-in", principal: ee }),
|
|
19
19
|
principalKey: () => ee.kind,
|
|
20
20
|
signedOutPage: (e, t) => new Response(null, { status: 401, headers: t })
|
|
21
21
|
}), tt = (e, t) => {
|
|
22
|
-
const r = new
|
|
22
|
+
const r = new Ze(e, { resourceLimits: t });
|
|
23
23
|
return {
|
|
24
24
|
postMessage: (o) => {
|
|
25
25
|
r.postMessage(o);
|
|
@@ -404,7 +404,7 @@ const ee = Object.freeze({ kind: "anonymous" }), $t = Object.freeze({
|
|
|
404
404
|
console.warn(`[markdown-explorer] the file-system source ${T(n.sourceId)} does not list ${T(n.path)}: ${n.reason}`);
|
|
405
405
|
} : j, H = /* @__PURE__ */ new Set(), ye = (n) => {
|
|
406
406
|
const l = ze(y, ...n.split("/")), i = Q(y, l);
|
|
407
|
-
return i === "" || i === ".." || i.startsWith(`..${
|
|
407
|
+
return i === "" || i === ".." || i.startsWith(`..${Z}`) || J(i) ? null : l;
|
|
408
408
|
}, X = (n, l) => {
|
|
409
409
|
const i = `${l}\0${n}`;
|
|
410
410
|
H.has(i) || H.size >= R || (H.add(i), he({ sourceId: t, path: n, reason: l }));
|
|
@@ -441,9 +441,9 @@ const ee = Object.freeze({ kind: "anonymous" }), $t = Object.freeze({
|
|
|
441
441
|
if (u += w.length, u > R) throw new C("too-large");
|
|
442
442
|
return w.sort((d, k) => Tt(d.dirent.name, k.dirent.name)), (await Promise.all(
|
|
443
443
|
w.map(async ({ dirent: d, relativePath: k, path: x }) => {
|
|
444
|
-
const S = await kt(
|
|
444
|
+
const S = await kt(q(s, d.name)), L = S === void 0 ? {} : { modifiedAt: S };
|
|
445
445
|
if (!d.isDirectory()) return { name: d.name, path: x, type: "file", ...L };
|
|
446
|
-
const Y = await g(
|
|
446
|
+
const Y = await g(q(s, d.name), k);
|
|
447
447
|
return Y === null ? null : { name: d.name, path: x, type: "directory", ...L, children: Y };
|
|
448
448
|
})
|
|
449
449
|
)).filter((d) => d !== null);
|
|
@@ -467,8 +467,8 @@ const ee = Object.freeze({ kind: "anonymous" }), $t = Object.freeze({
|
|
|
467
467
|
const m = await le(i, { bigint: !0 });
|
|
468
468
|
if (m.isSymbolicLink()) return { status: "refused", reason: "forbidden" };
|
|
469
469
|
if (!m.isFile()) return { status: "refused", reason: "unsupported" };
|
|
470
|
-
const u = await
|
|
471
|
-
return u !== i || _.deniesPath(Q(y, u).split(
|
|
470
|
+
const u = await qe(i);
|
|
471
|
+
return u !== i || _.deniesPath(Q(y, u).split(Z).join("/")) ? { status: "refused", reason: "forbidden" } : { status: "file", target: i, name: l.slice(l.lastIndexOf("/") + 1), stats: m };
|
|
472
472
|
}, ke = async (n, l, i) => {
|
|
473
473
|
let m;
|
|
474
474
|
try {
|
|
@@ -540,7 +540,7 @@ export {
|
|
|
540
540
|
$t as anonymousAccess,
|
|
541
541
|
Wt as createFileSystemSource,
|
|
542
542
|
Gt as createMarkdownExplorer,
|
|
543
|
-
|
|
543
|
+
Zt as decodeText,
|
|
544
544
|
K as decodeTextLeniently,
|
|
545
545
|
$ as isAcceptableDocumentPath,
|
|
546
546
|
Jt as isDeniedPath,
|
package/dist/serverCore.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./location-DrOP6t1F.cjs"),c=require("./ownUrls-BTPGNhBt.cjs"),u=require("./explorerCore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./location-DrOP6t1F.cjs"),c=require("./ownUrls-BTPGNhBt.cjs"),u=require("./explorerCore-DivWkFQF.cjs"),x=require("react-router"),d=require("./describeValue-Ccvhbt36.cjs"),_=(i,e)=>new Promise((o,a)=>{const t=()=>a(e.reason);e.addEventListener("abort",t,{once:!0}),i.then(n=>{e.removeEventListener("abort",t),o(n)},n=>{e.removeEventListener("abort",t),a(n)}),e.aborted&&t()}),L=(i,{dataPath:e,pageAddress:o})=>{if(E.assertMountPath("dataPath",e),typeof o!="string")throw new TypeError(`[markdown-explorer] pageAddress must be a string; got ${d.describeValue(o)}`);if(!URL.canParse(e,o))throw new RangeError(`[markdown-explorer] pageAddress must be an absolute URL the data path resolves against; got ${d.describeValue(o)}`);const a=new URL(o),t=`${e}/`;return async(n,h)=>{const s=new Request(n instanceof Request?n:new URL(String(n),a),h);s.signal.throwIfAborted();const r=new URL(s.url);if(r.protocol!==a.protocol||r.host!==a.host||!r.pathname.startsWith(t))throw new TypeError(`[markdown-explorer] the in-process fetch answers only ${t}*; got ${r.protocol}//${r.host}${r.pathname}`);const T={request:s,url:r,pattern:`${e}/*`,params:{"*":r.pathname.slice(t.length)},context:new x.RouterContextProvider},p=s.method==="GET"||s.method==="HEAD",l=await _(p?i.dataLoader(T):i.dataAction(T),s.signal);return s.method==="HEAD"?new Response(null,{headers:l.headers,status:l.status,statusText:l.statusText}):l}};exports.decodeText=E.decodeText;exports.decodeTextLeniently=E.decodeTextLeniently;exports.isExplorerSourceId=E.isExplorerSourceId;exports.legacyTextEncodingOf=E.legacyTextEncodingOf;exports.DEFAULT_DENIED_PATH_SEGMENTS=c.DEFAULT_DENIED_PATH_SEGMENTS;exports.EXPLORER_MAX_HEADINGS=c.EXPLORER_MAX_HEADINGS;exports.MAX_DOCUMENT_PATH_LENGTH=c.MAX_DOCUMENT_PATH_LENGTH;exports.isAcceptableDocumentPath=c.isAcceptableDocumentPath;exports.isDeniedPath=c.isDeniedPath;exports.isExplorerDocumentLang=c.isExplorerDocumentLang;exports.ASSET_CONTENT_SECURITY_POLICIES=u.ASSET_CONTENT_SECURITY_POLICIES;exports.ExplorerError=u.ExplorerError;exports.createExplorerServer=u.createExplorerServer;exports.createInProcessDataFetch=L;
|
package/dist/serverCore.d.cts
CHANGED
|
@@ -9,6 +9,6 @@ export { ExplorerError, type ExplorerLogDetail, type ExplorerLogger, type Explor
|
|
|
9
9
|
export { createExplorerServer } from "./server/explorerCore.cjs";
|
|
10
10
|
export { createInProcessDataFetch } from "./server/inProcessFetch.cjs";
|
|
11
11
|
export type { ExplorerServerPlatform, SanitizerSetup } from "./server/platform.cjs";
|
|
12
|
-
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerServerCoreConfig, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, } from "./server/ports.cjs";
|
|
12
|
+
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerPageRouteArgs, ExplorerServerCoreConfig, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, } from "./server/ports.cjs";
|
|
13
13
|
export type { SanitizerLimitsInput } from "./server/sanitizerOptions.cjs";
|
|
14
14
|
export type { HtmlSanitizerService, SanitizedHtml, SanitizeRequest } from "./server/sanitizerService.cjs";
|
package/dist/serverCore.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ export { ExplorerError, type ExplorerLogDetail, type ExplorerLogger, type Explor
|
|
|
9
9
|
export { createExplorerServer } from "./server/explorerCore.js";
|
|
10
10
|
export { createInProcessDataFetch } from "./server/inProcessFetch.js";
|
|
11
11
|
export type { ExplorerServerPlatform, SanitizerSetup } from "./server/platform.js";
|
|
12
|
-
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerServerCoreConfig, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, } from "./server/ports.js";
|
|
12
|
+
export type { ExplorerAncestorsOptions, ExplorerAssetFile, ExplorerAssetOptions, ExplorerAssetRedirect, ExplorerAuthentication, ExplorerAuthenticationMode, ExplorerBoundaryAnswer, ExplorerByteRange, ExplorerDataPlan, ExplorerDocumentIdBinding, ExplorerDocumentIdIssue, ExplorerDocumentIdPorts, ExplorerEditPorts, ExplorerHostDocument, ExplorerHostEditSource, ExplorerHostPreview, ExplorerHostSaveDraft, ExplorerHostSaveResult, ExplorerPageLoaderResult, ExplorerPageRouteArgs, ExplorerServerCoreConfig, ExplorerServerSharedConfig, ExplorerSource, ExplorerSourceBoundary, ExplorerSourceContext, MarkdownExplorerServer, } from "./server/ports.js";
|
|
13
13
|
export type { SanitizerLimitsInput } from "./server/sanitizerOptions.js";
|
|
14
14
|
export type { HtmlSanitizerService, SanitizedHtml, SanitizeRequest } from "./server/sanitizerService.js";
|
package/dist/serverCore.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as l } from "./location-Dh6K-y7w.js";
|
|
2
2
|
import { d as R, b as A, i as D, l as _ } from "./location-Dh6K-y7w.js";
|
|
3
3
|
import { D as g, E as P, M as I, i as U, a as $, b as v } from "./ownUrls-DD0cSCsF.js";
|
|
4
|
-
import { A as N, E as H, c as M } from "./explorerCore-
|
|
4
|
+
import { A as N, E as H, c as M } from "./explorerCore-EkU0mwdW.js";
|
|
5
5
|
import { RouterContextProvider as d } from "react-router";
|
|
6
6
|
import { d as p } from "./describeValue-CLlVRO8d.js";
|
|
7
7
|
const u = (c, e) => new Promise((o, n) => {
|