@prisma/cli 3.0.0-dev.99.1 → 8.0.0-rc.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/README.md +3 -1
- package/dist/cli.js +15115 -16
- package/dist/deploy-framework-C7bQM00A.js +23 -0
- package/dist/payload-B88Qvzxk-CrtTXSOe.js +34 -0
- package/dist/sender.js +192 -0
- package/package.json +22 -18
- package/dist/adapters/git.js +0 -54
- package/dist/adapters/local-state.js +0 -144
- package/dist/adapters/mock-api.js +0 -136
- package/dist/adapters/token-storage.js +0 -418
- package/dist/cli2.js +0 -119
- package/dist/commands/app/index.js +0 -345
- package/dist/commands/auth/index.js +0 -96
- package/dist/commands/branch/index.js +0 -27
- package/dist/commands/database/index.js +0 -159
- package/dist/commands/env.js +0 -99
- package/dist/commands/git/index.js +0 -36
- package/dist/commands/project/index.js +0 -69
- package/dist/commands/version/index.js +0 -18
- package/dist/controllers/app-env-api.js +0 -54
- package/dist/controllers/app-env-file.js +0 -181
- package/dist/controllers/app-env.js +0 -502
- package/dist/controllers/app.js +0 -2443
- package/dist/controllers/auth.js +0 -316
- package/dist/controllers/branch.js +0 -103
- package/dist/controllers/database.js +0 -318
- package/dist/controllers/project.js +0 -731
- package/dist/controllers/select-prompt-port.js +0 -12
- package/dist/controllers/version.js +0 -12
- package/dist/lib/app/app-interaction.js +0 -5
- package/dist/lib/app/app-provider.js +0 -544
- package/dist/lib/app/branch-database-api.js +0 -102
- package/dist/lib/app/branch-database-deploy.js +0 -325
- package/dist/lib/app/branch-database.js +0 -215
- package/dist/lib/app/build-settings.js +0 -93
- package/dist/lib/app/build.js +0 -80
- package/dist/lib/app/bun-project.js +0 -45
- package/dist/lib/app/compute-config.js +0 -147
- package/dist/lib/app/deploy-output.js +0 -24
- package/dist/lib/app/deploy-plan.js +0 -58
- package/dist/lib/app/deploy-progress.js +0 -100
- package/dist/lib/app/domain-guidance.js +0 -14
- package/dist/lib/app/env-config.js +0 -67
- package/dist/lib/app/env-file.js +0 -82
- package/dist/lib/app/env-vars.js +0 -50
- package/dist/lib/app/local-dev.js +0 -109
- package/dist/lib/app/production-deploy-gate.js +0 -161
- package/dist/lib/app/read-branch.js +0 -30
- package/dist/lib/auth/auth-ops.js +0 -158
- package/dist/lib/auth/client.js +0 -22
- package/dist/lib/auth/guard.js +0 -38
- package/dist/lib/auth/login.js +0 -330
- package/dist/lib/database/provider.js +0 -167
- package/dist/lib/diagnostics.js +0 -15
- package/dist/lib/fs/home-path.js +0 -24
- package/dist/lib/git/local-branch.js +0 -53
- package/dist/lib/git/local-status.js +0 -57
- package/dist/lib/project/interactive-setup.js +0 -56
- package/dist/lib/project/local-pin.js +0 -200
- package/dist/lib/project/resolution.js +0 -386
- package/dist/lib/project/setup.js +0 -135
- package/dist/lib/version.js +0 -55
- package/dist/output/patterns.js +0 -90
- package/dist/presenters/app-env.js +0 -265
- package/dist/presenters/app.js +0 -646
- package/dist/presenters/auth.js +0 -183
- package/dist/presenters/branch.js +0 -46
- package/dist/presenters/database.js +0 -274
- package/dist/presenters/project.js +0 -174
- package/dist/presenters/verbose-context.js +0 -64
- package/dist/presenters/version.js +0 -29
- package/dist/shell/command-arguments.js +0 -6
- package/dist/shell/command-meta.js +0 -622
- package/dist/shell/command-runner.js +0 -112
- package/dist/shell/diagnostics-output.js +0 -57
- package/dist/shell/errors.js +0 -134
- package/dist/shell/global-flags.js +0 -37
- package/dist/shell/help.js +0 -89
- package/dist/shell/output.js +0 -82
- package/dist/shell/prompt.js +0 -41
- package/dist/shell/runtime.js +0 -55
- package/dist/shell/ui.js +0 -116
- package/dist/shell/update-check.js +0 -247
- package/dist/use-cases/auth.js +0 -145
- package/dist/use-cases/branch.js +0 -47
- package/dist/use-cases/create-cli-gateways.js +0 -68
- package/dist/use-cases/project.js +0 -30
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { selectPrompt } from "../shell/prompt.js";
|
|
2
|
-
//#region src/controllers/select-prompt-port.ts
|
|
3
|
-
function createSelectPromptPort(context) {
|
|
4
|
-
return { select: ({ message, choices }) => selectPrompt({
|
|
5
|
-
input: context.runtime.stdin,
|
|
6
|
-
output: context.runtime.stderr,
|
|
7
|
-
message,
|
|
8
|
-
choices
|
|
9
|
-
}) };
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { createSelectPromptPort };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { buildVersionResult } from "../lib/version.js";
|
|
2
|
-
//#region src/controllers/version.ts
|
|
3
|
-
async function runVersion(context) {
|
|
4
|
-
return {
|
|
5
|
-
command: "version",
|
|
6
|
-
result: buildVersionResult(context.runtime.env, context.runtime.argv),
|
|
7
|
-
warnings: [],
|
|
8
|
-
nextSteps: []
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { runVersion };
|
|
@@ -1,544 +0,0 @@
|
|
|
1
|
-
import { createBranchDatabase, createEnvironmentVariable, deleteBranchDatabase, deleteEnvironmentVariable, listEnvironmentVariables, updateEnvironmentVariable } from "./branch-database-api.js";
|
|
2
|
-
import { AppBuildStrategy } from "./build.js";
|
|
3
|
-
import { envVarNames } from "./env-vars.js";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { ApiError, CancelledError, ComputeClient, streamLogs } from "@prisma/compute-sdk";
|
|
6
|
-
//#region src/lib/app/app-provider.ts
|
|
7
|
-
var DomainApiError = class extends Error {
|
|
8
|
-
status;
|
|
9
|
-
code;
|
|
10
|
-
hint;
|
|
11
|
-
constructor(options) {
|
|
12
|
-
super(`${options.summary}: ${options.message}${options.hint ? ` ${options.hint}` : ""}`);
|
|
13
|
-
this.name = "DomainApiError";
|
|
14
|
-
this.status = options.status;
|
|
15
|
-
this.code = options.code ?? null;
|
|
16
|
-
this.hint = options.hint ?? null;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
function createAppProvider(client, options) {
|
|
20
|
-
const sdk = new ComputeClient(client);
|
|
21
|
-
return {
|
|
22
|
-
async createProject(options) {
|
|
23
|
-
const projectResult = await sdk.createProject({
|
|
24
|
-
name: options.name,
|
|
25
|
-
signal: options.signal
|
|
26
|
-
});
|
|
27
|
-
if (projectResult.isErr()) throw new Error(projectResult.error.message);
|
|
28
|
-
return {
|
|
29
|
-
id: projectResult.value.id,
|
|
30
|
-
name: projectResult.value.name
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
async listApps(projectId, options) {
|
|
34
|
-
return listComputeServices(client, {
|
|
35
|
-
projectId,
|
|
36
|
-
branchGitName: options?.branchName,
|
|
37
|
-
signal: options?.signal
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
async resolveBranch(projectId, options) {
|
|
41
|
-
const branch = await resolveOrCreateBranch(client, {
|
|
42
|
-
projectId,
|
|
43
|
-
gitName: options.branchName,
|
|
44
|
-
signal: options.signal
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
id: branch.id,
|
|
48
|
-
name: branch.gitName,
|
|
49
|
-
role: branch.role
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
async createBranchDatabase(options) {
|
|
53
|
-
return createBranchDatabase(client, options);
|
|
54
|
-
},
|
|
55
|
-
async deleteBranchDatabase(options) {
|
|
56
|
-
return deleteBranchDatabase(client, options);
|
|
57
|
-
},
|
|
58
|
-
async listEnvironmentVariables(options) {
|
|
59
|
-
return listEnvironmentVariables(client, options);
|
|
60
|
-
},
|
|
61
|
-
async createEnvironmentVariable(options) {
|
|
62
|
-
return createEnvironmentVariable(client, options);
|
|
63
|
-
},
|
|
64
|
-
async updateEnvironmentVariable(options) {
|
|
65
|
-
return updateEnvironmentVariable(client, options);
|
|
66
|
-
},
|
|
67
|
-
async deleteEnvironmentVariable(options) {
|
|
68
|
-
return deleteEnvironmentVariable(client, options);
|
|
69
|
-
},
|
|
70
|
-
async removeApp(appId, options) {
|
|
71
|
-
const appResult = await sdk.showService({
|
|
72
|
-
serviceId: appId,
|
|
73
|
-
signal: options?.signal
|
|
74
|
-
});
|
|
75
|
-
if (appResult.isErr()) throw new Error(appResult.error.message);
|
|
76
|
-
const destroyResult = await sdk.destroyService({
|
|
77
|
-
serviceId: appId,
|
|
78
|
-
keepService: false,
|
|
79
|
-
timeoutSeconds: 120,
|
|
80
|
-
pollIntervalMs: 2e3,
|
|
81
|
-
signal: options?.signal
|
|
82
|
-
});
|
|
83
|
-
if (destroyResult.isErr()) throw new Error(destroyResult.error.message);
|
|
84
|
-
return {
|
|
85
|
-
id: appResult.value.id,
|
|
86
|
-
name: appResult.value.name
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
async listDomains(appId, options) {
|
|
90
|
-
return listComputeServiceDomains(client, appId, options?.signal);
|
|
91
|
-
},
|
|
92
|
-
async addDomain(options) {
|
|
93
|
-
const result = await client.POST("/v1/compute-services/{computeServiceId}/domains", {
|
|
94
|
-
params: { path: { computeServiceId: options.appId } },
|
|
95
|
-
body: { hostname: options.hostname },
|
|
96
|
-
signal: options.signal
|
|
97
|
-
});
|
|
98
|
-
if (result.error || !result.data) {
|
|
99
|
-
if (result.response.status === 409) {
|
|
100
|
-
const existing = (await listComputeServiceDomains(client, options.appId, options.signal)).find((domain) => sameHostname(domain.hostname, options.hostname));
|
|
101
|
-
if (existing) return {
|
|
102
|
-
domain: existing,
|
|
103
|
-
existing: true
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
throw domainApiCallError("Failed to add custom domain", result.response, result.error);
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
domain: normalizeDomainRecord(result.data.data),
|
|
110
|
-
existing: false
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
async showDomain(domainId, options) {
|
|
114
|
-
const result = await client.GET("/v1/domains/{domainId}", {
|
|
115
|
-
params: { path: { domainId } },
|
|
116
|
-
signal: options?.signal
|
|
117
|
-
});
|
|
118
|
-
if (result.error || !result.data) throw domainApiCallError("Failed to show custom domain", result.response, result.error);
|
|
119
|
-
return normalizeDomainRecord(result.data.data);
|
|
120
|
-
},
|
|
121
|
-
async removeDomain(domainId, options) {
|
|
122
|
-
const result = await client.DELETE("/v1/domains/{domainId}", {
|
|
123
|
-
params: { path: { domainId } },
|
|
124
|
-
signal: options?.signal
|
|
125
|
-
});
|
|
126
|
-
if (result.error) throw domainApiCallError("Failed to remove custom domain", result.response, result.error);
|
|
127
|
-
},
|
|
128
|
-
async retryDomain(domainId, options) {
|
|
129
|
-
const result = await client.POST("/v1/domains/{domainId}/retry", {
|
|
130
|
-
params: { path: { domainId } },
|
|
131
|
-
signal: options?.signal
|
|
132
|
-
});
|
|
133
|
-
if (result.error || !result.data) throw domainApiCallError("Failed to retry custom domain", result.response, result.error);
|
|
134
|
-
return normalizeDomainRecord(result.data.data);
|
|
135
|
-
},
|
|
136
|
-
async promoteDeployment(options) {
|
|
137
|
-
const promoteResult = await sdk.promote({
|
|
138
|
-
serviceId: options.appId,
|
|
139
|
-
versionId: options.deploymentId,
|
|
140
|
-
timeoutSeconds: 120,
|
|
141
|
-
pollIntervalMs: 2e3,
|
|
142
|
-
signal: options.signal,
|
|
143
|
-
progress: options.progress
|
|
144
|
-
});
|
|
145
|
-
if (promoteResult.isErr()) throw new Error(promoteResult.error.message);
|
|
146
|
-
},
|
|
147
|
-
async deployApp(options) {
|
|
148
|
-
const resolvedApp = options.appId ? {
|
|
149
|
-
appId: options.appId,
|
|
150
|
-
appName: options.appName,
|
|
151
|
-
region: options.region
|
|
152
|
-
} : options.branchName && options.appName ? await createBranchApp(client, {
|
|
153
|
-
projectId: options.projectId,
|
|
154
|
-
branchName: options.branchName,
|
|
155
|
-
appName: options.appName,
|
|
156
|
-
region: options.region,
|
|
157
|
-
signal: options.signal
|
|
158
|
-
}) : {
|
|
159
|
-
appId: void 0,
|
|
160
|
-
appName: options.appName,
|
|
161
|
-
region: options.region
|
|
162
|
-
};
|
|
163
|
-
const deployResult = await sdk.deploy({
|
|
164
|
-
strategy: new AppBuildStrategy({
|
|
165
|
-
appPath: path.resolve(options.cwd),
|
|
166
|
-
entrypoint: options.entrypoint,
|
|
167
|
-
buildType: options.buildType,
|
|
168
|
-
signal: options.signal,
|
|
169
|
-
buildSettings: options.buildSettings
|
|
170
|
-
}),
|
|
171
|
-
projectId: options.projectId,
|
|
172
|
-
serviceId: resolvedApp.appId,
|
|
173
|
-
serviceName: resolvedApp.appName,
|
|
174
|
-
region: resolvedApp.region,
|
|
175
|
-
portMapping: options.portMapping,
|
|
176
|
-
envVars: options.envVars,
|
|
177
|
-
timeoutSeconds: 120,
|
|
178
|
-
pollIntervalMs: 2e3,
|
|
179
|
-
interaction: options.interaction,
|
|
180
|
-
signal: options.signal,
|
|
181
|
-
progress: options.progress
|
|
182
|
-
});
|
|
183
|
-
if (deployResult.isErr()) throw new Error(deployResult.error.message);
|
|
184
|
-
const deployed = deployResult.value;
|
|
185
|
-
return {
|
|
186
|
-
projectId: deployed.projectId,
|
|
187
|
-
app: {
|
|
188
|
-
id: deployed.serviceId,
|
|
189
|
-
name: deployed.serviceName,
|
|
190
|
-
region: deployed.region ?? null,
|
|
191
|
-
liveDeploymentId: deployed.versionId,
|
|
192
|
-
liveUrl: toAbsoluteUrl(deployed.serviceEndpointDomain ?? null)
|
|
193
|
-
},
|
|
194
|
-
deployment: {
|
|
195
|
-
id: deployed.versionId,
|
|
196
|
-
status: "running",
|
|
197
|
-
url: toAbsoluteUrl(deployed.serviceEndpointDomain ?? deployed.versionEndpointDomain ?? null)
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
},
|
|
201
|
-
async updateAppEnv(options) {
|
|
202
|
-
const updateResult = await sdk.updateEnv({
|
|
203
|
-
serviceId: options.appId,
|
|
204
|
-
envVars: options.envVars,
|
|
205
|
-
timeoutSeconds: 120,
|
|
206
|
-
pollIntervalMs: 2e3,
|
|
207
|
-
signal: options.signal,
|
|
208
|
-
progress: options.progress
|
|
209
|
-
});
|
|
210
|
-
if (updateResult.isErr()) throw new Error(updateResult.error.message);
|
|
211
|
-
const promoteResult = await sdk.promote({
|
|
212
|
-
serviceId: options.appId,
|
|
213
|
-
versionId: updateResult.value.versionId,
|
|
214
|
-
timeoutSeconds: 120,
|
|
215
|
-
pollIntervalMs: 2e3,
|
|
216
|
-
signal: options.signal,
|
|
217
|
-
progress: options.promoteProgress
|
|
218
|
-
});
|
|
219
|
-
if (promoteResult.isErr()) throw new Error(promoteResult.error.message);
|
|
220
|
-
const [serviceResult, versionResult] = await Promise.all([sdk.showService({
|
|
221
|
-
serviceId: options.appId,
|
|
222
|
-
signal: options.signal
|
|
223
|
-
}), sdk.showVersion({
|
|
224
|
-
versionId: updateResult.value.versionId,
|
|
225
|
-
signal: options.signal
|
|
226
|
-
})]);
|
|
227
|
-
if (serviceResult.isErr()) throw new Error(serviceResult.error.message);
|
|
228
|
-
if (versionResult.isErr()) throw new Error(versionResult.error.message);
|
|
229
|
-
return {
|
|
230
|
-
projectId: updateResult.value.projectId,
|
|
231
|
-
app: {
|
|
232
|
-
id: serviceResult.value.id,
|
|
233
|
-
name: serviceResult.value.name,
|
|
234
|
-
region: serviceResult.value.region ?? null,
|
|
235
|
-
liveDeploymentId: serviceResult.value.latestVersionId ?? null,
|
|
236
|
-
liveUrl: toAbsoluteUrl(serviceResult.value.serviceEndpointDomain ?? null)
|
|
237
|
-
},
|
|
238
|
-
deployment: {
|
|
239
|
-
id: versionResult.value.id,
|
|
240
|
-
status: versionResult.value.status,
|
|
241
|
-
createdAt: versionResult.value.createdAt,
|
|
242
|
-
url: toAbsoluteUrl(serviceResult.value.serviceEndpointDomain ?? versionResult.value.previewDomain ?? null),
|
|
243
|
-
live: true
|
|
244
|
-
},
|
|
245
|
-
variables: envVarNames(versionResult.value.envVars)
|
|
246
|
-
};
|
|
247
|
-
},
|
|
248
|
-
async listAppEnvNames(options) {
|
|
249
|
-
const [serviceResult, versionResult] = await Promise.all([sdk.showService({
|
|
250
|
-
serviceId: options.appId,
|
|
251
|
-
signal: options.signal
|
|
252
|
-
}), sdk.showVersion({
|
|
253
|
-
versionId: options.deploymentId,
|
|
254
|
-
signal: options.signal
|
|
255
|
-
})]);
|
|
256
|
-
if (serviceResult.isErr()) throw new Error(serviceResult.error.message);
|
|
257
|
-
if (versionResult.isErr()) throw new Error(versionResult.error.message);
|
|
258
|
-
return {
|
|
259
|
-
projectId: serviceResult.value.projectId,
|
|
260
|
-
app: {
|
|
261
|
-
id: serviceResult.value.id,
|
|
262
|
-
name: serviceResult.value.name,
|
|
263
|
-
region: serviceResult.value.region ?? null,
|
|
264
|
-
liveDeploymentId: serviceResult.value.latestVersionId ?? null,
|
|
265
|
-
liveUrl: toAbsoluteUrl(serviceResult.value.serviceEndpointDomain ?? null)
|
|
266
|
-
},
|
|
267
|
-
deployment: {
|
|
268
|
-
id: versionResult.value.id,
|
|
269
|
-
status: versionResult.value.status,
|
|
270
|
-
createdAt: versionResult.value.createdAt,
|
|
271
|
-
url: toAbsoluteUrl(versionResult.value.previewDomain ?? null),
|
|
272
|
-
live: serviceResult.value.latestVersionId === versionResult.value.id
|
|
273
|
-
},
|
|
274
|
-
variables: envVarNames(versionResult.value.envVars)
|
|
275
|
-
};
|
|
276
|
-
},
|
|
277
|
-
async listDeployments(appId, options) {
|
|
278
|
-
const [appResult, versionsResult] = await Promise.all([sdk.showService({
|
|
279
|
-
serviceId: appId,
|
|
280
|
-
signal: options?.signal
|
|
281
|
-
}), sdk.listVersions({
|
|
282
|
-
serviceId: appId,
|
|
283
|
-
signal: options?.signal
|
|
284
|
-
})]);
|
|
285
|
-
if (appResult.isErr()) throw new Error(appResult.error.message);
|
|
286
|
-
if (versionsResult.isErr()) throw new Error(versionsResult.error.message);
|
|
287
|
-
return {
|
|
288
|
-
app: {
|
|
289
|
-
id: appResult.value.id,
|
|
290
|
-
name: appResult.value.name,
|
|
291
|
-
region: appResult.value.region ?? null,
|
|
292
|
-
liveDeploymentId: appResult.value.latestVersionId ?? null,
|
|
293
|
-
liveUrl: toAbsoluteUrl(appResult.value.serviceEndpointDomain ?? null)
|
|
294
|
-
},
|
|
295
|
-
deployments: versionsResult.value.slice().sort((left, right) => {
|
|
296
|
-
const byDate = right.createdAt.localeCompare(left.createdAt);
|
|
297
|
-
return byDate !== 0 ? byDate : right.id.localeCompare(left.id);
|
|
298
|
-
}).map((deployment) => ({
|
|
299
|
-
id: deployment.id,
|
|
300
|
-
status: deployment.status,
|
|
301
|
-
createdAt: deployment.createdAt,
|
|
302
|
-
url: toAbsoluteUrl(deployment.previewDomain ?? null),
|
|
303
|
-
live: null
|
|
304
|
-
}))
|
|
305
|
-
};
|
|
306
|
-
},
|
|
307
|
-
async showDeployment(deploymentId, options) {
|
|
308
|
-
const deploymentResult = await sdk.showVersion({
|
|
309
|
-
versionId: deploymentId,
|
|
310
|
-
signal: options?.signal
|
|
311
|
-
});
|
|
312
|
-
if (deploymentResult.isErr()) {
|
|
313
|
-
if (ApiError.is(deploymentResult.error) && deploymentResult.error.statusCode === 404) return null;
|
|
314
|
-
throw new Error(deploymentResult.error.message);
|
|
315
|
-
}
|
|
316
|
-
return {
|
|
317
|
-
app: await findAppForDeployment(sdk, deploymentId, options?.signal),
|
|
318
|
-
deployment: {
|
|
319
|
-
id: deploymentResult.value.id,
|
|
320
|
-
status: deploymentResult.value.status,
|
|
321
|
-
createdAt: deploymentResult.value.createdAt,
|
|
322
|
-
url: toAbsoluteUrl(deploymentResult.value.previewDomain ?? null),
|
|
323
|
-
live: null
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
},
|
|
327
|
-
async streamDeploymentLogs(streamOptions) {
|
|
328
|
-
if (!options?.baseUrl || !options.getToken) throw new Error("Log streaming requires an authenticated API base URL and token.");
|
|
329
|
-
const result = await streamLogs({
|
|
330
|
-
baseUrl: options.baseUrl,
|
|
331
|
-
token: await options.getToken(),
|
|
332
|
-
versionId: streamOptions.deploymentId,
|
|
333
|
-
signal: streamOptions.signal
|
|
334
|
-
}, streamOptions.onRecord);
|
|
335
|
-
if (result.isErr()) {
|
|
336
|
-
if (CancelledError.is(result.error)) return;
|
|
337
|
-
throw result.error;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
async function listBranches(client, options) {
|
|
343
|
-
const result = await client.GET("/v1/projects/{projectId}/branches", {
|
|
344
|
-
params: {
|
|
345
|
-
path: { projectId: options.projectId },
|
|
346
|
-
query: { gitName: options.gitName }
|
|
347
|
-
},
|
|
348
|
-
signal: options.signal
|
|
349
|
-
});
|
|
350
|
-
if (result.error || !result.data) throw apiCallError("Failed to list branches", result.response, result.error);
|
|
351
|
-
return result.data.data.map((branch) => ({
|
|
352
|
-
id: branch.id,
|
|
353
|
-
gitName: branch.gitName,
|
|
354
|
-
isDefault: branch.isDefault,
|
|
355
|
-
role: branch.role
|
|
356
|
-
}));
|
|
357
|
-
}
|
|
358
|
-
async function resolveOrCreateBranch(client, options) {
|
|
359
|
-
const existing = (await listBranches(client, options))[0];
|
|
360
|
-
if (existing) return existing;
|
|
361
|
-
const result = await client.POST("/v1/projects/{projectId}/branches", {
|
|
362
|
-
params: { path: { projectId: options.projectId } },
|
|
363
|
-
body: { gitName: options.gitName },
|
|
364
|
-
signal: options.signal
|
|
365
|
-
});
|
|
366
|
-
if (result.error || !result.data) {
|
|
367
|
-
if (result.response.status === 409) {
|
|
368
|
-
const raced = (await listBranches(client, options))[0];
|
|
369
|
-
if (raced) return raced;
|
|
370
|
-
}
|
|
371
|
-
throw apiCallError(`Failed to create branch "${options.gitName}"`, result.response, result.error);
|
|
372
|
-
}
|
|
373
|
-
const branch = result.data.data;
|
|
374
|
-
return {
|
|
375
|
-
id: branch.id,
|
|
376
|
-
gitName: branch.gitName,
|
|
377
|
-
isDefault: branch.isDefault,
|
|
378
|
-
role: branch.role
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
async function listComputeServices(client, options) {
|
|
382
|
-
const services = [];
|
|
383
|
-
let cursor;
|
|
384
|
-
while (true) {
|
|
385
|
-
const result = await client.GET("/v1/compute-services", {
|
|
386
|
-
params: { query: {
|
|
387
|
-
projectId: options.projectId,
|
|
388
|
-
branchGitName: options.branchGitName,
|
|
389
|
-
cursor
|
|
390
|
-
} },
|
|
391
|
-
signal: options.signal
|
|
392
|
-
});
|
|
393
|
-
if (result.error || !result.data) throw apiCallError("Failed to list apps", result.response, result.error);
|
|
394
|
-
services.push(...result.data.data);
|
|
395
|
-
if (!result.data.pagination.hasMore || !result.data.pagination.nextCursor) break;
|
|
396
|
-
cursor = result.data.pagination.nextCursor;
|
|
397
|
-
}
|
|
398
|
-
return services.map((service) => ({
|
|
399
|
-
id: service.id,
|
|
400
|
-
name: service.name,
|
|
401
|
-
region: service.region.id ?? null,
|
|
402
|
-
branchId: service.branchId,
|
|
403
|
-
liveDeploymentId: service.latestVersionId ?? null,
|
|
404
|
-
liveUrl: toAbsoluteUrl(service.serviceEndpointDomain ?? null)
|
|
405
|
-
}));
|
|
406
|
-
}
|
|
407
|
-
async function listComputeServiceDomains(client, computeServiceId, signal) {
|
|
408
|
-
const result = await client.GET("/v1/compute-services/{computeServiceId}/domains", {
|
|
409
|
-
params: { path: { computeServiceId } },
|
|
410
|
-
signal
|
|
411
|
-
});
|
|
412
|
-
if (result.error || !result.data) throw domainApiCallError("Failed to list custom domains", result.response, result.error);
|
|
413
|
-
return result.data.data.map((domain) => normalizeDomainRecord(domain));
|
|
414
|
-
}
|
|
415
|
-
function normalizeDomainRecord(domain) {
|
|
416
|
-
return {
|
|
417
|
-
id: domain.id,
|
|
418
|
-
type: domain.type,
|
|
419
|
-
url: domain.url,
|
|
420
|
-
hostname: domain.hostname,
|
|
421
|
-
computeServiceId: domain.computeServiceId,
|
|
422
|
-
status: domain.status,
|
|
423
|
-
foundryStatus: domain.foundryStatus,
|
|
424
|
-
failureReason: domain.failureReason,
|
|
425
|
-
failureCategory: domain.failureCategory,
|
|
426
|
-
certExpiresAt: domain.certExpiresAt,
|
|
427
|
-
createdAt: domain.createdAt,
|
|
428
|
-
updatedAt: domain.updatedAt,
|
|
429
|
-
dnsRecords: normalizeDomainDnsRecords(domain.dnsRecords)
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
function normalizeDomainDnsRecords(records) {
|
|
433
|
-
if (!Array.isArray(records)) return [];
|
|
434
|
-
return records.map((record) => {
|
|
435
|
-
if (typeof record.type !== "string" || typeof record.name !== "string" || typeof record.value !== "string") return null;
|
|
436
|
-
return {
|
|
437
|
-
type: record.type,
|
|
438
|
-
name: record.name,
|
|
439
|
-
value: record.value,
|
|
440
|
-
ttl: typeof record.ttl === "number" ? record.ttl : null
|
|
441
|
-
};
|
|
442
|
-
}).filter((record) => Boolean(record));
|
|
443
|
-
}
|
|
444
|
-
function sameHostname(left, right) {
|
|
445
|
-
return normalizeHostnameForComparison(left) === normalizeHostnameForComparison(right);
|
|
446
|
-
}
|
|
447
|
-
function normalizeHostnameForComparison(hostname) {
|
|
448
|
-
return hostname.trim().replace(/\.$/, "").toLowerCase();
|
|
449
|
-
}
|
|
450
|
-
async function createBranchApp(client, options) {
|
|
451
|
-
const branch = await resolveOrCreateBranch(client, {
|
|
452
|
-
projectId: options.projectId,
|
|
453
|
-
gitName: options.branchName,
|
|
454
|
-
signal: options.signal
|
|
455
|
-
});
|
|
456
|
-
const result = await client.POST("/v1/compute-services", {
|
|
457
|
-
body: {
|
|
458
|
-
projectId: options.projectId,
|
|
459
|
-
branchId: branch.id,
|
|
460
|
-
displayName: options.appName,
|
|
461
|
-
...options.region ? { regionId: options.region } : {}
|
|
462
|
-
},
|
|
463
|
-
signal: options.signal
|
|
464
|
-
});
|
|
465
|
-
if (result.error || !result.data) {
|
|
466
|
-
if (result.response.status === 409) {
|
|
467
|
-
const matched = (await listComputeServices(client, {
|
|
468
|
-
projectId: options.projectId,
|
|
469
|
-
branchGitName: options.branchName,
|
|
470
|
-
signal: options.signal
|
|
471
|
-
})).find((app) => app.name === options.appName);
|
|
472
|
-
if (matched) return {
|
|
473
|
-
appId: matched.id,
|
|
474
|
-
appName: matched.name,
|
|
475
|
-
region: matched.region ?? options.region
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
throw apiCallError(`Failed to create app "${options.appName}"`, result.response, result.error);
|
|
479
|
-
}
|
|
480
|
-
const service = result.data.data;
|
|
481
|
-
return {
|
|
482
|
-
appId: service.id,
|
|
483
|
-
appName: service.name,
|
|
484
|
-
region: service.region.id ?? options.region
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
function apiCallError(summary, response, error) {
|
|
488
|
-
if (response.status === 404) return /* @__PURE__ */ new Error("Resource Not Found");
|
|
489
|
-
const message = error.error?.message ?? `Management API returned HTTP ${response.status}.`;
|
|
490
|
-
const hint = error.error?.hint ? ` ${error.error.hint}` : "";
|
|
491
|
-
return /* @__PURE__ */ new Error(`${summary}: ${message}${hint}`);
|
|
492
|
-
}
|
|
493
|
-
function domainApiCallError(summary, response, error) {
|
|
494
|
-
return new DomainApiError({
|
|
495
|
-
summary,
|
|
496
|
-
status: response.status,
|
|
497
|
-
code: error.error?.code ?? null,
|
|
498
|
-
message: error.error?.message ?? `Management API returned HTTP ${response.status}.`,
|
|
499
|
-
hint: error.error?.hint ?? null
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
async function findAppForDeployment(sdk, deploymentId, signal) {
|
|
503
|
-
const projectsResult = await sdk.listProjects({ signal });
|
|
504
|
-
if (projectsResult.isErr()) throw new Error(projectsResult.error.message);
|
|
505
|
-
for (const project of projectsResult.value) {
|
|
506
|
-
const servicesResult = await sdk.listServices({
|
|
507
|
-
projectId: project.id,
|
|
508
|
-
signal
|
|
509
|
-
});
|
|
510
|
-
if (servicesResult.isErr()) throw new Error(servicesResult.error.message);
|
|
511
|
-
for (const service of servicesResult.value) {
|
|
512
|
-
const app = await findServiceAppForDeployment(sdk, service.id, deploymentId, signal);
|
|
513
|
-
if (app) return app;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
async function findServiceAppForDeployment(sdk, serviceId, deploymentId, signal) {
|
|
519
|
-
const detailResult = await sdk.showService({
|
|
520
|
-
serviceId,
|
|
521
|
-
signal
|
|
522
|
-
});
|
|
523
|
-
if (detailResult.isErr()) throw new Error(detailResult.error.message);
|
|
524
|
-
const app = {
|
|
525
|
-
id: detailResult.value.id,
|
|
526
|
-
name: detailResult.value.name,
|
|
527
|
-
region: detailResult.value.region ?? null,
|
|
528
|
-
liveDeploymentId: detailResult.value.latestVersionId ?? null,
|
|
529
|
-
liveUrl: toAbsoluteUrl(detailResult.value.serviceEndpointDomain ?? null)
|
|
530
|
-
};
|
|
531
|
-
if (app.liveDeploymentId === deploymentId) return app;
|
|
532
|
-
const versionsResult = await sdk.listVersions({
|
|
533
|
-
serviceId,
|
|
534
|
-
signal
|
|
535
|
-
});
|
|
536
|
-
if (versionsResult.isErr()) throw new Error(versionsResult.error.message);
|
|
537
|
-
return versionsResult.value.some((version) => version.id === deploymentId) ? app : null;
|
|
538
|
-
}
|
|
539
|
-
function toAbsoluteUrl(url) {
|
|
540
|
-
if (!url) return null;
|
|
541
|
-
return url.startsWith("https://") || url.startsWith("http://") ? url : `https://${url}`;
|
|
542
|
-
}
|
|
543
|
-
//#endregion
|
|
544
|
-
export { DomainApiError, createAppProvider };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//#region src/lib/app/branch-database-api.ts
|
|
2
|
-
async function createBranchDatabase(client, options) {
|
|
3
|
-
const result = await client.POST("/v1/databases", {
|
|
4
|
-
body: {
|
|
5
|
-
projectId: options.projectId,
|
|
6
|
-
branchId: options.branchId,
|
|
7
|
-
name: options.branchName,
|
|
8
|
-
source: { type: "empty" }
|
|
9
|
-
},
|
|
10
|
-
signal: options.signal
|
|
11
|
-
});
|
|
12
|
-
if (result.error || !result.data) throw apiCallError(`Failed to create database for branch "${options.branchName}"`, result.response, result.error);
|
|
13
|
-
return normalizeBranchDatabaseRecord(result.data.data);
|
|
14
|
-
}
|
|
15
|
-
async function listEnvironmentVariables(client, options) {
|
|
16
|
-
const variables = [];
|
|
17
|
-
let cursor;
|
|
18
|
-
while (true) {
|
|
19
|
-
const result = await client.GET("/v1/environment-variables", {
|
|
20
|
-
params: { query: {
|
|
21
|
-
projectId: options.projectId,
|
|
22
|
-
class: options.className,
|
|
23
|
-
key: options.key,
|
|
24
|
-
branchId: options.branchId,
|
|
25
|
-
cursor
|
|
26
|
-
} },
|
|
27
|
-
signal: options.signal
|
|
28
|
-
});
|
|
29
|
-
if (result.error || !result.data) throw apiCallError("Failed to list environment variables", result.response, result.error);
|
|
30
|
-
variables.push(...result.data.data);
|
|
31
|
-
if (!result.data.pagination.hasMore || !result.data.pagination.nextCursor) break;
|
|
32
|
-
cursor = result.data.pagination.nextCursor;
|
|
33
|
-
}
|
|
34
|
-
return variables.map((variable) => normalizeEnvironmentVariable(variable));
|
|
35
|
-
}
|
|
36
|
-
async function createEnvironmentVariable(client, options) {
|
|
37
|
-
const result = await client.POST("/v1/environment-variables", {
|
|
38
|
-
body: {
|
|
39
|
-
projectId: options.projectId,
|
|
40
|
-
class: options.className,
|
|
41
|
-
key: options.key,
|
|
42
|
-
value: options.value,
|
|
43
|
-
...options.branchId ? { branchId: options.branchId } : {}
|
|
44
|
-
},
|
|
45
|
-
signal: options.signal
|
|
46
|
-
});
|
|
47
|
-
if (result.error || !result.data) throw apiCallError(`Failed to add ${options.key}`, result.response, result.error);
|
|
48
|
-
return normalizeEnvironmentVariable(result.data.data);
|
|
49
|
-
}
|
|
50
|
-
async function deleteBranchDatabase(client, options) {
|
|
51
|
-
const result = await client.DELETE("/v1/databases/{databaseId}", {
|
|
52
|
-
params: { path: { databaseId: options.databaseId } },
|
|
53
|
-
signal: options.signal
|
|
54
|
-
});
|
|
55
|
-
if (result.error) throw apiCallError("Failed to delete branch database", result.response, result.error);
|
|
56
|
-
}
|
|
57
|
-
async function updateEnvironmentVariable(client, options) {
|
|
58
|
-
const result = await client.PATCH("/v1/environment-variables/{envVarId}", {
|
|
59
|
-
params: { path: { envVarId: options.envVarId } },
|
|
60
|
-
body: { value: options.value },
|
|
61
|
-
signal: options.signal
|
|
62
|
-
});
|
|
63
|
-
if (result.error || !result.data) throw apiCallError("Failed to update environment variable", result.response, result.error);
|
|
64
|
-
return normalizeEnvironmentVariable(result.data.data);
|
|
65
|
-
}
|
|
66
|
-
async function deleteEnvironmentVariable(client, options) {
|
|
67
|
-
const result = await client.DELETE("/v1/environment-variables/{envVarId}", {
|
|
68
|
-
params: { path: { envVarId: options.envVarId } },
|
|
69
|
-
signal: options.signal
|
|
70
|
-
});
|
|
71
|
-
if (result.error) throw apiCallError("Failed to delete environment variable", result.response, result.error);
|
|
72
|
-
}
|
|
73
|
-
function normalizeEnvironmentVariable(variable) {
|
|
74
|
-
return {
|
|
75
|
-
id: variable.id,
|
|
76
|
-
key: variable.key,
|
|
77
|
-
branchId: variable.branchId,
|
|
78
|
-
className: variable.class,
|
|
79
|
-
isManagedBySystem: variable.isManagedBySystem
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function normalizeBranchDatabaseRecord(database) {
|
|
83
|
-
const connection = database.connections?.[0];
|
|
84
|
-
const databaseUrl = connection?.endpoints?.pooled?.connectionString;
|
|
85
|
-
const directUrl = connection?.endpoints?.direct?.connectionString ?? null;
|
|
86
|
-
if (!databaseUrl) throw new Error("Created database did not return a pooled connection string.");
|
|
87
|
-
return {
|
|
88
|
-
id: database.id,
|
|
89
|
-
name: database.name,
|
|
90
|
-
branchId: database.branchId,
|
|
91
|
-
databaseUrl,
|
|
92
|
-
directUrl
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function apiCallError(summary, response, error) {
|
|
96
|
-
if (response.status === 404) return /* @__PURE__ */ new Error("Resource Not Found");
|
|
97
|
-
const message = error.error?.message ?? `Management API returned HTTP ${response.status}.`;
|
|
98
|
-
const hint = error.error?.hint ? ` ${error.error.hint}` : "";
|
|
99
|
-
return /* @__PURE__ */ new Error(`${summary}: ${message}${hint}`);
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
|
-
export { createBranchDatabase, createEnvironmentVariable, deleteBranchDatabase, deleteEnvironmentVariable, listEnvironmentVariables, updateEnvironmentVariable };
|