@bright-logic-digital/site-editor 0.0.0-stage → 1.0.0-rc.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +4 -0
  3. package/README.md +318 -2
  4. package/bin/cli.js +92 -0
  5. package/bin/copy-editor.js +211 -0
  6. package/bin/node-version.js +20 -0
  7. package/bin/site-config.js +46 -0
  8. package/bin/site-editor.js +16 -0
  9. package/editor/admin.css +438 -0
  10. package/editor/api.js +138 -0
  11. package/editor/app.js +1178 -0
  12. package/editor/asset-map.js +38 -0
  13. package/editor/boot.js +72 -0
  14. package/editor/copy.js +239 -0
  15. package/editor/drafts.js +67 -0
  16. package/editor/format.js +80 -0
  17. package/editor/forms.js +918 -0
  18. package/editor/images.js +212 -0
  19. package/editor/index.html +27 -0
  20. package/editor/model.js +152 -0
  21. package/editor/pages.js +297 -0
  22. package/editor/photos.js +232 -0
  23. package/editor/publish.js +45 -0
  24. package/editor/shared/rules.js +118 -0
  25. package/editor/shared/site.js +128 -0
  26. package/editor/shared/validate.js +303 -0
  27. package/editor/signin.js +154 -0
  28. package/editor/status.js +90 -0
  29. package/editor/uploads.js +91 -0
  30. package/guide/check.js +233 -0
  31. package/hosts/next.js +19 -0
  32. package/hosts/pages.js +20 -0
  33. package/hosts/shared.js +42 -0
  34. package/package.json +91 -4
  35. package/server/blob-sha.js +10 -0
  36. package/server/changes.js +24 -0
  37. package/server/check-content.js +197 -0
  38. package/server/config.js +97 -0
  39. package/server/dispatch.js +207 -0
  40. package/server/github.js +149 -0
  41. package/server/handlers.js +364 -0
  42. package/server/index.js +153 -0
  43. package/server/local-repo.js +171 -0
  44. package/server/mapped-repo.js +48 -0
  45. package/server/memory-repo.js +104 -0
  46. package/server/path-map.js +26 -0
  47. package/server/signin/access.js +329 -0
  48. package/server/signin/code-store.sql +60 -0
  49. package/server/signin/code.js +192 -0
  50. package/server/signin/codes.js +171 -0
  51. package/server/signin/refusal.js +76 -0
  52. package/server/signin/session.js +90 -0
  53. package/tests/fixtures/image-files.json +14 -0
  54. package/tests/fixtures/slugs.json +202 -0
  55. package/tests/fixtures/validation.json +12734 -0
  56. package/types/bin/cli.d.ts +1 -0
  57. package/types/bin/copy-editor.d.ts +32 -0
  58. package/types/bin/node-version.d.ts +8 -0
  59. package/types/bin/site-config.d.ts +17 -0
  60. package/types/bin/site-editor.d.ts +2 -0
  61. package/types/editor/api.d.ts +37 -0
  62. package/types/editor/copy.d.ts +153 -0
  63. package/types/editor/shared/rules.d.ts +33 -0
  64. package/types/editor/shared/site.d.ts +35 -0
  65. package/types/editor/shared/validate.d.ts +19 -0
  66. package/types/guide/check.d.ts +31 -0
  67. package/types/hosts/next.d.ts +12 -0
  68. package/types/hosts/pages.d.ts +9 -0
  69. package/types/hosts/shared.d.ts +21 -0
  70. package/types/server/blob-sha.d.ts +1 -0
  71. package/types/server/changes.d.ts +2 -0
  72. package/types/server/check-content.d.ts +16 -0
  73. package/types/server/config.d.ts +46 -0
  74. package/types/server/dispatch.d.ts +51 -0
  75. package/types/server/github.d.ts +27 -0
  76. package/types/server/handlers.d.ts +116 -0
  77. package/types/server/index.d.ts +75 -0
  78. package/types/server/local-repo.d.ts +16 -0
  79. package/types/server/mapped-repo.d.ts +10 -0
  80. package/types/server/memory-repo.d.ts +28 -0
  81. package/types/server/path-map.d.ts +3 -0
  82. package/types/server/signin/access.d.ts +68 -0
  83. package/types/server/signin/code.d.ts +44 -0
  84. package/types/server/signin/codes.d.ts +98 -0
  85. package/types/server/signin/refusal.d.ts +122 -0
  86. package/types/server/signin/session.d.ts +29 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Why copy may not empty out, as a sentence naming it, or null when it may:
3
+ * out does not exist, is an empty folder (or holds only an unfinished
4
+ * temporary marker), or holds the site-config.json of an earlier copy.
5
+ * @param {string} out
6
+ * @returns {string | null}
7
+ */
8
+ export function destinationProblem(out: string): string | null;
9
+ /**
10
+ * The editor's page with title put in its one <title> element, escaped, so
11
+ * the tab shows the site's name from the first paint.
12
+ * @param {string} html
13
+ * @param {string} title
14
+ * @returns {string}
15
+ */
16
+ export function stampTitle(html: string, title: string): string;
17
+ /**
18
+ * Copy the editor for the site whose config file is configFile into out.
19
+ * Checks everything before it changes anything; throws a CommandError,
20
+ * having changed nothing, when it cannot copy.
21
+ * @param {{ configFile: string, out: string }} options
22
+ * @returns {Promise<{ out: string, version: string }>} out: its absolute path
23
+ */
24
+ export function copyEditor({ configFile, out }: {
25
+ configFile: string;
26
+ out: string;
27
+ }): Promise<{
28
+ out: string;
29
+ version: string;
30
+ }>;
31
+ /** Where the new site-config.json is written before it is renamed into place. */
32
+ export const TEMP_MARKER: "site-config.json.partial";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The sentence to print when version (process.versions.node, such as
3
+ * "24.22.1") is older than the command needs, or null when it is fine. A
4
+ * version that cannot be read counts as too old.
5
+ * @param {string} version
6
+ * @returns {string | null}
7
+ */
8
+ export function tooOldSentence(version: string): string | null;
@@ -0,0 +1,17 @@
1
+ /** The version in the package's own package.json. */
2
+ export function packageVersion(): string;
3
+ /**
4
+ * The site's config file (an ES module whose default export is the config),
5
+ * loaded and checked. Throws a CommandError naming the file, and the keys
6
+ * that are wrong, when it cannot be used.
7
+ * @param {string} configFile as given on the command line
8
+ * @returns {Promise<{ config: SiteConfig, file: string }>} file: its absolute path
9
+ */
10
+ export function loadSiteConfig(configFile: string): Promise<{
11
+ config: SiteConfig;
12
+ file: string;
13
+ }>;
14
+ /** @typedef {import("../server/signin/refusal.js").SiteConfig} SiteConfig */
15
+ export class CommandError extends Error {
16
+ }
17
+ export type SiteConfig = import("../server/signin/refusal.js").SiteConfig;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,37 @@
1
+ /** `timers` ({setTimeout, clearTimeout}) is passed in so tests need not wait.
2
+ * `signIn` is the site config's: "code" (the editor's own sign-in) or
3
+ * "access" (a sign-in in front of the site). */
4
+ export function createApi(fetch: any, timers?: typeof globalThis, { signIn }?: {
5
+ signIn?: string | undefined;
6
+ }): {
7
+ state: () => Promise<any>;
8
+ doc: (path: any) => Promise<any>;
9
+ publish: (body: any) => Promise<any>;
10
+ status: (mine: any, deployed: any) => Promise<any>;
11
+ upload: (name: any, base64: any) => Promise<any>;
12
+ deployed(): Promise<any>;
13
+ /** Sign-in by emailed code; verify sets the session cookie. */
14
+ session: {
15
+ request: (email: any) => Promise<any>;
16
+ verify: (email: any, code: any) => Promise<any>;
17
+ signOut: () => Promise<any>;
18
+ };
19
+ };
20
+ export class ApiError extends Error {
21
+ constructor({ status, code, message, problems, paths }: {
22
+ status?: number | undefined;
23
+ code: any;
24
+ message: any;
25
+ problems: any;
26
+ paths: any;
27
+ });
28
+ status: number;
29
+ code: any;
30
+ problems: any;
31
+ paths: any;
32
+ }
33
+ export class SessionExpired extends Error {
34
+ constructor();
35
+ }
36
+ /** A photo file of up to 2 MB, sent from a phone on a slow connection. */
37
+ export const UPLOAD_TIMEOUT_MS: number;
@@ -0,0 +1,153 @@
1
+ /** Called by configureSite (shared/site.js) with the site's config, and by
2
+ * nothing else: a site's wording is set only with the rest of its config. */
3
+ export function configureText(site: any): void;
4
+ /** What to show for a failed request: {text, actions}, plus `detail`, a
5
+ * second sentence, where one is needed. `actions` names the choices to
6
+ * offer, from ACTIONS. With `loading`, the request was reading, not saving.
7
+ * The server's own message is never shown. */
8
+ export function errorView(error: any, { loading }?: {
9
+ loading?: boolean | undefined;
10
+ }): {
11
+ text: any;
12
+ actions: any[];
13
+ detail?: undefined;
14
+ } | {
15
+ text: any;
16
+ detail: any;
17
+ actions: any[];
18
+ };
19
+ /** Who the owner is told to tell when something needs a person: the site
20
+ * config's `developer`, unless it sets one. */
21
+ export const DEFAULT_DEVELOPER: "your web developer";
22
+ /** The keys of the editor's words that only one kind of sign-in (the site
23
+ * config's signIn) ever shows: the emailed-code screens and the Sign out
24
+ * button belong to "code"; the message for a sign-in in front of the site
25
+ * that could not be confirmed belongs to "access". Every other key is shown
26
+ * under both. Nothing at run time reads this; guide/check.js does. */
27
+ export const SIGN_IN_KEYS: Readonly<{
28
+ code: readonly string[];
29
+ access: readonly string[];
30
+ }>;
31
+ export let TEXT: Readonly<{
32
+ publishing: "Publishing. This takes about a minute.";
33
+ loading: "Loading";
34
+ homeHeading: "Your pages";
35
+ homeIntro: "Choose a page to change its words. Nothing changes on the site until you publish.";
36
+ unpublished: "Unpublished changes";
37
+ back: "Back to all pages";
38
+ publish: "Publish";
39
+ seePage: "See the page";
40
+ restored: "Your unpublished changes from last time are back.";
41
+ timeout: `Your change is saved but is not showing on the site yet. Please let ${any} know.`;
42
+ signedOut: "You've been signed out. Your changes are safe.";
43
+ stale: "This page was changed somewhere else.";
44
+ staleKeep: "If you keep your changes, they will replace the other change when you publish.";
45
+ connection: "Couldn't save. Check your connection and try again.";
46
+ connectionLoading: "Couldn't load. Check your connection and try again.";
47
+ serverSide: string;
48
+ unconfirmed: string;
49
+ wrongHost: "Use the editor at";
50
+ crashed: string;
51
+ notSetUp: `The editor isn't set up for you yet. Please let ${any} know.`;
52
+ invalid: `The site would not accept this page as it is. Please let ${any} know.`;
53
+ tooLarge: `This page is too big to publish in one go. Please let ${any} know.`;
54
+ notFound: "This page can't be found on the site any more. Go back and choose it again.";
55
+ storageRefused: "Your changes can't be kept if you close this page. Publish before you leave.";
56
+ formatHint: string;
57
+ formatHintAccent: string;
58
+ formatRefused: "Select plain words first, without * or [ ] in them.";
59
+ linkOneLine: "A link has to be on one line. Select words on a single line.";
60
+ dismiss: "Dismiss";
61
+ openFailed: "Open the page";
62
+ bold: "Bold";
63
+ italic: "Italic";
64
+ colour: "Colour";
65
+ link: "Link";
66
+ describePhoto: "Describe this photo";
67
+ describePhotoHelp: "Read out to people who cannot see the photo.";
68
+ noPhoto: "No photo to show";
69
+ photoComing: "This photo is being added to the site. It will show here in a minute.";
70
+ chooseOne: "Choose one";
71
+ moveUp: "Move up";
72
+ moveDown: "Move down";
73
+ remove: "Remove";
74
+ confirmYes: "Yes, remove";
75
+ confirmNo: "Keep it";
76
+ replacePhoto: "Replace photo";
77
+ choosePhoto: "Choose photo";
78
+ preparingPhoto: "Preparing photo…";
79
+ pickAgain: "Pick your new photo again.";
80
+ keepCurrentPhoto: "Keep the current photo";
81
+ photoNotSaved: "That photo could not be saved. Pick it again.";
82
+ removePhoto: "Remove photo";
83
+ discardAsk: "Throw away your changes to this page?";
84
+ discardYes: "Yes, discard";
85
+ discardNo: "Keep editing";
86
+ extraPages: "Extra pages";
87
+ notPublishedYet: "Not published yet";
88
+ addPage: "Add a page";
89
+ newPageTitle: "Page title";
90
+ addressFixed: "This can't be changed later.";
91
+ createPage: "Create page";
92
+ cancel: "Cancel";
93
+ pageCap: "You have 30 extra pages, the most the site allows. Delete one to add another.";
94
+ cannotKeepNewPage: string;
95
+ discardNewAsk: "Throw away this page? It has never been published, so it will be gone.";
96
+ deletePage: "Delete this page";
97
+ deleteYes: "Yes, delete it";
98
+ deleteNo: "Keep the page";
99
+ deleteChanged: "This page was changed somewhere else. Check it, then delete it if you still want to.";
100
+ deleteChangedLost: string;
101
+ deletedElsewhere: "This page was deleted somewhere else.";
102
+ badAddress: "That page address can't be used. Delete this page and add it again with a different title.";
103
+ tooManyPages: "The site can hold 30 extra pages. Delete one before adding another.";
104
+ signInHeading: "Sign in";
105
+ signInIntro: "Enter your email address and we'll email you a code to sign in with.";
106
+ emailLabel: "Email address";
107
+ sendCode: "Email me a code";
108
+ codeLabel: "Code";
109
+ signIn: "Sign in";
110
+ sendNewCode: "Send a new code";
111
+ otherAddress: "Use a different address";
112
+ newCodeSent: "We sent a new code. Use the newest one.";
113
+ enterEmail: "Enter your email address.";
114
+ enterCode: "Enter the code from the email.";
115
+ signOut: "Sign out";
116
+ }>;
117
+ export let STATUS: Readonly<{
118
+ saving: "Saving";
119
+ publishing: any;
120
+ live: "Live";
121
+ }>;
122
+ /** Why a picked photo cannot be used, by ImageError code (see images.js). */
123
+ export const PHOTO_ERRORS: Readonly<{
124
+ cannot_read: string;
125
+ too_big: "That file is over 25 MB. Pick a smaller photo.";
126
+ too_small: "That photo is too small. It needs to be at least 700 pixels wide.";
127
+ too_heavy: "That photo is too detailed to upload. Try a different photo.";
128
+ }>;
129
+ /** The labels of the actions errorView names. */
130
+ export const ACTIONS: Readonly<{
131
+ signin: "Sign in again";
132
+ retry: "Retry";
133
+ keep: "Keep my changes";
134
+ discard: "Discard my changes";
135
+ reload: "Reload";
136
+ }>;
137
+ export function itemName(itemLabel: any, n: any): string;
138
+ export function itemKindName(itemLabel: any, n: any, kindLabel: any): string;
139
+ export function addLabel(itemLabel: any): string;
140
+ export function addKindLabel(kindLabel: any): string;
141
+ export function moveUpName(itemLabel: any, n: any): string;
142
+ export function moveDownName(itemLabel: any, n: any): string;
143
+ export function removeName(itemLabel: any, n: any): string;
144
+ export function confirmRemove(itemLabel: any, n: any): string;
145
+ export function characters(n: any, max: any): string;
146
+ export function failedElsewhere(label: any, text: any): string;
147
+ export function notDeleted(title: any, text: any): string;
148
+ export function newPageAddress(host: any, slug: any): string;
149
+ export function editorVersion(version: any): string;
150
+ export function codeSent(address: any): string;
151
+ export function deleteAsk(title: any): string;
152
+ export function uploadingPhoto(n: any, total: any): string;
153
+ export function problemCount(n: any): string;
@@ -0,0 +1,33 @@
1
+ /** Addresses of link attempts that would not become a link: a label with
2
+ * nothing visible in it, an address that may not be used, or an attempt that
3
+ * is not a complete link. Reads at most 200 characters past each attempt. */
4
+ export function badLinks(text: any): string[];
5
+ /** True when slug can be a new simple page's address. taken: a Set of the
6
+ * addresses other pages already have. */
7
+ export function isUsableSlug(slug: any, taken: any): boolean;
8
+ /** An address made from a title: plain a-z0-9 words joined by "-", accents
9
+ * and apostrophes dropped ("Matt's" is "matts"). Empty when nothing in the
10
+ * title can be kept. */
11
+ export function slugify(title: any): string;
12
+ /** A usable address for a page with this title: its slug, or that slug with
13
+ * "-2", "-3", ... until it is free; "page" when the title gives nothing,
14
+ * and "page-" in front of one that would start with "admin".
15
+ * Never reserved, taken, empty, under the sign-in or longer than MAX_SLUG.
16
+ * The loop ends: the base is never under the sign-in, so a numbered form of
17
+ * it is never reserved or under the sign-in, and only `taken` can refuse
18
+ * one, which holds finitely many. */
19
+ export function uniqueSlug(title: any, taken: any): string;
20
+ export const ALLOWED_URL_PREFIXES: string[];
21
+ export const DOC_PATH_RE: RegExp;
22
+ export const UPLOAD_NAME_RE: RegExp;
23
+ export const SHA_RE: RegExp;
24
+ /** A whole-string match: "$" without the m flag does not match before a
25
+ * final line break, unlike Python's. */
26
+ export const SLUG_RE: RegExp;
27
+ export const MAX_SLUG: 60;
28
+ export function reservedNames(): readonly string[];
29
+ /** The editor's sign-in covers every path that starts with this, so a page
30
+ * there would be hidden from visitors. */
31
+ export const SIGN_IN_PREFIX: "admin";
32
+ /** The most simple pages the site may hold. */
33
+ export const MAX_CUSTOM_PAGES: 30;
@@ -0,0 +1,35 @@
1
+ /** The names of the keys in values that are unknown or malformed, in the
2
+ * order given: "text.<key>" for a sentence that is not the editor's or is
3
+ * not words. Judges the browser keys only; give it browserConfig(config). */
4
+ export function siteProblems(values: any): string[];
5
+ /** A new object holding only the browser keys present in config. */
6
+ export function browserConfig(config: any): {};
7
+ /** Make values the site's config, starting again from the defaults. Throws,
8
+ * changing nothing, when siteProblems finds any. */
9
+ export function configureSite(values: any): void;
10
+ export const SITE_DEFAULTS: Readonly<{
11
+ title: "Website editor";
12
+ signIn: "code";
13
+ trailingSlash: false;
14
+ photos: "key";
15
+ reserved: readonly never[];
16
+ bareHost: null;
17
+ editorAddress: null;
18
+ liveWaitMs: 360000;
19
+ developer: "your web developer";
20
+ text: Readonly<{}>;
21
+ }>;
22
+ /** The keys the browser's config holds; a site's config file holds more. */
23
+ export const BROWSER_KEYS: readonly string[];
24
+ export let SITE: Readonly<{
25
+ title: "Website editor";
26
+ signIn: "code";
27
+ trailingSlash: false;
28
+ photos: "key";
29
+ reserved: readonly never[];
30
+ bareHost: null;
31
+ editorAddress: null;
32
+ liveWaitMs: 360000;
33
+ developer: "your web developer";
34
+ text: Readonly<{}>;
35
+ }>;
@@ -0,0 +1,19 @@
1
+ export function docTypeForPath(path: any): string | null;
2
+ /** True when field exists in obj: it has no `when`, or its sibling holds
3
+ * one of the listed values. */
4
+ export function applies(field: any, obj: any): boolean;
5
+ /** The most characters a text or textarea field may hold. */
6
+ export function textLimit(field: any): any;
7
+ /** Problems with doc, as [{field, code, message}]. Empty when it is valid. */
8
+ export function validateDoc(schema: any, docType: any, doc: any): any[];
9
+ /** Every image object in doc, in field order. */
10
+ export function collectImages(schema: any, docType: any, doc: any): any[];
11
+ /** Repo-relative paths of every file of the image, in width order. */
12
+ export function imageFiles(image: any): any;
13
+ export function emptyValue(field: any): any;
14
+ /** A document with every field present and empty. */
15
+ export function emptyDoc(schema: any, docType: any): {};
16
+ export const BAD_CHAR: RegExp;
17
+ export const IMAGE_BASE: RegExp;
18
+ /** The most characters a photo description may hold. */
19
+ export const ALT_MAX: 200;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The problems with a site's guide, one plain sentence each; empty when the
3
+ * guide agrees with the editor. Reads the editor's words under the site's
4
+ * config (its reworded sentences, its sign-in) and leaves the editor's site
5
+ * config (SITE) as it was.
6
+ * @param {string} html the guide's page
7
+ * @param {Record<string, any>} config the site's config file
8
+ * @param {Schema} schema the site's content/schema.json
9
+ * @param {{ minLabels?: number }} [options] minLabels: the fewest editor
10
+ * words the guide must quote, 30 unless a site's guide is short
11
+ * @returns {string[]}
12
+ */
13
+ export function guideProblems(html: string, config: Record<string, any>, schema: Schema, { minLabels }?: {
14
+ minLabels?: number;
15
+ }): string[];
16
+ export type Field = {
17
+ label?: string;
18
+ itemLabel?: string;
19
+ type?: string;
20
+ fixed?: boolean;
21
+ options?: Array<{
22
+ label: string;
23
+ }>;
24
+ fields?: Field[];
25
+ };
26
+ export type Schema = {
27
+ documents: Record<string, {
28
+ label: string;
29
+ fields: Field[];
30
+ }>;
31
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @param {import("./shared.js").HostOptions} options
3
+ * createEditorApi's options, or a function that gives them
4
+ */
5
+ export function createNextRoute(options: import("./shared.js").HostOptions): {
6
+ GET: (request: Request) => Promise<Response>;
7
+ HEAD: (request: Request) => Promise<Response>;
8
+ POST: (request: Request) => Promise<Response>;
9
+ PUT: (request: Request) => Promise<Response>;
10
+ PATCH: (request: Request) => Promise<Response>;
11
+ DELETE: (request: Request) => Promise<Response>;
12
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @param {import("./shared.js").HostOptions} options
3
+ * createEditorApi's options, or a function that gives them
4
+ * @returns {(context: { request: Request, env: Record<string, string | undefined> }) => Promise<Response>}
5
+ */
6
+ export function createPagesFunction(options: import("./shared.js").HostOptions): (context: {
7
+ request: Request;
8
+ env: Record<string, string | undefined>;
9
+ }) => Promise<Response>;
@@ -0,0 +1,21 @@
1
+ /** @typedef {import("../server/index.js").EditorApiOptions} EditorApiOptions */
2
+ /**
3
+ * The options, or a function that gives them (so a site can build its code
4
+ * store or local repository only when the first request arrives).
5
+ * @typedef {EditorApiOptions | (() => EditorApiOptions)} HostOptions
6
+ */
7
+ /**
8
+ * A handler that builds the API once, on its first request, and then
9
+ * hands it every request. If building throws (a wrong config, say), the
10
+ * answer is the dispatcher's fixed 500 and the log gets the message only;
11
+ * the next request tries again.
12
+ * @param {HostOptions} options
13
+ * @returns {(request: Request, env: Record<string, string | undefined>) => Promise<Response>}
14
+ */
15
+ export function lazyApi(options: HostOptions): (request: Request, env: Record<string, string | undefined>) => Promise<Response>;
16
+ export type EditorApiOptions = import("../server/index.js").EditorApiOptions;
17
+ /**
18
+ * The options, or a function that gives them (so a site can build its code
19
+ * store or local repository only when the first request arrives).
20
+ */
21
+ export type HostOptions = EditorApiOptions | (() => EditorApiOptions);
@@ -0,0 +1 @@
1
+ export function blobSha(input: any): Promise<string>;
@@ -0,0 +1,2 @@
1
+ /** Throws a TypeError naming the first problem with changes. */
2
+ export function checkChanges(changes: any): void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Problems with the content under appDir, each naming the file and field.
3
+ * Empty when the content is ready to build. Judges extra pages' addresses
4
+ * by the config's reserved names; leaves the editor's site config (SITE) as
5
+ * it was.
6
+ * @param {string} appDir the folder paths.local is relative to
7
+ * @param {SiteConfig} config the site's config file
8
+ * @returns {string[]}
9
+ */
10
+ export function checkContent(appDir: string, config: SiteConfig): string[];
11
+ export type SiteConfig = import("./signin/refusal.js").SiteConfig;
12
+ export type Field = {
13
+ key: string;
14
+ type: string;
15
+ fields?: Field[];
16
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Trimmed, lower-cased address, or null when the input is not one.
3
+ * @param {unknown} input
4
+ * @returns {string | null}
5
+ */
6
+ export function normalizeEmail(input: unknown): string | null;
7
+ /**
8
+ * The NAMES of the settings that are missing or malformed, plus the guard's
9
+ * own words when it is what refuses. Never a value. Empty when the
10
+ * configuration is usable.
11
+ * @param {Env} env
12
+ * @param {ReadOptions} [options]
13
+ * @returns {string[]}
14
+ */
15
+ export function configProblems(env: Env, { liveBranchGuard }?: ReadOptions): string[];
16
+ /**
17
+ * The editor's configuration, or null unless every part is present and valid
18
+ * (exactly when configProblems is not empty). Values are not trimmed.
19
+ * @param {Env} env
20
+ * @param {ReadOptions} [options]
21
+ * @returns {AdminConfig | null}
22
+ */
23
+ export function readAdminConfig(env: Env, options?: ReadOptions): AdminConfig | null;
24
+ /**
25
+ * Local editing mode: true exactly when ADMIN_LOCAL is "1", NODE_ENV is not
26
+ * "production" (a missing NODE_ENV counts as not production) and VERCEL is
27
+ * unset or empty. So ADMIN_LOCAL must never be set on a deployed host.
28
+ * @param {Env} env
29
+ * @returns {boolean}
30
+ */
31
+ export function isLocalMode(env: Env): boolean;
32
+ export type AdminConfig = {
33
+ token: string;
34
+ repo: string;
35
+ branch: string;
36
+ emails: string[];
37
+ secret: string;
38
+ };
39
+ export type Env = Record<string, string | undefined>;
40
+ export type ReadOptions = {
41
+ /**
42
+ * "vercel" (the default):
43
+ * GITHUB_BRANCH may be main only when VERCEL_ENV is "production". null: no guard.
44
+ */
45
+ liveBranchGuard?: "vercel" | null | undefined;
46
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @param {Request} request
3
+ * @param {AdminDeps} deps
4
+ * @returns {Promise<Response>}
5
+ */
6
+ export function handleAdminRequest(request: Request, deps: AdminDeps): Promise<Response>;
7
+ /** The most characters a publish request's body may hold. */
8
+ export const MAX_PUBLISH_CHARS: 500000;
9
+ export type SignInProvider = import("./signin/refusal.js").SignInProvider;
10
+ export type SignInContext = import("./signin/refusal.js").SignInContext;
11
+ export type GithubSettings = import("./signin/refusal.js").GithubSettings;
12
+ export type SiteConfig = import("./signin/refusal.js").SiteConfig;
13
+ export type Repo = {
14
+ head: () => Promise<{
15
+ commit: string;
16
+ files: Map<string, string>;
17
+ }>;
18
+ readText: (sha: string) => Promise<string>;
19
+ createBlob: (base64: string) => Promise<string>;
20
+ commit: (input: {
21
+ parent: string;
22
+ changes: unknown[];
23
+ message: string;
24
+ }) => Promise<string>;
25
+ contains: (ancestor: string, descendant: string) => Promise<boolean>;
26
+ };
27
+ export type AdminDeps = {
28
+ /**
29
+ * the settings, for this request
30
+ */
31
+ env: Record<string, string | undefined>;
32
+ /**
33
+ * the site's config, already checked
34
+ */
35
+ config: SiteConfig;
36
+ signIn: SignInProvider;
37
+ /**
38
+ * the site's repository
39
+ */
40
+ repoFor: (settings: GithubSettings) => Repo;
41
+ now: () => number;
42
+ log: (line: string) => void;
43
+ /**
44
+ * set only when the site
45
+ * offers local mode; used only when the settings ask for it
46
+ */
47
+ local?: {
48
+ user: string;
49
+ repo: Repo;
50
+ } | undefined;
51
+ };
@@ -0,0 +1,27 @@
1
+ /** identity: { name, email } sent as author and committer, or null to send
2
+ * neither (GitHub then records the token's owner). userAgent: the site's
3
+ * own name for its requests (config.commit). */
4
+ export function createGithubRepo({ token, repo, branch, fetch, identity, userAgent }: {
5
+ token: any;
6
+ repo: any;
7
+ branch: any;
8
+ fetch: any;
9
+ identity?: null | undefined;
10
+ userAgent: any;
11
+ }): {
12
+ head: () => Promise<{
13
+ commit: string;
14
+ files: Map<any, any>;
15
+ }>;
16
+ readText: (sha: any) => Promise<string>;
17
+ createBlob: (base64: any) => Promise<string>;
18
+ commit: ({ parent, changes, message }: {
19
+ parent: any;
20
+ changes: any;
21
+ message: any;
22
+ }) => Promise<string>;
23
+ contains: (ancestor: any, descendant: any) => Promise<boolean>;
24
+ };
25
+ export class RepoMoved extends Error {
26
+ constructor(message?: string);
27
+ }