@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.
@@ -0,0 +1,3 @@
1
+ import { AxiosInstance } from "axios";
2
+ declare const _default: AxiosInstance;
3
+ export default _default;
@@ -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();
@@ -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();
@@ -8,3 +8,7 @@ function sayHello() {
8
8
  function sayGoodbye() {
9
9
  console.log('goodbye');
10
10
  }
11
+ // {
12
+ // "randomId": "876259e6-37b3-4def-b21e-2ca36a12236a",
13
+ // "counter": 3
14
+ // }
package/dist/index.d.ts CHANGED
@@ -1 +1,4 @@
1
- export { sayHello, sayGoodbye } from './hello-world';
1
+ import { ApiConfig } from "./config";
2
+ import * as TestApi from "./testApi";
3
+ export declare const configure: (apiConfig: ApiConfig) => void;
4
+ export declare const TestAPI: typeof TestApi;
package/dist/index.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sayGoodbye = exports.sayHello = void 0;
4
- var hello_world_1 = require("./hello-world");
5
- Object.defineProperty(exports, "sayHello", { enumerable: true, get: function () { return hello_world_1.sayHello; } });
6
- Object.defineProperty(exports, "sayGoodbye", { enumerable: true, get: function () { return hello_world_1.sayGoodbye; } });
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;
@@ -0,0 +1,2 @@
1
+ import { TestData } from "./types";
2
+ export declare const getTest: () => Promise<TestData[]>;
@@ -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;
@@ -0,0 +1,4 @@
1
+ export interface TestData {
2
+ randomId: string;
3
+ counter: number;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@unmeshed/sdk",
3
- "version": "1.0.4",
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
  }