@seed-hypermedia/client 0.0.38 → 0.0.40

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/hm-types.mjs CHANGED
@@ -114,6 +114,10 @@ import {
114
114
  HMPublishBlobsInputSchema,
115
115
  HMPublishBlobsOutputSchema,
116
116
  HMPublishBlobsRequestSchema,
117
+ HMQueryBlockInputSchema,
118
+ HMQueryBlockItemSummarySchema,
119
+ HMQueryBlockPayloadSchema,
120
+ HMQueryBlockRequestSchema,
117
121
  HMQueryInclusionSchema,
118
122
  HMQueryRequestSchema,
119
123
  HMQueryResultSchema,
@@ -172,7 +176,7 @@ import {
172
176
  toNumber,
173
177
  unpackHmId,
174
178
  unpackedHmIdSchema
175
- } from "./chunk-PY2VJAIE.mjs";
179
+ } from "./chunk-2E3HWHST.mjs";
176
180
  export {
177
181
  BackgroundColorAnnotationSchema,
178
182
  BlockRangeSchema,
@@ -289,6 +293,10 @@ export {
289
293
  HMPublishBlobsInputSchema,
290
294
  HMPublishBlobsOutputSchema,
291
295
  HMPublishBlobsRequestSchema,
296
+ HMQueryBlockInputSchema,
297
+ HMQueryBlockItemSummarySchema,
298
+ HMQueryBlockPayloadSchema,
299
+ HMQueryBlockRequestSchema,
292
300
  HMQueryInclusionSchema,
293
301
  HMQueryRequestSchema,
294
302
  HMQueryResultSchema,
package/dist/index.mjs CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  serializeBlockRange,
18
18
  toNumber,
19
19
  unpackHmId
20
- } from "./chunk-PY2VJAIE.mjs";
20
+ } from "./chunk-2E3HWHST.mjs";
21
21
 
22
22
  // src/capability.ts
23
23
  import { encode as cborEncode2 } from "@ipld/dag-cbor";
@@ -2173,10 +2173,9 @@ async function resolveHypermediaUrl(url, opts) {
2173
2173
  let blockRef = null;
2174
2174
  let blockRange = null;
2175
2175
  let panel = null;
2176
- let parsedHostname = null;
2176
+ let parsedUrl = null;
2177
2177
  try {
2178
- const parsedUrl = new URL(url);
2179
- parsedHostname = parsedUrl.hostname;
2178
+ parsedUrl = new URL(url);
2180
2179
  const hasVersion = parsedUrl.searchParams.has("v");
2181
2180
  const hasLatest = parsedUrl.searchParams.has("l");
2182
2181
  panel = parsedUrl.searchParams.get("panel");
@@ -2194,45 +2193,42 @@ async function resolveHypermediaUrl(url, opts) {
2194
2193
  latest = blockRef ? false : hasLatest || !hasVersion;
2195
2194
  } catch {
2196
2195
  }
2197
- if ((opts == null ? void 0 : opts.domainResolver) && parsedHostname) {
2196
+ if ((opts == null ? void 0 : opts.domainResolver) && parsedUrl) {
2198
2197
  try {
2199
- const parsedUrl = new URL(url);
2200
- const uid = await opts.domainResolver(parsedHostname);
2198
+ const uid = await opts.domainResolver(parsedUrl.hostname);
2201
2199
  if (uid) {
2202
- const pathSegments = parsedUrl.pathname.split("/").filter(Boolean);
2203
- const profilePath = resolveProfilePath(uid, pathSegments);
2204
- const resolvedUid = (profilePath == null ? void 0 : profilePath.uid) || uid;
2205
- const path = (profilePath == null ? void 0 : profilePath.path) || (pathSegments.length > 0 ? pathSegments : null);
2206
- const version = parsedUrl.searchParams.get("v") || null;
2207
- const pathStr = path ? "/" + path.join("/") : "";
2208
- const siteHostname = parsedUrl.origin;
2209
- return {
2210
- id: `hm://${resolvedUid}${pathStr}`,
2211
- hmId: {
2212
- id: `hm://${resolvedUid}${pathStr}`,
2213
- uid: resolvedUid,
2214
- path,
2215
- version,
2216
- blockRef,
2217
- blockRange,
2218
- hostname: siteHostname,
2219
- scheme: "hm",
2220
- latest
2221
- },
2222
- version,
2223
- title: null,
2224
- target: null,
2225
- authors: null,
2226
- type: null,
2200
+ return buildResolvedUrlFromDomainUid(parsedUrl, uid, {
2201
+ latest,
2202
+ blockRef,
2203
+ blockRange,
2227
2204
  panel
2228
- };
2205
+ });
2229
2206
  }
2230
2207
  } catch {
2231
2208
  }
2232
2209
  }
2233
- const response = await fetch(url, {
2234
- method: "OPTIONS"
2235
- });
2210
+ let response;
2211
+ try {
2212
+ response = await fetch(url, {
2213
+ method: "OPTIONS"
2214
+ });
2215
+ } catch (error) {
2216
+ if ((opts == null ? void 0 : opts.domainResolver) && parsedUrl) {
2217
+ try {
2218
+ const uid = await opts.domainResolver(parsedUrl.hostname);
2219
+ if (uid) {
2220
+ return buildResolvedUrlFromDomainUid(parsedUrl, uid, {
2221
+ latest,
2222
+ blockRef,
2223
+ blockRange,
2224
+ panel
2225
+ });
2226
+ }
2227
+ } catch {
2228
+ }
2229
+ }
2230
+ throw error;
2231
+ }
2236
2232
  if (response.status === 200) {
2237
2233
  const rawId = response.headers.get("x-hypermedia-id");
2238
2234
  const id = rawId ? decodeURIComponent(rawId) : null;
@@ -2290,6 +2286,40 @@ async function resolveId(input, opts) {
2290
2286
  }
2291
2287
  throw new Error(`Invalid Hypermedia ID: ${input}`);
2292
2288
  }
2289
+ function buildResolvedUrlFromDomainUid(parsedUrl, uid, {
2290
+ latest,
2291
+ blockRef,
2292
+ blockRange,
2293
+ panel
2294
+ }) {
2295
+ const pathSegments = entityQueryPathToHmIdPath(parsedUrl.pathname);
2296
+ const profilePath = resolveProfilePath(uid, pathSegments);
2297
+ const resolvedUid = (profilePath == null ? void 0 : profilePath.uid) || uid;
2298
+ const path = (profilePath == null ? void 0 : profilePath.path) || (pathSegments.length > 0 ? pathSegments : null);
2299
+ const version = parsedUrl.searchParams.get("v") || null;
2300
+ const pathStr = path ? "/" + path.join("/") : "";
2301
+ const siteHostname = parsedUrl.origin;
2302
+ return {
2303
+ id: `hm://${resolvedUid}${pathStr}`,
2304
+ hmId: {
2305
+ id: `hm://${resolvedUid}${pathStr}`,
2306
+ uid: resolvedUid,
2307
+ path,
2308
+ version,
2309
+ blockRef,
2310
+ blockRange,
2311
+ hostname: siteHostname,
2312
+ scheme: "hm",
2313
+ latest
2314
+ },
2315
+ version,
2316
+ title: null,
2317
+ target: null,
2318
+ authors: null,
2319
+ type: null,
2320
+ panel
2321
+ };
2322
+ }
2293
2323
  function resolveProfilePath(siteUid, pathSegments) {
2294
2324
  if (pathSegments[0] !== ":profile") return null;
2295
2325
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-hypermedia/client",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",