@partium/js-sdk 14.0.2 → 14.1.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 (142) hide show
  1. package/catalog/index.js +21 -1
  2. package/catalog/models/catalog-image-info.js +22 -1
  3. package/catalog/models/catalog-image.js +40 -1
  4. package/catalog/models/upsert-catalog-images-dto.js +3 -1
  5. package/catalog/models/upsert-images-result.js +3 -1
  6. package/catalog/services/images.service.js +62 -1
  7. package/core/constants/constants.js +16 -1
  8. package/core/decorators/injection-identifier.js +19 -1
  9. package/core/factories/paginated-request-service.factory.js +33 -1
  10. package/core/index.js +63 -1
  11. package/core/integration-defaults/http/fetch-api-http-error-helper.js +129 -1
  12. package/core/integration-defaults/http/file-transfer/axios-file-transfer.service.js +138 -1
  13. package/core/integration-defaults/http/file-transfer/fetch-api-file-transfer.service.js +210 -1
  14. package/core/integration-defaults/http/handle-axios-error-helper.js +79 -1
  15. package/core/integration-defaults/http/https-client/axios-https-client.service.js +182 -1
  16. package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +198 -1
  17. package/core/integration-defaults/http/js-oauth-keycloak-https.service.js +32 -1
  18. package/core/integration-defaults/js-p-file.js +36 -1
  19. package/core/integration-defaults/session/js-oauth-api-key-session.service.js +206 -1
  20. package/core/integration-defaults/session/js-oauth-keycloak-auth-config.js +64 -1
  21. package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +257 -1
  22. package/core/integration-defaults/web-device-status.service.js +125 -1
  23. package/core/integration-defaults/web-file.service.js +135 -1
  24. package/core/integration-defaults/web-indexeddb.service.js +142 -1
  25. package/core/integration-defaults/web-local-storage.service.js +310 -1
  26. package/core/models/api-object.js +16 -1
  27. package/core/models/auth-config.js +72 -1
  28. package/core/models/device-info.js +34 -1
  29. package/core/models/error.js +107 -1
  30. package/core/models/formatted-string.js +14 -1
  31. package/core/models/i18n-map.js +61 -1
  32. package/core/models/i18n-string.js +35 -1
  33. package/core/models/log.js +137 -1
  34. package/core/models/organization.js +159 -1
  35. package/core/models/p-file.js +23 -1
  36. package/core/models/paginated-list.js +41 -1
  37. package/core/models/partium-config.js +43 -1
  38. package/core/models/user-token.js +11 -1
  39. package/core/models/user.js +88 -1
  40. package/core/services/backend-status.service.js +147 -1
  41. package/core/services/base-login-init.service.js +57 -1
  42. package/core/services/base.service.js +37 -1
  43. package/core/services/device-status.service.interface.js +117 -1
  44. package/core/services/file.service.interface.js +61 -1
  45. package/core/services/http/file-transfer/file-transfer.service.interface.js +125 -1
  46. package/core/services/http/https-client/https-client.service.interface.js +152 -1
  47. package/core/services/http/https.service.interface.js +294 -1
  48. package/core/services/http/oauth-https.service.js +218 -1
  49. package/core/services/local-storage.service.interface.js +378 -1
  50. package/core/services/log.service.js +139 -1
  51. package/core/services/organization.service.js +202 -1
  52. package/core/services/paginated-request.service.js +160 -1
  53. package/core/services/recent-parts.service.js +194 -1
  54. package/core/services/service-provider.js +114 -1
  55. package/core/services/session/oauth-session.service.js +104 -1
  56. package/core/services/session/session.service.interface.js +367 -1
  57. package/core/utils/general-helper.js +110 -1
  58. package/data/index.js +44 -1
  59. package/data/models/announcement.js +70 -1
  60. package/data/models/assembly-hierarchy-node-breadcrumb.js +51 -1
  61. package/data/models/assembly-hierarchy-node.js +46 -1
  62. package/data/models/attribute.js +106 -1
  63. package/data/models/csa-request-search.js +46 -1
  64. package/data/models/csa-request-status.js +51 -1
  65. package/data/models/csa-request.js +112 -1
  66. package/data/models/document.js +17 -1
  67. package/data/models/filter-key.js +36 -1
  68. package/data/models/filter-option-value.js +41 -1
  69. package/data/models/image.d.ts +6 -1
  70. package/data/models/image.js +77 -1
  71. package/data/models/inquiry.js +71 -1
  72. package/data/models/mounting-location.js +58 -1
  73. package/data/models/multiple-expert-searches.js +40 -1
  74. package/data/models/part-enrichment-data.js +50 -1
  75. package/data/models/part.js +168 -1
  76. package/data/models/shopping-cart.js +60 -1
  77. package/data/services/announcement.service.js +89 -1
  78. package/data/services/assembly-hierarchy-nodes.service.js +193 -1
  79. package/data/services/csa-helper.service.js +158 -1
  80. package/data/services/customer-service-assistance.service.js +276 -1
  81. package/data/services/filter.service.js +97 -1
  82. package/data/services/inquiry.service.js +68 -1
  83. package/data/services/part-attribute.service.js +118 -1
  84. package/data/services/part-enrichment.service.js +56 -1
  85. package/data/services/part.service.js +182 -1
  86. package/data/services/related-parts.service.js +83 -1
  87. package/data/services/shopping-cart.service.js +152 -1
  88. package/find/index.js +51 -1
  89. package/find/models/assets/asset.js +32 -1
  90. package/find/models/search-filter.js +205 -1
  91. package/find/models/search-input.js +3 -1
  92. package/find/models/search-output.js +3 -1
  93. package/find/models/search-result-status.js +40 -1
  94. package/find/models/search-session-log-object.js +22 -1
  95. package/find/models/search-status/cv-search-status.js +22 -1
  96. package/find/models/search-status/search-filter-status.js +36 -1
  97. package/find/models/search-status/search-status.js +56 -1
  98. package/find/models/search-status/tag-search-status.js +23 -1
  99. package/find/models/search-status/text-search-status.js +18 -1
  100. package/find/models/search-tag.js +16 -1
  101. package/find/models/smart-filter.js +49 -1
  102. package/find/models/tagable/i18n-tagable.js +37 -1
  103. package/find/models/tagable/tagable-base.js +22 -1
  104. package/find/models/tagable/tagable.js +37 -1
  105. package/find/models/text-search-config.js +70 -1
  106. package/find/models/text-search-manipulator.js +90 -1
  107. package/find/models/text-search-result-item/text-search-error.js +12 -1
  108. package/find/models/text-search-result-item/text-search-result-item-document.js +34 -1
  109. package/find/models/text-search-result-item/text-search-result-item-part.js +36 -1
  110. package/find/models/text-search-result-item/text-search-result-item-recent-query.js +35 -1
  111. package/find/models/text-search-result-item/text-search-result-item-unknown.js +38 -1
  112. package/find/models/text-search-result-item/text-search-result-item.js +22 -1
  113. package/find/services/asset.service.js +348 -1
  114. package/find/services/filter-uploaders/filter-uploader.js +3 -1
  115. package/find/services/filter-uploaders/update-filters-uploader.js +77 -1
  116. package/find/services/filter-uploaders/update-filters.model.js +7 -1
  117. package/find/services/search/cv-search.service.js +214 -1
  118. package/find/services/search/recent-text-search-queries.service.js +260 -1
  119. package/find/services/search/search-result.service.js +539 -1
  120. package/find/services/search/search.service.js +514 -1
  121. package/find/services/search/tag-search.service.js +124 -1
  122. package/find/services/search/text-search.service.js +316 -1
  123. package/find/services/search-filter.service.js +292 -1
  124. package/find/utils/search-helper.js +75 -1
  125. package/gen/sdk-version.d.ts +1 -1
  126. package/gen/sdk-version.js +5 -1
  127. package/index.js +392 -1
  128. package/management/index.js +21 -1
  129. package/management/models/api-key-list-response.js +3 -1
  130. package/management/models/api-key-type.js +9 -1
  131. package/management/models/api-key.js +3 -1
  132. package/management/services/api-key.service.js +53 -1
  133. package/ocr/index.js +20 -1
  134. package/ocr/models/detect-response.js +3 -1
  135. package/ocr/models/detected-text-entry.js +3 -1
  136. package/ocr/services/ocr.service.js +59 -1
  137. package/package.json +1 -1
  138. package/user-data/index.js +21 -1
  139. package/user-data/models/part-with-nullable.js +3 -1
  140. package/user-data/models/request-list/request-list.js +63 -1
  141. package/user-data/services/favorite/favorite.service.js +108 -1
  142. package/user-data/services/request-list/request-list.service.js +133 -1
@@ -1,2 +1,125 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
2
- "use strict";var __extends=this&&this.__extends||function(){var e=function(r,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},e(r,t)};return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}}(),__assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var r,t=1,o=arguments.length;t<o;t++)for(var s in r=arguments[t])Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s]);return e},__assign.apply(this,arguments)},__decorate=this&&this.__decorate||function(e,r,t,o){var s,c=arguments.length,i=c<3?r:null===o?o=Object.getOwnPropertyDescriptor(r,t):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,r,t,o);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(i=(c<3?s(i):c>3?s(r,t,i):s(r,t))||i);return c>3&&i&&Object.defineProperty(r,t,i),i},__spreadArray=this&&this.__spreadArray||function(e,r,t){if(t||2===arguments.length)for(var o,s=0,c=r.length;s<c;s++)!o&&s in r||(o||(o=Array.prototype.slice.call(r,0,s)),o[s]=r[s]);return e.concat(o||Array.prototype.slice.call(r))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.TagSearchServiceImpl=void 0;var rxjs_1=require("rxjs"),text_search_service_1=require("./text-search.service"),operators_1=require("rxjs/operators"),injection_identifier_1=require("../../../core/decorators/injection-identifier"),base_service_1=require("../../../core/services/base.service"),log_service_1=require("../../../core/services/log.service"),core_1=require("../../../core"),TagSearchServiceImpl=function(e){function r(r){var t=e.call(this,r)||this;return t.proposedSearchTagsSub=new rxjs_1.BehaviorSubject([]),t}return __extends(r,e),r.prototype.onCreate=function(){this.textSearchService=this.serviceProvider.getService(text_search_service_1.TextSearchServiceImpl),this.logService=this.serviceProvider.getService(log_service_1.LogServiceImpl)},r.prototype.getProposedSearchTags=function(){return this.proposedSearchTagsSub.asObservable()},r.prototype.updateProposedTags=function(e){this.tagSearchStatus.proposedSearchTags=__spreadArray([],e,!0),this.proposedSearchTagsSub.next(__spreadArray([],e,!0))},r.prototype.reset=function(e){this.searchStatus=e,this.tagSearchStatus=e.tagSearchStatus,this.proposedSearchTagsSub.next([])},r.prototype.addSearchTag=function(e,r,t){var o,s=this,c="";return(o=t||this.searchStatus.textSearchStatus.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC])?(c=o.trim(),c="".concat(c," ").concat(e.value)):c=e.value,this.logService.logEvent(new core_1.EventLog({version:core_1.EVENTLOG_VERSIONS.V_2_0_0,organizationId:this.searchStatus.searchDomainId,interface:(null==r?void 0:r.eventInterface)||core_1.INTERFACE.API_ACCESS,event:core_1.EVENT.SEARCH_INPUT_SEMANTIC_TAGS,data:{searchSessionId:this.searchStatus.searchSessionID,value:e.value,score:e.score}})).subscribe((function(){}),(function(e){console.log("Error while sending log event: ",e)})),this.textSearchService.getSearchQueries().pipe((0,operators_1.take)(1),(0,operators_1.mergeMap)((function(e){var r;return s.textSearchService.performTextSearch(__assign(__assign({},e),((r={})[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC]=c,r)))})))},r=__decorate([(0,injection_identifier_1.InjectionIdentifier)("TagSearchService")],r)}(base_service_1.BaseService);exports.TagSearchServiceImpl=TagSearchServiceImpl;
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
37
+ if (ar || !(i in from)) {
38
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
39
+ ar[i] = from[i];
40
+ }
41
+ }
42
+ return to.concat(ar || Array.prototype.slice.call(from));
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.TagSearchServiceImpl = void 0;
46
+ var rxjs_1 = require("rxjs");
47
+ var text_search_service_1 = require("./text-search.service");
48
+ var operators_1 = require("rxjs/operators");
49
+ var injection_identifier_1 = require("../../../core/decorators/injection-identifier");
50
+ var base_service_1 = require("../../../core/services/base.service");
51
+ var log_service_1 = require("../../../core/services/log.service");
52
+ var core_1 = require("../../../core");
53
+ var TagSearchServiceImpl = /** @class */ (function (_super) {
54
+ __extends(TagSearchServiceImpl, _super);
55
+ function TagSearchServiceImpl(serviceProvider) {
56
+ var _this = _super.call(this, serviceProvider) || this;
57
+ _this.proposedSearchTagsSub = new rxjs_1.BehaviorSubject([]);
58
+ return _this;
59
+ }
60
+ TagSearchServiceImpl.prototype.onCreate = function () {
61
+ this.textSearchService = this.serviceProvider.getService(text_search_service_1.TextSearchServiceImpl);
62
+ this.logService = this.serviceProvider.getService(log_service_1.LogServiceImpl);
63
+ };
64
+ TagSearchServiceImpl.prototype.getProposedSearchTags = function () {
65
+ return this.proposedSearchTagsSub.asObservable();
66
+ };
67
+ TagSearchServiceImpl.prototype.updateProposedTags = function (searchTags) {
68
+ this.tagSearchStatus.proposedSearchTags = __spreadArray([], searchTags, true);
69
+ this.proposedSearchTagsSub.next(__spreadArray([], searchTags, true));
70
+ };
71
+ /**
72
+ * Reset the search-tag service. Called when a new search session is created.
73
+ *
74
+ * @param searchStatus the search status object of the new search session.
75
+ */
76
+ TagSearchServiceImpl.prototype.reset = function (searchStatus) {
77
+ this.searchStatus = searchStatus;
78
+ this.tagSearchStatus = searchStatus.tagSearchStatus;
79
+ this.proposedSearchTagsSub.next([]);
80
+ };
81
+ TagSearchServiceImpl.prototype.addSearchTag = function (searchTag, tagSearchEventContext, customQuery) {
82
+ var _this = this;
83
+ var query;
84
+ var updatedQuery = '';
85
+ if (customQuery) {
86
+ query = customQuery;
87
+ }
88
+ else {
89
+ query = this.searchStatus.textSearchStatus.searchQueries[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC];
90
+ }
91
+ if (query) {
92
+ updatedQuery = query.trim(); // remove leading and tailing blanks
93
+ updatedQuery = "".concat(updatedQuery, " ").concat(searchTag.value); // append tag
94
+ }
95
+ else {
96
+ // query empty -> use tag only
97
+ updatedQuery = searchTag.value;
98
+ }
99
+ this.logService
100
+ .logEvent(new core_1.EventLog({
101
+ version: core_1.EVENTLOG_VERSIONS.V_2_0_0,
102
+ organizationId: this.searchStatus.searchDomainId, // the searchDomainId is the same as the organizationId
103
+ interface: (tagSearchEventContext === null || tagSearchEventContext === void 0 ? void 0 : tagSearchEventContext.eventInterface) || core_1.INTERFACE.API_ACCESS,
104
+ event: core_1.EVENT.SEARCH_INPUT_SEMANTIC_TAGS,
105
+ data: {
106
+ searchSessionId: this.searchStatus.searchSessionID,
107
+ value: searchTag.value,
108
+ score: searchTag.score,
109
+ },
110
+ }))
111
+ .subscribe(function () { }, function (error) {
112
+ console.log('Error while sending log event: ', error);
113
+ });
114
+ return this.textSearchService.getSearchQueries().pipe((0, operators_1.take)(1), (0, operators_1.mergeMap)(function (queries) {
115
+ var _a;
116
+ return _this.textSearchService.performTextSearch(__assign(__assign({}, queries), (_a = {}, _a[text_search_service_1.TEXT_SEARCH_TYPE.SEMANTIC] = updatedQuery, _a)));
117
+ }));
118
+ };
119
+ TagSearchServiceImpl = __decorate([
120
+ (0, injection_identifier_1.InjectionIdentifier)('TagSearchService')
121
+ ], TagSearchServiceImpl);
122
+ return TagSearchServiceImpl;
123
+ }(base_service_1.BaseService));
124
+ exports.TagSearchServiceImpl = TagSearchServiceImpl;
125
+ //# sourceMappingURL=tag-search.service.js.map
@@ -1,2 +1,317 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
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,c=arguments.length,i=c<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,s);else for(var n=e.length-1;n>=0;n--)(a=e[n])&&(i=(c<3?a(i):c>3?a(t,r,i):a(t,r))||i);return c>3&&i&&Object.defineProperty(t,r,i),i};Object.defineProperty(exports,"__esModule",{value:!0}),exports.TextSearchServiceImpl=exports.TEXT_SEARCH_TYPE=void 0;var TEXT_SEARCH_TYPE,rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),text_search_manipulator_1=require("../../models/text-search-manipulator"),text_search_result_item_unknown_1=require("../../models/text-search-result-item/text-search-result-item-unknown"),text_search_result_item_recent_query_1=require("../../models/text-search-result-item/text-search-result-item-recent-query"),text_search_result_item_part_1=require("../../models/text-search-result-item/text-search-result-item-part"),_=require("lodash"),text_search_config_1=require("../../models/text-search-config"),search_result_service_1=require("./search-result.service"),text_search_result_item_document_1=require("../../models/text-search-result-item/text-search-result-item-document"),recent_text_search_queries_service_1=require("./recent-text-search-queries.service"),https_service_interface_1=require("../../../core/services/http/https.service.interface"),injection_identifier_1=require("../../../core/decorators/injection-identifier"),base_service_1=require("../../../core/services/base.service"),part_1=require("../../../data/models/part"),i18n_string_1=require("../../../core/models/i18n-string"),document_1=require("../../../data/models/document"),FIELDS_PER_DOMAIN={};FIELDS_PER_DOMAIN[text_search_config_1.SEARCH_DOMAINS.PART]=["full_text.*"],FIELDS_PER_DOMAIN[text_search_config_1.SEARCH_DOMAINS.DOCUMENT]=["name","name.ngram","attachment.content"],function(e){e.SEMANTIC="semanticText",e.EXACT="exactText"}(TEXT_SEARCH_TYPE||(exports.TEXT_SEARCH_TYPE=TEXT_SEARCH_TYPE={}));var TextSearchServiceImpl=function(e){function t(t){var r,s=e.call(this,t)||this;return s.skipAutoTextSearchAfterLoadingEventFlag=!1,s.temporarySearchResult$=new rxjs_1.BehaviorSubject(null),s.currentSearchQuery$=new rxjs_1.BehaviorSubject(null),s.curTextSearchQueries$=new rxjs_1.BehaviorSubject(((r={})[TEXT_SEARCH_TYPE.SEMANTIC]="",r[TEXT_SEARCH_TYPE.EXACT]="",r)),s.externalTempSearchResultManipulator=new text_search_manipulator_1.TextSearchManipulatorDoNothing,s}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.recentTextSearchQueriesService=this.serviceProvider.getService(recent_text_search_queries_service_1.RecentTextSearchQueriesServiceImpl),this.subscribeSearchChanges()},t.prototype.reset=function(e){var t;this.searchStatus=e,this.textSearchStatus=e.textSearchStatus,this.currentSearchQuery$.next(null),this.curTextSearchQueries$.next(((t={})[TEXT_SEARCH_TYPE.SEMANTIC]="",t[TEXT_SEARCH_TYPE.EXACT]="",t))},t.prototype.setStatusExternal=function(e,t,r,s){this.searchStatus=e,this.textSearchStatus=e.textSearchStatus,this.setTextQueries(s),this.skipAutoTextSearchAfterLoadingEventFlag=!0},t.prototype.setTextQueries=function(e){e&&(this.textSearchStatus.searchQueries=e,this.curTextSearchQueries$.next(e))},t.prototype.performTextSearch=function(e,t){var r,s=this;return void 0===t&&(t=!1),this.textSearchStatus.searchQueries=e,this.curTextSearchQueries$.next(e),this.httpsService.patch("search/".concat(this.searchStatus.searchSessionID),{method:"textSearch",options:{textSearch:(r={},r[TEXT_SEARCH_TYPE.SEMANTIC]=e[TEXT_SEARCH_TYPE.SEMANTIC]||"",r[TEXT_SEARCH_TYPE.EXACT]=e[TEXT_SEARCH_TYPE.EXACT]||"",r)}}).pipe((0,operators_1.tap)((function(){if(!t){var r=e[TEXT_SEARCH_TYPE.SEMANTIC],a=e[TEXT_SEARCH_TYPE.EXACT];r&&s.recentTextSearchQueriesService.addSemanticTextQuery(r),a&&s.recentTextSearchQueriesService.addExactTextQuery(a)}s.searchResultService.startPollingForResults()})))},t.prototype.getSearchQueries=function(){return this.curTextSearchQueries$.asObservable()},t.prototype.subscribeSearchChanges=function(){var e=this;this.currentSearchQuery$.pipe((0,operators_1.filter)((function(t){var r=e.skipAutoTextSearchAfterLoadingEventFlag;return e.skipAutoTextSearchAfterLoadingEventFlag=!1,!r})),(0,operators_1.debounceTime)(100),(0,operators_1.distinctUntilChanged)(),(0,operators_1.switchMap)((function(t){var r=t;return e.performQuickTextSearch(t).pipe((0,operators_1.catchError)((function(t){return console.log("Search error: ",t),e.temporarySearchResult$.next({query:r,error:t}),(0,rxjs_1.of)(void 0)})))}))).subscribe((function(t){t?e.temporarySearchResult$.next(t):e.temporarySearchResult$.next({query:null,result:[]})}),(function(e){console.log("TextSearch error: ",e)}))},t.prototype.performQuickTextSearch=function(e){var t=this;return(0,rxjs_1.of)({query:e,result:[]}).pipe((0,operators_1.mergeMap)((function(r){var s,a,c,i=null===(c=null===(a=null===(s=t.textSearchStatus)||void 0===s?void 0:s.searchConfig)||void 0===a?void 0:a.temporarySearch)||void 0===c?void 0:c.includes(text_search_config_1.TEMPORARY_SEARCH_TYPE.QUICK_TEXT_SEARCH);return e&&e.length>0&&i?t.httpsService.post("search/".concat(t.searchStatus.searchSessionID),t.getElasticSearchObject(e)).pipe((0,operators_1.map)((function(t){var r=[];if(t.results){var s=Object.keys(t.results);return _.forEach(s,(function(e){"entities"===e?_.forEach(t.results[e],(function(e){r.push(new text_search_result_item_part_1.TextSearchResultItemPart(new part_1.Part({name:new i18n_string_1.i18nString(e.name),partiumId:e.partiumId,externalId:e.externalId,externalPayload:e.externalPayload,dataOrigin:part_1.DATA_ORIGIN.PARTIAL}),e.confidence))})):"documents"===e?_.forEach(t.results[e],(function(e){r.push(new text_search_result_item_document_1.TextSearchResultItemDocument(new document_1.Document({name:e.name,partiumId:e.partiumId,externalId:e.externalId,externalPayload:e.externalPayload}),e.confidence))})):_.forEach(t.results[e],(function(t){r.push(new text_search_result_item_unknown_1.TextSearchResultItemUnknown(t,t.confidence,e))}))})),r=_.orderBy(r,["confidence"],["desc"]),{query:e,result:r}}})),(0,operators_1.mergeMap)((function(e){return(0,rxjs_1.from)(t.externalTempSearchResultManipulator.textSearchResultManipulatorFunction(e))}))):(0,rxjs_1.of)(r)})),(0,operators_1.mergeMap)((function(e){var r,s,a;return(null===(a=null===(s=null===(r=t.textSearchStatus)||void 0===r?void 0:r.searchConfig)||void 0===s?void 0:s.temporarySearch)||void 0===a?void 0:a.includes(text_search_config_1.TEMPORARY_SEARCH_TYPE.RECENT_SEARCH_QUERIES))?t.recentTextSearchQueriesService.getQueries().pipe((0,operators_1.first)(),(0,operators_1.map)((function(t){var r;return(r=e.result).push.apply(r,t.map((function(e){return new text_search_result_item_recent_query_1.TextSearchResultItemRecentQuery(e,1)}))),e}))):(0,rxjs_1.of)(e)})))},t.prototype.getElasticSearchObject=function(e){var t=this;return{textSearch:{searchObjects:this.textSearchStatus.searchConfig.domains.map((function(r){return{type:t.textSearchStatus.searchConfig.searchType,options:__assign({skip:0,limit:t.textSearchStatus.searchConfig.limit,domain:r,fields:t.getElasticSearchFields(r),searchTerm:e},t.textSearchStatus.searchConfig.searchType===text_search_config_1.SEARCH_TYPE.FUZZY&&{fuzziness:t.textSearchStatus.searchConfig.fuzziness})}}))}}},t.prototype.getElasticSearchFields=function(e){return e===text_search_config_1.SEARCH_DOMAINS.PART&&this.searchStatus.searchLanguage?["full_text.".concat(this.searchStatus.searchLanguage)]:FIELDS_PER_DOMAIN[e]},t=__decorate([(0,injection_identifier_1.InjectionIdentifier)("TextSearchService")],t)}(base_service_1.BaseService);exports.TextSearchServiceImpl=TextSearchServiceImpl;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TextSearchServiceImpl = exports.TEXT_SEARCH_TYPE = void 0;
37
+ var rxjs_1 = require("rxjs");
38
+ var operators_1 = require("rxjs/operators");
39
+ var text_search_manipulator_1 = require("../../models/text-search-manipulator");
40
+ var text_search_result_item_unknown_1 = require("../../models/text-search-result-item/text-search-result-item-unknown");
41
+ var text_search_result_item_recent_query_1 = require("../../models/text-search-result-item/text-search-result-item-recent-query");
42
+ var text_search_result_item_part_1 = require("../../models/text-search-result-item/text-search-result-item-part");
43
+ var _ = require("lodash");
44
+ var text_search_config_1 = require("../../models/text-search-config");
45
+ var search_result_service_1 = require("./search-result.service");
46
+ var text_search_result_item_document_1 = require("../../models/text-search-result-item/text-search-result-item-document");
47
+ var recent_text_search_queries_service_1 = require("./recent-text-search-queries.service");
48
+ var https_service_interface_1 = require("../../../core/services/http/https.service.interface");
49
+ var injection_identifier_1 = require("../../../core/decorators/injection-identifier");
50
+ var base_service_1 = require("../../../core/services/base.service");
51
+ var part_1 = require("../../../data/models/part");
52
+ var i18n_string_1 = require("../../../core/models/i18n-string");
53
+ var document_1 = require("../../../data/models/document");
54
+ var FIELDS_PER_DOMAIN = {};
55
+ FIELDS_PER_DOMAIN[text_search_config_1.SEARCH_DOMAINS.PART] = ['full_text.*'];
56
+ FIELDS_PER_DOMAIN[text_search_config_1.SEARCH_DOMAINS.DOCUMENT] = ['name', 'name.ngram', 'attachment.content'];
57
+ var TEXT_SEARCH_TYPE;
58
+ (function (TEXT_SEARCH_TYPE) {
59
+ TEXT_SEARCH_TYPE["SEMANTIC"] = "semanticText";
60
+ TEXT_SEARCH_TYPE["EXACT"] = "exactText";
61
+ })(TEXT_SEARCH_TYPE || (exports.TEXT_SEARCH_TYPE = TEXT_SEARCH_TYPE = {}));
62
+ var TextSearchServiceImpl = /** @class */ (function (_super) {
63
+ __extends(TextSearchServiceImpl, _super);
64
+ function TextSearchServiceImpl(serviceProvider) {
65
+ var _a;
66
+ var _this = _super.call(this, serviceProvider) || this;
67
+ // flag which is used to skip the initial triggering of a temporary-text-search after loading an old search session
68
+ _this.skipAutoTextSearchAfterLoadingEventFlag = false;
69
+ _this.temporarySearchResult$ = new rxjs_1.BehaviorSubject(null);
70
+ _this.currentSearchQuery$ = new rxjs_1.BehaviorSubject(null);
71
+ _this.curTextSearchQueries$ = new rxjs_1.BehaviorSubject((_a = {},
72
+ _a[TEXT_SEARCH_TYPE.SEMANTIC] = '',
73
+ _a[TEXT_SEARCH_TYPE.EXACT] = '',
74
+ _a));
75
+ _this.externalTempSearchResultManipulator = new text_search_manipulator_1.TextSearchManipulatorDoNothing(); // do nothing
76
+ return _this;
77
+ }
78
+ TextSearchServiceImpl.prototype.onCreate = function () {
79
+ this.httpsService = this.serviceProvider.getService(https_service_interface_1.HttpsService);
80
+ this.searchResultService = this.serviceProvider.getService(search_result_service_1.SearchResultService);
81
+ this.recentTextSearchQueriesService = this.serviceProvider.getService(recent_text_search_queries_service_1.RecentTextSearchQueriesServiceImpl);
82
+ this.subscribeSearchChanges();
83
+ };
84
+ TextSearchServiceImpl.prototype.reset = function (searchStatus) {
85
+ var _a;
86
+ this.searchStatus = searchStatus;
87
+ this.textSearchStatus = searchStatus.textSearchStatus;
88
+ this.currentSearchQuery$.next(null);
89
+ this.curTextSearchQueries$.next((_a = {},
90
+ _a[TEXT_SEARCH_TYPE.SEMANTIC] = '',
91
+ _a[TEXT_SEARCH_TYPE.EXACT] = '',
92
+ _a));
93
+ };
94
+ /**
95
+ * Set the text-search-status to a certain status.
96
+ * This can happen if an old search-session is loaded or a change of the search-input
97
+ * was initiated on the backend-side.
98
+ *
99
+ * @param searchStatus the search-status object
100
+ * @param query the query of the old session
101
+ * @param searchConfig the search-config of the old session (if null => use default)
102
+ * @param textSearchStatus the textSearchStatus containing exact and semantic searches
103
+ */
104
+ TextSearchServiceImpl.prototype.setStatusExternal = function (searchStatus, query, searchConfig, textSearchQueries) {
105
+ this.searchStatus = searchStatus;
106
+ this.textSearchStatus = searchStatus.textSearchStatus;
107
+ this.setTextQueries(textSearchQueries);
108
+ this.skipAutoTextSearchAfterLoadingEventFlag = true;
109
+ };
110
+ TextSearchServiceImpl.prototype.setTextQueries = function (textSearchQueries) {
111
+ if (textSearchQueries) {
112
+ this.textSearchStatus.searchQueries = textSearchQueries;
113
+ this.curTextSearchQueries$.next(textSearchQueries);
114
+ }
115
+ };
116
+ TextSearchServiceImpl.prototype.performTextSearch = function (textSearchQueries, skipAddingToRecentQueries) {
117
+ var _a;
118
+ var _this = this;
119
+ if (skipAddingToRecentQueries === void 0) { skipAddingToRecentQueries = false; }
120
+ this.textSearchStatus.searchQueries = textSearchQueries;
121
+ this.curTextSearchQueries$.next(textSearchQueries);
122
+ // this function is only available for find-backend version 4. Throw error, if lower than 4
123
+ return this.httpsService.patch("search/".concat(this.searchStatus.searchSessionID), {
124
+ method: 'textSearch',
125
+ options: {
126
+ textSearch: (_a = {},
127
+ _a[TEXT_SEARCH_TYPE.SEMANTIC] = textSearchQueries[TEXT_SEARCH_TYPE.SEMANTIC] || '',
128
+ _a[TEXT_SEARCH_TYPE.EXACT] = textSearchQueries[TEXT_SEARCH_TYPE.EXACT] || '',
129
+ _a),
130
+ },
131
+ })
132
+ .pipe((0, operators_1.tap)(function () {
133
+ if (!skipAddingToRecentQueries) {
134
+ var semanticText = textSearchQueries[TEXT_SEARCH_TYPE.SEMANTIC];
135
+ var exactText = textSearchQueries[TEXT_SEARCH_TYPE.EXACT];
136
+ if (semanticText) {
137
+ _this.recentTextSearchQueriesService.addSemanticTextQuery(semanticText); // add semantic text query to recent queries
138
+ }
139
+ if (exactText) {
140
+ _this.recentTextSearchQueriesService.addExactTextQuery(exactText); // add exact text query to recent queries
141
+ }
142
+ }
143
+ _this.searchResultService.startPollingForResults(); // automatically start polling for results (will be ended in searchservice, when results have arrived)
144
+ }));
145
+ };
146
+ TextSearchServiceImpl.prototype.getSearchQueries = function () {
147
+ return this.curTextSearchQueries$.asObservable();
148
+ };
149
+ /**
150
+ *
151
+ * Handle currentSearchQuery$ changes.
152
+ * Only the latest request is processed and only if it really changed (distinctUntilChanged)
153
+ * Similarily, the search filters stream is merged with the query change stream and it fires every time one of the streams emits
154
+ * https://angular-2-training-book.rangle.io/http/search_with_switchmap
155
+ * https://stackoverflow.com/questions/53432096/observables-cancel-previous-http-request-on-new-subscription-call
156
+ */
157
+ TextSearchServiceImpl.prototype.subscribeSearchChanges = function () {
158
+ var _this = this;
159
+ this.currentSearchQuery$
160
+ .pipe((0, operators_1.filter)(function (_searchText) {
161
+ // when loading an old search-session, the quick-text-search should not be executed, unless the query is changed again
162
+ var skip = _this.skipAutoTextSearchAfterLoadingEventFlag;
163
+ _this.skipAutoTextSearchAfterLoadingEventFlag = false;
164
+ return !skip;
165
+ }), (0, operators_1.debounceTime)(100), (0, operators_1.distinctUntilChanged)(), (0, operators_1.switchMap)(function (searchText) {
166
+ var curQuery = searchText;
167
+ // keep main stream alive by catching in inner pipe
168
+ return _this.performQuickTextSearch(searchText).pipe((0, operators_1.catchError)(function (err) {
169
+ console.log('Search error: ', err);
170
+ _this.temporarySearchResult$.next({
171
+ query: curQuery,
172
+ error: err,
173
+ });
174
+ return (0, rxjs_1.of)(undefined);
175
+ }));
176
+ }))
177
+ .subscribe(function (res) {
178
+ if (res) {
179
+ _this.temporarySearchResult$.next(res);
180
+ }
181
+ else {
182
+ _this.temporarySearchResult$.next({
183
+ query: null,
184
+ result: [],
185
+ });
186
+ }
187
+ }, function (err) {
188
+ console.log('TextSearch error: ', err);
189
+ });
190
+ };
191
+ /**
192
+ * Sends the quick text search request to the backend and return the result as observable
193
+ *
194
+ * @deprecated quick text search is deprecated and will be replaced in the future
195
+ *
196
+ * @param query the current temporary search query
197
+ */
198
+ TextSearchServiceImpl.prototype.performQuickTextSearch = function (query) {
199
+ var _this = this;
200
+ return (0, rxjs_1.of)({
201
+ query: query,
202
+ result: [],
203
+ }).pipe((0, operators_1.mergeMap)(function (res) {
204
+ var _a, _b, _c;
205
+ // perform backend-quick-search if enabled
206
+ var quickTextSearchEnabled = (_c = (_b = (_a = _this.textSearchStatus) === null || _a === void 0 ? void 0 : _a.searchConfig) === null || _b === void 0 ? void 0 : _b.temporarySearch) === null || _c === void 0 ? void 0 : _c.includes(text_search_config_1.TEMPORARY_SEARCH_TYPE.QUICK_TEXT_SEARCH);
207
+ if (query && query.length > 0 && quickTextSearchEnabled) {
208
+ return _this.httpsService
209
+ .post("search/".concat(_this.searchStatus.searchSessionID), _this.getElasticSearchObject(query))
210
+ .pipe((0, operators_1.map)(function (res) {
211
+ var resultItems = [];
212
+ if (res.results) {
213
+ var keys = Object.keys(res.results);
214
+ _.forEach(keys, function (key) {
215
+ if (key === 'entities') {
216
+ _.forEach(res.results[key], function (part) {
217
+ resultItems.push(new text_search_result_item_part_1.TextSearchResultItemPart(new part_1.Part({
218
+ name: new i18n_string_1.i18nString(part.name),
219
+ // description: new i18nString(item.part.description),
220
+ // images: item.part.images,
221
+ partiumId: part.partiumId,
222
+ externalId: part.externalId,
223
+ externalPayload: part.externalPayload,
224
+ dataOrigin: part_1.DATA_ORIGIN.PARTIAL,
225
+ }), part.confidence));
226
+ });
227
+ }
228
+ else if (key === 'documents') {
229
+ _.forEach(res.results[key], function (document) {
230
+ resultItems.push(new text_search_result_item_document_1.TextSearchResultItemDocument(new document_1.Document({
231
+ name: document.name,
232
+ partiumId: document.partiumId,
233
+ externalId: document.externalId,
234
+ externalPayload: document.externalPayload,
235
+ }), document.confidence));
236
+ });
237
+ }
238
+ else {
239
+ // SDK currently only knows search-results of type Part adn Document, all others are Unknown and can be replaced by the app using the sdk
240
+ _.forEach(res.results[key], function (item) {
241
+ resultItems.push(new text_search_result_item_unknown_1.TextSearchResultItemUnknown(item, item.confidence, key));
242
+ });
243
+ }
244
+ });
245
+ // sort all entries by confidence
246
+ resultItems = _.orderBy(resultItems, ['confidence'], ['desc']);
247
+ return {
248
+ query: query,
249
+ result: resultItems,
250
+ };
251
+ }
252
+ }), (0, operators_1.mergeMap)(function (res) {
253
+ return (0, rxjs_1.from)(_this.externalTempSearchResultManipulator.textSearchResultManipulatorFunction(res));
254
+ }));
255
+ }
256
+ else {
257
+ return (0, rxjs_1.of)(res);
258
+ }
259
+ }), (0, operators_1.mergeMap)(function (res) {
260
+ var _a, _b, _c;
261
+ // append recent queries if enabled
262
+ var recentSearchQueriesEnabled = (_c = (_b = (_a = _this.textSearchStatus) === null || _a === void 0 ? void 0 : _a.searchConfig) === null || _b === void 0 ? void 0 : _b.temporarySearch) === null || _c === void 0 ? void 0 : _c.includes(text_search_config_1.TEMPORARY_SEARCH_TYPE.RECENT_SEARCH_QUERIES);
263
+ if (recentSearchQueriesEnabled) {
264
+ return _this.recentTextSearchQueriesService.getQueries().pipe((0, operators_1.first)(), (0, operators_1.map)(function (recentQueries) {
265
+ var _a;
266
+ (_a = res.result).push.apply(_a, recentQueries.map(function (query) { return new text_search_result_item_recent_query_1.TextSearchResultItemRecentQuery(query, 1); }));
267
+ return res;
268
+ }));
269
+ }
270
+ else {
271
+ return (0, rxjs_1.of)(res);
272
+ }
273
+ }));
274
+ };
275
+ /**
276
+ * Builds search-object for elastic-search that is sent with the request.
277
+ *
278
+ * @param query the query to search for
279
+ * @param domains the domains to search in
280
+ */
281
+ TextSearchServiceImpl.prototype.getElasticSearchObject = function (query) {
282
+ var _this = this;
283
+ return {
284
+ textSearch: {
285
+ searchObjects: this.textSearchStatus.searchConfig.domains.map(function (domain) {
286
+ var outSearchObject = {
287
+ // PPD-469: performs search where query length is equal or smaller to fuzziness value with EXACT search, to avoid meaningless results
288
+ type: _this.textSearchStatus.searchConfig.searchType,
289
+ options: __assign({ skip: 0, limit: _this.textSearchStatus.searchConfig.limit, domain: domain, fields: _this.getElasticSearchFields(domain), searchTerm: query }, (_this.textSearchStatus.searchConfig.searchType === text_search_config_1.SEARCH_TYPE.FUZZY && {
290
+ fuzziness: _this.textSearchStatus.searchConfig.fuzziness,
291
+ })),
292
+ };
293
+ return outSearchObject;
294
+ }),
295
+ },
296
+ };
297
+ };
298
+ /**
299
+ * returns the search fields to use in the ElasticSearchObject
300
+ *
301
+ * @param domain domain option (e.g. part or document)
302
+ * @returns fields to search in
303
+ */
304
+ TextSearchServiceImpl.prototype.getElasticSearchFields = function (domain) {
305
+ if (domain === text_search_config_1.SEARCH_DOMAINS.PART && this.searchStatus.searchLanguage) {
306
+ // for parts we use the language of the search session if it is defined to improve quicktext search
307
+ return ["full_text.".concat(this.searchStatus.searchLanguage)];
308
+ }
309
+ return FIELDS_PER_DOMAIN[domain];
310
+ };
311
+ TextSearchServiceImpl = __decorate([
312
+ (0, injection_identifier_1.InjectionIdentifier)('TextSearchService')
313
+ ], TextSearchServiceImpl);
314
+ return TextSearchServiceImpl;
315
+ }(base_service_1.BaseService));
316
+ exports.TextSearchServiceImpl = TextSearchServiceImpl;
317
+ //# sourceMappingURL=text-search.service.js.map