@upstep/js 0.7.1 → 0.8.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 +4 -2
- package/dist/api-BdOCiCLM.js +1 -0
- package/dist/{api-DSXEYv9R.mjs → api-ZTIiZxlg.mjs} +42 -21
- package/dist/api.d.ts +17 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +23 -15
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +175 -60
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- 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/upstep.global.js +12 -4
- package/dist/widget.d.ts +20 -0
- package/dist/widget.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/api-ZqVkOuh0.js +0 -1
package/README.md
CHANGED
|
@@ -100,7 +100,7 @@ Every entry point (`Upstep.init`, `<UpstepProvider>`, and the script tag's `data
|
|
|
100
100
|
|
|
101
101
|
### AI and live chat in the existing widget
|
|
102
102
|
|
|
103
|
-
Version 0.7.
|
|
103
|
+
Version 0.7.2 includes a **Support** tab to the same widget that handles feedback and
|
|
104
104
|
voting. Enable customer support for your paid project in the UpStep dashboard,
|
|
105
105
|
learn the business website, and confirm the business details and contact email.
|
|
106
106
|
The project must be enabled on the server; `chat: true` never bypasses plan access.
|
|
@@ -121,7 +121,7 @@ import { UpstepProvider, FeedbackWidget } from '@upstep/js/react';
|
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
```html
|
|
124
|
-
<script defer src="https://unpkg.com/@upstep/js@0.7.
|
|
124
|
+
<script defer src="https://unpkg.com/@upstep/js@0.7.2/dist/upstep.global.js"
|
|
125
125
|
data-api-key="YOUR_PROJECT_KEY" data-chat="true"></script>
|
|
126
126
|
```
|
|
127
127
|
|
|
@@ -140,3 +140,5 @@ The website launcher and its opened chat/feedback panel stay in the bottom-right
|
|
|
140
140
|
Support can show quick replies, issue details, resolution confirmations, and a contact card. The team action appears only after AI discusses the issue and tries to help, or establishes that a human must perform the action. Asking for an agent alone never opens a contact form. Active cards stay near the composer, contact details use two short steps, and optional issue fields expand only when needed. The server requires a name and valid email before queueing a private ticket. AI replies stay short, with separate paragraphs and no em dashes.
|
|
141
141
|
|
|
142
142
|
A DOM-free client is available from `@upstep/js/support` for custom native integrations. The React Native SDK uses this same client inside its existing feedback sheet.
|
|
143
|
+
|
|
144
|
+
Business branding comes from Customer support → Settings in UpStep. Website learning detects a business icon for review; you can replace it with an upload or public image URL. The approved icon is shared by the web and native chat widgets. Setup questions offer suggested choices when appropriate, with a custom answer field.
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
if (typeof window > "u") return
|
|
1
|
+
const h = "upstep-anonymous-id";
|
|
2
|
+
function a() {
|
|
3
|
+
const i = typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
4
|
+
if (typeof window > "u") return i;
|
|
5
5
|
try {
|
|
6
|
-
const e = window.localStorage.getItem(
|
|
7
|
-
return e || (window.localStorage.setItem(
|
|
6
|
+
const e = window.localStorage.getItem(h);
|
|
7
|
+
return e || (window.localStorage.setItem(h, i), i);
|
|
8
8
|
} catch {
|
|
9
|
-
return
|
|
9
|
+
return i;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
class
|
|
12
|
+
class c {
|
|
13
13
|
constructor(e) {
|
|
14
|
-
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 =
|
|
14
|
+
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 = a();
|
|
15
15
|
}
|
|
16
16
|
/** Update the end-user id at runtime (e.g. after the user logs in). */
|
|
17
17
|
setUserId(e) {
|
|
@@ -37,25 +37,46 @@ class u {
|
|
|
37
37
|
supportFrameUrl(e, t = "#D97757") {
|
|
38
38
|
return `${this.baseUrl}/support/${encodeURIComponent(this.apiKey)}?theme=${encodeURIComponent(e)}&accent=${encodeURIComponent(t)}`;
|
|
39
39
|
}
|
|
40
|
-
connectSupportFrame(e) {
|
|
41
|
-
const
|
|
42
|
-
var
|
|
43
|
-
return (
|
|
40
|
+
connectSupportFrame(e, t = {}) {
|
|
41
|
+
const s = new URL(this.baseUrl).origin, r = () => {
|
|
42
|
+
var o;
|
|
43
|
+
return (o = e.contentWindow) == null ? void 0 : o.postMessage(
|
|
44
44
|
{
|
|
45
45
|
type: "upstep:support:identity",
|
|
46
46
|
token: this.supportIdentityToken,
|
|
47
|
-
accentColor: getComputedStyle(e).color
|
|
47
|
+
accentColor: getComputedStyle(e).color,
|
|
48
|
+
...t.isVisible ? { visible: t.isVisible() } : {}
|
|
48
49
|
},
|
|
49
|
-
|
|
50
|
+
s
|
|
50
51
|
);
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
}, d = (o) => {
|
|
53
|
+
if (o.origin !== s || o.source !== e.contentWindow)
|
|
54
|
+
return;
|
|
55
|
+
const n = o.data;
|
|
56
|
+
if ((n == null ? void 0 : n.type) === "upstep:support:ready") r();
|
|
57
|
+
else if ((n == null ? void 0 : n.type) === "upstep:support:unread" && t.onUnread) {
|
|
58
|
+
const u = Number(n.count);
|
|
59
|
+
t.onUnread({
|
|
60
|
+
count: Number.isFinite(u) ? Math.max(0, Math.floor(u)) : 0,
|
|
61
|
+
newMessage: n.newMessage === !0,
|
|
62
|
+
author: String(n.author ?? "").slice(0, 80),
|
|
63
|
+
preview: String(n.preview ?? "").slice(0, 200),
|
|
64
|
+
sound: n.sound !== !1
|
|
65
|
+
});
|
|
66
|
+
}
|
|
54
67
|
};
|
|
55
|
-
return e.addEventListener("load",
|
|
56
|
-
e.removeEventListener("load",
|
|
68
|
+
return e.addEventListener("load", r), window.addEventListener("message", d), () => {
|
|
69
|
+
e.removeEventListener("load", r), window.removeEventListener("message", d);
|
|
57
70
|
};
|
|
58
71
|
}
|
|
72
|
+
/** Tell the chat whether it is on screen so it can track unread messages. */
|
|
73
|
+
notifySupportVisibility(e, t) {
|
|
74
|
+
var s;
|
|
75
|
+
(s = e.contentWindow) == null || s.postMessage(
|
|
76
|
+
{ type: "upstep:support:visible", visible: t },
|
|
77
|
+
new URL(this.baseUrl).origin
|
|
78
|
+
);
|
|
79
|
+
}
|
|
59
80
|
async listFeedback(e) {
|
|
60
81
|
const t = new URLSearchParams();
|
|
61
82
|
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);
|
|
@@ -120,5 +141,5 @@ class u {
|
|
|
120
141
|
}
|
|
121
142
|
}
|
|
122
143
|
export {
|
|
123
|
-
|
|
144
|
+
c as U
|
|
124
145
|
};
|
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { Feedback, FeedbackListResponse, FeedbackWithComments, SubmitFeedbackPayload, VotePayload, UpstepConfig } from '@upstep/types';
|
|
2
|
+
/** Unread chat messages reported by the support chat while it is closed or scrolled away. */
|
|
3
|
+
export interface SupportUnread {
|
|
4
|
+
count: number;
|
|
5
|
+
/** True when this report was triggered by a message that just arrived. */
|
|
6
|
+
newMessage: boolean;
|
|
7
|
+
author: string;
|
|
8
|
+
preview: string;
|
|
9
|
+
/** Whether the customer wants a sound for new messages. */
|
|
10
|
+
sound: boolean;
|
|
11
|
+
}
|
|
2
12
|
export declare class UpstepApiClient {
|
|
3
13
|
readonly baseUrl: string;
|
|
4
14
|
readonly apiKey: string;
|
|
@@ -12,7 +22,13 @@ export declare class UpstepApiClient {
|
|
|
12
22
|
private headers;
|
|
13
23
|
supportEnabled(): Promise<boolean>;
|
|
14
24
|
supportFrameUrl(theme: string, accentColor?: string): string;
|
|
15
|
-
connectSupportFrame(frame: HTMLIFrameElement
|
|
25
|
+
connectSupportFrame(frame: HTMLIFrameElement, options?: {
|
|
26
|
+
/** Whether the chat is currently on screen. Lets the chat know when messages are unseen. */
|
|
27
|
+
isVisible?: () => boolean;
|
|
28
|
+
onUnread?: (unread: SupportUnread) => void;
|
|
29
|
+
}): () => void;
|
|
30
|
+
/** Tell the chat whether it is on screen so it can track unread messages. */
|
|
31
|
+
notifySupportVisibility(frame: HTMLIFrameElement, visible: boolean): void;
|
|
16
32
|
listFeedback(params?: {
|
|
17
33
|
cursor?: string;
|
|
18
34
|
limit?: number;
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACb,MAAM,eAAe,CAAC;AAyBvB,qBAAa,eAAe;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE7B,MAAM,EAAE,YAAY;IAShC,uEAAuE;IACvE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAIpC,OAAO,CAAC,OAAO;IAOT,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAYxC,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,SAAY,GAAG,MAAM;IAI/D,mBAAmB,CAAC,KAAK,EAAE,iBAAiB;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACb,MAAM,eAAe,CAAC;AAyBvB,6FAA6F;AAC7F,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,qBAAa,eAAe;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE7B,MAAM,EAAE,YAAY;IAShC,uEAAuE;IACvE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAIpC,OAAO,CAAC,OAAO;IAOT,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAYxC,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,SAAY,GAAG,MAAM;IAI/D,mBAAmB,CACjB,KAAK,EAAE,iBAAiB,EACxB,OAAO,GAAE;QACP,4FAA4F;QAC5F,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;QAC1B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;KACvC;IAqCR,6EAA6E;IAC7E,uBAAuB,CAAC,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO;IAO5D,YAAY,CAAC,MAAM,CAAC,EAAE;QAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACzB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAkB3B,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAcjE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBpE,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAc1D,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAcpD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const b=require("./api-BdOCiCLM.js"),m="#D97757",l={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},u={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function c(s){if(s==="light"||s==="dark")return s;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 x(s,t,e){return`
|
|
2
2
|
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
3
|
-
#upstep-btn{position:fixed;bottom:24px;right:24px;left:auto;z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${
|
|
3
|
+
#upstep-btn{position:fixed;bottom:24px;right:24px;left:auto;z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${s};color:#fff;border:none;border-radius:9999px;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
4
|
#upstep-btn svg{width:16px;height:16px;flex-shrink:0}
|
|
5
5
|
#upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
|
|
6
6
|
@media(max-width:639px){#upstep-btn{padding:12px}#upstep-btn span{display:none}}
|
|
@@ -21,22 +21,22 @@
|
|
|
21
21
|
#upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
|
|
22
22
|
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius:12px;padding:12px;font-size:16px;line-height:1.6;resize:vertical;outline:none;background:${e.bgSoft};color:${e.text};transition:border-color .15s}
|
|
23
23
|
.upstep-form textarea::placeholder{color:${e.textFaint}}
|
|
24
|
-
.upstep-form textarea:focus{border-color:${
|
|
24
|
+
.upstep-form textarea:focus{border-color:${s};background:${e.bg}}
|
|
25
25
|
.upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
|
|
26
26
|
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius:9px;border:1px solid ${e.border};background:${e.bg};color:${e.textSoft};font-size:14px;font-weight:600;cursor:pointer;transition:all .15s}
|
|
27
27
|
.upstep-type-btn svg{width:12px;height:12px;flex-shrink:0}
|
|
28
28
|
.upstep-type-btn:hover{border-color:${e.textFaint}}
|
|
29
|
-
.upstep-type-btn.selected{background:${
|
|
30
|
-
.upstep-submit{width:100%;padding:12px;background:${
|
|
29
|
+
.upstep-type-btn.selected{background:${s};color:#fff;border-color:${s}}
|
|
30
|
+
.upstep-submit{width:100%;padding:12px;background:${s};color:#fff;border:none;border-radius:11px;font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
|
|
31
31
|
.upstep-submit:hover{filter:brightness(.94)}
|
|
32
32
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
33
|
-
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${
|
|
33
|
+
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${s};font-weight:500}
|
|
34
34
|
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius:14px;margin-bottom:10px;background:${e.bg};transition:border-color .15s}
|
|
35
35
|
.upstep-feedback-item:hover{border-color:${e.textFaint}}
|
|
36
36
|
.upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius:11px;border:1px solid ${e.border};background:${e.bgSoft};cursor:pointer;transition:all .15s}
|
|
37
|
-
.upstep-vote:hover{border-color:${
|
|
38
|
-
.upstep-vote.voted{border-color:${
|
|
39
|
-
.upstep-vote-arrow{font-size:11px;line-height:1;color:${
|
|
37
|
+
.upstep-vote:hover{border-color:${s}}
|
|
38
|
+
.upstep-vote.voted{border-color:${s};background:${s}1a}
|
|
39
|
+
.upstep-vote-arrow{font-size:11px;line-height:1;color:${s}}
|
|
40
40
|
.upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
|
|
41
41
|
.upstep-feedback-main{flex:1;min-width:0}
|
|
42
42
|
.upstep-feedback-content{font-size:16px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
|
|
@@ -46,20 +46,28 @@
|
|
|
46
46
|
.upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
|
|
47
47
|
.upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
|
|
48
48
|
.upstep-feedback-date{font-size:11px;color:${e.textFaint}}
|
|
49
|
+
#upstep-btn{position:fixed}
|
|
50
|
+
.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)}
|
|
51
|
+
@keyframes upstep-pop{from{transform:scale(.4)}to{transform:scale(1)}}
|
|
52
|
+
#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:14px 14px 4px 14px;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)}
|
|
53
|
+
#upstep-toast b{font-size:12px}
|
|
54
|
+
#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}
|
|
55
|
+
#upstep-toast em{font-style:normal;font-size:11px;font-weight:600;color:${s}}
|
|
56
|
+
@media(prefers-reduced-motion:reduce){.upstep-unread,#upstep-toast{animation:none}}
|
|
49
57
|
.upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
|
|
50
58
|
.upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
|
|
51
|
-
`}const g='<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 y{constructor(t,e={}){this.isOpen=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.hasSupport=!1,this.disconnectSupport=null,this.client=t,this.accent=e.accentColor??
|
|
59
|
+
`}const g='<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 y{constructor(t,e={}){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.accent=e.accentColor??m,this.position="right",this.showLauncher=e.launcher!==!1,this.themeMode=e.theme??"auto",this.palette=c(this.themeMode)==="dark"?u:l}mount(){this.injectStyles(),this.showLauncher&&this.renderButton(),this.client.supportEnabled().then(t=>{if(this.hasSupport=t,t){const e=document.querySelector("#upstep-btn span");e&&(e.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 e;(e=document.getElementById("upstep-styles"))==null||e.remove();const t=document.createElement("style");t.id="upstep-styles",t.textContent=x(this.accent,this.position,this.palette),document.head.appendChild(t)}renderButton(){const t=document.createElement("button");t.id="upstep-btn",t.setAttribute("aria-label","Open help and feedback"),t.innerHTML=`${g}<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=c(this.themeMode),e=document.getElementById("upstep-backdrop"),o=this.supportFrame();if(!this.isOpen&&e&&o&&e.style.display==="none"&&this.frameTheme===t){this.isOpen=!0,e.style.display="",this.client.notifySupportVisibility(o,!0),this.setUnread(0),this.fetchFeed();return}this.isOpen=!0,this.palette=t==="dark"?u:l,this.injectStyles(),this.fetchFeed(),this.renderModal(),this.setUnread(0)}closeModal(){var t,e;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,(e=document.getElementById("upstep-backdrop"))==null||e.remove()}setUnread(t){this.unread=t;const e=document.getElementById("upstep-btn"),o=e==null?void 0:e.querySelector(".upstep-unread");if(e){if(t>0){const n=o??document.createElement("span");n.className="upstep-unread",n.textContent=t>9?"9+":String(t),o||e.appendChild(n)}else o==null||o.remove();e.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 e=document.createElement("button");e.id="upstep-toast",e.type="button",e.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",e.append(o,i,n),e.addEventListener("click",()=>this.openModal()),document.body.appendChild(e),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 e=t.currentTime;for(const[o,i]of[[880,0],[1318,.12]]){const n=t.createOscillator(),p=t.createGain();n.type="sine",n.frequency.value=o,p.gain.setValueAtTime(1e-4,e+i),p.gain.exponentialRampToValueAtTime(.14,e+i+.02),p.gain.exponentialRampToValueAtTime(1e-4,e+i+.5),n.connect(p),p.connect(t.destination),n.start(e+i),n.stop(e+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,p;(i=this.disconnectSupport)==null||i.call(this),this.disconnectSupport=null;const e=document.createElement("div");e.id="upstep-backdrop",e.addEventListener("click",a=>{a.target===e&&this.closeModal()}),e.innerHTML=`
|
|
52
60
|
<div id="upstep-modal" style="max-width:${this.hasSupport?"460px":"440px"}">
|
|
53
61
|
${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
62
|
<div id="upstep-body" style="${this.tab==="support"?"padding:0;overflow:hidden":""}">
|
|
55
63
|
${this.tab==="support"?`<iframe id="upstep-support-frame" title="Customer support" src="${this.client.supportFrameUrl(this.palette.bg==="#000000"?"dark":"light",this.accent)}" 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
64
|
</div>
|
|
57
65
|
</div>
|
|
58
|
-
`,(
|
|
66
|
+
`,(n=document.getElementById("upstep-backdrop"))==null||n.remove(),t&&(e.style.display="none"),document.body.appendChild(e),(p=e.querySelector("#upstep-close"))==null||p.addEventListener("click",()=>this.closeModal()),e.querySelectorAll(".upstep-tab").forEach(a=>{a.addEventListener("click",()=>{this.tab=a.dataset.tab,this.renderModal()})});const o=e.querySelector("#upstep-support-frame");o&&(o.style.color=this.accent,this.frameTheme=this.palette.bg==="#000000"?"dark":"light",this.disconnectSupport=this.client.connectSupportFrame(o,{isVisible:()=>this.isOpen,onUnread:a=>this.onSupportUnread(a)})),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){const t=["BUG","FEATURE","GENERAL"],e={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
67
|
<div class="upstep-form">
|
|
60
68
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
61
69
|
<div class="upstep-type-row">
|
|
62
|
-
${t.map(
|
|
70
|
+
${t.map(i=>`<button class="upstep-type-btn${this.selectedType===i?" selected":""}" data-type="${i}">${o[i]}${e[i]}</button>`).join("")}
|
|
63
71
|
</div>
|
|
64
72
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
65
73
|
<div id="upstep-form-msg"></div>
|
|
@@ -71,11 +79,11 @@
|
|
|
71
79
|
<span class="upstep-vote-count">${t.upvotes}</span>
|
|
72
80
|
</button>
|
|
73
81
|
<div class="upstep-feedback-main">
|
|
74
|
-
<p class="upstep-feedback-content">${
|
|
82
|
+
<p class="upstep-feedback-content">${h(t.content)}</p>
|
|
75
83
|
<div class="upstep-feedback-meta">
|
|
76
84
|
<span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
|
|
77
|
-
<span class="upstep-badge upstep-badge-general">${
|
|
85
|
+
<span class="upstep-badge upstep-badge-general">${h(((e=t.boardStatus)==null?void 0:e.name)??t.status.replace("_"," "))}</span>
|
|
78
86
|
<span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
|
|
79
87
|
</div>
|
|
80
88
|
</div>
|
|
81
|
-
</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(e=>{e.addEventListener("click",()=>{this.selectedType=e.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(
|
|
89
|
+
</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(e=>{e.addEventListener("click",()=>{this.selectedType=e.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(o=>o.classList.remove("selected")),e.classList.add("selected")})}),(t=document.getElementById("upstep-submit-btn"))==null||t.addEventListener("click",async()=>{const e=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),i=document.getElementById("upstep-submit-btn");if(!e||this.loading)return;const n=e.value.trim();if(n){this.loading=!0,i&&(i.disabled=!0,i.textContent="Sending…");try{await this.client.submitFeedback({content:n,type:this.selectedType}),e.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 e=t.dataset.feedback;try{await this.client.vote(e,"UP"),await this.fetchFeed()}catch{}})})}}function h(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let d=null,r=null;const f={init(s){if(d=new b.UpstepApiClient(s),typeof window<"u"){const t={};s.accentColor!==void 0&&(t.accentColor=s.accentColor),s.position!==void 0&&(t.position=s.position),s.theme!==void 0&&(t.theme=s.theme),s.launcher!==void 0&&(t.launcher=s.launcher);const e=()=>{r=new y(d,t),r.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()}return d},open(){r==null||r.openWidget()},close(){r==null||r.closeWidget()},identify(s){d==null||d.setUserId(s)},identifySupport(s){var e;d&&(d.supportIdentityToken=s);const t=document.querySelector("#upstep-support-frame");t&&d&&((e=t.contentWindow)==null||e.postMessage({type:"upstep:support:identity",token:s,visible:(r==null?void 0:r.isChatVisible())??!0},new URL(d.baseUrl).origin))},onUnread(s){return(r==null?void 0:r.onUnread(s))??(()=>{})},get client(){if(!d)throw new Error("Upstep.init() must be called first");return d}};if(typeof document<"u"){const s=document.currentScript,t=s==null?void 0:s.dataset.apiKey,e=s==null?void 0:s.dataset.userId,o=s==null?void 0:s.dataset.baseUrl,i=s==null?void 0:s.dataset.accentColor,n=s==null?void 0:s.dataset.position,p=s==null?void 0:s.dataset.theme;if(t){const a={apiKey:t};e&&(a.userId=e),(s==null?void 0:s.dataset.chat)!==void 0&&(a.chat=s.dataset.chat!=="false"),o&&(a.baseUrl=o),i&&(a.accentColor=i),(n==="left"||n==="right")&&(a.position=n),(p==="light"||p==="dark"||p==="auto")&&(a.theme=p),f.init(a)}}exports.UpstepApiClient=b.UpstepApiClient;exports.default=f;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ declare const Upstep: {
|
|
|
12
12
|
identify(userId: string | undefined): void;
|
|
13
13
|
/** Change or clear verified support identity after login/logout. */
|
|
14
14
|
identifySupport(token: string | undefined): void;
|
|
15
|
+
/** Subscribe to the number of unread support messages, e.g. to drive your own launcher badge. */
|
|
16
|
+
onUnread(listener: (count: number) => void): () => void;
|
|
15
17
|
readonly client: UpstepApiClient;
|
|
16
18
|
};
|
|
17
19
|
export default Upstep;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGxC,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;AAK3B,QAAA,MAAM,MAAM;iBACG,YAAY;IAqBzB,0EAA0E;;IAK1E,iCAAiC;;IAKjC,6EAA6E;qBAC5D,MAAM,GAAG,SAAS;IAInC,oEAAoE;2BAC7C,MAAM,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGxC,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;AAK3B,QAAA,MAAM,MAAM;iBACG,YAAY;IAqBzB,0EAA0E;;IAK1E,iCAAiC;;IAKjC,6EAA6E;qBAC5D,MAAM,GAAG,SAAS;IAInC,oEAAoE;2BAC7C,MAAM,GAAG,SAAS;IAMzC,iGAAiG;uBAC9E,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;qBAI5B,eAAe;CAI9B,CAAC;AAEF,eAAe,MAAM,CAAC"}
|