@obniz/obniz-now-sdk 0.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.
- package/README.md +8 -0
- package/dist/ObnizApiError.d.ts +62 -0
- package/dist/ObnizNow.d.ts +104 -0
- package/dist/ObnizNow.test.d.ts +1 -0
- package/dist/ObnizNowApiError.d.ts +62 -0
- package/dist/index.browser.mjs +3253 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3379 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3376 -0
- package/dist/index.mjs.map +1 -0
- package/dist/sdk-core/apis/AnalyticsApi.d.ts +35 -0
- package/dist/sdk-core/apis/ConnectionModelsApi.d.ts +89 -0
- package/dist/sdk-core/apis/ConnectionsApi.d.ts +61 -0
- package/dist/sdk-core/apis/ConvertersApi.d.ts +28 -0
- package/dist/sdk-core/apis/EventsApi.d.ts +49 -0
- package/dist/sdk-core/apis/GroupsApi.d.ts +62 -0
- package/dist/sdk-core/apis/InboundConnectionsApi.d.ts +47 -0
- package/dist/sdk-core/apis/InboundSourcesApi.d.ts +113 -0
- package/dist/sdk-core/apis/IntegrationsApi.d.ts +121 -0
- package/dist/sdk-core/apis/IntelligencesApi.d.ts +84 -0
- package/dist/sdk-core/apis/IssuesApi.d.ts +63 -0
- package/dist/sdk-core/apis/MachineApi.d.ts +142 -0
- package/dist/sdk-core/apis/MachinesApi.d.ts +97 -0
- package/dist/sdk-core/apis/NotificationsApi.d.ts +72 -0
- package/dist/sdk-core/apis/ReportsApi.d.ts +85 -0
- package/dist/sdk-core/apis/ThreadsApi.d.ts +165 -0
- package/dist/sdk-core/apis/UnitsApi.d.ts +151 -0
- package/dist/sdk-core/apis/index.d.ts +17 -0
- package/dist/sdk-core/index.d.ts +3 -0
- package/dist/sdk-core/models/index.d.ts +5368 -0
- package/dist/sdk-core/runtime.d.ts +181 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ResponseError } from "./sdk-core/runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced API error with automatically parsed response data
|
|
4
|
+
*
|
|
5
|
+
* All API methods automatically convert ResponseError to ObnizApiError,
|
|
6
|
+
* so you get parsed error information without manual handling.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* try {
|
|
11
|
+
* await client.machines.getMachine({ id: 'invalid-id' });
|
|
12
|
+
* } catch (error) {
|
|
13
|
+
* if (error instanceof ObnizApiError) {
|
|
14
|
+
* console.error(`API Error [${error.status}]: ${error.message}`);
|
|
15
|
+
* console.error('Error data:', error.data);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class ObnizApiError extends Error {
|
|
21
|
+
/** HTTP status code (e.g., 404, 500) */
|
|
22
|
+
readonly status: number;
|
|
23
|
+
/** HTTP status text (e.g., "Not Found", "Internal Server Error") */
|
|
24
|
+
readonly statusText: string;
|
|
25
|
+
/** Parsed response body data */
|
|
26
|
+
readonly data: any;
|
|
27
|
+
/** Original ResponseError for advanced use cases */
|
|
28
|
+
readonly originalError: ResponseError;
|
|
29
|
+
constructor(responseError: ResponseError, status: number, statusText: string, data: any);
|
|
30
|
+
/**
|
|
31
|
+
* Create ObnizApiError from ResponseError by parsing the response
|
|
32
|
+
*/
|
|
33
|
+
static fromResponseError(error: ResponseError): Promise<ObnizApiError>;
|
|
34
|
+
/**
|
|
35
|
+
* Get response headers (useful for rate limiting, caching, etc.)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const rateLimit = error.getResponseHeaders().get('x-ratelimit-remaining');
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
getResponseHeaders(): Headers;
|
|
43
|
+
/**
|
|
44
|
+
* Get full request URL
|
|
45
|
+
*/
|
|
46
|
+
getRequestUrl(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Control JSON serialization - don't include originalError
|
|
49
|
+
*/
|
|
50
|
+
toJSON(): {
|
|
51
|
+
name: string;
|
|
52
|
+
message: string;
|
|
53
|
+
status: number;
|
|
54
|
+
statusText: string;
|
|
55
|
+
data: any;
|
|
56
|
+
stack: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wraps an API object to automatically convert ResponseError to ObnizApiError
|
|
61
|
+
*/
|
|
62
|
+
export declare function wrapApiWithErrorHandling<T extends object>(api: T): T;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { AnalyticsApi, ConnectionModelsApi, ConnectionsApi, EventsApi, GroupsApi, InboundConnectionsApi, InboundSourcesApi, IntegrationsApi, IntelligencesApi, IssuesApi, MachineApi, MachinesApi, NotificationsApi, ReportsApi, ThreadsApi, UnitsApi } from "./sdk-core";
|
|
2
|
+
export interface CookieAuthOptions {
|
|
3
|
+
token: string;
|
|
4
|
+
accountId: string;
|
|
5
|
+
}
|
|
6
|
+
type BaseOptions = {
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
};
|
|
10
|
+
type WithoutCookies = {
|
|
11
|
+
token: string;
|
|
12
|
+
cookies?: never;
|
|
13
|
+
};
|
|
14
|
+
type WithCookies = {
|
|
15
|
+
cookies: CookieAuthOptions;
|
|
16
|
+
token?: never;
|
|
17
|
+
};
|
|
18
|
+
export type ObnizNowTokenOptions = BaseOptions & WithoutCookies;
|
|
19
|
+
export type ObnizNowCookiesOptions = BaseOptions & WithCookies;
|
|
20
|
+
export type ObnizNowOptions = (BaseOptions & WithoutCookies) | (BaseOptions & WithCookies);
|
|
21
|
+
/**
|
|
22
|
+
* ObnizNow SDK main class
|
|
23
|
+
*
|
|
24
|
+
* Provides access to all Obniz Now API endpoints.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { ObnizNow } from '@obniz/sdk';
|
|
29
|
+
*
|
|
30
|
+
* // Initialize with your API token
|
|
31
|
+
* const client = new ObnizNow({
|
|
32
|
+
* token: 'your-api-token'
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // List machines
|
|
36
|
+
* const machines = await client.machines.listMachines({ limit: 10 });
|
|
37
|
+
*
|
|
38
|
+
* // Get analytics results
|
|
39
|
+
* const analytics = await client.analytics.getAnalyticsResults(
|
|
40
|
+
* 'basic_statistics',
|
|
41
|
+
* 'machine-123'
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Custom base URL for local development
|
|
48
|
+
* const devClient = new ObnizNow({
|
|
49
|
+
* token: 'your-token',
|
|
50
|
+
* baseUrl: 'http://localhost:8080'
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare class ObnizNow {
|
|
55
|
+
/** Analytics API - Execute and retrieve analytics results */
|
|
56
|
+
readonly analytics: AnalyticsApi;
|
|
57
|
+
/** Connection Models API - Manage connection model configurations */
|
|
58
|
+
readonly connectionModels: ConnectionModelsApi;
|
|
59
|
+
/** Connections API - Manage machine connections */
|
|
60
|
+
readonly connections: ConnectionsApi;
|
|
61
|
+
/** Events API - Access event data and history */
|
|
62
|
+
readonly events: EventsApi;
|
|
63
|
+
/** Groups API - Organize machines into groups */
|
|
64
|
+
readonly groups: GroupsApi;
|
|
65
|
+
/** Inbound Connections API - Manage inbound data connections */
|
|
66
|
+
readonly inboundConnections: InboundConnectionsApi;
|
|
67
|
+
/** Inbound Sources API - Configure data sources */
|
|
68
|
+
readonly inboundSources: InboundSourcesApi;
|
|
69
|
+
/** Integrations API - Manage third-party integrations */
|
|
70
|
+
readonly integrations: IntegrationsApi;
|
|
71
|
+
/** Intelligences API - AI and intelligence features */
|
|
72
|
+
readonly intelligences: IntelligencesApi;
|
|
73
|
+
/** Issues API - Track and manage issues */
|
|
74
|
+
readonly issues: IssuesApi;
|
|
75
|
+
/** Machine API - Single machine operations */
|
|
76
|
+
readonly machine: MachineApi;
|
|
77
|
+
/** Machines API - Machine management and operations */
|
|
78
|
+
readonly machines: MachinesApi;
|
|
79
|
+
/** Notifications API - Manage notification settings */
|
|
80
|
+
readonly notifications: NotificationsApi;
|
|
81
|
+
/** Reports API - Generate and retrieve reports */
|
|
82
|
+
readonly reports: ReportsApi;
|
|
83
|
+
/** Threads API - Discussion threads and communications */
|
|
84
|
+
readonly threads: ThreadsApi;
|
|
85
|
+
/** Units API - Unit data and state management */
|
|
86
|
+
readonly units: UnitsApi;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new ObnizNow SDK client instance
|
|
89
|
+
*
|
|
90
|
+
* @param options - Configuration options
|
|
91
|
+
* @param options.token - API authentication token (required)
|
|
92
|
+
* @param options.baseUrl - Base URL for API requests (optional, defaults to 'https://api.obniz.com')
|
|
93
|
+
* @param options.fetch - Custom fetch implementation (optional, for Node.js < 18 or custom scenarios)
|
|
94
|
+
*
|
|
95
|
+
* @throws {Error} When token is not provided
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const client = new ObnizNow({ token: 'your-api-token' });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
constructor(options: ObnizNowOptions);
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ResponseError } from "./sdk-core/runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced API error with automatically parsed response data
|
|
4
|
+
*
|
|
5
|
+
* All API methods automatically convert ResponseError to ObnizApiError,
|
|
6
|
+
* so you get parsed error information without manual handling.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* try {
|
|
11
|
+
* await client.machines.getMachine({ id: 'invalid-id' });
|
|
12
|
+
* } catch (error) {
|
|
13
|
+
* if (error instanceof ObnizApiError) {
|
|
14
|
+
* console.error(`API Error [${error.status}]: ${error.message}`);
|
|
15
|
+
* console.error('Error data:', error.data);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class ObnizNowApiError extends Error {
|
|
21
|
+
/** HTTP status code (e.g., 404, 500) */
|
|
22
|
+
readonly status: number;
|
|
23
|
+
/** HTTP status text (e.g., "Not Found", "Internal Server Error") */
|
|
24
|
+
readonly statusText: string;
|
|
25
|
+
/** Parsed response body data */
|
|
26
|
+
readonly data: any;
|
|
27
|
+
/** Original ResponseError for advanced use cases */
|
|
28
|
+
readonly originalError: ResponseError;
|
|
29
|
+
constructor(responseError: ResponseError, status: number, statusText: string, data: any);
|
|
30
|
+
/**
|
|
31
|
+
* Create ObnizApiError from ResponseError by parsing the response
|
|
32
|
+
*/
|
|
33
|
+
static fromResponseError(error: ResponseError): Promise<ObnizNowApiError>;
|
|
34
|
+
/**
|
|
35
|
+
* Get response headers (useful for rate limiting, caching, etc.)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const rateLimit = error.getResponseHeaders().get('x-ratelimit-remaining');
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
getResponseHeaders(): Headers;
|
|
43
|
+
/**
|
|
44
|
+
* Get full request URL
|
|
45
|
+
*/
|
|
46
|
+
getRequestUrl(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Control JSON serialization - don't include originalError
|
|
49
|
+
*/
|
|
50
|
+
toJSON(): {
|
|
51
|
+
name: string;
|
|
52
|
+
message: string;
|
|
53
|
+
status: number;
|
|
54
|
+
statusText: string;
|
|
55
|
+
data: any;
|
|
56
|
+
stack: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wraps an API object to automatically convert ResponseError to ObnizApiError
|
|
61
|
+
*/
|
|
62
|
+
export declare function wrapApiWithErrorHandling<T extends object>(api: T): T;
|