@blogmcp/sdk 0.3.2 → 0.6.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/dist/core/client-types.d.ts +7 -1
- package/dist/core/client.d.ts +25 -1
- package/dist/core/client.js +38 -34
- package/dist/core/consultation-adapter.d.ts +90 -0
- package/dist/core/consultation-adapter.js +200 -0
- package/dist/core/consultations.d.ts +108 -0
- package/dist/core/consultations.js +95 -0
- package/dist/core/errors.d.ts +52 -0
- package/dist/core/errors.js +73 -0
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.js +80 -64
- package/dist/core/queries.d.ts +16 -1
- package/dist/core/queries.js +198 -61
- package/dist/core/review/format.d.ts +30 -0
- package/dist/core/review/format.js +78 -0
- package/dist/core/review/index.d.ts +6 -0
- package/dist/core/review/index.js +9 -0
- package/dist/core/review/types.d.ts +176 -0
- package/dist/core/review/types.js +9 -0
- package/dist/core/server-only.d.ts +12 -0
- package/dist/core/server-only.js +11 -0
- package/dist/core/types.d.ts +295 -0
- package/dist/packages/mdx-render-vue/dist/composables/useGallery.js +12 -11
- package/dist/packages/mdx-render-vue/dist/composables/useTripMap.js +16 -16
- package/dist/packages/mdx-render-vue/dist/edit/TripMapEdit.vue.js +1 -1
- package/dist/packages/mdx-render-vue/dist/registry.js +21 -22
- package/dist/packages/mdx-render-vue/dist/render/alert/Alert.vue2.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/badge/Badge.vue2.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/button/Button.vue2.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/callout/CalloutDefault.vue.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/callout/CalloutMinimal.vue.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/tripmap/TripMapDefault.vue.js +2 -2
- package/dist/packages/tripmap-core/dist/attribution.js +121 -6
- package/dist/packages/tripmap-core/dist/css.js +68 -16
- package/dist/packages/tripmap-core/dist/detail.js +10 -9
- package/dist/packages/tripmap-core/dist/engine.js +285 -247
- package/dist/packages/tripmap-core/dist/export.js +48 -46
- package/dist/packages/tripmap-core/dist/filmstrip.js +30 -17
- package/dist/packages/tripmap-core/dist/framing.js +30 -30
- package/dist/packages/tripmap-core/dist/generated/maplibre-worker.bundle.js +1 -1
- package/dist/packages/tripmap-core/dist/heading.js +8 -0
- package/dist/packages/tripmap-core/dist/href.js +18 -0
- package/dist/packages/tripmap-core/dist/index.js +32 -24
- package/dist/packages/tripmap-core/dist/lightbox.js +31 -29
- package/dist/packages/tripmap-core/dist/line.js +6 -6
- package/dist/packages/tripmap-core/dist/markers.js +47 -43
- package/dist/packages/tripmap-core/dist/nodes.js +56 -43
- package/dist/packages/tripmap-core/dist/playback.js +17 -17
- package/dist/packages/tripmap-core/dist/preload.js +14 -14
- package/dist/packages/tripmap-core/dist/theme.js +21 -21
- package/dist/{node_modules → packages/tripmap-core/node_modules}/maplibre-gl/dist/maplibre-gl.js +1890 -1720
- package/dist/{node_modules → packages/tripmap-core/node_modules}/pmtiles/dist/esm/index.js +1 -1
- package/dist/react/KbMdxContent.js +7 -8
- package/dist/vue/components/KbMdxContent.vue2.js +6 -7
- package/package.json +8 -3
- package/src/core/client-types.ts +13 -2
- package/src/core/client.ts +40 -5
- package/src/core/consultation-adapter.ts +408 -0
- package/src/core/consultations.ts +224 -0
- package/src/core/errors.ts +145 -0
- package/src/core/index.ts +68 -0
- package/src/core/queries.ts +167 -3
- package/src/core/review/format.ts +138 -0
- package/src/core/review/index.ts +22 -0
- package/src/core/review/types.ts +168 -0
- package/src/core/server-only.ts +20 -0
- package/src/core/types.ts +337 -0
- package/dist/_virtual/constants.js +0 -4
- package/dist/_virtual/index.js +0 -2
- package/dist/_virtual/index2.js +0 -4
- package/dist/_virtual/index3.js +0 -2
- package/dist/_virtual/re.js +0 -4
- package/dist/node_modules/@braintree/sanitize-url/dist/constants.js +0 -8
- package/dist/node_modules/@braintree/sanitize-url/dist/index.js +0 -60
- package/dist/node_modules/dompurify/dist/purify.es.js +0 -662
- package/dist/node_modules/semver/classes/comparator.js +0 -56
- package/dist/node_modules/semver/classes/range.js +0 -148
- package/dist/node_modules/semver/classes/semver.js +0 -169
- package/dist/node_modules/semver/functions/clean.js +0 -14
- package/dist/node_modules/semver/functions/cmp.js +0 -39
- package/dist/node_modules/semver/functions/coerce.js +0 -33
- package/dist/node_modules/semver/functions/compare-build.js +0 -14
- package/dist/node_modules/semver/functions/compare-loose.js +0 -11
- package/dist/node_modules/semver/functions/compare.js +0 -11
- package/dist/node_modules/semver/functions/diff.js +0 -24
- package/dist/node_modules/semver/functions/eq.js +0 -11
- package/dist/node_modules/semver/functions/gt.js +0 -11
- package/dist/node_modules/semver/functions/gte.js +0 -11
- package/dist/node_modules/semver/functions/inc.js +0 -21
- package/dist/node_modules/semver/functions/lt.js +0 -11
- package/dist/node_modules/semver/functions/lte.js +0 -11
- package/dist/node_modules/semver/functions/major.js +0 -11
- package/dist/node_modules/semver/functions/minor.js +0 -11
- package/dist/node_modules/semver/functions/neq.js +0 -11
- package/dist/node_modules/semver/functions/parse.js +0 -21
- package/dist/node_modules/semver/functions/patch.js +0 -11
- package/dist/node_modules/semver/functions/prerelease.js +0 -14
- package/dist/node_modules/semver/functions/rcompare.js +0 -11
- package/dist/node_modules/semver/functions/rsort.js +0 -11
- package/dist/node_modules/semver/functions/satisfies.js +0 -18
- package/dist/node_modules/semver/functions/sort.js +0 -11
- package/dist/node_modules/semver/functions/valid.js +0 -14
- package/dist/node_modules/semver/index.js +0 -97
- package/dist/node_modules/semver/internal/constants.js +0 -28
- package/dist/node_modules/semver/internal/debug.js +0 -8
- package/dist/node_modules/semver/internal/identifiers.js +0 -18
- package/dist/node_modules/semver/internal/lrucache.js +0 -32
- package/dist/node_modules/semver/internal/parse-options.js +0 -10
- package/dist/node_modules/semver/internal/re.js +0 -32
- package/dist/node_modules/semver/ranges/gtr.js +0 -11
- package/dist/node_modules/semver/ranges/intersects.js +0 -11
- package/dist/node_modules/semver/ranges/ltr.js +0 -11
- package/dist/node_modules/semver/ranges/max-satisfying.js +0 -22
- package/dist/node_modules/semver/ranges/min-satisfying.js +0 -22
- package/dist/node_modules/semver/ranges/min-version.js +0 -42
- package/dist/node_modules/semver/ranges/outside.js +0 -44
- package/dist/node_modules/semver/ranges/simplify.js +0 -24
- package/dist/node_modules/semver/ranges/subset.js +0 -94
- package/dist/node_modules/semver/ranges/to-comparators.js +0 -11
- package/dist/node_modules/semver/ranges/valid.js +0 -17
- package/dist/packages/mdx-schema/dist/composables/useMdxParsing.js +0 -389
- package/dist/packages/mdx-schema/dist/metadata/index.js +0 -526
- package/dist/packages/mdx-schema/dist/prepareProps.js +0 -46
- package/dist/packages/mdx-schema/dist/styles/index.js +0 -141
- package/dist/packages/mdx-schema/dist/tripmap.js +0 -88
- package/dist/packages/mdx-schema/dist/types/index.js +0 -26
- package/dist/packages/sanitize/dist/html.js +0 -89
- /package/dist/{node_modules → packages/tripmap-core/node_modules}/maplibre-gl/dist/maplibre-gl-shared.js +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reader consultations — the reader side of the KB GraphQL API
|
|
3
|
+
* (docs/internal/reader-consultations.md §8.1 and §8.6).
|
|
4
|
+
*
|
|
5
|
+
* Two namespaces on `KbClient`:
|
|
6
|
+
*
|
|
7
|
+
* consultations a reader with an identity in the client's token
|
|
8
|
+
* storage: a delegated storefront token (see
|
|
9
|
+
* `createDelegatedTokenMinter`; server-side only) or a
|
|
10
|
+
* signed-in KB reader account's own token (fine in a
|
|
11
|
+
* browser, so this namespace has no browser guard).
|
|
12
|
+
* The team is never a reader. `publicConfig` needs none.
|
|
13
|
+
* consultationSession an anonymous asker who opened a magic link. The link
|
|
14
|
+
* token and the session string are bearer capabilities,
|
|
15
|
+
* so every method is SERVER-ONLY: it rejects in a
|
|
16
|
+
* browser before any request is made. Keep the session
|
|
17
|
+
* in an HttpOnly cookie (`__Host-`) and call these from
|
|
18
|
+
* the storefront's server. `attach` additionally needs
|
|
19
|
+
* the reader's identity (a delegated token).
|
|
20
|
+
*
|
|
21
|
+
* Queries throw `KbGraphQLError` (e.g. code NOT_FOUND, INVALID_LINK,
|
|
22
|
+
* UNAUTHENTICATED). Mutations resolve to their `{success, code, error, ...}`
|
|
23
|
+
* result and do not throw on domain errors; they throw only when the request
|
|
24
|
+
* itself fails (network, a GraphQL validation error).
|
|
25
|
+
*
|
|
26
|
+
* The storefront forwards the reader's IP for the KB's quotas with the client's
|
|
27
|
+
* `headers` option (`X-Blogmcp-Client-Ip`), on a client built per request.
|
|
28
|
+
* The KB honours that header ONLY from a credentialed caller: the delegated
|
|
29
|
+
* token for `consultations` and `attach`, and for the other session calls the
|
|
30
|
+
* storefront's public-level "reader proxy" service key in the token storage
|
|
31
|
+
* (reader-consultations.md §3.2). From an anonymous client the header is
|
|
32
|
+
* ignored, and every reader lands in the per-IP quota bucket of the
|
|
33
|
+
* storefront's one egress IP (link exchange, link requests, session posts).
|
|
34
|
+
* Nothing here logs: bodies, sessions, tokens and addresses stay in memory.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { KbGraphQLError } from './errors'
|
|
38
|
+
import * as Q from './queries'
|
|
39
|
+
import { assertServerOnly } from './server-only'
|
|
40
|
+
import type {
|
|
41
|
+
ConsultationConsentWithdrawalResult,
|
|
42
|
+
ConsultationMessageInput,
|
|
43
|
+
ConsultationPublicConfig,
|
|
44
|
+
ConsultationSessionResult,
|
|
45
|
+
CreateMyConsultationInput,
|
|
46
|
+
ReaderConsultation,
|
|
47
|
+
ReaderConsultationConsent,
|
|
48
|
+
ReaderConsultationResult,
|
|
49
|
+
ReaderConsultationSummary,
|
|
50
|
+
} from './types'
|
|
51
|
+
|
|
52
|
+
/** Executes one GraphQL document (the client's `executeGraphQL`). */
|
|
53
|
+
export type GraphQLExec = <T>(query: string, variables?: Record<string, unknown>) => Promise<T>
|
|
54
|
+
|
|
55
|
+
export interface KbConsultationsApi {
|
|
56
|
+
/** Enabled channels with their legal mode and current text, in `locale` (falls back to `en`). Public. */
|
|
57
|
+
publicConfig(locale: string): Promise<ConsultationPublicConfig>
|
|
58
|
+
/** The reader's own consultations, newest activity first (`limit` 1..100, default 20). */
|
|
59
|
+
mine(params?: { limit?: number; offset?: number }): Promise<ReaderConsultationSummary[]>
|
|
60
|
+
/** One of the reader's consultations. Throws KbGraphQLError NOT_FOUND for any id that is not theirs. */
|
|
61
|
+
get(id: string): Promise<ReaderConsultation>
|
|
62
|
+
/**
|
|
63
|
+
* Open a consultation on the `web` channel (CHANNEL_NOT_ALLOWED unless the
|
|
64
|
+
* tenant enabled it). Send `consent` only when `consent(locale).needsConsent`
|
|
65
|
+
* says so; a CONSENT_REQUIRED answer means it became needed meanwhile (the
|
|
66
|
+
* reader withdrew it elsewhere, or the tenant asked everyone again).
|
|
67
|
+
*/
|
|
68
|
+
create(input: CreateMyConsultationInput): Promise<ReaderConsultationResult>
|
|
69
|
+
/** Write in one of the reader's consultations; reopens an answered or closed one. */
|
|
70
|
+
post(consultationId: string, message: ConsultationMessageInput): Promise<ReaderConsultationResult>
|
|
71
|
+
/**
|
|
72
|
+
* Close the consultation now; it is deleted after the tenant's grace period.
|
|
73
|
+
* The reader's consent stays — withdrawing it is `withdrawConsent()`.
|
|
74
|
+
*/
|
|
75
|
+
requestErasure(consultationId: string): Promise<ReaderConsultationResult>
|
|
76
|
+
/**
|
|
77
|
+
* The reader's own consent, and whether their next question must carry one
|
|
78
|
+
* (then with the consent text in `locale`, falling back to `en`). Takes no
|
|
79
|
+
* id: always the caller's own. Works while the module is off.
|
|
80
|
+
*/
|
|
81
|
+
consent(locale: string): Promise<ReaderConsultationConsent>
|
|
82
|
+
/**
|
|
83
|
+
* Withdraw the reader's consent: it ends, and every question of theirs that
|
|
84
|
+
* relied on it closes now and is deleted after the grace period (unless the
|
|
85
|
+
* law requires keeping it); questions asked through a notice-mode channel
|
|
86
|
+
* stay. The next question asks for consent again. Resolves
|
|
87
|
+
* `{success: false, code: 'NOTHING_TO_DO'}` when there is no active consent.
|
|
88
|
+
* Works while the module is off.
|
|
89
|
+
*/
|
|
90
|
+
withdrawConsent(): Promise<ConsultationConsentWithdrawalResult>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* SERVER-ONLY: every method rejects when a global `window` exists. Call it on
|
|
95
|
+
* a client whose token storage holds the reader-proxy service key (so the
|
|
96
|
+
* forwarded reader IP counts), or the reader's delegated token for `attach`.
|
|
97
|
+
*/
|
|
98
|
+
export interface KbConsultationSessionApi {
|
|
99
|
+
/** Exchange a magic-link token (from the URL fragment) for a session. Unusable tokens give INVALID_LINK. */
|
|
100
|
+
exchange(token: string): Promise<ConsultationSessionResult>
|
|
101
|
+
/** The consultation a session opens. Throws KbGraphQLError INVALID_LINK when the session is not usable. */
|
|
102
|
+
get(session: string): Promise<ReaderConsultation>
|
|
103
|
+
/** Write in the consultation a session opens. */
|
|
104
|
+
post(session: string, message: ConsultationMessageInput): Promise<ReaderConsultationResult>
|
|
105
|
+
/** Close the consultation now; it is deleted after the tenant's grace period. */
|
|
106
|
+
requestErasure(session: string): Promise<ReaderConsultationResult>
|
|
107
|
+
/** End the session (drop the cookie too). */
|
|
108
|
+
close(session: string): Promise<ReaderConsultationResult>
|
|
109
|
+
/**
|
|
110
|
+
* Move the consultation to the reader's account. Needs BOTH the session and
|
|
111
|
+
* a reader identity (a delegated token in this client) whose verified
|
|
112
|
+
* address matches the thread's; otherwise ATTACH_EMAIL_MISMATCH.
|
|
113
|
+
*/
|
|
114
|
+
attach(session: string): Promise<ReaderConsultationResult>
|
|
115
|
+
/**
|
|
116
|
+
* Ask for fresh links to the answered consultations of an address. Always
|
|
117
|
+
* resolves true, whether or not the address ever wrote in.
|
|
118
|
+
*/
|
|
119
|
+
requestLink(email: string): Promise<boolean>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The field of a GraphQL response; a missing one is a malformed response, not a silent undefined. */
|
|
123
|
+
async function field<T>(pending: Promise<unknown>, name: string): Promise<T> {
|
|
124
|
+
const data = (await pending) as Record<string, unknown> | null | undefined
|
|
125
|
+
const value = data?.[name]
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
throw new KbGraphQLError([{ message: `Malformed GraphQL response: data.${name} is missing` }])
|
|
128
|
+
}
|
|
129
|
+
return value as T
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function createConsultationsApi(exec: GraphQLExec): KbConsultationsApi {
|
|
133
|
+
return {
|
|
134
|
+
publicConfig: (locale) =>
|
|
135
|
+
field(exec(Q.CONSULTATION_PUBLIC_CONFIG, { locale }), 'consultationPublicConfig'),
|
|
136
|
+
mine: (params) =>
|
|
137
|
+
field(
|
|
138
|
+
exec(Q.MY_CONSULTATIONS, { limit: params?.limit, offset: params?.offset }),
|
|
139
|
+
'myConsultations',
|
|
140
|
+
),
|
|
141
|
+
get: (id) => field(exec(Q.MY_CONSULTATION, { id }), 'myConsultation'),
|
|
142
|
+
create: (input) =>
|
|
143
|
+
field(
|
|
144
|
+
exec(Q.CREATE_MY_CONSULTATION, {
|
|
145
|
+
// Only the fields of CreateMyConsultationInput: an unknown key would
|
|
146
|
+
// fail GraphQL input coercion for the whole request.
|
|
147
|
+
input: {
|
|
148
|
+
body: input.body,
|
|
149
|
+
languageCode: input.languageCode,
|
|
150
|
+
consent: input.consent
|
|
151
|
+
? { version: input.consent.version, locale: input.consent.locale }
|
|
152
|
+
: undefined,
|
|
153
|
+
notice: input.notice
|
|
154
|
+
? { version: input.notice.version, locale: input.notice.locale }
|
|
155
|
+
: undefined,
|
|
156
|
+
clientRequestId: input.clientRequestId,
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
'createMyConsultation',
|
|
160
|
+
),
|
|
161
|
+
post: (consultationId, message) =>
|
|
162
|
+
field(
|
|
163
|
+
exec(Q.POST_MY_CONSULTATION_MESSAGE, {
|
|
164
|
+
consultationId,
|
|
165
|
+
body: message.body,
|
|
166
|
+
clientRequestId: message.clientRequestId,
|
|
167
|
+
}),
|
|
168
|
+
'postMyConsultationMessage',
|
|
169
|
+
),
|
|
170
|
+
requestErasure: (consultationId) =>
|
|
171
|
+
field(exec(Q.REQUEST_MY_CONSULTATION_ERASURE, { consultationId }), 'requestMyConsultationErasure'),
|
|
172
|
+
consent: (locale) => field(exec(Q.MY_CONSULTATION_CONSENT, { locale }), 'myConsultationConsent'),
|
|
173
|
+
withdrawConsent: () => field(exec(Q.WITHDRAW_MY_CONSULTATION_CONSENT, {}), 'withdrawMyConsultationConsent'),
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const SESSION_SECRET = 'a consultation session or link token must never reach page JavaScript.'
|
|
178
|
+
|
|
179
|
+
export function createConsultationSessionApi(exec: GraphQLExec): KbConsultationSessionApi {
|
|
180
|
+
/** Rejects in a browser BEFORE the argument is serialised or sent anywhere. */
|
|
181
|
+
const guarded =
|
|
182
|
+
<A extends unknown[], R>(method: string, run: (...args: A) => Promise<R>) =>
|
|
183
|
+
async (...args: A): Promise<R> => {
|
|
184
|
+
assertServerOnly(`consultationSession.${method}`, SESSION_SECRET)
|
|
185
|
+
return run(...args)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
exchange: guarded('exchange', (token: string) =>
|
|
190
|
+
field<ConsultationSessionResult>(exec(Q.EXCHANGE_CONSULTATION_LINK, { token }), 'exchangeConsultationLink'),
|
|
191
|
+
),
|
|
192
|
+
get: guarded('get', (session: string) =>
|
|
193
|
+
field<ReaderConsultation>(exec(Q.CONSULTATION_BY_SESSION, { session }), 'consultationBySession'),
|
|
194
|
+
),
|
|
195
|
+
post: guarded('post', (session: string, message: ConsultationMessageInput) =>
|
|
196
|
+
field<ReaderConsultationResult>(
|
|
197
|
+
exec(Q.POST_CONSULTATION_MESSAGE_BY_SESSION, {
|
|
198
|
+
session,
|
|
199
|
+
body: message.body,
|
|
200
|
+
clientRequestId: message.clientRequestId,
|
|
201
|
+
}),
|
|
202
|
+
'postConsultationMessageBySession',
|
|
203
|
+
),
|
|
204
|
+
),
|
|
205
|
+
requestErasure: guarded('requestErasure', (session: string) =>
|
|
206
|
+
field<ReaderConsultationResult>(
|
|
207
|
+
exec(Q.REQUEST_CONSULTATION_ERASURE_BY_SESSION, { session }),
|
|
208
|
+
'requestConsultationErasureBySession',
|
|
209
|
+
),
|
|
210
|
+
),
|
|
211
|
+
close: guarded('close', (session: string) =>
|
|
212
|
+
field<ReaderConsultationResult>(exec(Q.CLOSE_CONSULTATION_SESSION, { session }), 'closeConsultationSession'),
|
|
213
|
+
),
|
|
214
|
+
attach: guarded('attach', (session: string) =>
|
|
215
|
+
field<ReaderConsultationResult>(
|
|
216
|
+
exec(Q.ATTACH_CONSULTATION_TO_MY_ACCOUNT, { session }),
|
|
217
|
+
'attachConsultationToMyAccount',
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
requestLink: guarded('requestLink', (email: string) =>
|
|
221
|
+
field<boolean>(exec(Q.REQUEST_CONSULTATION_LINK, { email }), 'requestConsultationLink'),
|
|
222
|
+
),
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors raised by the KB SDK.
|
|
3
|
+
*
|
|
4
|
+
* `KbGraphQLError` is thrown for every GraphQL error the KB API returns. It is
|
|
5
|
+
* an `Error` subclass that keeps the server's message, so code written against
|
|
6
|
+
* SDK 0.3 (`catch (e) { e.message }`) keeps working; new code reads the
|
|
7
|
+
* machine-readable `code` from `errors[0].extensions.code` instead of parsing
|
|
8
|
+
* the message.
|
|
9
|
+
*
|
|
10
|
+
* `CONSULTATION_ERROR_CODES` mirrors the KB API's single list of reader
|
|
11
|
+
* consultation codes (apps/knowledge-base/api/src/services/consultations/
|
|
12
|
+
* consultation-errors.ts, docs/internal/reader-consultations.md §11). A drift
|
|
13
|
+
* test compares the two lists.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Every reader-consultation error code of the KB API, in its declaration order. */
|
|
17
|
+
export const CONSULTATION_ERROR_CODES = [
|
|
18
|
+
'UNAUTHENTICATED',
|
|
19
|
+
'FORBIDDEN',
|
|
20
|
+
'NOT_FOUND',
|
|
21
|
+
'FEATURE_DISABLED',
|
|
22
|
+
'INVALID_INPUT',
|
|
23
|
+
'BODY_TOO_LONG',
|
|
24
|
+
'NOTICE_REQUIRED',
|
|
25
|
+
'NOTICE_VERSION_UNKNOWN',
|
|
26
|
+
'CONSENT_REQUIRED',
|
|
27
|
+
'CONSENT_VERSION_UNKNOWN',
|
|
28
|
+
'CHANNEL_NOT_ALLOWED',
|
|
29
|
+
'THREAD_REQUIRED',
|
|
30
|
+
'SENDER_MISMATCH',
|
|
31
|
+
'QUOTA_EXCEEDED',
|
|
32
|
+
'INVALID_LINK',
|
|
33
|
+
'THREAD_CLOSED',
|
|
34
|
+
'ATTACH_EMAIL_MISMATCH',
|
|
35
|
+
'STALE_THREAD',
|
|
36
|
+
'STALE_LEASE',
|
|
37
|
+
'NOTHING_TO_DO',
|
|
38
|
+
'IDEMPOTENCY_CONFLICT',
|
|
39
|
+
'LEGAL_HOLD',
|
|
40
|
+
'CONTENT_ACCESS_REQUIRED',
|
|
41
|
+
'READER_URL_MISSING',
|
|
42
|
+
'READER_PATH_MISSING',
|
|
43
|
+
'TEXT_MISSING',
|
|
44
|
+
'OPERATOR_MISSING',
|
|
45
|
+
'TEXT_VERSION_EXISTS',
|
|
46
|
+
'CONTENT_ACCESS_ATTESTATION_REQUIRED',
|
|
47
|
+
'AI_DRAFTS_DISABLED',
|
|
48
|
+
'AI_LOCAL_UNAVAILABLE',
|
|
49
|
+
'PROCESSING_RESTRICTED',
|
|
50
|
+
'DRAFT_FLAGS_UNACKNOWLEDGED',
|
|
51
|
+
'REPLY_POLICY_MISSING',
|
|
52
|
+
'DRAFT_ID_REQUIRED',
|
|
53
|
+
'CARD_GUARD_FAILED',
|
|
54
|
+
'CARD_CONFIRMATION_REQUIRED',
|
|
55
|
+
'STALE_CARD',
|
|
56
|
+
'RETRY_LATER',
|
|
57
|
+
'INTERNAL_ERROR',
|
|
58
|
+
] as const
|
|
59
|
+
|
|
60
|
+
/** A reader-consultation error code (the `code` of a result or of a thrown error). */
|
|
61
|
+
export type ConsultationErrorCode = (typeof CONSULTATION_ERROR_CODES)[number]
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Any error code the SDK can surface: a consultation code, a code a GraphQL
|
|
65
|
+
* server attaches on its own (validation, parse, ...), or any other string a
|
|
66
|
+
* newer server may send. The `string & {}` arm keeps editor autocompletion for
|
|
67
|
+
* the known codes while accepting unknown ones.
|
|
68
|
+
*/
|
|
69
|
+
export type KbErrorCode =
|
|
70
|
+
| ConsultationErrorCode
|
|
71
|
+
| 'GRAPHQL_VALIDATION_FAILED'
|
|
72
|
+
| 'GRAPHQL_PARSE_FAILED'
|
|
73
|
+
| 'BAD_USER_INPUT'
|
|
74
|
+
| 'INTERNAL_SERVER_ERROR'
|
|
75
|
+
| (string & {})
|
|
76
|
+
|
|
77
|
+
const CONSULTATION_CODE_SET: ReadonlySet<string> = new Set(CONSULTATION_ERROR_CODES)
|
|
78
|
+
|
|
79
|
+
/** True for a code from the consultation list (narrows unknown codes away). */
|
|
80
|
+
export function isConsultationErrorCode(code: unknown): code is ConsultationErrorCode {
|
|
81
|
+
return typeof code === 'string' && CONSULTATION_CODE_SET.has(code)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** One GraphQL error as the server sent it (the shape of `response.errors[n]`). */
|
|
85
|
+
export interface RawGraphQLError {
|
|
86
|
+
message: string
|
|
87
|
+
path?: ReadonlyArray<string | number>
|
|
88
|
+
extensions?: Record<string, unknown>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** One GraphQL error, normalised. */
|
|
92
|
+
export interface KbGraphQLErrorEntry {
|
|
93
|
+
message: string
|
|
94
|
+
/** `extensions.code`, or null when the server attached none. */
|
|
95
|
+
code: KbErrorCode | null
|
|
96
|
+
path: ReadonlyArray<string | number> | null
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const MAX_CODE_LENGTH = 128
|
|
100
|
+
|
|
101
|
+
function entryOf(raw: unknown): KbGraphQLErrorEntry {
|
|
102
|
+
const e = (raw ?? {}) as Partial<RawGraphQLError>
|
|
103
|
+
const code = e.extensions?.code
|
|
104
|
+
return {
|
|
105
|
+
message: typeof e.message === 'string' && e.message !== '' ? e.message : 'GraphQL error',
|
|
106
|
+
code: typeof code === 'string' && code !== '' && code.length <= MAX_CODE_LENGTH ? code : null,
|
|
107
|
+
path: Array.isArray(e.path) ? [...e.path] : null,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Brand shared by every copy of the SDK loaded in one process (a bundler can
|
|
113
|
+
* load the src and the dist build side by side), so `isKbGraphQLError` works
|
|
114
|
+
* where `instanceof` would not.
|
|
115
|
+
*/
|
|
116
|
+
const KB_GRAPHQL_ERROR_BRAND = Symbol.for('@blogmcp/sdk/KbGraphQLError')
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A GraphQL error returned by the KB API. `message` and `code` come from the
|
|
120
|
+
* FIRST error; `errors` holds all of them.
|
|
121
|
+
*/
|
|
122
|
+
export class KbGraphQLError extends Error {
|
|
123
|
+
/** `errors[0].extensions.code`, or null when absent. */
|
|
124
|
+
readonly code: KbErrorCode | null
|
|
125
|
+
readonly errors: readonly KbGraphQLErrorEntry[]
|
|
126
|
+
|
|
127
|
+
constructor(errors: ReadonlyArray<RawGraphQLError | unknown>) {
|
|
128
|
+
const entries = (errors.length > 0 ? errors : [undefined]).map(entryOf)
|
|
129
|
+
super(entries[0].message)
|
|
130
|
+
this.name = 'KbGraphQLError'
|
|
131
|
+
this.code = entries[0].code
|
|
132
|
+
this.errors = entries
|
|
133
|
+
// Non-enumerable, so it stays out of serialised errors and of the .d.ts.
|
|
134
|
+
Object.defineProperty(this, KB_GRAPHQL_ERROR_BRAND, { value: true })
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** True for a KbGraphQLError, also one thrown by another copy of the SDK. */
|
|
139
|
+
export function isKbGraphQLError(err: unknown): err is KbGraphQLError {
|
|
140
|
+
if (err instanceof KbGraphQLError) return true
|
|
141
|
+
return (
|
|
142
|
+
err instanceof Error &&
|
|
143
|
+
(err as unknown as Record<symbol, unknown>)[KB_GRAPHQL_ERROR_BRAND] === true
|
|
144
|
+
)
|
|
145
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -26,9 +26,60 @@ export type {
|
|
|
26
26
|
FeedbackNotificationFrequency,
|
|
27
27
|
UpdateReportSettingsInput,
|
|
28
28
|
PaginatedResponse,
|
|
29
|
+
// Reader consultations (GraphQL reader surface)
|
|
30
|
+
ReaderConsultationStatus,
|
|
31
|
+
ReaderConsultationAuthor,
|
|
32
|
+
ReaderConsultationMessage,
|
|
33
|
+
ReaderConsultation,
|
|
34
|
+
ReaderConsultationSummary,
|
|
35
|
+
ReaderConsultationResult,
|
|
36
|
+
ConsultationSessionResult,
|
|
37
|
+
ConsultationLegalMode,
|
|
38
|
+
ConsultationLegalText,
|
|
39
|
+
ConsultationChannelConfig,
|
|
40
|
+
ConsultationPublicConfig,
|
|
41
|
+
ConsultationLegalInput,
|
|
42
|
+
CreateMyConsultationInput,
|
|
43
|
+
ConsultationMessageInput,
|
|
44
|
+
ReaderConsultationConsent,
|
|
45
|
+
ConsultationConsentWithdrawalResult,
|
|
46
|
+
// Reader consultations (adapter REST contract)
|
|
47
|
+
ConsultationOwnerRef,
|
|
48
|
+
ConsultationConsentInput,
|
|
49
|
+
ConsultationNewThreadInput,
|
|
50
|
+
ConsultationIngestInput,
|
|
51
|
+
ConsultationIngestResult,
|
|
52
|
+
ConsultationDeliveryKind,
|
|
53
|
+
ConsultationLeaseInput,
|
|
54
|
+
ConsultationLeasedDelivery,
|
|
55
|
+
ConsultationLeaseResult,
|
|
56
|
+
ConsultationAckInput,
|
|
57
|
+
ConsultationFailInput,
|
|
58
|
+
ConsultationOkResult,
|
|
59
|
+
ConsultationOutboxStats,
|
|
60
|
+
ConsultationEraseInput,
|
|
61
|
+
ConsultationEraseResult,
|
|
62
|
+
ConsultationOwnerRefsInput,
|
|
63
|
+
ConsultationOwnerRefsResult,
|
|
64
|
+
ConsultationThreadOwner,
|
|
65
|
+
ConsultationThreadByNotice,
|
|
29
66
|
} from './types'
|
|
30
67
|
export { ACCESS_LEVEL_ORDER } from './types'
|
|
31
68
|
|
|
69
|
+
// Errors (GraphQL errors carry the server's `extensions.code`)
|
|
70
|
+
export {
|
|
71
|
+
KbGraphQLError,
|
|
72
|
+
isKbGraphQLError,
|
|
73
|
+
CONSULTATION_ERROR_CODES,
|
|
74
|
+
isConsultationErrorCode,
|
|
75
|
+
} from './errors'
|
|
76
|
+
export type {
|
|
77
|
+
KbErrorCode,
|
|
78
|
+
ConsultationErrorCode,
|
|
79
|
+
KbGraphQLErrorEntry,
|
|
80
|
+
RawGraphQLError,
|
|
81
|
+
} from './errors'
|
|
82
|
+
|
|
32
83
|
// Client types
|
|
33
84
|
export type {
|
|
34
85
|
KbClientConfig,
|
|
@@ -77,6 +128,20 @@ export type {
|
|
|
77
128
|
DelegatedIdentity,
|
|
78
129
|
} from './delegated-identity'
|
|
79
130
|
|
|
131
|
+
// Reader consultations: the KbClient namespaces' types, and the tenant
|
|
132
|
+
// adapter's REST client (server-only — it holds a scoped adapter key)
|
|
133
|
+
export type { KbConsultationsApi, KbConsultationSessionApi } from './consultations'
|
|
134
|
+
export {
|
|
135
|
+
createConsultationAdapterClient,
|
|
136
|
+
ConsultationAdapterError,
|
|
137
|
+
isConsultationAdapterError,
|
|
138
|
+
} from './consultation-adapter'
|
|
139
|
+
export type {
|
|
140
|
+
ConsultationAdapterClient,
|
|
141
|
+
ConsultationAdapterClientConfig,
|
|
142
|
+
ConsultationAdapterOperation,
|
|
143
|
+
} from './consultation-adapter'
|
|
144
|
+
|
|
80
145
|
// Content utilities
|
|
81
146
|
export { stripLeadingH1, generateDescription } from './article-seo'
|
|
82
147
|
export { createMarkedInstance, defaultImageHtml, parseMarkdownSafe } from './markdown'
|
|
@@ -158,3 +223,6 @@ export {
|
|
|
158
223
|
componentMetadata,
|
|
159
224
|
} from '@blogmcp/mdx-schema/metadata'
|
|
160
225
|
export type { ComponentMetadata, PropMetadata } from '@blogmcp/mdx-schema/metadata'
|
|
226
|
+
|
|
227
|
+
// Review links (review a draft on your own article page)
|
|
228
|
+
export * from './review'
|
package/src/core/queries.ts
CHANGED
|
@@ -191,11 +191,13 @@ export const KB_LANGUAGES = `
|
|
|
191
191
|
}
|
|
192
192
|
`
|
|
193
193
|
|
|
194
|
-
// ==================== Translations ====================
|
|
194
|
+
// ==================== Translations (internal tokens only) ====================
|
|
195
195
|
|
|
196
|
+
// Keyed by article id: the KB field has always taken `articleId` (SDK ≤ 0.3
|
|
197
|
+
// sent `sourceFilename`, which the API rejected on every call).
|
|
196
198
|
export const ARTICLE_TRANSLATIONS = `
|
|
197
|
-
query ArticleTranslations($
|
|
198
|
-
listArticleTranslations(
|
|
199
|
+
query ArticleTranslations($articleId: ID!) {
|
|
200
|
+
listArticleTranslations(articleId: $articleId) {
|
|
199
201
|
id
|
|
200
202
|
languageCode
|
|
201
203
|
title
|
|
@@ -449,3 +451,165 @@ export const UPDATE_MY_REPORT_SETTINGS = `
|
|
|
449
451
|
}
|
|
450
452
|
}
|
|
451
453
|
`
|
|
454
|
+
|
|
455
|
+
// ==================== Reader Consultations ====================
|
|
456
|
+
//
|
|
457
|
+
// docs/internal/reader-consultations.md §8.1. The `my*` fields need a reader
|
|
458
|
+
// identity (a delegated storefront token); the session fields take the
|
|
459
|
+
// session string itself as the bearer capability and belong on a server.
|
|
460
|
+
|
|
461
|
+
const READER_CONSULTATION_FIELDS = `
|
|
462
|
+
id
|
|
463
|
+
status
|
|
464
|
+
canReply
|
|
465
|
+
canAttachToAccount
|
|
466
|
+
createdAt
|
|
467
|
+
lastActivityAt
|
|
468
|
+
messages {
|
|
469
|
+
id
|
|
470
|
+
author
|
|
471
|
+
authorName
|
|
472
|
+
body
|
|
473
|
+
createdAt
|
|
474
|
+
}
|
|
475
|
+
`
|
|
476
|
+
|
|
477
|
+
const READER_CONSULTATION_RESULT_FIELDS = `
|
|
478
|
+
success
|
|
479
|
+
code
|
|
480
|
+
error
|
|
481
|
+
duplicate
|
|
482
|
+
consultation {${READER_CONSULTATION_FIELDS}}
|
|
483
|
+
`
|
|
484
|
+
|
|
485
|
+
export const CONSULTATION_PUBLIC_CONFIG = `
|
|
486
|
+
query ConsultationPublicConfig($locale: String!) {
|
|
487
|
+
consultationPublicConfig(locale: $locale) {
|
|
488
|
+
enabled
|
|
489
|
+
channels {
|
|
490
|
+
channel
|
|
491
|
+
mode
|
|
492
|
+
text {
|
|
493
|
+
purpose
|
|
494
|
+
version
|
|
495
|
+
locale
|
|
496
|
+
body
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
`
|
|
502
|
+
|
|
503
|
+
export const MY_CONSULTATIONS = `
|
|
504
|
+
query MyConsultations($limit: Int, $offset: Int) {
|
|
505
|
+
myConsultations(limit: $limit, offset: $offset) {
|
|
506
|
+
id
|
|
507
|
+
status
|
|
508
|
+
createdAt
|
|
509
|
+
lastActivityAt
|
|
510
|
+
messageCount
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
`
|
|
514
|
+
|
|
515
|
+
export const MY_CONSULTATION = `
|
|
516
|
+
query MyConsultation($id: ID!) {
|
|
517
|
+
myConsultation(id: $id) {${READER_CONSULTATION_FIELDS}}
|
|
518
|
+
}
|
|
519
|
+
`
|
|
520
|
+
|
|
521
|
+
export const CREATE_MY_CONSULTATION = `
|
|
522
|
+
mutation CreateMyConsultation($input: CreateMyConsultationInput!) {
|
|
523
|
+
createMyConsultation(input: $input) {${READER_CONSULTATION_RESULT_FIELDS}}
|
|
524
|
+
}
|
|
525
|
+
`
|
|
526
|
+
|
|
527
|
+
export const POST_MY_CONSULTATION_MESSAGE = `
|
|
528
|
+
mutation PostMyConsultationMessage($consultationId: ID!, $body: String!, $clientRequestId: String!) {
|
|
529
|
+
postMyConsultationMessage(consultationId: $consultationId, body: $body, clientRequestId: $clientRequestId) {${READER_CONSULTATION_RESULT_FIELDS}}
|
|
530
|
+
}
|
|
531
|
+
`
|
|
532
|
+
|
|
533
|
+
export const REQUEST_MY_CONSULTATION_ERASURE = `
|
|
534
|
+
mutation RequestMyConsultationErasure($consultationId: ID!) {
|
|
535
|
+
requestMyConsultationErasure(consultationId: $consultationId) {${READER_CONSULTATION_RESULT_FIELDS}}
|
|
536
|
+
}
|
|
537
|
+
`
|
|
538
|
+
|
|
539
|
+
export const MY_CONSULTATION_CONSENT = `
|
|
540
|
+
query MyConsultationConsent($locale: String!) {
|
|
541
|
+
myConsultationConsent(locale: $locale) {
|
|
542
|
+
mode
|
|
543
|
+
active
|
|
544
|
+
givenAt
|
|
545
|
+
version
|
|
546
|
+
needsConsent
|
|
547
|
+
text {
|
|
548
|
+
purpose
|
|
549
|
+
version
|
|
550
|
+
locale
|
|
551
|
+
body
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
`
|
|
556
|
+
|
|
557
|
+
export const WITHDRAW_MY_CONSULTATION_CONSENT = `
|
|
558
|
+
mutation WithdrawMyConsultationConsent {
|
|
559
|
+
withdrawMyConsultationConsent {
|
|
560
|
+
success
|
|
561
|
+
code
|
|
562
|
+
error
|
|
563
|
+
threadsClosed
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
`
|
|
567
|
+
|
|
568
|
+
export const EXCHANGE_CONSULTATION_LINK = `
|
|
569
|
+
mutation ExchangeConsultationLink($token: String!) {
|
|
570
|
+
exchangeConsultationLink(token: $token) {
|
|
571
|
+
success
|
|
572
|
+
code
|
|
573
|
+
error
|
|
574
|
+
session
|
|
575
|
+
expiresAt
|
|
576
|
+
consultation {${READER_CONSULTATION_FIELDS}}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
`
|
|
580
|
+
|
|
581
|
+
export const CONSULTATION_BY_SESSION = `
|
|
582
|
+
query ConsultationBySession($session: String!) {
|
|
583
|
+
consultationBySession(session: $session) {${READER_CONSULTATION_FIELDS}}
|
|
584
|
+
}
|
|
585
|
+
`
|
|
586
|
+
|
|
587
|
+
export const POST_CONSULTATION_MESSAGE_BY_SESSION = `
|
|
588
|
+
mutation PostConsultationMessageBySession($session: String!, $body: String!, $clientRequestId: String!) {
|
|
589
|
+
postConsultationMessageBySession(session: $session, body: $body, clientRequestId: $clientRequestId) {${READER_CONSULTATION_RESULT_FIELDS}}
|
|
590
|
+
}
|
|
591
|
+
`
|
|
592
|
+
|
|
593
|
+
export const REQUEST_CONSULTATION_ERASURE_BY_SESSION = `
|
|
594
|
+
mutation RequestConsultationErasureBySession($session: String!) {
|
|
595
|
+
requestConsultationErasureBySession(session: $session) {${READER_CONSULTATION_RESULT_FIELDS}}
|
|
596
|
+
}
|
|
597
|
+
`
|
|
598
|
+
|
|
599
|
+
export const CLOSE_CONSULTATION_SESSION = `
|
|
600
|
+
mutation CloseConsultationSession($session: String!) {
|
|
601
|
+
closeConsultationSession(session: $session) {${READER_CONSULTATION_RESULT_FIELDS}}
|
|
602
|
+
}
|
|
603
|
+
`
|
|
604
|
+
|
|
605
|
+
export const ATTACH_CONSULTATION_TO_MY_ACCOUNT = `
|
|
606
|
+
mutation AttachConsultationToMyAccount($session: String!) {
|
|
607
|
+
attachConsultationToMyAccount(session: $session) {${READER_CONSULTATION_RESULT_FIELDS}}
|
|
608
|
+
}
|
|
609
|
+
`
|
|
610
|
+
|
|
611
|
+
export const REQUEST_CONSULTATION_LINK = `
|
|
612
|
+
mutation RequestConsultationLink($email: String!) {
|
|
613
|
+
requestConsultationLink(email: $email)
|
|
614
|
+
}
|
|
615
|
+
`
|