inkwire-receiver-core 0.1.1 → 1.0.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/README.md +135 -16
- package/dist/auth.d.ts +18 -1
- package/dist/auth.js +31 -5
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +13 -2
- package/dist/files.d.ts +33 -0
- package/dist/files.js +210 -0
- package/dist/handle.d.ts +135 -10
- package/dist/handle.js +483 -46
- package/dist/index.d.ts +18 -5
- package/dist/index.js +11 -4
- package/dist/list.d.ts +19 -0
- package/dist/list.js +66 -0
- package/dist/lock.d.ts +6 -0
- package/dist/lock.js +17 -0
- package/dist/media-meta.d.ts +22 -0
- package/dist/media-meta.js +64 -0
- package/dist/media.d.ts +20 -0
- package/dist/media.js +125 -0
- package/dist/render.d.ts +18 -0
- package/dist/render.js +53 -4
- package/dist/schema.d.ts +239 -6
- package/dist/schema.js +89 -6
- package/dist/seo.d.ts +9 -0
- package/dist/seo.js +39 -0
- package/dist/store.d.ts +102 -32
- package/dist/store.js +1 -18
- package/dist/stores/file.d.ts +67 -0
- package/dist/stores/file.js +227 -0
- package/dist/stores/github.d.ts +94 -0
- package/dist/stores/github.js +334 -0
- package/dist/stores/memory.d.ts +27 -0
- package/dist/stores/memory.js +65 -0
- package/dist/testing.d.ts +49 -0
- package/dist/testing.js +223 -0
- package/package.json +47 -9
- package/dist/__tests__/handle.test.d.ts +0 -1
- package/dist/__tests__/handle.test.js +0 -56
- package/dist/__tests__/render.test.d.ts +0 -1
- package/dist/__tests__/render.test.js +0 -17
package/dist/lock.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const tails = new Map();
|
|
2
|
+
/**
|
|
3
|
+
* Runs `fn` after every earlier call with the same `key` has finished, so a read-check-write (an
|
|
4
|
+
* If-Match test, a slug check) cannot interleave with another write in this process. One process
|
|
5
|
+
* only: a store shared by several processes needs its own conditional write.
|
|
6
|
+
*/
|
|
7
|
+
export function withLock(key, fn) {
|
|
8
|
+
const prev = tails.get(key) ?? Promise.resolve();
|
|
9
|
+
const run = prev.then(fn, fn);
|
|
10
|
+
const tail = run.catch(() => undefined);
|
|
11
|
+
tails.set(key, tail);
|
|
12
|
+
tail.then(() => {
|
|
13
|
+
if (tails.get(key) === tail)
|
|
14
|
+
tails.delete(key);
|
|
15
|
+
});
|
|
16
|
+
return run;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StoredMedia } from "./store.js";
|
|
2
|
+
/** The sidecar next to a stored image: `<hex>-<filename>.meta.json`. File-backed stores share it. */
|
|
3
|
+
export interface MediaMeta {
|
|
4
|
+
alt?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
content_type: string;
|
|
7
|
+
created_at: string;
|
|
8
|
+
}
|
|
9
|
+
/** A media id is 16 hex characters; the file is `<id>-<filename>`. Anything else never touches a path. */
|
|
10
|
+
export declare const MEDIA_ID_RE: RegExp;
|
|
11
|
+
export declare const MEDIA_FILE_RE: RegExp;
|
|
12
|
+
export declare const META_SUFFIX = ".meta.json";
|
|
13
|
+
export declare function mimeForName(name: string): string;
|
|
14
|
+
export declare function serializeMeta(m: MediaMeta): string;
|
|
15
|
+
/** Reads a sidecar; a missing or unreadable one falls back to what the file name and its time say. */
|
|
16
|
+
export declare function parseMeta(raw: string | null, name: string, fallbackCreatedAt: string): MediaMeta;
|
|
17
|
+
export declare function toMedia(id: string, url: string, m: MediaMeta): StoredMedia;
|
|
18
|
+
/** Applies a PATCH to a sidecar: a string sets, null clears, absent keeps. */
|
|
19
|
+
export declare function patchMeta(m: MediaMeta, patch: {
|
|
20
|
+
alt?: string | null;
|
|
21
|
+
title?: string | null;
|
|
22
|
+
}): MediaMeta;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** A media id is 16 hex characters; the file is `<id>-<filename>`. Anything else never touches a path. */
|
|
2
|
+
export const MEDIA_ID_RE = /^[0-9a-f]{16}$/;
|
|
3
|
+
export const MEDIA_FILE_RE = /^([0-9a-f]{16})-(.+)$/;
|
|
4
|
+
export const META_SUFFIX = ".meta.json";
|
|
5
|
+
const BY_EXT = {
|
|
6
|
+
jpg: "image/jpeg",
|
|
7
|
+
jpeg: "image/jpeg",
|
|
8
|
+
png: "image/png",
|
|
9
|
+
gif: "image/gif",
|
|
10
|
+
webp: "image/webp",
|
|
11
|
+
avif: "image/avif",
|
|
12
|
+
};
|
|
13
|
+
export function mimeForName(name) {
|
|
14
|
+
return BY_EXT[name.split(".").pop()?.toLowerCase() ?? ""] ?? "application/octet-stream";
|
|
15
|
+
}
|
|
16
|
+
export function serializeMeta(m) {
|
|
17
|
+
const out = { content_type: m.content_type, created_at: m.created_at };
|
|
18
|
+
if (m.alt !== undefined)
|
|
19
|
+
out.alt = m.alt;
|
|
20
|
+
if (m.title !== undefined)
|
|
21
|
+
out.title = m.title;
|
|
22
|
+
return JSON.stringify(out);
|
|
23
|
+
}
|
|
24
|
+
/** Reads a sidecar; a missing or unreadable one falls back to what the file name and its time say. */
|
|
25
|
+
export function parseMeta(raw, name, fallbackCreatedAt) {
|
|
26
|
+
let j = {};
|
|
27
|
+
if (raw) {
|
|
28
|
+
try {
|
|
29
|
+
const v = JSON.parse(raw);
|
|
30
|
+
if (v && typeof v === "object" && !Array.isArray(v))
|
|
31
|
+
j = v;
|
|
32
|
+
}
|
|
33
|
+
catch { }
|
|
34
|
+
}
|
|
35
|
+
const s = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
36
|
+
const created = s(j.created_at);
|
|
37
|
+
return {
|
|
38
|
+
...(s(j.alt) !== undefined ? { alt: s(j.alt) } : {}),
|
|
39
|
+
...(s(j.title) !== undefined ? { title: s(j.title) } : {}),
|
|
40
|
+
content_type: s(j.content_type) ?? mimeForName(name),
|
|
41
|
+
created_at: created && !Number.isNaN(Date.parse(created)) ? created : fallbackCreatedAt,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function toMedia(id, url, m) {
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
url,
|
|
48
|
+
...(m.alt !== undefined ? { alt: m.alt } : {}),
|
|
49
|
+
...(m.title !== undefined ? { title: m.title } : {}),
|
|
50
|
+
mime_type: m.content_type,
|
|
51
|
+
created_at: m.created_at,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Applies a PATCH to a sidecar: a string sets, null clears, absent keeps. */
|
|
55
|
+
export function patchMeta(m, patch) {
|
|
56
|
+
const next = { content_type: m.content_type, created_at: m.created_at };
|
|
57
|
+
const alt = patch.alt === undefined ? m.alt : (patch.alt ?? undefined);
|
|
58
|
+
const title = patch.title === undefined ? m.title : (patch.title ?? undefined);
|
|
59
|
+
if (alt !== undefined && alt !== "")
|
|
60
|
+
next.alt = alt;
|
|
61
|
+
if (title !== undefined && title !== "")
|
|
62
|
+
next.title = title;
|
|
63
|
+
return next;
|
|
64
|
+
}
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const IMAGE_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "image/avif"];
|
|
2
|
+
export type ImageType = (typeof IMAGE_TYPES)[number];
|
|
3
|
+
export declare const EXTENSION: Record<ImageType, string>;
|
|
4
|
+
/** The image type the bytes really are, from their magic numbers; null for anything else (SVG included). */
|
|
5
|
+
export declare function sniffImage(b: Uint8Array): ImageType | null;
|
|
6
|
+
/**
|
|
7
|
+
* An image the receiver will store: allowed by declared type AND by its bytes, never SVG (refused
|
|
8
|
+
* by name, by type and by content). The sniffed type wins; a declared type that disagrees is refused.
|
|
9
|
+
*/
|
|
10
|
+
export declare function assertImage(bytes: Uint8Array, declaredType: string | undefined, filename: string | undefined): ImageType;
|
|
11
|
+
export interface MultipartPart {
|
|
12
|
+
name: string;
|
|
13
|
+
filename?: string;
|
|
14
|
+
contentType?: string;
|
|
15
|
+
data: Buffer;
|
|
16
|
+
}
|
|
17
|
+
/** Splits a multipart/form-data body by hand: scan for the boundary, read each part's headers and bytes. */
|
|
18
|
+
export declare function parseMultipart(body: Buffer, contentType: string): MultipartPart[];
|
|
19
|
+
/** A filename safe on any disk: no path, no odd characters, an extension that matches the real type. */
|
|
20
|
+
export declare function safeFilename(name: string | undefined, type: ImageType): string;
|
package/dist/media.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { InkwireError } from "./errors.js";
|
|
2
|
+
export const IMAGE_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp", "image/avif"];
|
|
3
|
+
export const EXTENSION = {
|
|
4
|
+
"image/jpeg": "jpg",
|
|
5
|
+
"image/png": "png",
|
|
6
|
+
"image/gif": "gif",
|
|
7
|
+
"image/webp": "webp",
|
|
8
|
+
"image/avif": "avif",
|
|
9
|
+
};
|
|
10
|
+
/** The image type the bytes really are, from their magic numbers; null for anything else (SVG included). */
|
|
11
|
+
export function sniffImage(b) {
|
|
12
|
+
const at = (i, ...v) => v.every((x, j) => b[i + j] === x);
|
|
13
|
+
if (b.length >= 3 && at(0, 0xff, 0xd8, 0xff))
|
|
14
|
+
return "image/jpeg";
|
|
15
|
+
if (b.length >= 8 && at(0, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a))
|
|
16
|
+
return "image/png";
|
|
17
|
+
if (b.length >= 6 && at(0, 0x47, 0x49, 0x46, 0x38) && (b[4] === 0x37 || b[4] === 0x39) && b[5] === 0x61)
|
|
18
|
+
return "image/gif";
|
|
19
|
+
if (b.length >= 12 && at(0, 0x52, 0x49, 0x46, 0x46) && at(8, 0x57, 0x45, 0x42, 0x50))
|
|
20
|
+
return "image/webp";
|
|
21
|
+
if (b.length >= 12 && at(4, 0x66, 0x74, 0x79, 0x70)) {
|
|
22
|
+
// ISO BMFF "ftyp": major brand, then compatible brands, one of them avif/avis.
|
|
23
|
+
const size = Math.min(((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]) >>> 0, b.length, 64);
|
|
24
|
+
for (let i = 8; i + 4 <= size; i += 4) {
|
|
25
|
+
if (i === 12)
|
|
26
|
+
continue; // minor version
|
|
27
|
+
const brand = String.fromCharCode(b[i], b[i + 1], b[i + 2], b[i + 3]);
|
|
28
|
+
if (brand === "avif" || brand === "avis")
|
|
29
|
+
return "image/avif";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const looksLikeSvg = (b) => {
|
|
35
|
+
const head = Buffer.from(b.subarray(0, 2048)).toString("utf8").toLowerCase();
|
|
36
|
+
return head.includes("<svg") || (head.trimStart().startsWith("<?xml") && head.includes("svg"));
|
|
37
|
+
};
|
|
38
|
+
const canonicalType = (t) => {
|
|
39
|
+
const base = t.split(";")[0].trim().toLowerCase();
|
|
40
|
+
return base === "image/jpg" || base === "image/pjpeg" ? "image/jpeg" : base;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* An image the receiver will store: allowed by declared type AND by its bytes, never SVG (refused
|
|
44
|
+
* by name, by type and by content). The sniffed type wins; a declared type that disagrees is refused.
|
|
45
|
+
*/
|
|
46
|
+
export function assertImage(bytes, declaredType, filename) {
|
|
47
|
+
const declared = declaredType ? canonicalType(declaredType) : undefined;
|
|
48
|
+
if (filename && /\.svgz?$/i.test(filename))
|
|
49
|
+
throw new InkwireError("invalid_payload", "SVG images are not accepted");
|
|
50
|
+
if (declared && declared.includes("svg"))
|
|
51
|
+
throw new InkwireError("invalid_payload", "SVG images are not accepted");
|
|
52
|
+
if (looksLikeSvg(bytes))
|
|
53
|
+
throw new InkwireError("invalid_payload", "SVG images are not accepted");
|
|
54
|
+
const sniffed = sniffImage(bytes);
|
|
55
|
+
if (!sniffed)
|
|
56
|
+
throw new InkwireError("invalid_payload", "the file is not a JPEG, PNG, GIF, WebP or AVIF image");
|
|
57
|
+
if (declared && declared !== "application/octet-stream" && declared !== sniffed) {
|
|
58
|
+
if (!IMAGE_TYPES.includes(declared)) {
|
|
59
|
+
throw new InkwireError("invalid_payload", `content type ${declared} is not an accepted image type`);
|
|
60
|
+
}
|
|
61
|
+
throw new InkwireError("invalid_payload", `the file says ${declared} but its content is ${sniffed}`);
|
|
62
|
+
}
|
|
63
|
+
return sniffed;
|
|
64
|
+
}
|
|
65
|
+
function boundaryOf(contentType) {
|
|
66
|
+
const m = /boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(contentType);
|
|
67
|
+
const b = m?.[1] ?? m?.[2];
|
|
68
|
+
if (!b || b.length > 200)
|
|
69
|
+
throw new InkwireError("invalid_payload", "multipart body has no boundary");
|
|
70
|
+
return b;
|
|
71
|
+
}
|
|
72
|
+
/** Splits a multipart/form-data body by hand: scan for the boundary, read each part's headers and bytes. */
|
|
73
|
+
export function parseMultipart(body, contentType) {
|
|
74
|
+
const delim = Buffer.from(`--${boundaryOf(contentType)}`);
|
|
75
|
+
const parts = [];
|
|
76
|
+
let pos = body.indexOf(delim);
|
|
77
|
+
if (pos === -1)
|
|
78
|
+
throw new InkwireError("invalid_payload", "multipart body is malformed");
|
|
79
|
+
for (;;) {
|
|
80
|
+
pos += delim.length;
|
|
81
|
+
// "--" after the delimiter closes the body; otherwise a line break follows.
|
|
82
|
+
if (body[pos] === 0x2d && body[pos + 1] === 0x2d)
|
|
83
|
+
break;
|
|
84
|
+
if (body[pos] === 0x0d && body[pos + 1] === 0x0a)
|
|
85
|
+
pos += 2;
|
|
86
|
+
else if (body[pos] === 0x0a)
|
|
87
|
+
pos += 1;
|
|
88
|
+
else
|
|
89
|
+
throw new InkwireError("invalid_payload", "multipart body is malformed");
|
|
90
|
+
const headerEnd = body.indexOf("\r\n\r\n", pos);
|
|
91
|
+
if (headerEnd === -1)
|
|
92
|
+
throw new InkwireError("invalid_payload", "multipart body is malformed");
|
|
93
|
+
const headerText = body.subarray(pos, headerEnd).toString("utf8");
|
|
94
|
+
const next = body.indexOf(Buffer.concat([Buffer.from("\r\n"), delim]), headerEnd + 4);
|
|
95
|
+
if (next === -1)
|
|
96
|
+
throw new InkwireError("invalid_payload", "multipart body is malformed");
|
|
97
|
+
const data = body.subarray(headerEnd + 4, next);
|
|
98
|
+
const headers = new Map();
|
|
99
|
+
for (const line of headerText.split(/\r\n/)) {
|
|
100
|
+
const c = line.indexOf(":");
|
|
101
|
+
if (c > 0)
|
|
102
|
+
headers.set(line.slice(0, c).trim().toLowerCase(), line.slice(c + 1).trim());
|
|
103
|
+
}
|
|
104
|
+
const disp = headers.get("content-disposition") ?? "";
|
|
105
|
+
const name = /(?:^|[;\s])name="([^"]*)"/i.exec(disp)?.[1] ?? /(?:^|[;\s])name=([^;\s]+)/i.exec(disp)?.[1];
|
|
106
|
+
if (name !== undefined) {
|
|
107
|
+
const filename = /filename="([^"]*)"/i.exec(disp)?.[1] ?? /filename=([^;\s]+)/i.exec(disp)?.[1];
|
|
108
|
+
parts.push({ name, filename, contentType: headers.get("content-type"), data: Buffer.from(data) });
|
|
109
|
+
}
|
|
110
|
+
pos = next + 2; // at the delimiter again
|
|
111
|
+
}
|
|
112
|
+
return parts;
|
|
113
|
+
}
|
|
114
|
+
/** A filename safe on any disk: no path, no odd characters, an extension that matches the real type. */
|
|
115
|
+
export function safeFilename(name, type) {
|
|
116
|
+
const base = (name ?? "").split(/[\\/]/).pop() ?? "";
|
|
117
|
+
const lastDot = base.lastIndexOf(".");
|
|
118
|
+
const rawStem = lastDot > 0 ? base.slice(0, lastDot) : base;
|
|
119
|
+
const stem = rawStem
|
|
120
|
+
.replace(/[^A-Za-z0-9._-]+/g, "-")
|
|
121
|
+
.replace(/^[.-]+|[.-]+$/g, "")
|
|
122
|
+
.slice(0, 80)
|
|
123
|
+
.replace(/[.-]+$/g, "");
|
|
124
|
+
return `${stem || "image"}.${EXTENSION[type]}`;
|
|
125
|
+
}
|
package/dist/render.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical allowlist (SPEC, "Content safety"): sanitize-html's default tags unioned with
|
|
3
|
+
* `img`. Only `a` and `img` keep attributes; schemes are http, https and mailto.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ALLOWED_TAGS: string[];
|
|
6
|
+
export declare const ALLOWED_ATTRIBUTES: Record<string, string[]>;
|
|
7
|
+
export declare const ALLOWED_SCHEMES: string[];
|
|
1
8
|
export declare function renderMarkdown(markdown: string): string;
|
|
9
|
+
/** Lowercase, non-alphanumerics to "-", trimmed, at most 255 chars. Falls back to "entry". */
|
|
2
10
|
export declare function slugify(s: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Text edits for a client: each `find` must occur EXACTLY once in the current markdown (non
|
|
13
|
+
* overlapping count), else nothing is returned and an `invalid_payload` error says which edit and why
|
|
14
|
+
* (`edit_not_found: …` / `edit_ambiguous: …`). Edits apply in order, so a later `find` sees the result
|
|
15
|
+
* of an earlier `replace`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function edits(markdown: string, changes: {
|
|
18
|
+
find: string;
|
|
19
|
+
replace: string;
|
|
20
|
+
}[]): string;
|
package/dist/render.js
CHANGED
|
@@ -1,15 +1,64 @@
|
|
|
1
1
|
import MarkdownIt from "markdown-it";
|
|
2
2
|
import sanitizeHtml from "sanitize-html";
|
|
3
|
+
import { InkwireError } from "./errors.js";
|
|
3
4
|
const md = new MarkdownIt({ html: true, linkify: true });
|
|
5
|
+
/**
|
|
6
|
+
* The canonical allowlist (SPEC, "Content safety"): sanitize-html's default tags unioned with
|
|
7
|
+
* `img`. Only `a` and `img` keep attributes; schemes are http, https and mailto.
|
|
8
|
+
*/
|
|
9
|
+
export const ALLOWED_TAGS = [...new Set([...sanitizeHtml.defaults.allowedTags, "img"])];
|
|
10
|
+
export const ALLOWED_ATTRIBUTES = {
|
|
11
|
+
a: ["href", "name", "rel"],
|
|
12
|
+
img: ["src", "alt", "title"],
|
|
13
|
+
};
|
|
14
|
+
export const ALLOWED_SCHEMES = ["http", "https", "mailto"];
|
|
4
15
|
export function renderMarkdown(markdown) {
|
|
5
16
|
const raw = md.render(markdown);
|
|
6
17
|
return sanitizeHtml(raw, {
|
|
7
|
-
allowedTags:
|
|
8
|
-
allowedAttributes:
|
|
9
|
-
allowedSchemes:
|
|
18
|
+
allowedTags: ALLOWED_TAGS,
|
|
19
|
+
allowedAttributes: ALLOWED_ATTRIBUTES,
|
|
20
|
+
allowedSchemes: ALLOWED_SCHEMES,
|
|
10
21
|
disallowedTagsMode: "discard",
|
|
11
22
|
});
|
|
12
23
|
}
|
|
24
|
+
/** Lowercase, non-alphanumerics to "-", trimmed, at most 255 chars. Falls back to "entry". */
|
|
13
25
|
export function slugify(s) {
|
|
14
|
-
return s
|
|
26
|
+
return (s
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
29
|
+
.replace(/^-+|-+$/g, "")
|
|
30
|
+
.slice(0, 255)
|
|
31
|
+
.replace(/-+$/g, "") || "entry");
|
|
32
|
+
}
|
|
33
|
+
const preview = (s) => (s.length > 60 ? `${s.slice(0, 60)}…` : s);
|
|
34
|
+
function countOccurrences(haystack, needle) {
|
|
35
|
+
let n = 0;
|
|
36
|
+
for (let at = haystack.indexOf(needle); at !== -1; at = haystack.indexOf(needle, at + needle.length))
|
|
37
|
+
n++;
|
|
38
|
+
return n;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Text edits for a client: each `find` must occur EXACTLY once in the current markdown (non
|
|
42
|
+
* overlapping count), else nothing is returned and an `invalid_payload` error says which edit and why
|
|
43
|
+
* (`edit_not_found: …` / `edit_ambiguous: …`). Edits apply in order, so a later `find` sees the result
|
|
44
|
+
* of an earlier `replace`.
|
|
45
|
+
*/
|
|
46
|
+
export function edits(markdown, changes) {
|
|
47
|
+
let out = markdown;
|
|
48
|
+
changes.forEach((c, i) => {
|
|
49
|
+
const n = i + 1;
|
|
50
|
+
if (typeof c.find !== "string" || c.find === "") {
|
|
51
|
+
throw new InkwireError("invalid_payload", `edit_not_found: edit ${n} has an empty "find"`);
|
|
52
|
+
}
|
|
53
|
+
const hits = countOccurrences(out, c.find);
|
|
54
|
+
if (hits === 0) {
|
|
55
|
+
throw new InkwireError("invalid_payload", `edit_not_found: edit ${n}: "${preview(c.find)}" does not occur in the markdown`);
|
|
56
|
+
}
|
|
57
|
+
if (hits > 1) {
|
|
58
|
+
throw new InkwireError("invalid_payload", `edit_ambiguous: edit ${n}: "${preview(c.find)}" occurs ${hits} times; include more surrounding text so it matches once`);
|
|
59
|
+
}
|
|
60
|
+
const at = out.indexOf(c.find);
|
|
61
|
+
out = out.slice(0, at) + c.replace + out.slice(at + c.find.length);
|
|
62
|
+
});
|
|
63
|
+
return out;
|
|
15
64
|
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const ContentInput: z.ZodObject<{
|
|
3
3
|
external_id: z.ZodString;
|
|
4
4
|
title: z.ZodString;
|
|
5
5
|
markdown: z.ZodString;
|
|
6
|
+
kind: z.ZodDefault<z.ZodString>;
|
|
6
7
|
slug: z.ZodOptional<z.ZodString>;
|
|
7
8
|
excerpt: z.ZodOptional<z.ZodString>;
|
|
8
9
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
10
|
+
categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
9
11
|
cover_image_url: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
12
|
+
cover_image_alt: z.ZodOptional<z.ZodString>;
|
|
10
13
|
canonical_url: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
14
|
+
seo: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
title: z.ZodOptional<z.ZodString>;
|
|
16
|
+
description: z.ZodOptional<z.ZodString>;
|
|
17
|
+
image_url: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
18
|
+
noindex: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
og_title: z.ZodOptional<z.ZodString>;
|
|
20
|
+
og_description: z.ZodOptional<z.ZodString>;
|
|
21
|
+
json_ld: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
22
|
+
}, "strict", z.ZodTypeAny, {
|
|
23
|
+
title?: string | undefined;
|
|
24
|
+
description?: string | undefined;
|
|
25
|
+
image_url?: string | undefined;
|
|
26
|
+
noindex?: boolean | undefined;
|
|
27
|
+
og_title?: string | undefined;
|
|
28
|
+
og_description?: string | undefined;
|
|
29
|
+
json_ld?: string | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
title?: string | undefined;
|
|
32
|
+
description?: string | undefined;
|
|
33
|
+
image_url?: string | undefined;
|
|
34
|
+
noindex?: boolean | undefined;
|
|
35
|
+
og_title?: string | undefined;
|
|
36
|
+
og_description?: string | undefined;
|
|
37
|
+
json_ld?: string | undefined;
|
|
38
|
+
}>>;
|
|
11
39
|
author: z.ZodOptional<z.ZodObject<{
|
|
12
40
|
name: z.ZodOptional<z.ZodString>;
|
|
13
41
|
email: z.ZodOptional<z.ZodString>;
|
|
@@ -21,34 +49,239 @@ export declare const PostInput: z.ZodObject<{
|
|
|
21
49
|
status: z.ZodDefault<z.ZodEnum<["draft", "published"]>>;
|
|
22
50
|
published_at: z.ZodOptional<z.ZodString>;
|
|
23
51
|
}, "strict", z.ZodTypeAny, {
|
|
24
|
-
external_id: string;
|
|
25
52
|
title: string;
|
|
26
|
-
markdown: string;
|
|
27
53
|
status: "draft" | "published";
|
|
54
|
+
external_id: string;
|
|
55
|
+
markdown: string;
|
|
56
|
+
kind: string;
|
|
28
57
|
slug?: string | undefined;
|
|
29
58
|
excerpt?: string | undefined;
|
|
30
59
|
tags?: string[] | undefined;
|
|
60
|
+
categories?: string[] | undefined;
|
|
31
61
|
cover_image_url?: string | undefined;
|
|
62
|
+
cover_image_alt?: string | undefined;
|
|
32
63
|
canonical_url?: string | undefined;
|
|
64
|
+
seo?: {
|
|
65
|
+
title?: string | undefined;
|
|
66
|
+
description?: string | undefined;
|
|
67
|
+
image_url?: string | undefined;
|
|
68
|
+
noindex?: boolean | undefined;
|
|
69
|
+
og_title?: string | undefined;
|
|
70
|
+
og_description?: string | undefined;
|
|
71
|
+
json_ld?: string | undefined;
|
|
72
|
+
} | undefined;
|
|
33
73
|
author?: {
|
|
34
74
|
name?: string | undefined;
|
|
35
75
|
email?: string | undefined;
|
|
36
76
|
} | undefined;
|
|
37
77
|
published_at?: string | undefined;
|
|
38
78
|
}, {
|
|
39
|
-
external_id: string;
|
|
40
79
|
title: string;
|
|
80
|
+
external_id: string;
|
|
41
81
|
markdown: string;
|
|
82
|
+
status?: "draft" | "published" | undefined;
|
|
83
|
+
kind?: string | undefined;
|
|
42
84
|
slug?: string | undefined;
|
|
43
85
|
excerpt?: string | undefined;
|
|
44
|
-
status?: "draft" | "published" | undefined;
|
|
45
86
|
tags?: string[] | undefined;
|
|
87
|
+
categories?: string[] | undefined;
|
|
46
88
|
cover_image_url?: string | undefined;
|
|
89
|
+
cover_image_alt?: string | undefined;
|
|
47
90
|
canonical_url?: string | undefined;
|
|
91
|
+
seo?: {
|
|
92
|
+
title?: string | undefined;
|
|
93
|
+
description?: string | undefined;
|
|
94
|
+
image_url?: string | undefined;
|
|
95
|
+
noindex?: boolean | undefined;
|
|
96
|
+
og_title?: string | undefined;
|
|
97
|
+
og_description?: string | undefined;
|
|
98
|
+
json_ld?: string | undefined;
|
|
99
|
+
} | undefined;
|
|
48
100
|
author?: {
|
|
49
101
|
name?: string | undefined;
|
|
50
102
|
email?: string | undefined;
|
|
51
103
|
} | undefined;
|
|
52
104
|
published_at?: string | undefined;
|
|
53
105
|
}>;
|
|
54
|
-
export type
|
|
106
|
+
export type UpsertInput = z.infer<typeof ContentInput>;
|
|
107
|
+
export declare const PatchSchema: z.ZodEffects<z.ZodObject<{
|
|
108
|
+
title: z.ZodOptional<z.ZodString>;
|
|
109
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
110
|
+
markdown: z.ZodOptional<z.ZodString>;
|
|
111
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
112
|
+
excerpt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
113
|
+
tags: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
114
|
+
categories: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
115
|
+
cover_image_url: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, string, string>>>;
|
|
116
|
+
cover_image_alt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
117
|
+
canonical_url: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, string, string>>>;
|
|
118
|
+
seo: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
119
|
+
title: z.ZodOptional<z.ZodString>;
|
|
120
|
+
description: z.ZodOptional<z.ZodString>;
|
|
121
|
+
image_url: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, string, string>>>;
|
|
122
|
+
noindex: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
+
og_title: z.ZodOptional<z.ZodString>;
|
|
124
|
+
og_description: z.ZodOptional<z.ZodString>;
|
|
125
|
+
json_ld: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, string, string>>>;
|
|
126
|
+
}, "strict", z.ZodTypeAny, {
|
|
127
|
+
title?: string | undefined;
|
|
128
|
+
description?: string | undefined;
|
|
129
|
+
image_url?: string | null | undefined;
|
|
130
|
+
noindex?: boolean | undefined;
|
|
131
|
+
og_title?: string | undefined;
|
|
132
|
+
og_description?: string | undefined;
|
|
133
|
+
json_ld?: string | null | undefined;
|
|
134
|
+
}, {
|
|
135
|
+
title?: string | undefined;
|
|
136
|
+
description?: string | undefined;
|
|
137
|
+
image_url?: string | null | undefined;
|
|
138
|
+
noindex?: boolean | undefined;
|
|
139
|
+
og_title?: string | undefined;
|
|
140
|
+
og_description?: string | undefined;
|
|
141
|
+
json_ld?: string | null | undefined;
|
|
142
|
+
}>>>;
|
|
143
|
+
author: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
144
|
+
name: z.ZodOptional<z.ZodString>;
|
|
145
|
+
email: z.ZodOptional<z.ZodString>;
|
|
146
|
+
}, "strict", z.ZodTypeAny, {
|
|
147
|
+
name?: string | undefined;
|
|
148
|
+
email?: string | undefined;
|
|
149
|
+
}, {
|
|
150
|
+
name?: string | undefined;
|
|
151
|
+
email?: string | undefined;
|
|
152
|
+
}>>>;
|
|
153
|
+
status: z.ZodOptional<z.ZodEnum<["draft", "published"]>>;
|
|
154
|
+
published_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
155
|
+
}, "strict", z.ZodTypeAny, {
|
|
156
|
+
title?: string | undefined;
|
|
157
|
+
status?: "draft" | "published" | undefined;
|
|
158
|
+
markdown?: string | undefined;
|
|
159
|
+
kind?: string | undefined;
|
|
160
|
+
slug?: string | undefined;
|
|
161
|
+
excerpt?: string | null | undefined;
|
|
162
|
+
tags?: string[] | null | undefined;
|
|
163
|
+
categories?: string[] | null | undefined;
|
|
164
|
+
cover_image_url?: string | null | undefined;
|
|
165
|
+
cover_image_alt?: string | null | undefined;
|
|
166
|
+
canonical_url?: string | null | undefined;
|
|
167
|
+
seo?: {
|
|
168
|
+
title?: string | undefined;
|
|
169
|
+
description?: string | undefined;
|
|
170
|
+
image_url?: string | null | undefined;
|
|
171
|
+
noindex?: boolean | undefined;
|
|
172
|
+
og_title?: string | undefined;
|
|
173
|
+
og_description?: string | undefined;
|
|
174
|
+
json_ld?: string | null | undefined;
|
|
175
|
+
} | null | undefined;
|
|
176
|
+
author?: {
|
|
177
|
+
name?: string | undefined;
|
|
178
|
+
email?: string | undefined;
|
|
179
|
+
} | null | undefined;
|
|
180
|
+
published_at?: string | null | undefined;
|
|
181
|
+
}, {
|
|
182
|
+
title?: string | undefined;
|
|
183
|
+
status?: "draft" | "published" | undefined;
|
|
184
|
+
markdown?: string | undefined;
|
|
185
|
+
kind?: string | undefined;
|
|
186
|
+
slug?: string | undefined;
|
|
187
|
+
excerpt?: string | null | undefined;
|
|
188
|
+
tags?: string[] | null | undefined;
|
|
189
|
+
categories?: string[] | null | undefined;
|
|
190
|
+
cover_image_url?: string | null | undefined;
|
|
191
|
+
cover_image_alt?: string | null | undefined;
|
|
192
|
+
canonical_url?: string | null | undefined;
|
|
193
|
+
seo?: {
|
|
194
|
+
title?: string | undefined;
|
|
195
|
+
description?: string | undefined;
|
|
196
|
+
image_url?: string | null | undefined;
|
|
197
|
+
noindex?: boolean | undefined;
|
|
198
|
+
og_title?: string | undefined;
|
|
199
|
+
og_description?: string | undefined;
|
|
200
|
+
json_ld?: string | null | undefined;
|
|
201
|
+
} | null | undefined;
|
|
202
|
+
author?: {
|
|
203
|
+
name?: string | undefined;
|
|
204
|
+
email?: string | undefined;
|
|
205
|
+
} | null | undefined;
|
|
206
|
+
published_at?: string | null | undefined;
|
|
207
|
+
}>, {
|
|
208
|
+
title?: string | undefined;
|
|
209
|
+
status?: "draft" | "published" | undefined;
|
|
210
|
+
markdown?: string | undefined;
|
|
211
|
+
kind?: string | undefined;
|
|
212
|
+
slug?: string | undefined;
|
|
213
|
+
excerpt?: string | null | undefined;
|
|
214
|
+
tags?: string[] | null | undefined;
|
|
215
|
+
categories?: string[] | null | undefined;
|
|
216
|
+
cover_image_url?: string | null | undefined;
|
|
217
|
+
cover_image_alt?: string | null | undefined;
|
|
218
|
+
canonical_url?: string | null | undefined;
|
|
219
|
+
seo?: {
|
|
220
|
+
title?: string | undefined;
|
|
221
|
+
description?: string | undefined;
|
|
222
|
+
image_url?: string | null | undefined;
|
|
223
|
+
noindex?: boolean | undefined;
|
|
224
|
+
og_title?: string | undefined;
|
|
225
|
+
og_description?: string | undefined;
|
|
226
|
+
json_ld?: string | null | undefined;
|
|
227
|
+
} | null | undefined;
|
|
228
|
+
author?: {
|
|
229
|
+
name?: string | undefined;
|
|
230
|
+
email?: string | undefined;
|
|
231
|
+
} | null | undefined;
|
|
232
|
+
published_at?: string | null | undefined;
|
|
233
|
+
}, {
|
|
234
|
+
title?: string | undefined;
|
|
235
|
+
status?: "draft" | "published" | undefined;
|
|
236
|
+
markdown?: string | undefined;
|
|
237
|
+
kind?: string | undefined;
|
|
238
|
+
slug?: string | undefined;
|
|
239
|
+
excerpt?: string | null | undefined;
|
|
240
|
+
tags?: string[] | null | undefined;
|
|
241
|
+
categories?: string[] | null | undefined;
|
|
242
|
+
cover_image_url?: string | null | undefined;
|
|
243
|
+
cover_image_alt?: string | null | undefined;
|
|
244
|
+
canonical_url?: string | null | undefined;
|
|
245
|
+
seo?: {
|
|
246
|
+
title?: string | undefined;
|
|
247
|
+
description?: string | undefined;
|
|
248
|
+
image_url?: string | null | undefined;
|
|
249
|
+
noindex?: boolean | undefined;
|
|
250
|
+
og_title?: string | undefined;
|
|
251
|
+
og_description?: string | undefined;
|
|
252
|
+
json_ld?: string | null | undefined;
|
|
253
|
+
} | null | undefined;
|
|
254
|
+
author?: {
|
|
255
|
+
name?: string | undefined;
|
|
256
|
+
email?: string | undefined;
|
|
257
|
+
} | null | undefined;
|
|
258
|
+
published_at?: string | null | undefined;
|
|
259
|
+
}>;
|
|
260
|
+
export type PatchInput = z.infer<typeof PatchSchema>;
|
|
261
|
+
export declare const MediaUrlInput: z.ZodObject<{
|
|
262
|
+
url: z.ZodEffects<z.ZodString, string, string>;
|
|
263
|
+
alt: z.ZodOptional<z.ZodString>;
|
|
264
|
+
}, "strict", z.ZodTypeAny, {
|
|
265
|
+
url: string;
|
|
266
|
+
alt?: string | undefined;
|
|
267
|
+
}, {
|
|
268
|
+
url: string;
|
|
269
|
+
alt?: string | undefined;
|
|
270
|
+
}>;
|
|
271
|
+
export declare const MediaPatchSchema: z.ZodEffects<z.ZodObject<{
|
|
272
|
+
alt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
273
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
274
|
+
}, "strict", z.ZodTypeAny, {
|
|
275
|
+
alt?: string | null | undefined;
|
|
276
|
+
title?: string | null | undefined;
|
|
277
|
+
}, {
|
|
278
|
+
alt?: string | null | undefined;
|
|
279
|
+
title?: string | null | undefined;
|
|
280
|
+
}>, {
|
|
281
|
+
alt?: string | null | undefined;
|
|
282
|
+
title?: string | null | undefined;
|
|
283
|
+
}, {
|
|
284
|
+
alt?: string | null | undefined;
|
|
285
|
+
title?: string | null | undefined;
|
|
286
|
+
}>;
|
|
287
|
+
export type MediaPatchInput = z.infer<typeof MediaPatchSchema>;
|