@upstep/js 0.7.2 → 0.9.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 +20 -2
- package/dist/{api-DSXEYv9R.mjs → api-CROQwfAo.mjs} +58 -23
- package/dist/api-j3GMTEE7.js +1 -0
- package/dist/api.d.ts +28 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +52 -43
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +253 -110
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +14 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +439 -423
- package/dist/support.cjs +1 -1
- package/dist/support.d.ts +31 -0
- package/dist/support.d.ts.map +1 -1
- package/dist/support.js +136 -48
- package/dist/theme.cjs +1 -0
- package/dist/theme.d.ts +76 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +177 -0
- package/dist/upstep.global.js +55 -46
- package/dist/widget.d.ts +31 -1
- package/dist/widget.d.ts.map +1 -1
- package/package.json +7 -2
- package/dist/api-ZqVkOuh0.js +0 -1
package/dist/upstep.global.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
(function(){"use strict";const l="upstep-anonymous-id";function
|
|
2
|
-
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
3
|
-
#upstep-btn
|
|
1
|
+
(function(){"use strict";const L="#C9481F",A="#FF7A50";function g(e){return e==="dark"?A:L}const y=12,O=32,N=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,f="(\\d{1,3}(?:\\.\\d+)?)",k="(\\d*\\.?\\d+%?)",z=new RegExp(`^rgba?\\(\\s*${f}\\s*(?:,\\s*${f}\\s*,\\s*${f}\\s*(?:,\\s*${k}\\s*)?|\\s+${f}\\s+${f}\\s*(?:\\/\\s*${k}\\s*)?)\\)$`,"i");function b(e){if(typeof e!="string"||e.length>64)return null;const t=e.trim();if(N.test(t)){let u=t.slice(1);u.length<=4&&(u=u.split("").map(l=>l+l).join(""));const h=l=>parseInt(u.slice(l,l+2),16);return[h(0),h(2),h(4),u.length===8?Math.round(h(6)/255*1e3)/1e3:1]}const s=z.exec(t);if(!s)return null;const[o,i,n,a]=[s[1],s[2]??s[5],s[3]??s[6],s[4]??s[7]],r=[o,i,n].map(Number);if(r.some(u=>!(u>=0&&u<=255)))return null;let c=1;return a!==void 0&&(c=a.endsWith("%")?Number(a.slice(0,-1))/100:Number(a),!(c>=0&&c<=1))?null:[r[0],r[1],r[2],c]}function B(e){return b(e)!==null}function v([e,t,s,o]){const i=n=>Math.round(Math.min(255,Math.max(0,n))).toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(s)}${o<1?i(o*255):""}`}function R(e,t,s){const o=b(e),i=b(t);if(!o||!i)return null;const n=Math.min(1,Math.max(0,s));return v([o[0]+(i[0]-o[0])*n,o[1]+(i[1]-o[1])*n,o[2]+(i[2]-o[2])*n,o[3]+(i[3]-o[3])*n])}function j(e,t){const s=b(e);return s?v([s[0],s[1],s[2],s[3]*t]):null}function $([e,t,s]){const o=i=>{const n=i/255;return n<=.03928?n/12.92:((n+.055)/1.055)**2.4};return .2126*o(e)+.7152*o(t)+.0722*o(s)}function w(e,t){const s=b(e),o=b(t);if(!s||!o)return null;const[i,n]=[$(s),$(o)].sort((a,r)=>r-a);return(i+.05)/(n+.05)}const m="#ffffff",S="#1a1915";function H(e){const t=w(e,m);return t===null||t>=3?m:(w(e,S)??0)>t?S:m}function I(e){const t=typeof e=="number"?e:Number(e);return e==null||e===""||!Number.isFinite(t)?y:Math.round(Math.min(O,Math.max(0,t)))}function V(e,t){return Math.round(e*t/y)}const U=["background","surface","border","text","textMuted","accentText"];function E(e,t){const s={};if(!e)return s;for(const o of[e,e[t]])if(o)for(const i of U){const n=o[i];typeof n=="string"&&n.trim()&&(s[i]=n.trim())}return s}const q={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},D={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function F(e,t,s){return R(e,t,s)??`color-mix(in srgb, ${e} ${Math.round((1-s)*100)}%, ${t})`}function P(e){var r;const t=e.mode==="dark"?D:q,s=E(e.colors,e.mode),o=((r=e.accentColor)==null?void 0:r.trim())||g(e.mode),i=s.background??t.bg,n=s.text??t.text,a=s.surface??t.bgSoft;return{dark:e.mode==="dark",bg:i,bgSoft:a,bgHover:s.surface||s.text?F(a,n,.06):t.bgHover,text:n,textSoft:s.textMuted??t.textSoft,textFaint:s.textMuted||s.background?F(s.textMuted??t.textSoft,i,.4):t.textFaint,border:s.border??t.border,overlay:t.overlay,accent:o,accentText:s.accentText??H(o),accentTint:j(o,.1)??`color-mix(in srgb, ${o} 10%, transparent)`,radius:I(e.radius)}}function G(e){var i;const t=E(e.colors,e.mode),s={},o={background:"bg",surface:"surface",border:"border",text:"text",textMuted:"muted",accentText:"accentText"};for(const n of U){const a=t[n];B(a)&&(s[o[n]]=a)}return e.radius!==void 0&&(s.radius=String(I(e.radius))),(i=e.fontFamily)!=null&&i.trim()&&(s.font=e.fontFamily.trim()),s}const M="upstep-anonymous-id";function K(){const e=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;if(typeof window>"u")return e;try{const t=window.localStorage.getItem(M);return t||(window.localStorage.setItem(M,e),e)}catch{return e}}class W{constructor(t){this.baseUrl=(t.baseUrl??"https://upstep.dev").replace(/\/$/,""),this.apiKey=t.apiKey,this.supportIdentityToken=t.supportIdentityToken,this.chat=t.chat!==!1,t.userId!==void 0&&(this.userId=t.userId),this.anonymousId=K()}setUserId(t){this.userId=t}headers(){return{"Content-Type":"application/json","x-api-key":this.apiKey}}async supportEnabled(){if(!this.chat)return!1;try{const t=await fetch(`${this.baseUrl}/api/sdk/support`,{headers:this.headers()});return t.ok&&(await t.json()).enabled===!0}catch{return!1}}supportFrameUrl(t,s,o={}){const i=new URLSearchParams({theme:t,accent:s||g(t==="dark"?"dark":"light")}),n=G({mode:t==="dark"?"dark":"light",...o});for(const[a,r]of Object.entries(n))i.set(a,r);return`${this.baseUrl}/support/${encodeURIComponent(this.apiKey)}?${i}`}connectSupportFrame(t,s={}){const o=new URL(this.baseUrl).origin,i=()=>{var a;return(a=t.contentWindow)==null?void 0:a.postMessage({type:"upstep:support:identity",token:this.supportIdentityToken,accentColor:getComputedStyle(t).color,...s.isVisible?{visible:s.isVisible()}:{}},o)},n=a=>{if(a.origin!==o||a.source!==t.contentWindow)return;const r=a.data;if((r==null?void 0:r.type)==="upstep:support:ready")i();else if((r==null?void 0:r.type)==="upstep:support:unread"&&s.onUnread){const c=Number(r.count);s.onUnread({count:Number.isFinite(c)?Math.max(0,Math.floor(c)):0,newMessage:r.newMessage===!0,author:String(r.author??"").slice(0,80),preview:String(r.preview??"").slice(0,200),sound:r.sound!==!1})}};return t.addEventListener("load",i),window.addEventListener("message",n),()=>{t.removeEventListener("load",i),window.removeEventListener("message",n)}}notifySupportVisibility(t,s){var o;(o=t.contentWindow)==null||o.postMessage({type:"upstep:support:visible",visible:s},new URL(this.baseUrl).origin)}async listFeedback(t){const s=new URLSearchParams;t!=null&&t.cursor&&s.set("cursor",t.cursor),t!=null&&t.limit&&s.set("limit",String(t.limit)),t!=null&&t.type&&s.set("type",t.type),t!=null&&t.status&&s.set("status",t.status),t!=null&&t.sort&&s.set("sort",t.sort),this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback?${s}`,{headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`);return o.json()}async submitFeedback(t){const s=await fetch(`${this.baseUrl}/api/sdk/feedback`,{method:"POST",headers:this.headers(),body:JSON.stringify({...t,endUserId:t.endUserId??this.userId,anonymousId:t.anonymousId??this.anonymousId})});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async vote(t,s){const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}/vote`,{method:"POST",headers:this.headers(),body:JSON.stringify({value:s,endUserId:this.userId,anonymousId:this.anonymousId})});if(!o.ok)throw new Error(`Upstep: ${o.status}`)}async getItem(t){const s=new URLSearchParams;this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}?${s}`,{headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`);return o.json()}async removeVote(t){if(!this.userId&&!this.anonymousId)return;const s=new URLSearchParams;this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}/vote?${s}`,{method:"DELETE",headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`)}}function _(e){const t=e==null?void 0:e.trim();return t&&/^[\w\s,"'.-]{1,200}$/.test(t)?t:""}function T(e){if(e==="light"||e==="dark")return e;if(typeof document<"u"){const t=document.documentElement;return t.classList.contains("dark")||t.getAttribute("data-theme")==="dark"?"dark":"light"}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Y(e,t){const s="right:24px;left:auto",o=e.accent,i=e.accentText,n=a=>`${V(a,e.radius)}px`;return`
|
|
2
|
+
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}${t?`
|
|
3
|
+
#upstep-btn,#upstep-btn *,#upstep-backdrop,#upstep-backdrop *,#upstep-toast,#upstep-toast *{font-family:${t}}`:""}
|
|
4
|
+
#upstep-btn{position:fixed;bottom:24px;${s};z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${o};color:${i};border:none;border-radius:${n(9999)};padding:12px 18px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 6px 20px rgba(26,25,21,.18);transition:transform .15s,box-shadow .15s}
|
|
4
5
|
#upstep-btn svg{width:16px;height:16px;flex-shrink:0}
|
|
5
6
|
#upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
|
|
6
7
|
@media(max-width:639px){#upstep-btn{padding:12px}#upstep-btn span{display:none}}
|
|
@@ -8,74 +9,82 @@
|
|
|
8
9
|
#upstep-backdrop{position:fixed;inset:0;background:transparent;z-index:9999;display:flex;align-items:flex-end;justify-content:flex-end;padding:0 24px 88px;animation:upstep-fade .2s ease}
|
|
9
10
|
@keyframes upstep-fade{from{opacity:0}to{opacity:1}}
|
|
10
11
|
@keyframes upstep-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
|
|
11
|
-
#upstep-modal{background:${
|
|
12
|
+
#upstep-modal{background:${e.bg};border:1px solid ${e.border};border-radius:${n(20)};width:100%;max-width:440px;max-height:calc(100dvh - 112px);display:flex;flex-direction:column;overflow:hidden;box-shadow:0 24px 64px rgba(0,0,0,.28);animation:upstep-rise .26s cubic-bezier(.16,1,.3,1)}
|
|
12
13
|
#upstep-header{display:flex;align-items:flex-start;justify-content:space-between;padding:20px 20px 0}
|
|
13
|
-
#upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${
|
|
14
|
-
#upstep-header p{margin:2px 0 0;font-size:14px;color:${
|
|
15
|
-
#upstep-close{background:${
|
|
16
|
-
#upstep-close:hover{background:${
|
|
17
|
-
#upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${
|
|
18
|
-
.upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius
|
|
19
|
-
.upstep-mode .upstep-tab.active{background:${
|
|
20
|
-
.upstep-tab.active{background:${
|
|
14
|
+
#upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${e.text};letter-spacing:-.01em}
|
|
15
|
+
#upstep-header p{margin:2px 0 0;font-size:14px;color:${e.textFaint}}
|
|
16
|
+
#upstep-close{background:${e.bgSoft};border:none;width:28px;height:28px;border-radius:${n(8)};font-size:14px;cursor:pointer;color:${e.textSoft};line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
|
|
17
|
+
#upstep-close:hover{background:${e.bgHover};color:${e.text}}
|
|
18
|
+
#upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius:${n(11)}}
|
|
19
|
+
.upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius:${n(8)};font-size:14px;font-weight:600;color:${e.textSoft};cursor:pointer;transition:all .15s}
|
|
20
|
+
.upstep-mode .upstep-tab.active{background:${e.bgSoft};box-shadow:none}
|
|
21
|
+
.upstep-tab.active{background:${e.bg};color:${e.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
|
|
21
22
|
#upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
|
|
22
|
-
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${
|
|
23
|
-
.upstep-form textarea::placeholder{color:${
|
|
24
|
-
.upstep-form textarea:focus{border-color:${
|
|
23
|
+
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius:${n(12)};padding:12px;font-size:16px;line-height:1.6;resize:vertical;outline:none;background:${e.bgSoft};color:${e.text};transition:border-color .15s}
|
|
24
|
+
.upstep-form textarea::placeholder{color:${e.textFaint}}
|
|
25
|
+
.upstep-form textarea:focus{border-color:${o};background:${e.bg}}
|
|
25
26
|
.upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
|
|
26
|
-
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius
|
|
27
|
+
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius:${n(9)};border:1px solid ${e.border};background:${e.bg};color:${e.textSoft};font-size:14px;font-weight:600;cursor:pointer;transition:all .15s}
|
|
27
28
|
.upstep-type-btn svg{width:12px;height:12px;flex-shrink:0}
|
|
28
|
-
.upstep-type-btn:hover{border-color:${
|
|
29
|
-
.upstep-type-btn.selected{background:${
|
|
30
|
-
.upstep-submit{width:100%;padding:12px;background:${
|
|
29
|
+
.upstep-type-btn:hover{border-color:${e.textFaint}}
|
|
30
|
+
.upstep-type-btn.selected{background:${o};color:${i};border-color:${o}}
|
|
31
|
+
.upstep-submit{width:100%;padding:12px;background:${o};color:${i};border:none;border-radius:${n(11)};font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
|
|
31
32
|
.upstep-submit:hover{filter:brightness(.94)}
|
|
32
33
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
33
|
-
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${
|
|
34
|
-
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${
|
|
35
|
-
.upstep-feedback-item:hover{border-color:${
|
|
36
|
-
.upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius
|
|
37
|
-
.upstep-vote:hover{border-color:${
|
|
38
|
-
.upstep-vote.voted{border-color:${
|
|
39
|
-
.upstep-vote-arrow{font-size:11px;line-height:1;color:${
|
|
40
|
-
.upstep-vote-count{font-size:14px;font-weight:700;color:${
|
|
34
|
+
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${o};font-weight:500}
|
|
35
|
+
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius:${n(14)};margin-bottom:10px;background:${e.bg};transition:border-color .15s}
|
|
36
|
+
.upstep-feedback-item:hover{border-color:${e.textFaint}}
|
|
37
|
+
.upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius:${n(11)};border:1px solid ${e.border};background:${e.bgSoft};cursor:pointer;transition:all .15s}
|
|
38
|
+
.upstep-vote:hover{border-color:${o}}
|
|
39
|
+
.upstep-vote.voted{border-color:${o};background:${e.accentTint}}
|
|
40
|
+
.upstep-vote-arrow{font-size:11px;line-height:1;color:${o}}
|
|
41
|
+
.upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
|
|
41
42
|
.upstep-feedback-main{flex:1;min-width:0}
|
|
42
|
-
.upstep-feedback-content{font-size:16px;line-height:1.5;color:${
|
|
43
|
+
.upstep-feedback-content{font-size:16px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
|
|
43
44
|
.upstep-feedback-meta{display:flex;align-items:center;gap:7px}
|
|
44
|
-
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius
|
|
45
|
+
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:${n(9999)};font-size:10.5px;font-weight:700;letter-spacing:.02em}
|
|
45
46
|
.upstep-badge-bug{background:#fdecec;color:#d6453d}
|
|
46
47
|
.upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
|
|
47
|
-
.upstep-badge-general{background:${
|
|
48
|
-
.upstep-feedback-date{font-size:11px;color:${
|
|
49
|
-
|
|
50
|
-
.upstep-
|
|
51
|
-
|
|
48
|
+
.upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
|
|
49
|
+
.upstep-feedback-date{font-size:11px;color:${e.textFaint}}
|
|
50
|
+
#upstep-btn{position:fixed}
|
|
51
|
+
.upstep-unread{position:absolute;top:-7px;right:-5px;min-width:22px;height:22px;padding:0 6px;border-radius:11px;background:${e.text};color:${e.bg};border:2px solid ${e.bg};font-size:12px;font-weight:700;line-height:18px;text-align:center;font-variant-numeric:tabular-nums;animation:upstep-pop .45s cubic-bezier(.3,1.6,.5,1)}
|
|
52
|
+
@keyframes upstep-pop{from{transform:scale(.4)}to{transform:scale(1)}}
|
|
53
|
+
#upstep-toast{position:fixed;bottom:84px;right:24px;z-index:9998;max-width:min(300px,calc(100vw - 48px));display:grid;gap:2px;text-align:left;background:${e.bg};color:${e.text};border:1px solid ${e.border};border-radius:${n(14)} ${n(14)} ${n(4)} ${n(14)};padding:10px 12px;box-shadow:0 10px 32px rgba(0,0,0,.2);cursor:pointer;animation:upstep-rise .26s cubic-bezier(.16,1,.3,1)}
|
|
54
|
+
#upstep-toast b{font-size:12px}
|
|
55
|
+
#upstep-toast span{font-size:14px;line-height:1.4;color:${e.textSoft};display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
56
|
+
#upstep-toast em{font-style:normal;font-size:11px;font-weight:600;color:${o}}
|
|
57
|
+
@media(prefers-reduced-motion:reduce){.upstep-unread,#upstep-toast{animation:none}}
|
|
58
|
+
.upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
|
|
59
|
+
.upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
|
|
60
|
+
`}const J='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';class X{constructor(t,s={}){this.isOpen=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.hasSupport=!1,this.disconnectSupport=null,this.unread=0,this.audio=null,this.frameTheme=null,this.unreadListeners=new Set,this.client=t,this.options=s,this.position="right",this.showLauncher=s.launcher!==!1,this.themeMode=s.theme??"auto",this.palette=this.buildPalette(T(this.themeMode))}buildPalette(t){return P({mode:t,accentColor:this.options.accentColor,colors:this.options.colors,radius:this.options.radius})}get accent(){return this.palette.accent}supportFrameSrc(){return this.client.supportFrameUrl(this.palette.dark?"dark":"light",this.accent,{colors:this.options.colors,radius:this.options.radius,fontFamily:this.options.fontFamily})}mount(){this.injectStyles(),this.showLauncher&&this.renderButton(),this.client.supportEnabled().then(t=>{if(this.hasSupport=t,t){const s=document.querySelector("#upstep-btn span");s&&(s.textContent="Help & feedback"),this.isOpen?this.renderModal():this.hasOpenedSupport()&&this.preloadSupport()}})}openWidget(){this.openModal()}closeWidget(){this.closeModal()}isChatVisible(){return this.isOpen}onUnread(t){return this.unreadListeners.add(t),t(this.unread),()=>{this.unreadListeners.delete(t)}}injectStyles(){var s;(s=document.getElementById("upstep-styles"))==null||s.remove();const t=document.createElement("style");t.id="upstep-styles",t.textContent=Y(this.palette,_(this.options.fontFamily)),document.head.appendChild(t)}renderButton(){const t=document.createElement("button");t.id="upstep-btn",t.setAttribute("aria-label","Open help and feedback"),t.innerHTML=`${J}<span>Feedback</span>`,t.addEventListener("click",()=>{this.openModal()}),document.body.appendChild(t)}supportFrame(){return document.querySelector("#upstep-support-frame")}get usedKey(){return`upstep:support-opened:${this.client.baseUrl}`}hasOpenedSupport(){try{return localStorage.getItem(this.usedKey)==="1"}catch{return!1}}preloadSupport(){this.tab="support",this.renderModal(!0)}openModal(){if(this.unlockAudio(),!this.isOpen&&this.hasSupport){this.tab="support";try{localStorage.setItem(this.usedKey,"1")}catch{}}const t=T(this.themeMode),s=document.getElementById("upstep-backdrop"),o=this.supportFrame();if(!this.isOpen&&s&&o&&s.style.display==="none"&&this.frameTheme===t){this.isOpen=!0,s.style.display="",this.client.notifySupportVisibility(o,!0),this.setUnread(0),this.fetchFeed();return}this.isOpen=!0,this.palette=this.buildPalette(t),this.injectStyles(),this.fetchFeed(),this.renderModal(),this.setUnread(0)}closeModal(){var t,s;if(this.isOpen=!1,this.hasSupport){const o=this.supportFrame(),i=document.getElementById("upstep-backdrop");o&&i?(i.style.display="none",this.client.notifySupportVisibility(o,!1)):this.preloadSupport();return}(t=this.disconnectSupport)==null||t.call(this),this.disconnectSupport=null,(s=document.getElementById("upstep-backdrop"))==null||s.remove()}setUnread(t){this.unread=t;const s=document.getElementById("upstep-btn"),o=s==null?void 0:s.querySelector(".upstep-unread");if(s){if(t>0){const n=o??document.createElement("span");n.className="upstep-unread",n.textContent=t>9?"9+":String(t),o||s.appendChild(n)}else o==null||o.remove();s.setAttribute("aria-label",t>0?`Open help and feedback, ${t} unread ${t===1?"message":"messages"}`:"Open help and feedback")}const i=document.title.replace(/^\(\d+\)\s/,"");document.title=t>0?`(${t}) ${i}`:i,t===0&&this.hideToast(),this.unreadListeners.forEach(n=>n(t))}onSupportUnread(t){if(this.isOpen)return this.setUnread(0);this.setUnread(t.count),t.newMessage&&t.count>0&&(this.showToast(t),t.sound&&this.chime())}showToast(t){this.hideToast();const s=document.createElement("button");s.id="upstep-toast",s.type="button",s.setAttribute("role","status");const o=document.createElement("b");o.textContent=t.author||"New message";const i=document.createElement("span");i.textContent=t.preview;const n=document.createElement("em");n.textContent=t.count>1?`${t.count} new messages`:"Tap to reply",s.append(o,i,n),s.addEventListener("click",()=>this.openModal()),document.body.appendChild(s),this.toastTimer=setTimeout(()=>this.hideToast(),9e3)}hideToast(){var t;clearTimeout(this.toastTimer),(t=document.getElementById("upstep-toast"))==null||t.remove()}unlockAudio(){try{const t=window.AudioContext||window.webkitAudioContext;if(!t)return;this.audio=this.audio??new t,this.audio.state==="suspended"&&this.audio.resume()}catch{}}chime(){const t=this.audio;if(!t||t.state!=="running")return;const s=t.currentTime;for(const[o,i]of[[880,0],[1318,.12]]){const n=t.createOscillator(),a=t.createGain();n.type="sine",n.frequency.value=o,a.gain.setValueAtTime(1e-4,s+i),a.gain.exponentialRampToValueAtTime(.14,s+i+.02),a.gain.exponentialRampToValueAtTime(1e-4,s+i+.5),n.connect(a),a.connect(t.destination),n.start(s+i),n.stop(s+i+.55)}}async fetchFeed(){try{const t=await this.client.listFeedback({sort:"votes",limit:20});this.feedItems=t.items,this.renderFeedList()}catch{}}renderModal(t=!1){var i,n,a;(i=this.disconnectSupport)==null||i.call(this),this.disconnectSupport=null;const s=document.createElement("div");s.id="upstep-backdrop",s.addEventListener("click",r=>{r.target===s&&this.closeModal()}),s.innerHTML=`
|
|
52
61
|
<div id="upstep-modal" style="max-width:${this.hasSupport?"460px":"440px"}">
|
|
53
62
|
${this.hasSupport?`<div class="upstep-mode" style="display:flex;align-items:center;gap:14px;padding:10px 14px;border-bottom:1px solid ${this.palette.border}"><div id="upstep-tabs" style="margin:0;padding:0;background:transparent;flex:1"><button class="upstep-tab ${this.tab==="support"?"active":""}" data-tab="support">Support</button><button class="upstep-tab ${this.tab==="submit"?"active":""}" data-tab="submit">Feedback</button><button class="upstep-tab ${this.tab==="feed"?"active":""}" data-tab="feed">Ideas</button></div><button id="upstep-close" aria-label="Close" style="flex-shrink:0;background:transparent">✕</button></div>`:`<div id="upstep-header"><div><h2>Share your feedback</h2><p>Tell us what to build next, or vote on ideas.</p></div><button id="upstep-close" aria-label="Close">✕</button></div><div id="upstep-tabs"><button class="upstep-tab ${this.tab==="submit"?"active":""}" data-tab="submit">Give feedback</button><button class="upstep-tab ${this.tab==="feed"?"active":""}" data-tab="feed">Vote on ideas</button></div>`}
|
|
54
63
|
<div id="upstep-body" style="${this.tab==="support"?"padding:0;overflow:hidden":""}">
|
|
55
|
-
${this.tab==="support"?`<iframe id="upstep-support-frame" title="Customer support" src="${this.
|
|
64
|
+
${this.tab==="support"?`<iframe id="upstep-support-frame" title="Customer support" src="${x(this.supportFrameSrc())}" style="width:100%;height:min(560px,calc(100dvh - 168px));min-height:300px;border:0;display:block"></iframe>`:this.tab==="submit"?this.renderSubmitForm():this.renderFeed()}
|
|
56
65
|
</div>
|
|
57
66
|
</div>
|
|
58
|
-
`,(
|
|
67
|
+
`,(n=document.getElementById("upstep-backdrop"))==null||n.remove(),t&&(s.style.display="none"),document.body.appendChild(s),(a=s.querySelector("#upstep-close"))==null||a.addEventListener("click",()=>this.closeModal()),s.querySelectorAll(".upstep-tab").forEach(r=>{r.addEventListener("click",()=>{this.tab=r.dataset.tab,this.renderModal()})});const o=s.querySelector("#upstep-support-frame");o&&(o.style.color=this.accent,this.frameTheme=this.palette.dark?"dark":"light",this.disconnectSupport=this.client.connectSupportFrame(o,{isVisible:()=>this.isOpen,onUnread:r=>this.onSupportUnread(r)})),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){const t=["BUG","FEATURE","GENERAL"],s={BUG:"Bug",FEATURE:"Feature",GENERAL:"General"},o={BUG:'<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="8" cy="10" rx="3.5" ry="4.5"/><path d="M8 5.5V4M5.5 6.5 3.5 5M10.5 6.5 12.5 5M4.5 10.5 2.5 10M11.5 10.5 13.5 10"/></svg>',FEATURE:'<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2v1.5M8 12.5V14M2 8h1.5M12.5 8H14M4.1 4.1l1 1M10.9 10.9l1 1M11.9 4.1l-1 1M5.1 10.9l-1 1"/><circle cx="8" cy="8" r="2.5"/></svg>',GENERAL:'<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 9a2 2 0 0 1-2 2H5L2 14V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v5z"/></svg>'};return`
|
|
59
68
|
<div class="upstep-form">
|
|
60
69
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
61
70
|
<div class="upstep-type-row">
|
|
62
|
-
${
|
|
71
|
+
${t.map(i=>`<button class="upstep-type-btn${this.selectedType===i?" selected":""}" data-type="${i}">${o[i]}${s[i]}</button>`).join("")}
|
|
63
72
|
</div>
|
|
64
73
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
65
74
|
<div id="upstep-form-msg"></div>
|
|
66
75
|
</div>
|
|
67
|
-
`}renderFeed(){return this.feedItems.length?this.feedItems.map(
|
|
68
|
-
<div class="upstep-feedback-item" data-id="${
|
|
69
|
-
<button class="upstep-vote${
|
|
76
|
+
`}renderFeed(){return this.feedItems.length?this.feedItems.map(t=>{var s;return`
|
|
77
|
+
<div class="upstep-feedback-item" data-id="${t.id}">
|
|
78
|
+
<button class="upstep-vote${t.userVote==="UP"?" voted":""}" data-vote="UP" data-feedback="${t.id}">
|
|
70
79
|
<span class="upstep-vote-arrow">▲</span>
|
|
71
|
-
<span class="upstep-vote-count">${
|
|
80
|
+
<span class="upstep-vote-count">${t.upvotes}</span>
|
|
72
81
|
</button>
|
|
73
82
|
<div class="upstep-feedback-main">
|
|
74
|
-
<p class="upstep-feedback-content">${
|
|
83
|
+
<p class="upstep-feedback-content">${x(t.content)}</p>
|
|
75
84
|
<div class="upstep-feedback-meta">
|
|
76
|
-
<span class="upstep-badge upstep-badge-${
|
|
77
|
-
<span class="upstep-badge upstep-badge-general">${
|
|
78
|
-
<span class="upstep-feedback-date">${new Date(
|
|
85
|
+
<span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
|
|
86
|
+
<span class="upstep-badge upstep-badge-general">${x(((s=t.boardStatus)==null?void 0:s.name)??t.status.replace("_"," "))}</span>
|
|
87
|
+
<span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
|
|
79
88
|
</div>
|
|
80
89
|
</div>
|
|
81
|
-
</div>`}).join(""):'<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>'}renderFeedList(){const
|
|
90
|
+
</div>`}).join(""):'<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>'}renderFeedList(){const t=document.getElementById("upstep-body");!t||this.tab!=="feed"||(t.innerHTML=this.renderFeed(),this.bindVoteButtons())}bindSubmitForm(){var t;document.querySelectorAll(".upstep-type-btn").forEach(s=>{s.addEventListener("click",()=>{this.selectedType=s.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(o=>o.classList.remove("selected")),s.classList.add("selected")})}),(t=document.getElementById("upstep-submit-btn"))==null||t.addEventListener("click",async()=>{const s=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),i=document.getElementById("upstep-submit-btn");if(!s||this.loading)return;const n=s.value.trim();if(n){this.loading=!0,i&&(i.disabled=!0,i.textContent="Sending…");try{await this.client.submitFeedback({content:n,type:this.selectedType}),s.value="",o&&(o.textContent="Feedback received. Thank you."),await this.fetchFeed()}catch{o&&(o.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,i&&(i.disabled=!1,i.textContent="Send feedback")}}})}bindVoteButtons(){document.querySelectorAll(".upstep-vote").forEach(t=>{t.addEventListener("click",async()=>{const s=t.dataset.feedback;try{await this.client.vote(s,"UP"),await this.fetchFeed()}catch{}})})}}function x(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let p=null,d=null;const C={init(e){if(p=new W(e),typeof window<"u"){const t={};e.accentColor!==void 0&&(t.accentColor=e.accentColor),e.position!==void 0&&(t.position=e.position),e.theme!==void 0&&(t.theme=e.theme),e.launcher!==void 0&&(t.launcher=e.launcher),e.colors!==void 0&&(t.colors=e.colors),e.radius!==void 0&&(t.radius=e.radius),e.fontFamily!==void 0&&(t.fontFamily=e.fontFamily);const s=()=>{d=new X(p,t),d.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",s):s()}return p},open(){d==null||d.openWidget()},close(){d==null||d.closeWidget()},identify(e){p==null||p.setUserId(e)},identifySupport(e){var s;p&&(p.supportIdentityToken=e);const t=document.querySelector("#upstep-support-frame");t&&p&&((s=t.contentWindow)==null||s.postMessage({type:"upstep:support:identity",token:e,visible:(d==null?void 0:d.isChatVisible())??!0},new URL(p.baseUrl).origin))},onUnread(e){return(d==null?void 0:d.onUnread(e))??(()=>{})},get client(){if(!p)throw new Error("Upstep.init() must be called first");return p}};if(typeof document<"u"){const e=document.currentScript,t=e==null?void 0:e.dataset.apiKey,s=e==null?void 0:e.dataset.userId,o=e==null?void 0:e.dataset.baseUrl,i=e==null?void 0:e.dataset.accentColor,n=e==null?void 0:e.dataset.position,a=e==null?void 0:e.dataset.theme;if(t){const r={apiKey:t};s&&(r.userId=s),(e==null?void 0:e.dataset.chat)!==void 0&&(r.chat=e.dataset.chat!=="false"),o&&(r.baseUrl=o),i&&(r.accentColor=i),(n==="left"||n==="right")&&(r.position=n),(a==="light"||a==="dark"||a==="auto")&&(r.theme=a);const c=e==null?void 0:e.dataset.colors;if(c)try{const l=JSON.parse(c);l&&typeof l=="object"&&(r.colors=l)}catch{console.warn("Upstep: data-colors must be JSON")}const u=e==null?void 0:e.dataset.radius;u&&Number.isFinite(Number(u))&&(r.radius=Number(u));const h=e==null?void 0:e.dataset.fontFamily;h&&(r.fontFamily=h),C.init(r)}}window.Upstep=C})();
|
package/dist/widget.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { UpstepColorOverrides } from '@upstep/types';
|
|
1
2
|
import { UpstepApiClient } from './api';
|
|
2
3
|
type ThemeMode = "light" | "dark" | "auto";
|
|
3
4
|
export interface WidgetOptions {
|
|
4
5
|
accentColor?: string;
|
|
6
|
+
/** Panel color overrides. Unset keys keep the default palette. */
|
|
7
|
+
colors?: UpstepColorOverrides;
|
|
8
|
+
/** Base corner radius in px. Defaults to 12. */
|
|
9
|
+
radius?: number;
|
|
10
|
+
/** CSS font-family for the widget. */
|
|
11
|
+
fontFamily?: string;
|
|
5
12
|
position?: "left" | "right";
|
|
6
13
|
/** Color theme. "auto" follows the OS preference. Defaults to "auto". */
|
|
7
14
|
theme?: ThemeMode;
|
|
@@ -15,23 +22,46 @@ export declare class UpstepWidget {
|
|
|
15
22
|
private feedItems;
|
|
16
23
|
private selectedType;
|
|
17
24
|
private loading;
|
|
18
|
-
private accent;
|
|
19
25
|
private position;
|
|
20
26
|
private showLauncher;
|
|
21
27
|
private themeMode;
|
|
28
|
+
private options;
|
|
22
29
|
private palette;
|
|
23
30
|
private hasSupport;
|
|
24
31
|
private disconnectSupport;
|
|
32
|
+
private unread;
|
|
33
|
+
private toastTimer;
|
|
34
|
+
private audio;
|
|
35
|
+
private frameTheme;
|
|
36
|
+
private unreadListeners;
|
|
25
37
|
constructor(client: UpstepApiClient, options?: WidgetOptions);
|
|
38
|
+
private buildPalette;
|
|
39
|
+
private get accent();
|
|
40
|
+
private supportFrameSrc;
|
|
26
41
|
mount(): void;
|
|
27
42
|
/** Open the feedback modal programmatically (e.g. from your own button). */
|
|
28
43
|
openWidget(): void;
|
|
29
44
|
/** Close the feedback modal programmatically. */
|
|
30
45
|
closeWidget(): void;
|
|
46
|
+
/** Whether the chat window is currently on screen. */
|
|
47
|
+
isChatVisible(): boolean;
|
|
48
|
+
/** Number of unread support messages. Subscribe to drive your own launcher or badge. */
|
|
49
|
+
onUnread(listener: (count: number) => void): () => void;
|
|
31
50
|
private injectStyles;
|
|
32
51
|
private renderButton;
|
|
52
|
+
private supportFrame;
|
|
53
|
+
private get usedKey();
|
|
54
|
+
private hasOpenedSupport;
|
|
55
|
+
private preloadSupport;
|
|
33
56
|
private openModal;
|
|
34
57
|
private closeModal;
|
|
58
|
+
private setUnread;
|
|
59
|
+
private onSupportUnread;
|
|
60
|
+
private showToast;
|
|
61
|
+
private hideToast;
|
|
62
|
+
/** Browsers only allow sound after a click, so prepare audio when the chat is first opened. */
|
|
63
|
+
private unlockAudio;
|
|
64
|
+
private chime;
|
|
35
65
|
private fetchFeed;
|
|
36
66
|
private renderModal;
|
|
37
67
|
private renderSubmitForm;
|
package/dist/widget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAsB,MAAM,OAAO,CAAC;AAG5D,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAwG3C,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,yEAAyE;IACzE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,GAAG,CAAiB;IAC5B,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,UAAU,CAA4C;IAC9D,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,eAAe,CAAsC;gBAEjD,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,aAAkB;IAShE,OAAO,CAAC,YAAY;IASpB,OAAO,KAAK,MAAM,GAEjB;IAED,OAAO,CAAC,eAAe;IAYvB,KAAK;IAgBL,4EAA4E;IAC5E,UAAU;IAIV,iDAAiD;IACjD,WAAW;IAIX,sDAAsD;IACtD,aAAa;IAIb,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;IAQ1C,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,YAAY;IAIpB,OAAO,KAAK,OAAO,GAElB;IAED,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,SAAS;IAsCjB,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,SAAS;IAmBjB,OAAO,CAAC,SAAS;IAKjB,+FAA+F;IAC/F,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,KAAK;YAsBC,SAAS;IAUvB,OAAO,CAAC,WAAW;IA+CnB,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,UAAU;IAyBlB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAsDtB,OAAO,CAAC,eAAe;CAaxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upstep/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "UpStep feedback, voting and AI support widgets for web apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://upstep.dev",
|
|
@@ -36,13 +36,18 @@
|
|
|
36
36
|
"types": "./dist/support.d.ts",
|
|
37
37
|
"import": "./dist/support.js",
|
|
38
38
|
"require": "./dist/support.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./theme": {
|
|
41
|
+
"types": "./dist/theme.d.ts",
|
|
42
|
+
"import": "./dist/theme.js",
|
|
43
|
+
"require": "./dist/theme.cjs"
|
|
39
44
|
}
|
|
40
45
|
},
|
|
41
46
|
"files": [
|
|
42
47
|
"dist"
|
|
43
48
|
],
|
|
44
49
|
"dependencies": {
|
|
45
|
-
"@upstep/types": "0.
|
|
50
|
+
"@upstep/types": "0.9.0"
|
|
46
51
|
},
|
|
47
52
|
"peerDependencies": {
|
|
48
53
|
"react": ">=18",
|
package/dist/api-ZqVkOuh0.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const d="upstep-anonymous-id";function h(){const o=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;if(typeof window>"u")return o;try{const e=window.localStorage.getItem(d);return e||(window.localStorage.setItem(d,o),o)}catch{return o}}class u{constructor(e){this.baseUrl=(e.baseUrl??"https://upstep.dev").replace(/\/$/,""),this.apiKey=e.apiKey,this.supportIdentityToken=e.supportIdentityToken,this.chat=e.chat!==!1,e.userId!==void 0&&(this.userId=e.userId),this.anonymousId=h()}setUserId(e){this.userId=e}headers(){return{"Content-Type":"application/json","x-api-key":this.apiKey}}async supportEnabled(){if(!this.chat)return!1;try{const e=await fetch(`${this.baseUrl}/api/sdk/support`,{headers:this.headers()});return e.ok&&(await e.json()).enabled===!0}catch{return!1}}supportFrameUrl(e,t="#D97757"){return`${this.baseUrl}/support/${encodeURIComponent(this.apiKey)}?theme=${encodeURIComponent(e)}&accent=${encodeURIComponent(t)}`}connectSupportFrame(e){const t=new URL(this.baseUrl).origin,s=()=>{var n;return(n=e.contentWindow)==null?void 0:n.postMessage({type:"upstep:support:identity",token:this.supportIdentityToken,accentColor:getComputedStyle(e).color},t)},i=n=>{var r;n.origin===t&&n.source===e.contentWindow&&((r=n.data)==null?void 0:r.type)==="upstep:support:ready"&&s()};return e.addEventListener("load",s),window.addEventListener("message",i),()=>{e.removeEventListener("load",s),window.removeEventListener("message",i)}}async listFeedback(e){const t=new URLSearchParams;e!=null&&e.cursor&&t.set("cursor",e.cursor),e!=null&&e.limit&&t.set("limit",String(e.limit)),e!=null&&e.type&&t.set("type",e.type),e!=null&&e.status&&t.set("status",e.status),e!=null&&e.sort&&t.set("sort",e.sort),this.userId&&t.set("endUserId",this.userId),this.anonymousId&&t.set("anonymousId",this.anonymousId);const s=await fetch(`${this.baseUrl}/api/sdk/feedback?${t}`,{headers:this.headers()});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async submitFeedback(e){const t=await fetch(`${this.baseUrl}/api/sdk/feedback`,{method:"POST",headers:this.headers(),body:JSON.stringify({...e,endUserId:e.endUserId??this.userId,anonymousId:e.anonymousId??this.anonymousId})});if(!t.ok)throw new Error(`Upstep: ${t.status}`);return t.json()}async vote(e,t){const s=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}/vote`,{method:"POST",headers:this.headers(),body:JSON.stringify({value:t,endUserId:this.userId,anonymousId:this.anonymousId})});if(!s.ok)throw new Error(`Upstep: ${s.status}`)}async getItem(e){const t=new URLSearchParams;this.userId&&t.set("endUserId",this.userId),this.anonymousId&&t.set("anonymousId",this.anonymousId);const s=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}?${t}`,{headers:this.headers()});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async removeVote(e){if(!this.userId&&!this.anonymousId)return;const t=new URLSearchParams;this.userId&&t.set("endUserId",this.userId),this.anonymousId&&t.set("anonymousId",this.anonymousId);const s=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}/vote?${t}`,{method:"DELETE",headers:this.headers()});if(!s.ok)throw new Error(`Upstep: ${s.status}`)}}exports.UpstepApiClient=u;
|