@askdialog/dialog-sdk 0.0.0-beta-20260605145702

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.
Files changed (59) hide show
  1. package/README.md +408 -0
  2. package/dist/Dialog.d.ts +56 -0
  3. package/dist/Dialog.d.ts.map +1 -0
  4. package/dist/Dialog.js +150 -0
  5. package/dist/EventsHandler.d.ts +16 -0
  6. package/dist/EventsHandler.d.ts.map +1 -0
  7. package/dist/EventsHandler.js +71 -0
  8. package/dist/config/config.development.d.ts +6 -0
  9. package/dist/config/config.development.d.ts.map +1 -0
  10. package/dist/config/config.development.js +4 -0
  11. package/dist/config/config.production.d.ts +6 -0
  12. package/dist/config/config.production.d.ts.map +1 -0
  13. package/dist/config/config.production.js +4 -0
  14. package/dist/config/index.d.ts +6 -0
  15. package/dist/config/index.d.ts.map +1 -0
  16. package/dist/config/index.js +4 -0
  17. package/dist/constants/theme.d.ts +3 -0
  18. package/dist/constants/theme.d.ts.map +1 -0
  19. package/dist/constants/theme.js +21 -0
  20. package/dist/constants/user.d.ts +3 -0
  21. package/dist/constants/user.d.ts.map +1 -0
  22. package/dist/constants/user.js +2 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +3 -0
  26. package/dist/services/base.d.ts +2 -0
  27. package/dist/services/base.d.ts.map +1 -0
  28. package/dist/services/base.js +4 -0
  29. package/dist/services/suggestions.d.ts +3 -0
  30. package/dist/services/suggestions.d.ts.map +1 -0
  31. package/dist/services/suggestions.js +12 -0
  32. package/dist/types/assistantEvent.d.ts +27 -0
  33. package/dist/types/assistantEvent.d.ts.map +1 -0
  34. package/dist/types/assistantEvent.js +12 -0
  35. package/dist/types/constructor.d.ts +19 -0
  36. package/dist/types/constructor.d.ts.map +1 -0
  37. package/dist/types/constructor.js +1 -0
  38. package/dist/types/events.d.ts +50 -0
  39. package/dist/types/events.d.ts.map +1 -0
  40. package/dist/types/events.js +10 -0
  41. package/dist/types/global.d.ts +11 -0
  42. package/dist/types/global.d.ts.map +1 -0
  43. package/dist/types/global.js +1 -0
  44. package/dist/types/index.d.ts +7 -0
  45. package/dist/types/index.d.ts.map +1 -0
  46. package/dist/types/index.js +6 -0
  47. package/dist/types/product.d.ts +36 -0
  48. package/dist/types/product.d.ts.map +1 -0
  49. package/dist/types/product.js +1 -0
  50. package/dist/types/suggestion.d.ts +10 -0
  51. package/dist/types/suggestion.d.ts.map +1 -0
  52. package/dist/types/suggestion.js +1 -0
  53. package/dist/types/theme.d.ts +22 -0
  54. package/dist/types/theme.d.ts.map +1 -0
  55. package/dist/types/theme.js +1 -0
  56. package/dist/utils/localization.d.ts +8 -0
  57. package/dist/utils/localization.d.ts.map +1 -0
  58. package/dist/utils/localization.js +21 -0
  59. package/package.json +57 -0
package/README.md ADDED
@@ -0,0 +1,408 @@
1
+ # Dialog SDK
2
+
3
+ ## Dialog
4
+
5
+ Dialog is an AI assistant designed to boost e-commerce sales by providing intelligent product recommendations and seamless customer interactions.
6
+
7
+ Visit our website: [Dialog AI Assistant](https://www.askdialog.com/)
8
+
9
+ ## Description
10
+
11
+ Dialog SDK is a powerful TypeScript library that seamlessly integrates the Dialog AI assistant into your applications. It provides a comprehensive set of tools for managing assistant interactions, handling e-commerce operations like product fetching and cart management, and customizing the assistant's appearance to match your brand.
12
+
13
+ ## Get started
14
+
15
+ ### Prerequisites
16
+
17
+ Before using the Dialog SDK, you need:
18
+
19
+ - An active API Key, you can retrieve your api key in your [organization settings](https://app.askdialog.com/settings)
20
+
21
+ ### Installation
22
+
23
+ ```bash
24
+ npm install @dialog/dialog-sdk
25
+ # or
26
+ pnpm add @dialog/dialog-sdk
27
+ # or
28
+ yarn add @dialog/dialog-sdk
29
+ ```
30
+
31
+ You can also use our CDN link if you’re not using a package manager.
32
+
33
+ - Add the script to your project (replace X, Y, Z by versions)
34
+
35
+ ```html
36
+ <script src="https://d2m6yt8rnm4dos.cloudfront.net/dialog-sdk.X.Y.Z.min.js"></script>
37
+ ```
38
+ - The `DialogSDK` object will be available on the `window`. You can access all features as shown below:
39
+ ```typescript
40
+
41
+ const client = new window.DialogSDK.Dialog({
42
+ apiKey: 'YOUR_API_KEY',
43
+ // ........
44
+ })
45
+ ```
46
+
47
+ ### Instantiate the client
48
+
49
+ ```typescript
50
+ import { Dialog } from '@dialog/dialog-sdk';
51
+
52
+ const client = new Dialog({
53
+ apiKey: 'YOUR_API_KEY', // required
54
+ locale: 'TARGETED_LOCALE', // required
55
+ callbacks: {
56
+ addToCart: async ({
57
+ productId,
58
+ quantity,
59
+ currency,
60
+ variantId,
61
+ price,
62
+ }: {
63
+ productId: string;
64
+ quantity: number;
65
+ currency?: string;
66
+ variantId?: string;
67
+ price?: string;
68
+ }) => Promise<void>, // required
69
+ getProduct: async (
70
+ productId: string,
71
+ variantId?: string
72
+ ) => Promise<SimplifiedProduct>, // required
73
+ },
74
+ });
75
+ ```
76
+
77
+ The apiKey is required to authenticate with our API and interact with our assistant.
78
+ The locale specifies the language you want to use.
79
+ The addToCart function is triggered when a user clicks the AddToCart button.
80
+ The getProduct function is used to display product information in the assistant.
81
+
82
+ When the client is instantiated, it will automatically insert into the DOM the Dialog Assistant script, so you can interact with the assistant using `sendProductMessage` or `sendGenericMessage`.
83
+
84
+ ### Getters
85
+
86
+ - apiKey
87
+ - theme
88
+ - userId
89
+ - locale
90
+
91
+ ### Features
92
+
93
+ - Send a message with context
94
+
95
+ ```typescript
96
+ client.sendProductMessage({
97
+ question: 'YOUR_QUESTION', // required
98
+ productId: 'PRODUCT_ID', // required
99
+ productTitle: 'PRODUCT_TITLE', // required
100
+ answer: '', // Optional
101
+ selectedVariantId?: 'CURRENT_VARIANT_ID', // Optional
102
+ })
103
+ ```
104
+
105
+ - Send message without context
106
+
107
+ ```typescript
108
+ client.sendGenericMessage({
109
+ question: 'YOUR_QUESTION', // required
110
+ });
111
+ ```
112
+
113
+ - Get locale information
114
+
115
+ ```typescript
116
+ const localizationInfos = await client.getLocalizationInformations();
117
+
118
+ /*
119
+ Example of expected result when locale: 'en'
120
+ {
121
+ countryCode: "US",
122
+ formatted: "en-US",
123
+ language: "English",
124
+ locale: "en"
125
+ }
126
+ */
127
+ ```
128
+
129
+ - Get suggestion questions
130
+
131
+ You can use this query to make your own integration and trigger `sendProductMessage` or `sendGenericMessage` on user click.
132
+
133
+ ```typescript
134
+ const suggestions = await client.getSuggestions(productId);
135
+
136
+ /*
137
+ Example of expected result:
138
+ {
139
+ "questions": [
140
+ {
141
+ "question": "What is the formula used in this repairing gel to soothe the skin after sun exposure?"
142
+ },
143
+ {
144
+ "question": "How does this gel relieve sunburn and reduce pain?"
145
+ },
146
+ {
147
+ "question": "What are the benefits for the skin after using this product following excessive exposure to UV rays?"
148
+ }
149
+ ],
150
+ "assistantName": "Your expert",
151
+ "inputPlaceholder": "Ask any question...",
152
+ "description": "Ask any question about this product"
153
+ }
154
+ */
155
+ ```
156
+
157
+
158
+ - Handler for fetch product
159
+
160
+ The `getProduct` callback is called by the assistant to display product information. You must return an object matching the `SimplifiedProduct` interface.
161
+
162
+ **Parameters:**
163
+
164
+ | Parameter | Type | Required | Description |
165
+ |-----------|------|----------|-------------|
166
+ | `productId` | `string` | Yes | The product identifier |
167
+ | `variantId` | `string` | No | The selected variant identifier |
168
+
169
+ **Return type: `SimplifiedProduct`**
170
+
171
+ | Field | Type | Required | Description |
172
+ |-------|------|----------|-------------|
173
+ | `id` | `string` | Yes | Product identifier |
174
+ | `title` | `string` | Yes | Product name |
175
+ | `handle` | `string` | Yes | URL-friendly product slug |
176
+ | `totalInventory` | `number` | Yes | Total available stock across all variants |
177
+ | `variants` | `SimplifiedProductVariant[]` | Yes | List of product variants (see below) |
178
+ | `descriptionHtml` | `string` | No | Product description in HTML |
179
+ | `url` | `string` | No | Product page URL |
180
+ | `featuredImage` | `{ url?: string } \| null` | No | Main product image |
181
+ | `options` | `SimplifiedProductOption[]` | No | Product options (size, color, etc.) |
182
+
183
+ **Variant: `SimplifiedProductVariant`**
184
+
185
+ | Field | Type | Required | Description |
186
+ |-------|------|----------|-------------|
187
+ | `id` | `string` | Yes | Variant identifier |
188
+ | `price` | `string` | Yes | Variant price (e.g. `"29.99"`) |
189
+ | `currencyCode` | `string` | Yes | ISO 4217 currency code (e.g. `"EUR"`, `"USD"`) |
190
+ | `displayName` | `string` | No | Variant display name |
191
+ | `inventoryQuantity` | `number` | No | Available stock for this variant |
192
+ | `compareAtPrice` | `string \| null` | No | Original price before discount |
193
+ | `url` | `string` | No | Variant-specific page URL |
194
+ | `selectedOptions` | `{ name: string; value: string }[]` | No | Option values for this variant (e.g. `[{ name: "Size", value: "M" }]`) |
195
+ | `image` | `{ url?: string } \| null` | No | Variant-specific image |
196
+
197
+ **Option: `SimplifiedProductOption`** *(optional)*
198
+
199
+ | Field | Type | Required | Description |
200
+ |-------|------|----------|-------------|
201
+ | `id` | `string` | Yes | Option identifier |
202
+ | `name` | `string` | Yes | Option name (e.g. `"Size"`, `"Color"`) |
203
+ | `position` | `number` | Yes | Display order |
204
+ | `values` | `string[]` | Yes | Available values (e.g. `["S", "M", "L"]`) |
205
+
206
+ **Example:**
207
+
208
+ ```typescript
209
+ const client = new Dialog({
210
+ ...,
211
+ callbacks: {
212
+ getProduct: async (
213
+ productId: string,
214
+ variantId?: string,
215
+ ): Promise<SimplifiedProduct> => {
216
+ const response = await fetch(`https://your-api.com/products/${productId}`);
217
+ const data = await response.json();
218
+
219
+ return {
220
+ id: data.id,
221
+ title: data.name,
222
+ handle: data.slug,
223
+ totalInventory: data.stock,
224
+ featuredImage: { url: data.imageUrl },
225
+ variants: data.variants.map((v: any) => ({
226
+ id: v.id,
227
+ price: v.price.toString(),
228
+ currencyCode: 'EUR',
229
+ displayName: v.name,
230
+ inventoryQuantity: v.stock,
231
+ compareAtPrice: v.originalPrice?.toString() ?? null,
232
+ selectedOptions: v.options,
233
+ image: v.imageUrl ? { url: v.imageUrl } : null,
234
+ })),
235
+ options: data.options?.map((o: any) => ({
236
+ id: o.id,
237
+ name: o.name,
238
+ position: o.position,
239
+ values: o.values,
240
+ })),
241
+ };
242
+ },
243
+ },
244
+ });
245
+ ```
246
+
247
+ - Handler for add to cart
248
+
249
+ ```typescript
250
+ const client = new Dialog({
251
+ ...,
252
+ callbacks: {
253
+ addToCart: ({
254
+ productId,
255
+ quantity,
256
+ variantId,
257
+ currency
258
+ }: {
259
+ productId: string;
260
+ quantity: number;
261
+ currency?: string;
262
+ variantId?: string;
263
+ }): Promise<void> => {
264
+ // Call your api to trigger addToCart
265
+ const response = await fetch('....');
266
+
267
+ // Trigger other stuff like confirmation modal
268
+ return;
269
+ }
270
+ },
271
+ });
272
+ ```
273
+
274
+
275
+ ### Theming (Still in construction)
276
+
277
+ We are currently working on the theming part so you may find some issues. Contact us if you need more customization.
278
+
279
+
280
+ ⚠️ Title, description and content properties are used only to theme the Vue component for the moment.
281
+
282
+ ```typescript
283
+ const client = new Dialog({
284
+ ...,
285
+ theme: {
286
+ backgroundColor?: string;
287
+ primaryColor?: string;
288
+ ctaTextColor?: string;
289
+ ctaBorderType?: 'straight' | 'rounded';
290
+ capitalizeCtas?: boolean;
291
+ fontFamily?: string;
292
+ highlightProductName?: boolean;
293
+ title?: { // Used in Vue component only
294
+ fontSize?: string;
295
+ color?: string;
296
+ }
297
+ description?: { // Used in Vue component only
298
+ fontSize?: string;
299
+ color?: string;
300
+ }
301
+ content?: { // Used in Vue component only
302
+ fontSize?: string;
303
+ color?: string;
304
+ }
305
+ }
306
+ });
307
+ ```
308
+
309
+ ### Tracking
310
+
311
+ Our SDK includes a tracking system to monitor user interactions in your purchase flow.
312
+
313
+ #### Automatic Tracking
314
+
315
+ When a user interacts with our assistant and clicks on an "Add to Cart" CTA, it automatically triggers the previously configured `addToCart` callback (see "Client Instantiation" section). These events are tracked internally by our system.
316
+
317
+ #### Manual Tracking
318
+
319
+ However, we cannot automatically detect cart additions or checkout completions that occur **after** using our assistant. To get accurate data in your Dialog dashboards, you should use the following tracking methods:
320
+
321
+ #### Available Methods
322
+
323
+ ```typescript
324
+
325
+ client.registerAddToCartEvent({
326
+ productId: 'ProductIdentifier', // {string} - Required
327
+ quantity: 1, // {number} - Required
328
+ currency: 'EUR', // {string} - Optional
329
+ variantId: 'VariantIdentifier', // {string} - Optional
330
+ price: '12.00' // {string} - Optional
331
+ });
332
+
333
+ client.registerSubmitCheckoutEvent({
334
+ productId: 'ProductIdentifier', // {string} - Required
335
+ quantity: 1, // {number} - Required
336
+ price: '12.00', // {string} - Required
337
+ currency: 'EUR', // {string} - Optional
338
+ variantId: 'VariantIdentifier' // {string} - Optional
339
+ });
340
+ ```
341
+
342
+ #### Listen for Assistant Events
343
+
344
+ The SDK provides real-time event listening for user interactions with the Dialog assistant.
345
+
346
+ ```typescript
347
+ // Basic event listener setup
348
+ const unsubscribe = client.onAssistantEvent((event) => {
349
+ console.log('Event type:', event.type);
350
+ console.log('Event payload:', event.payload);
351
+ });
352
+
353
+ // Clean up the event listener when needed
354
+ unsubscribe();
355
+ ```
356
+
357
+ #### Event Structure
358
+
359
+ All events follow this structure:
360
+
361
+ ```typescript
362
+ interface AssistantEvent {
363
+ type: string;
364
+ payload: {
365
+ // Common fields (included in all events)
366
+ date: string; // ISO timestamp
367
+ locale: string; // Current locale
368
+ url: string; // Current page URL
369
+ userId?: string; // User ID if available
370
+
371
+ // Event-specific fields
372
+ productId?: string; // When interacting with products
373
+ variantId?: string; // When interacting with variants
374
+ }
375
+ }
376
+ ```
377
+
378
+ #### Available Event Types
379
+
380
+ - **userOpenedAssistant** - User opened the assistant interface
381
+ - **userClosedAssistant** - User closed the assistant interface
382
+ - **userSentMessage** - User sent a message to the assistant
383
+ - **userClickedOnProductCard** - User clicked on a product card for more details
384
+ - **userOpenedRecommendation** - User clicked on a product recommendation
385
+ - **userAddedToCart** - User added a product to cart via the assistant
386
+ - **userSendPositiveFeedback** - User gave positive feedback on AI response
387
+ - **userSendNegativeFeedback** - User gave negative feedback on AI response
388
+
389
+ #### Example Usage
390
+
391
+ ```typescript
392
+ client.onAssistantEvent((event) => {
393
+ switch (event.type) {
394
+ case 'userAddedToCart':
395
+ // Track conversion in your analytics
396
+ analytics.track('assistant_conversion', {
397
+ productId: event.payload.productId,
398
+ timestamp: event.payload.date
399
+ });
400
+ break;
401
+
402
+ case 'userSendNegativeFeedback':
403
+ // Log for improvement analysis
404
+ console.log('Negative feedback at:', event.payload.url);
405
+ break;
406
+ }
407
+ });
408
+ ```
@@ -0,0 +1,56 @@
1
+ import { DialogConstructor } from "./types/constructor";
2
+ import { Theme } from "./types/theme";
3
+ import { DetailedLocaleInfo } from "./utils/localization";
4
+ import { Suggestion } from "./types/suggestion";
5
+ import { GenericQuestionPayload, OpenAssistantPayload, ProductQuestionPayload } from "./types/events";
6
+ import { SimplifiedProduct } from "./types/product";
7
+ import { EventsHandler } from "./EventsHandler";
8
+ import { AssistantEvent } from "./types/assistantEvent";
9
+ export declare class Dialog {
10
+ static readonly VERSION: string;
11
+ private _apiKey;
12
+ private _locale;
13
+ private _callbacks;
14
+ private _theme;
15
+ private _userId;
16
+ private _eventsHandler;
17
+ constructor({ apiKey, locale, callbacks, theme, userId }: DialogConstructor);
18
+ get apiKey(): string;
19
+ get theme(): Theme;
20
+ get userId(): string;
21
+ get locale(): string;
22
+ get eventsHandler(): EventsHandler;
23
+ getLocalizationInformations(): DetailedLocaleInfo | null;
24
+ private _createOrRetrieveUserId;
25
+ getSuggestions(productId: string): Promise<Suggestion>;
26
+ openAssistant(params: OpenAssistantPayload): void;
27
+ closeAssistant(): void;
28
+ sendProductMessage(params: ProductQuestionPayload): void;
29
+ sendGenericMessage(params: GenericQuestionPayload): void;
30
+ onAssistantEvent(listener: (event: AssistantEvent) => void): void;
31
+ dispatchAssistantEvent(event: AssistantEvent): void;
32
+ getProduct(productId: string, variantId?: string): Promise<SimplifiedProduct>;
33
+ addToCart({ productId, quantity, currency, variantId, price, }: {
34
+ productId: string;
35
+ quantity: number;
36
+ price?: string;
37
+ currency?: string;
38
+ variantId?: string;
39
+ }): Promise<void>;
40
+ registerAddToCartEvent({ productId, quantity, currency, variantId, price, }: {
41
+ productId: string;
42
+ quantity: number;
43
+ price?: string;
44
+ currency?: string;
45
+ variantId?: string;
46
+ }): void;
47
+ registerSubmitCheckoutEvent({ productId, quantity, currency, variantId, price, }: {
48
+ productId: string;
49
+ quantity: number;
50
+ price: string;
51
+ currency?: string;
52
+ variantId?: string;
53
+ }): void;
54
+ private _loadAssistant;
55
+ }
56
+ //# sourceMappingURL=Dialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../src/Dialog.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,kBAAkB,EAEnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAEL,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,qBAAa,MAAM;IACjB,gBAAuB,OAAO,SAAuB;IAErD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,UAAU,CAGhB;IACF,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAgB;gBAE1B,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,iBAAiB;IAc3E,IAAW,MAAM,IAAI,MAAM,CAE1B;IACD,IAAW,KAAK,IAAI,KAAK,CAExB;IACD,IAAW,MAAM,IAAI,MAAM,CAE1B;IACD,IAAW,MAAM,IAAI,MAAM,CAE1B;IACD,IAAW,aAAa,IAAI,aAAa,CAExC;IAEM,2BAA2B,IAAI,kBAAkB,GAAG,IAAI;IAI/D,OAAO,CAAC,uBAAuB;IAkBlB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAK5D,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAKjD,cAAc,IAAI,IAAI;IAItB,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAIxD,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAOxD,gBAAgB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;IAIjE,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAInD,UAAU,CACf,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,CAAC;IAIhB,SAAS,CAAC,EACrB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBV,sBAAsB,CAAC,EAC5B,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI;IAWD,2BAA2B,CAAC,EACjC,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI;IAWR,OAAO,CAAC,cAAc;CA4BvB"}
package/dist/Dialog.js ADDED
@@ -0,0 +1,150 @@
1
+ /* eslint-disable max-lines */
2
+ import { uuidv7 } from "uuidv7";
3
+ import packageJson from "../package.json";
4
+ import { defaultTheme } from "./constants/theme";
5
+ import { getDetailedLocaleInfo, } from "./utils/localization";
6
+ import { ANONYMOUS_CUSTOMER_ID, CUSTOMER_ID } from "./constants/user";
7
+ import { DialogEvents, } from "./types/events";
8
+ import { EventsHandler } from "./EventsHandler";
9
+ import { loadSuggestions } from "./services/suggestions";
10
+ import { config } from "./config";
11
+ export class Dialog {
12
+ static VERSION = packageJson.version;
13
+ _apiKey;
14
+ _locale;
15
+ _callbacks;
16
+ _theme;
17
+ _userId;
18
+ _eventsHandler;
19
+ constructor({ apiKey, locale, callbacks, theme, userId }) {
20
+ this._apiKey = apiKey;
21
+ this._locale = locale;
22
+ this._callbacks = callbacks;
23
+ this._theme = { ...defaultTheme, ...theme };
24
+ this._userId = this._createOrRetrieveUserId(userId);
25
+ this._eventsHandler = new EventsHandler(locale, userId);
26
+ window.dialog = {
27
+ instance: this,
28
+ version: Dialog.VERSION,
29
+ };
30
+ this._loadAssistant();
31
+ }
32
+ get apiKey() {
33
+ return this._apiKey;
34
+ }
35
+ get theme() {
36
+ return this._theme;
37
+ }
38
+ get userId() {
39
+ return this._userId;
40
+ }
41
+ get locale() {
42
+ return this._locale;
43
+ }
44
+ get eventsHandler() {
45
+ return this._eventsHandler;
46
+ }
47
+ getLocalizationInformations() {
48
+ return getDetailedLocaleInfo(this._locale);
49
+ }
50
+ _createOrRetrieveUserId(userId) {
51
+ if (userId !== undefined) {
52
+ localStorage.setItem(CUSTOMER_ID, userId);
53
+ return userId;
54
+ }
55
+ const existingAnonymousUserId = localStorage.getItem(ANONYMOUS_CUSTOMER_ID);
56
+ if (existingAnonymousUserId !== null) {
57
+ return existingAnonymousUserId;
58
+ }
59
+ const newUserId = uuidv7();
60
+ localStorage.setItem(ANONYMOUS_CUSTOMER_ID, newUserId);
61
+ return newUserId;
62
+ }
63
+ async getSuggestions(productId) {
64
+ return loadSuggestions(this._apiKey, this._locale, productId);
65
+ }
66
+ // TODO: Not yet implemented on assistant
67
+ openAssistant(params) {
68
+ this._eventsHandler.emitExternalEvent(DialogEvents.OPEN_ASSISTANT, params);
69
+ }
70
+ // TODO: Not yet implemented on assistant
71
+ closeAssistant() {
72
+ this._eventsHandler.emitExternalEvent(DialogEvents.CLOSE_ASSISTANT);
73
+ }
74
+ sendProductMessage(params) {
75
+ this._eventsHandler.emitExternalEvent(DialogEvents.SEND_MESSAGE, params);
76
+ }
77
+ sendGenericMessage(params) {
78
+ this._eventsHandler.emitExternalEvent(DialogEvents.SEND_GENERIC_QUESTION, params);
79
+ }
80
+ onAssistantEvent(listener) {
81
+ this._eventsHandler.onAssistantEvent(listener);
82
+ }
83
+ dispatchAssistantEvent(event) {
84
+ this._eventsHandler.emitAssistantEvent(event.type, event.payload);
85
+ }
86
+ getProduct(productId, variantId) {
87
+ return this._callbacks.getProduct(productId, variantId);
88
+ }
89
+ async addToCart({ productId, quantity, currency, variantId, price, }) {
90
+ await this._callbacks.addToCart({
91
+ productId,
92
+ variantId,
93
+ quantity,
94
+ currency,
95
+ price,
96
+ });
97
+ this.registerAddToCartEvent({
98
+ productId,
99
+ variantId,
100
+ quantity,
101
+ currency,
102
+ price,
103
+ });
104
+ return;
105
+ }
106
+ registerAddToCartEvent({ productId, quantity, currency, variantId, price, }) {
107
+ this._eventsHandler.emitExternalEvent(DialogEvents.TRACK_ADD_TO_CART, {
108
+ userId: this._userId,
109
+ productId,
110
+ variantId,
111
+ quantity,
112
+ price,
113
+ currency,
114
+ });
115
+ }
116
+ registerSubmitCheckoutEvent({ productId, quantity, currency, variantId, price, }) {
117
+ this._eventsHandler.emitExternalEvent(DialogEvents.TRACK_SUBMIT_CHECKOUT, {
118
+ userId: this._userId,
119
+ productId,
120
+ variantId,
121
+ quantity,
122
+ price,
123
+ currency,
124
+ });
125
+ }
126
+ _loadAssistant() {
127
+ const localeInfo = getDetailedLocaleInfo(this._locale);
128
+ if (localeInfo === null) {
129
+ console.error("Missing locale information");
130
+ return;
131
+ }
132
+ const div = document.createElement("div");
133
+ div.id = "dialog-shopify-ai";
134
+ div.dataset.shopIsoCode = this._locale;
135
+ div.dataset.apiKey = this._apiKey;
136
+ div.dataset.userId = this._userId;
137
+ div.dataset.countryCode = localeInfo.countryCode;
138
+ div.dataset.language = localeInfo.language;
139
+ document.body.appendChild(div);
140
+ setTimeout(() => {
141
+ const script = document.createElement("script");
142
+ script.type = "text/javascript";
143
+ script.defer = true;
144
+ script.async = true;
145
+ script.type = "module";
146
+ script.src = config.assistantUrl;
147
+ document.head.insertBefore(script, document.head.firstChild);
148
+ }, 50);
149
+ }
150
+ }
@@ -0,0 +1,16 @@
1
+ import { AssistantEvent, AssistantEventPayload, CommonPayload, GenericAssistantEventPayload } from "./types/assistantEvent";
2
+ import { DialogEvent } from "./types/events";
3
+ export declare class EventsHandler {
4
+ private _locale;
5
+ private _userId?;
6
+ private _consumerReady;
7
+ private _bufferedEvents;
8
+ constructor(locale: string, userId?: string);
9
+ emitExternalEvent(type: DialogEvent["type"], payload?: DialogEvent["payload"]): void;
10
+ notifyConsumerReady(): void;
11
+ notifyConsumerGone(): void;
12
+ private _dispatchExternalEvent;
13
+ emitAssistantEvent(type: AssistantEvent["type"], payload?: GenericAssistantEventPayload): void;
14
+ onAssistantEvent(listener: (event: AssistantEvent<CommonPayload & AssistantEventPayload>) => void): () => void;
15
+ }
16
+ //# sourceMappingURL=EventsHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventsHandler.d.ts","sourceRoot":"","sources":["../src/EventsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,aAAa,EAEb,4BAA4B,EAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAuB,WAAW,EAAgB,MAAM,gBAAgB,CAAC;AAehF,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,eAAe,CAAuB;gBAElC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAKpC,iBAAiB,CACtB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EACzB,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,GAC/B,IAAI;IAYA,mBAAmB,IAAI,IAAI;IAU3B,kBAAkB,IAAI,IAAI;IAIjC,OAAO,CAAC,sBAAsB;IAWvB,kBAAkB,CACvB,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,4BAA4B,GACrC,IAAI;IAQA,gBAAgB,CACrB,QAAQ,EAAE,CACR,KAAK,EAAE,cAAc,CAAC,aAAa,GAAG,qBAAqB,CAAC,KACzD,IAAI,GACR,MAAM,IAAI;CA0Bd"}
@@ -0,0 +1,71 @@
1
+ import { DIALOG_ASSISTANT_EVENT, } from "./types/assistantEvent";
2
+ import { DIALOG_CUSTOM_EVENT, DialogEvents } from "./types/events";
3
+ // Tracking events can fire (e.g. add-to-cart on page load) before the host app
4
+ // has mounted its listener. We buffer those until a consumer signals readiness,
5
+ // then flush, so none are dispatched into the void.
6
+ const BUFFERED_EVENT_TYPES = new Set([
7
+ DialogEvents.TRACK_ADD_TO_CART,
8
+ DialogEvents.TRACK_SUBMIT_CHECKOUT,
9
+ ]);
10
+ export class EventsHandler {
11
+ _locale;
12
+ _userId;
13
+ _consumerReady = false;
14
+ _bufferedEvents = [];
15
+ constructor(locale, userId) {
16
+ this._locale = locale;
17
+ this._userId = userId;
18
+ }
19
+ emitExternalEvent(type, payload) {
20
+ if (!this._consumerReady && BUFFERED_EVENT_TYPES.has(type)) {
21
+ this._bufferedEvents.push({ type, payload });
22
+ return;
23
+ }
24
+ this._dispatchExternalEvent(type, payload);
25
+ }
26
+ // Signalled by the host app once its tracking listener is attached. Flushing
27
+ // here (not on emit) guarantees buffered events reach an existing listener.
28
+ notifyConsumerReady() {
29
+ this._consumerReady = true;
30
+ const buffered = this._bufferedEvents;
31
+ this._bufferedEvents = [];
32
+ buffered.forEach(({ type, payload }) => this._dispatchExternalEvent(type, payload));
33
+ }
34
+ notifyConsumerGone() {
35
+ this._consumerReady = false;
36
+ }
37
+ _dispatchExternalEvent(type, payload) {
38
+ const event = new CustomEvent(DIALOG_CUSTOM_EVENT, {
39
+ detail: { type, payload },
40
+ });
41
+ window.dispatchEvent(event);
42
+ }
43
+ emitAssistantEvent(type, payload) {
44
+ const event = new CustomEvent(DIALOG_ASSISTANT_EVENT, {
45
+ detail: { type, payload },
46
+ });
47
+ window.dispatchEvent(event);
48
+ }
49
+ onAssistantEvent(listener) {
50
+ const handler = (e) => {
51
+ const customEvent = e;
52
+ const commonPayload = {
53
+ locale: this._locale,
54
+ url: window.location.href,
55
+ date: new Date().toISOString(),
56
+ };
57
+ listener({
58
+ type: customEvent.detail.type,
59
+ payload: {
60
+ userId: this._userId,
61
+ ...commonPayload,
62
+ ...customEvent.detail.payload,
63
+ },
64
+ });
65
+ };
66
+ window.addEventListener(DIALOG_ASSISTANT_EVENT, handler);
67
+ return () => {
68
+ window.removeEventListener(DIALOG_ASSISTANT_EVENT, handler);
69
+ };
70
+ }
71
+ }
@@ -0,0 +1,6 @@
1
+ export declare const config: {
2
+ baseApiUrl: string;
3
+ assistantUrl: string;
4
+ };
5
+ export type Config = typeof config;
6
+ //# sourceMappingURL=config.development.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.development.d.ts","sourceRoot":"","sources":["../../src/config/config.development.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const config = {
2
+ baseApiUrl: "https://abkjr5ukvi.execute-api.eu-west-1.amazonaws.com",
3
+ assistantUrl: "https://d2bycosa71tnxv.cloudfront.net/assets/index.js",
4
+ };
@@ -0,0 +1,6 @@
1
+ export declare const config: {
2
+ baseApiUrl: string;
3
+ assistantUrl: string;
4
+ };
5
+ export type Config = typeof config;
6
+ //# sourceMappingURL=config.production.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.production.d.ts","sourceRoot":"","sources":["../../src/config/config.production.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const config = {
2
+ baseApiUrl: "https://rtbzcxkmwj.execute-api.eu-west-1.amazonaws.com",
3
+ assistantUrl: "https://d2zm7i5bmzo6ze.cloudfront.net/assets/index.js",
4
+ };
@@ -0,0 +1,6 @@
1
+ export declare const config: {
2
+ baseApiUrl: string;
3
+ assistantUrl: string;
4
+ };
5
+ export type Config = typeof config;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const config = {
2
+ baseApiUrl: "https://rtbzcxkmwj.execute-api.eu-west-1.amazonaws.com",
3
+ assistantUrl: "https://d2zm7i5bmzo6ze.cloudfront.net/assets/index.js",
4
+ };
@@ -0,0 +1,3 @@
1
+ import { Theme } from "../types/theme";
2
+ export declare const defaultTheme: Theme;
3
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/constants/theme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,eAAO,MAAM,YAAY,EAAE,KAoB1B,CAAC"}
@@ -0,0 +1,21 @@
1
+ export const defaultTheme = {
2
+ backgroundColor: "#FFFFFF",
3
+ primaryColor: "#000000",
4
+ ctaTextColor: "#FFFFFF",
5
+ ctaBorderType: "rounded",
6
+ capitalizeCtas: false,
7
+ fontFamily: "Inter, sans-serif",
8
+ highlightProductName: true,
9
+ title: {
10
+ fontSize: "16px",
11
+ color: "#000000",
12
+ },
13
+ description: {
14
+ fontSize: "14px",
15
+ color: "#000000",
16
+ },
17
+ content: {
18
+ fontSize: "14px",
19
+ color: "#000000",
20
+ },
21
+ };
@@ -0,0 +1,3 @@
1
+ export declare const ANONYMOUS_CUSTOMER_ID = "ANONYMOUS_CUSTOMER_ID";
2
+ export declare const CUSTOMER_ID = "CUSTOMER_ID";
3
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/constants/user.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAC7D,eAAO,MAAM,WAAW,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const ANONYMOUS_CUSTOMER_ID = "ANONYMOUS_CUSTOMER_ID";
2
+ export const CUSTOMER_ID = "CUSTOMER_ID";
@@ -0,0 +1,4 @@
1
+ export * from "./Dialog";
2
+ export * from "./EventsHandler";
3
+ export * from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./Dialog";
2
+ export * from "./EventsHandler";
3
+ export * from "./types";
@@ -0,0 +1,2 @@
1
+ export declare const getBaseApiUrl: () => string;
2
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/services/base.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,QAAO,MAEhC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { config } from "../config";
2
+ export const getBaseApiUrl = () => {
3
+ return config.baseApiUrl;
4
+ };
@@ -0,0 +1,3 @@
1
+ import { Suggestion } from "../types/suggestion";
2
+ export declare const loadSuggestions: (apiKey: string, locale: string, productId: string) => Promise<Suggestion>;
3
+ //# sourceMappingURL=suggestions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestions.d.ts","sourceRoot":"","sources":["../../src/services/suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,WAAW,MAAM,KAChB,OAAO,CAAC,UAAU,CAiBpB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { getBaseApiUrl } from "./base";
2
+ export const loadSuggestions = async (apiKey, locale, productId) => {
3
+ const pagePath = window.location.pathname.split("?")[0];
4
+ const baseApiUrl = getBaseApiUrl();
5
+ const response = await fetch(`${baseApiUrl}/ai/product-questions?pagePath=${pagePath}&locale=${locale}&productId=${productId}`, {
6
+ headers: {
7
+ Authorization: apiKey,
8
+ },
9
+ });
10
+ const data = await response.json();
11
+ return data;
12
+ };
@@ -0,0 +1,27 @@
1
+ export declare const DIALOG_ASSISTANT_EVENT = "dialogAssistantEvent";
2
+ export declare enum AssistantEvents {
3
+ USER_OPENED_ASSISTANT = "userOpenedAssistant",
4
+ USER_CLOSED_ASSISTANT = "userClosedAssistant",
5
+ USER_SENT_MESSAGE = "userSentMessage",
6
+ USER_CLICKED_ON_PRODUCT_CARD = "userClickedOnProductCard",
7
+ USER_OPENED_RECOMMENDATION = "userOpenedRecommendation",
8
+ USER_ADDED_TO_CART = "userAddedToCart",
9
+ USER_SEND_POSITIVE_FEEDBACK = "userSendPositiveFeedback",
10
+ USER_SEND_NEGATIVE_FEEDBACK = "userSendNegativeFeedback"
11
+ }
12
+ export interface CommonPayload {
13
+ date: string;
14
+ locale: string;
15
+ url: string;
16
+ }
17
+ export interface GenericAssistantEventPayload {
18
+ userId?: string;
19
+ productId?: string;
20
+ variantId?: string;
21
+ }
22
+ export type AssistantEventPayload = GenericAssistantEventPayload;
23
+ export interface AssistantEvent<T = AssistantEventPayload> {
24
+ type: AssistantEvents;
25
+ payload: T;
26
+ }
27
+ //# sourceMappingURL=assistantEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistantEvent.d.ts","sourceRoot":"","sources":["../../src/types/assistantEvent.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,yBAAyB,CAAC;AAE7D,oBAAY,eAAe;IACzB,qBAAqB,wBAAwB;IAC7C,qBAAqB,wBAAwB;IAC7C,iBAAiB,oBAAoB;IACrC,4BAA4B,6BAA6B;IACzD,0BAA0B,6BAA6B;IACvD,kBAAkB,oBAAoB;IACtC,2BAA2B,6BAA6B;IACxD,2BAA2B,6BAA6B;CACzD;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,4BAA4B;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAEjE,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,qBAAqB;IACvD,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC;CACZ"}
@@ -0,0 +1,12 @@
1
+ export const DIALOG_ASSISTANT_EVENT = "dialogAssistantEvent";
2
+ export var AssistantEvents;
3
+ (function (AssistantEvents) {
4
+ AssistantEvents["USER_OPENED_ASSISTANT"] = "userOpenedAssistant";
5
+ AssistantEvents["USER_CLOSED_ASSISTANT"] = "userClosedAssistant";
6
+ AssistantEvents["USER_SENT_MESSAGE"] = "userSentMessage";
7
+ AssistantEvents["USER_CLICKED_ON_PRODUCT_CARD"] = "userClickedOnProductCard";
8
+ AssistantEvents["USER_OPENED_RECOMMENDATION"] = "userOpenedRecommendation";
9
+ AssistantEvents["USER_ADDED_TO_CART"] = "userAddedToCart";
10
+ AssistantEvents["USER_SEND_POSITIVE_FEEDBACK"] = "userSendPositiveFeedback";
11
+ AssistantEvents["USER_SEND_NEGATIVE_FEEDBACK"] = "userSendNegativeFeedback";
12
+ })(AssistantEvents || (AssistantEvents = {}));
@@ -0,0 +1,19 @@
1
+ import { SimplifiedProduct } from "./product";
2
+ import { Theme } from "./theme";
3
+ export interface DialogConstructor {
4
+ apiKey: string;
5
+ locale: string;
6
+ callbacks: {
7
+ addToCart: ({ productId, quantity, price, variantId, currency, }: {
8
+ productId: string;
9
+ quantity: number;
10
+ price?: string;
11
+ variantId?: string;
12
+ currency?: string;
13
+ }) => Promise<void>;
14
+ getProduct: (productId: string, variantId?: string) => Promise<SimplifiedProduct>;
15
+ };
16
+ theme?: Partial<Theme>;
17
+ userId?: string;
18
+ }
19
+ //# sourceMappingURL=constructor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../src/types/constructor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE;QACT,SAAS,EAAE,CAAC,EACV,SAAS,EACT,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,GACT,EAAE;YACD,SAAS,EAAE,MAAM,CAAC;YAClB,QAAQ,EAAE,MAAM,CAAC;YACjB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;SACnB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACpB,UAAU,EAAE,CACV,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,KACf,OAAO,CAAC,iBAAiB,CAAC,CAAC;KACjC,CAAC;IACF,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ export declare const DIALOG_CUSTOM_EVENT = "enableDialogAssistantEvent";
2
+ export declare enum DialogEvents {
3
+ OPEN_ASSISTANT = "open_assistant",
4
+ CLOSE_ASSISTANT = "close_assistant",
5
+ SEND_MESSAGE = "PRODUCT_QUESTION",
6
+ SEND_GENERIC_QUESTION = "GENERIC_QUESTION",
7
+ TRACK_ADD_TO_CART = "TRACK_ADD_TO_CART",
8
+ TRACK_SUBMIT_CHECKOUT = "TRACK_SUBMIT_CHECKOUT"
9
+ }
10
+ export interface GenericQuestionPayload {
11
+ question: string;
12
+ }
13
+ export interface ProductQuestionPayload extends GenericQuestionPayload {
14
+ answer?: string;
15
+ productId: string;
16
+ productTitle: string;
17
+ fromQuestionSuggestion?: boolean;
18
+ selectedVariantId?: string;
19
+ }
20
+ export interface OpenAssistantPayload {
21
+ question?: string;
22
+ answer?: string;
23
+ productId?: string;
24
+ productTitle?: string;
25
+ fromQuestionSuggestion?: boolean;
26
+ selectedVariantId?: string;
27
+ }
28
+ export type DiagnosticButtonType = "productPageButton" | "simpleButton";
29
+ export interface DiagnosticPayload {
30
+ productTitle: string;
31
+ handle: string;
32
+ productId: string;
33
+ selectedVariantId?: string;
34
+ buttonType: DiagnosticButtonType;
35
+ url: string;
36
+ }
37
+ export interface TrackEventPayload {
38
+ userId?: string;
39
+ productId: string;
40
+ variantId?: string;
41
+ quantity: number;
42
+ price?: string;
43
+ currency?: string;
44
+ }
45
+ export type DialogEventPayload = ProductQuestionPayload | GenericQuestionPayload | DiagnosticPayload | OpenAssistantPayload | TrackEventPayload;
46
+ export interface DialogEvent<T = DialogEventPayload> {
47
+ type: DialogEvents;
48
+ payload: T;
49
+ }
50
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,+BAA+B,CAAC;AAEhE,oBAAY,YAAY;IACtB,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,YAAY,qBAAqB;IACjC,qBAAqB,qBAAqB;IAC1C,iBAAiB,sBAAsB;IACvC,qBAAqB,0BAA0B;CAChD;AACD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,sBAAuB,SAAQ,sBAAsB;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG,cAAc,CAAC;AAExE,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,oBAAoB,CAAC;IACjC,GAAG,EAAE,MAAM,CAAC;CACb;AAMD,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,kBAAkB,GAC1B,sBAAsB,GACtB,sBAAsB,GACtB,iBAAiB,GACjB,oBAAoB,GACpB,iBAAiB,CAAC;AAEtB,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,kBAAkB;IACjD,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,CAAC,CAAC;CACZ"}
@@ -0,0 +1,10 @@
1
+ export const DIALOG_CUSTOM_EVENT = "enableDialogAssistantEvent";
2
+ export var DialogEvents;
3
+ (function (DialogEvents) {
4
+ DialogEvents["OPEN_ASSISTANT"] = "open_assistant";
5
+ DialogEvents["CLOSE_ASSISTANT"] = "close_assistant";
6
+ DialogEvents["SEND_MESSAGE"] = "PRODUCT_QUESTION";
7
+ DialogEvents["SEND_GENERIC_QUESTION"] = "GENERIC_QUESTION";
8
+ DialogEvents["TRACK_ADD_TO_CART"] = "TRACK_ADD_TO_CART";
9
+ DialogEvents["TRACK_SUBMIT_CHECKOUT"] = "TRACK_SUBMIT_CHECKOUT";
10
+ })(DialogEvents || (DialogEvents = {}));
@@ -0,0 +1,11 @@
1
+ import { Dialog } from "../Dialog";
2
+ declare global {
3
+ interface Window {
4
+ dialog?: {
5
+ instance?: Dialog;
6
+ version?: string;
7
+ };
8
+ }
9
+ }
10
+ export {};
11
+ //# sourceMappingURL=global.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../src/types/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,CAAC,EAAE;YACP,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;KACH;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export * from "./events";
2
+ export * from "./product";
3
+ export * from "./suggestion";
4
+ export * from "./theme";
5
+ export * from "./constructor";
6
+ export * from "./assistantEvent";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./events";
2
+ export * from "./product";
3
+ export * from "./suggestion";
4
+ export * from "./theme";
5
+ export * from "./constructor";
6
+ export * from "./assistantEvent";
@@ -0,0 +1,36 @@
1
+ export interface SimplifiedProductVariant {
2
+ id: string;
3
+ displayName?: string;
4
+ inventoryQuantity?: number;
5
+ price: string;
6
+ currencyCode: string;
7
+ compareAtPrice?: string | null;
8
+ url?: string;
9
+ selectedOptions?: {
10
+ name: string;
11
+ value: string;
12
+ }[];
13
+ image?: {
14
+ url?: string;
15
+ } | null;
16
+ }
17
+ export interface SimplifiedProductOption {
18
+ values: string[];
19
+ id: string;
20
+ name: string;
21
+ position: number;
22
+ }
23
+ export interface SimplifiedProduct {
24
+ id: string;
25
+ title: string;
26
+ handle: string;
27
+ descriptionHtml?: string;
28
+ url?: string;
29
+ totalInventory: number;
30
+ featuredImage?: {
31
+ url?: string;
32
+ } | null;
33
+ variants: SimplifiedProductVariant[];
34
+ options?: SimplifiedProductOption[];
35
+ }
36
+ //# sourceMappingURL=product.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../src/types/product.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;IACJ,KAAK,CAAC,EAAE;QACN,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,GAAG,IAAI,CAAC;CACV;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,GAAG,IAAI,CAAC;IACT,QAAQ,EAAE,wBAAwB,EAAE,CAAC;IACrC,OAAO,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACrC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface Suggestion {
2
+ questions: {
3
+ question: string;
4
+ answer?: string;
5
+ }[];
6
+ assistantName?: string;
7
+ description?: string;
8
+ inputPlaceholder?: string;
9
+ }
10
+ //# sourceMappingURL=suggestion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestion.d.ts","sourceRoot":"","sources":["../../src/types/suggestion.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,EAAE,CAAC;IACJ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ export interface Theme {
2
+ backgroundColor?: string;
3
+ primaryColor?: string;
4
+ ctaTextColor?: string;
5
+ ctaBorderType?: "straight" | "rounded";
6
+ capitalizeCtas?: boolean;
7
+ fontFamily?: string;
8
+ highlightProductName?: boolean;
9
+ title?: {
10
+ fontSize?: string;
11
+ color?: string;
12
+ };
13
+ description?: {
14
+ fontSize?: string;
15
+ color?: string;
16
+ };
17
+ content?: {
18
+ fontSize?: string;
19
+ color?: string;
20
+ };
21
+ }
22
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/types/theme.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACvC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE;QACN,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,WAAW,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export interface DetailedLocaleInfo {
2
+ language: string;
3
+ countryCode: string;
4
+ formatted: string;
5
+ locale: string;
6
+ }
7
+ export declare const getDetailedLocaleInfo: (locale: string) => DetailedLocaleInfo | null;
8
+ //# sourceMappingURL=localization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../src/utils/localization.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,KACb,kBAAkB,GAAG,IAsBvB,CAAC"}
@@ -0,0 +1,21 @@
1
+ export const getDetailedLocaleInfo = (locale) => {
2
+ try {
3
+ const localeObj = new Intl.Locale(locale);
4
+ const language = localeObj.language;
5
+ const countryCode = localeObj.region ?? localeObj.maximize().region;
6
+ const languageNames = new Intl.DisplayNames(["en"], { type: "language" });
7
+ const languageName = languageNames.of(localeObj.baseName);
8
+ if (languageName === undefined || countryCode === undefined) {
9
+ return null;
10
+ }
11
+ return {
12
+ language: languageName,
13
+ countryCode,
14
+ formatted: `${language}-${countryCode}`,
15
+ locale,
16
+ };
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ };
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@askdialog/dialog-sdk",
3
+ "version": "0.0.0-beta-20260605145702",
4
+ "private": false,
5
+ "description": "Dialog SDK",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "dialog",
20
+ "ai",
21
+ "assistant",
22
+ "ecommerce",
23
+ "sdk",
24
+ "typescript"
25
+ ],
26
+ "author": "Dialog",
27
+ "license": "MIT",
28
+ "devDependencies": {
29
+ "esbuild": "^0.25.12",
30
+ "eslint-import-resolver-typescript": "^4.4.4",
31
+ "eslint-plugin-import": "^2.32.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "dependencies": {
37
+ "uuidv7": "^1.0.2"
38
+ },
39
+ "scripts": {
40
+ "clean": "rm -rf dist",
41
+ "set-config": "chmod +x scripts/set-config.sh && ./scripts/set-config.sh",
42
+ "build": "pnpm run build:prod",
43
+ "build:dev": "pnpm run clean && pnpm run set-config development && tsc",
44
+ "build:prod": "pnpm run clean && pnpm run set-config production && tsc",
45
+ "lint": "eslint .",
46
+ "lint:fix": "eslint . --fix",
47
+ "test-type": "tsc --noEmit",
48
+ "link": "pnpm link --global",
49
+ "unlink": "pnpm unlink",
50
+ "watch": "tsc --watch",
51
+ "build:bundle:iife": "pnpm run build:prod && mkdir -p bundle && esbuild src/index.ts --bundle --platform=browser --format=iife --global-name=DialogSDK --minify --outfile=bundle/dialog-sdk.$npm_package_version.min.js",
52
+ "deploy:s3": "aws s3 cp bundle/dialog-sdk.$npm_package_version.min.js s3://dialog-sdk/",
53
+ "deploy:cloudfront": "aws cloudfront create-invalidation --distribution-id E3NRPUUF94K3P6 --no-cli-pager --paths \"/dialog-sdk.$npm_package_version.min.js\"",
54
+ "deploy:cdn": "pnpm run build:prod && pnpm run build:bundle:iife && pnpm run deploy:s3 && pnpm run deploy:cloudfront",
55
+ "deploy:cdn:publish": "pnpm run build:prod && pnpm run build:bundle:iife && pnpm run deploy:s3 && pnpm run deploy:cloudfront && pnpm publish"
56
+ }
57
+ }