@jini-ai/cookie-consent 0.0.0-stage → 0.6.15-rc.2
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 +201 -0
- package/README.md +100 -2
- package/dist/banner.css +45 -0
- package/dist/client/dom.d.ts +33 -0
- package/dist/client/dom.js +137 -0
- package/dist/client/entry.d.ts +2 -0
- package/dist/client/entry.js +7 -0
- package/dist/client/index.d.ts +45 -0
- package/dist/client/index.js +230 -0
- package/dist/client.min.js +1 -0
- package/dist/contract.d.ts +206 -0
- package/dist/contract.js +26 -0
- package/dist/node/index.d.ts +67 -0
- package/dist/node/index.js +231 -0
- package/dist/plugins.d.ts +15 -0
- package/dist/plugins.js +78 -0
- package/dist/policy.d.ts +47 -0
- package/dist/policy.js +95 -0
- package/dist/render/banner.d.ts +64 -0
- package/dist/render/banner.js +96 -0
- package/dist/render/base-css.d.ts +4 -0
- package/dist/render/base-css.js +35 -0
- package/dist/render/css-parser.d.ts +31 -0
- package/dist/render/css-parser.js +170 -0
- package/dist/render/css.d.ts +50 -0
- package/dist/render/css.js +259 -0
- package/dist/render/index.d.ts +7 -0
- package/dist/render/index.js +5 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +4 -0
- package/dist/server/receipt.d.ts +70 -0
- package/dist/server/receipt.js +94 -0
- package/dist/server/region.d.ts +22 -0
- package/dist/server/region.js +46 -0
- package/package.json +95 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Open Design contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jini-ai/cookie-consent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cookie consent with no dependencies and no vendor code. It has five parts:
|
|
4
|
+
|
|
5
|
+
- a consent-state contract that any banner can drive,
|
|
6
|
+
- a small browser client (`dist/client.min.js`),
|
|
7
|
+
- a banner renderer that returns plain strings, with owner CSS,
|
|
8
|
+
- web-standard receipts (`Request` → `Response`),
|
|
9
|
+
- open plugin slots.
|
|
10
|
+
|
|
11
|
+
Vendors (analytics, ads, region lookups) plug in from their own packages.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @jini-ai/cookie-consent
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Standalone use
|
|
20
|
+
|
|
21
|
+
Render on the server (or at build time), serve the client and mount the receipt endpoint.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { renderBanner } from '@jini-ai/cookie-consent/render';
|
|
25
|
+
|
|
26
|
+
const { head, body, problems } = renderBanner(
|
|
27
|
+
{ mode: 'jini', client: { contract: 1, policy: '2026-10-26', regionMode: 'auto' }, copy: { privacyPolicyUrl: '/privacy' } },
|
|
28
|
+
{ clientSrc: '/consent/client.min.js', evidence: { mode: 'durable', endpoint: '/_consent' } },
|
|
29
|
+
);
|
|
30
|
+
// Put `head` in <head> and `body` at the end of <body>. Serve
|
|
31
|
+
// node_modules/@jini-ai/cookie-consent/dist/client.min.js at /consent/client.min.js.
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { handleReceipt } from '@jini-ai/cookie-consent/server';
|
|
36
|
+
import { createConsentFileRecords, createNodeConsentFiles } from '@jini-ai/cookie-consent/node';
|
|
37
|
+
|
|
38
|
+
const store = createConsentFileRecords({ directory: './consent-receipts', files: createNodeConsentFiles({ atomicWrite }) });
|
|
39
|
+
// POST /_consent, with request.url built from the site's PUBLIC origin:
|
|
40
|
+
const response = await handleReceipt({ request, ports: { store, policy: () => '2026-10-26', ids: () => crypto.randomUUID(), now: Date.now } });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- **Modes:**
|
|
44
|
+
- `jini` is the built-in banner.
|
|
45
|
+
- `headless` is your own banner. It drives `window.jiniConsent` (`get`, `set`, `subscribe`, `open`, `setOpen`).
|
|
46
|
+
- `off` renders the client config without banner UI and permits anonymous analytics only. It writes no consent cookie or receipt and ignores earlier choices. Raw inert tags stay blocked.
|
|
47
|
+
- **Evidence:**
|
|
48
|
+
- `durable`: a grant only takes effect once the server has stored its receipt.
|
|
49
|
+
- `local`: the record stays in the browser (static export, Electron, `file:`) and is labelled as browser-only.
|
|
50
|
+
- Denial applies before any network call. Global Privacy Control or DNT turns off analytics and marketing (including anonymous analytics), and nothing can turn them back on. The receipt response never sets a cookie.
|
|
51
|
+
- Choices use `jini_choices`, separate from the older CMS engine's HttpOnly `jini_consent`. Old cookies are never imported as consent; returning visitors choose once under this engine. Hosts may expire the old host-only cookie when switching engines.
|
|
52
|
+
- **Server-side gate:** `readConsent({ cookieHeader, policy, regionMode }, { secGpc, dnt, anonymous })` from `./server`. Bind `anonymous: true` when the banner is off. The historical `gpc` state/receipt field records the effective GPC-or-DNT opt-out.
|
|
53
|
+
- **Inert tags:**
|
|
54
|
+
- `<script type="text/plain" data-consent-category="analytics">` runs only once its category is allowed.
|
|
55
|
+
- `<iframe data-consent-category data-src>` loads only once its category is allowed.
|
|
56
|
+
|
|
57
|
+
A runnable example is in `examples/cookie-consent-standalone` (it includes a slow fake vendor that shows queueing).
|
|
58
|
+
|
|
59
|
+
## Plugin slots
|
|
60
|
+
|
|
61
|
+
The slot set is open. Each kind is a string. A contribution for a kind that no slot defines yet waits until `defineSlot` arrives. Every register or inject call takes `(required, optional)` objects.
|
|
62
|
+
|
|
63
|
+
- **Browser adapters** (`kind: 'consent-adapter'`, category `functional` | `analytics` | `marketing`). There are two forms:
|
|
64
|
+
- Lazy: `{ id, kind, category, src, config }` goes in the page config's `plugins`, and the module at `src` is imported on grant, or for cleanup in off mode when `supportsAnonymous: true`.
|
|
65
|
+
- Live: the module is pushed before or after the client loads:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
(window.jiniConsentQueue ||= []).push({ id: 'stats', kind: 'consent-adapter', category: 'analytics',
|
|
69
|
+
grant({ config, state, signal }) { /* start the vendor */ return { revoke() { /* stop it */ return true; } }; } });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
In off mode `allowed.analytics` is always `false`; `state.analyticsLevel` is `anonymous` (or `none` under GPC/DNT). Adapters must read `state.analyticsLevel` (`none` | `anonymous` | `full`). Only adapters declaring `supportsAnonymous: true` can run in off mode. Anonymous means no cookies/localStorage/sessionStorage created, no cross-page identifier, person profiles, IP geolocation, replay or form-input capture. Adapters remove their own leftover identity at anonymous/none levels; off-mode adapters may be imported for this cleanup without a grant. Hosts must pass the server decision to collectors; a browser payload never sets its own level.
|
|
73
|
+
|
|
74
|
+
If `revoke()` returns false (or is missing), the page reloads so that it ends up clean.
|
|
75
|
+
- **Server region resolvers** (`kind: 'region-resolver'`). There are two forms:
|
|
76
|
+
- Live: `resolve({ request })`.
|
|
77
|
+
- Data only: `{ header, usValues }`. `REGION_SLOT` turns this into a header resolver.
|
|
78
|
+
|
|
79
|
+
`resolveRegion` takes the first definite answer. A resolver that throws or times out, or no resolver knowing the answer, gives `strict`. An unknown region always gets the strict banner, with Reject on the first layer. There is no geo file.
|
|
80
|
+
- **Any other kind:** call `createPluginRegistry({}, { slots: [mySlot] })`, or `registry.defineSlot({ slot })` at any time.
|
|
81
|
+
|
|
82
|
+
## Editing the banner CSS
|
|
83
|
+
|
|
84
|
+
Owners can write any selector under `#jini-consent`, `.jini-consent` or `.jini-consent-reopen`. The compiler handles bad input like this:
|
|
85
|
+
|
|
86
|
+
- A bad rule is dropped and reported in `problems`. The other rules still apply.
|
|
87
|
+
- A syntax error drops only the custom CSS. Appearance tokens still apply.
|
|
88
|
+
- Text whose contrast is below 4.5:1 drops only the root colors.
|
|
89
|
+
|
|
90
|
+
Some selectors are refused, so that Reject always looks like Accept:
|
|
91
|
+
|
|
92
|
+
- attribute selectors,
|
|
93
|
+
- structural pseudo-classes (`:first-child`, `:not`, ...),
|
|
94
|
+
- pseudo-elements,
|
|
95
|
+
- `+` and `~`.
|
|
96
|
+
|
|
97
|
+
An engine parity block is always added after the owner's CSS. `compileConsentCss({ css, tokens })` (from `./render`) gives an editor the same result as the live page. The admin preview renders with `preview: { region }` and puts `htmlAttrs` on the preview iframe's `<html>`.
|
|
98
|
+
|
|
99
|
+
## Size
|
|
100
|
+
|
|
101
|
+
`dist/client.min.js` is about 4.4 KB gzipped, and that includes the built-in banner binding. The build fails above 4,608 bytes (`npm run build` prints the size). The design target was about 3 KB. The gate is set to stop further growth, not to bless the current size.
|
package/dist/banner.css
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
.jini-consent{--consent-bg:var(--jini-surface,var(--bg,Canvas));--consent-fg:var(--jini-text,var(--fg,CanvasText));--consent-border:var(--jini-border,var(--border,color-mix(in srgb,var(--consent-fg) 14%,var(--consent-bg))));--consent-accent:var(--jini-accent,var(--accent,var(--consent-fg)));--consent-radius:var(--jini-radius,14px);--consent-button-bg:color-mix(in srgb,var(--consent-fg) 7%,var(--consent-bg));--consent-button-hover-bg:color-mix(in srgb,var(--consent-fg) 13%,var(--consent-bg));--consent-button-border:color-mix(in srgb,var(--consent-fg) 26%,var(--consent-bg));--consent-shadow:0 1px 2px #0000000f,0 12px 32px #00000024;position:fixed;inset:auto 1rem 1rem;z-index:2147483647;margin:auto;max-width:380px;max-height:85dvh;overflow:auto;padding:14px 16px;border:1px solid var(--consent-border);border-radius:var(--consent-radius);background:var(--consent-bg);color:var(--consent-fg);box-shadow:var(--consent-shadow);font:inherit;font-size:13.5px;line-height:1.45;text-align:start;box-sizing:border-box}
|
|
3
|
+
.jini-consent *,.jini-consent *::before,.jini-consent *::after{box-sizing:border-box}
|
|
4
|
+
.jini-consent h2{font:inherit;font-size:15px;font-weight:650;margin:0 0 4px;color:inherit}
|
|
5
|
+
.jini-consent p{margin:0 0 6px;color:inherit}
|
|
6
|
+
.jini-consent-links{font-size:12.5px}
|
|
7
|
+
.jini-consent-actions{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(120px,100%),1fr));gap:8px;margin-top:10px}
|
|
8
|
+
.jini-consent button,.jini-consent summary,.jini-consent-reopen{font:inherit;cursor:pointer}
|
|
9
|
+
.jini-consent button{min-height:34px;padding:4px 12px;border:1px solid var(--consent-button-border);border-radius:8px;background:var(--consent-button-bg);color:inherit;font-weight:600;transition:background-color .15s ease,border-color .15s ease}
|
|
10
|
+
.jini-consent button:hover{background:var(--consent-button-hover-bg)}
|
|
11
|
+
.jini-consent .jini-consent-link{margin-top:10px;padding:0;min-height:0;border:0;background:transparent;font-size:12.5px;font-weight:400;text-decoration:underline;text-underline-offset:.2em}
|
|
12
|
+
.jini-consent a{color:inherit;text-decoration:underline;text-underline-offset:.2em;text-decoration-thickness:1px}
|
|
13
|
+
.jini-consent :focus-visible{outline:3px solid currentColor;outline-offset:2px;border-radius:8px}
|
|
14
|
+
.jini-consent details{margin-top:10px}
|
|
15
|
+
.jini-consent summary{display:inline-flex;align-items:center;list-style:none;font-size:12.5px;text-decoration:underline;text-underline-offset:.2em}
|
|
16
|
+
.jini-consent summary::-webkit-details-marker{display:none}
|
|
17
|
+
.jini-consent fieldset{margin:.25rem 0 0;padding:.25rem .875rem;border:1px solid var(--consent-border);border-radius:12px}
|
|
18
|
+
.jini-consent legend{padding:0 .35rem;font-size:.8125rem;font-weight:600;color:inherit}
|
|
19
|
+
.jini-consent label{display:flex;align-items:center;gap:.6rem;padding:.35rem 0;min-height:32px}
|
|
20
|
+
.jini-consent input{width:1.15rem;height:1.15rem;margin:0;accent-color:var(--consent-accent)}
|
|
21
|
+
#jini-consent:where([data-placement="bottom-left"]){inset:auto auto 1rem 1rem}
|
|
22
|
+
#jini-consent:where([data-placement="bottom-right"]){inset:auto 1rem 1rem auto}
|
|
23
|
+
#jini-consent:where([data-placement="top-bar"]){inset:1rem 1rem auto}
|
|
24
|
+
.jini-consent-reopen{display:none;position:fixed;left:1rem;bottom:1rem;z-index:2147483646;padding:.5rem 1rem;border:1px solid var(--jini-border,#0002);border-radius:999px;background:var(--jini-surface,Canvas);color:var(--jini-text,CanvasText);font-size:12.5px;box-shadow:0 1px 2px #0000000f,0 8px 20px #0000001f}
|
|
25
|
+
html[data-consent="set"]:not([data-consent-open]) .jini-consent-reopen{display:inline-flex}
|
|
26
|
+
@media(max-width:640px){.jini-consent{inset:auto 0 0;padding:12px 16px calc(12px + env(safe-area-inset-bottom,0px));border-radius:var(--consent-radius) var(--consent-radius) 0 0}}
|
|
27
|
+
@media(prefers-reduced-motion:reduce){.jini-consent,.jini-consent *{transition:none!important;animation:none!important}}
|
|
28
|
+
|
|
29
|
+
/* ENGINE PARITY BLOCK */
|
|
30
|
+
#jini-consent{position:fixed!important;z-index:2147483647!important;visibility:visible!important;opacity:1!important;transform:none!important;clip:auto!important;clip-path:none!important;filter:none!important;pointer-events:auto!important;isolation:isolate!important}
|
|
31
|
+
#jini-consent:not([hidden]){display:block!important;background-image:none!important;min-width:0!important;max-height:85dvh!important;overflow:auto!important;box-sizing:border-box!important}
|
|
32
|
+
#jini-consent[hidden]{display:none!important}
|
|
33
|
+
#jini-consent :is(h2,p,label,legend,fieldset,details,.jini-consent-actions){background:transparent!important}
|
|
34
|
+
#jini-consent :is(h2,p,label,legend,details,.jini-consent-actions){color:inherit!important}
|
|
35
|
+
#jini-consent .jini-consent-actions{display:grid!important}
|
|
36
|
+
#jini-consent :is(button,a,summary){visibility:visible!important;opacity:1!important;transform:none!important;clip-path:none!important;filter:none!important;pointer-events:auto!important;color:inherit!important}
|
|
37
|
+
#jini-consent :is(a,summary){background:transparent!important;border:0!important}
|
|
38
|
+
#jini-consent .jini-consent-actions button{background:var(--consent-button-bg)!important;border:1px solid var(--consent-button-border)!important}
|
|
39
|
+
#jini-consent .jini-consent-actions button:hover{background:var(--consent-button-hover-bg)!important}
|
|
40
|
+
#jini-consent .jini-consent-link{background:transparent!important;border:0!important}
|
|
41
|
+
#jini-consent button{display:inline-flex!important;align-items:center!important;justify-content:center!important;min-width:0!important;max-width:100%!important;white-space:normal!important;overflow-wrap:anywhere!important}
|
|
42
|
+
#jini-consent a{display:inline!important;text-decoration:underline!important}
|
|
43
|
+
#jini-consent :focus-visible{outline:3px solid currentColor!important;outline-offset:2px!important}
|
|
44
|
+
html[data-consent-region="opt-out"] #jini-consent [data-consent-only="opt-in"],html:not([data-consent-region="opt-out"]) #jini-consent [data-consent-only="opt-out"],html:not([data-consent-gpc]) #jini-consent [data-consent-gpc]{display:none!important}
|
|
45
|
+
@media(max-width:640px){#jini-consent{inset:auto 0 0!important;width:100%!important;max-width:100%!important;margin:0!important}}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @file DOM helpers for the browser client: cookies, storage purge, inert tags and the Jini banner binding.
|
|
2
|
+
* The Jini banner is a client of the public API, exactly like an owner's own ("My own") banner. */
|
|
3
|
+
import { type Choices, type ConsentState, type JiniConsentApi, type Optional, type StoragePrefixes } from '../contract.js';
|
|
4
|
+
/** @complexity O(cookie header). Malformed escapes read as "no value", never throw. */
|
|
5
|
+
export declare function readCookie(doc: Document, name: string): string | null;
|
|
6
|
+
export declare function writeCookie(doc: Document, { name, value, maxAgeS }: {
|
|
7
|
+
name: string;
|
|
8
|
+
value: string;
|
|
9
|
+
maxAgeS: number;
|
|
10
|
+
}, { domain }?: {
|
|
11
|
+
domain?: string | undefined;
|
|
12
|
+
}): void;
|
|
13
|
+
/** Expire prefixed cookies and local-storage keys; storage access can throw in sandboxes. @complexity O(cookies + keys). */
|
|
14
|
+
export declare function purge(doc: Document, storage?: StoragePrefixes): void;
|
|
15
|
+
/** Allowed inert tags become live, in authored order (async=false). Unknown labels stay inert.
|
|
16
|
+
* @complexity O(inert tags). */
|
|
17
|
+
export declare function activateInert(doc: Document, { allowed, ran }: {
|
|
18
|
+
allowed: Choices;
|
|
19
|
+
ran: Set<Optional>;
|
|
20
|
+
}): void;
|
|
21
|
+
/** Footer links and the reopen button work for every banner mode, including "My own". */
|
|
22
|
+
export declare function installOpeners({ api, doc }: {
|
|
23
|
+
api: JiniConsentApi;
|
|
24
|
+
doc: Document;
|
|
25
|
+
}): void;
|
|
26
|
+
/** A durable grant that is still waiting for its receipt keeps the banner open with its alert. */
|
|
27
|
+
export declare const waiting: (s: ConsentState) => boolean;
|
|
28
|
+
/** Wire #jini-consent (renderBanner's markup) to the public API. @complexity O(1) per click. */
|
|
29
|
+
export declare function bindBanner({ api, doc }: {
|
|
30
|
+
api: JiniConsentApi;
|
|
31
|
+
doc: Document;
|
|
32
|
+
}): void;
|
|
33
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/** @file DOM helpers for the browser client: cookies, storage purge, inert tags and the Jini banner binding.
|
|
2
|
+
* The Jini banner is a client of the public API, exactly like an owner's own ("My own") banner. */
|
|
3
|
+
import { OPEN_EVENT, OPTIONAL } from '../contract.js';
|
|
4
|
+
const INERT = 'script[type="text/plain"][data-consent-category],iframe[data-consent-category][data-src]';
|
|
5
|
+
const SKIP = new Set(['type', 'data-src', 'data-type', 'data-consent-category']);
|
|
6
|
+
// Not <html>: the client sets html[data-consent-open] while the banner shows, and every click's closest() would hit it.
|
|
7
|
+
const OPENERS = ':not(html)[data-consent-open],a[href="#privacy-choices"]';
|
|
8
|
+
/** @complexity O(cookie header). Malformed escapes read as "no value", never throw. */
|
|
9
|
+
export function readCookie(doc, name) {
|
|
10
|
+
const part = doc.cookie.split(/;\s*/).find(p => p.startsWith(name + '='));
|
|
11
|
+
try {
|
|
12
|
+
return part ? decodeURIComponent(part.slice(name.length + 1)) : null;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function writeCookie(doc, { name, value, maxAgeS }, { domain } = {}) {
|
|
19
|
+
const secure = doc.defaultView?.location.protocol === 'https:' ? '; Secure' : '';
|
|
20
|
+
doc.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${Math.floor(maxAgeS)}; SameSite=Lax${secure}${domain ? `; Domain=${domain}` : ''}`;
|
|
21
|
+
}
|
|
22
|
+
/** Vendors set cookies on the registrable domain, so expire on the host and each parent domain. */
|
|
23
|
+
function expireEverywhere(doc, name) {
|
|
24
|
+
const parts = (doc.defaultView?.location.hostname ?? '').split('.');
|
|
25
|
+
doc.cookie = `${name}=; Path=/; Max-Age=0`;
|
|
26
|
+
for (let i = 0; i < parts.length - 1; i++)
|
|
27
|
+
doc.cookie = `${name}=; Path=/; Max-Age=0; Domain=.${parts.slice(i).join('.')}`;
|
|
28
|
+
}
|
|
29
|
+
/** Expire prefixed cookies and local-storage keys; storage access can throw in sandboxes. @complexity O(cookies + keys). */
|
|
30
|
+
export function purge(doc, storage) {
|
|
31
|
+
if (!storage)
|
|
32
|
+
return;
|
|
33
|
+
for (const part of doc.cookie.split(/;\s*/)) {
|
|
34
|
+
const name = part.split('=')[0];
|
|
35
|
+
if (storage.cookies?.some(p => name.startsWith(p)))
|
|
36
|
+
expireEverywhere(doc, name);
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const local = doc.defaultView.localStorage;
|
|
40
|
+
for (const key of Object.keys(local))
|
|
41
|
+
if (storage.local?.some(p => key.startsWith(p)))
|
|
42
|
+
local.removeItem(key);
|
|
43
|
+
}
|
|
44
|
+
catch { /* no storage: nothing to purge */ }
|
|
45
|
+
}
|
|
46
|
+
// MOVED-FROM: @jini-ai/cms consent/html/client.ts template release (ordered, each template consumed once).
|
|
47
|
+
// TODO(P4): delete the cms runtime once the consumer inserts this client.
|
|
48
|
+
/** Allowed inert tags become live, in authored order (async=false). Unknown labels stay inert.
|
|
49
|
+
* @complexity O(inert tags). */
|
|
50
|
+
export function activateInert(doc, { allowed, ran }) {
|
|
51
|
+
doc.querySelectorAll(INERT).forEach(node => {
|
|
52
|
+
const category = node.dataset.consentCategory;
|
|
53
|
+
if (!OPTIONAL.includes(category) || !allowed[category])
|
|
54
|
+
return;
|
|
55
|
+
ran.add(category);
|
|
56
|
+
if (node.tagName === 'IFRAME') {
|
|
57
|
+
node.setAttribute('src', node.dataset.src);
|
|
58
|
+
node.removeAttribute('data-src');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
node.replaceWith(liveScript(doc, node));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function liveScript(doc, inert) {
|
|
65
|
+
const s = doc.createElement('script');
|
|
66
|
+
for (const { name, value } of Array.from(inert.attributes))
|
|
67
|
+
if (!SKIP.has(name))
|
|
68
|
+
s.setAttribute(name, value);
|
|
69
|
+
if (inert.nonce)
|
|
70
|
+
s.nonce = inert.nonce; // owner-set CSPs keep working
|
|
71
|
+
if (inert.dataset.type)
|
|
72
|
+
s.type = inert.dataset.type;
|
|
73
|
+
if (inert.dataset.src)
|
|
74
|
+
s.src = inert.dataset.src;
|
|
75
|
+
else
|
|
76
|
+
s.text = inert.text;
|
|
77
|
+
s.async = false;
|
|
78
|
+
return s;
|
|
79
|
+
}
|
|
80
|
+
/** Footer links and the reopen button work for every banner mode, including "My own". */
|
|
81
|
+
export function installOpeners({ api, doc }) {
|
|
82
|
+
doc.addEventListener('click', event => {
|
|
83
|
+
if (!event.target.closest?.(OPENERS))
|
|
84
|
+
return;
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
api.open();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function readPicked(root) {
|
|
90
|
+
const picked = {};
|
|
91
|
+
for (const c of OPTIONAL) {
|
|
92
|
+
const box = root.querySelector(`input[name="${c}"]`);
|
|
93
|
+
if (box)
|
|
94
|
+
picked[c] = box.checked;
|
|
95
|
+
}
|
|
96
|
+
return picked;
|
|
97
|
+
}
|
|
98
|
+
function syncInputs(root, s) {
|
|
99
|
+
for (const c of OPTIONAL) {
|
|
100
|
+
const box = root.querySelector(`input[name="${c}"]`);
|
|
101
|
+
if (!box)
|
|
102
|
+
continue;
|
|
103
|
+
box.checked = s.choices[c];
|
|
104
|
+
box.disabled = s.gpc && c !== 'functional'; // GPC-clamped categories cannot be ticked
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** A durable grant that is still waiting for its receipt keeps the banner open with its alert. */
|
|
108
|
+
export const waiting = (s) => OPTIONAL.some(c => s.choices[c] && !s.allowed[c]);
|
|
109
|
+
/** Wire #jini-consent (renderBanner's markup) to the public API. @complexity O(1) per click. */
|
|
110
|
+
export function bindBanner({ api, doc }) {
|
|
111
|
+
const root = doc.getElementById('jini-consent');
|
|
112
|
+
if (!root)
|
|
113
|
+
return;
|
|
114
|
+
const alert = root.querySelector('[data-consent-error]');
|
|
115
|
+
const show = (open) => { root.hidden = !open; api.setOpen({ open }); };
|
|
116
|
+
const settle = (s) => {
|
|
117
|
+
if (alert)
|
|
118
|
+
alert.hidden = !waiting(s);
|
|
119
|
+
if (!waiting(s))
|
|
120
|
+
show(false);
|
|
121
|
+
};
|
|
122
|
+
root.addEventListener('click', event => {
|
|
123
|
+
const action = event.target.closest?.('[data-consent-action]')?.getAttribute('data-consent-action');
|
|
124
|
+
if (!action)
|
|
125
|
+
return;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
void api.set({ action: action }, { choices: readPicked(root) }).then(settle);
|
|
128
|
+
});
|
|
129
|
+
root.addEventListener('keydown', event => { if (event.key === 'Escape' && api.get().status === 'set')
|
|
130
|
+
show(false); });
|
|
131
|
+
doc.addEventListener(OPEN_EVENT, () => { syncInputs(root, api.get()); show(true); root.querySelector('button')?.focus(); });
|
|
132
|
+
api.subscribe({ listener: s => { syncInputs(root, s); if (alert && !alert.hidden && !waiting(s))
|
|
133
|
+
settle(s); } });
|
|
134
|
+
syncInputs(root, api.get());
|
|
135
|
+
show(api.get().status === 'pending');
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=dom.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** @file IIFE entry for dist/client.min.js: boots from #jini-consent-config, with the Jini banner binding.
|
|
2
|
+
* (Measured: the binding adds ~0.35 KB gz, too little to justify a second file for headless pages; an ESM
|
|
3
|
+
* host that wants a headless-only build calls boot() from ./client without bindBanner.) */
|
|
4
|
+
import { bindBanner } from './dom.js';
|
|
5
|
+
import { boot } from './index.js';
|
|
6
|
+
boot(window, { bindBanner });
|
|
7
|
+
//# sourceMappingURL=entry.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** @file Browser runtime (dist/client.min.js). It owns the cookie, the adapter lifecycle, inert tags and
|
|
2
|
+
* receipts. Denial is applied before any network; a durable grant runs only once its receipt exists; a
|
|
3
|
+
* response never sets a cookie, so a slow Accept can't overwrite a newer Reject. No polling, and no reload
|
|
4
|
+
* unless something already ran that cannot be stopped (a raw inert script, or an adapter that can't revoke). */
|
|
5
|
+
import { type ClientConfig, type ConsentAdapter, type Evidence, type JiniConsentApi, type PluginRegistry, type StoragePrefixes } from '../contract.js';
|
|
6
|
+
export interface ClientPorts {
|
|
7
|
+
doc: Document;
|
|
8
|
+
fetch: typeof fetch;
|
|
9
|
+
now: () => number;
|
|
10
|
+
gpc: () => boolean;
|
|
11
|
+
reload: () => void;
|
|
12
|
+
importModule: (src: string) => Promise<{
|
|
13
|
+
default: ConsentAdapter;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export interface ClientOptions {
|
|
17
|
+
plugins?: PluginRegistry;
|
|
18
|
+
evidence?: Evidence | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** @example createCookieConsent({ config, ports: browserPorts(window) }, { evidence: { mode: 'local' } }) */
|
|
21
|
+
export declare function createCookieConsent({ config, ports }: {
|
|
22
|
+
config: ClientConfig;
|
|
23
|
+
ports: ClientPorts;
|
|
24
|
+
}, options?: ClientOptions): JiniConsentApi;
|
|
25
|
+
export declare function browserPorts(win: Window & typeof globalThis): ClientPorts;
|
|
26
|
+
export interface BootOptions {
|
|
27
|
+
ports?: ClientPorts;
|
|
28
|
+
/** The Jini banner binding; only the client-jini.min.js build passes it, so headless pages never download it. */
|
|
29
|
+
bindBanner?: (required: {
|
|
30
|
+
api: JiniConsentApi;
|
|
31
|
+
doc: Document;
|
|
32
|
+
}) => void;
|
|
33
|
+
}
|
|
34
|
+
/** Reads #jini-consent-config, installs window.jiniConsent, drains and replaces the pre-boot queue.
|
|
35
|
+
* A missing or broken config installs nothing, so nothing optional can run (fail closed). */
|
|
36
|
+
export declare function boot(win?: Window & typeof globalThis, { ports, bindBanner }?: BootOptions): JiniConsentApi | undefined;
|
|
37
|
+
/** Delete only the caller's storage prefixes; blocked localStorage is tolerated.
|
|
38
|
+
* @example purgeStorage({ doc: document, storage: { cookies: ['vendor_'], local: ['vendor_'] } })
|
|
39
|
+
* @complexity O(cookies + local keys), O(keys) temporary space; no new identity or network. */
|
|
40
|
+
export declare function purgeStorage({ doc, storage }: {
|
|
41
|
+
doc: Document;
|
|
42
|
+
storage: StoragePrefixes;
|
|
43
|
+
}, _optional?: {}): void;
|
|
44
|
+
export { bindBanner, installOpeners } from './dom.js';
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|