@tdacorp/hyle-sdk 0.23.0 → 0.24.0
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/README.md +35 -19
- package/dist/check-routes-bin.js +28 -15
- package/dist/{chunk-YHXE3TGS.js → chunk-4REU4HJI.js} +27 -15
- package/dist/{chunk-UFMKLCXS.js → chunk-5TKJH2XC.js} +2 -2
- package/dist/{chunk-VXARM37R.js → chunk-BDFMNY76.js} +11 -5
- package/dist/{chunk-VUML2UPD.js → chunk-SY2FMIRZ.js} +1 -1
- package/dist/{chunk-JHZJOJDC.js → chunk-Y3BACEWA.js} +1 -1
- package/dist/{client--ighAWaj.d.ts → client-BErei7cE.d.ts} +5 -4
- package/dist/{client-DK-S2580.d.cts → client-DrB2vcTi.d.cts} +5 -4
- package/dist/comments.cjs +3 -2
- package/dist/comments.js +3 -2
- package/dist/{embed-XT0x_Jaa.d.cts → embed-B7T--kTT.d.cts} +1 -1
- package/dist/{embed-g7NT1CyB.d.ts → embed-DavTgSU4.d.ts} +1 -1
- package/dist/html.cjs +3 -2
- package/dist/html.js +2 -2
- package/dist/index.cjs +28 -15
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.cjs +233 -148
- package/dist/next.d.cts +36 -31
- package/dist/next.d.ts +36 -31
- package/dist/next.js +204 -135
- package/dist/react.cjs +3 -2
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/{resolve-CiZCPysX.d.cts → resolve-03IVloXU.d.cts} +1 -1
- package/dist/{resolve-BqC9l5RH.d.ts → resolve-BseM68oy.d.ts} +1 -1
- package/dist/{types-b9QbmEDd.d.cts → types-Dx-fEiZd.d.cts} +25 -5
- package/dist/{types-b9QbmEDd.d.ts → types-Dx-fEiZd.d.ts} +25 -5
- package/dist/use-cache.cjs +28 -15
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ const html = hastToHtml(article.content.tree, { baseUrl: "https://example.com/bl
|
|
|
116
116
|
| `@tdacorp/hyle-sdk` | `createHyleClient` (typed `resolve`, `mounts`, `preview` and `asset`), `listPublicationPaths`, `checkRoutes` and the other route-check functions, `Cp1ClientError`, `verifyHyleSignature`, `parseSignatureHeader`, `isValidCacheTag`, `DeliveryDedupe`, `createRevalidationCallbackRoute`, `parseCommentEvent`, the result types | nothing (no framework) |
|
|
117
117
|
| `@tdacorp/hyle-sdk/react` | `ArticlePage`, `Comments`, `HyleReactions`, `ListPage`, `HyleListView`, `HyleArticleView`, `DocsPage`, `NotFound`, `Redirecting`, `Unavailable`, `HyleBody`, `HyleToc`, `HastContent`, `TrustedServerHtml`, `sanitizeHast` | react >= 19 |
|
|
118
118
|
| `@tdacorp/hyle-sdk/html` | `hastToHtml`, `HastLimitError` (server only) | nothing (no framework) |
|
|
119
|
-
| `@tdacorp/hyle-sdk/next` | `hylePage`, `hyleMetadata`, `hyleSitemap`, `hyleFeed`, `hyleRootPage`, `hyleRootMetadata`, `hyleRootSitemap`, `createMarkdownRoute`, `markdownRewritePath`, `createLlmsTxtRoute`, `createRevalidateRoute`, `createAssetRoute`, `createOgImageRoute`, `createEngagementRoute`, `hylePreviewPage`, `hylePreviewMetadata`, `
|
|
119
|
+
| `@tdacorp/hyle-sdk/next` | `hylePage`, `hyleMetadata`, `hyleSitemap`, `hyleFeed`, `hyleRootPage`, `hyleRootMetadata`, `hyleRootSitemap`, `createMarkdownRoute`, `markdownRewritePath`, `createLlmsTxtRoute`, `createRevalidateRoute`, `createAssetRoute`, `createOgImageRoute`, `createEngagementRoute`, `hylePreviewPage`, `hylePreviewMetadata`, `hyleProtectedMetadata`, `createProtectedUnlockRoute`, `hyleProtectedProxy`, `hyleProtectedPage`, `HyleList`, `HyleArticle`, `HyleComments`, `HyleCommentsFallback`, `fetchResolver`, `workspaceTags` | next >= 16 |
|
|
120
120
|
| `@tdacorp/hyle-sdk/next/use-cache` | `cachedResolver` | next >= 16 with `cacheComponents: true` |
|
|
121
121
|
| `@tdacorp/hyle-sdk/styles.css` | the stylesheet | |
|
|
122
122
|
|
|
@@ -425,36 +425,52 @@ The token is a bearer secret for that draft, together with your read credential,
|
|
|
425
425
|
- The token is in the page URL and the image URLs, so your access logs and the browser's history record it, and any script on the page can read it from `location.href`. Keep analytics, error reporting and other third-party scripts off this route, including ones your root layout adds to every page.
|
|
426
426
|
- Your proxy or middleware must let `/hyle-preview` through without a sign-in redirect that copies the URL elsewhere, and a catch-all must not claim it.
|
|
427
427
|
|
|
428
|
-
## Protected
|
|
428
|
+
## Protected shares
|
|
429
429
|
|
|
430
|
-
A protected
|
|
431
|
-
|
|
432
|
-
Two route files, ready made:
|
|
433
|
-
|
|
434
|
-
```ts
|
|
435
|
-
// app/p/[id]/page.tsx
|
|
436
|
-
import { hyleProtectedMetadata, hyleProtectedPage } from "@tdacorp/hyle-sdk/next";
|
|
437
|
-
|
|
438
|
-
export const metadata = hyleProtectedMetadata;
|
|
439
|
-
export default hyleProtectedPage({ baseUrl: process.env.HYLE_TARGET_BASE_URL!, token: process.env.HYLE_TARGET_TOKEN! });
|
|
440
|
-
```
|
|
430
|
+
A protected share is a named group of documents that a visitor opens with a password (hyle ADR 0040). It is never published: it is in no list, sitemap, feed or search, and its pages are `noindex`. The share is reachable at a slug on your site, for example `/news/field-notes`, and `/news/field-notes/<doc>` for one of its documents. Your existing catch-all serves it, so the only route file to add is the unlock route:
|
|
441
431
|
|
|
442
432
|
```ts
|
|
443
|
-
// app/
|
|
433
|
+
// app/hyle-protected/unlock/route.ts
|
|
444
434
|
import { createProtectedUnlockRoute } from "@tdacorp/hyle-sdk/next";
|
|
445
435
|
|
|
446
436
|
export const { POST } = createProtectedUnlockRoute();
|
|
447
437
|
```
|
|
448
438
|
|
|
449
|
-
Without a cookie the page shows a password form (labelled, `autocomplete="off"`, the error announced) that posts to `/
|
|
439
|
+
`hyleRootPage` checks the slugs hyle reports in `GET /cp1/read/mounts` (`protected`) together with the mounts, and a path under a live slug is drawn without any resolve call. The longest entry wins, a share beating a mount only when it is longer, or equally long and of the same workspace config: one workspace's share never hides another workspace's mount. **A share hides everything under its slug** (`/<slug>` and `/<slug>/<doc>`), so a slug must not be a path or the parent of a path your host serves itself (`/learn` would take your own `/learn/notes`). hyle refuses a slug at, above or under a reserved path (`reserved_paths`, and the routes `hyle-sdk-check-routes --sync` sends as `host_reserved_paths`); a host route that was never synced is yours to keep out of share slugs. Without a cookie the page shows a password form (labelled, `autocomplete="off"`, the error announced) under a generic "Password required" heading. hyle's gate reply carries no share name, so a slug reveals only that a share exists. The form posts `slug` and `password` to `/hyle-protected/unlock`. The unlock route checks that the POST is same-origin and that its form body is at most 1 KiB, stores the password in an `HttpOnly`, `Secure`, `SameSite=Lax` cookie for 12 hours, scoped to `Path=/<slug>` and, for the share's images, to `Path=/api/hyle/assets` (never `Path=/`, so no other request of your host carries it), and redirects to `/<slug>`. It never calls hyle, so one view is one open. The page then asks hyle with `client.protected(slug, password, docSlug?)`: a wrong or expired password shows the form again with "Wrong or expired password". A good one draws one document as an article, or several as the docs layout with a sidebar that highlights the current document. The cookie is named `hyle_p_` and 16 characters of a hash of the slug, so one visitor can hold a password for each share.
|
|
440
|
+
|
|
441
|
+
The password must be 12 to 128 visible ASCII characters (no space, quote, comma, semicolon, percent sign or backslash), so it fits a cookie and a header unchanged. It is sent to hyle only in the `cp-protected` header, and a malformed slug or password is refused before anything is sent. The redirect target is built from the validated slug alone. Nothing is logged. Keep analytics off the protected paths: a page URL is shared with the person who holds the password.
|
|
442
|
+
|
|
443
|
+
Every answer that involves a protected share is `Cache-Control: no-store`, `X-Robots-Tag: noindex, nofollow` and `Referrer-Policy: no-referrer`. The unlock form is accepted by `Sec-Fetch-Site: same-origin` (whatever the `Origin`) or, when the browser does not send it, by `Origin` against the request's host, so a host that sets a global `Referrer-Policy: no-referrer` keeps working.
|
|
444
|
+
|
|
445
|
+
Images of a share go through `createAssetRoute` (`?hyle_protected=<slug>` reads the same cookie, and the route asks hyle for `?protected=<slug>` with the password in `cp-protected`). A basePath, or a locale-prefix middleware that rewrites or redirects the share paths, breaks it: leave the share slugs and `/hyle-protected/unlock` out of any basePath, locale or rewrite rule.
|
|
450
446
|
|
|
451
|
-
|
|
447
|
+
**A static or ISR catch-all needs two more files.** A share is read with the visitor's cookie, and a page with `export const revalidate = 3600` or `generateStaticParams` cannot read a cookie at request time: Next answers 500 (`DYNAMIC_SERVER_USAGE`) for the password form and the share alike (measured on Next 16.5; a catch-all with `export const dynamic = "force-dynamic"`, or with neither `revalidate` nor `generateStaticParams`, is rendered per request and needs nothing here). On such a host a share is drawn by a dynamic route that the host's proxy rewrites to, so the share URL does not change and the other pages stay cached:
|
|
452
448
|
|
|
453
|
-
|
|
449
|
+
```ts
|
|
450
|
+
// proxy.ts (Next 16; middleware.ts on older versions). Keep your own matcher, and leave /_next, /api and /hyle-protected out of it.
|
|
451
|
+
import { NextResponse, type NextRequest } from "next/server";
|
|
452
|
+
import { hyleProtectedProxy } from "@tdacorp/hyle-sdk/next";
|
|
453
|
+
import { configs } from "./hyle-configs"; // the array you pass to hyleRootPage
|
|
454
|
+
|
|
455
|
+
const share = hyleProtectedProxy(configs);
|
|
456
|
+
export async function proxy(req: NextRequest) {
|
|
457
|
+
return (await share(req)) ?? NextResponse.next();
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
```tsx
|
|
462
|
+
// app/hyle-protected/view/[[...path]]/page.tsx
|
|
463
|
+
import { hyleProtectedMetadata, hyleProtectedPage } from "@tdacorp/hyle-sdk/next";
|
|
464
|
+
import { configs } from "../../../../hyle-configs";
|
|
465
|
+
|
|
466
|
+
export const dynamic = "force-dynamic";
|
|
467
|
+
export const metadata = hyleProtectedMetadata;
|
|
468
|
+
export default hyleProtectedPage(configs);
|
|
469
|
+
```
|
|
454
470
|
|
|
455
|
-
|
|
471
|
+
`hyleProtectedProxy` rewrites a path to `/hyle-protected/view/<path>` only when it is under a slug hyle lists as protected, and returns `undefined` for everything else. A proxy has no fetch cache, so it keeps one read of hyle's mounts per config in memory for 30 seconds (shared by concurrent requests; the last good copy is used when a refresh fails) and matches every path against it locally, so random paths cost no call to hyle: a new share is rewritten within 30 seconds, a mounts read that fails with no copy counts as "not a share" for those 30 seconds. Without the proxy, a share on such a host is the 500 above.
|
|
456
472
|
|
|
457
|
-
Requires a Hyle with migration
|
|
473
|
+
Requires a Hyle with migration 0111 and the `GET /cp1/read/_protected` and `GET /cp1/read/_protected/gate` routes (ADR 0040).
|
|
458
474
|
|
|
459
475
|
## Comments, votes and reactions
|
|
460
476
|
|
package/dist/check-routes-bin.js
CHANGED
|
@@ -16,9 +16,11 @@ var PREVIEW_PARAM = "hyle_preview";
|
|
|
16
16
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
17
17
|
var PROTECTED_PARAM = "hyle_protected";
|
|
18
18
|
var PROTECTED_HEADER = "cp-protected";
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
19
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
20
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
21
|
+
var PROTECTED_DOC_SLUG = /^[a-z0-9-]+$/;
|
|
22
|
+
var PROTECTED_PASSWORD = /^[\x21\x23-\x24\x26-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]{12,128}$/;
|
|
23
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
22
24
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
23
25
|
|
|
24
26
|
// src/errors.ts
|
|
@@ -100,7 +102,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
100
102
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
101
103
|
function isMounts(data) {
|
|
102
104
|
const mounts = data.mounts;
|
|
103
|
-
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string");
|
|
105
|
+
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string") && (data.protected === void 0 || isStrings(data.protected));
|
|
104
106
|
}
|
|
105
107
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
106
108
|
let origin;
|
|
@@ -183,22 +185,35 @@ function createHyleClient(options) {
|
|
|
183
185
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
184
186
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
185
187
|
}
|
|
186
|
-
async function
|
|
187
|
-
if (!
|
|
188
|
-
const reply = await get("/cp1/read/_protected", new URLSearchParams(
|
|
188
|
+
async function protectedGate(slug) {
|
|
189
|
+
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
190
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
191
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
192
|
+
const data = reply.parsed?.data;
|
|
193
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
194
|
+
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
195
|
+
throw failure(reply);
|
|
196
|
+
}
|
|
197
|
+
async function protectedShare(slug, password, docSlug) {
|
|
198
|
+
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
199
|
+
const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
|
|
200
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
189
201
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
190
202
|
const data = reply.parsed?.data;
|
|
191
203
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
192
204
|
const article = data?.article;
|
|
193
|
-
const expires = data
|
|
194
|
-
if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
195
|
-
return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${
|
|
205
|
+
const { name, expires_at: expires, documents, doc_slug: current } = data ?? {};
|
|
206
|
+
if (data?.cp !== 1 || data.kind !== "protected" || typeof name !== "string" || typeof expires !== "string" && expires !== null || !Array.isArray(documents) || typeof current !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
207
|
+
return { cp: 1, kind: "protected", name, expires_at: expires, documents, doc_slug: current, article: withAssetQuery(article, `${PROTECTED_PARAM}=${slug}`) };
|
|
196
208
|
}
|
|
197
209
|
async function asset(file, opts = {}) {
|
|
198
210
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
199
211
|
const { previewToken } = opts;
|
|
200
212
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
201
|
-
const
|
|
213
|
+
const { protectedAccess } = opts;
|
|
214
|
+
if (protectedAccess !== void 0 && !(PROTECTED_SLUG.test(protectedAccess.slug) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a share slug and password");
|
|
215
|
+
const query = protectedAccess === void 0 ? "" : `?protected=${encodeURIComponent(protectedAccess.slug)}`;
|
|
216
|
+
const url = `${base}/cp1/read/assets/${file}${query}`;
|
|
202
217
|
const headers = new Headers();
|
|
203
218
|
const applied = applyCredential(headers, options, "GET", url);
|
|
204
219
|
if (applied) await applied;
|
|
@@ -206,10 +221,8 @@ function createHyleClient(options) {
|
|
|
206
221
|
const value = opts.headers?.[name];
|
|
207
222
|
if (value) headers.set(name, value);
|
|
208
223
|
}
|
|
209
|
-
const { protectedAccess } = opts;
|
|
210
|
-
if (protectedAccess !== void 0 && !(PROTECTED_ID.test(protectedAccess.pageId) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a page id and password");
|
|
211
224
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
212
|
-
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER,
|
|
225
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
213
226
|
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
214
227
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
215
228
|
}
|
|
@@ -220,7 +233,7 @@ function createHyleClient(options) {
|
|
|
220
233
|
if (applied) await applied;
|
|
221
234
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
222
235
|
}
|
|
223
|
-
return { resolve, mounts, pushPosts, preview, protected:
|
|
236
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
224
237
|
}
|
|
225
238
|
|
|
226
239
|
// src/host-sync.ts
|
|
@@ -5,11 +5,12 @@ import {
|
|
|
5
5
|
PREVIEW_HEADER,
|
|
6
6
|
PREVIEW_PARAM,
|
|
7
7
|
PREVIEW_TOKEN,
|
|
8
|
+
PROTECTED_DOC_SLUG,
|
|
8
9
|
PROTECTED_HEADER,
|
|
9
|
-
PROTECTED_ID,
|
|
10
10
|
PROTECTED_PARAM,
|
|
11
|
-
PROTECTED_PASSWORD
|
|
12
|
-
|
|
11
|
+
PROTECTED_PASSWORD,
|
|
12
|
+
PROTECTED_SLUG
|
|
13
|
+
} from "./chunk-BDFMNY76.js";
|
|
13
14
|
|
|
14
15
|
// src/errors.ts
|
|
15
16
|
var Cp1ClientError = class extends Error {
|
|
@@ -101,7 +102,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
101
102
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
102
103
|
function isMounts(data) {
|
|
103
104
|
const mounts = data.mounts;
|
|
104
|
-
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string");
|
|
105
|
+
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string") && (data.protected === void 0 || isStrings(data.protected));
|
|
105
106
|
}
|
|
106
107
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
107
108
|
let origin;
|
|
@@ -184,22 +185,35 @@ function createHyleClient(options) {
|
|
|
184
185
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
185
186
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
186
187
|
}
|
|
187
|
-
async function
|
|
188
|
-
if (!
|
|
189
|
-
const reply = await get("/cp1/read/_protected", new URLSearchParams(
|
|
188
|
+
async function protectedGate(slug) {
|
|
189
|
+
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
190
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
191
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
192
|
+
const data = reply.parsed?.data;
|
|
193
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
194
|
+
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
195
|
+
throw failure(reply);
|
|
196
|
+
}
|
|
197
|
+
async function protectedShare(slug, password, docSlug) {
|
|
198
|
+
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
199
|
+
const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
|
|
200
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
190
201
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
191
202
|
const data = reply.parsed?.data;
|
|
192
203
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
193
204
|
const article = data?.article;
|
|
194
|
-
const expires = data
|
|
195
|
-
if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
196
|
-
return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${
|
|
205
|
+
const { name, expires_at: expires, documents, doc_slug: current } = data ?? {};
|
|
206
|
+
if (data?.cp !== 1 || data.kind !== "protected" || typeof name !== "string" || typeof expires !== "string" && expires !== null || !Array.isArray(documents) || typeof current !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
207
|
+
return { cp: 1, kind: "protected", name, expires_at: expires, documents, doc_slug: current, article: withAssetQuery(article, `${PROTECTED_PARAM}=${slug}`) };
|
|
197
208
|
}
|
|
198
209
|
async function asset(file, opts = {}) {
|
|
199
210
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
200
211
|
const { previewToken } = opts;
|
|
201
212
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
202
|
-
const
|
|
213
|
+
const { protectedAccess } = opts;
|
|
214
|
+
if (protectedAccess !== void 0 && !(PROTECTED_SLUG.test(protectedAccess.slug) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a share slug and password");
|
|
215
|
+
const query = protectedAccess === void 0 ? "" : `?protected=${encodeURIComponent(protectedAccess.slug)}`;
|
|
216
|
+
const url = `${base}/cp1/read/assets/${file}${query}`;
|
|
203
217
|
const headers = new Headers();
|
|
204
218
|
const applied = applyCredential(headers, options, "GET", url);
|
|
205
219
|
if (applied) await applied;
|
|
@@ -207,10 +221,8 @@ function createHyleClient(options) {
|
|
|
207
221
|
const value = opts.headers?.[name];
|
|
208
222
|
if (value) headers.set(name, value);
|
|
209
223
|
}
|
|
210
|
-
const { protectedAccess } = opts;
|
|
211
|
-
if (protectedAccess !== void 0 && !(PROTECTED_ID.test(protectedAccess.pageId) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a page id and password");
|
|
212
224
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
213
|
-
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER,
|
|
225
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
214
226
|
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
215
227
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
216
228
|
}
|
|
@@ -221,7 +233,7 @@ function createHyleClient(options) {
|
|
|
221
233
|
if (applied) await applied;
|
|
222
234
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
223
235
|
}
|
|
224
|
-
return { resolve, mounts, pushPosts, preview, protected:
|
|
236
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
225
237
|
}
|
|
226
238
|
|
|
227
239
|
// src/host-sync.ts
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
scopeId,
|
|
10
10
|
stringsFor,
|
|
11
11
|
youtubeId
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-Y3BACEWA.js";
|
|
13
13
|
import {
|
|
14
14
|
hostAssetHtml,
|
|
15
15
|
themeFontHrefs,
|
|
16
16
|
themeStylesheetHref
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-BDFMNY76.js";
|
|
18
18
|
|
|
19
19
|
// src/react/content.tsx
|
|
20
20
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime";
|
|
@@ -20,10 +20,15 @@ var PREVIEW_PARAM = "hyle_preview";
|
|
|
20
20
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
21
21
|
var PROTECTED_PARAM = "hyle_protected";
|
|
22
22
|
var PROTECTED_HEADER = "cp-protected";
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
23
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
24
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
25
|
+
var PROTECTED_DOC_SLUG = /^[a-z0-9-]+$/;
|
|
26
|
+
var PROTECTED_PASSWORD = /^[\x21\x23-\x24\x26-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]{12,128}$/;
|
|
27
|
+
async function protectedCookieName(slug) {
|
|
28
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(slug));
|
|
29
|
+
return `hyle_p_${Buffer.from(digest).toString("base64url").slice(0, 16)}`;
|
|
30
|
+
}
|
|
31
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
27
32
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
28
33
|
function hostAssetSrc(src) {
|
|
29
34
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
@@ -59,7 +64,8 @@ export {
|
|
|
59
64
|
PREVIEW_QUERY_SOURCE,
|
|
60
65
|
PROTECTED_PARAM,
|
|
61
66
|
PROTECTED_HEADER,
|
|
62
|
-
|
|
67
|
+
PROTECTED_SLUG,
|
|
68
|
+
PROTECTED_DOC_SLUG,
|
|
63
69
|
PROTECTED_PASSWORD,
|
|
64
70
|
protectedCookieName,
|
|
65
71
|
hostAssetSrc,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as Resolved, h as MountsResult, H as HylePreview, e as HyleProtectedGate, d as HyleProtected } from './types-Dx-fEiZd.js';
|
|
2
2
|
|
|
3
3
|
/** docs/cp1-spec.md section 5.3.3: `hyle.push/1`, the whole-post delivery of a path in push mode (ADR 0025). */
|
|
4
4
|
declare const MAX_PUSH_BODY_BYTES: number;
|
|
@@ -187,9 +187,9 @@ interface AssetOptions {
|
|
|
187
187
|
readonly timeoutMs?: number;
|
|
188
188
|
/** A draft preview's token (hyle ADR 0037): hyle then also serves the assets that draft names. The answer is never cached. */
|
|
189
189
|
readonly previewToken?: string;
|
|
190
|
-
/** A protected
|
|
190
|
+
/** A protected share's slug and password (hyle ADR 0040): hyle then also serves that share's assets. The answer is never cached. */
|
|
191
191
|
readonly protectedAccess?: {
|
|
192
|
-
readonly
|
|
192
|
+
readonly slug: string;
|
|
193
193
|
readonly password: string;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
@@ -202,7 +202,8 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
202
202
|
readonly init?: HyleRequestInit;
|
|
203
203
|
}) => Promise<PushPage>;
|
|
204
204
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
-
|
|
205
|
+
protectedGate: (slug: string) => Promise<HyleProtectedGate>;
|
|
206
|
+
protected: (slug: string, password: string, docSlug?: string) => Promise<HyleProtected>;
|
|
206
207
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
207
208
|
theme: (opts?: {
|
|
208
209
|
readonly timeoutMs?: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as Resolved, h as MountsResult, H as HylePreview, e as HyleProtectedGate, d as HyleProtected } from './types-Dx-fEiZd.cjs';
|
|
2
2
|
|
|
3
3
|
/** docs/cp1-spec.md section 5.3.3: `hyle.push/1`, the whole-post delivery of a path in push mode (ADR 0025). */
|
|
4
4
|
declare const MAX_PUSH_BODY_BYTES: number;
|
|
@@ -187,9 +187,9 @@ interface AssetOptions {
|
|
|
187
187
|
readonly timeoutMs?: number;
|
|
188
188
|
/** A draft preview's token (hyle ADR 0037): hyle then also serves the assets that draft names. The answer is never cached. */
|
|
189
189
|
readonly previewToken?: string;
|
|
190
|
-
/** A protected
|
|
190
|
+
/** A protected share's slug and password (hyle ADR 0040): hyle then also serves that share's assets. The answer is never cached. */
|
|
191
191
|
readonly protectedAccess?: {
|
|
192
|
-
readonly
|
|
192
|
+
readonly slug: string;
|
|
193
193
|
readonly password: string;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
@@ -202,7 +202,8 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
202
202
|
readonly init?: HyleRequestInit;
|
|
203
203
|
}) => Promise<PushPage>;
|
|
204
204
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
-
|
|
205
|
+
protectedGate: (slug: string) => Promise<HyleProtectedGate>;
|
|
206
|
+
protected: (slug: string, password: string, docSlug?: string) => Promise<HyleProtected>;
|
|
206
207
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
207
208
|
theme: (opts?: {
|
|
208
209
|
readonly timeoutMs?: number;
|
package/dist/comments.cjs
CHANGED
|
@@ -370,8 +370,9 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
370
370
|
var PREVIEW_PARAM = "hyle_preview";
|
|
371
371
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
372
372
|
var PROTECTED_PARAM = "hyle_protected";
|
|
373
|
-
var
|
|
374
|
-
var
|
|
373
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
374
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
375
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
375
376
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
376
377
|
function hostAssetSrc(src) {
|
|
377
378
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
package/dist/comments.js
CHANGED
|
@@ -126,8 +126,9 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
126
126
|
var PREVIEW_PARAM = "hyle_preview";
|
|
127
127
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
128
128
|
var PROTECTED_PARAM = "hyle_protected";
|
|
129
|
-
var
|
|
130
|
-
var
|
|
129
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
130
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
131
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
131
132
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
132
133
|
function hostAssetSrc(src) {
|
|
133
134
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { m as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-Dx-fEiZd.cjs';
|
|
3
3
|
|
|
4
4
|
type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
|
|
5
5
|
interface LinkProps {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { m as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-Dx-fEiZd.js';
|
|
3
3
|
|
|
4
4
|
type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
|
|
5
5
|
interface LinkProps {
|
package/dist/html.cjs
CHANGED
|
@@ -37,8 +37,9 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
37
37
|
var PREVIEW_PARAM = "hyle_preview";
|
|
38
38
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
39
39
|
var PROTECTED_PARAM = "hyle_protected";
|
|
40
|
-
var
|
|
41
|
-
var
|
|
40
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
41
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
42
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
42
43
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
43
44
|
function hostAssetSrc(src) {
|
|
44
45
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
package/dist/html.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -61,9 +61,11 @@ var PREVIEW_PARAM = "hyle_preview";
|
|
|
61
61
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
62
62
|
var PROTECTED_PARAM = "hyle_protected";
|
|
63
63
|
var PROTECTED_HEADER = "cp-protected";
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
64
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
65
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
66
|
+
var PROTECTED_DOC_SLUG = /^[a-z0-9-]+$/;
|
|
67
|
+
var PROTECTED_PASSWORD = /^[\x21\x23-\x24\x26-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]{12,128}$/;
|
|
68
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
67
69
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
68
70
|
|
|
69
71
|
// src/errors.ts
|
|
@@ -145,7 +147,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
145
147
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
146
148
|
function isMounts(data) {
|
|
147
149
|
const mounts = data.mounts;
|
|
148
|
-
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string");
|
|
150
|
+
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string") && (data.protected === void 0 || isStrings(data.protected));
|
|
149
151
|
}
|
|
150
152
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
151
153
|
let origin;
|
|
@@ -228,22 +230,35 @@ function createHyleClient(options) {
|
|
|
228
230
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
229
231
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
230
232
|
}
|
|
231
|
-
async function
|
|
232
|
-
if (!
|
|
233
|
-
const reply = await get("/cp1/read/_protected", new URLSearchParams(
|
|
233
|
+
async function protectedGate(slug) {
|
|
234
|
+
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
235
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
236
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
237
|
+
const data = reply.parsed?.data;
|
|
238
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
239
|
+
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
240
|
+
throw failure(reply);
|
|
241
|
+
}
|
|
242
|
+
async function protectedShare(slug, password, docSlug) {
|
|
243
|
+
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
244
|
+
const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
|
|
245
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
234
246
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
235
247
|
const data = reply.parsed?.data;
|
|
236
248
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
237
249
|
const article = data?.article;
|
|
238
|
-
const expires = data
|
|
239
|
-
if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
240
|
-
return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${
|
|
250
|
+
const { name, expires_at: expires, documents, doc_slug: current } = data ?? {};
|
|
251
|
+
if (data?.cp !== 1 || data.kind !== "protected" || typeof name !== "string" || typeof expires !== "string" && expires !== null || !Array.isArray(documents) || typeof current !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
252
|
+
return { cp: 1, kind: "protected", name, expires_at: expires, documents, doc_slug: current, article: withAssetQuery(article, `${PROTECTED_PARAM}=${slug}`) };
|
|
241
253
|
}
|
|
242
254
|
async function asset(file, opts = {}) {
|
|
243
255
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
244
256
|
const { previewToken } = opts;
|
|
245
257
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
246
|
-
const
|
|
258
|
+
const { protectedAccess } = opts;
|
|
259
|
+
if (protectedAccess !== void 0 && !(PROTECTED_SLUG.test(protectedAccess.slug) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a share slug and password");
|
|
260
|
+
const query = protectedAccess === void 0 ? "" : `?protected=${encodeURIComponent(protectedAccess.slug)}`;
|
|
261
|
+
const url = `${base}/cp1/read/assets/${file}${query}`;
|
|
247
262
|
const headers = new Headers();
|
|
248
263
|
const applied = applyCredential(headers, options, "GET", url);
|
|
249
264
|
if (applied) await applied;
|
|
@@ -251,10 +266,8 @@ function createHyleClient(options) {
|
|
|
251
266
|
const value = opts.headers?.[name];
|
|
252
267
|
if (value) headers.set(name, value);
|
|
253
268
|
}
|
|
254
|
-
const { protectedAccess } = opts;
|
|
255
|
-
if (protectedAccess !== void 0 && !(PROTECTED_ID.test(protectedAccess.pageId) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a page id and password");
|
|
256
269
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
257
|
-
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER,
|
|
270
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
258
271
|
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
259
272
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
260
273
|
}
|
|
@@ -265,7 +278,7 @@ function createHyleClient(options) {
|
|
|
265
278
|
if (applied) await applied;
|
|
266
279
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
267
280
|
}
|
|
268
|
-
return { resolve, mounts, pushPosts, preview, protected:
|
|
281
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
269
282
|
}
|
|
270
283
|
|
|
271
284
|
// src/host-sync.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HyleAuth, a as HyleClient } from './client-
|
|
2
|
-
export { A as AssetOptions, b as HyleClientOptions, c as HyleCredential, d as HyleRequestInit, M as MAX_PUSH_BODY_BYTES, e as MountsOptions, P as PushEvent, f as PushEventType, g as PushPage, h as PushPost, i as PushRoute, j as PushRouteOptions, k as PushStore, R as ResolveOptions, l as ResyncOptions, m as ResyncResult, n as createHyleClient, o as createPushRoute, r as resyncPath, s as staleAfterResync } from './client-
|
|
3
|
-
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, D as DocumentMetaFields, E as EngageComment, b as EngageHeldComment, c as EngageListing, F as Fallback, H as HylePreview, d as HyleProtected, L as ListItem, M as Mount,
|
|
1
|
+
import { H as HyleAuth, a as HyleClient } from './client-DrB2vcTi.cjs';
|
|
2
|
+
export { A as AssetOptions, b as HyleClientOptions, c as HyleCredential, d as HyleRequestInit, M as MAX_PUSH_BODY_BYTES, e as MountsOptions, P as PushEvent, f as PushEventType, g as PushPage, h as PushPost, i as PushRoute, j as PushRouteOptions, k as PushStore, R as ResolveOptions, l as ResyncOptions, m as ResyncResult, n as createHyleClient, o as createPushRoute, r as resyncPath, s as staleAfterResync } from './client-DrB2vcTi.cjs';
|
|
3
|
+
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, D as DocumentMetaFields, E as EngageComment, b as EngageHeldComment, c as EngageListing, F as Fallback, H as HylePreview, d as HyleProtected, e as HyleProtectedGate, f as HyleProtectedShare, L as ListItem, M as Mount, g as Mounts, h as MountsResult, N as NavItem, i as NavNode, j as NavTree, R as ReactionCounts, k as ReactionKind, l as Resolved, m as ResolvedArticle, n as ResolvedDisabled, o as ResolvedList, p as ResolvedNotFound, q as ResolvedRedirect, T as ThemeRef, r as TocEntry, V as VoteValue } from './types-Dx-fEiZd.cjs';
|
|
4
4
|
export { C as CommentEvent, a as CommentEventType, R as RevalidationCallbackOptions, b as RevalidationCallbackRoute, c as RevalidationPayload, d as createRevalidationCallbackRoute, p as parseCommentEvent } from './revalidation-callback-BQl77tQR.cjs';
|
|
5
5
|
|
|
6
6
|
declare class Cp1ClientError extends Error {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HyleAuth, a as HyleClient } from './client
|
|
2
|
-
export { A as AssetOptions, b as HyleClientOptions, c as HyleCredential, d as HyleRequestInit, M as MAX_PUSH_BODY_BYTES, e as MountsOptions, P as PushEvent, f as PushEventType, g as PushPage, h as PushPost, i as PushRoute, j as PushRouteOptions, k as PushStore, R as ResolveOptions, l as ResyncOptions, m as ResyncResult, n as createHyleClient, o as createPushRoute, r as resyncPath, s as staleAfterResync } from './client
|
|
3
|
-
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, D as DocumentMetaFields, E as EngageComment, b as EngageHeldComment, c as EngageListing, F as Fallback, H as HylePreview, d as HyleProtected, L as ListItem, M as Mount,
|
|
1
|
+
import { H as HyleAuth, a as HyleClient } from './client-BErei7cE.js';
|
|
2
|
+
export { A as AssetOptions, b as HyleClientOptions, c as HyleCredential, d as HyleRequestInit, M as MAX_PUSH_BODY_BYTES, e as MountsOptions, P as PushEvent, f as PushEventType, g as PushPage, h as PushPost, i as PushRoute, j as PushRouteOptions, k as PushStore, R as ResolveOptions, l as ResyncOptions, m as ResyncResult, n as createHyleClient, o as createPushRoute, r as resyncPath, s as staleAfterResync } from './client-BErei7cE.js';
|
|
3
|
+
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, D as DocumentMetaFields, E as EngageComment, b as EngageHeldComment, c as EngageListing, F as Fallback, H as HylePreview, d as HyleProtected, e as HyleProtectedGate, f as HyleProtectedShare, L as ListItem, M as Mount, g as Mounts, h as MountsResult, N as NavItem, i as NavNode, j as NavTree, R as ReactionCounts, k as ReactionKind, l as Resolved, m as ResolvedArticle, n as ResolvedDisabled, o as ResolvedList, p as ResolvedNotFound, q as ResolvedRedirect, T as ThemeRef, r as TocEntry, V as VoteValue } from './types-Dx-fEiZd.js';
|
|
4
4
|
export { C as CommentEvent, a as CommentEventType, R as RevalidationCallbackOptions, b as RevalidationCallbackRoute, c as RevalidationPayload, d as createRevalidationCallbackRoute, p as parseCommentEvent } from './revalidation-callback-BQl77tQR.js';
|
|
5
5
|
|
|
6
6
|
declare class Cp1ClientError extends Error {
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
staleAfterResync,
|
|
24
24
|
syncHostReserved,
|
|
25
25
|
verifyHyleSignature
|
|
26
|
-
} from "./chunk-
|
|
27
|
-
import "./chunk-
|
|
26
|
+
} from "./chunk-4REU4HJI.js";
|
|
27
|
+
import "./chunk-BDFMNY76.js";
|
|
28
28
|
export {
|
|
29
29
|
CACHE_TAG_PATTERN,
|
|
30
30
|
Cp1ClientError,
|