@tdacorp/hyle-sdk 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -19
- package/dist/check-routes-bin.js +28 -15
- package/dist/{chunk-YHXE3TGS.js → chunk-4REU4HJI.js} +27 -15
- package/dist/{chunk-UFMKLCXS.js → chunk-5TKJH2XC.js} +2 -2
- package/dist/{chunk-VXARM37R.js → chunk-BDFMNY76.js} +11 -5
- package/dist/{chunk-VUML2UPD.js → chunk-SY2FMIRZ.js} +1 -1
- package/dist/{chunk-JHZJOJDC.js → chunk-Y3BACEWA.js} +1 -1
- package/dist/{client--ighAWaj.d.ts → client-BErei7cE.d.ts} +5 -4
- package/dist/{client-DK-S2580.d.cts → client-DrB2vcTi.d.cts} +5 -4
- package/dist/comments.cjs +3 -2
- package/dist/comments.js +3 -2
- package/dist/{embed-XT0x_Jaa.d.cts → embed-B7T--kTT.d.cts} +1 -1
- package/dist/{embed-g7NT1CyB.d.ts → embed-DavTgSU4.d.ts} +1 -1
- package/dist/html.cjs +3 -2
- package/dist/html.js +2 -2
- package/dist/index.cjs +28 -15
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.cjs +233 -148
- package/dist/next.d.cts +36 -31
- package/dist/next.d.ts +36 -31
- package/dist/next.js +204 -135
- package/dist/react.cjs +3 -2
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/{resolve-CiZCPysX.d.cts → resolve-03IVloXU.d.cts} +1 -1
- package/dist/{resolve-BqC9l5RH.d.ts → resolve-BseM68oy.d.ts} +1 -1
- package/dist/{types-b9QbmEDd.d.cts → types-Dx-fEiZd.d.cts} +25 -5
- package/dist/{types-b9QbmEDd.d.ts → types-Dx-fEiZd.d.ts} +25 -5
- package/dist/use-cache.cjs +28 -15
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +3 -3
- package/package.json +1 -1
|
@@ -177,6 +177,8 @@ interface Mounts {
|
|
|
177
177
|
readonly supported_locales: readonly string[];
|
|
178
178
|
readonly mounts: readonly Mount[];
|
|
179
179
|
readonly reserved: readonly string[];
|
|
180
|
+
/** The slugs of live protected shares on this workspace (hyle ADR 0040); absent from an older server. */
|
|
181
|
+
readonly protected?: readonly string[];
|
|
180
182
|
/** Absent without a theme and from an older server. */
|
|
181
183
|
readonly theme?: ThemeRef;
|
|
182
184
|
readonly cache: CacheInfo;
|
|
@@ -276,17 +278,35 @@ type HylePreview =
|
|
|
276
278
|
} | {
|
|
277
279
|
readonly kind: "disabled";
|
|
278
280
|
};
|
|
279
|
-
/** The `data` of GET /cp1/read/_protected (hyle ADR
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
{
|
|
281
|
+
/** The `data` of GET /cp1/read/_protected (hyle ADR 0040): a protected share's document. `documents` lists the share's pages in order. */
|
|
282
|
+
interface HyleProtectedShare {
|
|
283
|
+
readonly cp: 1;
|
|
283
284
|
readonly kind: "protected";
|
|
285
|
+
readonly name: string;
|
|
286
|
+
/** When the share stops working, or null for none. */
|
|
284
287
|
readonly expires_at: string | null;
|
|
288
|
+
readonly documents: readonly {
|
|
289
|
+
readonly doc_slug: string;
|
|
290
|
+
readonly title: string;
|
|
291
|
+
readonly position: number;
|
|
292
|
+
}[];
|
|
293
|
+
/** The document this answer draws. */
|
|
294
|
+
readonly doc_slug: string;
|
|
295
|
+
/** The article's asset addresses carry the share slug. */
|
|
285
296
|
readonly article: ResolvedArticle;
|
|
297
|
+
}
|
|
298
|
+
type HyleProtected = HyleProtectedShare | {
|
|
299
|
+
readonly kind: "notfound";
|
|
300
|
+
} | {
|
|
301
|
+
readonly kind: "disabled";
|
|
302
|
+
};
|
|
303
|
+
/** The `data` of GET /cp1/read/_protected/gate: a live share exists at the slug (no name, it is behind the password), or why none does. */
|
|
304
|
+
type HyleProtectedGate = {
|
|
305
|
+
readonly kind: "gate";
|
|
286
306
|
} | {
|
|
287
307
|
readonly kind: "notfound";
|
|
288
308
|
} | {
|
|
289
309
|
readonly kind: "disabled";
|
|
290
310
|
};
|
|
291
311
|
|
|
292
|
-
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, HyleProtected as d,
|
|
312
|
+
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, HyleProtected as d, HyleProtectedGate as e, HyleProtectedShare as f, Mounts as g, MountsResult as h, NavNode as i, NavTree as j, ReactionKind as k, Resolved as l, ResolvedArticle as m, ResolvedDisabled as n, ResolvedList as o, ResolvedNotFound as p, ResolvedRedirect as q, TocEntry as r };
|
|
@@ -177,6 +177,8 @@ interface Mounts {
|
|
|
177
177
|
readonly supported_locales: readonly string[];
|
|
178
178
|
readonly mounts: readonly Mount[];
|
|
179
179
|
readonly reserved: readonly string[];
|
|
180
|
+
/** The slugs of live protected shares on this workspace (hyle ADR 0040); absent from an older server. */
|
|
181
|
+
readonly protected?: readonly string[];
|
|
180
182
|
/** Absent without a theme and from an older server. */
|
|
181
183
|
readonly theme?: ThemeRef;
|
|
182
184
|
readonly cache: CacheInfo;
|
|
@@ -276,17 +278,35 @@ type HylePreview =
|
|
|
276
278
|
} | {
|
|
277
279
|
readonly kind: "disabled";
|
|
278
280
|
};
|
|
279
|
-
/** The `data` of GET /cp1/read/_protected (hyle ADR
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
{
|
|
281
|
+
/** The `data` of GET /cp1/read/_protected (hyle ADR 0040): a protected share's document. `documents` lists the share's pages in order. */
|
|
282
|
+
interface HyleProtectedShare {
|
|
283
|
+
readonly cp: 1;
|
|
283
284
|
readonly kind: "protected";
|
|
285
|
+
readonly name: string;
|
|
286
|
+
/** When the share stops working, or null for none. */
|
|
284
287
|
readonly expires_at: string | null;
|
|
288
|
+
readonly documents: readonly {
|
|
289
|
+
readonly doc_slug: string;
|
|
290
|
+
readonly title: string;
|
|
291
|
+
readonly position: number;
|
|
292
|
+
}[];
|
|
293
|
+
/** The document this answer draws. */
|
|
294
|
+
readonly doc_slug: string;
|
|
295
|
+
/** The article's asset addresses carry the share slug. */
|
|
285
296
|
readonly article: ResolvedArticle;
|
|
297
|
+
}
|
|
298
|
+
type HyleProtected = HyleProtectedShare | {
|
|
299
|
+
readonly kind: "notfound";
|
|
300
|
+
} | {
|
|
301
|
+
readonly kind: "disabled";
|
|
302
|
+
};
|
|
303
|
+
/** The `data` of GET /cp1/read/_protected/gate: a live share exists at the slug (no name, it is behind the password), or why none does. */
|
|
304
|
+
type HyleProtectedGate = {
|
|
305
|
+
readonly kind: "gate";
|
|
286
306
|
} | {
|
|
287
307
|
readonly kind: "notfound";
|
|
288
308
|
} | {
|
|
289
309
|
readonly kind: "disabled";
|
|
290
310
|
};
|
|
291
311
|
|
|
292
|
-
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, HyleProtected as d,
|
|
312
|
+
export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, HyleProtected as d, HyleProtectedGate as e, HyleProtectedShare as f, Mounts as g, MountsResult as h, NavNode as i, NavTree as j, ReactionKind as k, Resolved as l, ResolvedArticle as m, ResolvedDisabled as n, ResolvedList as o, ResolvedNotFound as p, ResolvedRedirect as q, TocEntry as r };
|
package/dist/use-cache.cjs
CHANGED
|
@@ -37,9 +37,11 @@ var PREVIEW_PARAM = "hyle_preview";
|
|
|
37
37
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
38
38
|
var PROTECTED_PARAM = "hyle_protected";
|
|
39
39
|
var PROTECTED_HEADER = "cp-protected";
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
40
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
41
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
42
|
+
var PROTECTED_DOC_SLUG = /^[a-z0-9-]+$/;
|
|
43
|
+
var PROTECTED_PASSWORD = /^[\x21\x23-\x24\x26-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]{12,128}$/;
|
|
44
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
43
45
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
44
46
|
|
|
45
47
|
// src/errors.ts
|
|
@@ -121,7 +123,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
121
123
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
122
124
|
function isMounts(data) {
|
|
123
125
|
const mounts = data.mounts;
|
|
124
|
-
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");
|
|
126
|
+
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));
|
|
125
127
|
}
|
|
126
128
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
127
129
|
let origin;
|
|
@@ -204,22 +206,35 @@ function createHyleClient(options) {
|
|
|
204
206
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
205
207
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
206
208
|
}
|
|
207
|
-
async function
|
|
208
|
-
if (!
|
|
209
|
-
const reply = await get("/cp1/read/_protected", new URLSearchParams(
|
|
209
|
+
async function protectedGate(slug) {
|
|
210
|
+
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
211
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
212
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
213
|
+
const data = reply.parsed?.data;
|
|
214
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
215
|
+
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
216
|
+
throw failure(reply);
|
|
217
|
+
}
|
|
218
|
+
async function protectedShare(slug, password, docSlug) {
|
|
219
|
+
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
220
|
+
const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
|
|
221
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
210
222
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
211
223
|
const data = reply.parsed?.data;
|
|
212
224
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
213
225
|
const article = data?.article;
|
|
214
|
-
const expires = data
|
|
215
|
-
if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
216
|
-
return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${
|
|
226
|
+
const { name, expires_at: expires, documents, doc_slug: current } = data ?? {};
|
|
227
|
+
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);
|
|
228
|
+
return { cp: 1, kind: "protected", name, expires_at: expires, documents, doc_slug: current, article: withAssetQuery(article, `${PROTECTED_PARAM}=${slug}`) };
|
|
217
229
|
}
|
|
218
230
|
async function asset(file, opts = {}) {
|
|
219
231
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
220
232
|
const { previewToken } = opts;
|
|
221
233
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
222
|
-
const
|
|
234
|
+
const { protectedAccess } = opts;
|
|
235
|
+
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");
|
|
236
|
+
const query = protectedAccess === void 0 ? "" : `?protected=${encodeURIComponent(protectedAccess.slug)}`;
|
|
237
|
+
const url = `${base}/cp1/read/assets/${file}${query}`;
|
|
223
238
|
const headers = new Headers();
|
|
224
239
|
const applied = applyCredential(headers, options, "GET", url);
|
|
225
240
|
if (applied) await applied;
|
|
@@ -227,10 +242,8 @@ function createHyleClient(options) {
|
|
|
227
242
|
const value = opts.headers?.[name];
|
|
228
243
|
if (value) headers.set(name, value);
|
|
229
244
|
}
|
|
230
|
-
const { protectedAccess } = opts;
|
|
231
|
-
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");
|
|
232
245
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
233
|
-
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER,
|
|
246
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
234
247
|
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
235
248
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
236
249
|
}
|
|
@@ -241,7 +254,7 @@ function createHyleClient(options) {
|
|
|
241
254
|
if (applied) await applied;
|
|
242
255
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
243
256
|
}
|
|
244
|
-
return { resolve, mounts, pushPosts, preview, protected:
|
|
257
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
245
258
|
}
|
|
246
259
|
|
|
247
260
|
// src/tag-validation.ts
|
package/dist/use-cache.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HyleAuth } from './client-
|
|
2
|
-
import { H as HyleResolver } from './resolve-
|
|
3
|
-
import './types-
|
|
1
|
+
import { H as HyleAuth } from './client-DrB2vcTi.cjs';
|
|
2
|
+
import { H as HyleResolver } from './resolve-03IVloXU.cjs';
|
|
3
|
+
import './types-Dx-fEiZd.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
package/dist/use-cache.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HyleAuth } from './client
|
|
2
|
-
import { H as HyleResolver } from './resolve-
|
|
3
|
-
import './types-
|
|
1
|
+
import { H as HyleAuth } from './client-BErei7cE.js';
|
|
2
|
+
import { H as HyleResolver } from './resolve-BseM68oy.js';
|
|
3
|
+
import './types-Dx-fEiZd.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
package/dist/use-cache.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_REVALIDATE
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SY2FMIRZ.js";
|
|
4
4
|
import {
|
|
5
5
|
createHyleClient,
|
|
6
6
|
isValidCacheTag
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-4REU4HJI.js";
|
|
8
|
+
import "./chunk-BDFMNY76.js";
|
|
9
9
|
|
|
10
10
|
// src/next/use-cache.ts
|
|
11
11
|
import { cacheLife, cacheTag } from "next/cache";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tdacorp/hyle-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "hyle SDK: a typed client for hyle's resolve endpoint, a hast renderer for React, and a Next.js catch-all page with tag-based revalidation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|