@seed-hypermedia/client 0.0.113 → 0.0.115

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.
Files changed (43) hide show
  1. package/dist/auto-link.mjs +3 -3
  2. package/dist/blocks-to-markdown.mjs +3 -2
  3. package/dist/capability.mjs +2 -2
  4. package/dist/{chunk-UHAYFVBP.mjs → chunk-3LMBGHBE.mjs} +75 -5
  5. package/dist/{chunk-3P4J4WDY.mjs → chunk-54K7Z3BG.mjs} +1 -1
  6. package/dist/{chunk-KMACFX6U.mjs → chunk-BGWUWAFJ.mjs} +1 -1
  7. package/dist/{chunk-URLWDK7P.mjs → chunk-BZOAANTM.mjs} +1 -1
  8. package/dist/{chunk-2PRZIGCZ.mjs → chunk-DQMPCZVZ.mjs} +14 -5
  9. package/dist/chunk-HSDV6WEU.mjs +10 -0
  10. package/dist/{chunk-5VBVPSXD.mjs → chunk-HZQXXBOH.mjs} +2 -2
  11. package/dist/chunk-JELXCUZJ.mjs +49 -0
  12. package/dist/{chunk-3TERIXHU.mjs → chunk-LWCFLZRZ.mjs} +7 -30
  13. package/dist/{chunk-OXZCRYUS.mjs → chunk-MJFOPYAB.mjs} +1 -1
  14. package/dist/{chunk-YF2CLLSQ.mjs → chunk-MTJRBDF2.mjs} +3 -3
  15. package/dist/{chunk-AUKAVTTK.mjs → chunk-MZMGRUTQ.mjs} +1 -1
  16. package/dist/{chunk-YC433TGZ.mjs → chunk-QIKOXXTT.mjs} +1 -1
  17. package/dist/{chunk-GLY3UZ3W.mjs → chunk-UQWQXOBZ.mjs} +1 -1
  18. package/dist/{chunk-LQTTR4ZP.mjs → chunk-V2XTXDGG.mjs} +1 -1
  19. package/dist/{chunk-NLH5MKTK.mjs → chunk-ZVPHEP3X.mjs} +1 -1
  20. package/dist/client.mjs +2 -2
  21. package/dist/comment.mjs +2 -2
  22. package/dist/document-state.mjs +2 -2
  23. package/dist/editorblock-to-hmblock.mjs +2 -2
  24. package/dist/hm-resolver.d.ts +13 -0
  25. package/dist/hm-resolver.mjs +6 -2
  26. package/dist/hm-types.d.ts +5 -452
  27. package/dist/hm-types.mjs +1 -3
  28. package/dist/hmblock-to-editorblock.mjs +2 -2
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.mjs +20 -16
  31. package/dist/pdf-to-blocks.mjs +3 -3
  32. package/dist/resource-read.mjs +4 -4
  33. package/dist/schema-engine.mjs +2 -2
  34. package/dist/schema-registry.generated.mjs +1 -1
  35. package/dist/schema-resolve.mjs +4 -4
  36. package/dist/schema-subtypes.mjs +4 -4
  37. package/dist/schema-types.generated.d.ts +14 -5
  38. package/dist/signed-blob.mjs +2 -2
  39. package/dist/tei-to-blocks.mjs +2 -2
  40. package/dist/unicode.mjs +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-ALW35WVX.mjs +0 -75
  43. package/dist/chunk-MLR4UDOJ.mjs +0 -10
@@ -4,13 +4,13 @@ import {
4
4
  documentContainsLinkToChild,
5
5
  documentHasSelfQuery,
6
6
  shouldAutoLinkParent
7
- } from "./chunk-5VBVPSXD.mjs";
7
+ } from "./chunk-HZQXXBOH.mjs";
8
8
  import "./chunk-O5MHN2EO.mjs";
9
9
  import "./chunk-PJ2RFT5A.mjs";
10
- import "./chunk-KMACFX6U.mjs";
10
+ import "./chunk-BGWUWAFJ.mjs";
11
11
  import "./chunk-LVAHHQIK.mjs";
12
12
  import "./chunk-DR3HJ6BV.mjs";
13
- import "./chunk-3TERIXHU.mjs";
13
+ import "./chunk-LWCFLZRZ.mjs";
14
14
  import "./chunk-AHQWDCHV.mjs";
15
15
  import "./chunk-7P6ASYW6.mjs";
16
16
  export {
@@ -7,8 +7,9 @@ import {
7
7
  emitFrontmatter,
8
8
  parseDraftFilename,
9
9
  slugify
10
- } from "./chunk-2PRZIGCZ.mjs";
11
- import "./chunk-3TERIXHU.mjs";
10
+ } from "./chunk-DQMPCZVZ.mjs";
11
+ import "./chunk-3LMBGHBE.mjs";
12
+ import "./chunk-LWCFLZRZ.mjs";
12
13
  import "./chunk-AHQWDCHV.mjs";
13
14
  import "./chunk-7P6ASYW6.mjs";
14
15
  export {
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createCapability,
3
3
  resolveCapability
4
- } from "./chunk-LQTTR4ZP.mjs";
4
+ } from "./chunk-V2XTXDGG.mjs";
5
5
  import "./chunk-LVAHHQIK.mjs";
6
6
  import "./chunk-NBCHK76Q.mjs";
7
7
  import "./chunk-DR3HJ6BV.mjs";
8
- import "./chunk-3TERIXHU.mjs";
8
+ import "./chunk-LWCFLZRZ.mjs";
9
9
  import "./chunk-AHQWDCHV.mjs";
10
10
  import "./chunk-3TPCJCVO.mjs";
11
11
  import "./chunk-7P6ASYW6.mjs";
@@ -2,13 +2,22 @@ import {
2
2
  entityQueryPathToHmIdPath,
3
3
  parseFragment,
4
4
  unpackHmId
5
- } from "./chunk-3TERIXHU.mjs";
5
+ } from "./chunk-LWCFLZRZ.mjs";
6
6
  import {
7
7
  pageParamsFromUrl
8
8
  } from "./chunk-AHQWDCHV.mjs";
9
9
 
10
10
  // src/hm-resolver.ts
11
+ function hmDomainUrlToWebUrl(input) {
12
+ if (!input.startsWith("hm://")) return null;
13
+ const parsed = unpackHmId(input);
14
+ if (!(parsed == null ? void 0 : parsed.uid.includes("."))) return null;
15
+ const url = new URL(`https://${input.slice("hm://".length)}`);
16
+ if (url.username || url.password) throw new Error("Hypermedia domain URLs cannot contain credentials");
17
+ return url.href;
18
+ }
11
19
  async function resolveHypermediaUrl(url, opts) {
20
+ url = hmDomainUrlToWebUrl(url) || url;
12
21
  let latest = false;
13
22
  let blockRef = null;
14
23
  let blockRange = null;
@@ -132,10 +141,11 @@ async function resolveHypermediaUrl(url, opts) {
132
141
  return null;
133
142
  }
134
143
  async function resolveId(input, opts) {
135
- const parsed = unpackHmId(input);
144
+ const domainUrl = hmDomainUrlToWebUrl(input);
145
+ const parsed = domainUrl ? null : unpackHmId(input);
136
146
  if (parsed) return parsed;
137
- if (input.startsWith("http://") || input.startsWith("https://")) {
138
- const resolved = await resolveHypermediaUrl(input, opts);
147
+ if (domainUrl || input.startsWith("http://") || input.startsWith("https://")) {
148
+ const resolved = await resolveHypermediaUrl(domainUrl || input, opts);
139
149
  if (resolved == null ? void 0 : resolved.hmId) return resolved.hmId;
140
150
  throw new Error(`URL does not appear to be a Seed Hypermedia resource: ${input}`);
141
151
  }
@@ -203,8 +213,68 @@ function resolveProfilePath(siteUid, pathSegments) {
203
213
  path: [":profile"]
204
214
  };
205
215
  }
216
+ var COMMENT_VIEW_TERMS = /* @__PURE__ */ new Set([":comments", ":comment", ":discussions"]);
217
+ var COMMENT_PANEL_PREFIXES = /* @__PURE__ */ new Set(["comments", "comment", "discussions"]);
218
+ function extractCommentIdFromPanel(panel) {
219
+ if (!panel) return null;
220
+ const [viewTerm, first, second] = panel.split("/");
221
+ if (!viewTerm || !COMMENT_PANEL_PREFIXES.has(viewTerm)) return null;
222
+ if (first && second) return `${first}/${second}`;
223
+ return null;
224
+ }
225
+ function extractCommentIdFromPath(pathParts) {
226
+ if (pathParts.length >= 3) {
227
+ const thirdToLast = pathParts[pathParts.length - 3];
228
+ if (thirdToLast && COMMENT_VIEW_TERMS.has(thirdToLast)) {
229
+ return `${pathParts[pathParts.length - 2]}/${pathParts[pathParts.length - 1]}`;
230
+ }
231
+ }
232
+ if (pathParts.length >= 2) {
233
+ const secondToLast = pathParts[pathParts.length - 2];
234
+ if (secondToLast && COMMENT_VIEW_TERMS.has(secondToLast)) return pathParts[pathParts.length - 1] || null;
235
+ }
236
+ return null;
237
+ }
238
+ function parseReplyCommentId(reply) {
239
+ if (!reply) return null;
240
+ const [first, second] = reply.split("/");
241
+ if (first && second) return `${first}/${second}`;
242
+ return null;
243
+ }
244
+ function extractCommentIdFromUrl(url) {
245
+ const isWeb = url.startsWith("http://") || url.startsWith("https://");
246
+ let panelCommentId = null;
247
+ let pathCommentId = null;
248
+ let reply = null;
249
+ if (isWeb) {
250
+ let parsedUrl;
251
+ try {
252
+ parsedUrl = new URL(url);
253
+ } catch {
254
+ return null;
255
+ }
256
+ panelCommentId = extractCommentIdFromPanel(parsedUrl.searchParams.get("panel"));
257
+ reply = parseReplyCommentId(parsedUrl.searchParams.get("reply"));
258
+ const unpacked = unpackHmId(url);
259
+ const pathParts = (unpacked == null ? void 0 : unpacked.path) ?? parsedUrl.pathname.split("/").filter(Boolean);
260
+ pathCommentId = extractCommentIdFromPath(pathParts);
261
+ } else {
262
+ const [withoutHash] = url.split("#");
263
+ const [withoutQuery, queryString] = withoutHash.split("?");
264
+ const searchParams = new URLSearchParams(queryString);
265
+ panelCommentId = extractCommentIdFromPanel(searchParams.get("panel"));
266
+ reply = parseReplyCommentId(searchParams.get("reply"));
267
+ const parsed = unpackHmId(withoutQuery);
268
+ pathCommentId = (parsed == null ? void 0 : parsed.path) ? extractCommentIdFromPath(parsed.path) : null;
269
+ }
270
+ const threadCommentId = panelCommentId || pathCommentId;
271
+ if (!threadCommentId) return null;
272
+ return reply ?? threadCommentId;
273
+ }
206
274
 
207
275
  export {
276
+ hmDomainUrlToWebUrl,
208
277
  resolveHypermediaUrl,
209
- resolveId
278
+ resolveId,
279
+ extractCommentIdFromUrl
210
280
  };
@@ -7,7 +7,7 @@ import {
7
7
  codePointLength,
8
8
  parseHMQueryFiltersJSON,
9
9
  toNumber
10
- } from "./chunk-3TERIXHU.mjs";
10
+ } from "./chunk-LWCFLZRZ.mjs";
11
11
 
12
12
  // src/editorblock-to-hmblock.ts
13
13
  function toHMBlockType(editorBlockType) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  packHmId,
3
3
  unpackHmId
4
- } from "./chunk-3TERIXHU.mjs";
4
+ } from "./chunk-LWCFLZRZ.mjs";
5
5
 
6
6
  // src/document-state.ts
7
7
  async function resolveDocumentState(client, targetId) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getSupportedHMQueryFilters,
3
3
  isSurrogate
4
- } from "./chunk-3TERIXHU.mjs";
4
+ } from "./chunk-LWCFLZRZ.mjs";
5
5
 
6
6
  // src/hmblock-to-editorblock.ts
7
7
  function toEditorBlockType(hmBlockType) {
@@ -1,7 +1,10 @@
1
+ import {
2
+ resolveId
3
+ } from "./chunk-3LMBGHBE.mjs";
1
4
  import {
2
5
  normalizeQuerySort,
3
6
  unpackHmId
4
- } from "./chunk-3TERIXHU.mjs";
7
+ } from "./chunk-LWCFLZRZ.mjs";
5
8
 
6
9
  // src/blocks-to-markdown.ts
7
10
  import { stringify as stringifyYaml } from "yaml";
@@ -728,13 +731,20 @@ async function resolveInlineEmbed(ann, type, ctx) {
728
731
  return `[\u2197 ${fallbackLabel(link)}`;
729
732
  }
730
733
  }
734
+ async function resolveMarkdownReferenceId(link, ctx) {
735
+ return resolveId(link, {
736
+ domainResolver: async (domain) => {
737
+ const info = await ctx.client.request("GetDomain", { domain });
738
+ return info.registeredAccountUid ? { registeredAccountUid: info.registeredAccountUid, isGateway: info.isGateway } : null;
739
+ }
740
+ });
741
+ }
731
742
  async function resolveEmbeddedResource(link, ctx) {
732
743
  var _a, _b;
733
744
  const cacheKey = `embed:${link}`;
734
745
  const cached = ctx.cache.get(cacheKey);
735
746
  if (cached) return cached;
736
- const id = unpackHmId(link);
737
- if (!id) throw new Error("Invalid HM link");
747
+ const id = await resolveMarkdownReferenceId(link, ctx);
738
748
  const resource = await ctx.client.request("Resource", id);
739
749
  let resolved;
740
750
  if (resource.type === "document") {
@@ -771,8 +781,7 @@ async function resolveReference(link, ctx, mentionKind) {
771
781
  const cacheKey = `${mentionKind || "legacy"}:${link}`;
772
782
  const cached = ctx.cache.get(cacheKey);
773
783
  if (cached) return cached;
774
- const id = unpackHmId(link);
775
- if (!id) throw new Error("Invalid HM link");
784
+ const id = await resolveMarkdownReferenceId(link, ctx);
776
785
  let resolved;
777
786
  const profileAccountUid = ((_a = id.path) == null ? void 0 : _a[0]) === ":profile" ? id.path[1] || id.uid : !((_b = id.path) == null ? void 0 : _b.length) ? id.uid : null;
778
787
  if (profileAccountUid && mentionKind !== "document") {