@athoscommerce/snap-store-mobx 1.2.3-beta.2 → 1.2.3-beta.4
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/Stores/AutocompleteFacetStore.d.ts.map +1 -1
- package/dist/cjs/Autocomplete/Stores/AutocompleteFacetStore.js +4 -2
- package/dist/cjs/Chat/ChatStore.d.ts +2 -0
- package/dist/cjs/Chat/ChatStore.d.ts.map +1 -1
- package/dist/cjs/Chat/ChatStore.js +52 -5
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.d.ts.map +1 -1
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.js +4 -2
- package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts +15 -1
- package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts.map +1 -1
- package/dist/cjs/Chat/Stores/ChatSessionStore.js +79 -2
- package/dist/cjs/Search/Stores/SearchFacetStore.d.ts +11 -11
- package/dist/cjs/Search/Stores/SearchFacetStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchFacetStore.js +32 -22
- package/dist/esm/Autocomplete/Stores/AutocompleteFacetStore.d.ts.map +1 -1
- package/dist/esm/Autocomplete/Stores/AutocompleteFacetStore.js +7 -5
- package/dist/esm/Chat/ChatStore.d.ts +2 -0
- package/dist/esm/Chat/ChatStore.d.ts.map +1 -1
- package/dist/esm/Chat/ChatStore.js +51 -5
- package/dist/esm/Chat/Stores/ChatAttachmentStore.d.ts.map +1 -1
- package/dist/esm/Chat/Stores/ChatAttachmentStore.js +4 -2
- package/dist/esm/Chat/Stores/ChatSessionStore.d.ts +15 -1
- package/dist/esm/Chat/Stores/ChatSessionStore.d.ts.map +1 -1
- package/dist/esm/Chat/Stores/ChatSessionStore.js +82 -2
- package/dist/esm/Search/Stores/SearchFacetStore.d.ts +11 -11
- package/dist/esm/Search/Stores/SearchFacetStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchFacetStore.js +31 -22
- package/package.json +5 -5
|
@@ -128,8 +128,9 @@ var Facet = /** @class */ (function () {
|
|
|
128
128
|
}
|
|
129
129
|
Object.defineProperty(Facet.prototype, "clear", {
|
|
130
130
|
get: function () {
|
|
131
|
+
var _a, _b;
|
|
131
132
|
return {
|
|
132
|
-
url: this.services.urlManager.remove('page').remove("filter.".concat(this.field)),
|
|
133
|
+
url: (_b = (_a = this.services) === null || _a === void 0 ? void 0 : _a.urlManager) === null || _b === void 0 ? void 0 : _b.remove('page').remove("filter.".concat(this.field)),
|
|
133
134
|
};
|
|
134
135
|
},
|
|
135
136
|
enumerable: false,
|
|
@@ -305,15 +306,18 @@ exports.ValueFacet = ValueFacet;
|
|
|
305
306
|
var FacetValue = /** @class */ (function () {
|
|
306
307
|
function FacetValue(services, facet, value) {
|
|
307
308
|
Object.assign(this, value);
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
valueUrl =
|
|
309
|
+
var urlManager = services === null || services === void 0 ? void 0 : services.urlManager;
|
|
310
|
+
if (urlManager) {
|
|
311
|
+
if (this.filtered) {
|
|
312
|
+
this.url = urlManager.remove('page').remove("filter.".concat(facet.field), value.value);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
var valueUrl = urlManager.remove('page');
|
|
316
|
+
if (facet.multiple == 'single') {
|
|
317
|
+
valueUrl = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.remove("filter.".concat(facet.field));
|
|
318
|
+
}
|
|
319
|
+
this.url = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.merge("filter.".concat(facet.field), value.value);
|
|
315
320
|
}
|
|
316
|
-
this.url = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.merge("filter.".concat(facet.field), value.value);
|
|
317
321
|
}
|
|
318
322
|
}
|
|
319
323
|
return FacetValue;
|
|
@@ -335,11 +339,14 @@ var FacetHierarchyValue = /** @class */ (function (_super) {
|
|
|
335
339
|
_this.history = true;
|
|
336
340
|
}
|
|
337
341
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
342
|
+
var urlManager = services === null || services === void 0 ? void 0 : services.urlManager;
|
|
343
|
+
if (urlManager) {
|
|
344
|
+
if (value.value) {
|
|
345
|
+
_this.url = urlManager.remove('page').set("filter.".concat(facet.field), value.value);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
_this.url = urlManager.remove('page').remove("filter.".concat(facet.field));
|
|
349
|
+
}
|
|
343
350
|
}
|
|
344
351
|
return _this;
|
|
345
352
|
}
|
|
@@ -349,15 +356,18 @@ exports.FacetHierarchyValue = FacetHierarchyValue;
|
|
|
349
356
|
var FacetRangeValue = /** @class */ (function () {
|
|
350
357
|
function FacetRangeValue(services, facet, value) {
|
|
351
358
|
Object.assign(this, value);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
valueUrl =
|
|
359
|
+
var urlManager = services === null || services === void 0 ? void 0 : services.urlManager;
|
|
360
|
+
if (urlManager) {
|
|
361
|
+
if (this.filtered) {
|
|
362
|
+
this.url = urlManager.remove('page').remove("filter.".concat(facet.field), [{ low: this.low, high: this.high }]);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
var valueUrl = urlManager.remove('page');
|
|
366
|
+
if (facet.multiple == 'single') {
|
|
367
|
+
valueUrl = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.remove("filter.".concat(facet.field));
|
|
368
|
+
}
|
|
369
|
+
this.url = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.merge("filter.".concat(facet.field), [{ low: this.low, high: this.high }]);
|
|
359
370
|
}
|
|
360
|
-
this.url = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.merge("filter.".concat(facet.field), [{ low: this.low, high: this.high }]);
|
|
361
371
|
}
|
|
362
372
|
}
|
|
363
373
|
return FacetRangeValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteFacetStore.d.ts","sourceRoot":"","sources":["../../../../src/Autocomplete/Stores/AutocompleteFacetStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,KAAK,4BAA4B,GAAG,sBAAsB,GAAG;IAC5D,KAAK,EAAE;QACN,YAAY,EAAE,sBAAsB,CAAC;KACrC,CAAC;CACF,CAAC;AACF,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAEW,MAAM,EAAE,4BAA4B;
|
|
1
|
+
{"version":3,"file":"AutocompleteFacetStore.d.ts","sourceRoot":"","sources":["../../../../src/Autocomplete/Stores/AutocompleteFacetStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,KAAK,4BAA4B,GAAG,sBAAsB,GAAG;IAC5D,KAAK,EAAE;QACN,YAAY,EAAE,sBAAsB,CAAC;KACrC,CAAC;CACF,CAAC;AACF,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAEW,MAAM,EAAE,4BAA4B;CAoChD"}
|
|
@@ -8,10 +8,12 @@ export class AutocompleteFacetStore extends Array {
|
|
|
8
8
|
// allow for only a singular facet option selection at a time
|
|
9
9
|
const facets = new SearchFacetStore({
|
|
10
10
|
...params,
|
|
11
|
-
services:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
services: services?.urlManager
|
|
12
|
+
? {
|
|
13
|
+
...services,
|
|
14
|
+
urlManager: services.urlManager.remove('filter'),
|
|
15
|
+
}
|
|
16
|
+
: services,
|
|
15
17
|
});
|
|
16
18
|
// mutate facet values to add 'preview' function
|
|
17
19
|
facets.forEach((facet) => {
|
|
@@ -26,7 +28,7 @@ export class AutocompleteFacetStore extends Array {
|
|
|
26
28
|
facet.filtered = true;
|
|
27
29
|
value.filtered = true;
|
|
28
30
|
state?.autocomplete.locks.facets.lock();
|
|
29
|
-
value.url
|
|
31
|
+
value.url?.go();
|
|
30
32
|
};
|
|
31
33
|
});
|
|
32
34
|
});
|
|
@@ -27,6 +27,7 @@ export declare class ChatStore extends AbstractStore<ChatStoreConfig> {
|
|
|
27
27
|
get currentChat(): ChatSessionStore | undefined;
|
|
28
28
|
get chatsIds(): string[];
|
|
29
29
|
get blocked(): boolean;
|
|
30
|
+
private applyChatStatusResponse;
|
|
30
31
|
handleChatStatusResponse(response: ChatStatusResponse): boolean;
|
|
31
32
|
reset(): void;
|
|
32
33
|
setProductQuickview(product: Product): void;
|
|
@@ -46,6 +47,7 @@ export declare class ChatStore extends AbstractStore<ChatStoreConfig> {
|
|
|
46
47
|
removeFacet(key: string, value: string): void;
|
|
47
48
|
clearPendingFacets(): void;
|
|
48
49
|
isFacetSelected(key: string, value: string): boolean;
|
|
50
|
+
isFacetRemoved(key: string, value: string): boolean;
|
|
49
51
|
request(request: ChatRequestModel): void;
|
|
50
52
|
update(data: {
|
|
51
53
|
chat: ChatResponseModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatStore.d.ts","sourceRoot":"","sources":["../../../src/Chat/ChatStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,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OAAO,EAAE,MAAM,GAAG,IAAI;IAI/C,qBAAqB,IAAI,IAAI;IAK7B,YAAY,IAAI,IAAI;IAoBpB,UAAU,CAAC,IAAI,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,gBAAgB;IAyB1D,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAa5B,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE;QAAE,WAAW,EAAE,cAAc,GAAG,gBAAgB,GAAG,mBAAmB,CAAA;KAAE,GAAG,IAAI;IAkBtH,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI;IAMjC,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAmB1B,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAuB7C,kBAAkB,IAAI,IAAI;IAc1B,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAkBpD,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAInD,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAmBxC,MAAM,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,iBAAiB,CAAC;QAAC,IAAI,EAAE,iBAAiB,CAAA;KAAE,GAAG,IAAI;CAkB/E"}
|
|
@@ -36,7 +36,10 @@ export class ChatStore extends AbstractStore {
|
|
|
36
36
|
this.storage.set('chatStatusResponse', null);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
|
|
39
|
+
// Apply the stored response without persisting, so the 12-hour
|
|
40
|
+
// checkTime keeps counting from the last real API call rather
|
|
41
|
+
// than resetting on every page load.
|
|
42
|
+
this.applyChatStatusResponse(storedChatStatus.response);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
catch {
|
|
@@ -66,6 +69,10 @@ export class ChatStore extends AbstractStore {
|
|
|
66
69
|
latestChatId = chatId;
|
|
67
70
|
}
|
|
68
71
|
});
|
|
72
|
+
// Prefer the persisted active chat ID so switching chats survives page reloads.
|
|
73
|
+
// Fall back to the most recently created chat if the stored ID is missing or stale.
|
|
74
|
+
const storedCurrentChatId = this.storage.get('currentChatId');
|
|
75
|
+
const activeChatId = storedCurrentChatId && this.chats.some((chat) => chat.id === storedCurrentChatId) ? storedCurrentChatId : latestChatId;
|
|
69
76
|
const storedMeta = this.storage.get('meta');
|
|
70
77
|
if (storedMeta) {
|
|
71
78
|
try {
|
|
@@ -79,7 +86,7 @@ export class ChatStore extends AbstractStore {
|
|
|
79
86
|
this.storedMetaData = metaData;
|
|
80
87
|
// Only hydrate the active chat session — inactive sessions will be
|
|
81
88
|
// hydrated lazily when switched to via switchChat()
|
|
82
|
-
const activeChat = this.chats.find((chat) => chat.id ===
|
|
89
|
+
const activeChat = this.chats.find((chat) => chat.id === activeChatId);
|
|
83
90
|
if (activeChat) {
|
|
84
91
|
activeChat.hydrateResults(metaData);
|
|
85
92
|
activeChat.hydrated = true;
|
|
@@ -89,7 +96,7 @@ export class ChatStore extends AbstractStore {
|
|
|
89
96
|
this.storage.set('meta', null);
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
|
-
this.currentChatId =
|
|
99
|
+
this.currentChatId = activeChatId;
|
|
93
100
|
makeObservable(this, {
|
|
94
101
|
meta: observable,
|
|
95
102
|
inputValue: observable,
|
|
@@ -122,16 +129,22 @@ export class ChatStore extends AbstractStore {
|
|
|
122
129
|
}
|
|
123
130
|
return isBlocked;
|
|
124
131
|
}
|
|
125
|
-
|
|
132
|
+
applyChatStatusResponse(response) {
|
|
126
133
|
const { chatbot, features } = response;
|
|
127
134
|
const { status, suggestedQuestions, welcomeMessage } = chatbot;
|
|
128
135
|
this.chatEnabled = status.enabled === true;
|
|
129
136
|
this.features = features;
|
|
130
137
|
this.suggestedQuestions = suggestedQuestions || [];
|
|
131
138
|
this.welcomeMessage = welcomeMessage || '';
|
|
132
|
-
this.storage.set('chatStatusResponse', JSON.stringify({ response, checkTime: Date.now() }));
|
|
133
139
|
return this.chatEnabled;
|
|
134
140
|
}
|
|
141
|
+
handleChatStatusResponse(response) {
|
|
142
|
+
const enabled = this.applyChatStatusResponse(response);
|
|
143
|
+
// Always persist on a real API response — restarts the 12-hour expiration
|
|
144
|
+
// so each new chat session refreshes the cache.
|
|
145
|
+
this.storage.set('chatStatusResponse', JSON.stringify({ response, checkTime: Date.now() }));
|
|
146
|
+
return enabled;
|
|
147
|
+
}
|
|
135
148
|
reset() {
|
|
136
149
|
this.chats = [];
|
|
137
150
|
this.clearProductQuickview();
|
|
@@ -193,6 +206,11 @@ export class ChatStore extends AbstractStore {
|
|
|
193
206
|
this.chats = [currentChat];
|
|
194
207
|
}
|
|
195
208
|
createChat(data) {
|
|
209
|
+
// abandon any in-flight request state from the previous chat — its
|
|
210
|
+
// response will be discarded by the controller, so the UI shouldn't
|
|
211
|
+
// keep showing its loading spinner or stale error
|
|
212
|
+
this.loading = false;
|
|
213
|
+
this.error = undefined;
|
|
196
214
|
// Prune old sessions before creating a new one to keep storage bounded
|
|
197
215
|
ChatSessionStore.pruneStoredSessions(this.storage);
|
|
198
216
|
const newChat = new ChatSessionStore({
|
|
@@ -204,6 +222,7 @@ export class ChatStore extends AbstractStore {
|
|
|
204
222
|
},
|
|
205
223
|
});
|
|
206
224
|
this.currentChatId = newChat.id;
|
|
225
|
+
this.storage.set('currentChatId', newChat.id);
|
|
207
226
|
this.chats.push(newChat);
|
|
208
227
|
return newChat;
|
|
209
228
|
}
|
|
@@ -216,6 +235,7 @@ export class ChatStore extends AbstractStore {
|
|
|
216
235
|
chatExists.hydrated = true;
|
|
217
236
|
}
|
|
218
237
|
this.currentChatId = id;
|
|
238
|
+
this.storage.set('currentChatId', id);
|
|
219
239
|
}
|
|
220
240
|
}
|
|
221
241
|
sendProductQuery(result, options) {
|
|
@@ -248,6 +268,13 @@ export class ChatStore extends AbstractStore {
|
|
|
248
268
|
label: facet.label,
|
|
249
269
|
count: facet.count,
|
|
250
270
|
});
|
|
271
|
+
// If re-selecting a previously removed server-side filter, remove it from removedFacets
|
|
272
|
+
if (this.currentChat) {
|
|
273
|
+
const removedIndex = this.currentChat.removedFacets.findIndex((rf) => rf.key === facet.key && rf.value === facet.value);
|
|
274
|
+
if (removedIndex !== -1) {
|
|
275
|
+
this.currentChat.removedFacets.splice(removedIndex, 1);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
251
278
|
}
|
|
252
279
|
removeFacet(key, value) {
|
|
253
280
|
const facetAttachment = this.currentChat?.attachments.items.find((item) => item.type === 'facet' &&
|
|
@@ -260,6 +287,14 @@ export class ChatStore extends AbstractStore {
|
|
|
260
287
|
this.currentChat?.attachments.items.splice(index, 1);
|
|
261
288
|
}
|
|
262
289
|
}
|
|
290
|
+
else if (this.currentChat) {
|
|
291
|
+
// No attachment exists — this is a server-side filtered facet.
|
|
292
|
+
// Track it as explicitly removed so the next request excludes it.
|
|
293
|
+
const alreadyRemoved = this.currentChat.removedFacets.some((rf) => rf.key === key && rf.value === value);
|
|
294
|
+
if (!alreadyRemoved) {
|
|
295
|
+
this.currentChat.removedFacets.push({ key, value });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
263
298
|
}
|
|
264
299
|
clearPendingFacets() {
|
|
265
300
|
const facetAttachments = this.currentChat?.attachments.items.filter((item) => item.type === 'facet' && (item.state === 'active' || item.state === 'attached')) || [];
|
|
@@ -269,13 +304,24 @@ export class ChatStore extends AbstractStore {
|
|
|
269
304
|
this.currentChat?.attachments.items.splice(index, 1);
|
|
270
305
|
}
|
|
271
306
|
});
|
|
307
|
+
if (this.currentChat) {
|
|
308
|
+
this.currentChat.removedFacets = [];
|
|
309
|
+
}
|
|
272
310
|
}
|
|
273
311
|
isFacetSelected(key, value) {
|
|
312
|
+
// A facet that has been explicitly removed by the user is not selected,
|
|
313
|
+
// even if the server still reports it as filtered.
|
|
314
|
+
if (this.isFacetRemoved(key, value)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
274
317
|
return (this.currentChat?.attachments.items.some((item) => item.type === 'facet' &&
|
|
275
318
|
item.key === key &&
|
|
276
319
|
item.value === value &&
|
|
277
320
|
(item.state === 'active' || item.state === 'attached')) || false);
|
|
278
321
|
}
|
|
322
|
+
isFacetRemoved(key, value) {
|
|
323
|
+
return this.currentChat?.removedFacets.some((rf) => rf.key === key && rf.value === value) || false;
|
|
324
|
+
}
|
|
279
325
|
request(request) {
|
|
280
326
|
this.currentChat?.request(request);
|
|
281
327
|
// remove any facet attachments after request
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,GA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KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,yBAAyB;CAkBjG;AACD,qBAAa,mBAAoB,SAAQ,cAAc;IAC/C,IAAI,EAAE,OAAO,GAAG,KAAK,CAAW;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEX,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,yBAAyB;IAoB9G,MAAM,gDAKH;QACF,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,eAAe,CAAC;KACxB,KAAG,OAAO,CAAC,IAAI,CAAC,CAUf;CACF"}
|
|
@@ -58,9 +58,11 @@ export class ChatAttachmentStore {
|
|
|
58
58
|
existingProductAttachment.requestType = attachment.requestType; // changes existing attachments to the incoming requestType
|
|
59
59
|
return existingProductAttachment;
|
|
60
60
|
}
|
|
61
|
-
//
|
|
61
|
+
// productComparison supports up to 4 products (matches ChatCompareStore.maxItems);
|
|
62
|
+
// trim oldest active/attached product attachments to keep total below the cap.
|
|
63
|
+
const COMPARISON_MAX = 4;
|
|
62
64
|
const productAttachments = this.items.filter((item) => item.type === 'product' && (item.state === 'active' || item.state === 'attached'));
|
|
63
|
-
while (productAttachments.length >=
|
|
65
|
+
while (productAttachments.length >= COMPARISON_MAX) {
|
|
64
66
|
const toRemove = productAttachments.pop();
|
|
65
67
|
if (toRemove) {
|
|
66
68
|
this.remove(toRemove.id);
|
|
@@ -3,6 +3,7 @@ import { ChatAttachmentAddAttachment, ChatAttachmentStore } from '../Stores/Chat
|
|
|
3
3
|
import type { StorageStore } from '../../Storage/StorageStore';
|
|
4
4
|
import { MetaResponseModel } from '@athoscommerce/snapi-types';
|
|
5
5
|
import { ChatCompareStore } from './ChatCompareStore';
|
|
6
|
+
import { SearchFacetStore } from '../../Search/Stores/SearchFacetStore';
|
|
6
7
|
export type ChatFeedbacks = {
|
|
7
8
|
messageId: string;
|
|
8
9
|
rating: 'UP' | 'DOWN';
|
|
@@ -16,6 +17,7 @@ export type ChatUserMessage = {
|
|
|
16
17
|
text: string;
|
|
17
18
|
attachments?: string[];
|
|
18
19
|
requestType?: string;
|
|
20
|
+
request?: Record<string, any>;
|
|
19
21
|
};
|
|
20
22
|
export type ChatProductQueryMessageData = {
|
|
21
23
|
id: string;
|
|
@@ -44,7 +46,14 @@ type ChatSessionStoreConfig = {
|
|
|
44
46
|
};
|
|
45
47
|
export type FacetsData = {
|
|
46
48
|
type: 'facets';
|
|
47
|
-
data:
|
|
49
|
+
data: SearchFacetStore;
|
|
50
|
+
filterSummary?: {
|
|
51
|
+
field: string;
|
|
52
|
+
value: string;
|
|
53
|
+
label?: string;
|
|
54
|
+
filterLabel?: string;
|
|
55
|
+
filterValue?: string;
|
|
56
|
+
}[];
|
|
48
57
|
};
|
|
49
58
|
export type ActionsData = {
|
|
50
59
|
type: 'actions';
|
|
@@ -68,6 +77,11 @@ export declare class ChatSessionStore {
|
|
|
68
77
|
dismissedSideChatMessageId: string | null;
|
|
69
78
|
activeMessageId: string | null;
|
|
70
79
|
sessionLimitReached: boolean;
|
|
80
|
+
/** Tracks server-filtered facets the user has explicitly unselected (pending next request). */
|
|
81
|
+
removedFacets: {
|
|
82
|
+
key: string;
|
|
83
|
+
value: string;
|
|
84
|
+
}[];
|
|
71
85
|
/** Whether raw stored results have been hydrated into Product/SearchResultStore instances. */
|
|
72
86
|
hydrated: boolean;
|
|
73
87
|
constructor(params: ChatSessionStoreConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatSessionStore.d.ts","sourceRoot":"","sources":["../../../../src/Chat/Stores/ChatSessionStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,mCAAmC,EACnC,iCAAiC,EACjC,uBAAuB,EACvB,6BAA6B,EAC7B,iCAAiC,EACjC,qCAAqC,EACrC,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,2BAA2B,EAI3B,mBAAmB,EACnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ChatSessionStore.d.ts","sourceRoot":"","sources":["../../../../src/Chat/Stores/ChatSessionStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,mCAAmC,EACnC,iCAAiC,EACjC,uBAAuB,EACvB,6BAA6B,EAC7B,iCAAiC,EACjC,qCAAqC,EACrC,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,2BAA2B,EAI3B,mBAAmB,EACnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAuD,MAAM,4BAA4B,CAAC;AACpH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AA2LxE,MAAM,MAAM,aAAa,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAC;AAEzE,MAAM,MAAM,mBAAmB,GAAG;IAAE,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAC;AAE5D,MAAM,MAA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AAE,sBAAsB;IAsEnC,eAAe,IAAI,IAAI;IAWvB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKlC,uBAAuB,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI;IAqB1C,sBAAsB,CAAC,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI;IAQpE,IAAI,SAAS,IAAI,OAAO,CAKvB;IAED,IAAI,UAAU,IAAI,0BAA0B,GAAG,IAAI,CAGlD;IAED,IAAI,aAAa,IAAI,WAAW,GAAG,IAAI,CAoCtC;IAEM,iBAAiB,IAAI,IAAI;IAKzB,gBAAgB,IAAI,MAAM,GAAG,SAAS;IAsBtC,KAAK,IAAI,IAAI;IASpB,OAAO,CAAC,WAAW,CAA8C;IAEjE,gEAAgE;IACzD,aAAa,IAAI,IAAI;IAmB5B;;;OAGG;IACI,IAAI,IAAI,IAAI;IAUnB,8DAA8D;WAChD,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,GAAE,MAAW,GAAG,IAAI;IAmBxF,2EAA2E;IACpE,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IA6C7C,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAyIxC,MAAM,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,iBAAiB,CAAC;QAAC,IAAI,EAAE,iBAAiB,CAAA;KAAE,GAAG,IAAI;CAiD/E"}
|
|
@@ -3,6 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
3
3
|
import { ChatAttachmentStore, } from '../Stores/ChatAttachmentStore';
|
|
4
4
|
import { ChatCompareStore } from './ChatCompareStore';
|
|
5
5
|
import { SearchResultStore, Product } from '../../Search/Stores/SearchResultStore';
|
|
6
|
+
import { SearchFacetStore } from '../../Search/Stores/SearchFacetStore';
|
|
6
7
|
function createChatResultStore(results, meta) {
|
|
7
8
|
return new SearchResultStore({
|
|
8
9
|
config: {},
|
|
@@ -21,14 +22,26 @@ function createChatProduct(result, meta) {
|
|
|
21
22
|
responseId: '',
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
function createChatFacetStore(facets, meta, storage) {
|
|
26
|
+
return new SearchFacetStore({
|
|
27
|
+
config: {},
|
|
28
|
+
stores: { storage },
|
|
29
|
+
data: {
|
|
30
|
+
search: { facets },
|
|
31
|
+
meta,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
24
35
|
/** Extract raw serializable data from a Product instance for storage. */
|
|
25
36
|
function serializeProduct(product) {
|
|
26
37
|
if (!(product instanceof Product))
|
|
27
38
|
return product;
|
|
28
39
|
const raw = {
|
|
29
40
|
id: product.id,
|
|
41
|
+
responseId: product.responseId,
|
|
30
42
|
mappings: product.mappings,
|
|
31
43
|
attributes: product.attributes,
|
|
44
|
+
badges: product.badges?.all?.map((b) => ({ tag: b.tag })) || [],
|
|
32
45
|
};
|
|
33
46
|
if (product.variants) {
|
|
34
47
|
raw.variants = {
|
|
@@ -128,6 +141,47 @@ function serializeChatForStorage(chat) {
|
|
|
128
141
|
}
|
|
129
142
|
});
|
|
130
143
|
}
|
|
144
|
+
/** Serialize SearchFacetStore instances in actions back to plain facet arrays for localStorage. */
|
|
145
|
+
function serializeActionsForStorage(actions) {
|
|
146
|
+
return actions.map((action) => {
|
|
147
|
+
if (action.type === 'facets') {
|
|
148
|
+
return {
|
|
149
|
+
...action,
|
|
150
|
+
data: serializeFacetStore(action.data),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return action;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** Convert a SearchFacetStore (or raw array) back to plain serializable facet objects. */
|
|
157
|
+
function serializeFacetStore(facetStore) {
|
|
158
|
+
return Array.from(facetStore).map((facet) => {
|
|
159
|
+
const serialized = {
|
|
160
|
+
field: facet.field,
|
|
161
|
+
label: facet.label,
|
|
162
|
+
type: facet.type,
|
|
163
|
+
filtered: facet.filtered,
|
|
164
|
+
};
|
|
165
|
+
if (facet.values) {
|
|
166
|
+
serialized.values = facet.values.map((value) => {
|
|
167
|
+
if (facet.type === 'range-buckets') {
|
|
168
|
+
return { low: value.low, high: value.high, label: value.label, count: value.count, filtered: value.filtered };
|
|
169
|
+
}
|
|
170
|
+
return { value: value.value, label: value.label, count: value.count, filtered: value.filtered };
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (facet.range) {
|
|
174
|
+
serialized.range = facet.range;
|
|
175
|
+
}
|
|
176
|
+
if (facet.active) {
|
|
177
|
+
serialized.active = facet.active;
|
|
178
|
+
}
|
|
179
|
+
if (facet.step != null) {
|
|
180
|
+
serialized.step = facet.step;
|
|
181
|
+
}
|
|
182
|
+
return serialized;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
131
185
|
export class ChatSessionStore {
|
|
132
186
|
constructor(params) {
|
|
133
187
|
this.chat = [];
|
|
@@ -143,6 +197,8 @@ export class ChatSessionStore {
|
|
|
143
197
|
this.dismissedSideChatMessageId = null;
|
|
144
198
|
this.activeMessageId = null;
|
|
145
199
|
this.sessionLimitReached = false;
|
|
200
|
+
/** Tracks server-filtered facets the user has explicitly unselected (pending next request). */
|
|
201
|
+
this.removedFacets = [];
|
|
146
202
|
/** Whether raw stored results have been hydrated into Product/SearchResultStore instances. */
|
|
147
203
|
this.hydrated = true;
|
|
148
204
|
this.saveTimerId = null;
|
|
@@ -205,6 +261,7 @@ export class ChatSessionStore {
|
|
|
205
261
|
dismissedSideChatMessageId: observable,
|
|
206
262
|
activeMessageId: observable,
|
|
207
263
|
sessionLimitReached: observable,
|
|
264
|
+
removedFacets: observable,
|
|
208
265
|
activeMessage: computed,
|
|
209
266
|
});
|
|
210
267
|
}
|
|
@@ -320,6 +377,7 @@ export class ChatSessionStore {
|
|
|
320
377
|
this.attachments.reset();
|
|
321
378
|
this.chat = [];
|
|
322
379
|
this.actions = [];
|
|
380
|
+
this.removedFacets = [];
|
|
323
381
|
this.feedbacks = [];
|
|
324
382
|
this.sessionFeedback = null;
|
|
325
383
|
}
|
|
@@ -333,7 +391,7 @@ export class ChatSessionStore {
|
|
|
333
391
|
sessionId: this.sessionId,
|
|
334
392
|
chat: serializeChatForStorage(this.chat),
|
|
335
393
|
attachments: serializeAttachmentsForStorage(this.attachments.items),
|
|
336
|
-
actions: this.actions,
|
|
394
|
+
actions: serializeActionsForStorage(this.actions),
|
|
337
395
|
feedbacks: this.feedbacks,
|
|
338
396
|
sessionFeedback: this.sessionFeedback,
|
|
339
397
|
feedbackDismissed: this.feedbackDismissed,
|
|
@@ -411,10 +469,20 @@ export class ChatSessionStore {
|
|
|
411
469
|
});
|
|
412
470
|
}
|
|
413
471
|
});
|
|
472
|
+
// Re-wrap raw stored facets as SearchFacetStore instances
|
|
473
|
+
this.actions.forEach((action, index) => {
|
|
474
|
+
if (action.type === 'facets' && action.data?.length > 0 && !(action.data instanceof SearchFacetStore)) {
|
|
475
|
+
this.actions[index] = {
|
|
476
|
+
...action,
|
|
477
|
+
data: createChatFacetStore(action.data, meta, this.storage),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
});
|
|
414
481
|
}
|
|
415
482
|
request(request) {
|
|
416
483
|
// clear the questions on new request
|
|
417
484
|
this.actions = [];
|
|
485
|
+
this.removedFacets = [];
|
|
418
486
|
this.requestType = request.data.requestType;
|
|
419
487
|
this.activeMessageId = null;
|
|
420
488
|
// remove any attachments that failed to upload
|
|
@@ -439,6 +507,17 @@ export class ChatSessionStore {
|
|
|
439
507
|
attachments: attachments.length > 0 ? attachments : undefined,
|
|
440
508
|
text: `Filter by ${filterTextArray.join(' and ')}`,
|
|
441
509
|
requestType: request.data.requestType,
|
|
510
|
+
request: request.data, // request is added here to conditionally display different text in MessageUser
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
else if (request.data.searchTerm) {
|
|
514
|
+
// for when a query is clicked from ChatInspirationResultMessage
|
|
515
|
+
this.chat.push({
|
|
516
|
+
id: uuidv4(),
|
|
517
|
+
messageType: 'user',
|
|
518
|
+
text: request.data.searchTerm,
|
|
519
|
+
requestType: request.data.requestType,
|
|
520
|
+
request: request.data, // request is added here to conditionally display different text in MessageUser
|
|
442
521
|
});
|
|
443
522
|
}
|
|
444
523
|
}
|
|
@@ -546,7 +625,8 @@ export class ChatSessionStore {
|
|
|
546
625
|
if (messageData.messageType === 'productSearchResult' && messageData.facets?.length > 0) {
|
|
547
626
|
this.actions.push({
|
|
548
627
|
type: 'facets',
|
|
549
|
-
data: messageData.facets,
|
|
628
|
+
data: createChatFacetStore(messageData.facets, meta, this.storage),
|
|
629
|
+
filterSummary: messageData.filterSummary || [],
|
|
550
630
|
});
|
|
551
631
|
}
|
|
552
632
|
// convert raw results to Product instances (via SearchResultStore) so
|
|
@@ -7,7 +7,7 @@ export type SearchFacetStoreConfig = {
|
|
|
7
7
|
stores: {
|
|
8
8
|
storage: StorageStore;
|
|
9
9
|
};
|
|
10
|
-
services
|
|
10
|
+
services?: StoreServices;
|
|
11
11
|
data: {
|
|
12
12
|
search?: SearchResponseModel;
|
|
13
13
|
meta: MetaResponseModel;
|
|
@@ -18,7 +18,7 @@ export declare class SearchFacetStore extends Array {
|
|
|
18
18
|
constructor(params: SearchFacetStoreConfig);
|
|
19
19
|
}
|
|
20
20
|
export declare class Facet {
|
|
21
|
-
services
|
|
21
|
+
services?: StoreServices;
|
|
22
22
|
type: 'range' | 'value' | 'range-buckets';
|
|
23
23
|
field: string;
|
|
24
24
|
filtered: boolean;
|
|
@@ -27,9 +27,9 @@ export declare class Facet {
|
|
|
27
27
|
display: string;
|
|
28
28
|
label: string;
|
|
29
29
|
storage: StorageStore;
|
|
30
|
-
constructor(services: StoreServices, storage: StorageStore, facet: SearchResponseModelFacetValue | SearchResponseModelFacetRange, facetMeta: MetaResponseModelFacet, config: FacetStoreConfig);
|
|
30
|
+
constructor(services: StoreServices | undefined, storage: StorageStore, facet: SearchResponseModelFacetValue | SearchResponseModelFacetRange, facetMeta: MetaResponseModelFacet, config: FacetStoreConfig);
|
|
31
31
|
get clear(): {
|
|
32
|
-
url: UrlManager;
|
|
32
|
+
url: UrlManager | undefined;
|
|
33
33
|
};
|
|
34
34
|
toggleCollapse(): void;
|
|
35
35
|
}
|
|
@@ -39,7 +39,7 @@ export declare class RangeFacet extends Facet {
|
|
|
39
39
|
active?: SearchRequestModelFilterRangeAllOfValue;
|
|
40
40
|
formatSeparator: string;
|
|
41
41
|
formatValue: string;
|
|
42
|
-
constructor(services: StoreServices, storage: StorageStore, facet: SearchResponseModelFacetRange, facetMeta: MetaResponseModelFacetSlider, config: FacetStoreConfig);
|
|
42
|
+
constructor(services: StoreServices | undefined, storage: StorageStore, facet: SearchResponseModelFacetRange, facetMeta: MetaResponseModelFacetSlider, config: FacetStoreConfig);
|
|
43
43
|
get filteredCount(): number;
|
|
44
44
|
}
|
|
45
45
|
export declare class ValueFacet extends Facet {
|
|
@@ -57,7 +57,7 @@ export declare class ValueFacet extends Facet {
|
|
|
57
57
|
toggle: (val?: boolean) => void;
|
|
58
58
|
calculate: () => void;
|
|
59
59
|
};
|
|
60
|
-
constructor(services: StoreServices, storage: StorageStore, facet: SearchResponseModelFacetValue, facetMeta: MetaResponseModelFacet, config: FacetStoreConfig);
|
|
60
|
+
constructor(services: StoreServices | undefined, storage: StorageStore, facet: SearchResponseModelFacetValue, facetMeta: MetaResponseModelFacet, config: FacetStoreConfig);
|
|
61
61
|
get filteredCount(): number;
|
|
62
62
|
get refinedValues(): (FacetHierarchyValue | FacetValue | FacetRangeValue | undefined)[];
|
|
63
63
|
}
|
|
@@ -67,14 +67,14 @@ export declare class FacetValue {
|
|
|
67
67
|
filtered: boolean;
|
|
68
68
|
value: string;
|
|
69
69
|
custom: object;
|
|
70
|
-
url
|
|
70
|
+
url?: UrlManager;
|
|
71
71
|
preview?: () => void;
|
|
72
|
-
constructor(services: StoreServices, facet: ValueFacet, value: SearchResponseModelFacetValueAllOfValues);
|
|
72
|
+
constructor(services: StoreServices | undefined, facet: ValueFacet, value: SearchResponseModelFacetValueAllOfValues);
|
|
73
73
|
}
|
|
74
74
|
export declare class FacetHierarchyValue extends FacetValue {
|
|
75
75
|
level: number;
|
|
76
76
|
history: boolean;
|
|
77
|
-
constructor(services: StoreServices, facet: ValueFacet & MetaResponseModelFacetHierarchyAllOf, value: SearchResponseModelFacetValueAllOfValues, filteredValues: SearchResponseModelFacetValueAllOfValues[]);
|
|
77
|
+
constructor(services: StoreServices | undefined, facet: ValueFacet & MetaResponseModelFacetHierarchyAllOf, value: SearchResponseModelFacetValueAllOfValues, filteredValues: SearchResponseModelFacetValueAllOfValues[]);
|
|
78
78
|
}
|
|
79
79
|
export declare class FacetRangeValue {
|
|
80
80
|
label: string;
|
|
@@ -83,7 +83,7 @@ export declare class FacetRangeValue {
|
|
|
83
83
|
low: number;
|
|
84
84
|
high: number;
|
|
85
85
|
custom: object;
|
|
86
|
-
url
|
|
87
|
-
constructor(services: StoreServices, facet: ValueFacet, value: SearchResponseModelFacetValueAllOfValues);
|
|
86
|
+
url?: UrlManager;
|
|
87
|
+
constructor(services: StoreServices | undefined, facet: ValueFacet, value: SearchResponseModelFacetValueAllOfValues);
|
|
88
88
|
}
|
|
89
89
|
//# sourceMappingURL=SearchFacetStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchFacetStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchFacetStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/G,OAAO,KAAK,EACX,sBAAsB,EAEtB,4BAA4B,EAC5B,uCAAuC,EACvC,oCAAoC,EAEpC,6BAA6B,EAC7B,6BAA6B,EAE7B,wCAAwC,EACxC,uCAAuC,EACvC,mBAA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