@devpad/api 2.0.0 → 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.
@@ -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
@@ -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
- }
@@ -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,49 +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
- constructor(options: {
28
- base_url: string;
29
- api_key?: string;
30
- max_history_size?: number;
31
- category?: string;
32
- credentials?: "include" | "omit" | "same-origin";
33
- auth_mode?: "session" | "key" | "cookie";
34
- default_headers?: Record<string, string>;
35
- custom_fetch?: typeof fetch;
36
- });
37
- private buildUrl;
38
- private generateRequestId;
39
- private request;
40
- get<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
41
- post<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
42
- patch<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
43
- put<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
44
- delete<T>(path: string, options?: Omit<RequestOptions, "method">): Promise<T>;
45
- history(): BufferedQueue<RequestHistoryEntry>;
46
- url(): string;
47
- headers(): Record<string, string>;
48
- }
49
- //# sourceMappingURL=request.d.ts.map
@@ -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;gBAEpC,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;KAC5B;IAiBD,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,iBAAiB;YAIX,OAAO;IAyId,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,193 +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
- }
22
- buildUrl(path, query) {
23
- const url = new URL(`${this.base_url}${path}`);
24
- if (query) {
25
- Object.entries(query).forEach(([key, value]) => {
26
- if (value)
27
- url.searchParams.append(key, value);
28
- });
29
- }
30
- return url.toString();
31
- }
32
- generateRequestId() {
33
- return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
34
- }
35
- async request(path, options = {}) {
36
- const { method = "GET", headers = {}, body, query } = options;
37
- const url = this.buildUrl(path, query);
38
- const requestId = this.generateRequestId();
39
- const startTime = Date.now();
40
- const timestamp = new Date().toISOString();
41
- // Log request start
42
- console.log(`[DEBUG][${this.category}] ${method} ${path} [${requestId}]`, {
43
- body,
44
- query,
45
- });
46
- const request_headers = {
47
- "Content-Type": "application/json",
48
- "X-Request-ID": requestId,
49
- ...this.default_headers,
50
- ...headers,
51
- };
52
- if (this.auth_mode === "session") {
53
- request_headers.Authorization = `Bearer jwt:${this.api_key.replace(/^jwt:/, "")}`;
54
- }
55
- else if (this.auth_mode === "key") {
56
- request_headers.Authorization = `Bearer ${this.api_key}`;
57
- }
58
- // Initialize history entry
59
- const historyEntry = {
60
- timestamp,
61
- method,
62
- path,
63
- options: { ...options, method },
64
- url,
65
- };
66
- try {
67
- const fetchOptions = {
68
- method,
69
- headers: request_headers,
70
- };
71
- if (body) {
72
- fetchOptions.body = JSON.stringify(body);
73
- }
74
- if (this.credentials) {
75
- fetchOptions.credentials = this.credentials;
76
- }
77
- else if (this.auth_mode === "cookie") {
78
- fetchOptions.credentials = "include";
79
- }
80
- const fetcher = this.custom_fetch ?? fetch;
81
- const response = await fetcher(url, fetchOptions);
82
- const duration = Date.now() - startTime;
83
- // Update history entry with response info
84
- historyEntry.status = response.status;
85
- historyEntry.duration = duration;
86
- if (!response.ok) {
87
- console.log(`[ERROR][${this.category}] ${method} ${path} [${requestId}] failed`, {
88
- status: response.status,
89
- duration: `${duration}ms`,
90
- body,
91
- query,
92
- });
93
- try {
94
- // Use centralized error handling
95
- handleHttpResponse(response);
96
- await handleResponseError(response);
97
- }
98
- catch (error) {
99
- // Log error in history and re-throw
100
- const errorMessage = error instanceof Error ? error.message : "Request failed";
101
- historyEntry.error = errorMessage;
102
- this.request_history.add(historyEntry);
103
- throw error;
104
- }
105
- }
106
- // Success - add to history
107
- this.request_history.add(historyEntry);
108
- // Handle response parsing
109
- let result;
110
- if (response.status === HTTP_STATUS.NO_CONTENT) {
111
- result = undefined;
112
- }
113
- else {
114
- const text = await response.text();
115
- if (!text || text.trim() === "" || text.trim() === "null") {
116
- result = undefined;
117
- }
118
- else {
119
- try {
120
- result = JSON.parse(text);
121
- }
122
- catch (parseError) {
123
- result = text;
124
- }
125
- }
126
- }
127
- // Log success
128
- console.log(`[INFO][${this.category}] ${method} ${path} [${requestId}] completed`, {
129
- status: response.status,
130
- duration: `${duration}ms`,
131
- });
132
- return result;
133
- }
134
- catch (error) {
135
- const duration = Date.now() - startTime;
136
- console.log(`[ERROR][${this.category}] ${method} ${path} [${requestId}] failed`, {
137
- url,
138
- duration: `${duration}ms`,
139
- error: error instanceof Error ? error.message : String(error),
140
- body,
141
- query,
142
- });
143
- // If this is already an API error, just re-throw it (already added to history above)
144
- if (error instanceof ApiError || error instanceof AuthenticationError) {
145
- throw error;
146
- }
147
- // Handle network error
148
- historyEntry.duration = duration;
149
- try {
150
- handleNetworkError(error);
151
- }
152
- catch (networkError) {
153
- const errorMessage = networkError instanceof Error ? networkError.message : "Unknown network error";
154
- historyEntry.error = errorMessage;
155
- this.request_history.add(historyEntry);
156
- throw networkError;
157
- }
158
- }
159
- }
160
- get(path, options = {}) {
161
- return this.request(path, { ...options, method: "GET" });
162
- }
163
- post(path, options = {}) {
164
- return this.request(path, { ...options, method: "POST" });
165
- }
166
- patch(path, options = {}) {
167
- return this.request(path, { ...options, method: "PATCH" });
168
- }
169
- put(path, options = {}) {
170
- return this.request(path, { ...options, method: "PUT" });
171
- }
172
- delete(path, options = {}) {
173
- return this.request(path, { ...options, method: "DELETE" });
174
- }
175
- history() {
176
- return this.request_history;
177
- }
178
- url() {
179
- return this.base_url;
180
- }
181
- headers() {
182
- const headers = {
183
- "Content-Type": "application/json",
184
- };
185
- if (this.auth_mode === "session") {
186
- headers.Authorization = `Bearer jwt:${this.api_key.replace(/^jwt:/, "")}`;
187
- }
188
- else if (this.auth_mode === "key") {
189
- headers["X-API-KEY"] = this.api_key;
190
- }
191
- return headers;
192
- }
193
- }
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
@@ -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
@@ -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"}