chowbea-axios 1.0.3 β†’ 1.0.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/README.md CHANGED
@@ -1,244 +1,98 @@
1
- # chowbea-axios
1
+ <p align="center">
2
+ <img src="https://axios.chowbea.com/images/chowbea-axios.png" alt="chowbea-axios" width="100%" />
3
+ </p>
2
4
 
3
- CLI tool that turns an OpenAPI spec into a typed Axios client and helpers.
5
+ <h1 align="center">Chowbea-axios</h1>
4
6
 
5
- ## Full Picture (How it Works)
7
+ <p align="center">
8
+ Turn your OpenAPI spec into a fully-typed Axios client. One command.
9
+ </p>
6
10
 
7
- - `init` creates `api.config.toml`, adds scripts, and generates base client files.
8
- - `fetch` (or `watch`) retrieves your spec into `_internal/openapi.json`.
9
- - Types and operations are generated into `_generated/`.
10
- - You import `api` from `api.client.ts` and call endpoints with full typing.
11
- - Editable files (`api.instance.ts`, `api.error.ts`, `api.client.ts`, `api.helpers.ts`) are generated once and kept.
11
+ <p align="center">
12
+ <a href="https://axios.chowbea.com">
13
+ <img src="https://img.shields.io/badge/πŸ“š_Read_the_Docs-axios.chowbea.com-10b981?style=for-the-badge" alt="Documentation" />
14
+ </a>
15
+ </p>
12
16
 
13
- ## Features
17
+ <p align="center">
18
+ <a href="https://github.com/oddFEELING/chowbea-axios/stargazers"><img src="https://img.shields.io/github/stars/oddFEELING/chowbea-axios?style=flat-square&color=10b981" alt="GitHub stars" /></a>
19
+ <a href="https://www.npmjs.com/package/chowbea-axios"><img src="https://img.shields.io/npm/v/chowbea-axios?style=flat-square&color=10b981" alt="npm version" /></a>
20
+ <a href="https://www.npmjs.com/package/chowbea-axios"><img src="https://img.shields.io/npm/dm/chowbea-axios?style=flat-square&color=10b981" alt="npm downloads" /></a>
21
+ <a href="https://github.com/oddFEELING/chowbea-axios/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-10b981?style=flat-square" alt="license" /></a>
22
+ </p>
14
23
 
15
- - **Self-healing**: Auto-creates config and output directories if missing
16
- - **Retry logic**: Network operations retry 3x with exponential backoff
17
- - **Caching**: Skips regeneration when spec hasn't changed
18
- - **Atomic writes**: Generation never leaves files in a partial state
19
- - **Graceful shutdown**: Watch mode preserves cache on interruption
20
- - **Result-based errors**: API calls return `{ data, error }` instead of throwing
21
- - **Error normalization**: Extracts messages from various API response formats
22
- - **Local spec support**: Use local OpenAPI files instead of remote endpoints
23
- - **Auth headers**: Configure headers with env var interpolation for protected specs
24
+ ---
24
25
 
25
- ## Installation + Prerequisites
26
-
27
- - Node `>=18` (per `package.json`)
28
- - `init` installs `axios` into your project automatically
29
-
30
- ```bash
31
- # Global install
32
- npm install -g chowbea-axios
33
- ```
34
-
35
- Or use without installing:
26
+ ## Quick Start
36
27
 
37
28
  ```bash
38
- # One-off usage
29
+ # Initialize and configure
39
30
  npx chowbea-axios init
40
- ```
41
-
42
- ## Quick Start (First Run)
43
-
44
- ```bash
45
- # 1) Initialize in your project (creates config + base client files)
46
- chowbea-axios init
47
-
48
- # 2) Fetch spec and generate types + operations
49
- chowbea-axios fetch
50
31
 
51
- # 3) (Optional) Watch for spec changes during development
52
- chowbea-axios watch
32
+ # Fetch spec and generate client
33
+ npx chowbea-axios fetch
53
34
  ```
54
35
 
55
- Then use the client:
36
+ Then import and use:
56
37
 
57
38
  ```typescript
58
- import { api } from "./app/services/api/api.client";
39
+ import { api } from "./services/api/api.client";
59
40
 
60
- // Result-based call (never throws)
61
- const { data, error } = await api.get("/users/{id}", { id: "123" });
41
+ const { data, error } = await api.op.getUserById({ id: "123" });
62
42
 
63
- if (error) {
64
- console.error(error.message);
65
- return;
66
- }
43
+ if (error) return console.error(error.message);
67
44
 
68
- // Typed response data
69
- console.log(data.name);
45
+ console.log(data.name); // ✨ Fully typed
70
46
  ```
71
47
 
72
- ## Configuration Reference
73
-
74
- `api.config.toml` is created by `init` and is the main source of truth:
75
-
76
- ```toml
77
- api_endpoint = "http://localhost:3000/docs/swagger/json"
78
- poll_interval_ms = 10000
79
- # spec_file = "./openapi.json"
80
-
81
- [output]
82
- folder = "app/services/api"
83
-
84
- [instance]
85
- base_url_env = "VITE_API_URL"
86
- token_key = "auth-token"
87
- with_credentials = true
88
- timeout = 30000
48
+ ## Why chowbea-axios?
89
49
 
90
- [fetch]
91
- # headers = { Authorization = "Bearer $API_TOKEN" }
50
+ - **Zero manual types** β€” Generated directly from your OpenAPI spec
51
+ - **Full autocomplete** β€” Every endpoint, parameter, and response
52
+ - **Result-based errors** β€” `{ data, error }` instead of try/catch
53
+ - **Watch mode** β€” Auto-regenerate when your spec changes
92
54
 
93
- [watch]
94
- debug = false
95
- ```
96
-
97
- - `api_endpoint`: Remote OpenAPI endpoint used by `fetch` and `watch`.
98
- - `spec_file`: Optional local spec path; if set, it overrides `api_endpoint` for generation.
99
- - `poll_interval_ms`: Watch interval if `--interval` is not provided.
100
- - `[output].folder`: Where generated files go (relative to project root).
101
- - `[instance].base_url_env`: Name of the env var read at runtime in `api.instance.ts`.
102
- - `[instance].token_key`: localStorage key used by the axios instance.
103
- - `[instance].with_credentials`: Adds cookies/credentials to requests.
104
- - `[instance].timeout`: Axios request timeout (ms).
105
- - `[fetch].headers`: Extra headers for remote fetch; values can use `$ENV` or `${ENV}`.
106
- - `[watch].debug`: Enables verbose cycle logs.
107
-
108
- ## Generated Files & Editability
55
+ ## What Gets Generated
109
56
 
110
57
  ```
111
- app/services/api/
112
- β”œβ”€β”€ _internal/
113
- β”‚ β”œβ”€β”€ .api-cache.json # Cache metadata
114
- β”‚ └── openapi.json # Cached spec
58
+ services/api/
115
59
  β”œβ”€β”€ _generated/
116
- β”‚ β”œβ”€β”€ api.operations.ts # Generated operations (overwritten)
117
- β”‚ └── api.types.ts # Generated types (overwritten)
118
- β”œβ”€β”€ api.helpers.ts # Helper types (editable, generated once)
119
- β”œβ”€β”€ api.instance.ts # Axios instance (editable, generated once)
120
- β”œβ”€β”€ api.error.ts # Error types (editable, generated once)
121
- └── api.client.ts # Typed API client (editable, generated once)
122
- ```
123
-
124
- - `_internal` and `_generated` are always overwritten during generation.
125
- - The root files are generated once and safe to edit.
126
-
127
- ## Client Usage & Error Handling
128
-
129
- All client calls return `{ data, error }` instead of throwing. This keeps error handling explicit and predictable.
130
-
131
- ```typescript
132
- import { api } from "./app/services/api/api.client";
133
-
134
- // Result-based call
135
- const { data, error } = await api.post("/users", { name: "Ada" });
136
-
137
- if (error) {
138
- console.error(error.message);
139
- return;
140
- }
141
-
142
- console.log(data.id);
60
+ β”‚ β”œβ”€β”€ api.types.ts # All TypeScript types
61
+ β”‚ └── api.operations.ts # Typed operation methods
62
+ β”œβ”€β”€ api.client.ts # Your API client (editable)
63
+ β”œβ”€β”€ api.instance.ts # Axios instance (editable)
64
+ └── api.helpers.ts # Type helpers (editable)
143
65
  ```
144
66
 
145
- ## Helpers (api.helpers.ts)
146
-
147
- Use helpers to extract request/response types and schema models when you want explicit type control in app code.
148
-
149
- **Base helpers**
150
- - `Paths`: Union of all OpenAPI path strings.
151
- - `HttpMethod`: `"get" | "post" | "put" | "delete" | "patch"`.
152
- - `Expand<T>`: Expands a single level of a type for better intellisense.
153
- - `ExpandRecursively<T>`: Expands nested types for full intellisense.
154
-
155
- **Path-based helpers**
156
- - `ApiRequestBody<P, M>`: Request body type for a path + method.
157
- - `ApiResponseData<P, M, Status?>`: Response body type for a path + method.
158
- - `ApiPathParams<P>`: Path params extracted from `{param}` segments.
159
- - `ApiQueryParams<P, M>`: Query params type for a path + method.
160
- - `ApiStatusCodes<P, M>`: Available status codes for a path + method.
67
+ ## Commands
161
68
 
162
- **Operation-based helpers**
163
- - `ServerRequestBody<OpId>`: Request body by `operationId`.
164
- - `ServerRequestParams<OpId>`: Path + query params by `operationId`.
165
- - `ServerResponseType<OpId, Status?>`: Response type by `operationId`.
69
+ | Command | Description |
70
+ | ------- | ----------- |
71
+ | `init` | Interactive setup β€” creates config and base files |
72
+ | `fetch` | Fetch spec from endpoint and generate types |
73
+ | `generate` | Generate from cached/local spec |
74
+ | `watch` | Watch for spec changes and auto-regenerate |
75
+ | `status` | Show current config and cache status |
76
+ | `validate` | Validate your OpenAPI spec |
77
+ | `diff` | Compare specs and show changes |
166
78
 
167
- **Schema helpers**
168
- - `ServerModel<ModelName>`: Extract schema types from OpenAPI components.
79
+ ---
169
80
 
170
- ```typescript
171
- import type {
172
- Paths,
173
- HttpMethod,
174
- Expand,
175
- ExpandRecursively,
176
- ApiRequestBody,
177
- ApiResponseData,
178
- ApiPathParams,
179
- ApiQueryParams,
180
- ApiStatusCodes,
181
- ServerRequestBody,
182
- ServerRequestParams,
183
- ServerResponseType,
184
- ServerModel,
185
- } from "./app/services/api/api.helpers";
186
-
187
- // Path-based helpers
188
- type CreateUserInput = ApiRequestBody<"/users", "post">;
189
- type UserResponse = ApiResponseData<"/users/{id}", "get">;
190
- type UserPath = ApiPathParams<"/users/{id}">;
191
- type UserQuery = ApiQueryParams<"/users", "get">;
192
- type UserStatus = ApiStatusCodes<"/users/{id}", "get">;
193
-
194
- // Operation-based helpers (uses operationId keys)
195
- type CreateUserInputByOp = ServerRequestBody<"createUser">;
196
- type UserParamsByOp = ServerRequestParams<"getUserById">;
197
- type UserResponseByOp = ServerResponseType<"getUserById">;
198
-
199
- // Schema helpers
200
- type UserModel = ServerModel<"User">;
201
- ```
202
-
203
- ## Path-Based vs Operation-Based Approaches
204
-
205
- **Path-based** is great for quick usage when you know the endpoint path:
206
-
207
- ```typescript
208
- // Calls by path template
209
- const { data, error } = await api.get("/users/{id}", { id: "123" });
210
- ```
81
+ <p align="center">
82
+ <a href="https://axios.chowbea.com">
83
+ <strong>β†’ View full documentation</strong>
84
+ </a>
85
+ </p>
211
86
 
212
- **Operation-based** uses OpenAPI `operationId` for semantic method names:
87
+ ## ⭐ Support
213
88
 
214
- ```typescript
215
- // Calls by operationId (generated in api.operations.ts)
216
- const { data, error } = await api.op.getUserById({ id: "123" });
217
- ```
89
+ If chowbea-axios helps you ship faster, consider giving it a star! It helps others discover the project and motivates continued development.
218
90
 
219
- **When to choose which**
220
- - Path-based: fastest for exploration and when you don’t control `operationId`s.
221
- - Operation-based: cleaner call sites and more stable names when `operationId`s are consistent.
222
-
223
- ## Command Reference
224
-
225
- | Command | Purpose | Key flags |
226
- | --- | --- | --- |
227
- | `chowbea-axios init` | Interactive setup. Prompts for API endpoint, output folder, and package manager. | `--force`, `--skip-scripts`, `--skip-client`, `--skip-concurrent` |
228
- | `chowbea-axios fetch` | Fetch remote spec and generate types/operations. | `-c, --config`, `-e, --endpoint`, `-s, --spec-file`, `-f, --force`, `-n, --dry-run`, `--types-only`, `--operations-only` |
229
- | `chowbea-axios generate` | Generate types/operations from the cached spec (or a local file). | `-c, --config`, `-s, --spec-file`, `-n, --dry-run`, `--types-only`, `--operations-only` |
230
- | `chowbea-axios watch` | Watch for spec changes and regenerate on a timer. | `-c, --config`, `-i, --interval`, `-d, --debug` |
231
- | `chowbea-axios status` | Show config + cache + generated file status. | `-c, --config` |
232
- | `chowbea-axios validate` | Validate the OpenAPI spec structure. | `-c, --config`, `-s, --spec`, `--strict` |
233
- | `chowbea-axios diff` | Compare cached spec with a new spec (remote or local). | `-c, --config`, `-s, --spec` |
234
-
235
- ## Tips & Troubleshooting
236
-
237
- - Re-run `fetch` whenever your API spec changes.
238
- - Use `watch` during local dev to keep types up to date.
239
- - Delete `app/services/api/_internal` to reset cache if types seem stale.
240
- - If scripts are missing, re-run `init` (or add them manually).
241
- - If headers use `$ENV`/`${ENV}`, make sure those env vars are set.
91
+ <p align="center">
92
+ <a href="https://github.com/oddFEELING/chowbea-axios">
93
+ <img src="https://img.shields.io/badge/⭐_Star_on_GitHub-oddFEELING%2Fchowbea--axios-10b981?style=for-the-badge&logo=github" alt="Star on GitHub" />
94
+ </a>
95
+ </p>
242
96
 
243
97
  ## License
244
98
 
@@ -546,5 +546,5 @@
546
546
  ]
547
547
  }
548
548
  },
549
- "version": "1.0.3"
549
+ "version": "1.0.4"
550
550
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chowbea-axios",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Type-safe axios client that makes api requests a breeze",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -55,7 +55,7 @@
55
55
  "codegen",
56
56
  "cli"
57
57
  ],
58
- "homepage": "https://github.com/oddFEELING/chowbea-axios#readme",
58
+ "homepage": "https://axios.chowbea.com",
59
59
  "bugs": {
60
60
  "url": "https://github.com/oddFEELING/chowbea-axios/issues"
61
61
  },