@tdacorp/hyle-sdk 0.23.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 +36 -18
- package/dist/check-routes-bin.js +34 -16
- 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-O4QWHXVH.js} +1 -1
- package/dist/{chunk-YHXE3TGS.js → chunk-RCK4NCYC.js} +33 -16
- package/dist/{chunk-JHZJOJDC.js → chunk-Y3BACEWA.js} +1 -1
- package/dist/{client-DK-S2580.d.cts → client-CI-3cHtc.d.cts} +13 -5
- package/dist/{client--ighAWaj.d.ts → client-DN38IP63.d.ts} +13 -5
- package/dist/comments.cjs +3 -2
- package/dist/comments.js +3 -2
- package/dist/{embed-g7NT1CyB.d.ts → embed-BaLQbE_n.d.ts} +1 -1
- package/dist/{embed-XT0x_Jaa.d.cts → embed-BrrGgkgQ.d.cts} +1 -1
- package/dist/html.cjs +3 -2
- package/dist/html.js +2 -2
- package/dist/index.cjs +34 -16
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.cjs +316 -184
- package/dist/next.d.cts +46 -31
- package/dist/next.d.ts +46 -31
- package/dist/next.js +265 -154
- 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-Ce_yz8gC.d.cts} +1 -1
- package/dist/{resolve-BqC9l5RH.d.ts → resolve-DMHbYyTS.d.ts} +1 -1
- package/dist/{types-b9QbmEDd.d.cts → types-CxE8kLeo.d.cts} +30 -5
- package/dist/{types-b9QbmEDd.d.ts → types-CxE8kLeo.d.ts} +30 -5
- package/dist/use-cache.cjs +34 -16
- 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/dist/react.cjs
CHANGED
|
@@ -74,8 +74,9 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
74
74
|
var PREVIEW_PARAM = "hyle_preview";
|
|
75
75
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
76
76
|
var PROTECTED_PARAM = "hyle_protected";
|
|
77
|
-
var
|
|
78
|
-
var
|
|
77
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
78
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
79
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
79
80
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
80
81
|
function hostAssetSrc(src) {
|
|
81
82
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
package/dist/react.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-
|
|
4
|
-
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-
|
|
3
|
+
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-BrrGgkgQ.cjs';
|
|
4
|
+
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-BrrGgkgQ.cjs';
|
|
5
5
|
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.cjs';
|
|
6
|
-
import {
|
|
6
|
+
import { n as ResolvedArticle, L as ListItem, s as TocEntry, p as ResolvedList, c as EngageListing, T as ThemeRef } from './types-CxE8kLeo.cjs';
|
|
7
7
|
import 'hast';
|
|
8
8
|
|
|
9
9
|
interface HastContentProps {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-
|
|
4
|
-
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-
|
|
3
|
+
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-BaLQbE_n.js';
|
|
4
|
+
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-BaLQbE_n.js';
|
|
5
5
|
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.js';
|
|
6
|
-
import {
|
|
6
|
+
import { n as ResolvedArticle, L as ListItem, s as TocEntry, p as ResolvedList, c as EngageListing, T as ThemeRef } from './types-CxE8kLeo.js';
|
|
7
7
|
import 'hast';
|
|
8
8
|
|
|
9
9
|
interface HastContentProps {
|
package/dist/react.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
isClampedSource,
|
|
21
21
|
isLargeDiagram,
|
|
22
22
|
stripMermaidConfig
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-5TKJH2XC.js";
|
|
24
24
|
import {
|
|
25
25
|
HastLimitError,
|
|
26
26
|
VIEWER_LABELS_EN,
|
|
@@ -28,8 +28,8 @@ import {
|
|
|
28
28
|
sanitizeHast,
|
|
29
29
|
scopeId,
|
|
30
30
|
stringsFor
|
|
31
|
-
} from "./chunk-
|
|
32
|
-
import "./chunk-
|
|
31
|
+
} from "./chunk-Y3BACEWA.js";
|
|
32
|
+
import "./chunk-BDFMNY76.js";
|
|
33
33
|
export {
|
|
34
34
|
ArticlePage,
|
|
35
35
|
Comments,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as Resolved } from './types-CxE8kLeo.cjs';
|
|
2
2
|
|
|
3
3
|
/** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
|
|
4
4
|
type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string, nav?: "tree", format?: "md") => Promise<Resolved>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as Resolved } from './types-CxE8kLeo.js';
|
|
2
2
|
|
|
3
3
|
/** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
|
|
4
4
|
type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string, nav?: "tree", format?: "md") => Promise<Resolved>;
|
|
@@ -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,40 @@ 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
|
+
/** hyle refused the read for now (HTTP 429): try again after `retryAfterSeconds`. */
|
|
299
|
+
interface HyleProtectedLimited {
|
|
300
|
+
readonly kind: "limited";
|
|
301
|
+
readonly retryAfterSeconds: number;
|
|
302
|
+
}
|
|
303
|
+
type HyleProtected = HyleProtectedShare | HyleProtectedLimited | {
|
|
304
|
+
readonly kind: "notfound";
|
|
286
305
|
} | {
|
|
306
|
+
readonly kind: "disabled";
|
|
307
|
+
};
|
|
308
|
+
/** 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. */
|
|
309
|
+
type HyleProtectedGate = {
|
|
310
|
+
readonly kind: "gate";
|
|
311
|
+
} | HyleProtectedLimited | {
|
|
287
312
|
readonly kind: "notfound";
|
|
288
313
|
} | {
|
|
289
314
|
readonly kind: "disabled";
|
|
290
315
|
};
|
|
291
316
|
|
|
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,
|
|
317
|
+
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, HyleProtectedLimited as f, HyleProtectedShare as g, Mounts as h, MountsResult as i, NavNode as j, NavTree as k, ReactionKind as l, Resolved as m, ResolvedArticle as n, ResolvedDisabled as o, ResolvedList as p, ResolvedNotFound as q, ResolvedRedirect as r, TocEntry as s };
|
|
@@ -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,40 @@ 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
|
+
/** hyle refused the read for now (HTTP 429): try again after `retryAfterSeconds`. */
|
|
299
|
+
interface HyleProtectedLimited {
|
|
300
|
+
readonly kind: "limited";
|
|
301
|
+
readonly retryAfterSeconds: number;
|
|
302
|
+
}
|
|
303
|
+
type HyleProtected = HyleProtectedShare | HyleProtectedLimited | {
|
|
304
|
+
readonly kind: "notfound";
|
|
286
305
|
} | {
|
|
306
|
+
readonly kind: "disabled";
|
|
307
|
+
};
|
|
308
|
+
/** 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. */
|
|
309
|
+
type HyleProtectedGate = {
|
|
310
|
+
readonly kind: "gate";
|
|
311
|
+
} | HyleProtectedLimited | {
|
|
287
312
|
readonly kind: "notfound";
|
|
288
313
|
} | {
|
|
289
314
|
readonly kind: "disabled";
|
|
290
315
|
};
|
|
291
316
|
|
|
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,
|
|
317
|
+
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, HyleProtectedLimited as f, HyleProtectedShare as g, Mounts as h, MountsResult as i, NavNode as j, NavTree as k, ReactionKind as l, Resolved as m, ResolvedArticle as n, ResolvedDisabled as o, ResolvedList as p, ResolvedNotFound as q, ResolvedRedirect as r, TocEntry as s };
|
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
|
|
@@ -95,6 +97,8 @@ function applyCredential(headers, credential, method, url) {
|
|
|
95
97
|
headers.set("cp-workspace", workspaceId);
|
|
96
98
|
});
|
|
97
99
|
}
|
|
100
|
+
var IP_LITERAL = /^[0-9a-fA-F:.]{2,45}$/;
|
|
101
|
+
var visitorHeaders = ({ clientIp }) => clientIp !== void 0 && IP_LITERAL.test(clientIp) ? { "x-forwarded-for": clientIp } : {};
|
|
98
102
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
99
103
|
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
100
104
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -121,7 +125,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
121
125
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
122
126
|
function isMounts(data) {
|
|
123
127
|
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");
|
|
128
|
+
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
129
|
}
|
|
126
130
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
127
131
|
let origin;
|
|
@@ -156,7 +160,7 @@ function createHyleClient(options) {
|
|
|
156
160
|
} catch {
|
|
157
161
|
parsed = void 0;
|
|
158
162
|
}
|
|
159
|
-
return { parsed, status: res.status };
|
|
163
|
+
return { parsed, status: res.status, retryAfter: res.headers.get("retry-after") };
|
|
160
164
|
}
|
|
161
165
|
const failure = ({ parsed, status }) => {
|
|
162
166
|
const err = parsed?.error;
|
|
@@ -204,22 +208,38 @@ function createHyleClient(options) {
|
|
|
204
208
|
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
209
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
206
210
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
211
|
+
const limited = ({ retryAfter }) => ({ kind: "limited", retryAfterSeconds: Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60)) });
|
|
212
|
+
async function protectedGate(slug, opts = {}) {
|
|
213
|
+
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
214
|
+
const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { headers: visitorHeaders(opts), cache: "no-store" });
|
|
215
|
+
if (reply.status === 429) return limited(reply);
|
|
216
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
217
|
+
const data = reply.parsed?.data;
|
|
218
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
219
|
+
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
220
|
+
throw failure(reply);
|
|
221
|
+
}
|
|
222
|
+
async function protectedShare(slug, password, docSlug, opts = {}) {
|
|
223
|
+
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
224
|
+
const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
|
|
225
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { ...visitorHeaders(opts), [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
226
|
+
if (reply.status === 429) return limited(reply);
|
|
210
227
|
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
211
228
|
const data = reply.parsed?.data;
|
|
212
229
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
213
230
|
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}=${
|
|
231
|
+
const { name, expires_at: expires, documents, doc_slug: current } = data ?? {};
|
|
232
|
+
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);
|
|
233
|
+
return { cp: 1, kind: "protected", name, expires_at: expires, documents, doc_slug: current, article: withAssetQuery(article, `${PROTECTED_PARAM}=${slug}`) };
|
|
217
234
|
}
|
|
218
235
|
async function asset(file, opts = {}) {
|
|
219
236
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
220
237
|
const { previewToken } = opts;
|
|
221
238
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
222
|
-
const
|
|
239
|
+
const { protectedAccess } = opts;
|
|
240
|
+
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");
|
|
241
|
+
const query = protectedAccess === void 0 ? "" : `?protected=${encodeURIComponent(protectedAccess.slug)}`;
|
|
242
|
+
const url = `${base}/cp1/read/assets/${file}${query}`;
|
|
223
243
|
const headers = new Headers();
|
|
224
244
|
const applied = applyCredential(headers, options, "GET", url);
|
|
225
245
|
if (applied) await applied;
|
|
@@ -227,10 +247,8 @@ function createHyleClient(options) {
|
|
|
227
247
|
const value = opts.headers?.[name];
|
|
228
248
|
if (value) headers.set(name, value);
|
|
229
249
|
}
|
|
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
250
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
233
|
-
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER,
|
|
251
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
234
252
|
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
235
253
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
236
254
|
}
|
|
@@ -241,7 +259,7 @@ function createHyleClient(options) {
|
|
|
241
259
|
if (applied) await applied;
|
|
242
260
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
243
261
|
}
|
|
244
|
-
return { resolve, mounts, pushPosts, preview, protected:
|
|
262
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
245
263
|
}
|
|
246
264
|
|
|
247
265
|
// 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-CI-3cHtc.cjs';
|
|
2
|
+
import { H as HyleResolver } from './resolve-Ce_yz8gC.cjs';
|
|
3
|
+
import './types-CxE8kLeo.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-DN38IP63.js';
|
|
2
|
+
import { H as HyleResolver } from './resolve-DMHbYyTS.js';
|
|
3
|
+
import './types-CxE8kLeo.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-O4QWHXVH.js";
|
|
4
4
|
import {
|
|
5
5
|
createHyleClient,
|
|
6
6
|
isValidCacheTag
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-RCK4NCYC.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.1",
|
|
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": {
|