@athoscommerce/snap-store-mobx 1.2.3-beta.4 → 1.4.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/cjs/Autocomplete/AutocompleteStore.d.ts +1 -1
- package/dist/cjs/Autocomplete/AutocompleteStore.d.ts.map +1 -1
- package/dist/cjs/Autocomplete/AutocompleteStore.js +4 -4
- package/dist/cjs/Autocomplete/Stores/AutocompleteFacetStore.d.ts.map +1 -1
- package/dist/cjs/Autocomplete/Stores/AutocompleteFacetStore.js +2 -4
- package/dist/cjs/Finder/FinderStore.d.ts +1 -1
- package/dist/cjs/Finder/FinderStore.d.ts.map +1 -1
- package/dist/cjs/Finder/FinderStore.js +3 -3
- package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts +1 -1
- package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
- package/dist/cjs/Search/SearchStore.d.ts +1 -1
- package/dist/cjs/Search/SearchStore.d.ts.map +1 -1
- package/dist/cjs/Search/SearchStore.js +2 -2
- package/dist/cjs/Search/Stores/SearchFacetStore.d.ts +12 -12
- package/dist/cjs/Search/Stores/SearchFacetStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchFacetStore.js +22 -32
- package/dist/cjs/Search/Stores/SearchHistoryStore.js +2 -2
- package/dist/cjs/Search/Stores/index.d.ts +1 -1
- package/dist/cjs/Search/Stores/index.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/index.js +1 -2
- package/dist/cjs/index.d.ts +1 -5
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -8
- package/dist/cjs/types.d.ts +2 -13
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteStore.d.ts +1 -1
- package/dist/esm/Autocomplete/AutocompleteStore.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteStore.js +2 -2
- package/dist/esm/Autocomplete/Stores/AutocompleteFacetStore.d.ts.map +1 -1
- package/dist/esm/Autocomplete/Stores/AutocompleteFacetStore.js +5 -7
- package/dist/esm/Finder/FinderStore.d.ts +1 -1
- package/dist/esm/Finder/FinderStore.d.ts.map +1 -1
- package/dist/esm/Finder/FinderStore.js +1 -1
- package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts +1 -1
- package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
- package/dist/esm/Search/SearchStore.d.ts +1 -1
- package/dist/esm/Search/SearchStore.d.ts.map +1 -1
- package/dist/esm/Search/SearchStore.js +1 -1
- package/dist/esm/Search/Stores/SearchFacetStore.d.ts +12 -12
- package/dist/esm/Search/Stores/SearchFacetStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchFacetStore.js +22 -31
- package/dist/esm/Search/Stores/SearchHistoryStore.js +1 -1
- package/dist/esm/Search/Stores/index.d.ts +1 -1
- package/dist/esm/Search/Stores/index.d.ts.map +1 -1
- package/dist/esm/Search/Stores/index.js +1 -1
- package/dist/esm/index.d.ts +1 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -3
- package/dist/esm/types.d.ts +2 -13
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +11 -6
- package/dist/cjs/Chat/ChatStore.d.ts +0 -57
- package/dist/cjs/Chat/ChatStore.d.ts.map +0 -1
- package/dist/cjs/Chat/ChatStore.js +0 -415
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.d.ts +0 -98
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.d.ts.map +0 -1
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.js +0 -314
- package/dist/cjs/Chat/Stores/ChatCompareStore.d.ts +0 -14
- package/dist/cjs/Chat/Stores/ChatCompareStore.d.ts.map +0 -1
- package/dist/cjs/Chat/Stores/ChatCompareStore.js +0 -63
- package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts +0 -117
- package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts.map +0 -1
- package/dist/cjs/Chat/Stores/ChatSessionStore.js +0 -689
- package/dist/cjs/Storage/StorageStore.d.ts +0 -27
- package/dist/cjs/Storage/StorageStore.d.ts.map +0 -1
- package/dist/cjs/Storage/StorageStore.js +0 -176
- package/dist/esm/Chat/ChatStore.d.ts +0 -57
- package/dist/esm/Chat/ChatStore.d.ts.map +0 -1
- package/dist/esm/Chat/ChatStore.js +0 -355
- package/dist/esm/Chat/Stores/ChatAttachmentStore.d.ts +0 -98
- package/dist/esm/Chat/Stores/ChatAttachmentStore.d.ts.map +0 -1
- package/dist/esm/Chat/Stores/ChatAttachmentStore.js +0 -222
- package/dist/esm/Chat/Stores/ChatCompareStore.d.ts +0 -14
- package/dist/esm/Chat/Stores/ChatCompareStore.d.ts.map +0 -1
- package/dist/esm/Chat/Stores/ChatCompareStore.js +0 -49
- package/dist/esm/Chat/Stores/ChatSessionStore.d.ts +0 -117
- package/dist/esm/Chat/Stores/ChatSessionStore.d.ts.map +0 -1
- package/dist/esm/Chat/Stores/ChatSessionStore.js +0 -661
- package/dist/esm/Storage/StorageStore.d.ts +0 -27
- package/dist/esm/Storage/StorageStore.d.ts.map +0 -1
- package/dist/esm/Storage/StorageStore.js +0 -169
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.ChatStore = void 0;
|
|
30
|
-
var mobx_1 = require("mobx");
|
|
31
|
-
var MetaStore_1 = require("../Meta/MetaStore");
|
|
32
|
-
var AbstractStore_1 = require("../Abstract/AbstractStore");
|
|
33
|
-
var StorageStore_1 = require("../Storage/StorageStore");
|
|
34
|
-
var ChatSessionStore_1 = require("./Stores/ChatSessionStore");
|
|
35
|
-
var SearchResultStore_1 = require("../Search/Stores/SearchResultStore");
|
|
36
|
-
var CHAT_STATUS_EXPIRATION_TIME = 1000 * 60 * 60 * 12; // 12 hours
|
|
37
|
-
var ChatStore = /** @class */ (function (_super) {
|
|
38
|
-
__extends(ChatStore, _super);
|
|
39
|
-
function ChatStore(config) {
|
|
40
|
-
var _this = _super.call(this, config) || this;
|
|
41
|
-
_this.meta = undefined;
|
|
42
|
-
_this.inputValue = '';
|
|
43
|
-
_this.open = false;
|
|
44
|
-
_this.chats = [];
|
|
45
|
-
_this.chatEnabled = null;
|
|
46
|
-
_this.initChatLoading = false;
|
|
47
|
-
_this.suggestedQuestions = [];
|
|
48
|
-
_this.welcomeMessage = '';
|
|
49
|
-
_this.features = { imageSearch: { enabled: false }, similarProducts: { enabled: false } };
|
|
50
|
-
_this.productQuickview = null;
|
|
51
|
-
_this.productQuickviewError = null;
|
|
52
|
-
/** Raw meta kept for lazy hydration of inactive chat sessions. */
|
|
53
|
-
_this.storedMetaData = null;
|
|
54
|
-
var legacyKey = "ss-".concat(_this.config.id);
|
|
55
|
-
var storageKey = _this.config.siteId ? "ss-".concat(_this.config.siteId, "-").concat(_this.config.id) : legacyKey;
|
|
56
|
-
_this.storage = new StorageStore_1.StorageStore({
|
|
57
|
-
type: 'local',
|
|
58
|
-
key: storageKey,
|
|
59
|
-
});
|
|
60
|
-
var storedChatStatusResponse = _this.storage.get('chatStatusResponse');
|
|
61
|
-
if (storedChatStatusResponse) {
|
|
62
|
-
try {
|
|
63
|
-
var storedChatStatus = JSON.parse(storedChatStatusResponse);
|
|
64
|
-
if (storedChatStatus.checkTime && Date.now() - storedChatStatus.checkTime > CHAT_STATUS_EXPIRATION_TIME) {
|
|
65
|
-
// chat status is expired, remove from storage to trigger a new check
|
|
66
|
-
_this.storage.set('chatStatusResponse', null);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// Apply the stored response without persisting, so the 12-hour
|
|
70
|
-
// checkTime keeps counting from the last real API call rather
|
|
71
|
-
// than resetting on every page load.
|
|
72
|
-
_this.applyChatStatusResponse(storedChatStatus.response);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (_a) {
|
|
76
|
-
_this.storage.set('chatStatusResponse', null);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// check for entries in storage
|
|
80
|
-
var latestChatId = '';
|
|
81
|
-
var storedChats = _this.storage.get('chats');
|
|
82
|
-
storedChats &&
|
|
83
|
-
Object.keys(storedChats || {}).forEach(function (chatId) {
|
|
84
|
-
var chatData = storedChats[chatId];
|
|
85
|
-
if (chatData) {
|
|
86
|
-
var restoredChat = new ChatSessionStore_1.ChatSessionStore({
|
|
87
|
-
data: __assign(__assign({}, chatData), { id: chatId }),
|
|
88
|
-
stores: {
|
|
89
|
-
storage: _this.storage,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
// Mark as unhydrated — results are still raw JSON from storage.
|
|
93
|
-
// Only the active session will be hydrated below.
|
|
94
|
-
restoredChat.hydrated = false;
|
|
95
|
-
_this.chats.push(restoredChat);
|
|
96
|
-
latestChatId = chatId;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
// Prefer the persisted active chat ID so switching chats survives page reloads.
|
|
100
|
-
// Fall back to the most recently created chat if the stored ID is missing or stale.
|
|
101
|
-
var storedCurrentChatId = _this.storage.get('currentChatId');
|
|
102
|
-
var activeChatId = storedCurrentChatId && _this.chats.some(function (chat) { return chat.id === storedCurrentChatId; }) ? storedCurrentChatId : latestChatId;
|
|
103
|
-
var storedMeta = _this.storage.get('meta');
|
|
104
|
-
if (storedMeta) {
|
|
105
|
-
try {
|
|
106
|
-
var metaData = JSON.parse(storedMeta);
|
|
107
|
-
_this.meta = new MetaStore_1.MetaStore({
|
|
108
|
-
data: {
|
|
109
|
-
meta: metaData,
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
// Keep raw meta for lazy hydration of inactive sessions
|
|
113
|
-
_this.storedMetaData = metaData;
|
|
114
|
-
// Only hydrate the active chat session — inactive sessions will be
|
|
115
|
-
// hydrated lazily when switched to via switchChat()
|
|
116
|
-
var activeChat = _this.chats.find(function (chat) { return chat.id === activeChatId; });
|
|
117
|
-
if (activeChat) {
|
|
118
|
-
activeChat.hydrateResults(metaData);
|
|
119
|
-
activeChat.hydrated = true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch (_b) {
|
|
123
|
-
_this.storage.set('meta', null);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
_this.currentChatId = activeChatId;
|
|
127
|
-
(0, mobx_1.makeObservable)(_this, {
|
|
128
|
-
meta: mobx_1.observable,
|
|
129
|
-
inputValue: mobx_1.observable,
|
|
130
|
-
open: mobx_1.observable,
|
|
131
|
-
chats: mobx_1.observable,
|
|
132
|
-
currentChatId: mobx_1.observable,
|
|
133
|
-
chatEnabled: mobx_1.observable,
|
|
134
|
-
initChatLoading: mobx_1.observable,
|
|
135
|
-
blocked: mobx_1.computed,
|
|
136
|
-
currentChat: mobx_1.computed,
|
|
137
|
-
chatsIds: mobx_1.computed,
|
|
138
|
-
features: mobx_1.observable,
|
|
139
|
-
suggestedQuestions: mobx_1.observable,
|
|
140
|
-
welcomeMessage: mobx_1.observable,
|
|
141
|
-
productQuickview: mobx_1.observable,
|
|
142
|
-
productQuickviewError: mobx_1.observable,
|
|
143
|
-
});
|
|
144
|
-
return _this;
|
|
145
|
-
}
|
|
146
|
-
Object.defineProperty(ChatStore.prototype, "currentChat", {
|
|
147
|
-
get: function () {
|
|
148
|
-
var _this = this;
|
|
149
|
-
return this.chats.find(function (chat) { return chat.id === _this.currentChatId; });
|
|
150
|
-
},
|
|
151
|
-
enumerable: false,
|
|
152
|
-
configurable: true
|
|
153
|
-
});
|
|
154
|
-
Object.defineProperty(ChatStore.prototype, "chatsIds", {
|
|
155
|
-
get: function () {
|
|
156
|
-
return this.chats.map(function (chat) { return chat.id; });
|
|
157
|
-
},
|
|
158
|
-
enumerable: false,
|
|
159
|
-
configurable: true
|
|
160
|
-
});
|
|
161
|
-
Object.defineProperty(ChatStore.prototype, "blocked", {
|
|
162
|
-
get: function () {
|
|
163
|
-
var _a;
|
|
164
|
-
var isBlocked = false;
|
|
165
|
-
var blockedAttachments = (_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.items.some(function (item) { return item.type === 'image' && item.state === 'loading'; });
|
|
166
|
-
if (this.loading || blockedAttachments) {
|
|
167
|
-
isBlocked = true;
|
|
168
|
-
}
|
|
169
|
-
return isBlocked;
|
|
170
|
-
},
|
|
171
|
-
enumerable: false,
|
|
172
|
-
configurable: true
|
|
173
|
-
});
|
|
174
|
-
ChatStore.prototype.applyChatStatusResponse = function (response) {
|
|
175
|
-
var chatbot = response.chatbot, features = response.features;
|
|
176
|
-
var status = chatbot.status, suggestedQuestions = chatbot.suggestedQuestions, welcomeMessage = chatbot.welcomeMessage;
|
|
177
|
-
this.chatEnabled = status.enabled === true;
|
|
178
|
-
this.features = features;
|
|
179
|
-
this.suggestedQuestions = suggestedQuestions || [];
|
|
180
|
-
this.welcomeMessage = welcomeMessage || '';
|
|
181
|
-
return this.chatEnabled;
|
|
182
|
-
};
|
|
183
|
-
ChatStore.prototype.handleChatStatusResponse = function (response) {
|
|
184
|
-
var enabled = this.applyChatStatusResponse(response);
|
|
185
|
-
// Always persist on a real API response — restarts the 12-hour expiration
|
|
186
|
-
// so each new chat session refreshes the cache.
|
|
187
|
-
this.storage.set('chatStatusResponse', JSON.stringify({ response: response, checkTime: Date.now() }));
|
|
188
|
-
return enabled;
|
|
189
|
-
};
|
|
190
|
-
ChatStore.prototype.reset = function () {
|
|
191
|
-
this.chats = [];
|
|
192
|
-
this.clearProductQuickview();
|
|
193
|
-
this.storage.clear();
|
|
194
|
-
this.createChat();
|
|
195
|
-
};
|
|
196
|
-
ChatStore.prototype.setProductQuickview = function (product) {
|
|
197
|
-
this.productQuickview = product;
|
|
198
|
-
this.productQuickviewError = null;
|
|
199
|
-
};
|
|
200
|
-
ChatStore.prototype.updateProductQuickview = function (response) {
|
|
201
|
-
var _a;
|
|
202
|
-
if (!this.productQuickview) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
// merge parent-level mappings from the API response into the Product
|
|
206
|
-
this.productQuickview.mappings = __assign(__assign({}, this.productQuickview.mappings), { core: __assign(__assign({}, this.productQuickview.mappings.core), response.mappings.core) });
|
|
207
|
-
var meta = ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.data) || {};
|
|
208
|
-
if (this.productQuickview.variants) {
|
|
209
|
-
// update existing Variants with new data from the Products API
|
|
210
|
-
this.productQuickview.variants.optionConfig = response.variants.optionConfig;
|
|
211
|
-
this.productQuickview.variants.update(response.variants.data);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
// create Variants for the first time using the Products API data
|
|
215
|
-
this.productQuickview.variants = new SearchResultStore_1.Variants({
|
|
216
|
-
data: {
|
|
217
|
-
mask: this.productQuickview.mask,
|
|
218
|
-
variants: response.variants.data,
|
|
219
|
-
optionConfig: response.variants.optionConfig,
|
|
220
|
-
meta: meta,
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
ChatStore.prototype.setProductQuickviewError = function (message) {
|
|
226
|
-
this.productQuickviewError = message;
|
|
227
|
-
};
|
|
228
|
-
ChatStore.prototype.clearProductQuickview = function () {
|
|
229
|
-
this.productQuickview = null;
|
|
230
|
-
this.productQuickviewError = null;
|
|
231
|
-
};
|
|
232
|
-
ChatStore.prototype.clearHistory = function () {
|
|
233
|
-
// drop previous chats while keeping the conversation the user is currently in;
|
|
234
|
-
// if there is no current chat, fall back to a full reset
|
|
235
|
-
var currentChat = this.currentChat;
|
|
236
|
-
if (!currentChat) {
|
|
237
|
-
this.reset();
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
var storedChats = this.storage.get('chats') || {};
|
|
241
|
-
var filtered = {};
|
|
242
|
-
if (storedChats[currentChat.id]) {
|
|
243
|
-
filtered[currentChat.id] = storedChats[currentChat.id];
|
|
244
|
-
}
|
|
245
|
-
this.storage.set('chats', filtered);
|
|
246
|
-
this.chats = [currentChat];
|
|
247
|
-
};
|
|
248
|
-
ChatStore.prototype.createChat = function (data) {
|
|
249
|
-
// abandon any in-flight request state from the previous chat — its
|
|
250
|
-
// response will be discarded by the controller, so the UI shouldn't
|
|
251
|
-
// keep showing its loading spinner or stale error
|
|
252
|
-
this.loading = false;
|
|
253
|
-
this.error = undefined;
|
|
254
|
-
// Prune old sessions before creating a new one to keep storage bounded
|
|
255
|
-
ChatSessionStore_1.ChatSessionStore.pruneStoredSessions(this.storage);
|
|
256
|
-
var newChat = new ChatSessionStore_1.ChatSessionStore({
|
|
257
|
-
data: {
|
|
258
|
-
sessionId: data === null || data === void 0 ? void 0 : data.sessionId,
|
|
259
|
-
},
|
|
260
|
-
stores: {
|
|
261
|
-
storage: this.storage,
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
this.currentChatId = newChat.id;
|
|
265
|
-
this.storage.set('currentChatId', newChat.id);
|
|
266
|
-
this.chats.push(newChat);
|
|
267
|
-
return newChat;
|
|
268
|
-
};
|
|
269
|
-
ChatStore.prototype.switchChat = function (id) {
|
|
270
|
-
var chatExists = this.chats.find(function (chat) { return chat.id === id; });
|
|
271
|
-
if (chatExists) {
|
|
272
|
-
// Lazily hydrate results when switching to a session for the first time
|
|
273
|
-
if (!chatExists.hydrated && this.storedMetaData) {
|
|
274
|
-
chatExists.hydrateResults(this.storedMetaData);
|
|
275
|
-
chatExists.hydrated = true;
|
|
276
|
-
}
|
|
277
|
-
this.currentChatId = id;
|
|
278
|
-
this.storage.set('currentChatId', id);
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
ChatStore.prototype.sendProductQuery = function (result, options) {
|
|
282
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
283
|
-
var display = (result === null || result === void 0 ? void 0 : result.display) || result;
|
|
284
|
-
(_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.add({
|
|
285
|
-
type: 'product',
|
|
286
|
-
requestType: options.requestType,
|
|
287
|
-
productId: result.id,
|
|
288
|
-
name: (_c = (_b = display.mappings) === null || _b === void 0 ? void 0 : _b.core) === null || _c === void 0 ? void 0 : _c.name,
|
|
289
|
-
thumbnailUrl: ((_e = (_d = display.mappings) === null || _d === void 0 ? void 0 : _d.core) === null || _e === void 0 ? void 0 : _e.thumbnailImageUrl) || ((_g = (_f = display.mappings) === null || _f === void 0 ? void 0 : _f.core) === null || _g === void 0 ? void 0 : _g.imageUrl),
|
|
290
|
-
});
|
|
291
|
-
// for the productQuery flow we want the secondary chat to immediately
|
|
292
|
-
// show the product details panel — push a productQuery message so it
|
|
293
|
-
// becomes the active side-chat message until a productAnswer arrives
|
|
294
|
-
if (options.requestType === 'productQuery' && this.currentChat) {
|
|
295
|
-
this.currentChat.pushProductQueryMessage(result);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
ChatStore.prototype.compareProduct = function (result) {
|
|
299
|
-
var _a;
|
|
300
|
-
(_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.comparisons.add({
|
|
301
|
-
result: result,
|
|
302
|
-
});
|
|
303
|
-
};
|
|
304
|
-
ChatStore.prototype.addFacet = function (facet) {
|
|
305
|
-
var _a;
|
|
306
|
-
(_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.add({
|
|
307
|
-
type: 'facet',
|
|
308
|
-
key: facet.key,
|
|
309
|
-
facetLabel: facet.facetLabel,
|
|
310
|
-
value: facet.value,
|
|
311
|
-
label: facet.label,
|
|
312
|
-
count: facet.count,
|
|
313
|
-
});
|
|
314
|
-
// If re-selecting a previously removed server-side filter, remove it from removedFacets
|
|
315
|
-
if (this.currentChat) {
|
|
316
|
-
var removedIndex = this.currentChat.removedFacets.findIndex(function (rf) { return rf.key === facet.key && rf.value === facet.value; });
|
|
317
|
-
if (removedIndex !== -1) {
|
|
318
|
-
this.currentChat.removedFacets.splice(removedIndex, 1);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
ChatStore.prototype.removeFacet = function (key, value) {
|
|
323
|
-
var _a, _b, _c;
|
|
324
|
-
var facetAttachment = (_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.items.find(function (item) {
|
|
325
|
-
return item.type === 'facet' &&
|
|
326
|
-
item.key === key &&
|
|
327
|
-
item.value === value &&
|
|
328
|
-
(item.state === 'active' || item.state === 'attached');
|
|
329
|
-
});
|
|
330
|
-
if (facetAttachment) {
|
|
331
|
-
var index = (_b = this.currentChat) === null || _b === void 0 ? void 0 : _b.attachments.items.indexOf(facetAttachment);
|
|
332
|
-
if (index !== undefined && index !== -1) {
|
|
333
|
-
(_c = this.currentChat) === null || _c === void 0 ? void 0 : _c.attachments.items.splice(index, 1);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
else if (this.currentChat) {
|
|
337
|
-
// No attachment exists — this is a server-side filtered facet.
|
|
338
|
-
// Track it as explicitly removed so the next request excludes it.
|
|
339
|
-
var alreadyRemoved = this.currentChat.removedFacets.some(function (rf) { return rf.key === key && rf.value === value; });
|
|
340
|
-
if (!alreadyRemoved) {
|
|
341
|
-
this.currentChat.removedFacets.push({ key: key, value: value });
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
ChatStore.prototype.clearPendingFacets = function () {
|
|
346
|
-
var _this = this;
|
|
347
|
-
var _a;
|
|
348
|
-
var facetAttachments = ((_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.items.filter(function (item) { return item.type === 'facet' && (item.state === 'active' || item.state === 'attached'); })) || [];
|
|
349
|
-
facetAttachments.forEach(function (item) {
|
|
350
|
-
var _a, _b;
|
|
351
|
-
var index = (_a = _this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.items.indexOf(item);
|
|
352
|
-
if (index !== undefined && index !== -1) {
|
|
353
|
-
(_b = _this.currentChat) === null || _b === void 0 ? void 0 : _b.attachments.items.splice(index, 1);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
if (this.currentChat) {
|
|
357
|
-
this.currentChat.removedFacets = [];
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
ChatStore.prototype.isFacetSelected = function (key, value) {
|
|
361
|
-
var _a;
|
|
362
|
-
// A facet that has been explicitly removed by the user is not selected,
|
|
363
|
-
// even if the server still reports it as filtered.
|
|
364
|
-
if (this.isFacetRemoved(key, value)) {
|
|
365
|
-
return false;
|
|
366
|
-
}
|
|
367
|
-
return (((_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.items.some(function (item) {
|
|
368
|
-
return item.type === 'facet' &&
|
|
369
|
-
item.key === key &&
|
|
370
|
-
item.value === value &&
|
|
371
|
-
(item.state === 'active' || item.state === 'attached');
|
|
372
|
-
})) || false);
|
|
373
|
-
};
|
|
374
|
-
ChatStore.prototype.isFacetRemoved = function (key, value) {
|
|
375
|
-
var _a;
|
|
376
|
-
return ((_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.removedFacets.some(function (rf) { return rf.key === key && rf.value === value; })) || false;
|
|
377
|
-
};
|
|
378
|
-
ChatStore.prototype.request = function (request) {
|
|
379
|
-
var _this = this;
|
|
380
|
-
var _a, _b, _c;
|
|
381
|
-
(_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.request(request);
|
|
382
|
-
// remove any facet attachments after request
|
|
383
|
-
var facetAttachments = ((_b = this.currentChat) === null || _b === void 0 ? void 0 : _b.attachments.attached.filter(function (item) { return item.type === 'facet'; })) || [];
|
|
384
|
-
facetAttachments.forEach(function (item) {
|
|
385
|
-
var _a;
|
|
386
|
-
(_a = _this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.remove(item.id);
|
|
387
|
-
});
|
|
388
|
-
// remove any productSimilar attachments after request
|
|
389
|
-
var productSimilarAttachments = ((_c = this.currentChat) === null || _c === void 0 ? void 0 : _c.attachments.attached.filter(function (item) { return item.type === 'product' && item.requestType === 'productSimilar'; })) || [];
|
|
390
|
-
productSimilarAttachments.forEach(function (item) {
|
|
391
|
-
var _a;
|
|
392
|
-
(_a = _this.currentChat) === null || _a === void 0 ? void 0 : _a.attachments.remove(item.id);
|
|
393
|
-
});
|
|
394
|
-
};
|
|
395
|
-
ChatStore.prototype.update = function (data) {
|
|
396
|
-
// TODO: handle error
|
|
397
|
-
// if(err?.responseBody?.errorMessage || err?.responseBody?.errorCode) {
|
|
398
|
-
// const errorMessage = err?.responseBody?.errorMessage || 'An unknown error has occurred.';
|
|
399
|
-
// }
|
|
400
|
-
var _a;
|
|
401
|
-
(_a = this.currentChat) === null || _a === void 0 ? void 0 : _a.update(data);
|
|
402
|
-
if (!this.meta) {
|
|
403
|
-
this.storage.set('meta', JSON.stringify(data.meta));
|
|
404
|
-
}
|
|
405
|
-
this.meta = new MetaStore_1.MetaStore({
|
|
406
|
-
data: {
|
|
407
|
-
meta: data.meta,
|
|
408
|
-
},
|
|
409
|
-
});
|
|
410
|
-
// Keep raw meta in sync for lazy hydration of inactive sessions
|
|
411
|
-
this.storedMetaData = data.meta;
|
|
412
|
-
};
|
|
413
|
-
return ChatStore;
|
|
414
|
-
}(AbstractStore_1.AbstractStore));
|
|
415
|
-
exports.ChatStore = ChatStore;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
type AttachmentState = 'loading' | 'error' | 'attached' | 'active' | 'saved';
|
|
2
|
-
type AttachmentError = {
|
|
3
|
-
message: string;
|
|
4
|
-
};
|
|
5
|
-
export type ChatAttachmentAddAttachment = ChatAttachmentImageConfig | ChatAttachmentProductConfig | ChatAttachmentFacetConfig;
|
|
6
|
-
export declare class ChatAttachmentStore {
|
|
7
|
-
items: ChatAttachments[];
|
|
8
|
-
constructor();
|
|
9
|
-
get attached(): ChatAttachments[];
|
|
10
|
-
get compared(): ChatAttachmentProduct[];
|
|
11
|
-
add<T extends ChatAttachments>(attachment: ChatAttachmentAddAttachment): T;
|
|
12
|
-
remove(id: string): void;
|
|
13
|
-
get(id: string): ChatAttachments | undefined;
|
|
14
|
-
reset(): void;
|
|
15
|
-
hydrate(attachments: ChatAttachmentAddAttachment[]): void;
|
|
16
|
-
}
|
|
17
|
-
type ChatAttachments = ChatAttachmentImage | ChatAttachmentProduct | ChatAttachmentFacet;
|
|
18
|
-
declare abstract class ChatAttachment {
|
|
19
|
-
abstract type: string;
|
|
20
|
-
id: string;
|
|
21
|
-
state: AttachmentState;
|
|
22
|
-
error?: AttachmentError;
|
|
23
|
-
constructor(params?: {
|
|
24
|
-
data?: {
|
|
25
|
-
id?: string;
|
|
26
|
-
state?: AttachmentState;
|
|
27
|
-
error?: AttachmentError;
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
save(): void;
|
|
31
|
-
activate(): void;
|
|
32
|
-
}
|
|
33
|
-
type ChatAttachmentImageConfig = {
|
|
34
|
-
type: 'image';
|
|
35
|
-
id?: string;
|
|
36
|
-
base64?: string;
|
|
37
|
-
fileName?: string;
|
|
38
|
-
imageId?: string;
|
|
39
|
-
imageUrl?: string;
|
|
40
|
-
thumbnailUrl?: string;
|
|
41
|
-
state?: AttachmentState;
|
|
42
|
-
error?: AttachmentError;
|
|
43
|
-
};
|
|
44
|
-
type ChatAttachmentProductConfig = {
|
|
45
|
-
type: 'product';
|
|
46
|
-
id?: string;
|
|
47
|
-
productId: string;
|
|
48
|
-
thumbnailUrl: string;
|
|
49
|
-
name: string;
|
|
50
|
-
requestType: 'productQuery' | 'productSimilar' | 'productComparison';
|
|
51
|
-
state?: AttachmentState;
|
|
52
|
-
error?: AttachmentError;
|
|
53
|
-
};
|
|
54
|
-
type ChatAttachmentFacetConfig = {
|
|
55
|
-
type: 'facet';
|
|
56
|
-
id?: string;
|
|
57
|
-
key: string;
|
|
58
|
-
facetLabel: string;
|
|
59
|
-
value: string;
|
|
60
|
-
label: string;
|
|
61
|
-
count: number;
|
|
62
|
-
state?: AttachmentState;
|
|
63
|
-
error?: AttachmentError;
|
|
64
|
-
};
|
|
65
|
-
export declare class ChatAttachmentProduct extends ChatAttachment {
|
|
66
|
-
type: 'product' | never;
|
|
67
|
-
productId: string;
|
|
68
|
-
thumbnailUrl: string;
|
|
69
|
-
name: string;
|
|
70
|
-
requestType: 'productQuery' | 'productSimilar' | 'productComparison';
|
|
71
|
-
constructor({ id, productId, thumbnailUrl, name, requestType, state, error }: ChatAttachmentProductConfig);
|
|
72
|
-
}
|
|
73
|
-
export declare class ChatAttachmentFacet extends ChatAttachment {
|
|
74
|
-
type: 'facet' | never;
|
|
75
|
-
key: string;
|
|
76
|
-
facetLabel: string;
|
|
77
|
-
value: string;
|
|
78
|
-
label: string;
|
|
79
|
-
count: number;
|
|
80
|
-
constructor({ id, key, facetLabel, value, label, count, state, error }: ChatAttachmentFacetConfig);
|
|
81
|
-
}
|
|
82
|
-
export declare class ChatAttachmentImage extends ChatAttachment {
|
|
83
|
-
type: 'image' | never;
|
|
84
|
-
fileName?: string;
|
|
85
|
-
imageId?: string;
|
|
86
|
-
imageUrl?: string;
|
|
87
|
-
thumbnailUrl?: string;
|
|
88
|
-
base64?: string;
|
|
89
|
-
constructor({ id, base64, fileName, imageId, imageUrl, thumbnailUrl, state, error }: ChatAttachmentImageConfig);
|
|
90
|
-
update: ({ imageId, imageUrl, thumbnailUrl, error, }: {
|
|
91
|
-
imageId?: string;
|
|
92
|
-
imageUrl?: string;
|
|
93
|
-
thumbnailUrl?: string;
|
|
94
|
-
error?: AttachmentError;
|
|
95
|
-
}) => Promise<void>;
|
|
96
|
-
}
|
|
97
|
-
export {};
|
|
98
|
-
//# sourceMappingURL=ChatAttachmentStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChatAttachmentStore.d.ts","sourceRoot":"","sources":["../../../../src/Chat/Stores/ChatAttachmentStore.ts"],"names":[],"mappings":"AAKA,KAAK,eAAe,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC7E,KAAK,eAAe,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,yBAAyB,GAAG,2BAA2B,GAAG,yBAAyB,CAAC;AAE9H,qBAAa,mBAAmB;IACxB,KAAK,EAAE,eAAe,EAAE,CAAM;;IAUrC,IAAI,QAAQ,sBAEX;IAED,IAAI,QAAQ,4BAKX;IAED,GAAG,CAAC,CAAC,SAAS,eAAe,EAAE,UAAU,EAAE,2BAA2B,GAAG,CAAC;IAiG1E,MAAM,CAAC,EAAE,EAAE,MAAM;IAajB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAI5C,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,WAAW,EAAE,2BAA2B,EAAE,GAAG,IAAI;CAezD;AAID,KAAK,eAAe,GAAG,mBAAmB,GAAG,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