@blogmcp/sdk 0.1.1 → 0.1.3
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 +15 -1
- package/dist/core/client.js +27 -26
- package/dist/core/index.d.ts +1 -1
- package/dist/core/queries.d.ts +1 -0
- package/dist/core/queries.js +60 -45
- package/dist/core/types.d.ts +19 -0
- package/dist/packages/sanitize/dist/html.js +56 -19
- package/package.json +3 -3
- package/src/core/client.ts +16 -0
- package/src/core/index.ts +1 -0
- package/src/core/queries.ts +19 -0
- package/src/core/types.ts +20 -0
package/dist/core/client.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* const data = await client.articles.list({ status: 'published', limit: 10 })
|
|
7
7
|
*/
|
|
8
8
|
import type { KbClientConfig } from './client-types';
|
|
9
|
-
import type { Article, ArticleWithTranslation, Tag, LocalizedTag, Language, SearchResult, KBContextChunk, Translation, Comment, CommentsConnection, CommentResult, AuthResult, RegisterResult, UpdateProfileResult, ReportSettings, UpdateReportSettingsInput } from './types';
|
|
9
|
+
import type { Article, ArticleWithTranslation, ArticleVersionContent, Tag, LocalizedTag, Language, SearchResult, KBContextChunk, Translation, Comment, CommentsConnection, CommentResult, AuthResult, RegisterResult, UpdateProfileResult, ReportSettings, UpdateReportSettingsInput } from './types';
|
|
10
10
|
import type { NavNode } from './navigation';
|
|
11
11
|
export interface KbClient {
|
|
12
12
|
articles: {
|
|
@@ -44,6 +44,20 @@ export interface KbClient {
|
|
|
44
44
|
resolveAlias(filename: string): Promise<{
|
|
45
45
|
articleAliasTarget: string | null;
|
|
46
46
|
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Fetch ONE article version's content by its STABLE version id, for headless
|
|
49
|
+
* preview / A/B (test-before-publish, multi-variant serving). Bypasses publish
|
|
50
|
+
* status, so the server returns it only to an INTERNAL caller (server client
|
|
51
|
+
* holding the api token) OR a caller passing a valid `previewKey` minted for
|
|
52
|
+
* this exact versionId. Returns `{ articleVersion: null }` when missing or
|
|
53
|
+
* unauthorized. Versions are per-language; the returned `languageCode` is the
|
|
54
|
+
* version's own translation — no language argument is taken.
|
|
55
|
+
*/
|
|
56
|
+
getVersion(versionId: string, opts?: {
|
|
57
|
+
previewKey?: string;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
articleVersion: ArticleVersionContent | null;
|
|
60
|
+
}>;
|
|
47
61
|
};
|
|
48
62
|
search: {
|
|
49
63
|
query(params: {
|
package/dist/core/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { UPDATE_MY_PROFILE as A, UPDATE_MY_REPORT_SETTINGS as
|
|
2
|
-
import { createMemoryTokenStorage as
|
|
3
|
-
function
|
|
1
|
+
import { UPDATE_MY_PROFILE as i, ARTICLE_VERSION as A, UPDATE_MY_REPORT_SETTINGS as S, MY_REPORT_SETTINGS as _, CHANGE_PASSWORD as I, RESEND_VERIFICATION as l, RESET_PASSWORD as R, FORGOT_PASSWORD as c, VERIFY_EMAIL as d, REGISTER as N, LOGIN as O, DELETE_COMMENT as C, UPDATE_COMMENT as L, CREATE_COMMENT as u, GET_COMMENT as h, ARTICLE_COMMENTS as p, GET_TRANSLATION as g, ARTICLE_TRANSLATIONS as G, KB_NAVIGATION as m, KB_LANGUAGES as M, LOCALIZED_TAGS as P, ACCESSIBLE_TAGS as y, GET_KB_CONTEXT as D, SEARCH_KNOWLEDGE_BASE as f, ARTICLE_ALIAS_TARGET as w, ARTICLE_WITH_TRANSLATION_BY_ID as B, ARTICLE_WITH_TRANSLATION as v, ACCESSIBLE_ARTICLES as W } from "./queries.js";
|
|
2
|
+
import { createMemoryTokenStorage as K } from "./auth.js";
|
|
3
|
+
function k() {
|
|
4
4
|
return async (n, o) => (await fetch(n, {
|
|
5
5
|
method: o.method,
|
|
6
6
|
headers: o.headers,
|
|
@@ -22,58 +22,59 @@ async function x(n, o, a) {
|
|
|
22
22
|
return t.data;
|
|
23
23
|
}
|
|
24
24
|
function Y(n) {
|
|
25
|
-
const o = n.fetcher ||
|
|
25
|
+
const o = n.fetcher || k(), a = n.tokenStorage || K(), s = { endpoint: n.isServer && n.serverEndpoint ? n.serverEndpoint : n.endpoint, fetcher: o, tokenStorage: a };
|
|
26
26
|
function t(e, r) {
|
|
27
27
|
return x(s, e, r);
|
|
28
28
|
}
|
|
29
29
|
return {
|
|
30
30
|
articles: {
|
|
31
|
-
list: (e) => t(
|
|
32
|
-
getWithTranslation: (e, r) => t(
|
|
31
|
+
list: (e) => t(W, e),
|
|
32
|
+
getWithTranslation: (e, r) => t(v, { filename: e, languageCode: r }),
|
|
33
33
|
getWithTranslationById: (e, r) => t(B, { id: e, languageCode: r }),
|
|
34
|
-
resolveAlias: (e) => t(
|
|
34
|
+
resolveAlias: (e) => t(w, { filename: e }),
|
|
35
|
+
getVersion: (e, r) => t(A, { versionId: e, previewKey: r?.previewKey ?? null })
|
|
35
36
|
},
|
|
36
37
|
search: {
|
|
37
38
|
query: (e) => t(f, e),
|
|
38
39
|
getContext: (e, r) => t(D, { query: e, maxChunks: r })
|
|
39
40
|
},
|
|
40
41
|
tags: {
|
|
41
|
-
list: () => t(
|
|
42
|
-
listLocalized: (e) => t(
|
|
42
|
+
list: () => t(y),
|
|
43
|
+
listLocalized: (e) => t(P, { languageCode: e })
|
|
43
44
|
},
|
|
44
45
|
languages: {
|
|
45
|
-
list: () => t(
|
|
46
|
+
list: () => t(M)
|
|
46
47
|
},
|
|
47
48
|
navigation: {
|
|
48
|
-
get: (e) => t(
|
|
49
|
+
get: (e) => t(m, e ?? {})
|
|
49
50
|
},
|
|
50
51
|
translations: {
|
|
51
52
|
list: (e) => t(G, { sourceFilename: e }),
|
|
52
|
-
get: (e, r) => t(
|
|
53
|
+
get: (e, r) => t(g, { sourceFilename: e, languageCode: r })
|
|
53
54
|
},
|
|
54
55
|
comments: {
|
|
55
|
-
list: (e, r) => t(
|
|
56
|
+
list: (e, r) => t(p, { articleId: e, languageCode: r }),
|
|
56
57
|
get: (e, r) => t(h, { commentId: e, languageCode: r }),
|
|
57
|
-
create: (e) => t(
|
|
58
|
-
update: (e, r) => t(
|
|
59
|
-
delete: (e) => t(
|
|
58
|
+
create: (e) => t(u, e),
|
|
59
|
+
update: (e, r) => t(L, { commentId: e, content: r }),
|
|
60
|
+
delete: (e) => t(C, { commentId: e })
|
|
60
61
|
},
|
|
61
62
|
auth: {
|
|
62
|
-
login: (e, r) => t(
|
|
63
|
-
register: (e, r, T) => t(
|
|
64
|
-
verifyEmail: (e) => t(
|
|
65
|
-
forgotPassword: (e) => t(
|
|
66
|
-
resetPassword: (e, r) => t(
|
|
67
|
-
resendVerification: (e) => t(
|
|
68
|
-
changePassword: (e, r) => t(
|
|
69
|
-
updateProfile: (e) => t(
|
|
63
|
+
login: (e, r) => t(O, { email: e, password: r }),
|
|
64
|
+
register: (e, r, T) => t(N, { email: e, password: r, name: T }),
|
|
65
|
+
verifyEmail: (e) => t(d, { token: e }),
|
|
66
|
+
forgotPassword: (e) => t(c, { email: e }),
|
|
67
|
+
resetPassword: (e, r) => t(R, { token: e, password: r }),
|
|
68
|
+
resendVerification: (e) => t(l, { email: e }),
|
|
69
|
+
changePassword: (e, r) => t(I, { currentPassword: e, newPassword: r }),
|
|
70
|
+
updateProfile: (e) => t(i, {
|
|
70
71
|
name: e.name ?? null,
|
|
71
72
|
email: e.email ?? null
|
|
72
73
|
})
|
|
73
74
|
},
|
|
74
75
|
reportSettings: {
|
|
75
|
-
get: () => t(
|
|
76
|
-
update: (e) => t(
|
|
76
|
+
get: () => t(_),
|
|
77
|
+
update: (e) => t(S, e)
|
|
77
78
|
},
|
|
78
79
|
executeGraphQL: t
|
|
79
80
|
};
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Article, ArticleWithTranslation, MediaGeo, ContentImageGeo, Tag, LocalizedTag, SearchResult, KBContextChunk, Translation, Language, AccessLevel, Comment, CommentSubscriptionEvent, CommentsConnection, CommentResult, AuthUser, AuthResult, RegisterResult, UpdateProfileResult, ReportSettings, ReportPolicyValue, EmailNotificationFrequency, FeedbackNotificationFrequency, UpdateReportSettingsInput, PaginatedResponse, } from './types';
|
|
1
|
+
export type { Article, ArticleWithTranslation, ArticleVersionContent, MediaGeo, ContentImageGeo, Tag, LocalizedTag, SearchResult, KBContextChunk, Translation, Language, AccessLevel, Comment, CommentSubscriptionEvent, CommentsConnection, CommentResult, AuthUser, AuthResult, RegisterResult, UpdateProfileResult, ReportSettings, ReportPolicyValue, EmailNotificationFrequency, FeedbackNotificationFrequency, UpdateReportSettingsInput, PaginatedResponse, } from './types';
|
|
2
2
|
export { ACCESS_LEVEL_ORDER } from './types';
|
|
3
3
|
export type { KbClientConfig, Fetcher, TokenStorage, ImageHtmlRenderer, SanitizeFn, } from './client-types';
|
|
4
4
|
export type { KbClient } from './client';
|
package/dist/core/queries.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const ACCESSIBLE_ARTICLES = "\n query AccessibleArticles($status
|
|
|
9
9
|
export declare const ARTICLE_WITH_TRANSLATION = "\n query ArticleWithTranslation($filename: String!, $languageCode: String!) {\n articleWithTranslation(filename: $filename, languageCode: $languageCode) {\n id\n filename\n contentType\n status\n description\n sourceLanguageCode\n createdAt\n updatedAt\n publishedAt\n title\n content\n languageCode\n isSource\n isFallback\n featuredImageUrl\n featuredImageGeo {\n latitude\n longitude\n altitude\n placeName\n }\n contentImagesGeo {\n url\n latitude\n longitude\n altitude\n placeName\n }\n accessRights\n}\n }\n";
|
|
10
10
|
export declare const ARTICLE_WITH_TRANSLATION_BY_ID = "\n query ArticleWithTranslationById($id: ID!, $languageCode: String!) {\n articleWithTranslationById(id: $id, languageCode: $languageCode) {\n id\n filename\n contentType\n status\n description\n sourceLanguageCode\n createdAt\n updatedAt\n publishedAt\n title\n content\n languageCode\n isSource\n isFallback\n featuredImageUrl\n featuredImageGeo {\n latitude\n longitude\n altitude\n placeName\n }\n contentImagesGeo {\n url\n latitude\n longitude\n altitude\n placeName\n }\n accessRights\n}\n }\n";
|
|
11
11
|
export declare const ARTICLE_ALIAS_TARGET = "\n query ArticleAliasTarget($filename: String!) {\n articleAliasTarget(filename: $filename)\n }\n";
|
|
12
|
+
export declare const ARTICLE_VERSION = "\n query ArticleVersion($versionId: ID!, $previewKey: String) {\n articleVersion(versionId: $versionId, previewKey: $previewKey) {\n versionId\n articleId\n filename\n versionNumber\n title\n content\n languageCode\n schemaVersion\n createdAt\n }\n }\n";
|
|
12
13
|
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";
|
|
13
14
|
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";
|
|
14
15
|
export declare const KB_NAVIGATION = "\n query KbNavigation($scope: String, $locale: String) {\n kbNavigation(scope: $scope, locale: $locale)\n }\n";
|
package/dist/core/queries.js
CHANGED
|
@@ -59,6 +59,20 @@ const a = `
|
|
|
59
59
|
articleAliasTarget(filename: $filename)
|
|
60
60
|
}
|
|
61
61
|
`, r = `
|
|
62
|
+
query ArticleVersion($versionId: ID!, $previewKey: String) {
|
|
63
|
+
articleVersion(versionId: $versionId, previewKey: $previewKey) {
|
|
64
|
+
versionId
|
|
65
|
+
articleId
|
|
66
|
+
filename
|
|
67
|
+
versionNumber
|
|
68
|
+
title
|
|
69
|
+
content
|
|
70
|
+
languageCode
|
|
71
|
+
schemaVersion
|
|
72
|
+
createdAt
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`, s = `
|
|
62
76
|
query SearchKnowledgeBase($query: String!, $tags: [String!], $contentType: String, $limit: Int, $minSimilarity: Float, $searchMode: SearchMode) {
|
|
63
77
|
searchKnowledgeBase(query: $query, tags: $tags, contentType: $contentType, limit: $limit, minSimilarity: $minSimilarity, searchMode: $searchMode) {
|
|
64
78
|
articleId
|
|
@@ -68,7 +82,7 @@ const a = `
|
|
|
68
82
|
similarity
|
|
69
83
|
}
|
|
70
84
|
}
|
|
71
|
-
`,
|
|
85
|
+
`, c = `
|
|
72
86
|
query GetKBContext($query: String!, $maxChunks: Int) {
|
|
73
87
|
getKBContext(query: $query, maxChunks: $maxChunks) {
|
|
74
88
|
chunks {
|
|
@@ -80,11 +94,11 @@ const a = `
|
|
|
80
94
|
totalChunks
|
|
81
95
|
}
|
|
82
96
|
}
|
|
83
|
-
`,
|
|
97
|
+
`, l = `
|
|
84
98
|
query KbNavigation($scope: String, $locale: String) {
|
|
85
99
|
kbNavigation(scope: $scope, locale: $locale)
|
|
86
100
|
}
|
|
87
|
-
`,
|
|
101
|
+
`, d = `
|
|
88
102
|
query AccessibleTags {
|
|
89
103
|
accessibleKbTags {
|
|
90
104
|
tags {
|
|
@@ -97,7 +111,7 @@ const a = `
|
|
|
97
111
|
totalCount
|
|
98
112
|
}
|
|
99
113
|
}
|
|
100
|
-
`,
|
|
114
|
+
`, m = `
|
|
101
115
|
query LocalizedTags($languageCode: String!) {
|
|
102
116
|
localizedTags(languageCode: $languageCode) {
|
|
103
117
|
id
|
|
@@ -110,7 +124,7 @@ const a = `
|
|
|
110
124
|
isFallback
|
|
111
125
|
}
|
|
112
126
|
}
|
|
113
|
-
`,
|
|
127
|
+
`, u = `
|
|
114
128
|
query KBLanguages {
|
|
115
129
|
kbLanguages {
|
|
116
130
|
id
|
|
@@ -122,7 +136,7 @@ const a = `
|
|
|
122
136
|
sortOrder
|
|
123
137
|
}
|
|
124
138
|
}
|
|
125
|
-
`,
|
|
139
|
+
`, g = `
|
|
126
140
|
query ArticleTranslations($sourceFilename: String!) {
|
|
127
141
|
listArticleTranslations(sourceFilename: $sourceFilename) {
|
|
128
142
|
id
|
|
@@ -133,7 +147,7 @@ const a = `
|
|
|
133
147
|
updatedAt
|
|
134
148
|
}
|
|
135
149
|
}
|
|
136
|
-
`,
|
|
150
|
+
`, $ = `
|
|
137
151
|
query GetTranslation($sourceFilename: String!, $languageCode: String!) {
|
|
138
152
|
getTranslation(sourceFilename: $sourceFilename, languageCode: $languageCode) {
|
|
139
153
|
id
|
|
@@ -161,7 +175,7 @@ const a = `
|
|
|
161
175
|
isTranslated
|
|
162
176
|
isEdited
|
|
163
177
|
createdAt
|
|
164
|
-
`,
|
|
178
|
+
`, C = `
|
|
165
179
|
query ArticleComments($articleId: ID!, $languageCode: String!) {
|
|
166
180
|
articleComments(articleId: $articleId, languageCode: $languageCode) {
|
|
167
181
|
comments {
|
|
@@ -179,7 +193,7 @@ const a = `
|
|
|
179
193
|
totalCount
|
|
180
194
|
}
|
|
181
195
|
}
|
|
182
|
-
`,
|
|
196
|
+
`, S = `
|
|
183
197
|
query GetComment($commentId: ID!, $languageCode: String!) {
|
|
184
198
|
comment(commentId: $commentId, languageCode: $languageCode) {
|
|
185
199
|
${e}
|
|
@@ -188,7 +202,7 @@ const a = `
|
|
|
188
202
|
}
|
|
189
203
|
}
|
|
190
204
|
}
|
|
191
|
-
`,
|
|
205
|
+
`, I = `
|
|
192
206
|
mutation CreateComment($articleId: ID!, $content: String!, $sourceLanguageCode: String!, $parentCommentId: ID) {
|
|
193
207
|
createComment(articleId: $articleId, content: $content, sourceLanguageCode: $sourceLanguageCode, parentCommentId: $parentCommentId) {
|
|
194
208
|
success
|
|
@@ -198,7 +212,7 @@ const a = `
|
|
|
198
212
|
}
|
|
199
213
|
}
|
|
200
214
|
}
|
|
201
|
-
`,
|
|
215
|
+
`, T = `
|
|
202
216
|
mutation UpdateComment($commentId: ID!, $content: String!) {
|
|
203
217
|
updateComment(commentId: $commentId, content: $content) {
|
|
204
218
|
success
|
|
@@ -208,21 +222,21 @@ const a = `
|
|
|
208
222
|
}
|
|
209
223
|
}
|
|
210
224
|
}
|
|
211
|
-
`,
|
|
225
|
+
`, p = `
|
|
212
226
|
mutation DeleteComment($commentId: ID!) {
|
|
213
227
|
deleteComment(commentId: $commentId) {
|
|
214
228
|
success
|
|
215
229
|
error
|
|
216
230
|
}
|
|
217
231
|
}
|
|
218
|
-
`,
|
|
232
|
+
`, E = `
|
|
219
233
|
subscription CommentUpdates($articleId: ID!) {
|
|
220
234
|
commentUpdates(articleId: $articleId) {
|
|
221
235
|
type
|
|
222
236
|
commentId
|
|
223
237
|
}
|
|
224
238
|
}
|
|
225
|
-
`,
|
|
239
|
+
`, A = `
|
|
226
240
|
mutation Login($email: String!, $password: String!) {
|
|
227
241
|
login(email: $email, password: $password) {
|
|
228
242
|
success
|
|
@@ -236,7 +250,7 @@ const a = `
|
|
|
236
250
|
error
|
|
237
251
|
}
|
|
238
252
|
}
|
|
239
|
-
`,
|
|
253
|
+
`, R = `
|
|
240
254
|
mutation Register($email: String!, $password: String!, $name: String) {
|
|
241
255
|
register(email: $email, password: $password, name: $name) {
|
|
242
256
|
success
|
|
@@ -244,14 +258,14 @@ const a = `
|
|
|
244
258
|
error
|
|
245
259
|
}
|
|
246
260
|
}
|
|
247
|
-
`,
|
|
261
|
+
`, y = `
|
|
248
262
|
mutation VerifyEmail($token: String!) {
|
|
249
263
|
verifyEmail(token: $token) {
|
|
250
264
|
success
|
|
251
265
|
error
|
|
252
266
|
}
|
|
253
267
|
}
|
|
254
|
-
`,
|
|
268
|
+
`, f = `
|
|
255
269
|
mutation ForgotPassword($email: String!) {
|
|
256
270
|
forgotPassword(email: $email) {
|
|
257
271
|
success
|
|
@@ -259,14 +273,14 @@ const a = `
|
|
|
259
273
|
error
|
|
260
274
|
}
|
|
261
275
|
}
|
|
262
|
-
`,
|
|
276
|
+
`, N = `
|
|
263
277
|
mutation ResetPassword($token: String!, $password: String!) {
|
|
264
278
|
resetPassword(token: $token, password: $password) {
|
|
265
279
|
success
|
|
266
280
|
error
|
|
267
281
|
}
|
|
268
282
|
}
|
|
269
|
-
`,
|
|
283
|
+
`, L = `
|
|
270
284
|
mutation ResendVerification($email: String!) {
|
|
271
285
|
resendVerification(email: $email) {
|
|
272
286
|
success
|
|
@@ -274,14 +288,14 @@ const a = `
|
|
|
274
288
|
error
|
|
275
289
|
}
|
|
276
290
|
}
|
|
277
|
-
`,
|
|
291
|
+
`, _ = `
|
|
278
292
|
mutation ChangePassword($currentPassword: String!, $newPassword: String!) {
|
|
279
293
|
changePassword(currentPassword: $currentPassword, newPassword: $newPassword) {
|
|
280
294
|
success
|
|
281
295
|
error
|
|
282
296
|
}
|
|
283
297
|
}
|
|
284
|
-
`,
|
|
298
|
+
`, P = `
|
|
285
299
|
mutation UpdateMyProfile($name: String, $email: String) {
|
|
286
300
|
updateMyProfile(name: $name, email: $email) {
|
|
287
301
|
success
|
|
@@ -295,7 +309,7 @@ const a = `
|
|
|
295
309
|
error
|
|
296
310
|
}
|
|
297
311
|
}
|
|
298
|
-
`,
|
|
312
|
+
`, w = `
|
|
299
313
|
query MyReportSettings {
|
|
300
314
|
myReportSettings {
|
|
301
315
|
autoReportErrors
|
|
@@ -338,31 +352,32 @@ const a = `
|
|
|
338
352
|
`;
|
|
339
353
|
export {
|
|
340
354
|
a as ACCESSIBLE_ARTICLES,
|
|
341
|
-
|
|
355
|
+
d as ACCESSIBLE_TAGS,
|
|
342
356
|
i as ARTICLE_ALIAS_TARGET,
|
|
343
|
-
|
|
344
|
-
|
|
357
|
+
C as ARTICLE_COMMENTS,
|
|
358
|
+
g as ARTICLE_TRANSLATIONS,
|
|
359
|
+
r as ARTICLE_VERSION,
|
|
345
360
|
n as ARTICLE_WITH_TRANSLATION,
|
|
346
361
|
o as ARTICLE_WITH_TRANSLATION_BY_ID,
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
362
|
+
_ as CHANGE_PASSWORD,
|
|
363
|
+
E as COMMENT_UPDATES_SUBSCRIPTION,
|
|
364
|
+
I as CREATE_COMMENT,
|
|
365
|
+
p as DELETE_COMMENT,
|
|
366
|
+
f as FORGOT_PASSWORD,
|
|
367
|
+
S as GET_COMMENT,
|
|
368
|
+
c as GET_KB_CONTEXT,
|
|
369
|
+
$ as GET_TRANSLATION,
|
|
370
|
+
u as KB_LANGUAGES,
|
|
371
|
+
l as KB_NAVIGATION,
|
|
372
|
+
m as LOCALIZED_TAGS,
|
|
373
|
+
A as LOGIN,
|
|
374
|
+
w as MY_REPORT_SETTINGS,
|
|
375
|
+
R as REGISTER,
|
|
376
|
+
L as RESEND_VERIFICATION,
|
|
377
|
+
N as RESET_PASSWORD,
|
|
378
|
+
s as SEARCH_KNOWLEDGE_BASE,
|
|
379
|
+
T as UPDATE_COMMENT,
|
|
380
|
+
P as UPDATE_MY_PROFILE,
|
|
366
381
|
M as UPDATE_MY_REPORT_SETTINGS,
|
|
367
|
-
|
|
382
|
+
y as VERIFY_EMAIL
|
|
368
383
|
};
|
package/dist/core/types.d.ts
CHANGED
|
@@ -51,6 +51,25 @@ export interface ArticleWithTranslation {
|
|
|
51
51
|
contentImagesGeo?: ContentImageGeo[] | null;
|
|
52
52
|
accessRights: string[];
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* A single immutable article version's content, addressed by its STABLE version
|
|
56
|
+
* id. Returned by `client.articles.getVersion`. Generic preview / A/B exposure —
|
|
57
|
+
* the server bypasses publish status, so the fetch requires either an internal
|
|
58
|
+
* token or a valid `previewKey` for this exact versionId. Versions are
|
|
59
|
+
* per-language; `languageCode` is the version's own translation language.
|
|
60
|
+
*/
|
|
61
|
+
export interface ArticleVersionContent {
|
|
62
|
+
versionId: string;
|
|
63
|
+
articleId: string;
|
|
64
|
+
filename: string;
|
|
65
|
+
versionNumber: number;
|
|
66
|
+
title: string;
|
|
67
|
+
content: string;
|
|
68
|
+
languageCode: string;
|
|
69
|
+
/** SCHEMA_VERSION the snapshot was authored under (lets consumers detect staleness). */
|
|
70
|
+
schemaVersion: string | null;
|
|
71
|
+
createdAt: string;
|
|
72
|
+
}
|
|
54
73
|
export interface Tag {
|
|
55
74
|
id: string;
|
|
56
75
|
slug: string;
|
|
@@ -1,22 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
let
|
|
3
|
-
function
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
1
|
+
import f from "../../../node_modules/dompurify/dist/purify.es.js";
|
|
2
|
+
let i;
|
|
3
|
+
function u() {
|
|
4
|
+
if (i)
|
|
5
|
+
return i;
|
|
6
6
|
if (typeof window < "u" && typeof window.document < "u")
|
|
7
|
-
|
|
7
|
+
i = f;
|
|
8
8
|
else {
|
|
9
9
|
const { JSDOM: t } = require("jsdom");
|
|
10
|
-
|
|
10
|
+
i = f(new t("").window);
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return a(i), m(i), i;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
t.addHook("afterSanitizeAttributes", (
|
|
16
|
-
|
|
14
|
+
function a(t) {
|
|
15
|
+
t.addHook("afterSanitizeAttributes", (e) => {
|
|
16
|
+
e.tagName === "A" && e.getAttribute("target") === "_blank" && e.setAttribute("rel", "noopener noreferrer");
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const c = /* @__PURE__ */ new Set([
|
|
20
|
+
"width",
|
|
21
|
+
"height",
|
|
22
|
+
"min-width",
|
|
23
|
+
"min-height",
|
|
24
|
+
"max-width",
|
|
25
|
+
"max-height",
|
|
26
|
+
"aspect-ratio",
|
|
27
|
+
"object-fit"
|
|
28
|
+
]);
|
|
29
|
+
function A(t) {
|
|
30
|
+
return t.length > 0 && t.length <= 40 && /^[a-z0-9.%/\s-]+$/i.test(t) && !/url|expression|\\/i.test(t);
|
|
31
|
+
}
|
|
32
|
+
function S(t) {
|
|
33
|
+
const e = [];
|
|
34
|
+
for (const r of t.split(";")) {
|
|
35
|
+
const n = r.indexOf(":");
|
|
36
|
+
if (n < 0)
|
|
37
|
+
continue;
|
|
38
|
+
const o = r.slice(0, n).trim().toLowerCase(), s = r.slice(n + 1).trim();
|
|
39
|
+
c.has(o) && A(s) && e.push(`${o}:${s}`);
|
|
40
|
+
}
|
|
41
|
+
return e.join(";");
|
|
42
|
+
}
|
|
43
|
+
function m(t) {
|
|
44
|
+
t.addHook("afterSanitizeAttributes", (e) => {
|
|
45
|
+
if (!e.hasAttribute("style"))
|
|
46
|
+
return;
|
|
47
|
+
const r = S(e.getAttribute("style") || "");
|
|
48
|
+
r ? e.setAttribute("style", r) : e.removeAttribute("style");
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const l = {
|
|
20
52
|
USE_PROFILES: { html: !0 },
|
|
21
53
|
ADD_ATTR: ["target", "rel"],
|
|
22
54
|
FORBID_TAGS: ["style", "form", "input", "iframe"],
|
|
@@ -24,18 +56,23 @@ const n = {
|
|
|
24
56
|
SANITIZE_NAMED_PROPS: !0,
|
|
25
57
|
ALLOW_DATA_ATTR: !1
|
|
26
58
|
};
|
|
27
|
-
function
|
|
28
|
-
return
|
|
59
|
+
function p(t, e = l) {
|
|
60
|
+
return u().sanitize(t, e);
|
|
29
61
|
}
|
|
30
62
|
({
|
|
31
63
|
// Derive from STRICT_CONFIG so its security posture — and any FUTURE hardening (a new
|
|
32
64
|
// FORBID_TAGS/FORBID_ATTR entry) — propagates to this higher-risk host boundary automatically.
|
|
33
65
|
// ADD_ATTR is overridden outright (it restates STRICT_CONFIG's target/rel + adds the two
|
|
34
|
-
// structural attrs the overlay anchors on)
|
|
35
|
-
|
|
66
|
+
// structural attrs the overlay anchors on). FORBID_ATTR is overridden to DROP `style` from
|
|
67
|
+
// the forbid list (keeping only `formaction`): DOMPurify then lets `style` through, and the
|
|
68
|
+
// shared `installStyleAllowlistHook` narrows it to the SIZING-only allowlist — so a customer
|
|
69
|
+
// renderer's intrinsic sizing (icon width/height) survives, while nothing that can overlay or
|
|
70
|
+
// reflow the contained host does, and customer JS still cannot run. STRICT_CONFIG (blog
|
|
71
|
+
// content) keeps `style` forbidden, so this exception is scoped to the embed host only.
|
|
72
|
+
...l
|
|
36
73
|
});
|
|
37
74
|
export {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
75
|
+
l as STRICT_CONFIG,
|
|
76
|
+
u as getPurifier,
|
|
77
|
+
p as sanitizeHtml
|
|
41
78
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blogmcp/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Headless SDK for Knowledge Base blog — core client, Vue composables, Nuxt adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@blogmcp/mdx-schema": "^0.1.
|
|
65
|
-
"@blogmcp/sanitize": "^0.1.
|
|
64
|
+
"@blogmcp/mdx-schema": "^0.1.3",
|
|
65
|
+
"@blogmcp/sanitize": "^0.1.3",
|
|
66
66
|
"marked": "^15.0.7"
|
|
67
67
|
},
|
|
68
68
|
"optionalDependencies": {
|
package/src/core/client.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { KbClientConfig, Fetcher, TokenStorage } from './client-types'
|
|
|
10
10
|
import type {
|
|
11
11
|
Article,
|
|
12
12
|
ArticleWithTranslation,
|
|
13
|
+
ArticleVersionContent,
|
|
13
14
|
Tag,
|
|
14
15
|
LocalizedTag,
|
|
15
16
|
Language,
|
|
@@ -110,6 +111,19 @@ export interface KbClient {
|
|
|
110
111
|
resolveAlias(
|
|
111
112
|
filename: string,
|
|
112
113
|
): Promise<{ articleAliasTarget: string | null }>
|
|
114
|
+
/**
|
|
115
|
+
* Fetch ONE article version's content by its STABLE version id, for headless
|
|
116
|
+
* preview / A/B (test-before-publish, multi-variant serving). Bypasses publish
|
|
117
|
+
* status, so the server returns it only to an INTERNAL caller (server client
|
|
118
|
+
* holding the api token) OR a caller passing a valid `previewKey` minted for
|
|
119
|
+
* this exact versionId. Returns `{ articleVersion: null }` when missing or
|
|
120
|
+
* unauthorized. Versions are per-language; the returned `languageCode` is the
|
|
121
|
+
* version's own translation — no language argument is taken.
|
|
122
|
+
*/
|
|
123
|
+
getVersion(
|
|
124
|
+
versionId: string,
|
|
125
|
+
opts?: { previewKey?: string },
|
|
126
|
+
): Promise<{ articleVersion: ArticleVersionContent | null }>
|
|
113
127
|
}
|
|
114
128
|
search: {
|
|
115
129
|
query(params: {
|
|
@@ -240,6 +254,8 @@ export function createKbClient(config: KbClientConfig): KbClient {
|
|
|
240
254
|
exec(Q.ARTICLE_WITH_TRANSLATION_BY_ID, { id, languageCode }),
|
|
241
255
|
resolveAlias: (filename) =>
|
|
242
256
|
exec(Q.ARTICLE_ALIAS_TARGET, { filename }),
|
|
257
|
+
getVersion: (versionId, opts) =>
|
|
258
|
+
exec(Q.ARTICLE_VERSION, { versionId, previewKey: opts?.previewKey ?? null }),
|
|
243
259
|
},
|
|
244
260
|
search: {
|
|
245
261
|
query: (params) => exec(Q.SEARCH_KNOWLEDGE_BASE, params),
|
package/src/core/index.ts
CHANGED
package/src/core/queries.ts
CHANGED
|
@@ -82,6 +82,25 @@ export const ARTICLE_ALIAS_TARGET = `
|
|
|
82
82
|
}
|
|
83
83
|
`
|
|
84
84
|
|
|
85
|
+
// Fetch ONE article version's content by its stable version id, for headless
|
|
86
|
+
// preview / A/B. Bypasses publish status, so the server serves it only to an
|
|
87
|
+
// internal caller OR a caller presenting a valid `previewKey` for this versionId.
|
|
88
|
+
export const ARTICLE_VERSION = `
|
|
89
|
+
query ArticleVersion($versionId: ID!, $previewKey: String) {
|
|
90
|
+
articleVersion(versionId: $versionId, previewKey: $previewKey) {
|
|
91
|
+
versionId
|
|
92
|
+
articleId
|
|
93
|
+
filename
|
|
94
|
+
versionNumber
|
|
95
|
+
title
|
|
96
|
+
content
|
|
97
|
+
languageCode
|
|
98
|
+
schemaVersion
|
|
99
|
+
createdAt
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
`
|
|
103
|
+
|
|
85
104
|
// ==================== Search ====================
|
|
86
105
|
|
|
87
106
|
export const SEARCH_KNOWLEDGE_BASE = `
|
package/src/core/types.ts
CHANGED
|
@@ -57,6 +57,26 @@ export interface ArticleWithTranslation {
|
|
|
57
57
|
accessRights: string[]
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* A single immutable article version's content, addressed by its STABLE version
|
|
62
|
+
* id. Returned by `client.articles.getVersion`. Generic preview / A/B exposure —
|
|
63
|
+
* the server bypasses publish status, so the fetch requires either an internal
|
|
64
|
+
* token or a valid `previewKey` for this exact versionId. Versions are
|
|
65
|
+
* per-language; `languageCode` is the version's own translation language.
|
|
66
|
+
*/
|
|
67
|
+
export interface ArticleVersionContent {
|
|
68
|
+
versionId: string
|
|
69
|
+
articleId: string
|
|
70
|
+
filename: string
|
|
71
|
+
versionNumber: number
|
|
72
|
+
title: string
|
|
73
|
+
content: string
|
|
74
|
+
languageCode: string
|
|
75
|
+
/** SCHEMA_VERSION the snapshot was authored under (lets consumers detect staleness). */
|
|
76
|
+
schemaVersion: string | null
|
|
77
|
+
createdAt: string
|
|
78
|
+
}
|
|
79
|
+
|
|
60
80
|
// ==================== Tag Types ====================
|
|
61
81
|
|
|
62
82
|
export interface Tag {
|