@upstep/js 0.8.0 → 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-ZTIiZxlg.mjs → api-CROQwfAo.mjs} +23 -9
- package/dist/api-j3GMTEE7.js +1 -0
- package/dist/api.d.ts +11 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +51 -50
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +163 -135
- 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/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 +51 -50
- package/dist/widget.d.ts +11 -1
- package/dist/widget.d.ts.map +1 -1
- package/package.json +14 -9
- package/dist/api-BdOCiCLM.js +0 -1
package/dist/api-BdOCiCLM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const h="upstep-anonymous-id";function c(){const i=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;if(typeof window>"u")return i;try{const e=window.localStorage.getItem(h);return e||(window.localStorage.setItem(h,i),i)}catch{return i}}class a{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=c()}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,t={}){const s=new URL(this.baseUrl).origin,r=()=>{var o;return(o=e.contentWindow)==null?void 0:o.postMessage({type:"upstep:support:identity",token:this.supportIdentityToken,accentColor:getComputedStyle(e).color,...t.isVisible?{visible:t.isVisible()}:{}},s)},d=o=>{if(o.origin!==s||o.source!==e.contentWindow)return;const n=o.data;if((n==null?void 0:n.type)==="upstep:support:ready")r();else if((n==null?void 0:n.type)==="upstep:support:unread"&&t.onUnread){const u=Number(n.count);t.onUnread({count:Number.isFinite(u)?Math.max(0,Math.floor(u)):0,newMessage:n.newMessage===!0,author:String(n.author??"").slice(0,80),preview:String(n.preview??"").slice(0,200),sound:n.sound!==!1})}};return e.addEventListener("load",r),window.addEventListener("message",d),()=>{e.removeEventListener("load",r),window.removeEventListener("message",d)}}notifySupportVisibility(e,t){var s;(s=e.contentWindow)==null||s.postMessage({type:"upstep:support:visible",visible:t},new URL(this.baseUrl).origin)}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=a;
|