@brostark/solutions-client 1.0.0 → 1.0.1
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 +22 -0
- package/dist/api/v1/search.d.ts.map +1 -0
- package/dist/api/v1/search.js +33 -0
- package/dist/api/v1/upload.d.ts +1 -0
- package/dist/api/v1/upload.d.ts.map +1 -0
- package/dist/api/v1/upload.js +1 -0
- package/dist/api/v1/video.d.ts +40 -0
- package/dist/api/v1/video.d.ts.map +1 -0
- package/dist/api/v1/video.js +62 -0
- package/dist/client.d.ts +30 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +20 -0
- package/dist/constant.d.ts +19 -0
- package/dist/constant.d.ts.map +1 -0
- package/dist/constant.js +22 -0
- package/dist/helper.d.ts +9 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/helper.js +14 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/httpRequest.d.ts +53 -0
- package/dist/lib/httpRequest.d.ts.map +1 -0
- package/dist/lib/httpRequest.js +129 -0
- package/dist/lib/security.d.ts +1 -0
- package/dist/lib/security.d.ts.map +1 -0
- package/dist/lib/security.js +1 -0
- package/dist/lib/types.d.ts +31 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/package.json +1 -2
- package/src/api/v1/search.ts +34 -0
- package/src/client.ts +2 -0
- package/src/constant.ts +1 -1
- package/src/lib/httpRequest.ts +16 -0
- package/src/lib/types.ts +29 -0
- package/package-lock.json +0 -4983
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BrostarkSolutions, ListOptions } from "../../lib/types";
|
|
2
|
+
/**
|
|
3
|
+
* Generates an API to manage search
|
|
4
|
+
* @param apiUrl - The API URL
|
|
5
|
+
* @param apiKey - The API key for authentication
|
|
6
|
+
* @returns An object containing methods to interact with the search API
|
|
7
|
+
*/
|
|
8
|
+
export declare const generateSearchAPI: (apiUrl: string, apiKey: string) => {
|
|
9
|
+
/**
|
|
10
|
+
* Lists the search collections
|
|
11
|
+
* @param options - The pagination options
|
|
12
|
+
* @returns A promise with the list of search collections
|
|
13
|
+
*/
|
|
14
|
+
listCollections: (options?: ListOptions) => Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a search collection
|
|
17
|
+
* @param params - The parameters for the search collection
|
|
18
|
+
* @returns A promise with the created search collection
|
|
19
|
+
*/
|
|
20
|
+
createCollection: (params: BrostarkSolutions.Search.CreateCollectionParams) => Promise<any>;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +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;AAIjE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM;IAE5D;;;;OAIG;gCAC8B,WAAW;IAK5C;;;;OAIG;+BAC8B,iBAAiB,CAAC,MAAM,CAAC,sBAAsB;CAMnF,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSearchAPI = void 0;
|
|
4
|
+
const httpRequest_1 = require("../../lib/httpRequest");
|
|
5
|
+
/**
|
|
6
|
+
* Generates an API to manage search
|
|
7
|
+
* @param apiUrl - The API URL
|
|
8
|
+
* @param apiKey - The API key for authentication
|
|
9
|
+
* @returns An object containing methods to interact with the search API
|
|
10
|
+
*/
|
|
11
|
+
const generateSearchAPI = (apiUrl, apiKey) => {
|
|
12
|
+
return {
|
|
13
|
+
/**
|
|
14
|
+
* Lists the search collections
|
|
15
|
+
* @param options - The pagination options
|
|
16
|
+
* @returns A promise with the list of search collections
|
|
17
|
+
*/
|
|
18
|
+
listCollections: async (options = {}) => {
|
|
19
|
+
const response = await (0, httpRequest_1.httpListRequest)(`${apiUrl}/search/collections`, apiKey, options);
|
|
20
|
+
return response.data;
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Creates a search collection
|
|
24
|
+
* @param params - The parameters for the search collection
|
|
25
|
+
* @returns A promise with the created search collection
|
|
26
|
+
*/
|
|
27
|
+
createCollection: async (params) => {
|
|
28
|
+
const response = await (0, httpRequest_1.httpPostRequest)(`${apiUrl}/search/collections`, apiKey, params);
|
|
29
|
+
return response.data;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.generateSearchAPI = generateSearchAPI;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/api/v1/upload.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ListOptions } from "../../lib/types";
|
|
2
|
+
/**
|
|
3
|
+
* Generates an API to manage videos
|
|
4
|
+
* @param apiUrl - The base URL of the API
|
|
5
|
+
* @param apiKey - The API key for authentication
|
|
6
|
+
* @returns An object containing methods to interact with the video API
|
|
7
|
+
*/
|
|
8
|
+
export declare const generateVideoAPI: (apiUrl: string, apiKey: string) => {
|
|
9
|
+
/**
|
|
10
|
+
* Lists videos with pagination
|
|
11
|
+
* @param options - Pagination options (limit and startAfter)
|
|
12
|
+
* @returns A promise with the list of videos
|
|
13
|
+
*/
|
|
14
|
+
list: (options?: ListOptions) => Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Uploads a new video
|
|
17
|
+
* @param file - The video file to upload
|
|
18
|
+
* @returns A promise with information about the uploaded video (URL and path)
|
|
19
|
+
*/
|
|
20
|
+
upload: (file: File) => Promise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves information about a specific video
|
|
23
|
+
* @param id - The video identifier
|
|
24
|
+
* @returns A promise with the video information
|
|
25
|
+
*/
|
|
26
|
+
get: (id: string) => Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the video URL
|
|
29
|
+
* @param id - The video identifier
|
|
30
|
+
* @returns A promise with the video URL
|
|
31
|
+
*/
|
|
32
|
+
stream: (filename: string) => Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Deletes a video
|
|
35
|
+
* @param id - The identifier of the video to delete
|
|
36
|
+
* @returns A promise with deletion confirmation
|
|
37
|
+
*/
|
|
38
|
+
remove: (id: string) => Promise<any>;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=video.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../src/api/v1/video.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM;IAI3D;;;;OAIG;qBACmB,WAAW;IAKjC;;;;OAIG;mBACkB,IAAI;IAKzB;;;;OAIG;cACa,MAAM;IAKtB;;;;OAIG;uBACsB,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC;IAKjD;;;;OAIG;iBACgB,MAAM;CAK5B,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateVideoAPI = void 0;
|
|
4
|
+
const jwt_decode_1 = require("jwt-decode");
|
|
5
|
+
const httpRequest_1 = require("../../lib/httpRequest");
|
|
6
|
+
/**
|
|
7
|
+
* Generates an API to manage videos
|
|
8
|
+
* @param apiUrl - The base URL of the API
|
|
9
|
+
* @param apiKey - The API key for authentication
|
|
10
|
+
* @returns An object containing methods to interact with the video API
|
|
11
|
+
*/
|
|
12
|
+
const generateVideoAPI = (apiUrl, apiKey) => {
|
|
13
|
+
const { accountId } = (0, jwt_decode_1.jwtDecode)(apiKey);
|
|
14
|
+
return {
|
|
15
|
+
/**
|
|
16
|
+
* Lists videos with pagination
|
|
17
|
+
* @param options - Pagination options (limit and startAfter)
|
|
18
|
+
* @returns A promise with the list of videos
|
|
19
|
+
*/
|
|
20
|
+
list: async (options = {}) => {
|
|
21
|
+
const response = await (0, httpRequest_1.httpListRequest)(`${apiUrl}/videos`, apiKey, options);
|
|
22
|
+
return response.data;
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Uploads a new video
|
|
26
|
+
* @param file - The video file to upload
|
|
27
|
+
* @returns A promise with information about the uploaded video (URL and path)
|
|
28
|
+
*/
|
|
29
|
+
upload: async (file) => {
|
|
30
|
+
const response = await (0, httpRequest_1.httpUploadRequest)(`${apiUrl}/upload/video`, apiKey, file);
|
|
31
|
+
return response.data;
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves information about a specific video
|
|
35
|
+
* @param id - The video identifier
|
|
36
|
+
* @returns A promise with the video information
|
|
37
|
+
*/
|
|
38
|
+
get: async (id) => {
|
|
39
|
+
const response = await (0, httpRequest_1.httpGetRequest)(`${apiUrl}/videos/${id}`, apiKey);
|
|
40
|
+
return response.data;
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the video URL
|
|
44
|
+
* @param id - The video identifier
|
|
45
|
+
* @returns A promise with the video URL
|
|
46
|
+
*/
|
|
47
|
+
stream: async (filename) => {
|
|
48
|
+
const response = await (0, httpRequest_1.httpGetRequest)(`${apiUrl}/stream/${accountId}/${filename.split("/").pop()?.split(".")[0]}`, apiKey);
|
|
49
|
+
return response.data;
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Deletes a video
|
|
53
|
+
* @param id - The identifier of the video to delete
|
|
54
|
+
* @returns A promise with deletion confirmation
|
|
55
|
+
*/
|
|
56
|
+
remove: async (id) => {
|
|
57
|
+
const response = await (0, httpRequest_1.httpDeleteRequest)(`${apiUrl}/videos/${id}`, apiKey);
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.generateVideoAPI = generateVideoAPI;
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ApiVersion } from "./constant";
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating the client
|
|
4
|
+
*/
|
|
5
|
+
export interface CreateClientOptions {
|
|
6
|
+
/** The API host (default: DEFAULT_API_HOST) */
|
|
7
|
+
host?: string;
|
|
8
|
+
/** The API version (default: DEFAULT_API_VERSION) */
|
|
9
|
+
version?: ApiVersion;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the API client
|
|
13
|
+
* @param apiKey - The API key for authentication
|
|
14
|
+
* @param options - The configuration options for the client
|
|
15
|
+
* @returns An object containing the different APIs available
|
|
16
|
+
*/
|
|
17
|
+
export declare function createClient(apiKey: string, options?: CreateClientOptions): {
|
|
18
|
+
video: {
|
|
19
|
+
list: (options?: import("./lib/types").ListOptions) => Promise<any>;
|
|
20
|
+
upload: (file: File) => Promise<any>;
|
|
21
|
+
get: (id: string) => Promise<any>;
|
|
22
|
+
stream: (filename: string) => Promise<string>;
|
|
23
|
+
remove: (id: string) => Promise<any>;
|
|
24
|
+
};
|
|
25
|
+
search: {
|
|
26
|
+
listCollections: (options?: import("./lib/types").ListOptions) => Promise<any>;
|
|
27
|
+
createCollection: (params: import("./lib/types").BrostarkSolutions.Search.CreateCollectionParams) => Promise<any>;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAyC,MAAM,YAAY,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;;;;;;;;;;;;EAY7E"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createClient = createClient;
|
|
4
|
+
const search_1 = require("./api/v1/search");
|
|
5
|
+
const video_1 = require("./api/v1/video");
|
|
6
|
+
const constant_1 = require("./constant");
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of the API client
|
|
9
|
+
* @param apiKey - The API key for authentication
|
|
10
|
+
* @param options - The configuration options for the client
|
|
11
|
+
* @returns An object containing the different APIs available
|
|
12
|
+
*/
|
|
13
|
+
function createClient(apiKey, options = {}) {
|
|
14
|
+
const { host = constant_1.DEFAULT_API_HOST, version = constant_1.DEFAULT_API_VERSION, } = options;
|
|
15
|
+
const apiUrl = `${host}/${version}`;
|
|
16
|
+
return {
|
|
17
|
+
video: (0, video_1.generateVideoAPI)(apiUrl, apiKey),
|
|
18
|
+
search: (0, search_1.generateSearchAPI)(apiUrl, apiKey),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Available API versions
|
|
3
|
+
*/
|
|
4
|
+
export declare enum ApiVersion {
|
|
5
|
+
V1 = "v1"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Default API host
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_API_HOST = "https://api-solutions.brostark.io";
|
|
11
|
+
/**
|
|
12
|
+
* Default API version
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_API_VERSION = ApiVersion.V1;
|
|
15
|
+
/**
|
|
16
|
+
* Maximum limit for list requests
|
|
17
|
+
*/
|
|
18
|
+
export declare const MAX_LIMIT = 100;
|
|
19
|
+
//# sourceMappingURL=constant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../src/constant.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,UAAU;IACpB,EAAE,OAAO;CACV;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,sCAAsC,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,SAAS,MAAM,CAAC"}
|
package/dist/constant.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_LIMIT = exports.DEFAULT_API_VERSION = exports.DEFAULT_API_HOST = exports.ApiVersion = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Available API versions
|
|
6
|
+
*/
|
|
7
|
+
var ApiVersion;
|
|
8
|
+
(function (ApiVersion) {
|
|
9
|
+
ApiVersion["V1"] = "v1";
|
|
10
|
+
})(ApiVersion || (exports.ApiVersion = ApiVersion = {}));
|
|
11
|
+
/**
|
|
12
|
+
* Default API host
|
|
13
|
+
*/
|
|
14
|
+
exports.DEFAULT_API_HOST = "https://api-solutions.brostark.io";
|
|
15
|
+
/**
|
|
16
|
+
* Default API version
|
|
17
|
+
*/
|
|
18
|
+
exports.DEFAULT_API_VERSION = ApiVersion.V1;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum limit for list requests
|
|
21
|
+
*/
|
|
22
|
+
exports.MAX_LIMIT = 100;
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets a limit between a minimum and maximum value
|
|
3
|
+
* @param limit - The desired limit
|
|
4
|
+
* @param min - The minimum allowed value
|
|
5
|
+
* @param max - The maximum allowed value
|
|
6
|
+
* @returns The adjusted limit
|
|
7
|
+
*/
|
|
8
|
+
export declare const setLimit: (limit: number, min: number, max: number) => number;
|
|
9
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/helper.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setLimit = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Sets a limit between a minimum and maximum value
|
|
6
|
+
* @param limit - The desired limit
|
|
7
|
+
* @param min - The minimum allowed value
|
|
8
|
+
* @param max - The maximum allowed value
|
|
9
|
+
* @returns The adjusted limit
|
|
10
|
+
*/
|
|
11
|
+
const setLimit = (limit, min, max) => {
|
|
12
|
+
return Math.min(Math.max(limit, min), max);
|
|
13
|
+
};
|
|
14
|
+
exports.setLimit = setLimit;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACzB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ListOptions } from "./types";
|
|
2
|
+
type RequestOptions = Omit<RequestInit, "body"> & {
|
|
3
|
+
params?: Record<string, unknown>;
|
|
4
|
+
data?: unknown;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Base function to make an HTTP request
|
|
8
|
+
* @param apiUrl - The API URL
|
|
9
|
+
* @param apiKey - The API key for authentication
|
|
10
|
+
* @param options - The request configuration options
|
|
11
|
+
* @returns A promise with the request response
|
|
12
|
+
*/
|
|
13
|
+
export declare const httpRequest: (apiUrl: string, apiKey: string, options: RequestOptions) => Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* Makes an HTTP request to list resources with pagination
|
|
16
|
+
* @param apiUrl - The API URL
|
|
17
|
+
* @param apiKey - The API key for authentication
|
|
18
|
+
* @param options - The pagination options (limit and startAfter)
|
|
19
|
+
* @returns A promise with the list of resources
|
|
20
|
+
*/
|
|
21
|
+
export declare const httpListRequest: (apiUrl: string, apiKey: string, options: ListOptions) => Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* Makes an HTTP GET request
|
|
24
|
+
* @param apiUrl - The API URL
|
|
25
|
+
* @param apiKey - The API key for authentication
|
|
26
|
+
* @returns A promise with the resource data
|
|
27
|
+
*/
|
|
28
|
+
export declare const httpGetRequest: (apiUrl: string, apiKey: string) => Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Makes an HTTP POST request
|
|
31
|
+
* @param apiUrl - The API URL
|
|
32
|
+
* @param apiKey - The API key for authentication
|
|
33
|
+
* @param data - The data to send in the request
|
|
34
|
+
* @returns A promise with the resource data
|
|
35
|
+
*/
|
|
36
|
+
export declare const httpPostRequest: (apiUrl: string, apiKey: string, data: unknown) => Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Makes an HTTP DELETE request
|
|
39
|
+
* @param apiUrl - The API URL
|
|
40
|
+
* @param apiKey - The API key for authentication
|
|
41
|
+
* @returns A promise with the deletion confirmation
|
|
42
|
+
*/
|
|
43
|
+
export declare const httpDeleteRequest: (apiUrl: string, apiKey: string) => Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Makes an HTTP request to upload a file
|
|
46
|
+
* @param apiUrl - The API URL
|
|
47
|
+
* @param apiKey - The API key for authentication
|
|
48
|
+
* @param file - The file to upload
|
|
49
|
+
* @returns A promise with information about the uploaded file
|
|
50
|
+
*/
|
|
51
|
+
export declare const httpUploadRequest: (apiUrl: string, apiKey: string, file: File) => Promise<any>;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=httpRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpRequest.d.ts","sourceRoot":"","sources":["../../src/lib/httpRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC,KAAK,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAU,QAAQ,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS,cAAc,iBAkDxF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS,WAAW,iBAOnF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,iBAI5D,CAAA;AAGD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,EAAE,MAAM,OAAO,iBAK5E,CAAA;AAGD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,iBAI/D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,EAAE,MAAM,IAAI,iBAQ3E,CAAA"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpUploadRequest = exports.httpDeleteRequest = exports.httpPostRequest = exports.httpGetRequest = exports.httpListRequest = exports.httpRequest = void 0;
|
|
4
|
+
const helper_1 = require("../helper");
|
|
5
|
+
const constant_1 = require("../constant");
|
|
6
|
+
/**
|
|
7
|
+
* Base function to make an HTTP request
|
|
8
|
+
* @param apiUrl - The API URL
|
|
9
|
+
* @param apiKey - The API key for authentication
|
|
10
|
+
* @param options - The request configuration options
|
|
11
|
+
* @returns A promise with the request response
|
|
12
|
+
*/
|
|
13
|
+
const httpRequest = async (apiUrl, apiKey, options) => {
|
|
14
|
+
const { headers, params, data, ...rest } = options;
|
|
15
|
+
const url = new URL(apiUrl);
|
|
16
|
+
if (params) {
|
|
17
|
+
for (const [key, value] of Object.entries(params)) {
|
|
18
|
+
if (value !== undefined && value !== null) {
|
|
19
|
+
url.searchParams.set(key, String(value));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const config = {
|
|
24
|
+
mode: "no-cors",
|
|
25
|
+
method: "GET",
|
|
26
|
+
...rest,
|
|
27
|
+
};
|
|
28
|
+
const finalHeaders = {
|
|
29
|
+
"x-api-key": apiKey,
|
|
30
|
+
...headers,
|
|
31
|
+
};
|
|
32
|
+
if (data) {
|
|
33
|
+
if (data instanceof File) {
|
|
34
|
+
config.body = data;
|
|
35
|
+
if (!headers || !headers["Content-Type"]) {
|
|
36
|
+
finalHeaders["Content-Type"] = data.type;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
config.body = JSON.stringify(data);
|
|
41
|
+
finalHeaders["Content-Type"] = "application/json";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
config.headers = finalHeaders;
|
|
45
|
+
const response = await fetch(url.toString(), config);
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const errorData = await response.json().catch(() => ({ message: response.statusText }));
|
|
48
|
+
throw new Error(errorData.message || "HTTP request failed");
|
|
49
|
+
}
|
|
50
|
+
const responseText = await response.text();
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(responseText);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return responseText;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.httpRequest = httpRequest;
|
|
59
|
+
/**
|
|
60
|
+
* Makes an HTTP request to list resources with pagination
|
|
61
|
+
* @param apiUrl - The API URL
|
|
62
|
+
* @param apiKey - The API key for authentication
|
|
63
|
+
* @param options - The pagination options (limit and startAfter)
|
|
64
|
+
* @returns A promise with the list of resources
|
|
65
|
+
*/
|
|
66
|
+
const httpListRequest = (apiUrl, apiKey, options) => {
|
|
67
|
+
return (0, exports.httpRequest)(apiUrl, apiKey, {
|
|
68
|
+
params: {
|
|
69
|
+
limit: (0, helper_1.setLimit)(options.limit ?? 10, 1, constant_1.MAX_LIMIT),
|
|
70
|
+
startAfter: options.startAfter,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
exports.httpListRequest = httpListRequest;
|
|
75
|
+
/**
|
|
76
|
+
* Makes an HTTP GET request
|
|
77
|
+
* @param apiUrl - The API URL
|
|
78
|
+
* @param apiKey - The API key for authentication
|
|
79
|
+
* @returns A promise with the resource data
|
|
80
|
+
*/
|
|
81
|
+
const httpGetRequest = (apiUrl, apiKey) => {
|
|
82
|
+
return (0, exports.httpRequest)(apiUrl, apiKey, {
|
|
83
|
+
method: "GET",
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
exports.httpGetRequest = httpGetRequest;
|
|
87
|
+
/**
|
|
88
|
+
* Makes an HTTP POST request
|
|
89
|
+
* @param apiUrl - The API URL
|
|
90
|
+
* @param apiKey - The API key for authentication
|
|
91
|
+
* @param data - The data to send in the request
|
|
92
|
+
* @returns A promise with the resource data
|
|
93
|
+
*/
|
|
94
|
+
const httpPostRequest = (apiUrl, apiKey, data) => {
|
|
95
|
+
return (0, exports.httpRequest)(apiUrl, apiKey, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
data,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
exports.httpPostRequest = httpPostRequest;
|
|
101
|
+
/**
|
|
102
|
+
* Makes an HTTP DELETE request
|
|
103
|
+
* @param apiUrl - The API URL
|
|
104
|
+
* @param apiKey - The API key for authentication
|
|
105
|
+
* @returns A promise with the deletion confirmation
|
|
106
|
+
*/
|
|
107
|
+
const httpDeleteRequest = (apiUrl, apiKey) => {
|
|
108
|
+
return (0, exports.httpRequest)(apiUrl, apiKey, {
|
|
109
|
+
method: "DELETE",
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
exports.httpDeleteRequest = httpDeleteRequest;
|
|
113
|
+
/**
|
|
114
|
+
* Makes an HTTP request to upload a file
|
|
115
|
+
* @param apiUrl - The API URL
|
|
116
|
+
* @param apiKey - The API key for authentication
|
|
117
|
+
* @param file - The file to upload
|
|
118
|
+
* @returns A promise with information about the uploaded file
|
|
119
|
+
*/
|
|
120
|
+
const httpUploadRequest = (apiUrl, apiKey, file) => {
|
|
121
|
+
return (0, exports.httpRequest)(apiUrl, apiKey, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
data: file,
|
|
124
|
+
headers: {
|
|
125
|
+
"Content-Type": file.type,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
exports.httpUploadRequest = httpUploadRequest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/lib/security.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ListOptions {
|
|
2
|
+
limit?: number;
|
|
3
|
+
startAfter?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare namespace BrostarkSolutions {
|
|
6
|
+
namespace Search {
|
|
7
|
+
type FieldType = "string" | "int32" | "int64" | "float" | "bool" | "geopoint" | "geopolygon" | "geopoint[]" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]" | "object" | "object[]" | "auto" | "string*" | "image";
|
|
8
|
+
interface CollectionField {
|
|
9
|
+
name: string;
|
|
10
|
+
type: FieldType;
|
|
11
|
+
optional?: boolean;
|
|
12
|
+
facet?: boolean;
|
|
13
|
+
index?: boolean;
|
|
14
|
+
sort?: boolean;
|
|
15
|
+
locale?: string;
|
|
16
|
+
infix?: boolean;
|
|
17
|
+
stem?: boolean;
|
|
18
|
+
num_dim?: number;
|
|
19
|
+
store?: boolean;
|
|
20
|
+
range_index?: boolean;
|
|
21
|
+
[t: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface CreateCollectionParams {
|
|
24
|
+
name: string;
|
|
25
|
+
fields: CollectionField[];
|
|
26
|
+
defaultSortingField?: string;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAGD,yBAAiB,iBAAiB,CAAC;IACjC,UAAiB,MAAM,CAAC;QACtB,KAAY,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;QACtO,UAAiB,eAAe;YAC9B,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,SAAS,CAAC;YAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,KAAK,CAAC,EAAE,OAAO,CAAC;YAChB,KAAK,CAAC,EAAE,OAAO,CAAC;YAChB,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,KAAK,CAAC,EAAE,OAAO,CAAC;YAChB,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,KAAK,CAAC,EAAE,OAAO,CAAC;YAChB,WAAW,CAAC,EAAE,OAAO,CAAC;YACtB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;SACtB;QAED,UAAiB,sBAAsB;YACrC,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,eAAe,EAAE,CAAC;YAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;YAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACpC;KACF;CACF"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brostark/solutions-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
8
8
|
"watch": "tsc --watch",
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
|
-
"publish": "npm publish",
|
|
11
10
|
"publish:patch": "npm version patch && npm publish",
|
|
12
11
|
"publish:minor": "npm version minor && npm publish",
|
|
13
12
|
"publish:major": "npm version major && npm publish"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BrostarkSolutions, ListOptions } from "../../lib/types";
|
|
2
|
+
import { httpListRequest, httpPostRequest } from "../../lib/httpRequest";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates an API to manage search
|
|
7
|
+
* @param apiUrl - The API URL
|
|
8
|
+
* @param apiKey - The API key for authentication
|
|
9
|
+
* @returns An object containing methods to interact with the search API
|
|
10
|
+
*/
|
|
11
|
+
export const generateSearchAPI = (apiUrl: string, apiKey: string) => {
|
|
12
|
+
return {
|
|
13
|
+
/**
|
|
14
|
+
* Lists the search collections
|
|
15
|
+
* @param options - The pagination options
|
|
16
|
+
* @returns A promise with the list of search collections
|
|
17
|
+
*/
|
|
18
|
+
listCollections: async (options: ListOptions = {}) => {
|
|
19
|
+
const response = await httpListRequest(`${apiUrl}/search/collections`, apiKey, options);
|
|
20
|
+
return response.data;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a search collection
|
|
25
|
+
* @param params - The parameters for the search collection
|
|
26
|
+
* @returns A promise with the created search collection
|
|
27
|
+
*/
|
|
28
|
+
createCollection: async (params: BrostarkSolutions.Search.CreateCollectionParams) => {
|
|
29
|
+
const response = await httpPostRequest(`${apiUrl}/search/collections`, apiKey, params);
|
|
30
|
+
|
|
31
|
+
return response.data;
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { generateSearchAPI } from "./api/v1/search";
|
|
1
2
|
import { generateVideoAPI } from "./api/v1/video";
|
|
2
3
|
import { ApiVersion, DEFAULT_API_HOST, DEFAULT_API_VERSION } from "./constant";
|
|
3
4
|
|
|
@@ -27,5 +28,6 @@ export function createClient(apiKey: string, options: CreateClientOptions = {})
|
|
|
27
28
|
|
|
28
29
|
return {
|
|
29
30
|
video: generateVideoAPI(apiUrl, apiKey),
|
|
31
|
+
search: generateSearchAPI(apiUrl, apiKey),
|
|
30
32
|
}
|
|
31
33
|
}
|
package/src/constant.ts
CHANGED
package/src/lib/httpRequest.ts
CHANGED
|
@@ -94,6 +94,22 @@ export const httpGetRequest = (apiUrl: string, apiKey: string) => {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Makes an HTTP POST request
|
|
100
|
+
* @param apiUrl - The API URL
|
|
101
|
+
* @param apiKey - The API key for authentication
|
|
102
|
+
* @param data - The data to send in the request
|
|
103
|
+
* @returns A promise with the resource data
|
|
104
|
+
*/
|
|
105
|
+
export const httpPostRequest = (apiUrl: string, apiKey: string, data: unknown) => {
|
|
106
|
+
return httpRequest(apiUrl, apiKey, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
data,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
97
113
|
/**
|
|
98
114
|
* Makes an HTTP DELETE request
|
|
99
115
|
* @param apiUrl - The API URL
|