proseva-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,57 @@
1
+ # ProSeVA SDK
2
+
3
+ Type-safe TypeScript client generated from `server/openapi.json` for interacting with the ProSeVA API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ # From repository root after building
9
+ bun install # ensure workspace deps
10
+ cd proseva-sdk
11
+ bun install # installs sdk-specific dev deps
12
+ bun pack # optional: create tarball for local install
13
+ ```
14
+
15
+ To consume locally without publishing:
16
+
17
+ ```bash
18
+ # from another project
19
+ npm install /path/to/pro-se-va-copy/proseva-sdk
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```ts
25
+ import { createProsevaClientWithToken } from "proseva-sdk";
26
+
27
+ const api = createProsevaClientWithToken("<jwt>", {
28
+ baseUrl: "https://proseva.example.com/api",
29
+ });
30
+
31
+ const { data } = await api.GET("/cases");
32
+ ```
33
+
34
+ ### Auth tokens
35
+ Pass `getAuthToken` (sync or async) to attach `Authorization: Bearer <token>` automatically:
36
+
37
+ ```ts
38
+ import { createProsevaClient } from "proseva-sdk";
39
+
40
+ const api = createProsevaClient({
41
+ getAuthToken: async () => process.env.PROSEVA_TOKEN ?? null,
42
+ });
43
+ ```
44
+
45
+ ## Regenerate types
46
+
47
+ ```bash
48
+ cd proseva-sdk
49
+ bun x openapi-typescript ../server/openapi.json --output src/types.ts
50
+ bun x tsc -p tsconfig.json
51
+ ```
52
+
53
+ ## Exports
54
+
55
+ - `createProsevaClient`
56
+ - `createProsevaClientWithToken`
57
+ - OpenAPI types: `paths`, `components`, `operations`
@@ -0,0 +1,33 @@
1
+ import type { Client } from "openapi-fetch";
2
+ import type { paths } from "./types.js";
3
+ export type { paths, components, operations } from "./types.js";
4
+ /**
5
+ * Configuration for the generated ProSeVA API client.
6
+ */
7
+ export interface ProsevaClientOptions {
8
+ /**
9
+ * Base URL used for all requests. Defaults to `"/api"` which matches the app server.
10
+ * Provide an absolute URL when consuming the SDK from another host.
11
+ */
12
+ baseUrl?: string;
13
+ /**
14
+ * Token (string), sync function, or async function that returns a bearer token.
15
+ * If provided, the client injects it into the `Authorization` header on every request.
16
+ */
17
+ getAuthToken?: (() => Promise<string | null>) | (() => string | null) | string | null;
18
+ /**
19
+ * Optional custom fetch implementation (e.g. `undici` or `node-fetch`) for non-browser environments.
20
+ * Defaults to `globalThis.fetch`.
21
+ */
22
+ fetch?: typeof fetch;
23
+ }
24
+ /** Typed OpenAPI client instance for the ProSeVA API. */
25
+ export type ProsevaClient = Client<paths>;
26
+ /**
27
+ * Create a typed ProSeVA API client. Pass `getAuthToken` to auto-attach a bearer token.
28
+ */
29
+ export declare function createProsevaClient(options?: ProsevaClientOptions): ProsevaClient;
30
+ /**
31
+ * Convenience wrapper that builds a client with a fixed bearer token.
32
+ */
33
+ export declare function createProsevaClientWithToken(token: string, options?: Omit<ProsevaClientOptions, "getAuthToken">): ProsevaClient;
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ import createClient from "openapi-fetch";
2
+ /**
3
+ * Create a typed ProSeVA API client. Pass `getAuthToken` to auto-attach a bearer token.
4
+ */
5
+ export function createProsevaClient(options = {}) {
6
+ const client = createClient({
7
+ baseUrl: options.baseUrl ?? "/api",
8
+ fetch: options.fetch ?? globalThis.fetch,
9
+ });
10
+ const getAuth = options.getAuthToken;
11
+ if (getAuth) {
12
+ client.use({
13
+ async onRequest({ request }) {
14
+ const token = typeof getAuth === "function" ? await getAuth() : (getAuth ?? null);
15
+ if (token) {
16
+ request.headers.set("Authorization", `Bearer ${token}`);
17
+ }
18
+ return request;
19
+ },
20
+ });
21
+ }
22
+ return client;
23
+ }
24
+ /**
25
+ * Convenience wrapper that builds a client with a fixed bearer token.
26
+ */
27
+ export function createProsevaClientWithToken(token, options = {}) {
28
+ return createProsevaClient({ ...options, getAuthToken: () => token });
29
+ }