@telia-ace/knowledge-widget-types-grid 1.0.12 → 1.0.15
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/{lib-esm → dist}/data/data-client.d.ts +0 -0
- package/{lib-esm → dist}/data/index.d.ts +0 -0
- package/{lib-esm → dist}/data/legacy-conversion.d.ts +0 -0
- package/{lib-esm → dist}/index.d.ts +0 -0
- package/dist/index.js +686 -0
- package/dist/index.js.map +1 -0
- package/dist/index2.js +6 -0
- package/dist/index2.js.map +1 -0
- package/{lib-esm → dist}/widget/extended-widget.d.ts +0 -0
- package/{lib-esm → dist}/widget/index.d.ts +0 -0
- package/{lib-esm → dist}/widget/services.d.ts +1 -1
- package/package.json +14 -15
- package/lib/data/data-client.d.ts +0 -91
- package/lib/data/data-client.js +0 -504
- package/lib/data/index.d.ts +0 -3
- package/lib/data/index.js +0 -24
- package/lib/data/legacy-conversion.d.ts +0 -75
- package/lib/data/legacy-conversion.js +0 -308
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -25
- package/lib/widget/extended-widget.d.ts +0 -5
- package/lib/widget/extended-widget.js +0 -32
- package/lib/widget/index.d.ts +0 -1
- package/lib/widget/index.js +0 -8
- package/lib/widget/services.d.ts +0 -3
- package/lib/widget/services.js +0 -40
- package/lib-esm/data/data-client.js +0 -500
- package/lib-esm/data/index.js +0 -3
- package/lib-esm/data/legacy-conversion.js +0 -304
- package/lib-esm/index.js +0 -3
- package/lib-esm/widget/extended-widget.js +0 -30
- package/lib-esm/widget/index.js +0 -1
- package/lib-esm/widget/services.js +0 -12
package/lib/data/data-client.js
DELETED
|
@@ -1,504 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __values = (this && this.__values) || function(o) {
|
|
66
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
67
|
-
if (m) return m.call(o);
|
|
68
|
-
if (o && typeof o.length === "number") return {
|
|
69
|
-
next: function () {
|
|
70
|
-
if (o && i >= o.length) o = void 0;
|
|
71
|
-
return { value: o && o[i++], done: !o };
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
75
|
-
};
|
|
76
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
|
-
exports.determineServiceClientQueryType = exports.SortingType = exports.FeedbackType = exports.ServiceClientQueryType = exports.DataType = void 0;
|
|
78
|
-
var knowledge_widget_core_1 = require("@telia-ace/knowledge-widget-core");
|
|
79
|
-
var widget_utilities_1 = require("@telia-ace/widget-utilities");
|
|
80
|
-
var legacy_conversion_1 = require("./legacy-conversion");
|
|
81
|
-
var DataType;
|
|
82
|
-
(function (DataType) {
|
|
83
|
-
DataType["Guide"] = "guide";
|
|
84
|
-
DataType["Guides"] = "guides";
|
|
85
|
-
DataType["GuidesByCategory"] = "guides-by-category";
|
|
86
|
-
DataType["RowNotifications"] = "row-notices";
|
|
87
|
-
DataType["NotificationLists"] = "notification-lists";
|
|
88
|
-
DataType["GuideCategories"] = "guide-categories";
|
|
89
|
-
DataType["ContactMethodCategories"] = "contact-method-categories";
|
|
90
|
-
DataType["ContactMethod"] = "contact-method";
|
|
91
|
-
DataType["ContactMethods"] = "contact-methods";
|
|
92
|
-
DataType["Tags"] = "tags";
|
|
93
|
-
DataType["TagsOnGuides"] = "tagsonguides";
|
|
94
|
-
})(DataType = exports.DataType || (exports.DataType = {}));
|
|
95
|
-
var ServiceClientQueryType;
|
|
96
|
-
(function (ServiceClientQueryType) {
|
|
97
|
-
ServiceClientQueryType["Match"] = "match";
|
|
98
|
-
ServiceClientQueryType["Categories"] = "categories";
|
|
99
|
-
ServiceClientQueryType["Guide"] = "guide";
|
|
100
|
-
ServiceClientQueryType["Contacts"] = "contacts";
|
|
101
|
-
ServiceClientQueryType["ContactMethod"] = "contact-method";
|
|
102
|
-
ServiceClientQueryType["MatchByCategory"] = "match-by-category";
|
|
103
|
-
ServiceClientQueryType["Tags"] = "tags";
|
|
104
|
-
ServiceClientQueryType["TagsOnGuides"] = "tagsonguides";
|
|
105
|
-
ServiceClientQueryType["Notifications"] = "notifications";
|
|
106
|
-
})(ServiceClientQueryType = exports.ServiceClientQueryType || (exports.ServiceClientQueryType = {}));
|
|
107
|
-
var FeedbackType;
|
|
108
|
-
(function (FeedbackType) {
|
|
109
|
-
FeedbackType["Positive"] = "Positive";
|
|
110
|
-
FeedbackType["Negative"] = "Negative";
|
|
111
|
-
})(FeedbackType = exports.FeedbackType || (exports.FeedbackType = {}));
|
|
112
|
-
var SortingType;
|
|
113
|
-
(function (SortingType) {
|
|
114
|
-
SortingType["POPULARITY_DESCENDING"] = "popularity-descending";
|
|
115
|
-
SortingType["ALPHABETIC_ASCENDING"] = "alphabetic-ascending";
|
|
116
|
-
SortingType["ALPHABETIC_DESCENDING"] = "alphabetic-descending";
|
|
117
|
-
SortingType["MODIFIED_ASCENDING"] = "modified-ascending";
|
|
118
|
-
SortingType["MODIFIED_DESCENDING"] = "modified-descending";
|
|
119
|
-
SortingType["PUBLISHED_ASCENDING"] = "published-ascending";
|
|
120
|
-
SortingType["PUBLISHED_DESCENDING"] = "published-descending";
|
|
121
|
-
})(SortingType = exports.SortingType || (exports.SortingType = {}));
|
|
122
|
-
var determineServiceClientQueryType = function (type) {
|
|
123
|
-
switch (type) {
|
|
124
|
-
case DataType.Guides:
|
|
125
|
-
return ServiceClientQueryType.Match;
|
|
126
|
-
case DataType.GuidesByCategory:
|
|
127
|
-
return ServiceClientQueryType.MatchByCategory;
|
|
128
|
-
case DataType.Guide:
|
|
129
|
-
return ServiceClientQueryType.Guide;
|
|
130
|
-
case DataType.GuideCategories:
|
|
131
|
-
return ServiceClientQueryType.Categories;
|
|
132
|
-
case DataType.ContactMethodCategories:
|
|
133
|
-
case DataType.ContactMethods:
|
|
134
|
-
return ServiceClientQueryType.Contacts;
|
|
135
|
-
case DataType.ContactMethod:
|
|
136
|
-
return ServiceClientQueryType.ContactMethod;
|
|
137
|
-
case DataType.Tags:
|
|
138
|
-
return ServiceClientQueryType.Tags;
|
|
139
|
-
case DataType.TagsOnGuides:
|
|
140
|
-
return ServiceClientQueryType.TagsOnGuides;
|
|
141
|
-
case DataType.NotificationLists:
|
|
142
|
-
case DataType.RowNotifications:
|
|
143
|
-
return ServiceClientQueryType.Notifications;
|
|
144
|
-
default:
|
|
145
|
-
throw 'error';
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
exports.determineServiceClientQueryType = determineServiceClientQueryType;
|
|
149
|
-
var widgetIsHidden = function (container) { return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
-
var invoke, renderState;
|
|
151
|
-
return __generator(this, function (_a) {
|
|
152
|
-
switch (_a.label) {
|
|
153
|
-
case 0:
|
|
154
|
-
invoke = container.get('$widget').invoke;
|
|
155
|
-
return [4 /*yield*/, invoke('renderState')];
|
|
156
|
-
case 1:
|
|
157
|
-
renderState = _a.sent();
|
|
158
|
-
return [2 /*return*/, renderState === knowledge_widget_core_1.WidgetRenderState.hidden];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}); };
|
|
162
|
-
var DataClient = /** @class */ (function () {
|
|
163
|
-
function DataClient(container, matchingClient) {
|
|
164
|
-
var _this = this;
|
|
165
|
-
this.container = container;
|
|
166
|
-
this.matchingClient = matchingClient;
|
|
167
|
-
this.queries = new Map();
|
|
168
|
-
this.lastTake = 0;
|
|
169
|
-
this.getUnresolvedQueries = function () {
|
|
170
|
-
var unresolvedCount = 0;
|
|
171
|
-
_this.queries.forEach(function (queries, type) {
|
|
172
|
-
var hasUnresolved = queries.some(function (query) { return !query.resolved; });
|
|
173
|
-
if (hasUnresolved) {
|
|
174
|
-
unresolvedCount = +1;
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
return unresolvedCount;
|
|
178
|
-
};
|
|
179
|
-
this.events = container.get('$widget').events;
|
|
180
|
-
this.events.subscribe('widget:settings-updated', function () { return (_this.queries = new Map()); });
|
|
181
|
-
this.events.subscribe('widget:render-state-changed', function (event, _a) {
|
|
182
|
-
var next = _a.next, previous = _a.previous;
|
|
183
|
-
if (previous === knowledge_widget_core_1.WidgetRenderState.hidden && next === knowledge_widget_core_1.WidgetRenderState.open) {
|
|
184
|
-
_this.fetchAllUnresolvedQueries();
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
DataClient.getInstance = function (container) {
|
|
189
|
-
return container.getAsync('dataClient');
|
|
190
|
-
};
|
|
191
|
-
DataClient.prototype.fetch = function (type, params) {
|
|
192
|
-
var _this = this;
|
|
193
|
-
return new Promise(function (resolve, reject) {
|
|
194
|
-
if (params.take) {
|
|
195
|
-
_this.lastTake = +(params.take || 0);
|
|
196
|
-
}
|
|
197
|
-
(0, widget_utilities_1.removeNullAndUndefinedValues)(params);
|
|
198
|
-
var serviceClientQueryType = (0, exports.determineServiceClientQueryType)(type);
|
|
199
|
-
var queries = _this.queries.get(serviceClientQueryType) || [];
|
|
200
|
-
var query = queries.find(function (q) { return (0, widget_utilities_1.shallowCompare)(q.params, params); });
|
|
201
|
-
if (query) {
|
|
202
|
-
var index = queries.indexOf(query);
|
|
203
|
-
if (query.resolved) {
|
|
204
|
-
_this.events.dispatch('data-client:fetched', {
|
|
205
|
-
params: params,
|
|
206
|
-
type: serviceClientQueryType,
|
|
207
|
-
response: query.data,
|
|
208
|
-
unresolvedQueries: _this.getUnresolvedQueries(),
|
|
209
|
-
});
|
|
210
|
-
_this.track(query.data, serviceClientQueryType, query.error);
|
|
211
|
-
if (query.data && query.error) {
|
|
212
|
-
reject({ error: query.error });
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
resolve(query.data);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
query.resolvers.push({ resolve: resolve, reject: reject });
|
|
220
|
-
}
|
|
221
|
-
queries.splice(index, 1);
|
|
222
|
-
queries.push(query);
|
|
223
|
-
_this.queries.set(serviceClientQueryType, queries);
|
|
224
|
-
if (!query.loading && !query.resolved) {
|
|
225
|
-
return _this.runQuery(serviceClientQueryType, params);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
queries.push({
|
|
230
|
-
params: params,
|
|
231
|
-
resolved: false,
|
|
232
|
-
loading: true,
|
|
233
|
-
data: {},
|
|
234
|
-
resolvers: [{ resolve: resolve, reject: reject }],
|
|
235
|
-
});
|
|
236
|
-
_this.queries.set(serviceClientQueryType, queries);
|
|
237
|
-
return _this.runQuery(serviceClientQueryType, params);
|
|
238
|
-
}
|
|
239
|
-
}).then(function (res) { return (0, widget_utilities_1.deepClone)(res); });
|
|
240
|
-
};
|
|
241
|
-
// query the cached data
|
|
242
|
-
DataClient.prototype.read = function (type, options) {
|
|
243
|
-
var select = options.select;
|
|
244
|
-
var serviceClientQueryType = (0, exports.determineServiceClientQueryType)(type);
|
|
245
|
-
var queries = this.queries.get(serviceClientQueryType) || [];
|
|
246
|
-
var result = queries.reduce(function (acc, query) {
|
|
247
|
-
if (typeof select === 'function') {
|
|
248
|
-
var match = select(query.data);
|
|
249
|
-
if (match) {
|
|
250
|
-
acc.push(match);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
acc.push(query.data);
|
|
255
|
-
}
|
|
256
|
-
return acc;
|
|
257
|
-
}, []);
|
|
258
|
-
return result;
|
|
259
|
-
};
|
|
260
|
-
DataClient.prototype.feedback = function (id, connection, feedback) {
|
|
261
|
-
return this.matchingClient.giveFeedback(id, connection, feedback);
|
|
262
|
-
};
|
|
263
|
-
DataClient.prototype.setLoadingStatus = function (type, params, loading) {
|
|
264
|
-
var queries = this.queries.get(type) || [];
|
|
265
|
-
var query = queries.find(function (q) { return (0, widget_utilities_1.shallowCompare)(q.params, params); });
|
|
266
|
-
if (query) {
|
|
267
|
-
query.loading = loading;
|
|
268
|
-
}
|
|
269
|
-
this.queries.set(type, queries);
|
|
270
|
-
};
|
|
271
|
-
DataClient.prototype.runQuery = function (type, params) {
|
|
272
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
-
var _a, searchPhrase, _b, categories, _c, contactMethodCategoryId, _d, contactMethodId, _e, tagId, _f, take, _g, connection, guideId, _h, expandCategories, currentCategory, _j, sorting, _k, guideIds, trimmedPhrase, formatSortingValues;
|
|
274
|
-
var _this = this;
|
|
275
|
-
return __generator(this, function (_l) {
|
|
276
|
-
switch (_l.label) {
|
|
277
|
-
case 0:
|
|
278
|
-
_a = params.searchPhrase, searchPhrase = _a === void 0 ? '' : _a, _b = params.categories, categories = _b === void 0 ? '0' : _b, _c = params.contactMethodCategoryId, contactMethodCategoryId = _c === void 0 ? '0' : _c, _d = params.contactMethodId, contactMethodId = _d === void 0 ? '0' : _d, _e = params.tagId, tagId = _e === void 0 ? undefined : _e, _f = params.take, take = _f === void 0 ? 5 : _f, _g = params.connection, connection = _g === void 0 ? '' : _g, guideId = params.guideId, _h = params.expandCategories, expandCategories = _h === void 0 ? 'descendants' : _h, currentCategory = params.currentCategory, _j = params.sorting, sorting = _j === void 0 ? SortingType.POPULARITY_DESCENDING : _j, _k = params.guideIds, guideIds = _k === void 0 ? [] : _k;
|
|
279
|
-
trimmedPhrase = searchPhrase.toString().trim();
|
|
280
|
-
return [4 /*yield*/, widgetIsHidden(this.container)];
|
|
281
|
-
case 1:
|
|
282
|
-
if (_l.sent()) {
|
|
283
|
-
return [2 /*return*/, Promise.resolve()];
|
|
284
|
-
}
|
|
285
|
-
switch (type) {
|
|
286
|
-
case ServiceClientQueryType.Match: {
|
|
287
|
-
formatSortingValues = function (sorting) {
|
|
288
|
-
var _a = __read(sorting.split('-'), 2), type = _a[0], direction = _a[1];
|
|
289
|
-
var sortKeysMap = new Map([
|
|
290
|
-
['popularity', 'popularity'],
|
|
291
|
-
['alphabetic', 'title'],
|
|
292
|
-
['modified', 'lastModified'],
|
|
293
|
-
['published', 'firstPublished'],
|
|
294
|
-
]);
|
|
295
|
-
return {
|
|
296
|
-
type: sortKeysMap.get(type),
|
|
297
|
-
direction: direction,
|
|
298
|
-
};
|
|
299
|
-
};
|
|
300
|
-
if (guideIds.length) {
|
|
301
|
-
return [2 /*return*/, this.matchingClient
|
|
302
|
-
.customRequest('guides', 'POST', {
|
|
303
|
-
configuration: { ids: guideIds, take: +take },
|
|
304
|
-
})
|
|
305
|
-
.then(function (matches) { return matches && _this.handleResponse(matches, type, params); })];
|
|
306
|
-
}
|
|
307
|
-
return [2 /*return*/, this.matchingClient
|
|
308
|
-
.match(trimmedPhrase, {
|
|
309
|
-
categories: categories === '0'
|
|
310
|
-
? []
|
|
311
|
-
: Array.isArray(categories)
|
|
312
|
-
? categories
|
|
313
|
-
: [+categories],
|
|
314
|
-
take: +take,
|
|
315
|
-
tags: tagId,
|
|
316
|
-
sorting: formatSortingValues(sorting),
|
|
317
|
-
ids: guideIds,
|
|
318
|
-
})
|
|
319
|
-
.then(function (matches) { return matches && _this.handleResponse(matches, type, params); })];
|
|
320
|
-
}
|
|
321
|
-
case ServiceClientQueryType.MatchByCategory: {
|
|
322
|
-
return [2 /*return*/, this.matchingClient
|
|
323
|
-
.match(trimmedPhrase, {
|
|
324
|
-
groupByCategory: true,
|
|
325
|
-
categories: categories === '0'
|
|
326
|
-
? []
|
|
327
|
-
: Array.isArray(categories)
|
|
328
|
-
? categories
|
|
329
|
-
: [+categories],
|
|
330
|
-
take: +take,
|
|
331
|
-
tags: tagId,
|
|
332
|
-
})
|
|
333
|
-
.then(function (matches) { return matches && _this.handleResponse(matches, type, params); })];
|
|
334
|
-
}
|
|
335
|
-
case ServiceClientQueryType.Guide: {
|
|
336
|
-
return [2 /*return*/, this.matchingClient
|
|
337
|
-
.getGuide(guideId, { connectionId: connection })
|
|
338
|
-
.then(function (guide) {
|
|
339
|
-
if (guide) {
|
|
340
|
-
_this.handleResponse(guide, type, params);
|
|
341
|
-
}
|
|
342
|
-
})
|
|
343
|
-
.catch(function (e) {
|
|
344
|
-
var error = {
|
|
345
|
-
message: 'Something went wrong.',
|
|
346
|
-
status: e.status || 400,
|
|
347
|
-
};
|
|
348
|
-
if (error.status === 404) {
|
|
349
|
-
error.message = 'The guide could not be found.';
|
|
350
|
-
}
|
|
351
|
-
_this.handleResponse({}, type, params, error);
|
|
352
|
-
})];
|
|
353
|
-
}
|
|
354
|
-
case ServiceClientQueryType.Categories: {
|
|
355
|
-
return [2 /*return*/, this.matchingClient
|
|
356
|
-
.getCategories({ phrase: trimmedPhrase, expand: expandCategories, tags: tagId })
|
|
357
|
-
.then(function (categories) { return categories && _this.handleResponse(categories, type, params); })];
|
|
358
|
-
}
|
|
359
|
-
case ServiceClientQueryType.Contacts: {
|
|
360
|
-
if (guideId) {
|
|
361
|
-
return [2 /*return*/, this.matchingClient
|
|
362
|
-
.contactMethods(+guideId, { phrase: trimmedPhrase })
|
|
363
|
-
.then(function (result) { return result && _this.handleResponse(result, type, params); })];
|
|
364
|
-
}
|
|
365
|
-
return [2 /*return*/, this.matchingClient
|
|
366
|
-
.contacts(+contactMethodCategoryId, { phrase: trimmedPhrase })
|
|
367
|
-
.then(function (result) { return result && _this.handleResponse(result, type, params); })];
|
|
368
|
-
}
|
|
369
|
-
case ServiceClientQueryType.ContactMethod: {
|
|
370
|
-
return [2 /*return*/, this.matchingClient
|
|
371
|
-
.getContactMethod(+contactMethodId, { guideId: guideId, currentCategory: currentCategory })
|
|
372
|
-
.then(function (result) { return result && _this.handleResponse(result, type, params); })];
|
|
373
|
-
}
|
|
374
|
-
case ServiceClientQueryType.Tags: {
|
|
375
|
-
return [2 /*return*/, this.matchingClient
|
|
376
|
-
.customRequest('tags', 'GET', {
|
|
377
|
-
configuration: {
|
|
378
|
-
take: 999999,
|
|
379
|
-
phrase: trimmedPhrase,
|
|
380
|
-
categories: categories === '0'
|
|
381
|
-
? []
|
|
382
|
-
: Array.isArray(categories)
|
|
383
|
-
? categories
|
|
384
|
-
: [+categories],
|
|
385
|
-
},
|
|
386
|
-
})
|
|
387
|
-
.then(function (result) { return result && _this.handleResponse(result, type, params); })];
|
|
388
|
-
}
|
|
389
|
-
case ServiceClientQueryType.TagsOnGuides: {
|
|
390
|
-
return [2 /*return*/, this.matchingClient
|
|
391
|
-
.customRequest('tagsonguides', 'GET', {
|
|
392
|
-
configuration: {
|
|
393
|
-
take: 999999,
|
|
394
|
-
phrase: trimmedPhrase,
|
|
395
|
-
categories: categories === '0'
|
|
396
|
-
? []
|
|
397
|
-
: Array.isArray(categories)
|
|
398
|
-
? categories
|
|
399
|
-
: [+categories],
|
|
400
|
-
tags: tagId,
|
|
401
|
-
},
|
|
402
|
-
})
|
|
403
|
-
.then(function (result) { return result && _this.handleResponse(result, type, params); })];
|
|
404
|
-
}
|
|
405
|
-
case ServiceClientQueryType.Notifications: {
|
|
406
|
-
return [2 /*return*/, this.matchingClient
|
|
407
|
-
.customRequest('notices', 'GET', {
|
|
408
|
-
configuration: {
|
|
409
|
-
phrase: trimmedPhrase,
|
|
410
|
-
categories: categories === '0'
|
|
411
|
-
? []
|
|
412
|
-
: Array.isArray(categories)
|
|
413
|
-
? categories
|
|
414
|
-
: [+categories],
|
|
415
|
-
},
|
|
416
|
-
})
|
|
417
|
-
.then(function (result) { return result && _this.handleResponse(result, type, params); })];
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
return [2 /*return*/];
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
};
|
|
425
|
-
DataClient.prototype.handleResponse = function (data, type, params, error) {
|
|
426
|
-
if (data === void 0) { data = {}; }
|
|
427
|
-
var queries = this.queries.get(type) || [];
|
|
428
|
-
var existing = queries.find(function (q) { return (0, widget_utilities_1.shallowCompare)(q.params, params); });
|
|
429
|
-
if (existing) {
|
|
430
|
-
var formatted_1 = error ? error : (0, legacy_conversion_1.formatLegacyData)(type, data);
|
|
431
|
-
this.track(formatted_1, type, error);
|
|
432
|
-
existing.resolvers.forEach(function (r) {
|
|
433
|
-
if (error) {
|
|
434
|
-
r.reject({ error: formatted_1 });
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
r.resolve(formatted_1);
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
var index = queries.indexOf(existing);
|
|
441
|
-
if (index > -1) {
|
|
442
|
-
queries.splice(index, 1);
|
|
443
|
-
}
|
|
444
|
-
queries.push(__assign(__assign({}, existing), { error: error, resolvers: [], data: formatted_1, resolved: true }));
|
|
445
|
-
this.setLoadingStatus(type, params, false);
|
|
446
|
-
this.queries.set(type, queries);
|
|
447
|
-
if (!error) {
|
|
448
|
-
this.events.dispatch('data-client:fetched', {
|
|
449
|
-
type: type,
|
|
450
|
-
params: params,
|
|
451
|
-
response: formatted_1,
|
|
452
|
-
unresolvedQueries: this.getUnresolvedQueries(),
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
DataClient.prototype.fetchAllUnresolvedQueries = function () {
|
|
458
|
-
var e_1, _a;
|
|
459
|
-
var _this = this;
|
|
460
|
-
var _loop_1 = function (queryType, queries) {
|
|
461
|
-
queries
|
|
462
|
-
.filter(function (query) { return !query.resolved; })
|
|
463
|
-
.forEach(function (query) {
|
|
464
|
-
_this.runQuery(queryType, query.params);
|
|
465
|
-
});
|
|
466
|
-
};
|
|
467
|
-
try {
|
|
468
|
-
for (var _b = __values(this.queries), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
469
|
-
var _d = __read(_c.value, 2), queryType = _d[0], queries = _d[1];
|
|
470
|
-
_loop_1(queryType, queries);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
474
|
-
finally {
|
|
475
|
-
try {
|
|
476
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
477
|
-
}
|
|
478
|
-
finally { if (e_1) throw e_1.error; }
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
DataClient.prototype.track = function (data, type, error) {
|
|
482
|
-
if (data === void 0) { data = {}; }
|
|
483
|
-
var widget = this.container.get('$widget');
|
|
484
|
-
if (widget && !error) {
|
|
485
|
-
widget.events.dispatch('tracking:service-client-response', {
|
|
486
|
-
type: type,
|
|
487
|
-
data: data,
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
else if (widget) {
|
|
491
|
-
widget.events.dispatch('tracking:service-client-error', {
|
|
492
|
-
type: type,
|
|
493
|
-
error: error,
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
DataClient.create = function (container) {
|
|
498
|
-
return container
|
|
499
|
-
.getAsync('matchingClient')
|
|
500
|
-
.then(function (matchingClient) { return new DataClient(container, matchingClient); });
|
|
501
|
-
};
|
|
502
|
-
return DataClient;
|
|
503
|
-
}());
|
|
504
|
-
exports.default = DataClient;
|
package/lib/data/index.d.ts
DELETED
package/lib/data/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DataClient = void 0;
|
|
21
|
-
__exportStar(require("./data-client"), exports);
|
|
22
|
-
var data_client_1 = require("./data-client");
|
|
23
|
-
Object.defineProperty(exports, "DataClient", { enumerable: true, get: function () { return __importDefault(data_client_1).default; } });
|
|
24
|
-
__exportStar(require("./legacy-conversion"), exports);
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ContactMethodType as ContactMethod } from '@telia-ace/knowledge-widget-adapters';
|
|
2
|
-
import { Category, DialogItem, Guide, Notification, NotificationList, Tag } from '@telia-ace/knowledge-widget-core';
|
|
3
|
-
import { DataError, ServiceClientQueryType } from './data-client';
|
|
4
|
-
export declare type MatchResult = {
|
|
5
|
-
guides: Guide[];
|
|
6
|
-
matches: number;
|
|
7
|
-
topNotifications: Notification[];
|
|
8
|
-
middleNotifications: Notification[];
|
|
9
|
-
bottomNotifications: Notification[];
|
|
10
|
-
notificationLists: NotificationList[];
|
|
11
|
-
tags: Tag[];
|
|
12
|
-
byCategory: {
|
|
13
|
-
id: string;
|
|
14
|
-
guides: Guide[];
|
|
15
|
-
matches: number;
|
|
16
|
-
}[];
|
|
17
|
-
};
|
|
18
|
-
export declare type TagsResult = Tag[];
|
|
19
|
-
export declare type CategoriesResult = {
|
|
20
|
-
categories: Category[];
|
|
21
|
-
matches: number;
|
|
22
|
-
};
|
|
23
|
-
export declare type NotificationResults = Pick<MatchResult, 'topNotifications' | 'middleNotifications' | 'bottomNotifications' | 'notificationLists'>;
|
|
24
|
-
export declare type GuideResult = {
|
|
25
|
-
guide: {
|
|
26
|
-
id: string;
|
|
27
|
-
title: string;
|
|
28
|
-
body: string;
|
|
29
|
-
modified: string;
|
|
30
|
-
modifiedBy: string | null;
|
|
31
|
-
publishedBy: string | null;
|
|
32
|
-
published: string;
|
|
33
|
-
connection: string;
|
|
34
|
-
categories: number[];
|
|
35
|
-
hasHandover: boolean;
|
|
36
|
-
allowFeedback: boolean;
|
|
37
|
-
seoMetaDescription: string | null;
|
|
38
|
-
seoAllowIndex: boolean | null;
|
|
39
|
-
perspective: string | null;
|
|
40
|
-
perspectives: {
|
|
41
|
-
[key: string]: string;
|
|
42
|
-
};
|
|
43
|
-
translations?: {
|
|
44
|
-
[key: string]: string;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
related: Guide[];
|
|
48
|
-
dialog: DialogItem[];
|
|
49
|
-
contactMethods: ContactMethod[];
|
|
50
|
-
tags: Tag[];
|
|
51
|
-
error?: DataError;
|
|
52
|
-
};
|
|
53
|
-
export declare type ContactsResult = {
|
|
54
|
-
categories: Category[];
|
|
55
|
-
contactMethods: ContactMethod[];
|
|
56
|
-
topNotifications: Notification[];
|
|
57
|
-
middleNotifications: Notification[];
|
|
58
|
-
bottomNotifications: Notification[];
|
|
59
|
-
notificationLists: NotificationList[];
|
|
60
|
-
};
|
|
61
|
-
export declare type SubmissionResult = {
|
|
62
|
-
contactMethod?: ContactMethod;
|
|
63
|
-
valid: boolean;
|
|
64
|
-
};
|
|
65
|
-
export declare const formatLegacyData: (type: ServiceClientQueryType, data: any) => Tag[] | MatchResult | CategoriesResult | ContactMethod | GuideResult | ContactsResult | {
|
|
66
|
-
topNotifications: Notification[];
|
|
67
|
-
middleNotifications: Notification[];
|
|
68
|
-
bottomNotifications: Notification[];
|
|
69
|
-
notificationLists: NotificationList[];
|
|
70
|
-
} | {
|
|
71
|
-
topNotifications?: undefined;
|
|
72
|
-
middleNotifications?: undefined;
|
|
73
|
-
bottomNotifications?: undefined;
|
|
74
|
-
notificationLists?: undefined;
|
|
75
|
-
};
|