oneentry 1.0.177 → 1.0.178
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/dist/forms-data/formsDataApi.d.ts +12 -2
- package/dist/forms-data/formsDataApi.js +95 -71
- package/dist/pages/pagesApi.d.ts +2 -1
- package/dist/pages/pagesApi.js +4 -2
- package/dist/pages/pagesInterfaces.d.ts +2 -1
- package/dist/products/productsApi.d.ts +14 -8
- package/dist/products/productsApi.js +24 -12
- package/dist/products/productsInterfaces.d.ts +11 -5
- package/dist/search/searchApi.d.ts +2 -1
- package/dist/search/searchApi.js +3 -1
- package/dist/search/searchInterfaces.d.ts +2 -1
- package/esm/forms-data/formsDataApi.d.ts +12 -2
- package/esm/forms-data/formsDataApi.js +95 -71
- package/esm/pages/pagesApi.d.ts +2 -1
- package/esm/pages/pagesApi.js +4 -2
- package/esm/pages/pagesInterfaces.d.ts +2 -1
- package/esm/products/productsApi.d.ts +14 -8
- package/esm/products/productsApi.js +24 -12
- package/esm/products/productsInterfaces.d.ts +11 -5
- package/esm/search/searchApi.d.ts +2 -1
- package/esm/search/searchApi.js +3 -1
- package/esm/search/searchInterfaces.d.ts +2 -1
- package/package.json +2 -2
|
@@ -136,11 +136,21 @@ export default class FormsDataApi extends AsyncModules implements IFormsData {
|
|
|
136
136
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/getFormsDataByMarker getFormsDataByMarker} documentation.
|
|
137
137
|
*/
|
|
138
138
|
getFormsDataByMarker(marker: string, formModuleConfigId: number, body?: IFormsDataFilter, isExtended?: number, langCode?: string, offset?: number, limit?: number): Promise<IFormsByMarkerDataEntity | IError>;
|
|
139
|
+
/**
|
|
140
|
+
* Wrap the caller's flat `formData` array under its language code and upload any
|
|
141
|
+
* file fields, so the submit endpoints receive `{ [langCode]: [...] }`. Shared by
|
|
142
|
+
* postFormsData and updateFormsDataByid so the two never diverge.
|
|
143
|
+
* @param {FormDataType[]} rawFormData - Flat array of form fields.
|
|
144
|
+
* @param {string} langCode - Language code the fields are wrapped under.
|
|
145
|
+
* @returns {Promise<object>} The locale-keyed formData and the first upload error, if any.
|
|
146
|
+
*/
|
|
147
|
+
private _buildLocalizedFormData;
|
|
139
148
|
/**
|
|
140
149
|
* Update one object of form data by id. Requires user authentication.
|
|
141
150
|
* @handleName updateFormsDataByid
|
|
142
151
|
* @param {number} id - Form data ID. Example: 1.
|
|
143
|
-
* @param {
|
|
152
|
+
* @param {IBodyPostFormData} body - Form data to save: the same fields as in `postFormsData` (`formIdentifier`, `formModuleConfigId`, `moduleEntityIdentifier`, `replayTo`, `status`, `formData`). The flat `formData` array is wrapped under `langCode` before sending, exactly like `postFormsData`.
|
|
153
|
+
* @param {string} [langCode] - Language code the form fields are saved under. Default: "en_US".
|
|
144
154
|
* @example
|
|
145
155
|
{
|
|
146
156
|
"formIdentifier": "test-form",
|
|
@@ -159,7 +169,7 @@ export default class FormsDataApi extends AsyncModules implements IFormsData {
|
|
|
159
169
|
* @returns {Promise<IUpdateFormsData | IError>} Returns an object containing the updated form data or an error object if there was an issue.
|
|
160
170
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/updateFormsDataByid updateFormsDataByid} documentation.
|
|
161
171
|
*/
|
|
162
|
-
updateFormsDataByid(id: number, body?:
|
|
172
|
+
updateFormsDataByid(id: number, body: IBodyPostFormData, langCode?: string): Promise<IUpdateFormsData | IError>;
|
|
163
173
|
/**
|
|
164
174
|
* Update form data status by id. Requires user authentication.
|
|
165
175
|
* @handleName updateFormsDataStatusByid
|
|
@@ -104,73 +104,8 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
104
104
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/postFormsData postFormsData} documentation.
|
|
105
105
|
*/
|
|
106
106
|
async postFormsData(body, langCode = this.state.lang) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
formData[langCode] = Array.isArray(body.formData)
|
|
110
|
-
? body.formData.filter((fd) => fd.type !== 'button')
|
|
111
|
-
: [body.formData].filter((fd) => fd.type !== 'button');
|
|
112
|
-
/**
|
|
113
|
-
* Handle file uploads if fileQuery is present
|
|
114
|
-
* Check if there is any element in formData[langCode] that contains one of the specified types
|
|
115
|
-
*/
|
|
116
|
-
if (formData[langCode].find((fd) => ['file', 'image', 'groupOfImages'].includes(fd.type))) {
|
|
117
|
-
// Create an instance of FileUploadingApi with the current state
|
|
118
|
-
const fileUploader = new fileUploadingApi_1.default(this.state);
|
|
119
|
-
// Process each element in formData[langCode] asynchronously
|
|
120
|
-
formData[langCode] = await Promise.all(formData[langCode].map(async (field) => {
|
|
121
|
-
// Check if the type is one of the specified types
|
|
122
|
-
if (['file', 'image', 'groupOfImages'].includes(field.type)) {
|
|
123
|
-
// Work on a copy: the caller's field keeps its File and its fileQuery,
|
|
124
|
-
// so a reused body sends the same form again (CMS-1071)
|
|
125
|
-
const fd = { ...field };
|
|
126
|
-
// If fileQuery does not exist, we create it and assign it to an object with the following properties:
|
|
127
|
-
if (!fd.fileQuery) {
|
|
128
|
-
const fileQuery = {
|
|
129
|
-
type: 'page',
|
|
130
|
-
entity: 'editor',
|
|
131
|
-
// Generate a random 4-digit ID
|
|
132
|
-
id: Number(Math.floor(Math.random() * 10000)
|
|
133
|
-
.toString()
|
|
134
|
-
.padStart(4, '0')),
|
|
135
|
-
};
|
|
136
|
-
fd.fileQuery = fileQuery;
|
|
137
|
-
}
|
|
138
|
-
// Convert fd.value to an array if it is a FileList, otherwise use it directly
|
|
139
|
-
const filesArray = typeof FileList !== 'undefined' && fd.value instanceof FileList
|
|
140
|
-
? Array.from(fd.value)
|
|
141
|
-
: fd.value;
|
|
142
|
-
// If filesArray is an array, upload the files it holds asynchronously
|
|
143
|
-
if (Array.isArray(filesArray)) {
|
|
144
|
-
const uploadPromises = filesArray.map((file) =>
|
|
145
|
-
// An entry that is already in storage is passed through: a
|
|
146
|
-
// second upload would send the descriptor itself as the file
|
|
147
|
-
// and the endpoint answers `value[0].filename is required`.
|
|
148
|
-
this._isUploadable(file)
|
|
149
|
-
? fileUploader.upload(file, fd.fileQuery).catch((e) => e)
|
|
150
|
-
: file);
|
|
151
|
-
fd.value = (await Promise.all(uploadPromises)).flat();
|
|
152
|
-
}
|
|
153
|
-
// If fd.value is a single File or Blob, upload it
|
|
154
|
-
else if (this._isUploadable(fd.value)) {
|
|
155
|
-
fd.value = await fileUploader
|
|
156
|
-
.upload(fd.value, fd.fileQuery)
|
|
157
|
-
.catch((e) => e); // Catch any errors during upload
|
|
158
|
-
}
|
|
159
|
-
// Remove the 'fileQuery' property from the object after processing
|
|
160
|
-
delete fd.fileQuery;
|
|
161
|
-
// Remove the 'contentType' property from the file object because it is not needed and not valid
|
|
162
|
-
fd.value = this._stripContentType(fd.value);
|
|
163
|
-
return fd;
|
|
164
|
-
}
|
|
165
|
-
// Return the form data element untouched
|
|
166
|
-
return field;
|
|
167
|
-
}));
|
|
168
|
-
}
|
|
169
|
-
// A failed upload used to be sent to the platform as the field's value, and the caller
|
|
170
|
-
// got a success: the form is not sent, the upload's error is the answer
|
|
171
|
-
const uploadError = formData[langCode]
|
|
172
|
-
.flatMap((field) => Array.isArray(field === null || field === void 0 ? void 0 : field.value) ? field.value : [field === null || field === void 0 ? void 0 : field.value])
|
|
173
|
-
.find((value) => this._isErrorResponse(value));
|
|
107
|
+
// Wrap the flat formData under langCode (and upload any files) before sending
|
|
108
|
+
const { formData, uploadError } = await this._buildLocalizedFormData(body.formData, langCode);
|
|
174
109
|
if (uploadError) {
|
|
175
110
|
if (this.state.isShell) {
|
|
176
111
|
return uploadError;
|
|
@@ -288,11 +223,90 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
288
223
|
const validated = await this._validateResponse(result, schema('FormsByMarkerDataResponseSchema'));
|
|
289
224
|
return this._normalizeData(validated, langCode);
|
|
290
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Wrap the caller's flat `formData` array under its language code and upload any
|
|
228
|
+
* file fields, so the submit endpoints receive `{ [langCode]: [...] }`. Shared by
|
|
229
|
+
* postFormsData and updateFormsDataByid so the two never diverge.
|
|
230
|
+
* @param {FormDataType[]} rawFormData - Flat array of form fields.
|
|
231
|
+
* @param {string} langCode - Language code the fields are wrapped under.
|
|
232
|
+
* @returns {Promise<object>} The locale-keyed formData and the first upload error, if any.
|
|
233
|
+
*/
|
|
234
|
+
async _buildLocalizedFormData(rawFormData, langCode) {
|
|
235
|
+
const formData = {};
|
|
236
|
+
// filter button fields; keep spam fields so the captcha token in their `value` reaches the server
|
|
237
|
+
formData[langCode] = Array.isArray(rawFormData)
|
|
238
|
+
? rawFormData.filter((fd) => fd.type !== 'button')
|
|
239
|
+
: [rawFormData].filter((fd) => fd.type !== 'button');
|
|
240
|
+
/**
|
|
241
|
+
* Handle file uploads if fileQuery is present
|
|
242
|
+
* Check if there is any element in formData[langCode] that contains one of the specified types
|
|
243
|
+
*/
|
|
244
|
+
if (formData[langCode].find((fd) => ['file', 'image', 'groupOfImages'].includes(fd.type))) {
|
|
245
|
+
// Create an instance of FileUploadingApi with the current state
|
|
246
|
+
const fileUploader = new fileUploadingApi_1.default(this.state);
|
|
247
|
+
// Process each element in formData[langCode] asynchronously
|
|
248
|
+
formData[langCode] = await Promise.all(formData[langCode].map(async (field) => {
|
|
249
|
+
// Check if the type is one of the specified types
|
|
250
|
+
if (['file', 'image', 'groupOfImages'].includes(field.type)) {
|
|
251
|
+
// Work on a copy: the caller's field keeps its File and its fileQuery,
|
|
252
|
+
// so a reused body sends the same form again (CMS-1071)
|
|
253
|
+
const fd = { ...field };
|
|
254
|
+
// If fileQuery does not exist, we create it and assign it to an object with the following properties:
|
|
255
|
+
if (!fd.fileQuery) {
|
|
256
|
+
const fileQuery = {
|
|
257
|
+
type: 'page',
|
|
258
|
+
entity: 'editor',
|
|
259
|
+
// Generate a random 4-digit ID
|
|
260
|
+
id: Number(Math.floor(Math.random() * 10000)
|
|
261
|
+
.toString()
|
|
262
|
+
.padStart(4, '0')),
|
|
263
|
+
};
|
|
264
|
+
fd.fileQuery = fileQuery;
|
|
265
|
+
}
|
|
266
|
+
// Convert fd.value to an array if it is a FileList, otherwise use it directly
|
|
267
|
+
const filesArray = typeof FileList !== 'undefined' && fd.value instanceof FileList
|
|
268
|
+
? Array.from(fd.value)
|
|
269
|
+
: fd.value;
|
|
270
|
+
// If filesArray is an array, upload the files it holds asynchronously
|
|
271
|
+
if (Array.isArray(filesArray)) {
|
|
272
|
+
const uploadPromises = filesArray.map((file) =>
|
|
273
|
+
// An entry that is already in storage is passed through: a
|
|
274
|
+
// second upload would send the descriptor itself as the file
|
|
275
|
+
// and the endpoint answers `value[0].filename is required`.
|
|
276
|
+
this._isUploadable(file)
|
|
277
|
+
? fileUploader.upload(file, fd.fileQuery).catch((e) => e)
|
|
278
|
+
: file);
|
|
279
|
+
fd.value = (await Promise.all(uploadPromises)).flat();
|
|
280
|
+
}
|
|
281
|
+
// If fd.value is a single File or Blob, upload it
|
|
282
|
+
else if (this._isUploadable(fd.value)) {
|
|
283
|
+
fd.value = await fileUploader
|
|
284
|
+
.upload(fd.value, fd.fileQuery)
|
|
285
|
+
.catch((e) => e); // Catch any errors during upload
|
|
286
|
+
}
|
|
287
|
+
// Remove the 'fileQuery' property from the object after processing
|
|
288
|
+
delete fd.fileQuery;
|
|
289
|
+
// Remove the 'contentType' property from the file object because it is not needed and not valid
|
|
290
|
+
fd.value = this._stripContentType(fd.value);
|
|
291
|
+
return fd;
|
|
292
|
+
}
|
|
293
|
+
// Return the form data element untouched
|
|
294
|
+
return field;
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
// A failed upload used to be sent to the platform as the field's value, and the caller
|
|
298
|
+
// got a success: the form is not sent, the upload's error is the answer
|
|
299
|
+
const uploadError = formData[langCode]
|
|
300
|
+
.flatMap((field) => Array.isArray(field === null || field === void 0 ? void 0 : field.value) ? field.value : [field === null || field === void 0 ? void 0 : field.value])
|
|
301
|
+
.find((value) => this._isErrorResponse(value));
|
|
302
|
+
return { formData, uploadError };
|
|
303
|
+
}
|
|
291
304
|
/**
|
|
292
305
|
* Update one object of form data by id. Requires user authentication.
|
|
293
306
|
* @handleName updateFormsDataByid
|
|
294
307
|
* @param {number} id - Form data ID. Example: 1.
|
|
295
|
-
* @param {
|
|
308
|
+
* @param {IBodyPostFormData} body - Form data to save: the same fields as in `postFormsData` (`formIdentifier`, `formModuleConfigId`, `moduleEntityIdentifier`, `replayTo`, `status`, `formData`). The flat `formData` array is wrapped under `langCode` before sending, exactly like `postFormsData`.
|
|
309
|
+
* @param {string} [langCode] - Language code the form fields are saved under. Default: "en_US".
|
|
296
310
|
* @example
|
|
297
311
|
{
|
|
298
312
|
"formIdentifier": "test-form",
|
|
@@ -311,11 +325,21 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
311
325
|
* @returns {Promise<IUpdateFormsData | IError>} Returns an object containing the updated form data or an error object if there was an issue.
|
|
312
326
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/updateFormsDataByid updateFormsDataByid} documentation.
|
|
313
327
|
*/
|
|
314
|
-
async updateFormsDataByid(id, body =
|
|
315
|
-
|
|
328
|
+
async updateFormsDataByid(id, body, langCode = this.state.lang) {
|
|
329
|
+
// Wrap the flat formData under langCode (and upload any files) — the endpoint
|
|
330
|
+
// rejects a flat array with `400 formData must be ... keyed by lang code`
|
|
331
|
+
const { formData, uploadError } = await this._buildLocalizedFormData(body.formData, langCode);
|
|
332
|
+
if (uploadError) {
|
|
333
|
+
if (this.state.isShell) {
|
|
334
|
+
return uploadError;
|
|
335
|
+
}
|
|
336
|
+
throw uploadError;
|
|
337
|
+
}
|
|
338
|
+
const result = await this._fetchPut(`/${this._pathSegment(String(id))}`, { ...body, formData });
|
|
316
339
|
// Validate response if validation is enabled
|
|
317
340
|
const validated = await this._validateResponse(result, schema('UpdateFormsDataSchema'));
|
|
318
|
-
|
|
341
|
+
// The fields went in under `langCode`, so unwrap the response from the same locale
|
|
342
|
+
return this._normalizeData(validated, langCode);
|
|
319
343
|
}
|
|
320
344
|
/**
|
|
321
345
|
* Update form data status by id. Requires user authentication.
|
package/dist/pages/pagesApi.d.ts
CHANGED
|
@@ -86,12 +86,13 @@ export default class PagesApi extends AsyncModules implements IPagesApi {
|
|
|
86
86
|
* @param {string} name - Text to search for in page titles (`localizeInfos.title`) in the requested language. Example: "About Us".
|
|
87
87
|
* @param {string} [url] - Page URL. Example: "catalog".
|
|
88
88
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
89
|
+
* @param {boolean} [correct] - Correct typos by the project's search dictionary first. The API defaults to `true`; pass `false` to search the query as is.
|
|
89
90
|
* @returns {Promise<IPagesEntity[] | IPageSearchResult[] | IError>} Returns found pages as an array of PageEntity objects, an array of short PageSearchResult cards when the traficLimit config option is enabled, or an empty array [] (if there is no data)
|
|
90
91
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
91
92
|
* @description Quick search for page objects with limited output. The quick search endpoint returns short cards ({ id, title }); with traficLimit enabled they are returned as is, otherwise full page entities are fetched for the found ids. The search runs in `langCode`, and a found page that cannot be loaded in that language is left out of the result.
|
|
92
93
|
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/searchPage searchPage} documentation.
|
|
93
94
|
*/
|
|
94
|
-
searchPage(name: string, url?: string, langCode?: string): Promise<IPagesEntity[] | IPageSearchResult[] | IError>;
|
|
95
|
+
searchPage(name: string, url?: string, langCode?: string, correct?: boolean): Promise<IPagesEntity[] | IPageSearchResult[] | IError>;
|
|
95
96
|
/**
|
|
96
97
|
* Semantic (vector) search for pages.
|
|
97
98
|
* @handleName getPagesByVectorSearch
|
package/dist/pages/pagesApi.js
CHANGED
|
@@ -223,15 +223,17 @@ class PagesApi extends asyncModules_1.default {
|
|
|
223
223
|
* @param {string} name - Text to search for in page titles (`localizeInfos.title`) in the requested language. Example: "About Us".
|
|
224
224
|
* @param {string} [url] - Page URL. Example: "catalog".
|
|
225
225
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
226
|
+
* @param {boolean} [correct] - Correct typos by the project's search dictionary first. The API defaults to `true`; pass `false` to search the query as is.
|
|
226
227
|
* @returns {Promise<IPagesEntity[] | IPageSearchResult[] | IError>} Returns found pages as an array of PageEntity objects, an array of short PageSearchResult cards when the traficLimit config option is enabled, or an empty array [] (if there is no data)
|
|
227
228
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
228
229
|
* @description Quick search for page objects with limited output. The quick search endpoint returns short cards ({ id, title }); with traficLimit enabled they are returned as is, otherwise full page entities are fetched for the found ids. The search runs in `langCode`, and a found page that cannot be loaded in that language is left out of the result.
|
|
229
230
|
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/searchPage searchPage} documentation.
|
|
230
231
|
*/
|
|
231
|
-
async searchPage(name, url, langCode = this.state.lang) {
|
|
232
|
+
async searchPage(name, url, langCode = this.state.lang, correct) {
|
|
232
233
|
// Fetch data from the server using a GET request to perform a quick search by page name and language code
|
|
233
234
|
const urlPart = url ? `url=${encodeURIComponent(url)}&` : '';
|
|
234
|
-
const
|
|
235
|
+
const correctPart = correct !== undefined ? `&correct=${correct}` : '';
|
|
236
|
+
const searchPages = await this._fetchGet(`/quick/search?${urlPart}langCode=${encodeURIComponent(langCode)}&name=${encodeURIComponent(name)}${correctPart}`);
|
|
235
237
|
// Validate response if validation is enabled
|
|
236
238
|
const data = (await this._validateResponse(searchPages, schema('PageSearchResponseSchema')));
|
|
237
239
|
// Check if there is no traffic limit set in the state
|
|
@@ -72,11 +72,12 @@ interface IPagesApi {
|
|
|
72
72
|
* @param {string} name - Text to search for in page titles (`localizeInfos.title`) in the requested language. Example: "About Us".
|
|
73
73
|
* @param {string} [url] - Optional page URL to filter search results. Example: "catalog".
|
|
74
74
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
75
|
+
* @param {boolean} [correct] - Correct typos by the project's search dictionary first. The API defaults to `true`; pass `false` to search the query as is.
|
|
75
76
|
* @returns {IPagesEntity[] | IPageSearchResult[]} Returns found pages as an array of PageEntity objects, an array of short PageSearchResult cards when the traficLimit config option is enabled, or an empty array [] (if there is no data)
|
|
76
77
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
77
78
|
* @description This method performs a quick search for page objects with limited output. With traficLimit enabled the raw quick search response is returned as short cards; otherwise full page entities are fetched for the found ids.
|
|
78
79
|
*/
|
|
79
|
-
searchPage(name: string, url?: string, langCode?: LangType): Promise<IPagesEntity[] | IPageSearchResult[] | IError>;
|
|
80
|
+
searchPage(name: string, url?: string, langCode?: LangType, correct?: boolean): Promise<IPagesEntity[] | IPageSearchResult[] | IError>;
|
|
80
81
|
/**
|
|
81
82
|
* Semantic (vector) search for pages.
|
|
82
83
|
* @handleName getPagesByVectorSearch
|
|
@@ -247,12 +247,13 @@ export default class ProductsApi extends AsyncModules implements IProductsApi {
|
|
|
247
247
|
* @param {number} id - Product ID. Example: 12345.
|
|
248
248
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
249
249
|
* @param {boolean} [isNormalized] - Deprecated: the API no longer reads it, the answer is the same with `true`, `false` or without it. Kept for compatibility.
|
|
250
|
+
* @param {string} [signPrice] - Marker of an orders storage to fix the price for. When set, the product comes with a `signedPrice` holding the price for a limited time; an unknown marker fails the request with `404 Specified orders storage for price signature not found`.
|
|
250
251
|
* @returns {Promise<IProductsEntity | IError>} ProductEntity object.
|
|
251
252
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
252
253
|
* @description Retrieve one product object. A product with no translation in `langCode` answers `404 Product not found` — there is no fallback to another language.
|
|
253
254
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductById getProductById} documentation.
|
|
254
255
|
*/
|
|
255
|
-
getProductById(id: number, langCode?: string, isNormalized?: boolean): Promise<IProductsEntity | IError>;
|
|
256
|
+
getProductById(id: number, langCode?: string, isNormalized?: boolean, signPrice?: string): Promise<IProductsEntity | IError>;
|
|
256
257
|
/**
|
|
257
258
|
* Getting a product block object by product id.
|
|
258
259
|
* @handleName getProductBlockById
|
|
@@ -269,16 +270,19 @@ export default class ProductsApi extends AsyncModules implements IProductsApi {
|
|
|
269
270
|
* @handleName searchProduct
|
|
270
271
|
* @param {string} name - Text to search for in product titles (`localizeInfos.title`) in the requested language. Example: "laminat".
|
|
271
272
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
273
|
+
* @param {string} [url] - URL of a catalog page to search within that category. Default: the whole catalog.
|
|
274
|
+
* @param {boolean} [correct] - Correct typos by the project's search dictionary first. The API defaults to `true`; pass `false` to search the query as is.
|
|
272
275
|
* @returns {Promise<IProductsEntity[] | IProductSearchResult[] | IError>} Array with ProductEntity objects, or an array with short ProductSearchResult cards when the traficLimit config option is enabled
|
|
273
276
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
274
277
|
* @description Quick search for product page objects with limited output. The quick search endpoint returns short cards ({ id, title, pageId }); with traficLimit enabled they are returned as is, otherwise full product entities are fetched for the found ids.
|
|
275
278
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/searchProduct searchProduct} documentation.
|
|
276
279
|
*/
|
|
277
|
-
searchProduct(name: string, langCode?: string): Promise<IProductsEntity[] | IProductSearchResult[] | IError>;
|
|
280
|
+
searchProduct(name: string, langCode?: string, url?: string, correct?: boolean): Promise<IProductsEntity[] | IProductSearchResult[] | IError>;
|
|
278
281
|
/**
|
|
279
282
|
* Getting the number of products for the entire catalog.
|
|
280
283
|
* @handleName getProductsCount
|
|
281
284
|
* @param {any[]} [body] - Filter objects with search conditions. Default: `[]`.
|
|
285
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be one of the project's active languages — an inactive one answers `400 langCode must be one of the active languages`. The count reflects the products visible in that language.
|
|
282
286
|
* @example
|
|
283
287
|
[
|
|
284
288
|
{
|
|
@@ -289,15 +293,16 @@ export default class ProductsApi extends AsyncModules implements IProductsApi {
|
|
|
289
293
|
]
|
|
290
294
|
* @returns {Promise<IProductsCount | IError>} Object with product items count.
|
|
291
295
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
292
|
-
* @description This method calculates and returns the total number of products present across the entire catalog, optionally applying specified filters.
|
|
296
|
+
* @description This method calculates and returns the total number of products present across the entire catalog, optionally applying specified filters. The request carries `langCode`; it must be an active language of the project, otherwise the API answers `400`.
|
|
293
297
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductsCount getProductsCount} documentation.
|
|
294
298
|
*/
|
|
295
|
-
getProductsCount(body?: any[]): Promise<IProductsCount | IError>;
|
|
299
|
+
getProductsCount(body?: any[], langCode?: string): Promise<IProductsCount | IError>;
|
|
296
300
|
/**
|
|
297
301
|
* Getting the number of products on a catalog page by page ID.
|
|
298
302
|
* @handleName getProductsCountByPageId
|
|
299
303
|
* @param {number | string} id - Page ID. Example: 12345.
|
|
300
304
|
* @param {any[]} [body] - Filter objects with search conditions. Default: `[]`.
|
|
305
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be one of the project's active languages — an inactive one answers `400 langCode must be one of the active languages`. The count reflects the products visible in that language.
|
|
301
306
|
* @example
|
|
302
307
|
[
|
|
303
308
|
{
|
|
@@ -308,10 +313,10 @@ export default class ProductsApi extends AsyncModules implements IProductsApi {
|
|
|
308
313
|
]
|
|
309
314
|
* @returns {Promise<IProductsCount | IError>} Object with product items count.
|
|
310
315
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
311
|
-
* @description This method calculates and returns the number of products available on a given catalog page, identified by its page ID, with optional filtering. The
|
|
316
|
+
* @description This method calculates and returns the number of products available on a given catalog page, identified by its page ID, with optional filtering. The request carries `langCode`; it must be an active language of the project (an inactive one answers `400`), and the count reflects the products visible in that language.
|
|
312
317
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductsCountByPageId getProductsCountByPageId} documentation.
|
|
313
318
|
*/
|
|
314
|
-
getProductsCountByPageId(id: number | string, body?: any[]): Promise<IProductsCount | IError>;
|
|
319
|
+
getProductsCountByPageId(id: number | string, body?: any[], langCode?: string): Promise<IProductsCount | IError>;
|
|
315
320
|
/**
|
|
316
321
|
* Semantic (vector) search for products.
|
|
317
322
|
* @handleName getProductsByVectorSearch
|
|
@@ -330,6 +335,7 @@ export default class ProductsApi extends AsyncModules implements IProductsApi {
|
|
|
330
335
|
* @handleName getProductsCountByPageUrl
|
|
331
336
|
* @param {string} url - Page URL. Example: "catalog".
|
|
332
337
|
* @param {any[]} [body] - Filter objects with search conditions. Default: `[]`.
|
|
338
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be one of the project's active languages — an inactive one answers `400 langCode must be one of the active languages`. The count reflects the products visible in that language.
|
|
333
339
|
* @example
|
|
334
340
|
[
|
|
335
341
|
{
|
|
@@ -340,8 +346,8 @@ export default class ProductsApi extends AsyncModules implements IProductsApi {
|
|
|
340
346
|
]
|
|
341
347
|
* @returns {Promise<IProductsCount | IError>} Object with product items count.
|
|
342
348
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
343
|
-
* @description This method calculates and returns the number of products available on a given catalog page, identified by its URL, with optional filtering. The
|
|
349
|
+
* @description This method calculates and returns the number of products available on a given catalog page, identified by its URL, with optional filtering. The request carries `langCode`; it must be an active language of the project (an inactive one answers `400`), and the count reflects the products visible in that language.
|
|
344
350
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductsCountByPageUrl getProductsCountByPageUrl} documentation.
|
|
345
351
|
*/
|
|
346
|
-
getProductsCountByPageUrl(url: string, body?: any[]): Promise<IProductsCount | IError>;
|
|
352
|
+
getProductsCountByPageUrl(url: string, body?: any[], langCode?: string): Promise<IProductsCount | IError>;
|
|
347
353
|
}
|
|
@@ -339,15 +339,18 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
339
339
|
* @param {number} id - Product ID. Example: 12345.
|
|
340
340
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
341
341
|
* @param {boolean} [isNormalized] - Deprecated: the API no longer reads it, the answer is the same with `true`, `false` or without it. Kept for compatibility.
|
|
342
|
+
* @param {string} [signPrice] - Marker of an orders storage to fix the price for. When set, the product comes with a `signedPrice` holding the price for a limited time; an unknown marker fails the request with `404 Specified orders storage for price signature not found`.
|
|
342
343
|
* @returns {Promise<IProductsEntity | IError>} ProductEntity object.
|
|
343
344
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
344
345
|
* @description Retrieve one product object. A product with no translation in `langCode` answers `404 Product not found` — there is no fallback to another language.
|
|
345
346
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductById getProductById} documentation.
|
|
346
347
|
*/
|
|
347
|
-
async getProductById(id, langCode = this.state.lang, isNormalized) {
|
|
348
|
+
async getProductById(id, langCode = this.state.lang, isNormalized, signPrice) {
|
|
348
349
|
const query = { langCode };
|
|
349
350
|
if (isNormalized !== undefined)
|
|
350
351
|
query.isNormalized = isNormalized;
|
|
352
|
+
if (signPrice !== undefined)
|
|
353
|
+
query.signPrice = signPrice;
|
|
351
354
|
const result = await this._fetchGet(`/${this._pathSegment(String(id))}?` + this._queryParamsToString(query));
|
|
352
355
|
// Validate response if validation is enabled
|
|
353
356
|
const validated = await this._validateResponse(result, schema('ProductEntitySchema'));
|
|
@@ -375,13 +378,17 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
375
378
|
* @handleName searchProduct
|
|
376
379
|
* @param {string} name - Text to search for in product titles (`localizeInfos.title`) in the requested language. Example: "laminat".
|
|
377
380
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
381
|
+
* @param {string} [url] - URL of a catalog page to search within that category. Default: the whole catalog.
|
|
382
|
+
* @param {boolean} [correct] - Correct typos by the project's search dictionary first. The API defaults to `true`; pass `false` to search the query as is.
|
|
378
383
|
* @returns {Promise<IProductsEntity[] | IProductSearchResult[] | IError>} Array with ProductEntity objects, or an array with short ProductSearchResult cards when the traficLimit config option is enabled
|
|
379
384
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
380
385
|
* @description Quick search for product page objects with limited output. The quick search endpoint returns short cards ({ id, title, pageId }); with traficLimit enabled they are returned as is, otherwise full product entities are fetched for the found ids.
|
|
381
386
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/searchProduct searchProduct} documentation.
|
|
382
387
|
*/
|
|
383
|
-
async searchProduct(name, langCode = this.state.lang) {
|
|
384
|
-
const
|
|
388
|
+
async searchProduct(name, langCode = this.state.lang, url, correct) {
|
|
389
|
+
const extra = (url ? `&url=${encodeURIComponent(url)}` : '') +
|
|
390
|
+
(correct !== undefined ? `&correct=${correct}` : '');
|
|
391
|
+
const result = await this._fetchGet(`/quick/search?langCode=${encodeURIComponent(langCode)}&name=${encodeURIComponent(name)}${extra}`);
|
|
385
392
|
// Validate response if validation is enabled
|
|
386
393
|
const searchProducts = (await this._validateResponse(result, schema('ProductSearchResponseSchema')));
|
|
387
394
|
if (!this.state.traficLimit && Array.isArray(searchProducts)) {
|
|
@@ -405,6 +412,7 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
405
412
|
* Getting the number of products for the entire catalog.
|
|
406
413
|
* @handleName getProductsCount
|
|
407
414
|
* @param {any[]} [body] - Filter objects with search conditions. Default: `[]`.
|
|
415
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be one of the project's active languages — an inactive one answers `400 langCode must be one of the active languages`. The count reflects the products visible in that language.
|
|
408
416
|
* @example
|
|
409
417
|
[
|
|
410
418
|
{
|
|
@@ -415,13 +423,13 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
415
423
|
]
|
|
416
424
|
* @returns {Promise<IProductsCount | IError>} Object with product items count.
|
|
417
425
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
418
|
-
* @description This method calculates and returns the total number of products present across the entire catalog, optionally applying specified filters.
|
|
426
|
+
* @description This method calculates and returns the total number of products present across the entire catalog, optionally applying specified filters. The request carries `langCode`; it must be an active language of the project, otherwise the API answers `400`.
|
|
419
427
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductsCount getProductsCount} documentation.
|
|
420
428
|
*/
|
|
421
429
|
async getProductsCount(
|
|
422
430
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
423
|
-
body = []) {
|
|
424
|
-
const result = await this._fetchPost(`/all/counts
|
|
431
|
+
body = [], langCode = this.state.lang) {
|
|
432
|
+
const result = await this._fetchPost(`/all/counts?` + this._queryParamsToString({ langCode }), body);
|
|
425
433
|
return result;
|
|
426
434
|
}
|
|
427
435
|
/**
|
|
@@ -429,6 +437,7 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
429
437
|
* @handleName getProductsCountByPageId
|
|
430
438
|
* @param {number | string} id - Page ID. Example: 12345.
|
|
431
439
|
* @param {any[]} [body] - Filter objects with search conditions. Default: `[]`.
|
|
440
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be one of the project's active languages — an inactive one answers `400 langCode must be one of the active languages`. The count reflects the products visible in that language.
|
|
432
441
|
* @example
|
|
433
442
|
[
|
|
434
443
|
{
|
|
@@ -439,13 +448,14 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
439
448
|
]
|
|
440
449
|
* @returns {Promise<IProductsCount | IError>} Object with product items count.
|
|
441
450
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
442
|
-
* @description This method calculates and returns the number of products available on a given catalog page, identified by its page ID, with optional filtering. The
|
|
451
|
+
* @description This method calculates and returns the number of products available on a given catalog page, identified by its page ID, with optional filtering. The request carries `langCode`; it must be an active language of the project (an inactive one answers `400`), and the count reflects the products visible in that language.
|
|
443
452
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductsCountByPageId getProductsCountByPageId} documentation.
|
|
444
453
|
*/
|
|
445
454
|
async getProductsCountByPageId(id,
|
|
446
455
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
447
|
-
body = []) {
|
|
448
|
-
const result = await this._fetchPost(`/page/${this._pathSegment(String(id))}/counts
|
|
456
|
+
body = [], langCode = this.state.lang) {
|
|
457
|
+
const result = await this._fetchPost(`/page/${this._pathSegment(String(id))}/counts?` +
|
|
458
|
+
this._queryParamsToString({ langCode }), body);
|
|
449
459
|
return result;
|
|
450
460
|
}
|
|
451
461
|
/**
|
|
@@ -474,6 +484,7 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
474
484
|
* @handleName getProductsCountByPageUrl
|
|
475
485
|
* @param {string} url - Page URL. Example: "catalog".
|
|
476
486
|
* @param {any[]} [body] - Filter objects with search conditions. Default: `[]`.
|
|
487
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be one of the project's active languages — an inactive one answers `400 langCode must be one of the active languages`. The count reflects the products visible in that language.
|
|
477
488
|
* @example
|
|
478
489
|
[
|
|
479
490
|
{
|
|
@@ -484,13 +495,14 @@ class ProductsApi extends asyncModules_1.default {
|
|
|
484
495
|
]
|
|
485
496
|
* @returns {Promise<IProductsCount | IError>} Object with product items count.
|
|
486
497
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
487
|
-
* @description This method calculates and returns the number of products available on a given catalog page, identified by its URL, with optional filtering. The
|
|
498
|
+
* @description This method calculates and returns the number of products available on a given catalog page, identified by its URL, with optional filtering. The request carries `langCode`; it must be an active language of the project (an inactive one answers `400`), and the count reflects the products visible in that language.
|
|
488
499
|
* @see {@link https://js-sdk.oneentry.cloud/docs/products/getProductsCountByPageUrl getProductsCountByPageUrl} documentation.
|
|
489
500
|
*/
|
|
490
501
|
async getProductsCountByPageUrl(url,
|
|
491
502
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
492
|
-
body = []) {
|
|
493
|
-
const result = await this._fetchPost(`/page/url/${this._pathSegments(url)}/counts
|
|
503
|
+
body = [], langCode = this.state.lang) {
|
|
504
|
+
const result = await this._fetchPost(`/page/url/${this._pathSegments(url)}/counts?` +
|
|
505
|
+
this._queryParamsToString({ langCode }), body);
|
|
494
506
|
return result;
|
|
495
507
|
}
|
|
496
508
|
}
|
|
@@ -170,11 +170,12 @@ interface IProductsApi {
|
|
|
170
170
|
* @param {number} id - Product ID. Example: 12345.
|
|
171
171
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
172
172
|
* @param {boolean} [isNormalized] - Deprecated: the API no longer reads it, the answer is the same with `true`, `false` or without it. Kept for compatibility.
|
|
173
|
+
* @param {string} [signPrice] - Marker of an orders storage to fix the price for; the product then carries a `signedPrice`. An unknown marker answers `404`.
|
|
173
174
|
* @returns {IProductsEntity} ProductEntity object.
|
|
174
175
|
* @throws {IError} If there is an error during the fetch operation, it will return an error object.
|
|
175
176
|
* @description This method retrieves one product object.
|
|
176
177
|
*/
|
|
177
|
-
getProductById(id: number, langCode?: string, isNormalized?: boolean): Promise<IProductsEntity | IError>;
|
|
178
|
+
getProductById(id: number, langCode?: string, isNormalized?: boolean, signPrice?: string): Promise<IProductsEntity | IError>;
|
|
178
179
|
/**
|
|
179
180
|
* Getting a product block object by product id.
|
|
180
181
|
* @handleName getProductBlockById
|
|
@@ -190,11 +191,13 @@ interface IProductsApi {
|
|
|
190
191
|
* @handleName searchProduct
|
|
191
192
|
* @param {string} name - Text to search for in product titles (`localizeInfos.title`) in the requested language. Example: 'laminat'.
|
|
192
193
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
194
|
+
* @param {string} [url] - URL of a catalog page to search within that category. Default: the whole catalog.
|
|
195
|
+
* @param {boolean} [correct] - Correct typos by the project's search dictionary first. The API defaults to `true`; pass `false` to search the query as is.
|
|
193
196
|
* @returns {IProductsEntity[] | IProductSearchResult[]} Array with ProductEntity objects, or an array with short ProductSearchResult cards when the traficLimit config option is enabled
|
|
194
197
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
195
198
|
* @description This method performs a quick search for product page objects with limited output. With traficLimit enabled the raw quick search response is returned as short cards; otherwise full product entities are fetched for the found ids.
|
|
196
199
|
*/
|
|
197
|
-
searchProduct(name: string, langCode?: string): Promise<IProductsEntity[] | IProductSearchResult[] | IError>;
|
|
200
|
+
searchProduct(name: string, langCode?: string, url?: string, correct?: boolean): Promise<IProductsEntity[] | IProductSearchResult[] | IError>;
|
|
198
201
|
/**
|
|
199
202
|
* Getting the number of products for the entire catalog.
|
|
200
203
|
* @handleName getProductsCount
|
|
@@ -209,9 +212,10 @@ interface IProductsApi {
|
|
|
209
212
|
]
|
|
210
213
|
* @returns {IProductsCount} Object with product items count.
|
|
211
214
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
215
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be an active language of the project — an inactive one answers `400`; the count reflects products visible in that language.
|
|
212
216
|
* @description This method calculates and returns the total number of products present across the entire catalog, optionally applying specified filters.
|
|
213
217
|
*/
|
|
214
|
-
getProductsCount(body?: object[]): Promise<IProductsCount | IError>;
|
|
218
|
+
getProductsCount(body?: object[], langCode?: string): Promise<IProductsCount | IError>;
|
|
215
219
|
/**
|
|
216
220
|
* Getting the number of products on a catalog page by page ID.
|
|
217
221
|
* @handleName getProductsCountByPageId
|
|
@@ -227,9 +231,10 @@ interface IProductsApi {
|
|
|
227
231
|
]
|
|
228
232
|
* @returns {IProductsCount} Object with product items count.
|
|
229
233
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
234
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be an active language of the project — an inactive one answers `400`; the count reflects products visible in that language.
|
|
230
235
|
* @description This method calculates and returns the number of products available on a given catalog page, identified by its page ID, with optional filtering.
|
|
231
236
|
*/
|
|
232
|
-
getProductsCountByPageId(id: number | string, body?: object[]): Promise<IProductsCount | IError>;
|
|
237
|
+
getProductsCountByPageId(id: number | string, body?: object[], langCode?: string): Promise<IProductsCount | IError>;
|
|
233
238
|
/**
|
|
234
239
|
* Getting the number of products on a catalog page by page URL.
|
|
235
240
|
* @handleName getProductsCountByPageUrl
|
|
@@ -245,9 +250,10 @@ interface IProductsApi {
|
|
|
245
250
|
]
|
|
246
251
|
* @returns {IProductsCount} Object with product items count.
|
|
247
252
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
253
|
+
* @param {string} [langCode] - Language code. Default: "en_US". Must be an active language of the project — an inactive one answers `400`; the count reflects products visible in that language.
|
|
248
254
|
* @description This method calculates and returns the number of products available on a given catalog page, identified by its URL, with optional filtering.
|
|
249
255
|
*/
|
|
250
|
-
getProductsCountByPageUrl(url: string, body?: object[]): Promise<IProductsCount | IError>;
|
|
256
|
+
getProductsCountByPageUrl(url: string, body?: object[], langCode?: string): Promise<IProductsCount | IError>;
|
|
251
257
|
/**
|
|
252
258
|
* Semantic (vector) search for products.
|
|
253
259
|
* @handleName getProductsByVectorSearch
|
|
@@ -27,10 +27,11 @@ export default class SearchApi extends AsyncModules implements ISearchApi {
|
|
|
27
27
|
* @param {number} [offset] - Offset for drilldown mode. Pass it only together with exactly one accessible type in `types`.
|
|
28
28
|
* @param {number} [limit] - Page size for drilldown mode. Pass it only together with exactly one accessible type in `types`; otherwise the API responds with `400 Drilldown mode (limit/offset) requires exactly one accessible type in types`. Without it, every group is returned in full.
|
|
29
29
|
* @param {string} [langCode] - Language code. Default: "en_US". The search index is built per language: words in another locale are found only when you pass that locale's `langCode`.
|
|
30
|
+
* @param {number} [limitPerType] - Dropdown mode: maximum items per type group (API default 5, max 20). Independent from `limit`/`offset`, which page a single type in drilldown mode.
|
|
30
31
|
* @returns {Promise<IGlobalSearchResponse | IError>} Returns the query and the found records grouped by entity type.
|
|
31
32
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
32
33
|
* @description Searches names and attribute values of visible records across entity types. The index is per language — the request carries `langCode`, so a bilingual project finds a word of either locale.
|
|
33
34
|
* @see {@link https://js-sdk.oneentry.cloud/docs/search/globalSearch globalSearch} documentation.
|
|
34
35
|
*/
|
|
35
|
-
globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number, langCode?: string): Promise<IGlobalSearchResponse | IError>;
|
|
36
|
+
globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number, langCode?: string, limitPerType?: number): Promise<IGlobalSearchResponse | IError>;
|
|
36
37
|
}
|
package/dist/search/searchApi.js
CHANGED
|
@@ -65,12 +65,13 @@ class SearchApi extends asyncModules_1.default {
|
|
|
65
65
|
* @param {number} [offset] - Offset for drilldown mode. Pass it only together with exactly one accessible type in `types`.
|
|
66
66
|
* @param {number} [limit] - Page size for drilldown mode. Pass it only together with exactly one accessible type in `types`; otherwise the API responds with `400 Drilldown mode (limit/offset) requires exactly one accessible type in types`. Without it, every group is returned in full.
|
|
67
67
|
* @param {string} [langCode] - Language code. Default: "en_US". The search index is built per language: words in another locale are found only when you pass that locale's `langCode`.
|
|
68
|
+
* @param {number} [limitPerType] - Dropdown mode: maximum items per type group (API default 5, max 20). Independent from `limit`/`offset`, which page a single type in drilldown mode.
|
|
68
69
|
* @returns {Promise<IGlobalSearchResponse | IError>} Returns the query and the found records grouped by entity type.
|
|
69
70
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
70
71
|
* @description Searches names and attribute values of visible records across entity types. The index is per language — the request carries `langCode`, so a bilingual project finds a word of either locale.
|
|
71
72
|
* @see {@link https://js-sdk.oneentry.cloud/docs/search/globalSearch globalSearch} documentation.
|
|
72
73
|
*/
|
|
73
|
-
async globalSearch(query, types, visibility, offset, limit, langCode = this.state.lang) {
|
|
74
|
+
async globalSearch(query, types, visibility, offset, limit, langCode = this.state.lang, limitPerType) {
|
|
74
75
|
// `types` is sent comma-separated — the array stringifies to exactly that.
|
|
75
76
|
// `langCode` is not optional decoration: the index is per language, and
|
|
76
77
|
// without it a word of a second locale answers an empty group (CMS-912).
|
|
@@ -81,6 +82,7 @@ class SearchApi extends asyncModules_1.default {
|
|
|
81
82
|
visibility,
|
|
82
83
|
offset,
|
|
83
84
|
limit,
|
|
85
|
+
limitPerType,
|
|
84
86
|
langCode,
|
|
85
87
|
};
|
|
86
88
|
const data = await this._fetchGet(`?` + this._queryParamsToString(params));
|
|
@@ -14,11 +14,12 @@ interface ISearchApi {
|
|
|
14
14
|
* @param {number} [offset] - Offset for drilldown mode. Pass it only together with exactly one accessible type in `types`.
|
|
15
15
|
* @param {number} [limit] - Page size for drilldown mode. Pass it only together with exactly one accessible type in `types`; otherwise the API responds with `400 Drilldown mode (limit/offset) requires exactly one accessible type in types`. Without it, every group is returned in full.
|
|
16
16
|
* @param {string} [langCode] - Language code. Default: "en_US". The search index is built per language: words in another locale are found only when you pass that locale's `langCode`.
|
|
17
|
+
* @param {number} [limitPerType] - Dropdown mode: maximum items per type group (API default 5, max 20). Independent from `limit`/`offset`, which page a single type in drilldown mode.
|
|
17
18
|
* @returns {Promise<IGlobalSearchResponse | IError>} Returns the query and the found records grouped by entity type.
|
|
18
19
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
19
20
|
* @description Searches names and attribute values of visible records across entity types. The index is per language — the request carries `langCode`, so a bilingual project finds a word of either locale.
|
|
20
21
|
*/
|
|
21
|
-
globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number, langCode?: string): Promise<IGlobalSearchResponse | IError>;
|
|
22
|
+
globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number, langCode?: string, limitPerType?: number): Promise<IGlobalSearchResponse | IError>;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Entity type a global search group or item belongs to.
|