astro-consent 1.0.0 → 1.0.3
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/dist/cli.cjs +11 -11
- package/dist/index.js +13 -17
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -69,13 +69,13 @@ let source = fs.readFileSync(configPath, "utf8");
|
|
|
69
69
|
REMOVE MODE
|
|
70
70
|
───────────────────────────────────── */
|
|
71
71
|
if (command === "remove") {
|
|
72
|
-
source = source.replace(/\s*
|
|
73
|
-
source = source.replace(/import\s+
|
|
72
|
+
source = source.replace(/\s*astroConsent\s*\(\s*\{[\s\S]*?\}\s*\),?/gm, "");
|
|
73
|
+
source = source.replace(/import\s+astroConsent\s+from\s+["']astro-consent["'];?\n?/, "");
|
|
74
74
|
fs.writeFileSync(configPath, source.trim() + "\n", "utf8");
|
|
75
75
|
const cssFile = path.join(CWD, "src", "cookiebanner.css");
|
|
76
76
|
if (fs.existsSync(cssFile))
|
|
77
77
|
fs.unlinkSync(cssFile);
|
|
78
|
-
console.log("\n🧹 astro-
|
|
78
|
+
console.log("\n🧹 astro-consent fully removed\n");
|
|
79
79
|
process.exit(0);
|
|
80
80
|
}
|
|
81
81
|
/* ─────────────────────────────────────
|
|
@@ -91,7 +91,7 @@ if (!fs.existsSync(cssDir)) {
|
|
|
91
91
|
───────────────────────────────────── */
|
|
92
92
|
if (!fs.existsSync(cssFile)) {
|
|
93
93
|
fs.writeFileSync(cssFile, `/* =========================================================
|
|
94
|
-
astro-
|
|
94
|
+
astro-consent — FULL THEME VARIABLES
|
|
95
95
|
All visuals are controlled from here.
|
|
96
96
|
This file is NEVER overwritten.
|
|
97
97
|
========================================================= */
|
|
@@ -286,16 +286,16 @@ if (!fs.existsSync(cssFile)) {
|
|
|
286
286
|
/* ─────────────────────────────────────
|
|
287
287
|
Inject Astro integration
|
|
288
288
|
───────────────────────────────────── */
|
|
289
|
-
if (!source.includes(`from "astro-
|
|
290
|
-
source = `import
|
|
289
|
+
if (!source.includes(`from "astro-consent"`)) {
|
|
290
|
+
source = `import astroConsent from "astro-consent";\n${source}`;
|
|
291
291
|
}
|
|
292
|
-
if (!source.includes("
|
|
293
|
-
const injection = `
|
|
292
|
+
if (!source.includes("astroConsent(")) {
|
|
293
|
+
const injection = ` astroConsent({
|
|
294
294
|
siteName: "My Website",
|
|
295
295
|
policyUrl: "/privacy",
|
|
296
296
|
consent: {
|
|
297
297
|
days: 30,
|
|
298
|
-
storageKey: "astro-
|
|
298
|
+
storageKey: "astro-consent"
|
|
299
299
|
},
|
|
300
300
|
categories: {
|
|
301
301
|
analytics: false,
|
|
@@ -306,6 +306,6 @@ if (!source.includes("astroCookieBanner(")) {
|
|
|
306
306
|
source = source.replace(/integrations\s*:\s*\[/, match => `${match}\n${injection}`);
|
|
307
307
|
}
|
|
308
308
|
fs.writeFileSync(configPath, source, "utf8");
|
|
309
|
-
console.log("\n🎉 astro-
|
|
309
|
+
console.log("\n🎉 astro-consent installed successfully");
|
|
310
310
|
console.log("👉 Edit src/cookiebanner.css to theme everything");
|
|
311
|
-
console.log("👉 Run `astro-
|
|
311
|
+
console.log("👉 Run `astro-consent remove` to uninstall\n");
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function astroConsent(options = {}) {
|
|
2
2
|
const siteName = options.siteName ?? "This website";
|
|
3
3
|
const policyUrl = options.policyUrl ?? "/privacy";
|
|
4
4
|
const consentDays = options.consent?.days ?? 30;
|
|
5
|
-
const storageKey = options.consent?.storageKey ?? "astro-
|
|
5
|
+
const storageKey = options.consent?.storageKey ?? "astro-consent";
|
|
6
6
|
const defaultCategories = {
|
|
7
7
|
essential: true,
|
|
8
8
|
analytics: false,
|
|
@@ -11,11 +11,11 @@ export default function astroCookieBanner(options = {}) {
|
|
|
11
11
|
};
|
|
12
12
|
const ttl = consentDays * 24 * 60 * 60 * 1000;
|
|
13
13
|
return {
|
|
14
|
-
name: "astro-
|
|
14
|
+
name: "astro-consent",
|
|
15
15
|
hooks: {
|
|
16
16
|
"astro:config:setup": ({ injectScript }) => {
|
|
17
17
|
/* ─────────────────────────────────────
|
|
18
|
-
|
|
18
|
+
Styles (banner + modal)
|
|
19
19
|
───────────────────────────────────── */
|
|
20
20
|
injectScript("head-inline", `
|
|
21
21
|
const style = document.createElement("style");
|
|
@@ -32,7 +32,7 @@ style.innerHTML = \`
|
|
|
32
32
|
|
|
33
33
|
/* ───── Banner ───── */
|
|
34
34
|
|
|
35
|
-
#astro-
|
|
35
|
+
#astro-consent-banner {
|
|
36
36
|
position: fixed;
|
|
37
37
|
left: 16px;
|
|
38
38
|
right: 16px;
|
|
@@ -115,7 +115,7 @@ style.innerHTML = \`
|
|
|
115
115
|
|
|
116
116
|
/* ───── Modal ───── */
|
|
117
117
|
|
|
118
|
-
#astro-
|
|
118
|
+
#astro-consent-modal {
|
|
119
119
|
position: fixed;
|
|
120
120
|
inset: 0;
|
|
121
121
|
background: rgba(0,0,0,.55);
|
|
@@ -136,10 +136,6 @@ style.innerHTML = \`
|
|
|
136
136
|
color: var(--cb-text);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
.cb-modal h3 {
|
|
140
|
-
margin: 0 0 16px;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
139
|
.cb-row {
|
|
144
140
|
display: flex;
|
|
145
141
|
justify-content: space-between;
|
|
@@ -221,7 +217,7 @@ document.head.appendChild(style);
|
|
|
221
217
|
}));
|
|
222
218
|
}
|
|
223
219
|
|
|
224
|
-
window.
|
|
220
|
+
window.astroConsent = {
|
|
225
221
|
get: read,
|
|
226
222
|
set: write,
|
|
227
223
|
reset(){
|
|
@@ -236,12 +232,12 @@ document.head.appendChild(style);
|
|
|
236
232
|
───────────────────────────────────── */
|
|
237
233
|
injectScript("page", `
|
|
238
234
|
(() => {
|
|
239
|
-
if (window.
|
|
235
|
+
if (window.astroConsent.get()) return;
|
|
240
236
|
|
|
241
237
|
const state = { ...${JSON.stringify(defaultCategories)} };
|
|
242
238
|
|
|
243
239
|
const banner = document.createElement("div");
|
|
244
|
-
banner.id = "astro-
|
|
240
|
+
banner.id = "astro-consent-banner";
|
|
245
241
|
|
|
246
242
|
banner.innerHTML = \`
|
|
247
243
|
<div class="cb-container">
|
|
@@ -263,12 +259,12 @@ document.head.appendChild(style);
|
|
|
263
259
|
document.body.appendChild(banner);
|
|
264
260
|
|
|
265
261
|
banner.querySelector(".cb-accept").onclick = () => {
|
|
266
|
-
window.
|
|
262
|
+
window.astroConsent.set({ essential:true, analytics:true, marketing:true });
|
|
267
263
|
banner.remove();
|
|
268
264
|
};
|
|
269
265
|
|
|
270
266
|
banner.querySelector(".cb-reject").onclick = () => {
|
|
271
|
-
window.
|
|
267
|
+
window.astroConsent.set({ essential:true });
|
|
272
268
|
banner.remove();
|
|
273
269
|
};
|
|
274
270
|
|
|
@@ -276,7 +272,7 @@ document.head.appendChild(style);
|
|
|
276
272
|
|
|
277
273
|
function openModal(){
|
|
278
274
|
const modal = document.createElement("div");
|
|
279
|
-
modal.id = "astro-
|
|
275
|
+
modal.id = "astro-consent-modal";
|
|
280
276
|
|
|
281
277
|
modal.innerHTML = \`
|
|
282
278
|
<div class="cb-modal">
|
|
@@ -316,7 +312,7 @@ document.head.appendChild(style);
|
|
|
316
312
|
});
|
|
317
313
|
|
|
318
314
|
modal.querySelector(".cb-accept").onclick = () => {
|
|
319
|
-
window.
|
|
315
|
+
window.astroConsent.set({ essential:true, ...state });
|
|
320
316
|
modal.remove();
|
|
321
317
|
banner.remove();
|
|
322
318
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-consent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A privacy-first, GDPR-compliant cookie consent banner for Astro with a built-in preferences modal, zero dependencies, and full theme control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
".": "./dist/index.js"
|
|
22
22
|
},
|
|
23
23
|
"bin": {
|
|
24
|
-
"astro-
|
|
24
|
+
"astro-consent": "dist/cli.cjs"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"LICENSE.md"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cli.json"
|
|
32
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cli.json && mv dist/cli.js dist/cli.cjs"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
35
35
|
"astro",
|