@tdacorp/hyle-sdk 0.22.2 → 0.23.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 +32 -1
- package/dist/check-routes-bin.js +26 -6
- package/dist/{chunk-IW3TUD4G.js → chunk-JHZJOJDC.js} +1 -1
- package/dist/{chunk-ZIW6FDU2.js → chunk-UFMKLCXS.js} +2 -2
- package/dist/{chunk-7T5EEJHK.js → chunk-VUML2UPD.js} +1 -1
- package/dist/{chunk-DUPT6XLB.js → chunk-VXARM37R.js} +12 -1
- package/dist/{chunk-KU7LWK4E.js → chunk-YHXE3TGS.js} +26 -7
- package/dist/{client-BGjmEWhN.d.cts → client--ighAWaj.d.ts} +7 -1
- package/dist/{client-D0LTpr3Y.d.ts → client-DK-S2580.d.cts} +7 -1
- package/dist/comments.cjs +4 -1
- package/dist/comments.js +4 -1
- package/dist/{embed-CbtsbZs3.d.cts → embed-XT0x_Jaa.d.cts} +1 -1
- package/dist/{embed-Cf_2ZR5x.d.ts → embed-g7NT1CyB.d.ts} +1 -1
- package/dist/html.cjs +4 -1
- package/dist/html.js +2 -2
- package/dist/index.cjs +26 -6
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.cjs +128 -18
- package/dist/next.d.cts +42 -7
- package/dist/next.d.ts +42 -7
- package/dist/next.js +108 -18
- package/dist/react.cjs +4 -1
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/{resolve-BysHtZ_i.d.ts → resolve-BqC9l5RH.d.ts} +1 -1
- package/dist/{resolve-BnIv7aB7.d.cts → resolve-CiZCPysX.d.cts} +1 -1
- package/dist/{types-D09Z072G.d.cts → types-b9QbmEDd.d.cts} +13 -1
- package/dist/{types-D09Z072G.d.ts → types-b9QbmEDd.d.ts} +13 -1
- package/dist/use-cache.cjs +26 -6
- 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`, `hyleProtectedPage`, `hyleProtectedMetadata`, `createProtectedUnlockRoute`, `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,37 @@ 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 pages
|
|
429
|
+
|
|
430
|
+
A protected page is a copy of an article that a visitor opens with a password (hyle ADR 0039). It is never published: it is in no list, sitemap, feed or search, and its page is `noindex`. Each invited person has their own password. The site draws it at `/p/<pageId>`.
|
|
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
|
+
```
|
|
441
|
+
|
|
442
|
+
```ts
|
|
443
|
+
// app/p/[id]/unlock/route.ts
|
|
444
|
+
import { createProtectedUnlockRoute } from "@tdacorp/hyle-sdk/next";
|
|
445
|
+
|
|
446
|
+
export const { POST } = createProtectedUnlockRoute();
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
Without a cookie the page shows a password form (labelled, `autocomplete="off"`, the error announced) that posts to `/p/<pageId>/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 named `hyle_p_<pageId>` for 12 hours, and redirects to `/p/<pageId>`. It never calls hyle, so one view is one open. The page then asks hyle with `client.protected(pageId, password)`: a wrong or expired password shows the form again with "Wrong or expired password", and a good one draws the article as a published page does, with its images through `createAssetRoute` (`?hyle_protected=<pageId>` reads the same cookie). The page is rendered per request and is never cached. Every answer that involves a protected page is `Cache-Control: no-store`, `X-Robots-Tag: noindex, nofollow` and `Referrer-Policy: no-referrer`.
|
|
450
|
+
|
|
451
|
+
The password is sent to hyle only in the `cp-protected` header, and a malformed page id or password is refused before anything is sent. The redirect target is built from the validated page id alone. Nothing is logged. Keep analytics off `/p/`, as for `/hyle-preview`: a page URL is shared with the person who holds the password.
|
|
452
|
+
|
|
453
|
+
The page's referrer is `same-origin`, not `no-referrer`: a no-referrer page makes browsers send `Origin: null` on its form POST. The unlock route decides by `Sec-Fetch-Site` when the browser sends it (only `same-origin` is accepted, whatever the `Origin`), and by `Origin` against the request's host otherwise. A host that sets a global `Referrer-Policy: no-referrer` therefore keeps working.
|
|
454
|
+
|
|
455
|
+
The form and its redirect use `/p/<pageId>` from the site root. A `basePath`, or a locale-prefix middleware that rewrites or redirects `/p`, breaks the unlock: keep `/p` (and `/p/<id>/unlock`) out of any basePath, locale or rewrite rule, the same way as `/hyle-preview`.
|
|
456
|
+
|
|
457
|
+
Requires a Hyle with migration 0110 and the `GET /cp1/read/_protected` route (ADR 0039).
|
|
458
|
+
|
|
428
459
|
## Comments, votes and reactions
|
|
429
460
|
|
|
430
461
|
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,12 @@ 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 PROTECTED_ID = new RegExp(`^${UUID}$`);
|
|
20
|
+
var PROTECTED_PASSWORD = /^[A-Za-z0-9]{16}$/;
|
|
21
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
|
|
22
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
18
23
|
|
|
19
24
|
// src/errors.ts
|
|
20
25
|
var Cp1ClientError = class extends Error {
|
|
@@ -46,8 +51,8 @@ function mapNode(node, mark, depth) {
|
|
|
46
51
|
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
47
52
|
};
|
|
48
53
|
}
|
|
49
|
-
function
|
|
50
|
-
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${
|
|
54
|
+
function withAssetQuery(article, query) {
|
|
55
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
|
|
51
56
|
const { publication, content } = article;
|
|
52
57
|
return {
|
|
53
58
|
...article,
|
|
@@ -176,7 +181,18 @@ function createHyleClient(options) {
|
|
|
176
181
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
177
182
|
const article = data?.article;
|
|
178
183
|
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:
|
|
184
|
+
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
185
|
+
}
|
|
186
|
+
async function protectedPage(pageId, password) {
|
|
187
|
+
if (!PROTECTED_ID.test(pageId) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
188
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams(), { headers: { [PROTECTED_HEADER]: `${pageId}.${password}` }, cache: "no-store" });
|
|
189
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
190
|
+
const data = reply.parsed?.data;
|
|
191
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
192
|
+
const article = data?.article;
|
|
193
|
+
const expires = data?.expires_at;
|
|
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}=${pageId}`) };
|
|
180
196
|
}
|
|
181
197
|
async function asset(file, opts = {}) {
|
|
182
198
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
@@ -190,8 +206,12 @@ function createHyleClient(options) {
|
|
|
190
206
|
const value = opts.headers?.[name];
|
|
191
207
|
if (value) headers.set(name, value);
|
|
192
208
|
}
|
|
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");
|
|
193
211
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
194
|
-
|
|
212
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, `${protectedAccess.pageId}.${protectedAccess.password}`);
|
|
213
|
+
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
214
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
195
215
|
}
|
|
196
216
|
async function theme(opts = {}) {
|
|
197
217
|
const url = `${base}/cp1/read/theme.css`;
|
|
@@ -200,7 +220,7 @@ function createHyleClient(options) {
|
|
|
200
220
|
if (applied) await applied;
|
|
201
221
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
202
222
|
}
|
|
203
|
-
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
223
|
+
return { resolve, mounts, pushPosts, preview, protected: protectedPage, asset, theme };
|
|
204
224
|
}
|
|
205
225
|
|
|
206
226
|
// src/host-sync.ts
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
scopeId,
|
|
10
10
|
stringsFor,
|
|
11
11
|
youtubeId
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-JHZJOJDC.js";
|
|
13
13
|
import {
|
|
14
14
|
hostAssetHtml,
|
|
15
15
|
themeFontHrefs,
|
|
16
16
|
themeStylesheetHref
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-VXARM37R.js";
|
|
18
18
|
|
|
19
19
|
// src/react/content.tsx
|
|
20
20
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime";
|
|
@@ -18,7 +18,13 @@ 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 PROTECTED_ID = new RegExp(`^${UUID}$`);
|
|
24
|
+
var PROTECTED_PASSWORD = /^[A-Za-z0-9]{16}$/;
|
|
25
|
+
var protectedCookieName = (pageId) => `hyle_p_${pageId}`;
|
|
26
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
|
|
27
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
22
28
|
function hostAssetSrc(src) {
|
|
23
29
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
24
30
|
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
|
|
@@ -51,6 +57,11 @@ export {
|
|
|
51
57
|
PREVIEW_HEADER,
|
|
52
58
|
PREVIEW_PARAM,
|
|
53
59
|
PREVIEW_QUERY_SOURCE,
|
|
60
|
+
PROTECTED_PARAM,
|
|
61
|
+
PROTECTED_HEADER,
|
|
62
|
+
PROTECTED_ID,
|
|
63
|
+
PROTECTED_PASSWORD,
|
|
64
|
+
protectedCookieName,
|
|
54
65
|
hostAssetSrc,
|
|
55
66
|
hostAssetHtml,
|
|
56
67
|
ASSET_CONTENT_TYPES
|
|
@@ -4,8 +4,12 @@ import {
|
|
|
4
4
|
ASSET_ROUTE_PREFIX,
|
|
5
5
|
PREVIEW_HEADER,
|
|
6
6
|
PREVIEW_PARAM,
|
|
7
|
-
PREVIEW_TOKEN
|
|
8
|
-
|
|
7
|
+
PREVIEW_TOKEN,
|
|
8
|
+
PROTECTED_HEADER,
|
|
9
|
+
PROTECTED_ID,
|
|
10
|
+
PROTECTED_PARAM,
|
|
11
|
+
PROTECTED_PASSWORD
|
|
12
|
+
} from "./chunk-VXARM37R.js";
|
|
9
13
|
|
|
10
14
|
// src/errors.ts
|
|
11
15
|
var Cp1ClientError = class extends Error {
|
|
@@ -37,8 +41,8 @@ function mapNode(node, mark, depth) {
|
|
|
37
41
|
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
38
42
|
};
|
|
39
43
|
}
|
|
40
|
-
function
|
|
41
|
-
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${
|
|
44
|
+
function withAssetQuery(article, query) {
|
|
45
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
|
|
42
46
|
const { publication, content } = article;
|
|
43
47
|
return {
|
|
44
48
|
...article,
|
|
@@ -178,7 +182,18 @@ function createHyleClient(options) {
|
|
|
178
182
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
179
183
|
const article = data?.article;
|
|
180
184
|
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:
|
|
185
|
+
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
186
|
+
}
|
|
187
|
+
async function protectedPage(pageId, password) {
|
|
188
|
+
if (!PROTECTED_ID.test(pageId) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
189
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams(), { headers: { [PROTECTED_HEADER]: `${pageId}.${password}` }, cache: "no-store" });
|
|
190
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
191
|
+
const data = reply.parsed?.data;
|
|
192
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
193
|
+
const article = data?.article;
|
|
194
|
+
const expires = data?.expires_at;
|
|
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}=${pageId}`) };
|
|
182
197
|
}
|
|
183
198
|
async function asset(file, opts = {}) {
|
|
184
199
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
@@ -192,8 +207,12 @@ function createHyleClient(options) {
|
|
|
192
207
|
const value = opts.headers?.[name];
|
|
193
208
|
if (value) headers.set(name, value);
|
|
194
209
|
}
|
|
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");
|
|
195
212
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
196
|
-
|
|
213
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, `${protectedAccess.pageId}.${protectedAccess.password}`);
|
|
214
|
+
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
215
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
197
216
|
}
|
|
198
217
|
async function theme(opts = {}) {
|
|
199
218
|
const url = `${base}/cp1/read/theme.css`;
|
|
@@ -202,7 +221,7 @@ function createHyleClient(options) {
|
|
|
202
221
|
if (applied) await applied;
|
|
203
222
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
204
223
|
}
|
|
205
|
-
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
224
|
+
return { resolve, mounts, pushPosts, preview, protected: protectedPage, asset, theme };
|
|
206
225
|
}
|
|
207
226
|
|
|
208
227
|
// src/host-sync.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as Resolved, f as MountsResult, H as HylePreview, d as HyleProtected } from './types-b9QbmEDd.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 page's id and password (hyle ADR 0039): hyle then also serves that page's assets. The answer is never cached. */
|
|
191
|
+
readonly protectedAccess?: {
|
|
192
|
+
readonly pageId: 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,7 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
197
202
|
readonly init?: HyleRequestInit;
|
|
198
203
|
}) => Promise<PushPage>;
|
|
199
204
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
+
protected: (pageId: string, password: string) => Promise<HyleProtected>;
|
|
200
206
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
201
207
|
theme: (opts?: {
|
|
202
208
|
readonly timeoutMs?: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as Resolved, f as MountsResult, H as HylePreview, d as HyleProtected } from './types-b9QbmEDd.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 page's id and password (hyle ADR 0039): hyle then also serves that page's assets. The answer is never cached. */
|
|
191
|
+
readonly protectedAccess?: {
|
|
192
|
+
readonly pageId: 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,7 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
197
202
|
readonly init?: HyleRequestInit;
|
|
198
203
|
}) => Promise<PushPage>;
|
|
199
204
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
+
protected: (pageId: string, password: string) => Promise<HyleProtected>;
|
|
200
206
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
201
207
|
theme: (opts?: {
|
|
202
208
|
readonly timeoutMs?: number;
|
package/dist/comments.cjs
CHANGED
|
@@ -369,7 +369,10 @@ 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 PROTECTED_ID = new RegExp(`^${UUID}$`);
|
|
374
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
|
|
375
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
373
376
|
function hostAssetSrc(src) {
|
|
374
377
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
375
378
|
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
|
package/dist/comments.js
CHANGED
|
@@ -125,7 +125,10 @@ 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 PROTECTED_ID = new RegExp(`^${UUID}$`);
|
|
130
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
|
|
131
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
129
132
|
function hostAssetSrc(src) {
|
|
130
133
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
131
134
|
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 { k as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-b9QbmEDd.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 { k as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-b9QbmEDd.js';
|
|
3
3
|
|
|
4
4
|
type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
|
|
5
5
|
interface LinkProps {
|
package/dist/html.cjs
CHANGED
|
@@ -36,7 +36,10 @@ 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 PROTECTED_ID = new RegExp(`^${UUID}$`);
|
|
41
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
|
|
42
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
40
43
|
function hostAssetSrc(src) {
|
|
41
44
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
42
45
|
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
|
package/dist/html.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -59,7 +59,12 @@ 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 PROTECTED_ID = new RegExp(`^${UUID}$`);
|
|
65
|
+
var PROTECTED_PASSWORD = /^[A-Za-z0-9]{16}$/;
|
|
66
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
|
|
67
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
63
68
|
|
|
64
69
|
// src/errors.ts
|
|
65
70
|
var Cp1ClientError = class extends Error {
|
|
@@ -91,8 +96,8 @@ function mapNode(node, mark, depth) {
|
|
|
91
96
|
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
92
97
|
};
|
|
93
98
|
}
|
|
94
|
-
function
|
|
95
|
-
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${
|
|
99
|
+
function withAssetQuery(article, query) {
|
|
100
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
|
|
96
101
|
const { publication, content } = article;
|
|
97
102
|
return {
|
|
98
103
|
...article,
|
|
@@ -221,7 +226,18 @@ function createHyleClient(options) {
|
|
|
221
226
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
222
227
|
const article = data?.article;
|
|
223
228
|
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:
|
|
229
|
+
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
230
|
+
}
|
|
231
|
+
async function protectedPage(pageId, password) {
|
|
232
|
+
if (!PROTECTED_ID.test(pageId) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
233
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams(), { headers: { [PROTECTED_HEADER]: `${pageId}.${password}` }, cache: "no-store" });
|
|
234
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
235
|
+
const data = reply.parsed?.data;
|
|
236
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
237
|
+
const article = data?.article;
|
|
238
|
+
const expires = data?.expires_at;
|
|
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}=${pageId}`) };
|
|
225
241
|
}
|
|
226
242
|
async function asset(file, opts = {}) {
|
|
227
243
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
@@ -235,8 +251,12 @@ function createHyleClient(options) {
|
|
|
235
251
|
const value = opts.headers?.[name];
|
|
236
252
|
if (value) headers.set(name, value);
|
|
237
253
|
}
|
|
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");
|
|
238
256
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
239
|
-
|
|
257
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, `${protectedAccess.pageId}.${protectedAccess.password}`);
|
|
258
|
+
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
259
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
240
260
|
}
|
|
241
261
|
async function theme(opts = {}) {
|
|
242
262
|
const url = `${base}/cp1/read/theme.css`;
|
|
@@ -245,7 +265,7 @@ function createHyleClient(options) {
|
|
|
245
265
|
if (applied) await applied;
|
|
246
266
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
247
267
|
}
|
|
248
|
-
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
268
|
+
return { resolve, mounts, pushPosts, preview, protected: protectedPage, asset, theme };
|
|
249
269
|
}
|
|
250
270
|
|
|
251
271
|
// 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-DK-S2580.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-DK-S2580.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, L as ListItem, M as Mount, e as Mounts, f as MountsResult, N as NavItem, g as NavNode, h as NavTree, R as ReactionCounts, i as ReactionKind, j as Resolved, k as ResolvedArticle, l as ResolvedDisabled, m as ResolvedList, n as ResolvedNotFound, o as ResolvedRedirect, T as ThemeRef, p as TocEntry, V as VoteValue } from './types-b9QbmEDd.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--ighAWaj.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--ighAWaj.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, L as ListItem, M as Mount, e as Mounts, f as MountsResult, N as NavItem, g as NavNode, h as NavTree, R as ReactionCounts, i as ReactionKind, j as Resolved, k as ResolvedArticle, l as ResolvedDisabled, m as ResolvedList, n as ResolvedNotFound, o as ResolvedRedirect, T as ThemeRef, p as TocEntry, V as VoteValue } from './types-b9QbmEDd.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-YHXE3TGS.js";
|
|
27
|
+
import "./chunk-VXARM37R.js";
|
|
28
28
|
export {
|
|
29
29
|
CACHE_TAG_PATTERN,
|
|
30
30
|
Cp1ClientError,
|