@blogmcp/sdk 0.12.0 → 0.13.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/dist/core/client.d.ts +9 -0
- package/dist/core/client.js +54 -50
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +113 -103
- package/dist/core/queries.d.ts +1 -0
- package/dist/core/queries.js +76 -71
- package/dist/core/review/types.d.ts +7 -0
- package/dist/core/style-layers.d.ts +88 -0
- package/dist/core/style-layers.js +69 -0
- package/package.json +3 -3
- package/src/core/client.ts +12 -0
- package/src/core/index.ts +14 -0
- package/src/core/queries.ts +8 -0
- package/src/core/review/types.ts +8 -0
- package/src/core/style-layers.ts +169 -0
package/dist/core/client.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { KbClientConfig } from './client-types.js';
|
|
9
9
|
import type { Article, ArticlePreview, ArticleWithTranslation, ArticleVersionContent, Tag, LocalizedTag, Language, SearchResult, KBContextChunk, Translation, Comment, CommentsConnection, CommentResult, AuthResult, RegisterResult, UpdateProfileResult, ReportSettings, UpdateReportSettingsInput } from './types.js';
|
|
10
10
|
import type { NavNode } from './navigation.js';
|
|
11
|
+
import { type StyleLayer } from './style-layers.js';
|
|
11
12
|
import { type KbConsultationsApi, type KbConsultationSessionApi } from './consultations.js';
|
|
12
13
|
export interface KbClient {
|
|
13
14
|
articles: {
|
|
@@ -131,6 +132,14 @@ export interface KbClient {
|
|
|
131
132
|
kbNavigation: NavNode[];
|
|
132
133
|
}>;
|
|
133
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* Style layers: the PUBLISHED layers of the site, in the order they apply (see `./style-layers`).
|
|
137
|
+
* Unlike the other groups this returns the parsed list, not the GraphQL field: an entry that is
|
|
138
|
+
* not a layer is dropped, so a caller can render what comes back.
|
|
139
|
+
*/
|
|
140
|
+
styleLayers: {
|
|
141
|
+
list(): Promise<StyleLayer[]>;
|
|
142
|
+
};
|
|
134
143
|
/**
|
|
135
144
|
* Editorial access to translation ROWS — INTERNAL tokens only (a server client holding a
|
|
136
145
|
* kb_* internal key). The server refuses every other caller: a translation row carries the
|
package/dist/core/client.js
CHANGED
|
@@ -1,97 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { parseStyleLayers as S } from "./style-layers.js";
|
|
2
|
+
import { UPDATE_MY_PROFILE as _, ARTICLE_VERSION as I, ACCESSIBLE_ARTICLES_WITH_LOCKED_LOCALIZED as l, ACCESSIBLE_ARTICLES_LOCALIZED as L, UPDATE_MY_REPORT_SETTINGS as C, MY_REPORT_SETTINGS as R, CHANGE_PASSWORD as d, RESEND_VERIFICATION as c, RESET_PASSWORD as u, FORGOT_PASSWORD as O, VERIFY_EMAIL as p, REGISTER as N, LOGIN as h, DELETE_COMMENT as m, UPDATE_COMMENT as y, CREATE_COMMENT as g, GET_COMMENT as G, ARTICLE_COMMENTS as P, GET_TRANSLATION as D, ARTICLE_TRANSLATIONS as B, KB_STYLE_LAYERS as M, KB_NAVIGATION as f, KB_LANGUAGES as w, LOCALIZED_TAGS as W, ACCESSIBLE_TAGS as v, GET_KB_CONTEXT as K, SEARCH_KNOWLEDGE_BASE as k, ARTICLE_ALIAS_TARGET as V, ARTICLE_PREVIEW_BY_ID as Y, ARTICLE_PREVIEW as b, ARTICLE_WITH_TRANSLATION_BY_ID as x, ARTICLE_WITH_TRANSLATION as H, ACCESSIBLE_ARTICLES_WITH_LOCKED as U, ACCESSIBLE_ARTICLES as F } from "./queries.js";
|
|
3
|
+
import { createMemoryTokenStorage as Q } from "./auth.js";
|
|
4
|
+
import { KbGraphQLError as Z } from "./errors.js";
|
|
5
|
+
import { createConsultationSessionApi as j, createConsultationsApi as z } from "./consultations.js";
|
|
6
|
+
function q() {
|
|
7
|
+
return async (n, a) => (await fetch(n, {
|
|
8
|
+
method: a.method,
|
|
9
|
+
headers: a.headers,
|
|
10
|
+
body: a.body
|
|
10
11
|
})).json();
|
|
11
12
|
}
|
|
12
|
-
async function
|
|
13
|
+
async function J(n, a, o) {
|
|
13
14
|
const T = {
|
|
14
15
|
...n.headers ?? {},
|
|
15
16
|
"Content-Type": "application/json"
|
|
16
|
-
},
|
|
17
|
-
|
|
17
|
+
}, s = n.tokenStorage.getToken();
|
|
18
|
+
s && (T.Authorization = `Bearer ${s}`);
|
|
18
19
|
const t = await n.fetcher(n.endpoint, {
|
|
19
20
|
method: "POST",
|
|
20
21
|
headers: T,
|
|
21
|
-
body: JSON.stringify({ query:
|
|
22
|
+
body: JSON.stringify({ query: a, variables: o })
|
|
22
23
|
});
|
|
23
24
|
if (t.errors?.length)
|
|
24
|
-
throw new
|
|
25
|
+
throw new Z(t.errors);
|
|
25
26
|
return t.data;
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
28
|
+
function ne(n) {
|
|
29
|
+
const a = n.fetcher || q(), o = n.tokenStorage || Q(), s = { endpoint: n.isServer && n.serverEndpoint ? n.serverEndpoint : n.endpoint, fetcher: a, tokenStorage: o, headers: n.headers };
|
|
29
30
|
function t(e, r) {
|
|
30
|
-
return
|
|
31
|
+
return J(s, e, r);
|
|
31
32
|
}
|
|
32
33
|
return {
|
|
33
34
|
articles: {
|
|
34
35
|
list: (e) => {
|
|
35
|
-
const { includeLocked: r, languageCode:
|
|
36
|
-
return
|
|
37
|
-
r ?
|
|
38
|
-
{ ...i, languageCode:
|
|
39
|
-
) : t(r ?
|
|
36
|
+
const { includeLocked: r, languageCode: E, includeUntranslated: A, ...i } = e ?? {};
|
|
37
|
+
return E ? t(
|
|
38
|
+
r ? l : L,
|
|
39
|
+
{ ...i, languageCode: E, includeUntranslated: A === !0 }
|
|
40
|
+
) : t(r ? U : F, i);
|
|
40
41
|
},
|
|
41
|
-
getWithTranslation: (e, r) => t(
|
|
42
|
-
getWithTranslationById: (e, r) => t(
|
|
43
|
-
getPreview: (e, r) => t(
|
|
44
|
-
getPreviewById: (e, r) => t(
|
|
45
|
-
resolveAlias: (e) => t(
|
|
46
|
-
getVersion: (e, r) => t(
|
|
42
|
+
getWithTranslation: (e, r) => t(H, { filename: e, languageCode: r }),
|
|
43
|
+
getWithTranslationById: (e, r) => t(x, { id: e, languageCode: r }),
|
|
44
|
+
getPreview: (e, r) => t(b, { filename: e, languageCode: r }),
|
|
45
|
+
getPreviewById: (e, r) => t(Y, { id: e, languageCode: r }),
|
|
46
|
+
resolveAlias: (e) => t(V, { filename: e }),
|
|
47
|
+
getVersion: (e, r) => t(I, { versionId: e, previewKey: r?.previewKey ?? null })
|
|
47
48
|
},
|
|
48
49
|
search: {
|
|
49
|
-
query: (e) => t(
|
|
50
|
-
getContext: (e, r) => t(
|
|
50
|
+
query: (e) => t(k, e),
|
|
51
|
+
getContext: (e, r) => t(K, { query: e, maxChunks: r })
|
|
51
52
|
},
|
|
52
53
|
tags: {
|
|
53
|
-
list: () => t(
|
|
54
|
-
listLocalized: (e) => t(
|
|
54
|
+
list: () => t(v),
|
|
55
|
+
listLocalized: (e) => t(W, { languageCode: e })
|
|
55
56
|
},
|
|
56
57
|
languages: {
|
|
57
|
-
list: () => t(
|
|
58
|
+
list: () => t(w)
|
|
58
59
|
},
|
|
59
60
|
navigation: {
|
|
60
|
-
get: (e) => t(
|
|
61
|
+
get: (e) => t(f, e ?? {})
|
|
62
|
+
},
|
|
63
|
+
styleLayers: {
|
|
64
|
+
list: async () => S((await t(M))?.kbStyleLayers)
|
|
61
65
|
},
|
|
62
66
|
translations: {
|
|
63
|
-
list: (e) => t(
|
|
67
|
+
list: (e) => t(B, { articleId: e }),
|
|
64
68
|
get: (e, r) => t(D, { sourceFilename: e, languageCode: r })
|
|
65
69
|
},
|
|
66
70
|
comments: {
|
|
67
71
|
list: (e, r) => t(P, { articleId: e, languageCode: r }),
|
|
68
72
|
get: (e, r) => t(G, { commentId: e, languageCode: r }),
|
|
69
|
-
create: (e) => t(
|
|
70
|
-
update: (e, r) => t(
|
|
71
|
-
delete: (e) => t(
|
|
73
|
+
create: (e) => t(g, e),
|
|
74
|
+
update: (e, r) => t(y, { commentId: e, content: r }),
|
|
75
|
+
delete: (e) => t(m, { commentId: e })
|
|
72
76
|
},
|
|
73
77
|
auth: {
|
|
74
|
-
login: (e, r) => t(
|
|
75
|
-
register: (e, r,
|
|
76
|
-
verifyEmail: (e) => t(
|
|
77
|
-
forgotPassword: (e) => t(
|
|
78
|
-
resetPassword: (e, r) => t(
|
|
79
|
-
resendVerification: (e) => t(
|
|
78
|
+
login: (e, r) => t(h, { email: e, password: r }),
|
|
79
|
+
register: (e, r, E) => t(N, { email: e, password: r, name: E }),
|
|
80
|
+
verifyEmail: (e) => t(p, { token: e }),
|
|
81
|
+
forgotPassword: (e) => t(O, { email: e }),
|
|
82
|
+
resetPassword: (e, r) => t(u, { token: e, password: r }),
|
|
83
|
+
resendVerification: (e) => t(c, { email: e }),
|
|
80
84
|
changePassword: (e, r) => t(d, { currentPassword: e, newPassword: r }),
|
|
81
|
-
updateProfile: (e) => t(
|
|
85
|
+
updateProfile: (e) => t(_, {
|
|
82
86
|
name: e.name ?? null,
|
|
83
87
|
email: e.email ?? null
|
|
84
88
|
})
|
|
85
89
|
},
|
|
86
90
|
reportSettings: {
|
|
87
|
-
get: () => t(
|
|
88
|
-
update: (e) => t(
|
|
91
|
+
get: () => t(R),
|
|
92
|
+
update: (e) => t(C, e)
|
|
89
93
|
},
|
|
90
|
-
consultations:
|
|
91
|
-
consultationSession:
|
|
94
|
+
consultations: z(t),
|
|
95
|
+
consultationSession: j(t),
|
|
92
96
|
executeGraphQL: t
|
|
93
97
|
};
|
|
94
98
|
}
|
|
95
99
|
export {
|
|
96
|
-
|
|
100
|
+
ne as createKbClient
|
|
97
101
|
};
|
package/dist/core/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type { KbClient } from './client.js';
|
|
|
9
9
|
export { createKbClient } from './client.js';
|
|
10
10
|
export type { NavNode, NavNodeType, NavBadge, NavGroupLink, NavNextPrev, FlatNavNode } from './navigation.js';
|
|
11
11
|
export { navWalk, findNavNode, navBreadcrumbs, navSiblings, navSubtree, navNextPrev, isNavigable, flattenNav, } from './navigation.js';
|
|
12
|
+
export type { StyleLayer, StyleLayerMatch } from './style-layers.js';
|
|
13
|
+
export { LAYER_SCOPE_TOKEN, parseStyleLayers, sortStyleLayers, layerMatches, matchLayers, mergePinnedLayers, layerScope, applyLayerScope, layerStyleText, } from './style-layers.js';
|
|
12
14
|
export type { AuthManager } from './auth.js';
|
|
13
15
|
export { createAuthManager, createMemoryTokenStorage, createLocalStorageTokenStorage, decodeJwtUser, hasAccessLevel, } from './auth.js';
|
|
14
16
|
export { createDelegatedTokenMinter, DelegatedTokenError, } from './delegated-identity.js';
|
package/dist/core/index.js
CHANGED
|
@@ -1,116 +1,126 @@
|
|
|
1
1
|
import { ACCESS_LEVEL_ORDER as t } from "./types.js";
|
|
2
|
-
import { CONSULTATION_ERROR_CODES as i, KbGraphQLError as n, isConsultationErrorCode as s, isKbGraphQLError as
|
|
3
|
-
import { commentErrorCode as p, commentErrorMessageKey as
|
|
2
|
+
import { CONSULTATION_ERROR_CODES as i, KbGraphQLError as n, isConsultationErrorCode as s, isKbGraphQLError as l } from "./errors.js";
|
|
3
|
+
import { commentErrorCode as p, commentErrorMessageKey as E } from "./comments-legacy.js";
|
|
4
4
|
import { createKbClient as R } from "./client.js";
|
|
5
|
-
import { findNavNode as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
5
|
+
import { findNavNode as d, flattenNav as x, isNavigable as T, navBreadcrumbs as S, navNextPrev as v, navSiblings as g, navSubtree as A, navWalk as _ } from "./navigation.js";
|
|
6
|
+
import { LAYER_SCOPE_TOKEN as C, applyLayerScope as u, layerMatches as I, layerScope as w, layerStyleText as b, matchLayers as y, mergePinnedLayers as N, parseStyleLayers as h, sortStyleLayers as M } from "./style-layers.js";
|
|
7
|
+
import { createAuthManager as k, createLocalStorageTokenStorage as P, createMemoryTokenStorage as W, decodeJwtUser as D, hasAccessLevel as H } from "./auth.js";
|
|
8
|
+
import { DelegatedTokenError as K, createDelegatedTokenMinter as U } from "./delegated-identity.js";
|
|
9
|
+
import { ConsultationAdapterError as G, createConsultationAdapterClient as B, isConsultationAdapterError as q } from "./consultation-adapter.js";
|
|
10
|
+
import { generateDescription as Q, stripLeadingH1 as Y } from "./article-seo.js";
|
|
11
|
+
import { createMarkedInstance as j, defaultImageHtml as X, parseMarkdownSafe as Z } from "./markdown.js";
|
|
12
|
+
import { deepMerge as ee } from "./blog-config.js";
|
|
13
|
+
import { retryWithBackoff as oe } from "./retry.js";
|
|
14
|
+
import { buildThemeCssVars as ae, darkenColor as ie, hexToHsl as ne, hexToRgb as se, hslToRgb as le, lightenColor as me, rgbTriplet as pe } from "./theme.js";
|
|
15
|
+
import { buildArticleSeo as fe, buildHomeSeo as Re, buildListPageSeo as ce, localizedHref as de, pageUrl as xe, stripLocalePrefix as Te } from "./seo.js";
|
|
16
|
+
import { buildArticleListItem as ve, formatArticleDate as ge, lockedRequiredAccess as Ae, resolveArticleAccessLevel as _e, toIsoDate as Le } from "./view-model.js";
|
|
17
|
+
import { createKbI18n as ue, mergeTranslations as Ie } from "./i18n.js";
|
|
17
18
|
import * as e from "./queries.js";
|
|
18
|
-
import { prepareProps as
|
|
19
|
-
import { extractTitleHeading as
|
|
20
|
-
import { componentMetadata as
|
|
21
|
-
import { REVIEW_PAGE_PATH as
|
|
22
|
-
import { formatReviewForAgent as
|
|
23
|
-
import { REVIEW_REASON_STATUS as
|
|
24
|
-
import { REVIEW_LAYER_SCRIPT_URL as
|
|
25
|
-
import { createReviewPlan as
|
|
26
|
-
import { REVIEW_FIELD_ATTR as
|
|
27
|
-
import { default as
|
|
28
|
-
import { default as
|
|
19
|
+
import { prepareProps as be } from "@blogmcp/mdx-schema/prepareProps";
|
|
20
|
+
import { extractTitleHeading as Ne, inlineMarkdownToPlainText as he } from "@blogmcp/mdx-schema/title";
|
|
21
|
+
import { componentMetadata as Oe, getComponentMetadata as ke, getComponentNames as Pe } from "@blogmcp/mdx-schema/metadata";
|
|
22
|
+
import { REVIEW_PAGE_PATH as De, REVIEW_ROUTE_PATTERN as He, isReviewTokenFormat as Ve } from "./review/types.js";
|
|
23
|
+
import { formatReviewForAgent as Ue, formatReviewRound as Fe } from "./review/format.js";
|
|
24
|
+
import { REVIEW_REASON_STATUS as Be, createReviewClient as qe, getReviewSession as ze } from "./review/client.js";
|
|
25
|
+
import { REVIEW_LAYER_SCRIPT_URL as Ye, REVIEW_SESSION_ELEMENT_ID as Je, renderReviewStatusHtml as je, reviewBootstrapHtml as Xe, reviewContentWithMedia as Ze, reviewFieldAttrs as $e, reviewIgnoreAttrs as er, reviewResponseHeaders as rr, reviewRootAttrs as or, reviewStatusText as tr } from "./review/page.js";
|
|
26
|
+
import { createReviewPlan as ir, normalizeReviewText as nr } from "./review/plan.js";
|
|
27
|
+
import { REVIEW_FIELD_ATTR as lr, REVIEW_IGNORE_ATTR as mr, REVIEW_ROOT_ATTR as pr, stampReviewDom as Er } from "./review/stamp.js";
|
|
28
|
+
import { default as Rr } from "./translations/cs.json.js";
|
|
29
|
+
import { default as dr } from "./translations/en.json.js";
|
|
29
30
|
export {
|
|
30
31
|
t as ACCESS_LEVEL_ORDER,
|
|
31
32
|
i as CONSULTATION_ERROR_CODES,
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
G as ConsultationAdapterError,
|
|
34
|
+
K as DelegatedTokenError,
|
|
34
35
|
n as KbGraphQLError,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
C as LAYER_SCOPE_TOKEN,
|
|
37
|
+
lr as REVIEW_FIELD_ATTR,
|
|
38
|
+
mr as REVIEW_IGNORE_ATTR,
|
|
39
|
+
Ye as REVIEW_LAYER_SCRIPT_URL,
|
|
40
|
+
De as REVIEW_PAGE_PATH,
|
|
41
|
+
Be as REVIEW_REASON_STATUS,
|
|
42
|
+
pr as REVIEW_ROOT_ATTR,
|
|
43
|
+
He as REVIEW_ROUTE_PATTERN,
|
|
44
|
+
Je as REVIEW_SESSION_ELEMENT_ID,
|
|
45
|
+
u as applyLayerScope,
|
|
46
|
+
ve as buildArticleListItem,
|
|
47
|
+
fe as buildArticleSeo,
|
|
48
|
+
Re as buildHomeSeo,
|
|
49
|
+
ce as buildListPageSeo,
|
|
50
|
+
ae as buildThemeCssVars,
|
|
48
51
|
p as commentErrorCode,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
E as commentErrorMessageKey,
|
|
53
|
+
Oe as componentMetadata,
|
|
54
|
+
k as createAuthManager,
|
|
55
|
+
B as createConsultationAdapterClient,
|
|
56
|
+
U as createDelegatedTokenMinter,
|
|
54
57
|
R as createKbClient,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
58
|
+
ue as createKbI18n,
|
|
59
|
+
P as createLocalStorageTokenStorage,
|
|
60
|
+
j as createMarkedInstance,
|
|
61
|
+
W as createMemoryTokenStorage,
|
|
62
|
+
qe as createReviewClient,
|
|
63
|
+
ir as createReviewPlan,
|
|
64
|
+
Rr as csTranslations,
|
|
65
|
+
ie as darkenColor,
|
|
66
|
+
D as decodeJwtUser,
|
|
67
|
+
ee as deepMerge,
|
|
68
|
+
X as defaultImageHtml,
|
|
69
|
+
dr as enTranslations,
|
|
70
|
+
Ne as extractTitleHeading,
|
|
71
|
+
d as findNavNode,
|
|
72
|
+
x as flattenNav,
|
|
73
|
+
ge as formatArticleDate,
|
|
74
|
+
Ue as formatReviewForAgent,
|
|
75
|
+
Fe as formatReviewRound,
|
|
76
|
+
Q as generateDescription,
|
|
77
|
+
ke as getComponentMetadata,
|
|
78
|
+
Pe as getComponentNames,
|
|
79
|
+
ze as getReviewSession,
|
|
80
|
+
H as hasAccessLevel,
|
|
81
|
+
ne as hexToHsl,
|
|
82
|
+
se as hexToRgb,
|
|
83
|
+
le as hslToRgb,
|
|
84
|
+
he as inlineMarkdownToPlainText,
|
|
85
|
+
q as isConsultationAdapterError,
|
|
83
86
|
s as isConsultationErrorCode,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
l as isKbGraphQLError,
|
|
88
|
+
T as isNavigable,
|
|
89
|
+
Ve as isReviewTokenFormat,
|
|
90
|
+
I as layerMatches,
|
|
91
|
+
w as layerScope,
|
|
92
|
+
b as layerStyleText,
|
|
93
|
+
me as lightenColor,
|
|
94
|
+
de as localizedHref,
|
|
95
|
+
Ae as lockedRequiredAccess,
|
|
96
|
+
y as matchLayers,
|
|
97
|
+
N as mergePinnedLayers,
|
|
98
|
+
Ie as mergeTranslations,
|
|
99
|
+
S as navBreadcrumbs,
|
|
100
|
+
v as navNextPrev,
|
|
101
|
+
g as navSiblings,
|
|
102
|
+
A as navSubtree,
|
|
95
103
|
_ as navWalk,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
nr as normalizeReviewText,
|
|
105
|
+
xe as pageUrl,
|
|
106
|
+
Z as parseMarkdownSafe,
|
|
107
|
+
h as parseStyleLayers,
|
|
108
|
+
be as prepareProps,
|
|
100
109
|
e as queries,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
je as renderReviewStatusHtml,
|
|
111
|
+
_e as resolveArticleAccessLevel,
|
|
112
|
+
oe as retryWithBackoff,
|
|
113
|
+
Xe as reviewBootstrapHtml,
|
|
114
|
+
Ze as reviewContentWithMedia,
|
|
115
|
+
$e as reviewFieldAttrs,
|
|
116
|
+
er as reviewIgnoreAttrs,
|
|
117
|
+
rr as reviewResponseHeaders,
|
|
118
|
+
or as reviewRootAttrs,
|
|
119
|
+
tr as reviewStatusText,
|
|
120
|
+
pe as rgbTriplet,
|
|
121
|
+
M as sortStyleLayers,
|
|
122
|
+
Er as stampReviewDom,
|
|
123
|
+
Y as stripLeadingH1,
|
|
124
|
+
Te as stripLocalePrefix,
|
|
125
|
+
Le as toIsoDate
|
|
116
126
|
};
|
package/dist/core/queries.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const ARTICLE_VERSION = "\n query ArticleVersion($versionId: ID!
|
|
|
18
18
|
export declare const SEARCH_KNOWLEDGE_BASE = "\n query SearchKnowledgeBase($query: String!, $tags: [String!], $contentType: String, $limit: Int, $minSimilarity: Float, $searchMode: SearchMode) {\n searchKnowledgeBase(query: $query, tags: $tags, contentType: $contentType, limit: $limit, minSimilarity: $minSimilarity, searchMode: $searchMode) {\n articleId\n filename\n title\n chunkText\n similarity\n }\n }\n";
|
|
19
19
|
export declare const GET_KB_CONTEXT = "\n query GetKBContext($query: String!, $maxChunks: Int) {\n getKBContext(query: $query, maxChunks: $maxChunks) {\n chunks {\n filename\n title\n text\n similarity\n }\n totalChunks\n }\n }\n";
|
|
20
20
|
export declare const KB_NAVIGATION = "\n query KbNavigation($scope: String, $locale: String) {\n kbNavigation(scope: $scope, locale: $locale)\n }\n";
|
|
21
|
+
export declare const KB_STYLE_LAYERS = "\n query KbStyleLayers {\n kbStyleLayers\n }\n";
|
|
21
22
|
export declare const ACCESSIBLE_TAGS = "\n query AccessibleTags {\n accessibleKbTags {\n tags {\n id\n slug\n name\n description\n color\n }\n totalCount\n }\n }\n";
|
|
22
23
|
export declare const LOCALIZED_TAGS = "\n query LocalizedTags($languageCode: String!) {\n localizedTags(languageCode: $languageCode) {\n id\n name\n slug\n description\n color\n accessLevel\n languageCode\n isFallback\n }\n }\n";
|
|
23
24
|
export declare const KB_LANGUAGES = "\n query KBLanguages {\n kbLanguages {\n id\n code\n name\n nativeName\n isSource\n isEnabled\n sortOrder\n }\n }\n";
|
package/dist/core/queries.js
CHANGED
|
@@ -78,7 +78,7 @@ const s = `
|
|
|
78
78
|
totalCount
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
`,
|
|
81
|
+
`, a = `
|
|
82
82
|
id
|
|
83
83
|
filename
|
|
84
84
|
contentType
|
|
@@ -116,13 +116,13 @@ const s = `
|
|
|
116
116
|
accessRights
|
|
117
117
|
`, c = `
|
|
118
118
|
query ArticleWithTranslation($filename: String!, $languageCode: String!) {
|
|
119
|
-
articleWithTranslation(filename: $filename, languageCode: $languageCode) {${
|
|
119
|
+
articleWithTranslation(filename: $filename, languageCode: $languageCode) {${a}}
|
|
120
120
|
}
|
|
121
121
|
`, u = `
|
|
122
122
|
query ArticleWithTranslationById($id: ID!, $languageCode: String!) {
|
|
123
|
-
articleWithTranslationById(id: $id, languageCode: $languageCode) {${
|
|
123
|
+
articleWithTranslationById(id: $id, languageCode: $languageCode) {${a}}
|
|
124
124
|
}
|
|
125
|
-
`,
|
|
125
|
+
`, o = `
|
|
126
126
|
id
|
|
127
127
|
filename
|
|
128
128
|
title
|
|
@@ -136,11 +136,11 @@ const s = `
|
|
|
136
136
|
excerpt
|
|
137
137
|
`, d = `
|
|
138
138
|
query ArticlePreview($filename: String!, $languageCode: String!) {
|
|
139
|
-
articlePreview(filename: $filename, languageCode: $languageCode) {${
|
|
139
|
+
articlePreview(filename: $filename, languageCode: $languageCode) {${o}}
|
|
140
140
|
}
|
|
141
141
|
`, g = `
|
|
142
142
|
query ArticlePreviewById($id: ID!, $languageCode: String!) {
|
|
143
|
-
articlePreviewById(id: $id, languageCode: $languageCode) {${
|
|
143
|
+
articlePreviewById(id: $id, languageCode: $languageCode) {${o}}
|
|
144
144
|
}
|
|
145
145
|
`, $ = `
|
|
146
146
|
query ArticleAliasTarget($filename: String!) {
|
|
@@ -187,6 +187,10 @@ const s = `
|
|
|
187
187
|
kbNavigation(scope: $scope, locale: $locale)
|
|
188
188
|
}
|
|
189
189
|
`, T = `
|
|
190
|
+
query KbStyleLayers {
|
|
191
|
+
kbStyleLayers
|
|
192
|
+
}
|
|
193
|
+
`, A = `
|
|
190
194
|
query AccessibleTags {
|
|
191
195
|
accessibleKbTags {
|
|
192
196
|
tags {
|
|
@@ -199,7 +203,7 @@ const s = `
|
|
|
199
203
|
totalCount
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
|
-
`,
|
|
206
|
+
`, E = `
|
|
203
207
|
query LocalizedTags($languageCode: String!) {
|
|
204
208
|
localizedTags(languageCode: $languageCode) {
|
|
205
209
|
id
|
|
@@ -212,7 +216,7 @@ const s = `
|
|
|
212
216
|
isFallback
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
|
-
`,
|
|
219
|
+
`, y = `
|
|
216
220
|
query KBLanguages {
|
|
217
221
|
kbLanguages {
|
|
218
222
|
id
|
|
@@ -224,7 +228,7 @@ const s = `
|
|
|
224
228
|
sortOrder
|
|
225
229
|
}
|
|
226
230
|
}
|
|
227
|
-
`,
|
|
231
|
+
`, _ = `
|
|
228
232
|
query ArticleTranslations($articleId: ID!) {
|
|
229
233
|
listArticleTranslations(articleId: $articleId) {
|
|
230
234
|
id
|
|
@@ -235,7 +239,7 @@ const s = `
|
|
|
235
239
|
updatedAt
|
|
236
240
|
}
|
|
237
241
|
}
|
|
238
|
-
`,
|
|
242
|
+
`, p = `
|
|
239
243
|
query GetTranslation($sourceFilename: String!, $languageCode: String!) {
|
|
240
244
|
getTranslation(sourceFilename: $sourceFilename, languageCode: $languageCode) {
|
|
241
245
|
id
|
|
@@ -263,7 +267,7 @@ const s = `
|
|
|
263
267
|
isTranslated
|
|
264
268
|
isEdited
|
|
265
269
|
createdAt
|
|
266
|
-
`,
|
|
270
|
+
`, L = `
|
|
267
271
|
query ArticleComments($articleId: ID!, $languageCode: String!) {
|
|
268
272
|
articleComments(articleId: $articleId, languageCode: $languageCode) {
|
|
269
273
|
comments {
|
|
@@ -290,7 +294,7 @@ const s = `
|
|
|
290
294
|
}
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
|
-
`,
|
|
297
|
+
`, R = `
|
|
294
298
|
mutation CreateComment($articleId: ID!, $content: String!, $sourceLanguageCode: String!, $parentCommentId: ID) {
|
|
295
299
|
createComment(articleId: $articleId, content: $content, sourceLanguageCode: $sourceLanguageCode, parentCommentId: $parentCommentId) {
|
|
296
300
|
success
|
|
@@ -300,7 +304,7 @@ const s = `
|
|
|
300
304
|
}
|
|
301
305
|
}
|
|
302
306
|
}
|
|
303
|
-
`,
|
|
307
|
+
`, f = `
|
|
304
308
|
mutation UpdateComment($commentId: ID!, $content: String!) {
|
|
305
309
|
updateComment(commentId: $commentId, content: $content) {
|
|
306
310
|
success
|
|
@@ -310,21 +314,21 @@ const s = `
|
|
|
310
314
|
}
|
|
311
315
|
}
|
|
312
316
|
}
|
|
313
|
-
`,
|
|
317
|
+
`, O = `
|
|
314
318
|
mutation DeleteComment($commentId: ID!) {
|
|
315
319
|
deleteComment(commentId: $commentId) {
|
|
316
320
|
success
|
|
317
321
|
error
|
|
318
322
|
}
|
|
319
323
|
}
|
|
320
|
-
`,
|
|
324
|
+
`, M = `
|
|
321
325
|
subscription CommentUpdates($articleId: ID!) {
|
|
322
326
|
commentUpdates(articleId: $articleId) {
|
|
323
327
|
type
|
|
324
328
|
commentId
|
|
325
329
|
}
|
|
326
330
|
}
|
|
327
|
-
`,
|
|
331
|
+
`, b = `
|
|
328
332
|
mutation Login($email: String!, $password: String!) {
|
|
329
333
|
login(email: $email, password: $password) {
|
|
330
334
|
success
|
|
@@ -338,7 +342,7 @@ const s = `
|
|
|
338
342
|
error
|
|
339
343
|
}
|
|
340
344
|
}
|
|
341
|
-
`,
|
|
345
|
+
`, P = `
|
|
342
346
|
mutation Register($email: String!, $password: String!, $name: String) {
|
|
343
347
|
register(email: $email, password: $password, name: $name) {
|
|
344
348
|
success
|
|
@@ -346,14 +350,14 @@ const s = `
|
|
|
346
350
|
error
|
|
347
351
|
}
|
|
348
352
|
}
|
|
349
|
-
`,
|
|
353
|
+
`, U = `
|
|
350
354
|
mutation VerifyEmail($token: String!) {
|
|
351
355
|
verifyEmail(token: $token) {
|
|
352
356
|
success
|
|
353
357
|
error
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
|
-
`,
|
|
360
|
+
`, q = `
|
|
357
361
|
mutation ForgotPassword($email: String!) {
|
|
358
362
|
forgotPassword(email: $email) {
|
|
359
363
|
success
|
|
@@ -368,7 +372,7 @@ const s = `
|
|
|
368
372
|
error
|
|
369
373
|
}
|
|
370
374
|
}
|
|
371
|
-
`,
|
|
375
|
+
`, D = `
|
|
372
376
|
mutation ResendVerification($email: String!) {
|
|
373
377
|
resendVerification(email: $email) {
|
|
374
378
|
success
|
|
@@ -376,7 +380,7 @@ const s = `
|
|
|
376
380
|
error
|
|
377
381
|
}
|
|
378
382
|
}
|
|
379
|
-
`,
|
|
383
|
+
`, k = `
|
|
380
384
|
mutation ChangePassword($currentPassword: String!, $newPassword: String!) {
|
|
381
385
|
changePassword(currentPassword: $currentPassword, newPassword: $newPassword) {
|
|
382
386
|
success
|
|
@@ -397,7 +401,7 @@ const s = `
|
|
|
397
401
|
error
|
|
398
402
|
}
|
|
399
403
|
}
|
|
400
|
-
`,
|
|
404
|
+
`, B = `
|
|
401
405
|
query MyReportSettings {
|
|
402
406
|
myReportSettings {
|
|
403
407
|
autoReportErrors
|
|
@@ -409,7 +413,7 @@ const s = `
|
|
|
409
413
|
feedbackNotifications
|
|
410
414
|
}
|
|
411
415
|
}
|
|
412
|
-
`,
|
|
416
|
+
`, v = `
|
|
413
417
|
mutation UpdateMyReportSettings(
|
|
414
418
|
$autoReportErrors: String
|
|
415
419
|
$autoReportContent: String
|
|
@@ -457,7 +461,7 @@ const s = `
|
|
|
457
461
|
error
|
|
458
462
|
duplicate
|
|
459
463
|
consultation {${n}}
|
|
460
|
-
`,
|
|
464
|
+
`, G = `
|
|
461
465
|
query ConsultationPublicConfig($locale: String!) {
|
|
462
466
|
consultationPublicConfig(locale: $locale) {
|
|
463
467
|
enabled
|
|
@@ -475,7 +479,7 @@ const s = `
|
|
|
475
479
|
}
|
|
476
480
|
}
|
|
477
481
|
}
|
|
478
|
-
`,
|
|
482
|
+
`, K = `
|
|
479
483
|
query MyConsultations($limit: Int, $offset: Int) {
|
|
480
484
|
myConsultations(limit: $limit, offset: $offset) {
|
|
481
485
|
id
|
|
@@ -485,23 +489,23 @@ const s = `
|
|
|
485
489
|
messageCount
|
|
486
490
|
}
|
|
487
491
|
}
|
|
488
|
-
`,
|
|
492
|
+
`, W = `
|
|
489
493
|
query MyConsultation($id: ID!) {
|
|
490
494
|
myConsultation(id: $id) {${n}}
|
|
491
495
|
}
|
|
492
|
-
`,
|
|
496
|
+
`, x = `
|
|
493
497
|
mutation CreateMyConsultation($input: CreateMyConsultationInput!) {
|
|
494
498
|
createMyConsultation(input: $input) {${t}}
|
|
495
499
|
}
|
|
496
|
-
`,
|
|
500
|
+
`, F = `
|
|
497
501
|
mutation PostMyConsultationMessage($consultationId: ID!, $body: String!, $clientRequestId: String!) {
|
|
498
502
|
postMyConsultationMessage(consultationId: $consultationId, body: $body, clientRequestId: $clientRequestId) {${t}}
|
|
499
503
|
}
|
|
500
|
-
`,
|
|
504
|
+
`, Y = `
|
|
501
505
|
mutation RequestMyConsultationErasure($consultationId: ID!) {
|
|
502
506
|
requestMyConsultationErasure(consultationId: $consultationId) {${t}}
|
|
503
507
|
}
|
|
504
|
-
`,
|
|
508
|
+
`, H = `
|
|
505
509
|
query MyConsultationConsent($locale: String!) {
|
|
506
510
|
myConsultationConsent(locale: $locale) {
|
|
507
511
|
mode
|
|
@@ -517,7 +521,7 @@ const s = `
|
|
|
517
521
|
}
|
|
518
522
|
}
|
|
519
523
|
}
|
|
520
|
-
`,
|
|
524
|
+
`, V = `
|
|
521
525
|
mutation WithdrawMyConsultationConsent {
|
|
522
526
|
withdrawMyConsultationConsent {
|
|
523
527
|
success
|
|
@@ -526,7 +530,7 @@ const s = `
|
|
|
526
530
|
threadsClosed
|
|
527
531
|
}
|
|
528
532
|
}
|
|
529
|
-
`,
|
|
533
|
+
`, z = `
|
|
530
534
|
mutation ExchangeConsultationLink($token: String!) {
|
|
531
535
|
exchangeConsultationLink(token: $token) {
|
|
532
536
|
success
|
|
@@ -537,27 +541,27 @@ const s = `
|
|
|
537
541
|
consultation {${n}}
|
|
538
542
|
}
|
|
539
543
|
}
|
|
540
|
-
`,
|
|
544
|
+
`, Q = `
|
|
541
545
|
query ConsultationBySession($session: String!) {
|
|
542
546
|
consultationBySession(session: $session) {${n}}
|
|
543
547
|
}
|
|
544
|
-
`,
|
|
548
|
+
`, Z = `
|
|
545
549
|
mutation PostConsultationMessageBySession($session: String!, $body: String!, $clientRequestId: String!) {
|
|
546
550
|
postConsultationMessageBySession(session: $session, body: $body, clientRequestId: $clientRequestId) {${t}}
|
|
547
551
|
}
|
|
548
|
-
`,
|
|
552
|
+
`, X = `
|
|
549
553
|
mutation RequestConsultationErasureBySession($session: String!) {
|
|
550
554
|
requestConsultationErasureBySession(session: $session) {${t}}
|
|
551
555
|
}
|
|
552
|
-
`,
|
|
556
|
+
`, j = `
|
|
553
557
|
mutation CloseConsultationSession($session: String!) {
|
|
554
558
|
closeConsultationSession(session: $session) {${t}}
|
|
555
559
|
}
|
|
556
|
-
`,
|
|
560
|
+
`, J = `
|
|
557
561
|
mutation AttachConsultationToMyAccount($session: String!) {
|
|
558
562
|
attachConsultationToMyAccount(session: $session) {${t}}
|
|
559
563
|
}
|
|
560
|
-
`,
|
|
564
|
+
`, ee = `
|
|
561
565
|
mutation RequestConsultationLink($email: String!) {
|
|
562
566
|
requestConsultationLink(email: $email)
|
|
563
567
|
}
|
|
@@ -567,49 +571,50 @@ export {
|
|
|
567
571
|
r as ACCESSIBLE_ARTICLES_LOCALIZED,
|
|
568
572
|
i as ACCESSIBLE_ARTICLES_WITH_LOCKED,
|
|
569
573
|
l as ACCESSIBLE_ARTICLES_WITH_LOCKED_LOCALIZED,
|
|
570
|
-
|
|
574
|
+
A as ACCESSIBLE_TAGS,
|
|
571
575
|
$ as ARTICLE_ALIAS_TARGET,
|
|
572
|
-
|
|
576
|
+
L as ARTICLE_COMMENTS,
|
|
573
577
|
d as ARTICLE_PREVIEW,
|
|
574
578
|
g as ARTICLE_PREVIEW_BY_ID,
|
|
575
|
-
|
|
579
|
+
_ as ARTICLE_TRANSLATIONS,
|
|
576
580
|
m as ARTICLE_VERSION,
|
|
577
581
|
c as ARTICLE_WITH_TRANSLATION,
|
|
578
582
|
u as ARTICLE_WITH_TRANSLATION_BY_ID,
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
583
|
+
J as ATTACH_CONSULTATION_TO_MY_ACCOUNT,
|
|
584
|
+
k as CHANGE_PASSWORD,
|
|
585
|
+
j as CLOSE_CONSULTATION_SESSION,
|
|
586
|
+
M as COMMENT_UPDATES_SUBSCRIPTION,
|
|
587
|
+
Q as CONSULTATION_BY_SESSION,
|
|
588
|
+
G as CONSULTATION_PUBLIC_CONFIG,
|
|
589
|
+
R as CREATE_COMMENT,
|
|
590
|
+
x as CREATE_MY_CONSULTATION,
|
|
591
|
+
O as DELETE_COMMENT,
|
|
592
|
+
z as EXCHANGE_CONSULTATION_LINK,
|
|
593
|
+
q as FORGOT_PASSWORD,
|
|
590
594
|
N as GET_COMMENT,
|
|
591
595
|
S as GET_KB_CONTEXT,
|
|
592
|
-
|
|
593
|
-
|
|
596
|
+
p as GET_TRANSLATION,
|
|
597
|
+
y as KB_LANGUAGES,
|
|
594
598
|
I as KB_NAVIGATION,
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
599
|
+
T as KB_STYLE_LAYERS,
|
|
600
|
+
E as LOCALIZED_TAGS,
|
|
601
|
+
b as LOGIN,
|
|
602
|
+
W as MY_CONSULTATION,
|
|
603
|
+
K as MY_CONSULTATIONS,
|
|
604
|
+
H as MY_CONSULTATION_CONSENT,
|
|
605
|
+
B as MY_REPORT_SETTINGS,
|
|
606
|
+
Z as POST_CONSULTATION_MESSAGE_BY_SESSION,
|
|
607
|
+
F as POST_MY_CONSULTATION_MESSAGE,
|
|
608
|
+
P as REGISTER,
|
|
609
|
+
X as REQUEST_CONSULTATION_ERASURE_BY_SESSION,
|
|
610
|
+
ee as REQUEST_CONSULTATION_LINK,
|
|
611
|
+
Y as REQUEST_MY_CONSULTATION_ERASURE,
|
|
612
|
+
D as RESEND_VERIFICATION,
|
|
608
613
|
h as RESET_PASSWORD,
|
|
609
614
|
C as SEARCH_KNOWLEDGE_BASE,
|
|
610
|
-
|
|
615
|
+
f as UPDATE_COMMENT,
|
|
611
616
|
w as UPDATE_MY_PROFILE,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
617
|
+
v as UPDATE_MY_REPORT_SETTINGS,
|
|
618
|
+
U as VERIFY_EMAIL,
|
|
619
|
+
V as WITHDRAW_MY_CONSULTATION_CONSENT
|
|
615
620
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* your frontend"). Dependency-free: shared by the page (through `@blogmcp/review`)
|
|
4
4
|
* and by server code that formats a review for the agent.
|
|
5
5
|
*/
|
|
6
|
+
import type { StyleLayer } from '../style-layers.js';
|
|
6
7
|
/** The route a site serves the review page on; `{token}` is the link's token. */
|
|
7
8
|
export declare const REVIEW_PAGE_PATH = "/preview/review/{token}";
|
|
8
9
|
/** Express-style pattern of the same route. */
|
|
@@ -83,6 +84,12 @@ export interface ReviewSession {
|
|
|
83
84
|
article: ReviewArticle;
|
|
84
85
|
/** Media the working copy references, keyed by slug (signed URLs for non-public ones). */
|
|
85
86
|
media: Record<string, ReviewMediaItem>;
|
|
87
|
+
/**
|
|
88
|
+
* Style-layer versions this link pins: on the review page a pinned version stands in for the
|
|
89
|
+
* published version of its layer (`mergePinnedLayers`). Absent from a knowledge base older than
|
|
90
|
+
* style layers; read it with `parseStyleLayers`, which takes that as an empty list.
|
|
91
|
+
*/
|
|
92
|
+
styleLayers?: StyleLayer[];
|
|
86
93
|
}
|
|
87
94
|
export interface ReviewState {
|
|
88
95
|
status: 'open';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style layers: named CSS a tenant keeps in the knowledge base and its site applies ON TOP of the
|
|
3
|
+
* design that ships in the site's code — a token, a campaign accent, the print layout of one kind
|
|
4
|
+
* of article — without a deploy of the site.
|
|
5
|
+
*
|
|
6
|
+
* The knowledge base validates a layer when it is saved and hands a site CSS in which every
|
|
7
|
+
* selector already lives under a placeholder scope root (`LAYER_SCOPE_TOKEN`). A site decides what
|
|
8
|
+
* that root is on its pages and substitutes it — a plain string replace, so no site needs a CSS
|
|
9
|
+
* parser:
|
|
10
|
+
*
|
|
11
|
+
* const layers = await client.styleLayers.list() // published, in order
|
|
12
|
+
* for (const layer of matchLayers(layers, { articleSlug })) {
|
|
13
|
+
* const css = layerStyleText(layer, layerScope('.my-article-root', layer.match))
|
|
14
|
+
* if (css) render(<style data-kb-layer={layer.name}>{css}</style>) // after your own stylesheets
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* Three rules for a site:
|
|
18
|
+
* - render the layers AFTER its own stylesheets, in the order given (a later layer wins);
|
|
19
|
+
* - with no layer, render nothing; a failure to read the layers renders the page without them;
|
|
20
|
+
* - choose a scope root that leaves out what a layer must never restyle (a checkout, an account,
|
|
21
|
+
* a consent dialog). A layer cannot reach outside the root it is given.
|
|
22
|
+
*
|
|
23
|
+
* Pure and dependency-free: safe in a browser bundle, on a server and in a test.
|
|
24
|
+
*/
|
|
25
|
+
/** The scope root in the CSS the knowledge base serves. A type selector no element has. */
|
|
26
|
+
export declare const LAYER_SCOPE_TOKEN = "__KB_LAYER_SCOPE__";
|
|
27
|
+
/** What a layer applies to. `value` is an article slug (the filename without `.mdx`) or its start. */
|
|
28
|
+
export type StyleLayerMatch = {
|
|
29
|
+
kind: 'site';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'article_prefix';
|
|
32
|
+
value: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'article';
|
|
35
|
+
value: string;
|
|
36
|
+
};
|
|
37
|
+
/** One version of a layer as a site receives it. */
|
|
38
|
+
export interface StyleLayer {
|
|
39
|
+
name: string;
|
|
40
|
+
match: StyleLayerMatch;
|
|
41
|
+
/** Layers apply in ascending position, ties by name. */
|
|
42
|
+
position: number;
|
|
43
|
+
version: number;
|
|
44
|
+
versionId: string;
|
|
45
|
+
/** Validated CSS with `LAYER_SCOPE_TOKEN` where the scope root goes. */
|
|
46
|
+
css: string;
|
|
47
|
+
}
|
|
48
|
+
/** The order layers apply in: ascending position, ties by name. Returns a new array. */
|
|
49
|
+
export declare function sortStyleLayers<T extends Pick<StyleLayer, 'position' | 'name'>>(layers: readonly T[]): T[];
|
|
50
|
+
/**
|
|
51
|
+
* The layers of an API answer — the `kbStyleLayers` field, a review session's `styleLayers`, or the
|
|
52
|
+
* REST list — as a sorted list. An entry that is not a layer is dropped, never thrown on: what a
|
|
53
|
+
* site does with a bad answer is render without it.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseStyleLayers(payload: unknown): StyleLayer[];
|
|
56
|
+
/** Whether a layer applies to a page: a `site` layer always, an article layer by the page's article slug. */
|
|
57
|
+
export declare function layerMatches(match: StyleLayerMatch, page: {
|
|
58
|
+
articleSlug?: string | null;
|
|
59
|
+
}): boolean;
|
|
60
|
+
/** The layers that apply to a page, in order. */
|
|
61
|
+
export declare function matchLayers(layers: readonly StyleLayer[], page: {
|
|
62
|
+
articleSlug?: string | null;
|
|
63
|
+
}): StyleLayer[];
|
|
64
|
+
/**
|
|
65
|
+
* The layers of a review page: a version the review link pins stands in for the published version
|
|
66
|
+
* of the same layer, and a pinned layer that is not published is added. In order.
|
|
67
|
+
*/
|
|
68
|
+
export declare function mergePinnedLayers(published: readonly StyleLayer[], pinned: readonly StyleLayer[]): StyleLayer[];
|
|
69
|
+
/**
|
|
70
|
+
* The scope root of a layer on a site that marks an article's root element with its slug
|
|
71
|
+
* (`<div class="article" data-article="my-slug">`): `base` for a `site` layer, `base[attr="slug"]`
|
|
72
|
+
* for an article, `base[attr^="prefix"]` for an article prefix. `base` is the selector of the
|
|
73
|
+
* element that carries the attribute.
|
|
74
|
+
*/
|
|
75
|
+
export declare function layerScope(base: string, match: StyleLayerMatch, attribute?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* The layer's CSS with the site's scope root in place of the placeholder.
|
|
78
|
+
*
|
|
79
|
+
* @throws TypeError when `scope` is not one selector (a list would scope only its last part).
|
|
80
|
+
*/
|
|
81
|
+
export declare function applyLayerScope(css: string, scope: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* The text of a layer's `<style>` element, or null when the layer must not be rendered: an empty
|
|
84
|
+
* layer, a scope that is not one selector, or CSS holding `</` or `<!--`. The knowledge base
|
|
85
|
+
* refuses those sequences when a layer is saved; this is the same check at the last step before
|
|
86
|
+
* the text goes into a page, where a `</style` would end the element.
|
|
87
|
+
*/
|
|
88
|
+
export declare function layerStyleText(layer: Pick<StyleLayer, 'css'>, scope: string): string | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const o = "__KB_LAYER_SCOPE__", a = /^[a-z][a-z0-9-]{0,62}$/, c = /^[a-z0-9][a-z0-9-]{0,199}$/, u = /[,{}<;]|\/\*|^\s*$/;
|
|
2
|
+
function l(t) {
|
|
3
|
+
if (!t || typeof t != "object") return null;
|
|
4
|
+
const { kind: e, value: r } = t;
|
|
5
|
+
return e === "site" ? { kind: "site" } : (e === "article" || e === "article_prefix") && typeof r == "string" && c.test(r) ? { kind: e, value: r } : null;
|
|
6
|
+
}
|
|
7
|
+
function f(t) {
|
|
8
|
+
if (!t || typeof t != "object") return null;
|
|
9
|
+
const e = t, r = l(e.match);
|
|
10
|
+
return typeof e.name != "string" || !a.test(e.name) || !r || typeof e.css != "string" || typeof e.version != "number" || typeof e.versionId != "string" ? null : {
|
|
11
|
+
name: e.name,
|
|
12
|
+
match: r,
|
|
13
|
+
position: typeof e.position == "number" && Number.isFinite(e.position) ? e.position : 0,
|
|
14
|
+
version: e.version,
|
|
15
|
+
versionId: e.versionId,
|
|
16
|
+
css: e.css
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function i(t) {
|
|
20
|
+
return [...t].sort((e, r) => e.position - r.position || (e.name < r.name ? -1 : e.name > r.name ? 1 : 0));
|
|
21
|
+
}
|
|
22
|
+
function m(t) {
|
|
23
|
+
const e = Array.isArray(t) ? t : t && typeof t == "object" && Array.isArray(t.layers) ? t.layers : [], r = [];
|
|
24
|
+
for (const n of e) {
|
|
25
|
+
const s = f(n);
|
|
26
|
+
s && r.push(s);
|
|
27
|
+
}
|
|
28
|
+
return i(r);
|
|
29
|
+
}
|
|
30
|
+
function y(t, e) {
|
|
31
|
+
if (t.kind === "site") return !0;
|
|
32
|
+
const r = e.articleSlug;
|
|
33
|
+
return r ? t.kind === "article" ? r === t.value : r.startsWith(t.value) : !1;
|
|
34
|
+
}
|
|
35
|
+
function _(t, e) {
|
|
36
|
+
return i(t.filter((r) => y(r.match, e)));
|
|
37
|
+
}
|
|
38
|
+
function E(t, e) {
|
|
39
|
+
const r = new Set(e.map((n) => n.name));
|
|
40
|
+
return i([...t.filter((n) => !r.has(n.name)), ...e]);
|
|
41
|
+
}
|
|
42
|
+
function S(t, e, r = "data-article") {
|
|
43
|
+
return e.kind === "site" ? t : `${t}[${r}${e.kind === "article" ? "=" : "^="}"${e.value}"]`;
|
|
44
|
+
}
|
|
45
|
+
function p(t, e) {
|
|
46
|
+
if (typeof e != "string" || u.test(e))
|
|
47
|
+
throw new TypeError('applyLayerScope: the scope must be one selector, e.g. ".article" or ".article[data-article=\\"x\\"]"');
|
|
48
|
+
return t.split(o).join(e.trim());
|
|
49
|
+
}
|
|
50
|
+
function g(t, e) {
|
|
51
|
+
const r = t.css;
|
|
52
|
+
if (typeof r != "string" || r.trim() === "" || r.includes("</") || r.includes("<!--")) return null;
|
|
53
|
+
try {
|
|
54
|
+
return p(r, e);
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
o as LAYER_SCOPE_TOKEN,
|
|
61
|
+
p as applyLayerScope,
|
|
62
|
+
y as layerMatches,
|
|
63
|
+
S as layerScope,
|
|
64
|
+
g as layerStyleText,
|
|
65
|
+
_ as matchLayers,
|
|
66
|
+
E as mergePinnedLayers,
|
|
67
|
+
m as parseStyleLayers,
|
|
68
|
+
i as sortStyleLayers
|
|
69
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blogmcp/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Headless SDK for Knowledge Base blog — core client, Vue composables, Nuxt adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -98,8 +98,8 @@
|
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
100
|
"dependencies": {
|
|
101
|
-
"@blogmcp/mdx-schema": "^0.
|
|
102
|
-
"@blogmcp/sanitize": "^0.
|
|
101
|
+
"@blogmcp/mdx-schema": "^0.13.0",
|
|
102
|
+
"@blogmcp/sanitize": "^0.13.0",
|
|
103
103
|
"marked": "^15.0.7"
|
|
104
104
|
},
|
|
105
105
|
"optionalDependencies": {
|
package/src/core/client.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
UpdateReportSettingsInput,
|
|
29
29
|
} from './types'
|
|
30
30
|
import type { NavNode } from './navigation'
|
|
31
|
+
import { parseStyleLayers, type StyleLayer } from './style-layers'
|
|
31
32
|
import * as Q from './queries'
|
|
32
33
|
import { createMemoryTokenStorage } from './auth'
|
|
33
34
|
import { KbGraphQLError } from './errors'
|
|
@@ -208,6 +209,14 @@ export interface KbClient {
|
|
|
208
209
|
navigation: {
|
|
209
210
|
get(params?: { scope?: string; locale?: string }): Promise<{ kbNavigation: NavNode[] }>
|
|
210
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Style layers: the PUBLISHED layers of the site, in the order they apply (see `./style-layers`).
|
|
214
|
+
* Unlike the other groups this returns the parsed list, not the GraphQL field: an entry that is
|
|
215
|
+
* not a layer is dropped, so a caller can render what comes back.
|
|
216
|
+
*/
|
|
217
|
+
styleLayers: {
|
|
218
|
+
list(): Promise<StyleLayer[]>
|
|
219
|
+
}
|
|
211
220
|
/**
|
|
212
221
|
* Editorial access to translation ROWS — INTERNAL tokens only (a server client holding a
|
|
213
222
|
* kb_* internal key). The server refuses every other caller: a translation row carries the
|
|
@@ -369,6 +378,9 @@ export function createKbClient(config: KbClientConfig): KbClient {
|
|
|
369
378
|
navigation: {
|
|
370
379
|
get: (params) => exec(Q.KB_NAVIGATION, params ?? {}),
|
|
371
380
|
},
|
|
381
|
+
styleLayers: {
|
|
382
|
+
list: async () => parseStyleLayers((await exec<{ kbStyleLayers?: unknown } | undefined>(Q.KB_STYLE_LAYERS))?.kbStyleLayers),
|
|
383
|
+
},
|
|
372
384
|
translations: {
|
|
373
385
|
list: (articleId) => exec(Q.ARTICLE_TRANSLATIONS, { articleId }),
|
|
374
386
|
get: (sourceFilename, languageCode) =>
|
package/src/core/index.ts
CHANGED
|
@@ -113,6 +113,20 @@ export {
|
|
|
113
113
|
flattenNav,
|
|
114
114
|
} from './navigation'
|
|
115
115
|
|
|
116
|
+
// Style layers (CSS the site applies on top of its own design)
|
|
117
|
+
export type { StyleLayer, StyleLayerMatch } from './style-layers'
|
|
118
|
+
export {
|
|
119
|
+
LAYER_SCOPE_TOKEN,
|
|
120
|
+
parseStyleLayers,
|
|
121
|
+
sortStyleLayers,
|
|
122
|
+
layerMatches,
|
|
123
|
+
matchLayers,
|
|
124
|
+
mergePinnedLayers,
|
|
125
|
+
layerScope,
|
|
126
|
+
applyLayerScope,
|
|
127
|
+
layerStyleText,
|
|
128
|
+
} from './style-layers'
|
|
129
|
+
|
|
116
130
|
// Auth
|
|
117
131
|
export type { AuthManager } from './auth'
|
|
118
132
|
export {
|
package/src/core/queries.ts
CHANGED
|
@@ -246,6 +246,14 @@ export const KB_NAVIGATION = `
|
|
|
246
246
|
}
|
|
247
247
|
`
|
|
248
248
|
|
|
249
|
+
// ==================== Style layers ====================
|
|
250
|
+
|
|
251
|
+
export const KB_STYLE_LAYERS = `
|
|
252
|
+
query KbStyleLayers {
|
|
253
|
+
kbStyleLayers
|
|
254
|
+
}
|
|
255
|
+
`
|
|
256
|
+
|
|
249
257
|
// ==================== Tags ====================
|
|
250
258
|
|
|
251
259
|
export const ACCESSIBLE_TAGS = `
|
package/src/core/review/types.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* and by server code that formats a review for the agent.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { StyleLayer } from '../style-layers'
|
|
8
|
+
|
|
7
9
|
/** The route a site serves the review page on; `{token}` is the link's token. */
|
|
8
10
|
export const REVIEW_PAGE_PATH = '/preview/review/{token}'
|
|
9
11
|
/** Express-style pattern of the same route. */
|
|
@@ -85,6 +87,12 @@ export interface ReviewSession {
|
|
|
85
87
|
article: ReviewArticle
|
|
86
88
|
/** Media the working copy references, keyed by slug (signed URLs for non-public ones). */
|
|
87
89
|
media: Record<string, ReviewMediaItem>
|
|
90
|
+
/**
|
|
91
|
+
* Style-layer versions this link pins: on the review page a pinned version stands in for the
|
|
92
|
+
* published version of its layer (`mergePinnedLayers`). Absent from a knowledge base older than
|
|
93
|
+
* style layers; read it with `parseStyleLayers`, which takes that as an empty list.
|
|
94
|
+
*/
|
|
95
|
+
styleLayers?: StyleLayer[]
|
|
88
96
|
}
|
|
89
97
|
|
|
90
98
|
export interface ReviewState {
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style layers: named CSS a tenant keeps in the knowledge base and its site applies ON TOP of the
|
|
3
|
+
* design that ships in the site's code — a token, a campaign accent, the print layout of one kind
|
|
4
|
+
* of article — without a deploy of the site.
|
|
5
|
+
*
|
|
6
|
+
* The knowledge base validates a layer when it is saved and hands a site CSS in which every
|
|
7
|
+
* selector already lives under a placeholder scope root (`LAYER_SCOPE_TOKEN`). A site decides what
|
|
8
|
+
* that root is on its pages and substitutes it — a plain string replace, so no site needs a CSS
|
|
9
|
+
* parser:
|
|
10
|
+
*
|
|
11
|
+
* const layers = await client.styleLayers.list() // published, in order
|
|
12
|
+
* for (const layer of matchLayers(layers, { articleSlug })) {
|
|
13
|
+
* const css = layerStyleText(layer, layerScope('.my-article-root', layer.match))
|
|
14
|
+
* if (css) render(<style data-kb-layer={layer.name}>{css}</style>) // after your own stylesheets
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* Three rules for a site:
|
|
18
|
+
* - render the layers AFTER its own stylesheets, in the order given (a later layer wins);
|
|
19
|
+
* - with no layer, render nothing; a failure to read the layers renders the page without them;
|
|
20
|
+
* - choose a scope root that leaves out what a layer must never restyle (a checkout, an account,
|
|
21
|
+
* a consent dialog). A layer cannot reach outside the root it is given.
|
|
22
|
+
*
|
|
23
|
+
* Pure and dependency-free: safe in a browser bundle, on a server and in a test.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** The scope root in the CSS the knowledge base serves. A type selector no element has. */
|
|
27
|
+
export const LAYER_SCOPE_TOKEN = '__KB_LAYER_SCOPE__'
|
|
28
|
+
|
|
29
|
+
/** What a layer applies to. `value` is an article slug (the filename without `.mdx`) or its start. */
|
|
30
|
+
export type StyleLayerMatch =
|
|
31
|
+
| { kind: 'site' }
|
|
32
|
+
| { kind: 'article_prefix'; value: string }
|
|
33
|
+
| { kind: 'article'; value: string }
|
|
34
|
+
|
|
35
|
+
/** One version of a layer as a site receives it. */
|
|
36
|
+
export interface StyleLayer {
|
|
37
|
+
name: string
|
|
38
|
+
match: StyleLayerMatch
|
|
39
|
+
/** Layers apply in ascending position, ties by name. */
|
|
40
|
+
position: number
|
|
41
|
+
version: number
|
|
42
|
+
versionId: string
|
|
43
|
+
/** Validated CSS with `LAYER_SCOPE_TOKEN` where the scope root goes. */
|
|
44
|
+
css: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const NAME_RE = /^[a-z][a-z0-9-]{0,62}$/
|
|
48
|
+
const MATCH_VALUE_RE = /^[a-z0-9][a-z0-9-]{0,199}$/
|
|
49
|
+
/** A scope root is one compound or complex selector: no list, no block, no markup. */
|
|
50
|
+
const SCOPE_FORBIDDEN_RE = /[,{}<;]|\/\*|^\s*$/
|
|
51
|
+
|
|
52
|
+
function parseMatch(input: unknown): StyleLayerMatch | null {
|
|
53
|
+
if (!input || typeof input !== 'object') return null
|
|
54
|
+
const { kind, value } = input as { kind?: unknown; value?: unknown }
|
|
55
|
+
if (kind === 'site') return { kind: 'site' }
|
|
56
|
+
if ((kind === 'article' || kind === 'article_prefix') && typeof value === 'string' && MATCH_VALUE_RE.test(value)) {
|
|
57
|
+
return { kind, value }
|
|
58
|
+
}
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseLayer(input: unknown): StyleLayer | null {
|
|
63
|
+
if (!input || typeof input !== 'object') return null
|
|
64
|
+
const raw = input as Record<string, unknown>
|
|
65
|
+
const match = parseMatch(raw.match)
|
|
66
|
+
if (
|
|
67
|
+
typeof raw.name !== 'string' ||
|
|
68
|
+
!NAME_RE.test(raw.name) ||
|
|
69
|
+
!match ||
|
|
70
|
+
typeof raw.css !== 'string' ||
|
|
71
|
+
typeof raw.version !== 'number' ||
|
|
72
|
+
typeof raw.versionId !== 'string'
|
|
73
|
+
) {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
name: raw.name,
|
|
78
|
+
match,
|
|
79
|
+
position: typeof raw.position === 'number' && Number.isFinite(raw.position) ? raw.position : 0,
|
|
80
|
+
version: raw.version,
|
|
81
|
+
versionId: raw.versionId,
|
|
82
|
+
css: raw.css,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The order layers apply in: ascending position, ties by name. Returns a new array. */
|
|
87
|
+
export function sortStyleLayers<T extends Pick<StyleLayer, 'position' | 'name'>>(layers: readonly T[]): T[] {
|
|
88
|
+
return [...layers].sort((a, b) => a.position - b.position || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The layers of an API answer — the `kbStyleLayers` field, a review session's `styleLayers`, or the
|
|
93
|
+
* REST list — as a sorted list. An entry that is not a layer is dropped, never thrown on: what a
|
|
94
|
+
* site does with a bad answer is render without it.
|
|
95
|
+
*/
|
|
96
|
+
export function parseStyleLayers(payload: unknown): StyleLayer[] {
|
|
97
|
+
const list = Array.isArray(payload)
|
|
98
|
+
? payload
|
|
99
|
+
: payload && typeof payload === 'object' && Array.isArray((payload as { layers?: unknown }).layers)
|
|
100
|
+
? (payload as { layers: unknown[] }).layers
|
|
101
|
+
: []
|
|
102
|
+
const layers: StyleLayer[] = []
|
|
103
|
+
for (const entry of list) {
|
|
104
|
+
const layer = parseLayer(entry)
|
|
105
|
+
if (layer) layers.push(layer)
|
|
106
|
+
}
|
|
107
|
+
return sortStyleLayers(layers)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Whether a layer applies to a page: a `site` layer always, an article layer by the page's article slug. */
|
|
111
|
+
export function layerMatches(match: StyleLayerMatch, page: { articleSlug?: string | null }): boolean {
|
|
112
|
+
if (match.kind === 'site') return true
|
|
113
|
+
const slug = page.articleSlug
|
|
114
|
+
if (!slug) return false
|
|
115
|
+
return match.kind === 'article' ? slug === match.value : slug.startsWith(match.value)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The layers that apply to a page, in order. */
|
|
119
|
+
export function matchLayers(layers: readonly StyleLayer[], page: { articleSlug?: string | null }): StyleLayer[] {
|
|
120
|
+
return sortStyleLayers(layers.filter((layer) => layerMatches(layer.match, page)))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The layers of a review page: a version the review link pins stands in for the published version
|
|
125
|
+
* of the same layer, and a pinned layer that is not published is added. In order.
|
|
126
|
+
*/
|
|
127
|
+
export function mergePinnedLayers(published: readonly StyleLayer[], pinned: readonly StyleLayer[]): StyleLayer[] {
|
|
128
|
+
const pinnedNames = new Set(pinned.map((layer) => layer.name))
|
|
129
|
+
return sortStyleLayers([...published.filter((layer) => !pinnedNames.has(layer.name)), ...pinned])
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The scope root of a layer on a site that marks an article's root element with its slug
|
|
134
|
+
* (`<div class="article" data-article="my-slug">`): `base` for a `site` layer, `base[attr="slug"]`
|
|
135
|
+
* for an article, `base[attr^="prefix"]` for an article prefix. `base` is the selector of the
|
|
136
|
+
* element that carries the attribute.
|
|
137
|
+
*/
|
|
138
|
+
export function layerScope(base: string, match: StyleLayerMatch, attribute = 'data-article'): string {
|
|
139
|
+
if (match.kind === 'site') return base
|
|
140
|
+
return `${base}[${attribute}${match.kind === 'article' ? '=' : '^='}"${match.value}"]`
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The layer's CSS with the site's scope root in place of the placeholder.
|
|
145
|
+
*
|
|
146
|
+
* @throws TypeError when `scope` is not one selector (a list would scope only its last part).
|
|
147
|
+
*/
|
|
148
|
+
export function applyLayerScope(css: string, scope: string): string {
|
|
149
|
+
if (typeof scope !== 'string' || SCOPE_FORBIDDEN_RE.test(scope)) {
|
|
150
|
+
throw new TypeError('applyLayerScope: the scope must be one selector, e.g. ".article" or ".article[data-article=\\"x\\"]"')
|
|
151
|
+
}
|
|
152
|
+
return css.split(LAYER_SCOPE_TOKEN).join(scope.trim())
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The text of a layer's `<style>` element, or null when the layer must not be rendered: an empty
|
|
157
|
+
* layer, a scope that is not one selector, or CSS holding `</` or `<!--`. The knowledge base
|
|
158
|
+
* refuses those sequences when a layer is saved; this is the same check at the last step before
|
|
159
|
+
* the text goes into a page, where a `</style` would end the element.
|
|
160
|
+
*/
|
|
161
|
+
export function layerStyleText(layer: Pick<StyleLayer, 'css'>, scope: string): string | null {
|
|
162
|
+
const css = layer.css
|
|
163
|
+
if (typeof css !== 'string' || css.trim() === '' || css.includes('</') || css.includes('<!--')) return null
|
|
164
|
+
try {
|
|
165
|
+
return applyLayerScope(css, scope)
|
|
166
|
+
} catch {
|
|
167
|
+
return null
|
|
168
|
+
}
|
|
169
|
+
}
|