oz-node-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 ADDED
@@ -0,0 +1,48 @@
1
+ # oz-node-sdk
2
+
3
+ Generated Node.js SDK for the oz API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @oz/oz-node-sdk
9
+ ```
10
+
11
+ or
12
+
13
+ ```bash
14
+ npm install @oz/oz-node-sdk
15
+ ```
16
+
17
+ ## Build
18
+
19
+ From this directory run:
20
+
21
+ ```bash
22
+ OPENAPI_SPEC_PATH=../../target/openapi/openapi.json bun run build
23
+ ```
24
+
25
+ The script reads the generated OpenAPI artifact and writes SDK artifacts to `dist/`.
26
+
27
+ ## Publish
28
+
29
+ ```bash
30
+ bun run clean
31
+ OPENAPI_SPEC_PATH=../../target/openapi/openapi.json bun run build
32
+ bun publish --access public
33
+ ```
34
+
35
+ `prepublishOnly` is configured to regenerate `dist` automatically before publish.
36
+
37
+ ## Usage
38
+
39
+ ```js
40
+ import { OzNodeSdkClient } from '@oz/oz-node-sdk';
41
+
42
+ const client = new OzNodeSdkClient({
43
+ baseUrl: 'http://localhost:8787',
44
+ apiKey: 'oz_live_xxx',
45
+ });
46
+
47
+ const projects = await client.GET_v2_projects();
48
+ ```
@@ -0,0 +1,56 @@
1
+ export interface OzNodeSdkOptions {
2
+ baseUrl?: string;
3
+ apiKey?: string;
4
+ headers?: Record<string, string>;
5
+ fetch?: typeof fetch;
6
+ }
7
+
8
+ export interface OzNodeRequestOptions {
9
+ pathParams?: Record<string, string | number>;
10
+ query?: Record<string, string | number | boolean | Array<string | number | boolean>>;
11
+ body?: unknown;
12
+ headers?: Record<string, string>;
13
+ signal?: AbortSignal;
14
+ }
15
+
16
+ export type OzNodeSdkEndpoint = {
17
+ method: string;
18
+ path: string;
19
+ operationId: string;
20
+ summary?: string;
21
+ tags?: string[];
22
+ };
23
+
24
+ export const openapiEndpoints: OzNodeSdkEndpoint[];
25
+
26
+ export class OzNodeSdkClient {
27
+ constructor(options?: OzNodeSdkOptions);
28
+ setApiKey(apiKey: string | null): void;
29
+ GET_api_csrf(options?: OzNodeRequestOptions): Promise<unknown>;
30
+ GET_api_keys(options?: OzNodeRequestOptions): Promise<unknown>;
31
+ POST_api_keys(options?: OzNodeRequestOptions): Promise<unknown>;
32
+ DELETE_api_keys_id(options?: OzNodeRequestOptions): Promise<unknown>;
33
+ GET_api_me(options?: OzNodeRequestOptions): Promise<unknown>;
34
+ GET_api_projects(options?: OzNodeRequestOptions): Promise<unknown>;
35
+ POST_api_projects(options?: OzNodeRequestOptions): Promise<unknown>;
36
+ DELETE_api_projects_slug_members(options?: OzNodeRequestOptions): Promise<unknown>;
37
+ GET_api_projects_slug_members(options?: OzNodeRequestOptions): Promise<unknown>;
38
+ POST_api_projects_slug_members(options?: OzNodeRequestOptions): Promise<unknown>;
39
+ POST_api_secrets_delete(options?: OzNodeRequestOptions): Promise<unknown>;
40
+ POST_api_secrets_list(options?: OzNodeRequestOptions): Promise<unknown>;
41
+ POST_api_secrets_read(options?: OzNodeRequestOptions): Promise<unknown>;
42
+ PUT_api_secrets_write(options?: OzNodeRequestOptions): Promise<unknown>;
43
+ GET_auth_github(options?: OzNodeRequestOptions): Promise<unknown>;
44
+ GET_auth_github_callback(options?: OzNodeRequestOptions): Promise<unknown>;
45
+ POST_auth_logout(options?: OzNodeRequestOptions): Promise<unknown>;
46
+ GET_v1_projects(options?: OzNodeRequestOptions): Promise<unknown>;
47
+ GET_v1_projects_slug_secrets(options?: OzNodeRequestOptions): Promise<unknown>;
48
+ DELETE_v1_projects_slug_secrets_key(options?: OzNodeRequestOptions): Promise<unknown>;
49
+ GET_v1_projects_slug_secrets_key(options?: OzNodeRequestOptions): Promise<unknown>;
50
+ PUT_v1_projects_slug_secrets_key(options?: OzNodeRequestOptions): Promise<unknown>;
51
+ GET_v2_projects(options?: OzNodeRequestOptions): Promise<unknown>;
52
+ POST_v2_secrets_delete(options?: OzNodeRequestOptions): Promise<unknown>;
53
+ POST_v2_secrets_list(options?: OzNodeRequestOptions): Promise<unknown>;
54
+ POST_v2_secrets_read(options?: OzNodeRequestOptions): Promise<unknown>;
55
+ PUT_v2_secrets_write(options?: OzNodeRequestOptions): Promise<unknown>;
56
+ }
package/dist/index.js ADDED
@@ -0,0 +1,420 @@
1
+ "use strict";
2
+
3
+ export const openapiEndpoints = [
4
+ {
5
+ "method": "GET",
6
+ "path": "/api/csrf",
7
+ "operationId": "GET_api_csrf",
8
+ "summary": "",
9
+ "tags": []
10
+ },
11
+ {
12
+ "method": "GET",
13
+ "path": "/api/keys",
14
+ "operationId": "GET_api_keys",
15
+ "summary": "",
16
+ "tags": []
17
+ },
18
+ {
19
+ "method": "POST",
20
+ "path": "/api/keys",
21
+ "operationId": "POST_api_keys",
22
+ "summary": "",
23
+ "tags": []
24
+ },
25
+ {
26
+ "method": "DELETE",
27
+ "path": "/api/keys/{id}",
28
+ "operationId": "DELETE_api_keys_id",
29
+ "summary": "",
30
+ "tags": []
31
+ },
32
+ {
33
+ "method": "GET",
34
+ "path": "/api/me",
35
+ "operationId": "GET_api_me",
36
+ "summary": "",
37
+ "tags": []
38
+ },
39
+ {
40
+ "method": "GET",
41
+ "path": "/api/projects",
42
+ "operationId": "GET_api_projects",
43
+ "summary": "",
44
+ "tags": []
45
+ },
46
+ {
47
+ "method": "POST",
48
+ "path": "/api/projects",
49
+ "operationId": "POST_api_projects",
50
+ "summary": "",
51
+ "tags": []
52
+ },
53
+ {
54
+ "method": "DELETE",
55
+ "path": "/api/projects/{slug}/members",
56
+ "operationId": "DELETE_api_projects_slug_members",
57
+ "summary": "",
58
+ "tags": []
59
+ },
60
+ {
61
+ "method": "GET",
62
+ "path": "/api/projects/{slug}/members",
63
+ "operationId": "GET_api_projects_slug_members",
64
+ "summary": "",
65
+ "tags": []
66
+ },
67
+ {
68
+ "method": "POST",
69
+ "path": "/api/projects/{slug}/members",
70
+ "operationId": "POST_api_projects_slug_members",
71
+ "summary": "",
72
+ "tags": []
73
+ },
74
+ {
75
+ "method": "POST",
76
+ "path": "/api/secrets/delete",
77
+ "operationId": "POST_api_secrets_delete",
78
+ "summary": "",
79
+ "tags": []
80
+ },
81
+ {
82
+ "method": "POST",
83
+ "path": "/api/secrets/list",
84
+ "operationId": "POST_api_secrets_list",
85
+ "summary": "",
86
+ "tags": []
87
+ },
88
+ {
89
+ "method": "POST",
90
+ "path": "/api/secrets/read",
91
+ "operationId": "POST_api_secrets_read",
92
+ "summary": "",
93
+ "tags": []
94
+ },
95
+ {
96
+ "method": "PUT",
97
+ "path": "/api/secrets/write",
98
+ "operationId": "PUT_api_secrets_write",
99
+ "summary": "",
100
+ "tags": []
101
+ },
102
+ {
103
+ "method": "GET",
104
+ "path": "/auth/github",
105
+ "operationId": "GET_auth_github",
106
+ "summary": "",
107
+ "tags": []
108
+ },
109
+ {
110
+ "method": "GET",
111
+ "path": "/auth/github/callback",
112
+ "operationId": "GET_auth_github_callback",
113
+ "summary": "",
114
+ "tags": []
115
+ },
116
+ {
117
+ "method": "POST",
118
+ "path": "/auth/logout",
119
+ "operationId": "POST_auth_logout",
120
+ "summary": "",
121
+ "tags": []
122
+ },
123
+ {
124
+ "method": "GET",
125
+ "path": "/v1/projects",
126
+ "operationId": "GET_v1_projects",
127
+ "summary": "",
128
+ "tags": []
129
+ },
130
+ {
131
+ "method": "GET",
132
+ "path": "/v1/projects/{slug}/secrets",
133
+ "operationId": "GET_v1_projects_slug_secrets",
134
+ "summary": "",
135
+ "tags": []
136
+ },
137
+ {
138
+ "method": "DELETE",
139
+ "path": "/v1/projects/{slug}/secrets/{key}",
140
+ "operationId": "DELETE_v1_projects_slug_secrets_key",
141
+ "summary": "",
142
+ "tags": []
143
+ },
144
+ {
145
+ "method": "GET",
146
+ "path": "/v1/projects/{slug}/secrets/{key}",
147
+ "operationId": "GET_v1_projects_slug_secrets_key",
148
+ "summary": "",
149
+ "tags": []
150
+ },
151
+ {
152
+ "method": "PUT",
153
+ "path": "/v1/projects/{slug}/secrets/{key}",
154
+ "operationId": "PUT_v1_projects_slug_secrets_key",
155
+ "summary": "",
156
+ "tags": []
157
+ },
158
+ {
159
+ "method": "GET",
160
+ "path": "/v2/projects",
161
+ "operationId": "GET_v2_projects",
162
+ "summary": "",
163
+ "tags": []
164
+ },
165
+ {
166
+ "method": "POST",
167
+ "path": "/v2/secrets/delete",
168
+ "operationId": "POST_v2_secrets_delete",
169
+ "summary": "",
170
+ "tags": []
171
+ },
172
+ {
173
+ "method": "POST",
174
+ "path": "/v2/secrets/list",
175
+ "operationId": "POST_v2_secrets_list",
176
+ "summary": "",
177
+ "tags": []
178
+ },
179
+ {
180
+ "method": "POST",
181
+ "path": "/v2/secrets/read",
182
+ "operationId": "POST_v2_secrets_read",
183
+ "summary": "",
184
+ "tags": []
185
+ },
186
+ {
187
+ "method": "PUT",
188
+ "path": "/v2/secrets/write",
189
+ "operationId": "PUT_v2_secrets_write",
190
+ "summary": "",
191
+ "tags": []
192
+ }
193
+ ];
194
+
195
+ const query = (searchParams = {}, search = new URLSearchParams()) => {
196
+ for (const [key, value] of Object.entries(searchParams)) {
197
+ if (value === undefined) {
198
+ continue;
199
+ }
200
+
201
+ if (Array.isArray(value)) {
202
+ for (const item of value) {
203
+ search.append(key, String(item));
204
+ }
205
+
206
+ continue;
207
+ }
208
+
209
+ search.append(key, String(value));
210
+ }
211
+
212
+ return search;
213
+ };
214
+
215
+ export class OzNodeSdkClient {
216
+ #baseUrl;
217
+ #apiKey;
218
+ #fetch;
219
+ #defaultHeaders;
220
+
221
+ constructor({
222
+ baseUrl = '',
223
+ apiKey,
224
+ fetch: fetchImpl,
225
+ headers = {},
226
+ } = {}) {
227
+ if (typeof fetchImpl !== 'undefined' && typeof fetchImpl !== 'function') {
228
+ throw new TypeError('fetch option must be a function');
229
+ }
230
+
231
+ const resolvedFetch = fetchImpl ?? globalThis.fetch;
232
+ if (typeof resolvedFetch !== 'function') {
233
+ throw new Error('No fetch implementation available in this environment');
234
+ }
235
+
236
+ this.#baseUrl = baseUrl.replace(//$/, '');
237
+ this.#apiKey = apiKey ?? null;
238
+ this.#fetch = resolvedFetch;
239
+ this.#defaultHeaders = { ...headers };
240
+ }
241
+
242
+ setApiKey(apiKey) {
243
+ this.#apiKey = apiKey;
244
+ }
245
+
246
+ #url(routePath, pathParams = {}, queryParams = {}) {
247
+ const path = routePath.replace(/{([^}/]+)}/g, (_match, key) => {
248
+ if (!(key in pathParams)) {
249
+ throw new Error('Missing path parameter: ' + key);
250
+ }
251
+
252
+ return encodeURIComponent(String(pathParams[key]));
253
+ });
254
+
255
+ const url = new URL(this.#baseUrl + path);
256
+ if (queryParams && Object.keys(queryParams).length > 0) {
257
+ query(url.searchParams, queryParams);
258
+ }
259
+
260
+ return url;
261
+ }
262
+
263
+ async #request(method, routePath, options = {}) {
264
+ const {
265
+ pathParams = {},
266
+ query: queryParams = {},
267
+ body,
268
+ headers = {},
269
+ signal,
270
+ } = options ?? {};
271
+
272
+ const url = this.#url(routePath, pathParams, queryParams);
273
+ const requestHeaders = {
274
+ ...this.#defaultHeaders,
275
+ ...headers,
276
+ Accept: 'application/json',
277
+ };
278
+
279
+ if (this.#apiKey) {
280
+ requestHeaders.Authorization = 'Bearer ' + this.#apiKey;
281
+ }
282
+
283
+ const init = {
284
+ method,
285
+ headers: requestHeaders,
286
+ signal,
287
+ };
288
+
289
+ if (body !== undefined && !['GET', 'HEAD'].includes(method)) {
290
+ requestHeaders['Content-Type'] = requestHeaders['Content-Type'] ?? 'application/json';
291
+ init.body = typeof body === 'string' ? body : JSON.stringify(body);
292
+ }
293
+
294
+ const response = await this.#fetch(url.href, init);
295
+ if (!response.ok) {
296
+ const responseText = await response.text();
297
+ throw new Error('API request failed (' + response.status + '): ' + (responseText || 'no response body'));
298
+ }
299
+
300
+ if (response.status === 204) {
301
+ return null;
302
+ }
303
+
304
+ const responseType = response.headers.get('content-type') || '';
305
+ if (responseType.includes('application/json')) {
306
+ return response.json();
307
+ }
308
+
309
+ return response.text();
310
+ }
311
+
312
+ async GET_api_csrf(options = {}) {
313
+ return this.#request("GET", "/api/csrf", options);
314
+ }
315
+
316
+ async GET_api_keys(options = {}) {
317
+ return this.#request("GET", "/api/keys", options);
318
+ }
319
+
320
+ async POST_api_keys(options = {}) {
321
+ return this.#request("POST", "/api/keys", options);
322
+ }
323
+
324
+ async DELETE_api_keys_id(options = {}) {
325
+ return this.#request("DELETE", "/api/keys/{id}", options);
326
+ }
327
+
328
+ async GET_api_me(options = {}) {
329
+ return this.#request("GET", "/api/me", options);
330
+ }
331
+
332
+ async GET_api_projects(options = {}) {
333
+ return this.#request("GET", "/api/projects", options);
334
+ }
335
+
336
+ async POST_api_projects(options = {}) {
337
+ return this.#request("POST", "/api/projects", options);
338
+ }
339
+
340
+ async DELETE_api_projects_slug_members(options = {}) {
341
+ return this.#request("DELETE", "/api/projects/{slug}/members", options);
342
+ }
343
+
344
+ async GET_api_projects_slug_members(options = {}) {
345
+ return this.#request("GET", "/api/projects/{slug}/members", options);
346
+ }
347
+
348
+ async POST_api_projects_slug_members(options = {}) {
349
+ return this.#request("POST", "/api/projects/{slug}/members", options);
350
+ }
351
+
352
+ async POST_api_secrets_delete(options = {}) {
353
+ return this.#request("POST", "/api/secrets/delete", options);
354
+ }
355
+
356
+ async POST_api_secrets_list(options = {}) {
357
+ return this.#request("POST", "/api/secrets/list", options);
358
+ }
359
+
360
+ async POST_api_secrets_read(options = {}) {
361
+ return this.#request("POST", "/api/secrets/read", options);
362
+ }
363
+
364
+ async PUT_api_secrets_write(options = {}) {
365
+ return this.#request("PUT", "/api/secrets/write", options);
366
+ }
367
+
368
+ async GET_auth_github(options = {}) {
369
+ return this.#request("GET", "/auth/github", options);
370
+ }
371
+
372
+ async GET_auth_github_callback(options = {}) {
373
+ return this.#request("GET", "/auth/github/callback", options);
374
+ }
375
+
376
+ async POST_auth_logout(options = {}) {
377
+ return this.#request("POST", "/auth/logout", options);
378
+ }
379
+
380
+ async GET_v1_projects(options = {}) {
381
+ return this.#request("GET", "/v1/projects", options);
382
+ }
383
+
384
+ async GET_v1_projects_slug_secrets(options = {}) {
385
+ return this.#request("GET", "/v1/projects/{slug}/secrets", options);
386
+ }
387
+
388
+ async DELETE_v1_projects_slug_secrets_key(options = {}) {
389
+ return this.#request("DELETE", "/v1/projects/{slug}/secrets/{key}", options);
390
+ }
391
+
392
+ async GET_v1_projects_slug_secrets_key(options = {}) {
393
+ return this.#request("GET", "/v1/projects/{slug}/secrets/{key}", options);
394
+ }
395
+
396
+ async PUT_v1_projects_slug_secrets_key(options = {}) {
397
+ return this.#request("PUT", "/v1/projects/{slug}/secrets/{key}", options);
398
+ }
399
+
400
+ async GET_v2_projects(options = {}) {
401
+ return this.#request("GET", "/v2/projects", options);
402
+ }
403
+
404
+ async POST_v2_secrets_delete(options = {}) {
405
+ return this.#request("POST", "/v2/secrets/delete", options);
406
+ }
407
+
408
+ async POST_v2_secrets_list(options = {}) {
409
+ return this.#request("POST", "/v2/secrets/list", options);
410
+ }
411
+
412
+ async POST_v2_secrets_read(options = {}) {
413
+ return this.#request("POST", "/v2/secrets/read", options);
414
+ }
415
+
416
+ async PUT_v2_secrets_write(options = {}) {
417
+ return this.#request("PUT", "/v2/secrets/write", options);
418
+ }
419
+
420
+ }