astro-consent 1.0.17 → 2.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/CHANGELOG.md +38 -0
- package/LICENSE.md +1 -1
- package/README.md +221 -120
- package/dist/cli.cjs +228 -264
- package/dist/index.d.ts +10 -0
- package/dist/index.js +222 -80
- package/dist/templates/cssTemplate.cjs +447 -0
- package/dist/templates/cssTemplate.d.ts +1 -1
- package/package.json +8 -6
- package/dist/templates/cssTemplate.js +0 -117
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `astro-consent` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows a simple Keep a Changelog style, with semantic versioning.
|
|
6
|
+
|
|
7
|
+
## [2.0.0] - 2026-04-01
|
|
8
|
+
|
|
9
|
+
### Breaking
|
|
10
|
+
|
|
11
|
+
- Changed the package to a major release after the CLI and integration workflow were expanded.
|
|
12
|
+
- The installer now writes a marked `astro-consent` block into `astro.config.*` so `init` and `remove` can target only the plugin stanza.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `init`, `remove`, `doctor`, and `status` CLI commands
|
|
17
|
+
- `--dry-run` support for install and remove
|
|
18
|
+
- `--json` output for `doctor` and `status`
|
|
19
|
+
- `banner` and `overlay` presentation modes
|
|
20
|
+
- Configurable display timing with `displayUntilIdle` and `displayIdleDelayMs`
|
|
21
|
+
- Configurable copy with `headline`, `description`, `acceptLabel`, `rejectLabel`, and `manageLabel`
|
|
22
|
+
- Separate `cookiePolicyUrl` and `privacyPolicyUrl` support with backwards-compatible `policyUrl` fallback
|
|
23
|
+
- Overlay accessibility improvements, including focus trapping, `Escape` to close, and focus return
|
|
24
|
+
- Generated editable stylesheet at `src/cookiebanner/styles.css`
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- Updated default copy to be more professional and concise
|
|
29
|
+
- Improved banner and overlay motion and spacing
|
|
30
|
+
- Reworked the README into a full onboarding guide
|
|
31
|
+
- Updated package branding to `Velohost UK Limited`
|
|
32
|
+
- Bumped the package major version to `2.0.0`
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- Safer install and removal behavior for `astro.config.*`
|
|
37
|
+
- Removed older CSS injection path in favor of a real generated stylesheet
|
|
38
|
+
- Improved CLI diagnostics and install/status reporting
|
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,90 +1,52 @@
|
|
|
1
1
|
# astro-consent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`astro-consent` is a privacy-first cookie consent integration for Astro. It adds a polished consent banner or overlay, generates an editable stylesheet in your project, and exposes a tiny runtime API for managing stored consent.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## What You Get
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- A banner or overlay consent UI
|
|
8
|
+
- A generated `src/cookiebanner/styles.css` file you can edit directly
|
|
9
|
+
- Idle-based display with a configurable fade-in delay
|
|
10
|
+
- Focus trapping, `Escape` to close, and focus return for the overlay
|
|
11
|
+
- CLI setup, removal, and diagnostics commands
|
|
12
|
+
- TypeScript support
|
|
13
|
+
- Compatibility with Astro 4, 5, and 6
|
|
8
14
|
|
|
9
|
-
##
|
|
15
|
+
## Quick Start
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
**astro-consent** is built differently:
|
|
14
|
-
|
|
15
|
-
- No trackers
|
|
16
|
-
- No remote calls
|
|
17
|
-
- No analytics SDKs
|
|
18
|
-
- No vendor lock-in
|
|
19
|
-
- No runtime dependencies
|
|
20
|
-
|
|
21
|
-
Just a **fast, deterministic, developer-controlled consent layer** that respects user privacy and legal boundaries.
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## ✨ Features
|
|
26
|
-
|
|
27
|
-
- ✅ GDPR / UK GDPR friendly
|
|
28
|
-
- 🍪 Consent categories: Essential, Analytics, Marketing
|
|
29
|
-
- 🎛️ Preferences modal with toggle switches
|
|
30
|
-
- ⚡ Zero runtime dependencies
|
|
31
|
-
- 🎨 Fully themeable via CSS variables
|
|
32
|
-
- 🧠 Frontend-controlled script loading
|
|
33
|
-
- 🧩 Native Astro integration
|
|
34
|
-
- 🧾 Built-in TypeScript declarations
|
|
35
|
-
- 🛠️ CLI installer & remover
|
|
36
|
-
- 🔁 Clean uninstall with no residue
|
|
37
|
-
- 🌍 Framework-agnostic frontend API
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## 📦 Installation (Required)
|
|
42
|
-
|
|
43
|
-
This package uses **both an Astro integration and a CLI installer**.
|
|
44
|
-
|
|
45
|
-
### 1️⃣ Install the package
|
|
17
|
+
### 1. Install the package
|
|
46
18
|
|
|
47
19
|
```bash
|
|
48
20
|
npm install astro-consent
|
|
49
21
|
```
|
|
50
22
|
|
|
51
|
-
|
|
23
|
+
### 2. Add the integration
|
|
52
24
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### 2️⃣ Run the installer
|
|
25
|
+
Use the CLI to wire everything into your Astro project:
|
|
56
26
|
|
|
57
27
|
```bash
|
|
58
|
-
npx astro-consent
|
|
28
|
+
npx astro-consent init
|
|
59
29
|
```
|
|
60
30
|
|
|
61
|
-
|
|
31
|
+
That will:
|
|
62
32
|
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
33
|
+
- add `astro-consent` to `astro.config.*`
|
|
34
|
+
- create `src/cookiebanner/styles.css` if it is missing
|
|
35
|
+
- add a starter configuration block with placeholder values
|
|
66
36
|
|
|
67
|
-
|
|
37
|
+
### 3. Edit the generated CSS
|
|
68
38
|
|
|
69
|
-
|
|
39
|
+
Open `src/cookiebanner/styles.css` in your project and customize the banner or modal visually. The package does not inject CSS through JavaScript, so this file is the single source of truth for styling.
|
|
70
40
|
|
|
71
|
-
###
|
|
41
|
+
### 4. Run your Astro app
|
|
72
42
|
|
|
73
43
|
```bash
|
|
74
|
-
|
|
44
|
+
npm run dev
|
|
75
45
|
```
|
|
76
46
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- The integration entry
|
|
80
|
-
- Generated files
|
|
81
|
-
- All banner logic
|
|
82
|
-
|
|
83
|
-
No orphaned config. No hidden state.
|
|
84
|
-
|
|
85
|
-
---
|
|
47
|
+
## Recommended Setup
|
|
86
48
|
|
|
87
|
-
|
|
49
|
+
The default install is designed to be easy to understand and safe to customise. A typical configuration looks like this:
|
|
88
50
|
|
|
89
51
|
```ts
|
|
90
52
|
import astroConsent from "astro-consent";
|
|
@@ -93,108 +55,247 @@ export default {
|
|
|
93
55
|
integrations: [
|
|
94
56
|
astroConsent({
|
|
95
57
|
siteName: "My Website",
|
|
96
|
-
|
|
58
|
+
headline: "Manage cookie preferences for My Website",
|
|
59
|
+
description:
|
|
60
|
+
"We use cookies to improve site performance, measure traffic, and support marketing.",
|
|
61
|
+
acceptLabel: "Accept all",
|
|
62
|
+
rejectLabel: "Reject all",
|
|
63
|
+
manageLabel: "Manage preferences",
|
|
64
|
+
cookiePolicyUrl: "/cookie-policy",
|
|
65
|
+
privacyPolicyUrl: "/privacy",
|
|
66
|
+
displayUntilIdle: true,
|
|
67
|
+
displayIdleDelayMs: 1000,
|
|
68
|
+
presentation: "banner",
|
|
97
69
|
consent: {
|
|
98
70
|
days: 30,
|
|
99
|
-
storageKey: "astro-
|
|
100
|
-
},
|
|
101
|
-
categories: {
|
|
102
|
-
analytics: false,
|
|
103
|
-
marketing: false
|
|
71
|
+
storageKey: "astro-consent"
|
|
104
72
|
}
|
|
105
73
|
})
|
|
106
74
|
]
|
|
107
75
|
};
|
|
108
76
|
```
|
|
109
77
|
|
|
110
|
-
|
|
78
|
+
## CLI Commands
|
|
111
79
|
|
|
112
|
-
|
|
113
|
-
A full, public URL to your Privacy or Cookie Policy page.
|
|
114
|
-
This is linked directly from the consent banner.
|
|
80
|
+
### `init`
|
|
115
81
|
|
|
116
|
-
|
|
117
|
-
|
|
82
|
+
```bash
|
|
83
|
+
npx astro-consent init
|
|
84
|
+
```
|
|
118
85
|
|
|
119
|
-
|
|
120
|
-
The `localStorage` key used to persist consent.
|
|
121
|
-
You may change this freely if you need per-site or per-environment isolation.
|
|
86
|
+
Adds the integration import and a marked configuration block to `astro.config.*`, then creates `src/cookiebanner/styles.css` if the file does not already exist.
|
|
122
87
|
|
|
123
|
-
|
|
124
|
-
Allows analytics scripts to load only after consent.
|
|
125
|
-
Typical use: Plausible, self-hosted analytics, Google Analytics.
|
|
88
|
+
### `remove`
|
|
126
89
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
90
|
+
```bash
|
|
91
|
+
npx astro-consent remove
|
|
92
|
+
```
|
|
130
93
|
|
|
131
|
-
|
|
94
|
+
Removes the marked `astro-consent` block from `astro.config.*`, removes the import, and deletes `src/cookiebanner/styles.css` if it exists.
|
|
132
95
|
|
|
133
|
-
|
|
96
|
+
### `doctor`
|
|
134
97
|
|
|
135
|
-
|
|
98
|
+
```bash
|
|
99
|
+
npx astro-consent doctor
|
|
100
|
+
```
|
|
136
101
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
102
|
+
Checks the following:
|
|
103
|
+
|
|
104
|
+
- Astro config import wiring
|
|
105
|
+
- `astroConsent(...)` integration wiring
|
|
106
|
+
- `src/cookiebanner/styles.css` existence
|
|
107
|
+
- `src/layouts/BaseLayout.astro` importing the stylesheet
|
|
108
|
+
|
|
109
|
+
Use JSON output for automation:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx astro-consent doctor --json
|
|
141
113
|
```
|
|
142
114
|
|
|
143
|
-
|
|
115
|
+
### `status`
|
|
144
116
|
|
|
145
|
-
|
|
117
|
+
```bash
|
|
118
|
+
npx astro-consent status
|
|
119
|
+
```
|
|
146
120
|
|
|
147
|
-
|
|
121
|
+
Reports the current install state:
|
|
148
122
|
|
|
149
|
-
|
|
123
|
+
- whether the Astro config is wired
|
|
124
|
+
- whether the stylesheet exists
|
|
125
|
+
- whether the package is linked into `node_modules`
|
|
126
|
+
- which consent storage key is configured
|
|
127
|
+
- a note explaining that actual consent state is browser-side
|
|
150
128
|
|
|
151
|
-
|
|
129
|
+
JSON output is also available:
|
|
152
130
|
|
|
153
|
-
|
|
131
|
+
```bash
|
|
132
|
+
npx astro-consent status --json
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Dry Run
|
|
136
|
+
|
|
137
|
+
Preview changes without writing files:
|
|
154
138
|
|
|
139
|
+
```bash
|
|
140
|
+
npx astro-consent init --dry-run
|
|
141
|
+
npx astro-consent remove --dry-run
|
|
155
142
|
```
|
|
156
|
-
|
|
143
|
+
|
|
144
|
+
## Presentation Modes
|
|
145
|
+
|
|
146
|
+
You can choose how the consent UI appears:
|
|
147
|
+
|
|
148
|
+
- `banner` for a standard bottom-of-page consent banner
|
|
149
|
+
- `overlay` for a centered modal-first experience
|
|
150
|
+
|
|
151
|
+
Example:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
astroConsent({
|
|
155
|
+
presentation: "overlay"
|
|
156
|
+
});
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
## Display Timing
|
|
160
|
+
|
|
161
|
+
The consent UI can wait until the browser is idle before appearing, then fade in after a short pause.
|
|
162
|
+
|
|
163
|
+
### `displayUntilIdle`
|
|
164
|
+
|
|
165
|
+
When `true`, the banner or overlay waits for browser idle before showing.
|
|
166
|
+
|
|
167
|
+
### `displayIdleDelayMs`
|
|
160
168
|
|
|
161
|
-
|
|
169
|
+
Adds a delay after idle before the UI becomes visible.
|
|
162
170
|
|
|
163
|
-
|
|
171
|
+
Example:
|
|
164
172
|
|
|
165
173
|
```ts
|
|
166
|
-
|
|
174
|
+
astroConsent({
|
|
175
|
+
displayUntilIdle: true,
|
|
176
|
+
displayIdleDelayMs: 1000
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Copy Customisation
|
|
181
|
+
|
|
182
|
+
These options let you tune the wording without editing the runtime:
|
|
183
|
+
|
|
184
|
+
- `siteName` sets the site name used in fallback copy
|
|
185
|
+
- `headline` sets the banner or dialog title
|
|
186
|
+
- `description` sets the explanatory text
|
|
187
|
+
- `acceptLabel` sets the primary action
|
|
188
|
+
- `rejectLabel` sets the reject action
|
|
189
|
+
- `manageLabel` sets the preferences action
|
|
190
|
+
|
|
191
|
+
Example:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
astroConsent({
|
|
195
|
+
siteName: "Escape Zone",
|
|
196
|
+
headline: "Manage cookie preferences for Escape Zone",
|
|
197
|
+
description:
|
|
198
|
+
"We use cookies to improve site performance, measure traffic, and support marketing.",
|
|
199
|
+
acceptLabel: "Accept all",
|
|
200
|
+
rejectLabel: "Reject all",
|
|
201
|
+
manageLabel: "Manage preferences"
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Policy Links
|
|
206
|
+
|
|
207
|
+
The consent UI supports separate links for cookie and privacy policy pages.
|
|
208
|
+
|
|
209
|
+
- `cookiePolicyUrl` controls the cookie policy link
|
|
210
|
+
- `privacyPolicyUrl` controls the privacy policy link
|
|
211
|
+
|
|
212
|
+
If you still pass `policyUrl`, it will be used for both links as a backwards-compatible fallback.
|
|
213
|
+
|
|
214
|
+
## Runtime API
|
|
215
|
+
|
|
216
|
+
The integration exposes a small browser API on `window.astroConsent`:
|
|
217
|
+
|
|
218
|
+
```js
|
|
219
|
+
window.astroConsent.get();
|
|
220
|
+
window.astroConsent.set({ essential: true, analytics: true, marketing: false });
|
|
221
|
+
window.astroConsent.reset();
|
|
167
222
|
```
|
|
168
223
|
|
|
169
|
-
|
|
224
|
+
- `get()` returns the stored consent object if one exists and is still valid
|
|
225
|
+
- `set(...)` stores a new consent state
|
|
226
|
+
- `reset()` clears consent and reloads the page
|
|
227
|
+
|
|
228
|
+
## Styling
|
|
229
|
+
|
|
230
|
+
The generated `src/cookiebanner/styles.css` file is meant to be edited directly.
|
|
231
|
+
|
|
232
|
+
It uses `cb-*` custom properties so you can change the visual style without rewriting selectors. The most useful tokens are:
|
|
233
|
+
|
|
234
|
+
- `--cb-bg`
|
|
235
|
+
- `--cb-text`
|
|
236
|
+
- `--cb-muted`
|
|
237
|
+
- `--cb-border`
|
|
238
|
+
- `--cb-accent`
|
|
239
|
+
- `--cb-accent-strong`
|
|
240
|
+
- `--cb-success`
|
|
241
|
+
- `--cb-shadow`
|
|
242
|
+
- `--cb-banner-radius`
|
|
243
|
+
- `--cb-modal-width`
|
|
244
|
+
- `--cb-button-bg`
|
|
245
|
+
- `--cb-button-secondary-bg`
|
|
246
|
+
|
|
247
|
+
## File Layout
|
|
248
|
+
|
|
249
|
+
The installer creates the stylesheet here:
|
|
250
|
+
|
|
251
|
+
```txt
|
|
252
|
+
src/cookiebanner/styles.css
|
|
253
|
+
```
|
|
170
254
|
|
|
171
|
-
|
|
172
|
-
- All colours, spacing, radius, and animations are controlled via CSS variables
|
|
173
|
-
- Full visual control with zero JavaScript theming
|
|
255
|
+
That file is intentionally local to your project. It is not injected from the package at runtime, which keeps styling under your control and avoids overwriting custom work.
|
|
174
256
|
|
|
175
|
-
|
|
257
|
+
## Notes
|
|
176
258
|
|
|
177
|
-
|
|
259
|
+
- Consent is stored in `localStorage`
|
|
260
|
+
- The stored value expires after the configured TTL
|
|
261
|
+
- Optional categories default to checked in the UI, but users can still reject them
|
|
262
|
+
- The overlay uses accessible dialog behavior, including focus trapping, `Escape` to close, and focus return to the trigger
|
|
178
263
|
|
|
179
|
-
|
|
180
|
-
- No tracking without permission
|
|
181
|
-
- No external requests
|
|
182
|
-
- Stored locally with TTL
|
|
264
|
+
## Troubleshooting
|
|
183
265
|
|
|
184
|
-
|
|
266
|
+
### The banner does not appear
|
|
185
267
|
|
|
186
|
-
|
|
268
|
+
Check the following:
|
|
187
269
|
|
|
188
|
-
|
|
270
|
+
1. `npx astro-consent init` has been run in the Astro project root
|
|
271
|
+
2. `astro.config.*` includes the `astro-consent` integration
|
|
272
|
+
3. `src/layouts/BaseLayout.astro` imports `../cookiebanner/styles.css`
|
|
273
|
+
4. You have not already stored consent in `localStorage`
|
|
189
274
|
|
|
190
|
-
|
|
275
|
+
### The CLI says the stylesheet is missing
|
|
276
|
+
|
|
277
|
+
Run:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
npx astro-consent init
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### The CLI says the config is not wired
|
|
284
|
+
|
|
285
|
+
Run:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
npx astro-consent doctor
|
|
289
|
+
```
|
|
191
290
|
|
|
192
|
-
|
|
291
|
+
and follow the fix instructions it prints.
|
|
193
292
|
|
|
194
|
-
|
|
293
|
+
## Why the Package Works This Way
|
|
195
294
|
|
|
196
|
-
|
|
295
|
+
The design is intentionally simple:
|
|
197
296
|
|
|
198
|
-
|
|
297
|
+
- the runtime handles consent logic and UI behavior
|
|
298
|
+
- the generated stylesheet handles appearance
|
|
299
|
+
- the CLI wires setup and removal cleanly
|
|
199
300
|
|
|
200
|
-
|
|
301
|
+
That separation keeps the plugin predictable, easier to debug, and safer to customise.
|