@albatrossai/albatross-sdk 0.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/client.d.ts +25 -0
- package/dist/client.js +46 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +30 -0
- package/package.json +22 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface Event {
|
|
2
|
+
units: Record<string, string>;
|
|
3
|
+
value?: string;
|
|
4
|
+
eventType: string;
|
|
5
|
+
payload?: Record<string, any>;
|
|
6
|
+
timestamp?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class Client {
|
|
9
|
+
token: string;
|
|
10
|
+
instanceUuid: string;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
constructor(token: string, instanceUuid: string, baseUrl?: string);
|
|
14
|
+
getVersion(): Promise<any>;
|
|
15
|
+
private handleNotOk;
|
|
16
|
+
catalogAdd: ({ entity, data, mainUnit, }: {
|
|
17
|
+
entity: string;
|
|
18
|
+
data: {
|
|
19
|
+
[k: string]: any;
|
|
20
|
+
}[];
|
|
21
|
+
mainUnit?: string;
|
|
22
|
+
}) => Promise<any>;
|
|
23
|
+
putEvent(payload: Event): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
export default Client;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
const hostDefault = "https://app.usealbatross.ai/api";
|
|
5
|
+
class Client {
|
|
6
|
+
constructor(token, instanceUuid, baseUrl = hostDefault) {
|
|
7
|
+
this.token = token;
|
|
8
|
+
this.instanceUuid = instanceUuid;
|
|
9
|
+
this.baseUrl = baseUrl;
|
|
10
|
+
this.catalogAdd = async ({ entity, data, mainUnit, }) => {
|
|
11
|
+
const formattedData = data.map(utils_1.flattenNested);
|
|
12
|
+
const response = await fetch(this.baseUrl + "/catalog", {
|
|
13
|
+
method: "PUT",
|
|
14
|
+
body: JSON.stringify({ data: formattedData, entity, mainUnit }),
|
|
15
|
+
headers: this.headers,
|
|
16
|
+
});
|
|
17
|
+
await this.handleNotOk(response);
|
|
18
|
+
return response.json();
|
|
19
|
+
};
|
|
20
|
+
this.headers = {
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
Authorization: "Bearer " + this.token,
|
|
23
|
+
"x-instance-id": this.instanceUuid,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async getVersion() {
|
|
27
|
+
const response = await fetch(this.baseUrl + "/version");
|
|
28
|
+
return response.json();
|
|
29
|
+
}
|
|
30
|
+
async handleNotOk(response) {
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
throw new Error(`Request failed: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async putEvent(payload) {
|
|
36
|
+
const url = `${this.baseUrl}/event`;
|
|
37
|
+
const response = await fetch(url, {
|
|
38
|
+
method: "PUT",
|
|
39
|
+
headers: this.headers,
|
|
40
|
+
body: JSON.stringify(payload),
|
|
41
|
+
});
|
|
42
|
+
await this.handleNotOk(response);
|
|
43
|
+
return response.json();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = Client;
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flattenNested = flattenNested;
|
|
4
|
+
function flattenNested(obj) {
|
|
5
|
+
const result = {};
|
|
6
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
7
|
+
if (typeof value === "object" && !Array.isArray(value) && value !== null) {
|
|
8
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
9
|
+
if (Array.isArray(nestedValue)) {
|
|
10
|
+
result[`${key}_${nestedKey}`] = nestedValue.join(",");
|
|
11
|
+
}
|
|
12
|
+
else if (typeof nestedValue === "object" && nestedValue !== null) {
|
|
13
|
+
Object.entries(nestedValue).forEach(([subKey, subValue]) => {
|
|
14
|
+
result[`${nestedKey}_${subKey}`] = subValue;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
result[`${key}_${nestedKey}`] = nestedValue;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else if (Array.isArray(value)) {
|
|
23
|
+
result[key] = value.join(",");
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
result[key] = value;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@albatrossai/albatross-sdk",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"main": "dist/client.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"author": "Albatross AI",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"description": "",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.7.2"
|
|
21
|
+
}
|
|
22
|
+
}
|