@tdacorp/hyle-sdk 0.17.0 → 0.22.2
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 +261 -42
- package/dist/check-routes-bin.js +190 -53
- package/dist/{chunk-6VOHFFA5.js → chunk-7T5EEJHK.js} +2 -2
- package/dist/chunk-DUPT6XLB.js +57 -0
- package/dist/chunk-IW3TUD4G.js +841 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-KU7LWK4E.js} +249 -24
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-SFFBZFEN.js +178 -0
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/chunk-ZIW6FDU2.js +1126 -0
- package/dist/client-BGjmEWhN.d.cts +207 -0
- package/dist/client-D0LTpr3Y.d.ts +207 -0
- package/dist/code-copy.cjs +74 -0
- package/dist/code-copy.d.cts +18 -0
- package/dist/code-copy.d.ts +18 -0
- package/dist/code-copy.js +50 -0
- package/dist/comments.cjs +738 -280
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +419 -331
- package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
- package/dist/docs-enhance.cjs +7 -4
- package/dist/docs-enhance.d.cts +5 -3
- package/dist/docs-enhance.d.ts +5 -3
- package/dist/docs-enhance.js +8 -5
- package/dist/{embed-DNTZ2UXv.d.ts → embed-CbtsbZs3.d.cts} +5 -3
- package/dist/{embed-BmdwA2G9.d.cts → embed-Cf_2ZR5x.d.ts} +5 -3
- package/dist/fragment-alias.cjs +51 -0
- package/dist/fragment-alias.d.cts +7 -0
- package/dist/fragment-alias.d.ts +7 -0
- package/dist/fragment-alias.js +27 -0
- package/dist/html.cjs +886 -0
- package/dist/html.d.cts +20 -0
- package/dist/html.d.ts +20 -0
- package/dist/html.js +45 -0
- package/dist/index.cjs +244 -24
- package/dist/index.d.cts +22 -68
- package/dist/index.d.ts +22 -68
- package/dist/index.js +12 -2
- package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.cts} +9 -0
- package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.ts} +9 -0
- package/dist/mermaid-diagram.cjs +441 -125
- package/dist/mermaid-diagram.d.cts +23 -7
- package/dist/mermaid-diagram.d.ts +23 -7
- package/dist/mermaid-diagram.js +213 -51
- package/dist/mermaid-image.cjs +137 -60
- package/dist/mermaid-image.d.cts +4 -3
- package/dist/mermaid-image.d.ts +4 -3
- package/dist/mermaid-image.js +27 -28
- package/dist/next.cjs +836 -304
- package/dist/next.d.cts +45 -20
- package/dist/next.d.ts +45 -20
- package/dist/next.js +151 -40
- package/dist/print-coordinator.cjs +157 -0
- package/dist/print-coordinator.d.cts +27 -0
- package/dist/print-coordinator.d.ts +27 -0
- package/dist/print-coordinator.js +83 -0
- package/dist/react.cjs +603 -240
- package/dist/react.d.cts +148 -30
- package/dist/react.d.ts +148 -30
- package/dist/react.js +26 -4
- package/dist/reactions.cjs +653 -0
- package/dist/reactions.d.cts +27 -0
- package/dist/reactions.d.ts +27 -0
- package/dist/reactions.js +364 -0
- package/dist/{resolve-euZ4-aC9.d.cts → resolve-BnIv7aB7.d.cts} +2 -2
- package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BysHtZ_i.d.ts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-BpY_AdZh.d.cts +23 -0
- package/dist/sanitize-BpY_AdZh.d.ts +23 -0
- package/dist/styles.css +100 -29
- package/dist/toc-spy.cjs +60 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +36 -0
- package/dist/{types-Czt887Iv.d.cts → types-D09Z072G.d.cts} +57 -2
- package/dist/{types-Czt887Iv.d.ts → types-D09Z072G.d.ts} +57 -2
- package/dist/use-cache.cjs +89 -13
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +8 -8
- package/dist/youtube-facade.cjs +50 -0
- package/dist/youtube-facade.d.cts +17 -0
- package/dist/youtube-facade.d.ts +17 -0
- package/dist/youtube-facade.js +26 -0
- package/package.json +16 -3
- package/dist/chunk-67IOIAVW.js +0 -35
- package/dist/chunk-DMK4XQLU.js +0 -1556
- package/dist/chunk-PJMJMP66.js +0 -63
- package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
- package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
package/dist/use-cache.cjs
CHANGED
|
@@ -27,9 +27,15 @@ var import_cache = require("next/cache");
|
|
|
27
27
|
|
|
28
28
|
// src/asset-path.ts
|
|
29
29
|
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
30
|
-
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
|
|
30
|
+
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
|
|
31
31
|
var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
|
|
32
|
-
var
|
|
32
|
+
var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
|
|
33
|
+
var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
|
|
34
|
+
var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
35
|
+
var PREVIEW_HEADER = "cp-preview";
|
|
36
|
+
var PREVIEW_PARAM = "hyle_preview";
|
|
37
|
+
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
38
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
|
|
33
39
|
|
|
34
40
|
// src/errors.ts
|
|
35
41
|
var Cp1ClientError = class extends Error {
|
|
@@ -47,7 +53,43 @@ var Cp1ClientError = class extends Error {
|
|
|
47
53
|
}
|
|
48
54
|
};
|
|
49
55
|
|
|
56
|
+
// src/preview.ts
|
|
57
|
+
var ASSET_PATH = /^\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?:\.[a-z0-9]+)?(?= |$)/i;
|
|
58
|
+
var ASSET_PROPERTIES = ["src", "dataLight", "dataDark"];
|
|
59
|
+
var MAX_DEPTH = 200;
|
|
60
|
+
function mapNode(node, mark, depth) {
|
|
61
|
+
if (typeof node !== "object" || node === null || depth > MAX_DEPTH) return node;
|
|
62
|
+
const { properties, children } = node;
|
|
63
|
+
const marked = properties && Object.fromEntries(ASSET_PROPERTIES.filter((name) => name in properties).map((name) => [name, mark(properties[name])]));
|
|
64
|
+
return {
|
|
65
|
+
...node,
|
|
66
|
+
...properties ? { properties: { ...properties, ...marked } } : {},
|
|
67
|
+
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function withPreviewAssets(article, token) {
|
|
71
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${PREVIEW_PARAM}=${token}`) : value;
|
|
72
|
+
const { publication, content } = article;
|
|
73
|
+
return {
|
|
74
|
+
...article,
|
|
75
|
+
publication: publication.cover ? { ...publication, cover: { path: String(mark(publication.cover.path)) } } : publication,
|
|
76
|
+
content: content.format === "hast" ? { ...content, tree: mapNode(content.tree, mark, 0) } : content
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
50
80
|
// src/client.ts
|
|
81
|
+
var RENDERER_VERSION = "4";
|
|
82
|
+
function applyCredential(headers, credential, method, url) {
|
|
83
|
+
if (!credential.auth) {
|
|
84
|
+
headers.set("authorization", `Bearer ${credential.token}`);
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const { workspaceId } = credential;
|
|
88
|
+
return credential.auth({ method, url }).then((extra) => {
|
|
89
|
+
for (const [name, value] of Object.entries(extra)) headers.set(name, value);
|
|
90
|
+
headers.set("cp-workspace", workspaceId);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
51
93
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
52
94
|
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
53
95
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -89,14 +131,16 @@ function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
|
89
131
|
}
|
|
90
132
|
function createHyleClient(options) {
|
|
91
133
|
checkBaseUrl(options.baseUrl, options.allowInsecureHttp);
|
|
92
|
-
if (!options.token) throw new TypeError("token is required");
|
|
134
|
+
if (!options.auth && !options.token) throw new TypeError("token is required");
|
|
93
135
|
const base = options.baseUrl.replace(/\/+$/, "");
|
|
94
136
|
const fetchImpl = options.fetch ?? fetch;
|
|
95
137
|
async function get(pathname, query, init) {
|
|
96
138
|
const url = new URL(`${base}${pathname}`);
|
|
97
139
|
url.search = query.toString();
|
|
98
140
|
const headers = new Headers(init?.headers);
|
|
99
|
-
headers.set("
|
|
141
|
+
headers.set("cp-renderer-version", RENDERER_VERSION);
|
|
142
|
+
const applied = applyCredential(headers, options, "GET", url.toString());
|
|
143
|
+
if (applied) await applied;
|
|
100
144
|
const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
101
145
|
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
102
146
|
const res = await fetchImpl(url.toString(), { ...init, method: "GET", headers, redirect: "error", signal });
|
|
@@ -136,16 +180,48 @@ function createHyleClient(options) {
|
|
|
136
180
|
if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
|
|
137
181
|
throw failure(reply);
|
|
138
182
|
}
|
|
183
|
+
async function pushPosts(opts) {
|
|
184
|
+
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(opts.section)) throw new TypeError("section must be a section slug");
|
|
185
|
+
const query = new URLSearchParams();
|
|
186
|
+
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
187
|
+
const reply = await get(`/cp1/read/sections/${opts.section}/posts`, query, opts.init);
|
|
188
|
+
const data = reply.parsed?.data;
|
|
189
|
+
if (data?.cp === 1 && data.kind === "push_posts" && Array.isArray(data.posts) && typeof data.complete === "boolean") return data;
|
|
190
|
+
throw failure(reply);
|
|
191
|
+
}
|
|
192
|
+
async function preview(token) {
|
|
193
|
+
if (typeof token !== "string" || !PREVIEW_TOKEN.test(token)) return { kind: "notfound" };
|
|
194
|
+
const reply = await get("/cp1/read/_preview", new URLSearchParams(), { headers: { [PREVIEW_HEADER]: token }, cache: "no-store" });
|
|
195
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
196
|
+
const data = reply.parsed?.data;
|
|
197
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
198
|
+
const article = data?.article;
|
|
199
|
+
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
200
|
+
return { kind: "preview", expires_at: data.expires_at, article: withPreviewAssets(article, token) };
|
|
201
|
+
}
|
|
139
202
|
async function asset(file, opts = {}) {
|
|
140
203
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
141
|
-
const
|
|
204
|
+
const { previewToken } = opts;
|
|
205
|
+
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
206
|
+
const url = `${base}/cp1/read/assets/${file}`;
|
|
207
|
+
const headers = new Headers();
|
|
208
|
+
const applied = applyCredential(headers, options, "GET", url);
|
|
209
|
+
if (applied) await applied;
|
|
142
210
|
for (const name of ["range", "if-range", "if-none-match"]) {
|
|
143
211
|
const value = opts.headers?.[name];
|
|
144
212
|
if (value) headers.set(name, value);
|
|
145
213
|
}
|
|
146
|
-
|
|
214
|
+
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
215
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...previewToken === void 0 ? {} : { cache: "no-store" } });
|
|
216
|
+
}
|
|
217
|
+
async function theme(opts = {}) {
|
|
218
|
+
const url = `${base}/cp1/read/theme.css`;
|
|
219
|
+
const headers = new Headers();
|
|
220
|
+
const applied = applyCredential(headers, options, "GET", url);
|
|
221
|
+
if (applied) await applied;
|
|
222
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
147
223
|
}
|
|
148
|
-
return { resolve, mounts, asset };
|
|
224
|
+
return { resolve, mounts, pushPosts, preview, asset, theme };
|
|
149
225
|
}
|
|
150
226
|
|
|
151
227
|
// src/tag-validation.ts
|
|
@@ -155,24 +231,24 @@ function isValidCacheTag(tag) {
|
|
|
155
231
|
}
|
|
156
232
|
|
|
157
233
|
// src/next/resolve.ts
|
|
158
|
-
var DEFAULT_REVALIDATE =
|
|
234
|
+
var DEFAULT_REVALIDATE = 86400;
|
|
159
235
|
|
|
160
236
|
// src/next/use-cache.ts
|
|
161
237
|
var MAX_TAGS = 128;
|
|
162
238
|
var DISABLED_REVALIDATE = 30;
|
|
163
|
-
var
|
|
239
|
+
var credentials = /* @__PURE__ */ new Map();
|
|
164
240
|
var keyOf = (baseUrl, workspaceId) => `${baseUrl}\0${workspaceId}`;
|
|
165
241
|
async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, nav, revalidate) {
|
|
166
242
|
"use cache";
|
|
167
|
-
const
|
|
168
|
-
if (!
|
|
169
|
-
const result = await createHyleClient({ baseUrl,
|
|
243
|
+
const credential = credentials.get(keyOf(baseUrl, workspaceId));
|
|
244
|
+
if (!credential) throw new Error("hyle: unknown cache configuration");
|
|
245
|
+
const result = await createHyleClient({ baseUrl, ...credential }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {}, ...nav === "tree" ? { nav: "tree" } : {} });
|
|
170
246
|
if (result.kind !== "disabled") (0, import_cache.cacheTag)(...result.cache.tags.filter(isValidCacheTag).slice(0, MAX_TAGS));
|
|
171
247
|
(0, import_cache.cacheLife)({ stale: 30, revalidate: result.kind === "disabled" ? Math.min(revalidate, DISABLED_REVALIDATE) : revalidate });
|
|
172
248
|
return result;
|
|
173
249
|
}
|
|
174
250
|
function cachedResolver(options) {
|
|
175
|
-
|
|
251
|
+
credentials.set(keyOf(options.baseUrl, options.workspaceId), options.auth ? { auth: options.auth, workspaceId: options.workspaceId } : { token: options.token });
|
|
176
252
|
const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
|
|
177
253
|
return (path, locale, limit, cursor, nav) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", nav ?? "", revalidate);
|
|
178
254
|
}
|
package/dist/use-cache.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { H as
|
|
2
|
-
import './
|
|
1
|
+
import { H as HyleAuth } from './client-BGjmEWhN.cjs';
|
|
2
|
+
import { H as HyleResolver } from './resolve-BnIv7aB7.cjs';
|
|
3
|
+
import './types-D09Z072G.cjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
|
@@ -7,14 +8,20 @@ import './types-Czt887Iv.cjs';
|
|
|
7
8
|
* if the host enables `cacheComponents: true`; with it off, merely importing this file fails the build. That is why it is
|
|
8
9
|
* a separate entry (`@tdacorp/hyle-sdk/next/use-cache`) that a host imports only when it opts in.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
type CachedResolverOptions = {
|
|
11
12
|
readonly baseUrl: string;
|
|
12
13
|
/** The workspace id (HYLE_WORKSPACE_ID). With `baseUrl` it identifies the cache entries, so it must not be secret. */
|
|
13
14
|
readonly workspaceId: string;
|
|
14
|
-
|
|
15
|
+
/** `token` (a target credential) or `auth` (an identity machine token, `HyleAuth`); never part of a cache key. */
|
|
15
16
|
/** Seconds before a cached page is revalidated in the background. Webhooks purge sooner. Default 300. */
|
|
16
17
|
readonly revalidate?: number;
|
|
17
|
-
}
|
|
18
|
+
} & ({
|
|
19
|
+
readonly token: string;
|
|
20
|
+
readonly auth?: never;
|
|
21
|
+
} | {
|
|
22
|
+
readonly auth: HyleAuth;
|
|
23
|
+
readonly token?: never;
|
|
24
|
+
});
|
|
18
25
|
declare function cachedResolver(options: CachedResolverOptions): HyleResolver;
|
|
19
26
|
|
|
20
27
|
export { type CachedResolverOptions, cachedResolver };
|
package/dist/use-cache.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { H as
|
|
2
|
-
import './
|
|
1
|
+
import { H as HyleAuth } from './client-D0LTpr3Y.js';
|
|
2
|
+
import { H as HyleResolver } from './resolve-BysHtZ_i.js';
|
|
3
|
+
import './types-D09Z072G.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
|
@@ -7,14 +8,20 @@ import './types-Czt887Iv.js';
|
|
|
7
8
|
* if the host enables `cacheComponents: true`; with it off, merely importing this file fails the build. That is why it is
|
|
8
9
|
* a separate entry (`@tdacorp/hyle-sdk/next/use-cache`) that a host imports only when it opts in.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
type CachedResolverOptions = {
|
|
11
12
|
readonly baseUrl: string;
|
|
12
13
|
/** The workspace id (HYLE_WORKSPACE_ID). With `baseUrl` it identifies the cache entries, so it must not be secret. */
|
|
13
14
|
readonly workspaceId: string;
|
|
14
|
-
|
|
15
|
+
/** `token` (a target credential) or `auth` (an identity machine token, `HyleAuth`); never part of a cache key. */
|
|
15
16
|
/** Seconds before a cached page is revalidated in the background. Webhooks purge sooner. Default 300. */
|
|
16
17
|
readonly revalidate?: number;
|
|
17
|
-
}
|
|
18
|
+
} & ({
|
|
19
|
+
readonly token: string;
|
|
20
|
+
readonly auth?: never;
|
|
21
|
+
} | {
|
|
22
|
+
readonly auth: HyleAuth;
|
|
23
|
+
readonly token?: never;
|
|
24
|
+
});
|
|
18
25
|
declare function cachedResolver(options: CachedResolverOptions): HyleResolver;
|
|
19
26
|
|
|
20
27
|
export { type CachedResolverOptions, cachedResolver };
|
package/dist/use-cache.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_REVALIDATE
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7T5EEJHK.js";
|
|
4
4
|
import {
|
|
5
5
|
createHyleClient,
|
|
6
6
|
isValidCacheTag
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-KU7LWK4E.js";
|
|
8
|
+
import "./chunk-DUPT6XLB.js";
|
|
9
9
|
|
|
10
10
|
// src/next/use-cache.ts
|
|
11
11
|
import { cacheLife, cacheTag } from "next/cache";
|
|
12
12
|
var MAX_TAGS = 128;
|
|
13
13
|
var DISABLED_REVALIDATE = 30;
|
|
14
|
-
var
|
|
14
|
+
var credentials = /* @__PURE__ */ new Map();
|
|
15
15
|
var keyOf = (baseUrl, workspaceId) => `${baseUrl}\0${workspaceId}`;
|
|
16
16
|
async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, nav, revalidate) {
|
|
17
17
|
"use cache";
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
const result = await createHyleClient({ baseUrl,
|
|
18
|
+
const credential = credentials.get(keyOf(baseUrl, workspaceId));
|
|
19
|
+
if (!credential) throw new Error("hyle: unknown cache configuration");
|
|
20
|
+
const result = await createHyleClient({ baseUrl, ...credential }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {}, ...nav === "tree" ? { nav: "tree" } : {} });
|
|
21
21
|
if (result.kind !== "disabled") cacheTag(...result.cache.tags.filter(isValidCacheTag).slice(0, MAX_TAGS));
|
|
22
22
|
cacheLife({ stale: 30, revalidate: result.kind === "disabled" ? Math.min(revalidate, DISABLED_REVALIDATE) : revalidate });
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
25
|
function cachedResolver(options) {
|
|
26
|
-
|
|
26
|
+
credentials.set(keyOf(options.baseUrl, options.workspaceId), options.auth ? { auth: options.auth, workspaceId: options.workspaceId } : { token: options.token });
|
|
27
27
|
const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
|
|
28
28
|
return (path, locale, limit, cursor, nav) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", nav ?? "", revalidate);
|
|
29
29
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/react/youtube-facade.tsx
|
|
22
|
+
var youtube_facade_exports = {};
|
|
23
|
+
__export(youtube_facade_exports, {
|
|
24
|
+
YouTubeFacade: () => YouTubeFacade
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(youtube_facade_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
function YouTubeFacade({ videoId, playLabel, frameTitle, children }) {
|
|
30
|
+
const [playing, setPlaying] = (0, import_react.useState)(false);
|
|
31
|
+
const id = encodeURIComponent(videoId);
|
|
32
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hyle-youtube", "data-slot-component": "YouTube", children: [
|
|
33
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "hyle-youtube-stage", children: playing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
34
|
+
"iframe",
|
|
35
|
+
{
|
|
36
|
+
ref: (frame) => frame?.focus(),
|
|
37
|
+
src: `https://www.youtube-nocookie.com/embed/${id}?autoplay=1`,
|
|
38
|
+
title: frameTitle,
|
|
39
|
+
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups allow-popups-to-escape-sandbox",
|
|
40
|
+
allow: "autoplay; encrypted-media; fullscreen; picture-in-picture",
|
|
41
|
+
referrerPolicy: "strict-origin-when-cross-origin"
|
|
42
|
+
}
|
|
43
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", "aria-label": playLabel, onClick: () => setPlaying(true), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: `https://i.ytimg.com/vi/${id}/hqdefault.jpg`, alt: "", loading: "lazy", decoding: "async", referrerPolicy: "no-referrer" }) }) }),
|
|
44
|
+
children
|
|
45
|
+
] });
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
YouTubeFacade
|
|
50
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
interface YouTubeFacadeProps {
|
|
4
|
+
/** An 11 character video id the server already validated. */
|
|
5
|
+
videoId: string;
|
|
6
|
+
playLabel: string;
|
|
7
|
+
frameTitle: string;
|
|
8
|
+
/** The plain link to the video; it stays visible, with or without JavaScript. */
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Click to load: until the click the only third-party request is the thumbnail from i.ytimg.com. The click swaps in a
|
|
13
|
+
* youtube-nocookie.com frame. `allow-same-origin` is safe here because the frame is another origin, never the host's.
|
|
14
|
+
*/
|
|
15
|
+
declare function YouTubeFacade({ videoId, playLabel, frameTitle, children }: YouTubeFacadeProps): ReactElement;
|
|
16
|
+
|
|
17
|
+
export { YouTubeFacade, type YouTubeFacadeProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
interface YouTubeFacadeProps {
|
|
4
|
+
/** An 11 character video id the server already validated. */
|
|
5
|
+
videoId: string;
|
|
6
|
+
playLabel: string;
|
|
7
|
+
frameTitle: string;
|
|
8
|
+
/** The plain link to the video; it stays visible, with or without JavaScript. */
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Click to load: until the click the only third-party request is the thumbnail from i.ytimg.com. The click swaps in a
|
|
13
|
+
* youtube-nocookie.com frame. `allow-same-origin` is safe here because the frame is another origin, never the host's.
|
|
14
|
+
*/
|
|
15
|
+
declare function YouTubeFacade({ videoId, playLabel, frameTitle, children }: YouTubeFacadeProps): ReactElement;
|
|
16
|
+
|
|
17
|
+
export { YouTubeFacade, type YouTubeFacadeProps };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/react/youtube-facade.tsx
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function YouTubeFacade({ videoId, playLabel, frameTitle, children }) {
|
|
7
|
+
const [playing, setPlaying] = useState(false);
|
|
8
|
+
const id = encodeURIComponent(videoId);
|
|
9
|
+
return /* @__PURE__ */ jsxs("div", { className: "hyle-youtube", "data-slot-component": "YouTube", children: [
|
|
10
|
+
/* @__PURE__ */ jsx("div", { className: "hyle-youtube-stage", children: playing ? /* @__PURE__ */ jsx(
|
|
11
|
+
"iframe",
|
|
12
|
+
{
|
|
13
|
+
ref: (frame) => frame?.focus(),
|
|
14
|
+
src: `https://www.youtube-nocookie.com/embed/${id}?autoplay=1`,
|
|
15
|
+
title: frameTitle,
|
|
16
|
+
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups allow-popups-to-escape-sandbox",
|
|
17
|
+
allow: "autoplay; encrypted-media; fullscreen; picture-in-picture",
|
|
18
|
+
referrerPolicy: "strict-origin-when-cross-origin"
|
|
19
|
+
}
|
|
20
|
+
) : /* @__PURE__ */ jsx("button", { type: "button", "aria-label": playLabel, onClick: () => setPlaying(true), children: /* @__PURE__ */ jsx("img", { src: `https://i.ytimg.com/vi/${id}/hqdefault.jpg`, alt: "", loading: "lazy", decoding: "async", referrerPolicy: "no-referrer" }) }) }),
|
|
21
|
+
children
|
|
22
|
+
] });
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
YouTubeFacade
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tdacorp/hyle-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.2",
|
|
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": {
|
|
@@ -40,6 +40,16 @@
|
|
|
40
40
|
"default": "./dist/react.cjs"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
"./html": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/html.d.ts",
|
|
46
|
+
"default": "./dist/html.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/html.d.cts",
|
|
50
|
+
"default": "./dist/html.cjs"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
43
53
|
"./next": {
|
|
44
54
|
"import": {
|
|
45
55
|
"types": "./dist/next.d.ts",
|
|
@@ -76,8 +86,9 @@
|
|
|
76
86
|
"LICENSE"
|
|
77
87
|
],
|
|
78
88
|
"dependencies": {
|
|
89
|
+
"hast-util-to-html": "^9.0.5",
|
|
79
90
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
80
|
-
"mermaid": "~11.
|
|
91
|
+
"mermaid": "~11.16.0"
|
|
81
92
|
},
|
|
82
93
|
"peerDependencies": {
|
|
83
94
|
"next": ">=16",
|
|
@@ -96,13 +107,15 @@
|
|
|
96
107
|
"@types/node": "^24.10.2",
|
|
97
108
|
"@types/react": "^19.2.18",
|
|
98
109
|
"@types/react-dom": "^19.2.5",
|
|
110
|
+
"jsdom": "^26.1.0",
|
|
99
111
|
"next": "^16.3.2",
|
|
100
112
|
"react": "19.2.8",
|
|
101
113
|
"react-dom": "19.2.8",
|
|
102
114
|
"tsup": "^8.5.1",
|
|
103
115
|
"typescript": "^5.9.3",
|
|
104
116
|
"vitest": "^4.1.10",
|
|
105
|
-
"@hyle/
|
|
117
|
+
"@hyle/content": "0.10.0",
|
|
118
|
+
"@hyle/renderer": "0.5.1"
|
|
106
119
|
},
|
|
107
120
|
"keywords": [
|
|
108
121
|
"hyle",
|
package/dist/chunk-67IOIAVW.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// src/asset-path.ts
|
|
2
|
-
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
3
|
-
var ASSET_RESERVED_PATH = "/api/hyle/*";
|
|
4
|
-
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
5
|
-
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
|
|
6
|
-
var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
|
|
7
|
-
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
|
|
8
|
-
function hostAssetSrc(src) {
|
|
9
|
-
const file = HYLE_ASSET_URL.exec(src)?.[1];
|
|
10
|
-
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
|
|
11
|
-
}
|
|
12
|
-
function hostAssetHtml(html) {
|
|
13
|
-
return html.replace(new RegExp(`(\\ssrc=")(/assets/${UUID}(?:\\.(?:${EXTENSIONS}))?)(")`, "gi"), (_m, open, url, close) => `${open}${hostAssetSrc(url)}${close}`);
|
|
14
|
-
}
|
|
15
|
-
var ASSET_CONTENT_TYPES = /* @__PURE__ */ new Set([
|
|
16
|
-
"image/png",
|
|
17
|
-
"image/jpeg",
|
|
18
|
-
"image/gif",
|
|
19
|
-
"image/webp",
|
|
20
|
-
"image/svg+xml",
|
|
21
|
-
"application/pdf",
|
|
22
|
-
"video/mp4",
|
|
23
|
-
"video/webm",
|
|
24
|
-
"audio/mpeg",
|
|
25
|
-
"audio/ogg"
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
ASSET_ROUTE_PREFIX,
|
|
30
|
-
ASSET_RESERVED_PATH,
|
|
31
|
-
ASSET_FILE,
|
|
32
|
-
hostAssetSrc,
|
|
33
|
-
hostAssetHtml,
|
|
34
|
-
ASSET_CONTENT_TYPES
|
|
35
|
-
};
|