@seed-hypermedia/client 0.0.68 → 0.0.70
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/LICENSE +201 -0
- package/dist/auth.d.ts +79 -0
- package/dist/auth.mjs +266 -0
- package/dist/auto-link.d.ts +3 -2
- package/dist/auto-link.mjs +21 -0
- package/dist/base64.mjs +9 -0
- package/dist/blobs.d.ts +170 -0
- package/dist/blobs.mjs +51 -0
- package/dist/block-diff.mjs +17 -0
- package/dist/blocks-to-markdown.mjs +22 -0
- package/dist/capability.d.ts +7 -2
- package/dist/capability.mjs +14 -0
- package/dist/cbor.d.ts +13 -0
- package/dist/cbor.mjs +13 -0
- package/dist/change.d.ts +8 -7
- package/dist/change.mjs +24 -0
- package/dist/chunk-2MD3FXKB.mjs +14 -0
- package/dist/chunk-37WRGUK4.mjs +125 -0
- package/dist/chunk-3KESF5XJ.mjs +297 -0
- package/dist/chunk-3TPCJCVO.mjs +24 -0
- package/dist/chunk-4Q3SAL5R.mjs +75 -0
- package/dist/chunk-52P3E6H6.mjs +459 -0
- package/dist/chunk-BUPMCRR4.mjs +48 -0
- package/dist/chunk-CBELM7KX.mjs +29 -0
- package/dist/{chunk-KCR3277A.mjs → chunk-DBHL3BYB.mjs} +9 -14
- package/dist/chunk-DR3HJ6BV.mjs +25 -0
- package/dist/chunk-EU36RFR3.mjs +159 -0
- package/dist/chunk-EY6RQVAP.mjs +138 -0
- package/dist/chunk-H7L4TI6X.mjs +705 -0
- package/dist/chunk-HBIVZA6C.mjs +102 -0
- package/dist/chunk-IT5LLTMP.mjs +209 -0
- package/dist/chunk-JT57MV7Y.mjs +136 -0
- package/dist/chunk-KO4XH5L2.mjs +475 -0
- package/dist/chunk-LVAHHQIK.mjs +41 -0
- package/dist/chunk-LYECQKZE.mjs +49 -0
- package/dist/chunk-N3P7S5YZ.mjs +118 -0
- package/dist/chunk-NPG76WUS.mjs +348 -0
- package/dist/chunk-NYWCMQTH.mjs +412 -0
- package/dist/chunk-OZKQOI2X.mjs +334 -0
- package/dist/chunk-PJ2RFT5A.mjs +113 -0
- package/dist/chunk-PPAY4WZX.mjs +40 -0
- package/dist/chunk-S2PVJK2P.mjs +517 -0
- package/dist/chunk-SHOAYNJY.mjs +289 -0
- package/dist/chunk-T5BTAJPW.mjs +725 -0
- package/dist/{chunk-EGCUJ6D6.mjs → chunk-UOL3F6XQ.mjs} +0 -12
- package/dist/chunk-VN7F33SS.mjs +108 -0
- package/dist/chunk-YNVFRCUH.mjs +171 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.mjs +15 -0
- package/dist/comment.d.ts +5 -4
- package/dist/comment.mjs +19 -0
- package/dist/contact.d.ts +5 -4
- package/dist/contact.mjs +15 -0
- package/dist/document-state.mjs +8 -0
- package/dist/editor-types.mjs +0 -0
- package/dist/editorblock-to-hmblock.mjs +11 -0
- package/dist/encryption.mjs +13 -0
- package/dist/errors.mjs +11 -0
- package/dist/file-to-ipfs.mjs +13 -0
- package/dist/grobid.mjs +11 -0
- package/dist/hm-resolver.mjs +10 -0
- package/dist/hmauth.d.ts +169 -0
- package/dist/hmauth.mjs +53 -0
- package/dist/hmblock-to-editorblock.mjs +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +132 -5453
- package/dist/keyfile.mjs +19 -0
- package/dist/markdown-to-blocks.mjs +15 -0
- package/dist/pdf-to-blocks-embedded.mjs +7 -0
- package/dist/pdf-to-blocks.mjs +11 -0
- package/dist/ref.d.ts +5 -4
- package/dist/ref.mjs +13 -0
- package/dist/resource-read.mjs +15 -0
- package/dist/signer.d.ts +42 -0
- package/dist/signer.mjs +9 -0
- package/dist/signing.d.ts +10 -2
- package/dist/signing.mjs +16 -0
- package/dist/tei-to-blocks.mjs +8 -0
- package/dist/unicode.mjs +19 -0
- package/dist/vault-local.mjs +10 -6
- package/dist/vault.d.ts +14 -4
- package/dist/vault.mjs +6 -2
- package/package.json +18 -28
- package/src/index.ts +0 -144
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SeedClientError,
|
|
3
|
+
SeedNetworkError,
|
|
4
|
+
SeedValidationError
|
|
5
|
+
} from "./chunk-CBELM7KX.mjs";
|
|
6
|
+
import {
|
|
7
|
+
createDocumentChange,
|
|
8
|
+
createGenesisChange,
|
|
9
|
+
signDocumentChange
|
|
10
|
+
} from "./chunk-JT57MV7Y.mjs";
|
|
11
|
+
import {
|
|
12
|
+
createVersionRef
|
|
13
|
+
} from "./chunk-PJ2RFT5A.mjs";
|
|
14
|
+
import {
|
|
15
|
+
HMActionSchema,
|
|
16
|
+
HMRequestSchema,
|
|
17
|
+
packHmId
|
|
18
|
+
} from "./chunk-SQEUO7FO.mjs";
|
|
19
|
+
|
|
20
|
+
// src/client.ts
|
|
21
|
+
import { encode as cborEncode } from "@ipld/dag-cbor";
|
|
22
|
+
import { deserialize } from "superjson";
|
|
23
|
+
var PRIMITIVE_VALUE_KEY = "__value";
|
|
24
|
+
function serializeQueryString(data, _schema) {
|
|
25
|
+
const params = new URLSearchParams();
|
|
26
|
+
if (typeof data !== "object" || data === null) {
|
|
27
|
+
if (data !== void 0 && data !== null) {
|
|
28
|
+
params.append(PRIMITIVE_VALUE_KEY, String(data));
|
|
29
|
+
}
|
|
30
|
+
const queryString2 = params.toString();
|
|
31
|
+
return queryString2 ? `?${queryString2}` : "";
|
|
32
|
+
}
|
|
33
|
+
for (const [key, value] of Object.entries(data)) {
|
|
34
|
+
if (value === void 0 || value === null) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
38
|
+
params.append(key, String(value));
|
|
39
|
+
} else {
|
|
40
|
+
params.append(key, JSON.stringify(value));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const queryString = params.toString();
|
|
44
|
+
return queryString ? `?${queryString}` : "";
|
|
45
|
+
}
|
|
46
|
+
function deserializeQueryString(queryString, schema) {
|
|
47
|
+
const cleanQuery = queryString.startsWith("?") ? queryString.slice(1) : queryString;
|
|
48
|
+
if (!cleanQuery) {
|
|
49
|
+
return schema.parse({});
|
|
50
|
+
}
|
|
51
|
+
const params = new URLSearchParams(cleanQuery);
|
|
52
|
+
if (params.has(PRIMITIVE_VALUE_KEY) && Array.from(params.keys()).length === 1) {
|
|
53
|
+
return schema.parse(params.get(PRIMITIVE_VALUE_KEY));
|
|
54
|
+
}
|
|
55
|
+
const result = {};
|
|
56
|
+
for (const [key, value] of Array.from(params.entries())) {
|
|
57
|
+
try {
|
|
58
|
+
result[key] = JSON.parse(value);
|
|
59
|
+
} catch {
|
|
60
|
+
result[key] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return schema.parse(result);
|
|
64
|
+
}
|
|
65
|
+
var QUERY_PARAM_SERIALIZERS = {
|
|
66
|
+
Account: (input) => ({
|
|
67
|
+
id: input
|
|
68
|
+
}),
|
|
69
|
+
Resource: (input) => ({
|
|
70
|
+
id: packHmId(input)
|
|
71
|
+
}),
|
|
72
|
+
ResourceMetadata: (input) => ({
|
|
73
|
+
id: packHmId(input)
|
|
74
|
+
}),
|
|
75
|
+
ListCitations: (input) => ({
|
|
76
|
+
targetId: packHmId(input.targetId)
|
|
77
|
+
}),
|
|
78
|
+
ListChanges: (input) => ({
|
|
79
|
+
targetId: packHmId(input.targetId)
|
|
80
|
+
}),
|
|
81
|
+
ListCapabilities: (input) => ({
|
|
82
|
+
targetId: packHmId(input.targetId)
|
|
83
|
+
}),
|
|
84
|
+
DiscoveryStatus: (input) => ({
|
|
85
|
+
uid: input.uid,
|
|
86
|
+
path: input.path.join("/"),
|
|
87
|
+
...input.version ? { v: input.version } : {},
|
|
88
|
+
...input.latest ? { l: "" } : {}
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
function createSeedClient(baseUrl, options) {
|
|
92
|
+
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
|
|
93
|
+
const fetchFn = (options == null ? void 0 : options.fetch) ?? globalThis.fetch;
|
|
94
|
+
const getDefaultHeaders = async () => typeof (options == null ? void 0 : options.headers) === "function" ? await options.headers() : (options == null ? void 0 : options.headers) ?? {};
|
|
95
|
+
async function request(key, input, options2) {
|
|
96
|
+
const requestSchema = HMRequestSchema.options.find((schema) => schema.shape.key.value === key);
|
|
97
|
+
if (!requestSchema) {
|
|
98
|
+
throw new SeedValidationError(`Unknown request key: ${key}`);
|
|
99
|
+
}
|
|
100
|
+
let validatedInput;
|
|
101
|
+
try {
|
|
102
|
+
validatedInput = requestSchema.shape.input.parse(input);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
throw new SeedValidationError(`Invalid input for ${key}: ${err instanceof Error ? err.message : String(err)}`);
|
|
105
|
+
}
|
|
106
|
+
let response;
|
|
107
|
+
const defaultHeaders = await getDefaultHeaders();
|
|
108
|
+
const isAction = HMActionSchema.options.some((s) => s.shape.key.value === key);
|
|
109
|
+
if (isAction) {
|
|
110
|
+
const url = `${normalizedBaseUrl}/api/${key}`;
|
|
111
|
+
try {
|
|
112
|
+
response = await fetchFn(url, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: {
|
|
115
|
+
Accept: "application/json",
|
|
116
|
+
"Content-Type": "application/cbor",
|
|
117
|
+
...defaultHeaders
|
|
118
|
+
},
|
|
119
|
+
body: new Uint8Array(cborEncode(stripUndefined(validatedInput))),
|
|
120
|
+
signal: options2 == null ? void 0 : options2.signal
|
|
121
|
+
});
|
|
122
|
+
} catch (err) {
|
|
123
|
+
if (isAbortError(err)) throw err;
|
|
124
|
+
throw new SeedNetworkError(
|
|
125
|
+
`Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`,
|
|
126
|
+
{ cause: err }
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
const inputToParams = QUERY_PARAM_SERIALIZERS[key];
|
|
131
|
+
let queryString;
|
|
132
|
+
if (inputToParams) {
|
|
133
|
+
const params = inputToParams(validatedInput);
|
|
134
|
+
const searchParams = new URLSearchParams(params);
|
|
135
|
+
queryString = searchParams.toString() ? `?${searchParams.toString()}` : "";
|
|
136
|
+
} else if (!validatedInput) {
|
|
137
|
+
queryString = "";
|
|
138
|
+
} else {
|
|
139
|
+
queryString = serializeQueryString(validatedInput, requestSchema.shape.input);
|
|
140
|
+
}
|
|
141
|
+
const url = `${normalizedBaseUrl}/api/${key}${queryString}`;
|
|
142
|
+
try {
|
|
143
|
+
response = await fetchFn(url, {
|
|
144
|
+
method: "GET",
|
|
145
|
+
headers: {
|
|
146
|
+
Accept: "application/json",
|
|
147
|
+
...defaultHeaders
|
|
148
|
+
},
|
|
149
|
+
signal: options2 == null ? void 0 : options2.signal
|
|
150
|
+
});
|
|
151
|
+
} catch (err) {
|
|
152
|
+
if (isAbortError(err)) throw err;
|
|
153
|
+
throw new SeedNetworkError(
|
|
154
|
+
`Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`,
|
|
155
|
+
{ cause: err }
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!response.ok) {
|
|
160
|
+
let errorBody;
|
|
161
|
+
try {
|
|
162
|
+
errorBody = await response.text();
|
|
163
|
+
} catch {
|
|
164
|
+
}
|
|
165
|
+
throw new SeedClientError(
|
|
166
|
+
formatHTTPErrorMessage(key, response.status, response.statusText, errorBody),
|
|
167
|
+
response.status,
|
|
168
|
+
errorBody
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const rawJson = await response.json();
|
|
172
|
+
const deserialized = deserialize(rawJson);
|
|
173
|
+
return requestSchema.shape.output.parse(deserialized);
|
|
174
|
+
}
|
|
175
|
+
function publish(input) {
|
|
176
|
+
return request("PublishBlobs", input);
|
|
177
|
+
}
|
|
178
|
+
async function publishDocument(input, signer) {
|
|
179
|
+
if (!input.genesis && !input.baseVersion && !input.path) {
|
|
180
|
+
const genesisChange = await createGenesisChange(signer);
|
|
181
|
+
const generation = input.generation != null ? Number(input.generation) : 1;
|
|
182
|
+
if (input.changes.every((change) => {
|
|
183
|
+
var _a;
|
|
184
|
+
return ((_a = change.op) == null ? void 0 : _a.case) === "setMetadata";
|
|
185
|
+
})) {
|
|
186
|
+
const contentChange = await createDocumentChange(
|
|
187
|
+
{
|
|
188
|
+
changes: input.changes,
|
|
189
|
+
genesisCid: genesisChange.cid,
|
|
190
|
+
deps: [genesisChange.cid],
|
|
191
|
+
depth: 1
|
|
192
|
+
},
|
|
193
|
+
signer
|
|
194
|
+
);
|
|
195
|
+
const ref = await createVersionRef(
|
|
196
|
+
{
|
|
197
|
+
space: input.account,
|
|
198
|
+
path: "",
|
|
199
|
+
genesis: genesisChange.cid.toString(),
|
|
200
|
+
version: contentChange.cid.toString(),
|
|
201
|
+
generation,
|
|
202
|
+
capability: input.capability
|
|
203
|
+
},
|
|
204
|
+
signer
|
|
205
|
+
);
|
|
206
|
+
await publish({
|
|
207
|
+
blobs: [
|
|
208
|
+
{ data: genesisChange.bytes, cid: genesisChange.cid.toString() },
|
|
209
|
+
{ data: contentChange.bytes, cid: contentChange.cid.toString() },
|
|
210
|
+
...ref.blobs
|
|
211
|
+
]
|
|
212
|
+
});
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const genesisRef = await createVersionRef(
|
|
216
|
+
{
|
|
217
|
+
space: input.account,
|
|
218
|
+
path: "",
|
|
219
|
+
genesis: genesisChange.cid.toString(),
|
|
220
|
+
version: genesisChange.cid.toString(),
|
|
221
|
+
generation,
|
|
222
|
+
capability: input.capability
|
|
223
|
+
},
|
|
224
|
+
signer
|
|
225
|
+
);
|
|
226
|
+
await publish({
|
|
227
|
+
blobs: [{ data: genesisChange.bytes, cid: genesisChange.cid.toString() }, ...genesisRef.blobs]
|
|
228
|
+
});
|
|
229
|
+
input = {
|
|
230
|
+
...input,
|
|
231
|
+
baseVersion: genesisChange.cid.toString(),
|
|
232
|
+
genesis: genesisChange.cid.toString(),
|
|
233
|
+
generation
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const prepareInput = {
|
|
237
|
+
account: input.account,
|
|
238
|
+
path: input.path,
|
|
239
|
+
baseVersion: input.baseVersion,
|
|
240
|
+
changes: input.changes,
|
|
241
|
+
capability: input.capability,
|
|
242
|
+
visibility: input.visibility
|
|
243
|
+
};
|
|
244
|
+
const { unsignedChange } = await request("PrepareDocumentChange", prepareInput);
|
|
245
|
+
const { publishInput } = await signDocumentChange(
|
|
246
|
+
{
|
|
247
|
+
account: input.account,
|
|
248
|
+
path: input.path,
|
|
249
|
+
unsignedChange,
|
|
250
|
+
genesis: input.genesis,
|
|
251
|
+
generation: input.generation,
|
|
252
|
+
capability: input.capability,
|
|
253
|
+
visibility: input.visibility
|
|
254
|
+
},
|
|
255
|
+
signer
|
|
256
|
+
);
|
|
257
|
+
await publish(publishInput);
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
baseUrl: normalizedBaseUrl,
|
|
261
|
+
request,
|
|
262
|
+
publish,
|
|
263
|
+
publishBlobs: publish,
|
|
264
|
+
publishDocument
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function formatHTTPErrorMessage(key, status, statusText, body) {
|
|
268
|
+
const base = `HTTP ${status} from ${key}: ${statusText}`;
|
|
269
|
+
if (!body) return base;
|
|
270
|
+
try {
|
|
271
|
+
const parsed = JSON.parse(body);
|
|
272
|
+
if (parsed && typeof parsed === "object" && typeof parsed.error === "string" && parsed.error.trim()) {
|
|
273
|
+
return `${base}: ${parsed.error}`;
|
|
274
|
+
}
|
|
275
|
+
} catch {
|
|
276
|
+
}
|
|
277
|
+
const trimmed = body.trim();
|
|
278
|
+
return trimmed ? `${base}: ${trimmed}` : base;
|
|
279
|
+
}
|
|
280
|
+
function isAbortError(err) {
|
|
281
|
+
return typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError";
|
|
282
|
+
}
|
|
283
|
+
function stripUndefined(obj) {
|
|
284
|
+
if (obj === null || obj === void 0 || typeof obj !== "object") return obj;
|
|
285
|
+
if (ArrayBuffer.isView(obj) || obj instanceof ArrayBuffer) return obj;
|
|
286
|
+
if (Array.isArray(obj)) return obj.map(stripUndefined);
|
|
287
|
+
const result = {};
|
|
288
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
289
|
+
if (v !== void 0) result[k] = stripUndefined(v);
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export {
|
|
295
|
+
deserializeQueryString,
|
|
296
|
+
createSeedClient
|
|
297
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/cbor.ts
|
|
2
|
+
import * as dagCBOR from "@ipld/dag-cbor";
|
|
3
|
+
import * as cborg from "cborg";
|
|
4
|
+
var encodeOpts = {
|
|
5
|
+
...dagCBOR.encodeOptions,
|
|
6
|
+
typeEncoders: {
|
|
7
|
+
...dagCBOR.encodeOptions.typeEncoders,
|
|
8
|
+
undefined: () => null
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var code2 = dagCBOR.code;
|
|
12
|
+
function encode2(obj) {
|
|
13
|
+
return cborg.encode(obj, encodeOpts);
|
|
14
|
+
}
|
|
15
|
+
function decode2(data) {
|
|
16
|
+
return dagCBOR.decode(data);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
encodeOpts,
|
|
21
|
+
code2 as code,
|
|
22
|
+
encode2 as encode,
|
|
23
|
+
decode2 as decode
|
|
24
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveId
|
|
3
|
+
} from "./chunk-YNVFRCUH.mjs";
|
|
4
|
+
import {
|
|
5
|
+
createSeedClient
|
|
6
|
+
} from "./chunk-3KESF5XJ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
unpackHmId
|
|
9
|
+
} from "./chunk-SQEUO7FO.mjs";
|
|
10
|
+
|
|
11
|
+
// src/resource-read.ts
|
|
12
|
+
async function resolveIdWithClient(rawId, options = {}) {
|
|
13
|
+
const commentId = extractCommentIdFromReadableUrl(rawId);
|
|
14
|
+
const parsed = commentId ? commentIdToHmId(commentId) : unpackHmId(rawId);
|
|
15
|
+
if (parsed) {
|
|
16
|
+
if (isWebUrl(rawId)) {
|
|
17
|
+
const origin2 = new URL(rawId).origin;
|
|
18
|
+
return { id: parsed, client: createSeedClient(origin2), serverUrl: origin2 };
|
|
19
|
+
}
|
|
20
|
+
const client = options.client ?? createSeedClient(normalizeServerUrl(options.serverUrl || "https://hyper.media"));
|
|
21
|
+
return { id: parsed, client, serverUrl: client.baseUrl };
|
|
22
|
+
}
|
|
23
|
+
const id = await resolveId(rawId, { domainResolver: options.domainResolver });
|
|
24
|
+
const origin = new URL(rawId).origin;
|
|
25
|
+
return { id, client: createSeedClient(origin), serverUrl: origin };
|
|
26
|
+
}
|
|
27
|
+
var COMMENT_VIEW_TERMS = /* @__PURE__ */ new Set([":comments", ":comment", ":discussions"]);
|
|
28
|
+
function extractCommentIdFromReadableUrl(rawId) {
|
|
29
|
+
if (isWebUrl(rawId)) {
|
|
30
|
+
const url = new URL(rawId);
|
|
31
|
+
const panelCommentId = extractCommentIdFromPanel(url.searchParams.get("panel"));
|
|
32
|
+
if (panelCommentId) return panelCommentId;
|
|
33
|
+
return extractCommentIdFromPath(url.pathname.split("/").filter(Boolean));
|
|
34
|
+
}
|
|
35
|
+
const [withoutHash] = rawId.split("#");
|
|
36
|
+
const [withoutQuery] = withoutHash.split("?");
|
|
37
|
+
const parsed = unpackHmId(withoutQuery);
|
|
38
|
+
return (parsed == null ? void 0 : parsed.path) ? extractCommentIdFromPath(parsed.path) : null;
|
|
39
|
+
}
|
|
40
|
+
function extractCommentIdFromPanel(panel) {
|
|
41
|
+
if (!panel) return null;
|
|
42
|
+
const [viewTerm, first, second] = panel.split("/");
|
|
43
|
+
if (viewTerm !== "comments" && viewTerm !== "comment" && viewTerm !== "discussions") return null;
|
|
44
|
+
if (first && second) return `${first}/${second}`;
|
|
45
|
+
return first || null;
|
|
46
|
+
}
|
|
47
|
+
function extractCommentIdFromPath(pathParts) {
|
|
48
|
+
if (pathParts.length >= 3) {
|
|
49
|
+
const thirdToLast = pathParts[pathParts.length - 3];
|
|
50
|
+
if (thirdToLast && COMMENT_VIEW_TERMS.has(thirdToLast)) {
|
|
51
|
+
return `${pathParts[pathParts.length - 2]}/${pathParts[pathParts.length - 1]}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (pathParts.length >= 2) {
|
|
55
|
+
const secondToLast = pathParts[pathParts.length - 2];
|
|
56
|
+
if (secondToLast && COMMENT_VIEW_TERMS.has(secondToLast)) return pathParts[pathParts.length - 1] || null;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
function commentIdToHmId(commentId) {
|
|
61
|
+
const parsed = unpackHmId(`hm://${commentId}`);
|
|
62
|
+
if (!parsed) throw new Error(`Invalid comment ID: ${commentId}`);
|
|
63
|
+
return parsed;
|
|
64
|
+
}
|
|
65
|
+
function isWebUrl(rawId) {
|
|
66
|
+
return rawId.startsWith("http://") || rawId.startsWith("https://");
|
|
67
|
+
}
|
|
68
|
+
function normalizeServerUrl(serverUrl) {
|
|
69
|
+
const withScheme = serverUrl.startsWith("http://") || serverUrl.startsWith("https://") ? serverUrl : `https://${serverUrl}`;
|
|
70
|
+
return withScheme.replace(/\/+$/, "");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
resolveIdWithClient
|
|
75
|
+
};
|