@partium/js-sdk 15.20.0 → 16.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.
- package/core/constants/constants.d.ts +2 -2
- package/core/constants/constants.js +1 -1
- package/core/index.d.ts +2 -2
- package/core/index.js +1 -1
- package/core/integration-defaults/http/https-client/axios-https-client.service.d.ts +5 -0
- package/core/integration-defaults/http/https-client/axios-https-client.service.js +1 -1
- package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +1 -1
- package/core/integration-defaults/session/js-oauth-api-key-session.service.js +1 -1
- package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +1 -1
- package/core/integration-defaults/session/js-oauth-web-cookie-session.service.js +1 -1
- package/core/models/log.d.ts +3 -1
- package/core/models/log.js +1 -1
- package/core/models/user.d.ts +7 -43
- package/core/models/user.js +1 -1
- package/core/services/http/https.service.interface.d.ts +20 -20
- package/core/services/http/https.service.interface.js +1 -1
- package/core/services/http/oauth-https.service.d.ts +3 -3
- package/core/services/local-storage.service.interface.d.ts +1 -1
- package/core/services/log.service.d.ts +1 -1
- package/core/services/organization/index.d.ts +6 -0
- package/core/services/organization/index.js +2 -0
- package/core/services/organization/models/get-organization-by-id-request.d.ts +10 -0
- package/core/services/organization/models/get-organization-by-name-request.d.ts +10 -0
- package/core/services/organization/models/get-organizations-request.d.ts +33 -0
- package/core/services/organization/models/get-organizations-request.js +2 -0
- package/core/services/organization/models/organization.d.ts +77 -0
- package/core/services/organization/models/organization.js +2 -0
- package/core/services/organization/organization.service.d.ts +81 -0
- package/core/services/organization/organization.service.js +2 -0
- package/core/services/recent-parts.service.d.ts +1 -1
- package/core/services/session/session.service.interface.d.ts +17 -5
- package/core/services/session/session.service.interface.js +1 -1
- package/core/utils/general-helper.d.ts +2 -1
- package/core/utils/general-helper.js +1 -1
- package/core/utils/multipart-upload.helper.d.ts +20 -0
- package/core/utils/multipart-upload.helper.js +2 -0
- package/data/models/attribute.d.ts +5 -5
- package/data/models/attribute.js +1 -1
- package/data/models/csa-request.d.ts +2 -3
- package/data/models/csa-request.js +1 -1
- package/data/models/image.d.ts +10 -13
- package/data/models/image.js +1 -1
- package/data/models/part-data.d.ts +1 -1
- package/data/models/part.d.ts +13 -9
- package/data/models/part.js +1 -1
- package/data/services/customer-service-assistance.service.d.ts +3 -22
- package/data/services/customer-service-assistance.service.js +1 -1
- package/data/services/data.service.js +1 -1
- package/data/services/filter.service.d.ts +0 -21
- package/data/services/filter.service.js +1 -1
- package/enrichment/models/enrichment-job-part.d.ts +2 -2
- package/enrichment/models/enrichment-job-part.js +1 -1
- package/enrichment/models/enrichment-job.d.ts +2 -2
- package/enrichment/models/enrichment-job.js +1 -1
- package/find/index.d.ts +1 -28
- package/find/index.js +1 -1
- package/find/models/image-crop-area.d.ts +7 -0
- package/find/models/search-input.d.ts +11 -3
- package/find/models/search-input.js +1 -1
- package/find/services/asset.service.d.ts +41 -102
- package/find/services/asset.service.js +1 -1
- package/find/services/search/search.service.d.ts +5 -218
- package/find/services/search/search.service.js +1 -1
- package/gen/sdk-version.d.ts +1 -1
- package/gen/sdk-version.js +1 -1
- package/index.d.ts +16 -8
- package/index.js +1 -1
- package/ocr/index.d.ts +1 -2
- package/ocr/index.js +1 -1
- package/ocr/models/ocr-response.d.ts +5 -0
- package/ocr/models/ocr-response.js +2 -0
- package/ocr/services/ocr.service.d.ts +9 -15
- package/ocr/services/ocr.service.js +1 -1
- package/package.json +1 -1
- package/selection/index.d.ts +17 -0
- package/selection/index.js +2 -0
- package/selection/models/add-all-search-session-parts-to-selection-request.d.ts +4 -0
- package/selection/models/add-all-search-session-parts-to-selection-request.js +2 -0
- package/selection/models/add-all-search-session-parts-to-selection-response.d.ts +5 -0
- package/selection/models/add-all-search-session-parts-to-selection-response.js +2 -0
- package/selection/models/add-parts-from-file-to-selection-request.d.ts +10 -0
- package/selection/models/add-parts-from-file-to-selection-request.js +2 -0
- package/selection/models/add-parts-from-file-to-selection-response.d.ts +33 -0
- package/selection/models/add-parts-from-file-to-selection-response.js +2 -0
- package/selection/models/add-parts-to-selection-request.d.ts +4 -0
- package/selection/models/add-parts-to-selection-request.js +2 -0
- package/selection/models/add-parts-to-selection-response.d.ts +5 -0
- package/selection/models/add-parts-to-selection-response.js +2 -0
- package/selection/models/check-which-parts-in-selection-request.d.ts +4 -0
- package/selection/models/check-which-parts-in-selection-request.js +2 -0
- package/selection/models/check-which-parts-in-selection-response.d.ts +4 -0
- package/selection/models/check-which-parts-in-selection-response.js +2 -0
- package/selection/models/create-selection-request.d.ts +6 -0
- package/selection/models/create-selection-request.js +2 -0
- package/selection/models/create-selection-response.d.ts +10 -0
- package/selection/models/create-selection-response.js +2 -0
- package/selection/models/remove-all-search-session-parts-from-selection-request.d.ts +4 -0
- package/selection/models/remove-all-search-session-parts-from-selection-request.js +2 -0
- package/selection/models/remove-all-search-session-parts-from-selection-response.d.ts +5 -0
- package/selection/models/remove-all-search-session-parts-from-selection-response.js +2 -0
- package/selection/models/remove-parts-from-selection-request.d.ts +4 -0
- package/selection/models/remove-parts-from-selection-request.js +2 -0
- package/selection/models/remove-parts-from-selection-response.d.ts +5 -0
- package/selection/models/remove-parts-from-selection-response.js +2 -0
- package/selection/models/selection-search-summary-response.d.ts +5 -0
- package/selection/models/selection-search-summary-response.js +2 -0
- package/selection/services/selection.service.d.ts +95 -0
- package/selection/services/selection.service.js +2 -0
- package/core/models/organization.d.ts +0 -127
- package/core/models/organization.js +0 -2
- package/core/services/organization.service.d.ts +0 -48
- package/core/services/organization.service.js +0 -2
- package/data/services/csa-helper.service.d.ts +0 -32
- package/data/services/csa-helper.service.js +0 -2
- package/find/models/assets/asset.d.ts +0 -24
- package/find/models/assets/asset.js +0 -2
- package/find/models/search-filter.d.ts +0 -87
- package/find/models/search-filter.js +0 -2
- package/find/models/search-result-status.d.ts +0 -33
- package/find/models/search-result-status.js +0 -2
- package/find/models/search-session-log-object.d.ts +0 -16
- package/find/models/search-session-log-object.js +0 -2
- package/find/models/search-status/cv-search-status.d.ts +0 -20
- package/find/models/search-status/cv-search-status.js +0 -2
- package/find/models/search-status/search-filter-status.d.ts +0 -33
- package/find/models/search-status/search-filter-status.js +0 -2
- package/find/models/search-status/search-status.d.ts +0 -34
- package/find/models/search-status/search-status.js +0 -2
- package/find/models/search-status/tag-search-status.d.ts +0 -16
- package/find/models/search-status/tag-search-status.js +0 -2
- package/find/models/search-status/text-search-status.d.ts +0 -15
- package/find/models/search-status/text-search-status.js +0 -2
- package/find/models/search-tag.d.ts +0 -12
- package/find/models/search-tag.js +0 -2
- package/find/models/tagable/i18n-tagable.d.ts +0 -10
- package/find/models/tagable/i18n-tagable.js +0 -2
- package/find/models/tagable/tagable-base.d.ts +0 -11
- package/find/models/tagable/tagable-base.js +0 -2
- package/find/models/tagable/tagable.d.ts +0 -10
- package/find/models/tagable/tagable.js +0 -2
- package/find/models/text-search-config.d.ts +0 -57
- package/find/models/text-search-config.js +0 -2
- package/find/models/text-search-manipulator.d.ts +0 -46
- package/find/models/text-search-manipulator.js +0 -2
- package/find/models/text-search-result-item/text-search-error.d.ts +0 -7
- package/find/models/text-search-result-item/text-search-error.js +0 -2
- package/find/models/text-search-result-item/text-search-result-item-document.d.ts +0 -10
- package/find/models/text-search-result-item/text-search-result-item-document.js +0 -2
- package/find/models/text-search-result-item/text-search-result-item-part.d.ts +0 -12
- package/find/models/text-search-result-item/text-search-result-item-part.js +0 -2
- package/find/models/text-search-result-item/text-search-result-item-recent-query.d.ts +0 -10
- package/find/models/text-search-result-item/text-search-result-item-recent-query.js +0 -2
- package/find/models/text-search-result-item/text-search-result-item-unknown.d.ts +0 -12
- package/find/models/text-search-result-item/text-search-result-item-unknown.js +0 -2
- package/find/models/text-search-result-item/text-search-result-item.d.ts +0 -16
- package/find/models/text-search-result-item/text-search-result-item.js +0 -2
- package/find/services/filter-uploaders/filter-uploader.d.ts +0 -13
- package/find/services/filter-uploaders/update-filters-uploader.d.ts +0 -17
- package/find/services/filter-uploaders/update-filters-uploader.js +0 -2
- package/find/services/filter-uploaders/update-filters.model.d.ts +0 -19
- package/find/services/filter-uploaders/update-filters.model.js +0 -2
- package/find/services/search/cv-search.service.d.ts +0 -103
- package/find/services/search/cv-search.service.js +0 -2
- package/find/services/search/search-result.service.d.ts +0 -142
- package/find/services/search/search-result.service.js +0 -2
- package/find/services/search/tag-search.service.d.ts +0 -66
- package/find/services/search/tag-search.service.js +0 -2
- package/find/services/search/text-search.service.d.ts +0 -116
- package/find/services/search/text-search.service.js +0 -2
- package/find/services/search-filter.service.d.ts +0 -223
- package/find/services/search-filter.service.js +0 -2
- package/find/utils/search-helper.d.ts +0 -14
- package/find/utils/search-helper.js +0 -2
- package/ocr/models/detect-response.d.ts +0 -5
- package/ocr/models/detected-text-entry.d.ts +0 -5
- /package/{find/services/filter-uploaders/filter-uploader.js → core/services/organization/models/get-organization-by-id-request.js} +0 -0
- /package/{ocr/models/detect-response.js → core/services/organization/models/get-organization-by-name-request.js} +0 -0
- /package/{ocr/models/detected-text-entry.js → find/models/image-crop-area.js} +0 -0
|
@@ -6,155 +6,94 @@ import { BaseLoginInitService } from '../../core/services/base-login-init.servic
|
|
|
6
6
|
import { DownloadStatus } from '../../core/services/http/file-transfer/file-transfer.service.interface';
|
|
7
7
|
import { BACKEND_SERVICE } from '../../core/services/http/https.service.interface';
|
|
8
8
|
import { ServiceProvider } from '../../core/services/service-provider';
|
|
9
|
-
import { Asset } from '../models/assets/asset';
|
|
10
9
|
import { EventContext, Organization } from '../../core';
|
|
11
10
|
export interface AssetEventContext extends EventContext {
|
|
11
|
+
/** Organization id used for V2 event logging (e.g. image-dimensions log). */
|
|
12
|
+
organizationId: string;
|
|
12
13
|
searchSessionId?: string;
|
|
13
14
|
}
|
|
15
|
+
export interface ImageUploadApiResponse {
|
|
16
|
+
assetId: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ImageDownloadUrlsApiResponse {
|
|
19
|
+
urls: Record<string, string>;
|
|
20
|
+
}
|
|
14
21
|
/**
|
|
15
22
|
* Service for creating and uploading assets of different types.
|
|
16
|
-
*
|
|
17
|
-
* Process:
|
|
18
|
-
* When a new asset should be created
|
|
19
|
-
* - a request is sent to the backend to request a new upload
|
|
20
|
-
* - the BE returns with an upload url
|
|
21
|
-
* - after the upload is finished the App notifies the BE about the finished upload
|
|
22
|
-
* - and the final asset will be created in the BE
|
|
23
23
|
*/
|
|
24
24
|
export interface AssetService {
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* Upload an image that can be reused in subsequent searches without uploading it again.
|
|
27
|
+
* The returned assetId can be passed as `searchImageAssetId` in the search-input of performSearch.
|
|
28
|
+
* It is also possible to use the image for other purpose, such as CSA-metadata.
|
|
29
|
+
*
|
|
30
|
+
* Only available on platforms that support multipart-upload (see PFile.supportsMultipartUpload).
|
|
31
|
+
* On other platforms an SdkError with code MULTIPART_UPLOAD_NOT_SUPPORTED is emitted.
|
|
29
32
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
34
|
-
*
|
|
33
|
+
* @param image the image to upload
|
|
34
|
+
* @param organizationName (optional) organization name to associate with the uploaded image.
|
|
35
|
+
* If not provided, the authenticated user's default organization is used by the backend.
|
|
36
|
+
* @param assetEventContext AssetEventContext for V2 event logging. Must include `organizationId`; pass `searchSessionId` to associate the image-dimensions-log with an existing search-session.
|
|
37
|
+
* @returns Observable that resolves with the assetId of the uploaded image
|
|
35
38
|
*/
|
|
36
|
-
|
|
37
|
-
asset: Asset;
|
|
38
|
-
progress: number;
|
|
39
|
-
}>;
|
|
39
|
+
uploadImage(image: PFile, organizationName: string | undefined, assetEventContext: AssetEventContext): Observable<string>;
|
|
40
40
|
/**
|
|
41
41
|
* Download an image by its assetId and preferred size.
|
|
42
42
|
*
|
|
43
43
|
* @param assetId the assetId of the image that should be downloaded
|
|
44
44
|
* @param size the names of the sizes this image is available in eg: "original", "thumbnail", "medium"
|
|
45
|
+
* @param origin the origin of the image (defaults to PARTIUM; pass DATA for data-backend images)
|
|
45
46
|
* @returns an Observable that resolves with the DownloadStatus of the download, which contains
|
|
46
47
|
* the progress and the PFile as soon as it is finished
|
|
47
48
|
*/
|
|
48
49
|
downloadImage(assetId: string, size?: string, origin?: BACKEND_SERVICE): Observable<DownloadStatus>;
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
-
* Download an image from Find BE
|
|
52
|
-
*
|
|
53
|
-
* @param assetId asset-id of the image to download
|
|
54
|
-
*/
|
|
55
|
-
getImageUrlFromFind(assetId: string): Observable<{
|
|
56
|
-
url: string;
|
|
57
|
-
assetId: string;
|
|
58
|
-
}>;
|
|
59
|
-
/**
|
|
60
|
-
* Download an document by its assetId.
|
|
61
|
-
*
|
|
62
|
-
* @param assetId the assetId of the document that should be downloaded
|
|
63
|
-
* @returns an Observable that resolves with the DownloadStatus of the download, which contains
|
|
64
|
-
* the progress and the PFile as soon as it is finished
|
|
51
|
+
* Get the download urls of an image by its assetId.
|
|
65
52
|
*
|
|
66
|
-
* @
|
|
53
|
+
* @param assetId the assetId of the image that should be downloaded
|
|
54
|
+
* @returns an Observable that resolves with the download urls of the image in the form of { size: url }
|
|
67
55
|
*/
|
|
68
|
-
|
|
56
|
+
getImageDownloadUrls(assetId: string): Observable<Record<string, string>>;
|
|
69
57
|
}
|
|
70
58
|
export declare class AssetServiceImpl extends BaseLoginInitService implements AssetService {
|
|
71
59
|
private httpsService;
|
|
72
60
|
private fileTransferService;
|
|
73
61
|
private fileService;
|
|
74
62
|
private logService;
|
|
75
|
-
private MAX_UPLOAD_IMAGE_WIDTH;
|
|
76
|
-
private MAX_UPLOAD_IMAGE_HEIGHT;
|
|
77
63
|
constructor(serviceProvider: ServiceProvider);
|
|
78
64
|
onCreate(): void;
|
|
79
65
|
/**
|
|
80
66
|
* Called on login
|
|
81
67
|
*/
|
|
82
68
|
init(config: PartiumConfig, userEmail: string, currentOrganization$: Observable<Organization>): Observable<void>;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}>;
|
|
69
|
+
uploadImage(image: PFile, organizationName: string | undefined, assetEventContext: AssetEventContext): Observable<string>;
|
|
70
|
+
downloadImage(assetId: string, size?: string, origin?: BACKEND_SERVICE): Observable<DownloadStatus>;
|
|
71
|
+
getImageDownloadUrls(assetId: string): Observable<Record<string, string>>;
|
|
87
72
|
/**
|
|
88
73
|
* Check if the asset is an image and, in that case, log its dimensions.
|
|
74
|
+
* Fire-and-forget: failures only get logged to the console and never affect the upload itself.
|
|
89
75
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @return Promise<boolean>
|
|
92
|
-
*/
|
|
93
|
-
private getFileDimensions;
|
|
94
|
-
/**
|
|
95
|
-
* Check if the provided dimensions are supported.
|
|
96
|
-
*
|
|
97
|
-
* @param width number
|
|
98
|
-
* @param height number
|
|
99
|
-
* @return boolean
|
|
100
|
-
*/
|
|
101
|
-
private validateDimensions;
|
|
102
|
-
/**
|
|
103
|
-
* Log image dimensions to BE-Log service.
|
|
104
|
-
*
|
|
105
|
-
* @param width number
|
|
106
|
-
* @param height number
|
|
107
|
-
* @param searchDomainId string
|
|
76
|
+
* @param image PFile
|
|
108
77
|
* @param assetEventContext AssetEventContext
|
|
109
|
-
* @return Promise<void>
|
|
110
78
|
*/
|
|
111
79
|
private logImageDimensions;
|
|
112
|
-
downloadImage(assetId: string, size?: string, origin?: BACKEND_SERVICE): Observable<DownloadStatus>;
|
|
113
80
|
/**
|
|
114
|
-
* Get the
|
|
81
|
+
* Get the download url of an image by its assetId.
|
|
115
82
|
*
|
|
116
|
-
* @param assetId the assetId of image
|
|
83
|
+
* @param assetId the assetId of the image that should be downloaded
|
|
117
84
|
* @param size the names of the sizes this image is available in eg: "original", "thumbnail", "medium"
|
|
118
|
-
* @returns Observable that resolves with an object containing the
|
|
119
|
-
* can be downloaded and the assetId of the
|
|
85
|
+
* @returns Observable that resolves with an object containing the url, where the image
|
|
86
|
+
* can be downloaded and the assetId of the image
|
|
120
87
|
*/
|
|
121
88
|
private getImageUrl;
|
|
122
|
-
getImageUrlFromFind(assetId: string): Observable<{
|
|
123
|
-
url: string;
|
|
124
|
-
assetId: string;
|
|
125
|
-
}>;
|
|
126
|
-
downloadDocument(assetId: string): Observable<DownloadStatus>;
|
|
127
89
|
/**
|
|
128
|
-
* Get the temporary download url of
|
|
129
|
-
*
|
|
130
|
-
* @param assetId the assetId of the document
|
|
131
|
-
* @returns Observable that resolves with an object containing the temporary url, where the document
|
|
132
|
-
* can be downloaded and the assetId of the asset
|
|
133
|
-
*/
|
|
134
|
-
private getDocumentUrl;
|
|
135
|
-
/**
|
|
136
|
-
* Upload a newly created asset to the BE.
|
|
137
|
-
*
|
|
138
|
-
* @param searchDomainId Search domain to upload the asset to.
|
|
139
|
-
* @param asset the asset to upload
|
|
140
|
-
* @returns Observable that resolves with an object containing the asset-object
|
|
141
|
-
* and the current upload progress
|
|
142
|
-
*/
|
|
143
|
-
private uploadAsset;
|
|
144
|
-
/**
|
|
145
|
-
* Send a request to the backend to create a new asset and retrieve the uploadUrl and
|
|
146
|
-
* Reference id. This data is then applied to the given asset object.
|
|
147
|
-
*
|
|
148
|
-
* @param searchDomainId Search domain to upload the asset to.
|
|
149
|
-
* @param asset the asset object to prepare for upload
|
|
150
|
-
* @returns Observable that resolves when the prepare-asset is finished successfully
|
|
151
|
-
*/
|
|
152
|
-
private prepareAssetUpload;
|
|
153
|
-
/**
|
|
154
|
-
* Sends a request to the backend to verify an uploaded asset.
|
|
90
|
+
* Get the temporary download url of an image by its assetId and preferred size
|
|
155
91
|
*
|
|
156
|
-
* @param
|
|
157
|
-
* @
|
|
92
|
+
* @param assetId the assetId of image
|
|
93
|
+
* @param size the names of the sizes this image is available in eg: "original", "thumbnail", "medium"
|
|
94
|
+
* @returns Observable that resolves with an object containing the temporary url, where the image
|
|
95
|
+
* can be downloaded and the assetId of the image
|
|
158
96
|
*/
|
|
159
|
-
private
|
|
97
|
+
private getDataImageUrl;
|
|
98
|
+
private resolveDownloadUrlForSize;
|
|
160
99
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Copyright © 2022-2026 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
|
|
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 i(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}}(),__assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var r,t=1,i=arguments.length;t<i;t++)for(var n in r=arguments[t])Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n]);return e},__assign.apply(this,arguments)},__decorate=this&&this.__decorate||function(e,r,t,i){var n,o=arguments.length,s=o<3?r:null===i?i=Object.getOwnPropertyDescriptor(r,t):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,r,t,i);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(s=(o<3?n(s):o>3?n(r,t,s):n(r,t))||s);return o>3&&s&&Object.defineProperty(r,t,s),s},__awaiter=this&&this.__awaiter||function(e,r,t,i){return new(t||(t=Promise))((function(n,o){function s(e){try{a(i.next(e))}catch(e){o(e)}}function c(e){try{a(i.throw(e))}catch(e){o(e)}}function a(e){var r;e.done?n(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,c)}a((i=i.apply(e,r||[])).next())}))},__generator=this&&this.__generator||function(e,r){var t,i,n,o,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(c){return function(a){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(s=0)),s;)try{if(t=1,i&&(n=2&c[0]?i.return:c[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,c[1])).done)return n;switch(i=0,n&&(c=[2&c[0],n.value]),c[0]){case 0:case 1:n=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,i=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!n||c[1]>n[0]&&c[1]<n[3])){s.label=c[1];break}if(6===c[0]&&s.label<n[1]){s.label=n[1],n=c;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(c);break}n[2]&&s.ops.pop(),s.trys.pop();continue}c=r.call(e,s)}catch(e){c=[6,e],i=0}finally{t=n=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.AssetServiceImpl=void 0;var rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),injection_identifier_1=require("../../core/decorators/injection-identifier"),error_1=require("../../core/models/error"),p_file_1=require("../../core/models/p-file"),base_login_init_service_1=require("../../core/services/base-login-init.service"),file_service_interface_1=require("../../core/services/file.service.interface"),file_transfer_service_interface_1=require("../../core/services/http/file-transfer/file-transfer.service.interface"),https_service_interface_1=require("../../core/services/http/https.service.interface"),log_service_1=require("../../core/services/log.service"),core_1=require("../../core"),multipart_upload_helper_1=require("../../core/utils/multipart-upload.helper"),AssetServiceImpl=function(e){function r(r){return e.call(this,r)||this}return __extends(r,e),r.prototype.onCreate=function(){this.httpsService=this.serviceProvider.getService(https_service_interface_1.HttpsService),this.fileTransferService=this.serviceProvider.getService(file_transfer_service_interface_1.FileTransferService),this.fileService=this.serviceProvider.getService(file_service_interface_1.FileService),this.logService=this.serviceProvider.getService(log_service_1.LogServiceImpl)},r.prototype.init=function(r,t,i){return e.prototype.init.call(this,r,t,i),(0,rxjs_1.of)(void 0)},r.prototype.uploadImage=function(e,r,t){var i=this;return(0,multipart_upload_helper_1.guardMultipartUpload)(e,(function(){return(0,rxjs_1.defer)((function(){return i.logImageDimensions(e,t),(0,multipart_upload_helper_1.postPFileImageMultipartRequest)(i.httpsService,{url:"/assets/images",image:e,input:r?{organization:r}:void 0,eventInterface:t.eventInterface})})).pipe((0,operators_1.map)((function(e){return e.assetId})))}))},r.prototype.downloadImage=function(e,r,t){var i=this;return void 0===r&&(r="original"),void 0===t&&(t=https_service_interface_1.BACKEND_SERVICE.PARTIUM),(t===https_service_interface_1.BACKEND_SERVICE.DATA?this.getDataImageUrl(e,r):this.getImageUrl(e,r)).pipe((0,operators_1.mergeMap)((function(e){return i.fileTransferService.downloadFile(e)})))},r.prototype.getImageDownloadUrls=function(e){return this.httpsService.get("assets/images/".concat(e),null,https_service_interface_1.BACKEND_SERVICE.PARTIUM).pipe((0,operators_1.map)((function(e){return e.urls})))},r.prototype.logImageDimensions=function(e,r){return __awaiter(this,void 0,void 0,(function(){var t,i,n,o;return __generator(this,(function(s){switch(s.label){case 0:return[4,this.fileService.getFileType(e)];case 1:if(s.sent()!==p_file_1.PFileType.IMAGE)return console.log("Wrong file type provided. Type IMAGE required."),[2];s.label=2;case 2:return s.trys.push([2,5,,6]),[4,this.fileService.getImageDimensions(e)];case 3:return t=s.sent(),i=t[0],n=t[1],[4,(0,rxjs_1.firstValueFrom)(this.logService.logEvent(new core_1.EventLog({version:core_1.EVENTLOG_VERSIONS.V_2_0_0,organizationId:r.organizationId,interface:r.eventInterface||core_1.INTERFACE.API_ACCESS,event:core_1.EVENT.ATTEMPT_UPLOAD_IMAGE_DIMENSIONS,data:__assign(__assign({},r.searchSessionId&&{searchSessionId:r.searchSessionId}),{width:i,height:n})})))];case 4:return s.sent(),[3,6];case 5:return o=s.sent(),console.log("Error while sending log event ".concat(core_1.EVENT.ATTEMPT_UPLOAD_IMAGE_DIMENSIONS,": "),o),[3,6];case 6:return[2]}}))}))},r.prototype.getImageUrl=function(e,r){var t=this;return this.getImageDownloadUrls(e).pipe((0,operators_1.map)((function(i){return t.resolveDownloadUrlForSize(i,e,r)})))},r.prototype.getDataImageUrl=function(e,r){var t=this;return this.httpsService.get("images/".concat(e),null,https_service_interface_1.BACKEND_SERVICE.DATA).pipe((0,operators_1.map)((function(i){return t.resolveDownloadUrlForSize(i.urls,e,r)})))},r.prototype.resolveDownloadUrlForSize=function(e,r,t){var i=null==e?void 0:e[t];if(!i)throw new error_1.SdkError(error_1.SDK_ERROR_CODES.NOT_FOUND,null,"Could not find image with id: ".concat(r," in size: ").concat(t));return i},r=__decorate([(0,injection_identifier_1.InjectionIdentifier)("AssetService")],r)}(base_login_init_service_1.BaseLoginInitService);exports.AssetServiceImpl=AssetServiceImpl;
|
|
@@ -1,33 +1,21 @@
|
|
|
1
1
|
// Copyright © 2022-2026 Partium, Inc. DBA Partium
|
|
2
|
-
import { TextSearchService, TextSearchServiceImpl } from './text-search.service';
|
|
3
|
-
import { CvSearchServiceImpl, CvSearchService } from './cv-search.service';
|
|
4
2
|
import { Observable } from 'rxjs';
|
|
5
|
-
import {
|
|
6
|
-
import { SearchFilter } from '../../models/search-filter';
|
|
7
|
-
import { SearchFilterServiceImpl, SearchFilterService } from '../search-filter.service';
|
|
8
|
-
import { SearchSessionLogObject } from '../../models/search-session-log-object';
|
|
9
|
-
import { CurResultList } from './search-result.service';
|
|
10
|
-
import { TagSearchService, TagSearchServiceImpl } from './tag-search.service';
|
|
11
|
-
import { SearchResultStatus } from '../../models/search-result-status';
|
|
12
|
-
import { SdkError } from '../../../core/models/error';
|
|
13
|
-
import { PFile } from '../../../core/models/p-file';
|
|
14
|
-
import { Part, PartFromFindAPI } from '../../../data/models/part';
|
|
3
|
+
import { PartFromPartiumAPI } from '../../../data/models/part';
|
|
15
4
|
import { ServiceProvider } from '../../../core/services/service-provider';
|
|
16
5
|
import { EventContext } from '../../../core/models/log';
|
|
17
6
|
import { RecentTextSearchQueriesService } from './recent-text-search-queries.service';
|
|
18
|
-
import {
|
|
7
|
+
import { SmartFilterFromAPI } from '../../models/smart-filter';
|
|
19
8
|
import { SearchInput } from '../../models/search-input';
|
|
20
9
|
import { SEARCH_OUTPUT_STATUS, SearchOutput } from '../../models/search-output';
|
|
21
10
|
import { BaseLoginInitService, Organization, PartiumConfig } from '../../../core';
|
|
22
|
-
import { ImageCropArea } from '../../models/
|
|
11
|
+
import { ImageCropArea } from '../../models/image-crop-area';
|
|
23
12
|
export interface SearchEventContext extends EventContext {
|
|
24
13
|
languageUi?: string;
|
|
25
|
-
searchSessionId?: string;
|
|
26
14
|
}
|
|
27
15
|
export interface SearchApiResponse {
|
|
28
16
|
sessionId: string;
|
|
29
17
|
resultsTotalCount: number;
|
|
30
|
-
results:
|
|
18
|
+
results: PartFromPartiumAPI[];
|
|
31
19
|
smartFilters?: SmartFilterFromAPI[];
|
|
32
20
|
imageId?: string;
|
|
33
21
|
status?: SEARCH_OUTPUT_STATUS;
|
|
@@ -57,9 +45,6 @@ export interface SearchApiResponse {
|
|
|
57
45
|
};
|
|
58
46
|
};
|
|
59
47
|
}
|
|
60
|
-
export interface ImageUploadApiResponse {
|
|
61
|
-
imageId: string;
|
|
62
|
-
}
|
|
63
48
|
interface FilterFromAPIResponse {
|
|
64
49
|
label: string;
|
|
65
50
|
values: string[];
|
|
@@ -67,159 +52,9 @@ interface FilterFromAPIResponse {
|
|
|
67
52
|
type SearchResultOptions = Record<string, string | number | boolean>;
|
|
68
53
|
/**
|
|
69
54
|
* This service is the central service for managing all search-related interaction.
|
|
70
|
-
* It
|
|
71
|
-
* Also it provides functionality for managing search-sessions, such as creating
|
|
72
|
-
* new search-sessions or retrieving the search-result.
|
|
73
|
-
*
|
|
74
|
-
* The search results are managed in the SearchResultService
|
|
55
|
+
* It allows to perform searches or load search-results from a previous search.
|
|
75
56
|
*/
|
|
76
57
|
export interface SearchService {
|
|
77
|
-
/**
|
|
78
|
-
* Start a new search session in the context of an organization. If there was already an active search session,
|
|
79
|
-
* the old one ends with the start of the new one. Only one search session can be active at the time.
|
|
80
|
-
*
|
|
81
|
-
* @param searchDomainId the id of the search domain
|
|
82
|
-
* @param filters (optional) search filters can either be directly passed when creating search, or later via the SearchFilterService
|
|
83
|
-
* @param searchLanguage (optional) language to use for the search. Only configured languages are allowed to be used.
|
|
84
|
-
* If not provided it defaults to a configured default language for an organization.
|
|
85
|
-
* Language is expected to be a two-letter string, according to ISO 639-1 (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
|
86
|
-
* @param searchEventContext (optional) SearchEventContext object to add the missing data that will be logged using the log format V2
|
|
87
|
-
* @returns Observable that resolves with the request to the backend
|
|
88
|
-
*
|
|
89
|
-
* @deprecated use performSearch instead
|
|
90
|
-
*/
|
|
91
|
-
startNewSearch(searchDomainId: string, filters?: Array<SearchFilter>, searchLanguage?: string, searchEventContext?: SearchEventContext): Observable<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Load an existing search session into the active search-state.
|
|
94
|
-
* This allows to load and continue an older search-session.
|
|
95
|
-
* It can also be used to only view the state of that search-session,
|
|
96
|
-
* including the last result-list.
|
|
97
|
-
*
|
|
98
|
-
* TODO This function is currently only used to load the search-results of an
|
|
99
|
-
* older search-session. Loading of the search-inputs is not fully working yet
|
|
100
|
-
* and should therefore not yet be used.
|
|
101
|
-
*
|
|
102
|
-
* @param searchSessionId the id of the search-session to load
|
|
103
|
-
*
|
|
104
|
-
* @beta
|
|
105
|
-
*
|
|
106
|
-
* @deprecated use performSearch instead
|
|
107
|
-
*/
|
|
108
|
-
loadExistingSearchSession(searchSessionId: string): void;
|
|
109
|
-
/**
|
|
110
|
-
* Leave the currently active search-session.
|
|
111
|
-
* This will reset the state of the whole search-session, but the
|
|
112
|
-
* search-session will keep existing and can be continued at a later
|
|
113
|
-
* point, if desired.
|
|
114
|
-
*
|
|
115
|
-
* @deprecated use performSearch instead
|
|
116
|
-
*/
|
|
117
|
-
leaveCurrentSearchSession(): void;
|
|
118
|
-
/**
|
|
119
|
-
* Get an observable that always emits the whole currently available result list every
|
|
120
|
-
* time it changes.
|
|
121
|
-
*
|
|
122
|
-
* @returns Observable that emits an Array with the current result list every time it changes, or an SdkError when an error happens during processing of the search in the backend
|
|
123
|
-
*
|
|
124
|
-
* @deprecated use performSearch instead
|
|
125
|
-
*/
|
|
126
|
-
getCurResultList(): Observable<CurResultList | SdkError>;
|
|
127
|
-
/**
|
|
128
|
-
* Get an observable that always emits changes in the search-result-state.
|
|
129
|
-
* The initial state after creating a new search-session will be CREATED.
|
|
130
|
-
* While processing search-input the state will be RUNNING.
|
|
131
|
-
* Only when creation of search-results and creation of search-tags is finished,
|
|
132
|
-
* it will change to FINISHED.
|
|
133
|
-
*SearchFilterServiceImpl
|
|
134
|
-
* @returns Observable that emits changesSearchFilterServiceImpllt-state
|
|
135
|
-
*
|
|
136
|
-
* @deprecated use performSearch instead
|
|
137
|
-
*/
|
|
138
|
-
getSearchResultStatus(): Observable<SearchResultStatus>;
|
|
139
|
-
/**
|
|
140
|
-
* Get the ID of the current search session
|
|
141
|
-
*
|
|
142
|
-
* @returns the current search session id
|
|
143
|
-
*
|
|
144
|
-
* @deprecated use performSearch instead
|
|
145
|
-
*/
|
|
146
|
-
getCurSearchSessionID(): string;
|
|
147
|
-
/**
|
|
148
|
-
* Get an observable that always emits the current search session id every
|
|
149
|
-
* time it changes.
|
|
150
|
-
*
|
|
151
|
-
* @returns Observable that emits a string with the current search session id every time it changes
|
|
152
|
-
*
|
|
153
|
-
* @deprecated use performSearch instead
|
|
154
|
-
*/
|
|
155
|
-
getCurSearchSessionID$(): Observable<string>;
|
|
156
|
-
/**
|
|
157
|
-
* Get the SearchStatus object of the currently active search. It contains information about
|
|
158
|
-
* the active search session and all active search components.
|
|
159
|
-
*
|
|
160
|
-
* @returns the SearchStatus object, representing the current search
|
|
161
|
-
*
|
|
162
|
-
* @deprecated use performSearch instead
|
|
163
|
-
*/
|
|
164
|
-
getSearchStatus(): SearchStatus;
|
|
165
|
-
/**
|
|
166
|
-
* @deprecated use performSearch instead
|
|
167
|
-
*/
|
|
168
|
-
getCurResultListLength(): number;
|
|
169
|
-
/**
|
|
170
|
-
* @deprecated use performSearch instead
|
|
171
|
-
*/
|
|
172
|
-
getCurResultListValue(): Array<Part>;
|
|
173
|
-
/**
|
|
174
|
-
* Log some other type of information to the currently active search session.
|
|
175
|
-
* (Other than that which is already logged automatically, like cv, ...)
|
|
176
|
-
* Can be used for questions, feedback...
|
|
177
|
-
*
|
|
178
|
-
* @deprecated use the LogService for logging
|
|
179
|
-
*
|
|
180
|
-
*/
|
|
181
|
-
logToSearchSession(logObject: SearchSessionLogObject): Observable<void>;
|
|
182
|
-
/**
|
|
183
|
-
* Load more results of the current result list.
|
|
184
|
-
* The newly loaded results will emit via the getCurResultList-Observable,
|
|
185
|
-
* along with the already known results.
|
|
186
|
-
*
|
|
187
|
-
* @deprecated use performSearch instead
|
|
188
|
-
*/
|
|
189
|
-
loadMoreSearchResults(): void;
|
|
190
|
-
/**
|
|
191
|
-
* Get an Observable that always resolves with the latest search status
|
|
192
|
-
* when a search is performed.
|
|
193
|
-
*
|
|
194
|
-
* @returns Observable that always resolves with the latest search status whenever changed
|
|
195
|
-
*
|
|
196
|
-
* @deprecated use performSearch instead
|
|
197
|
-
*/
|
|
198
|
-
allSearchInputsEmpty(): Observable<boolean>;
|
|
199
|
-
/**
|
|
200
|
-
* Get an Observable that always emits the current Smart Filters every time they change.
|
|
201
|
-
*
|
|
202
|
-
* @returns Get an Observable that always emits the current Smart Filters every time they change
|
|
203
|
-
*
|
|
204
|
-
* @deprecated use performSearch instead
|
|
205
|
-
*/
|
|
206
|
-
getCurSmartFilters(): Observable<SmartFilter[]>;
|
|
207
|
-
/**
|
|
208
|
-
* @deprecated use performSearch instead
|
|
209
|
-
*/
|
|
210
|
-
text: TextSearchService;
|
|
211
|
-
/**
|
|
212
|
-
* @deprecated use performSearch instead
|
|
213
|
-
*/
|
|
214
|
-
cv: CvSearchService;
|
|
215
|
-
/**
|
|
216
|
-
* @deprecated use performSearch instead
|
|
217
|
-
*/
|
|
218
|
-
filter: SearchFilterService;
|
|
219
|
-
/**
|
|
220
|
-
* @deprecated use performSearch instead
|
|
221
|
-
*/
|
|
222
|
-
searchTag: TagSearchService;
|
|
223
58
|
recentTextSearchQueries: RecentTextSearchQueriesService;
|
|
224
59
|
/**
|
|
225
60
|
* Perform a search with the given input synchronously (uses the new synchronous Search-API).
|
|
@@ -243,74 +78,26 @@ export interface SearchService {
|
|
|
243
78
|
* @returns object of type SearchOutput that contains all search-details, such as search-input + result-list, smart-filters, ... (depending on projection)
|
|
244
79
|
*/
|
|
245
80
|
getSearchOutput(searchSessionId: string, projection?: string[], resultOptions?: SearchResultOptions, organizationName?: string): Observable<SearchOutput>;
|
|
246
|
-
/**
|
|
247
|
-
* Upload an image that can be reused in subsequent searches without uploading it again.
|
|
248
|
-
* The returned imageId can be passed as `searchImageAssetId` in the search-input of performSearch.
|
|
249
|
-
*
|
|
250
|
-
* Only available on platforms that support multipart-upload (see PFile.supportsMultipartUpload).
|
|
251
|
-
* On other platforms an SdkError with code MULTIPART_UPLOAD_NOT_SUPPORTED is emitted.
|
|
252
|
-
*
|
|
253
|
-
* @param searchImage the image to upload
|
|
254
|
-
* @param organizationName (optional) organization name to associate with the uploaded image.
|
|
255
|
-
* If not provided, the authenticated user's default organization is used by the backend.
|
|
256
|
-
* @param searchEventContext (optional) SearchEventContext object to add the missing data that will be logged using the log format V2.
|
|
257
|
-
* Pass a searchSessionId to associate the image-dimensions-log with an existing search-session.
|
|
258
|
-
* @returns Observable that resolves with the imageId of the uploaded image
|
|
259
|
-
*/
|
|
260
|
-
uploadSearchImage(searchImage: PFile, organizationName?: string, searchEventContext?: SearchEventContext): Observable<string>;
|
|
261
81
|
}
|
|
262
82
|
export declare class SearchServiceImpl extends BaseLoginInitService implements SearchService {
|
|
263
83
|
private httpsService;
|
|
264
|
-
private searchResultService;
|
|
265
84
|
private logService;
|
|
266
85
|
private deviceStatusService;
|
|
267
86
|
private organizationService;
|
|
268
|
-
private assetService;
|
|
269
|
-
private fileService;
|
|
270
|
-
private searchStatus;
|
|
271
|
-
private readonly searchSessionID$;
|
|
272
87
|
constructor(serviceProvider: ServiceProvider);
|
|
273
88
|
onCreate(): void;
|
|
274
89
|
/**
|
|
275
90
|
* Initializes the SearchService
|
|
276
91
|
*/
|
|
277
92
|
init(config: PartiumConfig, userEmail: string, currentOrganization$: Observable<Organization>): Observable<void>;
|
|
278
|
-
get text(): TextSearchServiceImpl;
|
|
279
|
-
get cv(): CvSearchServiceImpl;
|
|
280
|
-
get filter(): SearchFilterServiceImpl;
|
|
281
|
-
get searchTag(): TagSearchServiceImpl;
|
|
282
93
|
get recentTextSearchQueries(): RecentTextSearchQueriesService;
|
|
283
|
-
startNewSearch(searchDomainId: string, filters?: Array<SearchFilter>, searchLanguage?: string, searchEventContext?: SearchEventContext): Observable<void>;
|
|
284
|
-
loadExistingSearchSession(searchSessionId: string): void;
|
|
285
|
-
leaveCurrentSearchSession(): void;
|
|
286
|
-
getCurResultList(): Observable<CurResultList | SdkError>;
|
|
287
|
-
getSearchResultStatus(): Observable<SearchResultStatus>;
|
|
288
|
-
getCurSearchSessionID(): string;
|
|
289
|
-
getCurSearchSessionID$(): Observable<string>;
|
|
290
|
-
getSearchStatus(): SearchStatus;
|
|
291
|
-
getCurResultListLength(): number;
|
|
292
|
-
getCurResultListValue(): Array<Part>;
|
|
293
|
-
logToSearchSession(logObject: SearchSessionLogObject): Observable<void>;
|
|
294
|
-
loadMoreSearchResults(): void;
|
|
295
|
-
allSearchInputsEmpty(): Observable<boolean>;
|
|
296
|
-
getCurSmartFilters(): Observable<SmartFilter[]>;
|
|
297
94
|
performSearch(searchInput: SearchInput, searchEventContext?: SearchEventContext, projection?: string[], resultOptions?: SearchResultOptions, skipDeviceInfoEventLog?: boolean): Observable<SearchOutput>;
|
|
298
95
|
getSearchOutput(searchSessionId: string, projection?: string[], resultOptions?: SearchResultOptions, organizationName?: string): Observable<SearchOutput>;
|
|
299
|
-
uploadSearchImage(searchImage: PFile, organizationName?: string, searchEventContext?: SearchEventContext): Observable<string>;
|
|
300
|
-
/**
|
|
301
|
-
* Log the dimensions of an upload-attempted search-image (analogue to the image-dimensions-log in the AssetService).
|
|
302
|
-
* Fire-and-forget: failures only get logged to the console and never affect the upload itself.
|
|
303
|
-
*/
|
|
304
|
-
private logSearchImageDimensions;
|
|
305
96
|
private logDeviceInfo;
|
|
306
97
|
private getOrganizationId;
|
|
307
98
|
private prepareFilters;
|
|
308
99
|
private processSearchApiResponse;
|
|
309
100
|
private removeDuplicatesFromArray;
|
|
310
|
-
/**
|
|
311
|
-
* TODO used for backwards-compatibility, can be removed when SearchStatus is deleted
|
|
312
|
-
*/
|
|
313
|
-
private updateSearchStatus;
|
|
314
101
|
/**
|
|
315
102
|
* Add text-searches to recent text-searches if set
|
|
316
103
|
* @param searchInput the new search-input
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Copyright © 2022-2026 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,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"),error_1=require("../../../core/models/error"),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.searchStatus=new search_status_1.SearchStatus,r.searchSessionID$=new rxjs_1.BehaviorSubject(""),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),this.fileService=this.serviceProvider.getService(core_1.FileService)},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 t&&t.length>0?a.filter.setSearchFilters(t):(0,rxjs_1.of)(void 0)})),(0,operators_1.catchError)((function(e){return a.searchStatus=new search_status_1.SearchStatus,a.searchSessionID$.next(""),(0,rxjs_1.throwError)((function(){return 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.searchSessionID||""},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",_,void 0,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,void 0,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,void 0,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,r})),(0,operators_1.switchMap)((function(t){return u.getOrganizationId(e.organizationName).pipe((0,operators_1.map)((function(e){return{organizationId:e,searchOutput:t}})))})),(0,operators_1.tap)((function(r){var s,i=r.searchOutput,c=r.organizationId;u.updateSearchStatus(i,c),e.searchSessionId||a||u.logDeviceInfo(null!==(s=i.searchInput.searchSessionId)&&void 0!==s?s:"",c,t)})),(0,operators_1.map)((function(e){return e.searchOutput})))},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.uploadSearchImage=function(e,t,r){var s=this;if(!e.supportsMultipartUpload())return(0,rxjs_1.throwError)((function(){return new error_1.SdkError(error_1.SDK_ERROR_CODES.MULTIPART_UPLOAD_NOT_SUPPORTED,{},"Standalone image-upload is only available on platforms that support multipart-upload. Pass the image directly to performSearch instead.")}));var a=new FormData;return t&&a.append("input",JSON.stringify({organization:t})),e.appendToFormData("image",a),(0,rxjs_1.defer)((function(){return s.logSearchImageDimensions(e,t,r),s.httpsService.post("/find/images",a,void 0,https_service_interface_1.BACKEND_SERVICE.PARTIUM,{"Content-Type":"multipart/form-data","X-Partium-Interface":(null==r?void 0:r.eventInterface)||log_1.INTERFACE.API_ACCESS})})).pipe((0,operators_1.map)((function(e){return e.imageId})))},t.prototype.logSearchImageDimensions=function(e,t,r){var s=this,a=t?this.getOrganizationId(t):this.currentOrganization$.pipe((0,operators_1.map)((function(e){return e.partiumId})));(0,rxjs_1.combineLatest)([a,(0,rxjs_1.from)(this.fileService.getImageDimensions(e))]).pipe((0,operators_1.first)(),(0,operators_1.mergeMap)((function(e){var t=e[0],a=e[1],i=a[0],c=a[1];return 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.ATTEMPT_UPLOAD_IMAGE_DIMENSIONS,data:__assign(__assign({},(null==r?void 0:r.searchSessionId)&&{searchSessionId:r.searchSessionId}),{width:i,height:c})}))}))).subscribe({error:function(e){console.error("Error while sending log event ".concat(log_1.EVENT.ATTEMPT_UPLOAD_IMAGE_DIMENSIONS,": "),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""})))},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,v,g,d,f=null!==(r=null===(t=e.request)||void 0===t?void 0:t.language)&&void 0!==r?r:"",I=null!==(i=null===(a=null===(s=e.request)||void 0===s?void 0:s.matches)||void 0===a?void 0:a.organization)&&void 0!==i?i:"";return __assign(__assign({searchInput:__assign({organizationName:I,searchLanguage:f,searchSessionId:e.sessionId},e.request&&{text:null===(c=e.request.matches)||void 0===c?void 0:c.text,searchQueries:{exactText:null===(n=e.request.matches)||void 0===n?void 0:n.exact,semanticText:null===(o=e.request.matches)||void 0===o?void 0:o.text},searchImageAssetId:e.request.reusableImageId||e.imageId,searchImageCropArea:null===(u=e.request.imageOptions)||void 0===u?void 0:u.areaOfInterest,hierarchyFilters:null===(h=e.request.matches)||void 0===h?void 0:h.hierarchyPartiumIds,attributeFilters:null===(_=null===(l=e.request.matches)||void 0===l?void 0:l.filters)||void 0===_?void 0:_.reduce((function(e,t){var r;return __assign(__assign({},e),((r={})[t.label]=t.values,r))}),{}),similarTo:null===(S=e.request.matches)||void 0===S?void 0:S.similarTo,duplicateOf:null===(p=e.request.matches)||void 0===p?void 0:p.duplicateOf,hasRelatedParts:null===(v=e.request.matches)||void 0===v?void 0:v.hasRelatedParts}),resultsTotalCount:e.resultsTotalCount,searchResults:e.results.map((function(e){return part_1.Part.fromAPIResponse(e,part_1.DATA_ORIGIN.FIND_API,f)}))},e.status&&{status:e.status}),{smartFilters:null!==(d=null===(g=e.smartFilters)||void 0===g?void 0:g.map((function(e){return smart_filter_1.SmartFilter.fromAPIResponse(e)})))&&void 0!==d?d:[]})},t.prototype.removeDuplicatesFromArray=function(e){return Array.from(new Set(e))},t.prototype.updateSearchStatus=function(e,t){var r,s,a,i,c,n,o;this.searchStatus=this.searchStatus||new search_status_1.SearchStatus,this.searchStatus.searchDomainId=t,this.searchStatus.searchSessionID=null!==(r=e.searchInput.searchSessionId)&&void 0!==r?r:"",this.searchSessionID$.next(this.searchStatus.searchSessionID),this.searchStatus.searchLanguage=null!==(s=e.searchInput.searchLanguage)&&void 0!==s?s:null,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.text)&&void 0!==a?a:"",this.searchStatus.textSearchStatus.searchQueries=null!==(i=e.searchInput.searchQueries)&&void 0!==i?i:{},this.searchStatus.cvSearchStatus=this.searchStatus.cvSearchStatus||new cv_search_status_1.CVSearchStatus,this.searchStatus.cvSearchStatus.assetId=null!==(c=e.searchInput.searchImageAssetId)&&void 0!==c?c:"",this.searchStatus.cvSearchStatus.cvImage=e.searchInput.searchImage?new asset_1.Asset(e.searchInput.searchImage):null,this.searchStatus.cvSearchStatus.cropArea=e.searchInput.searchImageCropArea,this.searchStatus.filterStatus=this.searchStatus.filterStatus||new search_filter_status_1.SearchFilterStatus;var u=null!==(n=e.searchInput.hierarchyFilters)&&void 0!==n?n:[],h=null!==(o=e.searchInput.attributeFilters)&&void 0!==o?o:{};this.searchStatus.filterStatus.filters=__spreadArray(__spreadArray([],u.length>0?[new search_filter_1.HierarchyPartiumIdFilter(u,[])]:[],!0),Object.keys(h).map((function(e){return new search_filter_1.KvpHardFilter(e,e,h[e])})),!0),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;
|
|
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 i(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}}(),__assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var r,t=1,i=arguments.length;t<i;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,i){var s,a=arguments.length,n=a<3?r:null===i?i=Object.getOwnPropertyDescriptor(r,t):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,r,t,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(n=(a<3?s(n):a>3?s(r,t,n):s(r,t))||n);return a>3&&n&&Object.defineProperty(r,t,n),n},__spreadArray=this&&this.__spreadArray||function(e,r,t){if(t||2===arguments.length)for(var i,s=0,a=r.length;s<a;s++)!i&&s in r||(i||(i=Array.prototype.slice.call(r,0,s)),i[s]=r[s]);return e.concat(i||Array.prototype.slice.call(r))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SearchServiceImpl=void 0;var rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),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"),search_input_1=require("../../models/search-input"),core_1=require("../../../core"),multipart_upload_helper_1=require("../../../core/utils/multipart-upload.helper"),SearchServiceImpl=function(e){function r(r){return e.call(this,r)||this}return __extends(r,e),r.prototype.onCreate=function(){this.httpsService=this.serviceProvider.getService(https_service_interface_1.HttpsService),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.OrganizationServiceImpl)},r.prototype.init=function(r,t,i){return e.prototype.init.call(this,r,t,i),(0,rxjs_1.of)(void 0)},Object.defineProperty(r.prototype,"recentTextSearchQueries",{get:function(){return this.serviceProvider.getService(recent_text_search_queries_service_1.RecentTextSearchQueriesServiceImpl)},enumerable:!1,configurable:!0}),r.prototype.performSearch=function(e,r,t,i,s){var a,n,o,c,u=this;void 0===t&&(t=["smartFilters","results.id","results.partiumId","results.name","request"]),void 0===i&&(i={limit:25}),void 0===s&&(s=!1);var 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===(a=e.searchQueries)||void 0===a?void 0:a.semanticText))&&{text:e.text||(null===(n=e.searchQueries)||void 0===n?void 0:n.semanticText)}),(null===(o=e.searchQueries)||void 0===o?void 0:o.exactText)&&{exact:null===(c=e.searchQueries)||void 0===c?void 0:c.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([],t,!0),["request"],!1)),resultOptions:i});return this.updateRecentTextSearch(e),(e.searchImage?(0,multipart_upload_helper_1.guardMultipartUpload)(e.searchImage,(function(){return(0,multipart_upload_helper_1.postPFileImageMultipartRequest)(u.httpsService,{url:"/find/search",image:e.searchImage,input:l,eventInterface:null==r?void 0:r.eventInterface})})):this.httpsService.post("/find/search",l,void 0,https_service_interface_1.BACKEND_SERVICE.PARTIUM,{"X-Partium-Interface":(null==r?void 0:r.eventInterface)||log_1.INTERFACE.API_ACCESS})).pipe((0,operators_1.map)((function(r){var t=u.processSearchApiResponse(r);return t.searchInput.searchImage=e.searchImage,t})),(0,operators_1.tap)((function(t){e.searchSessionId||s||u.getOrganizationId(e.organizationName).subscribe({next:function(e){var i;u.logDeviceInfo(null!==(i=t.searchInput.searchSessionId)&&void 0!==i?i:"",e,r)},error:function(e){console.error("Error while resolving organization for device info log: ",e)}})})))},r.prototype.getSearchOutput=function(e,r,t,i){var s=this;return void 0===r&&(r=["smartFilters","results.id","results.partiumId","results.name","request"]),void 0===t&&(t={limit:25}),(i?(0,rxjs_1.of)(i):this.currentOrganization$.pipe((0,operators_1.map)((function(e){return e.name})))).pipe((0,operators_1.switchMap)((function(i){return s.httpsService.get("/find/search/state/".concat(e),(0,core_1.toQueryParams)(__assign({projection:s.removeDuplicatesFromArray(__spreadArray(__spreadArray([],r,!0),["request"],!1)),organization:i},t)),https_service_interface_1.BACKEND_SERVICE.PARTIUM)})),(0,operators_1.map)((function(e){return s.processSearchApiResponse(e)})))},r.prototype.logDeviceInfo=function(e,r,t){var i=this;this.deviceStatusService.getDeviceInfo().then((function(s){var a=__assign(__assign({},s),{partiumSdkVersion:sdk_version_1.SDK_VERSION_NUMBER,languageUi:(null==t?void 0:t.languageUi)||null,searchSessionId:e});i.logService.logEvent(new log_1.EventLog({organizationId:r,version:log_1.EVENTLOG_VERSIONS.V_2_0_0,interface:(null==t?void 0:t.eventInterface)||log_1.INTERFACE.API_ACCESS,event:log_1.EVENT.DEVICE_INFO,data:a})).subscribe({next:function(){},error:function(e){console.error("Error while sending log event ".concat(log_1.EVENT.DEVICE_INFO,": "),e)}})}))},r.prototype.getOrganizationId=function(e){return this.organizationService.getOrganizationByName({name:e}).pipe((0,operators_1.map)((function(e){return e.partiumId})))},r.prototype.prepareFilters=function(e){return Object.keys(e).map((function(r){return{label:r,values:e[r].map((function(e){return e}))}}))},r.prototype.processSearchApiResponse=function(e){var r,t,i,s,a,n,o,c,u,l,_,p,h,d,v,g,f,m=null!==(t=null===(r=e.request)||void 0===r?void 0:r.language)&&void 0!==t?t:"",I=null!==(a=null===(s=null===(i=e.request)||void 0===i?void 0:i.matches)||void 0===s?void 0:s.organization)&&void 0!==a?a:"";return __assign(__assign({searchInput:__assign({organizationName:I,searchLanguage:m,searchSessionId:e.sessionId},e.request&&{text:null===(n=e.request.matches)||void 0===n?void 0:n.text,searchQueries:{exactText:null===(o=e.request.matches)||void 0===o?void 0:o.exact,semanticText:null===(c=e.request.matches)||void 0===c?void 0:c.text},searchImageAssetId:e.request.reusableImageId||e.imageId,searchImageCropArea:null===(u=e.request.imageOptions)||void 0===u?void 0:u.areaOfInterest,hierarchyFilters:null===(l=e.request.matches)||void 0===l?void 0:l.hierarchyPartiumIds,attributeFilters:null===(p=null===(_=e.request.matches)||void 0===_?void 0:_.filters)||void 0===p?void 0:p.reduce((function(e,r){var t;return __assign(__assign({},e),((t={})[r.label]=r.values,t))}),{}),similarTo:null===(h=e.request.matches)||void 0===h?void 0:h.similarTo,duplicateOf:null===(d=e.request.matches)||void 0===d?void 0:d.duplicateOf,hasRelatedParts:null===(v=e.request.matches)||void 0===v?void 0:v.hasRelatedParts}),resultsTotalCount:e.resultsTotalCount,searchResults:e.results.map((function(e){return part_1.Part.fromAPIResponse(e,part_1.DATA_ORIGIN.PARTIUM_API,m)}))},e.status&&{status:e.status}),{smartFilters:null!==(f=null===(g=e.smartFilters)||void 0===g?void 0:g.map((function(e){return smart_filter_1.SmartFilter.fromAPIResponse(e)})))&&void 0!==f?f:[]})},r.prototype.removeDuplicatesFromArray=function(e){return Array.from(new Set(e))},r.prototype.updateRecentTextSearch=function(e){e.searchQueries&&e.searchQueries[search_input_1.TEXT_SEARCH_TYPE.SEMANTIC]&&this.recentTextSearchQueries.addSemanticTextQuery(e.searchQueries[search_input_1.TEXT_SEARCH_TYPE.SEMANTIC]),e.searchQueries&&e.searchQueries[search_input_1.TEXT_SEARCH_TYPE.EXACT]&&(this.recentTextSearchQueries.addExactTextQuery(e.searchQueries[search_input_1.TEXT_SEARCH_TYPE.EXACT]),this.recentTextSearchQueries.addQuery(e.searchQueries[search_input_1.TEXT_SEARCH_TYPE.EXACT])),e.text&&this.recentTextSearchQueries.addQuery(e.text)},r=__decorate([(0,injection_identifier_1.InjectionIdentifier)("SearchService")],r)}(core_1.BaseLoginInitService);exports.SearchServiceImpl=SearchServiceImpl;
|
package/gen/sdk-version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Copyright © 2022-2026 Partium, Inc. DBA Partium
|
|
2
|
-
export declare const SDK_VERSION_NUMBER = "
|
|
2
|
+
export declare const SDK_VERSION_NUMBER = "16.1.0";
|
package/gen/sdk-version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Copyright © 2022-2026 Partium, Inc. DBA Partium
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SDK_VERSION_NUMBER=void 0,exports.SDK_VERSION_NUMBER="
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SDK_VERSION_NUMBER=void 0,exports.SDK_VERSION_NUMBER="16.1.0";
|