freestyle-sandboxes 0.0.97 → 0.1.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/README.md +39 -48
- package/index.cjs +4381 -0
- package/index.d.cts +9404 -0
- package/index.d.mts +9404 -0
- package/index.mjs +4367 -0
- package/package.json +16 -109
- package/dist/ai/inde.d.cts +0 -75
- package/dist/ai/inde.d.mts +0 -75
- package/dist/ai/index.cjs +0 -13
- package/dist/ai/index.d.cts +0 -75
- package/dist/ai/index.d.mts +0 -75
- package/dist/ai/index.mjs +0 -4
- package/dist/expo/inde.d.cts +0 -6
- package/dist/expo/inde.d.mts +0 -6
- package/dist/expo/index.cjs +0 -319
- package/dist/expo/index.d.cts +0 -6
- package/dist/expo/index.d.mts +0 -6
- package/dist/expo/index.mjs +0 -297
- package/dist/inde.d.cts +0 -373
- package/dist/inde.d.mts +0 -373
- package/dist/index-BKAG8L-o.mjs +0 -3061
- package/dist/index-DuOpIaWc.cjs +0 -3068
- package/dist/index.cjs +0 -1329
- package/dist/index.d-9H_wnIbz.d.ts +0 -4223
- package/dist/index.d.cts +0 -373
- package/dist/index.d.mts +0 -373
- package/dist/index.mjs +0 -1327
- package/dist/langgraph/inde.d.cts +0 -4180
- package/dist/langgraph/inde.d.mts +0 -4180
- package/dist/langgraph/index.cjs +0 -17155
- package/dist/langgraph/index.d.cts +0 -4180
- package/dist/langgraph/index.d.mts +0 -4180
- package/dist/langgraph/index.mjs +0 -17153
- package/dist/mastra/inde.d.cts +0 -2623
- package/dist/mastra/inde.d.mts +0 -2623
- package/dist/mastra/index.cjs +0 -55
- package/dist/mastra/index.d.cts +0 -2623
- package/dist/mastra/index.d.mts +0 -2623
- package/dist/mastra/index.mjs +0 -53
- package/dist/react/dev-server/index..d.cts +0 -33
- package/dist/react/dev-server/index..d.mts +0 -33
- package/dist/react/dev-server/index.cjs +0 -148
- package/dist/react/dev-server/index.d.cts +0 -33
- package/dist/react/dev-server/index.d.mts +0 -33
- package/dist/react/dev-server/index.mjs +0 -145
- package/dist/types.gen-CJa21P0C.d.ts +0 -1902
- package/dist/types.gen-DKjMRuu5.d.ts +0 -1898
- package/dist/utils/inde.d.cts +0 -10
- package/dist/utils/inde.d.mts +0 -10
- package/dist/utils/index.cjs +0 -100
- package/dist/utils/index.d.cts +0 -10
- package/dist/utils/index.d.mts +0 -10
- package/dist/utils/index.mjs +0 -75
- package/openapi/index.ts +0 -3
- package/openapi/sdk.gen.ts +0 -929
- package/openapi/types.gen.ts +0 -2234
- package/openapi-ts.config.ts +0 -7
- package/openapi.json +0 -1
- package/src/ai/index.ts +0 -164
- package/src/dev-server.ts +0 -95
- package/src/expo/_expo_internals.ts +0 -389
- package/src/expo/index.ts +0 -26
- package/src/index.ts +0 -1459
- package/src/langgraph/index.ts +0 -33
- package/src/mastra/index.ts +0 -38
- package/src/react/dev-server/index.tsx +0 -195
- package/src/react/dev-server/types.ts +0 -5
- package/src/utils/index.ts +0 -97
- package/tsconfig.json +0 -8
package/dist/index.mjs
DELETED
|
@@ -1,1327 +0,0 @@
|
|
|
1
|
-
import { createClient, createConfig } from '@hey-api/client-fetch';
|
|
2
|
-
|
|
3
|
-
const client = createClient(createConfig());
|
|
4
|
-
const handleDeployCloudstate = (options) => {
|
|
5
|
-
return (options?.client ?? client).post({
|
|
6
|
-
...options,
|
|
7
|
-
url: "/cloudstate/v1/deploy"
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
const handleBackupCloudstate = (options) => {
|
|
11
|
-
return (options?.client ?? client).get({
|
|
12
|
-
...options,
|
|
13
|
-
url: "/cloudstate/v1/projects/{id}/backup"
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
const handleVerifyWildcard = (options) => {
|
|
17
|
-
return (options?.client ?? client).post({
|
|
18
|
-
...options,
|
|
19
|
-
url: "/domains/v1/certs/{domain}/wildcard"
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const handleListDomains = (options) => {
|
|
23
|
-
return (options?.client ?? client).get({
|
|
24
|
-
...options,
|
|
25
|
-
url: "/domains/v1/domains"
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
const handleListDomainMappings = (options) => {
|
|
29
|
-
return (options?.client ?? client).get({
|
|
30
|
-
...options,
|
|
31
|
-
url: "/domains/v1/mappings"
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const handleInsertDomainMapping = (options) => {
|
|
35
|
-
return (options?.client ?? client).post({
|
|
36
|
-
...options,
|
|
37
|
-
url: "/domains/v1/mappings/{domain}"
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
const handleDeleteDomainMapping = (options) => {
|
|
41
|
-
return (options?.client ?? client).delete({
|
|
42
|
-
...options,
|
|
43
|
-
url: "/domains/v1/mappings/{domain}"
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
const handleListDomainVerificationRequests = (options) => {
|
|
47
|
-
return (options?.client ?? client).get({
|
|
48
|
-
...options,
|
|
49
|
-
url: "/domains/v1/verifications"
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const handleVerifyDomain = (options) => {
|
|
53
|
-
return (options?.client ?? client).put({
|
|
54
|
-
...options,
|
|
55
|
-
url: "/domains/v1/verifications"
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
const handleCreateDomainVerification = (options) => {
|
|
59
|
-
return (options?.client ?? client).post({
|
|
60
|
-
...options,
|
|
61
|
-
url: "/domains/v1/verifications"
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
const handleDeleteDomainVerification = (options) => {
|
|
65
|
-
return (options?.client ?? client).delete({
|
|
66
|
-
...options,
|
|
67
|
-
url: "/domains/v1/verifications"
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
const handleEphemeralDevServer = (options) => {
|
|
71
|
-
return (options?.client ?? client).post({
|
|
72
|
-
...options,
|
|
73
|
-
url: "/ephemeral/v1/dev-servers"
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
const handleExecOnEphemeralDevServer = (options) => {
|
|
77
|
-
return (options?.client ?? client).post({
|
|
78
|
-
...options,
|
|
79
|
-
url: "/ephemeral/v1/dev-servers/exec"
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
const handleWriteFileFromEphemeralDevServer = (options) => {
|
|
83
|
-
return (options?.client ?? client).put({
|
|
84
|
-
...options,
|
|
85
|
-
url: "/ephemeral/v1/dev-servers/files/{filepath}"
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
const handleReadFileFromEphemeralDevServer = (options) => {
|
|
89
|
-
return (options?.client ?? client).post({
|
|
90
|
-
...options,
|
|
91
|
-
url: "/ephemeral/v1/dev-servers/files/{filepath}"
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
const handleGitCommitPush = (options) => {
|
|
95
|
-
return (options?.client ?? client).post({
|
|
96
|
-
...options,
|
|
97
|
-
url: "/ephemeral/v1/dev-servers/git/commit-push"
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
const handleShutdownDevServer = (options) => {
|
|
101
|
-
return (options?.client ?? client).post({
|
|
102
|
-
...options,
|
|
103
|
-
url: "/ephemeral/v1/dev-servers/shutdown"
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
const handleDevServerStatus = (options) => {
|
|
107
|
-
return (options?.client ?? client).get({
|
|
108
|
-
...options,
|
|
109
|
-
url: "/ephemeral/v1/dev-servers/status"
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
const handleListExecuteRuns = (options) => {
|
|
113
|
-
return (options?.client ?? client).get({
|
|
114
|
-
...options,
|
|
115
|
-
url: "/execute/v1/deployments"
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
const handleGetExecuteRun = (options) => {
|
|
119
|
-
return (options?.client ?? client).get({
|
|
120
|
-
...options,
|
|
121
|
-
url: "/execute/v1/deployments/{deployment}"
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
const handleExecuteScript = (options) => {
|
|
125
|
-
return (options?.client ?? client).post({
|
|
126
|
-
...options,
|
|
127
|
-
url: "/execute/v1/script"
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
const handleCreateIdentity = (options) => {
|
|
131
|
-
return (options?.client ?? client).post({
|
|
132
|
-
...options,
|
|
133
|
-
url: "/git/v1/identity"
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
const handleDeleteIdentity = (options) => {
|
|
137
|
-
return (options?.client ?? client).delete({
|
|
138
|
-
...options,
|
|
139
|
-
url: "/git/v1/identity/{identity}"
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
const handleListPermissions = (options) => {
|
|
143
|
-
return (options?.client ?? client).get({
|
|
144
|
-
...options,
|
|
145
|
-
url: "/git/v1/identity/{identity}/permissions"
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
const handleDescribePermission = (options) => {
|
|
149
|
-
return (options?.client ?? client).get({
|
|
150
|
-
...options,
|
|
151
|
-
url: "/git/v1/identity/{identity}/permissions/{repo}"
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
const handleGrantPermission = (options) => {
|
|
155
|
-
return (options?.client ?? client).post({
|
|
156
|
-
...options,
|
|
157
|
-
url: "/git/v1/identity/{identity}/permissions/{repo}"
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
const handleRevokePermission = (options) => {
|
|
161
|
-
return (options?.client ?? client).delete({
|
|
162
|
-
...options,
|
|
163
|
-
url: "/git/v1/identity/{identity}/permissions/{repo}"
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
const handleUpdatePermission = (options) => {
|
|
167
|
-
return (options?.client ?? client).patch({
|
|
168
|
-
...options,
|
|
169
|
-
url: "/git/v1/identity/{identity}/permissions/{repo}"
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
const handleListGitTokens = (options) => {
|
|
173
|
-
return (options?.client ?? client).get({
|
|
174
|
-
...options,
|
|
175
|
-
url: "/git/v1/identity/{identity}/tokens"
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
const handleCreateGitToken = (options) => {
|
|
179
|
-
return (options?.client ?? client).post({
|
|
180
|
-
...options,
|
|
181
|
-
url: "/git/v1/identity/{identity}/tokens"
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
const handleRevokeGitToken = (options) => {
|
|
185
|
-
return (options?.client ?? client).delete({
|
|
186
|
-
...options,
|
|
187
|
-
url: "/git/v1/identity/{identity}/tokens"
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
const handleListRepositories = (options) => {
|
|
191
|
-
return (options?.client ?? client).get({
|
|
192
|
-
...options,
|
|
193
|
-
url: "/git/v1/repo"
|
|
194
|
-
});
|
|
195
|
-
};
|
|
196
|
-
const handleCreateRepo = (options) => {
|
|
197
|
-
return (options?.client ?? client).post({
|
|
198
|
-
...options,
|
|
199
|
-
url: "/git/v1/repo"
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
const handleGetDefaultBranch = (options) => {
|
|
203
|
-
return (options?.client ?? client).get({
|
|
204
|
-
...options,
|
|
205
|
-
url: "/git/v1/repo/{repo_id}/default-branch"
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
const handleSetDefaultBranch = (options) => {
|
|
209
|
-
return (options?.client ?? client).put({
|
|
210
|
-
...options,
|
|
211
|
-
url: "/git/v1/repo/{repo_id}/default-branch"
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
const getGithubSync = (options) => {
|
|
215
|
-
return (options?.client ?? client).get({
|
|
216
|
-
...options,
|
|
217
|
-
url: "/git/v1/repo/{repo_id}/github-sync"
|
|
218
|
-
});
|
|
219
|
-
};
|
|
220
|
-
const configureGithubSync = (options) => {
|
|
221
|
-
return (options?.client ?? client).post({
|
|
222
|
-
...options,
|
|
223
|
-
url: "/git/v1/repo/{repo_id}/github-sync"
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
const removeGithubSync = (options) => {
|
|
227
|
-
return (options?.client ?? client).delete({
|
|
228
|
-
...options,
|
|
229
|
-
url: "/git/v1/repo/{repo_id}/github-sync"
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
const handleDeleteRepo = (options) => {
|
|
233
|
-
return (options?.client ?? client).delete({
|
|
234
|
-
...options,
|
|
235
|
-
url: "/git/v1/repo/{repo}"
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
const handleGetContents = (options) => {
|
|
239
|
-
return (options?.client ?? client).get({
|
|
240
|
-
...options,
|
|
241
|
-
url: "/git/v1/repo/{repo}/contents/{path}"
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
|
-
const handleListGitTriggers = (options) => {
|
|
245
|
-
return (options?.client ?? client).get({
|
|
246
|
-
...options,
|
|
247
|
-
url: "/git/v1/repo/{repo}/trigger"
|
|
248
|
-
});
|
|
249
|
-
};
|
|
250
|
-
const handleCreateGitTrigger = (options) => {
|
|
251
|
-
return (options?.client ?? client).post({
|
|
252
|
-
...options,
|
|
253
|
-
url: "/git/v1/repo/{repo}/trigger"
|
|
254
|
-
});
|
|
255
|
-
};
|
|
256
|
-
const handleDeleteGitTrigger = (options) => {
|
|
257
|
-
return (options?.client ?? client).delete({
|
|
258
|
-
...options,
|
|
259
|
-
url: "/git/v1/repo/{repo}/trigger/{trigger}"
|
|
260
|
-
});
|
|
261
|
-
};
|
|
262
|
-
const handleGetLogs = (options) => {
|
|
263
|
-
return (options?.client ?? client).get({
|
|
264
|
-
...options,
|
|
265
|
-
url: "/observability/v1/logs"
|
|
266
|
-
});
|
|
267
|
-
};
|
|
268
|
-
const handleDeployWebV2 = (options) => {
|
|
269
|
-
return (options?.client ?? client).post({
|
|
270
|
-
...options,
|
|
271
|
-
url: "/web/v1/deployment"
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
const handleListWebDeploys = (options) => {
|
|
275
|
-
return (options?.client ?? client).get({
|
|
276
|
-
...options,
|
|
277
|
-
url: "/web/v1/deployments"
|
|
278
|
-
});
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
class FreestyleSandboxes {
|
|
282
|
-
client;
|
|
283
|
-
options;
|
|
284
|
-
constructor(options) {
|
|
285
|
-
this.options = options ?? {};
|
|
286
|
-
if (!options?.apiKey) {
|
|
287
|
-
this.options.apiKey = process.env.FREESTYLE_API_KEY;
|
|
288
|
-
}
|
|
289
|
-
if (typeof Deno !== "undefined") {
|
|
290
|
-
class FreestyleRequest extends Request {
|
|
291
|
-
constructor(input, init) {
|
|
292
|
-
if (init.client !== void 0) {
|
|
293
|
-
console.warn("Unsupported client detected, using default client");
|
|
294
|
-
delete init.client;
|
|
295
|
-
}
|
|
296
|
-
super(input, init);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
Request = FreestyleRequest;
|
|
300
|
-
}
|
|
301
|
-
this.client = createClient({
|
|
302
|
-
baseUrl: this.options?.baseUrl ?? "https://api.freestyle.sh",
|
|
303
|
-
headers: {
|
|
304
|
-
Authorization: `Bearer ${this.options.apiKey}`,
|
|
305
|
-
...this.options?.headers
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Execute a script in a sandbox.
|
|
311
|
-
*/
|
|
312
|
-
async executeScript(script, config) {
|
|
313
|
-
const response = await handleExecuteScript({
|
|
314
|
-
client: this.client,
|
|
315
|
-
body: {
|
|
316
|
-
script,
|
|
317
|
-
config
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
if (response.data) {
|
|
321
|
-
return response.data;
|
|
322
|
-
}
|
|
323
|
-
throw {
|
|
324
|
-
message: `Failed to execute script:
|
|
325
|
-
|
|
326
|
-
${script}
|
|
327
|
-
|
|
328
|
-
Error:
|
|
329
|
-
|
|
330
|
-
${JSON.stringify(
|
|
331
|
-
response
|
|
332
|
-
)}`,
|
|
333
|
-
error: response.error
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Deploy a Web project to a sandbox.
|
|
338
|
-
*/
|
|
339
|
-
async deployWeb(source, config) {
|
|
340
|
-
const response = await handleDeployWebV2({
|
|
341
|
-
client: this.client,
|
|
342
|
-
body: {
|
|
343
|
-
source,
|
|
344
|
-
config
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
if (response.data) {
|
|
348
|
-
return response.data;
|
|
349
|
-
}
|
|
350
|
-
throw new Error(
|
|
351
|
-
`Failed to deploy web project
|
|
352
|
-
|
|
353
|
-
Status: ${response.response.status}
|
|
354
|
-
|
|
355
|
-
Message: ${response.error}`
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Deploy a Cloudstate project to a sandbox.
|
|
360
|
-
*/
|
|
361
|
-
async deployCloudstate(body) {
|
|
362
|
-
const response = await handleDeployCloudstate({
|
|
363
|
-
client: this.client,
|
|
364
|
-
body
|
|
365
|
-
});
|
|
366
|
-
if (response.data) {
|
|
367
|
-
return response.data;
|
|
368
|
-
}
|
|
369
|
-
throw new Error("Failed to deploy Cloudstate project");
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Get a backup of a Cloudstate project in a sandbox.
|
|
373
|
-
* @param id The ID of the Cloudstate project.
|
|
374
|
-
* @returns The backup of the Cloudstate project.
|
|
375
|
-
* @throws An error if the backup could not be retrieved.
|
|
376
|
-
*/
|
|
377
|
-
async backupCloudstate(id) {
|
|
378
|
-
const response = await handleBackupCloudstate({
|
|
379
|
-
client: this.client,
|
|
380
|
-
path: {
|
|
381
|
-
id
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
if (response.data) {
|
|
385
|
-
return response.data;
|
|
386
|
-
}
|
|
387
|
-
throw new Error("Failed to get backup of Cloudstate project");
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Get logs for an execute run, or web deployment.
|
|
391
|
-
* @param id The ID of the sandbox.
|
|
392
|
-
* @returns The logs for the sandbox.
|
|
393
|
-
* @throws An error if the logs could not be retrieved.
|
|
394
|
-
*/
|
|
395
|
-
async getLogs(id) {
|
|
396
|
-
const response = await handleGetLogs({
|
|
397
|
-
client: this.client,
|
|
398
|
-
query: {
|
|
399
|
-
deploymentId: id
|
|
400
|
-
}
|
|
401
|
-
// path: {
|
|
402
|
-
// id: id,
|
|
403
|
-
// },
|
|
404
|
-
});
|
|
405
|
-
if (response.data) {
|
|
406
|
-
return response.data;
|
|
407
|
-
}
|
|
408
|
-
throw new Error("Failed to get logs for sandbox");
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Create a a domain verification request.
|
|
412
|
-
* @param domain The domain to verify.
|
|
413
|
-
* @returns The domain verification token.
|
|
414
|
-
*/
|
|
415
|
-
async createDomainVerificationRequest(domain) {
|
|
416
|
-
const response = await handleCreateDomainVerification({
|
|
417
|
-
client: this.client,
|
|
418
|
-
body: {
|
|
419
|
-
domain
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
if (response.data) {
|
|
423
|
-
return response.data;
|
|
424
|
-
}
|
|
425
|
-
throw new Error(response.error.message);
|
|
426
|
-
}
|
|
427
|
-
async verifyDomainVerificationRequest(id) {
|
|
428
|
-
const response = await handleVerifyDomain({
|
|
429
|
-
client: this.client,
|
|
430
|
-
body: {
|
|
431
|
-
id
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
if (response.data) {
|
|
435
|
-
return response.data;
|
|
436
|
-
}
|
|
437
|
-
throw new Error(
|
|
438
|
-
`Failed to verify domain verification request with ID ${id}: ${response.error.message}`
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Verify a domain. Note, this requires the domain verification token to be already set up.
|
|
443
|
-
* @param domain The domain to verify.
|
|
444
|
-
* @returns The domain verification request.
|
|
445
|
-
*/
|
|
446
|
-
async verifyDomain(domain) {
|
|
447
|
-
const response = await handleVerifyDomain({
|
|
448
|
-
client: this.client,
|
|
449
|
-
body: {
|
|
450
|
-
domain
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
if (response.data) {
|
|
454
|
-
return response.data;
|
|
455
|
-
}
|
|
456
|
-
throw new Error(
|
|
457
|
-
`Failed to verify domain ${domain}: ${response.error.message}`
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
async listDomains() {
|
|
461
|
-
const response = await handleListDomains({
|
|
462
|
-
client: this.client
|
|
463
|
-
});
|
|
464
|
-
if (response.data) {
|
|
465
|
-
return response.data;
|
|
466
|
-
}
|
|
467
|
-
throw new Error(`Failed to list domains
|
|
468
|
-
${response.error.message}`);
|
|
469
|
-
}
|
|
470
|
-
async listDomainVerificationRequests() {
|
|
471
|
-
const response = await handleListDomainVerificationRequests(
|
|
472
|
-
{
|
|
473
|
-
client: this.client
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
if (response.data) {
|
|
477
|
-
return response.data;
|
|
478
|
-
}
|
|
479
|
-
throw new Error(
|
|
480
|
-
`Failed to list domain verification requests
|
|
481
|
-
${response.error.message}`
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
async deleteDomainVerificationRequest(domain, verificationCode) {
|
|
485
|
-
const response = await handleDeleteDomainVerification({
|
|
486
|
-
client: this.client,
|
|
487
|
-
body: {
|
|
488
|
-
domain,
|
|
489
|
-
verificationCode
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
if (response.data) {
|
|
493
|
-
return response.data;
|
|
494
|
-
}
|
|
495
|
-
throw new Error(
|
|
496
|
-
`Failed to delete domain verification request for domain ${domain}: ${response.error.message}`
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
async listWebDeployments(limit, offset) {
|
|
500
|
-
const response = await handleListWebDeploys({
|
|
501
|
-
client: this.client,
|
|
502
|
-
query: {
|
|
503
|
-
limit: limit ?? 10,
|
|
504
|
-
offset: offset ?? 0
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
if (response.data) {
|
|
508
|
-
return response.data;
|
|
509
|
-
}
|
|
510
|
-
throw new Error(
|
|
511
|
-
`Failed to list web deployments
|
|
512
|
-
${response.error.message}`
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
async listExecuteRuns(limit, offset) {
|
|
516
|
-
const response = await handleListExecuteRuns({
|
|
517
|
-
client: this.client,
|
|
518
|
-
query: {
|
|
519
|
-
limit: limit ?? 10,
|
|
520
|
-
offset: offset ?? 0
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
if (response.data) {
|
|
524
|
-
return response.data;
|
|
525
|
-
}
|
|
526
|
-
throw new Error(`Failed to list execute runs
|
|
527
|
-
${response.error.message}`);
|
|
528
|
-
}
|
|
529
|
-
async getExecuteRun(id) {
|
|
530
|
-
const response = await handleGetExecuteRun({
|
|
531
|
-
client: this.client,
|
|
532
|
-
path: {
|
|
533
|
-
deployment: id
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
if (response.data) {
|
|
537
|
-
return response.data;
|
|
538
|
-
}
|
|
539
|
-
throw new Error(
|
|
540
|
-
`Failed to get execute run with ID ${id}: ${response.error.message}`
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
/** Provision a wildcard certificate for domain. */
|
|
544
|
-
async provisionWildcard(domain) {
|
|
545
|
-
const response = await handleVerifyWildcard({
|
|
546
|
-
client: this.client,
|
|
547
|
-
path: {
|
|
548
|
-
domain
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
if (response.data) {
|
|
552
|
-
return response.data;
|
|
553
|
-
}
|
|
554
|
-
throw new Error(
|
|
555
|
-
`Failed to provision wildcard for domain ${domain}: ${response.error.message}`
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* Insert a domain mapping for a deployment.
|
|
560
|
-
*/
|
|
561
|
-
async insertDomainMapping({
|
|
562
|
-
domain,
|
|
563
|
-
deploymentId
|
|
564
|
-
}) {
|
|
565
|
-
const response = await handleInsertDomainMapping({
|
|
566
|
-
client: this.client,
|
|
567
|
-
path: {
|
|
568
|
-
domain
|
|
569
|
-
},
|
|
570
|
-
body: {
|
|
571
|
-
deploymentId
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
if (response.data) {
|
|
575
|
-
return response.data;
|
|
576
|
-
}
|
|
577
|
-
throw new Error(
|
|
578
|
-
`Failed to insert domain mapping for domain ${domain} and deployment ${deploymentId}: ${response.error.message}`
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* Remove a domain mapping for a deployment.
|
|
583
|
-
*/
|
|
584
|
-
async removeDomainMapping({
|
|
585
|
-
domain
|
|
586
|
-
}) {
|
|
587
|
-
const response = await handleDeleteDomainMapping({
|
|
588
|
-
client: this.client,
|
|
589
|
-
path: {
|
|
590
|
-
domain
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
if (response.response.ok) {
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
throw new Error(
|
|
597
|
-
`Failed to remove domain mapping for domain ${domain}: ${response.error}`
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
async listDomainMappings({
|
|
601
|
-
domain,
|
|
602
|
-
domainOwnership,
|
|
603
|
-
limit = 10,
|
|
604
|
-
offset = 0
|
|
605
|
-
}) {
|
|
606
|
-
const response = await handleListDomainMappings({
|
|
607
|
-
client: this.client,
|
|
608
|
-
query: {
|
|
609
|
-
limit,
|
|
610
|
-
offset,
|
|
611
|
-
domain,
|
|
612
|
-
domainOwnership
|
|
613
|
-
}
|
|
614
|
-
});
|
|
615
|
-
if (response.data) {
|
|
616
|
-
return response.data;
|
|
617
|
-
}
|
|
618
|
-
throw new Error(
|
|
619
|
-
`Failed to list domain mappings: ${JSON.stringify(response.error)}`
|
|
620
|
-
);
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Create a new git repository.
|
|
624
|
-
*/
|
|
625
|
-
async createGitRepository({
|
|
626
|
-
name,
|
|
627
|
-
public: pub = false,
|
|
628
|
-
source,
|
|
629
|
-
import: _import,
|
|
630
|
-
defaultBranch,
|
|
631
|
-
devServers
|
|
632
|
-
}) {
|
|
633
|
-
const response = await handleCreateRepo({
|
|
634
|
-
client: this.client,
|
|
635
|
-
body: {
|
|
636
|
-
name,
|
|
637
|
-
public: pub,
|
|
638
|
-
source,
|
|
639
|
-
import: _import,
|
|
640
|
-
defaultBranch,
|
|
641
|
-
devServers
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
if (response.data) {
|
|
645
|
-
return response.data;
|
|
646
|
-
}
|
|
647
|
-
throw new Error(
|
|
648
|
-
`Failed to create git repository ${name}: ${response.error}`
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* List git repositories.
|
|
653
|
-
*/
|
|
654
|
-
async listGitRepositories({
|
|
655
|
-
limit = 10,
|
|
656
|
-
offset = 0
|
|
657
|
-
} = {}) {
|
|
658
|
-
const response = await handleListRepositories({
|
|
659
|
-
client: this.client,
|
|
660
|
-
query: {
|
|
661
|
-
limit,
|
|
662
|
-
offset
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
if (response.data) {
|
|
666
|
-
return response.data;
|
|
667
|
-
}
|
|
668
|
-
throw new Error(`Failed to list git repositories: ${response.error}`);
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Delete a git repository.
|
|
672
|
-
*/
|
|
673
|
-
async deleteGitRepository({
|
|
674
|
-
repoId
|
|
675
|
-
}) {
|
|
676
|
-
const response = await handleDeleteRepo({
|
|
677
|
-
client: this.client,
|
|
678
|
-
path: {
|
|
679
|
-
repo: repoId
|
|
680
|
-
}
|
|
681
|
-
});
|
|
682
|
-
if (response.data) {
|
|
683
|
-
return response.data;
|
|
684
|
-
}
|
|
685
|
-
throw new Error(
|
|
686
|
-
`Failed to delete git repository ${repoId}: ${response.error}`
|
|
687
|
-
);
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Create a new git identity.
|
|
691
|
-
*/
|
|
692
|
-
async createGitIdentity() {
|
|
693
|
-
const response = await handleCreateIdentity({
|
|
694
|
-
client: this.client
|
|
695
|
-
});
|
|
696
|
-
if (response.data) {
|
|
697
|
-
return response.data;
|
|
698
|
-
}
|
|
699
|
-
throw new Error(`Failed to create git identity: ${response.error}`);
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Delete a git identity.
|
|
703
|
-
*/
|
|
704
|
-
async deleteGitIdentity({
|
|
705
|
-
identityId
|
|
706
|
-
}) {
|
|
707
|
-
const response = await handleDeleteIdentity({
|
|
708
|
-
client: this.client,
|
|
709
|
-
path: {
|
|
710
|
-
identity: identityId
|
|
711
|
-
}
|
|
712
|
-
});
|
|
713
|
-
if (response.data) {
|
|
714
|
-
return response.data;
|
|
715
|
-
}
|
|
716
|
-
throw new Error(`Failed to delete git identity: ${response.error}`);
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* Grant a git identity access to a repository.
|
|
720
|
-
*/
|
|
721
|
-
async grantGitPermission({
|
|
722
|
-
repoId,
|
|
723
|
-
identityId,
|
|
724
|
-
permission
|
|
725
|
-
}) {
|
|
726
|
-
const response = await handleGrantPermission({
|
|
727
|
-
client: this.client,
|
|
728
|
-
path: {
|
|
729
|
-
repo: repoId,
|
|
730
|
-
identity: identityId
|
|
731
|
-
},
|
|
732
|
-
body: {
|
|
733
|
-
permission
|
|
734
|
-
}
|
|
735
|
-
});
|
|
736
|
-
if (response.data) {
|
|
737
|
-
return response.data;
|
|
738
|
-
}
|
|
739
|
-
throw new Error(
|
|
740
|
-
`Failed to grant access to git identity ${identityId} for repository ${repoId}: ${response.error}`
|
|
741
|
-
);
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Update a git identity's permissions on a repository.
|
|
745
|
-
*/
|
|
746
|
-
async updateGitPermission({
|
|
747
|
-
repoId,
|
|
748
|
-
identityId,
|
|
749
|
-
permission
|
|
750
|
-
}) {
|
|
751
|
-
const response = await handleUpdatePermission({
|
|
752
|
-
client: this.client,
|
|
753
|
-
path: {
|
|
754
|
-
repo: repoId,
|
|
755
|
-
identity: identityId
|
|
756
|
-
},
|
|
757
|
-
body: {
|
|
758
|
-
permission
|
|
759
|
-
}
|
|
760
|
-
});
|
|
761
|
-
if (response.data) {
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
throw new Error(
|
|
765
|
-
`Failed to update permission for git identity ${identityId} for repository ${repoId}: ${response.error}`
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Revoke a git identity's access to a repository.
|
|
770
|
-
*/
|
|
771
|
-
async revokeGitPermission({
|
|
772
|
-
repoId,
|
|
773
|
-
identityId
|
|
774
|
-
}) {
|
|
775
|
-
const response = await handleRevokePermission({
|
|
776
|
-
client: this.client,
|
|
777
|
-
path: {
|
|
778
|
-
repo: repoId,
|
|
779
|
-
identity: identityId
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
if (response.data) {
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
throw new Error(
|
|
786
|
-
`Failed to revoke access to git identity ${identityId} for repository ${repoId}: ${response.error}`
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* List access permissions for a git identity.
|
|
791
|
-
*/
|
|
792
|
-
async listGitPermissions({
|
|
793
|
-
identityId
|
|
794
|
-
}) {
|
|
795
|
-
const response = await handleListPermissions({
|
|
796
|
-
client: this.client,
|
|
797
|
-
path: {
|
|
798
|
-
identity: identityId
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
if (response.data) {
|
|
802
|
-
return response.data;
|
|
803
|
-
}
|
|
804
|
-
throw new Error(
|
|
805
|
-
`Failed to list permissions for git identity ${identityId}: ${response.error}`
|
|
806
|
-
);
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* Get the permission of a git identity on a repository.
|
|
810
|
-
*/
|
|
811
|
-
async getGitPermission({
|
|
812
|
-
repoId,
|
|
813
|
-
identityId
|
|
814
|
-
}) {
|
|
815
|
-
const response = await handleDescribePermission({
|
|
816
|
-
client: this.client,
|
|
817
|
-
path: {
|
|
818
|
-
repo: repoId,
|
|
819
|
-
identity: identityId
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
if (response.data) {
|
|
823
|
-
return response.data;
|
|
824
|
-
}
|
|
825
|
-
throw new Error(
|
|
826
|
-
`Failed to get permission for git identity ${identityId} on repository ${repoId}: ${response.error}`
|
|
827
|
-
);
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Create a new git access token for an identity.
|
|
831
|
-
*/
|
|
832
|
-
async createGitAccessToken({
|
|
833
|
-
identityId
|
|
834
|
-
}) {
|
|
835
|
-
const response = await handleCreateGitToken({
|
|
836
|
-
client: this.client,
|
|
837
|
-
path: {
|
|
838
|
-
identity: identityId
|
|
839
|
-
}
|
|
840
|
-
});
|
|
841
|
-
if (response.data) {
|
|
842
|
-
return response.data;
|
|
843
|
-
}
|
|
844
|
-
throw new Error(
|
|
845
|
-
`Failed to create git access token: ${response.error.message}`
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
|
-
* Revoke a git access token.
|
|
850
|
-
*/
|
|
851
|
-
async revokeGitAccessToken({
|
|
852
|
-
identityId,
|
|
853
|
-
tokenId
|
|
854
|
-
}) {
|
|
855
|
-
const response = await handleRevokeGitToken({
|
|
856
|
-
client: this.client,
|
|
857
|
-
body: {
|
|
858
|
-
tokenId
|
|
859
|
-
},
|
|
860
|
-
path: {
|
|
861
|
-
identity: identityId
|
|
862
|
-
}
|
|
863
|
-
});
|
|
864
|
-
if (response.data) {
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
throw new Error(
|
|
868
|
-
`Failed to revoke git access token ${tokenId}: ${response.error.message}`
|
|
869
|
-
);
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* List git access tokens for an identity.
|
|
873
|
-
*/
|
|
874
|
-
async listGitAccessTokens({
|
|
875
|
-
identityId
|
|
876
|
-
}) {
|
|
877
|
-
const response = await handleListGitTokens({
|
|
878
|
-
client: this.client,
|
|
879
|
-
path: {
|
|
880
|
-
identity: identityId
|
|
881
|
-
}
|
|
882
|
-
});
|
|
883
|
-
if (response.data) {
|
|
884
|
-
return response.data;
|
|
885
|
-
}
|
|
886
|
-
throw new Error(
|
|
887
|
-
`Failed to list git access tokens: ${response.error.message}`
|
|
888
|
-
);
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* List git triggers for a repository.
|
|
892
|
-
*/
|
|
893
|
-
async listGitTriggers({
|
|
894
|
-
repoId
|
|
895
|
-
}) {
|
|
896
|
-
const response = await handleListGitTriggers({
|
|
897
|
-
client: this.client,
|
|
898
|
-
path: {
|
|
899
|
-
repo: repoId
|
|
900
|
-
}
|
|
901
|
-
});
|
|
902
|
-
if (response.data) {
|
|
903
|
-
return response.data;
|
|
904
|
-
}
|
|
905
|
-
throw new Error(
|
|
906
|
-
`Failed to list git triggers for repository ${repoId}: ${response.error.message}`
|
|
907
|
-
);
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Create a git trigger for a repository.
|
|
911
|
-
*/
|
|
912
|
-
async createGitTrigger({
|
|
913
|
-
repoId,
|
|
914
|
-
trigger,
|
|
915
|
-
action
|
|
916
|
-
}) {
|
|
917
|
-
const response = await handleCreateGitTrigger({
|
|
918
|
-
client: this.client,
|
|
919
|
-
path: {
|
|
920
|
-
repo: repoId
|
|
921
|
-
},
|
|
922
|
-
body: {
|
|
923
|
-
trigger,
|
|
924
|
-
action
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
if (response.data) {
|
|
928
|
-
return response.data;
|
|
929
|
-
}
|
|
930
|
-
throw new Error(
|
|
931
|
-
`Failed to create git trigger for repository ${repoId}: ${response.error.message}`
|
|
932
|
-
);
|
|
933
|
-
}
|
|
934
|
-
/**
|
|
935
|
-
* Delete a git trigger.
|
|
936
|
-
*/
|
|
937
|
-
async deleteGitTrigger({
|
|
938
|
-
triggerId,
|
|
939
|
-
repo
|
|
940
|
-
}) {
|
|
941
|
-
const response = await handleDeleteGitTrigger({
|
|
942
|
-
client: this.client,
|
|
943
|
-
path: {
|
|
944
|
-
trigger: triggerId,
|
|
945
|
-
repo
|
|
946
|
-
}
|
|
947
|
-
});
|
|
948
|
-
if (response.data) {
|
|
949
|
-
return;
|
|
950
|
-
}
|
|
951
|
-
throw new Error(
|
|
952
|
-
`Failed to delete git trigger ${triggerId}: ${response.error.message}`
|
|
953
|
-
);
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Set the default branch for a git repository.
|
|
957
|
-
*/
|
|
958
|
-
async setGitRepoDefaultBranch({
|
|
959
|
-
repoId,
|
|
960
|
-
defaultBranch
|
|
961
|
-
}) {
|
|
962
|
-
const response = await handleSetDefaultBranch({
|
|
963
|
-
client: this.client,
|
|
964
|
-
path: {
|
|
965
|
-
repo_id: repoId
|
|
966
|
-
},
|
|
967
|
-
body: {
|
|
968
|
-
defaultBranch
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
if (response.error) {
|
|
972
|
-
throw new Error(`Failed to set default branch: ${response.error}`);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
/**
|
|
976
|
-
* Get the default branch for a git repository.
|
|
977
|
-
*/
|
|
978
|
-
async getGitRepoDefaultBranch({
|
|
979
|
-
repoId
|
|
980
|
-
}) {
|
|
981
|
-
const response = await handleGetDefaultBranch({
|
|
982
|
-
client: this.client,
|
|
983
|
-
path: { repo_id: repoId }
|
|
984
|
-
});
|
|
985
|
-
if (response.data) {
|
|
986
|
-
return response.data.defaultBranch;
|
|
987
|
-
}
|
|
988
|
-
throw new Error(
|
|
989
|
-
`Failed to get default branch for repository ${repoId}: ${response.error}`
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Get the contents of a git repository at the given path.
|
|
994
|
-
*/
|
|
995
|
-
async getGitRepoContents({
|
|
996
|
-
repoId,
|
|
997
|
-
path,
|
|
998
|
-
ref
|
|
999
|
-
}) {
|
|
1000
|
-
const response = await handleGetContents({
|
|
1001
|
-
client: this.client,
|
|
1002
|
-
path: {
|
|
1003
|
-
repo: repoId,
|
|
1004
|
-
path: path ?? "",
|
|
1005
|
-
"*path": path ?? null
|
|
1006
|
-
},
|
|
1007
|
-
query: {
|
|
1008
|
-
ref
|
|
1009
|
-
}
|
|
1010
|
-
});
|
|
1011
|
-
if (response.data) {
|
|
1012
|
-
return response.data;
|
|
1013
|
-
}
|
|
1014
|
-
throw new Error(
|
|
1015
|
-
`Failed to get git repository contents: ${response.error.message}`
|
|
1016
|
-
);
|
|
1017
|
-
}
|
|
1018
|
-
/**
|
|
1019
|
-
* Configure a git repository to sync with GitHub.
|
|
1020
|
-
*/
|
|
1021
|
-
async configureGitRepoGitHubSync({
|
|
1022
|
-
repoId,
|
|
1023
|
-
githubRepoName
|
|
1024
|
-
}) {
|
|
1025
|
-
const response = await configureGithubSync({
|
|
1026
|
-
client: this.client,
|
|
1027
|
-
path: {
|
|
1028
|
-
repo_id: repoId
|
|
1029
|
-
},
|
|
1030
|
-
body: {
|
|
1031
|
-
githubRepoName
|
|
1032
|
-
}
|
|
1033
|
-
});
|
|
1034
|
-
if (response.error) {
|
|
1035
|
-
throw new Error(`Failed to configure GitHub sync: ${response.error}`);
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
/**
|
|
1039
|
-
* Remove the GitHub sync configuration for a git repository.
|
|
1040
|
-
*/
|
|
1041
|
-
async removeGitRepoGitHubSync({ repoId }) {
|
|
1042
|
-
const response = await removeGithubSync({
|
|
1043
|
-
client: this.client,
|
|
1044
|
-
path: {
|
|
1045
|
-
repo_id: repoId
|
|
1046
|
-
}
|
|
1047
|
-
});
|
|
1048
|
-
if (response.error) {
|
|
1049
|
-
throw new Error(`Failed to remove GitHub sync: ${response.error}`);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
/**
|
|
1053
|
-
* Get the GitHub sync configuration for a git repository.
|
|
1054
|
-
*/
|
|
1055
|
-
async getGitRepoGitHubSyncConfig({
|
|
1056
|
-
repoId
|
|
1057
|
-
}) {
|
|
1058
|
-
const response = await getGithubSync({
|
|
1059
|
-
client: this.client,
|
|
1060
|
-
path: {
|
|
1061
|
-
repo_id: repoId
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
1064
|
-
if (response.response.status === 404) {
|
|
1065
|
-
return null;
|
|
1066
|
-
}
|
|
1067
|
-
if (response.error) {
|
|
1068
|
-
throw new Error(`Failed to get GitHub sync config: ${response.error}`);
|
|
1069
|
-
}
|
|
1070
|
-
return response.data ?? null;
|
|
1071
|
-
}
|
|
1072
|
-
/**
|
|
1073
|
-
* Request a dev server for a repository. If a dev server is already running
|
|
1074
|
-
* for that repository, it will return a url to that server. Dev servers are
|
|
1075
|
-
* ephemeral so you should call this function every time you need a url. Do
|
|
1076
|
-
* not store the url in your database!
|
|
1077
|
-
*/
|
|
1078
|
-
async requestDevServer(options) {
|
|
1079
|
-
function formatHook(serverUrl, repoUrl) {
|
|
1080
|
-
const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl);
|
|
1081
|
-
return hook;
|
|
1082
|
-
}
|
|
1083
|
-
const response = await handleEphemeralDevServer({
|
|
1084
|
-
client: this.client,
|
|
1085
|
-
body: {
|
|
1086
|
-
...options,
|
|
1087
|
-
// @ts-ignore
|
|
1088
|
-
repo: options.repoUrl
|
|
1089
|
-
}
|
|
1090
|
-
});
|
|
1091
|
-
if (response.error) {
|
|
1092
|
-
throw new Error(
|
|
1093
|
-
// @ts-ignore
|
|
1094
|
-
`Failed to request dev server: ${response.error.message}`
|
|
1095
|
-
);
|
|
1096
|
-
}
|
|
1097
|
-
if (response.data.isNew) {
|
|
1098
|
-
const rId = options.repoId || options.repoUrl?.split("/").at(-1);
|
|
1099
|
-
await this.createGitTrigger({
|
|
1100
|
-
repoId: rId,
|
|
1101
|
-
action: {
|
|
1102
|
-
endpoint: formatHook(
|
|
1103
|
-
response.data?.url,
|
|
1104
|
-
options.repoUrl || `https://git.freestyle.sh/${rId}`
|
|
1105
|
-
),
|
|
1106
|
-
action: "webhook"
|
|
1107
|
-
},
|
|
1108
|
-
trigger: {
|
|
1109
|
-
event: "push"
|
|
1110
|
-
}
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
if (!response.data) {
|
|
1114
|
-
throw new Error(`Failed to request dev server: ${response.error}`);
|
|
1115
|
-
}
|
|
1116
|
-
const data = response.data;
|
|
1117
|
-
const devServerInstance = {
|
|
1118
|
-
repoId: options.repoId || options.repo || "",
|
|
1119
|
-
kind: "repo",
|
|
1120
|
-
gitRef: options.gitRef
|
|
1121
|
-
};
|
|
1122
|
-
const client = this.client;
|
|
1123
|
-
const that = this;
|
|
1124
|
-
return {
|
|
1125
|
-
...response.data,
|
|
1126
|
-
isNew: data.isNew,
|
|
1127
|
-
ephemeralUrl: data.ephemeralUrl ?? data.url,
|
|
1128
|
-
mcpEphemeralUrl: data.mcpEphemeralUrl ?? data.url + "/mcp",
|
|
1129
|
-
codeServerUrl: data.codeServerUrl ?? (data.ephemeralUrl ?? data.url) + "/__freestyle_code_server/?folder=/template",
|
|
1130
|
-
async status() {
|
|
1131
|
-
const response2 = await handleDevServerStatus({
|
|
1132
|
-
client,
|
|
1133
|
-
body: {
|
|
1134
|
-
devServer: devServerInstance
|
|
1135
|
-
}
|
|
1136
|
-
});
|
|
1137
|
-
if (response2.error) {
|
|
1138
|
-
throw new Error(`Failed to get status: ${response2.error}`);
|
|
1139
|
-
}
|
|
1140
|
-
return {
|
|
1141
|
-
installing: response2.data.installing,
|
|
1142
|
-
devRunning: response2.data.devRunning
|
|
1143
|
-
};
|
|
1144
|
-
},
|
|
1145
|
-
async commitAndPush(message) {
|
|
1146
|
-
const response2 = await handleGitCommitPush({
|
|
1147
|
-
client,
|
|
1148
|
-
body: {
|
|
1149
|
-
devServer: devServerInstance,
|
|
1150
|
-
message
|
|
1151
|
-
}
|
|
1152
|
-
});
|
|
1153
|
-
if (response2.error) {
|
|
1154
|
-
throw new Error(`Failed to commit and push: ${response2.error}`);
|
|
1155
|
-
}
|
|
1156
|
-
},
|
|
1157
|
-
async shutdown() {
|
|
1158
|
-
const response2 = await handleShutdownDevServer({
|
|
1159
|
-
client,
|
|
1160
|
-
body: {
|
|
1161
|
-
devServer: devServerInstance
|
|
1162
|
-
}
|
|
1163
|
-
});
|
|
1164
|
-
if (response2.error) {
|
|
1165
|
-
throw new Error(`Failed to shutdown dev server: ${response2.error}`);
|
|
1166
|
-
}
|
|
1167
|
-
return {
|
|
1168
|
-
success: response2.data.success,
|
|
1169
|
-
message: response2.data.message
|
|
1170
|
-
};
|
|
1171
|
-
},
|
|
1172
|
-
fs: {
|
|
1173
|
-
async ls(path = "") {
|
|
1174
|
-
const response2 = await handleReadFileFromEphemeralDevServer({
|
|
1175
|
-
client,
|
|
1176
|
-
path: {
|
|
1177
|
-
filepath: path,
|
|
1178
|
-
"*filepath": path
|
|
1179
|
-
},
|
|
1180
|
-
body: {
|
|
1181
|
-
devServer: devServerInstance,
|
|
1182
|
-
encoding: "utf-8"
|
|
1183
|
-
}
|
|
1184
|
-
});
|
|
1185
|
-
if (response2.error) {
|
|
1186
|
-
throw new Error(`Failed to list directory: ${response2.error}`);
|
|
1187
|
-
}
|
|
1188
|
-
if (!response2.data?.content) {
|
|
1189
|
-
return [];
|
|
1190
|
-
}
|
|
1191
|
-
if (response2.data.content.kind === "directory") {
|
|
1192
|
-
return response2.data.content.files;
|
|
1193
|
-
}
|
|
1194
|
-
return [];
|
|
1195
|
-
},
|
|
1196
|
-
async *watch() {
|
|
1197
|
-
const response2 = await that.fetch(
|
|
1198
|
-
"/ephemeral/v1/dev-servers/watch-files",
|
|
1199
|
-
{
|
|
1200
|
-
method: "POST",
|
|
1201
|
-
body: JSON.stringify({
|
|
1202
|
-
devServer: {
|
|
1203
|
-
repoId: devServerInstance.repoId,
|
|
1204
|
-
kind: devServerInstance.kind
|
|
1205
|
-
}
|
|
1206
|
-
})
|
|
1207
|
-
}
|
|
1208
|
-
);
|
|
1209
|
-
if (!response2.ok) {
|
|
1210
|
-
throw new Error(
|
|
1211
|
-
`Failed to fetch stream: ${response2.status} ${response2.statusText}`
|
|
1212
|
-
);
|
|
1213
|
-
}
|
|
1214
|
-
if (!response2.body) {
|
|
1215
|
-
throw new Error("Failed to fetch stream: No response body");
|
|
1216
|
-
}
|
|
1217
|
-
const reader = response2.body.getReader();
|
|
1218
|
-
const decoder = new TextDecoder("utf-8");
|
|
1219
|
-
let buffer = "";
|
|
1220
|
-
while (true) {
|
|
1221
|
-
const { done, value } = await reader.read();
|
|
1222
|
-
if (done) break;
|
|
1223
|
-
buffer += decoder.decode(value, { stream: true });
|
|
1224
|
-
let newlineIndex;
|
|
1225
|
-
while ((newlineIndex = buffer.indexOf("\n")) >= 0) {
|
|
1226
|
-
const line = buffer.slice(0, newlineIndex).trim();
|
|
1227
|
-
buffer = buffer.slice(newlineIndex + 1);
|
|
1228
|
-
if (line) {
|
|
1229
|
-
yield JSON.parse(line);
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
if (buffer.trim()) {
|
|
1234
|
-
yield JSON.parse(buffer.trim());
|
|
1235
|
-
}
|
|
1236
|
-
},
|
|
1237
|
-
async readFile(path, encoding = "utf-8") {
|
|
1238
|
-
const response2 = await handleReadFileFromEphemeralDevServer({
|
|
1239
|
-
client,
|
|
1240
|
-
path: {
|
|
1241
|
-
filepath: path,
|
|
1242
|
-
"*filepath": path
|
|
1243
|
-
},
|
|
1244
|
-
body: {
|
|
1245
|
-
devServer: devServerInstance,
|
|
1246
|
-
encoding
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1249
|
-
if (response2.error) {
|
|
1250
|
-
throw new Error(`Failed to read file: ${response2.error}`);
|
|
1251
|
-
}
|
|
1252
|
-
if (!response2.data?.content || response2.data.content.kind !== "file") {
|
|
1253
|
-
throw new Error(`Not a file or file not found: ${path}`);
|
|
1254
|
-
}
|
|
1255
|
-
return response2.data.content.content;
|
|
1256
|
-
},
|
|
1257
|
-
async writeFile(path, content, encoding = "utf-8") {
|
|
1258
|
-
const contentStr = typeof content === "string" ? content : Buffer.from(content).toString(encoding);
|
|
1259
|
-
const response2 = await handleWriteFileFromEphemeralDevServer({
|
|
1260
|
-
client,
|
|
1261
|
-
path: {
|
|
1262
|
-
filepath: path,
|
|
1263
|
-
"*filepath": path
|
|
1264
|
-
},
|
|
1265
|
-
body: {
|
|
1266
|
-
devServer: devServerInstance,
|
|
1267
|
-
content: contentStr,
|
|
1268
|
-
encoding
|
|
1269
|
-
}
|
|
1270
|
-
});
|
|
1271
|
-
if (response2.error) {
|
|
1272
|
-
throw new Error(
|
|
1273
|
-
`Failed to write file: ${JSON.stringify(response2.error)}`
|
|
1274
|
-
);
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
},
|
|
1278
|
-
process: {
|
|
1279
|
-
async exec(cmd, background = false) {
|
|
1280
|
-
const response2 = await handleExecOnEphemeralDevServer(
|
|
1281
|
-
{
|
|
1282
|
-
client,
|
|
1283
|
-
body: {
|
|
1284
|
-
devServer: devServerInstance,
|
|
1285
|
-
command: cmd,
|
|
1286
|
-
background
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
);
|
|
1290
|
-
if (response2.error) {
|
|
1291
|
-
throw new Error(`Failed to execute command: ${response2.error}`);
|
|
1292
|
-
}
|
|
1293
|
-
return {
|
|
1294
|
-
id: response2.data.id,
|
|
1295
|
-
isNew: response2.data.isNew,
|
|
1296
|
-
stdout: response2.data.stdout,
|
|
1297
|
-
stderr: response2.data.stderr
|
|
1298
|
-
};
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
fetch(path, init) {
|
|
1304
|
-
const headers = new Headers(init?.headers);
|
|
1305
|
-
for (const [key, value] of Object.entries(this.options.headers ?? {})) {
|
|
1306
|
-
if (!headers.has(key)) {
|
|
1307
|
-
headers.append(key, value);
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
if (!headers.has("Authorization")) {
|
|
1311
|
-
headers.append("Authorization", `Bearer ${this.options.apiKey}`);
|
|
1312
|
-
}
|
|
1313
|
-
if (!headers.has("Content-Type")) {
|
|
1314
|
-
headers.append("Content-Type", "application/json");
|
|
1315
|
-
}
|
|
1316
|
-
const url = new URL(
|
|
1317
|
-
path,
|
|
1318
|
-
this.options.baseUrl ?? "https://api.freestyle.sh"
|
|
1319
|
-
);
|
|
1320
|
-
return fetch(url, {
|
|
1321
|
-
...init ?? {},
|
|
1322
|
-
headers
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
export { FreestyleSandboxes };
|