@athoscommerce/snap-store-mobx 1.4.0 → 1.5.1-beta.110
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.map +1 -1
- package/dist/cjs/Autocomplete/AutocompleteStore.js +4 -1
- package/dist/cjs/Autocomplete/Stores/AutocompleteFacetStore.js +2 -1
- package/dist/cjs/Chat/ChatStore.d.ts +86 -0
- package/dist/cjs/Chat/ChatStore.d.ts.map +1 -0
- package/dist/cjs/Chat/ChatStore.js +539 -0
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.d.ts +98 -0
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.d.ts.map +1 -0
- package/dist/cjs/Chat/Stores/ChatAttachmentStore.js +314 -0
- package/dist/cjs/Chat/Stores/ChatCompareStore.d.ts +16 -0
- package/dist/cjs/Chat/Stores/ChatCompareStore.d.ts.map +1 -0
- package/dist/cjs/Chat/Stores/ChatCompareStore.js +65 -0
- package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts +107 -0
- package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts.map +1 -0
- package/dist/cjs/Chat/Stores/ChatSessionStore.js +635 -0
- package/dist/cjs/Recommendation/Stores/RecommendationProfileStore.js +1 -1
- package/dist/cjs/Search/Stores/SearchFacetStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchFacetStore.js +13 -10
- 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 +2 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/types.d.ts +21 -2
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteStore.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteStore.js +3 -1
- package/dist/esm/Autocomplete/Stores/AutocompleteFacetStore.js +1 -1
- package/dist/esm/Chat/ChatStore.d.ts +86 -0
- package/dist/esm/Chat/ChatStore.d.ts.map +1 -0
- package/dist/esm/Chat/ChatStore.js +478 -0
- package/dist/esm/Chat/Stores/ChatAttachmentStore.d.ts +98 -0
- package/dist/esm/Chat/Stores/ChatAttachmentStore.d.ts.map +1 -0
- package/dist/esm/Chat/Stores/ChatAttachmentStore.js +222 -0
- package/dist/esm/Chat/Stores/ChatCompareStore.d.ts +16 -0
- package/dist/esm/Chat/Stores/ChatCompareStore.d.ts.map +1 -0
- package/dist/esm/Chat/Stores/ChatCompareStore.js +51 -0
- package/dist/esm/Chat/Stores/ChatSessionStore.d.ts +107 -0
- package/dist/esm/Chat/Stores/ChatSessionStore.d.ts.map +1 -0
- package/dist/esm/Chat/Stores/ChatSessionStore.js +601 -0
- package/dist/esm/Recommendation/Stores/RecommendationProfileStore.js +1 -1
- package/dist/esm/Search/Stores/SearchFacetStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchFacetStore.js +13 -10
- 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 +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.d.ts +21 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,314 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.ChatAttachmentImage = exports.ChatAttachmentFacet = exports.ChatAttachmentProduct = exports.ChatAttachmentStore = void 0;
|
|
55
|
+
// TODO: implement
|
|
56
|
+
// how should localStorage be handled for attachments?
|
|
57
|
+
var uuid_1 = require("uuid");
|
|
58
|
+
var mobx_1 = require("mobx");
|
|
59
|
+
var ChatCompareStore_1 = require("./ChatCompareStore");
|
|
60
|
+
var ChatAttachmentStore = /** @class */ (function () {
|
|
61
|
+
function ChatAttachmentStore() {
|
|
62
|
+
this.items = [];
|
|
63
|
+
(0, mobx_1.makeObservable)(this, {
|
|
64
|
+
items: mobx_1.observable,
|
|
65
|
+
attached: mobx_1.computed,
|
|
66
|
+
compared: mobx_1.computed,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
Object.defineProperty(ChatAttachmentStore.prototype, "attached", {
|
|
70
|
+
get: function () {
|
|
71
|
+
return this.items.filter(function (item) { return item.state !== 'saved'; });
|
|
72
|
+
},
|
|
73
|
+
enumerable: false,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(ChatAttachmentStore.prototype, "compared", {
|
|
77
|
+
get: function () {
|
|
78
|
+
return this.items
|
|
79
|
+
.filter(function (item) { return item.state !== 'saved'; })
|
|
80
|
+
.filter(function (item) { return item.type === 'product'; })
|
|
81
|
+
.filter(function (item) { return item.requestType === 'productComparison'; });
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
ChatAttachmentStore.prototype.add = function (attachment) {
|
|
87
|
+
var _this = this;
|
|
88
|
+
// TODO: check if attachment already exists
|
|
89
|
+
switch (attachment.type) {
|
|
90
|
+
case 'image': {
|
|
91
|
+
// if there are currently any other attachments remove them
|
|
92
|
+
this.items.forEach(function (item) {
|
|
93
|
+
_this.remove(item.id);
|
|
94
|
+
});
|
|
95
|
+
var newAttachment = new ChatAttachmentImage(attachment);
|
|
96
|
+
this.items.push(newAttachment);
|
|
97
|
+
return newAttachment;
|
|
98
|
+
}
|
|
99
|
+
case 'product': {
|
|
100
|
+
// 'productSimilar' and 'productQuery' are single-product flows — replace any
|
|
101
|
+
// existing attachments so the conversation only targets the latest product
|
|
102
|
+
if (attachment.requestType === 'productSimilar' || attachment.requestType === 'productQuery') {
|
|
103
|
+
this.items.forEach(function (item) {
|
|
104
|
+
_this.remove(item.id);
|
|
105
|
+
});
|
|
106
|
+
var newAttachment_1 = new ChatAttachmentProduct(attachment);
|
|
107
|
+
this.items.unshift(newAttachment_1);
|
|
108
|
+
return newAttachment_1;
|
|
109
|
+
}
|
|
110
|
+
// For 'productQuery' or 'productComparison', continue with existing logic
|
|
111
|
+
// if there are currently any other attachments remove them
|
|
112
|
+
this.items.forEach(function (item) {
|
|
113
|
+
if (item.type !== 'product') {
|
|
114
|
+
_this.remove(item.id);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
// check if product is already attached
|
|
118
|
+
var existingProductAttachment = this.items.find(function (item) {
|
|
119
|
+
return item.type === 'product' &&
|
|
120
|
+
(item.state === 'active' || item.state === 'attached') &&
|
|
121
|
+
item.productId === attachment.productId;
|
|
122
|
+
});
|
|
123
|
+
if (existingProductAttachment) {
|
|
124
|
+
existingProductAttachment.requestType = attachment.requestType; // changes existing attachments to the incoming requestType
|
|
125
|
+
return existingProductAttachment;
|
|
126
|
+
}
|
|
127
|
+
// productComparison supports up to CHAT_COMPARISON_MAX products (matches ChatCompareStore.maxItems);
|
|
128
|
+
// trim oldest active/attached product attachments to keep total below the cap.
|
|
129
|
+
var productAttachments = this.items.filter(function (item) { return item.type === 'product' && (item.state === 'active' || item.state === 'attached'); });
|
|
130
|
+
while (productAttachments.length >= ChatCompareStore_1.CHAT_COMPARISON_MAX) {
|
|
131
|
+
var toRemove = productAttachments.pop();
|
|
132
|
+
if (toRemove) {
|
|
133
|
+
this.remove(toRemove.id);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.items.forEach(function (item) {
|
|
137
|
+
item.requestType = attachment.requestType; // changes existing attachments to the incoming requestType
|
|
138
|
+
});
|
|
139
|
+
var newAttachment = new ChatAttachmentProduct(attachment);
|
|
140
|
+
this.items.unshift(newAttachment);
|
|
141
|
+
return newAttachment;
|
|
142
|
+
}
|
|
143
|
+
case 'facet': {
|
|
144
|
+
// if there are currently any non-facet attachments remove them
|
|
145
|
+
this.items.forEach(function (item) {
|
|
146
|
+
if (item.type !== 'facet') {
|
|
147
|
+
_this.remove(item.id);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
// check if this exact facet value is already attached
|
|
151
|
+
var existingFacet = this.items.find(function (item) {
|
|
152
|
+
return item.type === 'facet' &&
|
|
153
|
+
item.key === attachment.key &&
|
|
154
|
+
item.value === attachment.value &&
|
|
155
|
+
(item.state === 'active' || item.state === 'attached');
|
|
156
|
+
});
|
|
157
|
+
if (existingFacet) {
|
|
158
|
+
return existingFacet;
|
|
159
|
+
}
|
|
160
|
+
var newAttachment = new ChatAttachmentFacet(attachment);
|
|
161
|
+
this.items.push(newAttachment);
|
|
162
|
+
return newAttachment;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
ChatAttachmentStore.prototype.remove = function (id) {
|
|
167
|
+
var index = this.items.findIndex(function (item) { return item.id === id; });
|
|
168
|
+
var attachment = this.items[index];
|
|
169
|
+
if (attachment.state === 'active' || attachment.state === 'saved') {
|
|
170
|
+
attachment.save();
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
if (index !== -1) {
|
|
174
|
+
this.items.splice(index, 1);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
ChatAttachmentStore.prototype.get = function (id) {
|
|
179
|
+
return this.items.find(function (item) { return item.id === id; });
|
|
180
|
+
};
|
|
181
|
+
ChatAttachmentStore.prototype.reset = function () {
|
|
182
|
+
this.items = [];
|
|
183
|
+
};
|
|
184
|
+
// Restore serialized attachments from storage without running the add() dedup logic,
|
|
185
|
+
// which would otherwise drop earlier images when multiple attachments are loaded.
|
|
186
|
+
ChatAttachmentStore.prototype.hydrate = function (attachments) {
|
|
187
|
+
var _this = this;
|
|
188
|
+
attachments.forEach(function (attachment) {
|
|
189
|
+
switch (attachment.type) {
|
|
190
|
+
case 'image':
|
|
191
|
+
_this.items.push(new ChatAttachmentImage(attachment));
|
|
192
|
+
break;
|
|
193
|
+
case 'product':
|
|
194
|
+
_this.items.push(new ChatAttachmentProduct(attachment));
|
|
195
|
+
break;
|
|
196
|
+
case 'facet':
|
|
197
|
+
_this.items.push(new ChatAttachmentFacet(attachment));
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
return ChatAttachmentStore;
|
|
203
|
+
}());
|
|
204
|
+
exports.ChatAttachmentStore = ChatAttachmentStore;
|
|
205
|
+
var ChatAttachment = /** @class */ (function () {
|
|
206
|
+
function ChatAttachment(params) {
|
|
207
|
+
if (params === void 0) { params = {}; }
|
|
208
|
+
var _a, _b, _c, _d;
|
|
209
|
+
this.state = 'loading';
|
|
210
|
+
this.error = undefined;
|
|
211
|
+
this.id = (_b = (_a = params.data) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : (0, uuid_1.v4)();
|
|
212
|
+
this.state = (_d = (_c = params.data) === null || _c === void 0 ? void 0 : _c.state) !== null && _d !== void 0 ? _d : 'loading';
|
|
213
|
+
(0, mobx_1.makeObservable)(this, {
|
|
214
|
+
id: mobx_1.observable,
|
|
215
|
+
state: mobx_1.observable,
|
|
216
|
+
error: mobx_1.observable,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
ChatAttachment.prototype.save = function () {
|
|
220
|
+
this.state = 'saved';
|
|
221
|
+
};
|
|
222
|
+
ChatAttachment.prototype.activate = function () {
|
|
223
|
+
this.state = 'active';
|
|
224
|
+
};
|
|
225
|
+
return ChatAttachment;
|
|
226
|
+
}());
|
|
227
|
+
var ChatAttachmentProduct = /** @class */ (function (_super) {
|
|
228
|
+
__extends(ChatAttachmentProduct, _super);
|
|
229
|
+
function ChatAttachmentProduct(_a) {
|
|
230
|
+
var id = _a.id, productId = _a.productId, thumbnailUrl = _a.thumbnailUrl, name = _a.name, requestType = _a.requestType, state = _a.state, error = _a.error;
|
|
231
|
+
var _this = _super.call(this, { data: { id: id, state: state, error: error } }) || this;
|
|
232
|
+
_this.type = 'product';
|
|
233
|
+
_this.state = state !== null && state !== void 0 ? state : 'attached';
|
|
234
|
+
_this.productId = productId;
|
|
235
|
+
_this.thumbnailUrl = thumbnailUrl;
|
|
236
|
+
_this.name = name;
|
|
237
|
+
_this.requestType = requestType;
|
|
238
|
+
(0, mobx_1.makeObservable)(_this, {
|
|
239
|
+
type: mobx_1.observable,
|
|
240
|
+
productId: mobx_1.observable,
|
|
241
|
+
thumbnailUrl: mobx_1.observable,
|
|
242
|
+
name: mobx_1.observable,
|
|
243
|
+
requestType: mobx_1.observable,
|
|
244
|
+
});
|
|
245
|
+
return _this;
|
|
246
|
+
}
|
|
247
|
+
return ChatAttachmentProduct;
|
|
248
|
+
}(ChatAttachment));
|
|
249
|
+
exports.ChatAttachmentProduct = ChatAttachmentProduct;
|
|
250
|
+
var ChatAttachmentFacet = /** @class */ (function (_super) {
|
|
251
|
+
__extends(ChatAttachmentFacet, _super);
|
|
252
|
+
function ChatAttachmentFacet(_a) {
|
|
253
|
+
var id = _a.id, key = _a.key, facetLabel = _a.facetLabel, value = _a.value, label = _a.label, count = _a.count, state = _a.state, error = _a.error;
|
|
254
|
+
var _this = _super.call(this, { data: { id: id, state: state, error: error } }) || this;
|
|
255
|
+
_this.type = 'facet';
|
|
256
|
+
_this.state = state !== null && state !== void 0 ? state : 'attached';
|
|
257
|
+
_this.key = key;
|
|
258
|
+
_this.facetLabel = facetLabel;
|
|
259
|
+
_this.value = value;
|
|
260
|
+
_this.label = label;
|
|
261
|
+
_this.count = count;
|
|
262
|
+
(0, mobx_1.makeObservable)(_this, {
|
|
263
|
+
type: mobx_1.observable,
|
|
264
|
+
key: mobx_1.observable,
|
|
265
|
+
facetLabel: mobx_1.observable,
|
|
266
|
+
value: mobx_1.observable,
|
|
267
|
+
label: mobx_1.observable,
|
|
268
|
+
});
|
|
269
|
+
return _this;
|
|
270
|
+
}
|
|
271
|
+
return ChatAttachmentFacet;
|
|
272
|
+
}(ChatAttachment));
|
|
273
|
+
exports.ChatAttachmentFacet = ChatAttachmentFacet;
|
|
274
|
+
var ChatAttachmentImage = /** @class */ (function (_super) {
|
|
275
|
+
__extends(ChatAttachmentImage, _super);
|
|
276
|
+
function ChatAttachmentImage(_a) {
|
|
277
|
+
var id = _a.id, base64 = _a.base64, fileName = _a.fileName, imageId = _a.imageId, imageUrl = _a.imageUrl, thumbnailUrl = _a.thumbnailUrl, state = _a.state, error = _a.error;
|
|
278
|
+
var _this = _super.call(this, { data: { id: id, state: state, error: error } }) || this;
|
|
279
|
+
_this.type = 'image';
|
|
280
|
+
// used to update attachment after upload or from
|
|
281
|
+
_this.update = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
282
|
+
var imageId = _b.imageId, imageUrl = _b.imageUrl, thumbnailUrl = _b.thumbnailUrl, error = _b.error;
|
|
283
|
+
return __generator(this, function (_c) {
|
|
284
|
+
if (imageId && imageUrl && thumbnailUrl) {
|
|
285
|
+
this.state = 'attached';
|
|
286
|
+
this.imageId = imageId;
|
|
287
|
+
this.imageUrl = imageUrl;
|
|
288
|
+
this.thumbnailUrl = thumbnailUrl;
|
|
289
|
+
}
|
|
290
|
+
else if (error) {
|
|
291
|
+
this.state = 'error';
|
|
292
|
+
this.error = error;
|
|
293
|
+
}
|
|
294
|
+
return [2 /*return*/];
|
|
295
|
+
});
|
|
296
|
+
}); };
|
|
297
|
+
_this.base64 = base64;
|
|
298
|
+
_this.fileName = fileName;
|
|
299
|
+
_this.imageId = imageId;
|
|
300
|
+
_this.imageUrl = imageUrl;
|
|
301
|
+
_this.thumbnailUrl = thumbnailUrl;
|
|
302
|
+
(0, mobx_1.makeObservable)(_this, {
|
|
303
|
+
type: mobx_1.observable,
|
|
304
|
+
imageId: mobx_1.observable,
|
|
305
|
+
imageUrl: mobx_1.observable,
|
|
306
|
+
thumbnailUrl: mobx_1.observable,
|
|
307
|
+
base64: mobx_1.observable,
|
|
308
|
+
fileName: mobx_1.observable,
|
|
309
|
+
});
|
|
310
|
+
return _this;
|
|
311
|
+
}
|
|
312
|
+
return ChatAttachmentImage;
|
|
313
|
+
}(ChatAttachment));
|
|
314
|
+
exports.ChatAttachmentImage = ChatAttachmentImage;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Maximum number of products that can be added to a chat comparison. */
|
|
2
|
+
export declare const CHAT_COMPARISON_MAX = 4;
|
|
3
|
+
export declare class ChatCompareStore {
|
|
4
|
+
items: any[];
|
|
5
|
+
committedItems: any[];
|
|
6
|
+
maxItems: number;
|
|
7
|
+
constructor();
|
|
8
|
+
add(item: any): void;
|
|
9
|
+
remove(itemId: string): void;
|
|
10
|
+
reset(): void;
|
|
11
|
+
resetCommitted(): void;
|
|
12
|
+
commit(): void;
|
|
13
|
+
get compared(): any[];
|
|
14
|
+
get committed(): any[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ChatCompareStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatCompareStore.d.ts","sourceRoot":"","sources":["../../../../src/Chat/Stores/ChatCompareStore.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,qBAAa,gBAAgB;IACrB,KAAK,EAAE,GAAG,EAAE,CAAM;IAClB,cAAc,EAAE,GAAG,EAAE,CAAM;IAC3B,QAAQ,EAAE,MAAM,CAAuB;;IAa9C,GAAG,CAAC,IAAI,EAAE,GAAG;IAYb,MAAM,CAAC,MAAM,EAAE,MAAM;IAIrB,KAAK;IAIL,cAAc;IAKd,MAAM;IAON,IAAI,QAAQ,UAEX;IAED,IAAI,SAAS,UAEZ;CACD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatCompareStore = exports.CHAT_COMPARISON_MAX = void 0;
|
|
4
|
+
var mobx_1 = require("mobx");
|
|
5
|
+
/** Maximum number of products that can be added to a chat comparison. */
|
|
6
|
+
exports.CHAT_COMPARISON_MAX = 4;
|
|
7
|
+
var ChatCompareStore = /** @class */ (function () {
|
|
8
|
+
function ChatCompareStore() {
|
|
9
|
+
this.items = [];
|
|
10
|
+
this.committedItems = [];
|
|
11
|
+
this.maxItems = exports.CHAT_COMPARISON_MAX;
|
|
12
|
+
(0, mobx_1.makeObservable)(this, {
|
|
13
|
+
items: mobx_1.observable,
|
|
14
|
+
committedItems: mobx_1.observable,
|
|
15
|
+
maxItems: mobx_1.observable,
|
|
16
|
+
compared: mobx_1.computed,
|
|
17
|
+
committed: mobx_1.computed,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
// add, remove, reset methods
|
|
21
|
+
ChatCompareStore.prototype.add = function (item) {
|
|
22
|
+
var _a;
|
|
23
|
+
// prevent adding the same product to the comparison twice
|
|
24
|
+
if (((_a = item.result) === null || _a === void 0 ? void 0 : _a.id) && this.items.some(function (existing) { var _a; return ((_a = existing.result) === null || _a === void 0 ? void 0 : _a.id) === item.result.id; })) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (this.items.length >= this.maxItems) {
|
|
28
|
+
// handle max items reached, e.g. remove the oldest item
|
|
29
|
+
this.items.shift();
|
|
30
|
+
}
|
|
31
|
+
this.items.push(item);
|
|
32
|
+
};
|
|
33
|
+
ChatCompareStore.prototype.remove = function (itemId) {
|
|
34
|
+
this.items = this.items.filter(function (item) { var _a; return ((_a = item.result) === null || _a === void 0 ? void 0 : _a.id) !== itemId; });
|
|
35
|
+
};
|
|
36
|
+
ChatCompareStore.prototype.reset = function () {
|
|
37
|
+
this.items = [];
|
|
38
|
+
};
|
|
39
|
+
ChatCompareStore.prototype.resetCommitted = function () {
|
|
40
|
+
this.committedItems = [];
|
|
41
|
+
};
|
|
42
|
+
// move the current items to the committed list and clear items
|
|
43
|
+
ChatCompareStore.prototype.commit = function () {
|
|
44
|
+
if (this.items.length > 0) {
|
|
45
|
+
this.committedItems = this.items.slice();
|
|
46
|
+
this.items = [];
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(ChatCompareStore.prototype, "compared", {
|
|
50
|
+
get: function () {
|
|
51
|
+
return this.items;
|
|
52
|
+
},
|
|
53
|
+
enumerable: false,
|
|
54
|
+
configurable: true
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(ChatCompareStore.prototype, "committed", {
|
|
57
|
+
get: function () {
|
|
58
|
+
return this.committedItems;
|
|
59
|
+
},
|
|
60
|
+
enumerable: false,
|
|
61
|
+
configurable: true
|
|
62
|
+
});
|
|
63
|
+
return ChatCompareStore;
|
|
64
|
+
}());
|
|
65
|
+
exports.ChatCompareStore = ChatCompareStore;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ChatResponseModel, ChatRequestModel, ChatResponseTextData, ChatResponseProductSearchResultData, ChatResponseInspirationResultData, ChatResponseContentData, ChatResponseProductAnswerData, ChatResponseProductComparisonData, ChatResponseProductRecommendationData, ChatResponseErrorData, ChatResponseTopicDriftData } from '@athoscommerce/snap-client';
|
|
2
|
+
import { ChatAttachmentAddAttachment, ChatAttachmentStore } from '../Stores/ChatAttachmentStore';
|
|
3
|
+
import type { StorageStore } from '@athoscommerce/snap-toolbox';
|
|
4
|
+
import { MetaResponseModel } from '@athoscommerce/snapi-types';
|
|
5
|
+
import { ChatCompareStore } from './ChatCompareStore';
|
|
6
|
+
export type ChatFeedbacks = {
|
|
7
|
+
messageId: string;
|
|
8
|
+
rating: 'UP' | 'DOWN';
|
|
9
|
+
};
|
|
10
|
+
export type ChatSessionFeedback = {
|
|
11
|
+
rating: 'UP' | 'DOWN';
|
|
12
|
+
};
|
|
13
|
+
export type ChatUserMessage = {
|
|
14
|
+
id: string;
|
|
15
|
+
messageType: 'user';
|
|
16
|
+
text: string;
|
|
17
|
+
attachments?: string[];
|
|
18
|
+
requestType?: string;
|
|
19
|
+
request?: Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
export type ChatProductQueryMessageData = {
|
|
22
|
+
id: string;
|
|
23
|
+
messageType: 'productQuery';
|
|
24
|
+
sourceProduct: any;
|
|
25
|
+
sourceMessageId?: string;
|
|
26
|
+
};
|
|
27
|
+
export type ChatSystemMessage = ChatResponseTextData | ChatResponseContentData | ChatResponseProductSearchResultData | ChatResponseInspirationResultData | ChatResponseProductAnswerData | ChatResponseProductComparisonData | ChatResponseProductRecommendationData | ChatResponseErrorData | ChatResponseTopicDriftData | ChatProductQueryMessageData;
|
|
28
|
+
export type ChatMessage = ChatUserMessage | ChatSystemMessage;
|
|
29
|
+
type ChatSessionStoreConfig = {
|
|
30
|
+
data?: {
|
|
31
|
+
id?: string;
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
chat?: ChatMessage[];
|
|
34
|
+
attachments?: ChatAttachmentAddAttachment[];
|
|
35
|
+
actions?: ChatActions;
|
|
36
|
+
feedbacks?: ChatFeedbacks[];
|
|
37
|
+
sessionFeedback?: ChatSessionFeedback | null;
|
|
38
|
+
feedbackDismissed?: boolean;
|
|
39
|
+
createdAt?: Date;
|
|
40
|
+
sessionEndTime?: Date;
|
|
41
|
+
committedComparisons?: any[];
|
|
42
|
+
};
|
|
43
|
+
stores: {
|
|
44
|
+
storage: StorageStore;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type ActionsData = {
|
|
48
|
+
type: 'actions';
|
|
49
|
+
data: any;
|
|
50
|
+
};
|
|
51
|
+
export type ChatActions = ActionsData[];
|
|
52
|
+
/** Snapshot of facet labels keyed by field — used to render the user message text for a productSearch request. */
|
|
53
|
+
export type FilterLabelMap = Record<string, {
|
|
54
|
+
facetLabel: string;
|
|
55
|
+
values: Record<string, string>;
|
|
56
|
+
}>;
|
|
57
|
+
export declare class ChatSessionStore {
|
|
58
|
+
chat: ChatMessage[];
|
|
59
|
+
actions: ChatActions;
|
|
60
|
+
id: string;
|
|
61
|
+
sessionId?: string;
|
|
62
|
+
attachments: ChatAttachmentStore;
|
|
63
|
+
comparisons: ChatCompareStore;
|
|
64
|
+
storage: StorageStore;
|
|
65
|
+
feedbacks: ChatFeedbacks[];
|
|
66
|
+
sessionFeedback: ChatSessionFeedback | null;
|
|
67
|
+
feedbackDismissed: boolean;
|
|
68
|
+
feedbackJustGiven: boolean;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
sessionEndTime?: Date;
|
|
71
|
+
requestType: string;
|
|
72
|
+
dismissedSideChatMessageId: string | null;
|
|
73
|
+
activeMessageId: string | null;
|
|
74
|
+
sessionLimitReached: boolean;
|
|
75
|
+
/** Whether raw stored results have been hydrated into Product/SearchResultStore instances. */
|
|
76
|
+
hydrated: boolean;
|
|
77
|
+
constructor(params: ChatSessionStoreConfig);
|
|
78
|
+
dismissSideChat(): void;
|
|
79
|
+
setActiveMessage(id: string): void;
|
|
80
|
+
pushProductQueryMessage(result: any): void;
|
|
81
|
+
popProductQueryMessage(restoreActiveMessageId?: string): void;
|
|
82
|
+
get isExpired(): boolean;
|
|
83
|
+
get topicDrift(): ChatResponseTopicDriftData | null;
|
|
84
|
+
get activeMessage(): ChatMessage | null;
|
|
85
|
+
dismissTopicDrift(): void;
|
|
86
|
+
handleTopicDrift(): string | undefined;
|
|
87
|
+
reset(): void;
|
|
88
|
+
private saveTimerId;
|
|
89
|
+
/** Persist the session to storage immediately (synchronous). */
|
|
90
|
+
saveImmediate(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Schedule a save — multiple calls within the debounce window are coalesced
|
|
93
|
+
* into a single localStorage write.
|
|
94
|
+
*/
|
|
95
|
+
save(): void;
|
|
96
|
+
/** Remove oldest stored sessions when exceeding the limit. */
|
|
97
|
+
static pruneStoredSessions(storage: StorageStore, maxSessions?: number): void;
|
|
98
|
+
/** Re-wrap raw stored results as Product / SearchResultStore instances. */
|
|
99
|
+
hydrateResults(meta: MetaResponseModel): void;
|
|
100
|
+
request(request: ChatRequestModel, filterLabels?: FilterLabelMap): void;
|
|
101
|
+
update(data: {
|
|
102
|
+
chat: ChatResponseModel;
|
|
103
|
+
meta: MetaResponseModel;
|
|
104
|
+
}): void;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=ChatSessionStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatSessionStore.d.ts","sourceRoot":"","sources":["../../../../src/Chat/Stores/ChatSessionStore.ts"],"names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