@askdialog/dialog-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/Dialog.d.ts +38 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +80 -0
- package/dist/EventsHandler.d.ts +6 -0
- package/dist/EventsHandler.d.ts.map +1 -0
- package/dist/EventsHandler.js +10 -0
- package/dist/Tracking.d.ts +9 -0
- package/dist/Tracking.d.ts.map +1 -0
- package/dist/Tracking.js +17 -0
- package/dist/config/config.development.d.ts +5 -0
- package/dist/config/config.development.d.ts.map +1 -0
- package/dist/config/config.development.js +3 -0
- package/dist/config/config.production.d.ts +5 -0
- package/dist/config/config.production.d.ts.map +1 -0
- package/dist/config/config.production.js +3 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/constants/theme.d.ts +3 -0
- package/dist/constants/theme.d.ts.map +1 -0
- package/dist/constants/theme.js +11 -0
- package/dist/constants/user.d.ts +3 -0
- package/dist/constants/user.d.ts.map +1 -0
- package/dist/constants/user.js +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/services/base.d.ts +2 -0
- package/dist/services/base.d.ts.map +1 -0
- package/dist/services/base.js +4 -0
- package/dist/services/suggestions.d.ts +3 -0
- package/dist/services/suggestions.d.ts.map +1 -0
- package/dist/services/suggestions.js +12 -0
- package/dist/types/constructor.d.ts +17 -0
- package/dist/types/constructor.d.ts.map +1 -0
- package/dist/types/constructor.js +1 -0
- package/dist/types/events.d.ts +41 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +8 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/product.d.ts +16 -0
- package/dist/types/product.d.ts.map +1 -0
- package/dist/types/product.js +1 -0
- package/dist/types/suggestion.d.ts +10 -0
- package/dist/types/suggestion.d.ts.map +1 -0
- package/dist/types/suggestion.js +1 -0
- package/dist/types/theme.d.ts +12 -0
- package/dist/types/theme.d.ts.map +1 -0
- package/dist/types/theme.js +1 -0
- package/dist/types/trackings.d.ts +5 -0
- package/dist/types/trackings.d.ts.map +1 -0
- package/dist/types/trackings.js +5 -0
- package/dist/utils/localization.d.ts +7 -0
- package/dist/utils/localization.d.ts.map +1 -0
- package/dist/utils/localization.js +20 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Dialog Custom SDK
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Dialog Custom SDK is a TypeScript library that allows easy integration of the Dialog assistant.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @dialog/dialog-sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @dialog/dialog-sdk
|
|
13
|
+
# or
|
|
14
|
+
yarn add @dialog/dialog-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Main Features
|
|
18
|
+
|
|
19
|
+
- Assistant controls (open / close / send message)
|
|
20
|
+
- Custom handler for fetch product
|
|
21
|
+
- Custom handler for add to cart
|
|
22
|
+
- Custom assistant theming
|
package/dist/Dialog.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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 { Product } from './types/product';
|
|
7
|
+
export declare class Dialog {
|
|
8
|
+
private _apiKey;
|
|
9
|
+
private _locale;
|
|
10
|
+
private _callbacks;
|
|
11
|
+
private _theme;
|
|
12
|
+
private _userId;
|
|
13
|
+
private _eventsHandler;
|
|
14
|
+
private _tracking;
|
|
15
|
+
constructor({ apiKey, locale, callbacks, theme, userId }: DialogConstructor);
|
|
16
|
+
get theme(): Theme;
|
|
17
|
+
get userId(): string;
|
|
18
|
+
getLocalizationInformations(): DetailedLocaleInfo | null;
|
|
19
|
+
private _createOrRetrieveUserId;
|
|
20
|
+
getSuggestions(productId: string): Promise<Suggestion>;
|
|
21
|
+
openAssistant(params: OpenAssistantPayload): void;
|
|
22
|
+
closeAssistant(): void;
|
|
23
|
+
sendProductMessage(params: ProductQuestionPayload): void;
|
|
24
|
+
sendGenericMessage(params: GenericQuestionPayload): void;
|
|
25
|
+
getProduct(productId: string, variantId: string): Promise<Product>;
|
|
26
|
+
addToCart({ productId, variantId, quantity, }: {
|
|
27
|
+
productId: string;
|
|
28
|
+
variantId: string;
|
|
29
|
+
quantity: number;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
registerAddToCartEvent({ productId, variantId, quantity, }: {
|
|
32
|
+
productId: string;
|
|
33
|
+
variantId: string;
|
|
34
|
+
quantity: number;
|
|
35
|
+
}): void;
|
|
36
|
+
registerSubmitCheckoutEvent(): void;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=Dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../src/Dialog.ts"],"names":[],"mappings":"AAEA,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,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK1C,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,UAAU,CAWhB;IACF,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,SAAS,CAAW;gBAEhB,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,iBAAiB;IAU3E,IAAW,KAAK,IAAI,KAAK,CAExB;IACD,IAAW,MAAM,IAAI,MAAM,CAE1B;IAEM,2BAA2B,IAAI,kBAAkB,GAAG,IAAI;IAI/D,OAAO,CAAC,uBAAuB;IAkBlB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI5D,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAIjD,cAAc,IAAI,IAAI;IAItB,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAIxD,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAOxD,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlE,SAAS,CAAC,EACf,SAAS,EACT,SAAS,EACT,QAAQ,GACT,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIV,sBAAsB,CAAC,EAC5B,SAAS,EACT,SAAS,EACT,QAAQ,GACT,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,IAAI;IAQD,2BAA2B,IAAI,IAAI;CAG3C"}
|
package/dist/Dialog.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { uuidv7 } from 'uuidv7';
|
|
2
|
+
import { defaultTheme } from './constants/theme';
|
|
3
|
+
import { getDetailedLocaleInfo, } from './utils/localization';
|
|
4
|
+
import { ANONYMOUS_CUSTOMER_ID, CUSTOMER_ID } from './constants/user';
|
|
5
|
+
import { DialogEvents, } from './types/events';
|
|
6
|
+
import { EventsHandler } from './EventsHandler';
|
|
7
|
+
import { Tracking } from './Tracking';
|
|
8
|
+
import { TrackingEvents } from './types/trackings';
|
|
9
|
+
import { loadSuggestions } from './services/suggestions';
|
|
10
|
+
export class Dialog {
|
|
11
|
+
_apiKey;
|
|
12
|
+
_locale;
|
|
13
|
+
_callbacks;
|
|
14
|
+
_theme;
|
|
15
|
+
_userId;
|
|
16
|
+
_eventsHandler;
|
|
17
|
+
_tracking;
|
|
18
|
+
constructor({ apiKey, locale, callbacks, theme, userId }) {
|
|
19
|
+
this._apiKey = apiKey;
|
|
20
|
+
this._locale = locale;
|
|
21
|
+
this._callbacks = callbacks;
|
|
22
|
+
this._theme = { ...defaultTheme, ...theme };
|
|
23
|
+
this._userId = this._createOrRetrieveUserId(userId);
|
|
24
|
+
this._eventsHandler = new EventsHandler();
|
|
25
|
+
this._tracking = new Tracking(apiKey);
|
|
26
|
+
}
|
|
27
|
+
get theme() {
|
|
28
|
+
return this._theme;
|
|
29
|
+
}
|
|
30
|
+
get userId() {
|
|
31
|
+
return this._userId;
|
|
32
|
+
}
|
|
33
|
+
getLocalizationInformations() {
|
|
34
|
+
return getDetailedLocaleInfo(this._locale);
|
|
35
|
+
}
|
|
36
|
+
_createOrRetrieveUserId(userId) {
|
|
37
|
+
if (userId !== undefined) {
|
|
38
|
+
localStorage.setItem(CUSTOMER_ID, userId);
|
|
39
|
+
return userId;
|
|
40
|
+
}
|
|
41
|
+
const existingAnonymousUserId = localStorage.getItem(ANONYMOUS_CUSTOMER_ID);
|
|
42
|
+
if (existingAnonymousUserId !== null) {
|
|
43
|
+
return existingAnonymousUserId;
|
|
44
|
+
}
|
|
45
|
+
const newUserId = uuidv7();
|
|
46
|
+
localStorage.setItem(ANONYMOUS_CUSTOMER_ID, newUserId);
|
|
47
|
+
return newUserId;
|
|
48
|
+
}
|
|
49
|
+
async getSuggestions(productId) {
|
|
50
|
+
return loadSuggestions(this._apiKey, this._locale, productId);
|
|
51
|
+
}
|
|
52
|
+
openAssistant(params) {
|
|
53
|
+
this._eventsHandler.emitExternalEvent(DialogEvents.OPEN_ASSISTANT, params);
|
|
54
|
+
}
|
|
55
|
+
closeAssistant() {
|
|
56
|
+
this._eventsHandler.emitExternalEvent(DialogEvents.CLOSE_ASSISTANT);
|
|
57
|
+
}
|
|
58
|
+
sendProductMessage(params) {
|
|
59
|
+
this._eventsHandler.emitExternalEvent(DialogEvents.SEND_MESSAGE, params);
|
|
60
|
+
}
|
|
61
|
+
sendGenericMessage(params) {
|
|
62
|
+
this._eventsHandler.emitExternalEvent(DialogEvents.SEND_GENERIC_QUESTION, params);
|
|
63
|
+
}
|
|
64
|
+
getProduct(productId, variantId) {
|
|
65
|
+
return this._callbacks.getProduct(productId, variantId);
|
|
66
|
+
}
|
|
67
|
+
addToCart({ productId, variantId, quantity, }) {
|
|
68
|
+
return this._callbacks.addToCart({ productId, variantId, quantity });
|
|
69
|
+
}
|
|
70
|
+
registerAddToCartEvent({ productId, variantId, quantity, }) {
|
|
71
|
+
this._tracking.track(TrackingEvents.USER_ADDED_TO_CART, {
|
|
72
|
+
product_id: productId,
|
|
73
|
+
variant_id: variantId,
|
|
74
|
+
quantity,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
registerSubmitCheckoutEvent() {
|
|
78
|
+
this._tracking.track(TrackingEvents.USER_SUBMITTED_CHECKOUT);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventsHandler.d.ts","sourceRoot":"","sources":["../src/EventsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElE,qBAAa,aAAa;;IAGjB,iBAAiB,CACtB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EACzB,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,GAC/B,IAAI;CAOR"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DIALOG_CUSTOM_EVENT } from './types/events';
|
|
2
|
+
export class EventsHandler {
|
|
3
|
+
constructor() { }
|
|
4
|
+
emitExternalEvent(type, payload) {
|
|
5
|
+
const event = new CustomEvent(DIALOG_CUSTOM_EVENT, {
|
|
6
|
+
detail: { type, payload },
|
|
7
|
+
});
|
|
8
|
+
window.dispatchEvent(event);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TrackingEvents } from './types/trackings';
|
|
2
|
+
export declare class Tracking {
|
|
3
|
+
private _posthog;
|
|
4
|
+
private readonly _token;
|
|
5
|
+
private readonly _apiHost;
|
|
6
|
+
constructor(apiKey: string);
|
|
7
|
+
track(event: TrackingEvents, properties?: Record<string, unknown>): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=Tracking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tracking.d.ts","sourceRoot":"","sources":["../src/Tracking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqD;IAC5E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;gBAE3C,MAAM,EAAE,MAAM;IASnB,KAAK,CACV,KAAK,EAAE,cAAc,EACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,IAAI;CAGR"}
|
package/dist/Tracking.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import posthog from 'posthog-js';
|
|
2
|
+
export class Tracking {
|
|
3
|
+
_posthog;
|
|
4
|
+
_token = 'phc_EKMR6Jt4OTMEYmoUlz0v58KPwqcFxI7aZCLckpSD8Tv';
|
|
5
|
+
_apiHost = 'https://eu.i.posthog.com';
|
|
6
|
+
constructor(apiKey) {
|
|
7
|
+
this._posthog = posthog.init(this._token, {
|
|
8
|
+
api_host: this._apiHost,
|
|
9
|
+
});
|
|
10
|
+
this._posthog.identify(apiKey, {
|
|
11
|
+
host: window.location.hostname,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
track(event, properties) {
|
|
15
|
+
this._posthog.capture(event, properties);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.development.d.ts","sourceRoot":"","sources":["../../src/config/config.development.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;CAElB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.production.d.ts","sourceRoot":"","sources":["../../src/config/config.production.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;CAElB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;CAElB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC"}
|
|
@@ -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,KAU1B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
titleFontSize: 16,
|
|
10
|
+
contentFontSize: 14,
|
|
11
|
+
};
|
|
@@ -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"}
|
package/dist/index.d.ts
ADDED
|
@@ -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,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -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 @@
|
|
|
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,17 @@
|
|
|
1
|
+
import { Product } from './product';
|
|
2
|
+
import { Theme } from './theme';
|
|
3
|
+
export interface DialogConstructor {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
locale: string;
|
|
6
|
+
callbacks: {
|
|
7
|
+
addToCart: ({ productId, variantId, quantity, }: {
|
|
8
|
+
productId: string;
|
|
9
|
+
variantId: string;
|
|
10
|
+
quantity: number;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
getProduct: (productId: string, variantId: string) => Promise<Product>;
|
|
13
|
+
};
|
|
14
|
+
theme?: Partial<Theme>;
|
|
15
|
+
userId?: string;
|
|
16
|
+
}
|
|
17
|
+
//# 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,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,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,SAAS,EACT,QAAQ,GACT,EAAE;YACD,SAAS,EAAE,MAAM,CAAC;YAClB,SAAS,EAAE,MAAM,CAAC;YAClB,QAAQ,EAAE,MAAM,CAAC;SAClB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACpB,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;KACxE,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,41 @@
|
|
|
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
|
+
}
|
|
8
|
+
export interface GenericQuestionPayload {
|
|
9
|
+
question: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ProductQuestionPayload extends GenericQuestionPayload {
|
|
12
|
+
answer?: string;
|
|
13
|
+
productId: string;
|
|
14
|
+
productTitle: string;
|
|
15
|
+
fromQuestionSuggestion?: boolean;
|
|
16
|
+
selectedVariantId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface OpenAssistantPayload {
|
|
19
|
+
question?: string;
|
|
20
|
+
answer?: string;
|
|
21
|
+
productId?: string;
|
|
22
|
+
productTitle?: string;
|
|
23
|
+
handle?: string;
|
|
24
|
+
fromQuestionSuggestion?: boolean;
|
|
25
|
+
selectedVariantId?: string;
|
|
26
|
+
}
|
|
27
|
+
export type DiagnosticButtonType = 'productPageButton' | 'simpleButton';
|
|
28
|
+
export interface DiagnosticPayload {
|
|
29
|
+
productTitle: string;
|
|
30
|
+
handle: string;
|
|
31
|
+
productId: string;
|
|
32
|
+
selectedVariantId?: string;
|
|
33
|
+
buttonType: DiagnosticButtonType;
|
|
34
|
+
url: string;
|
|
35
|
+
}
|
|
36
|
+
export type DialogEventPayload = ProductQuestionPayload | GenericQuestionPayload | DiagnosticPayload | OpenAssistantPayload;
|
|
37
|
+
export interface DialogEvent<T = DialogEventPayload> {
|
|
38
|
+
type: DialogEvents;
|
|
39
|
+
payload: T;
|
|
40
|
+
}
|
|
41
|
+
//# 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;CAC3C;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,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,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;AAED,MAAM,MAAM,kBAAkB,GAC1B,sBAAsB,GACtB,sBAAsB,GACtB,iBAAiB,GACjB,oBAAoB,CAAC;AAEzB,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,kBAAkB;IACjD,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,CAAC,CAAC;CACZ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 || (DialogEvents = {}));
|
|
@@ -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,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Product {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
handle: string;
|
|
5
|
+
variants: {
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
price: number;
|
|
9
|
+
compareAtPrice: number;
|
|
10
|
+
availableQuantity: number;
|
|
11
|
+
image: {
|
|
12
|
+
src: string;
|
|
13
|
+
};
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
//# 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,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,KAAK,EAAE;YACL,GAAG,EAAE,MAAM,CAAC;SACb,CAAC;KACH,EAAE,CAAC;CACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,12 @@
|
|
|
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
|
+
titleFontSize: number;
|
|
10
|
+
contentFontSize: number;
|
|
11
|
+
}
|
|
12
|
+
//# 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,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,UAAU,GAAG,SAAS,CAAC;IACtC,cAAc,EAAE,OAAO,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trackings.d.ts","sourceRoot":"","sources":["../../src/types/trackings.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,kBAAkB,uBAAuB;IACzC,uBAAuB,4BAA4B;CACpD"}
|
|
@@ -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;CACnB;AAED,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,KACb,kBAAkB,GAAG,IAqBvB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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(language);
|
|
8
|
+
if (languageName === undefined || countryCode === undefined) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
language: languageName,
|
|
13
|
+
countryCode,
|
|
14
|
+
formatted: `${language}-${countryCode}`,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@askdialog/dialog-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
+
"author": "Dialog",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
23
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
24
|
+
"eslint": "^8.56.0",
|
|
25
|
+
"eslint-config-prettier": "^10.1.1",
|
|
26
|
+
"eslint-import-resolver-typescript": "^4.3.2",
|
|
27
|
+
"eslint-plugin-import": "^2.31.0",
|
|
28
|
+
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
29
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
30
|
+
"typescript": "^5.8.3"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"posthog-js": "^1.235.3",
|
|
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:dev": "pnpm run clean && pnpm run set-config development && tsc",
|
|
43
|
+
"build:prod": "pnpm run clean && pnpm run set-config production && tsc",
|
|
44
|
+
"test-linter": "eslint . --ext .ts",
|
|
45
|
+
"test-type": "tsc --noEmit",
|
|
46
|
+
"link": "pnpm link --global",
|
|
47
|
+
"unlink": "pnpm unlink",
|
|
48
|
+
"watch": "tsc --watch"
|
|
49
|
+
}
|
|
50
|
+
}
|