@anyformat/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,55 @@
1
+ # @anyformat/sdk
2
+
3
+ TypeScript SDK for the AnyFormat API. Mirrors the Python SDK's fluent flow.
4
+
5
+ ```ts
6
+ import { Anyformat, Schema } from "@anyformat/sdk";
7
+
8
+ const af = new Anyformat({ apiKey: process.env.ANYFORMAT_API_KEY! });
9
+
10
+ const result = await af
11
+ .workflow("Invoice")
12
+ .parse()
13
+ .extract([
14
+ Schema.string("vendor", "Vendor name on the invoice."),
15
+ Schema.float("total", "Grand total amount."),
16
+ Schema.enum("currency", "Currency of the totals.", [
17
+ Schema.option("USD", "US Dollar."),
18
+ Schema.option("EUR", "Euro."),
19
+ ]),
20
+ ])
21
+ .run(file)
22
+ .wait();
23
+
24
+ result.field("vendor")?.value; // -> "Acme Corp"
25
+ ```
26
+
27
+ ## How it's built
28
+
29
+ The wire types and the low-level HTTP client are **generated** from the API's
30
+ OpenAPI spec with [Hey API](https://heyapi.dev) — they are not hand-written and
31
+ must not be edited. Everything in `src/sdk/` is generated; the hand-written
32
+ ergonomic layer (`Schema`, `WorkflowBuilder`, `Result`, `Anyformat`) wraps it.
33
+
34
+ ## Regenerating (and the drift guard)
35
+
36
+ ```bash
37
+ npm run gen # dump the v2 OpenAPI offline + regenerate src/sdk
38
+ npm run gen:check # regenerate and fail if the committed output drifted
39
+ ```
40
+
41
+ `gen:check` runs in CI and as a pre-commit hook (scoped to changes under
42
+ `anyformat/services/api` and `anyformat/workflow`) so the committed SDK can
43
+ never fall behind the backend. The SDK's own `tsc` then fails to compile if a
44
+ backend model change alters a type the hand-written layer relies on — drift is
45
+ caught as a type error, not just a diff.
46
+
47
+ ## Scripts
48
+
49
+ | script | what |
50
+ | --- | --- |
51
+ | `npm run gen` | dump spec + regenerate `src/sdk` |
52
+ | `npm run gen:check` | regenerate + assert no drift |
53
+ | `npm run build` | bundle to `dist/` (ESM + CJS + types) via tsup |
54
+ | `npm run typecheck` | `tsc --noEmit` |
55
+ | `npm test` | vitest |