@littlefriend/feedback 0.1.0 → 0.1.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/dist/index.js +26 -8
- package/dist/lf-feedback.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -28,6 +28,11 @@ var LIMITS = {
|
|
|
28
28
|
var RETENTION_DAYS = {
|
|
29
29
|
events: { min: 1, max: 365, default: 7 },
|
|
30
30
|
aggregates: { min: 30, max: 395, default: 395 },
|
|
31
|
+
/**
|
|
32
|
+
* Server log lines, a separate add-on with its own store. The default, null, keeps them for
|
|
33
|
+
* good: past LOG_LIMITS.hotDays they move to the archive and stay searchable.
|
|
34
|
+
*/
|
|
35
|
+
logs: { min: 1, max: 3650, default: null },
|
|
31
36
|
feedback: { min: 1, max: 365, default: 90 }
|
|
32
37
|
};
|
|
33
38
|
var SESSION_ID_RE = /^[A-Za-z0-9_-]{16,32}$/;
|
|
@@ -43,11 +48,11 @@ var TOKENISH_RE = /^(?=.*\d)(?=.*[a-zA-Z])[A-Za-z0-9_-]{20,}$/;
|
|
|
43
48
|
var DOTTED_TOKEN_RE = /^(?:eyJ[A-Za-z0-9_-]{4,}(?:\.[A-Za-z0-9_-]*){1,4}|(?=.*\d)(?=.*[A-Z])[A-Za-z0-9_-]{16,}(?:\.[A-Za-z0-9_-]{16,}){2})$/;
|
|
44
49
|
var ROUTE_PARAM_RE = /^:[a-z_][a-z0-9_]{0,31}$/;
|
|
45
50
|
var CONTROL_RE = /[\u0000-\u001f\u007f]/g;
|
|
46
|
-
var
|
|
51
|
+
var SURROGATE_RE = /[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
|
|
47
52
|
var MAX_RAW_PATH = 2048;
|
|
48
53
|
var PII_SCAN_LIMIT = 2048;
|
|
49
54
|
function cleanText(value) {
|
|
50
|
-
return value.replace(CONTROL_RE, "").replace(
|
|
55
|
+
return value.replace(CONTROL_RE, "").replace(SURROGATE_RE, (m) => m.length === 2 ? m : "");
|
|
51
56
|
}
|
|
52
57
|
function looksLikePII(input) {
|
|
53
58
|
const value = input.length > PII_SCAN_LIMIT ? input.slice(0, PII_SCAN_LIMIT) : input;
|
|
@@ -55,13 +60,27 @@ function looksLikePII(input) {
|
|
|
55
60
|
return true;
|
|
56
61
|
if ((HEXISH_RE.test(value) || UUID_RE.test(value)) && HEX_LETTER_RE.test(value))
|
|
57
62
|
return false;
|
|
58
|
-
return LONG_DIGITS_RE.test(value);
|
|
63
|
+
return LONG_DIGITS_RE.test(value) || announcesCredential(value);
|
|
59
64
|
}
|
|
60
|
-
var
|
|
61
|
-
|
|
65
|
+
var CREDENTIAL_RES = [
|
|
66
|
+
// Slack: xoxb-, xoxp-, xoxa-, xoxe-, xoxr-, xoxs- and a digit.
|
|
67
|
+
/(?:^|[^A-Za-z0-9])xox[abeprs]-\d/,
|
|
68
|
+
// GitHub tokens: ghp_, gho_, ghu_, ghs_, ghr_ and 36 letters and digits; fine-grained ones.
|
|
69
|
+
/(?:^|[^A-Za-z0-9])gh[pousr]_[A-Za-z0-9]{36}/,
|
|
70
|
+
/(?:^|[^A-Za-z0-9])github_pat_[A-Za-z0-9_]{22,}/,
|
|
71
|
+
// AWS access key ids: AKIA or ASIA and 16 capitals and digits.
|
|
72
|
+
/(?:^|[^A-Za-z0-9])(?:AKIA|ASIA)[A-Z0-9]{16}(?![A-Za-z0-9])/,
|
|
73
|
+
// Stripe secret and restricted keys.
|
|
74
|
+
/(?:^|[^A-Za-z0-9])[sr]k_(?:live|test)_[A-Za-z0-9]{16,}/,
|
|
75
|
+
// A JWT, or its header on its own: `{"alg"` always encodes to `eyJ`.
|
|
76
|
+
/(?:^|[^A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{16,}/
|
|
77
|
+
];
|
|
78
|
+
var announcesCredential = (value) => CREDENTIAL_RES.some((re) => re.test(value));
|
|
62
79
|
function sanitizeRoute(input) {
|
|
63
80
|
return cleanPath(input, false);
|
|
64
81
|
}
|
|
82
|
+
var ASSET_HASH_RE = /(^|[^a-z\d])(?=\d*[a-f])[\da-f]{8,64}(?![a-z\d])/gi;
|
|
83
|
+
var ASSET_RE = /\.(?:[cm]?js|css)$/;
|
|
65
84
|
var PARAM_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
66
85
|
var isParamValue = (body) => NUMERIC_RE.test(body) || UUID_RE.test(body) || HEXISH_RE.test(body) || DOTTED_TOKEN_RE.test(body);
|
|
67
86
|
function cleanPath(input, strictParams, keep) {
|
|
@@ -101,7 +120,7 @@ function cleanPath(input, strictParams, keep) {
|
|
|
101
120
|
const body = seg.startsWith(":") ? seg.slice(1) : seg;
|
|
102
121
|
if (NUMERIC_RE.test(body) || UUID_RE.test(body) || HEXISH_RE.test(body) || TOKENISH_RE.test(body) || DOTTED_TOKEN_RE.test(body))
|
|
103
122
|
return ":id";
|
|
104
|
-
if (looksLikePII(body))
|
|
123
|
+
if (looksLikePII(strictParams && ASSET_RE.test(body) ? body.replace(ASSET_HASH_RE, "$1_") : body))
|
|
105
124
|
return ":redacted";
|
|
106
125
|
return seg;
|
|
107
126
|
});
|
|
@@ -171,7 +190,6 @@ var FEEDBACK_LIMITS = {
|
|
|
171
190
|
webhookConcurrency: 4
|
|
172
191
|
};
|
|
173
192
|
var DEFAULT_FEEDBACK_LABEL = "Feedback";
|
|
174
|
-
var CARD_CANDIDATE_RE = new RegExp("(?<![\\d-])\\d(?:[ -]?\\d){12,18}(?![\\d])", "g");
|
|
175
193
|
function feedbackConsentLine(input) {
|
|
176
194
|
const what = input.visit ? "Your note, this page's address, the time, your device type and a link to this visit" : "Your note, this page's address, the time and your device type";
|
|
177
195
|
const site = input.site.replace(/^www\./, "") || "this site";
|
|
@@ -225,7 +243,7 @@ function routeOf(loc, templates) {
|
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
// src/version.ts
|
|
228
|
-
var VERSION = "0.1.
|
|
246
|
+
var VERSION = "0.1.2";
|
|
229
247
|
|
|
230
248
|
// src/styles.ts
|
|
231
249
|
var CSS = `:host{all:initial}
|
package/dist/lf-feedback.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e=/^[A-Za-z0-9_-]{16,32}$/,t=new RegExp("[^\\s@/]{1,64}@[^\\s@/]{1,253}\\.\\p{L}{2,24}","iu"),n=/\d[\d\s().-]{7,}\d/,r=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,a=/^[0-9a-f]{16,}$/i,i=/[a-f]/i,o=/^\d+$/,l=/^(?=.*\d)(?=.*[a-zA-Z])[A-Za-z0-9_-]{20,}$/,d=/^(?:eyJ[A-Za-z0-9_-]{4,}(?:\.[A-Za-z0-9_-]*){1,4}|(?=.*\d)(?=.*[A-Z])[A-Za-z0-9_-]{16,}(?:\.[A-Za-z0-9_-]{16,}){2})$/,s=/^:[a-z_][a-z0-9_]{0,31}$/,c=/[\u0000-\u001f\u007f]/g,p=new RegExp("[\\ud800-\\udbff](?![\\udc00-\\udfff])|(?<![\\ud800-\\udbff])[\\udc00-\\udfff]","g");function u(e){let o=e.length>2048?e.slice(0,2048):e;return!(!o.includes("@")||!t.test(o))||(!a.test(o)&&!r.test(o)||!i.test(o))&&n.test(o)}function f(e){return(e=>{if("string"!=typeof e||e.length>2048)return null;let t=e,n=t.search(/[?#]/);n>=0&&(t=t.slice(0,n)),t.startsWith("/")||(t=`/${t}`);let i=t;try{i=decodeURIComponent(t)}catch{}i=(e=>e.replace(c,"").replace(p,""))(i);let f=i.search(/[?#]/);f>=0&&(i=i.slice(0,f));let m=i.split("/").map(e=>{if(e.includes("="))return":redacted";if(""===e)return e;if(e.startsWith(":")){let t=e.slice(1);return g.test(t)?e:b(t)?":id":u(t)?":redacted":e}if(s.test(e))return e;let t=e.startsWith(":")?e.slice(1):e;return o.test(t)||r.test(t)||a.test(t)||l.test(t)||d.test(t)?":id":u(t)?":redacted":e}).join("/");return m.length>1&&m.endsWith("/")&&(m=m.slice(0,-1)),m.length>256?null:m})(e)}new RegExp("(?<![\\p{L}\\p{N}._%+-])[\\p{L}\\p{N}._%+-]{1,64}@(?:[\\p{L}\\p{N}](?:[\\p{L}\\p{N}-]{0,61}[\\p{L}\\p{N}])?\\.){1,8}\\p{L}{2,24}(?![\\p{L}\\p{N}_%+-]|\\.[\\p{L}\\p{N}])","gu"),new RegExp("(?<![\\w+.-])(?:\\+\\d{1,3}(?:[ .-]?\\(?\\d{1,5}\\)?){1,6}|(?:1[ .-]?)?(?:\\(\\d{3}\\)[ .-]?|\\d{3}[ .-])\\d{3}[ .-]\\d{4}|0\\d{1,4}[ -]\\d{3,4}[ -]?\\d{3,4})(?![\\d]|[.-]\\d)","g");var g=/^[A-Za-z_][A-Za-z0-9_]*$/,b=e=>o.test(e)||r.test(e)||a.test(e)||d.test(e),m=["confusing","bug","idea","other"];function h(e){return"string"==typeof e&&m.includes(e)}var y={confusing:"Confusing",bug:"Something broke",idea:"Idea",other:"Other"},x=["bottom_right","bottom_left","right_edge","manual"];function v(e){return"string"==typeof e&&x.includes(e)}var w=2e3;function k(e,t){let n=e.pathname,r="file:"===e.protocol?n.slice(n.lastIndexOf("/")):n;for(let[e,n]of t)if(n.test(r))return f(e)??"/";return f(r)??"/"}function L(e){return"empty"===e?"Write a note first.":"rate_limited"===e||"quota_exceeded"===e?"Too many notes right now. Please try again in a minute.":"network"===e?"Your note was not sent. Check your connection and try again.":"feedback_off"===e?"Feedback is turned off for this site.":"Your note was not sent. Please try again."}function $(e){let t=e;if(!0!==t?.on)return null;let n="string"==typeof t.label?t.label.trim().slice(0,24):"",r="string"==typeof t.prompt?t.prompt.trim().slice(0,140):"",a=t.days;return{v:1,on:!0,label:n||"Feedback",placement:v(t.placement)?t.placement:"bottom_right",prompt:r||null,days:"number"==typeof a&&Number.isInteger(a)&&a>=1?a:90}}new RegExp("(?<![\\d-])\\d(?:[ -]?\\d){12,18}(?![\\d])","g");var _,E=Symbol.for("littlefriend.feedback"),A=document,S=A.currentScript,z=S?.hasAttribute("data-site")?S:A.querySelector("script[data-site][data-feedback]"),C=e=>z?.getAttribute(`data-${e}`)||void 0,j=C("site");try{_=JSON.parse(C("routes")||A.querySelector("script[data-site][data-routes]")?.getAttribute("data-routes")||"[]")}catch{}j&&((t,n)=>{let r=t,a=r[E];if(a)return a;let i=function(t,n){let r,a,i=t.document,o=(n.api||"https://in.littlefriend.io").replace(/\/+$/,""),l=(e=>Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.startsWith("/")).map(e=>[e,RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/:\w+/g,"[^/]+").replace(/\*/g,".*")}/?$`)]):[])(n.routes),d=!1,s=new Promise(e=>i.prerendering?i.addEventListener("prerenderingchange",()=>e(),{once:!0}):e()).then(()=>t.fetch(`${o}/v1/f/config?k=${encodeURIComponent(n.site)}`,{credentials:"omit"})).then(e=>e.ok?e.json():null).then($,()=>null),c=()=>{let n=null,r=t.lf;if(r?.v)try{r("session",t=>{n="string"==typeof t&&e.test(t)?t:null})}catch{}return n},p=async e=>{let r=await s;if(d||!r)return{ok:!1,error:"feedback_off"};let a=e??{},i="string"==typeof a.text?a.text.trim():"";if(!i)return{ok:!1,error:"empty"};if(null!=a.category&&!h(a.category))return{ok:!1,error:"bad_category"};let p=c();return(async e=>{for(let n=0;;n++){e.s&&c()!==e.s&&(delete e.s,e.m="a");let r=JSON.stringify(e),a=0,i="network",l=1e3*2**n;try{let e=await t.fetch(`${o}/v1/f`,{method:"POST",body:r,credentials:"omit",keepalive:!0});if(a=e.status,a>=200&&a<300)return{ok:!0};let n=Number(e.headers.get("retry-after"));n>0&&(l=1e3*n);try{let t=await e.json();i="string"==typeof t?.error&&/^[a-z_]{1,40}$/.test(t.error)?t.error:"refused"}catch{i="refused"}if(429!==a&&a<500)return{ok:!1,error:i}}catch{}if(n>=3||l>1e4||d)return{ok:!1,error:i};await new Promise(e=>setTimeout(e,l))}})({v:1,k:n.site,i:[...crypto.getRandomValues(new Uint8Array(20))].map(e=>(31&e).toString(32)).join(""),t:[...i].slice(0,w).join(""),...h(a.category)?{c:a.category}:{},u:k(t.location,l),m:p?"j":"a",...p?{s:p}:{},sv:"feedback-0.1.0"})},u=e=>r||=(e=>{let{w:t,config:n}=e,r=t.document,a=r.createElement("div");a.setAttribute("data-lf-block",""),a.setAttribute("data-lf-feedback","");let i=a.attachShadow({mode:"open"});i.innerHTML='<style>:host{all:initial}\n*{box-sizing:border-box;font:14px/1.45 system-ui,sans-serif;color:inherit}\n.w{--b:#fff;--f:#1d1d22;--m:#55555f;--l:#cfcfd8;--a:#3346c4;--o:#fff;--e:#b42318;color:var(--f)}\n@media (prefers-color-scheme:dark){.w{--b:#1d1d23;--f:#f2f2f5;--m:#b0b0bc;--l:#45454f;--a:#9aa5ff;--o:#11131f;--e:#ff9b91}}\nbutton{border:1px solid var(--l);border-radius:8px;background:none;cursor:pointer;padding:8px 16px}\n.f{position:fixed;z-index:2147483000;right:16px;bottom:16px;border-radius:99px;background:var(--b);box-shadow:0 2px 10px #0003}\n.f.l{right:auto;left:16px}\n.f.e{right:0;bottom:auto;top:50%;transform:translateY(-50%) rotate(180deg);writing-mode:vertical-rl;padding:14px 8px}\n:focus-visible{outline:3px solid var(--a);outline-offset:2px}\n.b{position:fixed;inset:0;z-index:2147483001;display:flex;align-items:flex-end;justify-content:flex-end;padding:16px;background:#0004}\n.b.l{justify-content:flex-start}\n[hidden]{display:none!important}\n.d{position:relative;width:min(380px,100%);max-height:calc(100vh - 32px);overflow:auto;padding:20px;border:1px solid var(--l);border-radius:12px;background:var(--b);box-shadow:0 12px 40px #0005}\n@media (max-width:480px){.b{padding:0;justify-content:center}.d{width:100%;border-radius:12px 12px 0 0}}\nh2{margin:0 36px 12px 0;font-size:17px;font-weight:600}\nlabel,legend{display:block;margin:0 0 6px;font-weight:500}\ntextarea{display:block;width:100%;min-height:112px;resize:vertical;padding:8px 10px;border:1px solid var(--l);border-radius:8px;background:none}\n.n,.c{margin:4px 0 12px;color:var(--m);font-size:12.5px}\nfieldset{margin:0;padding:0;border:0}\n.r label{display:inline-flex;gap:4px;align-items:center;margin:0 12px 6px 0;font-weight:400}\ninput{margin:0;accent-color:var(--a)}\n.a{display:flex;justify-content:flex-end;gap:8px}\n.s{border-color:var(--a);background:var(--a);color:var(--o);font-weight:600}\n.s:disabled{opacity:.6}\n.x{position:absolute;top:10px;right:10px;width:34px;height:34px;padding:0;border:0;font-size:22px;line-height:1}\n.t{min-height:1.45em;margin:10px 0 0}\n.t.e{color:var(--e)}\n@media (prefers-reduced-motion:no-preference){.d{animation:i .16s ease-out}@keyframes i{from{opacity:0;transform:translateY(8px)}}}</style><div class="w"><button type="button" class="f" aria-haspopup="dialog"></button><div class="b" hidden><div class="d" role="dialog" aria-modal="true" aria-labelledby="h" aria-describedby="c"><button type="button" class="x" aria-label="Close">×</button><h2 id="h">Send feedback</h2><form novalidate><label for="m"></label><textarea id="m" aria-describedby="n"></textarea><p class="n" id="n"></p><fieldset><legend>Kind of note (optional)</legend><div class="r"></div></fieldset><p class="c" id="c"></p><div class="a"><button type="button" class="k">Cancel</button><button type="submit" class="s">Send</button></div></form><p class="t" role="status" aria-live="polite"></p></div></div></div>';let o=e=>i.querySelector(e),l=o(".f"),d=o(".b"),s=o(".d"),c=o("form"),p=o("textarea"),u=o(".n"),f=o(".c"),g=o(".t"),b=o(".s"),h=o(".x");l.textContent=n.label,"manual"===n.placement?l.remove():"bottom_left"===n.placement?(l.classList.add("l"),d.classList.add("l")):"right_edge"===n.placement&&l.classList.add("e"),o("label").textContent=n.prompt||"What could be better on this page?",p.maxLength=w;let x=o(".r");for(let e of m){let t=r.createElement("label"),n=r.createElement("input");n.type="radio",n.name="k",n.value=e,t.append(n,y[e]),x.append(t)}let v=null,k=!1,$=()=>{let e=w-p.value.length;u.textContent=`${e.toLocaleString("en-US")} ${1===e?"character":"characters"} left`};p.addEventListener("input",$);let _=(e,t=!1)=>{g.textContent=e,g.classList.toggle("e",t)},E=()=>{if(d.hidden)return;d.hidden=!0;let e=v&&v.isConnected?v:l.isConnected?l:null;v=null,e?.focus?.()},A=t=>{a.isConnected||(r.body||r.documentElement).append(a),v=t??null,c.hidden&&(c.hidden=!1,c.reset(),_("")),f.textContent=e.consent(),$(),d.hidden=!1,p.focus()},S=async()=>{if(k)return;if(!p.value.trim())return _(L("empty"),!0),void p.focus();let t=e.consent();if(t!==f.textContent)return f.textContent=t,void _("The line above changed. Read it, then press Send again.",!0);k=!0,b.disabled=!0,_("Sending");let n=x.querySelector(":checked")?.value,r=await e.submit({text:p.value,...n?{category:n}:{}});k=!1,b.disabled=!1,r.ok?(c.hidden=!0,_("Thanks. Your note was sent."),h.focus()):_(L(r.error),!0)};return l.addEventListener("click",()=>A(l)),h.addEventListener("click",E),o(".k").addEventListener("click",E),d.addEventListener("click",e=>{e.target===d&&E()}),c.addEventListener("submit",e=>{e.preventDefault(),S()}),p.addEventListener("keydown",e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),S())}),s.addEventListener("keydown",e=>{if("Escape"===e.key)e.preventDefault(),E();else if("Tab"===e.key){let t=[...s.querySelectorAll("button,textarea,input")].filter(e=>!e.disabled&&!e.closest("[hidden]")&&("INPUT"!==e.tagName||e.checked||!x.querySelector(":checked"))),n=t[0],r=t[t.length-1],a=i.activeElement;if(!n||!r)return;(e.shiftKey?a===n||!a:a===r||!a)&&(e.preventDefault(),(e.shiftKey?r:n).focus())}}),"manual"!==n.placement&&(r.body||r.documentElement).append(a),{open:A,close:E,destroy:()=>{d.hidden=!0,a.remove()},root:i}})({w:t,config:e,consent:()=>(e=>`${e.visit?"Your note, this page's address, the time, your device type and a link to this visit":"Your note, this page's address, the time and your device type"} go to the team behind ${e.site.replace(/^www\./,"")||"this site"} when you press Send, and are kept for ${1===e.days?"1 day":`${e.days} days`}. Please leave out passwords and card numbers.`)({site:t.location.hostname,days:e.days,visit:null!==c()}),submit:p}),f=async e=>{let t=await s;!d&&t&&u(t).open(e??null)};s.then(e=>{!d&&e&&"manual"!==e.placement&&u(e)});let g,b,x=e=>{let t=e[1],n=e[2];t&&"object"==typeof t?p(t).then(e=>{"function"==typeof n&&n(e)}):f(i.activeElement)},v=1e3,_=()=>{if(clearTimeout(a),d)return;let e=t.lf;if(!e){let n=(...e)=>n.q.push(e);n.q=[],t.lf=e=n}(!e.q||e.q!==g)&&(g=((e,t,n)=>{let r=e.q;(!r||"function"!=typeof r.push)&&(r=[],e.q=r);let a=e=>{try{n(e)}catch(e){setTimeout(()=>{throw e})}};if(Array.isArray(r))for(let e=0;e<r.length;)r[e]?.[0]===t?a(r.splice(e,1)[0]):e++;let i=r,o=i.push;return i.push=e=>e?.[0]===t?a(e):o.call(i,e),i})(e,"feedback",x)),e.v||(a=setTimeout(_,v),v=Math.min(2*v,3e4))},E=Object.getOwnPropertyDescriptor(t,"lf"),A=!!E&&!("value"in E),S=t.lf;if(!E||E.configurable){b={configurable:!0,enumerable:!E||E.enumerable,get:A?()=>E.get?.call(t):()=>S,set:e=>{A?E.set?.call(t,e):S=e,e?.v&&_()}};try{Object.defineProperty(t,"lf",b)}catch{b=void 0}}return _(),{ready:s,open:f,send:p,stop:()=>{if(d=!0,clearTimeout(a),b&&Object.getOwnPropertyDescriptor(t,"lf")?.get===b.get)try{Object.defineProperty(t,"lf",A&&E?E:{configurable:!0,enumerable:b.enumerable,writable:!0,value:S})}catch{}r?.destroy(),r=void 0},widget:()=>r}}(t,n);r[E]=i;let o=i.stop;i.stop=()=>{o(),r[E]===i&&delete r[E]}})(window,{site:j,api:C("api"),routes:Array.isArray(_)?_:[]})})();
|
|
1
|
+
(()=>{var e=/^[A-Za-z0-9_-]{16,32}$/,t=new RegExp("[^\\s@/]{1,64}@[^\\s@/]{1,253}\\.\\p{L}{2,24}","iu"),n=/\d[\d\s().-]{7,}\d/,r=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,a=/^[0-9a-f]{16,}$/i,i=/[a-f]/i,o=/^\d+$/,l=/^(?=.*\d)(?=.*[a-zA-Z])[A-Za-z0-9_-]{20,}$/,s=/^(?:eyJ[A-Za-z0-9_-]{4,}(?:\.[A-Za-z0-9_-]*){1,4}|(?=.*\d)(?=.*[A-Z])[A-Za-z0-9_-]{16,}(?:\.[A-Za-z0-9_-]{16,}){2})$/,d=/^:[a-z_][a-z0-9_]{0,31}$/,c=/[\u0000-\u001f\u007f]/g,u=/[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;function f(e){let o=e.length>2048?e.slice(0,2048):e;return!(!o.includes("@")||!t.test(o))||(!a.test(o)&&!r.test(o)||!i.test(o))&&(n.test(o)||b(o))}var p=[/(?:^|[^A-Za-z0-9])xox[abeprs]-\d/,/(?:^|[^A-Za-z0-9])gh[pousr]_[A-Za-z0-9]{36}/,/(?:^|[^A-Za-z0-9])github_pat_[A-Za-z0-9_]{22,}/,/(?:^|[^A-Za-z0-9])(?:AKIA|ASIA)[A-Z0-9]{16}(?![A-Za-z0-9])/,/(?:^|[^A-Za-z0-9])[sr]k_(?:live|test)_[A-Za-z0-9]{16,}/,/(?:^|[^A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{16,}/],b=e=>p.some(t=>t.test(e));function g(e){return(e=>{if("string"!=typeof e||e.length>2048)return null;let t=e,n=t.search(/[?#]/);n>=0&&(t=t.slice(0,n)),t.startsWith("/")||(t=`/${t}`);let i=t;try{i=decodeURIComponent(t)}catch{}i=(e=>e.replace(c,"").replace(u,e=>2===e.length?e:""))(i);let p=i.search(/[?#]/);p>=0&&(i=i.slice(0,p));let b=i.split("/").map(e=>{if(e.includes("="))return":redacted";if(""===e)return e;if(e.startsWith(":")){let t=e.slice(1);return m.test(t)?e:h(t)?":id":f(t)?":redacted":e}if(d.test(e))return e;let t=e.startsWith(":")?e.slice(1):e;return o.test(t)||r.test(t)||a.test(t)||l.test(t)||s.test(t)?":id":f(t)?":redacted":e}).join("/");return b.length>1&&b.endsWith("/")&&(b=b.slice(0,-1)),b.length>256?null:b})(e)}var m=/^[A-Za-z_][A-Za-z0-9_]*$/,h=e=>o.test(e)||r.test(e)||a.test(e)||s.test(e),y=["confusing","bug","idea","other"];function x(e){return"string"==typeof e&&y.includes(e)}var v={confusing:"Confusing",bug:"Something broke",idea:"Idea",other:"Other"},k=["bottom_right","bottom_left","right_edge","manual"];function w(e){return"string"==typeof e&&k.includes(e)}var A=2e3;function z(e,t){let n=e.pathname,r="file:"===e.protocol?n.slice(n.lastIndexOf("/")):n;for(let[e,n]of t)if(n.test(r))return g(e)??"/";return g(r)??"/"}function _(e){return"empty"===e?"Write a note first.":"rate_limited"===e||"quota_exceeded"===e?"Too many notes right now. Please try again in a minute.":"network"===e?"Your note was not sent. Check your connection and try again.":"feedback_off"===e?"Feedback is turned off for this site.":"Your note was not sent. Please try again."}function $(e){let t=e;if(!0!==t?.on)return null;let n="string"==typeof t.label?t.label.trim().slice(0,24):"",r="string"==typeof t.prompt?t.prompt.trim().slice(0,140):"",a=t.days;return{v:1,on:!0,label:n||"Feedback",placement:w(t.placement)?t.placement:"bottom_right",prompt:r||null,days:"number"==typeof a&&Number.isInteger(a)&&a>=1?a:90}}var S,Z=Symbol.for("littlefriend.feedback"),E=document,L=E.currentScript,C=L?.hasAttribute("data-site")?L:E.querySelector("script[data-site][data-feedback]"),j=e=>C?.getAttribute(`data-${e}`)||void 0,q=j("site");try{S=JSON.parse(j("routes")||E.querySelector("script[data-site][data-routes]")?.getAttribute("data-routes")||"[]")}catch{}q&&((t,n)=>{let r=t,a=r[Z];if(a)return a;let i=function(t,n){let r,a,i=t.document,o=(n.api||"https://in.littlefriend.io").replace(/\/+$/,""),l=(e=>Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.startsWith("/")).map(e=>[e,RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/:\w+/g,"[^/]+").replace(/\*/g,".*")}/?$`)]):[])(n.routes),s=!1,d=new Promise(e=>i.prerendering?i.addEventListener("prerenderingchange",()=>e(),{once:!0}):e()).then(()=>t.fetch(`${o}/v1/f/config?k=${encodeURIComponent(n.site)}`,{credentials:"omit"})).then(e=>e.ok?e.json():null).then($,()=>null),c=()=>{let n=null,r=t.lf;if(r?.v)try{r("session",t=>{n="string"==typeof t&&e.test(t)?t:null})}catch{}return n},u=async e=>{let r=await d;if(s||!r)return{ok:!1,error:"feedback_off"};let a=e??{},i="string"==typeof a.text?a.text.trim():"";if(!i)return{ok:!1,error:"empty"};if(null!=a.category&&!x(a.category))return{ok:!1,error:"bad_category"};let u=c();return(async e=>{for(let n=0;;n++){e.s&&c()!==e.s&&(delete e.s,e.m="a");let r=JSON.stringify(e),a=0,i="network",l=1e3*2**n;try{let e=await t.fetch(`${o}/v1/f`,{method:"POST",body:r,credentials:"omit",keepalive:!0});if(a=e.status,a>=200&&a<300)return{ok:!0};let n=Number(e.headers.get("retry-after"));n>0&&(l=1e3*n);try{let t=await e.json();i="string"==typeof t?.error&&/^[a-z_]{1,40}$/.test(t.error)?t.error:"refused"}catch{i="refused"}if(429!==a&&a<500)return{ok:!1,error:i}}catch{}if(n>=3||l>1e4||s)return{ok:!1,error:i};await new Promise(e=>setTimeout(e,l))}})({v:1,k:n.site,i:[...crypto.getRandomValues(new Uint8Array(20))].map(e=>(31&e).toString(32)).join(""),t:[...i].slice(0,A).join(""),...x(a.category)?{c:a.category}:{},u:z(t.location,l),m:u?"j":"a",...u?{s:u}:{},sv:"feedback-0.1.2"})},f=e=>r||=(e=>{let{w:t,config:n}=e,r=t.document,a=r.createElement("div");a.setAttribute("data-lf-block",""),a.setAttribute("data-lf-feedback","");let i=a.attachShadow({mode:"open"});i.innerHTML='<style>:host{all:initial}\n*{box-sizing:border-box;font:14px/1.45 system-ui,sans-serif;color:inherit}\n.w{--b:#fff;--f:#1d1d22;--m:#55555f;--l:#cfcfd8;--a:#3346c4;--o:#fff;--e:#b42318;color:var(--f)}\n@media (prefers-color-scheme:dark){.w{--b:#1d1d23;--f:#f2f2f5;--m:#b0b0bc;--l:#45454f;--a:#9aa5ff;--o:#11131f;--e:#ff9b91}}\nbutton{border:1px solid var(--l);border-radius:8px;background:none;cursor:pointer;padding:8px 16px}\n.f{position:fixed;z-index:2147483000;right:16px;bottom:16px;border-radius:99px;background:var(--b);box-shadow:0 2px 10px #0003}\n.f.l{right:auto;left:16px}\n.f.e{right:0;bottom:auto;top:50%;transform:translateY(-50%) rotate(180deg);writing-mode:vertical-rl;padding:14px 8px}\n:focus-visible{outline:3px solid var(--a);outline-offset:2px}\n.b{position:fixed;inset:0;z-index:2147483001;display:flex;align-items:flex-end;justify-content:flex-end;padding:16px;background:#0004}\n.b.l{justify-content:flex-start}\n[hidden]{display:none!important}\n.d{position:relative;width:min(380px,100%);max-height:calc(100vh - 32px);overflow:auto;padding:20px;border:1px solid var(--l);border-radius:12px;background:var(--b);box-shadow:0 12px 40px #0005}\n@media (max-width:480px){.b{padding:0;justify-content:center}.d{width:100%;border-radius:12px 12px 0 0}}\nh2{margin:0 36px 12px 0;font-size:17px;font-weight:600}\nlabel,legend{display:block;margin:0 0 6px;font-weight:500}\ntextarea{display:block;width:100%;min-height:112px;resize:vertical;padding:8px 10px;border:1px solid var(--l);border-radius:8px;background:none}\n.n,.c{margin:4px 0 12px;color:var(--m);font-size:12.5px}\nfieldset{margin:0;padding:0;border:0}\n.r label{display:inline-flex;gap:4px;align-items:center;margin:0 12px 6px 0;font-weight:400}\ninput{margin:0;accent-color:var(--a)}\n.a{display:flex;justify-content:flex-end;gap:8px}\n.s{border-color:var(--a);background:var(--a);color:var(--o);font-weight:600}\n.s:disabled{opacity:.6}\n.x{position:absolute;top:10px;right:10px;width:34px;height:34px;padding:0;border:0;font-size:22px;line-height:1}\n.t{min-height:1.45em;margin:10px 0 0}\n.t.e{color:var(--e)}\n@media (prefers-reduced-motion:no-preference){.d{animation:i .16s ease-out}@keyframes i{from{opacity:0;transform:translateY(8px)}}}</style><div class="w"><button type="button" class="f" aria-haspopup="dialog"></button><div class="b" hidden><div class="d" role="dialog" aria-modal="true" aria-labelledby="h" aria-describedby="c"><button type="button" class="x" aria-label="Close">×</button><h2 id="h">Send feedback</h2><form novalidate><label for="m"></label><textarea id="m" aria-describedby="n"></textarea><p class="n" id="n"></p><fieldset><legend>Kind of note (optional)</legend><div class="r"></div></fieldset><p class="c" id="c"></p><div class="a"><button type="button" class="k">Cancel</button><button type="submit" class="s">Send</button></div></form><p class="t" role="status" aria-live="polite"></p></div></div></div>';let o=e=>i.querySelector(e),l=o(".f"),s=o(".b"),d=o(".d"),c=o("form"),u=o("textarea"),f=o(".n"),p=o(".c"),b=o(".t"),g=o(".s"),m=o(".x");l.textContent=n.label,"manual"===n.placement?l.remove():"bottom_left"===n.placement?(l.classList.add("l"),s.classList.add("l")):"right_edge"===n.placement&&l.classList.add("e"),o("label").textContent=n.prompt||"What could be better on this page?",u.maxLength=A;let h=o(".r");for(let e of y){let t=r.createElement("label"),n=r.createElement("input");n.type="radio",n.name="k",n.value=e,t.append(n,v[e]),h.append(t)}let x=null,k=!1,w=()=>{let e=A-u.value.length;f.textContent=`${e.toLocaleString("en-US")} ${1===e?"character":"characters"} left`};u.addEventListener("input",w);let z=(e,t=!1)=>{b.textContent=e,b.classList.toggle("e",t)},$=()=>{if(s.hidden)return;s.hidden=!0;let e=x&&x.isConnected?x:l.isConnected?l:null;x=null,e?.focus?.()},S=t=>{a.isConnected||(r.body||r.documentElement).append(a),x=t??null,c.hidden&&(c.hidden=!1,c.reset(),z("")),p.textContent=e.consent(),w(),s.hidden=!1,u.focus()},Z=async()=>{if(k)return;if(!u.value.trim())return z(_("empty"),!0),void u.focus();let t=e.consent();if(t!==p.textContent)return p.textContent=t,void z("The line above changed. Read it, then press Send again.",!0);k=!0,g.disabled=!0,z("Sending");let n=h.querySelector(":checked")?.value,r=await e.submit({text:u.value,...n?{category:n}:{}});k=!1,g.disabled=!1,r.ok?(c.hidden=!0,z("Thanks. Your note was sent."),m.focus()):z(_(r.error),!0)};return l.addEventListener("click",()=>S(l)),m.addEventListener("click",$),o(".k").addEventListener("click",$),s.addEventListener("click",e=>{e.target===s&&$()}),c.addEventListener("submit",e=>{e.preventDefault(),Z()}),u.addEventListener("keydown",e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),Z())}),d.addEventListener("keydown",e=>{if("Escape"===e.key)e.preventDefault(),$();else if("Tab"===e.key){let t=[...d.querySelectorAll("button,textarea,input")].filter(e=>!e.disabled&&!e.closest("[hidden]")&&("INPUT"!==e.tagName||e.checked||!h.querySelector(":checked"))),n=t[0],r=t[t.length-1],a=i.activeElement;if(!n||!r)return;(e.shiftKey?a===n||!a:a===r||!a)&&(e.preventDefault(),(e.shiftKey?r:n).focus())}}),"manual"!==n.placement&&(r.body||r.documentElement).append(a),{open:S,close:$,destroy:()=>{s.hidden=!0,a.remove()},root:i}})({w:t,config:e,consent:()=>(e=>`${e.visit?"Your note, this page's address, the time, your device type and a link to this visit":"Your note, this page's address, the time and your device type"} go to the team behind ${e.site.replace(/^www\./,"")||"this site"} when you press Send, and are kept for ${1===e.days?"1 day":`${e.days} days`}. Please leave out passwords and card numbers.`)({site:t.location.hostname,days:e.days,visit:null!==c()}),submit:u}),p=async e=>{let t=await d;!s&&t&&f(t).open(e??null)};d.then(e=>{!s&&e&&"manual"!==e.placement&&f(e)});let b,g,m=e=>{let t=e[1],n=e[2];t&&"object"==typeof t?u(t).then(e=>{"function"==typeof n&&n(e)}):p(i.activeElement)},h=1e3,k=()=>{if(clearTimeout(a),s)return;let e=t.lf;if(!e){let n=(...e)=>n.q.push(e);n.q=[],t.lf=e=n}(!e.q||e.q!==b)&&(b=((e,t,n)=>{let r=e.q;(!r||"function"!=typeof r.push)&&(r=[],e.q=r);let a=e=>{try{n(e)}catch(e){setTimeout(()=>{throw e})}};if(Array.isArray(r))for(let e=0;e<r.length;)r[e]?.[0]===t?a(r.splice(e,1)[0]):e++;let i=r,o=i.push;return i.push=e=>e?.[0]===t?a(e):o.call(i,e),i})(e,"feedback",m)),e.v||(a=setTimeout(k,h),h=Math.min(2*h,3e4))},w=Object.getOwnPropertyDescriptor(t,"lf"),S=!!w&&!("value"in w),Z=t.lf;if(!w||w.configurable){g={configurable:!0,enumerable:!w||w.enumerable,get:S?()=>w.get?.call(t):()=>Z,set:e=>{S?w.set?.call(t,e):Z=e,e?.v&&k()}};try{Object.defineProperty(t,"lf",g)}catch{g=void 0}}return k(),{ready:d,open:p,send:u,stop:()=>{if(s=!0,clearTimeout(a),g&&Object.getOwnPropertyDescriptor(t,"lf")?.get===g.get)try{Object.defineProperty(t,"lf",S&&w?w:{configurable:!0,enumerable:g.enumerable,writable:!0,value:Z})}catch{}r?.destroy(),r=void 0},widget:()=>r}}(t,n);r[Z]=i;let o=i.stop;i.stop=()=>{o(),r[Z]===i&&delete r[Z]}})(window,{site:q,api:j("api"),routes:Array.isArray(S)?S:[]})})();
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Kept in step with package.json by test/size.test.ts. */
|
|
2
|
-
export declare const VERSION = "0.1.
|
|
2
|
+
export declare const VERSION = "0.1.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@littlefriend/feedback",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Little Friend feedback button: a small, accessible widget where a person can tell you a page is confusing, at the moment it happens. Sent only when they press Send.",
|
|
6
6
|
"keywords": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"happy-dom": "^20.0.0",
|
|
36
36
|
"terser": "^5.51.2",
|
|
37
37
|
"@littlefriend/contract": "0.1.0",
|
|
38
|
-
"@littlefriend/tracker": "0.1.
|
|
38
|
+
"@littlefriend/tracker": "0.1.8"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "node scripts/build.mjs",
|