@justai/core 0.3.0 → 0.4.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/package.json +2 -2
- package/src/index.d.ts +3 -0
- package/src/index.js +66 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The framework-free heart of the persona shell
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "The framework-free heart of the persona shell \u2014 the load-bearing behaviour (auth capture, reveal, ready) as plain strings, so Astro and Next inject the SAME logic instead of each re-writing it.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
package/src/index.d.ts
CHANGED
|
@@ -21,3 +21,6 @@ export declare const CONSENT_COPY: Record<string, { consentText: string; consent
|
|
|
21
21
|
|
|
22
22
|
/** The consent copy for a language, falling back to English. */
|
|
23
23
|
export declare function consentCopy(lang: string): { consentText: string; consentAllow: string; consentDecline: string; consentChoice: string };
|
|
24
|
+
|
|
25
|
+
/** The consent dialog's behaviour — origin-scoped, asked once, with the universal change-your-mind door. */
|
|
26
|
+
export declare const CONSENT_JS: string;
|
package/src/index.js
CHANGED
|
@@ -245,3 +245,69 @@ export const CONSENT_COPY = {
|
|
|
245
245
|
export function consentCopy(lang) {
|
|
246
246
|
return CONSENT_COPY[String(lang || "en").toLowerCase()] || CONSENT_COPY.en;
|
|
247
247
|
}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* queries: consent dialog script · why does the sheet not appear on some pages · consent is asked
|
|
252
|
+
* per domain not per page · getElementById kernel · the sheet never opened on feed ·
|
|
253
|
+
* only a choice may be remembered · the change-your-mind door · consent timezone list
|
|
254
|
+
*
|
|
255
|
+
* The consent dialog's behaviour — one copy, for every surface on a persona's origin.
|
|
256
|
+
*
|
|
257
|
+
* CONSENT IS SCOPED TO THE ORIGIN, NOT TO A PAGE. Whichever page a visitor enters by, if this origin
|
|
258
|
+
* has never asked, it asks — once. That is what a consent flow IS, and it is worth stating because
|
|
259
|
+
* ours was accidentally page-scoped for three weeks: the script used to bail on
|
|
260
|
+
* `!document.getElementById("kernel")`, a DOM sniff added to avoid asking on a 404. Feed pages have
|
|
261
|
+
* no kernel either, so on every /feed/* page in the fleet the question was never asked — silently,
|
|
262
|
+
* with nothing to notice it. A trust decision must never be inferred from an unrelated layout
|
|
263
|
+
* detail; the check is gone, and any page that renders the sheet may ask.
|
|
264
|
+
*
|
|
265
|
+
* ONLY A CHOICE MAY BE REMEMBERED AS A CHOICE. "confirm" is the heart, "denied" is a chosen
|
|
266
|
+
* "Stay invisible". Anything else — Escape, a tap on the backdrop — is not an answer: nothing is
|
|
267
|
+
* stored, the regional default stands, and the ask returns next visit. The session flag only keeps
|
|
268
|
+
* THIS visit quiet, so one slip-away buys one visit of peace rather than an answer nobody gave.
|
|
269
|
+
*
|
|
270
|
+
* THE DOOR IS UNIVERSAL. The footer's hidden `[data-consent-open]` anchor is labelled, revealed and
|
|
271
|
+
* wired here for EVERY visitor in EVERY region — a non-EEA visitor gets a real opt-out they were
|
|
272
|
+
* never offered, and anyone can reverse either answer. Only the AUTO-ask has narrow gates.
|
|
273
|
+
*
|
|
274
|
+
* THE TIMEZONE LIST IS A PROXY for "consent is legally asked here", never the thing itself, and it is
|
|
275
|
+
* the sibling of the region array in {@link analyticsJs}. `Europe/` carries almost all of the EEA but
|
|
276
|
+
* not all of it: twelve zones sit on other continents. Change one list and you must change the other,
|
|
277
|
+
* or a visitor is denied by region while never being offered the dialog.
|
|
278
|
+
*
|
|
279
|
+
* `returnValue` survives a close, so it is reset before every open or a stale answer replays.
|
|
280
|
+
*
|
|
281
|
+
* FOCUS IS GIVEN AT OPEN, not by an autofocus attribute. Chrome refuses to process `autofocus` in
|
|
282
|
+
* any document whose URL carries a fragment and warns on every load — /me#profile met it first. So
|
|
283
|
+
* the sheet ships no attribute, and the opener places focus by the genre's law: the ask genre puts
|
|
284
|
+
* it on the invitation (here), the destructive genre on the cancel (that consumer's own open).
|
|
285
|
+
*/
|
|
286
|
+
export const CONSENT_JS = `(function(){try{
|
|
287
|
+
var h=location.hostname;
|
|
288
|
+
if(h==="localhost"||h==="127.0.0.1"||h==="::1"||h==="[::1]"||h.indexOf("dev-")===0)return;
|
|
289
|
+
var el=document.getElementById("consent");if(!el||!el.showModal)return;
|
|
290
|
+
var open=function(){if(!el.open){el.returnValue="";el.showModal();var p=el.querySelector(".preferred");if(p)p.focus()}};
|
|
291
|
+
el.addEventListener("close",function(){
|
|
292
|
+
var rv=el.returnValue;
|
|
293
|
+
var v=rv==="confirm"?"granted":rv==="denied"?"denied":null;
|
|
294
|
+
if(v){gtag("consent","update",{analytics_storage:v});try{localStorage.setItem("consent",v)}catch(_){}}
|
|
295
|
+
else{try{sessionStorage.setItem("consent-later","1")}catch(_){}}
|
|
296
|
+
});
|
|
297
|
+
var doors=document.querySelectorAll("[data-consent-open]");
|
|
298
|
+
for(var i=0;i<doors.length;i++){var a=doors[i];
|
|
299
|
+
if(!a.textContent)a.textContent=el.getAttribute("data-choice-label")||"privacy choice";
|
|
300
|
+
a.hidden=false;var w=a.closest("[data-consent-door]");if(w)w.hidden=false;
|
|
301
|
+
a.addEventListener("click",function(ev){ev.preventDefault();open()})}
|
|
302
|
+
if(localStorage.getItem("consent"))return;
|
|
303
|
+
try{if(sessionStorage.getItem("consent-later"))return}catch(_){}
|
|
304
|
+
var tz=Intl.DateTimeFormat().resolvedOptions().timeZone||"";
|
|
305
|
+
var asked=tz.indexOf("Europe/")===0||[
|
|
306
|
+
"Asia/Nicosia","Asia/Famagusta",
|
|
307
|
+
"Atlantic/Canary","Atlantic/Azores","Atlantic/Madeira","Atlantic/Reykjavik",
|
|
308
|
+
"Arctic/Longyearbyen",
|
|
309
|
+
"America/Guadeloupe","America/Martinique","America/Cayenne",
|
|
310
|
+
"Indian/Reunion","Indian/Mayotte"].indexOf(tz)>=0;
|
|
311
|
+
if(!asked)return;
|
|
312
|
+
setTimeout(open,700);
|
|
313
|
+
}catch(_){}})();`;
|