@devpad/api 2.0.1 → 2.0.2
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/dist/chunk-5X36WMYQ.js +130 -0
- package/dist/chunk-FOO5XXY5.js +318 -0
- package/dist/chunk-WTGVONUB.js +166 -0
- package/dist/errors.d-C73AkrdX.d.ts +159 -0
- package/dist/index.d.ts +541 -13
- package/dist/index.js +1345 -6
- package/dist/media.d-R87HGuRp.d.ts +1047 -0
- package/dist/schema/blog.d.ts +5635 -0
- package/dist/schema/blog.js +348 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.js +186 -0
- package/dist/schema/media.d.ts +1676 -0
- package/dist/schema/media.js +776 -0
- package/dist/schema.d-BceDyQED.d.ts +3187 -0
- package/dist/types.d-1hBObc_N.d.ts +684 -0
- package/dist/types.d-CoHRMrYJ.d.ts +539 -0
- package/dist/types.d-UV8B6hPN.d.ts +6146 -0
- package/package.json +17 -4
- package/dist/api-client.d.ts +0 -470
- package/dist/api-client.d.ts.map +0 -1
- package/dist/api-client.js +0 -530
- package/dist/error-handlers.d.ts +0 -55
- package/dist/error-handlers.d.ts.map +0 -1
- package/dist/error-handlers.js +0 -217
- package/dist/errors.d.ts +0 -19
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -28
- package/dist/index.d.ts.map +0 -1
- package/dist/request.d.ts +0 -51
- package/dist/request.d.ts.map +0 -1
- package/dist/request.js +0 -197
- package/dist/result.d.ts +0 -10
- package/dist/result.d.ts.map +0 -1
- package/dist/result.js +0 -11
- package/dist/tools.d.ts +0 -84
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -474
package/dist/error-handlers.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { ApiError, AuthenticationError, NetworkError, ValidationError } from "./errors";
|
|
2
|
-
/**
|
|
3
|
-
* Centralized error handling utilities to reduce duplication
|
|
4
|
-
* across API client methods and improve consistency
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Standard HTTP status codes
|
|
8
|
-
*/
|
|
9
|
-
export const HTTP_STATUS = {
|
|
10
|
-
OK: 200,
|
|
11
|
-
CREATED: 201,
|
|
12
|
-
NO_CONTENT: 204,
|
|
13
|
-
BAD_REQUEST: 400,
|
|
14
|
-
UNAUTHORIZED: 401,
|
|
15
|
-
FORBIDDEN: 403,
|
|
16
|
-
NOT_FOUND: 404,
|
|
17
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Handle response based on status code with consistent error types
|
|
21
|
-
*/
|
|
22
|
-
export function handleHttpResponse(response) {
|
|
23
|
-
switch (response.status) {
|
|
24
|
-
case HTTP_STATUS.UNAUTHORIZED:
|
|
25
|
-
throw new AuthenticationError("Invalid or expired API key");
|
|
26
|
-
case HTTP_STATUS.NOT_FOUND:
|
|
27
|
-
throw new ApiError("Resource not found", { statusCode: HTTP_STATUS.NOT_FOUND });
|
|
28
|
-
case HTTP_STATUS.BAD_REQUEST:
|
|
29
|
-
// Will be handled by specific error text parsing
|
|
30
|
-
break;
|
|
31
|
-
default:
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
throw new ApiError(`Request failed: ${response.statusText}`, { statusCode: response.status });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Parse and throw appropriate error from response text
|
|
39
|
-
*/
|
|
40
|
-
export async function handleResponseError(response) {
|
|
41
|
-
const errorText = await response.text();
|
|
42
|
-
const errorMessage = errorText || "Request failed";
|
|
43
|
-
// Try to parse structured error responses
|
|
44
|
-
let parsedError = null;
|
|
45
|
-
try {
|
|
46
|
-
parsedError = JSON.parse(errorText);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
// Not JSON, use raw text
|
|
50
|
-
}
|
|
51
|
-
if (response.status === HTTP_STATUS.BAD_REQUEST && parsedError?.error?.name === "ZodError") {
|
|
52
|
-
// Enhanced: Create a more detailed ValidationError with the original Zod error info
|
|
53
|
-
const zodErrorDetails = parsedError.error?.issues ? JSON.stringify(parsedError.error) : errorMessage;
|
|
54
|
-
throw new ValidationError(zodErrorDetails);
|
|
55
|
-
}
|
|
56
|
-
throw new ApiError(errorMessage, { statusCode: response.status });
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Handle network errors consistently
|
|
60
|
-
*/
|
|
61
|
-
export function handleNetworkError(error) {
|
|
62
|
-
const message = error instanceof Error ? error.message : "Unknown network error";
|
|
63
|
-
throw new NetworkError(message);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Type guard to check if error is an API error
|
|
67
|
-
*/
|
|
68
|
-
export function isApiError(error) {
|
|
69
|
-
return error instanceof ApiError;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Type guard to check if error is an authentication error
|
|
73
|
-
*/
|
|
74
|
-
export function isAuthenticationError(error) {
|
|
75
|
-
return error instanceof AuthenticationError;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Type guard to check if error is a network error
|
|
79
|
-
*/
|
|
80
|
-
export function isNetworkError(error) {
|
|
81
|
-
return error instanceof NetworkError;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Parse Zod validation errors into user-friendly messages
|
|
85
|
-
*/
|
|
86
|
-
export function parseZodErrors(errorMessage) {
|
|
87
|
-
try {
|
|
88
|
-
// Try to parse as JSON first to get structured error info
|
|
89
|
-
let parsedError = null;
|
|
90
|
-
try {
|
|
91
|
-
parsedError = JSON.parse(errorMessage);
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
// If not JSON, try to extract Zod error details from the error message
|
|
95
|
-
const zodErrorMatch = errorMessage.match(/ZodError: (.+)/);
|
|
96
|
-
if (zodErrorMatch && zodErrorMatch[1]) {
|
|
97
|
-
try {
|
|
98
|
-
parsedError = JSON.parse(zodErrorMatch[1]);
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
// If still not JSON, try to extract from the message
|
|
102
|
-
const issuesMatch = errorMessage.match(/issues:\s*(\[.*\])/s);
|
|
103
|
-
if (issuesMatch && issuesMatch[1]) {
|
|
104
|
-
try {
|
|
105
|
-
parsedError = { issues: JSON.parse(issuesMatch[1]) };
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
// Fall back to basic parsing
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (parsedError?.issues && Array.isArray(parsedError.issues)) {
|
|
115
|
-
const friendlyMessages = parsedError.issues.map((issue) => {
|
|
116
|
-
const path = issue.path && issue.path.length > 0 ? issue.path.join(".") : "field";
|
|
117
|
-
const message = issue.message || "is invalid";
|
|
118
|
-
// Handle common validation types with friendly messages
|
|
119
|
-
switch (issue.code) {
|
|
120
|
-
case "invalid_type":
|
|
121
|
-
return `${path} must be a ${issue.expected} (received ${issue.received})`;
|
|
122
|
-
case "too_small":
|
|
123
|
-
if (issue.type === "string") {
|
|
124
|
-
return `${path} must be at least ${issue.minimum} characters long`;
|
|
125
|
-
}
|
|
126
|
-
if (issue.type === "number") {
|
|
127
|
-
return `${path} must be at least ${issue.minimum}`;
|
|
128
|
-
}
|
|
129
|
-
return `${path} is too small`;
|
|
130
|
-
case "too_big":
|
|
131
|
-
if (issue.type === "string") {
|
|
132
|
-
return `${path} must be no more than ${issue.maximum} characters long`;
|
|
133
|
-
}
|
|
134
|
-
if (issue.type === "number") {
|
|
135
|
-
return `${path} must be no more than ${issue.maximum}`;
|
|
136
|
-
}
|
|
137
|
-
return `${path} is too large`;
|
|
138
|
-
case "invalid_string":
|
|
139
|
-
if (issue.validation === "email") {
|
|
140
|
-
return `${path} must be a valid email address`;
|
|
141
|
-
}
|
|
142
|
-
if (issue.validation === "url") {
|
|
143
|
-
return `${path} must be a valid URL`;
|
|
144
|
-
}
|
|
145
|
-
if (issue.validation === "uuid") {
|
|
146
|
-
return `${path} must be a valid UUID`;
|
|
147
|
-
}
|
|
148
|
-
return `${path} format is invalid`;
|
|
149
|
-
case "custom":
|
|
150
|
-
return `${path}: ${message}`;
|
|
151
|
-
default:
|
|
152
|
-
return `${path}: ${message}`;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
if (friendlyMessages.length === 1) {
|
|
156
|
-
return friendlyMessages[0];
|
|
157
|
-
}
|
|
158
|
-
return `Validation failed:\n• ${friendlyMessages.join("\n• ")}`;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (e) {
|
|
162
|
-
// Fall back to original message if parsing fails
|
|
163
|
-
console.debug("Failed to parse Zod error:", e);
|
|
164
|
-
}
|
|
165
|
-
return errorMessage;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Get user-friendly error message from any error
|
|
169
|
-
*/
|
|
170
|
-
export function getUserFriendlyErrorMessage(error) {
|
|
171
|
-
if (isAuthenticationError(error)) {
|
|
172
|
-
return "Please check your API key and try again";
|
|
173
|
-
}
|
|
174
|
-
if (isNetworkError(error)) {
|
|
175
|
-
return "Network connection issue. Please try again";
|
|
176
|
-
}
|
|
177
|
-
if (isApiError(error)) {
|
|
178
|
-
if (error.statusCode === HTTP_STATUS.NOT_FOUND) {
|
|
179
|
-
return "The requested resource was not found";
|
|
180
|
-
}
|
|
181
|
-
if (error.statusCode === HTTP_STATUS.BAD_REQUEST) {
|
|
182
|
-
return "Invalid request. Please check your data";
|
|
183
|
-
}
|
|
184
|
-
// Enhanced: Parse Zod validation errors for ValidationError types
|
|
185
|
-
if (error.code === "VALIDATION_ERROR" && error.message) {
|
|
186
|
-
return parseZodErrors(error.message);
|
|
187
|
-
}
|
|
188
|
-
return error.message || "An error occurred";
|
|
189
|
-
}
|
|
190
|
-
return "An unexpected error occurred";
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Retry wrapper for API calls with exponential backoff
|
|
194
|
-
*/
|
|
195
|
-
export async function withRetry(operation, maxRetries = 3, baseDelay = 1000) {
|
|
196
|
-
let lastError;
|
|
197
|
-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
198
|
-
try {
|
|
199
|
-
return await operation();
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
lastError = error;
|
|
203
|
-
// Don't retry authentication or validation errors
|
|
204
|
-
if (isAuthenticationError(error) || error instanceof ValidationError) {
|
|
205
|
-
throw error;
|
|
206
|
-
}
|
|
207
|
-
// Don't retry on final attempt
|
|
208
|
-
if (attempt === maxRetries) {
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
// Exponential backoff
|
|
212
|
-
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
213
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
throw lastError;
|
|
217
|
-
}
|
package/dist/errors.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare class ApiError extends Error {
|
|
2
|
-
readonly code?: string;
|
|
3
|
-
readonly statusCode?: number;
|
|
4
|
-
constructor(message: string, options?: {
|
|
5
|
-
code?: string;
|
|
6
|
-
statusCode?: number;
|
|
7
|
-
});
|
|
8
|
-
static fromResponse(response: Response): ApiError;
|
|
9
|
-
}
|
|
10
|
-
export declare class AuthenticationError extends ApiError {
|
|
11
|
-
constructor(message?: string);
|
|
12
|
-
}
|
|
13
|
-
export declare class NetworkError extends ApiError {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
}
|
|
16
|
-
export declare class ValidationError extends ApiError {
|
|
17
|
-
constructor(message?: string);
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAG5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACf;IAQP,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;CAKjD;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;gBACpC,OAAO,GAAE,MAAgC;CAGrD;AAED,qBAAa,YAAa,SAAQ,QAAQ;gBAC7B,OAAO,GAAE,MAAiC;CAGtD;AAED,qBAAa,eAAgB,SAAQ,QAAQ;gBAChC,OAAO,GAAE,MAA4B;CAGjD"}
|
package/dist/errors.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class ApiError extends Error {
|
|
2
|
-
constructor(message, options = {}) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = "ApiError";
|
|
5
|
-
this.code = options.code ?? undefined;
|
|
6
|
-
this.statusCode = options.statusCode ?? undefined;
|
|
7
|
-
}
|
|
8
|
-
static fromResponse(response) {
|
|
9
|
-
return new ApiError(`API request failed: ${response.statusText}`, {
|
|
10
|
-
statusCode: response.status,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class AuthenticationError extends ApiError {
|
|
15
|
-
constructor(message = "Authentication failed") {
|
|
16
|
-
super(message, { code: "AUTHENTICATION_ERROR" });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class NetworkError extends ApiError {
|
|
20
|
-
constructor(message = "Network request failed") {
|
|
21
|
-
super(message, { code: "NETWORK_ERROR" });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class ValidationError extends ApiError {
|
|
25
|
-
constructor(message = "Validation failed") {
|
|
26
|
-
super(message, { code: "VALIDATION_ERROR" });
|
|
27
|
-
}
|
|
28
|
-
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,YAAY,EACX,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,IAAI,EACJ,eAAe,EACf,aAAa,EACb,SAAS,EACT,UAAU,GACV,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACX,SAAS,EACT,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,WAAW,EACX,UAAU,EACV,cAAc,EACd,aAAa,EACb,UAAU,EACV,WAAW,GACX,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACX,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,QAAQ,EACR,kBAAkB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/E,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC7F,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,eAAe,SAAS,CAAC"}
|
package/dist/request.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { type BufferedQueue } from "@devpad/schema";
|
|
2
|
-
export type RequestOptions = {
|
|
3
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
body?: unknown;
|
|
6
|
-
query?: Record<string, string>;
|
|
7
|
-
};
|
|
8
|
-
export type RequestHistoryEntry = {
|
|
9
|
-
timestamp: string;
|
|
10
|
-
method: string;
|
|
11
|
-
path: string;
|
|
12
|
-
options: RequestOptions;
|
|
13
|
-
url: string;
|
|
14
|
-
status?: number;
|
|
15
|
-
duration?: number;
|
|
16
|
-
error?: string;
|
|
17
|
-
};
|
|
18
|
-
export declare class ApiClient {
|
|
19
|
-
private base_url;
|
|
20
|
-
private api_key;
|
|
21
|
-
private request_history;
|
|
22
|
-
private category;
|
|
23
|
-
private default_headers;
|
|
24
|
-
private custom_fetch?;
|
|
25
|
-
private credentials?;
|
|
26
|
-
private auth_mode;
|
|
27
|
-
private debug;
|
|
28
|
-
constructor(options: {
|
|
29
|
-
base_url: string;
|
|
30
|
-
api_key?: string;
|
|
31
|
-
max_history_size?: number;
|
|
32
|
-
category?: string;
|
|
33
|
-
credentials?: "include" | "omit" | "same-origin";
|
|
34
|
-
auth_mode?: "session" | "key" | "cookie";
|
|
35
|
-
default_headers?: Record<string, string>;
|
|
36
|
-
custom_fetch?: typeof fetch;
|
|
37
|
-
debug?: boolean;
|
|
38
|
-
});
|
|
39
|
-
private buildUrl;
|
|
40
|
-
private generateRequestId;
|
|
41
|
-
private request;
|
|
42
|
-
get<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
|
|
43
|
-
post<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
|
|
44
|
-
patch<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
|
|
45
|
-
put<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
|
|
46
|
-
delete<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
|
|
47
|
-
history(): BufferedQueue<RequestHistoryEntry>;
|
|
48
|
-
url(): string;
|
|
49
|
-
headers(): Record<string, string>;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=request.d.ts.map
|
package/dist/request.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIxE,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,eAAe,CAAqC;IAC5D,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,OAAO,CAAC,WAAW,CAAC,CAAqC;IACzD,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,KAAK,CAAU;gBAEX,OAAO,EAAE;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,aAAa,CAAC;QACjD,SAAS,CAAC,EAAE,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC;QACzC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzC,YAAY,CAAC,EAAE,OAAO,KAAK,CAAC;QAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;KAChB;IAkBD,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,iBAAiB;YAIX,OAAO;IA4Id,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI9E,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI/E,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhF,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI9E,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjF,OAAO;IAIP,GAAG,IAAI,MAAM;IAIb,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAaxC"}
|
package/dist/request.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { ArrayBufferedQueue } from "@devpad/schema";
|
|
2
|
-
import { HTTP_STATUS, handleHttpResponse, handleNetworkError, handleResponseError } from "./error-handlers";
|
|
3
|
-
import { ApiError, AuthenticationError } from "./errors";
|
|
4
|
-
export class ApiClient {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
this.category = "api";
|
|
7
|
-
this.auth_mode = options.auth_mode ?? (options.api_key?.startsWith("jwt:") ? "session" : "key");
|
|
8
|
-
if (this.auth_mode !== "cookie") {
|
|
9
|
-
if (!options.api_key)
|
|
10
|
-
throw new Error("API key is required");
|
|
11
|
-
if (options.api_key.length < 10)
|
|
12
|
-
throw new Error("API key is too short");
|
|
13
|
-
}
|
|
14
|
-
this.base_url = options.base_url;
|
|
15
|
-
this.api_key = options.api_key ?? "";
|
|
16
|
-
this.category = options.category || "api";
|
|
17
|
-
this.credentials = options.credentials;
|
|
18
|
-
this.default_headers = options.default_headers ?? {};
|
|
19
|
-
this.custom_fetch = options.custom_fetch;
|
|
20
|
-
this.request_history = new ArrayBufferedQueue(options.max_history_size ?? 5);
|
|
21
|
-
this.debug = options.debug ?? false;
|
|
22
|
-
}
|
|
23
|
-
buildUrl(path, query) {
|
|
24
|
-
const url = new URL(`${this.base_url}${path}`);
|
|
25
|
-
if (query) {
|
|
26
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
27
|
-
if (value)
|
|
28
|
-
url.searchParams.append(key, value);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return url.toString();
|
|
32
|
-
}
|
|
33
|
-
generateRequestId() {
|
|
34
|
-
return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
35
|
-
}
|
|
36
|
-
async request(path, options = {}) {
|
|
37
|
-
const { method = "GET", headers = {}, body, query } = options;
|
|
38
|
-
const url = this.buildUrl(path, query);
|
|
39
|
-
const requestId = this.generateRequestId();
|
|
40
|
-
const startTime = Date.now();
|
|
41
|
-
const timestamp = new Date().toISOString();
|
|
42
|
-
if (this.debug) {
|
|
43
|
-
console.log(`[DEBUG][${this.category}] ${method} ${path} [${requestId}]`, { body, query });
|
|
44
|
-
}
|
|
45
|
-
const request_headers = {
|
|
46
|
-
"Content-Type": "application/json",
|
|
47
|
-
"X-Request-ID": requestId,
|
|
48
|
-
...this.default_headers,
|
|
49
|
-
...headers,
|
|
50
|
-
};
|
|
51
|
-
if (this.auth_mode === "session") {
|
|
52
|
-
request_headers.Authorization = `Bearer jwt:${this.api_key.replace(/^jwt:/, "")}`;
|
|
53
|
-
}
|
|
54
|
-
else if (this.auth_mode === "key") {
|
|
55
|
-
request_headers.Authorization = `Bearer ${this.api_key}`;
|
|
56
|
-
}
|
|
57
|
-
// Initialize history entry
|
|
58
|
-
const historyEntry = {
|
|
59
|
-
timestamp,
|
|
60
|
-
method,
|
|
61
|
-
path,
|
|
62
|
-
options: { ...options, method },
|
|
63
|
-
url,
|
|
64
|
-
};
|
|
65
|
-
try {
|
|
66
|
-
const fetchOptions = {
|
|
67
|
-
method,
|
|
68
|
-
headers: request_headers,
|
|
69
|
-
};
|
|
70
|
-
if (body) {
|
|
71
|
-
fetchOptions.body = JSON.stringify(body);
|
|
72
|
-
}
|
|
73
|
-
if (this.credentials) {
|
|
74
|
-
fetchOptions.credentials = this.credentials;
|
|
75
|
-
}
|
|
76
|
-
else if (this.auth_mode === "cookie") {
|
|
77
|
-
fetchOptions.credentials = "include";
|
|
78
|
-
}
|
|
79
|
-
const fetcher = this.custom_fetch ?? fetch;
|
|
80
|
-
const response = await fetcher(url, fetchOptions);
|
|
81
|
-
const duration = Date.now() - startTime;
|
|
82
|
-
// Update history entry with response info
|
|
83
|
-
historyEntry.status = response.status;
|
|
84
|
-
historyEntry.duration = duration;
|
|
85
|
-
if (!response.ok) {
|
|
86
|
-
if (this.debug) {
|
|
87
|
-
console.log(`[ERROR][${this.category}] ${method} ${path} [${requestId}] failed`, {
|
|
88
|
-
status: response.status,
|
|
89
|
-
duration: `${duration}ms`,
|
|
90
|
-
body,
|
|
91
|
-
query,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
// Use centralized error handling
|
|
96
|
-
handleHttpResponse(response);
|
|
97
|
-
await handleResponseError(response);
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
// Log error in history and re-throw
|
|
101
|
-
const errorMessage = error instanceof Error ? error.message : "Request failed";
|
|
102
|
-
historyEntry.error = errorMessage;
|
|
103
|
-
this.request_history.add(historyEntry);
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// Success - add to history
|
|
108
|
-
this.request_history.add(historyEntry);
|
|
109
|
-
// Handle response parsing
|
|
110
|
-
let result;
|
|
111
|
-
if (response.status === HTTP_STATUS.NO_CONTENT) {
|
|
112
|
-
result = undefined;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
const text = await response.text();
|
|
116
|
-
if (!text || text.trim() === "" || text.trim() === "null") {
|
|
117
|
-
result = undefined;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
try {
|
|
121
|
-
result = JSON.parse(text);
|
|
122
|
-
}
|
|
123
|
-
catch (parseError) {
|
|
124
|
-
result = text;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (this.debug) {
|
|
129
|
-
console.log(`[INFO][${this.category}] ${method} ${path} [${requestId}] completed`, {
|
|
130
|
-
status: response.status,
|
|
131
|
-
duration: `${duration}ms`,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
const duration = Date.now() - startTime;
|
|
138
|
-
if (this.debug) {
|
|
139
|
-
console.log(`[ERROR][${this.category}] ${method} ${path} [${requestId}] failed`, {
|
|
140
|
-
url,
|
|
141
|
-
duration: `${duration}ms`,
|
|
142
|
-
error: error instanceof Error ? error.message : String(error),
|
|
143
|
-
body,
|
|
144
|
-
query,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
// If this is already an API error, just re-throw it (already added to history above)
|
|
148
|
-
if (error instanceof ApiError || error instanceof AuthenticationError) {
|
|
149
|
-
throw error;
|
|
150
|
-
}
|
|
151
|
-
// Handle network error
|
|
152
|
-
historyEntry.duration = duration;
|
|
153
|
-
try {
|
|
154
|
-
handleNetworkError(error);
|
|
155
|
-
}
|
|
156
|
-
catch (networkError) {
|
|
157
|
-
const errorMessage = networkError instanceof Error ? networkError.message : "Unknown network error";
|
|
158
|
-
historyEntry.error = errorMessage;
|
|
159
|
-
this.request_history.add(historyEntry);
|
|
160
|
-
throw networkError;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
get(path, options = {}) {
|
|
165
|
-
return this.request(path, { ...options, method: "GET" });
|
|
166
|
-
}
|
|
167
|
-
post(path, options = {}) {
|
|
168
|
-
return this.request(path, { ...options, method: "POST" });
|
|
169
|
-
}
|
|
170
|
-
patch(path, options = {}) {
|
|
171
|
-
return this.request(path, { ...options, method: "PATCH" });
|
|
172
|
-
}
|
|
173
|
-
put(path, options = {}) {
|
|
174
|
-
return this.request(path, { ...options, method: "PUT" });
|
|
175
|
-
}
|
|
176
|
-
delete(path, options = {}) {
|
|
177
|
-
return this.request(path, { ...options, method: "DELETE" });
|
|
178
|
-
}
|
|
179
|
-
history() {
|
|
180
|
-
return this.request_history;
|
|
181
|
-
}
|
|
182
|
-
url() {
|
|
183
|
-
return this.base_url;
|
|
184
|
-
}
|
|
185
|
-
headers() {
|
|
186
|
-
const headers = {
|
|
187
|
-
"Content-Type": "application/json",
|
|
188
|
-
};
|
|
189
|
-
if (this.auth_mode === "session") {
|
|
190
|
-
headers.Authorization = `Bearer jwt:${this.api_key.replace(/^jwt:/, "")}`;
|
|
191
|
-
}
|
|
192
|
-
else if (this.auth_mode === "key") {
|
|
193
|
-
headers["X-API-KEY"] = this.api_key;
|
|
194
|
-
}
|
|
195
|
-
return headers;
|
|
196
|
-
}
|
|
197
|
-
}
|
package/dist/result.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { err, ok, type Result } from "@f0rbit/corpus";
|
|
2
|
-
export type ApiResultError = {
|
|
3
|
-
message: string;
|
|
4
|
-
code?: string;
|
|
5
|
-
status_code?: number;
|
|
6
|
-
};
|
|
7
|
-
export type ApiResult<T> = Result<T, ApiResultError>;
|
|
8
|
-
export declare function wrap<T>(fn: () => Promise<T>): Promise<ApiResult<T>>;
|
|
9
|
-
export { ok, err, type Result };
|
|
10
|
-
//# sourceMappingURL=result.d.ts.map
|
package/dist/result.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;AAErD,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAUnE;AAED,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,MAAM,EAAE,CAAC"}
|
package/dist/result.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { err, ok } from "@f0rbit/corpus";
|
|
2
|
-
export function wrap(fn) {
|
|
3
|
-
return fn()
|
|
4
|
-
.then(data => ok(data))
|
|
5
|
-
.catch(error => err({
|
|
6
|
-
message: error.message || "Unknown error",
|
|
7
|
-
code: error.code,
|
|
8
|
-
status_code: error.statusCode || error.status_code,
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
11
|
-
export { ok, err };
|
package/dist/tools.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { ApiClient } from "./api-client";
|
|
3
|
-
export declare const project_filters: z.ZodObject<{
|
|
4
|
-
private: z.ZodOptional<z.ZodBoolean>;
|
|
5
|
-
}, "strip", z.ZodTypeAny, {
|
|
6
|
-
private?: boolean | undefined;
|
|
7
|
-
}, {
|
|
8
|
-
private?: boolean | undefined;
|
|
9
|
-
}>;
|
|
10
|
-
export declare const project_by_id_or_name: z.ZodEffects<z.ZodObject<{
|
|
11
|
-
id: z.ZodOptional<z.ZodString>;
|
|
12
|
-
name: z.ZodOptional<z.ZodString>;
|
|
13
|
-
}, "strip", z.ZodTypeAny, {
|
|
14
|
-
name?: string | undefined;
|
|
15
|
-
id?: string | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
name?: string | undefined;
|
|
18
|
-
id?: string | undefined;
|
|
19
|
-
}>, {
|
|
20
|
-
name?: string | undefined;
|
|
21
|
-
id?: string | undefined;
|
|
22
|
-
}, {
|
|
23
|
-
name?: string | undefined;
|
|
24
|
-
id?: string | undefined;
|
|
25
|
-
}>;
|
|
26
|
-
export declare const task_filters: z.ZodObject<{
|
|
27
|
-
project_id: z.ZodOptional<z.ZodString>;
|
|
28
|
-
tag_id: z.ZodOptional<z.ZodString>;
|
|
29
|
-
}, "strip", z.ZodTypeAny, {
|
|
30
|
-
project_id?: string | undefined;
|
|
31
|
-
tag_id?: string | undefined;
|
|
32
|
-
}, {
|
|
33
|
-
project_id?: string | undefined;
|
|
34
|
-
tag_id?: string | undefined;
|
|
35
|
-
}>;
|
|
36
|
-
export declare const task_by_id: z.ZodObject<{
|
|
37
|
-
id: z.ZodString;
|
|
38
|
-
}, "strip", z.ZodTypeAny, {
|
|
39
|
-
id: string;
|
|
40
|
-
}, {
|
|
41
|
-
id: string;
|
|
42
|
-
}>;
|
|
43
|
-
export declare const milestone_filters: z.ZodObject<{
|
|
44
|
-
project_id: z.ZodOptional<z.ZodString>;
|
|
45
|
-
}, "strip", z.ZodTypeAny, {
|
|
46
|
-
project_id?: string | undefined;
|
|
47
|
-
}, {
|
|
48
|
-
project_id?: string | undefined;
|
|
49
|
-
}>;
|
|
50
|
-
export declare const milestone_by_id: z.ZodObject<{
|
|
51
|
-
id: z.ZodString;
|
|
52
|
-
}, "strip", z.ZodTypeAny, {
|
|
53
|
-
id: string;
|
|
54
|
-
}, {
|
|
55
|
-
id: string;
|
|
56
|
-
}>;
|
|
57
|
-
export declare const goal_by_id: z.ZodObject<{
|
|
58
|
-
id: z.ZodString;
|
|
59
|
-
}, "strip", z.ZodTypeAny, {
|
|
60
|
-
id: string;
|
|
61
|
-
}, {
|
|
62
|
-
id: string;
|
|
63
|
-
}>;
|
|
64
|
-
export declare const github_branches: z.ZodObject<{
|
|
65
|
-
owner: z.ZodString;
|
|
66
|
-
repo: z.ZodString;
|
|
67
|
-
}, "strip", z.ZodTypeAny, {
|
|
68
|
-
owner: string;
|
|
69
|
-
repo: string;
|
|
70
|
-
}, {
|
|
71
|
-
owner: string;
|
|
72
|
-
repo: string;
|
|
73
|
-
}>;
|
|
74
|
-
export interface ToolDefinition<TInput = any, TOutput = any> {
|
|
75
|
-
name: string;
|
|
76
|
-
description: string;
|
|
77
|
-
inputSchema: z.ZodType<TInput>;
|
|
78
|
-
execute: (client: ApiClient, input: TInput) => Promise<TOutput>;
|
|
79
|
-
}
|
|
80
|
-
export declare const tools: Record<string, ToolDefinition>;
|
|
81
|
-
export declare function zodToMCPSchema(schema: z.ZodType<any>): z.ZodType<any, z.ZodTypeDef, any>;
|
|
82
|
-
export declare const toolNames: string[];
|
|
83
|
-
export declare function getTool(name: string): ToolDefinition | undefined;
|
|
84
|
-
//# sourceMappingURL=tools.d.ts.map
|
package/dist/tools.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQ9C,eAAO,MAAM,eAAe;;;;;;EAE1B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;EAO/B,CAAC;AAEJ,eAAO,MAAM,YAAY;;;;;;;;;EAGvB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;EAErB,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;EAE5B,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;EAE1B,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;EAErB,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;EAG1B,CAAC;AAGH,MAAM,WAAW,cAAc,CAAC,MAAM,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAChE;AAGD,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAsdhD,CAAC;AAGF,wBAAgB,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,qCAIpD;AAGD,eAAO,MAAM,SAAS,UAAqB,CAAC;AAG5C,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAEhE"}
|