@feedbackrelay/web 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.md +21 -21
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -6,7 +6,7 @@ Read the host instructions and [README.md](README.md). Keep the host's UI/framew
|
|
|
6
6
|
|
|
7
7
|
Use Node.js 26/npm for this checkout's build and packaging commands; Node is a development tool, not a device/browser requirement.
|
|
8
8
|
|
|
9
|
-
Install @feedbackrelay/web@0.1.
|
|
9
|
+
Install @feedbackrelay/web@0.1.1 from npm. Contributors can use the local archive steps in README.md to test source changes. `createRelayClient` requires appId/teamId/relayId/publishableKey; optional settings include baseUrl, app release, context, screenshot restriction, private selectors, local uploadLimits and replay. `send(input, options?)` returns a receipt Promise. Imports stay SSR-safe; sends need a browser. Core source/API floors are Chrome/Edge 93+, Firefox 92+ and Safari/iOS Safari 15.4+ (Object.hasOwn); do not claim old-browser certification or add polyfills. Plain HTML needs no JavaScript SDK.
|
|
10
10
|
|
|
11
11
|
Browser FormData/File/Blob uploads real files. Empty files count; never remove caller parts silently. Snapshot without mutating the form. Native HTML uses hidden _relay_key; enhanced forms remove reserved fields before SDK send. No script is required for plain HTML, which returns JSON and adds no SDK diagnostics/capture.
|
|
12
12
|
|
package/README.md
CHANGED
|
@@ -17,28 +17,9 @@ Use Node.js 26/npm for this checkout's build tools. Core API floors are Chrome/E
|
|
|
17
17
|
From your app folder, install the SDK:
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
npm install @feedbackrelay/web@0.1.
|
|
20
|
+
npm install @feedbackrelay/web@0.1.1
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
### Local archive for contributors
|
|
24
|
-
|
|
25
|
-
To test SDK source changes before publishing another version, build a local archive from this repository:
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
cd "/path/to/relay-sdk/sdk/web"
|
|
29
|
-
npm ci
|
|
30
|
-
npm pack
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
This creates `feedbackrelay-web-0.1.0.tgz`. Install it in your app:
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
cd "/path/to/your-web-app"
|
|
37
|
-
npm install "/path/to/relay-sdk/sdk/web/feedbackrelay-web-0.1.0.tgz"
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Replace paths with your actual folders. Repack and reinstall after SDK changes, even if the version is unchanged. `npm pack` does not publish to a registry.
|
|
41
|
-
|
|
42
23
|
## 2. Create a client and send
|
|
43
24
|
|
|
44
25
|
```ts
|
|
@@ -317,7 +298,26 @@ Publishable keys identify submission scope, not app authenticity. The service mu
|
|
|
317
298
|
|
|
318
299
|
After a receipt, cancelling the completed send does not stop its separate media job. Destroy that client to cancel its media, or clear the recorder to discard all retained history and media.
|
|
319
300
|
|
|
320
|
-
##
|
|
301
|
+
## Contributor development
|
|
302
|
+
|
|
303
|
+
The npm installation above is all an app needs. To test SDK source changes locally, build an archive from a repository checkout:
|
|
304
|
+
|
|
305
|
+
```sh
|
|
306
|
+
cd "/path/to/relay-sdk/sdk/web"
|
|
307
|
+
npm ci
|
|
308
|
+
npm pack
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Install the generated archive in a separate app:
|
|
312
|
+
|
|
313
|
+
```sh
|
|
314
|
+
cd "/path/to/your-web-app"
|
|
315
|
+
npm install "/path/to/relay-sdk/sdk/web/feedbackrelay-web-0.1.1.tgz"
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Replace the paths with your folders. Repack and reinstall after source changes. `npm pack` does not publish anything.
|
|
319
|
+
|
|
320
|
+
### Checks
|
|
321
321
|
|
|
322
322
|
From this SDK folder:
|
|
323
323
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Y,c as F,d as Z,e as k,f as ee,i as te}from"./chunk-XFS2L2L2.js";var z=64*1024,K=1e4,J=class extends TypeError{},ne=()=>new TypeError("Relay data must contain only finite JSON values without cycles or accessors."),W=()=>new J("Relay data exceeds 64 KiB or its depth/node limit.");function q(e){let n=Object.getPrototypeOf(e);if(n===null||n===Object.prototype)return!0;let o=Object.getOwnPropertyDescriptor(n,"constructor")?.value;return Object.getPrototypeOf(n)===null&&typeof o=="function"&&Function.prototype.toString.call(o)===Function.prototype.toString.call(Object)}function oe(e){let n=new Set,o=0,t=0,f;function a(r=!1){throw f=r?W():ne(),f}let l=r=>{o+=r,o>z&&a(!0)},y=r=>(r.length>z&&a(!0),F(JSON.stringify(r))),i=(r,p)=>{if((++t>K||p>32)&&a(!0),r===null||typeof r=="boolean")return l(r===null||r?4:5),r;if(typeof r=="string")return l(y(r)),r;if(typeof r=="number"&&Number.isFinite(r))return l(JSON.stringify(r).length),r;(!r||typeof r!="object"||n.has(r))&&a();let m=Array.isArray(r);!m&&!q(r)&&a(),n.add(r);try{let h=m?Object.getOwnPropertyDescriptor(r,"length").value:0;m&&h>K-t&&a(!0);let u=Reflect.ownKeys(r);if(u.length>K+1&&a(!0),l(2),m){u.length!==h+1&&a();for(let d of u)d!=="length"&&(typeof d!="string"||!/^(0|[1-9]\d*)$/.test(d)||Number(d)>=h)&&a();let s=[];for(let d=0;d<h;d++){let R=Object.getOwnPropertyDescriptor(r,String(d));(!R||!("value"in R))&&a(),d&&l(1),s.push(i(R.value,p+1))}return s}let O=Object.create(null),c=0;for(let s of u){typeof s!="string"&&a();let d=Object.getOwnPropertyDescriptor(r,s);(!d||!("value"in d))&&a(),d.enumerable&&(l(y(s)+1+(c++?1:0)),O[s]=i(d.value,p+1))}return O}finally{n.delete(r)}};try{return i(e,0)}catch{throw f??ne()}}function fe(e){if(!(typeof FormData>"u"))try{return FormData.prototype.entries.call(e)}catch{return}}function ie(e){if(!(typeof Blob>"u"))try{let n=Object.getOwnPropertyDescriptor(Blob.prototype,"size").get.call(e),o=Object.getOwnPropertyDescriptor(Blob.prototype,"type").get.call(e),t="blob";if(typeof File<"u")try{t=Object.getOwnPropertyDescriptor(File.prototype,"name").get.call(e)}catch{}return{blob:e,size:n,type:o,name:t}}catch{return}}function re(e){let n=new FormData,o=[],t=0,f=0;for(let[a,l]of e){if(++t>1e3)throw new TypeError("Relay forms support at most 1,000 fields.");if(a.length>128||F(a)>128||/[\r\n\0]/.test(a)||a.startsWith("_relay_"))throw new TypeError("Relay field names must fit 128 UTF-8 bytes and cannot contain CR, LF, NUL or the reserved _relay_ prefix.");let y=typeof l=="string"?l:"";if(y.length>z||(f+=F(a)+F(y),f>z))throw W();if(typeof l=="string")n.append(a,l);else{let i=ie(l);if(!i)throw new TypeError("Relay form files must be File or Blob values.");if(i.name.length>255||F(i.name)>255||/[\r\n\0]/.test(i.name)||i.type.length>127||F(i.type)>127)throw new TypeError("Relay filenames must fit 255 UTF-8 bytes without CR, LF or NUL; MIME types must fit 127 bytes.");o.push(i.size),n.append(a,i.blob,i.name)}}return{data:n,fileSizes:o}}function ae(e){try{return{kind:"data",data:oe(e)}}catch(t){if(t instanceof J)throw t}let n=fe(e);if(n)return{kind:"data",...re(n)};let o=ie(e);return o?{kind:"data",...re([["file",o.blob]])}:{kind:"diagnostic",data:Z(e)}}function U(e){if(!e||typeof e!="object"||Array.isArray(e))throw new TypeError("Relay context must be a plain JSON object.");return oe(e)}function T(e){try{return e()}catch{return}}function S(e,n,o){o!==void 0&&(e[n]=o)}function x(e,n=!1,o=!1){let t=T(e);return typeof t=="number"&&Number.isFinite(t)&&t<=Number.MAX_SAFE_INTEGER&&(n?t>=0:t>0)&&(!o||Number.isSafeInteger(t))?t:void 0}function $(e){let n=T(e);return typeof n=="boolean"?n:void 0}function B(e,n){return n.find(o=>T(()=>window.matchMedia(`(${e}: ${o})`).matches)===!0)}function se(){let e=x(()=>window.innerWidth,!0,!0),n=x(()=>window.innerHeight,!0,!0),o=x(()=>window.devicePixelRatio),t={};e!==void 0&&n!==void 0&&o!==void 0&&(t.viewport={width:e,height:n,scale:o,orientation:e>n?"landscape":"portrait"});let f=T(()=>navigator.userAgent),a=T(()=>navigator.language);typeof f=="string"&&f&&(t.userAgent=f),typeof a=="string"&&a&&(t.language=a),S(t,"online",$(()=>navigator.onLine)),S(t,"hardwareConcurrency",x(()=>navigator.hardwareConcurrency,!1,!0)),S(t,"deviceMemoryGiB",x(()=>navigator.deviceMemory)),S(t,"maxTouchPoints",x(()=>navigator.maxTouchPoints,!0,!0));let l=T(()=>window.screen);if(l)for(let[u,O]of[["width","screenWidth"],["height","screenHeight"],["availWidth","screenAvailableWidth"],["availHeight","screenAvailableHeight"],["colorDepth","colorDepth"]])S(t,O,x(()=>l[u],!1,!0));S(t,"appearance",B("prefers-color-scheme",["light","dark"])),S(t,"contrast",B("prefers-contrast",["more","less","custom","no-preference"])),S(t,"pointer",B("pointer",["fine","coarse","none"]));let y=B("prefers-reduced-motion",["reduce","no-preference"]),i=B("forced-colors",["active","none"]),r=B("hover",["hover","none"]);y!==void 0&&(t.reducedMotion=y==="reduce"),i!==void 0&&(t.forcedColors=i==="active"),r!==void 0&&(t.hover=r==="hover");let p=T(()=>document.documentElement.dir);(p==="ltr"||p==="rtl")&&(t.layoutDirection=p);let m=T(()=>window.visualViewport);if(m){let u=x(()=>m.width),O=x(()=>m.height),c=x(()=>m.scale);if(u!==void 0&&O!==void 0&&c!==void 0){let s={width:u,height:O,scale:c};for(let d of["offsetLeft","offsetTop"]){let R=T(()=>m[d]);typeof R=="number"&&Number.isFinite(R)&&Math.abs(R)<=Number.MAX_SAFE_INTEGER&&(s[d]=R)}t.visualViewport=s}}S(t,"secureContext",$(()=>window.isSecureContext)),S(t,"crossOriginIsolated",$(()=>window.crossOriginIsolated));let h=T(()=>navigator.connection);if(h){let u=T(()=>h.effectiveType);(u==="slow-2g"||u==="2g"||u==="3g"||u==="4g")&&(t.networkEffectiveType=u),S(t,"networkRttMs",x(()=>h.rtt,!0)),S(t,"networkDownlinkMbps",x(()=>h.downlink,!0)),S(t,"networkSaveData",$(()=>h.saveData))}return t}function ue(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let n=Array.from(e,o=>o.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function ye(e,n){let{screenshot:o,...t}=e,f={...t,...o?{screenshot:ee(o,e.submissionId)}:{}},a=JSON.stringify(f);if(F(a)>128*1024)throw new TypeError("Relay submission exceeds 128 KiB. Reduce data or context.");let l=n?Array.from(n,([y,i])=>typeof i=="string"?{name:y,value:i}:{name:y,file:{name:i.name,mimeType:i.type,byteSize:i.size}}):void 0;return`{"submission":${a}${l?`,"formData":${JSON.stringify(l)}`:""}}`}function xe(e){if(!e||typeof e.appId!="string"||!e.appId.trim())throw new TypeError("Relay requires a nonempty appId.");for(let c of["appVersion","appBuild"])if(e[c]!==void 0&&typeof e[c]!="string")throw new TypeError(`${c} must be a string.`);if(e.screenshot!==void 0&&typeof e.screenshot!="boolean")throw new TypeError("screenshot must be boolean.");let n={id:e.appId,...e.appVersion!==void 0?{version:e.appVersion}:{},...e.appBuild!==void 0?{build:e.appBuild}:{}},o=te(e),t=e.screenshot!==!1,f=e.uploadLimits===void 0?{maxFiles:10,maxFileBytes:3*1024*1024,maxTotalFileBytes:3*1024*1024}:e.uploadLimits;if(!f||![f.maxFiles,f.maxFileBytes,f.maxTotalFileBytes].every(c=>typeof c=="number"&&Number.isSafeInteger(c)&&c>=0))throw new TypeError("uploadLimits requires three nonnegative safe integer limits.");let a={maxFiles:f.maxFiles,maxFileBytes:f.maxFileBytes,maxTotalFileBytes:f.maxTotalFileBytes};if(e.privateSelectors!==void 0&&!Array.isArray(e.privateSelectors))throw new TypeError("privateSelectors must be an array of CSS selectors.");let l=[...e.privateSelectors??[]];if(!l.every(c=>typeof c=="string"&&c.trim()))throw new TypeError("privateSelectors must contain CSS selectors.");let y=U(e.context===void 0?{}:e.context),i=e.replay;if(i!==void 0&&(!i||typeof i.attach!="function"||typeof i.clear!="function"||typeof i.destroy!="function"))throw new TypeError("replay must be a replay recorder.");let r;try{r=i?.attach({...o.scope,appId:n.id,privateSelectors:l,enabled:t})}catch{}let p=!1,m=new Set,h=Promise.resolve();async function u(c){let s=h,d,R=new Promise(C=>{d=C});h=s.then(()=>R);let b=c.capture.signal,D=performance.now()+5e3,v,w=new Promise(C=>{v=()=>C(void 0)});b.addEventListener("abort",v,{once:!0});let N=setTimeout(()=>c.capture.abort(),5e3);try{return b.aborted||performance.now()>=D||(await Promise.race([s,w]),b.aborted||performance.now()>=D)?void 0:await Promise.race([Y({signal:b,privateSelectors:l}).catch(()=>{}),w])}finally{clearTimeout(N),b.removeEventListener("abort",v),d()}}async function O(c,s={}){let d=y,R=new Date().toISOString(),b=ue(),D="invalid-options",v,w,N,C;try{if(arguments.length>2)throw new TypeError("send accepts data and optional send options only.");if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("Send options must be an object.");if(!q(s)||Reflect.ownKeys(s).some(g=>!["submissionId","signal","context","screenshot","onCollected"].includes(g)))throw new TypeError("Send options must be a plain object containing only submissionId, signal, context, screenshot or onCollected.");let E=s.submissionId;if(E!==void 0){if(typeof E!="string"||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(E))throw new TypeError("submissionId must be a UUID.");b=E}if(p)throw new k("destroyed",b,"Relay client has been destroyed.");if(typeof window>"u"||typeof document>"u")throw new TypeError("Relay sends require a browser.");let M=s.screenshot;if(M!==void 0&&typeof M!="boolean")throw new TypeError("screenshot must be boolean.");let L=s.onCollected;if(L!==void 0&&typeof L!="function")throw new TypeError("onCollected must be a function.");let H=t&&M!==!1;if(w=s.signal,w!==void 0&&(!w||typeof w.aborted!="boolean"||typeof w.addEventListener!="function"||typeof w.removeEventListener!="function"))throw new TypeError("signal must be an AbortSignal.");if(m.size>=4)throw new k("busy",b,"Four Relay sends are already active. Try again after one finishes.");v={controller:new AbortController,capture:new AbortController},m.add(v);let j=v;N=()=>{j.capture.abort(),j.controller.abort()},w?.aborted?N():w?.addEventListener("abort",N,{once:!0});let A=()=>{if(j.controller.signal.aborted||p)throw new k("cancelled",b,"Relay send cancelled. It may already have been accepted; retry with the same submissionId.")};A(),D="invalid-data";let G=s.context,ce=U(G===void 0?d:G),le=se(),I=ae(c),V=I.data,X=V instanceof FormData?V:void 0,P={schemaVersion:2,submissionId:b,invokedAt:R,kind:I.kind,...V instanceof FormData?{}:{data:V},app:{...n},sdk:{name:"@feedbackrelay/web",version:"0.1.0",platform:"web"},device:le,context:ce};if(F(JSON.stringify(P))>128*1024)throw new TypeError("Relay submission exceeds 128 KiB. Reduce data or context.");if(A(),I.fileSizes?.length){let g=a;if(!g.maxFiles||!g.maxFileBytes||!g.maxTotalFileBytes||I.fileSizes.length>g.maxFiles||I.fileSizes.some(_=>_>g.maxFileBytes)||I.fileSizes.reduce((_,de)=>_+de,0)>g.maxTotalFileBytes)throw new k("invalid-data",b,"Files exceed this relay's upload limits. Use fewer or smaller files.")}try{C=r?.freeze(b,E!==void 0,H)}catch{}if(!i&&H&&document.body){let g=await u(j);A(),g&&(P.screenshot=g)}if(A(),L){let g=ye(P,X);try{Promise.resolve(L(g,P.screenshot?.blob)).catch(()=>{})}catch{}A()}D="delivery";let Q=await o.submit(P,j.controller.signal,X);A();try{C?.accepted(Q)}catch{}return Q}catch(E){if(v?.controller.signal.aborted||p&&v){try{C?.cancel()}catch{}throw new k("cancelled",b,"Relay send cancelled. It may already have been accepted; retry with the same submissionId.")}throw E instanceof k?E:new k(D,b,D==="invalid-data"||D==="invalid-options"?E instanceof TypeError?E.message:"Invalid Relay submission.":"Could not send to Relay. Retry with the same submissionId.")}finally{try{w&&N&&w.removeEventListener("abort",N)}catch{}v&&(v.capture.abort(),m.delete(v))}}return{send(...c){let s=O(...c);return s.catch(()=>{}),s},setContext(c){if(p)throw new Error("Relay client has been destroyed.");let s=U(c);if(p)throw new Error("Relay client has been destroyed.");y=s},clearContext(){if(p)throw new Error("Relay client has been destroyed.");y={}},destroy(){if(!p){p=!0;for(let c of m)c.capture.abort(),c.controller.abort();y={};try{r?.detach()}catch{}}}}}export{k as RelaySendError,xe as createRelayClient};
|
|
1
|
+
import{a as Y,c as F,d as Z,e as k,f as ee,i as te}from"./chunk-XFS2L2L2.js";var z=64*1024,K=1e4,J=class extends TypeError{},ne=()=>new TypeError("Relay data must contain only finite JSON values without cycles or accessors."),W=()=>new J("Relay data exceeds 64 KiB or its depth/node limit.");function q(e){let n=Object.getPrototypeOf(e);if(n===null||n===Object.prototype)return!0;let o=Object.getOwnPropertyDescriptor(n,"constructor")?.value;return Object.getPrototypeOf(n)===null&&typeof o=="function"&&Function.prototype.toString.call(o)===Function.prototype.toString.call(Object)}function oe(e){let n=new Set,o=0,t=0,f;function a(r=!1){throw f=r?W():ne(),f}let l=r=>{o+=r,o>z&&a(!0)},y=r=>(r.length>z&&a(!0),F(JSON.stringify(r))),i=(r,p)=>{if((++t>K||p>32)&&a(!0),r===null||typeof r=="boolean")return l(r===null||r?4:5),r;if(typeof r=="string")return l(y(r)),r;if(typeof r=="number"&&Number.isFinite(r))return l(JSON.stringify(r).length),r;(!r||typeof r!="object"||n.has(r))&&a();let m=Array.isArray(r);!m&&!q(r)&&a(),n.add(r);try{let h=m?Object.getOwnPropertyDescriptor(r,"length").value:0;m&&h>K-t&&a(!0);let u=Reflect.ownKeys(r);if(u.length>K+1&&a(!0),l(2),m){u.length!==h+1&&a();for(let d of u)d!=="length"&&(typeof d!="string"||!/^(0|[1-9]\d*)$/.test(d)||Number(d)>=h)&&a();let s=[];for(let d=0;d<h;d++){let R=Object.getOwnPropertyDescriptor(r,String(d));(!R||!("value"in R))&&a(),d&&l(1),s.push(i(R.value,p+1))}return s}let O=Object.create(null),c=0;for(let s of u){typeof s!="string"&&a();let d=Object.getOwnPropertyDescriptor(r,s);(!d||!("value"in d))&&a(),d.enumerable&&(l(y(s)+1+(c++?1:0)),O[s]=i(d.value,p+1))}return O}finally{n.delete(r)}};try{return i(e,0)}catch{throw f??ne()}}function fe(e){if(!(typeof FormData>"u"))try{return FormData.prototype.entries.call(e)}catch{return}}function ie(e){if(!(typeof Blob>"u"))try{let n=Object.getOwnPropertyDescriptor(Blob.prototype,"size").get.call(e),o=Object.getOwnPropertyDescriptor(Blob.prototype,"type").get.call(e),t="blob";if(typeof File<"u")try{t=Object.getOwnPropertyDescriptor(File.prototype,"name").get.call(e)}catch{}return{blob:e,size:n,type:o,name:t}}catch{return}}function re(e){let n=new FormData,o=[],t=0,f=0;for(let[a,l]of e){if(++t>1e3)throw new TypeError("Relay forms support at most 1,000 fields.");if(a.length>128||F(a)>128||/[\r\n\0]/.test(a)||a.startsWith("_relay_"))throw new TypeError("Relay field names must fit 128 UTF-8 bytes and cannot contain CR, LF, NUL or the reserved _relay_ prefix.");let y=typeof l=="string"?l:"";if(y.length>z||(f+=F(a)+F(y),f>z))throw W();if(typeof l=="string")n.append(a,l);else{let i=ie(l);if(!i)throw new TypeError("Relay form files must be File or Blob values.");if(i.name.length>255||F(i.name)>255||/[\r\n\0]/.test(i.name)||i.type.length>127||F(i.type)>127)throw new TypeError("Relay filenames must fit 255 UTF-8 bytes without CR, LF or NUL; MIME types must fit 127 bytes.");o.push(i.size),n.append(a,i.blob,i.name)}}return{data:n,fileSizes:o}}function ae(e){try{return{kind:"data",data:oe(e)}}catch(t){if(t instanceof J)throw t}let n=fe(e);if(n)return{kind:"data",...re(n)};let o=ie(e);return o?{kind:"data",...re([["file",o.blob]])}:{kind:"diagnostic",data:Z(e)}}function U(e){if(!e||typeof e!="object"||Array.isArray(e))throw new TypeError("Relay context must be a plain JSON object.");return oe(e)}function T(e){try{return e()}catch{return}}function S(e,n,o){o!==void 0&&(e[n]=o)}function x(e,n=!1,o=!1){let t=T(e);return typeof t=="number"&&Number.isFinite(t)&&t<=Number.MAX_SAFE_INTEGER&&(n?t>=0:t>0)&&(!o||Number.isSafeInteger(t))?t:void 0}function $(e){let n=T(e);return typeof n=="boolean"?n:void 0}function B(e,n){return n.find(o=>T(()=>window.matchMedia(`(${e}: ${o})`).matches)===!0)}function se(){let e=x(()=>window.innerWidth,!0,!0),n=x(()=>window.innerHeight,!0,!0),o=x(()=>window.devicePixelRatio),t={};e!==void 0&&n!==void 0&&o!==void 0&&(t.viewport={width:e,height:n,scale:o,orientation:e>n?"landscape":"portrait"});let f=T(()=>navigator.userAgent),a=T(()=>navigator.language);typeof f=="string"&&f&&(t.userAgent=f),typeof a=="string"&&a&&(t.language=a),S(t,"online",$(()=>navigator.onLine)),S(t,"hardwareConcurrency",x(()=>navigator.hardwareConcurrency,!1,!0)),S(t,"deviceMemoryGiB",x(()=>navigator.deviceMemory)),S(t,"maxTouchPoints",x(()=>navigator.maxTouchPoints,!0,!0));let l=T(()=>window.screen);if(l)for(let[u,O]of[["width","screenWidth"],["height","screenHeight"],["availWidth","screenAvailableWidth"],["availHeight","screenAvailableHeight"],["colorDepth","colorDepth"]])S(t,O,x(()=>l[u],!1,!0));S(t,"appearance",B("prefers-color-scheme",["light","dark"])),S(t,"contrast",B("prefers-contrast",["more","less","custom","no-preference"])),S(t,"pointer",B("pointer",["fine","coarse","none"]));let y=B("prefers-reduced-motion",["reduce","no-preference"]),i=B("forced-colors",["active","none"]),r=B("hover",["hover","none"]);y!==void 0&&(t.reducedMotion=y==="reduce"),i!==void 0&&(t.forcedColors=i==="active"),r!==void 0&&(t.hover=r==="hover");let p=T(()=>document.documentElement.dir);(p==="ltr"||p==="rtl")&&(t.layoutDirection=p);let m=T(()=>window.visualViewport);if(m){let u=x(()=>m.width),O=x(()=>m.height),c=x(()=>m.scale);if(u!==void 0&&O!==void 0&&c!==void 0){let s={width:u,height:O,scale:c};for(let d of["offsetLeft","offsetTop"]){let R=T(()=>m[d]);typeof R=="number"&&Number.isFinite(R)&&Math.abs(R)<=Number.MAX_SAFE_INTEGER&&(s[d]=R)}t.visualViewport=s}}S(t,"secureContext",$(()=>window.isSecureContext)),S(t,"crossOriginIsolated",$(()=>window.crossOriginIsolated));let h=T(()=>navigator.connection);if(h){let u=T(()=>h.effectiveType);(u==="slow-2g"||u==="2g"||u==="3g"||u==="4g")&&(t.networkEffectiveType=u),S(t,"networkRttMs",x(()=>h.rtt,!0)),S(t,"networkDownlinkMbps",x(()=>h.downlink,!0)),S(t,"networkSaveData",$(()=>h.saveData))}return t}function ue(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let n=Array.from(e,o=>o.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function ye(e,n){let{screenshot:o,...t}=e,f={...t,...o?{screenshot:ee(o,e.submissionId)}:{}},a=JSON.stringify(f);if(F(a)>128*1024)throw new TypeError("Relay submission exceeds 128 KiB. Reduce data or context.");let l=n?Array.from(n,([y,i])=>typeof i=="string"?{name:y,value:i}:{name:y,file:{name:i.name,mimeType:i.type,byteSize:i.size}}):void 0;return`{"submission":${a}${l?`,"formData":${JSON.stringify(l)}`:""}}`}function xe(e){if(!e||typeof e.appId!="string"||!e.appId.trim())throw new TypeError("Relay requires a nonempty appId.");for(let c of["appVersion","appBuild"])if(e[c]!==void 0&&typeof e[c]!="string")throw new TypeError(`${c} must be a string.`);if(e.screenshot!==void 0&&typeof e.screenshot!="boolean")throw new TypeError("screenshot must be boolean.");let n={id:e.appId,...e.appVersion!==void 0?{version:e.appVersion}:{},...e.appBuild!==void 0?{build:e.appBuild}:{}},o=te(e),t=e.screenshot!==!1,f=e.uploadLimits===void 0?{maxFiles:10,maxFileBytes:3*1024*1024,maxTotalFileBytes:3*1024*1024}:e.uploadLimits;if(!f||![f.maxFiles,f.maxFileBytes,f.maxTotalFileBytes].every(c=>typeof c=="number"&&Number.isSafeInteger(c)&&c>=0))throw new TypeError("uploadLimits requires three nonnegative safe integer limits.");let a={maxFiles:f.maxFiles,maxFileBytes:f.maxFileBytes,maxTotalFileBytes:f.maxTotalFileBytes};if(e.privateSelectors!==void 0&&!Array.isArray(e.privateSelectors))throw new TypeError("privateSelectors must be an array of CSS selectors.");let l=[...e.privateSelectors??[]];if(!l.every(c=>typeof c=="string"&&c.trim()))throw new TypeError("privateSelectors must contain CSS selectors.");let y=U(e.context===void 0?{}:e.context),i=e.replay;if(i!==void 0&&(!i||typeof i.attach!="function"||typeof i.clear!="function"||typeof i.destroy!="function"))throw new TypeError("replay must be a replay recorder.");let r;try{r=i?.attach({...o.scope,appId:n.id,privateSelectors:l,enabled:t})}catch{}let p=!1,m=new Set,h=Promise.resolve();async function u(c){let s=h,d,R=new Promise(C=>{d=C});h=s.then(()=>R);let b=c.capture.signal,D=performance.now()+5e3,v,w=new Promise(C=>{v=()=>C(void 0)});b.addEventListener("abort",v,{once:!0});let N=setTimeout(()=>c.capture.abort(),5e3);try{return b.aborted||performance.now()>=D||(await Promise.race([s,w]),b.aborted||performance.now()>=D)?void 0:await Promise.race([Y({signal:b,privateSelectors:l}).catch(()=>{}),w])}finally{clearTimeout(N),b.removeEventListener("abort",v),d()}}async function O(c,s={}){let d=y,R=new Date().toISOString(),b=ue(),D="invalid-options",v,w,N,C;try{if(arguments.length>2)throw new TypeError("send accepts data and optional send options only.");if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("Send options must be an object.");if(!q(s)||Reflect.ownKeys(s).some(g=>!["submissionId","signal","context","screenshot","onCollected"].includes(g)))throw new TypeError("Send options must be a plain object containing only submissionId, signal, context, screenshot or onCollected.");let E=s.submissionId;if(E!==void 0){if(typeof E!="string"||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(E))throw new TypeError("submissionId must be a UUID.");b=E}if(p)throw new k("destroyed",b,"Relay client has been destroyed.");if(typeof window>"u"||typeof document>"u")throw new TypeError("Relay sends require a browser.");let M=s.screenshot;if(M!==void 0&&typeof M!="boolean")throw new TypeError("screenshot must be boolean.");let L=s.onCollected;if(L!==void 0&&typeof L!="function")throw new TypeError("onCollected must be a function.");let H=t&&M!==!1;if(w=s.signal,w!==void 0&&(!w||typeof w.aborted!="boolean"||typeof w.addEventListener!="function"||typeof w.removeEventListener!="function"))throw new TypeError("signal must be an AbortSignal.");if(m.size>=4)throw new k("busy",b,"Four Relay sends are already active. Try again after one finishes.");v={controller:new AbortController,capture:new AbortController},m.add(v);let j=v;N=()=>{j.capture.abort(),j.controller.abort()},w?.aborted?N():w?.addEventListener("abort",N,{once:!0});let A=()=>{if(j.controller.signal.aborted||p)throw new k("cancelled",b,"Relay send cancelled. It may already have been accepted; retry with the same submissionId.")};A(),D="invalid-data";let G=s.context,ce=U(G===void 0?d:G),le=se(),I=ae(c),V=I.data,X=V instanceof FormData?V:void 0,P={schemaVersion:2,submissionId:b,invokedAt:R,kind:I.kind,...V instanceof FormData?{}:{data:V},app:{...n},sdk:{name:"@feedbackrelay/web",version:"0.1.1",platform:"web"},device:le,context:ce};if(F(JSON.stringify(P))>128*1024)throw new TypeError("Relay submission exceeds 128 KiB. Reduce data or context.");if(A(),I.fileSizes?.length){let g=a;if(!g.maxFiles||!g.maxFileBytes||!g.maxTotalFileBytes||I.fileSizes.length>g.maxFiles||I.fileSizes.some(_=>_>g.maxFileBytes)||I.fileSizes.reduce((_,de)=>_+de,0)>g.maxTotalFileBytes)throw new k("invalid-data",b,"Files exceed this relay's upload limits. Use fewer or smaller files.")}try{C=r?.freeze(b,E!==void 0,H)}catch{}if(!i&&H&&document.body){let g=await u(j);A(),g&&(P.screenshot=g)}if(A(),L){let g=ye(P,X);try{Promise.resolve(L(g,P.screenshot?.blob)).catch(()=>{})}catch{}A()}D="delivery";let Q=await o.submit(P,j.controller.signal,X);A();try{C?.accepted(Q)}catch{}return Q}catch(E){if(v?.controller.signal.aborted||p&&v){try{C?.cancel()}catch{}throw new k("cancelled",b,"Relay send cancelled. It may already have been accepted; retry with the same submissionId.")}throw E instanceof k?E:new k(D,b,D==="invalid-data"||D==="invalid-options"?E instanceof TypeError?E.message:"Invalid Relay submission.":"Could not send to Relay. Retry with the same submissionId.")}finally{try{w&&N&&w.removeEventListener("abort",N)}catch{}v&&(v.capture.abort(),m.delete(v))}}return{send(...c){let s=O(...c);return s.catch(()=>{}),s},setContext(c){if(p)throw new Error("Relay client has been destroyed.");let s=U(c);if(p)throw new Error("Relay client has been destroyed.");y=s},clearContext(){if(p)throw new Error("Relay client has been destroyed.");y={}},destroy(){if(!p){p=!0;for(let c of m)c.capture.abort(),c.controller.abort();y={};try{r?.detach()}catch{}}}}}export{k as RelaySendError,xe as createRelayClient};
|