@bodhiapp/ts-client 0.1.2 → 0.1.4

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/package.json CHANGED
@@ -1,33 +1,40 @@
1
1
  {
2
2
  "name": "@bodhiapp/ts-client",
3
- "version": "0.1.2",
4
- "description": "TypeScript client for Bodhi API",
3
+ "version": "0.1.4",
4
+ "description": "TypeScript types for Bodhi API",
5
5
  "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
6
7
  "types": "dist/index.d.ts",
7
8
  "files": [
8
9
  "dist"
9
10
  ],
10
11
  "scripts": {
11
- "build": "npm run generate && tsc",
12
+ "build": "npm run generate && npm run bundle",
12
13
  "generate": "npm run generate:openapi && npm run generate:types",
13
14
  "generate:openapi": "cd .. && cargo run --package xtask openapi",
14
- "generate:types": "openapi-typescript ../openapi.json --output src/types/api.d.ts --export-type components",
15
- "compile": "tsc",
16
- "prepublishOnly": "npm run test",
17
- "test": "vitest run"
15
+ "generate:types": "openapi-ts",
16
+ "bundle": "npm run bundle:types && npm run bundle:esm && npm run bundle:cjs",
17
+ "bundle:types": "tsc --emitDeclarationOnly --outDir dist && mkdir -p dist/types && cp -r src/types/* dist/types/",
18
+ "bundle:esm": "esbuild src/index.ts --bundle --platform=neutral --format=esm --outfile=dist/index.mjs --external:./types --allow-overwrite",
19
+ "bundle:cjs": "esbuild src/index.ts --bundle --platform=neutral --format=cjs --outfile=dist/index.js --external:./types --allow-overwrite",
20
+ "test": "vitest run",
21
+ "clean": "rm -rf dist && rm -rf src/types"
18
22
  },
19
23
  "keywords": [
20
24
  "bodhi",
21
25
  "api",
22
- "client",
26
+ "types",
23
27
  "typescript"
24
28
  ],
25
29
  "author": "Bodhi Team",
26
30
  "license": "Apache-2.0",
27
31
  "devDependencies": {
28
- "openapi-typescript": "^6.7.3",
32
+ "@hey-api/openapi-ts": "^0.64.15",
33
+ "@types/node": "^22.13.14",
34
+ "esbuild": "^0.20.2",
35
+ "msw": "^2.7.3",
29
36
  "typescript": "^5.3.3",
30
- "vitest": "^1.2.1"
37
+ "vitest": "^3.0.9"
31
38
  },
32
39
  "publishConfig": {
33
40
  "access": "public"
package/dist/client.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import type { operations } from './types/api';
2
- export interface ClientOptions {
3
- baseUrl: string;
4
- apiKey?: string;
5
- headers?: Record<string, string>;
6
- }
7
- export declare class BodhiClient {
8
- private baseUrl;
9
- private headers;
10
- constructor(options: ClientOptions);
11
- /**
12
- * Make a request to the Bodhi API
13
- */
14
- request<T>(method: string, path: string, body?: unknown, additionalHeaders?: Record<string, string>): Promise<T>;
15
- /**
16
- * Create a chat completion
17
- */
18
- createChatCompletion(params: operations['createChatCompletion']['requestBody']['content']['application/json']): Promise<operations['createChatCompletion']['responses']['200']['content']['application/json']>;
19
- /**
20
- * List available models
21
- */
22
- listModels(): Promise<operations['listModels']['responses']['200']['content']['application/json']>;
23
- }
package/dist/client.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BodhiClient = void 0;
4
- class BodhiClient {
5
- constructor(options) {
6
- this.baseUrl = options.baseUrl.endsWith('/') ? options.baseUrl.slice(0, -1) : options.baseUrl;
7
- this.headers = {
8
- 'Content-Type': 'application/json',
9
- ...options.headers,
10
- };
11
- if (options.apiKey) {
12
- this.headers['Authorization'] = `Bearer ${options.apiKey}`;
13
- }
14
- }
15
- /**
16
- * Make a request to the Bodhi API
17
- */
18
- async request(method, path, body, additionalHeaders) {
19
- const url = `${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`;
20
- const response = await fetch(url, {
21
- method,
22
- headers: {
23
- ...this.headers,
24
- ...additionalHeaders,
25
- },
26
- body: body ? JSON.stringify(body) : undefined,
27
- });
28
- if (!response.ok) {
29
- const errorText = await response.text();
30
- throw new Error(`Request failed with status ${response.status}: ${errorText}`);
31
- }
32
- return response.json();
33
- }
34
- /**
35
- * Create a chat completion
36
- */
37
- async createChatCompletion(params) {
38
- return this.request('POST', '/v1/chat/completions', params);
39
- }
40
- /**
41
- * List available models
42
- */
43
- async listModels() {
44
- return this.request('GET', '/v1/models');
45
- }
46
- }
47
- exports.BodhiClient = BodhiClient;