@seed-hypermedia/client 0.0.103 → 0.0.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth.mjs +20 -2
- package/dist/{chunk-K5NYTWBJ.mjs → chunk-KKKXGVKJ.mjs} +17 -4
- package/dist/chunk-TGCGGVEU.mjs +58 -0
- package/dist/{chunk-7PB3EULG.mjs → chunk-UBBSVXFC.mjs} +20 -0
- package/dist/hmauth.d.ts +17 -0
- package/dist/hmauth.mjs +5 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +22 -10
- package/dist/markdown-to-blocks.d.ts +18 -2
- package/dist/markdown-to-blocks.mjs +3 -1
- package/dist/mermaid-parser.d.ts +14 -0
- package/dist/mermaid-parser.mjs +38 -0
- package/dist/mermaid-validation.d.ts +44 -0
- package/dist/mermaid-validation.mjs +13 -0
- package/package.json +1 -1
package/dist/auth.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
PARAM_CLIENT_ID,
|
|
3
3
|
PARAM_DATA,
|
|
4
4
|
PARAM_EMAIL,
|
|
5
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
5
6
|
PARAM_ERROR,
|
|
6
7
|
PARAM_PROOF,
|
|
7
8
|
PARAM_REDIRECT_URI,
|
|
@@ -9,9 +10,10 @@ import {
|
|
|
9
10
|
PARAM_SITE_NAME,
|
|
10
11
|
PARAM_STATE,
|
|
11
12
|
PARAM_TS,
|
|
13
|
+
parseEmailPrevalidation,
|
|
12
14
|
validateClientId,
|
|
13
15
|
validateRedirectUri
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-UBBSVXFC.mjs";
|
|
15
17
|
import {
|
|
16
18
|
decode,
|
|
17
19
|
encode
|
|
@@ -152,6 +154,7 @@ async function startAuth(config, options = {}) {
|
|
|
152
154
|
url.searchParams.set(PARAM_SESSION_KEY, session.principal);
|
|
153
155
|
url.searchParams.set(PARAM_STATE, authState);
|
|
154
156
|
url.searchParams.set(PARAM_TS, String(authStartTime));
|
|
157
|
+
if (config.requestEmailPrevalidation) url.searchParams.set(PARAM_EMAIL_PREVALIDATION, "1");
|
|
155
158
|
if (config.email) url.searchParams.set(PARAM_EMAIL, config.email);
|
|
156
159
|
if (config.siteName) url.searchParams.set(PARAM_SITE_NAME, config.siteName);
|
|
157
160
|
const signedUrl = url.toString();
|
|
@@ -161,6 +164,13 @@ async function startAuth(config, options = {}) {
|
|
|
161
164
|
}
|
|
162
165
|
async function handleCallback(config, options = {}) {
|
|
163
166
|
const url = new URL(window.location.href);
|
|
167
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
168
|
+
const emailProof = fragment.get(PARAM_EMAIL_PREVALIDATION);
|
|
169
|
+
if (fragment.has(PARAM_EMAIL_PREVALIDATION)) {
|
|
170
|
+
fragment.delete(PARAM_EMAIL_PREVALIDATION);
|
|
171
|
+
url.hash = fragment.toString();
|
|
172
|
+
window.history.replaceState(window.history.state, "", url.toString());
|
|
173
|
+
}
|
|
164
174
|
const dataParam = url.searchParams.get(PARAM_DATA);
|
|
165
175
|
const stateParam = url.searchParams.get(PARAM_STATE);
|
|
166
176
|
const error = url.searchParams.get(PARAM_ERROR);
|
|
@@ -221,13 +231,21 @@ async function handleCallback(config, options = {}) {
|
|
|
221
231
|
if (callbackData.profile && !principalEqual(callbackData.account, callbackData.profile.signer)) {
|
|
222
232
|
throw new Error("Callback account does not match profile signer");
|
|
223
233
|
}
|
|
234
|
+
let emailPrevalidation;
|
|
235
|
+
if (emailProof) {
|
|
236
|
+
try {
|
|
237
|
+
emailPrevalidation = parseEmailPrevalidation(decode2(decode(emailProof)), vaultUrl);
|
|
238
|
+
} catch {
|
|
239
|
+
}
|
|
240
|
+
}
|
|
224
241
|
await store.put(vaultUrl, { ...record, authState: null, authStartTime: null });
|
|
225
242
|
return {
|
|
226
243
|
accountPrincipal: principalToString(callbackData.account),
|
|
227
244
|
capability,
|
|
228
245
|
...profile ? { profile } : {},
|
|
229
246
|
session,
|
|
230
|
-
notifyServerUrl
|
|
247
|
+
notifyServerUrl,
|
|
248
|
+
...emailPrevalidation ? { emailPrevalidation } : {}
|
|
231
249
|
};
|
|
232
250
|
}
|
|
233
251
|
async function getSession(vaultUrl, options = {}) {
|
|
@@ -562,7 +562,13 @@ var METADATA_STRING_KEYS = [
|
|
|
562
562
|
"childrenType"
|
|
563
563
|
];
|
|
564
564
|
var METADATA_BOOLEAN_KEYS = ["showOutline", "showActivity"];
|
|
565
|
-
|
|
565
|
+
var MarkdownFrontmatterError = class extends Error {
|
|
566
|
+
constructor(message) {
|
|
567
|
+
super(message);
|
|
568
|
+
this.name = "MarkdownFrontmatterError";
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
function parseFrontmatter(markdown, options = {}) {
|
|
566
572
|
const trimmed = markdown.replace(/^/, "");
|
|
567
573
|
if (!trimmed.startsWith("---")) {
|
|
568
574
|
return { content: markdown, metadata: {} };
|
|
@@ -599,7 +605,13 @@ function parseFrontmatter(markdown) {
|
|
|
599
605
|
for (const key of METADATA_BOOLEAN_KEYS) {
|
|
600
606
|
if (metadata[key] !== void 0 && typeof metadata[key] !== "boolean") metadata[key] = Boolean(metadata[key]);
|
|
601
607
|
}
|
|
602
|
-
} catch {
|
|
608
|
+
} catch (error) {
|
|
609
|
+
if (options.strictFrontmatter !== false) {
|
|
610
|
+
const detail = (error instanceof Error ? error.message.split("\n")[0] : String(error)).replace(/:\s*$/, "");
|
|
611
|
+
throw new MarkdownFrontmatterError(
|
|
612
|
+
`Invalid YAML in frontmatter: ${detail}. Quote values that contain a colon, e.g. name: "A: B".`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
603
615
|
return { content: markdown, metadata: {} };
|
|
604
616
|
}
|
|
605
617
|
return { content: rest, metadata };
|
|
@@ -611,9 +623,9 @@ var IMAGE_START_RE = /^!\[/;
|
|
|
611
623
|
function startsSpecialBlock(rest) {
|
|
612
624
|
return HEADING_RE.test(rest) || FENCE_RE.test(rest) || rest.startsWith("$$") || IMAGE_START_RE.test(rest) || rest.startsWith("|") || STANDALONE_COMMENT_RE.test(rest) || END_RE.test(rest);
|
|
613
625
|
}
|
|
614
|
-
function parseMarkdown(markdown) {
|
|
626
|
+
function parseMarkdown(markdown, options = {}) {
|
|
615
627
|
var _a;
|
|
616
|
-
const { content, metadata } = parseFrontmatter(markdown);
|
|
628
|
+
const { content, metadata } = parseFrontmatter(markdown, options);
|
|
617
629
|
const lines = content.split("\n");
|
|
618
630
|
const infos = lines.map(analyzeLine);
|
|
619
631
|
const root = { list: [], childIndent: 0 };
|
|
@@ -894,6 +906,7 @@ export {
|
|
|
894
906
|
parseInlineFormatting,
|
|
895
907
|
hmAccountMentionUid,
|
|
896
908
|
mergeAdjacentAnnotations,
|
|
909
|
+
MarkdownFrontmatterError,
|
|
897
910
|
parseFrontmatter,
|
|
898
911
|
parseMarkdown,
|
|
899
912
|
markdownBlockNodesToHMBlockNodes,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/mermaid-validation.ts
|
|
2
|
+
var InvalidMermaidError = class extends Error {
|
|
3
|
+
errors;
|
|
4
|
+
constructor(errors) {
|
|
5
|
+
super(
|
|
6
|
+
`${errors.length === 1 ? "Invalid mermaid diagram" : `${errors.length} invalid mermaid diagrams`}: ` + errors.map((e) => `block ${e.blockId}: ${e.message}`).join("; ")
|
|
7
|
+
);
|
|
8
|
+
this.name = "InvalidMermaidError";
|
|
9
|
+
this.errors = errors;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function blockLanguage(block) {
|
|
13
|
+
if (typeof block.language === "string") return block.language;
|
|
14
|
+
const attr = block.attributes && block.attributes.language;
|
|
15
|
+
return typeof attr === "string" ? attr : void 0;
|
|
16
|
+
}
|
|
17
|
+
function collectMermaidBlocks(nodes) {
|
|
18
|
+
const out = [];
|
|
19
|
+
const walk = (list) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
for (const node of list) {
|
|
22
|
+
const { block } = node;
|
|
23
|
+
if (block.type === "Code" && ((_a = blockLanguage(block)) == null ? void 0 : _a.trim().toLowerCase()) === "mermaid") {
|
|
24
|
+
out.push({ blockId: block.id ?? "", source: block.text ?? "" });
|
|
25
|
+
}
|
|
26
|
+
if ((_b = node.children) == null ? void 0 : _b.length) walk(node.children);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
walk(nodes);
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
async function validateMermaidBlocks(nodes, parse) {
|
|
33
|
+
const errors = [];
|
|
34
|
+
for (const { blockId, source } of collectMermaidBlocks(nodes)) {
|
|
35
|
+
if (!source.trim()) {
|
|
36
|
+
errors.push({ blockId, message: "empty diagram" });
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
await parse(source);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
errors.push({ blockId, message: message.split("\n").slice(0, 3).join(" ").trim() });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return errors;
|
|
47
|
+
}
|
|
48
|
+
async function assertValidMermaid(nodes, parse) {
|
|
49
|
+
const errors = await validateMermaidBlocks(nodes, parse);
|
|
50
|
+
if (errors.length) throw new InvalidMermaidError(errors);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
InvalidMermaidError,
|
|
55
|
+
collectMermaidBlocks,
|
|
56
|
+
validateMermaidBlocks,
|
|
57
|
+
assertValidMermaid
|
|
58
|
+
};
|
|
@@ -14,6 +14,23 @@ import {
|
|
|
14
14
|
} from "./chunk-3TPCJCVO.mjs";
|
|
15
15
|
|
|
16
16
|
// src/hmauth.ts
|
|
17
|
+
function parseEmailPrevalidation(value, vaultUrl) {
|
|
18
|
+
if (!value || typeof value !== "object") return void 0;
|
|
19
|
+
const proof = value;
|
|
20
|
+
if (typeof proof.email !== "string" || !proof.email || typeof proof.host !== "string" || typeof proof.signer !== "string" || typeof proof.sig !== "string")
|
|
21
|
+
return void 0;
|
|
22
|
+
try {
|
|
23
|
+
if (proof.host !== new URL(vaultUrl).origin) return void 0;
|
|
24
|
+
const signer = decode(proof.signer);
|
|
25
|
+
const signature = decode(proof.sig);
|
|
26
|
+
if (signer.length !== ED25519_VARINT_PREFIX.length + 32 || !ED25519_VARINT_PREFIX.every((byte, index) => signer[index] === byte) || signature.length !== 64)
|
|
27
|
+
return void 0;
|
|
28
|
+
return { email: proof.email, host: proof.host, signer: proof.signer, sig: proof.sig };
|
|
29
|
+
} catch {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
var PARAM_EMAIL_PREVALIDATION = "email_prevalidation";
|
|
17
34
|
var PARAM_CLIENT_ID = "client_id";
|
|
18
35
|
var PARAM_REDIRECT_URI = "redirect_uri";
|
|
19
36
|
var PARAM_SESSION_KEY = "session_key";
|
|
@@ -189,6 +206,7 @@ function parseDelegationRequest(url) {
|
|
|
189
206
|
const siteName = parsedUrl.searchParams.get(PARAM_SITE_NAME) || void 0;
|
|
190
207
|
return {
|
|
191
208
|
originalUrl,
|
|
209
|
+
emailPrevalidation: parsedUrl.searchParams.get(PARAM_EMAIL_PREVALIDATION) === "1",
|
|
192
210
|
clientId,
|
|
193
211
|
redirectUri,
|
|
194
212
|
sessionKeyPrincipal: sessionKey,
|
|
@@ -264,6 +282,8 @@ async function createDelegation(issuer, sessionKeyPrincipal, clientId) {
|
|
|
264
282
|
}
|
|
265
283
|
|
|
266
284
|
export {
|
|
285
|
+
parseEmailPrevalidation,
|
|
286
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
267
287
|
PARAM_CLIENT_ID,
|
|
268
288
|
PARAM_REDIRECT_URI,
|
|
269
289
|
PARAM_SESSION_KEY,
|
package/dist/hmauth.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface HypermediaAuthConfig {
|
|
|
22
22
|
email?: string;
|
|
23
23
|
/** Optional display name of this site, shown in the vault's consent UI. */
|
|
24
24
|
siteName?: string;
|
|
25
|
+
/** Ask Vault to share verified email proof after consent. Disabled by default. */
|
|
26
|
+
requestEmailPrevalidation?: boolean;
|
|
25
27
|
}
|
|
26
28
|
/** Stored session key with metadata. */
|
|
27
29
|
export interface StoredSession {
|
|
@@ -56,7 +58,20 @@ export interface AuthResult {
|
|
|
56
58
|
session: StoredSession;
|
|
57
59
|
/** Notification server URL configured by the vault (optional). */
|
|
58
60
|
notifyServerUrl?: string;
|
|
61
|
+
/** Optional Vault email proof, delivered separately from public callback data. */
|
|
62
|
+
emailPrevalidation?: EmailPrevalidation;
|
|
59
63
|
}
|
|
64
|
+
/** Vault-signed email proof; the receiving service still verifies its signature and trusted issuer. */
|
|
65
|
+
export interface EmailPrevalidation {
|
|
66
|
+
email: string;
|
|
67
|
+
signer: string;
|
|
68
|
+
host: string;
|
|
69
|
+
sig: string;
|
|
70
|
+
}
|
|
71
|
+
/** Validate optional transported email proof without turning malformed metadata into a failed sign-in. */
|
|
72
|
+
export declare function parseEmailPrevalidation(value: unknown, vaultUrl: string): EmailPrevalidation | undefined;
|
|
73
|
+
/** Signed request opt-in and callback fragment key for private email proof transport. */
|
|
74
|
+
export declare const PARAM_EMAIL_PREVALIDATION = "email_prevalidation";
|
|
60
75
|
/** URL parameter name for the client ID (origin of the requesting site). */
|
|
61
76
|
export declare const PARAM_CLIENT_ID = "client_id";
|
|
62
77
|
/** URL parameter name for the redirect URI. */
|
|
@@ -87,6 +102,8 @@ export declare function principalDecode(principal: string): Uint8Array;
|
|
|
87
102
|
export interface DelegationRequest {
|
|
88
103
|
/** Original delegation request URL as received by the vault, including `proof`. */
|
|
89
104
|
originalUrl: string;
|
|
105
|
+
/** Client can consume email proof from the callback fragment without leaking it to HTTP requests. */
|
|
106
|
+
emailPrevalidation?: boolean;
|
|
90
107
|
/** The origin of the requesting site (must be HTTPS). e.g. "https://example.com". */
|
|
91
108
|
clientId: string;
|
|
92
109
|
/** Where to redirect after delegation. Must be a strict extension of clientId. */
|
package/dist/hmauth.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
PARAM_CLIENT_ID,
|
|
4
4
|
PARAM_DATA,
|
|
5
5
|
PARAM_EMAIL,
|
|
6
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
6
7
|
PARAM_ERROR,
|
|
7
8
|
PARAM_PROOF,
|
|
8
9
|
PARAM_REDIRECT_URI,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
buildCallbackUrl,
|
|
14
15
|
createDelegation,
|
|
15
16
|
parseDelegationRequest,
|
|
17
|
+
parseEmailPrevalidation,
|
|
16
18
|
principalDecode,
|
|
17
19
|
principalEncode,
|
|
18
20
|
validateClientId,
|
|
@@ -21,7 +23,7 @@ import {
|
|
|
21
23
|
validateSessionKeyPrincipal,
|
|
22
24
|
validateState,
|
|
23
25
|
verifyDelegationRequestProof
|
|
24
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-UBBSVXFC.mjs";
|
|
25
27
|
import "./chunk-2MD3FXKB.mjs";
|
|
26
28
|
import "./chunk-NBCHK76Q.mjs";
|
|
27
29
|
import "./chunk-DR3HJ6BV.mjs";
|
|
@@ -32,6 +34,7 @@ export {
|
|
|
32
34
|
PARAM_CLIENT_ID,
|
|
33
35
|
PARAM_DATA,
|
|
34
36
|
PARAM_EMAIL,
|
|
37
|
+
PARAM_EMAIL_PREVALIDATION,
|
|
35
38
|
PARAM_ERROR,
|
|
36
39
|
PARAM_PROOF,
|
|
37
40
|
PARAM_REDIRECT_URI,
|
|
@@ -42,6 +45,7 @@ export {
|
|
|
42
45
|
buildCallbackUrl,
|
|
43
46
|
createDelegation,
|
|
44
47
|
parseDelegationRequest,
|
|
48
|
+
parseEmailPrevalidation,
|
|
45
49
|
principalDecode,
|
|
46
50
|
principalEncode,
|
|
47
51
|
validateClientId,
|
package/dist/index.d.ts
CHANGED
|
@@ -31,8 +31,10 @@ export { resolveIdWithClient } from './resource-read';
|
|
|
31
31
|
export type { ResolveIdWithClientOptions, ResolvedIdWithClient } from './resource-read';
|
|
32
32
|
export { fileToIpfsBlobs, filesToIpfsBlobs, resolveFileLinksInBlocks, hasFileLinks } from './file-to-ipfs';
|
|
33
33
|
export type { CollectedBlob } from './file-to-ipfs';
|
|
34
|
-
export { parseMarkdown, flattenToOperations, parseInlineFormatting, parseFrontmatter, markdownBlockNodesToHMBlockNodes, hmAccountMentionUid, } from './markdown-to-blocks';
|
|
35
|
-
export type { BlockNode, SeedBlock, Annotation } from './markdown-to-blocks';
|
|
34
|
+
export { parseMarkdown, flattenToOperations, parseInlineFormatting, parseFrontmatter, markdownBlockNodesToHMBlockNodes, hmAccountMentionUid, MarkdownFrontmatterError, } from './markdown-to-blocks';
|
|
35
|
+
export type { BlockNode, SeedBlock, Annotation, ParseMarkdownOptions } from './markdown-to-blocks';
|
|
36
|
+
export { collectMermaidBlocks, validateMermaidBlocks, assertValidMermaid, InvalidMermaidError, } from './mermaid-validation';
|
|
37
|
+
export type { MermaidParser, MermaidDiagramError, MermaidBlockLike } from './mermaid-validation';
|
|
36
38
|
export { blocksToMarkdown, emitFrontmatter, slugify, draftFilename, parseDraftFilename, documentToResolvedMarkdown, commentToResolvedMarkdown, contentToResolvedMarkdown, } from './blocks-to-markdown';
|
|
37
39
|
export type { ResolvedMarkdownOptions } from './blocks-to-markdown';
|
|
38
40
|
export type { BlocksToMarkdownOptions } from './blocks-to-markdown';
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pdfToBlocks
|
|
3
|
+
} from "./chunk-NSNLRZ3X.mjs";
|
|
4
|
+
import {
|
|
5
|
+
teiToBlocks
|
|
6
|
+
} from "./chunk-GIKXPGFZ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
embeddedPdfToBlocks
|
|
9
|
+
} from "./chunk-2FJBS3V7.mjs";
|
|
1
10
|
import {
|
|
2
11
|
resolveIdWithClient
|
|
3
12
|
} from "./chunk-MHICVQJI.mjs";
|
|
@@ -10,22 +19,20 @@ import {
|
|
|
10
19
|
keyfile_exports
|
|
11
20
|
} from "./chunk-EY6RQVAP.mjs";
|
|
12
21
|
import {
|
|
22
|
+
MarkdownFrontmatterError,
|
|
13
23
|
flattenToOperations,
|
|
14
24
|
hmAccountMentionUid,
|
|
15
25
|
markdownBlockNodesToHMBlockNodes,
|
|
16
26
|
parseFrontmatter,
|
|
17
27
|
parseInlineFormatting,
|
|
18
28
|
parseMarkdown
|
|
19
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-KKKXGVKJ.mjs";
|
|
20
30
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import {
|
|
27
|
-
embeddedPdfToBlocks
|
|
28
|
-
} from "./chunk-2FJBS3V7.mjs";
|
|
31
|
+
InvalidMermaidError,
|
|
32
|
+
assertValidMermaid,
|
|
33
|
+
collectMermaidBlocks,
|
|
34
|
+
validateMermaidBlocks
|
|
35
|
+
} from "./chunk-TGCGGVEU.mjs";
|
|
29
36
|
import {
|
|
30
37
|
editorBlockToHMBlock,
|
|
31
38
|
editorBlocksToHMBlockNodes
|
|
@@ -155,14 +162,18 @@ export {
|
|
|
155
162
|
AnnotationSet,
|
|
156
163
|
DEFAULT_GROBID_URL,
|
|
157
164
|
HYPERMEDIA_SCHEME,
|
|
165
|
+
InvalidMermaidError,
|
|
166
|
+
MarkdownFrontmatterError,
|
|
158
167
|
SeedClientError,
|
|
159
168
|
SeedNetworkError,
|
|
160
169
|
SeedValidationError,
|
|
161
170
|
addSpanToAnnotation,
|
|
162
171
|
annotationContains,
|
|
172
|
+
assertValidMermaid,
|
|
163
173
|
autoLinkChildToParent,
|
|
164
174
|
blocksToMarkdown,
|
|
165
175
|
codePointLength,
|
|
176
|
+
collectMermaidBlocks,
|
|
166
177
|
commentRecordIdFromBlob,
|
|
167
178
|
commentToResolvedMarkdown,
|
|
168
179
|
computeReplaceOps,
|
|
@@ -245,5 +256,6 @@ export {
|
|
|
245
256
|
trimTrailingEmptyBlocks,
|
|
246
257
|
unpackHmId,
|
|
247
258
|
updateComment,
|
|
248
|
-
updateContact
|
|
259
|
+
updateContact,
|
|
260
|
+
validateMermaidBlocks
|
|
249
261
|
};
|
|
@@ -71,7 +71,23 @@ export type BlockComment = {
|
|
|
71
71
|
* and keys this client does not know (schema-typed documents carry their
|
|
72
72
|
* own). `title:` is accepted as a backward-compatible alias for `name:`.
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Thrown when a document starts with a `---` frontmatter block whose YAML does not parse.
|
|
76
|
+
* A silent fallthrough used to leave the whole block in the body as a paragraph, so the
|
|
77
|
+
* failure only surfaced to readers of the published document.
|
|
78
|
+
*/
|
|
79
|
+
export declare class MarkdownFrontmatterError extends Error {
|
|
80
|
+
constructor(message: string);
|
|
81
|
+
}
|
|
82
|
+
export type ParseMarkdownOptions = {
|
|
83
|
+
/**
|
|
84
|
+
* `true` (default) throws {@link MarkdownFrontmatterError} on invalid frontmatter YAML.
|
|
85
|
+
* `false` keeps the legacy behaviour of treating the block as body text, for display
|
|
86
|
+
* paths that must render whatever they are given.
|
|
87
|
+
*/
|
|
88
|
+
strictFrontmatter?: boolean;
|
|
89
|
+
};
|
|
90
|
+
export declare function parseFrontmatter(markdown: string, options?: ParseMarkdownOptions): {
|
|
75
91
|
content: string;
|
|
76
92
|
metadata: HMMetadata;
|
|
77
93
|
};
|
|
@@ -82,7 +98,7 @@ export declare function parseFrontmatter(markdown: string): {
|
|
|
82
98
|
* metadata and stripped from the content before tokenizing. Block IDs from
|
|
83
99
|
* `<!-- id:… -->` comments are preserved; absent ids are generated.
|
|
84
100
|
*/
|
|
85
|
-
export declare function parseMarkdown(markdown: string): {
|
|
101
|
+
export declare function parseMarkdown(markdown: string, options?: ParseMarkdownOptions): {
|
|
86
102
|
tree: BlockNode[];
|
|
87
103
|
metadata: HMMetadata;
|
|
88
104
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
MarkdownFrontmatterError,
|
|
2
3
|
flattenToOperations,
|
|
3
4
|
hmAccountMentionUid,
|
|
4
5
|
markdownBlockNodesToHMBlockNodes,
|
|
@@ -6,9 +7,10 @@ import {
|
|
|
6
7
|
parseFrontmatter,
|
|
7
8
|
parseInlineFormatting,
|
|
8
9
|
parseMarkdown
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-KKKXGVKJ.mjs";
|
|
10
11
|
import "./chunk-7P6ASYW6.mjs";
|
|
11
12
|
export {
|
|
13
|
+
MarkdownFrontmatterError,
|
|
12
14
|
flattenToOperations,
|
|
13
15
|
hmAccountMentionUid,
|
|
14
16
|
markdownBlockNodesToHMBlockNodes,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads mermaid's parser for {@link assertValidMermaid} in whatever runtime this runs in.
|
|
3
|
+
*
|
|
4
|
+
* Kept apart from `mermaid-validation.ts` so that importing the validator never pulls mermaid
|
|
5
|
+
* into a bundle. `mermaid` is a peer the caller installs; outside a browser a DOM shim is needed
|
|
6
|
+
* too (mermaid's sanitizer initialises against `window.document`), and `linkedom` is used when
|
|
7
|
+
* present. Both are imported dynamically with computed specifiers so bundlers leave them alone.
|
|
8
|
+
*/
|
|
9
|
+
import type { MermaidParser } from './mermaid-validation';
|
|
10
|
+
/**
|
|
11
|
+
* Returns a parser that rejects with mermaid's syntax error for invalid diagrams. The import is
|
|
12
|
+
* done once and shared; call sites pass the result to `assertValidMermaid`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadMermaidParser(): Promise<MermaidParser>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
2
|
+
|
|
3
|
+
// src/mermaid-parser.ts
|
|
4
|
+
var loader;
|
|
5
|
+
async function installDomShim() {
|
|
6
|
+
const g = globalThis;
|
|
7
|
+
if (typeof g.document !== "undefined") return;
|
|
8
|
+
const specifier = "linkedom";
|
|
9
|
+
const { parseHTML } = await import(
|
|
10
|
+
/* @vite-ignore */
|
|
11
|
+
specifier
|
|
12
|
+
);
|
|
13
|
+
const dom = parseHTML("<!doctype html><html><body></body></html>");
|
|
14
|
+
g.window = dom.window;
|
|
15
|
+
g.document = dom.document;
|
|
16
|
+
g.DOMParser = dom.DOMParser;
|
|
17
|
+
if (typeof g.navigator === "undefined") g.navigator = { userAgent: "node" };
|
|
18
|
+
}
|
|
19
|
+
function loadMermaidParser() {
|
|
20
|
+
if (!loader) {
|
|
21
|
+
loader = (async () => {
|
|
22
|
+
await installDomShim();
|
|
23
|
+
const specifier = "mermaid";
|
|
24
|
+
const mod = await import(
|
|
25
|
+
/* @vite-ignore */
|
|
26
|
+
specifier
|
|
27
|
+
);
|
|
28
|
+
return (source) => mod.default.parse(source);
|
|
29
|
+
})();
|
|
30
|
+
loader.catch(() => {
|
|
31
|
+
loader = void 0;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return loader;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
loadMermaidParser
|
|
38
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid diagram validation for Code blocks.
|
|
3
|
+
*
|
|
4
|
+
* A ```mermaid fence publishes as a Code block with `language: "mermaid"`. The viewer renders it
|
|
5
|
+
* with mermaid at read time, so a syntax error written today is only discovered by whoever opens
|
|
6
|
+
* the document. Writers (CLI, agents runtime, SDK users) call {@link assertValidMermaid} before
|
|
7
|
+
* publishing so the error lands on the author instead.
|
|
8
|
+
*
|
|
9
|
+
* This module has no dependency on mermaid itself: the parser is injected, because loading it
|
|
10
|
+
* differs per runtime (a browser has a DOM; Node and Bun need a shim). See `mermaid-parser.ts`
|
|
11
|
+
* for the loader used by the CLI and the agents runtime.
|
|
12
|
+
*/
|
|
13
|
+
/** Resolves when the source parses; rejects with mermaid's syntax error otherwise. */
|
|
14
|
+
export type MermaidParser = (source: string) => Promise<unknown>;
|
|
15
|
+
export type MermaidDiagramError = {
|
|
16
|
+
blockId: string;
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
|
19
|
+
/** The subset of a block node this module reads; both the parser tree and the API shape satisfy it. */
|
|
20
|
+
export type MermaidBlockLike = {
|
|
21
|
+
block: {
|
|
22
|
+
id?: string;
|
|
23
|
+
type: string;
|
|
24
|
+
text?: string;
|
|
25
|
+
language?: string;
|
|
26
|
+
attributes?: {
|
|
27
|
+
language?: string;
|
|
28
|
+
} | Record<string, unknown>;
|
|
29
|
+
};
|
|
30
|
+
children?: MermaidBlockLike[];
|
|
31
|
+
};
|
|
32
|
+
export declare class InvalidMermaidError extends Error {
|
|
33
|
+
readonly errors: MermaidDiagramError[];
|
|
34
|
+
constructor(errors: MermaidDiagramError[]);
|
|
35
|
+
}
|
|
36
|
+
/** Every Code block whose language is `mermaid`, in document order, with its source text. */
|
|
37
|
+
export declare function collectMermaidBlocks(nodes: MermaidBlockLike[]): Array<{
|
|
38
|
+
blockId: string;
|
|
39
|
+
source: string;
|
|
40
|
+
}>;
|
|
41
|
+
/** Parses every mermaid block with `parse` and returns the failures (empty when all are valid). */
|
|
42
|
+
export declare function validateMermaidBlocks(nodes: MermaidBlockLike[], parse: MermaidParser): Promise<MermaidDiagramError[]>;
|
|
43
|
+
/** Throws {@link InvalidMermaidError} when any mermaid block in `nodes` fails to parse. */
|
|
44
|
+
export declare function assertValidMermaid(nodes: MermaidBlockLike[], parse: MermaidParser): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InvalidMermaidError,
|
|
3
|
+
assertValidMermaid,
|
|
4
|
+
collectMermaidBlocks,
|
|
5
|
+
validateMermaidBlocks
|
|
6
|
+
} from "./chunk-TGCGGVEU.mjs";
|
|
7
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
8
|
+
export {
|
|
9
|
+
InvalidMermaidError,
|
|
10
|
+
assertValidMermaid,
|
|
11
|
+
collectMermaidBlocks,
|
|
12
|
+
validateMermaidBlocks
|
|
13
|
+
};
|