@prisma/cli 8.0.0-rc.1 → 8.0.0-rc.2-dev.49

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