bearminion 1.13.0 → 1.15.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/CHANGELOG.md +12 -0
- package/dist/astro.d.ts +75 -45
- package/dist/astro.js +106 -1553
- package/dist/cli.js +1 -1
- package/dist/content.d.ts +1 -1
- package/dist/content.js +1 -1
- package/dist/{draft-store-1Y4-sn45.js → draft-store-BaZYEe56.js} +45 -1
- package/dist/editor-context-CTfxXtny.d.ts +272 -0
- package/dist/{forms-dev-CEab55ss.js → forms-dev-CzUHR7oS.js} +1 -1
- package/dist/github-store-BT9uiq5W.d.ts +64 -0
- package/dist/github-store-D0bQOwdt.js +1755 -0
- package/dist/hosted.d.ts +45 -0
- package/dist/hosted.js +37 -0
- package/dist/index.d.ts +2 -103
- package/dist/{page-CwbIDegI.d.ts → page-FipdIFb5.d.ts} +37 -37
- package/dist/{reload-BIIa7pej.js → reload-BzVw721A.js} +1 -1
- package/dist/security-CBiOYdVE.js +24 -0
- package/dist/ui/mount.js +1 -2
- package/package.json +5 -1
- package/registry/default/registry.json +1 -1
- package/dist/options-DP6mTauQ.d.ts +0 -205
- package/dist/security-FLvgc2jD.js +0 -93
- package/dist/upload-rules-Cao9uY5K.js +0 -36
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as readDotEnv } from "./forms-dev-
|
|
2
|
+
import { i as readDotEnv } from "./forms-dev-CzUHR7oS.js";
|
|
3
3
|
import { i as syncSections, r as staleSectionsMessage, t as SectionsError } from "./sections-manifest-CO9QfJPG.js";
|
|
4
4
|
import { i as writeLock, n as readLock, r as recordFiles, t as hashContent } from "./hash-BeBymBO1.js";
|
|
5
5
|
import fs from "node:fs";
|
package/dist/content.d.ts
CHANGED
package/dist/content.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as createPageSchema, r as createTolerantPageSchema } from "./page-wlcQJAA-.js";
|
|
2
2
|
import { n as createMigrator } from "./migrate-b408EaLp.js";
|
|
3
|
-
import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-
|
|
3
|
+
import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-BzVw721A.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
//#region src/upload-rules.ts
|
|
2
|
+
/**
|
|
3
|
+
* Image upload rules shared by the dev server and the editor in the browser. No Node imports: the browser bundle
|
|
4
|
+
* uses it too.
|
|
5
|
+
*/
|
|
6
|
+
/** The default largest image the editor accepts: 5 MB. */
|
|
7
|
+
const DEFAULT_IMAGE_BYTE_LIMIT = 5242880;
|
|
8
|
+
const DEFAULT_CONVERT_QUALITY = .82;
|
|
9
|
+
const MAX_CONVERT_WIDTH = 16384;
|
|
10
|
+
/** Check `imageConvert` and fill in its defaults. `false` and `undefined` mean no conversion. */
|
|
11
|
+
function resolveConvert(input) {
|
|
12
|
+
if (input === void 0 || input === false) return null;
|
|
13
|
+
if (input.to !== "webp") throw new Error(`bearminion(): imageConvert.to must be "webp", got "${String(input.to)}".`);
|
|
14
|
+
const { maxWidth, quality = DEFAULT_CONVERT_QUALITY } = input;
|
|
15
|
+
if (maxWidth !== void 0 && (!Number.isInteger(maxWidth) || maxWidth < 16 || maxWidth > 16384)) throw new Error(`bearminion(): imageConvert.maxWidth must be a whole number from 16 to ${MAX_CONVERT_WIDTH}.`);
|
|
16
|
+
if (!Number.isFinite(quality) || quality < .1 || quality > 1) throw new Error("bearminion(): imageConvert.quality must be a number from 0.1 to 1.");
|
|
17
|
+
return {
|
|
18
|
+
to: "webp",
|
|
19
|
+
maxWidth: maxWidth ?? null,
|
|
20
|
+
quality
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Check `maxImageBytes`. */
|
|
24
|
+
function resolveMaxImageBytes(input) {
|
|
25
|
+
if (input === void 0) return DEFAULT_IMAGE_BYTE_LIMIT;
|
|
26
|
+
if (!Number.isInteger(input) || input < 1024) throw new Error("bearminion(): maxImageBytes must be a whole number of bytes, at least 1024.");
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
/** "4.2 MB", "310 KB", "512 B". */
|
|
30
|
+
function formatBytes(bytes) {
|
|
31
|
+
if (bytes >= 1048576) return `${(bytes / 1048576).toFixed(1).replace(/\.0$/, "")} MB`;
|
|
32
|
+
if (bytes >= 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
33
|
+
return `${bytes} B`;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
1
36
|
//#region src/asset-paths.ts
|
|
2
37
|
/** A project-relative image path that content may point at, such as `src/assets/uploads/hero-a1b2c3d4.png`. */
|
|
3
38
|
function isAssetPath(src) {
|
|
@@ -55,6 +90,15 @@ function draftImageUsages(src, drafts, labels) {
|
|
|
55
90
|
}
|
|
56
91
|
return usages;
|
|
57
92
|
}
|
|
93
|
+
/** One validation issue per image path in `document` whose file does not exist. */
|
|
94
|
+
async function missingAssetIssues(document, exists) {
|
|
95
|
+
const refs = assetRefs(document);
|
|
96
|
+
const present = await Promise.all(refs.map((ref) => exists(ref.src)));
|
|
97
|
+
return refs.flatMap((ref, index) => present[index] ? [] : [{
|
|
98
|
+
path: ref.path,
|
|
99
|
+
message: `Image file not found: ${ref.src}. Choose another image or upload it again.`
|
|
100
|
+
}]);
|
|
101
|
+
}
|
|
58
102
|
const PREFIX = "bearminion:draft:";
|
|
59
103
|
/** Stable id so two projects served from localhost do not share drafts. */
|
|
60
104
|
function projectId(root, siteName) {
|
|
@@ -233,4 +277,4 @@ function reloadDecision(input) {
|
|
|
233
277
|
return "reload";
|
|
234
278
|
}
|
|
235
279
|
//#endregion
|
|
236
|
-
export { isAssetPath as S, writeSaveNotice as _, localDraftStorage as a, describeSiteRef as b, projectId as c, removeDraft as d, savedNoticeFor as f, writeDraftRecord as g, sweepExpiredDrafts as h, isForeignSave as i, readDraftRecord as l, siteSavedKey as m, draftBannerText as n, pageDraftKey as o, siteDraftKey as p, hashText as r, pageSavedKey as s, assessStoredDraft as t, reloadDecision as u, assetRefs as v, draftImageUsages as x, describePageRef as y };
|
|
280
|
+
export { missingAssetIssues as C, resolveMaxImageBytes as D, resolveConvert as E, isAssetPath as S, formatBytes as T, writeSaveNotice as _, localDraftStorage as a, describeSiteRef as b, projectId as c, removeDraft as d, savedNoticeFor as f, writeDraftRecord as g, sweepExpiredDrafts as h, isForeignSave as i, readDraftRecord as l, siteSavedKey as m, draftBannerText as n, pageDraftKey as o, siteDraftKey as p, hashText as r, pageSavedKey as s, assessStoredDraft as t, reloadDecision as u, assetRefs as v, DEFAULT_IMAGE_BYTE_LIMIT as w, draftImageUsages as x, describePageRef as y };
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { N as ThemeDefinition, Y as SiteDefinition, j as SectionRegistry, n as PageRules, wt as ContentMigrator } from "./page-FipdIFb5.js";
|
|
2
|
+
//#region src/upload-names.d.ts
|
|
3
|
+
type ImageKind = 'png' | 'jpeg' | 'webp' | 'gif' | 'avif';
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/image-sniff.d.ts
|
|
6
|
+
interface SavedImage {
|
|
7
|
+
filename: string;
|
|
8
|
+
path: string;
|
|
9
|
+
bytes: number;
|
|
10
|
+
}
|
|
11
|
+
interface ListedImage {
|
|
12
|
+
filename: string;
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/video-sniff.d.ts
|
|
17
|
+
type VideoKind = 'mp4' | 'mov' | 'webm' | 'ogv';
|
|
18
|
+
interface SavedVideo {
|
|
19
|
+
filename: string;
|
|
20
|
+
/** Project-relative path of the file. */
|
|
21
|
+
path: string;
|
|
22
|
+
/** What a Media section's `video` field holds: the file's address on the site, such as `/videos/demo-1a2b.mp4`. */
|
|
23
|
+
url: string;
|
|
24
|
+
bytes: number;
|
|
25
|
+
}
|
|
26
|
+
type ListedVideo = Omit<SavedVideo, 'bytes'> & {
|
|
27
|
+
bytes?: number;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/store-core.d.ts
|
|
31
|
+
/**
|
|
32
|
+
* Where the editor reads and writes content. The editor API talks only to this interface, so the
|
|
33
|
+
* place the files live is a choice: {@link createFileStore} uses the local project, and another
|
|
34
|
+
* implementation (a Git host's API, say) can stand in without touching the API handlers.
|
|
35
|
+
*
|
|
36
|
+
* Keys are `/`-separated paths relative to the content directory: `site.json`, `pages/about.json`.
|
|
37
|
+
* Values are text. Parsing, validation and the JSON layout belong to the caller.
|
|
38
|
+
*
|
|
39
|
+
* Not part of the store: undo history (local editor state in `.editor/`), `Commit changes`
|
|
40
|
+
* (needs a local git work tree), and the loaders that run at build time.
|
|
41
|
+
*/
|
|
42
|
+
interface ContentStore {
|
|
43
|
+
/** The text at `key`, or `undefined` when there is none. */
|
|
44
|
+
read(key: string): Promise<string | undefined>;
|
|
45
|
+
exists(key: string): Promise<boolean>;
|
|
46
|
+
/** Names of the files directly inside the directory `dir`, sorted, or `undefined` when it does not exist. */
|
|
47
|
+
list(dir: string): Promise<string[] | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Apply changes that belong together, such as a rename (write the new file, remove the old one).
|
|
50
|
+
* Writes run before removals, so a failure never leaves the content with a page missing. An
|
|
51
|
+
* implementation that can make the whole batch atomic (one commit) should.
|
|
52
|
+
*/
|
|
53
|
+
apply(operations: readonly StoreOperation[]): Promise<void>;
|
|
54
|
+
/** Uploaded images. */
|
|
55
|
+
readonly uploads: UploadStore;
|
|
56
|
+
/** Uploaded videos, served from `public/`. Absent in stores that only hold images. */
|
|
57
|
+
readonly videos?: VideoStore;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the image file an image field points at (`src/assets/...`) exists. Saves that point at a missing file
|
|
60
|
+
* fail validation. A store without it skips that check.
|
|
61
|
+
*/
|
|
62
|
+
assetExists?(src: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* A view of the store for editing one entry (`page:about`, `site`), for stores that keep each entry's pending edits
|
|
65
|
+
* apart, such as `githubStore` in `pr` mode, where every scope is a branch and a pull request. Reads see the entry's
|
|
66
|
+
* pending edits, writes go to them. Absent when every write goes to the same place.
|
|
67
|
+
*/
|
|
68
|
+
scoped?(scope: string): ContentStore;
|
|
69
|
+
}
|
|
70
|
+
type StoreOperation = {
|
|
71
|
+
type: 'write';
|
|
72
|
+
key: string;
|
|
73
|
+
text: string;
|
|
74
|
+
} | {
|
|
75
|
+
type: 'remove';
|
|
76
|
+
key: string;
|
|
77
|
+
};
|
|
78
|
+
interface UploadStore {
|
|
79
|
+
list(): Promise<ListedImage[]>;
|
|
80
|
+
/** Store the bytes under a unique, sanitised name and return where it went. `path` is what image fields hold. */
|
|
81
|
+
save(input: {
|
|
82
|
+
originalName: string;
|
|
83
|
+
bytes: Uint8Array;
|
|
84
|
+
kind: ImageKind;
|
|
85
|
+
}): Promise<SavedImage>;
|
|
86
|
+
/** Delete one upload by file name. False when there is no such upload. */
|
|
87
|
+
remove(filename: string): Promise<boolean>;
|
|
88
|
+
}
|
|
89
|
+
interface VideoStore {
|
|
90
|
+
list(): Promise<ListedVideo[]>;
|
|
91
|
+
save(input: {
|
|
92
|
+
originalName: string;
|
|
93
|
+
bytes: Uint8Array;
|
|
94
|
+
kind: VideoKind;
|
|
95
|
+
}): Promise<SavedVideo>;
|
|
96
|
+
remove(filename: string): Promise<boolean>;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/git-types.d.ts
|
|
100
|
+
type ChangeStatus = 'added' | 'modified' | 'deleted' | 'renamed' | 'untracked';
|
|
101
|
+
interface ChangedFile {
|
|
102
|
+
/** Path relative to the project root, with `/` separators. */
|
|
103
|
+
path: string;
|
|
104
|
+
status: ChangeStatus;
|
|
105
|
+
}
|
|
106
|
+
interface GitInfo {
|
|
107
|
+
/** The `git` option is on. */
|
|
108
|
+
enabled: boolean;
|
|
109
|
+
/** The project is inside a git work tree. */
|
|
110
|
+
repo: boolean;
|
|
111
|
+
branch?: string;
|
|
112
|
+
files: ChangedFile[];
|
|
113
|
+
}
|
|
114
|
+
/** What the editor needs from a version-control backend. Absent on the context means Commit changes is off. */
|
|
115
|
+
interface GitPort {
|
|
116
|
+
info(): Promise<GitInfo>;
|
|
117
|
+
commit(message: string, paths?: readonly string[]): Promise<{
|
|
118
|
+
commit: string;
|
|
119
|
+
files: number;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/api-types.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* Request and response bodies of the dev editor API (`/__bearminion/api`). The server handlers and the
|
|
126
|
+
* overlay's client both use these, so a changed shape is a type error on both sides.
|
|
127
|
+
*/
|
|
128
|
+
/** Every error response. `issues` is present on schema validation failures. */
|
|
129
|
+
interface ApiProblem {
|
|
130
|
+
error: string;
|
|
131
|
+
message: string;
|
|
132
|
+
issues?: ApiIssue[];
|
|
133
|
+
}
|
|
134
|
+
/** One validation failure: a dotted path into the document and a message. */
|
|
135
|
+
interface ApiIssue {
|
|
136
|
+
path: string;
|
|
137
|
+
message: string;
|
|
138
|
+
/** Present on `POST /save`, which validates the page and the site together. */
|
|
139
|
+
file?: 'page' | 'site';
|
|
140
|
+
}
|
|
141
|
+
/** `GET /pages`. */
|
|
142
|
+
interface PageListItem {
|
|
143
|
+
slug: string;
|
|
144
|
+
title: string;
|
|
145
|
+
/** File name inside the pages directory. */
|
|
146
|
+
file: string;
|
|
147
|
+
system?: boolean;
|
|
148
|
+
anchors?: string[];
|
|
149
|
+
}
|
|
150
|
+
/** `GET /images` entries and the body of a successful `POST /images`. */
|
|
151
|
+
interface UploadedImage {
|
|
152
|
+
filename: string;
|
|
153
|
+
/** Project-relative path, the value image fields store. */
|
|
154
|
+
path: string;
|
|
155
|
+
bytes?: number;
|
|
156
|
+
}
|
|
157
|
+
/** `GET /videos` entries and the body of a successful `POST /videos`. */
|
|
158
|
+
interface UploadedVideo {
|
|
159
|
+
filename: string;
|
|
160
|
+
/** Project-relative path of the file. */
|
|
161
|
+
path: string;
|
|
162
|
+
/** What a Media section's `video` field holds, such as `/videos/demo-1a2b3c4d.mp4`. */
|
|
163
|
+
url: string;
|
|
164
|
+
bytes?: number;
|
|
165
|
+
}
|
|
166
|
+
/** `GET /history/site` and `GET /history/pages/:slug` entries. */
|
|
167
|
+
interface HistoryEntry {
|
|
168
|
+
id: string;
|
|
169
|
+
at: string;
|
|
170
|
+
}
|
|
171
|
+
/** `POST /save`. At least one of `page` and `site`. */
|
|
172
|
+
interface SaveRequest<TPage = unknown, TSite = unknown> {
|
|
173
|
+
page?: {
|
|
174
|
+
/** Slug the page is stored under now. When `document.slug` differs, the page is renamed (or made home). */
|
|
175
|
+
from: string;
|
|
176
|
+
document: TPage;
|
|
177
|
+
/** Where the current home page moves when this page becomes `index`. Required when a home page exists. */
|
|
178
|
+
previousHomeSlug?: string;
|
|
179
|
+
};
|
|
180
|
+
site?: TSite;
|
|
181
|
+
}
|
|
182
|
+
/** `POST /save` response: the documents as stored. */
|
|
183
|
+
interface SaveResponse<TPage = unknown, TSite = unknown> {
|
|
184
|
+
page?: TPage;
|
|
185
|
+
site?: TSite;
|
|
186
|
+
}
|
|
187
|
+
/** `POST /pages`. `template` is a section type or the slug of a page to copy. */
|
|
188
|
+
interface CreatePageRequest {
|
|
189
|
+
slug: string;
|
|
190
|
+
title: string;
|
|
191
|
+
template?: string;
|
|
192
|
+
}
|
|
193
|
+
/** `POST /git/commit`. */
|
|
194
|
+
interface CommitRequest {
|
|
195
|
+
message: string;
|
|
196
|
+
paths?: string[];
|
|
197
|
+
}
|
|
198
|
+
interface CommitResult {
|
|
199
|
+
commit: string;
|
|
200
|
+
files: number;
|
|
201
|
+
}
|
|
202
|
+
/** `POST /preview/site`. */
|
|
203
|
+
interface SitePreview {
|
|
204
|
+
header: string;
|
|
205
|
+
footer: string;
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/history-types.d.ts
|
|
209
|
+
type HistoryScope = 'page' | 'site';
|
|
210
|
+
/** Local copies of what was saved, so an earlier version can be loaded back into the draft. */
|
|
211
|
+
interface HistoryPort {
|
|
212
|
+
/** Newest first. */
|
|
213
|
+
list(scope: HistoryScope, slug?: string): Promise<HistoryEntry[]>;
|
|
214
|
+
read(scope: HistoryScope, slug: string, id: string): Promise<unknown | null>;
|
|
215
|
+
/** Never throws: history must not block a save. */
|
|
216
|
+
write(scope: HistoryScope, slug: string, value: unknown): Promise<void>;
|
|
217
|
+
/** Before the first save of a page or the site, keep the file as it was so even that first save can be undone. */
|
|
218
|
+
ensureBaseline(scope: HistoryScope, slug: string, current: unknown): Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/upload-rules.d.ts
|
|
222
|
+
/** Re-encode uploads in the browser before they are sent. */
|
|
223
|
+
interface ImageConvertOptions {
|
|
224
|
+
to: 'webp';
|
|
225
|
+
/** Wider images are scaled down to this width, never up. Default: no width cap. */
|
|
226
|
+
maxWidth?: number;
|
|
227
|
+
/** WebP quality, 0.1 to 1. Default 0.82. */
|
|
228
|
+
quality?: number;
|
|
229
|
+
}
|
|
230
|
+
/** What the browser needs to know before it sends a file. */
|
|
231
|
+
interface UploadRules {
|
|
232
|
+
maxBytes: number;
|
|
233
|
+
convert: {
|
|
234
|
+
to: 'webp';
|
|
235
|
+
maxWidth: number | null;
|
|
236
|
+
quality: number;
|
|
237
|
+
} | null;
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/editor-context.d.ts
|
|
241
|
+
interface EditorContext {
|
|
242
|
+
root: string;
|
|
243
|
+
contentDir: string;
|
|
244
|
+
uploadsDir: string;
|
|
245
|
+
videosDir: string;
|
|
246
|
+
maxVideoBytes: number;
|
|
247
|
+
maxImageBytes: number;
|
|
248
|
+
pageRules: PageRules;
|
|
249
|
+
/** `imageConvert`, validated and with its defaults filled in. `null` when conversion is off. */
|
|
250
|
+
imageConvert: UploadRules['convert'];
|
|
251
|
+
sections: SectionRegistry;
|
|
252
|
+
site: SiteDefinition;
|
|
253
|
+
theme: ThemeDefinition;
|
|
254
|
+
store: ContentStore;
|
|
255
|
+
/** Upgrades files written under an older `schemaVersion` and stamps the current one on write. */
|
|
256
|
+
migrator: ContentMigrator;
|
|
257
|
+
/** Commit changes is enabled. */
|
|
258
|
+
git: boolean;
|
|
259
|
+
/** The folder with the site's form handlers, or `null` when the `forms` option turns them off. */
|
|
260
|
+
formsDir?: string | null;
|
|
261
|
+
/**
|
|
262
|
+
* Undo history. The local editor keeps copies of what was saved in `.editor/history/`; a hosted editor has none,
|
|
263
|
+
* because the repository is the history.
|
|
264
|
+
*/
|
|
265
|
+
history?: HistoryPort;
|
|
266
|
+
/** Commit changes, when `git` is on and the project is a local git work tree. */
|
|
267
|
+
commits?: GitPort;
|
|
268
|
+
/** The file of the form handler `name` in the site, or `null` when there is none. Local projects only. */
|
|
269
|
+
formFile?: (name: string) => string | null;
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
export { ContentStore as _, CommitRequest as a, HistoryEntry as c, SaveResponse as d, SitePreview as f, GitInfo as g, ChangedFile as h, ApiProblem as i, PageListItem as l, UploadedVideo as m, ImageConvertOptions as n, CommitResult as o, UploadedImage as p, ApiIssue as r, CreatePageRequest as s, EditorContext as t, SaveRequest as u, StoreOperation as v, UploadStore as y };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { _ as ContentStore } from "./editor-context-CTfxXtny.js";
|
|
2
|
+
//#region src/store-error.d.ts
|
|
3
|
+
/** A key that is empty, absolute or leaves the content directory. */
|
|
4
|
+
declare class StoreKeyError extends Error {
|
|
5
|
+
constructor(key: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A store that could not do what was asked, for a reason the person editing can act on (a refused token, a protected
|
|
9
|
+
* branch, a branch that moved). The editor API answers it with `status` and `code`, so the message reaches the page
|
|
10
|
+
* instead of becoming a bare 500.
|
|
11
|
+
*/
|
|
12
|
+
declare class StoreError extends Error {
|
|
13
|
+
readonly status: number;
|
|
14
|
+
readonly code: string;
|
|
15
|
+
constructor(status: number, code: string, message: string);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/github-store.d.ts
|
|
19
|
+
interface GithubStoreOptions {
|
|
20
|
+
/** `owner/name`. */
|
|
21
|
+
repo: string;
|
|
22
|
+
/**
|
|
23
|
+
* A token that may write to the repository: a fine-grained personal access token with "Contents: Read and write" on
|
|
24
|
+
* this one repository. Keep it in the environment, never in a file the repository tracks.
|
|
25
|
+
*/
|
|
26
|
+
token: string;
|
|
27
|
+
/** The branch edits are committed to. Default: the repository's default branch. */
|
|
28
|
+
branch?: string;
|
|
29
|
+
/** The folder of the site inside the repository. Default: the repository root. */
|
|
30
|
+
rootDir?: string;
|
|
31
|
+
/** The content folder, relative to `rootDir`. Default `content`. */
|
|
32
|
+
contentDir?: string;
|
|
33
|
+
/** The folder uploaded images go to, relative to `rootDir`. Default `src/assets/uploads`. */
|
|
34
|
+
uploadsDir?: string;
|
|
35
|
+
/** The commit message for a change. Default: `Update pages/about.json`, `Update 3 files`, `Upload photo-1a2b3c4d.jpg`. */
|
|
36
|
+
message?: (change: {
|
|
37
|
+
written: readonly string[];
|
|
38
|
+
removed: readonly string[];
|
|
39
|
+
}) => string;
|
|
40
|
+
/**
|
|
41
|
+
* `direct` (default): a save is a commit on `branch`. `pr`: a save is a commit on a branch of its own for the entry
|
|
42
|
+
* being edited, with a pull request opened on the first save. Nothing here ever merges. Needs "Pull requests: Read
|
|
43
|
+
* and write" besides "Contents: Read and write".
|
|
44
|
+
*/
|
|
45
|
+
mode?: 'direct' | 'pr';
|
|
46
|
+
/** `pr` mode: the title and body of the pull request opened for an entry. */
|
|
47
|
+
pullRequest?: (change: {
|
|
48
|
+
scope: string;
|
|
49
|
+
written: readonly string[];
|
|
50
|
+
removed: readonly string[];
|
|
51
|
+
}) => {
|
|
52
|
+
title: string;
|
|
53
|
+
body: string;
|
|
54
|
+
};
|
|
55
|
+
/** `pr` mode: the label put on the pull requests. Default `bearminion`; `false` for none. */
|
|
56
|
+
label?: string | false;
|
|
57
|
+
/** The GitHub API. Default `https://api.github.com`. Set it for GitHub Enterprise. */
|
|
58
|
+
apiUrl?: string;
|
|
59
|
+
/** Default: the global `fetch`. */
|
|
60
|
+
fetch?: typeof fetch;
|
|
61
|
+
}
|
|
62
|
+
declare function githubStore(options: GithubStoreOptions): ContentStore;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { StoreKeyError as i, githubStore as n, StoreError as r, GithubStoreOptions as t };
|