freestyle 0.1.47 → 0.1.48

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.
Files changed (7) hide show
  1. package/README.md +51 -0
  2. package/index.cjs +1791 -1475
  3. package/index.d.cts +3943 -2379
  4. package/index.d.mts +3943 -2379
  5. package/index.mjs +1791 -1475
  6. package/package.json +1 -1
  7. package/index.js +0 -391
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "require": {
package/index.js DELETED
@@ -1,391 +0,0 @@
1
- // generated/client.ts
2
- function errorFromJSON(json, statusCode) {
3
- if (json && typeof json.message === "string") {
4
- const error = new Error(json.message);
5
- Object.assign(error, json);
6
- return error;
7
- }
8
- if (json && json.error && typeof json.error === "string") {
9
- return new Error(json.error);
10
- }
11
- if (typeof json === "string") {
12
- return new Error(json);
13
- }
14
- return new Error(`API Error (${statusCode}): ${JSON.stringify(json)}`);
15
- }
16
-
17
- class ApiClient {
18
- baseUrl;
19
- apiKey;
20
- fetchFn;
21
- constructor(config) {
22
- this.baseUrl = config.baseUrl || "https://api.freestyle.sh";
23
- this.apiKey = config.apiKey;
24
- this.fetchFn = config.fetch || fetch;
25
- }
26
- buildUrl(path, params, query) {
27
- let url = path;
28
- if (params) {
29
- for (const [key, value] of Object.entries(params)) {
30
- url = url.replace(`{${key}}`, encodeURIComponent(value));
31
- }
32
- }
33
- if (query) {
34
- const searchParams = new URLSearchParams;
35
- for (const [key, value] of Object.entries(query)) {
36
- if (value !== undefined && value !== null) {
37
- searchParams.append(key, String(value));
38
- }
39
- }
40
- const queryString = searchParams.toString();
41
- if (queryString) {
42
- url += `?${queryString}`;
43
- }
44
- }
45
- return this.baseUrl + url;
46
- }
47
- async request(method, url, body) {
48
- const headers = {
49
- Authorization: `Bearer ${this.apiKey}`
50
- };
51
- if (body) {
52
- headers["Content-Type"] = "application/json";
53
- }
54
- const response = await this.fetchFn(url, {
55
- method,
56
- headers,
57
- body: body ? JSON.stringify(body) : undefined
58
- });
59
- if (!response.ok) {
60
- const errorData = await response.json();
61
- throw errorFromJSON(errorData, response.status);
62
- }
63
- return response.json();
64
- }
65
- get(path, ...args) {
66
- const options = args[0];
67
- const url = this.buildUrl(path, options?.params, options?.query);
68
- return this.request("GET", url, options?.body);
69
- }
70
- post(path, ...args) {
71
- const options = args[0];
72
- const url = this.buildUrl(path, options?.params, options?.query);
73
- return this.request("POST", url, options?.body);
74
- }
75
- put(path, ...args) {
76
- const options = args[0];
77
- const url = this.buildUrl(path, options?.params, options?.query);
78
- return this.request("PUT", url, options?.body);
79
- }
80
- delete(path, ...args) {
81
- const options = args[0];
82
- const url = this.buildUrl(path, options?.params, options?.query);
83
- return this.request("DELETE", url, options?.body);
84
- }
85
- patch(path, ...args) {
86
- const options = args[0];
87
- const url = this.buildUrl(path, options?.params, options?.query);
88
- return this.request("PATCH", url, options?.body);
89
- }
90
- }
91
- // src/index.ts
92
- class Freestyle {
93
- apiClient;
94
- options;
95
- constructor({ apiKey, baseUrl } = {}) {
96
- if (!apiKey && !process.env.FREESTYLE_API_KEY) {
97
- throw new Error("API key is required. Please provide it in the constructor or set the FREESTYLE_API_KEY environment variable.");
98
- }
99
- this.options = {
100
- apiKey: apiKey ?? process.env.FREESTYLE_API_KEY,
101
- baseUrl: baseUrl ?? process.env.FREESTYLE_API_URL
102
- };
103
- this.apiClient = new ApiClient(this.options);
104
- }
105
- async executeScript(script, config) {
106
- return this.apiClient.post("/execute/v1/script", {
107
- body: { script, config }
108
- });
109
- }
110
- async deployWebV2(body) {
111
- return this.apiClient.post("/web/v1/deployment", { body });
112
- }
113
- async getLogs(deploymentId) {
114
- return this.apiClient.get("/observability/v1/logs", {
115
- query: { deploymentId }
116
- });
117
- }
118
- async createDomainVerificationRequest(domain) {
119
- return this.apiClient.post("/domains/v1/verifications", {
120
- body: { domain }
121
- });
122
- }
123
- async verifyDomainVerificationRequest(id) {
124
- return this.apiClient.put("/domains/v1/verifications", {
125
- body: { id }
126
- });
127
- }
128
- async verifyDomain(domain) {
129
- return this.apiClient.put("/domains/v1/verifications", {
130
- body: { domain }
131
- });
132
- }
133
- async listDomains(limit, offset) {
134
- return this.apiClient.get("/domains/v1/domains", {
135
- query: { limit, offset }
136
- });
137
- }
138
- async listDomainVerificationRequests() {
139
- return this.apiClient.get("/domains/v1/verifications", undefined);
140
- }
141
- async deleteDomainVerificationRequest(domain, verificationCode) {
142
- return this.apiClient.delete("/domains/v1/verifications", {
143
- body: { domain, verificationCode }
144
- });
145
- }
146
- async listWebDeployments(limit, offset) {
147
- return this.apiClient.get("/web/v1/deployments", {
148
- query: { limit: limit ?? 50, offset: offset ?? 0 }
149
- });
150
- }
151
- async listExecuteRuns(limit, offset) {
152
- return this.apiClient.get("/execute/v1/deployments", {
153
- query: { limit, offset }
154
- });
155
- }
156
- async getExecuteRun(deployment) {
157
- return this.apiClient.get("/execute/v1/deployments/{deployment}", {
158
- params: { deployment }
159
- });
160
- }
161
- async provisionWildcard(domain) {
162
- return this.apiClient.post("/domains/v1/certs/{domain}/wildcard", {
163
- params: { domain }
164
- });
165
- }
166
- async insertDomainMapping({
167
- domain,
168
- deploymentId
169
- }) {
170
- return this.apiClient.post("/domains/v1/mappings/{domain}", {
171
- params: { domain },
172
- body: { deploymentId }
173
- });
174
- }
175
- async removeDomainMapping({
176
- domain
177
- }) {
178
- return this.apiClient.delete("/domains/v1/mappings/{domain}", {
179
- params: { domain }
180
- });
181
- }
182
- async listDomainMappings({
183
- domain,
184
- domainOwnership,
185
- limit = 10,
186
- offset = 0
187
- } = {}) {
188
- return this.apiClient.get("/domains/v1/mappings", {
189
- query: { domain, domainOwnership, limit, offset }
190
- });
191
- }
192
- async createGitRepository(body) {
193
- return this.apiClient.post("/git/v1/repo", { body });
194
- }
195
- async listGitRepositories({
196
- limit = 10,
197
- offset = 0
198
- } = {}) {
199
- return this.apiClient.get("/git/v1/repo", {
200
- query: { limit, offset }
201
- });
202
- }
203
- async deleteGitRepository({
204
- repo
205
- }) {
206
- return this.apiClient.delete("/git/v1/repo/{repo}", {
207
- params: { repo }
208
- });
209
- }
210
- async createGitIdentity() {
211
- return this.apiClient.post("/git/v1/identity", undefined);
212
- }
213
- async deleteGitIdentity({
214
- identity
215
- }) {
216
- return this.apiClient.delete("/git/v1/identity/{identity}", {
217
- params: { identity }
218
- });
219
- }
220
- async grantGitPermission({
221
- repo,
222
- identity,
223
- permission
224
- }) {
225
- return this.apiClient.post("/git/v1/identity/{identity}/permissions/{repo}", {
226
- params: { identity, repo },
227
- body: { permission }
228
- });
229
- }
230
- async updateGitPermission({
231
- repo,
232
- identity,
233
- permission
234
- }) {
235
- return this.apiClient.patch("/git/v1/identity/{identity}/permissions/{repo}", {
236
- params: { identity, repo },
237
- body: { permission }
238
- });
239
- }
240
- async revokeGitPermission({
241
- repo,
242
- identity
243
- }) {
244
- return this.apiClient.delete("/git/v1/identity/{identity}/permissions/{repo}", {
245
- params: { identity, repo }
246
- });
247
- }
248
- async listGitPermissions({
249
- identity,
250
- limit,
251
- offset
252
- }) {
253
- return this.apiClient.get("/git/v1/identity/{identity}/permissions", {
254
- params: { identity },
255
- query: { limit, offset }
256
- });
257
- }
258
- async getGitPermission({
259
- repo,
260
- identity
261
- }) {
262
- return this.apiClient.get("/git/v1/identity/{identity}/permissions/{repo}", {
263
- params: { identity, repo }
264
- });
265
- }
266
- async createGitAccessToken({
267
- identity
268
- }) {
269
- return this.apiClient.post("/git/v1/identity/{identity}/tokens", {
270
- params: { identity }
271
- });
272
- }
273
- async revokeGitAccessToken({
274
- identity,
275
- tokenId
276
- }) {
277
- return this.apiClient.delete("/git/v1/identity/{identity}/tokens", {
278
- params: { identity },
279
- body: { tokenId }
280
- });
281
- }
282
- async listGitAccessTokens({
283
- identity
284
- }) {
285
- return this.apiClient.get("/git/v1/identity/{identity}/tokens", {
286
- params: { identity }
287
- });
288
- }
289
- async listGitTriggers({
290
- repo
291
- }) {
292
- return this.apiClient.get("/git/v1/repo/{repo}/trigger", {
293
- params: { repo }
294
- });
295
- }
296
- async createGitTrigger({
297
- repo,
298
- trigger,
299
- action
300
- }) {
301
- return this.apiClient.post("/git/v1/repo/{repo}/trigger", {
302
- params: { repo },
303
- body: { trigger, action }
304
- });
305
- }
306
- async deleteGitTrigger({
307
- repo,
308
- trigger
309
- }) {
310
- return this.apiClient.delete("/git/v1/repo/{repo}/trigger/{trigger}", {
311
- params: { repo, trigger }
312
- });
313
- }
314
- async setGitRepoDefaultBranch({
315
- repo_id,
316
- defaultBranch
317
- }) {
318
- return this.apiClient.put("/git/v1/repo/{repo_id}/default-branch", {
319
- params: { repo_id },
320
- body: { defaultBranch }
321
- });
322
- }
323
- async getGitRepoDefaultBranch({
324
- repo_id
325
- }) {
326
- return this.apiClient.get("/git/v1/repo/{repo_id}/default-branch", {
327
- params: { repo_id }
328
- });
329
- }
330
- async getGitRepoContents({
331
- repo,
332
- path = "",
333
- ref
334
- }) {
335
- return this.apiClient.get("/git/v1/repo/{repo}/contents/{path}", {
336
- params: { repo, path },
337
- query: { ref }
338
- });
339
- }
340
- async configureGitRepoGitHubSync({
341
- repo_id,
342
- githubRepoName
343
- }) {
344
- throw new Error("Not implemented - endpoint missing from OpenAPI spec");
345
- }
346
- async removeGitRepoGitHubSync({ repo_id }) {
347
- throw new Error("Not implemented - endpoint missing from OpenAPI spec");
348
- }
349
- async getGitRepoGitHubSyncConfig({
350
- repo_id
351
- }) {
352
- try {
353
- return await this.apiClient.get("/git/v1/repo/{repo_id}/github-sync", {
354
- params: { repo_id }
355
- });
356
- } catch (error) {
357
- if (error.message?.includes("404")) {
358
- return null;
359
- }
360
- throw error;
361
- }
362
- }
363
- async createDnsRecord(body) {
364
- return this.apiClient.post("/dns/v1/records", { body });
365
- }
366
- async listDnsRecords(query) {
367
- return this.apiClient.get("/dns/v1/records", { query });
368
- }
369
- async deleteDnsRecord(query) {
370
- return this.apiClient.delete("/dns/v1/records", { query });
371
- }
372
- fetch(path, init) {
373
- const headers = new Headers(init?.headers);
374
- if (!headers.has("Authorization")) {
375
- headers.append("Authorization", `Bearer ${this.options.apiKey}`);
376
- }
377
- if (!headers.has("Content-Type") && init?.body) {
378
- headers.append("Content-Type", "application/json");
379
- }
380
- const url = new URL(path, this.options.baseUrl ?? "https://api.freestyle.sh");
381
- return fetch(url, {
382
- ...init ?? {},
383
- headers
384
- });
385
- }
386
- }
387
- var src_default = Freestyle;
388
- export {
389
- src_default as default,
390
- Freestyle
391
- };