@obniz/obniz-now-sdk 0.1.0 → 0.1.11
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/LICENSE +15 -0
- package/README.md +204 -1
- package/dist/ObnizNow.d.ts +22 -2
- package/dist/ObnizNowApiError.d.ts +4 -7
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3494 -350
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3494 -351
- package/dist/index.mjs.map +1 -1
- package/dist/sdk-core/apis/AccountApi.d.ts +246 -0
- package/dist/sdk-core/apis/AuditLogsApi.d.ts +36 -0
- package/dist/sdk-core/apis/ConnectionsApi.d.ts +14 -1
- package/dist/sdk-core/apis/CustomizesApi.d.ts +104 -0
- package/dist/sdk-core/apis/FirmwareApi.d.ts +126 -0
- package/dist/sdk-core/apis/GroupsApi.d.ts +98 -1
- package/dist/sdk-core/apis/IntelligencesApi.d.ts +16 -1
- package/dist/sdk-core/apis/InvitationsApi.d.ts +120 -0
- package/dist/sdk-core/apis/IssuesApi.d.ts +27 -1
- package/dist/sdk-core/apis/MachineApi.d.ts +4 -2
- package/dist/sdk-core/apis/MachinesApi.d.ts +40 -1
- package/dist/sdk-core/apis/NotificationHistoryApi.d.ts +68 -0
- package/dist/sdk-core/apis/NotificationsApi.d.ts +34 -4
- package/dist/sdk-core/apis/ObnizApi.d.ts +45 -0
- package/dist/sdk-core/apis/ReportsApi.d.ts +27 -1
- package/dist/sdk-core/apis/SessionApi.d.ts +51 -0
- package/dist/sdk-core/apis/UsersApi.d.ts +68 -0
- package/dist/sdk-core/apis/index.d.ts +9 -0
- package/dist/sdk-core/models/index.d.ts +5492 -1679
- package/package.json +25 -16
- package/dist/ObnizApiError.d.ts +0 -62
- package/dist/ObnizNow.test.d.ts +0 -1
- package/dist/index.browser.mjs +0 -3253
- package/dist/index.browser.mjs.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 obniz
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,6 +3,209 @@
|
|
|
3
3
|
TypeScript/JavaScript SDK for Obniz Now API
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
|
+
```bash
|
|
7
|
+
npm install @obniz/obniz-now-sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Authentication
|
|
11
|
+
|
|
12
|
+
The SDK supports authentication using an API token (Bearer token). You can obtain your API token from your [Obniz account settings](https://obniz.com/).
|
|
13
|
+
|
|
14
|
+
### Using API Token
|
|
15
|
+
```typescript
|
|
16
|
+
import { ObnizNow } from '@obniz/obniz-now-sdk';
|
|
17
|
+
|
|
18
|
+
const client = new ObnizNow({
|
|
19
|
+
token: 'your-api-token-here'
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Using Environment Variables (Recommended)
|
|
24
|
+
```typescript
|
|
25
|
+
const client = new ObnizNow({
|
|
26
|
+
token: process.env.OBNIZ_NOW_TOKEN
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Basic Usage
|
|
31
|
+
|
|
32
|
+
### List Machines
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { ObnizNow } from '@obniz/obniz-now-sdk';
|
|
36
|
+
|
|
37
|
+
const client = new ObnizNow({ token: process.env.OBNIZ_TOKEN });
|
|
38
|
+
|
|
39
|
+
// Get list of machines
|
|
40
|
+
const response = await client.machines.listMachines({
|
|
41
|
+
limit: 10,
|
|
42
|
+
offset: 0
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log(`Found ${response.count} machines`);
|
|
46
|
+
response.items.forEach((item) => {
|
|
47
|
+
console.log(`- ${item.machine.name} (${item.machine.id})`);
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Get Machine Details
|
|
52
|
+
```typescript
|
|
53
|
+
// Get specific machine
|
|
54
|
+
const machine = await client.machine.getMachine({
|
|
55
|
+
machineId: 'machine-id'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log(`Name: ${machine.name}`);
|
|
59
|
+
console.log(`Created: ${machine.createdAt}`);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Get Events
|
|
63
|
+
```typescript
|
|
64
|
+
// Get recent events
|
|
65
|
+
const events = await client.events.listEvents({
|
|
66
|
+
from: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
|
|
67
|
+
to: new Date().toISOString(),
|
|
68
|
+
limit: 20
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log(`Found ${events.count} events`);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Error Handling
|
|
75
|
+
|
|
76
|
+
All API errors are automatically converted to `ObnizNowApiError` with parsed response data.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { ObnizNow, ObnizNowApiError } from '@obniz/obniz-now-sdk';
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const machine = await client.machine.getMachine({ machineId: 'invalid-id' });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof ObnizNowApiError) {
|
|
85
|
+
console.error(`Error ${error.status}: ${error.message}`);
|
|
86
|
+
console.error('Details:', error.data);
|
|
87
|
+
|
|
88
|
+
// Access response headers
|
|
89
|
+
const headers = error.getResponseHeaders();
|
|
90
|
+
const rateLimit = headers.get('x-ratelimit-remaining');
|
|
91
|
+
|
|
92
|
+
// Get request URL for debugging
|
|
93
|
+
console.error('Failed request:', error.getRequestUrl());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Browser Usage (Svelte)
|
|
99
|
+
|
|
100
|
+
### ⚠️ Security Warning
|
|
101
|
+
**Never expose your API token in client-side code!** Use one of these safe approaches:
|
|
102
|
+
|
|
103
|
+
### Option 1: Cookie-based Authentication (Recommended for custom pages)
|
|
104
|
+
```typescript
|
|
105
|
+
import { ObnizNow } from '@obniz/obniz-now-sdk';
|
|
106
|
+
|
|
107
|
+
const client = new ObnizNow({
|
|
108
|
+
baseUrl: window.location.origin,
|
|
109
|
+
cookies: {
|
|
110
|
+
// In browsers, existing same-origin cookies are sent by fetch(credentials: "include").
|
|
111
|
+
// These values are used only by non-browser runtimes where Cookie headers can be set.
|
|
112
|
+
token: '',
|
|
113
|
+
accountId: '',
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const machines = await client.machines.listMachines({ limit: 20 });
|
|
118
|
+
```
|
|
6
119
|
|
|
120
|
+
Your backend should set httpOnly cookies after user authentication.
|
|
121
|
+
|
|
122
|
+
For plain custom page HTML, import the browser bundle from a CDN or from a file hosted with the page:
|
|
123
|
+
|
|
124
|
+
```html
|
|
125
|
+
<script type="module">
|
|
126
|
+
import { ObnizNow } from "https://cdn.jsdelivr.net/npm/@obniz/obniz-now-sdk@0.1.11/dist/index.mjs";
|
|
127
|
+
|
|
128
|
+
const client = new ObnizNow({
|
|
129
|
+
baseUrl: window.location.origin,
|
|
130
|
+
cookies: { token: "", accountId: "" },
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const response = await client.machines.listMachines({ limit: 10, offset: 0 });
|
|
134
|
+
console.log(response.items);
|
|
135
|
+
</script>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Option 2: Backend Proxy
|
|
139
|
+
```typescript
|
|
140
|
+
// Frontend - call your backend API
|
|
141
|
+
const machines = await fetch('/api/obniz/machines').then(r => r.json());
|
|
142
|
+
|
|
143
|
+
// Backend (Node.js) - proxy to Obniz API
|
|
144
|
+
app.get('/api/obniz/machines', async (req, res) => {
|
|
145
|
+
const client = new ObnizNow({ token: process.env.OBNIZ_TOKEN });
|
|
146
|
+
const data = await client.machines.listMachines({ limit: 20 });
|
|
147
|
+
res.json(data);
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### SvelteKit Server-Side Example
|
|
152
|
+
```typescript
|
|
153
|
+
// src/routes/+page.server.ts
|
|
154
|
+
import { ObnizNow } from '@obniz/obniz-now-sdk';
|
|
155
|
+
|
|
156
|
+
export async function load() {
|
|
157
|
+
const client = new ObnizNow({ token: process.env.OBNIZ_TOKEN });
|
|
158
|
+
const machines = await client.machines.listMachines({ limit: 20 });
|
|
159
|
+
|
|
160
|
+
return { machines: machines.items };
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```svelte
|
|
165
|
+
<!-- src/routes/+page.svelte -->
|
|
166
|
+
<script lang="ts">
|
|
167
|
+
export let data;
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<h1>Machines</h1>
|
|
171
|
+
<ul>
|
|
172
|
+
{#each data.machines as item}
|
|
173
|
+
<li>{item.machine.name}</li>
|
|
174
|
+
{/each}
|
|
175
|
+
</ul>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Examples
|
|
179
|
+
See the examples/ directory for more detailed examples:
|
|
180
|
+
|
|
181
|
+
`basic-usage.ts` - SDK initialization and basic operations
|
|
182
|
+
|
|
183
|
+
`analytics.ts` - Working with analytics
|
|
184
|
+
|
|
185
|
+
`events.ts` - Retrieving and filtering events
|
|
186
|
+
|
|
187
|
+
`machine-management.ts` - CRUD operations
|
|
188
|
+
|
|
189
|
+
`custom-config.ts` - Advanced configuration (retry, logging)
|
|
190
|
+
|
|
191
|
+
`advanced-error-handling.ts` - Error inspection and debugging
|
|
192
|
+
|
|
193
|
+
## API Categories
|
|
194
|
+
|
|
195
|
+
The `ObnizNow` client exposes generated API groups including:
|
|
196
|
+
|
|
197
|
+
`account`, `analytics`, `auditLogs`, `connectionModels`, `connections`, `converters`, `customizes`, `events`, `firmware`, `groups`, `inboundConnections`, `inboundSources`, `integrations`, `intelligences`, `invitations`, `issues`, `machine`, `machines`, `notificationHistory`, `notifications`, `obniz`, `reports`, `session`, `threads`, `units`, and `users`.
|
|
198
|
+
|
|
199
|
+
### Run any example:
|
|
7
200
|
```bash
|
|
8
|
-
|
|
201
|
+
npx tsx examples/basic-usage.ts
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
# Requirements
|
|
205
|
+
Node.js >= 18.0.0
|
|
206
|
+
|
|
207
|
+
# Links
|
|
208
|
+
Website:
|
|
209
|
+
https://iot.obniz.com
|
|
210
|
+
|
|
211
|
+
API documentation: https://now.obniz.com/api/1/docs/
|
package/dist/ObnizNow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnalyticsApi, ConnectionModelsApi, ConnectionsApi, EventsApi, GroupsApi, InboundConnectionsApi, InboundSourcesApi, IntegrationsApi, IntelligencesApi, IssuesApi, MachineApi, MachinesApi, NotificationsApi, ReportsApi, ThreadsApi, UnitsApi } from "./sdk-core";
|
|
1
|
+
import { AccountApi, AnalyticsApi, AuditLogsApi, ConnectionModelsApi, ConnectionsApi, ConvertersApi, CustomizesApi, EventsApi, FirmwareApi, GroupsApi, InboundConnectionsApi, InboundSourcesApi, IntegrationsApi, IntelligencesApi, InvitationsApi, IssuesApi, MachineApi, MachinesApi, NotificationHistoryApi, NotificationsApi, ObnizApi, ReportsApi, SessionApi, ThreadsApi, UnitsApi, UsersApi } from "./sdk-core";
|
|
2
2
|
export interface CookieAuthOptions {
|
|
3
3
|
token: string;
|
|
4
4
|
accountId: string;
|
|
@@ -52,14 +52,24 @@ export type ObnizNowOptions = (BaseOptions & WithoutCookies) | (BaseOptions & Wi
|
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
54
|
export declare class ObnizNow {
|
|
55
|
+
/** Account API - Manage current account settings, members, API keys, plan, entitlements, usages, and secrets */
|
|
56
|
+
readonly account: AccountApi;
|
|
55
57
|
/** Analytics API - Execute and retrieve analytics results */
|
|
56
58
|
readonly analytics: AnalyticsApi;
|
|
59
|
+
/** Audit Logs API - Access account audit log entries */
|
|
60
|
+
readonly auditLogs: AuditLogsApi;
|
|
57
61
|
/** Connection Models API - Manage connection model configurations */
|
|
58
62
|
readonly connectionModels: ConnectionModelsApi;
|
|
59
63
|
/** Connections API - Manage machine connections */
|
|
60
64
|
readonly connections: ConnectionsApi;
|
|
65
|
+
/** Converters API - Data format conversions */
|
|
66
|
+
readonly converters: ConvertersApi;
|
|
67
|
+
/** Customizes API - Resolve account, machine, group, and asset customizations */
|
|
68
|
+
readonly customizes: CustomizesApi;
|
|
61
69
|
/** Events API - Access event data and history */
|
|
62
70
|
readonly events: EventsApi;
|
|
71
|
+
/** Firmware API - Inspect and update device firmware */
|
|
72
|
+
readonly firmware: FirmwareApi;
|
|
63
73
|
/** Groups API - Organize machines into groups */
|
|
64
74
|
readonly groups: GroupsApi;
|
|
65
75
|
/** Inbound Connections API - Manage inbound data connections */
|
|
@@ -70,20 +80,30 @@ export declare class ObnizNow {
|
|
|
70
80
|
readonly integrations: IntegrationsApi;
|
|
71
81
|
/** Intelligences API - AI and intelligence features */
|
|
72
82
|
readonly intelligences: IntelligencesApi;
|
|
83
|
+
/** Invitations API - Manage account invitations */
|
|
84
|
+
readonly invitations: InvitationsApi;
|
|
73
85
|
/** Issues API - Track and manage issues */
|
|
74
86
|
readonly issues: IssuesApi;
|
|
75
87
|
/** Machine API - Single machine operations */
|
|
76
88
|
readonly machine: MachineApi;
|
|
77
89
|
/** Machines API - Machine management and operations */
|
|
78
90
|
readonly machines: MachinesApi;
|
|
91
|
+
/** Notification History API - Access notification delivery history */
|
|
92
|
+
readonly notificationHistory: NotificationHistoryApi;
|
|
79
93
|
/** Notifications API - Manage notification settings */
|
|
80
94
|
readonly notifications: NotificationsApi;
|
|
95
|
+
/** Obniz API - Access obniz device metadata */
|
|
96
|
+
readonly obniz: ObnizApi;
|
|
81
97
|
/** Reports API - Generate and retrieve reports */
|
|
82
98
|
readonly reports: ReportsApi;
|
|
99
|
+
/** Session API - Browser session account selection and UI configuration */
|
|
100
|
+
readonly session: SessionApi;
|
|
83
101
|
/** Threads API - Discussion threads and communications */
|
|
84
102
|
readonly threads: ThreadsApi;
|
|
85
103
|
/** Units API - Unit data and state management */
|
|
86
104
|
readonly units: UnitsApi;
|
|
105
|
+
/** Users API - Manage current user and profile pictures */
|
|
106
|
+
readonly users: UsersApi;
|
|
87
107
|
/**
|
|
88
108
|
* Creates a new ObnizNow SDK client instance
|
|
89
109
|
*
|
|
@@ -101,4 +121,4 @@ export declare class ObnizNow {
|
|
|
101
121
|
*/
|
|
102
122
|
constructor(options: ObnizNowOptions);
|
|
103
123
|
}
|
|
104
|
-
export
|
|
124
|
+
export * from "./sdk-core";
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { ResponseError } from "./sdk-core/runtime";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* All API methods automatically convert ResponseError to ObnizApiError,
|
|
6
|
-
* so you get parsed error information without manual handling.
|
|
3
|
+
* All API methods automatically convert ResponseError to ObnizApiError
|
|
7
4
|
*
|
|
8
5
|
* @example
|
|
9
6
|
* ```typescript
|
|
10
7
|
* try {
|
|
11
8
|
* await client.machines.getMachine({ id: 'invalid-id' });
|
|
12
9
|
* } catch (error) {
|
|
13
|
-
* if (error instanceof
|
|
10
|
+
* if (error instanceof ObnizNowApiError) {
|
|
14
11
|
* console.error(`API Error [${error.status}]: ${error.message}`);
|
|
15
12
|
* console.error('Error data:', error.data);
|
|
16
13
|
* }
|
|
@@ -28,7 +25,7 @@ export declare class ObnizNowApiError extends Error {
|
|
|
28
25
|
readonly originalError: ResponseError;
|
|
29
26
|
constructor(responseError: ResponseError, status: number, statusText: string, data: any);
|
|
30
27
|
/**
|
|
31
|
-
* Create
|
|
28
|
+
* Create ObnizNowApiError from ResponseError by parsing the response
|
|
32
29
|
*/
|
|
33
30
|
static fromResponseError(error: ResponseError): Promise<ObnizNowApiError>;
|
|
34
31
|
/**
|
|
@@ -57,6 +54,6 @@ export declare class ObnizNowApiError extends Error {
|
|
|
57
54
|
};
|
|
58
55
|
}
|
|
59
56
|
/**
|
|
60
|
-
* Wraps an API object to automatically convert ResponseError to
|
|
57
|
+
* Wraps an API object to automatically convert ResponseError to ObnizNowApiError
|
|
61
58
|
*/
|
|
62
59
|
export declare function wrapApiWithErrorHandling<T extends object>(api: T): T;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { ObnizNow } from "./ObnizNow";
|
|
2
|
+
export type { ObnizNowOptions, ObnizNowTokenOptions, ObnizNowCookiesOptions, } from "./ObnizNow";
|
|
2
3
|
export { ObnizNowApiError } from "./ObnizNowApiError";
|
|
4
|
+
import * as Core from "./sdk-core/index";
|
|
5
|
+
export { Core as Models };
|