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