@cushin/api-runtime 2.0.1
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/LICENSE +0 -0
- package/README.md +95 -0
- package/dist/chunk-GL2GG37G.js +17 -0
- package/dist/chunk-GL2GG37G.js.map +1 -0
- package/dist/chunk-RJFROHWK.js +263 -0
- package/dist/chunk-RJFROHWK.js.map +1 -0
- package/dist/client.d.ts +40 -0
- package/dist/client.js +13 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +43 -0
- package/dist/schema.js +11 -0
- package/dist/schema.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @cushin/api-runtime
|
|
2
|
+
|
|
3
|
+
Runtime utilities for Cushin API codegen - provides type-safe HTTP client and schema helpers that can be used in both browser and Node.js environments.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🌐 **Browser-compatible** - No Node.js dependencies, works in any JavaScript environment
|
|
8
|
+
- 🔐 **Built-in auth** - Token management with automatic refresh
|
|
9
|
+
- 📝 **Type-safe** - Full TypeScript support with Zod schema validation
|
|
10
|
+
- 🎯 **Lightweight** - Minimal bundle size, only depends on `ky` and `zod`
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @cushin/api-runtime ky zod
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Define your API configuration
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { defineConfig, defineEndpoint } from "@cushin/api-runtime";
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
|
|
26
|
+
export const apiConfig = defineConfig({
|
|
27
|
+
baseUrl: "https://api.example.com",
|
|
28
|
+
endpoints: {
|
|
29
|
+
getUser: defineEndpoint({
|
|
30
|
+
path: "/users/:id",
|
|
31
|
+
method: "GET",
|
|
32
|
+
params: z.object({ id: z.string() }),
|
|
33
|
+
response: z.object({
|
|
34
|
+
id: z.string(),
|
|
35
|
+
name: z.string(),
|
|
36
|
+
email: z.string(),
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Create API client
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { createAPIClient } from "@cushin/api-runtime";
|
|
47
|
+
import { apiConfig } from "./api-config";
|
|
48
|
+
|
|
49
|
+
const client = createAPIClient(apiConfig, {
|
|
50
|
+
getTokens: async () => ({
|
|
51
|
+
accessToken: localStorage.getItem("token") || "",
|
|
52
|
+
}),
|
|
53
|
+
onAuthError: () => {
|
|
54
|
+
// Redirect to login
|
|
55
|
+
},
|
|
56
|
+
onRefreshToken: async () => {
|
|
57
|
+
// Refresh your token
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Use the client
|
|
62
|
+
const user = await client.getUser({ id: "123" });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Key Components
|
|
66
|
+
|
|
67
|
+
### `createAPIClient(config, authCallbacks?)`
|
|
68
|
+
|
|
69
|
+
Creates a type-safe API client with automatic token injection and refresh.
|
|
70
|
+
|
|
71
|
+
### `defineConfig(config)`
|
|
72
|
+
|
|
73
|
+
Helper function to define your API configuration with type inference.
|
|
74
|
+
|
|
75
|
+
### `defineEndpoint(config)`
|
|
76
|
+
|
|
77
|
+
Helper function to define individual endpoints with full type safety.
|
|
78
|
+
|
|
79
|
+
## Why separate from @cushin/api-codegen?
|
|
80
|
+
|
|
81
|
+
The runtime code needs to be imported by your web application, while the code generation tools (`@cushin/api-codegen`) contain Node.js-specific code (file system, path manipulation, etc.) that cannot be bundled for the browser.
|
|
82
|
+
|
|
83
|
+
By separating the runtime into its own package:
|
|
84
|
+
- ✅ Your web app can import runtime code without bundling Node.js dependencies
|
|
85
|
+
- ✅ Smaller bundle size for your application
|
|
86
|
+
- ✅ Clear separation of concerns
|
|
87
|
+
|
|
88
|
+
## Related Packages
|
|
89
|
+
|
|
90
|
+
- **[@cushin/api-codegen](../api-codegen)** - CLI tool to generate type-safe API clients
|
|
91
|
+
- **[@cushin/codegen-cli](../cli)** - Shared CLI utilities
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/schema.ts
|
|
2
|
+
function defineConfig(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
function defineEndpoint(config) {
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
function defineEndpoints(endpoints) {
|
|
9
|
+
return endpoints;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
defineConfig,
|
|
14
|
+
defineEndpoint,
|
|
15
|
+
defineEndpoints
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=chunk-GL2GG37G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema.ts"],"sourcesContent":["import type { z } from \"zod\";\n\nexport type HTTPMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\nexport interface APIEndpoint {\n path: string;\n method: HTTPMethod;\n baseUrl?: string;\n params?: z.ZodType<any>;\n query?: z.ZodType<any>;\n body?: z.ZodType<any>;\n response: z.ZodType<any>;\n tags?: string[];\n description?: string;\n}\n\nexport interface APIConfig {\n baseUrl?: string;\n endpoints: Record<string, APIEndpoint>;\n}\n\nexport type EndpointConfig<\n TPath extends string = string,\n TMethod extends HTTPMethod = HTTPMethod,\n TParams = undefined,\n TQuery = undefined,\n TBody = undefined,\n TResponse = any,\n> = {\n path: TPath;\n method: TMethod;\n baseUrl?: string;\n params?: z.ZodType<TParams>;\n query?: z.ZodType<TQuery>;\n body?: z.ZodType<TBody>;\n response: z.ZodType<TResponse>;\n tags?: string[];\n description?: string;\n};\n\n/**\n * Helper function to define API configuration with type safety\n */\nexport function defineConfig<T extends APIConfig>(config: T): T {\n return config;\n}\n\n/**\n * Helper function to define a single endpoint with type inference\n */\nexport function defineEndpoint<\n TPath extends string,\n TMethod extends HTTPMethod,\n TParams = undefined,\n TQuery = undefined,\n TBody = undefined,\n TResponse = any,\n>(\n config: EndpointConfig<TPath, TMethod, TParams, TQuery, TBody, TResponse>,\n): EndpointConfig<TPath, TMethod, TParams, TQuery, TBody, TResponse> {\n return config;\n}\n\n/**\n * Helper to define multiple endpoints\n */\nexport function defineEndpoints<T extends Record<string, APIEndpoint>>(\n endpoints: T,\n): T {\n return endpoints;\n}\n"],"mappings":";AA2CO,SAAS,aAAkC,QAAc;AAC9D,SAAO;AACT;AAKO,SAAS,eAQd,QACmE;AACnE,SAAO;AACT;AAKO,SAAS,gBACd,WACG;AACH,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import ky, { HTTPError } from "ky";
|
|
3
|
+
var APIError = class extends Error {
|
|
4
|
+
constructor(message, status, response) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.response = response;
|
|
8
|
+
this.name = "APIError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var AuthError = class extends APIError {
|
|
12
|
+
constructor(message = "Authentication failed") {
|
|
13
|
+
super(message, 401);
|
|
14
|
+
this.name = "AuthError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var APIClient = class {
|
|
18
|
+
constructor(config, authCallbacks) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.authCallbacks = authCallbacks;
|
|
21
|
+
this.hooks = {
|
|
22
|
+
beforeRequest: [
|
|
23
|
+
async (request) => {
|
|
24
|
+
const tokens = await this.authCallbacks?.getTokens();
|
|
25
|
+
if (tokens?.accessToken) {
|
|
26
|
+
request.headers.set(
|
|
27
|
+
"Authorization",
|
|
28
|
+
`Bearer ${tokens.accessToken}`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
beforeRetry: [
|
|
34
|
+
async ({ request, error, retryCount }) => {
|
|
35
|
+
if (error instanceof HTTPError && error.response.status === 401) {
|
|
36
|
+
if (retryCount === 1 && this.authCallbacks) {
|
|
37
|
+
try {
|
|
38
|
+
await this.refreshTokens();
|
|
39
|
+
const tokens = await this.authCallbacks.getTokens();
|
|
40
|
+
if (tokens?.accessToken) {
|
|
41
|
+
request.headers.set(
|
|
42
|
+
"Authorization",
|
|
43
|
+
`Bearer ${tokens.accessToken}`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
} catch (refreshError) {
|
|
47
|
+
this.authCallbacks.onAuthError?.();
|
|
48
|
+
throw new AuthError();
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
this.authCallbacks?.onAuthError?.();
|
|
52
|
+
throw new AuthError();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
beforeError: [
|
|
58
|
+
async (error) => {
|
|
59
|
+
const { response } = error;
|
|
60
|
+
if (response?.body) {
|
|
61
|
+
try {
|
|
62
|
+
const body = await response.json();
|
|
63
|
+
error.message = body.message || `HTTP ${response.status}`;
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return error;
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
this.client = ky.create({
|
|
72
|
+
prefixUrl: this.config.baseUrl,
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Type": "application/json"
|
|
75
|
+
},
|
|
76
|
+
retry: {
|
|
77
|
+
limit: 2,
|
|
78
|
+
methods: ["get", "post", "put", "delete", "patch"],
|
|
79
|
+
statusCodes: [401]
|
|
80
|
+
},
|
|
81
|
+
hooks: this.hooks
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
client;
|
|
85
|
+
isRefreshing = false;
|
|
86
|
+
refreshPromise = null;
|
|
87
|
+
hooks;
|
|
88
|
+
async refreshTokens() {
|
|
89
|
+
if (!this.authCallbacks) {
|
|
90
|
+
throw new AuthError("No auth callbacks provided");
|
|
91
|
+
}
|
|
92
|
+
if (this.isRefreshing && this.refreshPromise) {
|
|
93
|
+
return this.refreshPromise;
|
|
94
|
+
}
|
|
95
|
+
this.isRefreshing = true;
|
|
96
|
+
this.refreshPromise = (async () => {
|
|
97
|
+
try {
|
|
98
|
+
if (this.authCallbacks?.onRefreshToken) {
|
|
99
|
+
await this.authCallbacks.onRefreshToken();
|
|
100
|
+
} else {
|
|
101
|
+
throw new AuthError("No refresh token handler provided");
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw error;
|
|
105
|
+
} finally {
|
|
106
|
+
this.isRefreshing = false;
|
|
107
|
+
this.refreshPromise = null;
|
|
108
|
+
}
|
|
109
|
+
})();
|
|
110
|
+
return this.refreshPromise;
|
|
111
|
+
}
|
|
112
|
+
buildPath(path, params) {
|
|
113
|
+
if (!params) return path;
|
|
114
|
+
let finalPath = path;
|
|
115
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
116
|
+
finalPath = finalPath.replace(
|
|
117
|
+
`:${key}`,
|
|
118
|
+
encodeURIComponent(String(value))
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
return finalPath;
|
|
122
|
+
}
|
|
123
|
+
getEndpointBaseUrl(endpoint) {
|
|
124
|
+
return endpoint.baseUrl || this.config.baseUrl;
|
|
125
|
+
}
|
|
126
|
+
getClientForEndpoint(endpoint) {
|
|
127
|
+
const endpointBaseUrl = this.getEndpointBaseUrl(endpoint);
|
|
128
|
+
if (endpointBaseUrl === this.config.baseUrl) {
|
|
129
|
+
return this.client;
|
|
130
|
+
}
|
|
131
|
+
return ky.create({
|
|
132
|
+
prefixUrl: endpointBaseUrl,
|
|
133
|
+
headers: {
|
|
134
|
+
"Content-Type": "application/json"
|
|
135
|
+
},
|
|
136
|
+
retry: {
|
|
137
|
+
limit: 2,
|
|
138
|
+
methods: ["get", "post", "put", "delete", "patch"],
|
|
139
|
+
statusCodes: [401]
|
|
140
|
+
},
|
|
141
|
+
hooks: this.hooks
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async request(endpoint, params, query, body) {
|
|
145
|
+
try {
|
|
146
|
+
const path = this.buildPath(endpoint.path, params);
|
|
147
|
+
const client = this.getClientForEndpoint(endpoint);
|
|
148
|
+
const options = {
|
|
149
|
+
method: endpoint.method
|
|
150
|
+
};
|
|
151
|
+
if (query && Object.keys(query).length > 0) {
|
|
152
|
+
const searchParams = new URLSearchParams();
|
|
153
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
154
|
+
if (value !== void 0 && value !== null) {
|
|
155
|
+
searchParams.append(key, String(value));
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
if (searchParams.toString()) {
|
|
159
|
+
options.searchParams = searchParams;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (body && endpoint.method !== "GET") {
|
|
163
|
+
if (endpoint.body) {
|
|
164
|
+
const validatedBody = endpoint.body.parse(body);
|
|
165
|
+
options.json = validatedBody;
|
|
166
|
+
} else {
|
|
167
|
+
options.json = body;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const response = await client(path, options);
|
|
171
|
+
const data = await response.json();
|
|
172
|
+
if (endpoint.response) {
|
|
173
|
+
return endpoint.response.parse(data);
|
|
174
|
+
}
|
|
175
|
+
return data;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (error instanceof HTTPError) {
|
|
178
|
+
const errorData = await error.response.json().catch(() => ({}));
|
|
179
|
+
throw new APIError(
|
|
180
|
+
errorData.message || error.message,
|
|
181
|
+
error.response.status,
|
|
182
|
+
errorData
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (error instanceof AuthError) {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
throw new APIError(
|
|
189
|
+
error instanceof Error ? error.message : "Network error",
|
|
190
|
+
0
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
updateAuthCallbacks(authCallbacks) {
|
|
195
|
+
this.authCallbacks = authCallbacks;
|
|
196
|
+
}
|
|
197
|
+
async refreshAuth() {
|
|
198
|
+
if (!this.authCallbacks) {
|
|
199
|
+
throw new AuthError("No auth callbacks provided");
|
|
200
|
+
}
|
|
201
|
+
await this.refreshTokens();
|
|
202
|
+
}
|
|
203
|
+
generateMethods() {
|
|
204
|
+
const methods = {};
|
|
205
|
+
Object.entries(this.config.endpoints).forEach(([name, endpoint]) => {
|
|
206
|
+
if (endpoint.method === "GET") {
|
|
207
|
+
if (endpoint.params && endpoint.query) {
|
|
208
|
+
methods[name] = (params, query) => {
|
|
209
|
+
return this.request(endpoint, params, query);
|
|
210
|
+
};
|
|
211
|
+
} else if (endpoint.params) {
|
|
212
|
+
methods[name] = (params) => {
|
|
213
|
+
return this.request(endpoint, params);
|
|
214
|
+
};
|
|
215
|
+
} else if (endpoint.query) {
|
|
216
|
+
methods[name] = (query) => {
|
|
217
|
+
return this.request(endpoint, void 0, query);
|
|
218
|
+
};
|
|
219
|
+
} else {
|
|
220
|
+
methods[name] = () => {
|
|
221
|
+
return this.request(endpoint);
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
if (endpoint.params && endpoint.body) {
|
|
226
|
+
methods[name] = (params, body) => {
|
|
227
|
+
return this.request(endpoint, params, void 0, body);
|
|
228
|
+
};
|
|
229
|
+
} else if (endpoint.params) {
|
|
230
|
+
methods[name] = (params) => {
|
|
231
|
+
return this.request(endpoint, params);
|
|
232
|
+
};
|
|
233
|
+
} else if (endpoint.body) {
|
|
234
|
+
methods[name] = (body) => {
|
|
235
|
+
return this.request(endpoint, void 0, void 0, body);
|
|
236
|
+
};
|
|
237
|
+
} else {
|
|
238
|
+
methods[name] = () => {
|
|
239
|
+
return this.request(endpoint);
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return methods;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
function createAPIClient(config, authCallbacks) {
|
|
248
|
+
const instance = new APIClient(config, authCallbacks);
|
|
249
|
+
const methods = instance.generateMethods();
|
|
250
|
+
return {
|
|
251
|
+
...methods,
|
|
252
|
+
refreshAuth: () => instance.refreshAuth(),
|
|
253
|
+
updateAuthCallbacks: (newCallbacks) => instance.updateAuthCallbacks(newCallbacks)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export {
|
|
258
|
+
APIError,
|
|
259
|
+
AuthError,
|
|
260
|
+
APIClient,
|
|
261
|
+
createAPIClient
|
|
262
|
+
};
|
|
263
|
+
//# sourceMappingURL=chunk-RJFROHWK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import ky, { HTTPError } from \"ky\";\nimport type { APIConfig, APIEndpoint } from \"./schema.js\";\n\nexport interface AuthTokens {\n accessToken: string;\n refreshToken?: string;\n}\n\nexport interface AuthCallbacks {\n getTokens: () => Promise<AuthTokens | null>;\n onAuthError?: () => void;\n onRefreshToken?: () => Promise<void>;\n}\n\nexport class APIError extends Error {\n constructor(\n message: string,\n public status: number,\n public response?: any,\n ) {\n super(message);\n this.name = \"APIError\";\n }\n}\n\nexport class AuthError extends APIError {\n constructor(message: string = \"Authentication failed\") {\n super(message, 401);\n this.name = \"AuthError\";\n }\n}\n\nexport class APIClient {\n private client: typeof ky;\n private isRefreshing = false;\n private refreshPromise: Promise<void> | null = null;\n private hooks: any;\n\n constructor(\n private config: APIConfig,\n private authCallbacks?: AuthCallbacks,\n ) {\n this.hooks = {\n beforeRequest: [\n async (request: Request) => {\n const tokens = await this.authCallbacks?.getTokens();\n if (tokens?.accessToken) {\n request.headers.set(\n \"Authorization\",\n `Bearer ${tokens.accessToken}`,\n );\n }\n },\n ],\n beforeRetry: [\n async ({ request, error, retryCount }: any) => {\n if (error instanceof HTTPError && error.response.status === 401) {\n if (retryCount === 1 && this.authCallbacks) {\n try {\n await this.refreshTokens();\n const tokens = await this.authCallbacks.getTokens();\n if (tokens?.accessToken) {\n request.headers.set(\n \"Authorization\",\n `Bearer ${tokens.accessToken}`,\n );\n }\n } catch (refreshError) {\n this.authCallbacks.onAuthError?.();\n throw new AuthError();\n }\n } else {\n this.authCallbacks?.onAuthError?.();\n throw new AuthError();\n }\n }\n },\n ],\n beforeError: [\n async (error: any) => {\n const { response } = error;\n if (response?.body) {\n try {\n const body = await response.json();\n error.message =\n (body as Error).message || `HTTP ${response.status}`;\n } catch {\n // Keep original message\n }\n }\n return error;\n },\n ],\n };\n\n this.client = ky.create({\n prefixUrl: this.config.baseUrl,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n retry: {\n limit: 2,\n methods: [\"get\", \"post\", \"put\", \"delete\", \"patch\"],\n statusCodes: [401],\n },\n hooks: this.hooks,\n });\n }\n\n private async refreshTokens(): Promise<void> {\n if (!this.authCallbacks) {\n throw new AuthError(\"No auth callbacks provided\");\n }\n\n if (this.isRefreshing && this.refreshPromise) {\n return this.refreshPromise;\n }\n\n this.isRefreshing = true;\n\n this.refreshPromise = (async () => {\n try {\n if (this.authCallbacks?.onRefreshToken) {\n await this.authCallbacks.onRefreshToken();\n } else {\n throw new AuthError(\"No refresh token handler provided\");\n }\n } catch (error) {\n throw error;\n } finally {\n this.isRefreshing = false;\n this.refreshPromise = null;\n }\n })();\n\n return this.refreshPromise;\n }\n\n private buildPath(path: string, params?: Record<string, any>): string {\n if (!params) return path;\n\n let finalPath = path;\n Object.entries(params).forEach(([key, value]) => {\n finalPath = finalPath.replace(\n `:${key}`,\n encodeURIComponent(String(value)),\n );\n });\n\n return finalPath;\n }\n\n private getEndpointBaseUrl(endpoint: APIEndpoint): string {\n return endpoint.baseUrl || this.config.baseUrl!;\n }\n\n private getClientForEndpoint(endpoint: APIEndpoint): typeof ky {\n const endpointBaseUrl = this.getEndpointBaseUrl(endpoint);\n\n if (endpointBaseUrl === this.config.baseUrl) {\n return this.client;\n }\n\n return ky.create({\n prefixUrl: endpointBaseUrl,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n retry: {\n limit: 2,\n methods: [\"get\", \"post\", \"put\", \"delete\", \"patch\"],\n statusCodes: [401],\n },\n hooks: this.hooks,\n });\n }\n\n async request<T>(\n endpoint: APIEndpoint,\n params?: Record<string, any>,\n query?: Record<string, any>,\n body?: any,\n ): Promise<T> {\n try {\n const path = this.buildPath(endpoint.path, params);\n const client = this.getClientForEndpoint(endpoint);\n\n const options: Record<string, any> = {\n method: endpoint.method,\n };\n\n if (query && Object.keys(query).length > 0) {\n const searchParams = new URLSearchParams();\n Object.entries(query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n searchParams.append(key, String(value));\n }\n });\n if (searchParams.toString()) {\n options.searchParams = searchParams;\n }\n }\n\n if (body && endpoint.method !== \"GET\") {\n if (endpoint.body) {\n const validatedBody = endpoint.body.parse(body);\n options.json = validatedBody;\n } else {\n options.json = body;\n }\n }\n\n const response = await client(path, options);\n const data = await response.json();\n\n if (endpoint.response) {\n return endpoint.response.parse(data);\n }\n\n return data as T;\n } catch (error) {\n if (error instanceof HTTPError) {\n const errorData = await error.response.json().catch(() => ({}));\n throw new APIError(\n errorData.message || error.message,\n error.response.status,\n errorData,\n );\n }\n\n if (error instanceof AuthError) {\n throw error;\n }\n\n throw new APIError(\n error instanceof Error ? error.message : \"Network error\",\n 0,\n );\n }\n }\n\n updateAuthCallbacks(authCallbacks: AuthCallbacks) {\n this.authCallbacks = authCallbacks;\n }\n\n async refreshAuth(): Promise<void> {\n if (!this.authCallbacks) {\n throw new AuthError(\"No auth callbacks provided\");\n }\n await this.refreshTokens();\n }\n\n generateMethods() {\n const methods: any = {};\n\n Object.entries(this.config.endpoints).forEach(([name, endpoint]) => {\n if (endpoint.method === \"GET\") {\n if (endpoint.params && endpoint.query) {\n methods[name] = (params: any, query?: any): Promise<any> => {\n return this.request(endpoint, params, query);\n };\n } else if (endpoint.params) {\n methods[name] = (params: any): Promise<any> => {\n return this.request(endpoint, params);\n };\n } else if (endpoint.query) {\n methods[name] = (query?: any): Promise<any> => {\n return this.request(endpoint, undefined, query);\n };\n } else {\n methods[name] = (): Promise<any> => {\n return this.request(endpoint);\n };\n }\n } else {\n if (endpoint.params && endpoint.body) {\n methods[name] = (params: any, body: any): Promise<any> => {\n return this.request(endpoint, params, undefined, body);\n };\n } else if (endpoint.params) {\n methods[name] = (params: any): Promise<any> => {\n return this.request(endpoint, params);\n };\n } else if (endpoint.body) {\n methods[name] = (body: any): Promise<any> => {\n return this.request(endpoint, undefined, undefined, body);\n };\n } else {\n methods[name] = (): Promise<any> => {\n return this.request(endpoint);\n };\n }\n }\n });\n\n return methods;\n }\n}\n\nexport function createAPIClient(\n config: APIConfig,\n authCallbacks?: AuthCallbacks,\n) {\n const instance = new APIClient(config, authCallbacks);\n const methods = instance.generateMethods();\n\n return {\n ...methods,\n refreshAuth: () => instance.refreshAuth(),\n updateAuthCallbacks: (newCallbacks: AuthCallbacks) =>\n instance.updateAuthCallbacks(newCallbacks),\n };\n}\n"],"mappings":";AAAA,OAAO,MAAM,iBAAiB;AAcvB,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YACE,SACO,QACA,UACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,YAAN,cAAwB,SAAS;AAAA,EACtC,YAAY,UAAkB,yBAAyB;AACrD,UAAM,SAAS,GAAG;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,YAAN,MAAgB;AAAA,EAMrB,YACU,QACA,eACR;AAFQ;AACA;AAER,SAAK,QAAQ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QAAQ,QAAW,IAAI;AAAA,UACvD;AAAA,QACF,WAAW,SAAS,QAAQ;AAC1B,kBAAQ,IAAI,IAAI,CAAC,WAA8B;AAC7C,mBAAO,KAAK,QAAQ,UAAU,MAAM;AAAA,UACtC;AAAA,QACF,WAAW,SAAS,MAAM;AACxB,kBAAQ,IAAI,IAAI,CAAC,SAA4B;AAC3C,mBAAO,KAAK,QAAQ,UAAU,QAAW,QAAW,IAAI;AAAA,UAC1D;AAAA,QACF,OAAO;AACL,kBAAQ,IAAI,IAAI,MAAoB;AAClC,mBAAO,KAAK,QAAQ,QAAQ;AAAA,UAC9B;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAEO,SAAS,gBACd,QACA,eACA;AACA,QAAM,WAAW,IAAI,UAAU,QAAQ,aAAa;AACpD,QAAM,UAAU,SAAS,gBAAgB;AAEzC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,aAAa,MAAM,SAAS,YAAY;AAAA,IACxC,qBAAqB,CAAC,iBACpB,SAAS,oBAAoB,YAAY;AAAA,EAC7C;AACF;","names":[]}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { APIConfig, APIEndpoint } from './schema.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
interface AuthTokens {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
refreshToken?: string;
|
|
7
|
+
}
|
|
8
|
+
interface AuthCallbacks {
|
|
9
|
+
getTokens: () => Promise<AuthTokens | null>;
|
|
10
|
+
onAuthError?: () => void;
|
|
11
|
+
onRefreshToken?: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
declare class APIError extends Error {
|
|
14
|
+
status: number;
|
|
15
|
+
response?: any | undefined;
|
|
16
|
+
constructor(message: string, status: number, response?: any | undefined);
|
|
17
|
+
}
|
|
18
|
+
declare class AuthError extends APIError {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
declare class APIClient {
|
|
22
|
+
private config;
|
|
23
|
+
private authCallbacks?;
|
|
24
|
+
private client;
|
|
25
|
+
private isRefreshing;
|
|
26
|
+
private refreshPromise;
|
|
27
|
+
private hooks;
|
|
28
|
+
constructor(config: APIConfig, authCallbacks?: AuthCallbacks | undefined);
|
|
29
|
+
private refreshTokens;
|
|
30
|
+
private buildPath;
|
|
31
|
+
private getEndpointBaseUrl;
|
|
32
|
+
private getClientForEndpoint;
|
|
33
|
+
request<T>(endpoint: APIEndpoint, params?: Record<string, any>, query?: Record<string, any>, body?: any): Promise<T>;
|
|
34
|
+
updateAuthCallbacks(authCallbacks: AuthCallbacks): void;
|
|
35
|
+
refreshAuth(): Promise<void>;
|
|
36
|
+
generateMethods(): any;
|
|
37
|
+
}
|
|
38
|
+
declare function createAPIClient(config: APIConfig, authCallbacks?: AuthCallbacks): any;
|
|
39
|
+
|
|
40
|
+
export { APIClient, APIError, type AuthCallbacks, AuthError, type AuthTokens, createAPIClient };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
APIClient,
|
|
3
|
+
APIError,
|
|
4
|
+
AuthError,
|
|
5
|
+
createAPIClient
|
|
6
|
+
} from "./chunk-RJFROHWK.js";
|
|
7
|
+
import {
|
|
8
|
+
defineConfig,
|
|
9
|
+
defineEndpoint,
|
|
10
|
+
defineEndpoints
|
|
11
|
+
} from "./chunk-GL2GG37G.js";
|
|
12
|
+
export {
|
|
13
|
+
APIClient,
|
|
14
|
+
APIError,
|
|
15
|
+
AuthError,
|
|
16
|
+
createAPIClient,
|
|
17
|
+
defineConfig,
|
|
18
|
+
defineEndpoint,
|
|
19
|
+
defineEndpoints
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type HTTPMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
4
|
+
interface APIEndpoint {
|
|
5
|
+
path: string;
|
|
6
|
+
method: HTTPMethod;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
params?: z.ZodType<any>;
|
|
9
|
+
query?: z.ZodType<any>;
|
|
10
|
+
body?: z.ZodType<any>;
|
|
11
|
+
response: z.ZodType<any>;
|
|
12
|
+
tags?: string[];
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
15
|
+
interface APIConfig {
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
endpoints: Record<string, APIEndpoint>;
|
|
18
|
+
}
|
|
19
|
+
type EndpointConfig<TPath extends string = string, TMethod extends HTTPMethod = HTTPMethod, TParams = undefined, TQuery = undefined, TBody = undefined, TResponse = any> = {
|
|
20
|
+
path: TPath;
|
|
21
|
+
method: TMethod;
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
params?: z.ZodType<TParams>;
|
|
24
|
+
query?: z.ZodType<TQuery>;
|
|
25
|
+
body?: z.ZodType<TBody>;
|
|
26
|
+
response: z.ZodType<TResponse>;
|
|
27
|
+
tags?: string[];
|
|
28
|
+
description?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Helper function to define API configuration with type safety
|
|
32
|
+
*/
|
|
33
|
+
declare function defineConfig<T extends APIConfig>(config: T): T;
|
|
34
|
+
/**
|
|
35
|
+
* Helper function to define a single endpoint with type inference
|
|
36
|
+
*/
|
|
37
|
+
declare function defineEndpoint<TPath extends string, TMethod extends HTTPMethod, TParams = undefined, TQuery = undefined, TBody = undefined, TResponse = any>(config: EndpointConfig<TPath, TMethod, TParams, TQuery, TBody, TResponse>): EndpointConfig<TPath, TMethod, TParams, TQuery, TBody, TResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Helper to define multiple endpoints
|
|
40
|
+
*/
|
|
41
|
+
declare function defineEndpoints<T extends Record<string, APIEndpoint>>(endpoints: T): T;
|
|
42
|
+
|
|
43
|
+
export { type APIConfig, type APIEndpoint, type EndpointConfig, type HTTPMethod, defineConfig, defineEndpoint, defineEndpoints };
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cushin/api-runtime",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Runtime utilities for Cushin API codegen - types, schemas, and HTTP client",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/client.d.ts",
|
|
15
|
+
"import": "./dist/client.js"
|
|
16
|
+
},
|
|
17
|
+
"./schema": {
|
|
18
|
+
"types": "./dist/schema.d.ts",
|
|
19
|
+
"import": "./dist/schema.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"api",
|
|
28
|
+
"runtime",
|
|
29
|
+
"client",
|
|
30
|
+
"typescript",
|
|
31
|
+
"type-safe"
|
|
32
|
+
],
|
|
33
|
+
"author": "Le Viet Hoang",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"ky": "^1.0.0",
|
|
37
|
+
"zod": "^3.22.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^20.11.0",
|
|
41
|
+
"ky": "^1.2.0",
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"typescript": "^5.3.0",
|
|
44
|
+
"zod": "^3.25.76"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"dev": "tsup --watch",
|
|
52
|
+
"typecheck": "tsc --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|