@brostark/solutions-client 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
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
+ * Deletes a search collection
23
+ * @param name - The name of the collection to delete
24
+ * @returns A promise with the deleted collection
25
+ */
26
+ deleteCollection: (name: string) => Promise<any>;
27
+ /**
28
+ * Inserts a document into a search collection
29
+ * @param collectionName - The name of the collection to insert the document into
30
+ * @param document - The document to insert
31
+ * @returns A promise with the inserted document
32
+ */
33
+ upsertDocument: (collectionName: string, document: Record<string, unknown>) => Promise<any>;
34
+ /**
35
+ * Deletes a document from a search collection
36
+ * @param collectionName - The name of the collection to delete the document from
37
+ * @param documentId - The ID of the document to delete
38
+ * @returns A promise with the deleted document
39
+ */
40
+ deleteDocument: (collectionName: string, documentId: string) => Promise<any>;
41
+ /**
42
+ * Searches for documents in a search collection
43
+ * @param collectionName - The name of the collection to search in
44
+ * @param query - The query to search for
45
+ * @returns A promise with the search results
46
+ */
47
+ search: (collectionName: string, query: BrostarkSolutions.Search.SearchQuery) => Promise<any>;
48
+ };
49
+ //# 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;IAMhF;;;;OAIG;6BAC4B,MAAM;IAMrC;;;;;OAKG;qCACoC,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAMhF;;;;;OAKG;qCACoC,MAAM,cAAc,MAAM;IAMjE;;;;;OAKG;6BAC4B,MAAM,SAAS,iBAAiB,CAAC,MAAM,CAAC,WAAW;CAcrF,CAAA"}
@@ -0,0 +1,78 @@
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
+ * Deletes a search collection
33
+ * @param name - The name of the collection to delete
34
+ * @returns A promise with the deleted collection
35
+ */
36
+ deleteCollection: async (name) => {
37
+ const response = await (0, httpRequest_1.httpDeleteRequest)(`${apiUrl}/search/collections/${name}`, apiKey);
38
+ return response.data;
39
+ },
40
+ /**
41
+ * Inserts a document into a search collection
42
+ * @param collectionName - The name of the collection to insert the document into
43
+ * @param document - The document to insert
44
+ * @returns A promise with the inserted document
45
+ */
46
+ upsertDocument: async (collectionName, document) => {
47
+ const response = await (0, httpRequest_1.httpPostRequest)(`${apiUrl}/search/collections/${collectionName}/documents`, apiKey, document);
48
+ return response.data;
49
+ },
50
+ /**
51
+ * Deletes a document from a search collection
52
+ * @param collectionName - The name of the collection to delete the document from
53
+ * @param documentId - The ID of the document to delete
54
+ * @returns A promise with the deleted document
55
+ */
56
+ deleteDocument: async (collectionName, documentId) => {
57
+ const response = await (0, httpRequest_1.httpDeleteRequest)(`${apiUrl}/search/collections/${collectionName}/documents/${documentId}`, apiKey);
58
+ return response.data;
59
+ },
60
+ /**
61
+ * Searches for documents in a search collection
62
+ * @param collectionName - The name of the collection to search in
63
+ * @param query - The query to search for
64
+ * @returns A promise with the search results
65
+ */
66
+ search: async (collectionName, query) => {
67
+ const urlQuery = new URLSearchParams();
68
+ Object.entries(query).forEach(([key, value]) => {
69
+ if (value !== undefined && value !== null) {
70
+ urlQuery.set(key, String(value));
71
+ }
72
+ });
73
+ const response = await (0, httpRequest_1.httpGetRequest)(`${apiUrl}/search/collections/${collectionName}/search?${urlQuery.toString()}`, apiKey);
74
+ return response.data;
75
+ },
76
+ };
77
+ };
78
+ 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;
@@ -0,0 +1,34 @@
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
+ deleteCollection: (name: string) => Promise<any>;
29
+ upsertDocument: (collectionName: string, document: Record<string, unknown>) => Promise<any>;
30
+ deleteDocument: (collectionName: string, documentId: string) => Promise<any>;
31
+ search: (collectionName: string, query: import("./lib/types").BrostarkSolutions.Search.SearchQuery) => Promise<any>;
32
+ };
33
+ };
34
+ //# 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"}
@@ -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;
@@ -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;
@@ -0,0 +1,3 @@
1
+ import { createClient, CreateClientOptions } from "./client";
2
+ export { createClient, type CreateClientOptions };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,40 @@
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
+ interface SearchQuery {
30
+ query: string;
31
+ by?: string;
32
+ sortBy?: string;
33
+ filterBy?: string;
34
+ }
35
+ type Document = {
36
+ id: string;
37
+ } & Record<string, unknown>;
38
+ }
39
+ }
40
+ //# 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;QAED,UAAiB,WAAW;YAC1B,KAAK,EAAE,MAAM,CAAC;YACd,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;SACnB;QAED,KAAY,QAAQ,GAAG;YACrB,EAAE,EAAE,MAAM,CAAC;SACZ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B;CACF"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });