@tdacorp/hyle-sdk 0.24.0 → 0.24.1
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 +6 -4
- package/dist/check-routes-bin.js +10 -5
- package/dist/{chunk-SY2FMIRZ.js → chunk-O4QWHXVH.js} +1 -1
- package/dist/{chunk-4REU4HJI.js → chunk-RCK4NCYC.js} +10 -5
- package/dist/{client-DrB2vcTi.d.cts → client-CI-3cHtc.d.cts} +11 -4
- package/dist/{client-BErei7cE.d.ts → client-DN38IP63.d.ts} +11 -4
- package/dist/{embed-DavTgSU4.d.ts → embed-BaLQbE_n.d.ts} +1 -1
- package/dist/{embed-B7T--kTT.d.cts → embed-BrrGgkgQ.d.cts} +1 -1
- package/dist/index.cjs +10 -5
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/next.cjs +105 -58
- package/dist/next.d.cts +23 -13
- package/dist/next.d.ts +23 -13
- package/dist/next.js +80 -38
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/{resolve-03IVloXU.d.cts → resolve-Ce_yz8gC.d.cts} +1 -1
- package/dist/{resolve-BseM68oy.d.ts → resolve-DMHbYyTS.d.ts} +1 -1
- package/dist/{types-Dx-fEiZd.d.cts → types-CxE8kLeo.d.cts} +8 -3
- package/dist/{types-Dx-fEiZd.d.ts → types-CxE8kLeo.d.ts} +8 -3
- package/dist/use-cache.cjs +10 -5
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -427,7 +427,7 @@ The token is a bearer secret for that draft, together with your read credential,
|
|
|
427
427
|
|
|
428
428
|
## Protected shares
|
|
429
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.
|
|
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. The proxy rewrite (below) is what serves a share; the unlock route is the one more file:
|
|
431
431
|
|
|
432
432
|
```ts
|
|
433
433
|
// app/hyle-protected/unlock/route.ts
|
|
@@ -436,7 +436,7 @@ import { createProtectedUnlockRoute } from "@tdacorp/hyle-sdk/next";
|
|
|
436
436
|
export const { POST } = createProtectedUnlockRoute();
|
|
437
437
|
```
|
|
438
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
|
|
439
|
+
`hyleRootPage` checks the slugs hyle reports in `GET /cp1/read/mounts` (`protected`) together with the mounts, so the longest entry wins (and a path under a live slug makes no resolve call), but **`hyleRootPage` never draws a share: a path under a live slug is `notFound()` there**, because a share is read with the visitor's cookie and the catch-all may be ISR, where reading a cookie is a 500. The proxy rewrite below is what serves a share, on every host, so a host without it shows its shares as 404. 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
440
|
|
|
441
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
442
|
|
|
@@ -444,7 +444,7 @@ Every answer that involves a protected share is `Cache-Control: no-store`, `X-Ro
|
|
|
444
444
|
|
|
445
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
446
|
|
|
447
|
-
**A
|
|
447
|
+
**A share needs two more files: a proxy and a view route.** 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`, measured on Next 16.5). So 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
448
|
|
|
449
449
|
```ts
|
|
450
450
|
// proxy.ts (Next 16; middleware.ts on older versions). Keep your own matcher, and leave /_next, /api and /hyle-protected out of it.
|
|
@@ -468,7 +468,9 @@ export const metadata = hyleProtectedMetadata;
|
|
|
468
468
|
export default hyleProtectedPage(configs);
|
|
469
469
|
```
|
|
470
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
|
|
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 and matches every path against it locally, so random paths cost no call to hyle. It is stale-while-revalidate: once it has a copy it answers from it at once, and after 30 seconds ONE read refreshes it in the background (a failed refresh keeps the copy), so a slow hyle delays no request; a new share is rewritten within about 30 seconds. Only a cold start (no copy yet) waits, for at most `lookupTimeoutMs` (`hyleProtectedProxy(configs, { lookupTimeoutMs })`, default 1500), after which the request goes on as a normal, non-share request while the read finishes; a mounts read that fails with no copy counts as "not a share" for those 30 seconds. Without the proxy a share path reaches the catch-all, which answers 404.
|
|
472
|
+
|
|
473
|
+
The view route reads the visitor's address from the first `x-forwarded-for` hop, else `x-real-ip`, and sends it to hyle as `X-Forwarded-For` with the gate and open reads (`hyleProtectedPage(configs, { clientIp: (headers) => ... })` reads it from elsewhere; a value that is not an IPv4 or IPv6 literal is dropped). The first hop is the visitor's only when your edge overwrites that header. hyle's site read surface does not use it yet. When hyle answers 429 (too many attempts), the view draws a page headed "Too many attempts, try again later" with the seconds to wait taken from `Retry-After`; an App Router page cannot set a status or header, so it is drawn with status 200. `client.protected(slug, password, docSlug?, { clientIp })` and `client.protectedGate(slug, { clientIp })` return `{ kind: "limited", retryAfterSeconds }` for a 429.
|
|
472
474
|
|
|
473
475
|
Requires a Hyle with migration 0111 and the `GET /cp1/read/_protected` and `GET /cp1/read/_protected/gate` routes (ADR 0040).
|
|
474
476
|
|
package/dist/check-routes-bin.js
CHANGED
|
@@ -76,6 +76,8 @@ function applyCredential(headers, credential, method, url) {
|
|
|
76
76
|
headers.set("cp-workspace", workspaceId);
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
+
var IP_LITERAL = /^[0-9a-fA-F:.]{2,45}$/;
|
|
80
|
+
var visitorHeaders = ({ clientIp }) => clientIp !== void 0 && IP_LITERAL.test(clientIp) ? { "x-forwarded-for": clientIp } : {};
|
|
79
81
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
80
82
|
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
81
83
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -137,7 +139,7 @@ function createHyleClient(options) {
|
|
|
137
139
|
} catch {
|
|
138
140
|
parsed = void 0;
|
|
139
141
|
}
|
|
140
|
-
return { parsed, status: res.status };
|
|
142
|
+
return { parsed, status: res.status, retryAfter: res.headers.get("retry-after") };
|
|
141
143
|
}
|
|
142
144
|
const failure = ({ parsed, status }) => {
|
|
143
145
|
const err = parsed?.error;
|
|
@@ -185,19 +187,22 @@ function createHyleClient(options) {
|
|
|
185
187
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
186
188
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
187
189
|
}
|
|
188
|
-
|
|
190
|
+
const limited = ({ retryAfter }) => ({ kind: "limited", retryAfterSeconds: Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60)) });
|
|
191
|
+
async function protectedGate(slug, opts = {}) {
|
|
189
192
|
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
190
|
-
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
193
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { headers: visitorHeaders(opts), cache: "no-store" });
|
|
194
|
+
if (reply.status === 429) return limited(reply);
|
|
191
195
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
192
196
|
const data = reply.parsed?.data;
|
|
193
197
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
194
198
|
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
195
199
|
throw failure(reply);
|
|
196
200
|
}
|
|
197
|
-
async function protectedShare(slug, password, docSlug) {
|
|
201
|
+
async function protectedShare(slug, password, docSlug, opts = {}) {
|
|
198
202
|
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
199
203
|
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" });
|
|
204
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { ...visitorHeaders(opts), [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
205
|
+
if (reply.status === 429) return limited(reply);
|
|
201
206
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
202
207
|
const data = reply.parsed?.data;
|
|
203
208
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
@@ -65,6 +65,8 @@ function applyCredential(headers, credential, method, url) {
|
|
|
65
65
|
headers.set("cp-workspace", workspaceId);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
+
var IP_LITERAL = /^[0-9a-fA-F:.]{2,45}$/;
|
|
69
|
+
var visitorHeaders = ({ clientIp }) => clientIp !== void 0 && IP_LITERAL.test(clientIp) ? { "x-forwarded-for": clientIp } : {};
|
|
68
70
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
69
71
|
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
70
72
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -137,7 +139,7 @@ function createHyleClient(options) {
|
|
|
137
139
|
} catch {
|
|
138
140
|
parsed = void 0;
|
|
139
141
|
}
|
|
140
|
-
return { parsed, status: res.status };
|
|
142
|
+
return { parsed, status: res.status, retryAfter: res.headers.get("retry-after") };
|
|
141
143
|
}
|
|
142
144
|
const failure = ({ parsed, status }) => {
|
|
143
145
|
const err = parsed?.error;
|
|
@@ -185,19 +187,22 @@ function createHyleClient(options) {
|
|
|
185
187
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
186
188
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
187
189
|
}
|
|
188
|
-
|
|
190
|
+
const limited = ({ retryAfter }) => ({ kind: "limited", retryAfterSeconds: Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60)) });
|
|
191
|
+
async function protectedGate(slug, opts = {}) {
|
|
189
192
|
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
190
|
-
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
193
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { headers: visitorHeaders(opts), cache: "no-store" });
|
|
194
|
+
if (reply.status === 429) return limited(reply);
|
|
191
195
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
192
196
|
const data = reply.parsed?.data;
|
|
193
197
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
194
198
|
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
195
199
|
throw failure(reply);
|
|
196
200
|
}
|
|
197
|
-
async function protectedShare(slug, password, docSlug) {
|
|
201
|
+
async function protectedShare(slug, password, docSlug, opts = {}) {
|
|
198
202
|
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
199
203
|
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" });
|
|
204
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { ...visitorHeaders(opts), [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
205
|
+
if (reply.status === 429) return limited(reply);
|
|
201
206
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
202
207
|
const data = reply.parsed?.data;
|
|
203
208
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as Resolved, i as MountsResult, H as HylePreview, e as HyleProtectedGate, d as HyleProtected } from './types-CxE8kLeo.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;
|
|
@@ -193,6 +193,13 @@ interface AssetOptions {
|
|
|
193
193
|
readonly password: string;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
|
+
interface ProtectedReadOptions {
|
|
197
|
+
/**
|
|
198
|
+
* The visitor's address, sent to hyle as `X-Forwarded-For` so a read made for a visitor is attributable to them. Anything that is
|
|
199
|
+
* not an IPv4 or IPv6 literal is dropped. hyle's site read surface does not read it today (docs/cp1-spec.md section 3.10.3).
|
|
200
|
+
*/
|
|
201
|
+
readonly clientIp?: string | undefined;
|
|
202
|
+
}
|
|
196
203
|
declare function createHyleClient(options: HyleClientOptions): {
|
|
197
204
|
resolve: (opts: ResolveOptions) => Promise<Resolved>;
|
|
198
205
|
mounts: (opts?: MountsOptions) => Promise<MountsResult>;
|
|
@@ -202,8 +209,8 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
202
209
|
readonly init?: HyleRequestInit;
|
|
203
210
|
}) => Promise<PushPage>;
|
|
204
211
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
-
protectedGate: (slug: string) => Promise<HyleProtectedGate>;
|
|
206
|
-
protected: (slug: string, password: string, docSlug?: string) => Promise<HyleProtected>;
|
|
212
|
+
protectedGate: (slug: string, opts?: ProtectedReadOptions) => Promise<HyleProtectedGate>;
|
|
213
|
+
protected: (slug: string, password: string, docSlug?: string, opts?: ProtectedReadOptions) => Promise<HyleProtected>;
|
|
207
214
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
208
215
|
theme: (opts?: {
|
|
209
216
|
readonly timeoutMs?: number;
|
|
@@ -211,4 +218,4 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
211
218
|
};
|
|
212
219
|
type HyleClient = ReturnType<typeof createHyleClient>;
|
|
213
220
|
|
|
214
|
-
export { type AssetOptions as A, type HyleAuth as H, MAX_PUSH_BODY_BYTES as M, type
|
|
221
|
+
export { type AssetOptions as A, type HyleAuth as H, MAX_PUSH_BODY_BYTES as M, type ProtectedReadOptions as P, type ResolveOptions as R, type HyleClient as a, type HyleClientOptions as b, type HyleCredential as c, type HyleRequestInit as d, type MountsOptions as e, type PushEvent as f, type PushEventType as g, type PushPage as h, type PushPost as i, type PushRoute as j, type PushRouteOptions as k, type PushStore as l, type ResyncOptions as m, type ResyncResult as n, createHyleClient as o, createPushRoute as p, resyncPath as r, staleAfterResync as s };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as Resolved, i as MountsResult, H as HylePreview, e as HyleProtectedGate, d as HyleProtected } from './types-CxE8kLeo.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;
|
|
@@ -193,6 +193,13 @@ interface AssetOptions {
|
|
|
193
193
|
readonly password: string;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
|
+
interface ProtectedReadOptions {
|
|
197
|
+
/**
|
|
198
|
+
* The visitor's address, sent to hyle as `X-Forwarded-For` so a read made for a visitor is attributable to them. Anything that is
|
|
199
|
+
* not an IPv4 or IPv6 literal is dropped. hyle's site read surface does not read it today (docs/cp1-spec.md section 3.10.3).
|
|
200
|
+
*/
|
|
201
|
+
readonly clientIp?: string | undefined;
|
|
202
|
+
}
|
|
196
203
|
declare function createHyleClient(options: HyleClientOptions): {
|
|
197
204
|
resolve: (opts: ResolveOptions) => Promise<Resolved>;
|
|
198
205
|
mounts: (opts?: MountsOptions) => Promise<MountsResult>;
|
|
@@ -202,8 +209,8 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
202
209
|
readonly init?: HyleRequestInit;
|
|
203
210
|
}) => Promise<PushPage>;
|
|
204
211
|
preview: (token: string | undefined) => Promise<HylePreview>;
|
|
205
|
-
protectedGate: (slug: string) => Promise<HyleProtectedGate>;
|
|
206
|
-
protected: (slug: string, password: string, docSlug?: string) => Promise<HyleProtected>;
|
|
212
|
+
protectedGate: (slug: string, opts?: ProtectedReadOptions) => Promise<HyleProtectedGate>;
|
|
213
|
+
protected: (slug: string, password: string, docSlug?: string, opts?: ProtectedReadOptions) => Promise<HyleProtected>;
|
|
207
214
|
asset: (file: string, opts?: AssetOptions) => Promise<Response>;
|
|
208
215
|
theme: (opts?: {
|
|
209
216
|
readonly timeoutMs?: number;
|
|
@@ -211,4 +218,4 @@ declare function createHyleClient(options: HyleClientOptions): {
|
|
|
211
218
|
};
|
|
212
219
|
type HyleClient = ReturnType<typeof createHyleClient>;
|
|
213
220
|
|
|
214
|
-
export { type AssetOptions as A, type HyleAuth as H, MAX_PUSH_BODY_BYTES as M, type
|
|
221
|
+
export { type AssetOptions as A, type HyleAuth as H, MAX_PUSH_BODY_BYTES as M, type ProtectedReadOptions as P, type ResolveOptions as R, type HyleClient as a, type HyleClientOptions as b, type HyleCredential as c, type HyleRequestInit as d, type MountsOptions as e, type PushEvent as f, type PushEventType as g, type PushPage as h, type PushPost as i, type PushRoute as j, type PushRouteOptions as k, type PushStore as l, type ResyncOptions as m, type ResyncResult as n, createHyleClient as o, createPushRoute as p, resyncPath as r, staleAfterResync as s };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { n as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-CxE8kLeo.js';
|
|
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 { n as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-CxE8kLeo.cjs';
|
|
3
3
|
|
|
4
4
|
type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
|
|
5
5
|
interface LinkProps {
|
package/dist/index.cjs
CHANGED
|
@@ -121,6 +121,8 @@ function applyCredential(headers, credential, method, url) {
|
|
|
121
121
|
headers.set("cp-workspace", workspaceId);
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
|
+
var IP_LITERAL = /^[0-9a-fA-F:.]{2,45}$/;
|
|
125
|
+
var visitorHeaders = ({ clientIp }) => clientIp !== void 0 && IP_LITERAL.test(clientIp) ? { "x-forwarded-for": clientIp } : {};
|
|
124
126
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
125
127
|
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
126
128
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -182,7 +184,7 @@ function createHyleClient(options) {
|
|
|
182
184
|
} catch {
|
|
183
185
|
parsed = void 0;
|
|
184
186
|
}
|
|
185
|
-
return { parsed, status: res.status };
|
|
187
|
+
return { parsed, status: res.status, retryAfter: res.headers.get("retry-after") };
|
|
186
188
|
}
|
|
187
189
|
const failure = ({ parsed, status }) => {
|
|
188
190
|
const err = parsed?.error;
|
|
@@ -230,19 +232,22 @@ function createHyleClient(options) {
|
|
|
230
232
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
231
233
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
232
234
|
}
|
|
233
|
-
|
|
235
|
+
const limited = ({ retryAfter }) => ({ kind: "limited", retryAfterSeconds: Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60)) });
|
|
236
|
+
async function protectedGate(slug, opts = {}) {
|
|
234
237
|
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
235
|
-
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
238
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { headers: visitorHeaders(opts), cache: "no-store" });
|
|
239
|
+
if (reply.status === 429) return limited(reply);
|
|
236
240
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
237
241
|
const data = reply.parsed?.data;
|
|
238
242
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
239
243
|
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
240
244
|
throw failure(reply);
|
|
241
245
|
}
|
|
242
|
-
async function protectedShare(slug, password, docSlug) {
|
|
246
|
+
async function protectedShare(slug, password, docSlug, opts = {}) {
|
|
243
247
|
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
244
248
|
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" });
|
|
249
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { ...visitorHeaders(opts), [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
250
|
+
if (reply.status === 429) return limited(reply);
|
|
246
251
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
247
252
|
const data = reply.parsed?.data;
|
|
248
253
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
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
|
|
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,
|
|
1
|
+
import { H as HyleAuth, a as HyleClient } from './client-CI-3cHtc.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 ProtectedReadOptions, f as PushEvent, g as PushEventType, h as PushPage, i as PushPost, j as PushRoute, k as PushRouteOptions, l as PushStore, R as ResolveOptions, m as ResyncOptions, n as ResyncResult, o as createHyleClient, p as createPushRoute, r as resyncPath, s as staleAfterResync } from './client-CI-3cHtc.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 HyleProtectedLimited, g as HyleProtectedShare, L as ListItem, M as Mount, h as Mounts, i as MountsResult, N as NavItem, j as NavNode, k as NavTree, R as ReactionCounts, l as ReactionKind, m as Resolved, n as ResolvedArticle, o as ResolvedDisabled, p as ResolvedList, q as ResolvedNotFound, r as ResolvedRedirect, T as ThemeRef, s as TocEntry, V as VoteValue } from './types-CxE8kLeo.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
|
|
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,
|
|
1
|
+
import { H as HyleAuth, a as HyleClient } from './client-DN38IP63.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 ProtectedReadOptions, f as PushEvent, g as PushEventType, h as PushPage, i as PushPost, j as PushRoute, k as PushRouteOptions, l as PushStore, R as ResolveOptions, m as ResyncOptions, n as ResyncResult, o as createHyleClient, p as createPushRoute, r as resyncPath, s as staleAfterResync } from './client-DN38IP63.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 HyleProtectedLimited, g as HyleProtectedShare, L as ListItem, M as Mount, h as Mounts, i as MountsResult, N as NavItem, j as NavNode, k as NavTree, R as ReactionCounts, l as ReactionKind, m as Resolved, n as ResolvedArticle, o as ResolvedDisabled, p as ResolvedList, q as ResolvedNotFound, r as ResolvedRedirect, T as ThemeRef, s as TocEntry, V as VoteValue } from './types-CxE8kLeo.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 {
|