@satrush/api 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,97 @@
1
+ # SatRush Api Client
2
+
3
+ ## Overview
4
+
5
+ This package provides a TypeScript SDK for the SatRush public API. The SDK is generated from OpenAPI using
6
+ `@hey-api/openapi-ts` and exposes a class-based client plus typed helpers.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pnpm add @satrush/api
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import {SatrushBackendSdk, createClient, unwrap} from "@satrush/api";
18
+
19
+ const client = createClient({
20
+ baseUrl: "https://api.satrush.io/api",
21
+ });
22
+ const sdk = new SatrushBackendSdk({client});
23
+
24
+ const board = await unwrap(
25
+ sdk.getBoard(),
26
+ );
27
+ ```
28
+
29
+ ## How the SDK works
30
+
31
+ - Generation source: `openapi.yaml` is the canonical spec.
32
+ - Pre-processing: `scripts/camelizeOpenapi.mjs` produces `openapi.camel.yaml` (converts snake_case into cameCase).
33
+ - Code generation: `@hey-api/openapi-ts` generates `src/generated/**`.
34
+ - Post-processing: `scripts/postprocessOpenapi.mjs` patches the generated client to:
35
+ - snake_case request payloads/params
36
+ - camelCase response payloads
37
+ - apply response transforms before validators where needed
38
+ - apply custom SSE transforms (see below)
39
+
40
+ ## Case transforms and scalar transforms
41
+
42
+ - Requests: payloads and query params are snake_cased in `src/transforms.ts`.
43
+ - Responses: payloads are camelCased and then transformed for BigInt/Date via generated transformers.
44
+
45
+ ## SSE streams
46
+
47
+ SSE response transforms are maintained manually in `src/sseTransforms.ts`. The upstream transformer plugin does not
48
+ handle the SSE union schema, so any changes to SSE payloads must be reflected here.
49
+
50
+ If you add or modify SSE event types in `openapi.yaml`:
51
+
52
+ 1. Update the SSE schemas and discriminator mapping.
53
+ 2. Regenerate the SDK (`pnpm openapi`).
54
+ 3. Update `src/sseTransforms.ts` to apply the correct transforms for the new event type.
55
+
56
+ ## Global error behavior
57
+
58
+ To throw on non-2xx responses for all SDK calls, set `throwOnError: true` on the client instance
59
+ and attach the built-in interceptor that wraps errors as `SatRushSdkError`:
60
+
61
+ ```ts
62
+ import {SatRushBackendSdk, createClient, satrushSdkErrorInterceptor} from "@satrush/api";
63
+
64
+ const client = createClient({
65
+ baseUrl: "https://api.satrush.io/api",
66
+ throwOnError: true,
67
+ });
68
+ client.interceptors.error.use(satrushSdkErrorInterceptor);
69
+
70
+ const sdk = new SatRushBackendSdk({client});
71
+ ```
72
+
73
+ `SatRushSdkError` includes the HTTP status and the original error payload in `cause`.
74
+
75
+ If you already have a client, you can also enable it later:
76
+
77
+ ```ts
78
+ import {client, satrushSdkErrorInterceptor} from "@satrush/api";
79
+
80
+ client.setConfig({throwOnError: true});
81
+ client.interceptors.error.use(satrushSdkErrorInterceptor);
82
+ ```
83
+
84
+ When `responseStyle` is set to `"data"`, SDK calls return only the response payload
85
+ (no `{ data, error, request, response }` wrapper). This is useful for simpler call sites:
86
+
87
+ ```ts
88
+ import {SatRushBackendSdk, createClient} from "@satrush/api";
89
+
90
+ const client = createClient({
91
+ baseUrl: "https://api.satrush.io/api",
92
+ responseStyle: "data",
93
+ });
94
+
95
+ const sdk = new SatrushBackendSdk({client});
96
+ const board = await sdk.getBoard();
97
+ ```