@whoa-chat/react 0.0.0-stage → 0.2.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/dist/locales/bg.json +779 -0
- package/dist/locales/da.json +779 -0
- package/dist/locales/de.json +779 -0
- package/dist/locales/en.json +779 -0
- package/dist/locales/es.json +779 -0
- package/dist/locales/fr.json +809 -0
- package/dist/locales/index.d.ts +11807 -0
- package/dist/locales/index.js +1 -0
- package/dist/locales/it.json +779 -0
- package/dist/locales/ja.json +779 -0
- package/dist/locales/loaders.d.ts +3 -0
- package/dist/locales/loaders.js +1 -0
- package/dist/locales/nl.json +779 -0
- package/dist/locales/pl.json +839 -0
- package/dist/locales/pt-BR.json +779 -0
- package/dist/locales/pt-PT.json +779 -0
- package/dist/locales/sv.json +779 -0
- package/dist/locales/zh-CN.json +779 -0
- package/dist/locales/zh-TW.json +779 -0
- package/dist/src/ActionGroup.d.ts +12 -0
- package/dist/src/ActionGroup.js +1 -0
- package/dist/src/AiChoices.d.ts +10 -0
- package/dist/src/AiChoices.js +1 -0
- package/dist/src/AssistantNote.d.ts +8 -0
- package/dist/src/AssistantNote.js +1 -0
- package/dist/src/Attachments.d.ts +56 -0
- package/dist/src/Attachments.js +1 -0
- package/dist/src/AvailabilityCard.d.ts +19 -0
- package/dist/src/AvailabilityCard.js +1 -0
- package/dist/src/CardOutcome.d.ts +6 -0
- package/dist/src/CardOutcome.js +1 -0
- package/dist/src/ChatThread.d.ts +149 -0
- package/dist/src/ChatThread.js +8 -0
- package/dist/src/ComposerTools.d.ts +29 -0
- package/dist/src/ComposerTools.js +1 -0
- package/dist/src/CustomCard.d.ts +5 -0
- package/dist/src/CustomCard.js +1 -0
- package/dist/src/DraftCard.d.ts +10 -0
- package/dist/src/DraftCard.js +1 -0
- package/dist/src/EventRow.d.ts +5 -0
- package/dist/src/EventRow.js +2 -0
- package/dist/src/FormattedText.d.ts +45 -0
- package/dist/src/FormattedText.js +5 -0
- package/dist/src/HelpOfferCard.d.ts +10 -0
- package/dist/src/HelpOfferCard.js +1 -0
- package/dist/src/InboxTools.d.ts +53 -0
- package/dist/src/InboxTools.js +1 -0
- package/dist/src/MerchantPanel.d.ts +10 -0
- package/dist/src/MerchantPanel.js +1 -0
- package/dist/src/MessageActions.d.ts +15 -0
- package/dist/src/MessageActions.js +1 -0
- package/dist/src/MessagePreview.d.ts +20 -0
- package/dist/src/MessagePreview.js +1 -0
- package/dist/src/PasswordCard.d.ts +6 -0
- package/dist/src/PasswordCard.js +1 -0
- package/dist/src/RequestCards.d.ts +8 -0
- package/dist/src/RequestCards.js +1 -0
- package/dist/src/ReviewCard.d.ts +15 -0
- package/dist/src/ReviewCard.js +1 -0
- package/dist/src/RichCards.d.ts +37 -0
- package/dist/src/RichCards.js +1 -0
- package/dist/src/RichInput.d.ts +41 -0
- package/dist/src/RichInput.js +12 -0
- package/dist/src/StoreAvatar.d.ts +33 -0
- package/dist/src/StoreAvatar.js +1 -0
- package/dist/src/WorldMap.d.ts +10 -0
- package/dist/src/WorldMap.js +1 -0
- package/dist/src/agents.d.ts +9 -0
- package/dist/src/agents.js +1 -0
- package/dist/src/appearance.d.ts +17 -0
- package/dist/src/appearance.js +1 -0
- package/dist/src/chatApi.d.ts +179 -0
- package/dist/src/chatApi.js +1 -0
- package/dist/src/chatEnv.d.ts +16 -0
- package/dist/src/chatEnv.js +1 -0
- package/dist/src/chime.d.ts +7 -0
- package/dist/src/chime.js +1 -0
- package/dist/src/clock.d.ts +5 -0
- package/dist/src/clock.js +1 -0
- package/dist/src/copyToClipboard.d.ts +10 -0
- package/dist/src/copyToClipboard.js +1 -0
- package/dist/src/emojis.d.ts +6 -0
- package/dist/src/emojis.js +1 -0
- package/dist/src/flags.d.ts +5 -0
- package/dist/src/flags.js +1 -0
- package/dist/src/highlight.d.ts +8 -0
- package/dist/src/highlight.js +1 -0
- package/dist/src/host.d.ts +40 -0
- package/dist/src/host.js +1 -0
- package/dist/src/i18n.d.ts +2 -0
- package/dist/src/i18n.js +1 -0
- package/dist/src/refLinks.d.ts +7 -0
- package/dist/src/refLinks.js +1 -0
- package/dist/src/supportChat.css +2490 -0
- package/dist/src/useLive.d.ts +51 -0
- package/dist/src/useLive.js +1 -0
- package/dist/src/worldDots.d.ts +7 -0
- package/dist/src/worldDots.js +1 -0
- package/package.json +208 -4
- package/README.md +0 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { StoreStatus } from "@whoa-chat/core/panels";
|
|
2
|
+
export type StoreLook = {
|
|
3
|
+
favicon: string | null;
|
|
4
|
+
development: boolean;
|
|
5
|
+
reviewed?: boolean;
|
|
6
|
+
rating?: number | null;
|
|
7
|
+
locked?: boolean | null;
|
|
8
|
+
uninstalled?: boolean;
|
|
9
|
+
collaborator?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** What the inbox knows about a store, as the picture's markers. */
|
|
12
|
+
export declare const lookFrom: (info: {
|
|
13
|
+
development?: boolean;
|
|
14
|
+
reviewed?: {
|
|
15
|
+
rating: number | null;
|
|
16
|
+
} | null;
|
|
17
|
+
passwordProtected?: boolean | null;
|
|
18
|
+
logo?: string | null;
|
|
19
|
+
installed?: boolean;
|
|
20
|
+
} | null | undefined) => StoreLook | null;
|
|
21
|
+
export declare const StoreAvatar: ({ shop, name, look, size, flag, online, status }: {
|
|
22
|
+
shop: string | null;
|
|
23
|
+
name: string;
|
|
24
|
+
look?: StoreLook | null;
|
|
25
|
+
size?: number;
|
|
26
|
+
flag?: {
|
|
27
|
+
emoji: string;
|
|
28
|
+
title: string;
|
|
29
|
+
code?: string;
|
|
30
|
+
} | null;
|
|
31
|
+
online?: boolean;
|
|
32
|
+
status?: StoreStatus | null;
|
|
33
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as L}from"react/jsx-runtime";import{STORE_THREAD as m}from"@whoa-chat/core/conversation";import{useState as w}from"react";const y=n=>n?{uninstalled:n.installed===!1,favicon:n.logo??null,development:!!n.development,reviewed:!!n.reviewed,rating:n.reviewed?.rating??null,locked:n.passwordProtected??null}:null,c=["#ff6b2c","#f2506a","#e040c8","#a53af0","#4f7cff","#12a150","#f5a524","#0ea5a4"],b=n=>c[[...n].reduce((l,t)=>l*31+t.charCodeAt(0)>>>0,7)%c.length],S=n=>n.replace(/\.myshopify\.com(~[a-z0-9]+)?$/,"").split(/[\s._-]+/).filter(Boolean).slice(0,2).map(l=>l[0].toUpperCase()).join("")||"?",B=({dev:n})=>e("img",{className:"st-bag",src:n?"/support/shopify-dev.png":"/support/shopify.svg",alt:""}),N=({shop:n,name:l,look:t,size:i=40,flag:o=null,online:u=!1,status:r=null})=>{const[p,g]=w(!1),v=!!(n&&m.test(n)),a=!!t?.development,f=t?.favicon&&!p?e("img",{src:t.favicon,alt:"",onError:()=>g(!0)}):v?e(B,{dev:a}):e("span",{className:"st-initials",style:{background:b(l||n||"?"),fontSize:i*.38},children:S(l||n||"?")}),s=t?.reviewed?t.rating!==null&&t.rating!==void 0&&t.rating<=3?"low":"gold":null,h=[t?.uninstalled?"Uninstalled":null,t?.reviewed?`Reviewed${t.rating?` \u2605 ${t.rating}`:""}`:null,t?.collaborator?"Collaborator access":null,a?"Development store":t?.locked?"Password protected":null,r?.label??null].filter(Boolean),d=r&&!t?.uninstalled?{good:"done",partial:"half",none:"none"}[r.tone]:null;return L("span",{className:`st-avatar${t?.uninstalled?" st-avatar--gone":""}${a?" st-avatar--dev":""}${s?` st-avatar--ring-${s}`:""}`,style:{width:i,height:i},title:h.join(" \xB7 ")||void 0,children:[f,u&&e("i",{className:"st-online",title:"Online now","aria-label":"Online now"}),d&&e("i",{className:`st-setup st-setup--${d}`,"aria-hidden":!0,children:d==="done"&&e("svg",{viewBox:"0 0 16 16",width:"7",height:"7",children:e("path",{d:"M3.5 8.5 6.5 11.5 12.5 4.5",fill:"none",stroke:"#fff",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})}),o&&e("i",{className:"st-flag",title:o.title,"aria-label":o.title,children:o.code?e("img",{src:`https://flagcdn.com/${o.code.toLowerCase()}.svg`,alt:""}):e("span",{children:o.emoji})}),s?e("i",{className:`st-star${s==="low"?" st-star--low":""}`,children:e("svg",{viewBox:"0 0 16 16","aria-hidden":!0,children:e("path",{d:"M8 1.5l1.9 4.1 4.5.5-3.3 3.1.9 4.4L8 11.4l-4 2.2.9-4.4-3.3-3.1 4.5-.5z",fill:"#fff"})})}):a?e("i",{className:"st-code",children:e("svg",{viewBox:"0 0 16 16",width:"7",height:"7","aria-hidden":!0,children:e("path",{d:"M5.5 4.5 2 8l3.5 3.5M10.5 4.5 14 8l-3.5 3.5",fill:"none",stroke:"#fff",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):t?.locked?e("i",{className:"st-lock",children:e("svg",{viewBox:"0 0 16 16",width:"6.5",height:"6.5","aria-hidden":!0,children:e("path",{d:"M4.5 7V5.5a3.5 3.5 0 0 1 7 0V7M3.5 7h9v7h-9z",fill:"none",stroke:"#fff",strokeWidth:"1.8",strokeLinejoin:"round"})})}):null]})};export{N as StoreAvatar,y as lookFrom};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as r,jsxs as p}from"react/jsx-runtime";import{useMemo as d}from"react";import{LAND_ROWS as i,MAP as o}from"./worldDots.js";const s=o.cols,c=i.length,f=t=>(t+180)/360*s,v=t=>(o.top-t)/(o.top-o.bottom)*c,N=({pins:t})=>{const u=d(()=>{const e=[];return i.forEach((l,b)=>{let m=0;l.split(",").map(Number).forEach((n,g)=>{if(g%2===1)for(let a=0;a<n;a++)e.push([m+a,b]);m+=n})}),e},[]);return p("svg",{className:"wm",viewBox:`0 0 ${s} ${c}`,role:"img","aria-label":"World map",children:[u.map(([e,l])=>r("circle",{cx:e+.5,cy:l+.5,r:.32,className:"wm-land"},`${e}-${l}`)),t.map(e=>p("g",{transform:`translate(${f(e.longitude)} ${v(e.latitude)})`,children:[r("title",{children:e.label}),e.live&&r("circle",{r:1.6,className:"wm-pulse"}),r("circle",{r:.95,className:e.live?"wm-pin wm-pin--live":"wm-pin"})]},e.key))]})};export{N as WorldMap};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const teamAvatar: (name: string) => string | null;
|
|
2
|
+
export declare const SUPPORT_AGENTS: Record<string, {
|
|
3
|
+
avatar?: string;
|
|
4
|
+
role: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const AgentAvatar: ({ name, size }: {
|
|
7
|
+
name: string;
|
|
8
|
+
size?: number;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as n}from"react/jsx-runtime";import{useState as l}from"react";import{chatHost as r,isBotName as c}from"./host.js";const a=e=>r().team?.[e]??null,d=new Proxy({},{get:(e,t)=>typeof t=="string"&&r().team&&t in r().team?{role:"",...a(t)?{avatar:a(t)}:{}}:void 0,has:(e,t)=>typeof t=="string"&&!!(r().team&&t in r().team),ownKeys:()=>Object.keys(r().team??{}),getOwnPropertyDescriptor:(e,t)=>typeof t=="string"&&r().team&&t in r().team?{enumerable:!0,configurable:!0,value:{role:"",...a(t)?{avatar:a(t)}:{}}}:void 0}),f=({name:e,size:t=36})=>{const o=c(e)?r().brand.logo:a(e),[s,i]=l(null),g=o&&s!==o;return n("span",{className:"sc-avatar",style:{width:t,height:t,fontSize:t*.4},"aria-hidden":!0,children:g?n("img",{src:o,alt:"",onError:()=>i(o)}):e.slice(0,1).toUpperCase()})};export{f as AgentAvatar,d as SUPPORT_AGENTS,a as teamAvatar};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { i18n as I18n } from "i18next";
|
|
2
|
+
import { type Appearance } from "@whoa-chat/core/appearance";
|
|
3
|
+
import type { AppLinks } from "@whoa-chat/core/links";
|
|
4
|
+
/** Lays the workspace's reworded texts over the chat's strings, once per i18n instance and text. Only those keys change. */
|
|
5
|
+
export declare const applyAppearanceTexts: (i18n: I18n, texts: Appearance["texts"]) => void;
|
|
6
|
+
/** The chat's style for the workspace's colours in the merchant's view: no class and no variables when none are set. */
|
|
7
|
+
export declare const useAppearance: (i18n: I18n, merchantView: boolean) => {
|
|
8
|
+
className: string;
|
|
9
|
+
style: import("react").CSSProperties | undefined;
|
|
10
|
+
};
|
|
11
|
+
/** For hosts: fetch the workspace's appearance through the merchant API and hand it to the chat; failures change nothing. */
|
|
12
|
+
export declare const loadMerchantAppearance: (api: {
|
|
13
|
+
appearance: () => Promise<Appearance & {
|
|
14
|
+
brand?: unknown;
|
|
15
|
+
links?: AppLinks;
|
|
16
|
+
}>;
|
|
17
|
+
}) => Promise<Appearance | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useMemo as l}from"react";import{chatColorVars as f}from"@whoa-chat/core/appearance";import{chatHost as u,setChatHost as c}from"./host.js";import{CHAT_NS as m}from"./i18n.js";const p=new WeakMap,d=(n,e)=>{if(!e)return;const t=p.get(n)??new Set;p.set(n,t);for(const[s,i]of Object.entries(e))for(const[o,a]of Object.entries(i)){if(o.startsWith("widget."))continue;const r=`${s}\0${o}\0${a}`;t.has(r)||(t.add(r),n.addResource(s,m,o,a))}},A=(n,e)=>{const t=u().appearance;return e&&d(n,t?.texts),l(()=>{const s=e?f(t?.colors):{};return{className:s["--sc-accent"]?" sc-themed":"",style:Object.keys(s).length?s:void 0}},[t,e])},g=async n=>{const e=await n.appearance().catch(()=>null);if(!e)return null;e.links?.handle&&c({appLinks:[e.links]});const t={...e.colors&&Object.keys(e.colors).length?{colors:e.colors}:{},...e.texts&&Object.keys(e.texts).length?{texts:e.texts}:{}};return(t.colors||t.texts)&&c({appearance:t}),t};export{d as applyAppearanceTexts,g as loadMerchantAppearance,A as useAppearance};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { AiChoice, AiProgressStep, SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
export type ApiMessage = {
|
|
3
|
+
id: string;
|
|
4
|
+
shop: string;
|
|
5
|
+
from: "merchant" | "agent" | "system";
|
|
6
|
+
kind: "text" | "note" | "review_request" | "reference" | "offer" | "link" | "pricing" | "help_offer" | "password_request" | "event" | "draft" | "feature_request" | "ticket" | "custom";
|
|
7
|
+
body: string;
|
|
8
|
+
agentName?: string;
|
|
9
|
+
at: string;
|
|
10
|
+
review?: {
|
|
11
|
+
fixed: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
ask?: string;
|
|
14
|
+
beforeImageUrl?: string;
|
|
15
|
+
afterImageUrl?: string;
|
|
16
|
+
state: "sent" | "seen" | "clicked" | "issue" | "dismissed";
|
|
17
|
+
};
|
|
18
|
+
ref?: string;
|
|
19
|
+
link?: {
|
|
20
|
+
key: string;
|
|
21
|
+
path: string;
|
|
22
|
+
title: string;
|
|
23
|
+
crumb: string[];
|
|
24
|
+
about: string;
|
|
25
|
+
setting?: boolean;
|
|
26
|
+
};
|
|
27
|
+
pricing?: {
|
|
28
|
+
revenueUsd: number;
|
|
29
|
+
tierKey: string;
|
|
30
|
+
priceBookId?: string | null;
|
|
31
|
+
at: string;
|
|
32
|
+
};
|
|
33
|
+
mentions?: string[];
|
|
34
|
+
reminder?: boolean;
|
|
35
|
+
files?: {
|
|
36
|
+
key: string;
|
|
37
|
+
name: string;
|
|
38
|
+
type: string;
|
|
39
|
+
size: number;
|
|
40
|
+
}[];
|
|
41
|
+
clicks?: {
|
|
42
|
+
action: string;
|
|
43
|
+
at: string;
|
|
44
|
+
detail?: string;
|
|
45
|
+
}[];
|
|
46
|
+
email?: {
|
|
47
|
+
from: string;
|
|
48
|
+
subject: string;
|
|
49
|
+
verified: boolean;
|
|
50
|
+
};
|
|
51
|
+
editedAt?: string;
|
|
52
|
+
refs?: {
|
|
53
|
+
text: string;
|
|
54
|
+
ref: string;
|
|
55
|
+
}[];
|
|
56
|
+
bot?: boolean;
|
|
57
|
+
event?: {
|
|
58
|
+
type: string;
|
|
59
|
+
fields: {
|
|
60
|
+
label: string;
|
|
61
|
+
value: string;
|
|
62
|
+
url?: string;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
65
|
+
draft?: {
|
|
66
|
+
state: "open" | "sent" | "discarded";
|
|
67
|
+
by?: string;
|
|
68
|
+
at?: string;
|
|
69
|
+
sentId?: string;
|
|
70
|
+
note?: string;
|
|
71
|
+
};
|
|
72
|
+
translation?: {
|
|
73
|
+
from: string;
|
|
74
|
+
to: string;
|
|
75
|
+
text: string;
|
|
76
|
+
};
|
|
77
|
+
translating?: boolean;
|
|
78
|
+
original?: {
|
|
79
|
+
body: string;
|
|
80
|
+
lang: string;
|
|
81
|
+
};
|
|
82
|
+
ai?: {
|
|
83
|
+
question: string;
|
|
84
|
+
askedBy: string;
|
|
85
|
+
status: "running" | "done" | "error" | "cancelled";
|
|
86
|
+
steps: {
|
|
87
|
+
id: string;
|
|
88
|
+
tool: string;
|
|
89
|
+
input: string;
|
|
90
|
+
status: "running" | "done" | "error";
|
|
91
|
+
output?: string;
|
|
92
|
+
}[];
|
|
93
|
+
error?: string;
|
|
94
|
+
};
|
|
95
|
+
choices?: AiChoice[];
|
|
96
|
+
progress?: AiProgressStep[];
|
|
97
|
+
assigned?: string;
|
|
98
|
+
deletedAt?: string;
|
|
99
|
+
deletedBy?: string;
|
|
100
|
+
replyTo?: {
|
|
101
|
+
id: string;
|
|
102
|
+
from: "merchant" | "agent" | "system";
|
|
103
|
+
author: string;
|
|
104
|
+
excerpt: string;
|
|
105
|
+
};
|
|
106
|
+
reactions?: {
|
|
107
|
+
emoji: string;
|
|
108
|
+
by: string[];
|
|
109
|
+
}[];
|
|
110
|
+
verified?: string;
|
|
111
|
+
feature?: {
|
|
112
|
+
title: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
requestId?: string;
|
|
115
|
+
addedAt?: string;
|
|
116
|
+
};
|
|
117
|
+
card?: {
|
|
118
|
+
id: string;
|
|
119
|
+
name: string;
|
|
120
|
+
tree: import("@whoa-chat/core/cardTree").CardNode;
|
|
121
|
+
};
|
|
122
|
+
ticket?: {
|
|
123
|
+
title: string;
|
|
124
|
+
state: "open" | "fixed";
|
|
125
|
+
fixedAt?: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
export type ApiThread = {
|
|
129
|
+
shop: string;
|
|
130
|
+
shopName: string;
|
|
131
|
+
status: "open" | "resolved";
|
|
132
|
+
merchantReadAt?: string;
|
|
133
|
+
agentReadAt?: string;
|
|
134
|
+
agentDeliveredAt?: string;
|
|
135
|
+
lastMessageAt?: string;
|
|
136
|
+
};
|
|
137
|
+
/** cards: whether order, subscription and offer previews can load where this is drawn. */
|
|
138
|
+
export declare const toView: (m: ApiMessage, { cards }: {
|
|
139
|
+
cards: boolean;
|
|
140
|
+
}) => SupportMessageView;
|
|
141
|
+
/** The merchant's side, signed with the App Bridge session token on every call (the shop comes from it, never the body). */
|
|
142
|
+
/** A token getter for merchantChatApi and useLive from the host's own endpoint that returns a fresh merchant token
|
|
143
|
+
* (@whoa-chat/connector signMerchant): kept until five minutes before it expires, then fetched again. */
|
|
144
|
+
export declare const cachedMerchantToken: (fetchToken: () => Promise<string>) => () => Promise<string>;
|
|
145
|
+
export declare const merchantChatApi: (base: string, token: () => Promise<string>) => {
|
|
146
|
+
thread: (peek: boolean) => Promise<{
|
|
147
|
+
thread: ApiThread | null;
|
|
148
|
+
messages: ApiMessage[];
|
|
149
|
+
team?: Record<string, string>;
|
|
150
|
+
}>;
|
|
151
|
+
appearance: () => Promise<{
|
|
152
|
+
colors?: {
|
|
153
|
+
accent?: string;
|
|
154
|
+
launcher?: string;
|
|
155
|
+
};
|
|
156
|
+
texts?: Record<string, Record<string, string>>;
|
|
157
|
+
links?: import("@whoa-chat/core/links").AppLinks;
|
|
158
|
+
}>;
|
|
159
|
+
send: (body: string, fileKeys: string[], shopName: string, contact: string | null, workflow?: string, replyTo?: string) => Promise<{
|
|
160
|
+
message: ApiMessage;
|
|
161
|
+
}>;
|
|
162
|
+
react: (id: string, emoji: string) => Promise<{
|
|
163
|
+
ok: true;
|
|
164
|
+
}>;
|
|
165
|
+
reviewState: (messageId: string, state: string, outcome?: string) => Promise<{
|
|
166
|
+
ok: true;
|
|
167
|
+
}>;
|
|
168
|
+
track: (messageId: string, action: string, detail?: string) => Promise<{
|
|
169
|
+
ok: true;
|
|
170
|
+
}>;
|
|
171
|
+
upload: (file: File) => Promise<{
|
|
172
|
+
id: string;
|
|
173
|
+
name: string;
|
|
174
|
+
type: string;
|
|
175
|
+
size: number;
|
|
176
|
+
}>;
|
|
177
|
+
fileUrl: (key: string) => string;
|
|
178
|
+
fetchFile: (url: string) => Promise<Response>;
|
|
179
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{chatHost as c,setChatHost as u}from"./host.js";const f=(e,{cards:a})=>{const t={id:e.id,from:e.from,body:e.body,agentName:e.bot?c().brand.bot:e.agentName??null,at:e.at,review:null,...e.files?.length?{files:e.files.map(i=>({id:i.key,name:i.name,type:i.type,size:i.size}))}:{},...e.clicks?.length?{clicks:e.clicks.map(i=>({action:i.action,at:i.at,detail:i.detail??null}))}:{},...e.email?{email:e.email}:{},...e.editedAt?{editedAt:e.editedAt}:{},...e.refs?.length?{refs:e.refs}:{},...e.ai?{ai:e.ai}:{},...e.bot?{bot:!0}:{},...e.translation?{translation:e.translation}:{},...e.translating?{translating:!0}:{},...e.original?{original:e.original}:{},...e.choices?.length?{choices:e.choices}:{},...e.bot&&e.progress?.length?{progress:e.progress}:{},...e.bot&&e.assigned?{assigned:e.assigned}:{},...e.deletedAt?{deletedAt:e.deletedAt,deletedBy:e.deletedBy}:{},...e.replyTo?{replyTo:e.replyTo}:{},...e.reactions?.length?{reactions:e.reactions}:{},...e.verified?{verified:e.verified}:{}};switch(e.kind){case"draft":return{...t,kind:"draft",draft:e.draft??{state:"open"}};case"event":return{...t,kind:"event",event:e.event??{type:"other",fields:[]}};case"note":return{...t,kind:"note",mentions:e.mentions??[],...e.reminder?{reminder:!0}:{}};case"review_request":return{...t,kind:"review_request",review:e.review?{fixed:e.review.fixed,title:e.review.title??null,ask:e.review.ask??null,beforeImageUrl:e.review.beforeImageUrl??null,afterImageUrl:e.review.afterImageUrl??null,state:e.review.state}:null};case"link":return{...t,kind:"link",link:e.link??null};case"pricing":return{...t,kind:"pricing",pricing:e.pricing??null};case"help_offer":return{...t,kind:"help_offer"};case"password_request":return{...t,kind:"password_request"};case"feature_request":return{...t,kind:"feature_request",feature:e.feature??{title:e.body}};case"ticket":return{...t,kind:"ticket",ticket:e.ticket??{title:e.body,state:"open"}};case"reference":return a?{...t,kind:"subscription",subscriptionId:e.ref??null}:{...t,kind:"text",body:`#${e.ref}`};case"custom":return e.card?{...t,kind:"custom",card:e.card}:{...t,kind:"text"};case"offer":return a?{...t,kind:"offer",offerId:e.ref??null}:{...t,kind:"text",body:`Offer ${e.ref}`};default:return{...t,kind:"text"}}},h=e=>{let a=null,t=null;return async()=>a&&a.exp-3e5>Date.now()?a.token:(t??=e().then(i=>{let r=Date.now()+6e5;try{r=JSON.parse(atob(i.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"))).exp*1e3}catch{}return a={token:i,exp:r},i}).finally(()=>t=null),t)},k=(e,a)=>{const t=async(r,n)=>{const s=await fetch(`${e}${r}`,{...n,headers:{"content-type":"application/json",authorization:`Bearer ${await a()}`,...n?.headers}}),o=await s.json().catch(()=>({}));if(!s.ok)throw new Error(o.error??`Request failed (${s.status})`);return o},i=(r,n)=>t(r,{method:"POST",body:JSON.stringify(n)});return{thread:async r=>{const n=await t(`/v1/merchant/thread${r?"?peek=1":""}`);return n.team&&Object.keys(n.team).length&&u({team:n.team}),n},appearance:()=>t("/v1/merchant/appearance"),send:(r,n,s,o,g,l)=>i("/v1/merchant/messages",{body:r,shopName:s,...o?{contact:o}:{},...n.length?{files:n.map(d=>({key:d}))}:{},...g?{workflow:g}:{},...l?{replyTo:l}:{}}),react:(r,n)=>i("/v1/merchant/react",{id:r,emoji:n}),reviewState:(r,n,s)=>i("/v1/merchant/review-state",{messageId:r,state:n,outcome:s}),track:(r,n,s)=>t("/v1/merchant/card-action",{method:"POST",body:JSON.stringify({messageId:r,action:n,detail:s}),keepalive:!0}),upload:async r=>{const{upload:n,file:s}=await i("/v1/merchant/uploads",{name:r.name||"screenshot.png",type:r.type,size:r.size}),o=new FormData;for(const[g,l]of Object.entries(n.fields))o.append(g,l);if(o.append("file",r),!(await fetch(n.url,{method:"POST",body:o})).ok)throw new Error("Upload failed");return{id:s.key,name:s.name,type:s.type,size:s.size}},fileUrl:r=>`${e}/v1/merchant/files?${new URLSearchParams({key:r})}`,fetchFile:async r=>fetch(r,{headers:{authorization:`Bearer ${await a()}`}})}};export{h as cachedMerchantToken,k as merchantChatApi,f as toView};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type ChatEnv = {
|
|
3
|
+
previewUrl: (ref: string) => string;
|
|
4
|
+
open?: (path: string) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const ChatEnvContext: import("react").Context<ChatEnv | null>;
|
|
7
|
+
export declare const ChatEnvProvider: ({ value, children }: {
|
|
8
|
+
value: ChatEnv | null;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
11
|
+
export declare const useChatEnv: () => ChatEnv | null;
|
|
12
|
+
export declare const LinkNamesContext: import("react").Context<Record<string, string> | undefined>;
|
|
13
|
+
export declare const useLinkNames: () => Record<string, string> | undefined;
|
|
14
|
+
export declare const OpenedLinksContext: import("react").Context<Map<string, string> | null>;
|
|
15
|
+
/** When this link was opened, as words for its hover; null when it was not. */
|
|
16
|
+
export declare const useOpened: (url: string) => string | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as l}from"react/jsx-runtime";import{createContext as n,useContext as o}from"react";const s=n(null),c=({value:e,children:t})=>l(s.Provider,{value:e,children:t}),u=()=>o(s),p=n(void 0),v=()=>o(p),a=n(null),r=e=>e.replace(/[?#].*$/,"").replace(/\/+$/,""),x=e=>{const t=o(a);return t?.size?t.get(e)??t.get(r(e))??[...t].find(([i])=>r(i)===r(e))?.[1]??null:null};export{s as ChatEnvContext,c as ChatEnvProvider,p as LinkNamesContext,a as OpenedLinksContext,u as useChatEnv,v as useLinkNames,x as useOpened};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const soundOn: () => boolean;
|
|
2
|
+
export declare const setSoundOn: (on: boolean) => void;
|
|
3
|
+
export declare const setChimeLevel: (l: "soft" | "loud") => void;
|
|
4
|
+
export declare const chime: () => void;
|
|
5
|
+
export declare const visitChime: () => void;
|
|
6
|
+
/** Chimes when `key` (the newest message from the other side) changes, but not for what was already there on load. */
|
|
7
|
+
export declare const useChime: (key: string | null, loaded: boolean) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as f,useRef as y}from"react";const m="supr-chat-sound";let p=null;const w=()=>{try{return localStorage.getItem(m)!=="off"}catch{return!0}},b=e=>{try{localStorage.setItem(m,e?"on":"off")}catch{}},a=()=>{const e=window.AudioContext??window.webkitAudioContext;return e?(p??=new e,p):null};let l="soft";const C=e=>{l=e},T=()=>{if(!(typeof window>"u"||!w()))try{const e=a();if(!e)return;e.state==="suspended"&&e.resume();const t=e.currentTime,n=l==="loud",o=n?e.createDynamicsCompressor():null;o&&(o.threshold.value=-10,o.ratio.value=4,o.connect(e.destination));const i=n?[[880,0],[1318.5,.11],[1760,.22]]:[[880,0],[1318.5,.09]];for(const[s,r]of i)for(const[v,x,g]of n?[["triangle",1,1],["sine",2,.35]]:[["sine",1,1]]){const c=e.createOscillator(),u=e.createGain();c.type=v,c.frequency.value=s*x;const h=(n?.5:.12)*g,d=n?.6:.35;u.gain.setValueAtTime(1e-4,t+r),u.gain.exponentialRampToValueAtTime(h,t+r+.012),u.gain.exponentialRampToValueAtTime(1e-4,t+r+d),c.connect(u).connect(o??e.destination),c.start(t+r),c.stop(t+r+d+.05)}}catch{}},E=()=>{if(!(typeof window>"u"||!w()))try{const e=a();if(!e)return;e.state==="suspended"&&e.resume();const t=e.currentTime,n=l==="loud"?.4:.12;for(const[o,i]of[[1318.5,0],[1046.5,.28]]){const s=e.createOscillator(),r=e.createGain();s.type="sine",s.frequency.value=o,r.gain.setValueAtTime(1e-4,t+i),r.gain.exponentialRampToValueAtTime(n,t+i+.015),r.gain.exponentialRampToValueAtTime(1e-4,t+i+.9),s.connect(r).connect(e.destination),s.start(t+i),s.stop(t+i+.95)}}catch{}},V=(e,t)=>{const n=y(void 0);f(()=>{const o=()=>{try{a()?.resume()}catch{}};return window.addEventListener("pointerdown",o,{once:!0}),window.addEventListener("keydown",o,{once:!0}),()=>{window.removeEventListener("pointerdown",o),window.removeEventListener("keydown",o)}},[]),f(()=>{if(t){if(n.current===void 0){n.current=e;return}e&&e!==n.current&&T(),n.current=e}},[e,t])};export{T as chime,C as setChimeLevel,b as setSoundOn,w as soundOn,V as useChime,E as visitChime};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type ClockPref = "auto" | "12" | "24";
|
|
2
|
+
export declare const clockPref: () => ClockPref;
|
|
3
|
+
export declare const setClockPref: (pref: ClockPref) => void;
|
|
4
|
+
/** Options for a time of day in the chosen format ("3:05 PM" or "15:05"), plus any date parts. */
|
|
5
|
+
export declare const timeOpts: (extra?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e="supr-clock",r=()=>{try{const t=localStorage.getItem(e);return t==="12"||t==="24"?t:"auto"}catch{return"auto"}},c=t=>{try{t==="auto"?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}},a=(t={})=>{const o=r();return{hour:o==="24"?"2-digit":"numeric",minute:"2-digit",...o==="auto"?{}:{hour12:o==="12"},...t}};export{r as clockPref,c as setClockPref,a as timeOpts};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy text to the clipboard from inside the embedded admin.
|
|
3
|
+
*
|
|
4
|
+
* `navigator.clipboard` is refused in the app's iframe on some browsers (the
|
|
5
|
+
* Clipboard API needs a permissions grant the admin does not always hand down)
|
|
6
|
+
* and it rejects rather than falling back, so a copy button that only calls it
|
|
7
|
+
* reports a failure every time. The textarea and `execCommand` route still
|
|
8
|
+
* works there.
|
|
9
|
+
*/
|
|
10
|
+
export declare const copyToClipboard: (text: string) => Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=async t=>{try{return await navigator.clipboard.writeText(t),!0}catch{}try{const e=document.createElement("textarea");e.value=t,e.setAttribute("readonly",""),e.style.position="fixed",e.style.top="0",e.style.left="-9999px",document.body.appendChild(e),e.select(),e.setSelectionRange(0,t.length);const o=document.execCommand("copy");return document.body.removeChild(e),o}catch{return!1}};export{n as copyToClipboard};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=[{id:"smileys",emojis:[["\u{1F600}","grin happy"],["\u{1F603}","smile happy"],["\u{1F604}","smile laugh"],["\u{1F601}","beam grin"],["\u{1F606}","laugh"],["\u{1F605}","sweat smile relief"],["\u{1F602}","joy tears laugh"],["\u{1F923}","rofl laugh"],["\u{1F642}","slight smile"],["\u{1F609}","wink"],["\u{1F60A}","blush smile"],["\u{1F607}","angel innocent"],["\u{1F970}","love hearts"],["\u{1F60D}","heart eyes love"],["\u{1F929}","star struck wow"],["\u{1F618}","kiss"],["\u{1F60B}","yum tasty"],["\u{1F60E}","cool sunglasses"],["\u{1F913}","nerd"],["\u{1F9D0}","monocle inspect"],["\u{1F914}","thinking hmm"],["\u{1F928}","raised eyebrow doubt"],["\u{1F610}","neutral"],["\u{1F636}","speechless"],["\u{1F644}","eye roll"],["\u{1F60F}","smirk"],["\u{1F62C}","grimace awkward"],["\u{1F60C}","relieved"],["\u{1F634}","sleep tired"],["\u{1F92F}","mind blown"],["\u{1F973}","party celebrate"],["\u{1F62E}","wow surprised"],["\u{1F632}","astonished"],["\u{1F633}","flushed"],["\u{1F97A}","pleading please"],["\u{1F622}","cry sad"],["\u{1F62D}","sob cry"],["\u{1F624}","huff frustrated"],["\u{1F621}","angry"],["\u{1F917}","hug"],["\u{1F92D}","oops giggle"],["\u{1FAE1}","salute"],["\u{1F91E}","fingers crossed luck"],["\u{1FAE0}","melting"],["\u{1F635}","dizzy"],["\u{1F910}","zipper secret"],["\u{1F937}","shrug"],["\u{1F648}","see no evil oops"]]},{id:"gestures",emojis:[["\u{1F44D}","thumbs up yes ok"],["\u{1F44E}","thumbs down no"],["\u{1F44C}","ok perfect"],["\u270C\uFE0F","peace victory"],["\u{1F91D}","handshake deal"],["\u{1F44F}","clap applause"],["\u{1F64C}","raised hands hooray"],["\u{1F64F}","pray thanks please"],["\u{1F4AA}","strong muscle"],["\u{1F44B}","wave hello bye"],["\u{1F919}","call me"],["\u{1F449}","point right"],["\u{1F448}","point left"],["\u{1F446}","point up"],["\u{1F447}","point down"],["\u261D\uFE0F","index up"],["\u270B","hand stop"],["\u{1F590}\uFE0F","hand five"],["\u{1FAF6}","heart hands"],["\u{1F440}","eyes look"],["\u{1F9E0}","brain smart"],["\u{1F481}","info person"],["\u{1F64B}","raise hand question"],["\u{1F926}","facepalm"]]},{id:"hearts",emojis:[["\u2764\uFE0F","red heart love"],["\u{1F9E1}","orange heart"],["\u{1F49B}","yellow heart"],["\u{1F49A}","green heart"],["\u{1F499}","blue heart"],["\u{1F49C}","purple heart"],["\u{1F5A4}","black heart"],["\u{1F90D}","white heart"],["\u{1F496}","sparkling heart"],["\u{1F495}","two hearts"],["\u{1F4AF}","hundred perfect"],["\u2728","sparkles magic"],["\u{1F525}","fire hot lit"],["\u2B50","star"],["\u{1F31F}","glowing star"],["\u{1F4AB}","dizzy star"],["\u{1F389}","party tada celebrate"],["\u{1F38A}","confetti"],["\u{1F3C6}","trophy win"],["\u{1F947}","gold medal first"],["\u{1F381}","gift present"],["\u{1F680}","rocket launch"],["\u{1F308}","rainbow"],["\u2600\uFE0F","sun"]]},{id:"objects",emojis:[["\u2705","check done yes"],["\u2611\uFE0F","checkbox"],["\u274C","cross no wrong"],["\u26A0\uFE0F","warning"],["\u2757","exclamation important"],["\u2753","question"],["\u{1F4A1}","idea bulb tip"],["\u{1F50D}","search magnify"],["\u{1F6E0}\uFE0F","tools fix"],["\u2699\uFE0F","settings gear"],["\u{1F527}","wrench fix"],["\u{1F41B}","bug"],["\u{1F4E6}","package box order"],["\u{1F6D2}","cart shop"],["\u{1F6CD}\uFE0F","shopping bags"],["\u{1F4B3}","card payment"],["\u{1F4B0}","money"],["\u{1F9FE}","receipt invoice"],["\u{1F4C5}","calendar date"],["\u23F0","alarm clock time"],["\u23F3","hourglass wait"],["\u{1F4C8}","chart up growth"],["\u{1F4CA}","bar chart"],["\u{1F4DD}","memo note"],["\u{1F4CE}","paperclip attach"],["\u{1F517}","link"],["\u{1F4E7}","email"],["\u{1F4AC}","speech chat"],["\u{1F4E3}","megaphone announce"],["\u{1F514}","bell notification"],["\u{1F512}","lock secure"],["\u{1F511}","key"],["\u{1F3AF}","target goal"],["\u{1F9E9}","puzzle"],["\u2615","coffee"],["\u{1F36A}","cookie"]]}],i=s=>{const a=s.trim().toLowerCase(),t=o.flatMap(e=>e.emojis);return a?t.filter(([,e])=>e.split(" ").some(r=>r.startsWith(a))):t};export{o as EMOJI_GROUPS,i as searchEmojis};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const flagOf: (country: string | null | undefined) => string | null;
|
|
2
|
+
export declare const TEAM_FLAG = "\uD83C\uDDEC\uD83C\uDDE7";
|
|
3
|
+
export declare const languageFlag: (lang: string, country?: string | null) => string | null;
|
|
4
|
+
export declare const languageName: (lang: string, uiLang?: string) => string;
|
|
5
|
+
export declare const countryName: (country: string, uiLang?: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=e=>e&&/^[A-Za-z]{2}$/.test(e)?String.fromCodePoint(...[...e.toUpperCase()].map(t=>127462+t.charCodeAt(0)-65)):null,r=e=>{try{return new Intl.Locale(e).maximize()}catch{return null}},a="\u{1F1EC}\u{1F1E7}",s=(e,t)=>t&&r(`und-${t}`)?.language===e?n(t):e==="en"?a:n(r(e)?.region??null),i=(e,t)=>{try{return new Intl.DisplayNames([t??"en"],{type:"language"}).of(e)??e}catch{return e}},l=(e,t)=>{try{return new Intl.DisplayNames([t??"en"],{type:"region"}).of(e)??e}catch{return e}};export{a as TEAM_FLAG,l as countryName,n as flagOf,s as languageFlag,i as languageName};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "prismjs/components/prism-markup-templating";
|
|
2
|
+
import "prismjs/components/prism-liquid";
|
|
3
|
+
export declare const highlightCode: (code: string, language: string | null) => string | null;
|
|
4
|
+
export declare const codeTokens: (code: string, language: string | null) => {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
cls: string;
|
|
8
|
+
}[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import s from"prismjs";import"prismjs/components/prism-markup-templating";import"prismjs/components/prism-liquid";const g={javascript:"javascript",liquid:"liquid",css:"css"},y=(u,o)=>{const r=o?g[o]:void 0,i=r?s.languages[r]:void 0;if(!i)return null;try{return s.highlight(u,i,r)}catch{return null}},b=(u,o)=>{const r=o?g[o]:void 0,i=r?s.languages[r]:void 0;if(!i||!u)return[];try{const t={code:u,grammar:i,language:r};s.hooks.run("before-tokenize",t),t.tokens=s.tokenize(t.code,t.grammar),s.hooks.run("after-tokenize",t);const a=[],c=(m,e,l)=>{for(const n of m){if(typeof n=="string"){l&&n.length&&a.push({from:e,to:e+n.length,cls:l}),e+=n.length;continue}const f=Array.isArray(n.alias)?n.alias.join(" "):n.alias??"",h=`token ${n.type} ${f}`.trim();e=c(Array.isArray(n.content)?n.content:[n.content],e,h)}return e};return c(t.tokens,0,null),a}catch{return[]}};export{b as codeTokens,y as highlightCode};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Appearance } from "@whoa-chat/core/appearance";
|
|
2
|
+
import type { AppLinks } from "@whoa-chat/core/links";
|
|
3
|
+
import { type Brand } from "@whoa-chat/core/brand";
|
|
4
|
+
export type HostTier = {
|
|
5
|
+
key: string;
|
|
6
|
+
name: string;
|
|
7
|
+
upToUsd: number | null;
|
|
8
|
+
priceUsd: number;
|
|
9
|
+
annualPriceUsd: number;
|
|
10
|
+
};
|
|
11
|
+
export type ChatHost = {
|
|
12
|
+
priceBook: (id: string | null | undefined) => {
|
|
13
|
+
tiers: readonly HostTier[];
|
|
14
|
+
};
|
|
15
|
+
deepLinkOptions: () => {
|
|
16
|
+
key: string;
|
|
17
|
+
label: string;
|
|
18
|
+
}[];
|
|
19
|
+
/** The workspace's names (app, team, AI) and icon, as merchants see them. */
|
|
20
|
+
brand: Brand;
|
|
21
|
+
/** The workspace's colours and reworded texts (Customize page); unset: the chat as built. */
|
|
22
|
+
appearance?: Appearance;
|
|
23
|
+
/** The team's photos by the name they write as (null: initials). The inbox's list and the merchant's thread fill it. */
|
|
24
|
+
team?: Record<string, string | null>;
|
|
25
|
+
/** Each app's admin pages as link badges name them (Settings, per app); a link to an app not listed reads its path. */
|
|
26
|
+
appLinks?: AppLinks[];
|
|
27
|
+
};
|
|
28
|
+
/** Call once at startup, before the chat renders. */
|
|
29
|
+
export declare const setChatHost: (next: Partial<ChatHost>) => void;
|
|
30
|
+
export declare const chatHost: () => ChatHost;
|
|
31
|
+
/** The brand's names for the strings that say them ({{app}}, {{appFull}}, {{team}}, {{bot}}, {{botFull}}). */
|
|
32
|
+
export declare const brandVars: () => {
|
|
33
|
+
app: string;
|
|
34
|
+
appFull: string;
|
|
35
|
+
team: string;
|
|
36
|
+
bot: string;
|
|
37
|
+
botFull: string;
|
|
38
|
+
};
|
|
39
|
+
/** Whether a message's author is the workspace's AI (its short name, or the longer one older replies were saved with). */
|
|
40
|
+
export declare const isBotName: (name: string | null | undefined) => boolean;
|
package/dist/src/host.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{NEUTRAL_BRAND as i}from"@whoa-chat/core/brand";const r={priceBook:()=>({tiers:[]}),deepLinkOptions:()=>[],brand:i},a=globalThis,c=t=>{const o=a.__whoaChatHost??r;a.__whoaChatHost={...o,...t,...t.team?{team:{...o.team,...t.team}}:{}}},n=()=>a.__whoaChatHost??r,d=()=>{const{app:t,appFull:o,team:e,bot:s,botFull:p}=n().brand;return{app:t,appFull:o,team:e,bot:s,botFull:p}},h=t=>{const{bot:o,botFull:e}=n().brand;return!!t&&(t===o||t===e)};export{d as brandVars,n as chatHost,h as isBotName,c as setChatHost};
|
package/dist/src/i18n.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useTranslation as s}from"react-i18next";const a="whoaChat",n=o=>s(a);export{a as CHAT_NS,n as useTranslation};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type RefLink = (kind: "subscription" | "offer", id: string) => string | undefined;
|
|
2
|
+
export declare const splitRefs: (text: string, link: RefLink) => {
|
|
3
|
+
text: string;
|
|
4
|
+
href?: string;
|
|
5
|
+
}[];
|
|
6
|
+
/** The support app's page for a ref, switched to the store; supportUrl is the embedded app's base (…/apps/<id>/app). */
|
|
7
|
+
export declare const supportAppRefLink: (supportUrl: string | undefined, shop: string) => RefLink;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{STORE_THREAD as p,storeOf as g}from"@whoa-chat/core/conversation";const a=/(?<![\d+\w])#?(\d{10,12})(?![\d\w])|\b(offers?\s*(?:id\s*)?[:#]?\s*)([0-9a-f]{24})\b/gi,h=(s,i)=>{const e=[];let n=0;for(const t of s.matchAll(a)){const[o,c,d]=t[1]?["subscription",t[1],""]:["offer",t[3],t[2]],f=i(o,c);if(!f)continue;const r=(t.index??0)+d.length;r>n&&e.push({text:s.slice(n,r)}),e.push({text:s.slice(r,(t.index??0)+t[0].length),href:f}),n=(t.index??0)+t[0].length}return n<s.length&&e.push({text:s.slice(n)}),e},u=(s,i)=>(e,n)=>s&&p.test(i)?`${s.replace(/\/$/,"")}/${e==="subscription"?"contracts":"offers"}/${n}?${new URLSearchParams({switchTo:g(i)})}`:void 0;export{h as splitRefs,u as supportAppRefLink};
|