@yassirbenmoussa/aicommerce-sdk 1.1.0 → 1.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/ai-commerce.min.js +464 -2
- package/dist/index.cjs +838 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +219 -7
- package/dist/index.d.ts +219 -7
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +838 -1
- package/dist/index.mjs.map +1 -1
- package/dist/widget.min.js +466 -0
- package/dist/widget.min.js.map +1 -0
- package/package.json +3 -4
package/dist/ai-commerce.min.js
CHANGED
|
@@ -1,4 +1,466 @@
|
|
|
1
1
|
var AICommerceSDK=(function(exports){'use strict';/*! AI Commerce SDK v1.0.0 | MIT License | https://aicommerce.dev */
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var k=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var P=(t,e)=>()=>(t&&(e=t(t=0)),e);var L=(t,e)=>{for(var r in e)k(t,r,{get:e[r],enumerable:true});},J=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of F(e))!Y.call(t,d)&&d!==r&&k(t,d,{get:()=>e[d],enumerable:!(o=B(e,d))||o.enumerable});return t};var I=t=>J(k({},"__esModule",{value:true}),t);var S={};L(S,{AICommerce:()=>exports.AICommerce,AICommerceError:()=>exports.AICommerceError});exports.AICommerce=void 0;exports.AICommerceError=void 0;var b=P(()=>{exports.AICommerce=class t{constructor(e){this.sessionToken=null;this.products={create:async e=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify(e)}),batchUpsert:async e=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify({products:e})}),list:async e=>{let r=new URLSearchParams;e?.page&&r.set("page",String(e.page)),e?.perPage&&r.set("perPage",String(e.perPage)),e?.search&&r.set("search",e.search),e?.categoryId&&r.set("categoryId",e.categoryId),e?.isActive!==void 0&&r.set("isActive",String(e.isActive));let o=r.toString();return this.request(`/api/v1/products${o?`?${o}`:""}`)},get:async e=>this.request(`/api/v1/products/${e}`),update:async(e,r)=>this.request(`/api/v1/products/${e}`,{method:"PUT",body:JSON.stringify(r)}),delete:async e=>this.request(`/api/v1/products/${e}`,{method:"DELETE"})};if(!e.apiKey)throw new Error("AICommerce: apiKey is required");this.apiKey=e.apiKey,this.baseUrl=this.normalizeUrl(e.baseUrl||this.detectBaseUrl()),this.timeout=e.timeout||3e4;}detectBaseUrl(){return typeof window<"u"?window.location.origin:"https://api.aicommerce.dev"}normalizeUrl(e){return e.replace(/\/$/,"")}async request(e,r={}){let o=`${this.baseUrl}${e}`,d=new AbortController,l=setTimeout(()=>d.abort(),this.timeout);try{let s=await fetch(o,{...r,signal:d.signal,headers:{"Content-Type":"application/json","X-API-Key":this.apiKey,...this.sessionToken&&{"X-Session-Token":this.sessionToken},...r.headers}});if(clearTimeout(l),!s.ok){let n=await s.json().catch(()=>({})),h={code:n.code||"UNKNOWN_ERROR",message:n.message||n.error||`HTTP ${s.status}`,status:s.status};throw new exports.AICommerceError(h.message,h.code,h.status)}return s.json()}catch(s){throw clearTimeout(l),s instanceof exports.AICommerceError?s:s instanceof Error&&s.name==="AbortError"?new exports.AICommerceError("Request timeout","TIMEOUT",408):new exports.AICommerceError(s instanceof Error?s.message:"Unknown error","NETWORK_ERROR",0)}}async chat(e,r){let o=typeof e=="string"?{message:e,context:r,sessionToken:this.sessionToken||void 0}:{...e,sessionToken:e.sessionToken||this.sessionToken||void 0},d=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(o)});return d.sessionToken&&(this.sessionToken=d.sessionToken),d}async createSession(){let e=await this.request("/api/v1/chat/session",{method:"POST"});return this.sessionToken=e.session.token,e.session}clearSession(){this.sessionToken=null;}getSessionToken(){return this.sessionToken}setSessionToken(e){this.sessionToken=e;}async upload(e,r){let o=new FormData;o.append("file",e),r?.folder&&o.append("folder",r.folder),r?.productId&&o.append("productId",r.productId),r?.isPrimary&&o.append("isPrimary","true");let d=`${this.baseUrl}/api/v1/upload`,l=await fetch(d,{method:"POST",headers:{"X-API-Key":this.apiKey},body:o});if(!l.ok){let s=await l.json().catch(()=>({}));throw new exports.AICommerceError(s.message||s.error||`HTTP ${l.status}`,s.code||"UPLOAD_ERROR",l.status)}return l.json()}static async quickChat(e){return new t({apiKey:e.apiKey,baseUrl:e.baseUrl}).chat(e.message,e.context)}},exports.AICommerceError=class t extends Error{constructor(e,r,o){super(e),this.name="AICommerceError",this.code=r,this.status=o,Object.setPrototypeOf(this,t.prototype);}};});function X(t){let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:{r:99,g:102,b:241}}function T(t){let e=t.primaryColor,r=X(e),o=t.position==="bottom-left";return `
|
|
3
|
+
/* AI Commerce Widget Styles */
|
|
4
|
+
#aicommerce-widget {
|
|
5
|
+
--aic-primary: ${e};
|
|
6
|
+
--aic-primary-rgb: ${r.r}, ${r.g}, ${r.b};
|
|
7
|
+
--aic-primary-light: rgba(${r.r}, ${r.g}, ${r.b}, 0.1);
|
|
8
|
+
--aic-primary-dark: rgba(${r.r}, ${r.g}, ${r.b}, 0.9);
|
|
9
|
+
--aic-bg: #ffffff;
|
|
10
|
+
--aic-bg-secondary: #f8fafc;
|
|
11
|
+
--aic-text: #1e293b;
|
|
12
|
+
--aic-text-secondary: #64748b;
|
|
13
|
+
--aic-border: #e2e8f0;
|
|
14
|
+
--aic-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
|
15
|
+
--aic-radius: 16px;
|
|
16
|
+
--aic-z-index: ${t.zIndex};
|
|
17
|
+
|
|
18
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
|
19
|
+
font-size: 14px;
|
|
20
|
+
line-height: 1.5;
|
|
21
|
+
position: fixed;
|
|
22
|
+
bottom: 20px;
|
|
23
|
+
${o?"left: 20px;":"right: 20px;"}
|
|
24
|
+
z-index: var(--aic-z-index);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Dark theme */
|
|
28
|
+
#aicommerce-widget.aicommerce-theme-dark,
|
|
29
|
+
@media (prefers-color-scheme: dark) {
|
|
30
|
+
#aicommerce-widget.aicommerce-theme-auto {
|
|
31
|
+
--aic-bg: #1e293b;
|
|
32
|
+
--aic-bg-secondary: #0f172a;
|
|
33
|
+
--aic-text: #f1f5f9;
|
|
34
|
+
--aic-text-secondary: #94a3b8;
|
|
35
|
+
--aic-border: #334155;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* Launcher Button */
|
|
40
|
+
.aicommerce-launcher {
|
|
41
|
+
width: 60px;
|
|
42
|
+
height: 60px;
|
|
43
|
+
border-radius: 50%;
|
|
44
|
+
background: linear-gradient(135deg, var(--aic-primary), var(--aic-primary-dark));
|
|
45
|
+
border: none;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
box-shadow: 0 4px 20px rgba(var(--aic-primary-rgb), 0.4);
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
52
|
+
animation: aic-pulse 2s infinite;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.aicommerce-launcher:hover {
|
|
56
|
+
transform: scale(1.1);
|
|
57
|
+
box-shadow: 0 6px 30px rgba(var(--aic-primary-rgb), 0.5);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.aicommerce-launcher-icon {
|
|
61
|
+
font-size: 24px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.aicommerce-hidden {
|
|
65
|
+
display: none !important;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@keyframes aic-pulse {
|
|
69
|
+
0%, 100% { box-shadow: 0 4px 20px rgba(var(--aic-primary-rgb), 0.4); }
|
|
70
|
+
50% { box-shadow: 0 4px 30px rgba(var(--aic-primary-rgb), 0.6); }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* Chat Window */
|
|
74
|
+
.aicommerce-chat {
|
|
75
|
+
position: absolute;
|
|
76
|
+
bottom: 0;
|
|
77
|
+
${o?"left: 0;":"right: 0;"}
|
|
78
|
+
width: 380px;
|
|
79
|
+
max-width: calc(100vw - 40px);
|
|
80
|
+
height: 600px;
|
|
81
|
+
max-height: calc(100vh - 100px);
|
|
82
|
+
background: var(--aic-bg);
|
|
83
|
+
border-radius: var(--aic-radius);
|
|
84
|
+
box-shadow: var(--aic-shadow);
|
|
85
|
+
display: flex;
|
|
86
|
+
flex-direction: column;
|
|
87
|
+
overflow: hidden;
|
|
88
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
89
|
+
transform-origin: bottom ${o?"left":"right"};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.aicommerce-chat.aicommerce-closed {
|
|
93
|
+
opacity: 0;
|
|
94
|
+
transform: scale(0.9) translateY(20px);
|
|
95
|
+
pointer-events: none;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.aicommerce-chat.aicommerce-open {
|
|
99
|
+
opacity: 1;
|
|
100
|
+
transform: scale(1) translateY(0);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* Header */
|
|
104
|
+
.aicommerce-header {
|
|
105
|
+
background: linear-gradient(135deg, var(--aic-primary), var(--aic-primary-dark));
|
|
106
|
+
color: white;
|
|
107
|
+
padding: 16px 20px;
|
|
108
|
+
display: flex;
|
|
109
|
+
align-items: center;
|
|
110
|
+
justify-content: space-between;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.aicommerce-header-info {
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: center;
|
|
116
|
+
gap: 12px;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.aicommerce-avatar {
|
|
120
|
+
width: 40px;
|
|
121
|
+
height: 40px;
|
|
122
|
+
border-radius: 50%;
|
|
123
|
+
background: rgba(255, 255, 255, 0.2);
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: center;
|
|
127
|
+
font-size: 20px;
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.aicommerce-avatar img {
|
|
132
|
+
width: 100%;
|
|
133
|
+
height: 100%;
|
|
134
|
+
object-fit: cover;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.aicommerce-header-text {
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.aicommerce-bot-name {
|
|
143
|
+
font-weight: 600;
|
|
144
|
+
font-size: 16px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.aicommerce-status {
|
|
148
|
+
font-size: 12px;
|
|
149
|
+
opacity: 0.9;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.aicommerce-close {
|
|
153
|
+
width: 32px;
|
|
154
|
+
height: 32px;
|
|
155
|
+
border-radius: 50%;
|
|
156
|
+
background: rgba(255, 255, 255, 0.2);
|
|
157
|
+
border: none;
|
|
158
|
+
color: white;
|
|
159
|
+
cursor: pointer;
|
|
160
|
+
display: flex;
|
|
161
|
+
align-items: center;
|
|
162
|
+
justify-content: center;
|
|
163
|
+
font-size: 16px;
|
|
164
|
+
transition: background 0.2s;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.aicommerce-close:hover {
|
|
168
|
+
background: rgba(255, 255, 255, 0.3);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* Messages */
|
|
172
|
+
.aicommerce-messages {
|
|
173
|
+
flex: 1;
|
|
174
|
+
overflow-y: auto;
|
|
175
|
+
padding: 20px;
|
|
176
|
+
display: flex;
|
|
177
|
+
flex-direction: column;
|
|
178
|
+
gap: 16px;
|
|
179
|
+
background: var(--aic-bg-secondary);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.aicommerce-message {
|
|
183
|
+
max-width: 85%;
|
|
184
|
+
animation: aic-slide-in 0.3s ease-out;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.aicommerce-message.aicommerce-user {
|
|
188
|
+
align-self: flex-end;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.aicommerce-message.aicommerce-assistant {
|
|
192
|
+
align-self: flex-start;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.aicommerce-message-content {
|
|
196
|
+
padding: 12px 16px;
|
|
197
|
+
border-radius: 16px;
|
|
198
|
+
line-height: 1.5;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.aicommerce-user .aicommerce-message-content {
|
|
202
|
+
background: var(--aic-primary);
|
|
203
|
+
color: white;
|
|
204
|
+
border-bottom-right-radius: 4px;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.aicommerce-assistant .aicommerce-message-content {
|
|
208
|
+
background: var(--aic-bg);
|
|
209
|
+
color: var(--aic-text);
|
|
210
|
+
border-bottom-left-radius: 4px;
|
|
211
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@keyframes aic-slide-in {
|
|
215
|
+
from { opacity: 0; transform: translateY(10px); }
|
|
216
|
+
to { opacity: 1; transform: translateY(0); }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* Typing Indicator */
|
|
220
|
+
.aicommerce-typing {
|
|
221
|
+
display: flex;
|
|
222
|
+
gap: 4px;
|
|
223
|
+
padding: 12px 16px;
|
|
224
|
+
background: var(--aic-bg);
|
|
225
|
+
border-radius: 16px;
|
|
226
|
+
width: fit-content;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.aicommerce-typing span {
|
|
230
|
+
width: 8px;
|
|
231
|
+
height: 8px;
|
|
232
|
+
background: var(--aic-text-secondary);
|
|
233
|
+
border-radius: 50%;
|
|
234
|
+
animation: aic-bounce 1.4s infinite ease-in-out;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.aicommerce-typing span:nth-child(1) { animation-delay: -0.32s; }
|
|
238
|
+
.aicommerce-typing span:nth-child(2) { animation-delay: -0.16s; }
|
|
239
|
+
|
|
240
|
+
@keyframes aic-bounce {
|
|
241
|
+
0%, 80%, 100% { transform: scale(0); }
|
|
242
|
+
40% { transform: scale(1); }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/* Product Cards */
|
|
246
|
+
.aicommerce-products {
|
|
247
|
+
display: flex;
|
|
248
|
+
gap: 8px;
|
|
249
|
+
margin-top: 12px;
|
|
250
|
+
overflow-x: auto;
|
|
251
|
+
padding-bottom: 4px;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.aicommerce-product-card {
|
|
255
|
+
flex-shrink: 0;
|
|
256
|
+
width: 140px;
|
|
257
|
+
background: var(--aic-bg);
|
|
258
|
+
border-radius: 12px;
|
|
259
|
+
overflow: hidden;
|
|
260
|
+
cursor: pointer;
|
|
261
|
+
transition: all 0.2s;
|
|
262
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.aicommerce-product-card:hover {
|
|
266
|
+
transform: translateY(-2px);
|
|
267
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.aicommerce-product-image {
|
|
271
|
+
width: 100%;
|
|
272
|
+
height: 100px;
|
|
273
|
+
object-fit: cover;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.aicommerce-product-placeholder {
|
|
277
|
+
width: 100%;
|
|
278
|
+
height: 100px;
|
|
279
|
+
background: var(--aic-bg-secondary);
|
|
280
|
+
display: flex;
|
|
281
|
+
align-items: center;
|
|
282
|
+
justify-content: center;
|
|
283
|
+
font-size: 32px;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.aicommerce-product-info {
|
|
287
|
+
padding: 10px;
|
|
288
|
+
display: flex;
|
|
289
|
+
flex-direction: column;
|
|
290
|
+
gap: 4px;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.aicommerce-product-name {
|
|
294
|
+
font-weight: 500;
|
|
295
|
+
font-size: 13px;
|
|
296
|
+
color: var(--aic-text);
|
|
297
|
+
white-space: nowrap;
|
|
298
|
+
overflow: hidden;
|
|
299
|
+
text-overflow: ellipsis;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.aicommerce-product-price {
|
|
303
|
+
font-weight: 600;
|
|
304
|
+
font-size: 14px;
|
|
305
|
+
color: var(--aic-primary);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/* Input Area */
|
|
309
|
+
.aicommerce-input-container {
|
|
310
|
+
padding: 16px 20px;
|
|
311
|
+
background: var(--aic-bg);
|
|
312
|
+
border-top: 1px solid var(--aic-border);
|
|
313
|
+
display: flex;
|
|
314
|
+
gap: 12px;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.aicommerce-input {
|
|
318
|
+
flex: 1;
|
|
319
|
+
padding: 12px 16px;
|
|
320
|
+
border: 1px solid var(--aic-border);
|
|
321
|
+
border-radius: 24px;
|
|
322
|
+
background: var(--aic-bg-secondary);
|
|
323
|
+
color: var(--aic-text);
|
|
324
|
+
font-size: 14px;
|
|
325
|
+
outline: none;
|
|
326
|
+
transition: all 0.2s;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.aicommerce-input:focus {
|
|
330
|
+
border-color: var(--aic-primary);
|
|
331
|
+
box-shadow: 0 0 0 3px var(--aic-primary-light);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.aicommerce-input::placeholder {
|
|
335
|
+
color: var(--aic-text-secondary);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.aicommerce-send {
|
|
339
|
+
width: 44px;
|
|
340
|
+
height: 44px;
|
|
341
|
+
border-radius: 50%;
|
|
342
|
+
background: var(--aic-primary);
|
|
343
|
+
border: none;
|
|
344
|
+
color: white;
|
|
345
|
+
cursor: pointer;
|
|
346
|
+
display: flex;
|
|
347
|
+
align-items: center;
|
|
348
|
+
justify-content: center;
|
|
349
|
+
transition: all 0.2s;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.aicommerce-send:hover:not(:disabled) {
|
|
353
|
+
background: var(--aic-primary-dark);
|
|
354
|
+
transform: scale(1.05);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.aicommerce-send:disabled {
|
|
358
|
+
opacity: 0.6;
|
|
359
|
+
cursor: not-allowed;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/* Mobile Responsive */
|
|
363
|
+
@media (max-width: 420px) {
|
|
364
|
+
#aicommerce-widget {
|
|
365
|
+
bottom: 16px;
|
|
366
|
+
${o?"left: 16px;":"right: 16px;"}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.aicommerce-chat {
|
|
370
|
+
width: calc(100vw - 32px);
|
|
371
|
+
height: calc(100vh - 100px);
|
|
372
|
+
border-radius: 12px;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
.aicommerce-launcher {
|
|
376
|
+
width: 56px;
|
|
377
|
+
height: 56px;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/* Scrollbar */
|
|
382
|
+
.aicommerce-messages::-webkit-scrollbar {
|
|
383
|
+
width: 6px;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.aicommerce-messages::-webkit-scrollbar-track {
|
|
387
|
+
background: transparent;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.aicommerce-messages::-webkit-scrollbar-thumb {
|
|
391
|
+
background: var(--aic-border);
|
|
392
|
+
border-radius: 3px;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
.aicommerce-messages::-webkit-scrollbar-thumb:hover {
|
|
396
|
+
background: var(--aic-text-secondary);
|
|
397
|
+
}
|
|
398
|
+
`}function U(t){let e=document.createElement("style");e.id="aicommerce-widget-styles",e.textContent=t;let r=document.getElementById("aicommerce-widget-styles");return r&&r.remove(),document.head.appendChild(e),e}var q=P(()=>{});var M={};L(M,{AICommerceWidget:()=>exports.AICommerceWidget,createWidget:()=>$});function $(t){if(!t.apiKey)throw new Error("AICommerceWidget: apiKey is required");let e=new exports.AICommerce({apiKey:t.apiKey,baseUrl:t.baseUrl}),r={isOpen:false,isLoading:true,messages:[],storeConfig:null},o=null,s=null,n;async function h(){try{let i=t.baseUrl||A(),a=await fetch(`${i}/api/v1/store`,{headers:{"x-api-key":t.apiKey}});return a.ok?(await a.json()).store:null}catch(i){return console.error("Failed to fetch store config:",i),null}}function A(){if(typeof window<"u"){let i=document.querySelector("script[data-aicommerce-url]");if(i)return i.getAttribute("data-aicommerce-url")||""}return "https://api.aicommerce.dev"}async function W(){r.storeConfig=await h(),n={apiKey:t.apiKey,baseUrl:t.baseUrl||A(),position:t.position||"bottom-right",theme:t.theme||"auto",primaryColor:t.primaryColor||r.storeConfig?.primaryColor||"#6366f1",welcomeMessage:t.welcomeMessage||r.storeConfig?.welcomeMessage||"Hi! How can I help you find the perfect product today?",botName:t.botName||r.storeConfig?.chatBotName||"Shopping Assistant",zIndex:t.zIndex||9999,buttonText:t.buttonText||"\u{1F4AC}",hideLauncher:t.hideLauncher||false,onOpen:t.onOpen,onClose:t.onClose,onProductClick:t.onProductClick,onMessage:t.onMessage};let i=T(n);s=U(i),o=document.createElement("div"),o.id="aicommerce-widget",o.className=`aicommerce-widget aicommerce-${n.position} aicommerce-theme-${n.theme}`,document.body.appendChild(o),u(),r.messages.push({role:"assistant",content:n.welcomeMessage}),r.isLoading=false,u();}function u(){if(!o)return;let i=`
|
|
399
|
+
${n.hideLauncher?"":`
|
|
400
|
+
<button class="aicommerce-launcher ${r.isOpen?"aicommerce-hidden":""}" aria-label="Open chat">
|
|
401
|
+
<span class="aicommerce-launcher-icon">${n.buttonText}</span>
|
|
402
|
+
</button>
|
|
403
|
+
`}
|
|
404
|
+
|
|
405
|
+
<div class="aicommerce-chat ${r.isOpen?"aicommerce-open":"aicommerce-closed"}">
|
|
406
|
+
<div class="aicommerce-header">
|
|
407
|
+
<div class="aicommerce-header-info">
|
|
408
|
+
<div class="aicommerce-avatar">
|
|
409
|
+
${r.storeConfig?.logo?`<img src="${r.storeConfig.logo}" alt="${n.botName}" />`:"<span>\u{1F916}</span>"}
|
|
410
|
+
</div>
|
|
411
|
+
<div class="aicommerce-header-text">
|
|
412
|
+
<span class="aicommerce-bot-name">${n.botName}</span>
|
|
413
|
+
<span class="aicommerce-status">Online</span>
|
|
414
|
+
</div>
|
|
415
|
+
</div>
|
|
416
|
+
<button class="aicommerce-close" aria-label="Close chat">\u2715</button>
|
|
417
|
+
</div>
|
|
418
|
+
|
|
419
|
+
<div class="aicommerce-messages">
|
|
420
|
+
${r.messages.map(c=>`
|
|
421
|
+
<div class="aicommerce-message aicommerce-${c.role}">
|
|
422
|
+
<div class="aicommerce-message-content">${w(c.content)}</div>
|
|
423
|
+
${c.products&&c.products.length>0?`
|
|
424
|
+
<div class="aicommerce-products">
|
|
425
|
+
${c.products.map(m=>`
|
|
426
|
+
<div class="aicommerce-product-card" data-product-id="${m.id}">
|
|
427
|
+
${m.imageUrl?`
|
|
428
|
+
<img src="${m.imageUrl}" alt="${w(m.name)}" class="aicommerce-product-image" />
|
|
429
|
+
`:`
|
|
430
|
+
<div class="aicommerce-product-placeholder">\u{1F4E6}</div>
|
|
431
|
+
`}
|
|
432
|
+
<div class="aicommerce-product-info">
|
|
433
|
+
<span class="aicommerce-product-name">${w(m.name)}</span>
|
|
434
|
+
<span class="aicommerce-product-price">${N(m.price,m.currency)}</span>
|
|
435
|
+
</div>
|
|
436
|
+
</div>
|
|
437
|
+
`).join("")}
|
|
438
|
+
</div>
|
|
439
|
+
`:""}
|
|
440
|
+
</div>
|
|
441
|
+
`).join("")}
|
|
442
|
+
${r.isLoading?`
|
|
443
|
+
<div class="aicommerce-message aicommerce-assistant">
|
|
444
|
+
<div class="aicommerce-typing">
|
|
445
|
+
<span></span><span></span><span></span>
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
`:""}
|
|
449
|
+
</div>
|
|
450
|
+
|
|
451
|
+
<div class="aicommerce-input-container">
|
|
452
|
+
<input
|
|
453
|
+
type="text"
|
|
454
|
+
class="aicommerce-input"
|
|
455
|
+
placeholder="Type your message..."
|
|
456
|
+
${r.isLoading?"disabled":""}
|
|
457
|
+
/>
|
|
458
|
+
<button class="aicommerce-send" ${r.isLoading?"disabled":""} aria-label="Send message">
|
|
459
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
460
|
+
<path d="M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"/>
|
|
461
|
+
</svg>
|
|
462
|
+
</button>
|
|
463
|
+
</div>
|
|
464
|
+
</div>
|
|
465
|
+
`;o.innerHTML=i,z();let a=o.querySelector(".aicommerce-messages");a&&(a.scrollTop=a.scrollHeight);}function z(){if(!o)return;let i=o.querySelector(".aicommerce-launcher");i&&i.addEventListener("click",()=>x());let a=o.querySelector(".aicommerce-close");a&&a.addEventListener("click",()=>v());let c=o.querySelector(".aicommerce-input"),m=o.querySelector(".aicommerce-send");c&&c.addEventListener("keypress",f=>{f.key==="Enter"&&c.value.trim()&&(y(c.value.trim()),c.value="");}),m&&c&&m.addEventListener("click",()=>{c.value.trim()&&(y(c.value.trim()),c.value="");}),o.querySelectorAll(".aicommerce-product-card").forEach(f=>{f.addEventListener("click",()=>{let D=f.getAttribute("data-product-id"),O=r.messages.flatMap(C=>C.products||[]).find(C=>C.id===D);O&&n.onProductClick&&n.onProductClick(O);});});}async function y(i){r.messages.push({role:"user",content:i}),r.isLoading=true,u();try{let a=await e.chat(i);return r.messages.push({role:"assistant",content:a.reply,products:a.products}),n.onMessage&&n.onMessage(i,a),a}catch(a){throw r.messages.push({role:"assistant",content:"Sorry, I encountered an error. Please try again."}),a}finally{r.isLoading=false,u();}}function x(){r.isOpen=true,u(),n.onOpen?.(),setTimeout(()=>{o?.querySelector(".aicommerce-input")?.focus();},100);}function v(){r.isOpen=false,u(),n.onClose?.();}function K(){r.isOpen?v():x();}function j(){o&&(o.remove(),o=null),s&&(s.remove(),s=null);}function H(i){if(Object.assign(n,i),i.primaryColor){let a=T(n);s&&(s.textContent=a);}u();}function w(i){let a=document.createElement("div");return a.textContent=i,a.innerHTML}function N(i,a){let m={USD:"$",EUR:"\u20AC",GBP:"\xA3",MAD:"DH",SAR:"SAR",AED:"AED",JPY:"\xA5",CNY:"\xA5"}[a||"USD"]||a||"$";return `${i.toFixed(2)} ${m}`}return W(),{open:x,close:v,toggle:K,destroy:j,sendMessage:y,updateConfig:H}}exports.AICommerceWidget=void 0;var E=P(()=>{b();q();exports.AICommerceWidget={init:$,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=exports.AICommerceWidget);});b();E();var ee="1.0.0";typeof window<"u"&&(window.AICommerce=(b(),I(S)).AICommerce,window.AICommerceError=(b(),I(S)).AICommerceError,window.AICommerceWidget=(E(),I(M)).AICommerceWidget);exports.VERSION=ee;exports.createWidget=$;return exports;})({});//# sourceMappingURL=index.min.js.map
|
|
4
466
|
//# sourceMappingURL=index.min.js.map
|