@justai/core 0.3.0 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The framework-free heart of the persona shell — 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": {
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,64 @@ 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
+ export const CONSENT_JS = `(function(){try{
282
+ var h=location.hostname;
283
+ if(h==="localhost"||h==="127.0.0.1"||h==="::1"||h==="[::1]"||h.indexOf("dev-")===0)return;
284
+ var el=document.getElementById("consent");if(!el||!el.showModal)return;
285
+ var open=function(){if(!el.open){el.returnValue="";el.showModal()}};
286
+ el.addEventListener("close",function(){
287
+ var rv=el.returnValue;
288
+ var v=rv==="confirm"?"granted":rv==="denied"?"denied":null;
289
+ if(v){gtag("consent","update",{analytics_storage:v});try{localStorage.setItem("consent",v)}catch(_){}}
290
+ else{try{sessionStorage.setItem("consent-later","1")}catch(_){}}
291
+ });
292
+ var doors=document.querySelectorAll("[data-consent-open]");
293
+ for(var i=0;i<doors.length;i++){var a=doors[i];
294
+ if(!a.textContent)a.textContent=el.getAttribute("data-choice-label")||"privacy choice";
295
+ a.hidden=false;var w=a.closest("[data-consent-door]");if(w)w.hidden=false;
296
+ a.addEventListener("click",function(ev){ev.preventDefault();open()})}
297
+ if(localStorage.getItem("consent"))return;
298
+ try{if(sessionStorage.getItem("consent-later"))return}catch(_){}
299
+ var tz=Intl.DateTimeFormat().resolvedOptions().timeZone||"";
300
+ var asked=tz.indexOf("Europe/")===0||[
301
+ "Asia/Nicosia","Asia/Famagusta",
302
+ "Atlantic/Canary","Atlantic/Azores","Atlantic/Madeira","Atlantic/Reykjavik",
303
+ "Arctic/Longyearbyen",
304
+ "America/Guadeloupe","America/Martinique","America/Cayenne",
305
+ "Indian/Reunion","Indian/Mayotte"].indexOf(tz)>=0;
306
+ if(!asked)return;
307
+ setTimeout(open,700);
308
+ }catch(_){}})();`;