@brimsites/brimjs 0.0.0-stage → 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.
Files changed (238) hide show
  1. package/LICENSE +110 -0
  2. package/README.md +22 -2
  3. package/bin/brim.js +5 -0
  4. package/dist/cli.js +3802 -0
  5. package/editor-dist/editor.css +1 -0
  6. package/editor-dist/editor.js +91 -0
  7. package/package.json +71 -3
  8. package/skills/brim-convert/SKILL.md +256 -0
  9. package/skills/brim-hosting/SKILL.md +221 -0
  10. package/src/astro-shim.d.ts +5 -0
  11. package/src/auth/accounts.ts +341 -0
  12. package/src/auth/password.ts +34 -0
  13. package/src/auth/permissions.ts +44 -0
  14. package/src/blocks/accordion/Accordion.astro +48 -0
  15. package/src/blocks/accordion/accordion.css +63 -0
  16. package/src/blocks/analytics/Analytics.astro +45 -0
  17. package/src/blocks/analytics/ConsentBanner.astro +41 -0
  18. package/src/blocks/analytics/analytics.client.ts +125 -0
  19. package/src/blocks/analytics/analytics.css +51 -0
  20. package/src/blocks/analytics/consent.ts +51 -0
  21. package/src/blocks/button/Button.astro +64 -0
  22. package/src/blocks/button/button.css +100 -0
  23. package/src/blocks/carousel/Carousel.astro +140 -0
  24. package/src/blocks/carousel/carousel.client.ts +153 -0
  25. package/src/blocks/carousel/carousel.css +181 -0
  26. package/src/blocks/data/icons.ts +285 -0
  27. package/src/blocks/data/image-shapes.ts +91 -0
  28. package/src/blocks/data/social-icons.ts +41 -0
  29. package/src/blocks/data/social-networks.ts +256 -0
  30. package/src/blocks/divider/Divider.astro +27 -0
  31. package/src/blocks/divider/divider.css +17 -0
  32. package/src/blocks/form/Captcha.astro +27 -0
  33. package/src/blocks/form/Form.astro +250 -0
  34. package/src/blocks/form/FormField.astro +138 -0
  35. package/src/blocks/form/Newsletter.astro +80 -0
  36. package/src/blocks/form/form.client.ts +339 -0
  37. package/src/blocks/form/form.css +271 -0
  38. package/src/blocks/gallery/ImageGallery.astro +126 -0
  39. package/src/blocks/gallery/gallery.css +43 -0
  40. package/src/blocks/gallery/lightbox.client.ts +178 -0
  41. package/src/blocks/gallery/lightbox.css +134 -0
  42. package/src/blocks/icon/Icon.astro +41 -0
  43. package/src/blocks/icon/icon.css +16 -0
  44. package/src/blocks/image/Image.astro +158 -0
  45. package/src/blocks/image/image.css +42 -0
  46. package/src/blocks/images.ts +64 -0
  47. package/src/blocks/in-editor.client.ts +8 -0
  48. package/src/blocks/listing/Listing.astro +288 -0
  49. package/src/blocks/listing/ListingCards.astro +48 -0
  50. package/src/blocks/listing/listing.css +136 -0
  51. package/src/blocks/listing/query.ts +363 -0
  52. package/src/blocks/map/Map.astro +75 -0
  53. package/src/blocks/map/map.css +32 -0
  54. package/src/blocks/schemas/accordion.ts +118 -0
  55. package/src/blocks/schemas/button.ts +78 -0
  56. package/src/blocks/schemas/carousel.ts +133 -0
  57. package/src/blocks/schemas/divider.ts +29 -0
  58. package/src/blocks/schemas/form-field-types.ts +29 -0
  59. package/src/blocks/schemas/form.ts +350 -0
  60. package/src/blocks/schemas/icon.ts +24 -0
  61. package/src/blocks/schemas/image-gallery.ts +54 -0
  62. package/src/blocks/schemas/image.ts +87 -0
  63. package/src/blocks/schemas/index.ts +33 -0
  64. package/src/blocks/schemas/listing.ts +14 -0
  65. package/src/blocks/schemas/map.ts +81 -0
  66. package/src/blocks/schemas/newsletter.ts +324 -0
  67. package/src/blocks/schemas/social-media.ts +348 -0
  68. package/src/blocks/schemas/text.ts +151 -0
  69. package/src/blocks/schemas/video.ts +57 -0
  70. package/src/blocks/search/Search.astro +147 -0
  71. package/src/blocks/search/search.css +69 -0
  72. package/src/blocks/search/state.ts +28 -0
  73. package/src/blocks/settings.ts +94 -0
  74. package/src/blocks/social/SocialMedia.astro +102 -0
  75. package/src/blocks/social/social-links.ts +16 -0
  76. package/src/blocks/social/social.css +31 -0
  77. package/src/blocks/theme.ts +35 -0
  78. package/src/blocks/types.ts +52 -0
  79. package/src/blocks/video/Video.astro +90 -0
  80. package/src/blocks/video/video-source.ts +77 -0
  81. package/src/blocks/video/video.client.ts +43 -0
  82. package/src/blocks/video/video.css +29 -0
  83. package/src/check.ts +1119 -0
  84. package/src/cli.ts +493 -0
  85. package/src/components/Blocks.astro +68 -0
  86. package/src/components/Field.astro +61 -0
  87. package/src/components/Footer.astro +36 -0
  88. package/src/components/Link.astro +18 -0
  89. package/src/components/MobileMenu.astro +77 -0
  90. package/src/components/Navbar.astro +42 -0
  91. package/src/components/RichText.astro +32 -0
  92. package/src/components/Seo.astro +202 -0
  93. package/src/components/Setting.astro +46 -0
  94. package/src/components/Shared.astro +17 -0
  95. package/src/components/Text.astro +91 -0
  96. package/src/components/blocks.css +86 -0
  97. package/src/components/index.ts +27 -0
  98. package/src/components/mobile-menu.client.ts +21 -0
  99. package/src/components/mobile-menu.css +52 -0
  100. package/src/components/text.css +48 -0
  101. package/src/config.ts +413 -0
  102. package/src/content/block-layout.ts +63 -0
  103. package/src/content/block-values.ts +48 -0
  104. package/src/content/content-check.ts +174 -0
  105. package/src/content/content-types.ts +408 -0
  106. package/src/content/drafts.ts +115 -0
  107. package/src/content/feed.ts +237 -0
  108. package/src/content/field-types.ts +107 -0
  109. package/src/content/history.ts +140 -0
  110. package/src/content/ids.ts +50 -0
  111. package/src/content/image-size.ts +212 -0
  112. package/src/content/image-sizes.ts +126 -0
  113. package/src/content/item-fields.ts +110 -0
  114. package/src/content/item-head.ts +126 -0
  115. package/src/content/item-image.ts +26 -0
  116. package/src/content/item-path.ts +122 -0
  117. package/src/content/items.ts +580 -0
  118. package/src/content/language-scopes.ts +40 -0
  119. package/src/content/media.ts +271 -0
  120. package/src/content/menus.ts +51 -0
  121. package/src/content/page-templates.ts +52 -0
  122. package/src/content/redirects.ts +112 -0
  123. package/src/content/references.ts +165 -0
  124. package/src/content/rich-text.ts +63 -0
  125. package/src/content/search.ts +167 -0
  126. package/src/content/seed.ts +229 -0
  127. package/src/content/site-settings.ts +111 -0
  128. package/src/content/sitemap.ts +143 -0
  129. package/src/content/store.ts +225 -0
  130. package/src/content/tags.ts +67 -0
  131. package/src/content/text-default.ts +139 -0
  132. package/src/content/types.ts +137 -0
  133. package/src/content/validate.ts +253 -0
  134. package/src/content/validation-error.ts +2 -0
  135. package/src/db/cached.ts +140 -0
  136. package/src/db/database.ts +15 -0
  137. package/src/db/libsql.ts +29 -0
  138. package/src/db/schema.ts +189 -0
  139. package/src/db/url.ts +44 -0
  140. package/src/editor/client/BlockSettings.tsx +1063 -0
  141. package/src/editor/client/Chrome.tsx +284 -0
  142. package/src/editor/client/ContentBrowser.tsx +1299 -0
  143. package/src/editor/client/Editor.tsx +1756 -0
  144. package/src/editor/client/HistoryPanel.tsx +114 -0
  145. package/src/editor/client/ImagesWidget.tsx +113 -0
  146. package/src/editor/client/Inspector.tsx +127 -0
  147. package/src/editor/client/ItemForm.tsx +535 -0
  148. package/src/editor/client/LinkWidget.tsx +440 -0
  149. package/src/editor/client/ListingPanel.tsx +99 -0
  150. package/src/editor/client/Login.tsx +338 -0
  151. package/src/editor/client/Menu.tsx +64 -0
  152. package/src/editor/client/PageSettings.tsx +270 -0
  153. package/src/editor/client/RedirectsSettings.tsx +130 -0
  154. package/src/editor/client/Resize.tsx +204 -0
  155. package/src/editor/client/Sidebar.tsx +51 -0
  156. package/src/editor/client/SiteMap.tsx +568 -0
  157. package/src/editor/client/SiteSettings.tsx +409 -0
  158. package/src/editor/client/TextTools.tsx +391 -0
  159. package/src/editor/client/Toolbar.tsx +449 -0
  160. package/src/editor/client/VideoUpload.tsx +251 -0
  161. package/src/editor/client/api.ts +417 -0
  162. package/src/editor/client/brand.ts +20 -0
  163. package/src/editor/client/connection.ts +98 -0
  164. package/src/editor/client/context.ts +19 -0
  165. package/src/editor/client/css.d.ts +2 -0
  166. package/src/editor/client/editor.css +4656 -0
  167. package/src/editor/client/fields.tsx +812 -0
  168. package/src/editor/client/icons.tsx +174 -0
  169. package/src/editor/client/keys.ts +15 -0
  170. package/src/editor/client/kinds.ts +289 -0
  171. package/src/editor/client/languages.ts +32 -0
  172. package/src/editor/client/main.tsx +100 -0
  173. package/src/editor/client/responses.ts +26 -0
  174. package/src/editor/client/rich-text.ts +326 -0
  175. package/src/editor/client/site-tree.ts +239 -0
  176. package/src/editor/client/theme.ts +55 -0
  177. package/src/editor/client/tsconfig.json +18 -0
  178. package/src/editor/client/tus.ts +137 -0
  179. package/src/editor/client/use-rect.ts +50 -0
  180. package/src/editor/client/widgets.tsx +1218 -0
  181. package/src/forms/captcha.ts +83 -0
  182. package/src/forms/define.ts +166 -0
  183. package/src/forms/fields.ts +197 -0
  184. package/src/forms/file-types.ts +108 -0
  185. package/src/forms/files.ts +216 -0
  186. package/src/forms/form-page.ts +9 -0
  187. package/src/forms/handler.ts +622 -0
  188. package/src/forms/spec.ts +89 -0
  189. package/src/forms/store.ts +96 -0
  190. package/src/forms/work.ts +50 -0
  191. package/src/icons/library.ts +144 -0
  192. package/src/icons/load.ts +63 -0
  193. package/src/index.ts +99 -0
  194. package/src/init.ts +257 -0
  195. package/src/integration.ts +469 -0
  196. package/src/mail/mailer.ts +197 -0
  197. package/src/mail/notify.ts +272 -0
  198. package/src/mail/settings.ts +173 -0
  199. package/src/mail/templates.ts +191 -0
  200. package/src/mcp/page-nodes.ts +209 -0
  201. package/src/mcp/server.ts +111 -0
  202. package/src/mcp/tools.ts +637 -0
  203. package/src/runtime/TemplatePage.astro +39 -0
  204. package/src/runtime/TemplatePageStatic.astro +13 -0
  205. package/src/runtime/admin-route.ts +80 -0
  206. package/src/runtime/connect.ts +53 -0
  207. package/src/runtime/content.ts +188 -0
  208. package/src/runtime/context.ts +131 -0
  209. package/src/runtime/form-files.ts +18 -0
  210. package/src/runtime/forms-route.ts +33 -0
  211. package/src/runtime/forms.ts +28 -0
  212. package/src/runtime/icons.ts +5 -0
  213. package/src/runtime/media.ts +175 -0
  214. package/src/runtime/middleware.ts +186 -0
  215. package/src/runtime/nav.ts +13 -0
  216. package/src/runtime/query-reads.ts +49 -0
  217. package/src/runtime/query-store.ts +16 -0
  218. package/src/runtime/request-state.ts +69 -0
  219. package/src/runtime/robots.ts +29 -0
  220. package/src/runtime/rss-static.ts +16 -0
  221. package/src/runtime/rss.ts +29 -0
  222. package/src/runtime/server.ts +29 -0
  223. package/src/runtime/sitemap.ts +34 -0
  224. package/src/runtime/template-paths.ts +34 -0
  225. package/src/runtime/uploads-route.ts +13 -0
  226. package/src/seed-cli.ts +253 -0
  227. package/src/server/auth.ts +31 -0
  228. package/src/server/fetch-image.ts +219 -0
  229. package/src/server/handler.ts +2106 -0
  230. package/src/server/http.ts +162 -0
  231. package/src/server/locales.ts +73 -0
  232. package/src/server/node.ts +57 -0
  233. package/src/server/query-params.ts +249 -0
  234. package/src/server/rate-limit.ts +72 -0
  235. package/src/server/video-host.ts +162 -0
  236. package/src/starter.ts +70 -0
  237. package/src/version.ts +4 -0
  238. package/src/virtual.d.ts +65 -0
@@ -0,0 +1,162 @@
1
+ import type { VideoUploadsOptions } from "../config.ts";
2
+ import { ValidationError } from "../content/validate.ts";
3
+ import { HttpError } from "./http.ts";
4
+
5
+ /** What the editor says about a video before uploading it. */
6
+ export interface NewVideo {
7
+ name: string;
8
+ size: number;
9
+ type: string;
10
+ }
11
+
12
+ /** One uploaded video, as the host lists it. */
13
+ export interface HostedVideo {
14
+ id: string;
15
+ name: string;
16
+ /** In bytes. */
17
+ size: number;
18
+ status: "processing" | "ready" | "failed";
19
+ url: string;
20
+ posterUrl: string | null;
21
+ /** An ISO date, or "" when the host did not say. */
22
+ createdAt: string;
23
+ }
24
+
25
+ const HOST_TIMEOUT_MS = 20_000;
26
+ const MAX_NAME = 255;
27
+ /** Ids are the host's own; this only keeps them from changing the address that is asked. */
28
+ const VIDEO_ID = /^[A-Za-z0-9._~-]{1,200}$/;
29
+ /** What a host that does not know a call answers: the call is optional, so this is not an error. */
30
+ const NOT_SUPPORTED = [404, 405, 501];
31
+
32
+ /** One entry of the host's list, or `undefined` when it is not a video the editor could use or delete. */
33
+ function hostedVideo(entry: unknown): HostedVideo | undefined {
34
+ if (!entry || typeof entry !== "object") return undefined;
35
+ const { id, name, size, status, url, posterUrl, createdAt } = entry as Record<string, unknown>;
36
+ if (typeof id !== "string" || !VIDEO_ID.test(id) || typeof url !== "string") return undefined;
37
+ if (status !== "processing" && status !== "ready" && status !== "failed") return undefined;
38
+ return {
39
+ id,
40
+ name: typeof name === "string" ? name : "",
41
+ size: typeof size === "number" && Number.isFinite(size) && size >= 0 ? size : 0,
42
+ status,
43
+ url,
44
+ posterUrl: typeof posterUrl === "string" ? posterUrl : null,
45
+ createdAt: typeof createdAt === "string" ? createdAt : "",
46
+ };
47
+ }
48
+
49
+ export function parseNewVideo(body: Record<string, unknown>): NewVideo {
50
+ const { name, size, type } = body;
51
+ if (typeof name !== "string" || name.trim() === "" || name.length > MAX_NAME) {
52
+ throw new ValidationError(`"name" must be the file's name, at most ${MAX_NAME} characters.`);
53
+ }
54
+ if (typeof size !== "number" || !Number.isSafeInteger(size) || size <= 0) {
55
+ throw new ValidationError('"size" must be the file\'s size in bytes.');
56
+ }
57
+ if (typeof type !== "string" || !/^video\/[\w.+-]+$/i.test(type)) {
58
+ throw new ValidationError("Only video files can be uploaded here.");
59
+ }
60
+ return { name: name.trim(), size, type: type.toLowerCase() };
61
+ }
62
+
63
+ /**
64
+ * The video host of a site: any service that answers the calls below (see "Video uploads" in the README).
65
+ * The site's server talks to it; the browser only ever gets the upload address the host hands out.
66
+ */
67
+ export class VideoHost {
68
+ readonly #url: string;
69
+ readonly #token: string | undefined;
70
+ readonly #fetch: typeof fetch;
71
+
72
+ private constructor(url: string, token: string | undefined, fetchImpl: typeof fetch) {
73
+ this.#url = url.replace(/\/+$/, "");
74
+ this.#token = token;
75
+ this.#fetch = fetchImpl;
76
+ }
77
+
78
+ /** `undefined` when no host is set up, or its address cannot be used: the feature is then off. */
79
+ static from(options: VideoUploadsOptions | undefined, fetchImpl: typeof fetch = fetch): VideoHost | undefined {
80
+ const url = options?.url?.trim();
81
+ if (!url || !URL.canParse(url)) return undefined;
82
+ const { protocol, hostname } = new URL(url);
83
+ // The token travels with every call, so the address is HTTPS; a host on this machine is for development.
84
+ const local = hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
85
+ if (protocol !== "https:" && !(protocol === "http:" && local)) return undefined;
86
+ return new VideoHost(url, options?.token || undefined, fetchImpl);
87
+ }
88
+
89
+ /** Asks for a place to upload a video. Answers what the host answered: `id`, `upload`, `url`, `posterUrl`. */
90
+ async create(video: NewVideo): Promise<Record<string, unknown>> {
91
+ const answer = await this.#call("POST", this.#url, video);
92
+ const upload = answer.upload as Record<string, unknown> | undefined;
93
+ if (typeof answer.id !== "string" || typeof upload?.endpoint !== "string") {
94
+ throw new HttpError(502, "The video host gave an answer Brim does not understand.");
95
+ }
96
+ return answer;
97
+ }
98
+
99
+ /** Where a video is: `processing`, `ready` or `failed`, with its progress and the address to play. */
100
+ async status(id: string): Promise<Record<string, unknown>> {
101
+ if (!VIDEO_ID.test(id)) throw new HttpError(404, "This video does not exist.");
102
+ return this.#call("GET", `${this.#url}/${encodeURIComponent(id)}`);
103
+ }
104
+
105
+ /**
106
+ * The site's uploaded videos, newest first as the host orders them. `undefined` when the host does not list
107
+ * videos: listing is optional for a host, and the editor then shows no list.
108
+ */
109
+ async list(): Promise<HostedVideo[] | undefined> {
110
+ let answer: Record<string, unknown>;
111
+ try {
112
+ answer = await this.#call("GET", this.#url);
113
+ } catch (failure) {
114
+ if (failure instanceof HttpError && NOT_SUPPORTED.includes(failure.status)) return undefined;
115
+ throw failure;
116
+ }
117
+ if (!Array.isArray(answer.videos)) {
118
+ throw new HttpError(502, "The video host gave an answer Brim does not understand.");
119
+ }
120
+ return answer.videos.map(hostedVideo).filter((video) => video !== undefined);
121
+ }
122
+
123
+ /** Removes a video from the host for good. Pages that still show it stop playing it. */
124
+ async delete(id: string): Promise<void> {
125
+ if (!VIDEO_ID.test(id)) throw new HttpError(404, "This video does not exist.");
126
+ await this.#call("DELETE", `${this.#url}/${encodeURIComponent(id)}`, undefined, true);
127
+ }
128
+
129
+ /** `empty` lets a successful answer have no body, as a 204 does. */
130
+ async #call(method: string, url: string, body?: unknown, empty = false): Promise<Record<string, unknown>> {
131
+ let response: Response;
132
+ try {
133
+ response = await this.#fetch(url, {
134
+ method,
135
+ headers: {
136
+ accept: "application/json",
137
+ ...(this.#token && { authorization: `Bearer ${this.#token}` }),
138
+ ...(body !== undefined && { "content-type": "application/json" }),
139
+ },
140
+ ...(body !== undefined && { body: JSON.stringify(body) }),
141
+ redirect: "error",
142
+ signal: AbortSignal.timeout(HOST_TIMEOUT_MS),
143
+ });
144
+ } catch {
145
+ throw new HttpError(502, "The video host did not answer. Try again in a moment.");
146
+ }
147
+ const answer = (await response.json().catch(() => undefined)) as Record<string, unknown> | undefined;
148
+ if (!response.ok) {
149
+ // The host's own words are meant for the person uploading; its status says whose fault it was.
150
+ const message =
151
+ typeof answer?.error === "string" && answer.error ? answer.error : "The video host refused the request.";
152
+ // Not 401 or 403 though: those would say the editor's own sign-in failed, when it is the site's token.
153
+ const passed = response.status >= 400 && response.status < 600 && ![401, 403].includes(response.status);
154
+ throw new HttpError(passed ? response.status : 502, message);
155
+ }
156
+ if (answer === undefined && empty) return {};
157
+ if (!answer || typeof answer !== "object" || Array.isArray(answer)) {
158
+ throw new HttpError(502, "The video host gave an answer Brim does not understand.");
159
+ }
160
+ return answer;
161
+ }
162
+ }
package/src/starter.ts ADDED
@@ -0,0 +1,70 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
3
+ import { join, relative, sep } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ /**
7
+ * What `create-brim` copies into a new site, so `brim check` can tell which starter files a site still has
8
+ * unchanged. create-brim is not installed in a site, so the bundled CLI carries this list (see
9
+ * scripts/build-cli.mjs); inside the repository it is read from the template itself.
10
+ */
11
+ export interface StarterFile {
12
+ /** Relative to the site's folder, with forward slashes. */
13
+ path: string;
14
+ /** sha256 of the file with line endings normalized, for files create-brim copies as they are. */
15
+ sha256?: string;
16
+ /**
17
+ * The template text of a file create-brim fills in (`{{siteName}}`); a site's copy matches it when
18
+ * everything but the filled-in values is the same.
19
+ */
20
+ template?: string;
21
+ }
22
+
23
+ // Only the site's own code and files: README, package.json and the configs are expected to stay.
24
+ const CHECKED_FOLDERS = ["src", "public"];
25
+ // The placeholders create-brim fills in (see its index.js); other `{{…}}` text is left as it is.
26
+ const PLACEHOLDER = /\{\{(siteName|packageName|brimVersion)\}\}/;
27
+
28
+ declare const __BRIM_STARTER_MANIFEST__: StarterFile[] | undefined;
29
+
30
+ export function starterManifest(): StarterFile[] {
31
+ if (typeof __BRIM_STARTER_MANIFEST__ !== "undefined") return __BRIM_STARTER_MANIFEST__;
32
+ const template = fileURLToPath(new URL("../../create-brim/template/", import.meta.url));
33
+ return existsSync(template) ? readStarter(template) : [];
34
+ }
35
+
36
+ export function readStarter(templateFolder: string): StarterFile[] {
37
+ const files: StarterFile[] = [];
38
+ for (const folder of CHECKED_FOLDERS) {
39
+ const root = join(templateFolder, folder);
40
+ if (!existsSync(root)) continue;
41
+ for (const entry of readdirSync(root, { withFileTypes: true, recursive: true })) {
42
+ if (!entry.isFile()) continue;
43
+ const file = join(entry.parentPath, entry.name);
44
+ const path = relative(templateFolder, file).split(sep).join("/");
45
+ const text = normalize(readFileSync(file, "utf8"));
46
+ files.push(PLACEHOLDER.test(text) ? { path, template: text } : { path, sha256: hash(text) });
47
+ }
48
+ }
49
+ return files.sort((a, b) => a.path.localeCompare(b.path));
50
+ }
51
+
52
+ /** True when a site's file is still the one create-brim wrote. */
53
+ export function isUnchanged(starter: StarterFile, content: string): boolean {
54
+ const text = normalize(content);
55
+ if (starter.sha256) return hash(text) === starter.sha256;
56
+ if (starter.template === undefined) return false;
57
+ // A filled-in value is one line of text (create-brim escapes it like a JSON string).
58
+ const literal = starter.template.split(PLACEHOLDER).filter((_, index) => index % 2 === 0);
59
+ const pattern = literal.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[^\\n]*");
60
+ return new RegExp(`^${pattern}$`).test(text);
61
+ }
62
+
63
+ // Git may check files out with CRLF on Windows; that is not a change.
64
+ function normalize(text: string): string {
65
+ return text.replace(/\r\n/g, "\n");
66
+ }
67
+
68
+ function hash(text: string): string {
69
+ return createHash("sha256").update(text).digest("hex");
70
+ }
package/src/version.ts ADDED
@@ -0,0 +1,4 @@
1
+ import manifest from "../package.json" with { type: "json" };
2
+
3
+ /** The version of brimjs that runs, as published. */
4
+ export const VERSION: string = manifest.version;
@@ -0,0 +1,65 @@
1
+ declare module "virtual:brim/config" {
2
+ const config: {
3
+ databaseUrl: string;
4
+ authToken: string | undefined;
5
+ command: "dev" | "build" | "preview" | "sync";
6
+ /** How pages are made: live for everyone in dev, from the database per request, or once at build. */
7
+ mode: "dev" | "server" | "static";
8
+ /** True when Brim serves the feeds of content types (`/rss/…`), so pages may link them. */
9
+ feeds: boolean;
10
+ /** Where uploaded images are written. */
11
+ mediaDirectory: string;
12
+ /** Where the built editor is, as an installed brimjs has it. */
13
+ editorAssets: string;
14
+ locales: import("./server/locales.ts").LocaleConfig | undefined;
15
+ /** The video host named in the integration's options; the environment is read when the server starts. */
16
+ videoUploads: import("./config.ts").VideoUploadsOptions | undefined;
17
+ /** How the site sends email, as named in the options; the environment is read when the server starts. */
18
+ mail: import("./config.ts").MailOptions | undefined;
19
+ /** Where uploads are kept and served, as named in the options; the environment is read when the server starts. */
20
+ media: import("./config.ts").MediaOptions | undefined;
21
+ /** The brand colors from the integration's options, checked when the config was read. */
22
+ brandColors: import("./config.ts").BrandColor[];
23
+ /** Name, title template, fallbacks, theme color and favicon (the one named, or found in public/). */
24
+ identity: import("./config.ts").SiteIdentity;
25
+ contentTypes: import("./content/content-types.ts").ContentType[];
26
+ pageTemplates: import("./content/page-templates.ts").PageTemplate[];
27
+ /** The site's own settings, from `src/site-settings.ts`; null when it declares none. */
28
+ siteSettings: import("./content/site-settings.ts").SiteSettings | null;
29
+ /** The challenge forms ask for (its provider and public key), when the config sets one. */
30
+ captcha: import("./forms/captcha.ts").CaptchaOptions | undefined;
31
+ /** The private storage the config names for visitors' files, if any; the environment is read at start. */
32
+ formFiles: { storage?: { url: string; headers?: Record<string, string> } | undefined };
33
+ /** The emails the site writes itself, from `src/emails.ts`; null when it writes none. */
34
+ emails: import("./mail/templates.ts").SiteEmails | null;
35
+ /** The query parameters the site's code declares it reads (`brim({ query })`), checked when the config was read. */
36
+ query: import("./server/query-params.ts").QueryRules;
37
+ /** Names this build of the site's code: what its pages were seen reading is remembered for it alone. */
38
+ build: string;
39
+ /**
40
+ * Whether pages seen drawn may declare what they read: no code of the site reads the query without saying so.
41
+ * Otherwise only pages that called `readsQuery()` do.
42
+ */
43
+ learnQuery: boolean;
44
+ };
45
+ export default config;
46
+ }
47
+
48
+ declare module "virtual:brim/icons" {
49
+ const icons: {
50
+ options: import("./icons/library.ts").IconsOptions;
51
+ packs: import("./icons/library.ts").IconPack[];
52
+ };
53
+ export default icons;
54
+ }
55
+
56
+ declare module "virtual:brim/routes" {
57
+ const routes: import("./content/sitemap.ts").SiteRoutes;
58
+ export default routes;
59
+ }
60
+
61
+ declare namespace App {
62
+ interface Locals {
63
+ brim: import("./runtime/context.ts").BrimContext;
64
+ }
65
+ }