@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.
- package/LICENSE +110 -0
- package/README.md +22 -2
- package/bin/brim.js +5 -0
- package/dist/cli.js +3802 -0
- package/editor-dist/editor.css +1 -0
- package/editor-dist/editor.js +91 -0
- package/package.json +71 -3
- package/skills/brim-convert/SKILL.md +256 -0
- package/skills/brim-hosting/SKILL.md +221 -0
- package/src/astro-shim.d.ts +5 -0
- package/src/auth/accounts.ts +341 -0
- package/src/auth/password.ts +34 -0
- package/src/auth/permissions.ts +44 -0
- package/src/blocks/accordion/Accordion.astro +48 -0
- package/src/blocks/accordion/accordion.css +63 -0
- package/src/blocks/analytics/Analytics.astro +45 -0
- package/src/blocks/analytics/ConsentBanner.astro +41 -0
- package/src/blocks/analytics/analytics.client.ts +125 -0
- package/src/blocks/analytics/analytics.css +51 -0
- package/src/blocks/analytics/consent.ts +51 -0
- package/src/blocks/button/Button.astro +64 -0
- package/src/blocks/button/button.css +100 -0
- package/src/blocks/carousel/Carousel.astro +140 -0
- package/src/blocks/carousel/carousel.client.ts +153 -0
- package/src/blocks/carousel/carousel.css +181 -0
- package/src/blocks/data/icons.ts +285 -0
- package/src/blocks/data/image-shapes.ts +91 -0
- package/src/blocks/data/social-icons.ts +41 -0
- package/src/blocks/data/social-networks.ts +256 -0
- package/src/blocks/divider/Divider.astro +27 -0
- package/src/blocks/divider/divider.css +17 -0
- package/src/blocks/form/Captcha.astro +27 -0
- package/src/blocks/form/Form.astro +250 -0
- package/src/blocks/form/FormField.astro +138 -0
- package/src/blocks/form/Newsletter.astro +80 -0
- package/src/blocks/form/form.client.ts +339 -0
- package/src/blocks/form/form.css +271 -0
- package/src/blocks/gallery/ImageGallery.astro +126 -0
- package/src/blocks/gallery/gallery.css +43 -0
- package/src/blocks/gallery/lightbox.client.ts +178 -0
- package/src/blocks/gallery/lightbox.css +134 -0
- package/src/blocks/icon/Icon.astro +41 -0
- package/src/blocks/icon/icon.css +16 -0
- package/src/blocks/image/Image.astro +158 -0
- package/src/blocks/image/image.css +42 -0
- package/src/blocks/images.ts +64 -0
- package/src/blocks/in-editor.client.ts +8 -0
- package/src/blocks/listing/Listing.astro +288 -0
- package/src/blocks/listing/ListingCards.astro +48 -0
- package/src/blocks/listing/listing.css +136 -0
- package/src/blocks/listing/query.ts +363 -0
- package/src/blocks/map/Map.astro +75 -0
- package/src/blocks/map/map.css +32 -0
- package/src/blocks/schemas/accordion.ts +118 -0
- package/src/blocks/schemas/button.ts +78 -0
- package/src/blocks/schemas/carousel.ts +133 -0
- package/src/blocks/schemas/divider.ts +29 -0
- package/src/blocks/schemas/form-field-types.ts +29 -0
- package/src/blocks/schemas/form.ts +350 -0
- package/src/blocks/schemas/icon.ts +24 -0
- package/src/blocks/schemas/image-gallery.ts +54 -0
- package/src/blocks/schemas/image.ts +87 -0
- package/src/blocks/schemas/index.ts +33 -0
- package/src/blocks/schemas/listing.ts +14 -0
- package/src/blocks/schemas/map.ts +81 -0
- package/src/blocks/schemas/newsletter.ts +324 -0
- package/src/blocks/schemas/social-media.ts +348 -0
- package/src/blocks/schemas/text.ts +151 -0
- package/src/blocks/schemas/video.ts +57 -0
- package/src/blocks/search/Search.astro +147 -0
- package/src/blocks/search/search.css +69 -0
- package/src/blocks/search/state.ts +28 -0
- package/src/blocks/settings.ts +94 -0
- package/src/blocks/social/SocialMedia.astro +102 -0
- package/src/blocks/social/social-links.ts +16 -0
- package/src/blocks/social/social.css +31 -0
- package/src/blocks/theme.ts +35 -0
- package/src/blocks/types.ts +52 -0
- package/src/blocks/video/Video.astro +90 -0
- package/src/blocks/video/video-source.ts +77 -0
- package/src/blocks/video/video.client.ts +43 -0
- package/src/blocks/video/video.css +29 -0
- package/src/check.ts +1119 -0
- package/src/cli.ts +493 -0
- package/src/components/Blocks.astro +68 -0
- package/src/components/Field.astro +61 -0
- package/src/components/Footer.astro +36 -0
- package/src/components/Link.astro +18 -0
- package/src/components/MobileMenu.astro +77 -0
- package/src/components/Navbar.astro +42 -0
- package/src/components/RichText.astro +32 -0
- package/src/components/Seo.astro +202 -0
- package/src/components/Setting.astro +46 -0
- package/src/components/Shared.astro +17 -0
- package/src/components/Text.astro +91 -0
- package/src/components/blocks.css +86 -0
- package/src/components/index.ts +27 -0
- package/src/components/mobile-menu.client.ts +21 -0
- package/src/components/mobile-menu.css +52 -0
- package/src/components/text.css +48 -0
- package/src/config.ts +413 -0
- package/src/content/block-layout.ts +63 -0
- package/src/content/block-values.ts +48 -0
- package/src/content/content-check.ts +174 -0
- package/src/content/content-types.ts +408 -0
- package/src/content/drafts.ts +115 -0
- package/src/content/feed.ts +237 -0
- package/src/content/field-types.ts +107 -0
- package/src/content/history.ts +140 -0
- package/src/content/ids.ts +50 -0
- package/src/content/image-size.ts +212 -0
- package/src/content/image-sizes.ts +126 -0
- package/src/content/item-fields.ts +110 -0
- package/src/content/item-head.ts +126 -0
- package/src/content/item-image.ts +26 -0
- package/src/content/item-path.ts +122 -0
- package/src/content/items.ts +580 -0
- package/src/content/language-scopes.ts +40 -0
- package/src/content/media.ts +271 -0
- package/src/content/menus.ts +51 -0
- package/src/content/page-templates.ts +52 -0
- package/src/content/redirects.ts +112 -0
- package/src/content/references.ts +165 -0
- package/src/content/rich-text.ts +63 -0
- package/src/content/search.ts +167 -0
- package/src/content/seed.ts +229 -0
- package/src/content/site-settings.ts +111 -0
- package/src/content/sitemap.ts +143 -0
- package/src/content/store.ts +225 -0
- package/src/content/tags.ts +67 -0
- package/src/content/text-default.ts +139 -0
- package/src/content/types.ts +137 -0
- package/src/content/validate.ts +253 -0
- package/src/content/validation-error.ts +2 -0
- package/src/db/cached.ts +140 -0
- package/src/db/database.ts +15 -0
- package/src/db/libsql.ts +29 -0
- package/src/db/schema.ts +189 -0
- package/src/db/url.ts +44 -0
- package/src/editor/client/BlockSettings.tsx +1063 -0
- package/src/editor/client/Chrome.tsx +284 -0
- package/src/editor/client/ContentBrowser.tsx +1299 -0
- package/src/editor/client/Editor.tsx +1756 -0
- package/src/editor/client/HistoryPanel.tsx +114 -0
- package/src/editor/client/ImagesWidget.tsx +113 -0
- package/src/editor/client/Inspector.tsx +127 -0
- package/src/editor/client/ItemForm.tsx +535 -0
- package/src/editor/client/LinkWidget.tsx +440 -0
- package/src/editor/client/ListingPanel.tsx +99 -0
- package/src/editor/client/Login.tsx +338 -0
- package/src/editor/client/Menu.tsx +64 -0
- package/src/editor/client/PageSettings.tsx +270 -0
- package/src/editor/client/RedirectsSettings.tsx +130 -0
- package/src/editor/client/Resize.tsx +204 -0
- package/src/editor/client/Sidebar.tsx +51 -0
- package/src/editor/client/SiteMap.tsx +568 -0
- package/src/editor/client/SiteSettings.tsx +409 -0
- package/src/editor/client/TextTools.tsx +391 -0
- package/src/editor/client/Toolbar.tsx +449 -0
- package/src/editor/client/VideoUpload.tsx +251 -0
- package/src/editor/client/api.ts +417 -0
- package/src/editor/client/brand.ts +20 -0
- package/src/editor/client/connection.ts +98 -0
- package/src/editor/client/context.ts +19 -0
- package/src/editor/client/css.d.ts +2 -0
- package/src/editor/client/editor.css +4656 -0
- package/src/editor/client/fields.tsx +812 -0
- package/src/editor/client/icons.tsx +174 -0
- package/src/editor/client/keys.ts +15 -0
- package/src/editor/client/kinds.ts +289 -0
- package/src/editor/client/languages.ts +32 -0
- package/src/editor/client/main.tsx +100 -0
- package/src/editor/client/responses.ts +26 -0
- package/src/editor/client/rich-text.ts +326 -0
- package/src/editor/client/site-tree.ts +239 -0
- package/src/editor/client/theme.ts +55 -0
- package/src/editor/client/tsconfig.json +18 -0
- package/src/editor/client/tus.ts +137 -0
- package/src/editor/client/use-rect.ts +50 -0
- package/src/editor/client/widgets.tsx +1218 -0
- package/src/forms/captcha.ts +83 -0
- package/src/forms/define.ts +166 -0
- package/src/forms/fields.ts +197 -0
- package/src/forms/file-types.ts +108 -0
- package/src/forms/files.ts +216 -0
- package/src/forms/form-page.ts +9 -0
- package/src/forms/handler.ts +622 -0
- package/src/forms/spec.ts +89 -0
- package/src/forms/store.ts +96 -0
- package/src/forms/work.ts +50 -0
- package/src/icons/library.ts +144 -0
- package/src/icons/load.ts +63 -0
- package/src/index.ts +99 -0
- package/src/init.ts +257 -0
- package/src/integration.ts +469 -0
- package/src/mail/mailer.ts +197 -0
- package/src/mail/notify.ts +272 -0
- package/src/mail/settings.ts +173 -0
- package/src/mail/templates.ts +191 -0
- package/src/mcp/page-nodes.ts +209 -0
- package/src/mcp/server.ts +111 -0
- package/src/mcp/tools.ts +637 -0
- package/src/runtime/TemplatePage.astro +39 -0
- package/src/runtime/TemplatePageStatic.astro +13 -0
- package/src/runtime/admin-route.ts +80 -0
- package/src/runtime/connect.ts +53 -0
- package/src/runtime/content.ts +188 -0
- package/src/runtime/context.ts +131 -0
- package/src/runtime/form-files.ts +18 -0
- package/src/runtime/forms-route.ts +33 -0
- package/src/runtime/forms.ts +28 -0
- package/src/runtime/icons.ts +5 -0
- package/src/runtime/media.ts +175 -0
- package/src/runtime/middleware.ts +186 -0
- package/src/runtime/nav.ts +13 -0
- package/src/runtime/query-reads.ts +49 -0
- package/src/runtime/query-store.ts +16 -0
- package/src/runtime/request-state.ts +69 -0
- package/src/runtime/robots.ts +29 -0
- package/src/runtime/rss-static.ts +16 -0
- package/src/runtime/rss.ts +29 -0
- package/src/runtime/server.ts +29 -0
- package/src/runtime/sitemap.ts +34 -0
- package/src/runtime/template-paths.ts +34 -0
- package/src/runtime/uploads-route.ts +13 -0
- package/src/seed-cli.ts +253 -0
- package/src/server/auth.ts +31 -0
- package/src/server/fetch-image.ts +219 -0
- package/src/server/handler.ts +2106 -0
- package/src/server/http.ts +162 -0
- package/src/server/locales.ts +73 -0
- package/src/server/node.ts +57 -0
- package/src/server/query-params.ts +249 -0
- package/src/server/rate-limit.ts +72 -0
- package/src/server/video-host.ts +162 -0
- package/src/starter.ts +70 -0
- package/src/version.ts +4 -0
- package/src/virtual.d.ts +65 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
2
|
+
import type { Database } from "../db/database.ts";
|
|
3
|
+
import { MIN_PASSWORD_LENGTH, generatePassword, hashPassword, verifyPassword } from "./password.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An owner manages the site; an editor runs its content.
|
|
7
|
+
* What each may do is in `permissions.ts`.
|
|
8
|
+
*/
|
|
9
|
+
export type Role = "owner" | "editor";
|
|
10
|
+
const ROLE_NAMES: readonly Role[] = ["owner", "editor"];
|
|
11
|
+
|
|
12
|
+
export interface User {
|
|
13
|
+
id: string;
|
|
14
|
+
email: string;
|
|
15
|
+
role: Role;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const SESSION_SECONDS = 60 * 60 * 24 * 14;
|
|
19
|
+
const SIGN_IN_LINK_SECONDS = 120;
|
|
20
|
+
/** How long a "forgot password" link works. */
|
|
21
|
+
const RESET_LINK_SECONDS = 60 * 60;
|
|
22
|
+
/** Marks access tokens, so one pasted in the wrong place is easy to recognise. */
|
|
23
|
+
const TOKEN_PREFIX = "brim_"; // betterleaks:allow
|
|
24
|
+
const TOKEN_NAME = /^[\w .-]{1,64}$/; // betterleaks:allow
|
|
25
|
+
|
|
26
|
+
/** An access token as listed: never the token itself, which is shown once when created. */
|
|
27
|
+
export interface AccessToken {
|
|
28
|
+
name: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
lastUsedAt: string | null;
|
|
31
|
+
}
|
|
32
|
+
/** Verified when the email is unknown, so a login attempt takes the same time either way. */
|
|
33
|
+
const DECOY_HASH = await hashPassword(randomBytes(16).toString("hex"));
|
|
34
|
+
|
|
35
|
+
export class Accounts {
|
|
36
|
+
readonly #db: Database;
|
|
37
|
+
|
|
38
|
+
constructor(db: Database) {
|
|
39
|
+
this.#db = db;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async createUser(email: string, password: string, role: Role): Promise<User> { // betterleaks:allow
|
|
43
|
+
const normalized = normalizeEmail(email);
|
|
44
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalized)) throw new Error("Enter a valid email address.");
|
|
45
|
+
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
46
|
+
throw new Error(`The password needs at least ${MIN_PASSWORD_LENGTH} characters.`);
|
|
47
|
+
}
|
|
48
|
+
assertRole(role);
|
|
49
|
+
const existing = await this.#db.query("SELECT id FROM brim_users WHERE email = ?", [normalized]);
|
|
50
|
+
if (existing.length > 0) throw new Error(`A user with the email ${normalized} already exists.`);
|
|
51
|
+
|
|
52
|
+
const user: User = { id: randomUUID(), email: normalized, role };
|
|
53
|
+
await this.#db.query("INSERT INTO brim_users (id, email, password_hash, role, created_at) VALUES (?, ?, ?, ?, ?)", [
|
|
54
|
+
user.id,
|
|
55
|
+
user.email,
|
|
56
|
+
await hashPassword(password),
|
|
57
|
+
role,
|
|
58
|
+
new Date().toISOString(),
|
|
59
|
+
]);
|
|
60
|
+
return user;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async authenticate(email: string, password: string): Promise<User | undefined> { // betterleaks:allow
|
|
64
|
+
const rows = await this.#db.query("SELECT id, email, role, password_hash FROM brim_users WHERE email = ?", [
|
|
65
|
+
normalizeEmail(email),
|
|
66
|
+
]);
|
|
67
|
+
const row = rows[0];
|
|
68
|
+
const valid = await verifyPassword(password, row ? String(row.password_hash) : DECOY_HASH);
|
|
69
|
+
return row && valid ? { id: String(row.id), email: String(row.email), role: row.role as Role } : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Returns the token to hand to the browser. Only its hash is stored. */
|
|
73
|
+
async startSession(userId: string): Promise<{ token: string; maxAgeSeconds: number }> {
|
|
74
|
+
const token = randomBytes(32).toString("base64url");
|
|
75
|
+
await this.#db.batch([
|
|
76
|
+
{ sql: "DELETE FROM brim_sessions WHERE expires_at < ?", args: [nowSeconds()] },
|
|
77
|
+
{
|
|
78
|
+
sql: "INSERT INTO brim_sessions (token_hash, user_id, expires_at) VALUES (?, ?, ?)",
|
|
79
|
+
args: [hashToken(token), userId, nowSeconds() + SESSION_SECONDS],
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
return { token, maxAgeSeconds: SESSION_SECONDS };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async sessionUser(token: string): Promise<User | undefined> {
|
|
86
|
+
const rows = await this.#db.query(
|
|
87
|
+
`SELECT u.id, u.email, u.role FROM brim_sessions s JOIN brim_users u ON u.id = s.user_id
|
|
88
|
+
WHERE s.token_hash = ? AND s.expires_at >= ?`,
|
|
89
|
+
[hashToken(token), nowSeconds()],
|
|
90
|
+
);
|
|
91
|
+
const row = rows[0];
|
|
92
|
+
return row ? { id: String(row.id), email: String(row.email), role: row.role as Role } : undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A token that signs the user in once, within two minutes, with nothing to type: whoever runs the site hands
|
|
97
|
+
* it over in a link (`brim user link`), the way a host's dashboard opens the editor for someone it already knows.
|
|
98
|
+
* It is kept beside the sessions under a hash no session cookie can have, so it is never a session itself.
|
|
99
|
+
*/
|
|
100
|
+
async createSignInToken(email: string): Promise<{ token: string; maxAgeSeconds: number }> {
|
|
101
|
+
const user = await this.#userByEmail(email);
|
|
102
|
+
const token = randomBytes(32).toString("base64url");
|
|
103
|
+
await this.#db.batch([
|
|
104
|
+
{ sql: "DELETE FROM brim_sessions WHERE expires_at < ?", args: [nowSeconds()] },
|
|
105
|
+
{
|
|
106
|
+
sql: "INSERT INTO brim_sessions (token_hash, user_id, expires_at) VALUES (?, ?, ?)",
|
|
107
|
+
args: [hashSignInToken(token), user.id, nowSeconds() + SIGN_IN_LINK_SECONDS],
|
|
108
|
+
},
|
|
109
|
+
]);
|
|
110
|
+
return { token, maxAgeSeconds: SIGN_IN_LINK_SECONDS };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The user a sign-in token was made for. The token stops working here, used or expired. */
|
|
114
|
+
async redeemSignInToken(token: string): Promise<User | undefined> {
|
|
115
|
+
const rows = await this.#db.query(
|
|
116
|
+
"DELETE FROM brim_sessions WHERE token_hash = ? AND expires_at >= ? RETURNING user_id",
|
|
117
|
+
[hashSignInToken(token), nowSeconds()],
|
|
118
|
+
);
|
|
119
|
+
if (!rows[0]) return undefined;
|
|
120
|
+
const users = await this.#db.query("SELECT id, email, role FROM brim_users WHERE id = ?", [
|
|
121
|
+
String(rows[0].user_id),
|
|
122
|
+
]);
|
|
123
|
+
const row = users[0];
|
|
124
|
+
return row ? { id: String(row.id), email: String(row.email), role: row.role as Role } : undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A one-time token for setting a new password, emailed when someone says they forgot theirs; `undefined` when no
|
|
129
|
+
* user has that email (the caller answers the same either way). Kept beside the sessions under a hash no session
|
|
130
|
+
* or sign-in link can have, and ended by the new password, which ends every session of the user.
|
|
131
|
+
*/
|
|
132
|
+
async createResetToken(
|
|
133
|
+
email: string,
|
|
134
|
+
maxAgeSeconds = RESET_LINK_SECONDS,
|
|
135
|
+
): Promise<{ token: string; maxAgeSeconds: number } | undefined> {
|
|
136
|
+
const rows = await this.#db.query("SELECT id FROM brim_users WHERE email = ?", [normalizeEmail(email)]);
|
|
137
|
+
const userId = rows[0] ? String(rows[0].id) : undefined;
|
|
138
|
+
if (!userId) return undefined;
|
|
139
|
+
const token = randomBytes(32).toString("base64url");
|
|
140
|
+
await this.#db.batch([
|
|
141
|
+
{ sql: "DELETE FROM brim_sessions WHERE expires_at < ?", args: [nowSeconds()] },
|
|
142
|
+
{
|
|
143
|
+
sql: "INSERT INTO brim_sessions (token_hash, user_id, expires_at) VALUES (?, ?, ?)",
|
|
144
|
+
args: [hashResetToken(token), userId, nowSeconds() + maxAgeSeconds],
|
|
145
|
+
},
|
|
146
|
+
]);
|
|
147
|
+
return { token, maxAgeSeconds };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Sets a new password with a reset token, which works once: every session, sign-in link, reset link and access
|
|
152
|
+
* token of the user ends (see `setPassword`). Answers the user, or `undefined` for a token wrong, used or too old.
|
|
153
|
+
*/
|
|
154
|
+
async resetPassword(token: string, password: string): Promise<User | undefined> { // betterleaks:allow
|
|
155
|
+
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
156
|
+
throw new Error(`The password needs at least ${MIN_PASSWORD_LENGTH} characters.`);
|
|
157
|
+
}
|
|
158
|
+
const rows = await this.#db.query(
|
|
159
|
+
"DELETE FROM brim_sessions WHERE token_hash = ? AND expires_at >= ? RETURNING user_id",
|
|
160
|
+
[hashResetToken(token), nowSeconds()],
|
|
161
|
+
);
|
|
162
|
+
if (!rows[0]) return undefined;
|
|
163
|
+
const users = await this.#db.query("SELECT id, email, role FROM brim_users WHERE id = ?", [String(rows[0].user_id)]);
|
|
164
|
+
const row = users[0];
|
|
165
|
+
if (!row) return undefined;
|
|
166
|
+
await this.setPassword(String(row.email), password);
|
|
167
|
+
return { id: String(row.id), email: String(row.email), role: row.role as Role };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async endSession(token: string): Promise<void> {
|
|
171
|
+
await this.#db.query("DELETE FROM brim_sessions WHERE token_hash = ?", [hashToken(token)]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A long-lived token that acts as the user, for tools such as an AI client using the site's MCP.
|
|
176
|
+
* Returns the token to show once; only its hash is stored.
|
|
177
|
+
*/
|
|
178
|
+
async createToken(email: string, name: string): Promise<string> {
|
|
179
|
+
if (!TOKEN_NAME.test(name)) throw new Error("A token name is 1 to 64 letters, digits, spaces, dots or dashes.");
|
|
180
|
+
const user = await this.#userByEmail(email);
|
|
181
|
+
const taken = await this.#db.query("SELECT 1 FROM brim_tokens WHERE user_id = ? AND name = ?", [user.id, name]);
|
|
182
|
+
if (taken.length > 0) throw new Error(`${user.email} already has a token named "${name}".`);
|
|
183
|
+
const token = TOKEN_PREFIX + randomBytes(32).toString("base64url");
|
|
184
|
+
await this.#db.query("INSERT INTO brim_tokens (token_hash, user_id, name, created_at) VALUES (?, ?, ?, ?)", [
|
|
185
|
+
hashToken(token),
|
|
186
|
+
user.id,
|
|
187
|
+
name,
|
|
188
|
+
new Date().toISOString(),
|
|
189
|
+
]);
|
|
190
|
+
return token;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async tokenUser(token: string): Promise<User | undefined> {
|
|
194
|
+
if (!token.startsWith(TOKEN_PREFIX)) return undefined;
|
|
195
|
+
const hash = hashToken(token);
|
|
196
|
+
const rows = await this.#db.query(
|
|
197
|
+
"SELECT u.id, u.email, u.role FROM brim_tokens t JOIN brim_users u ON u.id = t.user_id WHERE t.token_hash = ?",
|
|
198
|
+
[hash],
|
|
199
|
+
);
|
|
200
|
+
const row = rows[0];
|
|
201
|
+
if (!row) return undefined;
|
|
202
|
+
await this.#db.query("UPDATE brim_tokens SET last_used_at = ? WHERE token_hash = ?", [
|
|
203
|
+
new Date().toISOString(),
|
|
204
|
+
hash,
|
|
205
|
+
]);
|
|
206
|
+
return { id: String(row.id), email: String(row.email), role: row.role as Role };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async listTokens(email: string): Promise<AccessToken[]> {
|
|
210
|
+
const user = await this.#userByEmail(email);
|
|
211
|
+
const rows = await this.#db.query(
|
|
212
|
+
"SELECT name, created_at, last_used_at FROM brim_tokens WHERE user_id = ? ORDER BY created_at",
|
|
213
|
+
[user.id],
|
|
214
|
+
);
|
|
215
|
+
return rows.map((row) => ({
|
|
216
|
+
name: String(row.name),
|
|
217
|
+
createdAt: String(row.created_at),
|
|
218
|
+
lastUsedAt: row.last_used_at === null ? null : String(row.last_used_at),
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Returns whether a token by that name existed. */
|
|
223
|
+
async revokeToken(email: string, name: string): Promise<boolean> {
|
|
224
|
+
const user = await this.#userByEmail(email);
|
|
225
|
+
const before = await this.#db.query("SELECT 1 FROM brim_tokens WHERE user_id = ? AND name = ?", [user.id, name]);
|
|
226
|
+
await this.#db.query("DELETE FROM brim_tokens WHERE user_id = ? AND name = ?", [user.id, name]);
|
|
227
|
+
return before.length > 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Everyone who can sign in, owners first, with when they joined and how many tokens they hold. */
|
|
231
|
+
async listUsers(): Promise<(User & { createdAt: string; tokens: number })[]> {
|
|
232
|
+
const rows = await this.#db.query(
|
|
233
|
+
`SELECT u.id, u.email, u.role, u.created_at, COUNT(t.token_hash) AS tokens
|
|
234
|
+
FROM brim_users u LEFT JOIN brim_tokens t ON t.user_id = u.id
|
|
235
|
+
GROUP BY u.id ORDER BY u.role = 'owner' DESC, u.email`,
|
|
236
|
+
);
|
|
237
|
+
return rows.map((row) => ({
|
|
238
|
+
id: String(row.id),
|
|
239
|
+
email: String(row.email),
|
|
240
|
+
role: row.role as Role,
|
|
241
|
+
createdAt: String(row.created_at),
|
|
242
|
+
tokens: Number(row.tokens),
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async setRole(email: string, role: Role): Promise<User> {
|
|
247
|
+
assertRole(role);
|
|
248
|
+
const user = await this.#userByEmail(email);
|
|
249
|
+
if (user.role === "owner" && role !== "owner") await this.#assertAnotherOwner(user);
|
|
250
|
+
await this.#db.query("UPDATE brim_users SET role = ? WHERE id = ?", [role, user.id]);
|
|
251
|
+
return { ...user, role };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Signs the user out everywhere: sessions and access tokens go with them. */
|
|
255
|
+
async removeUser(email: string): Promise<void> {
|
|
256
|
+
const user = await this.#userByEmail(email);
|
|
257
|
+
if (user.role === "owner") await this.#assertAnotherOwner(user);
|
|
258
|
+
await this.#db.batch([
|
|
259
|
+
{ sql: "DELETE FROM brim_sessions WHERE user_id = ?", args: [user.id] },
|
|
260
|
+
{ sql: "DELETE FROM brim_tokens WHERE user_id = ?", args: [user.id] },
|
|
261
|
+
{ sql: "DELETE FROM brim_users WHERE id = ?", args: [user.id] },
|
|
262
|
+
]);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* A new password signs the user out everywhere: open sessions and access tokens both end. A password is changed
|
|
267
|
+
* when someone else may know it, and they may have made themselves a token with it.
|
|
268
|
+
*/
|
|
269
|
+
async setPassword(email: string, password: string): Promise<void> { // betterleaks:allow
|
|
270
|
+
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
271
|
+
throw new Error(`The password needs at least ${MIN_PASSWORD_LENGTH} characters.`);
|
|
272
|
+
}
|
|
273
|
+
const user = await this.#userByEmail(email);
|
|
274
|
+
await this.#db.batch([
|
|
275
|
+
{ sql: "UPDATE brim_users SET password_hash = ? WHERE id = ?", args: [await hashPassword(password), user.id] }, // betterleaks:allow
|
|
276
|
+
{ sql: "DELETE FROM brim_sessions WHERE user_id = ?", args: [user.id] },
|
|
277
|
+
{ sql: "DELETE FROM brim_tokens WHERE user_id = ?", args: [user.id] },
|
|
278
|
+
]);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* "Reset access", for someone who lost their password or may have shared it: a new password (handed back once),
|
|
283
|
+
* every session and link of theirs ends, and their access tokens too when asked (a tool they connected stops).
|
|
284
|
+
*/
|
|
285
|
+
async resetAccess(email: string, options: { revokeTokens?: boolean } = {}): Promise<{ password: string; revokedTokens: number }> { // betterleaks:allow
|
|
286
|
+
const user = await this.#userByEmail(email);
|
|
287
|
+
const password = generatePassword(); // betterleaks:allow
|
|
288
|
+
const tokens = options.revokeTokens
|
|
289
|
+
? Number((await this.#db.query("SELECT COUNT(*) AS count FROM brim_tokens WHERE user_id = ?", [user.id]))[0]?.count ?? 0)
|
|
290
|
+
: 0;
|
|
291
|
+
await this.#db.batch([
|
|
292
|
+
{ sql: "UPDATE brim_users SET password_hash = ? WHERE id = ?", args: [await hashPassword(password), user.id] }, // betterleaks:allow
|
|
293
|
+
{ sql: "DELETE FROM brim_sessions WHERE user_id = ?", args: [user.id] },
|
|
294
|
+
...(options.revokeTokens ? [{ sql: "DELETE FROM brim_tokens WHERE user_id = ?", args: [user.id] }] : []),
|
|
295
|
+
]);
|
|
296
|
+
return { password, revokedTokens: tokens };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** A site always keeps an owner, so someone can still manage its users. */
|
|
300
|
+
async #assertAnotherOwner(user: User): Promise<void> {
|
|
301
|
+
const owners = await this.#db.query("SELECT COUNT(*) AS count FROM brim_users WHERE role = 'owner' AND id != ?", [
|
|
302
|
+
user.id,
|
|
303
|
+
]);
|
|
304
|
+
if (Number(owners[0]?.count ?? 0) === 0)
|
|
305
|
+
throw new Error(`${user.email} is the only owner; make someone else owner first.`);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async #userByEmail(email: string): Promise<User> {
|
|
309
|
+
const rows = await this.#db.query("SELECT id, email, role FROM brim_users WHERE email = ?", [
|
|
310
|
+
normalizeEmail(email),
|
|
311
|
+
]);
|
|
312
|
+
const row = rows[0];
|
|
313
|
+
if (!row) throw new Error(`There is no user with the email ${normalizeEmail(email)}.`);
|
|
314
|
+
return { id: String(row.id), email: String(row.email), role: row.role as Role };
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function assertRole(role: string): asserts role is Role {
|
|
319
|
+
if (!ROLE_NAMES.includes(role as Role)) throw new Error('The role is "owner" or "editor".');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** An email as accounts are kept and found by: every spelling of it that signs in is this one. */
|
|
323
|
+
export function normalizeEmail(email: string): string {
|
|
324
|
+
return email.trim().toLowerCase();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function hashToken(token: string): string {
|
|
328
|
+
return createHash("sha256").update(token).digest("base64url");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function hashSignInToken(token: string): string {
|
|
332
|
+
return hashToken(`sign-in:${token}`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function hashResetToken(token: string): string {
|
|
336
|
+
return hashToken(`reset:${token}`);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function nowSeconds(): number {
|
|
340
|
+
return Math.floor(Date.now() / 1000);
|
|
341
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const KEY_LENGTH = 64;
|
|
4
|
+
export const MIN_PASSWORD_LENGTH = 10; // betterleaks:allow
|
|
5
|
+
|
|
6
|
+
function derive(password: string, salt: Buffer): Promise<Buffer> { // betterleaks:allow
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
scrypt(password.normalize("NFKC"), salt, KEY_LENGTH, (error, key) => (error ? reject(error) : resolve(key)));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function hashPassword(password: string): Promise<string> { // betterleaks:allow
|
|
13
|
+
const salt = randomBytes(16);
|
|
14
|
+
const key = await derive(password, salt);
|
|
15
|
+
return `scrypt$${salt.toString("base64url")}$${key.toString("base64url")}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function verifyPassword(password: string, stored: string): Promise<boolean> { // betterleaks:allow
|
|
19
|
+
const [scheme, salt, key] = stored.split("$");
|
|
20
|
+
if (scheme !== "scrypt" || !salt || !key) return false;
|
|
21
|
+
const expected = Buffer.from(key, "base64url");
|
|
22
|
+
const actual = await derive(password, Buffer.from(salt, "base64url"));
|
|
23
|
+
return expected.length === actual.length && timingSafeEqual(expected, actual);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A password to hand over once, when an owner adds someone or resets their access: 4 groups of 5 characters from an
|
|
28
|
+
* alphabet without look-alikes (~100 bits), easy to read out or copy. The emailed link lets them choose their own.
|
|
29
|
+
*/
|
|
30
|
+
export function generatePassword(): string { // betterleaks:allow
|
|
31
|
+
const alphabet = "abcdefghjkmnpqrstuvwxyz23456789";
|
|
32
|
+
const characters = [...randomBytes(20)].map((byte) => alphabet[byte % alphabet.length]);
|
|
33
|
+
return [0, 5, 10, 15].map((start) => characters.slice(start, start + 5).join("")).join("-");
|
|
34
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Role, User } from "./accounts.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What a signed-in user may do, checked by the editor's API (and so by the site's MCP, which goes through it):
|
|
5
|
+
* - `content`: change texts, images, links, blocks and the fields of items; upload media; add private items.
|
|
6
|
+
* - `publish`: publish and unpublish pages and items, and delete items.
|
|
7
|
+
* - `pages`: add, rename, move and delete the pages made from templates.
|
|
8
|
+
* - `templates`: change the template of a content type, shared by the pages of all its items.
|
|
9
|
+
* - `responses`: read and delete what visitors sent through the site's forms.
|
|
10
|
+
* - `settings`: Site Settings (email, redirects).
|
|
11
|
+
* - `users`: add and remove the site's users, change their roles and reset their access (`/admin/api/users`, which a
|
|
12
|
+
* host's dashboard calls too). Access tokens are managed with the `brim` CLI, by whoever runs the site.
|
|
13
|
+
*/
|
|
14
|
+
export type Permission = "content" | "publish" | "pages" | "templates" | "responses" | "settings" | "users";
|
|
15
|
+
|
|
16
|
+
export const ROLES: readonly Role[] = ["owner", "editor"];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An owner builds and runs the site; an editor runs its content (the client of an agency: writes, publishes, adds
|
|
20
|
+
* pages, reads the forms) without touching its structure or settings.
|
|
21
|
+
*/
|
|
22
|
+
export const ROLE_PERMISSIONS: Record<Role, readonly Permission[]> = {
|
|
23
|
+
owner: ["content", "publish", "pages", "templates", "responses", "settings", "users"],
|
|
24
|
+
editor: ["content", "publish", "pages", "responses"],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export function permissionsOf(role: Role): readonly Permission[] {
|
|
28
|
+
return ROLE_PERMISSIONS[role] ?? [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function can(user: Pick<User, "role">, permission: Permission): boolean {
|
|
32
|
+
return permissionsOf(user.role).includes(permission);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What the API answers when a user asks for something their role does not allow. */
|
|
36
|
+
export const REFUSALS: Record<Permission, string> = {
|
|
37
|
+
content: "Your role cannot change the site's content.",
|
|
38
|
+
publish: "Your role cannot publish, unpublish or delete: ask an owner of the site.",
|
|
39
|
+
pages: "Your role cannot add, move or delete pages: ask an owner of the site.",
|
|
40
|
+
templates: "Only the site's owners can change a content type's template.",
|
|
41
|
+
responses: "Your role cannot see what visitors sent through the forms: ask an owner of the site.",
|
|
42
|
+
settings: "Only the site's owners can change its settings.",
|
|
43
|
+
users: "Only the site's owners can manage its users.",
|
|
44
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { defaultScope } from "../../runtime/request-state.ts";
|
|
3
|
+
import "./accordion.css";
|
|
4
|
+
import type { NodeScope } from "../../runtime/context.ts";
|
|
5
|
+
import { accordion } from "../schemas/accordion.ts";
|
|
6
|
+
import { plainText } from "../theme.ts";
|
|
7
|
+
|
|
8
|
+
export interface AccordionItem {
|
|
9
|
+
title: string;
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Questions that open to show their answer. Built on the browser's own <details>,
|
|
15
|
+
* so it works without JavaScript. Only the questions: a heading or an intro above them is the site's own `Text`.
|
|
16
|
+
*/
|
|
17
|
+
interface Props {
|
|
18
|
+
nodeId: string;
|
|
19
|
+
scope?: NodeScope;
|
|
20
|
+
items?: AccordionItem[];
|
|
21
|
+
allowMultiple?: boolean;
|
|
22
|
+
icon?: "chevron" | "plus";
|
|
23
|
+
gap?: number;
|
|
24
|
+
radius?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { nodeId, scope = defaultScope(), ...source } = Astro.props;
|
|
28
|
+
const settings = Astro.locals.brim.settings(accordion, nodeId, scope, source);
|
|
29
|
+
const items = (Array.isArray(settings.items) ? settings.items : []) as AccordionItem[];
|
|
30
|
+
// Sharing a name makes the browser close the open item when another one opens.
|
|
31
|
+
const group = settings.allowMultiple ? undefined : `brim-accordion-${nodeId}`;
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
<div
|
|
35
|
+
class="brim-accordion"
|
|
36
|
+
data-icon={settings.icon === "plus" ? "plus" : "chevron"}
|
|
37
|
+
style={`--brim-accordion-gap:${Number(settings.gap) || 0}px;--brim-accordion-radius:${Number(settings.radius) || 0}px`}
|
|
38
|
+
{...Astro.locals.brim.marker("accordion", nodeId, scope, settings)}
|
|
39
|
+
>
|
|
40
|
+
<div class="brim-accordion__items">
|
|
41
|
+
{items.map((item) => (
|
|
42
|
+
<details class="brim-accordion__item" name={group}>
|
|
43
|
+
<summary>{item.title}</summary>
|
|
44
|
+
<div class="brim-accordion__content">{plainText(item.content)}</div>
|
|
45
|
+
</details>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* In the `brim` layer: any CSS of the site wins over it, whatever its selectors. */
|
|
2
|
+
@layer brim {
|
|
3
|
+
.brim-accordion__items {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: var(--brim-accordion-gap, 10px);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.brim-accordion__item {
|
|
10
|
+
border: 1px solid var(--brim-theme-light2, #e4e4e7);
|
|
11
|
+
border-radius: var(--brim-accordion-radius, 14px);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.brim-accordion__item summary {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: space-between;
|
|
18
|
+
gap: 1rem;
|
|
19
|
+
padding: 1rem 1.25rem;
|
|
20
|
+
font-weight: 600;
|
|
21
|
+
list-style: none;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.brim-accordion__item summary::-webkit-details-marker {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.brim-accordion__item summary::after {
|
|
30
|
+
content: "";
|
|
31
|
+
flex: none;
|
|
32
|
+
width: 0.5em;
|
|
33
|
+
height: 0.5em;
|
|
34
|
+
border-right: 2px solid currentColor;
|
|
35
|
+
border-bottom: 2px solid currentColor;
|
|
36
|
+
transform: rotate(45deg);
|
|
37
|
+
transition: transform 0.15s;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.brim-accordion__item[open] summary::after {
|
|
41
|
+
transform: rotate(225deg);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.brim-accordion[data-icon="plus"] summary::after {
|
|
45
|
+
content: "+";
|
|
46
|
+
width: auto;
|
|
47
|
+
height: auto;
|
|
48
|
+
border: 0;
|
|
49
|
+
font-size: 1.25em;
|
|
50
|
+
line-height: 1;
|
|
51
|
+
transform: none;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.brim-accordion[data-icon="plus"] .brim-accordion__item[open] summary::after {
|
|
55
|
+
content: "−";
|
|
56
|
+
transform: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.brim-accordion__content {
|
|
60
|
+
padding: 0 1.25rem 1rem;
|
|
61
|
+
white-space: pre-line;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
import ConsentBanner from "./ConsentBanner.astro";
|
|
3
|
+
import { measurementId } from "./consent.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Visitor statistics with Google Analytics 4, for a site whose server has `BRIM_GOOGLE_ANALYTICS_ID`. Put it once in
|
|
7
|
+
* the layout, at the end of `<body>`; without the variable it draws nothing. Nothing is asked of Google before the
|
|
8
|
+
* visitor accepts, and whoever is signed in to the editor is never counted.
|
|
9
|
+
*
|
|
10
|
+
* The texts are the site's, in its language. An element with `data-cookie-settings` (written `hidden`, shown once there is
|
|
11
|
+
* something to choose) opens the choice again: `<button type="button" data-cookie-settings hidden>Cookie settings</button>`.
|
|
12
|
+
*/
|
|
13
|
+
interface Props {
|
|
14
|
+
text?: string;
|
|
15
|
+
acceptText?: string;
|
|
16
|
+
rejectText?: string;
|
|
17
|
+
/** The page about cookies and privacy, linked after the text. */
|
|
18
|
+
policyHref?: string;
|
|
19
|
+
policyText?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
text = "We use cookies to count visits and see which pages help. They start only if you accept.",
|
|
24
|
+
acceptText = "Accept",
|
|
25
|
+
rejectText = "Reject",
|
|
26
|
+
policyHref,
|
|
27
|
+
policyText = "Privacy policy",
|
|
28
|
+
} = Astro.props;
|
|
29
|
+
|
|
30
|
+
/** Read when the page is drawn, so the same build runs with or without it. A wrong id is said once, in the log. */
|
|
31
|
+
function configuredId(): string | undefined {
|
|
32
|
+
try {
|
|
33
|
+
return measurementId(process.env.BRIM_GOOGLE_ANALYTICS_ID);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const said = globalThis as { brimAnalyticsWarned?: boolean };
|
|
36
|
+
if (!said.brimAnalyticsWarned) console.warn(`[brim] ${(error as Error).message} Statistics are off.`);
|
|
37
|
+
said.brimAnalyticsWarned = true;
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const id = Astro.locals.brim.editing ? undefined : configuredId();
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
{id && <ConsentBanner {...{ id, text, acceptText, rejectText, policyHref, policyText }} />}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
import "./analytics.css";
|
|
3
|
+
|
|
4
|
+
/** The choice itself, drawn by `<Analytics>` only where statistics are on: its script comes with it. */
|
|
5
|
+
interface Props {
|
|
6
|
+
id: string;
|
|
7
|
+
text: string;
|
|
8
|
+
acceptText: string;
|
|
9
|
+
rejectText: string;
|
|
10
|
+
policyHref?: string | undefined;
|
|
11
|
+
policyText: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { id, text, acceptText, rejectText, policyHref, policyText } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<brim-analytics data-id={id}>
|
|
18
|
+
<section class="brim-consent" aria-label="Cookies" hidden>
|
|
19
|
+
<p class="brim-consent__text">
|
|
20
|
+
{text}
|
|
21
|
+
{policyHref && (
|
|
22
|
+
<Fragment>
|
|
23
|
+
{" "}
|
|
24
|
+
<a href={policyHref}>{policyText}</a>
|
|
25
|
+
</Fragment>
|
|
26
|
+
)}
|
|
27
|
+
</p>
|
|
28
|
+
<div class="brim-consent__actions">
|
|
29
|
+
<button type="button" class="brim-consent__button" data-consent="reject">
|
|
30
|
+
{rejectText}
|
|
31
|
+
</button>
|
|
32
|
+
<button type="button" class="brim-consent__button" data-consent="accept">
|
|
33
|
+
{acceptText}
|
|
34
|
+
</button>
|
|
35
|
+
</div>
|
|
36
|
+
</section>
|
|
37
|
+
</brim-analytics>
|
|
38
|
+
|
|
39
|
+
<script>
|
|
40
|
+
import "./analytics.client.ts";
|
|
41
|
+
</script>
|