@rcooler/consent 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RCooLeR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,57 @@
1
- # Temporary Holding Version
1
+ # @rcooler/consent
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Framework-independent browser consent controls with explicit adapters for
4
+ optional services. Once published, install with `npm install @rcooler/consent`, and serve the
5
+ configuration and receipt endpoints from the same origin as the page.
6
+
7
+ ```ts
8
+ import { deferredScript, initializeConsent } from "@rcooler/consent";
9
+ import "@rcooler/consent/consent.css";
10
+
11
+ const installation = await initializeConsent({ configURL: "/consent/config", locale: "en" });
12
+ const unregister = installation.controller.register(
13
+ "optional-service",
14
+ deferredScript("https://example.com/optional.js"),
15
+ );
16
+
17
+ // On application teardown:
18
+ // unregister();
19
+ // installation.destroy();
20
+ ```
21
+
22
+ Declare the service in the policy and include its ID in the host's
23
+ `allowed_services` for eligible pages. Do not also include its script as an
24
+ active script tag. `initializeConsent` mounts the UI and registers the declared GA4
25
+ service (one per policy); the headless `createConsent` and `mountConsent` exports provide lower
26
+ level control. `mountIframePlaceholder` provides an inert iframe placeholder.
27
+ Adapters are responsible for their own activation and cleanup.
28
+
29
+ The controller checks the site, policy version and epoch when restoring a
30
+ choice. When `receipt_url` is configured, affirmative choices require a receipt
31
+ acknowledgement before optional services activate. Static inline configurations
32
+ may omit that endpoint and retain choices locally without a central receipt history.
33
+ Denial and withdrawal take effect locally even if recording
34
+ fails. When revalidation of a `configURL` fails, optional services stop; a
35
+ recorded refusal is kept, while a grant has to be given again. Declared storage
36
+ of denied services is cleared; the `storage` and `cookies` options of
37
+ `createConsent` replace the browser's own. A service that has already executed
38
+ may leave state behind after its element is removed; an adapter can request a
39
+ reload on withdrawal. The host must account for third-party data and scripts
40
+ outside this library.
41
+
42
+ Regional HTTP configurations bind choices to the current country/state selection,
43
+ policy and resolver version. The controller records browser GPC, combines it with
44
+ the server signal and keeps privacy restrictions separately from category consent.
45
+ `controller.restrict({sale: true, sharing: true, targeted_advertising: true,
46
+ sensitive_data: false})` applies an opt-out and disables optional categories without
47
+ renewing previous grants. `decide` preserves these restrictions unless an explicit
48
+ third argument changes them; an active GPC signal cannot be cleared that way.
49
+
50
+ Declare `service.processing` only after reviewing all four uses. Omitting it means
51
+ unknown processing, which stays blocked under any privacy restriction. Region and
52
+ GPC changes never start trackers automatically. See the project's regional guide
53
+ for source coverage, deployment trust and the limits of browser-only enforcement.
54
+
55
+ For a script-tag installation and Go backend, see the
56
+ [project README](https://github.com/RCooLeR/consent#readme) and
57
+ [HTTP integration guide](https://github.com/RCooLeR/consent/blob/main/httpapi/README.md).
@@ -0,0 +1 @@
1
+ .consent-root{--consent-background: #fff;--consent-foreground: #172027;--consent-border: #65727d;--consent-accent: #075ca8;color:var(--consent-foreground);font:1rem/1.5 system-ui,sans-serif}.consent-root *,.consent-root *:before,.consent-root *:after{box-sizing:border-box}.consent-root [hidden]{display:none!important}.consent-banner,.consent-dialog{background:var(--consent-background);color:var(--consent-foreground);border:1px solid var(--consent-border);border-radius:.75rem;padding:1.25rem;box-shadow:0 .5rem 2rem #0003}.consent-banner{max-block-size:calc(100dvh - 5rem);overflow:auto;position:fixed;inset-inline:1rem;inset-block-end:4rem;z-index:2147483645;max-inline-size:46rem;margin-inline:auto}.consent-root h2{font-size:1.25rem;margin-block:0 .5rem}.consent-root p{margin-block:.5rem 1rem;overflow-wrap:anywhere}.consent-root a{color:var(--consent-accent);text-decoration:underline}.consent-actions{display:flex;flex-wrap:wrap;gap:.65rem;margin-block-start:1rem}.consent-action,.consent-preferences{font:inherit;font-weight:600;background:var(--consent-background);color:var(--consent-foreground);border:1px solid var(--consent-border);border-radius:.375rem;padding:.6rem 1rem;min-block-size:44px;cursor:pointer}.consent-action:disabled{opacity:.65;cursor:wait}.consent-root :focus-visible{outline:3px solid var(--consent-accent);outline-offset:3px}.consent-shortcuts{position:fixed;inset-inline-start:1rem;inset-block-end:.75rem;z-index:2147483645;display:flex;flex-wrap:wrap;gap:.5rem;max-inline-size:calc(100vw - 2rem)}.consent-shortcuts .consent-action{font-size:.875rem}.consent-rights{display:flex;flex-wrap:wrap;gap:1rem}.consent-signal{font-weight:600}.consent-root .consent-failure:empty{margin:0}.consent-status:empty{display:none}.consent-status{position:fixed;inset-inline:1rem;inset-block-start:1rem;z-index:2147483647;padding:.75rem;background:var(--consent-background);border:1px solid var(--consent-border)}.consent-dialog{max-inline-size:min(42rem,calc(100vw - 2rem));max-block-size:calc(100dvh - 2rem);overflow-y:auto}.consent-dialog::backdrop{background:#0008}.consent-categories{display:grid;gap:.75rem;margin-block:1rem}.consent-categories label{display:flex;align-items:center;gap:.65rem;min-block-size:44px;cursor:pointer}.consent-categories input{inline-size:1.25rem;block-size:1.25rem;accent-color:var(--consent-accent)}.consent-inventory section{border-block-start:1px solid var(--consent-border);padding-block:.75rem}.consent-inventory h4{margin-block:0 .25rem}.consent-preview .consent-banner,.consent-preview .consent-shortcuts,.consent-preview .consent-status{position:static;margin-block:.75rem}.consent-placeholder{padding:1rem;border:1px solid var(--consent-border, #65727d)}@media(max-width:36rem){.consent-actions>button{flex:1 1 100%}.consent-banner{inset-inline:.5rem;inset-block-end:10rem;max-block-size:calc(100dvh - 11rem)}}@media(prefers-reduced-motion:reduce){.consent-root *,.consent-root *:before,.consent-root *:after{scroll-behavior:auto;transition:none;animation:none}}
@@ -0,0 +1,18 @@
1
+ import type { ConsentController, PublicConfig } from "./types.js";
2
+ export interface ConsentOptions {
3
+ config: PublicConfig;
4
+ configURL?: string;
5
+ locale?: string;
6
+ storage?: Storage;
7
+ /** Cookie jar used to expire declared cookies of denied services; defaults to the document. */
8
+ cookies?: Pick<Document, "cookie">;
9
+ fetcher?: typeof fetch;
10
+ now?: () => number;
11
+ reload?: () => void;
12
+ origin?: string;
13
+ events?: Pick<Window, "addEventListener" | "removeEventListener">;
14
+ /** Hosts/tests may supply a privacy signal; it can only add to the server signal. */
15
+ privacySignal?: () => boolean;
16
+ }
17
+ /** No optional resource is created by this state machine without an explicit adapter. */
18
+ export declare function createConsent(options: ConsentOptions): ConsentController;