@seed-hypermedia/client 0.0.38 → 0.0.39
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/index.mjs +65 -35
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -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
|
|
2176
|
+
let parsedUrl = null;
|
|
2177
2177
|
try {
|
|
2178
|
-
|
|
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) &&
|
|
2196
|
+
if ((opts == null ? void 0 : opts.domainResolver) && parsedUrl) {
|
|
2198
2197
|
try {
|
|
2199
|
-
const
|
|
2200
|
-
const uid = await opts.domainResolver(parsedHostname);
|
|
2198
|
+
const uid = await opts.domainResolver(parsedUrl.hostname);
|
|
2201
2199
|
if (uid) {
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
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
|
-
|
|
2234
|
-
|
|
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 {
|