@literary-universe/sdk 0.2.0 → 0.3.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.
@@ -1,24 +1,41 @@
1
1
  import { type LiteraryUniverseClient } from './index.js';
2
2
  import type { JsonValue } from './json.js';
3
+ type Pending = {
4
+ operationId: string;
5
+ expectedVersion: string;
6
+ /** Digest of the form sent: `content`, or the Markdown body. */
7
+ hash: string;
8
+ content?: JsonValue;
9
+ markdown?: string;
10
+ };
3
11
  type ChapterFile = {
4
12
  id: string;
5
13
  language: string;
6
14
  file: string;
7
15
  version: string;
8
16
  hash: string;
9
- pending?: {
10
- operationId: string;
11
- expectedVersion: string;
17
+ /** The Markdown mirror; absent in projects pulled before it existed. */
18
+ markdown?: {
19
+ file: string;
12
20
  hash: string;
13
- content: JsonValue;
14
21
  };
22
+ pending?: Pending;
15
23
  };
16
24
  export type LocalProject = {
17
25
  version: 1;
18
26
  baseUrl: string;
19
27
  storyId: string;
28
+ /** The language filter the project was pulled with. */
29
+ language?: string;
20
30
  chapters: ChapterFile[];
21
31
  };
32
+ export type ChangeSource = 'none' | 'json' | 'markdown' | 'both';
33
+ /**
34
+ * What the server's Markdown has no form for, so a `markdown` save is refused
35
+ * with MARKDOWN_UNSUPPORTED: node and mark types, plus the paragraph/heading
36
+ * attributes `textAlign` (other than left) and `initialLetter`.
37
+ */
38
+ export declare const MARKDOWN_LOSSY_TYPES: readonly string[];
22
39
  /** Loads only the fixed managed-project layout, never arbitrary manifest paths. */
23
40
  export declare function readLocalProject(directory: string): LocalProject;
24
41
  export declare function localProjectStatus(directory: string): {
@@ -27,6 +44,7 @@ export declare function localProjectStatus(directory: string): {
27
44
  file: string;
28
45
  version: string;
29
46
  changed: boolean;
47
+ source: ChangeSource;
30
48
  pending: boolean;
31
49
  }[];
32
50
  /** Pulls into a new directory, preserving existing local files. */
@@ -35,7 +53,22 @@ export declare function pullLocalProject(client: LiteraryUniverseClient, input:
35
53
  baseUrl: string;
36
54
  storyId: string;
37
55
  language?: string;
38
- }): Promise<LocalProject>;
56
+ /** Re-pull an existing project instead; see refreshLocalProject. */
57
+ refresh?: boolean;
58
+ }): Promise<LocalProject | {
59
+ added: string[];
60
+ updated: string[];
61
+ removed: string[];
62
+ }>;
63
+ /** Re-pulls every chapter of an existing project; refuses while anything local is unpushed. */
64
+ export declare function refreshLocalProject(client: LiteraryUniverseClient, input: {
65
+ directory: string;
66
+ baseUrl: string;
67
+ }): Promise<{
68
+ added: string[];
69
+ updated: string[];
70
+ removed: string[];
71
+ }>;
39
72
  /** Saves each changed draft once; pending intents survive a lost response or stopped process. */
40
73
  export declare function pushLocalProject(client: LiteraryUniverseClient, input: {
41
74
  directory: string;
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
- import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
2
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
3
3
  import { hostname } from 'node:os';
4
4
  import { join, resolve } from 'node:path';
5
5
  import { LiteraryUniverseApiError, } from './index.js';
@@ -8,6 +8,64 @@ const failure = (code, message) => {
8
8
  };
9
9
  const digest = (content) => createHash('sha256').update(JSON.stringify(content)).digest('hex');
10
10
  const filename = (id, language) => `chapters/chapter-${id}.${language}.json`;
11
+ /**
12
+ * What the server's Markdown has no form for, so a `markdown` save is refused
13
+ * with MARKDOWN_UNSUPPORTED: node and mark types, plus the paragraph/heading
14
+ * attributes `textAlign` (other than left) and `initialLetter`.
15
+ */
16
+ export const MARKDOWN_LOSSY_TYPES = [
17
+ 'ruby',
18
+ 'connection',
19
+ 'textStyle',
20
+ 'emoji',
21
+ 'video',
22
+ 'workCard',
23
+ 'textAlign',
24
+ 'initialLetter',
25
+ 'playSceneHeading',
26
+ 'playCharacter',
27
+ 'playParenthetical',
28
+ 'playDialogue',
29
+ 'playLyric',
30
+ 'playTransition',
31
+ 'playSynopsis',
32
+ 'playNote',
33
+ 'playBoneyard',
34
+ 'playDialogueBlock',
35
+ 'playDualDialogue',
36
+ ];
37
+ /** Lossy types found in a Tiptap document, in document order. */
38
+ function lossyTypes(node, found = new Set()) {
39
+ if (!node || typeof node !== 'object')
40
+ return found;
41
+ const { type, attrs } = node;
42
+ if (typeof type === 'string' && MARKDOWN_LOSSY_TYPES.includes(type))
43
+ found.add(type);
44
+ const block = type === 'paragraph' || type === 'heading';
45
+ if (block && attrs?.textAlign != null && attrs.textAlign !== 'left')
46
+ found.add('textAlign');
47
+ if (block && attrs?.initialLetter)
48
+ found.add('initialLetter');
49
+ for (const value of Object.values(node))
50
+ lossyTypes(value, found);
51
+ return found;
52
+ }
53
+ const FRONTMATTER = /^---\n(?:[^\n]*\n)*?---\n/;
54
+ const MARKDOWN_NOTICE = /^# (?:This chapter has no Markdown form yet;[^\n]*|Edit chapters\/[^\n]* instead: this chapter contains [^\n]*)\n/;
55
+ /** Why the Markdown file must not be edited, or undefined when it may be. */
56
+ function markdownNotice(draft) {
57
+ if (draft.content == null || draft.markdown == null)
58
+ return '# This chapter has no Markdown form yet; open it once in the web editor to convert it, then run lu refresh';
59
+ const lossy = [...lossyTypes(draft.content)];
60
+ if (lossy.length)
61
+ return `# Edit ${filename(draft.id, draft.language)} instead: this chapter contains ${lossy.join(', ')}`;
62
+ }
63
+ function frontmatter(draft) {
64
+ const notice = markdownNotice(draft);
65
+ const fields = ['id', 'title', 'language', 'version'].map((key) => `${key}: ${JSON.stringify(draft[key])}`);
66
+ const header = ['---', ...fields, `editable: ${!notice}`, '---', ''];
67
+ return `${header.join('\n')}${notice ? `${notice}\n` : ''}\n`;
68
+ }
11
69
  const rootFor = (directory) => realpathSync(resolve(directory));
12
70
  function pathFor(root, file) {
13
71
  if (!/^(\.lu|chapters)\/[a-zA-Z0-9._-]+(?:\/[a-zA-Z0-9._-]+)?$/.test(file) ||
@@ -22,13 +80,10 @@ function pathFor(root, file) {
22
80
  }
23
81
  return path;
24
82
  }
25
- function writeJson(root, file, value) {
83
+ function writeText(root, file, text) {
26
84
  const path = pathFor(root, file);
27
85
  const temporary = `${path}.${randomUUID()}.tmp`;
28
- writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, {
29
- mode: 0o600,
30
- flag: 'wx',
31
- });
86
+ writeFileSync(temporary, text, { mode: 0o600, flag: 'wx' });
32
87
  try {
33
88
  renameSync(temporary, path);
34
89
  }
@@ -36,17 +91,28 @@ function writeJson(root, file, value) {
36
91
  rmSync(temporary, { force: true });
37
92
  }
38
93
  }
39
- function readJson(root, file) {
94
+ const writeJson = (root, file, value) => writeText(root, file, `${JSON.stringify(value, null, 2)}\n`);
95
+ const writeMarkdown = (root, file, draft) => writeText(root, file, frontmatter(draft) + (draft.markdown ?? ''));
96
+ function readText(root, file) {
40
97
  const path = pathFor(root, file);
41
98
  if (statSync(path).size > 16 * 1024 * 1024)
42
99
  failure('PAYLOAD_TOO_LARGE', 'Project file exceeds the size limit');
100
+ return readFileSync(path, 'utf8').replace(/^\uFEFF/, '');
101
+ }
102
+ function readJson(root, file) {
43
103
  try {
44
- return JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/, ''));
104
+ return JSON.parse(readText(root, file));
45
105
  }
46
106
  catch {
47
107
  return failure('INVALID_PROJECT', 'Project file contains invalid JSON');
48
108
  }
49
109
  }
110
+ /** The Markdown body: the file without its frontmatter, with LF line ends. */
111
+ const readBody = (root, file) => readText(root, file)
112
+ .replaceAll('\r\n', '\n')
113
+ .replace(FRONTMATTER, '')
114
+ .replace(MARKDOWN_NOTICE, '')
115
+ .replace(/^\n/, '');
50
116
  function clearDeadLock(root) {
51
117
  const existing = readJson(root, '.lu/lock');
52
118
  if (existing.host !== hostname() ||
@@ -81,15 +147,27 @@ export function readLocalProject(directory) {
81
147
  if (project?.version !== 1 ||
82
148
  typeof project.baseUrl !== 'string' ||
83
149
  !/^[a-zA-Z0-9_-]{1,100}$/.test(project.storyId) ||
150
+ (project.language !== undefined &&
151
+ !/^[a-zA-Z0-9-]{1,32}$/.test(project.language)) ||
84
152
  !Array.isArray(project.chapters))
85
153
  failure('INVALID_PROJECT', 'Invalid project manifest');
86
154
  const files = new Set();
87
155
  for (const chapter of project.chapters) {
88
156
  validateChapter(chapter, files);
89
157
  files.add(chapter.file.toLowerCase());
158
+ if (chapter.markdown)
159
+ validateMarkdown(chapter.markdown, files);
90
160
  }
91
161
  return project;
92
162
  }
163
+ function validateMarkdown(markdown, files) {
164
+ if (typeof markdown.file !== 'string' ||
165
+ !/^chapters\/[a-zA-Z0-9._-]+\.md$/.test(markdown.file) ||
166
+ typeof markdown.hash !== 'string' ||
167
+ files.has(markdown.file.toLowerCase()))
168
+ failure('INVALID_PROJECT', 'Invalid chapter manifest');
169
+ files.add(markdown.file.toLowerCase());
170
+ }
93
171
  function validateChapter(chapter, files) {
94
172
  if (!chapter ||
95
173
  typeof chapter.id !== 'string' ||
@@ -102,16 +180,29 @@ function validateChapter(chapter, files) {
102
180
  files.has(chapter.file.toLowerCase()))
103
181
  failure('INVALID_PROJECT', 'Invalid chapter manifest');
104
182
  }
183
+ /** Which local file differs from the manifest; `both` cannot be pushed. */
184
+ function inspect(root, chapter) {
185
+ const content = readJson(root, chapter.file);
186
+ const body = chapter.markdown ? readBody(root, chapter.markdown.file) : '';
187
+ const json = digest(content) !== chapter.hash;
188
+ const markdown = chapter.markdown !== undefined && digest(body) !== chapter.markdown.hash;
189
+ const source = json && markdown ? 'both' : json ? 'json' : markdown ? 'markdown' : 'none';
190
+ return { content, body, source };
191
+ }
105
192
  export function localProjectStatus(directory) {
106
193
  const root = rootFor(directory);
107
- return readLocalProject(root).chapters.map((chapter) => ({
108
- id: chapter.id,
109
- language: chapter.language,
110
- file: chapter.file,
111
- version: chapter.version,
112
- changed: digest(readJson(root, chapter.file)) !== chapter.hash,
113
- pending: Boolean(chapter.pending),
114
- }));
194
+ return readLocalProject(root).chapters.map((chapter) => {
195
+ const { source } = inspect(root, chapter);
196
+ return {
197
+ id: chapter.id,
198
+ language: chapter.language,
199
+ file: chapter.file,
200
+ version: chapter.version,
201
+ changed: source !== 'none',
202
+ source,
203
+ pending: Boolean(chapter.pending),
204
+ };
205
+ });
115
206
  }
116
207
  function initializeProject(directory) {
117
208
  mkdirSync(directory, { recursive: true });
@@ -134,6 +225,8 @@ async function pullPage(client, root, project, input, after) {
134
225
  language: input.language,
135
226
  });
136
227
  storePulledDraft(root, project, draft);
228
+ // A refresh stopped midway keeps a manifest that matches the files written so far.
229
+ writeJson(root, '.lu/project.json', project);
137
230
  }
138
231
  return page.pageInfo;
139
232
  }
@@ -141,10 +234,27 @@ function assertDistinctFile(project, file) {
141
234
  if (project.chapters.some((chapter) => chapter.file.toLowerCase() === file.toLowerCase()))
142
235
  failure('INVALID_PROJECT', 'Chapter filenames differ only by case; use individual draft files');
143
236
  }
237
+ /** `chapters/<seq>-<slug>.<lang>.md`, numbered on a collision. */
238
+ function markdownName(project, draft) {
239
+ const slug = draft.title
240
+ .toLowerCase()
241
+ .replace(/[^a-z0-9]+/g, '-')
242
+ .slice(0, 60)
243
+ .replace(/^-+|-+$/g, '') || 'chapter';
244
+ const base = `chapters/${String(draft.sequence).padStart(3, '0')}-${slug}`;
245
+ const taken = new Set(project.chapters.map((chapter) => chapter.markdown?.file.toLowerCase()));
246
+ for (let n = 1;; n++) {
247
+ const file = `${base}${n > 1 ? `-${n}` : ''}.${draft.language}.md`;
248
+ if (!taken.has(file.toLowerCase()))
249
+ return file;
250
+ }
251
+ }
144
252
  function storePulledDraft(root, project, draft) {
145
253
  const file = filename(draft.id, draft.language);
146
254
  assertDistinctFile(project, file);
255
+ const markdown = markdownName(project, draft);
147
256
  writeJson(root, file, draft.content);
257
+ writeMarkdown(root, markdown, draft);
148
258
  writeJson(root, `.lu/${file.split('/')[1]}`, draft);
149
259
  project.chapters.push({
150
260
  id: draft.id,
@@ -152,6 +262,7 @@ function storePulledDraft(root, project, draft) {
152
262
  file,
153
263
  version: draft.version,
154
264
  hash: digest(draft.content),
265
+ markdown: { file: markdown, hash: digest(draft.markdown ?? '') },
155
266
  });
156
267
  }
157
268
  async function pullPages(client, root, project, language) {
@@ -171,6 +282,8 @@ async function pullPages(client, root, project, language) {
171
282
  }
172
283
  /** Pulls into a new directory, preserving existing local files. */
173
284
  export async function pullLocalProject(client, input) {
285
+ if (input.refresh)
286
+ return refreshLocalProject(client, input);
174
287
  const root = initializeProject(input.directory);
175
288
  const release = lock(root);
176
289
  try {
@@ -178,6 +291,7 @@ export async function pullLocalProject(client, input) {
178
291
  version: 1,
179
292
  baseUrl: input.baseUrl,
180
293
  storyId: input.storyId,
294
+ ...(input.language ? { language: input.language } : {}),
181
295
  chapters: [],
182
296
  };
183
297
  await pullPages(client, root, project, input.language);
@@ -194,6 +308,84 @@ export async function pullLocalProject(client, input) {
194
308
  release();
195
309
  }
196
310
  }
311
+ /** Deletes the files of chapters the server no longer has and reports the difference. */
312
+ function reconcile(root, previous, project) {
313
+ const current = new Set(project.chapters.map((chapter) => chapter.file));
314
+ const kept = new Set(project.chapters.flatMap((chapter) => [
315
+ chapter.file,
316
+ chapter.markdown?.file,
317
+ ]));
318
+ for (const chapter of previous) {
319
+ for (const file of [chapter.file, chapter.markdown?.file])
320
+ if (file && !kept.has(file))
321
+ rmSync(pathFor(root, file), { force: true });
322
+ if (!current.has(chapter.file))
323
+ rmSync(pathFor(root, `.lu/${chapter.file.split('/')[1]}`), {
324
+ force: true,
325
+ });
326
+ }
327
+ return difference(previous, project.chapters);
328
+ }
329
+ const sameState = (before, after) => before.version === after.version &&
330
+ before.hash === after.hash &&
331
+ before.markdown?.hash === after.markdown?.hash;
332
+ function difference(previous, chapters) {
333
+ const was = new Map(previous.map((chapter) => [chapter.file, chapter]));
334
+ const current = new Set(chapters.map((chapter) => chapter.file));
335
+ const ids = (list) => [...new Set(list.map((c) => c.id))];
336
+ return {
337
+ added: ids(chapters.filter((chapter) => !was.has(chapter.file))),
338
+ updated: ids(chapters.filter((chapter) => {
339
+ const before = was.get(chapter.file);
340
+ return before && !sameState(before, chapter);
341
+ })),
342
+ removed: ids(previous.filter((chapter) => !current.has(chapter.file))),
343
+ };
344
+ }
345
+ /** Re-pulls every chapter of an existing project; refuses while anything local is unpushed. */
346
+ export async function refreshLocalProject(client, input) {
347
+ const root = rootFor(input.directory);
348
+ const release = lock(root);
349
+ try {
350
+ const project = openProject(root, input.baseUrl);
351
+ if (project.chapters.some((chapter) => chapter.pending || inspect(root, chapter).source !== 'none'))
352
+ failure('LOCAL_CHANGES', 'Push or revert local changes before refreshing');
353
+ const previous = project.chapters;
354
+ const staging = mkdtempSync(join(root, '.lu-refresh-'));
355
+ try {
356
+ initializeProject(staging);
357
+ project.chapters = [];
358
+ await pullPages(client, staging, project, project.language);
359
+ // Editors do not share our lock. Check again after the network reads.
360
+ if (previous.some((chapter) => inspect(root, chapter).source !== 'none'))
361
+ failure('LOCAL_CHANGES', 'Local changes appeared while refreshing');
362
+ const managed = new Set(previous.flatMap((chapter) => [
363
+ chapter.file,
364
+ chapter.markdown?.file,
365
+ `.lu/${chapter.file.split('/')[1]}`,
366
+ ]));
367
+ const files = project.chapters.flatMap((chapter) => [
368
+ chapter.file,
369
+ ...(chapter.markdown ? [chapter.markdown.file] : []),
370
+ `.lu/${chapter.file.split('/')[1]}`,
371
+ ]);
372
+ for (const file of files) {
373
+ if (existsSync(pathFor(root, file)) && !managed.has(file))
374
+ failure('LOCAL_CHANGES', 'Refresh would overwrite an unmanaged file');
375
+ }
376
+ for (const file of files)
377
+ writeText(root, file, readText(staging, file));
378
+ writeJson(root, '.lu/project.json', project);
379
+ return reconcile(root, previous, project);
380
+ }
381
+ finally {
382
+ rmSync(staging, { recursive: true, force: true });
383
+ }
384
+ }
385
+ finally {
386
+ release();
387
+ }
388
+ }
197
389
  /** Saves each changed draft once; pending intents survive a lost response or stopped process. */
198
390
  export async function pushLocalProject(client, input) {
199
391
  const root = rootFor(input.directory);
@@ -205,9 +397,18 @@ export async function pushLocalProject(client, input) {
205
397
  release();
206
398
  }
207
399
  }
400
+ /** Rewrites both files from the server's draft unless they changed again meanwhile. */
208
401
  function savedLocally(root, project, chapter, result) {
209
- if (digest(readJson(root, chapter.file)) === chapter.pending?.hash)
402
+ const { pending, markdown } = chapter;
403
+ const sentMarkdown = pending?.markdown !== undefined;
404
+ const jsonBefore = sentMarkdown ? chapter.hash : pending?.hash;
405
+ if (digest(readJson(root, chapter.file)) === jsonBefore)
210
406
  writeJson(root, chapter.file, result.draft.content);
407
+ const file = markdown?.file ?? markdownName(project, result.draft);
408
+ const bodyBefore = sentMarkdown ? pending?.hash : markdown?.hash;
409
+ if (!markdown || digest(readBody(root, file)) === bodyBefore)
410
+ writeMarkdown(root, file, result.draft);
411
+ chapter.markdown = { file, hash: digest(result.draft.markdown ?? '') };
211
412
  chapter.hash = digest(result.draft.content);
212
413
  chapter.version = result.version;
213
414
  delete chapter.pending;
@@ -259,33 +460,59 @@ const saveInput = ({ chapter, pending }) => ({
259
460
  language: chapter.language,
260
461
  expectedVersion: pending.expectedVersion,
261
462
  operationId: pending.operationId,
262
- content: pending.content,
463
+ ...(pending.markdown === undefined
464
+ ? { content: pending.content }
465
+ : { markdown: pending.markdown }),
263
466
  });
467
+ /** The intent to send: an earlier pending one, else the changed file's; or why nothing can be sent. */
264
468
  function snapshot(root, chapter) {
265
- const content = chapter.pending?.content ?? readJson(root, chapter.file);
266
- const pending = chapter.pending ?? {
267
- operationId: randomUUID(),
469
+ if (chapter.pending)
470
+ return { chapter, pending: chapter.pending };
471
+ const { content, body, source } = inspect(root, chapter);
472
+ if (source === 'none')
473
+ return source;
474
+ if (source === 'both')
475
+ return 'AMBIGUOUS_CHANGE';
476
+ // The stored server draft shows a missing Markdown form, which the JSON file alone cannot.
477
+ const stored = readJson(root, `.lu/${chapter.file.split('/')[1]}`);
478
+ if (source === 'markdown' && markdownNotice(stored))
479
+ return 'MARKDOWN_UNSUPPORTED';
480
+ const sent = source === 'markdown' ? { markdown: body } : { content };
481
+ const hash = digest(source === 'markdown' ? body : content);
482
+ const operationId = randomUUID();
483
+ const pending = {
484
+ operationId,
268
485
  expectedVersion: chapter.version,
269
- hash: digest(content),
270
- content,
486
+ hash,
487
+ ...sent,
271
488
  };
272
489
  return { chapter, pending };
273
490
  }
274
- async function preflight(client, root, baseUrl) {
491
+ function openProject(root, baseUrl) {
275
492
  const project = readLocalProject(root);
276
493
  if (new URL(project.baseUrl).href !== new URL(baseUrl).href)
277
494
  failure('DEPLOYMENT_MISMATCH', 'The selected deployment does not match this project');
278
- const changes = project.chapters
279
- .map((chapter) => snapshot(root, chapter))
280
- .filter(({ chapter, pending }) => chapter.pending || pending.hash !== chapter.hash);
495
+ return project;
496
+ }
497
+ async function preflight(client, root, baseUrl) {
498
+ const project = openProject(root, baseUrl);
499
+ const changes = [];
500
+ const unsendable = [];
501
+ for (const chapter of project.chapters) {
502
+ const change = snapshot(root, chapter);
503
+ if (typeof change === 'object')
504
+ changes.push(change);
505
+ else if (change !== 'none')
506
+ unsendable.push({ id: chapter.id, status: 'failed', code: change });
507
+ }
281
508
  for (const change of changes.filter(({ chapter }) => !chapter.pending))
282
509
  await client.validateDraft(saveInput(change));
283
- return { project, changes };
510
+ return { project, changes, unsendable };
284
511
  }
285
512
  async function pushLocked(client, root, baseUrl) {
286
- const { project, changes } = await preflight(client, root, baseUrl);
513
+ const { project, changes, unsendable } = await preflight(client, root, baseUrl);
287
514
  // Chapters are independent: a failure keeps its pending intent and the rest still push.
288
- const results = [];
515
+ const results = [...unsendable];
289
516
  for (const change of changes)
290
517
  results.push(await pushChapter(client, root, project, change));
291
518
  return results;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@literary-universe/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Literary Universe authoring API client for Node and Bun",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=24"
7
+ "node": ">=26"
8
8
  },
9
9
  "main": "./dist/cjs/index.js",
10
10
  "types": "./dist/cjs/index.d.ts",
@@ -38,6 +38,16 @@
38
38
  "types": "./dist/cjs/images.d.ts",
39
39
  "default": "./dist/cjs/images.js"
40
40
  }
41
+ },
42
+ "./mcp": {
43
+ "import": {
44
+ "types": "./dist/esm/mcp.d.ts",
45
+ "default": "./dist/esm/mcp.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/cjs/mcp.d.ts",
49
+ "default": "./dist/cjs/mcp.js"
50
+ }
41
51
  }
42
52
  },
43
53
  "files": [
@@ -58,21 +68,31 @@
58
68
  },
59
69
  "devDependencies": {
60
70
  "@graphql-codegen/typescript-operations": "6.2.0",
61
- "@types/node": "24.19.2",
71
+ "@modelcontextprotocol/sdk": "1.32.2",
72
+ "@types/node": "26.6.6",
62
73
  "graphql": "16.14.2",
63
74
  "sharp": "0.35.5",
64
- "typescript": "5.9.3"
75
+ "typescript": "5.9.3",
76
+ "zod": "4.6.7"
65
77
  },
66
78
  "overrides": {
67
79
  "@graphql-tools/utils": "12.1.0"
68
80
  },
69
81
  "license": "MIT",
70
82
  "peerDependencies": {
71
- "sharp": "0.35.5"
83
+ "sharp": "0.35.5",
84
+ "@modelcontextprotocol/sdk": "^1.32",
85
+ "zod": "^4"
72
86
  },
73
87
  "peerDependenciesMeta": {
74
88
  "sharp": {
75
89
  "optional": true
90
+ },
91
+ "@modelcontextprotocol/sdk": {
92
+ "optional": true
93
+ },
94
+ "zod": {
95
+ "optional": true
76
96
  }
77
97
  },
78
98
  "repository": {
package/schema.graphql CHANGED
@@ -79,6 +79,8 @@ type Query {
79
79
 
80
80
  """The saved series of a universe."""
81
81
  authorSeries(universeId: ID!): [AuthorSeries!]!
82
+ authorBlogPages(blogId: ID!, first: Int = 25, after: ID): [AuthorBlogDocument!]!
83
+ authorBlogMenus(blogId: ID!): [AuthorBlogDocument!]!
82
84
  }
83
85
 
84
86
  enum AuthorWorkState {
@@ -269,6 +271,7 @@ type Mutation {
269
271
  credential cannot use, and FAILED_PRECONDITION for a rating under review.
270
272
  """
271
273
  updateAuthorStory(storyId: ID!, input: AuthorStoryUpdateInput!): AuthorStoryHeader!
274
+ mutateAuthorBlog(input: AuthorBlogMutationInput!): AuthorBlogDocument!
272
275
  }
273
276
 
274
277
  type AuthorChapterHeader {
@@ -311,7 +314,14 @@ input AuthorDraftSaveInput {
311
314
  language: Locale
312
315
  expectedVersion: String!
313
316
  operationId: ID!
314
- content: JSON!
317
+
318
+ """Tiptap JSON. Provide exactly one of content and markdown."""
319
+ content: JSON
320
+
321
+ """
322
+ Markdown converted on the server with the editor's own Markdown extension. Provide exactly one of content and markdown. Rejected with MARKDOWN_UNSUPPORTED if the stored draft has nodes, marks or attributes Markdown cannot preserve; use content instead.
323
+ """
324
+ markdown: String
315
325
  }
316
326
 
317
327
  type AuthorContentWarning {
@@ -337,6 +347,7 @@ input AuthorChapterCreateInput {
337
347
  operationId: ID!
338
348
  title: String
339
349
  content: JSON
350
+ markdown: String
340
351
  isAIGenerated: Boolean
341
352
  }
342
353
 
@@ -600,6 +611,30 @@ input AuthorStoryUpdateInput {
600
611
  universeId: ID
601
612
  }
602
613
 
614
+ """
615
+ Private stored page/menu data including translations, plus an opaque concurrency token.
616
+ """
617
+ type AuthorBlogDocument {
618
+ id: ID!
619
+ version: String!
620
+ data: JSON!
621
+ }
622
+
623
+ input AuthorBlogMutationInput {
624
+ blogId: ID!
625
+ operationId: String!
626
+ expectedVersion: String
627
+ action: String!
628
+ pageId: ID
629
+ location: String
630
+ language: Locale
631
+ page: JSON
632
+ published: Boolean
633
+ items: [JSON!]
634
+ settings: JSON
635
+ entries: JSON
636
+ }
637
+
603
638
  scalar Date
604
639
 
605
640
  scalar DateTime