@brostark/solutions-client 1.1.13 → 1.1.15
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/api/v1/search.d.ts +7 -0
- package/dist/api/v1/search.d.ts.map +1 -1
- package/dist/api/v1/search.js +10 -0
- package/dist/helper.d.ts +6 -0
- package/dist/helper.d.ts.map +1 -1
- package/dist/helper.js +16 -1
- package/dist/lib/httpRequest.d.ts +1 -0
- package/dist/lib/httpRequest.d.ts.map +1 -1
- package/dist/lib/httpRequest.js +11 -3
- package/package.json +1 -1
- package/src/api/v1/search.ts +12 -0
- package/src/helper.ts +19 -1
- package/src/lib/httpRequest.ts +12 -4
package/dist/api/v1/search.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export declare const generateSearchAPI: (apiUrl: string, apiKey: string) => {
|
|
|
38
38
|
* @returns A promise with the deleted document
|
|
39
39
|
*/
|
|
40
40
|
deleteDocument: (collectionName: string, documentId: string) => Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Deletes multiple documents from a search collection
|
|
43
|
+
* @param collectionName - The name of the collection to delete the documents from
|
|
44
|
+
* @param documentIds - The IDs of the documents to delete
|
|
45
|
+
* @returns A promise with the deleted documents
|
|
46
|
+
*/
|
|
47
|
+
deleteMultipleDocuments: (collectionName: string, documentIds: string[]) => Promise<any>;
|
|
41
48
|
/**
|
|
42
49
|
* Gets a document from a search collection by its ID
|
|
43
50
|
* @param collectionName - The name of the collection to get the document from
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/api/v1/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKjE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM;IAE5D;;;;OAIG;gCAC8B,WAAW;IAK5C;;;;OAIG;+BAC8B,iBAAiB,CAAC,MAAM,CAAC,sBAAsB;IAMhF;;;;OAIG;6BAC4B,MAAM;IAMrC;;;;;OAKG;sCACqC,MAAM,aAAa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;IAMpF;;;;;OAKG;qCACoC,MAAM,cAAc,MAAM;IAMjE;;;;;OAKG;sCACqC,MAAM,cAAc,MAAM;IAMlE;;;;;OAKG;4BAC2B,MAAM,SAAS,iBAAiB,CAAC,MAAM,CAAC,WAAW,KAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC;CAcrI,CAAA"}
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/api/v1/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKjE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM;IAE5D;;;;OAIG;gCAC8B,WAAW;IAK5C;;;;OAIG;+BAC8B,iBAAiB,CAAC,MAAM,CAAC,sBAAsB;IAMhF;;;;OAIG;6BAC4B,MAAM;IAMrC;;;;;OAKG;sCACqC,MAAM,aAAa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;IAMpF;;;;;OAKG;qCACoC,MAAM,cAAc,MAAM;IAMjE;;;;;OAKG;8CAC6C,MAAM,eAAe,MAAM,EAAE;IAM7E;;;;;OAKG;sCACqC,MAAM,cAAc,MAAM;IAMlE;;;;;OAKG;4BAC2B,MAAM,SAAS,iBAAiB,CAAC,MAAM,CAAC,WAAW,KAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC;CAcrI,CAAA"}
|
package/dist/api/v1/search.js
CHANGED
|
@@ -58,6 +58,16 @@ const generateSearchAPI = (apiUrl, apiKey) => {
|
|
|
58
58
|
const response = await (0, httpRequest_1.httpDeleteRequest)(`${apiUrl}/search/collections/${collectionName}/documents/${documentId}`, apiKey);
|
|
59
59
|
return response.data;
|
|
60
60
|
},
|
|
61
|
+
/**
|
|
62
|
+
* Deletes multiple documents from a search collection
|
|
63
|
+
* @param collectionName - The name of the collection to delete the documents from
|
|
64
|
+
* @param documentIds - The IDs of the documents to delete
|
|
65
|
+
* @returns A promise with the deleted documents
|
|
66
|
+
*/
|
|
67
|
+
deleteMultipleDocuments: async (collectionName, documentIds) => {
|
|
68
|
+
const response = await (0, httpRequest_1.httpPostRequest)(`${apiUrl}/search/collections/${collectionName}/documents/delete`, apiKey, { documentIds });
|
|
69
|
+
return response.data;
|
|
70
|
+
},
|
|
61
71
|
/**
|
|
62
72
|
* Gets a document from a search collection by its ID
|
|
63
73
|
* @param collectionName - The name of the collection to get the document from
|
package/dist/helper.d.ts
CHANGED
|
@@ -13,4 +13,10 @@ export declare const setLimit: (limit: number, min: number, max: number) => numb
|
|
|
13
13
|
* @returns The URL with the query string
|
|
14
14
|
*/
|
|
15
15
|
export declare const buildUrlWithParams: (baseUrl: string, params?: Record<string, unknown>) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Remove undefined values of an objet
|
|
18
|
+
* @param record - The record
|
|
19
|
+
* @returns The record filtered
|
|
20
|
+
*/
|
|
21
|
+
export declare const removeUndefinedValues: <T extends object>(record: T) => T;
|
|
16
22
|
//# sourceMappingURL=helper.d.ts.map
|
package/dist/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,WAE/D,CAAA;AAGD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAiBtF,CAAA"}
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,WAE/D,CAAA;AAGD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAiBtF,CAAA;AAGD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,KAAG,CAUnE,CAAA"}
|
package/dist/helper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildUrlWithParams = exports.setLimit = void 0;
|
|
3
|
+
exports.removeUndefinedValues = exports.buildUrlWithParams = exports.setLimit = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Sets a limit between a minimum and maximum value
|
|
6
6
|
* @param limit - The desired limit
|
|
@@ -33,3 +33,18 @@ const buildUrlWithParams = (baseUrl, params) => {
|
|
|
33
33
|
return `${baseUrl}${separator}${search}`;
|
|
34
34
|
};
|
|
35
35
|
exports.buildUrlWithParams = buildUrlWithParams;
|
|
36
|
+
/**
|
|
37
|
+
* Remove undefined values of an objet
|
|
38
|
+
* @param record - The record
|
|
39
|
+
* @returns The record filtered
|
|
40
|
+
*/
|
|
41
|
+
const removeUndefinedValues = (record) => {
|
|
42
|
+
Object.keys(record).forEach((key) => {
|
|
43
|
+
const value = record[key];
|
|
44
|
+
if (typeof value === "undefined") {
|
|
45
|
+
delete record[key];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return record;
|
|
49
|
+
};
|
|
50
|
+
exports.removeUndefinedValues = removeUndefinedValues;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpRequest.d.ts","sourceRoot":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AQ3E,CAAA"}
|
package/dist/lib/httpRequest.js
CHANGED
|
@@ -11,13 +11,16 @@ const constant_1 = require("../constant");
|
|
|
11
11
|
* @returns A promise with the request response
|
|
12
12
|
*/
|
|
13
13
|
const httpRequest = async (apiUrl, apiKey, options) => {
|
|
14
|
-
const { headers, params, data, ...rest } = options;
|
|
14
|
+
const { headers, params, data, timeout: timeoutValue, ...rest } = options;
|
|
15
15
|
const url = (0, helper_1.buildUrlWithParams)(apiUrl, params);
|
|
16
|
-
const
|
|
16
|
+
const controller = typeof timeoutValue === "number" ? new AbortController() : undefined;
|
|
17
|
+
const timeoutId = typeof timeoutValue === "number" ? setTimeout(() => controller.abort(), timeoutValue) : undefined;
|
|
18
|
+
const config = (0, helper_1.removeUndefinedValues)({
|
|
17
19
|
mode: "cors",
|
|
18
20
|
method: "GET",
|
|
19
21
|
...rest,
|
|
20
|
-
|
|
22
|
+
signal: controller?.signal,
|
|
23
|
+
});
|
|
21
24
|
const finalHeaders = {
|
|
22
25
|
"x-api-key": apiKey,
|
|
23
26
|
...headers,
|
|
@@ -47,6 +50,11 @@ const httpRequest = async (apiUrl, apiKey, options) => {
|
|
|
47
50
|
catch (e) {
|
|
48
51
|
return responseText;
|
|
49
52
|
}
|
|
53
|
+
finally {
|
|
54
|
+
if (timeoutId !== undefined) {
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
50
58
|
};
|
|
51
59
|
exports.httpRequest = httpRequest;
|
|
52
60
|
/**
|
package/package.json
CHANGED
package/src/api/v1/search.ts
CHANGED
|
@@ -67,6 +67,18 @@ export const generateSearchAPI = (apiUrl: string, apiKey: string) => {
|
|
|
67
67
|
return response.data;
|
|
68
68
|
},
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Deletes multiple documents from a search collection
|
|
72
|
+
* @param collectionName - The name of the collection to delete the documents from
|
|
73
|
+
* @param documentIds - The IDs of the documents to delete
|
|
74
|
+
* @returns A promise with the deleted documents
|
|
75
|
+
*/
|
|
76
|
+
deleteMultipleDocuments: async (collectionName: string, documentIds: string[]) => {
|
|
77
|
+
const response = await httpPostRequest(`${apiUrl}/search/collections/${collectionName}/documents/delete`, apiKey, { documentIds });
|
|
78
|
+
|
|
79
|
+
return response.data;
|
|
80
|
+
},
|
|
81
|
+
|
|
70
82
|
/**
|
|
71
83
|
* Gets a document from a search collection by its ID
|
|
72
84
|
* @param collectionName - The name of the collection to get the document from
|
package/src/helper.ts
CHANGED
|
@@ -33,4 +33,22 @@ export const buildUrlWithParams = (baseUrl: string, params?: Record<string, unkn
|
|
|
33
33
|
const separator = baseUrl.includes("?") ? "&" : "?";
|
|
34
34
|
|
|
35
35
|
return `${baseUrl}${separator}${search}`;
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Remove undefined values of an objet
|
|
41
|
+
* @param record - The record
|
|
42
|
+
* @returns The record filtered
|
|
43
|
+
*/
|
|
44
|
+
export const removeUndefinedValues = <T extends object>(record: T): T => {
|
|
45
|
+
Object.keys(record).forEach((key) => {
|
|
46
|
+
const value = record[key as keyof typeof record];
|
|
47
|
+
|
|
48
|
+
if (typeof value === "undefined") {
|
|
49
|
+
delete record[key as keyof typeof record];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return record as T;
|
|
54
|
+
}
|
package/src/lib/httpRequest.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ListOptions } from "./types";
|
|
2
|
-
import { buildUrlWithParams, setLimit } from "../helper";
|
|
2
|
+
import { buildUrlWithParams, removeUndefinedValues, setLimit } from "../helper";
|
|
3
3
|
import { MAX_LIMIT } from "../constant";
|
|
4
4
|
|
|
5
5
|
type RequestOptions = Omit<RequestInit, "body"> & {
|
|
6
6
|
params?: Record<string, unknown>;
|
|
7
7
|
data?: unknown;
|
|
8
|
+
timeout?: number;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
|
|
@@ -16,15 +17,18 @@ type RequestOptions = Omit<RequestInit, "body"> & {
|
|
|
16
17
|
* @returns A promise with the request response
|
|
17
18
|
*/
|
|
18
19
|
export const httpRequest = async (apiUrl: string, apiKey: string, options: RequestOptions) => {
|
|
19
|
-
const { headers, params, data,
|
|
20
|
+
const { headers, params, data, timeout: timeoutValue,...rest } = options;
|
|
20
21
|
|
|
21
22
|
const url = buildUrlWithParams(apiUrl, params);
|
|
23
|
+
const controller = typeof timeoutValue === "number" ? new AbortController() : undefined;
|
|
24
|
+
const timeoutId = typeof timeoutValue === "number" ? setTimeout(() => controller!.abort(), timeoutValue) : undefined;
|
|
22
25
|
|
|
23
|
-
const config: RequestInit = {
|
|
26
|
+
const config: RequestInit = removeUndefinedValues({
|
|
24
27
|
mode: "cors",
|
|
25
28
|
method: "GET",
|
|
26
29
|
...rest,
|
|
27
|
-
|
|
30
|
+
signal: controller?.signal,
|
|
31
|
+
});
|
|
28
32
|
|
|
29
33
|
const finalHeaders: Record<string, string> = {
|
|
30
34
|
"x-api-key": apiKey,
|
|
@@ -57,6 +61,10 @@ export const httpRequest = async (apiUrl: string, apiKey: string, options: Reque
|
|
|
57
61
|
return JSON.parse(responseText);
|
|
58
62
|
} catch (e) {
|
|
59
63
|
return responseText;
|
|
64
|
+
} finally {
|
|
65
|
+
if (timeoutId !== undefined) {
|
|
66
|
+
clearTimeout(timeoutId);
|
|
67
|
+
}
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
|