@daybook/feedback 1.0.0 → 1.1.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/README.md +10 -9
- package/dist/feedback.js +3 -3
- package/dist/index.d.ts +12 -1
- package/dist/index.js +13 -4
- package/dist/types.d.ts +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,28 +13,26 @@ a triager needs is captured without asking them.
|
|
|
13
13
|
<script src="https://daybook.team/sdk/v1/feedback.js"></script>
|
|
14
14
|
<script>
|
|
15
15
|
var pm = DaybookFeedback.init({
|
|
16
|
-
apiUrl: 'https://pm-api.hreben.us',
|
|
17
16
|
ingestKey: 'pmi_…',
|
|
18
17
|
reporter: { externalId: user.id, email: user.email },
|
|
19
18
|
})
|
|
20
19
|
</script>
|
|
21
20
|
```
|
|
22
21
|
|
|
23
|
-
> **The package is not on npm yet.** Everything below is the shape it will have, and works today if
|
|
24
|
-
> you vendor `feedback.js` into your own build. Until it is published, the script tag is the route
|
|
25
|
-
> that works — it serves the same bundle.
|
|
26
|
-
|
|
27
22
|
The `/sdk/v1/` path is versioned on purpose. A script tag points at a URL forever, so what is there
|
|
28
23
|
stays compatible with what `/ingest/v1` accepts; a breaking change would appear at `/sdk/v2/` beside
|
|
29
24
|
it rather than replacing it under everybody's feet.
|
|
30
25
|
|
|
31
26
|
### JavaScript, as a module
|
|
32
27
|
|
|
28
|
+
```
|
|
29
|
+
npm install @daybook/feedback
|
|
30
|
+
```
|
|
31
|
+
|
|
33
32
|
```js
|
|
34
33
|
import { init } from '@daybook/feedback'
|
|
35
34
|
|
|
36
35
|
const pm = init({
|
|
37
|
-
apiUrl: 'https://pm-api.hreben.us',
|
|
38
36
|
ingestKey: 'pmi_…', // per-environment, write-only, safe to ship
|
|
39
37
|
app: { version: '1.4.0' },
|
|
40
38
|
reporter: { externalId: user.id, email: user.email },
|
|
@@ -53,7 +51,6 @@ import { init } from '@daybook/feedback'
|
|
|
53
51
|
export function FeedbackWidget({ user }: { user: { id: string; email: string } | null }) {
|
|
54
52
|
useEffect(() => {
|
|
55
53
|
const pm = init({
|
|
56
|
-
apiUrl: import.meta.env.VITE_FEEDBACK_API_URL,
|
|
57
54
|
ingestKey: import.meta.env.VITE_FEEDBACK_KEY,
|
|
58
55
|
surface: 'web-app',
|
|
59
56
|
reporter: user ? { externalId: user.id, email: user.email } : undefined,
|
|
@@ -86,7 +83,6 @@ export function useFeedback(user: Ref<{ id: string; email: string } | null>) {
|
|
|
86
83
|
// would fire during setup, before this runs, and identify() on nothing is silently no-op.
|
|
87
84
|
onMounted(() => {
|
|
88
85
|
pm = init({
|
|
89
|
-
apiUrl: import.meta.env.VITE_FEEDBACK_API_URL,
|
|
90
86
|
ingestKey: import.meta.env.VITE_FEEDBACK_KEY,
|
|
91
87
|
surface: 'web-app',
|
|
92
88
|
reporter: user.value
|
|
@@ -108,6 +104,11 @@ Call `useFeedback(user)` once, from `App.vue`.
|
|
|
108
104
|
|
|
109
105
|
A launcher appears bottom-right. `F` opens the picker, `Esc` backs out, `Cmd/Ctrl+Enter` sends.
|
|
110
106
|
|
|
107
|
+
The key is the only thing you have to supply. Reports go to Daybook's own API by default — where
|
|
108
|
+
they are received is ours to keep working, not a hostname for you to paste and then keep in step
|
|
109
|
+
with us. Pass `apiUrl` only to point at something that is not Daybook: a self-hosted install, or a
|
|
110
|
+
local API while you are developing.
|
|
111
|
+
|
|
111
112
|
## Allow your domain first
|
|
112
113
|
|
|
113
114
|
The widget only runs on domains you have listed. In Daybook, open **Project settings → Feedback
|
|
@@ -174,7 +175,7 @@ A third mode, for when the reporter already has a Daybook account — an interna
|
|
|
174
175
|
team dogfooding. Then there is no secret to configure at all:
|
|
175
176
|
|
|
176
177
|
```js
|
|
177
|
-
const pm = init({
|
|
178
|
+
const pm = init({ ingestKey: 'pmi_…' })
|
|
178
179
|
|
|
179
180
|
// It opens a popup, so a real click has to trigger it — a call at startup is blocked.
|
|
180
181
|
document.querySelector('#feedback-signin')
|
package/dist/feedback.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var DaybookFeedback=(()=>{var I=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var le=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},de=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ae(e))!ce.call(n,o)&&o!==t&&I(n,o,{get:()=>e[o],enumerable:!(r=se(e,o))||r.enumerable});return n};var pe=n=>de(I({},"__esModule",{value:!0}),n);var Re={};le(Re,{DaybookFeedback:()=>_,captureAnchor:()=>L,init:()=>Se,resolveAnchor:()=>te});function g(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}function M(n){var r,o,i,a,s,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((r=n.textContent)!=null?r:"").trim()){let d=n.closest("button, a, [role=button], [data-testid], label");if(d&&d!==n)return M(d)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let d=(i=(o=n.getAttribute("name"))!=null?o:n.id)!=null?i:"",p=n instanceof HTMLInputElement?n.type:e;return`${e}[${p}]${d?` name=${d}`:""}`}let t=(c=(a=n.getAttribute("aria-label"))!=null?a:n.getAttribute("data-testid"))!=null?c:((s=n.textContent)!=null?s:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function X(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var W="data-daybook-private";var x=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?X(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=s=>{let c=s.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",M(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,r=history.replaceState,o=()=>this.add("nav",g(location.href));history.pushState=(...s)=>{t.apply(history,s),o()},history.replaceState=(...s)=>{r.apply(history,s),o()},window.addEventListener("popstate",o),this.detach.push(()=>{history.pushState=t,history.replaceState=r,window.removeEventListener("popstate",o)});for(let s of["error","warn"]){let c=console[s];console[s]=(...d)=>{this.add("console",`${s}: ${d.map(C).join(" ")}`),c.apply(console,d)},this.detach.push(()=>{console[s]=c})}let i=s=>this.add("console",`uncaught: ${s.message}`),a=s=>this.add("console",`unhandled rejection: ${C(s.reason)}`);window.addEventListener("error",i),window.addEventListener("unhandledrejection",a),this.detach.push(()=>{window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",a)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let r=performance.now();try{let o=await e.apply(window,t),i=Math.round(performance.now()-r);return(!o.ok||i>3e3)&&this.add("network",`${o.status} ${g(V(t[0]))} ${i}ms`),o}catch(o){throw this.add("network",`failed ${g(V(t[0]))}: ${C(o)}`),o}},this.detach.push(()=>{window.fetch=e})}};function V(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function C(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var H="pm.feedback.queue";var E=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[]){var a,s;let r={idempotencyKey:(a=e.idempotencyKey)!=null?a:Y(),...e,attachments:[...(s=e.attachments)!=null?s:[],...t.map(c=>({filename:c.filename,contentType:c.contentType,size:c.blob.size}))]},o=await this.post("/ingest/v1",r);if(!o.ok)throw await k(o);let i=await o.json();return await Promise.all(t.map((c,d)=>{let p=i.attachments[d];return p?this.upload(p,c).catch(()=>{}):Promise.resolve()})),i}async flush(){let e=Q();if(e.length!==0){Z([]);for(let t of e)try{let r=await this.post("/ingest/v1",t);!r.ok&&(r.status===429||r.status>=500)&&F(t)}catch{F(t)}}}queue(e){var t;F({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:Y(),attachments:void 0})}async signIn(){let e=J(64),t=await he(e),r=J(16),o=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(r)}`,i=window.open(o,"daybook-feedback","width=460,height=640");if(!i)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let a=await new Promise((d,p)=>{let b=setInterval(()=>{i.closed&&(w(),p(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),y=m=>{if(m.origin!==new URL(this.base()).origin)return;let h=m.data;if((h==null?void 0:h.source)==="daybook-feedback"&&h.state===r){if(w(),h.error||!h.code){p(Object.assign(new Error("Sign-in was refused"),{code:h.error||"refused"}));return}d(h.code)}},w=()=>{clearInterval(b),window.removeEventListener("message",y)};window.addEventListener("message",y)}),s=await this.post("/ingest/v1/token",{code:a,codeVerifier:e});if(!s.ok)throw await k(s);let{identityToken:c}=await s.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}async handshake(e){var o,i;let t=await this.post("/ingest/v1/session",{...e,identityToken:(o=this.identityToken)!=null?o:void 0});if(!t.ok)throw await k(t);let r=await t.json();return this.session=(i=r.sessionToken)!=null?i:null,r}post(e,t){let r={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(r["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:r,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let r=await fetch(e.uploadUrl,{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!r.ok)throw await k(r);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function F(n){let e=Q();e.push(n),Z(e.slice(-20))}function Q(){try{let n=localStorage.getItem(H);return n?JSON.parse(n):[]}catch{return[]}}function Z(n){try{n.length===0?localStorage.removeItem(H):localStorage.setItem(H,JSON.stringify(n))}catch{}}async function k(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function Y(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function J(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,r=>e[r%e.length]).join("")}async function he(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function U(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:fe(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:ue()};return document.referrer&&(e.referrer=g(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function ue(){var o;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",r=(o=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:o[1];return{browser:r?`${e} ${r}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function fe(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function G(n){var r;if(typeof((r=navigator.mediaDevices)==null?void 0:r.getDisplayMedia)!="function")return null;let e=n?ge():()=>{},t=null;try{if(t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0}),!t.getVideoTracks()[0])return null;await new Promise(a=>setTimeout(a,250));let i=await me(t);return i?{blob:i,filename:"screenshot.png",contentType:"image/png"}:null}catch{return null}finally{t==null||t.getTracks().forEach(o=>o.stop()),e()}}async function me(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=document.createElement("canvas");t.width=e.videoWidth||window.innerWidth,t.height=e.videoHeight||window.innerHeight;let r=t.getContext("2d");return r?(r.drawImage(e,0,0,t.width,t.height),e.pause(),e.srcObject=null,new Promise(o=>t.toBlob(i=>o(i),"image/png"))):null}function ge(){let n=[...document.querySelectorAll(`[${W}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,r)=>{var o;t.style.filter=(o=e[r])!=null?o:""})}}function L(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:S(n/window.innerWidth),offsetY:S(e/window.innerHeight),elementText:null};let r=t.getBoundingClientRect();return{selector:be(t),offsetX:r.width>0?S((n-r.left)/r.width):0,offsetY:r.height>0?S((e-r.top)/r.height):0,elementText:ye(t)}}function te(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function be(n){if(n===document.body)return"body";for(let o of["data-testid","data-test","data-daybook-id","data-cy"]){let i=n.getAttribute(o);if(i){let a=`[${o}="${O(i)}"]`;if(T(a))return a}}if(n.id&&!ee(n.id)){let o=`#${O(n.id)}`;if(T(o))return o}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let o=t.tagName.toLowerCase(),i=Array.from(t.classList).filter(c=>!ee(c)).slice(0,2);i.length>0&&(o+=i.map(c=>`.${O(c)}`).join(""));let a=t.parentElement;if(a){let c=Array.from(a.children).filter(d=>d.tagName===t.tagName);c.length>1&&(o+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(o);let s=e.join(" > ");if(T(s))return s;t=a}let r=e.length>0?`body > ${e.join(" > ")}`:null;return r&&T(r)?r:null}function T(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function ee(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function ye(n){var r,o,i;let t=((o=(r=n.innerText)!=null?r:n.textContent)!=null?o:"").replace(/\s+/g," ").trim();if(!t){let a=(i=n.getAttribute("aria-label"))!=null?i:n.getAttribute("title");return(a==null?void 0:a.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function S(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function O(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var we=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function ne(n,e){let t=[];for(let r of n){if(e+t.length>=5)break;let o=we.test(r.type)?r.size>26214400?`Too large (${(r.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:r,filename:r.name||`pasted-${t.length+1}.${ve(r.type)}`,contentType:r.type,preview:o?null:URL.createObjectURL(r),error:o})}return t}function re(n){var r;let e=(r=n.clipboardData)==null?void 0:r.items;if(!e)return[];let t=[];for(let o of e){if(o.kind!=="file")continue;let i=o.getAsFile();i&&t.push(i)}return t}function R(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function ve(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function oe(n){var r;let t=(r=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?r:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}var $=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.state="ready";this.reference=null;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${Te}</style><style id="theme"></style><div id="layer"></div>`}setTheme(e){var a,s;let t=this.root.getElementById("theme");if(!t)return;if(!e){t.textContent="";return}let r=[];Ee(e.accent)&&r.push(`--pm-accent: ${e.accent}`);let o={none:"0",sm:"6px",md:"12px",lg:"18px"}[(a=e.cornerRadius)!=null?a:"md"];o&&r.push(`--pm-radius: ${o}`);let i=ke[(s=e.position)!=null?s:"bottom-right"];i&&r.push(i),t.textContent=r.length>0?`:host { ${r.join("; ")} }`:"",this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}setState(e){this.state=e,this.host.isConnected&&this.render()}mount(){var e;if(document.body.appendChild(this.host),this.render(),this.options.hotkey!==null){let t=((e=this.options.hotkey)!=null?e:"f").toLowerCase(),r=o=>{if(o.key==="Escape"){this.mode="idle",this.anchor=null,this.render();return}o.metaKey||o.ctrlKey||o.altKey||oe(o)||this.mode!=="composing"&&o.key.toLowerCase()===t&&(this.mode=this.mode==="picking"?"idle":"picking",this.render())};window.addEventListener("keydown",r),this.detach.push(()=>window.removeEventListener("keydown",r))}}unmount(){for(let e of this.detach.splice(0))e();this.host.remove()}open(){this.mode="picking",this.render()}setReporter(e){this.reporter=e}render(){let e=this.root.getElementById("layer");if(e.innerHTML="",this.mode==="idle"){e.appendChild(this.state==="pending"?this.pending():this.launcher());return}if(this.mode==="sent"){e.appendChild(this.sent());return}if(this.mode==="picking"){e.appendChild(this.picker());return}e.appendChild(this.composer())}pending(){let e=document.createElement("div");return e.className="launcher launcher--pending",e.setAttribute("role","status"),e.textContent="Feedback access pending approval",e}sent(){let e=document.createElement("div");e.className="panel panel--sent",e.setAttribute("role","status"),e.innerHTML=`
|
|
1
|
+
"use strict";var DaybookFeedback=(()=>{var I=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var le=Object.prototype.hasOwnProperty;var de=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},pe=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ce(e))!le.call(n,o)&&o!==t&&I(n,o,{get:()=>e[o],enumerable:!(r=ae(e,o))||r.enumerable});return n};var he=n=>pe(I({},"__esModule",{value:!0}),n);var _e={};de(_e,{DEFAULT_API_URL:()=>se,DaybookFeedback:()=>$,captureAnchor:()=>L,init:()=>Le,resolveAnchor:()=>te});function g(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}function M(n){var r,o,i,a,s,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((r=n.textContent)!=null?r:"").trim()){let d=n.closest("button, a, [role=button], [data-testid], label");if(d&&d!==n)return M(d)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let d=(i=(o=n.getAttribute("name"))!=null?o:n.id)!=null?i:"",p=n instanceof HTMLInputElement?n.type:e;return`${e}[${p}]${d?` name=${d}`:""}`}let t=(c=(a=n.getAttribute("aria-label"))!=null?a:n.getAttribute("data-testid"))!=null?c:((s=n.textContent)!=null?s:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function X(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var W="data-daybook-private";var x=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?X(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=s=>{let c=s.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",M(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,r=history.replaceState,o=()=>this.add("nav",g(location.href));history.pushState=(...s)=>{t.apply(history,s),o()},history.replaceState=(...s)=>{r.apply(history,s),o()},window.addEventListener("popstate",o),this.detach.push(()=>{history.pushState=t,history.replaceState=r,window.removeEventListener("popstate",o)});for(let s of["error","warn"]){let c=console[s];console[s]=(...d)=>{this.add("console",`${s}: ${d.map(C).join(" ")}`),c.apply(console,d)},this.detach.push(()=>{console[s]=c})}let i=s=>this.add("console",`uncaught: ${s.message}`),a=s=>this.add("console",`unhandled rejection: ${C(s.reason)}`);window.addEventListener("error",i),window.addEventListener("unhandledrejection",a),this.detach.push(()=>{window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",a)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let r=performance.now();try{let o=await e.apply(window,t),i=Math.round(performance.now()-r);return(!o.ok||i>3e3)&&this.add("network",`${o.status} ${g(V(t[0]))} ${i}ms`),o}catch(o){throw this.add("network",`failed ${g(V(t[0]))}: ${C(o)}`),o}},this.detach.push(()=>{window.fetch=e})}};function V(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function C(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var H="pm.feedback.queue";var E=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[]){var a,s;let r={idempotencyKey:(a=e.idempotencyKey)!=null?a:Y(),...e,attachments:[...(s=e.attachments)!=null?s:[],...t.map(c=>({filename:c.filename,contentType:c.contentType,size:c.blob.size}))]},o=await this.post("/ingest/v1",r);if(!o.ok)throw await k(o);let i=await o.json();return await Promise.all(t.map((c,d)=>{let p=i.attachments[d];return p?this.upload(p,c).catch(()=>{}):Promise.resolve()})),i}async flush(){let e=Q();if(e.length!==0){Z([]);for(let t of e)try{let r=await this.post("/ingest/v1",t);!r.ok&&(r.status===429||r.status>=500)&&F(t)}catch{F(t)}}}queue(e){var t;F({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:Y(),attachments:void 0})}async signIn(){let e=J(64),t=await ue(e),r=J(16),o=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(r)}`,i=window.open(o,"daybook-feedback","width=460,height=640");if(!i)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let a=await new Promise((d,p)=>{let b=setInterval(()=>{i.closed&&(w(),p(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),y=m=>{if(m.origin!==new URL(this.base()).origin)return;let h=m.data;if((h==null?void 0:h.source)==="daybook-feedback"&&h.state===r){if(w(),h.error||!h.code){p(Object.assign(new Error("Sign-in was refused"),{code:h.error||"refused"}));return}d(h.code)}},w=()=>{clearInterval(b),window.removeEventListener("message",y)};window.addEventListener("message",y)}),s=await this.post("/ingest/v1/token",{code:a,codeVerifier:e});if(!s.ok)throw await k(s);let{identityToken:c}=await s.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}async handshake(e){var o,i;let t=await this.post("/ingest/v1/session",{...e,identityToken:(o=this.identityToken)!=null?o:void 0});if(!t.ok)throw await k(t);let r=await t.json();return this.session=(i=r.sessionToken)!=null?i:null,r}post(e,t){let r={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(r["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:r,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let r=await fetch(e.uploadUrl,{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!r.ok)throw await k(r);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function F(n){let e=Q();e.push(n),Z(e.slice(-20))}function Q(){try{let n=localStorage.getItem(H);return n?JSON.parse(n):[]}catch{return[]}}function Z(n){try{n.length===0?localStorage.removeItem(H):localStorage.setItem(H,JSON.stringify(n))}catch{}}async function k(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function Y(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function J(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,r=>e[r%e.length]).join("")}async function ue(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function U(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:me(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:fe()};return document.referrer&&(e.referrer=g(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function fe(){var o;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",r=(o=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:o[1];return{browser:r?`${e} ${r}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function me(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function G(n){var r;if(typeof((r=navigator.mediaDevices)==null?void 0:r.getDisplayMedia)!="function")return null;let e=n?be():()=>{},t=null;try{if(t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0}),!t.getVideoTracks()[0])return null;await new Promise(a=>setTimeout(a,250));let i=await ge(t);return i?{blob:i,filename:"screenshot.png",contentType:"image/png"}:null}catch{return null}finally{t==null||t.getTracks().forEach(o=>o.stop()),e()}}async function ge(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=document.createElement("canvas");t.width=e.videoWidth||window.innerWidth,t.height=e.videoHeight||window.innerHeight;let r=t.getContext("2d");return r?(r.drawImage(e,0,0,t.width,t.height),e.pause(),e.srcObject=null,new Promise(o=>t.toBlob(i=>o(i),"image/png"))):null}function be(){let n=[...document.querySelectorAll(`[${W}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,r)=>{var o;t.style.filter=(o=e[r])!=null?o:""})}}function L(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:S(n/window.innerWidth),offsetY:S(e/window.innerHeight),elementText:null};let r=t.getBoundingClientRect();return{selector:ye(t),offsetX:r.width>0?S((n-r.left)/r.width):0,offsetY:r.height>0?S((e-r.top)/r.height):0,elementText:we(t)}}function te(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function ye(n){if(n===document.body)return"body";for(let o of["data-testid","data-test","data-daybook-id","data-cy"]){let i=n.getAttribute(o);if(i){let a=`[${o}="${P(i)}"]`;if(T(a))return a}}if(n.id&&!ee(n.id)){let o=`#${P(n.id)}`;if(T(o))return o}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let o=t.tagName.toLowerCase(),i=Array.from(t.classList).filter(c=>!ee(c)).slice(0,2);i.length>0&&(o+=i.map(c=>`.${P(c)}`).join(""));let a=t.parentElement;if(a){let c=Array.from(a.children).filter(d=>d.tagName===t.tagName);c.length>1&&(o+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(o);let s=e.join(" > ");if(T(s))return s;t=a}let r=e.length>0?`body > ${e.join(" > ")}`:null;return r&&T(r)?r:null}function T(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function ee(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function we(n){var r,o,i;let t=((o=(r=n.innerText)!=null?r:n.textContent)!=null?o:"").replace(/\s+/g," ").trim();if(!t){let a=(i=n.getAttribute("aria-label"))!=null?i:n.getAttribute("title");return(a==null?void 0:a.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function S(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function P(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var ve=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function ne(n,e){let t=[];for(let r of n){if(e+t.length>=5)break;let o=ve.test(r.type)?r.size>26214400?`Too large (${(r.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:r,filename:r.name||`pasted-${t.length+1}.${xe(r.type)}`,contentType:r.type,preview:o?null:URL.createObjectURL(r),error:o})}return t}function re(n){var r;let e=(r=n.clipboardData)==null?void 0:r.items;if(!e)return[];let t=[];for(let o of e){if(o.kind!=="file")continue;let i=o.getAsFile();i&&t.push(i)}return t}function R(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function xe(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function oe(n){var r;let t=(r=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?r:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}var _=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.state="ready";this.reference=null;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${Se}</style><style id="theme"></style><div id="layer"></div>`}setTheme(e){var a,s;let t=this.root.getElementById("theme");if(!t)return;if(!e){t.textContent="";return}let r=[];Te(e.accent)&&r.push(`--pm-accent: ${e.accent}`);let o={none:"0",sm:"6px",md:"12px",lg:"18px"}[(a=e.cornerRadius)!=null?a:"md"];o&&r.push(`--pm-radius: ${o}`);let i=Ee[(s=e.position)!=null?s:"bottom-right"];i&&r.push(i),t.textContent=r.length>0?`:host { ${r.join("; ")} }`:"",this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}setState(e){this.state=e,this.host.isConnected&&this.render()}mount(){var e;if(document.body.appendChild(this.host),this.render(),this.options.hotkey!==null){let t=((e=this.options.hotkey)!=null?e:"f").toLowerCase(),r=o=>{if(o.key==="Escape"){this.mode="idle",this.anchor=null,this.render();return}o.metaKey||o.ctrlKey||o.altKey||oe(o)||this.mode!=="composing"&&o.key.toLowerCase()===t&&(this.mode=this.mode==="picking"?"idle":"picking",this.render())};window.addEventListener("keydown",r),this.detach.push(()=>window.removeEventListener("keydown",r))}}unmount(){for(let e of this.detach.splice(0))e();this.host.remove()}open(){this.mode="picking",this.render()}setReporter(e){this.reporter=e}render(){let e=this.root.getElementById("layer");if(e.innerHTML="",this.mode==="idle"){e.appendChild(this.state==="pending"?this.pending():this.launcher());return}if(this.mode==="sent"){e.appendChild(this.sent());return}if(this.mode==="picking"){e.appendChild(this.picker());return}e.appendChild(this.composer())}pending(){let e=document.createElement("div");return e.className="launcher launcher--pending",e.setAttribute("role","status"),e.textContent="Feedback access pending approval",e}sent(){let e=document.createElement("div");e.className="panel panel--sent",e.setAttribute("role","status"),e.innerHTML=`
|
|
2
2
|
<div class="sent__tick" aria-hidden="true">✓</div>
|
|
3
3
|
<div>
|
|
4
4
|
<div class="panel__title">Thank you \u2014 that is on its way.</div>
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
<span class="panel__note">Sends the page, your browser, and recent errors.</span>
|
|
43
43
|
<button id="cancel" class="ghost">Cancel</button>
|
|
44
44
|
<button id="send" class="primary">Send</button>
|
|
45
|
-
</div>`;let r=[],o=e.querySelector("#files"),i=e.querySelector("#drop"),a=e.querySelector("#file"),s=()=>{o.innerHTML="",r.forEach((l,u)=>{var D;let f=document.createElement("div");f.className=l.error?"file file--bad":"file",f.innerHTML=l.preview?`<img src="${l.preview}" alt="" />`:'<span class="file__icon">\u25A6</span>';let A=document.createElement("span");A.className="file__name",A.textContent=(D=l.error)!=null?D:l.filename,f.appendChild(A);let v=document.createElement("button");v.className="link",v.textContent="\xD7",v.onclick=()=>{R([l]),r.splice(u,1),s()},f.appendChild(v),o.appendChild(f)}),i.style.display=r.length>=5?"none":""},c=l=>{r.push(...ne(l,r.length)),s()};a.onchange=()=>{a.files&&c(a.files)},e.querySelector("#browse").onclick=()=>a.click(),e.addEventListener("paste",l=>{let u=re(l);u.length>0&&(l.preventDefault(),c(u))}),i.addEventListener("dragover",l=>{l.preventDefault(),i.classList.add("drop--over")}),i.addEventListener("dragleave",()=>i.classList.remove("drop--over")),i.addEventListener("drop",l=>{var u,f;l.preventDefault(),i.classList.remove("drop--over"),c(Array.from((f=(u=l.dataTransfer)==null?void 0:u.files)!=null?f:[]))});let d="bug";e.querySelectorAll(".kind").forEach(l=>{l.onclick=()=>{var u;d=(u=l.dataset.kind)!=null?u:"bug",e.querySelectorAll(".kind").forEach(f=>f.classList.remove("kind--on")),l.classList.add("kind--on")}});let p=e.querySelector("#message"),b=e.querySelector("#email"),y=(N=(B=this.reporter)==null?void 0:B.email)!=null?N:(K=this.options.reporter)==null?void 0:K.email;y&&!b.value&&(b.value=y);let w=e.querySelector("#shot"),m=e.querySelector("#status"),h=e.querySelector("#send"),
|
|
45
|
+
</div>`;let r=[],o=e.querySelector("#files"),i=e.querySelector("#drop"),a=e.querySelector("#file"),s=()=>{o.innerHTML="",r.forEach((l,u)=>{var D;let f=document.createElement("div");f.className=l.error?"file file--bad":"file",f.innerHTML=l.preview?`<img src="${l.preview}" alt="" />`:'<span class="file__icon">\u25A6</span>';let A=document.createElement("span");A.className="file__name",A.textContent=(D=l.error)!=null?D:l.filename,f.appendChild(A);let v=document.createElement("button");v.className="link",v.textContent="\xD7",v.onclick=()=>{R([l]),r.splice(u,1),s()},f.appendChild(v),o.appendChild(f)}),i.style.display=r.length>=5?"none":""},c=l=>{r.push(...ne(l,r.length)),s()};a.onchange=()=>{a.files&&c(a.files)},e.querySelector("#browse").onclick=()=>a.click(),e.addEventListener("paste",l=>{let u=re(l);u.length>0&&(l.preventDefault(),c(u))}),i.addEventListener("dragover",l=>{l.preventDefault(),i.classList.add("drop--over")}),i.addEventListener("dragleave",()=>i.classList.remove("drop--over")),i.addEventListener("drop",l=>{var u,f;l.preventDefault(),i.classList.remove("drop--over"),c(Array.from((f=(u=l.dataTransfer)==null?void 0:u.files)!=null?f:[]))});let d="bug";e.querySelectorAll(".kind").forEach(l=>{l.onclick=()=>{var u;d=(u=l.dataset.kind)!=null?u:"bug",e.querySelectorAll(".kind").forEach(f=>f.classList.remove("kind--on")),l.classList.add("kind--on")}});let p=e.querySelector("#message"),b=e.querySelector("#email"),y=(N=(B=this.reporter)==null?void 0:B.email)!=null?N:(K=this.options.reporter)==null?void 0:K.email;y&&!b.value&&(b.value=y);let w=e.querySelector("#shot"),m=e.querySelector("#status"),h=e.querySelector("#send"),O=()=>{R(r),this.mode="idle",this.anchor=null,this.render()};e.querySelector("#cancel").onclick=O,e.querySelector("#close").onclick=O;let q=async()=>{if(!p.value.trim()){m.textContent="Say what happened first.";return}h.disabled=!0,m.textContent="Sending\u2026";try{this.reference=await this.onSubmit({message:p.value.trim(),kind:d,email:b.value.trim()||void 0,anchor:this.anchor,withScreenshot:w.checked,files:r.filter(l=>!l.error)})||null,R(r),this.mode="sent",this.anchor=null,this.render()}catch(l){h.disabled=!1,m.textContent=l instanceof Error?`${l.message} \u2014 saved, will retry.`:"Failed, saved and will retry."}};return h.onclick=q,p.onkeydown=l=>{(l.metaKey||l.ctrlKey)&&l.key==="Enter"&&q()},setTimeout(()=>p.focus(),0),e}};function ie(n){return n.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}var Ee={"bottom-right":"--pm-left: auto; --pm-right: 16px; --pm-top: auto; --pm-bottom: 16px","bottom-left":"--pm-left: 16px; --pm-right: auto; --pm-top: auto; --pm-bottom: 16px","top-right":"--pm-left: auto; --pm-right: 16px; --pm-top: 16px; --pm-bottom: auto","top-left":"--pm-left: 16px; --pm-right: auto; --pm-top: 16px; --pm-bottom: auto"};function Te(n){return typeof n=="string"&&/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%/]+\)|hsla?\([\d\s.,%/deg]+\)|[a-z]{3,20})$/i.test(n.trim())}var Se=`
|
|
46
46
|
:host {
|
|
47
47
|
all: initial;
|
|
48
48
|
|
|
@@ -159,4 +159,4 @@ textarea:focus, input:focus { outline: 2px solid #171717; outline-offset: -1px }
|
|
|
159
159
|
.file__icon { width: 28px; text-align: center }
|
|
160
160
|
.file__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
|
|
161
161
|
.link { border: 0; background: transparent; color: #525252; cursor: pointer; font-size: 11px; text-decoration: underline }
|
|
162
|
-
`;var
|
|
162
|
+
`;var se="https://api.daybook.team",$=class{constructor(e){this.options=e;this.widget=null;this.started=!1;this.inFlight=null;this.epoch=0;this.ready=null;var t;if(!e.ingestKey)throw new Error("ingestKey is required");this.client=new E((t=e.apiUrl)!=null?t:se,e.ingestKey),this.trail=e.breadcrumbs===!1?null:new x(40,e.redact!==!1)}start(){var e;return(e=this.trail)==null||e.start(),this.mount(),this.started||(this.started=!0,this.client.flush()),this.handshake(),this}mount(){this.widget||(this.widget=new _(this.options,e=>this.submit(e)),this.widget.setReporter(this.options.reporter),this.widget.mount())}handshake(){var r,o,i;let e=JSON.stringify([(r=this.options.reporter)!=null?r:null,(o=this.options.signature)!=null?o:null,this.epoch]);if(((i=this.inFlight)==null?void 0:i.key)===e)return this.inFlight.promise;let t=this.runHandshake().finally(()=>{var a;((a=this.inFlight)==null?void 0:a.promise)===t&&(this.inFlight=null)});return this.inFlight={key:e,promise:t},t}async runHandshake(){var e,t,r,o,i,a;try{let s=await this.client.handshake({identity:this.options.reporter,signature:this.options.signature,locale:typeof navigator!="undefined"?navigator.language:void 0});if(this.ready=s,(t=(e=this.options).onReady)==null||t.call(e,s),s.reporterStatus==="Blocked"){(r=this.widget)==null||r.unmount(),this.widget=null;return}this.mount(),this.widget.setTheme(Re(s.theme)),this.widget.setState(s.reporterStatus==="Pending"?"pending":"ready")}catch(s){(i=(o=this.options).onError)==null||i.call(o,s),console.warn("[feedback] handshake failed; the widget will not appear",s),(a=this.widget)==null||a.unmount(),this.widget=null}}identify(e){var t;this.options={...this.options,reporter:e?{...this.options.reporter,...e}:void 0},(t=this.widget)==null||t.setReporter(this.options.reporter),this.widget&&this.handshake()}async signIn(){await this.client.signIn(),this.epoch++,await this.handshake()}authenticate(e){this.options={...this.options,signature:e!=null?e:void 0},this.widget&&this.handshake()}stop(){var e,t;this.started=!1,(e=this.trail)==null||e.stop(),(t=this.widget)==null||t.unmount(),this.widget=null}open(){var e;(e=this.widget)==null||e.open()}async report(e,t={}){var r,o,i;return this.client.send({message:e,surface:this.options.surface,...t,context:{...U({breadcrumbs:(r=this.trail)==null?void 0:r.list(),app:this.options.app}),...(o=t.context)!=null?o:{}},reporter:(i=t.reporter)!=null?i:this.options.reporter})}async submit(e){var i,a,s,c,d;let t=e.withScreenshot&&this.options.screenshots!==!1?await G(this.options.redact!==!1):null,r=[...e.files,...t?[t]:[]],o={message:e.message,kind:e.kind,app:this.options.app,surface:this.options.surface,reporter:e.email?{...this.options.reporter,email:e.email}:this.options.reporter,context:U({anchor:e.anchor,breadcrumbs:(i=this.trail)==null?void 0:i.list(),app:this.options.app})};try{let p=await this.client.send(o,r);return(s=(a=this.options).onSent)==null||s.call(a,p),p.reference}catch(p){throw this.client.queue(o),(d=(c=this.options).onError)==null||d.call(c,p),p}}};function Le(n){return new $(n).start()}function Re(n){if(!n)return null;try{let e=JSON.parse(n);return e&&typeof e=="object"?e:null}catch{return null}}return he(_e);})();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { IngestRequest, IngestResponse, FeedbackOptions } from './types.js';
|
|
2
2
|
export type { Anchor, Breadcrumb, FeedbackKind, FeedbackTheme, HandshakeRequest, HandshakeResponse, IngestRequest, IngestResponse, FeedbackOptions, ReporterStatus, } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Where reports go unless the host says otherwise.
|
|
5
|
+
*
|
|
6
|
+
* Feedback is a hosted service, so the address is ours to keep working, not a setting every
|
|
7
|
+
* customer has to be told and then keep in step with us. Asking for it was also asking them to
|
|
8
|
+
* paste a hostname they have no way to check — and one wrong character means reports that vanish.
|
|
9
|
+
*
|
|
10
|
+
* This is as permanent as the wire contract: it ships inside published bundles and inside mobile
|
|
11
|
+
* builds that may never be updated. Moving the service means keeping this name resolving, forever,
|
|
12
|
+
* not editing this line.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_API_URL = "https://api.daybook.team";
|
|
3
15
|
export { captureAnchor, resolveAnchor } from './anchor.js';
|
|
4
16
|
/**
|
|
5
17
|
* In-app feedback for the web.
|
|
@@ -7,7 +19,6 @@ export { captureAnchor, resolveAnchor } from './anchor.js';
|
|
|
7
19
|
* import { init } from '@daybook/feedback'
|
|
8
20
|
*
|
|
9
21
|
* init({
|
|
10
|
-
* apiUrl: 'https://pm-api.hreben.us',
|
|
11
22
|
* ingestKey: 'pmi_…',
|
|
12
23
|
* app: { version: '1.4.0', environment: 'production' },
|
|
13
24
|
* })
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,18 @@ import { IngestClient } from './client.js';
|
|
|
3
3
|
import { captureContext } from './context.js';
|
|
4
4
|
import { captureScreenshot } from './screenshot.js';
|
|
5
5
|
import { FeedbackWidget } from './widget.js';
|
|
6
|
+
/**
|
|
7
|
+
* Where reports go unless the host says otherwise.
|
|
8
|
+
*
|
|
9
|
+
* Feedback is a hosted service, so the address is ours to keep working, not a setting every
|
|
10
|
+
* customer has to be told and then keep in step with us. Asking for it was also asking them to
|
|
11
|
+
* paste a hostname they have no way to check — and one wrong character means reports that vanish.
|
|
12
|
+
*
|
|
13
|
+
* This is as permanent as the wire contract: it ships inside published bundles and inside mobile
|
|
14
|
+
* builds that may never be updated. Moving the service means keeping this name resolving, forever,
|
|
15
|
+
* not editing this line.
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_API_URL = 'https://api.daybook.team';
|
|
6
18
|
export { captureAnchor, resolveAnchor } from './anchor.js';
|
|
7
19
|
/**
|
|
8
20
|
* In-app feedback for the web.
|
|
@@ -10,7 +22,6 @@ export { captureAnchor, resolveAnchor } from './anchor.js';
|
|
|
10
22
|
* import { init } from '@daybook/feedback'
|
|
11
23
|
*
|
|
12
24
|
* init({
|
|
13
|
-
* apiUrl: 'https://pm-api.hreben.us',
|
|
14
25
|
* ingestKey: 'pmi_…',
|
|
15
26
|
* app: { version: '1.4.0', environment: 'production' },
|
|
16
27
|
* })
|
|
@@ -49,11 +60,9 @@ export class DaybookFeedback {
|
|
|
49
60
|
this.epoch = 0;
|
|
50
61
|
/** The last handshake, for a host app that wants to explain a state in its own words. */
|
|
51
62
|
this.ready = null;
|
|
52
|
-
if (!options.apiUrl)
|
|
53
|
-
throw new Error('apiUrl is required');
|
|
54
63
|
if (!options.ingestKey)
|
|
55
64
|
throw new Error('ingestKey is required');
|
|
56
|
-
this.client = new IngestClient(options.apiUrl, options.ingestKey);
|
|
65
|
+
this.client = new IngestClient(options.apiUrl ?? DEFAULT_API_URL, options.ingestKey);
|
|
57
66
|
this.trail = options.breadcrumbs === false
|
|
58
67
|
? null
|
|
59
68
|
: new BreadcrumbTrail(40, options.redact !== false);
|
package/dist/types.d.ts
CHANGED
|
@@ -98,8 +98,15 @@ export interface FeedbackTheme {
|
|
|
98
98
|
colorScheme?: 'auto' | 'light' | 'dark';
|
|
99
99
|
}
|
|
100
100
|
export interface FeedbackOptions {
|
|
101
|
-
/**
|
|
102
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Where reports are sent. Defaults to Daybook's own API, which is almost always what you want:
|
|
103
|
+
* this is a hosted service, and which machine receives a report is ours to change, not something
|
|
104
|
+
* every customer should have pinned in their bundle.
|
|
105
|
+
*
|
|
106
|
+
* Set it only to point at something that is not Daybook — a self-hosted install, or our own app
|
|
107
|
+
* in development reporting to a local API.
|
|
108
|
+
*/
|
|
109
|
+
apiUrl?: string;
|
|
103
110
|
/** The ingest key. Public by design; it grants only filing feedback. */
|
|
104
111
|
ingestKey: string;
|
|
105
112
|
/**
|
package/package.json
CHANGED