@tdacorp/hyle-sdk 0.22.2 → 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 +48 -1
- package/dist/check-routes-bin.js +41 -8
- package/dist/{chunk-KU7LWK4E.js → chunk-4REU4HJI.js} +40 -9
- package/dist/{chunk-ZIW6FDU2.js → chunk-5TKJH2XC.js} +2 -2
- package/dist/{chunk-DUPT6XLB.js → chunk-BDFMNY76.js} +18 -1
- package/dist/{chunk-7T5EEJHK.js → chunk-SY2FMIRZ.js} +1 -1
- package/dist/{chunk-IW3TUD4G.js → chunk-Y3BACEWA.js} +1 -1
- package/dist/{client-BGjmEWhN.d.cts → client-BErei7cE.d.ts} +8 -1
- package/dist/{client-D0LTpr3Y.d.ts → client-DrB2vcTi.d.cts} +8 -1
- package/dist/comments.cjs +5 -1
- package/dist/comments.js +5 -1
- package/dist/{embed-CbtsbZs3.d.cts → embed-B7T--kTT.d.cts} +1 -1
- package/dist/{embed-Cf_2ZR5x.d.ts → embed-DavTgSU4.d.ts} +1 -1
- package/dist/html.cjs +5 -1
- package/dist/html.js +2 -2
- package/dist/index.cjs +41 -8
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.cjs +265 -70
- package/dist/next.d.cts +47 -7
- package/dist/next.d.ts +47 -7
- package/dist/next.js +224 -65
- package/dist/react.cjs +5 -1
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/{resolve-BnIv7aB7.d.cts → resolve-03IVloXU.d.cts} +1 -1
- package/dist/{resolve-BysHtZ_i.d.ts → resolve-BseM68oy.d.ts} +1 -1
- package/dist/{types-D09Z072G.d.cts → types-Dx-fEiZd.d.cts} +33 -1
- package/dist/{types-D09Z072G.d.ts → types-Dx-fEiZd.d.ts} +33 -1
- package/dist/use-cache.cjs +41 -8
- 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`, `HyleList`, `HyleArticle`, `HyleComments`, `HyleCommentsFallback`, `fetchResolver`, `workspaceTags` | next >= 16 |
|
|
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,6 +425,53 @@ 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 shares
|
|
429
|
+
|
|
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:
|
|
431
|
+
|
|
432
|
+
```ts
|
|
433
|
+
// app/hyle-protected/unlock/route.ts
|
|
434
|
+
import { createProtectedUnlockRoute } from "@tdacorp/hyle-sdk/next";
|
|
435
|
+
|
|
436
|
+
export const { POST } = createProtectedUnlockRoute();
|
|
437
|
+
```
|
|
438
|
+
|
|
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.
|
|
446
|
+
|
|
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:
|
|
448
|
+
|
|
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
|
+
```
|
|
470
|
+
|
|
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.
|
|
472
|
+
|
|
473
|
+
Requires a Hyle with migration 0111 and the `GET /cp1/read/_protected` and `GET /cp1/read/_protected/gate` routes (ADR 0040).
|
|
474
|
+
|
|
428
475
|
## Comments, votes and reactions
|
|
429
476
|
|
|
430
477
|
Readers can comment under an article, vote comments up or down and react (like, love, insightful, celebrate) to the article and to comments (hyle ADR 0017 and 0021, `docs/cp1-spec.md` section 3.11). It is off unless you turn it on in three places, and nothing on a cached page changes when someone reacts or votes: the section is fetched in the browser, uncached, after the article has rendered.
|
package/dist/check-routes-bin.js
CHANGED
|
@@ -14,7 +14,14 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
14
14
|
var PREVIEW_HEADER = "cp-preview";
|
|
15
15
|
var PREVIEW_PARAM = "hyle_preview";
|
|
16
16
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
17
|
-
var
|
|
17
|
+
var PROTECTED_PARAM = "hyle_protected";
|
|
18
|
+
var PROTECTED_HEADER = "cp-protected";
|
|
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}`;
|
|
24
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
18
25
|
|
|
19
26
|
// src/errors.ts
|
|
20
27
|
var Cp1ClientError = class extends Error {
|
|
@@ -46,8 +53,8 @@ function mapNode(node, mark, depth) {
|
|
|
46
53
|
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
47
54
|
};
|
|
48
55
|
}
|
|
49
|
-
function
|
|
50
|
-
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${
|
|
56
|
+
function withAssetQuery(article, query) {
|
|
57
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
|
|
51
58
|
const { publication, content } = article;
|
|
52
59
|
return {
|
|
53
60
|
...article,
|
|
@@ -95,7 +102,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
95
102
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
96
103
|
function isMounts(data) {
|
|
97
104
|
const mounts = data.mounts;
|
|
98
|
-
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));
|
|
99
106
|
}
|
|
100
107
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
101
108
|
let origin;
|
|
@@ -176,13 +183,37 @@ function createHyleClient(options) {
|
|
|
176
183
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
177
184
|
const article = data?.article;
|
|
178
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);
|
|
179
|
-
return { kind: "preview", expires_at: data.expires_at, article:
|
|
186
|
+
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
187
|
+
}
|
|
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" });
|
|
201
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
202
|
+
const data = reply.parsed?.data;
|
|
203
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
204
|
+
const article = data?.article;
|
|
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}`) };
|
|
180
208
|
}
|
|
181
209
|
async function asset(file, opts = {}) {
|
|
182
210
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
183
211
|
const { previewToken } = opts;
|
|
184
212
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
185
|
-
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}`;
|
|
186
217
|
const headers = new Headers();
|
|
187
218
|
const applied = applyCredential(headers, options, "GET", url);
|
|
188
219
|
if (applied) await applied;
|
|
@@ -191,7 +222,9 @@ function createHyleClient(options) {
|
|
|
191
222
|
if (value) headers.set(name, value);
|
|
192
223
|
}
|
|
193
224
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
194
|
-
|
|
225
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
226
|
+
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
227
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
195
228
|
}
|
|
196
229
|
async function theme(opts = {}) {
|
|
197
230
|
const url = `${base}/cp1/read/theme.css`;
|
|
@@ -200,7 +233,7 @@ function createHyleClient(options) {
|
|
|
200
233
|
if (applied) await applied;
|
|
201
234
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
202
235
|
}
|
|
203
|
-
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
236
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
204
237
|
}
|
|
205
238
|
|
|
206
239
|
// src/host-sync.ts
|
|
@@ -4,8 +4,13 @@ import {
|
|
|
4
4
|
ASSET_ROUTE_PREFIX,
|
|
5
5
|
PREVIEW_HEADER,
|
|
6
6
|
PREVIEW_PARAM,
|
|
7
|
-
PREVIEW_TOKEN
|
|
8
|
-
|
|
7
|
+
PREVIEW_TOKEN,
|
|
8
|
+
PROTECTED_DOC_SLUG,
|
|
9
|
+
PROTECTED_HEADER,
|
|
10
|
+
PROTECTED_PARAM,
|
|
11
|
+
PROTECTED_PASSWORD,
|
|
12
|
+
PROTECTED_SLUG
|
|
13
|
+
} from "./chunk-BDFMNY76.js";
|
|
9
14
|
|
|
10
15
|
// src/errors.ts
|
|
11
16
|
var Cp1ClientError = class extends Error {
|
|
@@ -37,8 +42,8 @@ function mapNode(node, mark, depth) {
|
|
|
37
42
|
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
38
43
|
};
|
|
39
44
|
}
|
|
40
|
-
function
|
|
41
|
-
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${
|
|
45
|
+
function withAssetQuery(article, query) {
|
|
46
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
|
|
42
47
|
const { publication, content } = article;
|
|
43
48
|
return {
|
|
44
49
|
...article,
|
|
@@ -97,7 +102,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
97
102
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
98
103
|
function isMounts(data) {
|
|
99
104
|
const mounts = data.mounts;
|
|
100
|
-
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));
|
|
101
106
|
}
|
|
102
107
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
103
108
|
let origin;
|
|
@@ -178,13 +183,37 @@ function createHyleClient(options) {
|
|
|
178
183
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
179
184
|
const article = data?.article;
|
|
180
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);
|
|
181
|
-
return { kind: "preview", expires_at: data.expires_at, article:
|
|
186
|
+
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
187
|
+
}
|
|
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" });
|
|
201
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
202
|
+
const data = reply.parsed?.data;
|
|
203
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
204
|
+
const article = data?.article;
|
|
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}`) };
|
|
182
208
|
}
|
|
183
209
|
async function asset(file, opts = {}) {
|
|
184
210
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
185
211
|
const { previewToken } = opts;
|
|
186
212
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
187
|
-
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}`;
|
|
188
217
|
const headers = new Headers();
|
|
189
218
|
const applied = applyCredential(headers, options, "GET", url);
|
|
190
219
|
if (applied) await applied;
|
|
@@ -193,7 +222,9 @@ function createHyleClient(options) {
|
|
|
193
222
|
if (value) headers.set(name, value);
|
|
194
223
|
}
|
|
195
224
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
196
|
-
|
|
225
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
226
|
+
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
227
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
197
228
|
}
|
|
198
229
|
async function theme(opts = {}) {
|
|
199
230
|
const url = `${base}/cp1/read/theme.css`;
|
|
@@ -202,7 +233,7 @@ function createHyleClient(options) {
|
|
|
202
233
|
if (applied) await applied;
|
|
203
234
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
204
235
|
}
|
|
205
|
-
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
236
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
206
237
|
}
|
|
207
238
|
|
|
208
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";
|
|
@@ -18,7 +18,18 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
18
18
|
var PREVIEW_HEADER = "cp-preview";
|
|
19
19
|
var PREVIEW_PARAM = "hyle_preview";
|
|
20
20
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
21
|
-
var
|
|
21
|
+
var PROTECTED_PARAM = "hyle_protected";
|
|
22
|
+
var PROTECTED_HEADER = "cp-protected";
|
|
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}`;
|
|
32
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
22
33
|
function hostAssetSrc(src) {
|
|
23
34
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
24
35
|
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
|
|
@@ -51,6 +62,12 @@ export {
|
|
|
51
62
|
PREVIEW_HEADER,
|
|
52
63
|
PREVIEW_PARAM,
|
|
53
64
|
PREVIEW_QUERY_SOURCE,
|
|
65
|
+
PROTECTED_PARAM,
|
|
66
|
+
PROTECTED_HEADER,
|
|
67
|
+
PROTECTED_SLUG,
|
|
68
|
+
PROTECTED_DOC_SLUG,
|
|
69
|
+
PROTECTED_PASSWORD,
|
|
70
|
+
protectedCookieName,
|
|
54
71
|
hostAssetSrc,
|
|
55
72
|
hostAssetHtml,
|
|
56
73
|
ASSET_CONTENT_TYPES
|
|
@@ -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,6 +187,11 @@ 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 share's slug and password (hyle ADR 0040): hyle then also serves that share's assets. The answer is never cached. */
|
|
191
|
+
readonly protectedAccess?: {
|
|
192
|
+
readonly slug: string;
|
|
193
|
+
readonly password: string;
|
|
194
|
+
};
|
|
190
195
|
}
|
|
191
196
|
declare function createHyleClient(options: HyleClientOptions): {
|
|
192
197
|
resolve: (opts: ResolveOptions) => Promise<Resolved>;
|
|
@@ -197,6 +202,8 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
197
202
|
readonly init?: HyleRequestInit;
|
|
198
203
|
}) => Promise<PushPage>;
|
|
199
204
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
+
protectedGate: (slug: string) => Promise<HyleProtectedGate>;
|
|
206
|
+
protected: (slug: string, password: string, docSlug?: string) => Promise<HyleProtected>;
|
|
200
207
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
201
208
|
theme: (opts?: {
|
|
202
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,6 +187,11 @@ 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 share's slug and password (hyle ADR 0040): hyle then also serves that share's assets. The answer is never cached. */
|
|
191
|
+
readonly protectedAccess?: {
|
|
192
|
+
readonly slug: string;
|
|
193
|
+
readonly password: string;
|
|
194
|
+
};
|
|
190
195
|
}
|
|
191
196
|
declare function createHyleClient(options: HyleClientOptions): {
|
|
192
197
|
resolve: (opts: ResolveOptions) => Promise<Resolved>;
|
|
@@ -197,6 +202,8 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
197
202
|
readonly init?: HyleRequestInit;
|
|
198
203
|
}) => Promise<PushPage>;
|
|
199
204
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
+
protectedGate: (slug: string) => Promise<HyleProtectedGate>;
|
|
206
|
+
protected: (slug: string, password: string, docSlug?: string) => Promise<HyleProtected>;
|
|
200
207
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
201
208
|
theme: (opts?: {
|
|
202
209
|
readonly timeoutMs?: number;
|
package/dist/comments.cjs
CHANGED
|
@@ -369,7 +369,11 @@ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
|
|
|
369
369
|
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
|
-
var
|
|
372
|
+
var PROTECTED_PARAM = "hyle_protected";
|
|
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}`;
|
|
376
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
373
377
|
function hostAssetSrc(src) {
|
|
374
378
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
375
379
|
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
|
package/dist/comments.js
CHANGED
|
@@ -125,7 +125,11 @@ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
|
|
|
125
125
|
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
|
-
var
|
|
128
|
+
var PROTECTED_PARAM = "hyle_protected";
|
|
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}`;
|
|
132
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
129
133
|
function hostAssetSrc(src) {
|
|
130
134
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
131
135
|
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : 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
|
@@ -36,7 +36,11 @@ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
|
|
|
36
36
|
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
|
-
var
|
|
39
|
+
var PROTECTED_PARAM = "hyle_protected";
|
|
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}`;
|
|
43
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
40
44
|
function hostAssetSrc(src) {
|
|
41
45
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
42
46
|
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
|
package/dist/html.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -59,7 +59,14 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
59
59
|
var PREVIEW_HEADER = "cp-preview";
|
|
60
60
|
var PREVIEW_PARAM = "hyle_preview";
|
|
61
61
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
62
|
-
var
|
|
62
|
+
var PROTECTED_PARAM = "hyle_protected";
|
|
63
|
+
var PROTECTED_HEADER = "cp-protected";
|
|
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}`;
|
|
69
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
63
70
|
|
|
64
71
|
// src/errors.ts
|
|
65
72
|
var Cp1ClientError = class extends Error {
|
|
@@ -91,8 +98,8 @@ function mapNode(node, mark, depth) {
|
|
|
91
98
|
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
92
99
|
};
|
|
93
100
|
}
|
|
94
|
-
function
|
|
95
|
-
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${
|
|
101
|
+
function withAssetQuery(article, query) {
|
|
102
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
|
|
96
103
|
const { publication, content } = article;
|
|
97
104
|
return {
|
|
98
105
|
...article,
|
|
@@ -140,7 +147,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
140
147
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
141
148
|
function isMounts(data) {
|
|
142
149
|
const mounts = data.mounts;
|
|
143
|
-
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));
|
|
144
151
|
}
|
|
145
152
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
146
153
|
let origin;
|
|
@@ -221,13 +228,37 @@ function createHyleClient(options) {
|
|
|
221
228
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
222
229
|
const article = data?.article;
|
|
223
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);
|
|
224
|
-
return { kind: "preview", expires_at: data.expires_at, article:
|
|
231
|
+
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
232
|
+
}
|
|
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" });
|
|
246
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
247
|
+
const data = reply.parsed?.data;
|
|
248
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
249
|
+
const article = data?.article;
|
|
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}`) };
|
|
225
253
|
}
|
|
226
254
|
async function asset(file, opts = {}) {
|
|
227
255
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
228
256
|
const { previewToken } = opts;
|
|
229
257
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
230
|
-
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}`;
|
|
231
262
|
const headers = new Headers();
|
|
232
263
|
const applied = applyCredential(headers, options, "GET", url);
|
|
233
264
|
if (applied) await applied;
|
|
@@ -236,7 +267,9 @@ function createHyleClient(options) {
|
|
|
236
267
|
if (value) headers.set(name, value);
|
|
237
268
|
}
|
|
238
269
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
239
|
-
|
|
270
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
271
|
+
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
272
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
240
273
|
}
|
|
241
274
|
async function theme(opts = {}) {
|
|
242
275
|
const url = `${base}/cp1/read/theme.css`;
|
|
@@ -245,7 +278,7 @@ function createHyleClient(options) {
|
|
|
245
278
|
if (applied) await applied;
|
|
246
279
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
247
280
|
}
|
|
248
|
-
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
281
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
249
282
|
}
|
|
250
283
|
|
|
251
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, 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, 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,
|