@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/support.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(a,t){if(t===null)return[];const e=a.filter(n=>n.role!=="SYSTEM"),s=e.findIndex(n=>n.id===t);return s<0?[]:e.slice(s+1).filter(n=>n.role!=="CUSTOMER")}function d(a,t=120){const e=a.replace(/\s+/g," ").trim();return e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e}class c extends Error{constructor(t,e){super(t),this.status=e}}function h(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const t=Math.floor(Math.random()*16);return(a==="x"?t:t&3|8).toString(16)})}class y{constructor(t,e,s=fetch){this.storage=e,this.transport=s,this.token=null,this.session=null,this.epoch=0,this.baseUrl=(t.baseUrl||"https://upstep.dev").replace(/\/$/,""),this.key=t.apiKey,this.identityToken=t.supportIdentityToken,this.storageKey=`upstep:support:${this.baseUrl}:${this.key}`,this.seenKey=`upstep:support-seen:${this.baseUrl}:${this.key}`,this.soundKey=`upstep:support-sound:${this.baseUrl}:${this.key}`}async identify(t){var e;t!==this.identityToken&&(this.epoch++,this.identityToken=t,this.token=null,this.session=null,await((e=this.storage)==null?void 0:e.removeItem(this.storageKey).catch(()=>{})))}async request(t,e){var i;const s=new AbortController,n=setTimeout(()=>s.abort(),2e4);try{const o=await this.transport(`${this.baseUrl}/api/sdk/support${t}`,{method:e===void 0?"GET":"POST",headers:{"Content-Type":"application/json","x-api-key":this.key,...this.token?{Authorization:`Bearer ${this.token}`}:{}},...e===void 0?{}:{body:JSON.stringify(e)},credentials:"omit",redirect:"error",signal:s.signal}),r=await o.json();if(!o.ok)throw o.status===401&&t&&(this.token=null,await((i=this.storage)==null?void 0:i.removeItem(this.storageKey).catch(()=>{}))),new c(typeof r.error=="string"?r.error:"Could not connect to support.",o.status);return r}finally{clearTimeout(n)}}async configuration(){try{return await this.request("")}catch(t){if(t instanceof c&&[402,404].includes(t.status))return null;throw t}}async ensureSession(){if(!this.token){if(!this.session){const t=this.epoch,e=this.identityToken,s=(async()=>{var i,o;if(!e)try{const r=await((i=this.storage)==null?void 0:i.getItem(this.storageKey));if(r&&t===this.epoch){this.token=r;return}}catch{}if(t!==this.epoch)throw new Error("Customer identity changed.");const n=await this.request("",e?{identityToken:e}:{});if(t!==this.epoch)throw new Error("Customer identity changed.");this.token=n.token,e||await((o=this.storage)==null?void 0:o.setItem(this.storageKey,n.token).catch(()=>{}))})();this.session=s,s.finally(()=>{this.session===s&&(this.session=null)}).catch(()=>{})}await this.session}}async conversations(){return await this.ensureSession(),(await this.request("/conversations")).conversations}async startConversation(){return await this.ensureSession(),this.request("/conversations",{})}async conversation(t){return await this.ensureSession(),this.request(`/conversations/${encodeURIComponent(t)}`)}async send(t,e,s=h()){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"message",content:e,clientMessageId:s})}async details(t,e){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"details",...e,clientMessageId:e.clientMessageId||h()})}async handoff(t,e,s){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"handoff",name:e,email:s})}async hasSession(){var t;if(this.token||this.identityToken)return!0;try{return!!await((t=this.storage)==null?void 0:t.getItem(this.storageKey))}catch{return!1}}async seenId(t){var e;try{const s=JSON.parse(await((e=this.storage)==null?void 0:e.getItem(this.seenKey))||"null");return(s==null?void 0:s.chat)===t?s.id:null}catch{return null}}async markSeen(t){var n;const e=t.messages.filter(i=>i.role!=="SYSTEM").at(-1);if(!e)return;const s={chat:t.id,id:e.id};await((n=this.storage)==null?void 0:n.setItem(this.seenKey,JSON.stringify(s)).catch(()=>{}))}async unread(){var u;const t={count:0,chatId:null};if(!await this.hasSession())return t;const e=(await this.conversations())[0];if(!e)return t;const s=await this.conversation(e.id);if(!s.messages.filter(p=>p.role!=="SYSTEM").at(-1))return{count:0,chatId:s.id};let i=null;try{i=JSON.parse(await((u=this.storage)==null?void 0:u.getItem(this.seenKey))||"null")}catch{i=null}if((i==null?void 0:i.chat)!==s.id)return await this.markSeen(s),{count:0,chatId:s.id};const o=l(s.messages,i.id),r=o.at(-1);return{count:o.length,chatId:s.id,...r?{latest:{author:r.role==="ASSISTANT"?"AI":r.authorName,role:r.role,preview:d(r.content)}}:{}}}async soundEnabled(){var t;try{return await((t=this.storage)==null?void 0:t.getItem(this.soundKey))!=="off"}catch{return!0}}async setSoundEnabled(t){var e;await((e=this.storage)==null?void 0:e.setItem(this.soundKey,t?"on":"off").catch(()=>{}))}}exports.SupportApiError=c;exports.SupportClient=y;exports.supportMessageId=h;exports.supportPreview=d;exports.unreadSupportMessages=l;
|
package/dist/support.d.ts
CHANGED
|
@@ -4,6 +4,22 @@ export interface SupportStorage {
|
|
|
4
4
|
setItem(key: string, value: string): Promise<void>;
|
|
5
5
|
removeItem(key: string): Promise<void>;
|
|
6
6
|
}
|
|
7
|
+
/** What a customer has not read yet in their latest conversation. */
|
|
8
|
+
export interface SupportUnreadSummary {
|
|
9
|
+
count: number;
|
|
10
|
+
chatId: string | null;
|
|
11
|
+
latest?: {
|
|
12
|
+
author: string;
|
|
13
|
+
role: string;
|
|
14
|
+
preview: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Incoming AI or team messages after the given message. System notes and the customer's own messages never count. */
|
|
18
|
+
export declare function unreadSupportMessages<T extends {
|
|
19
|
+
id: string;
|
|
20
|
+
role: string;
|
|
21
|
+
}>(messages: T[], seenId: string | null): T[];
|
|
22
|
+
export declare function supportPreview(text: string, max?: number): string;
|
|
7
23
|
export declare class SupportApiError extends Error {
|
|
8
24
|
readonly status: number;
|
|
9
25
|
constructor(message: string, status: number);
|
|
@@ -20,6 +36,8 @@ export declare class SupportClient {
|
|
|
20
36
|
private readonly baseUrl;
|
|
21
37
|
private readonly key;
|
|
22
38
|
private readonly storageKey;
|
|
39
|
+
private readonly seenKey;
|
|
40
|
+
private readonly soundKey;
|
|
23
41
|
constructor(config: Pick<UpstepConfig, "apiKey" | "baseUrl" | "supportIdentityToken">, storage?: SupportStorage | undefined, transport?: typeof fetch);
|
|
24
42
|
identify(token: string | undefined): Promise<void>;
|
|
25
43
|
private request;
|
|
@@ -43,5 +61,18 @@ export declare class SupportClient {
|
|
|
43
61
|
clientMessageId?: string;
|
|
44
62
|
}): Promise<void>;
|
|
45
63
|
handoff(id: string, name: string, email: string): Promise<void>;
|
|
64
|
+
/** True when this customer already has a support session, so checking for replies creates nothing new. */
|
|
65
|
+
hasSession(): Promise<boolean>;
|
|
66
|
+
/** The last message the customer has read in a conversation, if one was recorded. */
|
|
67
|
+
seenId(chatId: string): Promise<string | null>;
|
|
68
|
+
/** Record that the customer has read everything in this conversation. */
|
|
69
|
+
markSeen(conversation: SupportConversation): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Unread AI or team messages in the latest conversation. A conversation with
|
|
72
|
+
* no saved record counts as read, so returning customers never see a stale count.
|
|
73
|
+
*/
|
|
74
|
+
unread(): Promise<SupportUnreadSummary>;
|
|
75
|
+
soundEnabled(): Promise<boolean>;
|
|
76
|
+
setSoundEnabled(enabled: boolean): Promise<void>;
|
|
46
77
|
}
|
|
47
78
|
//# sourceMappingURL=support.d.ts.map
|
package/dist/support.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../src/support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AACD,qBAAa,eAAgB,SAAQ,KAAK;IAGtC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADvB,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM;CAI1B;AACD,wBAAgB,gBAAgB,WAK/B;AACD,6EAA6E;AAC7E,qBAAa,aAAa;
|
|
1
|
+
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../src/support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI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|
3
|
-
|
|
1
|
+
function d(a, t) {
|
|
2
|
+
if (t === null) return [];
|
|
3
|
+
const e = a.filter((n) => n.role !== "SYSTEM"), s = e.findIndex((n) => n.id === t);
|
|
4
|
+
return s < 0 ? [] : e.slice(s + 1).filter((n) => n.role !== "CUSTOMER");
|
|
5
|
+
}
|
|
6
|
+
function y(a, t = 120) {
|
|
7
|
+
const e = a.replace(/\s+/g, " ").trim();
|
|
8
|
+
return e.length > t ? `${e.slice(0, t - 1).trimEnd()}…` : e;
|
|
9
|
+
}
|
|
10
|
+
class c extends Error {
|
|
11
|
+
constructor(t, e) {
|
|
12
|
+
super(t), this.status = e;
|
|
4
13
|
}
|
|
5
14
|
}
|
|
6
|
-
function
|
|
15
|
+
function u() {
|
|
7
16
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (a) => {
|
|
8
17
|
const t = Math.floor(Math.random() * 16);
|
|
9
18
|
return (a === "x" ? t : t & 3 | 8).toString(16);
|
|
10
19
|
});
|
|
11
20
|
}
|
|
12
|
-
class
|
|
13
|
-
constructor(t,
|
|
14
|
-
this.storage =
|
|
21
|
+
class p {
|
|
22
|
+
constructor(t, e, s = fetch) {
|
|
23
|
+
this.storage = e, this.transport = s, this.token = null, this.session = null, this.epoch = 0, this.baseUrl = (t.baseUrl || "https://upstep.dev").replace(/\/$/, ""), this.key = t.apiKey, this.identityToken = t.supportIdentityToken, this.storageKey = `upstep:support:${this.baseUrl}:${this.key}`, this.seenKey = `upstep:support-seen:${this.baseUrl}:${this.key}`, this.soundKey = `upstep:support-sound:${this.baseUrl}:${this.key}`;
|
|
15
24
|
}
|
|
16
25
|
async identify(t) {
|
|
17
|
-
var
|
|
18
|
-
t !== this.identityToken && (this.epoch++, this.identityToken = t, this.token = null, this.session = null, await ((
|
|
26
|
+
var e;
|
|
27
|
+
t !== this.identityToken && (this.epoch++, this.identityToken = t, this.token = null, this.session = null, await ((e = this.storage) == null ? void 0 : e.removeItem(this.storageKey).catch(() => {
|
|
19
28
|
})));
|
|
20
29
|
}
|
|
21
|
-
async request(t,
|
|
22
|
-
var
|
|
23
|
-
const
|
|
30
|
+
async request(t, e) {
|
|
31
|
+
var i;
|
|
32
|
+
const s = new AbortController(), n = setTimeout(() => s.abort(), 2e4);
|
|
24
33
|
try {
|
|
25
|
-
const
|
|
26
|
-
method:
|
|
34
|
+
const o = await this.transport(`${this.baseUrl}/api/sdk/support${t}`, {
|
|
35
|
+
method: e === void 0 ? "GET" : "POST",
|
|
27
36
|
headers: {
|
|
28
37
|
"Content-Type": "application/json",
|
|
29
38
|
"x-api-key": this.key,
|
|
30
39
|
...this.token ? { Authorization: `Bearer ${this.token}` } : {}
|
|
31
40
|
},
|
|
32
|
-
...
|
|
41
|
+
...e === void 0 ? {} : { body: JSON.stringify(e) },
|
|
33
42
|
credentials: "omit",
|
|
34
43
|
redirect: "error",
|
|
35
|
-
signal:
|
|
36
|
-
}),
|
|
37
|
-
if (!
|
|
38
|
-
throw
|
|
39
|
-
}))), new
|
|
40
|
-
typeof
|
|
41
|
-
|
|
44
|
+
signal: s.signal
|
|
45
|
+
}), r = await o.json();
|
|
46
|
+
if (!o.ok)
|
|
47
|
+
throw o.status === 401 && t && (this.token = null, await ((i = this.storage) == null ? void 0 : i.removeItem(this.storageKey).catch(() => {
|
|
48
|
+
}))), new c(
|
|
49
|
+
typeof r.error == "string" ? r.error : "Could not connect to support.",
|
|
50
|
+
o.status
|
|
42
51
|
);
|
|
43
|
-
return
|
|
52
|
+
return r;
|
|
44
53
|
} finally {
|
|
45
|
-
clearTimeout(
|
|
54
|
+
clearTimeout(n);
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
57
|
async configuration() {
|
|
49
58
|
try {
|
|
50
59
|
return await this.request("");
|
|
51
60
|
} catch (t) {
|
|
52
|
-
if (t instanceof
|
|
61
|
+
if (t instanceof c && [402, 404].includes(t.status))
|
|
53
62
|
return null;
|
|
54
63
|
throw t;
|
|
55
64
|
}
|
|
@@ -57,28 +66,28 @@ class u {
|
|
|
57
66
|
async ensureSession() {
|
|
58
67
|
if (!this.token) {
|
|
59
68
|
if (!this.session) {
|
|
60
|
-
const t = this.epoch,
|
|
61
|
-
var
|
|
62
|
-
if (!
|
|
69
|
+
const t = this.epoch, e = this.identityToken, s = (async () => {
|
|
70
|
+
var i, o;
|
|
71
|
+
if (!e)
|
|
63
72
|
try {
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
this.token =
|
|
73
|
+
const r = await ((i = this.storage) == null ? void 0 : i.getItem(this.storageKey));
|
|
74
|
+
if (r && t === this.epoch) {
|
|
75
|
+
this.token = r;
|
|
67
76
|
return;
|
|
68
77
|
}
|
|
69
78
|
} catch {
|
|
70
79
|
}
|
|
71
80
|
if (t !== this.epoch) throw new Error("Customer identity changed.");
|
|
72
|
-
const
|
|
81
|
+
const n = await this.request(
|
|
73
82
|
"",
|
|
74
|
-
|
|
83
|
+
e ? { identityToken: e } : {}
|
|
75
84
|
);
|
|
76
85
|
if (t !== this.epoch) throw new Error("Customer identity changed.");
|
|
77
|
-
this.token =
|
|
86
|
+
this.token = n.token, e || await ((o = this.storage) == null ? void 0 : o.setItem(this.storageKey, n.token).catch(() => {
|
|
78
87
|
}));
|
|
79
88
|
})();
|
|
80
|
-
this.session =
|
|
81
|
-
this.session ===
|
|
89
|
+
this.session = s, s.finally(() => {
|
|
90
|
+
this.session === s && (this.session = null);
|
|
82
91
|
}).catch(() => {
|
|
83
92
|
});
|
|
84
93
|
}
|
|
@@ -98,30 +107,109 @@ class u {
|
|
|
98
107
|
`/conversations/${encodeURIComponent(t)}`
|
|
99
108
|
);
|
|
100
109
|
}
|
|
101
|
-
async send(t,
|
|
110
|
+
async send(t, e, s = u()) {
|
|
102
111
|
await this.ensureSession(), await this.request(`/conversations/${encodeURIComponent(t)}`, {
|
|
103
112
|
action: "message",
|
|
104
|
-
content:
|
|
105
|
-
clientMessageId:
|
|
113
|
+
content: e,
|
|
114
|
+
clientMessageId: s
|
|
106
115
|
});
|
|
107
116
|
}
|
|
108
|
-
async details(t,
|
|
117
|
+
async details(t, e) {
|
|
109
118
|
await this.ensureSession(), await this.request(`/conversations/${encodeURIComponent(t)}`, {
|
|
110
119
|
action: "details",
|
|
111
|
-
...
|
|
112
|
-
clientMessageId:
|
|
120
|
+
...e,
|
|
121
|
+
clientMessageId: e.clientMessageId || u()
|
|
113
122
|
});
|
|
114
123
|
}
|
|
115
|
-
async handoff(t,
|
|
124
|
+
async handoff(t, e, s) {
|
|
116
125
|
await this.ensureSession(), await this.request(`/conversations/${encodeURIComponent(t)}`, {
|
|
117
126
|
action: "handoff",
|
|
118
|
-
name:
|
|
119
|
-
email:
|
|
127
|
+
name: e,
|
|
128
|
+
email: s
|
|
120
129
|
});
|
|
121
130
|
}
|
|
131
|
+
/** True when this customer already has a support session, so checking for replies creates nothing new. */
|
|
132
|
+
async hasSession() {
|
|
133
|
+
var t;
|
|
134
|
+
if (this.token || this.identityToken) return !0;
|
|
135
|
+
try {
|
|
136
|
+
return !!await ((t = this.storage) == null ? void 0 : t.getItem(this.storageKey));
|
|
137
|
+
} catch {
|
|
138
|
+
return !1;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** The last message the customer has read in a conversation, if one was recorded. */
|
|
142
|
+
async seenId(t) {
|
|
143
|
+
var e;
|
|
144
|
+
try {
|
|
145
|
+
const s = JSON.parse(
|
|
146
|
+
await ((e = this.storage) == null ? void 0 : e.getItem(this.seenKey)) || "null"
|
|
147
|
+
);
|
|
148
|
+
return (s == null ? void 0 : s.chat) === t ? s.id : null;
|
|
149
|
+
} catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Record that the customer has read everything in this conversation. */
|
|
154
|
+
async markSeen(t) {
|
|
155
|
+
var n;
|
|
156
|
+
const e = t.messages.filter((i) => i.role !== "SYSTEM").at(-1);
|
|
157
|
+
if (!e) return;
|
|
158
|
+
const s = { chat: t.id, id: e.id };
|
|
159
|
+
await ((n = this.storage) == null ? void 0 : n.setItem(this.seenKey, JSON.stringify(s)).catch(() => {
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Unread AI or team messages in the latest conversation. A conversation with
|
|
164
|
+
* no saved record counts as read, so returning customers never see a stale count.
|
|
165
|
+
*/
|
|
166
|
+
async unread() {
|
|
167
|
+
var h;
|
|
168
|
+
const t = { count: 0, chatId: null };
|
|
169
|
+
if (!await this.hasSession()) return t;
|
|
170
|
+
const e = (await this.conversations())[0];
|
|
171
|
+
if (!e) return t;
|
|
172
|
+
const s = await this.conversation(e.id);
|
|
173
|
+
if (!s.messages.filter((l) => l.role !== "SYSTEM").at(-1)) return { count: 0, chatId: s.id };
|
|
174
|
+
let i = null;
|
|
175
|
+
try {
|
|
176
|
+
i = JSON.parse(await ((h = this.storage) == null ? void 0 : h.getItem(this.seenKey)) || "null");
|
|
177
|
+
} catch {
|
|
178
|
+
i = null;
|
|
179
|
+
}
|
|
180
|
+
if ((i == null ? void 0 : i.chat) !== s.id)
|
|
181
|
+
return await this.markSeen(s), { count: 0, chatId: s.id };
|
|
182
|
+
const o = d(s.messages, i.id), r = o.at(-1);
|
|
183
|
+
return {
|
|
184
|
+
count: o.length,
|
|
185
|
+
chatId: s.id,
|
|
186
|
+
...r ? {
|
|
187
|
+
latest: {
|
|
188
|
+
author: r.role === "ASSISTANT" ? "AI" : r.authorName,
|
|
189
|
+
role: r.role,
|
|
190
|
+
preview: y(r.content)
|
|
191
|
+
}
|
|
192
|
+
} : {}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
async soundEnabled() {
|
|
196
|
+
var t;
|
|
197
|
+
try {
|
|
198
|
+
return await ((t = this.storage) == null ? void 0 : t.getItem(this.soundKey)) !== "off";
|
|
199
|
+
} catch {
|
|
200
|
+
return !0;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async setSoundEnabled(t) {
|
|
204
|
+
var e;
|
|
205
|
+
await ((e = this.storage) == null ? void 0 : e.setItem(this.soundKey, t ? "on" : "off").catch(() => {
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
122
208
|
}
|
|
123
209
|
export {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
210
|
+
c as SupportApiError,
|
|
211
|
+
p as SupportClient,
|
|
212
|
+
u as supportMessageId,
|
|
213
|
+
y as supportPreview,
|
|
214
|
+
d as unreadSupportMessages
|
|
127
215
|
};
|
package/dist/theme.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="#C9481F",F="#FF7A50",L=g;function R(t){return t==="dark"?F:g}const A=12,$=32,U=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,d="(\\d{1,3}(?:\\.\\d+)?)",M="(\\d*\\.?\\d+%?)",H=new RegExp(`^rgba?\\(\\s*${d}\\s*(?:,\\s*${d}\\s*,\\s*${d}\\s*(?:,\\s*${M}\\s*)?|\\s+${d}\\s+${d}\\s*(?:\\/\\s*${M}\\s*)?)\\)$`,"i");function i(t){if(typeof t!="string"||t.length>64)return null;const r=t.trim();if(U.test(r)){let u=r.slice(1);u.length<=4&&(u=u.split("").map(f=>f+f).join(""));const b=f=>parseInt(u.slice(f,f+2),16);return[b(0),b(2),b(4),u.length===8?Math.round(b(6)/255*1e3)/1e3:1]}const e=H.exec(r);if(!e)return null;const[n,o,c,a]=[e[1],e[2]??e[5],e[3]??e[6],e[4]??e[7]],s=[n,o,c].map(Number);if(s.some(u=>!(u>=0&&u<=255)))return null;let l=1;return a!==void 0&&(l=a.endsWith("%")?Number(a.slice(0,-1))/100:Number(a),!(l>=0&&l<=1))?null:[s[0],s[1],s[2],l]}function D(t){return i(t)!==null}function T([t,r,e,n]){const o=c=>Math.round(Math.min(255,Math.max(0,c))).toString(16).padStart(2,"0");return`#${o(t)}${o(r)}${o(e)}${n<1?o(n*255):""}`}function N(t,r,e){const n=i(t),o=i(r);if(!n||!o)return null;const c=Math.min(1,Math.max(0,e));return T([n[0]+(o[0]-n[0])*c,n[1]+(o[1]-n[1])*c,n[2]+(o[2]-n[2])*c,n[3]+(o[3]-n[3])*c])}function p(t,r){const e=i(t);return e?T([e[0],e[1],e[2],e[3]*r]):null}function S([t,r,e]){const n=o=>{const c=o/255;return c<=.03928?c/12.92:((c+.055)/1.055)**2.4};return .2126*n(t)+.7152*n(r)+.0722*n(e)}function x(t,r){const e=i(t),n=i(r);if(!e||!n)return null;const[o,c]=[S(e),S(n)].sort((a,s)=>s-a);return(o+.05)/(c+.05)}const m="#ffffff",E="#1a1915";function v(t){const r=x(t,m);return r===null||r>=3?m:(x(t,E)??0)>r?E:m}function h(t){const r=typeof t=="number"?t:Number(t);return t==null||t===""||!Number.isFinite(r)?A:Math.round(Math.min($,Math.max(0,r)))}function k(t,r){return Math.round(t*r/A)}const y=["background","surface","border","text","textMuted","accentText"];function C(t,r){const e={};if(!t)return e;for(const n of[t,t[r]])if(n)for(const o of y){const c=n[o];typeof c=="string"&&c.trim()&&(e[o]=c.trim())}return e}const I={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},O={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function _(t,r,e){return N(t,r,e)??`color-mix(in srgb, ${t} ${Math.round((1-e)*100)}%, ${r})`}function P(t){var s;const r=t.mode==="dark"?O:I,e=C(t.colors,t.mode),n=((s=t.accentColor)==null?void 0:s.trim())||R(t.mode),o=e.background??r.bg,c=e.text??r.text,a=e.surface??r.bgSoft;return{dark:t.mode==="dark",bg:o,bgSoft:a,bgHover:e.surface||e.text?_(a,c,.06):r.bgHover,text:c,textSoft:e.textMuted??r.textSoft,textFaint:e.textMuted||e.background?_(e.textMuted??r.textSoft,o,.4):r.textFaint,border:e.border??r.border,overlay:r.overlay,accent:n,accentText:e.accentText??v(n),accentTint:p(n,.1)??`color-mix(in srgb, ${n} 10%, transparent)`,radius:h(t.radius)}}function G(t){var o;const r=C(t.colors,t.mode),e={},n={background:"bg",surface:"surface",border:"border",text:"text",textMuted:"muted",accentText:"accentText"};for(const c of y){const a=r[c];D(a)&&(e[n[c]]=a)}return t.radius!==void 0&&(e.radius=String(h(t.radius))),(o=t.fontFamily)!=null&&o.trim()&&(e.font=t.fontFamily.trim()),e}exports.DEFAULT_ACCENT=L;exports.DEFAULT_ACCENT_DARK=F;exports.DEFAULT_ACCENT_LIGHT=g;exports.DEFAULT_RADIUS=A;exports.MAX_RADIUS=$;exports.buildWidgetPalette=P;exports.clampRadius=h;exports.contrastRatio=x;exports.defaultAccent=R;exports.formatHex=T;exports.isSupportedColor=D;exports.mixColors=N;exports.parseColor=i;exports.readableTextOn=v;exports.resolveColorOverrides=C;exports.scaleRadius=k;exports.supportThemeParams=G;exports.withAlpha=p;
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { UpstepColorOverrides, UpstepThemeColors } from '@upstep/types';
|
|
2
|
+
/** Brand orange for light panels; white text reads on it. */
|
|
3
|
+
export declare const DEFAULT_ACCENT_LIGHT = "#C9481F";
|
|
4
|
+
/** Brighter brand orange for dark panels; dark text reads on it. */
|
|
5
|
+
export declare const DEFAULT_ACCENT_DARK = "#FF7A50";
|
|
6
|
+
/** The light-mode default, kept for callers that need a single color. */
|
|
7
|
+
export declare const DEFAULT_ACCENT = "#C9481F";
|
|
8
|
+
/** The accent to use: the host's own, or the brand default for the mode. */
|
|
9
|
+
export declare function defaultAccent(mode: "light" | "dark"): string;
|
|
10
|
+
/** Base corner radius in px. Every other corner in the widgets scales from it. */
|
|
11
|
+
export declare const DEFAULT_RADIUS = 12;
|
|
12
|
+
export declare const MAX_RADIUS = 32;
|
|
13
|
+
/** Red, green, blue in 0–255 and alpha in 0–1. */
|
|
14
|
+
export type Rgba = [number, number, number, number];
|
|
15
|
+
/** Parses hex (#rgb, #rgba, #rrggbb, #rrggbbaa) and rgb()/rgba() colors. Anything else is null. */
|
|
16
|
+
export declare function parseColor(input: unknown): Rgba | null;
|
|
17
|
+
/** Whether a value is a hex or rgb color, the only formats every SDK and the support chat accept. */
|
|
18
|
+
export declare function isSupportedColor(input: unknown): input is string;
|
|
19
|
+
export declare function formatHex([r, g, b, a]: Rgba): string;
|
|
20
|
+
/** Blends `amount` (0–1) of `toward` into `color`. Null if either color can't be parsed. */
|
|
21
|
+
export declare function mixColors(color: string, toward: string, amount: number): string | null;
|
|
22
|
+
/** The color at the given opacity. Null if it can't be parsed. */
|
|
23
|
+
export declare function withAlpha(color: string, alpha: number): string | null;
|
|
24
|
+
/** WCAG contrast ratio between two opaque colors (1–21). Null if either can't be parsed. */
|
|
25
|
+
export declare function contrastRatio(a: string, b: string): number | null;
|
|
26
|
+
/**
|
|
27
|
+
* Text color for a filled accent surface. White while it keeps at least 3:1
|
|
28
|
+
* contrast (WCAG's bar for bold UI text), otherwise whichever of white or
|
|
29
|
+
* near-black reads better. Unparseable accents get white, as before.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readableTextOn(background: string): string;
|
|
32
|
+
/** Clamps a radius to 0–32 px. Missing or invalid values give the default. */
|
|
33
|
+
export declare function clampRadius(value: unknown): number;
|
|
34
|
+
/** Scales one of the widget's built-in radii (designed for the 12 px default) to the chosen radius. */
|
|
35
|
+
export declare function scaleRadius(designed: number, radius: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Flattens `colors` for one mode: top-level keys, then that mode's keys on top.
|
|
38
|
+
* Empty or non-string values are dropped so they fall back to the defaults.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveColorOverrides(colors: UpstepColorOverrides | undefined, mode: "light" | "dark"): Partial<UpstepThemeColors>;
|
|
41
|
+
/** The web widget's palette. */
|
|
42
|
+
export interface WidgetPalette {
|
|
43
|
+
dark: boolean;
|
|
44
|
+
bg: string;
|
|
45
|
+
bgSoft: string;
|
|
46
|
+
bgHover: string;
|
|
47
|
+
text: string;
|
|
48
|
+
textSoft: string;
|
|
49
|
+
textFaint: string;
|
|
50
|
+
border: string;
|
|
51
|
+
overlay: string;
|
|
52
|
+
accent: string;
|
|
53
|
+
accentText: string;
|
|
54
|
+
/** Accent at low opacity, for selected/voted fills. */
|
|
55
|
+
accentTint: string;
|
|
56
|
+
radius: number;
|
|
57
|
+
}
|
|
58
|
+
/** Builds the web widget palette: defaults for the mode, then any overrides. */
|
|
59
|
+
export declare function buildWidgetPalette(options: {
|
|
60
|
+
mode: "light" | "dark";
|
|
61
|
+
accentColor?: string | undefined;
|
|
62
|
+
colors?: UpstepColorOverrides | undefined;
|
|
63
|
+
radius?: number | undefined;
|
|
64
|
+
}): WidgetPalette;
|
|
65
|
+
/**
|
|
66
|
+
* Query parameters for the hosted support chat. Only hex/rgb colors are
|
|
67
|
+
* sent, and only the keys that were overridden, so the chat keeps its own
|
|
68
|
+
* defaults for the rest.
|
|
69
|
+
*/
|
|
70
|
+
export declare function supportThemeParams(options: {
|
|
71
|
+
mode: "light" | "dark";
|
|
72
|
+
colors?: UpstepColorOverrides | undefined;
|
|
73
|
+
radius?: number | undefined;
|
|
74
|
+
fontFamily?: string | undefined;
|
|
75
|
+
}): Record<string, string>;
|
|
76
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE7E,6DAA6D;AAC7D,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAC9C,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,yEAAyE;AACzE,eAAO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9481F", N = "#FF7A50", I = M;
|
|
2
|
+
function y(t) {
|
|
3
|
+
return t === "dark" ? N : M;
|
|
4
|
+
}
|
|
5
|
+
const C = 12, R = 32, _ = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i, d = "(\\d{1,3}(?:\\.\\d+)?)", m = "(\\d*\\.?\\d+%?)", k = new RegExp(
|
|
6
|
+
`^rgba?\\(\\s*${d}\\s*(?:,\\s*${d}\\s*,\\s*${d}\\s*(?:,\\s*${m}\\s*)?|\\s+${d}\\s+${d}\\s*(?:\\/\\s*${m}\\s*)?)\\)$`,
|
|
7
|
+
"i"
|
|
8
|
+
);
|
|
9
|
+
function f(t) {
|
|
10
|
+
if (typeof t != "string" || t.length > 64) return null;
|
|
11
|
+
const n = t.trim();
|
|
12
|
+
if (_.test(n)) {
|
|
13
|
+
let u = n.slice(1);
|
|
14
|
+
u.length <= 4 && (u = u.split("").map((i) => i + i).join(""));
|
|
15
|
+
const b = (i) => parseInt(u.slice(i, i + 2), 16);
|
|
16
|
+
return [
|
|
17
|
+
b(0),
|
|
18
|
+
b(2),
|
|
19
|
+
b(4),
|
|
20
|
+
u.length === 8 ? Math.round(b(6) / 255 * 1e3) / 1e3 : 1
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
const e = k.exec(n);
|
|
24
|
+
if (!e) return null;
|
|
25
|
+
const [r, o, c, s] = [
|
|
26
|
+
e[1],
|
|
27
|
+
e[2] ?? e[5],
|
|
28
|
+
e[3] ?? e[6],
|
|
29
|
+
e[4] ?? e[7]
|
|
30
|
+
], a = [r, o, c].map(Number);
|
|
31
|
+
if (a.some((u) => !(u >= 0 && u <= 255))) return null;
|
|
32
|
+
let l = 1;
|
|
33
|
+
return s !== void 0 && (l = s.endsWith("%") ? Number(s.slice(0, -1)) / 100 : Number(s), !(l >= 0 && l <= 1)) ? null : [a[0], a[1], a[2], l];
|
|
34
|
+
}
|
|
35
|
+
function v(t) {
|
|
36
|
+
return f(t) !== null;
|
|
37
|
+
}
|
|
38
|
+
function $([t, n, e, r]) {
|
|
39
|
+
const o = (c) => Math.round(Math.min(255, Math.max(0, c))).toString(16).padStart(2, "0");
|
|
40
|
+
return `#${o(t)}${o(n)}${o(e)}${r < 1 ? o(r * 255) : ""}`;
|
|
41
|
+
}
|
|
42
|
+
function H(t, n, e) {
|
|
43
|
+
const r = f(t), o = f(n);
|
|
44
|
+
if (!r || !o) return null;
|
|
45
|
+
const c = Math.min(1, Math.max(0, e));
|
|
46
|
+
return $([
|
|
47
|
+
r[0] + (o[0] - r[0]) * c,
|
|
48
|
+
r[1] + (o[1] - r[1]) * c,
|
|
49
|
+
r[2] + (o[2] - r[2]) * c,
|
|
50
|
+
r[3] + (o[3] - r[3]) * c
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
function D(t, n) {
|
|
54
|
+
const e = f(t);
|
|
55
|
+
return e ? $([e[0], e[1], e[2], e[3] * n]) : null;
|
|
56
|
+
}
|
|
57
|
+
function g([t, n, e]) {
|
|
58
|
+
const r = (o) => {
|
|
59
|
+
const c = o / 255;
|
|
60
|
+
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
61
|
+
};
|
|
62
|
+
return 0.2126 * r(t) + 0.7152 * r(n) + 0.0722 * r(e);
|
|
63
|
+
}
|
|
64
|
+
function h(t, n) {
|
|
65
|
+
const e = f(t), r = f(n);
|
|
66
|
+
if (!e || !r) return null;
|
|
67
|
+
const [o, c] = [g(e), g(r)].sort((s, a) => a - s);
|
|
68
|
+
return (o + 0.05) / (c + 0.05);
|
|
69
|
+
}
|
|
70
|
+
const x = "#ffffff", A = "#1a1915";
|
|
71
|
+
function L(t) {
|
|
72
|
+
const n = h(t, x);
|
|
73
|
+
return n === null || n >= 3 ? x : (h(t, A) ?? 0) > n ? A : x;
|
|
74
|
+
}
|
|
75
|
+
function S(t) {
|
|
76
|
+
const n = typeof t == "number" ? t : Number(t);
|
|
77
|
+
return t == null || t === "" || !Number.isFinite(n) ? C : Math.round(Math.min(R, Math.max(0, n)));
|
|
78
|
+
}
|
|
79
|
+
function O(t, n) {
|
|
80
|
+
return Math.round(t * n / C);
|
|
81
|
+
}
|
|
82
|
+
const F = [
|
|
83
|
+
"background",
|
|
84
|
+
"surface",
|
|
85
|
+
"border",
|
|
86
|
+
"text",
|
|
87
|
+
"textMuted",
|
|
88
|
+
"accentText"
|
|
89
|
+
];
|
|
90
|
+
function E(t, n) {
|
|
91
|
+
const e = {};
|
|
92
|
+
if (!t) return e;
|
|
93
|
+
for (const r of [t, t[n]])
|
|
94
|
+
if (r)
|
|
95
|
+
for (const o of F) {
|
|
96
|
+
const c = r[o];
|
|
97
|
+
typeof c == "string" && c.trim() && (e[o] = c.trim());
|
|
98
|
+
}
|
|
99
|
+
return e;
|
|
100
|
+
}
|
|
101
|
+
const p = {
|
|
102
|
+
bg: "#ffffff",
|
|
103
|
+
bgSoft: "#f5f5f5",
|
|
104
|
+
bgHover: "#ededed",
|
|
105
|
+
text: "#1a1915",
|
|
106
|
+
textSoft: "#56544d",
|
|
107
|
+
textFaint: "#9b9890",
|
|
108
|
+
border: "#e8e6df",
|
|
109
|
+
overlay: "rgba(26,25,21,.45)"
|
|
110
|
+
}, U = {
|
|
111
|
+
bg: "#000000",
|
|
112
|
+
bgSoft: "#171717",
|
|
113
|
+
bgHover: "#262626",
|
|
114
|
+
text: "#f5f4f0",
|
|
115
|
+
textSoft: "#b4b1a8",
|
|
116
|
+
textFaint: "#7d7a72",
|
|
117
|
+
border: "#33312c",
|
|
118
|
+
overlay: "rgba(0,0,0,.6)"
|
|
119
|
+
};
|
|
120
|
+
function T(t, n, e) {
|
|
121
|
+
return H(t, n, e) ?? `color-mix(in srgb, ${t} ${Math.round((1 - e) * 100)}%, ${n})`;
|
|
122
|
+
}
|
|
123
|
+
function G(t) {
|
|
124
|
+
var a;
|
|
125
|
+
const n = t.mode === "dark" ? U : p, e = E(t.colors, t.mode), r = ((a = t.accentColor) == null ? void 0 : a.trim()) || y(t.mode), o = e.background ?? n.bg, c = e.text ?? n.text, s = e.surface ?? n.bgSoft;
|
|
126
|
+
return {
|
|
127
|
+
dark: t.mode === "dark",
|
|
128
|
+
bg: o,
|
|
129
|
+
bgSoft: s,
|
|
130
|
+
bgHover: e.surface || e.text ? T(s, c, 0.06) : n.bgHover,
|
|
131
|
+
text: c,
|
|
132
|
+
textSoft: e.textMuted ?? n.textSoft,
|
|
133
|
+
textFaint: e.textMuted || e.background ? T(e.textMuted ?? n.textSoft, o, 0.4) : n.textFaint,
|
|
134
|
+
border: e.border ?? n.border,
|
|
135
|
+
overlay: n.overlay,
|
|
136
|
+
accent: r,
|
|
137
|
+
accentText: e.accentText ?? L(r),
|
|
138
|
+
accentTint: D(r, 0.1) ?? `color-mix(in srgb, ${r} 10%, transparent)`,
|
|
139
|
+
radius: S(t.radius)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function K(t) {
|
|
143
|
+
var o;
|
|
144
|
+
const n = E(t.colors, t.mode), e = {}, r = {
|
|
145
|
+
background: "bg",
|
|
146
|
+
surface: "surface",
|
|
147
|
+
border: "border",
|
|
148
|
+
text: "text",
|
|
149
|
+
textMuted: "muted",
|
|
150
|
+
accentText: "accentText"
|
|
151
|
+
};
|
|
152
|
+
for (const c of F) {
|
|
153
|
+
const s = n[c];
|
|
154
|
+
v(s) && (e[r[c]] = s);
|
|
155
|
+
}
|
|
156
|
+
return t.radius !== void 0 && (e.radius = String(S(t.radius))), (o = t.fontFamily) != null && o.trim() && (e.font = t.fontFamily.trim()), e;
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
I as DEFAULT_ACCENT,
|
|
160
|
+
N as DEFAULT_ACCENT_DARK,
|
|
161
|
+
M as DEFAULT_ACCENT_LIGHT,
|
|
162
|
+
C as DEFAULT_RADIUS,
|
|
163
|
+
R as MAX_RADIUS,
|
|
164
|
+
G as buildWidgetPalette,
|
|
165
|
+
S as clampRadius,
|
|
166
|
+
h as contrastRatio,
|
|
167
|
+
y as defaultAccent,
|
|
168
|
+
$ as formatHex,
|
|
169
|
+
v as isSupportedColor,
|
|
170
|
+
H as mixColors,
|
|
171
|
+
f as parseColor,
|
|
172
|
+
L as readableTextOn,
|
|
173
|
+
E as resolveColorOverrides,
|
|
174
|
+
O as scaleRadius,
|
|
175
|
+
K as supportThemeParams,
|
|
176
|
+
D as withAlpha
|
|
177
|
+
};
|