@justai/core 0.2.1 → 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 +1 -1
- package/src/index.d.ts +9 -0
- package/src/index.js +171 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "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
|
@@ -15,3 +15,12 @@ export declare function measurementIdFor(host: string | null | undefined): strin
|
|
|
15
15
|
|
|
16
16
|
/** The whole analytics head block for a measurement id — non-production guard, consent defaults, config, deferred loader. */
|
|
17
17
|
export declare function analyticsJs(gaId: string): string;
|
|
18
|
+
|
|
19
|
+
/** The consent question in thirteen languages — the ecosystem's promise, said once. */
|
|
20
|
+
export declare const CONSENT_COPY: Record<string, { consentText: string; consentAllow: string; consentDecline: string; consentChoice: string }>;
|
|
21
|
+
|
|
22
|
+
/** The consent copy for a language, falling back to English. */
|
|
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
|
@@ -135,3 +135,174 @@ gtag("config",__g,{cookie_expires:60*60*24*60,page_title:document.title,allow_go
|
|
|
135
135
|
addEventListener("load",function(){(window.requestIdleCallback||function(f){setTimeout(f,1200)})(function(){var s=document.createElement("script");s.async=true;s.src="https://www.googletagmanager.com/gtag/js?id="+__g;document.head.appendChild(s)})});
|
|
136
136
|
}})();`;
|
|
137
137
|
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* queries: where does the consent dialog text live · change the consent wording · consentText ·
|
|
142
|
+
* consentAllow consentDecline consentChoice · why is the consent copy not in the persona ·
|
|
143
|
+
* feed cannot show the consent sheet · translate the consent question
|
|
144
|
+
*
|
|
145
|
+
* THE CONSENT COPY — the ecosystem's question to a visitor, in thirteen languages, said once.
|
|
146
|
+
*
|
|
147
|
+
* It used to live in every persona's own dictionary: thirteen languages across thirteen repos, and
|
|
148
|
+
* measured before this moved, all 52 strings were byte-identical in all of them. That is the tell.
|
|
149
|
+
* A persona's dictionary holds what makes it that persona; this is the ECOSYSTEM speaking, and the
|
|
150
|
+
* same sentence copied into a hundred and sixty-nine files is not localisation, it is a maintenance
|
|
151
|
+
* bill. Changing one word meant thirteen pull requests, and getting twelve of them right meant a
|
|
152
|
+
* visitor somewhere read an older promise than the one we thought we were making.
|
|
153
|
+
*
|
|
154
|
+
* It is legally load-bearing text. There is exactly one place it may be edited, and this is it.
|
|
155
|
+
*
|
|
156
|
+
* WHY HERE rather than in @justai/cuts: `feed` renders on every persona's host and depends on core,
|
|
157
|
+
* not on cuts. Putting the copy where only the Astro shell could reach it is what kept feed from
|
|
158
|
+
* asking the question at all. Content, like behaviour, belongs at the layer every face can reach.
|
|
159
|
+
*
|
|
160
|
+
* A locale with no entry falls back to English rather than rendering an empty sheet — a missing
|
|
161
|
+
* translation must never become a dialog with no question in it.
|
|
162
|
+
*/
|
|
163
|
+
export const CONSENT_COPY = {
|
|
164
|
+
"ar": {
|
|
165
|
+
"consentText": "أودّ أن أعرف أن أحدهم مرّ من هنا — بشكل مجهول، ولا أعرف من هو أبدًا. هل لي أن أحسب زيارتك؟",
|
|
166
|
+
"consentAllow": "احسبني ❤️",
|
|
167
|
+
"consentDecline": "أبقِني خفيًّا",
|
|
168
|
+
"consentChoice": "خيار الخصوصية"
|
|
169
|
+
},
|
|
170
|
+
"de": {
|
|
171
|
+
"consentText": "Ich wüsste gern, dass jemand da war — anonym, nie wer. Darf ich deinen Besuch zählen?",
|
|
172
|
+
"consentAllow": "Zähl mich mit ❤️",
|
|
173
|
+
"consentDecline": "Unsichtbar bleiben",
|
|
174
|
+
"consentChoice": "Privatsphäre-Wahl"
|
|
175
|
+
},
|
|
176
|
+
"en": {
|
|
177
|
+
"consentText": "I'd love to know someone was here — anonymously, never who. May I count your visit?",
|
|
178
|
+
"consentAllow": "Count me in ❤️",
|
|
179
|
+
"consentDecline": "Stay invisible",
|
|
180
|
+
"consentChoice": "privacy choice"
|
|
181
|
+
},
|
|
182
|
+
"es": {
|
|
183
|
+
"consentText": "Me encantaría saber que alguien pasó por aquí — de forma anónima, nunca quién. ¿Puedo contar tu visita?",
|
|
184
|
+
"consentAllow": "Cuenta conmigo ❤️",
|
|
185
|
+
"consentDecline": "Seguir invisible",
|
|
186
|
+
"consentChoice": "elección de privacidad"
|
|
187
|
+
},
|
|
188
|
+
"fr": {
|
|
189
|
+
"consentText": "J'aimerais savoir que quelqu'un est passé — anonymement, jamais qui. Puis-je compter ta visite ?",
|
|
190
|
+
"consentAllow": "Compte ma visite ❤️",
|
|
191
|
+
"consentDecline": "Rester invisible",
|
|
192
|
+
"consentChoice": "choix de confidentialité"
|
|
193
|
+
},
|
|
194
|
+
"hi": {
|
|
195
|
+
"consentText": "मुझे बस यह जानना अच्छा लगेगा कि कोई आया था — गुमनाम रूप से, कभी नहीं कि कौन। क्या मैं आपकी विज़िट गिन सकता हूँ?",
|
|
196
|
+
"consentAllow": "मुझे गिनो ❤️",
|
|
197
|
+
"consentDecline": "अदृश्य रहूँ",
|
|
198
|
+
"consentChoice": "गोपनीयता विकल्प"
|
|
199
|
+
},
|
|
200
|
+
"it": {
|
|
201
|
+
"consentText": "Mi piacerebbe sapere che qualcuno è passato — in modo anonimo, mai chi. Posso contare la tua visita?",
|
|
202
|
+
"consentAllow": "Contami ❤️",
|
|
203
|
+
"consentDecline": "Resta invisibile",
|
|
204
|
+
"consentChoice": "scelta privacy"
|
|
205
|
+
},
|
|
206
|
+
"ja": {
|
|
207
|
+
"consentText": "誰かが来てくれたことだけ知りたいのです — 匿名で、誰かは決して分かりません。訪問を数えてもいいですか?",
|
|
208
|
+
"consentAllow": "数えていいよ ❤️",
|
|
209
|
+
"consentDecline": "見えないままで",
|
|
210
|
+
"consentChoice": "プライバシー設定"
|
|
211
|
+
},
|
|
212
|
+
"nl": {
|
|
213
|
+
"consentText": "Ik zou graag weten dat er iemand langskwam — anoniem, nooit wie. Mag ik je bezoek meetellen?",
|
|
214
|
+
"consentAllow": "Tel me mee ❤️",
|
|
215
|
+
"consentDecline": "Onzichtbaar blijven",
|
|
216
|
+
"consentChoice": "privacykeuze"
|
|
217
|
+
},
|
|
218
|
+
"pt": {
|
|
219
|
+
"consentText": "Adoraria saber que alguém passou por aqui — anonimamente, nunca quem. Posso contar a tua visita?",
|
|
220
|
+
"consentAllow": "Conta comigo ❤️",
|
|
221
|
+
"consentDecline": "Ficar invisível",
|
|
222
|
+
"consentChoice": "escolha de privacidade"
|
|
223
|
+
},
|
|
224
|
+
"ru": {
|
|
225
|
+
"consentText": "Мне бы хотелось знать, что кто-то заходил — анонимно, и никогда кто именно. Можно посчитать твой визит?",
|
|
226
|
+
"consentAllow": "Посчитай меня ❤️",
|
|
227
|
+
"consentDecline": "Остаться невидимым",
|
|
228
|
+
"consentChoice": "выбор приватности"
|
|
229
|
+
},
|
|
230
|
+
"tr": {
|
|
231
|
+
"consentText": "Birinin uğradığını bilmek isterim — anonim olarak, asla kim olduğunu değil. Ziyaretini sayabilir miyim?",
|
|
232
|
+
"consentAllow": "Beni say ❤️",
|
|
233
|
+
"consentDecline": "Görünmez kalayım",
|
|
234
|
+
"consentChoice": "gizlilik tercihi"
|
|
235
|
+
},
|
|
236
|
+
"zh": {
|
|
237
|
+
"consentText": "我只想知道有人来过 — 完全匿名,永远不知道是谁。可以把你的访问算上吗?",
|
|
238
|
+
"consentAllow": "算上我 ❤️",
|
|
239
|
+
"consentDecline": "保持隐身",
|
|
240
|
+
"consentChoice": "隐私选择"
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/** The consent copy for a language, falling back to English. Never returns undefined. */
|
|
245
|
+
export function consentCopy(lang) {
|
|
246
|
+
return CONSENT_COPY[String(lang || "en").toLowerCase()] || CONSENT_COPY.en;
|
|
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(_){}})();`;
|