@seed-hypermedia/client 0.0.68 → 0.0.69

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 (72) hide show
  1. package/LICENSE +201 -0
  2. package/dist/auth.d.ts +79 -0
  3. package/dist/auth.mjs +265 -0
  4. package/dist/auto-link.mjs +20 -0
  5. package/dist/base64.mjs +9 -0
  6. package/dist/blobs.d.ts +168 -0
  7. package/dist/blobs.mjs +50 -0
  8. package/dist/block-diff.mjs +17 -0
  9. package/dist/blocks-to-markdown.mjs +22 -0
  10. package/dist/capability.mjs +11 -0
  11. package/dist/cbor.d.ts +13 -0
  12. package/dist/cbor.mjs +13 -0
  13. package/dist/change.mjs +23 -0
  14. package/dist/chunk-2MD3FXKB.mjs +14 -0
  15. package/dist/chunk-3TPCJCVO.mjs +24 -0
  16. package/dist/chunk-52P3E6H6.mjs +459 -0
  17. package/dist/{chunk-KCR3277A.mjs → chunk-5EWV4OPF.mjs} +1 -1
  18. package/dist/chunk-CBELM7KX.mjs +29 -0
  19. package/dist/chunk-DXDF36H5.mjs +289 -0
  20. package/dist/chunk-EY6RQVAP.mjs +138 -0
  21. package/dist/chunk-FYUZZ3HT.mjs +199 -0
  22. package/dist/chunk-GKGWSN6J.mjs +75 -0
  23. package/dist/chunk-H7L4TI6X.mjs +705 -0
  24. package/dist/chunk-HBIVZA6C.mjs +102 -0
  25. package/dist/chunk-I3YUHKYW.mjs +135 -0
  26. package/dist/chunk-KO4XH5L2.mjs +475 -0
  27. package/dist/chunk-LYECQKZE.mjs +49 -0
  28. package/dist/chunk-MKUWQB5W.mjs +297 -0
  29. package/dist/chunk-N3P7S5YZ.mjs +118 -0
  30. package/dist/chunk-NPG76WUS.mjs +348 -0
  31. package/dist/chunk-NX7YFFRX.mjs +124 -0
  32. package/dist/chunk-OZKQOI2X.mjs +334 -0
  33. package/dist/chunk-PPAY4WZX.mjs +40 -0
  34. package/dist/chunk-QS7TPMYT.mjs +411 -0
  35. package/dist/chunk-S2PVJK2P.mjs +517 -0
  36. package/dist/chunk-T5BTAJPW.mjs +725 -0
  37. package/dist/{chunk-EGCUJ6D6.mjs → chunk-UOL3F6XQ.mjs} +0 -12
  38. package/dist/chunk-VN7F33SS.mjs +108 -0
  39. package/dist/chunk-W4OGV22Y.mjs +57 -0
  40. package/dist/chunk-WJQSJ6UM.mjs +159 -0
  41. package/dist/chunk-XI2LXZM7.mjs +112 -0
  42. package/dist/chunk-YNVFRCUH.mjs +171 -0
  43. package/dist/chunk-YZX54L3G.mjs +33 -0
  44. package/dist/client.mjs +14 -0
  45. package/dist/comment.mjs +18 -0
  46. package/dist/contact.mjs +14 -0
  47. package/dist/document-state.mjs +8 -0
  48. package/dist/editor-types.mjs +0 -0
  49. package/dist/editorblock-to-hmblock.mjs +11 -0
  50. package/dist/encryption.mjs +13 -0
  51. package/dist/errors.mjs +11 -0
  52. package/dist/file-to-ipfs.mjs +13 -0
  53. package/dist/grobid.mjs +11 -0
  54. package/dist/hm-resolver.mjs +10 -0
  55. package/dist/hm-types.d.ts +566 -566
  56. package/dist/hmauth.d.ts +169 -0
  57. package/dist/hmauth.mjs +52 -0
  58. package/dist/hmblock-to-editorblock.mjs +12 -0
  59. package/dist/index.mjs +124 -5453
  60. package/dist/keyfile.mjs +19 -0
  61. package/dist/markdown-to-blocks.mjs +15 -0
  62. package/dist/pdf-to-blocks-embedded.mjs +7 -0
  63. package/dist/pdf-to-blocks.mjs +11 -0
  64. package/dist/ref.mjs +12 -0
  65. package/dist/resource-read.mjs +14 -0
  66. package/dist/signing.mjs +13 -0
  67. package/dist/tei-to-blocks.mjs +8 -0
  68. package/dist/unicode.mjs +19 -0
  69. package/dist/vault-local.mjs +7 -6
  70. package/dist/vault.mjs +3 -2
  71. package/package.json +18 -28
  72. package/src/index.ts +0 -144
@@ -2,16 +2,6 @@ import {
2
2
  __export
3
3
  } from "./chunk-7P6ASYW6.mjs";
4
4
 
5
- // src/base64.ts
6
- import "core-js/modules/es.uint8-array.from-base64.js";
7
- import "core-js/modules/es.uint8-array.to-base64.js";
8
- function encode(data) {
9
- return data.toBase64({ alphabet: "base64url", omitPadding: true });
10
- }
11
- function decode(data) {
12
- return Uint8Array.fromBase64(data, { alphabet: "base64url" });
13
- }
14
-
15
5
  // src/encryption.ts
16
6
  var encryption_exports = {};
17
7
  __export(encryption_exports, {
@@ -55,8 +45,6 @@ async function decrypt(data, key) {
55
45
  }
56
46
 
57
47
  export {
58
- encode,
59
- decode,
60
48
  DEFAULT_PARAMS,
61
49
  deriveKeyFromPassword,
62
50
  encrypt,
@@ -0,0 +1,108 @@
1
+ // src/file-to-ipfs.ts
2
+ import { MemoryBlockstore } from "blockstore-core/memory";
3
+ import { importer as unixFSImporter } from "ipfs-unixfs-importer";
4
+ async function fileToIpfsBlobs(data) {
5
+ const blockstore = new MemoryBlockstore();
6
+ const results = unixFSImporter([{ content: data }], blockstore);
7
+ const result = await results.next();
8
+ if (!result.value) {
9
+ throw new Error("Failed to chunk file into IPFS blocks");
10
+ }
11
+ const rootCid = result.value.cid.toString();
12
+ const blobs = [];
13
+ for await (const pair of blockstore.getAll()) {
14
+ blobs.push({
15
+ cid: pair.cid.toString(),
16
+ data: pair.block
17
+ });
18
+ }
19
+ return { cid: rootCid, blobs };
20
+ }
21
+ async function filesToIpfsBlobs(binaries) {
22
+ const blockstore = new MemoryBlockstore();
23
+ const resultCIDs = [];
24
+ for (const binary of binaries) {
25
+ const results = unixFSImporter([{ content: binary }], blockstore);
26
+ const result = await results.next();
27
+ if (!result.value) {
28
+ throw new Error("Failed to chunk file into IPFS blocks");
29
+ }
30
+ resultCIDs.push(result.value.cid.toString());
31
+ }
32
+ const blobs = [];
33
+ for await (const pair of blockstore.getAll()) {
34
+ blobs.push({
35
+ cid: pair.cid.toString(),
36
+ data: pair.block
37
+ });
38
+ }
39
+ return { resultCIDs, blobs };
40
+ }
41
+ var FILE_PROTOCOL = "file://";
42
+ function getBlockLink(block) {
43
+ const b = block;
44
+ return typeof b.link === "string" ? b.link : void 0;
45
+ }
46
+ function setBlockLink(block, link) {
47
+ return { ...block, link };
48
+ }
49
+ async function resolveFileLinksInBlocks(nodes, readFile) {
50
+ const blockstore = new MemoryBlockstore();
51
+ const cidMap = /* @__PURE__ */ new Map();
52
+ const resolved = await resolveNodes(nodes, blockstore, cidMap, readFile);
53
+ const blobs = [];
54
+ for await (const pair of blockstore.getAll()) {
55
+ blobs.push({
56
+ cid: pair.cid.toString(),
57
+ data: pair.block
58
+ });
59
+ }
60
+ return { nodes: resolved, blobs };
61
+ }
62
+ async function resolveNodes(nodes, blockstore, cidMap, readFile) {
63
+ const result = [];
64
+ for (const node of nodes) {
65
+ let resolvedBlock = node.block;
66
+ const link = getBlockLink(resolvedBlock);
67
+ if (link && link.startsWith(FILE_PROTOCOL)) {
68
+ const filePath = link.slice(FILE_PROTOCOL.length);
69
+ const ipfsUrl = await resolveFileToCid(filePath, blockstore, cidMap, readFile);
70
+ resolvedBlock = setBlockLink(resolvedBlock, ipfsUrl);
71
+ }
72
+ const resolvedChildren = node.children ? await resolveNodes(node.children, blockstore, cidMap, readFile) : void 0;
73
+ result.push({ block: resolvedBlock, children: resolvedChildren });
74
+ }
75
+ return result;
76
+ }
77
+ async function resolveFileToCid(filePath, blockstore, cidMap, readFile) {
78
+ const cached = cidMap.get(filePath);
79
+ if (cached) return cached;
80
+ const data = await readFile(filePath);
81
+ const results = unixFSImporter([{ content: data }], blockstore);
82
+ const result = await results.next();
83
+ if (!result.value) {
84
+ throw new Error(`Failed to process file for IPFS: ${filePath}`);
85
+ }
86
+ const ipfsUrl = `ipfs://${result.value.cid.toString()}`;
87
+ cidMap.set(filePath, ipfsUrl);
88
+ return ipfsUrl;
89
+ }
90
+ function hasFileLinks(nodes) {
91
+ for (const node of nodes) {
92
+ const link = getBlockLink(node.block);
93
+ if (link && link.startsWith(FILE_PROTOCOL)) {
94
+ return true;
95
+ }
96
+ if (node.children && hasFileLinks(node.children)) {
97
+ return true;
98
+ }
99
+ }
100
+ return false;
101
+ }
102
+
103
+ export {
104
+ fileToIpfsBlobs,
105
+ filesToIpfsBlobs,
106
+ resolveFileLinksInBlocks,
107
+ hasFileLinks
108
+ };
@@ -0,0 +1,57 @@
1
+ import {
2
+ signObject,
3
+ toPublishInput
4
+ } from "./chunk-YZX54L3G.mjs";
5
+ import {
6
+ entityQueryPathToHmIdPath,
7
+ packBaseId
8
+ } from "./chunk-SQEUO7FO.mjs";
9
+
10
+ // src/capability.ts
11
+ import { encode as cborEncode } from "@ipld/dag-cbor";
12
+ import { base58btc } from "multiformats/bases/base58";
13
+ async function createCapability(input, signer) {
14
+ const signerKey = await signer.getPublicKey();
15
+ const ts = BigInt(Date.now());
16
+ const unsigned = {
17
+ type: "Capability",
18
+ signer: new Uint8Array(signerKey),
19
+ sig: new Uint8Array(64),
20
+ ts,
21
+ delegate: new Uint8Array(base58btc.decode(input.delegateUid)),
22
+ role: input.role
23
+ };
24
+ if (input.path) {
25
+ unsigned.path = input.path;
26
+ }
27
+ if (input.label) {
28
+ unsigned.label = input.label;
29
+ }
30
+ unsigned.sig = await signObject(signer, unsigned);
31
+ return toPublishInput(cborEncode(unsigned));
32
+ }
33
+ async function resolveCapability(client, targetAccount, signerAccount, path) {
34
+ if (targetAccount === signerAccount) return void 0;
35
+ const pathSegments = path ? entityQueryPathToHmIdPath(path) : null;
36
+ const targetId = {
37
+ id: packBaseId(targetAccount, pathSegments),
38
+ uid: targetAccount,
39
+ path: pathSegments,
40
+ version: null,
41
+ blockRef: null,
42
+ blockRange: null,
43
+ hostname: null,
44
+ latest: true,
45
+ scheme: null
46
+ };
47
+ const caps = await client.request("ListCapabilities", { targetId });
48
+ const match = caps.capabilities.find(
49
+ (c) => c.delegate === signerAccount && (c.role === "WRITER" || c.role === "AGENT")
50
+ );
51
+ return match == null ? void 0 : match.id;
52
+ }
53
+
54
+ export {
55
+ createCapability,
56
+ resolveCapability
57
+ };
@@ -0,0 +1,159 @@
1
+ import {
2
+ createChange,
3
+ createChangeOps
4
+ } from "./chunk-I3YUHKYW.mjs";
5
+ import {
6
+ createVersionRef
7
+ } from "./chunk-XI2LXZM7.mjs";
8
+ import {
9
+ resolveDocumentState
10
+ } from "./chunk-HBIVZA6C.mjs";
11
+ import {
12
+ entityQueryPathToHmIdPath,
13
+ packHmId,
14
+ unpackHmId
15
+ } from "./chunk-SQEUO7FO.mjs";
16
+
17
+ // src/auto-link.ts
18
+ import { CID } from "multiformats/cid";
19
+ function documentContainsLinkToChild(document, childId) {
20
+ const childUrlNormalized = packHmId({ ...childId, version: null, latest: null });
21
+ function searchBlocks(nodes) {
22
+ for (const node of nodes) {
23
+ if (node.block.type === "Embed") {
24
+ const linkId = unpackHmId(node.block.link);
25
+ if (linkId) {
26
+ const linkUrl = packHmId({ ...linkId, version: null, latest: null });
27
+ if (linkUrl === childUrlNormalized) return true;
28
+ }
29
+ }
30
+ const annotations = "annotations" in node.block ? node.block.annotations : void 0;
31
+ if (annotations) {
32
+ for (const ann of annotations) {
33
+ if (ann.type === "Link" || ann.type === "Embed") {
34
+ const linkId = unpackHmId(ann.link);
35
+ if (linkId) {
36
+ const linkUrl = packHmId({ ...linkId, version: null, latest: null });
37
+ if (linkUrl === childUrlNormalized) return true;
38
+ }
39
+ }
40
+ }
41
+ }
42
+ if (node.children && searchBlocks(node.children)) return true;
43
+ }
44
+ return false;
45
+ }
46
+ return searchBlocks(document.content || []);
47
+ }
48
+ function documentHasSelfQuery(document, documentId) {
49
+ const parentPathStr = (documentId.path || []).join("/");
50
+ function isSelfMatch(include) {
51
+ if (!include) return false;
52
+ if (include.space !== documentId.uid) return false;
53
+ const includePath = entityQueryPathToHmIdPath(include.path);
54
+ return (includePath || []).join("/") === parentPathStr;
55
+ }
56
+ function searchBlocks(nodes) {
57
+ var _a, _b;
58
+ for (const node of nodes) {
59
+ if (node.block.type === "Query") {
60
+ const includes = (_b = (_a = node.block.attributes) == null ? void 0 : _a.query) == null ? void 0 : _b.includes;
61
+ if (includes == null ? void 0 : includes.some(isSelfMatch)) return true;
62
+ }
63
+ if (node.children && searchBlocks(node.children)) return true;
64
+ }
65
+ return false;
66
+ }
67
+ return searchBlocks(document.content || []);
68
+ }
69
+ function shouldAutoLinkParent(isPrivate, parentDocument, editableLocation, parentId) {
70
+ if (isPrivate) return false;
71
+ if (parentDocument) {
72
+ if (documentContainsLinkToChild(parentDocument, editableLocation)) {
73
+ return false;
74
+ }
75
+ if (documentHasSelfQuery(parentDocument, parentId)) {
76
+ return false;
77
+ }
78
+ }
79
+ return true;
80
+ }
81
+ function createAutoLinkOps(parentDocument, childHmUrl, newBlockId) {
82
+ const existingRootBlockIds = (parentDocument.content || []).map((node) => node.block.id).filter(Boolean);
83
+ const embedBlock = {
84
+ id: newBlockId,
85
+ type: "Embed",
86
+ link: childHmUrl,
87
+ attributes: { view: "Card" }
88
+ };
89
+ return [
90
+ { type: "ReplaceBlock", block: embedBlock },
91
+ { type: "MoveBlocks", blocks: [...existingRootBlockIds, newBlockId], parent: "" }
92
+ ];
93
+ }
94
+ async function autoLinkChildToParent(opts) {
95
+ const { client, account, path, childHmUrl, signer } = opts;
96
+ const segments = path.replace(/^\//, "").split("/");
97
+ if (segments.length <= 1) return false;
98
+ const parentSegments = segments.slice(0, -1);
99
+ const parentPath = "/" + parentSegments.join("/");
100
+ const parentId = unpackHmId(`hm://${account}${parentPath}`);
101
+ if (!parentId) return false;
102
+ const childId = unpackHmId(childHmUrl);
103
+ if (!childId) return false;
104
+ let parentDocument = null;
105
+ try {
106
+ const resource = await client.request("Resource", { ...parentId, latest: true });
107
+ if (resource.type === "document") {
108
+ parentDocument = resource.document;
109
+ }
110
+ } catch {
111
+ return false;
112
+ }
113
+ if (!parentDocument) return false;
114
+ if (!shouldAutoLinkParent(false, parentDocument, childId, parentId)) {
115
+ return false;
116
+ }
117
+ const newBlockId = generateBlockId();
118
+ const ops = createAutoLinkOps(parentDocument, childHmUrl, newBlockId);
119
+ const hmUrl = `hm://${account}${parentPath}`;
120
+ const state = await resolveDocumentState(client, hmUrl);
121
+ const genesisCid = CID.parse(state.genesis);
122
+ const depCids = state.heads.map((h) => CID.parse(h));
123
+ const newDepth = state.headDepth + 1;
124
+ const { unsignedBytes, ts } = createChangeOps({ ops, genesisCid, deps: depCids, depth: newDepth });
125
+ const changeBlock = await createChange(unsignedBytes, signer);
126
+ const generation = Number(ts);
127
+ const refInput = await createVersionRef(
128
+ {
129
+ space: account,
130
+ path: parentPath,
131
+ genesis: state.genesis,
132
+ version: changeBlock.cid.toString(),
133
+ generation
134
+ },
135
+ signer
136
+ );
137
+ await client.publish({
138
+ blobs: [{ data: new Uint8Array(changeBlock.bytes), cid: changeBlock.cid.toString() }, ...refInput.blobs]
139
+ });
140
+ return true;
141
+ }
142
+ function generateBlockId() {
143
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
144
+ let id = "";
145
+ const bytes = new Uint8Array(10);
146
+ crypto.getRandomValues(bytes);
147
+ for (let i = 0; i < 10; i++) {
148
+ id += chars[bytes[i] % chars.length];
149
+ }
150
+ return id;
151
+ }
152
+
153
+ export {
154
+ documentContainsLinkToChild,
155
+ documentHasSelfQuery,
156
+ shouldAutoLinkParent,
157
+ createAutoLinkOps,
158
+ autoLinkChildToParent
159
+ };
@@ -0,0 +1,112 @@
1
+ import {
2
+ signObject,
3
+ toPublishInput
4
+ } from "./chunk-YZX54L3G.mjs";
5
+
6
+ // src/ref.ts
7
+ import { encode as cborEncode } from "@ipld/dag-cbor";
8
+ import { CID } from "multiformats";
9
+ import { base58btc } from "multiformats/bases/base58";
10
+ function bytesEqual(a, b) {
11
+ if (a.length !== b.length) return false;
12
+ for (let i = 0; i < a.length; i++) {
13
+ if (a[i] !== b[i]) return false;
14
+ }
15
+ return true;
16
+ }
17
+ function buildUnsignedRef({
18
+ signerKey,
19
+ space,
20
+ path,
21
+ genesis,
22
+ generation,
23
+ capability,
24
+ visibility,
25
+ ts
26
+ }) {
27
+ const signerBytes = new Uint8Array(signerKey);
28
+ const spaceBytes = new Uint8Array(base58btc.decode(space));
29
+ const unsigned = {
30
+ type: "Ref",
31
+ signer: signerBytes,
32
+ ts: BigInt(ts ?? Date.now()),
33
+ sig: new Uint8Array(64),
34
+ genesisBlob: CID.parse(genesis)
35
+ };
36
+ if (generation !== 0) {
37
+ unsigned.generation = generation;
38
+ }
39
+ if (!bytesEqual(spaceBytes, signerBytes)) {
40
+ unsigned.space = spaceBytes;
41
+ }
42
+ if (path) {
43
+ unsigned.path = path;
44
+ }
45
+ if (capability) {
46
+ unsigned.capability = CID.parse(capability);
47
+ }
48
+ if (visibility) {
49
+ unsigned.visibility = visibility;
50
+ }
51
+ return unsigned;
52
+ }
53
+ async function createVersionRef(input, signer) {
54
+ const signerKey = await signer.getPublicKey();
55
+ const unsigned = buildUnsignedRef({
56
+ signerKey,
57
+ space: input.space,
58
+ path: input.path,
59
+ genesis: input.genesis,
60
+ generation: input.generation,
61
+ capability: input.capability,
62
+ visibility: input.visibility,
63
+ ts: input.ts
64
+ });
65
+ unsigned.heads = input.version.split(".").map((v) => CID.parse(v));
66
+ unsigned.sig = await signObject(signer, unsigned);
67
+ return toPublishInput(cborEncode(unsigned));
68
+ }
69
+ async function createTombstoneRef(input, signer) {
70
+ const signerKey = await signer.getPublicKey();
71
+ const unsigned = buildUnsignedRef({
72
+ signerKey,
73
+ space: input.space,
74
+ path: input.path,
75
+ genesis: input.genesis,
76
+ generation: input.generation,
77
+ capability: input.capability
78
+ });
79
+ unsigned.heads = [];
80
+ unsigned.sig = await signObject(signer, unsigned);
81
+ return toPublishInput(cborEncode(unsigned));
82
+ }
83
+ async function createRedirectRef(input, signer) {
84
+ const signerKey = await signer.getPublicKey();
85
+ const unsigned = buildUnsignedRef({
86
+ signerKey,
87
+ space: input.space,
88
+ path: input.path,
89
+ genesis: input.genesis,
90
+ generation: input.generation,
91
+ capability: input.capability
92
+ });
93
+ unsigned.heads = [];
94
+ const redirect = {
95
+ path: input.targetPath
96
+ };
97
+ if (input.targetSpace && input.targetSpace !== input.space) {
98
+ redirect.space = new Uint8Array(base58btc.decode(input.targetSpace));
99
+ }
100
+ if (input.republish) {
101
+ redirect.republish = true;
102
+ }
103
+ unsigned.redirect = redirect;
104
+ unsigned.sig = await signObject(signer, unsigned);
105
+ return toPublishInput(cborEncode(unsigned));
106
+ }
107
+
108
+ export {
109
+ createVersionRef,
110
+ createTombstoneRef,
111
+ createRedirectRef
112
+ };
@@ -0,0 +1,171 @@
1
+ import {
2
+ entityQueryPathToHmIdPath,
3
+ parseFragment,
4
+ unpackHmId
5
+ } from "./chunk-SQEUO7FO.mjs";
6
+
7
+ // src/hm-resolver.ts
8
+ async function resolveHypermediaUrl(url, opts) {
9
+ let latest = false;
10
+ let blockRef = null;
11
+ let blockRange = null;
12
+ let panel = null;
13
+ let parsedUrl = null;
14
+ try {
15
+ parsedUrl = new URL(url);
16
+ const hasVersion = parsedUrl.searchParams.has("v");
17
+ const hasLatest = parsedUrl.searchParams.has("l");
18
+ panel = parsedUrl.searchParams.get("panel");
19
+ if (parsedUrl.hash) {
20
+ const fragment = parseFragment(parsedUrl.hash.slice(1));
21
+ if (fragment) {
22
+ blockRef = fragment.blockId;
23
+ if ("start" in fragment && fragment.start !== void 0) {
24
+ blockRange = { start: fragment.start, end: fragment.end };
25
+ } else if ("expanded" in fragment && fragment.expanded) {
26
+ blockRange = { expanded: fragment.expanded };
27
+ }
28
+ }
29
+ }
30
+ latest = blockRef ? false : hasLatest || !hasVersion;
31
+ } catch {
32
+ }
33
+ if ((opts == null ? void 0 : opts.domainResolver) && parsedUrl) {
34
+ try {
35
+ const uid = await opts.domainResolver(parsedUrl.hostname);
36
+ if (uid) {
37
+ return buildResolvedUrlFromDomainUid(parsedUrl, uid, {
38
+ latest,
39
+ blockRef,
40
+ blockRange,
41
+ panel
42
+ });
43
+ }
44
+ } catch {
45
+ }
46
+ }
47
+ let response;
48
+ try {
49
+ response = await fetch(url, {
50
+ method: "OPTIONS"
51
+ });
52
+ } catch (error) {
53
+ if ((opts == null ? void 0 : opts.domainResolver) && parsedUrl) {
54
+ try {
55
+ const uid = await opts.domainResolver(parsedUrl.hostname);
56
+ if (uid) {
57
+ return buildResolvedUrlFromDomainUid(parsedUrl, uid, {
58
+ latest,
59
+ blockRef,
60
+ blockRange,
61
+ panel
62
+ });
63
+ }
64
+ } catch {
65
+ }
66
+ }
67
+ throw error;
68
+ }
69
+ if (response.status === 200) {
70
+ const rawId = response.headers.get("x-hypermedia-id");
71
+ const id = rawId ? decodeURIComponent(rawId) : null;
72
+ const version = response.headers.get("x-hypermedia-version");
73
+ const encodedTitle = response.headers.get("x-hypermedia-title");
74
+ const title = encodedTitle ? decodeURIComponent(encodedTitle) : null;
75
+ const rawTarget = response.headers.get("x-hypermedia-target");
76
+ const target = rawTarget ? unpackHmId(decodeURIComponent(rawTarget)) : null;
77
+ const rawAuthors = response.headers.get("x-hypermedia-authors");
78
+ const authors = rawAuthors ? decodeURIComponent(rawAuthors).split(",").map((author) => unpackHmId(author)).filter((author) => author !== null) : null;
79
+ const type = response.headers.get("x-hypermedia-type");
80
+ if (id) {
81
+ const hmId = unpackHmId(id);
82
+ const resolvedVersion = version ?? (hmId == null ? void 0 : hmId.version) ?? null;
83
+ let siteHostname = null;
84
+ try {
85
+ const inputUrl = new URL(url);
86
+ if (!inputUrl.pathname.startsWith("/hm/")) {
87
+ siteHostname = inputUrl.origin;
88
+ }
89
+ } catch {
90
+ }
91
+ if (!hmId) {
92
+ return null;
93
+ }
94
+ return {
95
+ id,
96
+ hmId: {
97
+ ...hmId,
98
+ version: resolvedVersion,
99
+ latest,
100
+ blockRef,
101
+ blockRange,
102
+ hostname: siteHostname || hmId.hostname
103
+ },
104
+ version,
105
+ title,
106
+ target,
107
+ authors,
108
+ type,
109
+ panel
110
+ };
111
+ }
112
+ return null;
113
+ }
114
+ return null;
115
+ }
116
+ async function resolveId(input, opts) {
117
+ const parsed = unpackHmId(input);
118
+ if (parsed) return parsed;
119
+ if (input.startsWith("http://") || input.startsWith("https://")) {
120
+ const resolved = await resolveHypermediaUrl(input, opts);
121
+ if (resolved == null ? void 0 : resolved.hmId) return resolved.hmId;
122
+ throw new Error(`URL does not appear to be a Seed Hypermedia resource: ${input}`);
123
+ }
124
+ throw new Error(`Invalid Hypermedia ID: ${input}`);
125
+ }
126
+ function buildResolvedUrlFromDomainUid(parsedUrl, uid, {
127
+ latest,
128
+ blockRef,
129
+ blockRange,
130
+ panel
131
+ }) {
132
+ const pathSegments = entityQueryPathToHmIdPath(parsedUrl.pathname);
133
+ const profilePath = resolveProfilePath(uid, pathSegments);
134
+ const resolvedUid = (profilePath == null ? void 0 : profilePath.uid) || uid;
135
+ const path = (profilePath == null ? void 0 : profilePath.path) || (pathSegments.length > 0 ? pathSegments : null);
136
+ const version = parsedUrl.searchParams.get("v") || null;
137
+ const pathStr = path ? "/" + path.join("/") : "";
138
+ const siteHostname = parsedUrl.origin;
139
+ return {
140
+ id: `hm://${resolvedUid}${pathStr}`,
141
+ hmId: {
142
+ id: `hm://${resolvedUid}${pathStr}`,
143
+ uid: resolvedUid,
144
+ path,
145
+ version,
146
+ blockRef,
147
+ blockRange,
148
+ hostname: siteHostname,
149
+ scheme: "hm",
150
+ latest
151
+ },
152
+ version,
153
+ title: null,
154
+ target: null,
155
+ authors: null,
156
+ type: null,
157
+ panel
158
+ };
159
+ }
160
+ function resolveProfilePath(siteUid, pathSegments) {
161
+ if (pathSegments[0] !== ":profile") return null;
162
+ return {
163
+ uid: pathSegments[1] || siteUid,
164
+ path: [":profile"]
165
+ };
166
+ }
167
+
168
+ export {
169
+ resolveHypermediaUrl,
170
+ resolveId
171
+ };
@@ -0,0 +1,33 @@
1
+ // src/signing.ts
2
+ import { encode as cborEncode } from "@ipld/dag-cbor";
3
+ var cborCodec = {
4
+ code: 113,
5
+ encode: (input) => cborEncode(input),
6
+ name: "DAG-CBOR"
7
+ };
8
+ function normalizeBytes(data) {
9
+ const normalized = new Uint8Array(data.byteLength);
10
+ normalized.set(data);
11
+ return normalized;
12
+ }
13
+ async function signObject(signer, data) {
14
+ return await signer.sign(cborEncode(data));
15
+ }
16
+ function toPublishInput(blobData, extraBlobs) {
17
+ return {
18
+ blobs: [
19
+ { data: normalizeBytes(blobData) },
20
+ ...(extraBlobs || []).map((b) => ({
21
+ ...b.cid ? { cid: b.cid } : {},
22
+ data: normalizeBytes(b.data)
23
+ }))
24
+ ]
25
+ };
26
+ }
27
+
28
+ export {
29
+ cborCodec,
30
+ normalizeBytes,
31
+ signObject,
32
+ toPublishInput
33
+ };
@@ -0,0 +1,14 @@
1
+ import {
2
+ createSeedClient,
3
+ deserializeQueryString
4
+ } from "./chunk-MKUWQB5W.mjs";
5
+ import "./chunk-CBELM7KX.mjs";
6
+ import "./chunk-I3YUHKYW.mjs";
7
+ import "./chunk-XI2LXZM7.mjs";
8
+ import "./chunk-YZX54L3G.mjs";
9
+ import "./chunk-SQEUO7FO.mjs";
10
+ import "./chunk-7P6ASYW6.mjs";
11
+ export {
12
+ createSeedClient,
13
+ deserializeQueryString
14
+ };
@@ -0,0 +1,18 @@
1
+ import {
2
+ commentRecordIdFromBlob,
3
+ createComment,
4
+ deleteComment,
5
+ trimTrailingEmptyBlocks,
6
+ updateComment
7
+ } from "./chunk-QS7TPMYT.mjs";
8
+ import "./chunk-N3P7S5YZ.mjs";
9
+ import "./chunk-YZX54L3G.mjs";
10
+ import "./chunk-SQEUO7FO.mjs";
11
+ import "./chunk-7P6ASYW6.mjs";
12
+ export {
13
+ commentRecordIdFromBlob,
14
+ createComment,
15
+ deleteComment,
16
+ trimTrailingEmptyBlocks,
17
+ updateComment
18
+ };