alchemy 0.12.5 → 0.12.7
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/lib/cloudflare/ai-gateway.d.ts.map +1 -1
- package/lib/cloudflare/ai-gateway.js +1 -2
- package/lib/cloudflare/ai-gateway.js.map +1 -1
- package/lib/cloudflare/bindings.d.ts +2 -1
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bound.d.ts +2 -1
- package/lib/cloudflare/bound.d.ts.map +1 -1
- package/lib/cloudflare/hyperdrive.d.ts +216 -0
- package/lib/cloudflare/hyperdrive.d.ts.map +1 -0
- package/lib/cloudflare/hyperdrive.js +184 -0
- package/lib/cloudflare/hyperdrive.js.map +1 -0
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +19 -2
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +28 -4
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/neon/api-error.d.ts +31 -0
- package/lib/neon/api-error.d.ts.map +1 -0
- package/lib/neon/api-error.js +73 -0
- package/lib/neon/api-error.js.map +1 -0
- package/lib/neon/api.d.ts +70 -0
- package/lib/neon/api.d.ts.map +1 -0
- package/lib/neon/api.js +128 -0
- package/lib/neon/api.js.map +1 -0
- package/lib/neon/index.d.ts +4 -0
- package/lib/neon/index.d.ts.map +1 -0
- package/lib/neon/index.js +4 -0
- package/lib/neon/index.js.map +1 -0
- package/lib/neon/project.d.ts +345 -0
- package/lib/neon/project.d.ts.map +1 -0
- package/lib/neon/project.js +305 -0
- package/lib/neon/project.js.map +1 -0
- package/package.json +2 -1
- package/src/cloudflare/ai-gateway.ts +0 -1
- package/src/cloudflare/bindings.ts +4 -2
- package/src/cloudflare/bound.ts +20 -17
- package/src/cloudflare/hyperdrive.ts +375 -0
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/worker.ts +55 -6
- package/src/neon/api-error.ts +81 -0
- package/src/neon/api.ts +178 -0
- package/src/neon/index.ts +3 -0
- package/src/neon/project.ts +870 -0
package/src/neon/api.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { Secret } from "../secret.js";
|
|
2
|
+
import { withExponentialBackoff } from "../util/retry.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for Neon API requests
|
|
6
|
+
*/
|
|
7
|
+
export interface NeonApiOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Base URL for Neon API
|
|
10
|
+
* @default https://console.neon.tech/api/v2
|
|
11
|
+
*/
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* API Key to use (overrides NEON_API_KEY env var)
|
|
16
|
+
*/
|
|
17
|
+
apiKey?: Secret;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a NeonApi instance with environment variable fallback
|
|
22
|
+
* @param options API options
|
|
23
|
+
* @returns NeonApi instance
|
|
24
|
+
*/
|
|
25
|
+
export function createNeonApi(options: Partial<NeonApiOptions> = {}): NeonApi {
|
|
26
|
+
return new NeonApi({
|
|
27
|
+
baseUrl: options.baseUrl,
|
|
28
|
+
apiKey: options.apiKey,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get authentication headers for Neon API
|
|
34
|
+
* @param options NeonApiOptions
|
|
35
|
+
* @returns Headers for authentication
|
|
36
|
+
*/
|
|
37
|
+
export async function getNeonAuthHeaders(
|
|
38
|
+
options: Partial<NeonApiOptions>
|
|
39
|
+
): Promise<Record<string, string>> {
|
|
40
|
+
const apiKey = options.apiKey?.unencrypted ?? process.env.NEON_API_KEY;
|
|
41
|
+
|
|
42
|
+
if (!apiKey) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Neon API key is required. Set NEON_API_KEY environment variable or provide apiKey option."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
Accept: "application/json",
|
|
51
|
+
Authorization: `Bearer ${apiKey}`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Neon API client using raw fetch
|
|
57
|
+
*/
|
|
58
|
+
export class NeonApi {
|
|
59
|
+
public readonly baseUrl: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a new Neon API client
|
|
63
|
+
* Use createNeonApi factory function instead of direct constructor
|
|
64
|
+
*
|
|
65
|
+
* @param options API options
|
|
66
|
+
*/
|
|
67
|
+
constructor(private readonly options: NeonApiOptions) {
|
|
68
|
+
this.baseUrl = options.baseUrl ?? "https://console.neon.tech/api/v2";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Make a fetch request to the Neon API
|
|
73
|
+
*
|
|
74
|
+
* @param path API path (without base URL)
|
|
75
|
+
* @param init Fetch init options
|
|
76
|
+
* @returns Raw Response object from fetch
|
|
77
|
+
*/
|
|
78
|
+
async fetch(path: string, init: RequestInit = {}): Promise<Response> {
|
|
79
|
+
let headers: Record<string, string> = {};
|
|
80
|
+
|
|
81
|
+
if (Array.isArray(init.headers)) {
|
|
82
|
+
init.headers.forEach(([key, value]) => {
|
|
83
|
+
headers[key] = value;
|
|
84
|
+
});
|
|
85
|
+
} else if (init.headers instanceof Headers) {
|
|
86
|
+
init.headers.forEach((value, key) => {
|
|
87
|
+
headers[key] = value;
|
|
88
|
+
});
|
|
89
|
+
} else if (init.headers) {
|
|
90
|
+
headers = init.headers as Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
headers = {
|
|
94
|
+
...(await getNeonAuthHeaders(this.options)),
|
|
95
|
+
...headers,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Use withExponentialBackoff for automatic retry on network errors
|
|
99
|
+
return withExponentialBackoff(
|
|
100
|
+
() =>
|
|
101
|
+
fetch(`${this.baseUrl}${path}`, {
|
|
102
|
+
...init,
|
|
103
|
+
headers,
|
|
104
|
+
}),
|
|
105
|
+
(error) => {
|
|
106
|
+
// Only retry on network-related errors
|
|
107
|
+
const errorMsg = (error as Error).message || "";
|
|
108
|
+
const isNetworkError =
|
|
109
|
+
errorMsg.includes("socket connection was closed") ||
|
|
110
|
+
errorMsg.includes("ECONNRESET") ||
|
|
111
|
+
errorMsg.includes("ETIMEDOUT") ||
|
|
112
|
+
errorMsg.includes("ECONNREFUSED");
|
|
113
|
+
|
|
114
|
+
return isNetworkError || error?.status?.toString().startsWith("5");
|
|
115
|
+
},
|
|
116
|
+
5, // Maximum 5 attempts (1 initial + 4 retries)
|
|
117
|
+
1000 // Start with 1s delay, will exponentially increase
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Helper for GET requests
|
|
123
|
+
*/
|
|
124
|
+
async get(path: string, init: RequestInit = {}): Promise<Response> {
|
|
125
|
+
return this.fetch(path, { ...init, method: "GET" });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Helper for POST requests
|
|
130
|
+
*/
|
|
131
|
+
async post(
|
|
132
|
+
path: string,
|
|
133
|
+
body: any,
|
|
134
|
+
init: RequestInit = {}
|
|
135
|
+
): Promise<Response> {
|
|
136
|
+
const requestBody =
|
|
137
|
+
body instanceof FormData
|
|
138
|
+
? body
|
|
139
|
+
: typeof body === "string"
|
|
140
|
+
? body
|
|
141
|
+
: JSON.stringify(body);
|
|
142
|
+
return this.fetch(path, { ...init, method: "POST", body: requestBody });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Helper for PUT requests
|
|
147
|
+
*/
|
|
148
|
+
async put(
|
|
149
|
+
path: string,
|
|
150
|
+
body: any,
|
|
151
|
+
init: RequestInit = {}
|
|
152
|
+
): Promise<Response> {
|
|
153
|
+
const requestBody = body instanceof FormData ? body : JSON.stringify(body);
|
|
154
|
+
return this.fetch(path, { ...init, method: "PUT", body: requestBody });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Helper for PATCH requests
|
|
159
|
+
*/
|
|
160
|
+
async patch(
|
|
161
|
+
path: string,
|
|
162
|
+
body: any,
|
|
163
|
+
init: RequestInit = {}
|
|
164
|
+
): Promise<Response> {
|
|
165
|
+
return this.fetch(path, {
|
|
166
|
+
...init,
|
|
167
|
+
method: "PATCH",
|
|
168
|
+
body: JSON.stringify(body),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Helper for DELETE requests
|
|
174
|
+
*/
|
|
175
|
+
async delete(path: string, init: RequestInit = {}): Promise<Response> {
|
|
176
|
+
return this.fetch(path, { ...init, method: "DELETE" });
|
|
177
|
+
}
|
|
178
|
+
}
|