@unmeshed/sdk 1.0.4 → 1.0.6
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/apiClient.d.ts +3 -0
- package/dist/apiClient.js +31 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +21 -0
- package/dist/hello-world.js +4 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +8 -4
- package/dist/testApi.d.ts +2 -0
- package/dist/testApi.js +9 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +2 -0
- package/package.json +6 -2
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const axios_1 = require("axios");
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
class ApiClient {
|
|
6
|
+
constructor() {
|
|
7
|
+
const { hostname, port, bearerToken, basePath } = config_1.default.getConfig();
|
|
8
|
+
this.client = axios_1.default.create({
|
|
9
|
+
baseURL: `https://${hostname}:${port}${basePath || ""}`,
|
|
10
|
+
headers: {
|
|
11
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
// Optional: Add interceptors for request/response
|
|
16
|
+
this.client.interceptors.request.use((req) => {
|
|
17
|
+
// Modify request if needed
|
|
18
|
+
return req;
|
|
19
|
+
}, (error) => {
|
|
20
|
+
return Promise.reject(error);
|
|
21
|
+
});
|
|
22
|
+
this.client.interceptors.response.use((response) => response, (error) => {
|
|
23
|
+
// Handle errors globally
|
|
24
|
+
return Promise.reject(error);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getInstance() {
|
|
28
|
+
return this.client;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = new ApiClient().getInstance();
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ApiConfig {
|
|
2
|
+
hostname: string;
|
|
3
|
+
port: number;
|
|
4
|
+
bearerToken: string;
|
|
5
|
+
basePath?: string;
|
|
6
|
+
}
|
|
7
|
+
declare class Config {
|
|
8
|
+
private static instance;
|
|
9
|
+
private config;
|
|
10
|
+
private constructor();
|
|
11
|
+
static getInstance(): Config;
|
|
12
|
+
setConfig(config: ApiConfig): void;
|
|
13
|
+
getConfig(): ApiConfig;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: Config;
|
|
16
|
+
export default _default;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Config {
|
|
4
|
+
constructor() { }
|
|
5
|
+
static getInstance() {
|
|
6
|
+
if (!Config.instance) {
|
|
7
|
+
Config.instance = new Config();
|
|
8
|
+
}
|
|
9
|
+
return Config.instance;
|
|
10
|
+
}
|
|
11
|
+
setConfig(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
getConfig() {
|
|
15
|
+
if (!this.config) {
|
|
16
|
+
throw new Error("API configuration not set.");
|
|
17
|
+
}
|
|
18
|
+
return this.config;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = Config.getInstance();
|
package/dist/hello-world.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.TestAPI = exports.configure = void 0;
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
const TestApi = require("./testApi");
|
|
6
|
+
const configure = (apiConfig) => {
|
|
7
|
+
config_1.default.setConfig(apiConfig);
|
|
8
|
+
};
|
|
9
|
+
exports.configure = configure;
|
|
10
|
+
exports.TestAPI = TestApi;
|
package/dist/testApi.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTest = void 0;
|
|
4
|
+
const apiClient_1 = require("./apiClient");
|
|
5
|
+
const getTest = async () => {
|
|
6
|
+
const response = await apiClient_1.default.get("api/test/get");
|
|
7
|
+
return response.data;
|
|
8
|
+
};
|
|
9
|
+
exports.getTest = getTest;
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unmeshed/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Can log \"hello world\" and \"goodbye world\" to the console!",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"/dist"
|
|
9
|
-
]
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@types/axios": "^0.14.4",
|
|
12
|
+
"axios": "^1.7.9"
|
|
13
|
+
}
|
|
10
14
|
}
|