@partium/js-sdk 14.4.1 → 14.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/catalog/index.js +1 -21
  2. package/catalog/models/catalog-image-info.js +1 -22
  3. package/catalog/models/catalog-image.js +1 -40
  4. package/catalog/models/upsert-catalog-images-dto.js +1 -3
  5. package/catalog/models/upsert-images-result.js +1 -3
  6. package/catalog/services/images.service.js +1 -62
  7. package/core/constants/constants.d.ts +1 -0
  8. package/core/constants/constants.js +1 -16
  9. package/core/decorators/injection-identifier.js +1 -19
  10. package/core/factories/paginated-request-service.factory.js +1 -33
  11. package/core/index.js +1 -63
  12. package/core/integration-defaults/http/fetch-api-http-error-helper.js +1 -129
  13. package/core/integration-defaults/http/file-transfer/axios-file-transfer.service.js +1 -138
  14. package/core/integration-defaults/http/file-transfer/fetch-api-file-transfer.service.js +1 -210
  15. package/core/integration-defaults/http/handle-axios-error-helper.js +1 -79
  16. package/core/integration-defaults/http/https-client/axios-https-client.service.js +1 -182
  17. package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +1 -198
  18. package/core/integration-defaults/http/js-oauth-keycloak-https.service.js +1 -32
  19. package/core/integration-defaults/js-p-file.js +1 -36
  20. package/core/integration-defaults/session/js-oauth-api-key-session.service.js +1 -206
  21. package/core/integration-defaults/session/js-oauth-keycloak-auth-config.js +1 -64
  22. package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +1 -257
  23. package/core/integration-defaults/web-device-status.service.js +1 -125
  24. package/core/integration-defaults/web-file.service.js +1 -135
  25. package/core/integration-defaults/web-indexeddb.service.js +1 -142
  26. package/core/integration-defaults/web-local-storage.service.js +1 -310
  27. package/core/models/api-object.js +1 -16
  28. package/core/models/auth-config.js +1 -72
  29. package/core/models/device-info.js +1 -34
  30. package/core/models/error.js +1 -107
  31. package/core/models/formatted-string.js +1 -14
  32. package/core/models/i18n-map.js +1 -61
  33. package/core/models/i18n-string.js +1 -35
  34. package/core/models/log.js +1 -137
  35. package/core/models/organization.js +1 -159
  36. package/core/models/p-file.js +1 -23
  37. package/core/models/paginated-list.js +1 -41
  38. package/core/models/partium-config.js +1 -43
  39. package/core/models/user-token.js +1 -11
  40. package/core/models/user.js +1 -89
  41. package/core/services/backend-status.service.js +1 -147
  42. package/core/services/base-login-init.service.js +1 -57
  43. package/core/services/base.service.js +1 -37
  44. package/core/services/device-status.service.interface.js +1 -117
  45. package/core/services/file.service.interface.js +1 -61
  46. package/core/services/http/file-transfer/file-transfer.service.interface.js +1 -125
  47. package/core/services/http/https-client/https-client.service.interface.js +1 -152
  48. package/core/services/http/https.service.interface.d.ts +3 -1
  49. package/core/services/http/https.service.interface.js +1 -294
  50. package/core/services/http/oauth-https.service.js +1 -218
  51. package/core/services/local-storage.service.interface.js +1 -378
  52. package/core/services/log.service.js +1 -139
  53. package/core/services/organization.service.js +1 -202
  54. package/core/services/paginated-request.service.js +1 -154
  55. package/core/services/recent-parts.service.js +1 -194
  56. package/core/services/service-provider.js +1 -114
  57. package/core/services/session/oauth-session.service.js +1 -104
  58. package/core/services/session/session.service.interface.js +1 -367
  59. package/core/utils/general-helper.js +1 -110
  60. package/data/index.js +1 -44
  61. package/data/models/announcement.js +1 -70
  62. package/data/models/assembly-hierarchy-node-breadcrumb.js +1 -51
  63. package/data/models/assembly-hierarchy-node.js +1 -46
  64. package/data/models/attribute.js +1 -106
  65. package/data/models/csa-request-search.js +1 -46
  66. package/data/models/csa-request-status.js +1 -51
  67. package/data/models/csa-request.js +1 -112
  68. package/data/models/document.js +1 -17
  69. package/data/models/filter-key.js +1 -36
  70. package/data/models/filter-option-value.js +1 -41
  71. package/data/models/image.js +1 -77
  72. package/data/models/inquiry.js +1 -71
  73. package/data/models/mounting-location.js +1 -58
  74. package/data/models/multiple-expert-searches.js +1 -40
  75. package/data/models/part-enrichment-data.js +1 -50
  76. package/data/models/part.d.ts +1 -1
  77. package/data/models/part.js +1 -168
  78. package/data/models/shopping-cart.js +1 -60
  79. package/data/services/announcement.service.js +1 -89
  80. package/data/services/assembly-hierarchy-nodes.service.js +1 -193
  81. package/data/services/csa-helper.service.js +1 -158
  82. package/data/services/customer-service-assistance.service.js +1 -276
  83. package/data/services/filter.service.js +1 -97
  84. package/data/services/inquiry.service.js +1 -68
  85. package/data/services/part-attribute.service.js +1 -118
  86. package/data/services/part-enrichment.service.js +1 -56
  87. package/data/services/part.service.js +1 -182
  88. package/data/services/related-parts.service.js +1 -83
  89. package/data/services/shopping-cart.service.js +1 -152
  90. package/datacuration/index.d.ts +2 -0
  91. package/datacuration/index.js +2 -0
  92. package/datacuration/models/image-submission-request.d.ts +55 -0
  93. package/datacuration/models/image-submission-request.js +2 -0
  94. package/datacuration/models/submitted-image-response.d.ts +27 -0
  95. package/datacuration/models/submitted-image-response.js +2 -0
  96. package/datacuration/services/image-submission.service.d.ts +26 -0
  97. package/datacuration/services/image-submission.service.js +2 -0
  98. package/find/index.js +1 -51
  99. package/find/models/assets/asset.js +1 -32
  100. package/find/models/search-filter.js +1 -205
  101. package/find/models/search-input.js +1 -3
  102. package/find/models/search-output.js +1 -3
  103. package/find/models/search-result-status.js +1 -40
  104. package/find/models/search-session-log-object.js +1 -22
  105. package/find/models/search-status/cv-search-status.js +1 -22
  106. package/find/models/search-status/search-filter-status.js +1 -36
  107. package/find/models/search-status/search-status.js +1 -56
  108. package/find/models/search-status/tag-search-status.js +1 -23
  109. package/find/models/search-status/text-search-status.js +1 -18
  110. package/find/models/search-tag.js +1 -16
  111. package/find/models/smart-filter.js +1 -49
  112. package/find/models/tagable/i18n-tagable.js +1 -37
  113. package/find/models/tagable/tagable-base.js +1 -22
  114. package/find/models/tagable/tagable.js +1 -37
  115. package/find/models/text-search-config.js +1 -70
  116. package/find/models/text-search-manipulator.js +1 -90
  117. package/find/models/text-search-result-item/text-search-error.js +1 -12
  118. package/find/models/text-search-result-item/text-search-result-item-document.js +1 -34
  119. package/find/models/text-search-result-item/text-search-result-item-part.js +1 -36
  120. package/find/models/text-search-result-item/text-search-result-item-recent-query.js +1 -35
  121. package/find/models/text-search-result-item/text-search-result-item-unknown.js +1 -38
  122. package/find/models/text-search-result-item/text-search-result-item.js +1 -22
  123. package/find/services/asset.service.js +1 -348
  124. package/find/services/filter-uploaders/filter-uploader.js +1 -3
  125. package/find/services/filter-uploaders/update-filters-uploader.js +1 -77
  126. package/find/services/filter-uploaders/update-filters.model.js +1 -7
  127. package/find/services/search/cv-search.service.js +1 -214
  128. package/find/services/search/recent-text-search-queries.service.js +1 -260
  129. package/find/services/search/search-result.service.js +1 -539
  130. package/find/services/search/search.service.js +1 -514
  131. package/find/services/search/tag-search.service.js +1 -124
  132. package/find/services/search/text-search.service.js +1 -316
  133. package/find/services/search-filter.service.js +1 -292
  134. package/find/utils/search-helper.js +1 -75
  135. package/gen/sdk-version.d.ts +1 -1
  136. package/gen/sdk-version.js +1 -5
  137. package/index.d.ts +2 -0
  138. package/index.js +1 -392
  139. package/management/index.js +1 -21
  140. package/management/models/api-key-list-response.js +1 -3
  141. package/management/models/api-key-type.js +1 -9
  142. package/management/models/api-key.js +1 -3
  143. package/management/services/api-key.service.js +1 -53
  144. package/ocr/index.js +1 -20
  145. package/ocr/models/detect-response.js +1 -3
  146. package/ocr/models/detected-text-entry.js +1 -3
  147. package/ocr/services/ocr.service.js +1 -59
  148. package/package.json +1 -1
  149. package/user-data/index.js +1 -21
  150. package/user-data/models/part-with-nullable.js +1 -3
  151. package/user-data/models/request-list/request-list.js +1 -63
  152. package/user-data/services/favorite/favorite.service.js +1 -108
  153. package/user-data/services/request-list/request-list.service.js +1 -133
@@ -1,515 +1,2 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
2
- "use strict";
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
- var __assign = (this && this.__assign) || function () {
19
- __assign = Object.assign || function(t) {
20
- for (var s, i = 1, n = arguments.length; i < n; i++) {
21
- s = arguments[i];
22
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
23
- t[p] = s[p];
24
- }
25
- return t;
26
- };
27
- return __assign.apply(this, arguments);
28
- };
29
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
30
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
32
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33
- return c > 3 && r && Object.defineProperty(target, key, r), r;
34
- };
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __generator = (this && this.__generator) || function (thisArg, body) {
45
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
46
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
- function verb(n) { return function (v) { return step([n, v]); }; }
48
- function step(op) {
49
- if (f) throw new TypeError("Generator is already executing.");
50
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
- 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;
52
- if (y = 0, t) op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0: case 1: t = op; break;
55
- case 4: _.label++; return { value: op[1], done: false };
56
- case 5: _.label++; y = op[1]; op = [0]; continue;
57
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
- default:
59
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
- if (t[2]) _.ops.pop();
64
- _.trys.pop(); continue;
65
- }
66
- op = body.call(thisArg, _);
67
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
- }
70
- };
71
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
73
- if (ar || !(i in from)) {
74
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
75
- ar[i] = from[i];
76
- }
77
- }
78
- return to.concat(ar || Array.prototype.slice.call(from));
79
- };
80
- Object.defineProperty(exports, "__esModule", { value: true });
81
- exports.SearchServiceImpl = void 0;
82
- var text_search_service_1 = require("./text-search.service");
83
- var cv_search_service_1 = require("./cv-search.service");
84
- var rxjs_1 = require("rxjs");
85
- var operators_1 = require("rxjs/operators");
86
- var search_status_1 = require("../../models/search-status/search-status");
87
- var search_filter_1 = require("../../models/search-filter");
88
- var search_filter_service_1 = require("../search-filter.service");
89
- var search_result_service_1 = require("./search-result.service");
90
- var tag_search_service_1 = require("./tag-search.service");
91
- var search_result_status_1 = require("../../models/search-result-status");
92
- var sdk_version_1 = require("../../../gen/sdk-version");
93
- var part_1 = require("../../../data/models/part");
94
- var injection_identifier_1 = require("../../../core/decorators/injection-identifier");
95
- var https_service_interface_1 = require("../../../core/services/http/https.service.interface");
96
- var log_service_1 = require("../../../core/services/log.service");
97
- var device_status_service_interface_1 = require("../../../core/services/device-status.service.interface");
98
- var log_1 = require("../../../core/models/log");
99
- var recent_text_search_queries_service_1 = require("./recent-text-search-queries.service");
100
- var smart_filter_1 = require("../../models/smart-filter");
101
- var core_1 = require("../../../core");
102
- var cv_search_status_1 = require("../../models/search-status/cv-search-status");
103
- var asset_service_1 = require("../asset.service");
104
- var asset_1 = require("../../models/assets/asset");
105
- var text_search_status_1 = require("../../models/search-status/text-search-status");
106
- var search_filter_status_1 = require("../../models/search-status/search-filter-status");
107
- var tag_search_status_1 = require("../../models/search-status/tag-search-status");
108
- var SearchServiceImpl = /** @class */ (function (_super) {
109
- __extends(SearchServiceImpl, _super);
110
- function SearchServiceImpl(serviceProvider) {
111
- var _this = _super.call(this, serviceProvider) || this;
112
- _this.searchSessionID$ = new rxjs_1.BehaviorSubject(undefined);
113
- return _this;
114
- }
115
- SearchServiceImpl.prototype.onCreate = function () {
116
- this.httpsService = this.serviceProvider.getService(https_service_interface_1.HttpsService);
117
- this.searchResultService = this.serviceProvider.getService(search_result_service_1.SearchResultService);
118
- this.logService = this.serviceProvider.getService(log_service_1.LogServiceImpl);
119
- this.deviceStatusService = this.serviceProvider.getService(device_status_service_interface_1.DeviceStatusService);
120
- this.organizationService = this.serviceProvider.getService(core_1.OrganizationService);
121
- this.assetService = this.serviceProvider.getService(asset_service_1.AssetServiceImpl);
122
- };
123
- /**
124
- * Initializes the SearchService
125
- */
126
- SearchServiceImpl.prototype.init = function (config, userEmail, currentOrganization$) {
127
- _super.prototype.init.call(this, config, userEmail, currentOrganization$);
128
- return (0, rxjs_1.of)(undefined); // resolve
129
- };
130
- Object.defineProperty(SearchServiceImpl.prototype, "text", {
131
- get: function () {
132
- return this.serviceProvider.getService(text_search_service_1.TextSearchServiceImpl);
133
- },
134
- enumerable: false,
135
- configurable: true
136
- });
137
- Object.defineProperty(SearchServiceImpl.prototype, "cv", {
138
- get: function () {
139
- return this.serviceProvider.getService(cv_search_service_1.CvSearchServiceImpl);
140
- },
141
- enumerable: false,
142
- configurable: true
143
- });
144
- Object.defineProperty(SearchServiceImpl.prototype, "filter", {
145
- get: function () {
146
- return this.serviceProvider.getService(search_filter_service_1.SearchFilterServiceImpl);
147
- },
148
- enumerable: false,
149
- configurable: true
150
- });
151
- Object.defineProperty(SearchServiceImpl.prototype, "searchTag", {
152
- get: function () {
153
- return this.serviceProvider.getService(tag_search_service_1.TagSearchServiceImpl);
154
- },
155
- enumerable: false,
156
- configurable: true
157
- });
158
- Object.defineProperty(SearchServiceImpl.prototype, "recentTextSearchQueries", {
159
- get: function () {
160
- return this.serviceProvider.getService(recent_text_search_queries_service_1.RecentTextSearchQueriesServiceImpl);
161
- },
162
- enumerable: false,
163
- configurable: true
164
- });
165
- SearchServiceImpl.prototype.startNewSearch = function (searchDomainId, filters, searchLanguage, searchEventContext) {
166
- var _this = this;
167
- this.searchStatus = new search_status_1.SearchStatus(searchDomainId);
168
- this.searchSessionID$.next(this.searchStatus.searchSessionID);
169
- this.filter.reset(this.searchStatus);
170
- this.cv.reset(this.searchStatus);
171
- this.text.reset(this.searchStatus);
172
- this.searchTag.reset(this.searchStatus);
173
- this.searchResultService.reset(this.searchStatus);
174
- var params = {};
175
- if (searchLanguage) {
176
- params['language'] = searchLanguage;
177
- }
178
- if (searchEventContext && searchEventContext.languageUi) {
179
- params['languageUi'] = searchEventContext.languageUi;
180
- }
181
- return this.httpsService.post("domains/".concat(this.searchStatus.searchDomainId, "/search"), params).pipe((0, operators_1.tap)(function (res) { return __awaiter(_this, void 0, void 0, function () {
182
- var deviceInfo, deviceInfoAExtendedData, organizationId;
183
- return __generator(this, function (_a) {
184
- switch (_a.label) {
185
- case 0:
186
- this.searchStatus.searchSessionID = res['searchSessionId'];
187
- this.searchStatus.searchLanguage = res['language'];
188
- this.searchSessionID$.next(this.searchStatus.searchSessionID);
189
- console.log("SearchService - New Search: ".concat(this.searchStatus.searchSessionID));
190
- return [4 /*yield*/, this.deviceStatusService.getDeviceInfo()];
191
- case 1:
192
- deviceInfo = _a.sent();
193
- deviceInfoAExtendedData = __assign(__assign({}, deviceInfo), { partiumSdkVersion: sdk_version_1.SDK_VERSION_NUMBER, languageUi: (searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.languageUi) || null, searchSessionId: this.searchStatus.searchSessionID });
194
- organizationId = this.searchStatus.searchDomainId;
195
- this.logService
196
- .logEvent(new log_1.EventLog({
197
- organizationId: organizationId,
198
- version: log_1.EVENTLOG_VERSIONS.V_2_0_0,
199
- interface: (searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.eventInterface) || log_1.INTERFACE.API_ACCESS,
200
- event: log_1.EVENT.DEVICE_INFO,
201
- data: deviceInfoAExtendedData,
202
- }))
203
- .subscribe({
204
- next: function () {
205
- // do nothing (console.log will be called in log-service)
206
- },
207
- error: function (error) {
208
- console.error("Error while sending log event ".concat(log_1.EVENT.DEVICE_INFO, ": "), error);
209
- },
210
- });
211
- return [2 /*return*/];
212
- }
213
- });
214
- }); }), (0, operators_1.mergeMap)(function (res) {
215
- if ((filters === null || filters === void 0 ? void 0 : filters.length) > 0) {
216
- return _this.filter.setSearchFilters(filters);
217
- }
218
- else {
219
- return (0, rxjs_1.of)(undefined);
220
- }
221
- }), (0, operators_1.catchError)(function (error) {
222
- _this.searchStatus = null;
223
- _this.searchSessionID$.next(undefined);
224
- return (0, rxjs_1.throwError)(error);
225
- }));
226
- };
227
- SearchServiceImpl.prototype.loadExistingSearchSession = function (searchSessionId) {
228
- this.searchStatus = new search_status_1.SearchStatus();
229
- this.searchStatus.searchSessionID = searchSessionId;
230
- this.searchSessionID$.next(this.searchStatus.searchSessionID);
231
- this.filter.reset(this.searchStatus);
232
- this.cv.reset(this.searchStatus);
233
- this.text.reset(this.searchStatus);
234
- this.searchTag.reset(this.searchStatus);
235
- this.searchResultService.reset(this.searchStatus);
236
- // load the status of the whole search-session
237
- this.searchResultService.startPollingForResults();
238
- };
239
- SearchServiceImpl.prototype.leaveCurrentSearchSession = function () {
240
- var _a;
241
- this.searchStatus = new search_status_1.SearchStatus();
242
- this.searchSessionID$.next(this.searchStatus.searchSessionID);
243
- this.filter.reset(this.searchStatus);
244
- this.cv.reset(this.searchStatus);
245
- this.text.reset(this.searchStatus);
246
- this.searchTag.reset(this.searchStatus);
247
- (_a = this.searchResultService) === null || _a === void 0 ? void 0 : _a.reset(this.searchStatus);
248
- };
249
- SearchServiceImpl.prototype.getCurResultList = function () {
250
- return this.searchResultService.getCurResultList();
251
- };
252
- SearchServiceImpl.prototype.getSearchResultStatus = function () {
253
- return this.searchResultService.getSearchResultStatus();
254
- };
255
- SearchServiceImpl.prototype.getCurSearchSessionID = function () {
256
- return this.searchStatus ? this.searchStatus.searchSessionID : null;
257
- };
258
- SearchServiceImpl.prototype.getCurSearchSessionID$ = function () {
259
- return this.searchSessionID$.asObservable();
260
- };
261
- SearchServiceImpl.prototype.getSearchStatus = function () {
262
- return this.searchStatus;
263
- };
264
- SearchServiceImpl.prototype.getCurResultListLength = function () {
265
- return this.searchResultService.getCurResultListLength();
266
- };
267
- SearchServiceImpl.prototype.getCurResultListValue = function () {
268
- return this.searchResultService.getCurResultListValue();
269
- };
270
- SearchServiceImpl.prototype.logToSearchSession = function (logObject) {
271
- return this.httpsService.post("search/".concat(this.getCurSearchSessionID(), "/log"), logObject);
272
- };
273
- SearchServiceImpl.prototype.loadMoreSearchResults = function () {
274
- this.searchResultService.loadMoreResults();
275
- };
276
- SearchServiceImpl.prototype.allSearchInputsEmpty = function () {
277
- return (0, rxjs_1.combineLatest)([
278
- this.text.getSearchQueries().pipe((0, operators_1.map)(function (value) { return Object.values(value).some(function (item) { return item; }); })),
279
- this.cv.getCvImageValue().pipe((0, operators_1.map)(function (value) { return !!value; })),
280
- this.filter.getFilters().pipe((0, operators_1.map)(function (value) { return Object.values(value).some(function (item) { return item; }); })),
281
- ]).pipe((0, operators_1.switchMap)(function (_a) {
282
- var searchQueries = _a[0], cvImage = _a[1], filters = _a[2];
283
- return (0, rxjs_1.of)(!searchQueries && !cvImage && !filters);
284
- }));
285
- };
286
- SearchServiceImpl.prototype.getCurSmartFilters = function () {
287
- return this.searchResultService.getSmartFilters();
288
- };
289
- SearchServiceImpl.prototype.performSearch = function (searchInput, searchEventContext, projection, resultOptions, skipDeviceInfoEventLog) {
290
- var _this = this;
291
- var _a, _b, _c, _d;
292
- if (projection === void 0) { projection = ['smartFilters', 'results.id', 'results.partiumId', 'results.name', 'request']; }
293
- if (resultOptions === void 0) { resultOptions = { limit: 25 }; }
294
- if (skipDeviceInfoEventLog === void 0) { skipDeviceInfoEventLog = false; }
295
- var data = __assign(__assign(__assign(__assign(__assign({ language: searchInput.searchLanguage }, (searchInput.searchSessionId && { sessionId: searchInput.searchSessionId })), { matches: __assign(__assign(__assign(__assign(__assign(__assign(__assign({ organization: searchInput.organizationName }, ((searchInput.text || ((_a = searchInput.searchQueries) === null || _a === void 0 ? void 0 : _a.semanticText)) && { text: searchInput.text || ((_b = searchInput.searchQueries) === null || _b === void 0 ? void 0 : _b.semanticText) })), (((_c = searchInput.searchQueries) === null || _c === void 0 ? void 0 : _c.exactText) && { exact: (_d = searchInput.searchQueries) === null || _d === void 0 ? void 0 : _d.exactText })), (searchInput.hierarchyFilters && { hierarchyPartiumIds: searchInput.hierarchyFilters })), (searchInput.attributeFilters && { filters: this.prepareFilters(searchInput.attributeFilters) })), (searchInput.similarTo && { similarTo: searchInput.similarTo })), (searchInput.duplicateOf && { duplicateOf: searchInput.duplicateOf })), (searchInput.hasRelatedParts && { hasRelatedParts: searchInput.hasRelatedParts })) }), (searchInput.searchImageAssetId && { reusableImageId: searchInput.searchImageAssetId })), ((searchInput.searchImageAssetId || searchInput.searchImage) && searchInput.searchImageCropArea && {
296
- imageOptions: {
297
- areaOfInterest: searchInput.searchImageCropArea,
298
- },
299
- })), { projection: this.removeDuplicatesFromArray(__spreadArray(__spreadArray([], projection, true), ['request'], false)), // always include request in the projection, to have language and orgName available in to create SearchOutput object
300
- resultOptions: resultOptions });
301
- // update recent text-searches if set
302
- this.updateRecentTextSearch(searchInput);
303
- // prepare search-request (can differ if search-image is involved)
304
- var searchRequest;
305
- if (searchInput.searchImage) { // use multipart if searchImage is set
306
- if (searchInput.searchImage.supportsMultipartUpload()) { // can be sent as multipart request
307
- var formData = new FormData();
308
- formData.append('input', JSON.stringify(data));
309
- searchInput.searchImage.appendToFormData('image', formData);
310
- searchRequest = this.httpsService.post("/find/search", formData, null, https_service_interface_1.BACKEND_SERVICE.PARTIUM, {
311
- 'Content-Type': 'multipart/form-data',
312
- 'X-Partium-Interface': (searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.eventInterface) || log_1.INTERFACE.API_ACCESS,
313
- });
314
- }
315
- else { // image-upload has to be done separately, before performing the search
316
- searchRequest = this.getOrganizationId(searchInput.organizationName) // TODO this is not ideal yet, we need to fetch the org-id, as we only have the org-name available
317
- .pipe((0, operators_1.first)(), (0, operators_1.switchMap)(function (organizationId) {
318
- return _this.assetService.generateAsset(organizationId, searchInput.searchImage, { eventInterface: searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.eventInterface });
319
- }), (0, operators_1.filter)(function (upload) { return upload.asset.getStatus() === asset_1.ASSET_STATUS.VERIFIED; }), (0, operators_1.first)(), (0, operators_1.map)(function (upload) { return upload.asset.referenceId; }), (0, operators_1.switchMap)(function (searchImageAssetId) {
320
- if (searchImageAssetId) {
321
- data.reusableImageId = searchImageAssetId;
322
- }
323
- return _this.httpsService.post("/find/search", data, null, https_service_interface_1.BACKEND_SERVICE.PARTIUM, {
324
- 'X-Partium-Interface': (searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.eventInterface) || log_1.INTERFACE.API_ACCESS,
325
- });
326
- }));
327
- }
328
- }
329
- else { // standard json request
330
- searchRequest = this.httpsService.post("/find/search", data, null, https_service_interface_1.BACKEND_SERVICE.PARTIUM, {
331
- 'X-Partium-Interface': (searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.eventInterface) || log_1.INTERFACE.API_ACCESS,
332
- });
333
- }
334
- // execute search-request
335
- return searchRequest.pipe((0, operators_1.map)(function (response) {
336
- var searchOutput = _this.processSearchApiResponse(response);
337
- searchOutput.searchInput.searchImage = searchInput.searchImage;
338
- _this.updateSearchStatus(searchOutput); // TODO used for backwards-compatibility, can be removed when SearchStatus is deleted
339
- return searchOutput;
340
- }), (0, operators_1.tap)(function (searchOutput) {
341
- if (!searchInput.searchSessionId && !skipDeviceInfoEventLog) { // new search -> log device-info
342
- _this.getOrganizationId(searchInput.organizationName) // TODO this is not ideal yet, we need to fetch the org-id, as we only have the org-name available
343
- .pipe((0, operators_1.first)())
344
- .subscribe(function (organizationId) {
345
- _this.logDeviceInfo(searchOutput.searchInput.searchSessionId, organizationId, searchEventContext);
346
- });
347
- }
348
- }));
349
- };
350
- SearchServiceImpl.prototype.getSearchOutput = function (searchSessionId, projection, resultOptions, organizationName) {
351
- var _this = this;
352
- if (projection === void 0) { projection = ['smartFilters', 'results.id', 'results.partiumId', 'results.name', 'request']; }
353
- if (resultOptions === void 0) { resultOptions = { limit: 25 }; }
354
- var fetchOrganizationName;
355
- if (organizationName) {
356
- fetchOrganizationName = (0, rxjs_1.of)(organizationName);
357
- }
358
- else {
359
- fetchOrganizationName = this.currentOrganization$.pipe((0, operators_1.map)(function (organization) { return organization.name; }));
360
- }
361
- return fetchOrganizationName.pipe((0, operators_1.switchMap)(function (organizationName) {
362
- return _this.httpsService.get("/find/search/state/".concat(searchSessionId), __spreadArray([
363
- {
364
- projection: _this.removeDuplicatesFromArray(__spreadArray(__spreadArray([], projection, true), ['request'], false)), // always include request in the projection, to have searchLanguage and orgName available in to create SearchOutput object
365
- },
366
- {
367
- organization: organizationName,
368
- }
369
- ], Object.keys(resultOptions).map(function (param) {
370
- var _a;
371
- return (_a = {}, _a[param] = resultOptions[param], _a);
372
- }), true), https_service_interface_1.BACKEND_SERVICE.PARTIUM);
373
- }), (0, operators_1.map)(function (response) {
374
- return _this.processSearchApiResponse(response);
375
- }));
376
- };
377
- SearchServiceImpl.prototype.logDeviceInfo = function (searchSessionId, organizationId, searchEventContext) {
378
- var _this = this;
379
- this.deviceStatusService.getDeviceInfo()
380
- .then(function (deviceInfo) {
381
- var deviceInfoAExtendedData = __assign(__assign({}, deviceInfo), { partiumSdkVersion: sdk_version_1.SDK_VERSION_NUMBER, languageUi: (searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.languageUi) || null, searchSessionId: searchSessionId });
382
- _this.logService
383
- .logEvent(new log_1.EventLog({
384
- organizationId: organizationId,
385
- version: log_1.EVENTLOG_VERSIONS.V_2_0_0,
386
- interface: (searchEventContext === null || searchEventContext === void 0 ? void 0 : searchEventContext.eventInterface) || log_1.INTERFACE.API_ACCESS,
387
- event: log_1.EVENT.DEVICE_INFO,
388
- data: deviceInfoAExtendedData,
389
- }))
390
- .subscribe({
391
- next: function () {
392
- // do nothing (console.log will be called in log-service)
393
- },
394
- error: function (error) {
395
- console.error("Error while sending log event ".concat(log_1.EVENT.DEVICE_INFO, ": "), error);
396
- },
397
- });
398
- });
399
- };
400
- SearchServiceImpl.prototype.getOrganizationId = function (organizationName) {
401
- return (0, rxjs_1.from)(this.organizationService.getOrganizations()).pipe((0, operators_1.map)(function (organizations) {
402
- for (var _i = 0, organizations_1 = organizations; _i < organizations_1.length; _i++) {
403
- var org = organizations_1[_i];
404
- if (org.name.toLowerCase() === organizationName.toLowerCase()) {
405
- return org.partiumId;
406
- }
407
- }
408
- return null;
409
- }));
410
- };
411
- SearchServiceImpl.prototype.prepareFilters = function (filters) {
412
- return Object.keys(filters).map(function (filterName) { return ({
413
- label: filterName,
414
- values: filters[filterName].map(function (filterKey) { return filterKey; }),
415
- }); });
416
- };
417
- SearchServiceImpl.prototype.processSearchApiResponse = function (response) {
418
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
419
- var searchLanguage = (_a = response.request) === null || _a === void 0 ? void 0 : _a.language;
420
- var organizationName = (_c = (_b = response.request) === null || _b === void 0 ? void 0 : _b.matches) === null || _c === void 0 ? void 0 : _c.organization;
421
- return __assign({ searchInput: __assign({ organizationName: organizationName, searchLanguage: searchLanguage, searchSessionId: response.sessionId }, (response.request && {
422
- text: (_d = response.request.matches) === null || _d === void 0 ? void 0 : _d.text,
423
- searchQueries: {
424
- exactText: (_e = response.request.matches) === null || _e === void 0 ? void 0 : _e.exact,
425
- semanticText: (_f = response.request.matches) === null || _f === void 0 ? void 0 : _f.text
426
- },
427
- searchImageAssetId: response.request.reusableImageId || response.imageId,
428
- searchImageCropArea: (_g = response.request.imageOptions) === null || _g === void 0 ? void 0 : _g.areaOfInterest,
429
- hierarchyFilters: (_h = response.request.matches) === null || _h === void 0 ? void 0 : _h.hierarchyPartiumIds,
430
- attributeFilters: (_k = (_j = response.request.matches) === null || _j === void 0 ? void 0 : _j.filters) === null || _k === void 0 ? void 0 : _k.reduce(function (filters, filter) {
431
- var _a;
432
- return (__assign(__assign({}, filters), (_a = {}, _a[filter.label] = filter.values, _a)));
433
- }, {}),
434
- similarTo: (_l = response.request.matches) === null || _l === void 0 ? void 0 : _l.similarTo,
435
- duplicateOf: (_m = response.request.matches) === null || _m === void 0 ? void 0 : _m.duplicateOf,
436
- hasRelatedParts: (_o = response.request.matches) === null || _o === void 0 ? void 0 : _o.hasRelatedParts,
437
- })), resultsTotalCount: response.resultsTotalCount, searchResults: response.results.map(function (partFromApi) {
438
- return part_1.Part.fromAPIResponse(partFromApi, part_1.DATA_ORIGIN.FIND_API, searchLanguage);
439
- }) }, (response.smartFilters && { smartFilters: response.smartFilters.map(function (filterFromApi) {
440
- return smart_filter_1.SmartFilter.fromAPIResponse(filterFromApi);
441
- }) }));
442
- };
443
- SearchServiceImpl.prototype.removeDuplicatesFromArray = function (array) {
444
- return Array.from(new Set(array));
445
- };
446
- /**
447
- * TODO used for backwards-compatibility, can be removed when SearchStatus is deleted
448
- */
449
- SearchServiceImpl.prototype.updateSearchStatus = function (searchOutput) {
450
- var _this = this;
451
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
452
- this.searchStatus = this.searchStatus || new search_status_1.SearchStatus();
453
- this.getOrganizationId((_a = searchOutput.searchInput) === null || _a === void 0 ? void 0 : _a.organizationName)
454
- .pipe((0, operators_1.first)())
455
- .subscribe(function (organizationId) {
456
- _this.searchStatus.searchDomainId = organizationId;
457
- });
458
- this.searchStatus.searchSessionID = (_b = searchOutput.searchInput) === null || _b === void 0 ? void 0 : _b.searchSessionId;
459
- this.searchSessionID$.next(this.searchStatus.searchSessionID);
460
- this.searchStatus.searchLanguage = (_c = searchOutput.searchInput) === null || _c === void 0 ? void 0 : _c.searchLanguage;
461
- this.searchStatus.curResultList = searchOutput.searchResults;
462
- // text
463
- this.searchStatus.textSearchStatus = this.searchStatus.textSearchStatus || new text_search_status_1.TextSearchStatus();
464
- this.searchStatus.textSearchStatus.searchQuery = (_d = searchOutput.searchInput) === null || _d === void 0 ? void 0 : _d.text;
465
- this.searchStatus.textSearchStatus.searchQueries = (_e = searchOutput.searchInput) === null || _e === void 0 ? void 0 : _e.searchQueries;
466
- // image
467
- this.searchStatus.cvSearchStatus = this.searchStatus.cvSearchStatus || new cv_search_status_1.CVSearchStatus();
468
- this.searchStatus.cvSearchStatus.assetId = (_f = searchOutput.searchInput) === null || _f === void 0 ? void 0 : _f.searchImageAssetId;
469
- this.searchStatus.cvSearchStatus.cvImage = ((_g = searchOutput.searchInput) === null || _g === void 0 ? void 0 : _g.searchImage) ? new asset_1.Asset((_h = searchOutput.searchInput) === null || _h === void 0 ? void 0 : _h.searchImage) : null;
470
- this.searchStatus.cvSearchStatus.cropArea = (_j = searchOutput.searchInput) === null || _j === void 0 ? void 0 : _j.searchImageCropArea;
471
- // filter
472
- this.searchStatus.filterStatus = this.searchStatus.filterStatus || new search_filter_status_1.SearchFilterStatus();
473
- this.searchStatus.filterStatus.filters = __spreadArray(__spreadArray([], ((_l = (_k = searchOutput.searchInput) === null || _k === void 0 ? void 0 : _k.hierarchyFilters) === null || _l === void 0 ? void 0 : _l.length) ? [new search_filter_1.HierarchyPartiumIdFilter(searchOutput.searchInput.hierarchyFilters, [])] : [], true), ((_m = searchOutput.searchInput) === null || _m === void 0 ? void 0 : _m.attributeFilters) ? Object.keys((_o = searchOutput.searchInput) === null || _o === void 0 ? void 0 : _o.attributeFilters).map(function (name) { var _a; return new search_filter_1.KvpHardFilter(name, name, (_a = searchOutput.searchInput) === null || _a === void 0 ? void 0 : _a.attributeFilters[name]); }) : [], true);
474
- this.searchStatus.filterStatus.filters.map(function (filter) {
475
- var _a;
476
- return (_a = {}, _a[filter.key] = filter, _a);
477
- });
478
- this.searchStatus.filterStatus.filtersMap = this.searchStatus.filterStatus.filters.reduce(function (filtersMap, filter) {
479
- var _a;
480
- return (__assign(__assign({}, filtersMap), (_a = {}, _a[filter.key] = filter, _a)));
481
- }, {});
482
- this.searchStatus.filterStatus.excludedHierarchyNodes = {};
483
- // tags
484
- this.searchStatus.tagSearchStatus = this.searchStatus.tagSearchStatus || new tag_search_status_1.TagSearchStatus();
485
- this.searchStatus.tagSearchStatus.proposedSearchTags = [];
486
- // results
487
- this.searchStatus.searchResultStatus = this.searchStatus.searchResultStatus || new search_result_status_1.SearchResultStatus();
488
- this.searchStatus.searchResultStatus.status = search_result_status_1.SEARCH_RESULT_STATUS.FINISHED;
489
- this.searchStatus.searchResultStatus.asyncTagsStatus = search_result_status_1.ASYNC_TAG_STATUS.WILL_NOT_RECEIVE;
490
- this.searchStatus.searchResultStatus.asyncResultsStatus = search_result_status_1.ASYNC_RESULT_STATUS.RECEIVED;
491
- this.searchStatus.searchResultStatus.asyncSmartFiltersStatus = search_result_status_1.SMART_FILTERS_STATUS.WILL_NOT_RECEIVE;
492
- };
493
- /**
494
- * Add text-searches to recent text-searches if set
495
- * @param searchInput the new search-input
496
- */
497
- SearchServiceImpl.prototype.updateRecentTextSearch = function (searchInput) {
498
- if (searchInput.searchQueries && searchInput.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC]) {
499
- this.recentTextSearchQueries.addSemanticTextQuery(searchInput.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC]);
500
- }
501
- if (searchInput.searchQueries && searchInput.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.EXACT]) {
502
- this.recentTextSearchQueries.addExactTextQuery(searchInput.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.EXACT]);
503
- this.recentTextSearchQueries.addQuery(searchInput.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.EXACT]);
504
- }
505
- if (searchInput.text) {
506
- this.recentTextSearchQueries.addQuery(searchInput.text);
507
- }
508
- };
509
- SearchServiceImpl = __decorate([
510
- (0, injection_identifier_1.InjectionIdentifier)('SearchService')
511
- ], SearchServiceImpl);
512
- return SearchServiceImpl;
513
- }(core_1.BaseLoginInitService));
514
- exports.SearchServiceImpl = SearchServiceImpl;
515
- //# sourceMappingURL=search.service.js.map
2
+ "use strict";var __extends=this&&this.__extends||function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function s(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(s.prototype=r.prototype,new s)}}(),__assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},__assign.apply(this,arguments)},__decorate=this&&this.__decorate||function(e,t,r,s){var a,i=arguments.length,c=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,r,s);else for(var n=e.length-1;n>=0;n--)(a=e[n])&&(c=(i<3?a(c):i>3?a(t,r,c):a(t,r))||c);return i>3&&c&&Object.defineProperty(t,r,c),c},__awaiter=this&&this.__awaiter||function(e,t,r,s){return new(r||(r=Promise))((function(a,i){function c(e){try{o(s.next(e))}catch(e){i(e)}}function n(e){try{o(s.throw(e))}catch(e){i(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(c,n)}o((s=s.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,s,a,i,c={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function n(n){return function(o){return function(n){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,n[0]&&(c=0)),c;)try{if(r=1,s&&(a=2&n[0]?s.return:n[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,n[1])).done)return a;switch(s=0,a&&(n=[2&n[0],a.value]),n[0]){case 0:case 1:a=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,s=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(!(a=c.trys,(a=a.length>0&&a[a.length-1])||6!==n[0]&&2!==n[0])){c=0;continue}if(3===n[0]&&(!a||n[1]>a[0]&&n[1]<a[3])){c.label=n[1];break}if(6===n[0]&&c.label<a[1]){c.label=a[1],a=n;break}if(a&&c.label<a[2]){c.label=a[2],c.ops.push(n);break}a[2]&&c.ops.pop(),c.trys.pop();continue}n=t.call(e,c)}catch(e){n=[6,e],s=0}finally{r=a=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,o])}}},__spreadArray=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var s,a=0,i=t.length;a<i;a++)!s&&a in t||(s||(s=Array.prototype.slice.call(t,0,a)),s[a]=t[a]);return e.concat(s||Array.prototype.slice.call(t))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SearchServiceImpl=void 0;var text_search_service_1=require("./text-search.service"),cv_search_service_1=require("./cv-search.service"),rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),search_status_1=require("../../models/search-status/search-status"),search_filter_1=require("../../models/search-filter"),search_filter_service_1=require("../search-filter.service"),search_result_service_1=require("./search-result.service"),tag_search_service_1=require("./tag-search.service"),search_result_status_1=require("../../models/search-result-status"),sdk_version_1=require("../../../gen/sdk-version"),part_1=require("../../../data/models/part"),injection_identifier_1=require("../../../core/decorators/injection-identifier"),https_service_interface_1=require("../../../core/services/http/https.service.interface"),log_service_1=require("../../../core/services/log.service"),device_status_service_interface_1=require("../../../core/services/device-status.service.interface"),log_1=require("../../../core/models/log"),recent_text_search_queries_service_1=require("./recent-text-search-queries.service"),smart_filter_1=require("../../models/smart-filter"),core_1=require("../../../core"),cv_search_status_1=require("../../models/search-status/cv-search-status"),asset_service_1=require("../asset.service"),asset_1=require("../../models/assets/asset"),text_search_status_1=require("../../models/search-status/text-search-status"),search_filter_status_1=require("../../models/search-status/search-filter-status"),tag_search_status_1=require("../../models/search-status/tag-search-status"),SearchServiceImpl=function(e){function t(t){var r=e.call(this,t)||this;return r.searchSessionID$=new rxjs_1.BehaviorSubject(void 0),r}return __extends(t,e),t.prototype.onCreate=function(){this.httpsService=this.serviceProvider.getService(https_service_interface_1.HttpsService),this.searchResultService=this.serviceProvider.getService(search_result_service_1.SearchResultService),this.logService=this.serviceProvider.getService(log_service_1.LogServiceImpl),this.deviceStatusService=this.serviceProvider.getService(device_status_service_interface_1.DeviceStatusService),this.organizationService=this.serviceProvider.getService(core_1.OrganizationService),this.assetService=this.serviceProvider.getService(asset_service_1.AssetServiceImpl)},t.prototype.init=function(t,r,s){return e.prototype.init.call(this,t,r,s),(0,rxjs_1.of)(void 0)},Object.defineProperty(t.prototype,"text",{get:function(){return this.serviceProvider.getService(text_search_service_1.TextSearchServiceImpl)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"cv",{get:function(){return this.serviceProvider.getService(cv_search_service_1.CvSearchServiceImpl)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"filter",{get:function(){return this.serviceProvider.getService(search_filter_service_1.SearchFilterServiceImpl)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"searchTag",{get:function(){return this.serviceProvider.getService(tag_search_service_1.TagSearchServiceImpl)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"recentTextSearchQueries",{get:function(){return this.serviceProvider.getService(recent_text_search_queries_service_1.RecentTextSearchQueriesServiceImpl)},enumerable:!1,configurable:!0}),t.prototype.startNewSearch=function(e,t,r,s){var a=this;this.searchStatus=new search_status_1.SearchStatus(e),this.searchSessionID$.next(this.searchStatus.searchSessionID),this.filter.reset(this.searchStatus),this.cv.reset(this.searchStatus),this.text.reset(this.searchStatus),this.searchTag.reset(this.searchStatus),this.searchResultService.reset(this.searchStatus);var i={};return r&&(i.language=r),s&&s.languageUi&&(i.languageUi=s.languageUi),this.httpsService.post("domains/".concat(this.searchStatus.searchDomainId,"/search"),i).pipe((0,operators_1.tap)((function(e){return __awaiter(a,void 0,void 0,(function(){var t,r,a;return __generator(this,(function(i){switch(i.label){case 0:return this.searchStatus.searchSessionID=e.searchSessionId,this.searchStatus.searchLanguage=e.language,this.searchSessionID$.next(this.searchStatus.searchSessionID),console.log("SearchService - New Search: ".concat(this.searchStatus.searchSessionID)),[4,this.deviceStatusService.getDeviceInfo()];case 1:return t=i.sent(),r=__assign(__assign({},t),{partiumSdkVersion:sdk_version_1.SDK_VERSION_NUMBER,languageUi:(null==s?void 0:s.languageUi)||null,searchSessionId:this.searchStatus.searchSessionID}),a=this.searchStatus.searchDomainId,this.logService.logEvent(new log_1.EventLog({organizationId:a,version:log_1.EVENTLOG_VERSIONS.V_2_0_0,interface:(null==s?void 0:s.eventInterface)||log_1.INTERFACE.API_ACCESS,event:log_1.EVENT.DEVICE_INFO,data:r})).subscribe({next:function(){},error:function(e){console.error("Error while sending log event ".concat(log_1.EVENT.DEVICE_INFO,": "),e)}}),[2]}}))}))})),(0,operators_1.mergeMap)((function(e){return(null==t?void 0:t.length)>0?a.filter.setSearchFilters(t):(0,rxjs_1.of)(void 0)})),(0,operators_1.catchError)((function(e){return a.searchStatus=null,a.searchSessionID$.next(void 0),(0,rxjs_1.throwError)(e)})))},t.prototype.loadExistingSearchSession=function(e){this.searchStatus=new search_status_1.SearchStatus,this.searchStatus.searchSessionID=e,this.searchSessionID$.next(this.searchStatus.searchSessionID),this.filter.reset(this.searchStatus),this.cv.reset(this.searchStatus),this.text.reset(this.searchStatus),this.searchTag.reset(this.searchStatus),this.searchResultService.reset(this.searchStatus),this.searchResultService.startPollingForResults()},t.prototype.leaveCurrentSearchSession=function(){var e;this.searchStatus=new search_status_1.SearchStatus,this.searchSessionID$.next(this.searchStatus.searchSessionID),this.filter.reset(this.searchStatus),this.cv.reset(this.searchStatus),this.text.reset(this.searchStatus),this.searchTag.reset(this.searchStatus),null===(e=this.searchResultService)||void 0===e||e.reset(this.searchStatus)},t.prototype.getCurResultList=function(){return this.searchResultService.getCurResultList()},t.prototype.getSearchResultStatus=function(){return this.searchResultService.getSearchResultStatus()},t.prototype.getCurSearchSessionID=function(){return this.searchStatus?this.searchStatus.searchSessionID:null},t.prototype.getCurSearchSessionID$=function(){return this.searchSessionID$.asObservable()},t.prototype.getSearchStatus=function(){return this.searchStatus},t.prototype.getCurResultListLength=function(){return this.searchResultService.getCurResultListLength()},t.prototype.getCurResultListValue=function(){return this.searchResultService.getCurResultListValue()},t.prototype.logToSearchSession=function(e){return this.httpsService.post("search/".concat(this.getCurSearchSessionID(),"/log"),e)},t.prototype.loadMoreSearchResults=function(){this.searchResultService.loadMoreResults()},t.prototype.allSearchInputsEmpty=function(){return(0,rxjs_1.combineLatest)([this.text.getSearchQueries().pipe((0,operators_1.map)((function(e){return Object.values(e).some((function(e){return e}))}))),this.cv.getCvImageValue().pipe((0,operators_1.map)((function(e){return!!e}))),this.filter.getFilters().pipe((0,operators_1.map)((function(e){return Object.values(e).some((function(e){return e}))})))]).pipe((0,operators_1.switchMap)((function(e){var t=e[0],r=e[1],s=e[2];return(0,rxjs_1.of)(!t&&!r&&!s)})))},t.prototype.getCurSmartFilters=function(){return this.searchResultService.getSmartFilters()},t.prototype.performSearch=function(e,t,r,s,a){var i,c,n,o,u=this;void 0===r&&(r=["smartFilters","results.id","results.partiumId","results.name","request"]),void 0===s&&(s={limit:25}),void 0===a&&(a=!1);var h,l=__assign(__assign(__assign(__assign(__assign({language:e.searchLanguage},e.searchSessionId&&{sessionId:e.searchSessionId}),{matches:__assign(__assign(__assign(__assign(__assign(__assign(__assign({organization:e.organizationName},(e.text||(null===(i=e.searchQueries)||void 0===i?void 0:i.semanticText))&&{text:e.text||(null===(c=e.searchQueries)||void 0===c?void 0:c.semanticText)}),(null===(n=e.searchQueries)||void 0===n?void 0:n.exactText)&&{exact:null===(o=e.searchQueries)||void 0===o?void 0:o.exactText}),e.hierarchyFilters&&{hierarchyPartiumIds:e.hierarchyFilters}),e.attributeFilters&&{filters:this.prepareFilters(e.attributeFilters)}),e.similarTo&&{similarTo:e.similarTo}),e.duplicateOf&&{duplicateOf:e.duplicateOf}),e.hasRelatedParts&&{hasRelatedParts:e.hasRelatedParts})}),e.searchImageAssetId&&{reusableImageId:e.searchImageAssetId}),(e.searchImageAssetId||e.searchImage)&&e.searchImageCropArea&&{imageOptions:{areaOfInterest:e.searchImageCropArea}}),{projection:this.removeDuplicatesFromArray(__spreadArray(__spreadArray([],r,!0),["request"],!1)),resultOptions:s});if(this.updateRecentTextSearch(e),e.searchImage)if(e.searchImage.supportsMultipartUpload()){var _=new FormData;_.append("input",JSON.stringify(l)),e.searchImage.appendToFormData("image",_),h=this.httpsService.post("/find/search",_,null,https_service_interface_1.BACKEND_SERVICE.PARTIUM,{"Content-Type":"multipart/form-data","X-Partium-Interface":(null==t?void 0:t.eventInterface)||log_1.INTERFACE.API_ACCESS})}else h=this.getOrganizationId(e.organizationName).pipe((0,operators_1.first)(),(0,operators_1.switchMap)((function(r){return u.assetService.generateAsset(r,e.searchImage,{eventInterface:null==t?void 0:t.eventInterface})})),(0,operators_1.filter)((function(e){return e.asset.getStatus()===asset_1.ASSET_STATUS.VERIFIED})),(0,operators_1.first)(),(0,operators_1.map)((function(e){return e.asset.referenceId})),(0,operators_1.switchMap)((function(e){return e&&(l.reusableImageId=e),u.httpsService.post("/find/search",l,null,https_service_interface_1.BACKEND_SERVICE.PARTIUM,{"X-Partium-Interface":(null==t?void 0:t.eventInterface)||log_1.INTERFACE.API_ACCESS})})));else h=this.httpsService.post("/find/search",l,null,https_service_interface_1.BACKEND_SERVICE.PARTIUM,{"X-Partium-Interface":(null==t?void 0:t.eventInterface)||log_1.INTERFACE.API_ACCESS});return h.pipe((0,operators_1.map)((function(t){var r=u.processSearchApiResponse(t);return r.searchInput.searchImage=e.searchImage,u.updateSearchStatus(r),r})),(0,operators_1.tap)((function(r){e.searchSessionId||a||u.getOrganizationId(e.organizationName).pipe((0,operators_1.first)()).subscribe((function(e){u.logDeviceInfo(r.searchInput.searchSessionId,e,t)}))})))},t.prototype.getSearchOutput=function(e,t,r,s){var a=this;return void 0===t&&(t=["smartFilters","results.id","results.partiumId","results.name","request"]),void 0===r&&(r={limit:25}),(s?(0,rxjs_1.of)(s):this.currentOrganization$.pipe((0,operators_1.map)((function(e){return e.name})))).pipe((0,operators_1.switchMap)((function(s){return a.httpsService.get("/find/search/state/".concat(e),__spreadArray([{projection:a.removeDuplicatesFromArray(__spreadArray(__spreadArray([],t,!0),["request"],!1))},{organization:s}],Object.keys(r).map((function(e){var t;return(t={})[e]=r[e],t})),!0),https_service_interface_1.BACKEND_SERVICE.PARTIUM)})),(0,operators_1.map)((function(e){return a.processSearchApiResponse(e)})))},t.prototype.logDeviceInfo=function(e,t,r){var s=this;this.deviceStatusService.getDeviceInfo().then((function(a){var i=__assign(__assign({},a),{partiumSdkVersion:sdk_version_1.SDK_VERSION_NUMBER,languageUi:(null==r?void 0:r.languageUi)||null,searchSessionId:e});s.logService.logEvent(new log_1.EventLog({organizationId:t,version:log_1.EVENTLOG_VERSIONS.V_2_0_0,interface:(null==r?void 0:r.eventInterface)||log_1.INTERFACE.API_ACCESS,event:log_1.EVENT.DEVICE_INFO,data:i})).subscribe({next:function(){},error:function(e){console.error("Error while sending log event ".concat(log_1.EVENT.DEVICE_INFO,": "),e)}})}))},t.prototype.getOrganizationId=function(e){return(0,rxjs_1.from)(this.organizationService.getOrganizations()).pipe((0,operators_1.map)((function(t){for(var r=0,s=t;r<s.length;r++){var a=s[r];if(a.name.toLowerCase()===e.toLowerCase())return a.partiumId}return null})))},t.prototype.prepareFilters=function(e){return Object.keys(e).map((function(t){return{label:t,values:e[t].map((function(e){return e}))}}))},t.prototype.processSearchApiResponse=function(e){var t,r,s,a,i,c,n,o,u,h,l,_,S,p=null===(t=e.request)||void 0===t?void 0:t.language,v=null===(s=null===(r=e.request)||void 0===r?void 0:r.matches)||void 0===s?void 0:s.organization;return __assign({searchInput:__assign({organizationName:v,searchLanguage:p,searchSessionId:e.sessionId},e.request&&{text:null===(a=e.request.matches)||void 0===a?void 0:a.text,searchQueries:{exactText:null===(i=e.request.matches)||void 0===i?void 0:i.exact,semanticText:null===(c=e.request.matches)||void 0===c?void 0:c.text},searchImageAssetId:e.request.reusableImageId||e.imageId,searchImageCropArea:null===(n=e.request.imageOptions)||void 0===n?void 0:n.areaOfInterest,hierarchyFilters:null===(o=e.request.matches)||void 0===o?void 0:o.hierarchyPartiumIds,attributeFilters:null===(h=null===(u=e.request.matches)||void 0===u?void 0:u.filters)||void 0===h?void 0:h.reduce((function(e,t){var r;return __assign(__assign({},e),((r={})[t.label]=t.values,r))}),{}),similarTo:null===(l=e.request.matches)||void 0===l?void 0:l.similarTo,duplicateOf:null===(_=e.request.matches)||void 0===_?void 0:_.duplicateOf,hasRelatedParts:null===(S=e.request.matches)||void 0===S?void 0:S.hasRelatedParts}),resultsTotalCount:e.resultsTotalCount,searchResults:e.results.map((function(e){return part_1.Part.fromAPIResponse(e,part_1.DATA_ORIGIN.FIND_API,p)}))},e.smartFilters&&{smartFilters:e.smartFilters.map((function(e){return smart_filter_1.SmartFilter.fromAPIResponse(e)}))})},t.prototype.removeDuplicatesFromArray=function(e){return Array.from(new Set(e))},t.prototype.updateSearchStatus=function(e){var t,r,s,a,i,c,n,o,u,h,l,_,S,p=this;this.searchStatus=this.searchStatus||new search_status_1.SearchStatus,this.getOrganizationId(null===(t=e.searchInput)||void 0===t?void 0:t.organizationName).pipe((0,operators_1.first)()).subscribe((function(e){p.searchStatus.searchDomainId=e})),this.searchStatus.searchSessionID=null===(r=e.searchInput)||void 0===r?void 0:r.searchSessionId,this.searchSessionID$.next(this.searchStatus.searchSessionID),this.searchStatus.searchLanguage=null===(s=e.searchInput)||void 0===s?void 0:s.searchLanguage,this.searchStatus.curResultList=e.searchResults,this.searchStatus.textSearchStatus=this.searchStatus.textSearchStatus||new text_search_status_1.TextSearchStatus,this.searchStatus.textSearchStatus.searchQuery=null===(a=e.searchInput)||void 0===a?void 0:a.text,this.searchStatus.textSearchStatus.searchQueries=null===(i=e.searchInput)||void 0===i?void 0:i.searchQueries,this.searchStatus.cvSearchStatus=this.searchStatus.cvSearchStatus||new cv_search_status_1.CVSearchStatus,this.searchStatus.cvSearchStatus.assetId=null===(c=e.searchInput)||void 0===c?void 0:c.searchImageAssetId,this.searchStatus.cvSearchStatus.cvImage=(null===(n=e.searchInput)||void 0===n?void 0:n.searchImage)?new asset_1.Asset(null===(o=e.searchInput)||void 0===o?void 0:o.searchImage):null,this.searchStatus.cvSearchStatus.cropArea=null===(u=e.searchInput)||void 0===u?void 0:u.searchImageCropArea,this.searchStatus.filterStatus=this.searchStatus.filterStatus||new search_filter_status_1.SearchFilterStatus,this.searchStatus.filterStatus.filters=__spreadArray(__spreadArray([],(null===(l=null===(h=e.searchInput)||void 0===h?void 0:h.hierarchyFilters)||void 0===l?void 0:l.length)?[new search_filter_1.HierarchyPartiumIdFilter(e.searchInput.hierarchyFilters,[])]:[],!0),(null===(_=e.searchInput)||void 0===_?void 0:_.attributeFilters)?Object.keys(null===(S=e.searchInput)||void 0===S?void 0:S.attributeFilters).map((function(t){var r;return new search_filter_1.KvpHardFilter(t,t,null===(r=e.searchInput)||void 0===r?void 0:r.attributeFilters[t])})):[],!0),this.searchStatus.filterStatus.filters.map((function(e){var t;return(t={})[e.key]=e,t})),this.searchStatus.filterStatus.filtersMap=this.searchStatus.filterStatus.filters.reduce((function(e,t){var r;return __assign(__assign({},e),((r={})[t.key]=t,r))}),{}),this.searchStatus.filterStatus.excludedHierarchyNodes={},this.searchStatus.tagSearchStatus=this.searchStatus.tagSearchStatus||new tag_search_status_1.TagSearchStatus,this.searchStatus.tagSearchStatus.proposedSearchTags=[],this.searchStatus.searchResultStatus=this.searchStatus.searchResultStatus||new search_result_status_1.SearchResultStatus,this.searchStatus.searchResultStatus.status=search_result_status_1.SEARCH_RESULT_STATUS.FINISHED,this.searchStatus.searchResultStatus.asyncTagsStatus=search_result_status_1.ASYNC_TAG_STATUS.WILL_NOT_RECEIVE,this.searchStatus.searchResultStatus.asyncResultsStatus=search_result_status_1.ASYNC_RESULT_STATUS.RECEIVED,this.searchStatus.searchResultStatus.asyncSmartFiltersStatus=search_result_status_1.SMART_FILTERS_STATUS.WILL_NOT_RECEIVE},t.prototype.updateRecentTextSearch=function(e){e.searchQueries&&e.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC]&&this.recentTextSearchQueries.addSemanticTextQuery(e.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC]),e.searchQueries&&e.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.EXACT]&&(this.recentTextSearchQueries.addExactTextQuery(e.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.EXACT]),this.recentTextSearchQueries.addQuery(e.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.EXACT])),e.text&&this.recentTextSearchQueries.addQuery(e.text)},t=__decorate([(0,injection_identifier_1.InjectionIdentifier)("SearchService")],t)}(core_1.BaseLoginInitService);exports.SearchServiceImpl=SearchServiceImpl;