@cdwr/fly-node 0.1.0 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 0.2.0 (2025-01-30)
2
+
3
+ ### ✨ Features
4
+
5
+ - **fly-node:** optional opt out depot builder on deploy ([5bd15a0e1](https://github.com/codeware-sthlm/codeware/commit/5bd15a0e1))
6
+
7
+ ### 🐞 Bug Fixes
8
+
9
+ - **fly-node:** fix fly deploy command typo ([fa79f4daf](https://github.com/codeware-sthlm/codeware/commit/fa79f4daf))
10
+ - **fly-node:** use spawn pty for interactive prompts ([3998bc606](https://github.com/codeware-sthlm/codeware/commit/3998bc606))
11
+ - **fly-node:** detach postgres must handle interactive prompt ([6e2c79036](https://github.com/codeware-sthlm/codeware/commit/6e2c79036))
12
+
1
13
  ## 0.1.0 (2025-01-12)
2
14
 
3
15
  ### ✨ Features
package/README.md CHANGED
@@ -207,7 +207,14 @@ const response = await fly.deploy({
207
207
  postgres: 'db-app'
208
208
  });
209
209
 
210
- // With all options, could be a pull request preview deployment
210
+ // Opt out of the default depot builder
211
+ const response = await fly.deploy({
212
+ app: 'pr-19-foo-app',
213
+ config: 'apps/foo-app/fly.toml',
214
+ optOutDepotBuilder: true
215
+ });
216
+
217
+ // With options that could be a pull request preview deployment
211
218
  const response = await fly.deploy({
212
219
  app: 'pr-19-foo-app',
213
220
  config: 'apps/foo-app/fly.toml',
package/index.cjs CHANGED
@@ -65,24 +65,91 @@ var import_child_process2 = require("child_process");
65
65
  var import_util3 = require("util");
66
66
  var exec = (0, import_util3.promisify)(import_child_process2.exec);
67
67
 
68
+ // packages/core/src/lib/utils/promisified-spawn.ts
69
+ var import_child_process3 = require("child_process");
70
+ function spawn(command, args, options) {
71
+ return new Promise((resolve, reject) => {
72
+ const process2 = (0, import_child_process3.spawn)(command, args, {
73
+ ...options,
74
+ stdio: "pipe"
75
+ });
76
+ const stdoutChunks = [];
77
+ const stderrChunks = [];
78
+ process2.stdout.on("data", (data) => {
79
+ stdoutChunks.push(Buffer.from(data));
80
+ });
81
+ process2.stderr.on("data", (data) => {
82
+ stderrChunks.push(Buffer.from(data));
83
+ });
84
+ process2.on("close", (code) => {
85
+ const stdout = Buffer.concat(stdoutChunks).toString();
86
+ const stderr = Buffer.concat(stderrChunks).toString();
87
+ if (code === 0) {
88
+ resolve({ stdout, stderr });
89
+ } else {
90
+ reject(new Error(`Process exited with code ${code}
91
+ Error: ${stderr}`));
92
+ }
93
+ });
94
+ process2.on("error", reject);
95
+ });
96
+ }
97
+
68
98
  // packages/core/src/lib/utils/run-command.ts
69
99
  var import_testing = require("@nx/plugin/testing");
70
100
 
101
+ // packages/core/src/lib/utils/spawn-pty.ts
102
+ var import_node_pty_prebuilt_multiarch = require("@homebridge/node-pty-prebuilt-multiarch");
103
+ function spawnPty(command, args, options) {
104
+ return new Promise((resolve, reject) => {
105
+ const ptyData = [];
106
+ const ptyProcess = (0, import_node_pty_prebuilt_multiarch.spawn)(command, args, {
107
+ cwd: process.cwd(),
108
+ encoding: "utf-8",
109
+ env: process.env
110
+ });
111
+ ptyProcess.onData((data) => {
112
+ ptyData.push(data);
113
+ if (options?.prompt) {
114
+ const answer = options.prompt(data);
115
+ if (answer) {
116
+ ptyProcess.write(`${answer}
117
+ `);
118
+ }
119
+ }
120
+ });
121
+ ptyProcess.onExit(({ exitCode }) => {
122
+ const output = ptyData.join("");
123
+ if (exitCode === 0) {
124
+ resolve(output);
125
+ } else {
126
+ reject(
127
+ new Error(`Process exited with code ${exitCode}
128
+ Output: ${output}`)
129
+ );
130
+ }
131
+ });
132
+ });
133
+ }
134
+
71
135
  // packages/core/src/lib/utils/whoami.ts
72
136
  var import_npm_whoami = __toESM(require("npm-whoami"), 1);
73
137
 
74
138
  // packages/fly-node/src/lib/fly.class.ts
75
- var import_zod29 = require("zod");
139
+ var import_zod30 = require("zod");
76
140
 
77
- // packages/core/src/lib/zod/json.schema.ts
141
+ // packages/core/src/lib/zod/create-lowercase-schema.ts
78
142
  var import_zod = require("zod");
79
- var LiteralSchema = import_zod.z.union([import_zod.z.string(), import_zod.z.number(), import_zod.z.boolean(), import_zod.z.null()]);
80
- var JsonSchema = import_zod.z.lazy(
81
- () => import_zod.z.union([LiteralSchema, import_zod.z.array(JsonSchema), import_zod.z.record(JsonSchema)])
143
+
144
+ // packages/core/src/lib/zod/json.schema.ts
145
+ var import_zod2 = require("zod");
146
+ var LiteralSchema = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number(), import_zod2.z.boolean(), import_zod2.z.null()]);
147
+ var JsonSchema = import_zod2.z.lazy(
148
+ () => import_zod2.z.union([LiteralSchema, import_zod2.z.array(JsonSchema), import_zod2.z.record(JsonSchema)])
82
149
  );
83
150
 
84
151
  // packages/core/src/lib/zod/with-camel-case.preprocess.ts
85
- var import_zod2 = require("zod");
152
+ var import_zod3 = require("zod");
86
153
  var toCamelCase = (str, specialCases = {}) => {
87
154
  if (specialCases[str]) {
88
155
  return specialCases[str];
@@ -129,7 +196,7 @@ var transformKeys = (options) => {
129
196
  };
130
197
  var withCamelCase = (schema, options = {}) => {
131
198
  const { preserve = [], specialCases = {} } = options;
132
- return import_zod2.z.preprocess(
199
+ return import_zod3.z.preprocess(
133
200
  (data) => transformKeys({
134
201
  currentPath: [],
135
202
  data,
@@ -141,42 +208,42 @@ var withCamelCase = (schema, options = {}) => {
141
208
  };
142
209
 
143
210
  // packages/core/src/lib/zod/with-env-vars.preprocess.ts
144
- var import_zod3 = require("zod");
211
+ var import_zod4 = require("zod");
145
212
 
146
213
  // packages/core/src/lib/zod/with-replace-all.preprocess.ts
147
- var import_zod4 = require("zod");
214
+ var import_zod5 = require("zod");
148
215
 
149
216
  // packages/fly-node/src/lib/schemas/apps-create.schema.ts
150
- var import_zod6 = require("zod");
217
+ var import_zod7 = require("zod");
151
218
  var AppsCreateTransformedResponseSchema = withCamelCase(
152
- import_zod6.z.object({
153
- id: import_zod6.z.string(),
154
- name: import_zod6.z.string(),
155
- organization: import_zod6.z.object({
156
- id: import_zod6.z.string(),
157
- name: import_zod6.z.string()
219
+ import_zod7.z.object({
220
+ id: import_zod7.z.string(),
221
+ name: import_zod7.z.string(),
222
+ organization: import_zod7.z.object({
223
+ id: import_zod7.z.string(),
224
+ name: import_zod7.z.string()
158
225
  })
159
226
  })
160
227
  );
161
228
 
162
229
  // packages/fly-node/src/lib/schemas/apps-list.schema.ts
163
- var import_zod8 = require("zod");
164
- var AppsListTransformedResponseSchema = import_zod8.z.array(
230
+ var import_zod9 = require("zod");
231
+ var AppsListTransformedResponseSchema = import_zod9.z.array(
165
232
  withCamelCase(
166
- import_zod8.z.object({
167
- id: import_zod8.z.string(),
168
- name: import_zod8.z.string(),
169
- status: import_zod8.z.string(),
170
- deployed: import_zod8.z.boolean(),
171
- hostname: import_zod8.z.string(),
172
- organization: import_zod8.z.object({
173
- name: import_zod8.z.string(),
174
- slug: import_zod8.z.string()
233
+ import_zod9.z.object({
234
+ id: import_zod9.z.string(),
235
+ name: import_zod9.z.string(),
236
+ status: import_zod9.z.string(),
237
+ deployed: import_zod9.z.boolean(),
238
+ hostname: import_zod9.z.string(),
239
+ organization: import_zod9.z.object({
240
+ name: import_zod9.z.string(),
241
+ slug: import_zod9.z.string()
175
242
  }),
176
- currentRelease: import_zod8.z.nullable(
177
- import_zod8.z.object({
178
- status: import_zod8.z.string(),
179
- createdAt: import_zod8.z.string().datetime()
243
+ currentRelease: import_zod9.z.nullable(
244
+ import_zod9.z.object({
245
+ status: import_zod9.z.string(),
246
+ createdAt: import_zod9.z.string().datetime()
180
247
  })
181
248
  )
182
249
  })
@@ -184,46 +251,46 @@ var AppsListTransformedResponseSchema = import_zod8.z.array(
184
251
  );
185
252
 
186
253
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
187
- var import_zod12 = require("zod");
254
+ var import_zod13 = require("zod");
188
255
 
189
256
  // packages/fly-node/src/lib/schemas/certs-list.schema.ts
190
- var import_zod10 = require("zod");
191
- var CertsListFlyResponseElementSchema = import_zod10.z.object({
192
- createdAt: import_zod10.z.string().datetime(),
193
- hostname: import_zod10.z.string(),
194
- clientStatus: import_zod10.z.string()
257
+ var import_zod11 = require("zod");
258
+ var CertsListFlyResponseElementSchema = import_zod11.z.object({
259
+ createdAt: import_zod11.z.string().datetime(),
260
+ hostname: import_zod11.z.string(),
261
+ clientStatus: import_zod11.z.string()
195
262
  });
196
- var CertsListTransformedResponseSchema = import_zod10.z.array(
263
+ var CertsListTransformedResponseSchema = import_zod11.z.array(
197
264
  withCamelCase(CertsListFlyResponseElementSchema)
198
265
  );
199
266
 
200
267
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
201
- var CertsListWithAppTransformedResponseSchema = import_zod12.z.array(
268
+ var CertsListWithAppTransformedResponseSchema = import_zod13.z.array(
202
269
  withCamelCase(
203
270
  CertsListFlyResponseElementSchema.extend({
204
- app: import_zod12.z.string()
271
+ app: import_zod13.z.string()
205
272
  })
206
273
  )
207
274
  );
208
275
 
209
276
  // packages/fly-node/src/lib/schemas/config-show.schema.ts
210
- var import_zod14 = require("zod");
277
+ var import_zod15 = require("zod");
211
278
  var ConfigShowResponseSchema = withCamelCase(
212
- import_zod14.z.object({
213
- app: import_zod14.z.string(),
214
- primaryRegion: import_zod14.z.string().optional(),
215
- build: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional().or(
216
- import_zod14.z.object({
217
- args: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.string()).optional(),
218
- dockerfile: import_zod14.z.string().optional(),
219
- image: import_zod14.z.string().optional()
279
+ import_zod15.z.object({
280
+ app: import_zod15.z.string(),
281
+ primaryRegion: import_zod15.z.string().optional(),
282
+ build: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional().or(
283
+ import_zod15.z.object({
284
+ args: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.string()).optional(),
285
+ dockerfile: import_zod15.z.string().optional(),
286
+ image: import_zod15.z.string().optional()
220
287
  })
221
288
  ),
222
- deploy: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional().or(import_zod14.z.object({ strategy: import_zod14.z.string().optional() })),
223
- env: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.string()).optional(),
224
- httpService: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional(),
225
- mounts: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional(),
226
- services: import_zod14.z.array(import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any())).optional()
289
+ deploy: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional().or(import_zod15.z.object({ strategy: import_zod15.z.string().optional() })),
290
+ env: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.string()).optional(),
291
+ httpService: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional(),
292
+ mounts: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional(),
293
+ services: import_zod15.z.array(import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any())).optional()
227
294
  }),
228
295
  {
229
296
  preserve: ["build.args", "env"]
@@ -231,115 +298,115 @@ var ConfigShowResponseSchema = withCamelCase(
231
298
  );
232
299
 
233
300
  // packages/fly-node/src/lib/schemas/deploy.schema.ts
234
- var import_zod15 = require("zod");
235
- var DeployResponseSchema = import_zod15.z.object({
236
- app: import_zod15.z.string(),
237
- hostname: import_zod15.z.string(),
238
- url: import_zod15.z.string().url()
301
+ var import_zod16 = require("zod");
302
+ var DeployResponseSchema = import_zod16.z.object({
303
+ app: import_zod16.z.string(),
304
+ hostname: import_zod16.z.string(),
305
+ url: import_zod16.z.string().url()
239
306
  });
240
307
 
241
308
  // packages/fly-node/src/lib/schemas/helper-schemas.ts
242
- var import_zod16 = require("zod");
243
- var AllowEmptyUrlSchema = import_zod16.z.string().url().or(import_zod16.z.literal(""));
244
- var NameSchema = import_zod16.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
309
+ var import_zod17 = require("zod");
310
+ var AllowEmptyUrlSchema = import_zod17.z.string().url().or(import_zod17.z.literal(""));
311
+ var NameSchema = import_zod17.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
245
312
 
246
313
  // packages/fly-node/src/lib/schemas/postgres-list.ts
247
- var import_zod18 = require("zod");
248
- var PostgresListTransformedResponseSchema = import_zod18.z.array(
314
+ var import_zod19 = require("zod");
315
+ var PostgresListTransformedResponseSchema = import_zod19.z.array(
249
316
  withCamelCase(
250
- import_zod18.z.object({
251
- deployed: import_zod18.z.boolean(),
252
- hostname: import_zod18.z.string(),
253
- id: import_zod18.z.string(),
254
- name: import_zod18.z.string(),
255
- organization: import_zod18.z.object({ id: import_zod18.z.string(), slug: import_zod18.z.string() }),
256
- status: import_zod18.z.string(),
257
- version: import_zod18.z.number()
317
+ import_zod19.z.object({
318
+ deployed: import_zod19.z.boolean(),
319
+ hostname: import_zod19.z.string(),
320
+ id: import_zod19.z.string(),
321
+ name: import_zod19.z.string(),
322
+ organization: import_zod19.z.object({ id: import_zod19.z.string(), slug: import_zod19.z.string() }),
323
+ status: import_zod19.z.string(),
324
+ version: import_zod19.z.number()
258
325
  })
259
326
  )
260
327
  );
261
328
 
262
329
  // packages/fly-node/src/lib/schemas/postgres-users-list.ts
263
- var import_zod20 = require("zod");
264
- var PostgresUsersListTransformedResponseSchema = import_zod20.z.array(
330
+ var import_zod21 = require("zod");
331
+ var PostgresUsersListTransformedResponseSchema = import_zod21.z.array(
265
332
  withCamelCase(
266
- import_zod20.z.object({
267
- username: import_zod20.z.string(),
268
- superuser: import_zod20.z.boolean(),
269
- databases: import_zod20.z.array(import_zod20.z.string())
333
+ import_zod21.z.object({
334
+ username: import_zod21.z.string(),
335
+ superuser: import_zod21.z.boolean(),
336
+ databases: import_zod21.z.array(import_zod21.z.string())
270
337
  })
271
338
  )
272
339
  );
273
340
 
274
341
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
275
- var import_zod24 = require("zod");
342
+ var import_zod25 = require("zod");
276
343
 
277
344
  // packages/fly-node/src/lib/schemas/secrets-list.schema.ts
278
- var import_zod22 = require("zod");
279
- var SecretsListFlyResponseElementSchema = import_zod22.z.object({
280
- name: import_zod22.z.string(),
281
- digest: import_zod22.z.string(),
282
- createdAt: import_zod22.z.string().datetime()
345
+ var import_zod23 = require("zod");
346
+ var SecretsListFlyResponseElementSchema = import_zod23.z.object({
347
+ name: import_zod23.z.string(),
348
+ digest: import_zod23.z.string(),
349
+ createdAt: import_zod23.z.string().datetime()
283
350
  });
284
- var SecretsListTransformedResponseSchema = import_zod22.z.array(
351
+ var SecretsListTransformedResponseSchema = import_zod23.z.array(
285
352
  withCamelCase(SecretsListFlyResponseElementSchema)
286
353
  );
287
354
 
288
355
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
289
- var SecretsListWithAppTransformedResponseSchema = import_zod24.z.array(
356
+ var SecretsListWithAppTransformedResponseSchema = import_zod25.z.array(
290
357
  withCamelCase(
291
358
  SecretsListFlyResponseElementSchema.extend({
292
- app: import_zod24.z.string()
359
+ app: import_zod25.z.string()
293
360
  })
294
361
  )
295
362
  );
296
363
 
297
364
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
298
- var import_zod28 = require("zod");
365
+ var import_zod29 = require("zod");
299
366
 
300
367
  // packages/fly-node/src/lib/schemas/status.schema.ts
301
- var import_zod26 = require("zod");
302
- var statusFlyResponseSchema = import_zod26.z.object({
303
- deployed: import_zod26.z.boolean(),
304
- hostname: import_zod26.z.string(),
305
- id: import_zod26.z.string(),
306
- machines: import_zod26.z.array(
307
- import_zod26.z.object({
308
- id: import_zod26.z.string(),
309
- name: import_zod26.z.string(),
310
- state: import_zod26.z.string(),
311
- region: import_zod26.z.string(),
312
- createdAt: import_zod26.z.string().datetime(),
313
- updatedAt: import_zod26.z.string().datetime(),
314
- config: import_zod26.z.object({
315
- env: import_zod26.z.record(import_zod26.z.string()),
316
- metadata: import_zod26.z.record(import_zod26.z.string())
368
+ var import_zod27 = require("zod");
369
+ var statusFlyResponseSchema = import_zod27.z.object({
370
+ deployed: import_zod27.z.boolean(),
371
+ hostname: import_zod27.z.string(),
372
+ id: import_zod27.z.string(),
373
+ machines: import_zod27.z.array(
374
+ import_zod27.z.object({
375
+ id: import_zod27.z.string(),
376
+ name: import_zod27.z.string(),
377
+ state: import_zod27.z.string(),
378
+ region: import_zod27.z.string(),
379
+ createdAt: import_zod27.z.string().datetime(),
380
+ updatedAt: import_zod27.z.string().datetime(),
381
+ config: import_zod27.z.object({
382
+ env: import_zod27.z.record(import_zod27.z.string()),
383
+ metadata: import_zod27.z.record(import_zod27.z.string())
317
384
  }),
318
- events: import_zod26.z.array(
319
- import_zod26.z.object({
320
- type: import_zod26.z.string(),
321
- status: import_zod26.z.string(),
322
- timestamp: import_zod26.z.number()
385
+ events: import_zod27.z.array(
386
+ import_zod27.z.object({
387
+ type: import_zod27.z.string(),
388
+ status: import_zod27.z.string(),
389
+ timestamp: import_zod27.z.number()
323
390
  })
324
391
  ),
325
- checks: import_zod26.z.array(
326
- import_zod26.z.object({
327
- name: import_zod26.z.string(),
328
- status: import_zod26.z.string(),
329
- output: import_zod26.z.string(),
330
- updatedAt: import_zod26.z.string().datetime()
392
+ checks: import_zod27.z.array(
393
+ import_zod27.z.object({
394
+ name: import_zod27.z.string(),
395
+ status: import_zod27.z.string(),
396
+ output: import_zod27.z.string(),
397
+ updatedAt: import_zod27.z.string().datetime()
331
398
  })
332
399
  ).optional(),
333
- hostStatus: import_zod26.z.string()
400
+ hostStatus: import_zod27.z.string()
334
401
  })
335
402
  ),
336
- name: import_zod26.z.string(),
337
- organization: import_zod26.z.object({
338
- id: import_zod26.z.string(),
339
- slug: import_zod26.z.string()
403
+ name: import_zod27.z.string(),
404
+ organization: import_zod27.z.object({
405
+ id: import_zod27.z.string(),
406
+ slug: import_zod27.z.string()
340
407
  }),
341
- status: import_zod26.z.string(),
342
- version: import_zod26.z.number()
408
+ status: import_zod27.z.string(),
409
+ version: import_zod27.z.number()
343
410
  });
344
411
  var StatusTransformedResponseSchema = withCamelCase(
345
412
  statusFlyResponseSchema,
@@ -352,8 +419,8 @@ var StatusTransformedResponseSchema = withCamelCase(
352
419
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
353
420
  var StatusExtendedTransformedResponseSchema = withCamelCase(
354
421
  statusFlyResponseSchema.extend({
355
- domains: import_zod28.z.array(import_zod28.z.object({ hostname: import_zod28.z.string() })),
356
- secrets: import_zod28.z.array(import_zod28.z.object({ name: import_zod28.z.string() }))
422
+ domains: import_zod29.z.array(import_zod29.z.object({ hostname: import_zod29.z.string() })),
423
+ secrets: import_zod29.z.array(import_zod29.z.object({ name: import_zod29.z.string() }))
357
424
  }),
358
425
  {
359
426
  preserve: ["machines.config.env", "machines.config.metadata"]
@@ -477,7 +544,8 @@ ${error}`
477
544
  this.logger.info(
478
545
  `Detaching Postgres cluster '${cluster}' from application '${app}'`
479
546
  );
480
- await this.detachPostgres(cluster, app);
547
+ const output = await this.detachPostgres(cluster, app);
548
+ this.logger.info(output);
481
549
  }
482
550
  await this.destroyApp(app, options?.force);
483
551
  this.logger.info(`Application '${app}' was destroyed`);
@@ -624,6 +692,11 @@ ${error}`
624
692
  );
625
693
  }
626
694
  };
695
+ postgres = {
696
+ detach: async (cluster, app) => {
697
+ await this.detachPostgres(cluster, app);
698
+ }
699
+ };
627
700
  /**
628
701
  * Manage application secrets
629
702
  */
@@ -866,6 +939,9 @@ ${error}`);
866
939
  for (const [key, value] of Object.entries(options?.env || {})) {
867
940
  args.push("--env", `${key}=${this.safeArg(value)}`);
868
941
  }
942
+ if (options?.optOutDepotBuilder) {
943
+ args.push("--depot=false");
944
+ }
869
945
  args.push("--yes");
870
946
  this.logger.info(`Deploying '${appName}'...`);
871
947
  await this.execFly(args);
@@ -891,11 +967,19 @@ ${error}`);
891
967
  }
892
968
  /**
893
969
  * @private
970
+ * @returns Log output from the detach process
894
971
  * @throws An error if the Postgres database cannot be detached from an app
895
972
  */
896
973
  async detachPostgres(postgres, app) {
897
974
  const args = ["postgres", "detach", postgres, "--app", app];
898
- await this.execFly(args);
975
+ return await this.execFly(args, {
976
+ prompt: (output) => {
977
+ if (output.match(/select .* detach/i)) {
978
+ return app.replace(/-/g, "_");
979
+ }
980
+ return;
981
+ }
982
+ });
899
983
  }
900
984
  /**
901
985
  * @private
@@ -1032,7 +1116,7 @@ ${error}`);
1032
1116
  if (onError === "throwOnError") {
1033
1117
  throw error;
1034
1118
  }
1035
- if (error instanceof import_zod29.ZodError) {
1119
+ if (error instanceof import_zod30.ZodError) {
1036
1120
  this.logger.info(`Failed to parse response:
1037
1121
  ${error.message}`);
1038
1122
  this.logger.info(`Raw response:
@@ -1119,6 +1203,7 @@ ${JSON.stringify(response, null, 2)}`);
1119
1203
  this.logger.info("Authenticating with Fly.io...");
1120
1204
  let user = await this.execFly(
1121
1205
  ["auth", "whoami"],
1206
+ void 0,
1122
1207
  "nullOnError",
1123
1208
  true
1124
1209
  // won't use token
@@ -1136,34 +1221,43 @@ ${JSON.stringify(response, null, 2)}`);
1136
1221
  throw error;
1137
1222
  }
1138
1223
  }
1139
- async execFly(command, onError = "throwOnError", skipToken) {
1140
- const cmdArr = Array.isArray(command) ? command : [command];
1224
+ async execFly(command, options, onError = "throwOnError", skipToken) {
1225
+ const args = Array.isArray(command) ? command : command.split(" ");
1141
1226
  if (!skipToken && !this.authByLogin && this._config.token) {
1142
- cmdArr.push("--access-token", this._config.token);
1227
+ args.push("--access-token", this._config.token);
1143
1228
  }
1144
- const flyCmd = `flyctl ${cmdArr.filter(Boolean).join(" ")}`;
1145
- let stdout = "";
1229
+ const flyCmd = "flyctl";
1230
+ const toLogCmd = `${flyCmd} ${args.join(" ")}`;
1231
+ let output = "";
1146
1232
  try {
1147
- this.traceCLI("CALL", flyCmd);
1148
- const result = await exec(flyCmd);
1149
- stdout = result.stdout.trim();
1150
- this.traceCLI("RESULT", stdout);
1233
+ this.traceCLI("CALL", toLogCmd);
1234
+ if (options?.prompt) {
1235
+ output = await spawnPty(flyCmd, args, { prompt: options.prompt });
1236
+ this.traceCLI("RESULT", output);
1237
+ } else {
1238
+ const result = await spawn(flyCmd, args, options);
1239
+ output = result.stdout.trim();
1240
+ const stderr = result.stderr.trim();
1241
+ this.traceCLI("RESULT", `${output}${stderr ? `
1242
+ ${stderr}` : ""}`);
1243
+ }
1151
1244
  } catch (error) {
1152
- this.traceCLI("RESULT", error);
1245
+ const errorMsg = error.message;
1246
+ this.traceCLI("RESULT", errorMsg);
1153
1247
  if (onError === "throwOnError") {
1154
- throw new Error(`Command failed: ${flyCmd}
1155
- ${error}`);
1248
+ throw new Error(`Command failed: ${toLogCmd}
1249
+ ${errorMsg}`);
1156
1250
  }
1157
1251
  return null;
1158
1252
  }
1159
1253
  try {
1160
- return JSON.parse(stdout);
1254
+ return JSON.parse(output);
1161
1255
  } catch {
1162
- if (stdout) {
1256
+ if (output) {
1163
1257
  if (this.logger.traceCLI) {
1164
1258
  this.logger.info(`Failed to parse as JSON, returning raw output`);
1165
1259
  }
1166
- return stdout;
1260
+ return output;
1167
1261
  }
1168
1262
  }
1169
1263
  return void 0;
@@ -1233,7 +1327,7 @@ ${error}`);
1233
1327
  * @returns `true` if the Fly CLI is installed, `false` otherwise
1234
1328
  */
1235
1329
  async isInstalled() {
1236
- return await this.execFly("version", "nullOnError") !== null;
1330
+ return await this.execFly("version", void 0, "nullOnError") !== null;
1237
1331
  }
1238
1332
  /**
1239
1333
  * @private
package/index.js CHANGED
@@ -29,24 +29,93 @@ import { exec as cpExec } from "child_process";
29
29
  import { promisify as promisify3 } from "util";
30
30
  var exec = promisify3(cpExec);
31
31
 
32
+ // packages/core/src/lib/utils/promisified-spawn.ts
33
+ import {
34
+ spawn as cpSpawn
35
+ } from "child_process";
36
+ function spawn(command, args, options) {
37
+ return new Promise((resolve, reject) => {
38
+ const process2 = cpSpawn(command, args, {
39
+ ...options,
40
+ stdio: "pipe"
41
+ });
42
+ const stdoutChunks = [];
43
+ const stderrChunks = [];
44
+ process2.stdout.on("data", (data) => {
45
+ stdoutChunks.push(Buffer.from(data));
46
+ });
47
+ process2.stderr.on("data", (data) => {
48
+ stderrChunks.push(Buffer.from(data));
49
+ });
50
+ process2.on("close", (code) => {
51
+ const stdout = Buffer.concat(stdoutChunks).toString();
52
+ const stderr = Buffer.concat(stderrChunks).toString();
53
+ if (code === 0) {
54
+ resolve({ stdout, stderr });
55
+ } else {
56
+ reject(new Error(`Process exited with code ${code}
57
+ Error: ${stderr}`));
58
+ }
59
+ });
60
+ process2.on("error", reject);
61
+ });
62
+ }
63
+
32
64
  // packages/core/src/lib/utils/run-command.ts
33
65
  import { tmpProjPath } from "@nx/plugin/testing";
34
66
 
67
+ // packages/core/src/lib/utils/spawn-pty.ts
68
+ import { spawn as spawn2 } from "@homebridge/node-pty-prebuilt-multiarch";
69
+ function spawnPty(command, args, options) {
70
+ return new Promise((resolve, reject) => {
71
+ const ptyData = [];
72
+ const ptyProcess = spawn2(command, args, {
73
+ cwd: process.cwd(),
74
+ encoding: "utf-8",
75
+ env: process.env
76
+ });
77
+ ptyProcess.onData((data) => {
78
+ ptyData.push(data);
79
+ if (options?.prompt) {
80
+ const answer = options.prompt(data);
81
+ if (answer) {
82
+ ptyProcess.write(`${answer}
83
+ `);
84
+ }
85
+ }
86
+ });
87
+ ptyProcess.onExit(({ exitCode }) => {
88
+ const output = ptyData.join("");
89
+ if (exitCode === 0) {
90
+ resolve(output);
91
+ } else {
92
+ reject(
93
+ new Error(`Process exited with code ${exitCode}
94
+ Output: ${output}`)
95
+ );
96
+ }
97
+ });
98
+ });
99
+ }
100
+
35
101
  // packages/core/src/lib/utils/whoami.ts
36
102
  import npmWhoami from "npm-whoami";
37
103
 
38
104
  // packages/fly-node/src/lib/fly.class.ts
39
105
  import { ZodError } from "zod";
40
106
 
41
- // packages/core/src/lib/zod/json.schema.ts
107
+ // packages/core/src/lib/zod/create-lowercase-schema.ts
42
108
  import { z } from "zod";
43
- var LiteralSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
44
- var JsonSchema = z.lazy(
45
- () => z.union([LiteralSchema, z.array(JsonSchema), z.record(JsonSchema)])
109
+
110
+ // packages/core/src/lib/zod/json.schema.ts
111
+ import { z as z2 } from "zod";
112
+ var LiteralSchema = z2.union([z2.string(), z2.number(), z2.boolean(), z2.null()]);
113
+ var JsonSchema = z2.lazy(
114
+ () => z2.union([LiteralSchema, z2.array(JsonSchema), z2.record(JsonSchema)])
46
115
  );
47
116
 
48
117
  // packages/core/src/lib/zod/with-camel-case.preprocess.ts
49
- import { z as z2 } from "zod";
118
+ import { z as z3 } from "zod";
50
119
  var toCamelCase = (str, specialCases = {}) => {
51
120
  if (specialCases[str]) {
52
121
  return specialCases[str];
@@ -93,7 +162,7 @@ var transformKeys = (options) => {
93
162
  };
94
163
  var withCamelCase = (schema, options = {}) => {
95
164
  const { preserve = [], specialCases = {} } = options;
96
- return z2.preprocess(
165
+ return z3.preprocess(
97
166
  (data) => transformKeys({
98
167
  currentPath: [],
99
168
  data,
@@ -105,42 +174,42 @@ var withCamelCase = (schema, options = {}) => {
105
174
  };
106
175
 
107
176
  // packages/core/src/lib/zod/with-env-vars.preprocess.ts
108
- import { z as z3 } from "zod";
177
+ import { z as z4 } from "zod";
109
178
 
110
179
  // packages/core/src/lib/zod/with-replace-all.preprocess.ts
111
- import { z as z4 } from "zod";
180
+ import { z as z5 } from "zod";
112
181
 
113
182
  // packages/fly-node/src/lib/schemas/apps-create.schema.ts
114
- import { z as z5 } from "zod";
183
+ import { z as z6 } from "zod";
115
184
  var AppsCreateTransformedResponseSchema = withCamelCase(
116
- z5.object({
117
- id: z5.string(),
118
- name: z5.string(),
119
- organization: z5.object({
120
- id: z5.string(),
121
- name: z5.string()
185
+ z6.object({
186
+ id: z6.string(),
187
+ name: z6.string(),
188
+ organization: z6.object({
189
+ id: z6.string(),
190
+ name: z6.string()
122
191
  })
123
192
  })
124
193
  );
125
194
 
126
195
  // packages/fly-node/src/lib/schemas/apps-list.schema.ts
127
- import { z as z6 } from "zod";
128
- var AppsListTransformedResponseSchema = z6.array(
196
+ import { z as z7 } from "zod";
197
+ var AppsListTransformedResponseSchema = z7.array(
129
198
  withCamelCase(
130
- z6.object({
131
- id: z6.string(),
132
- name: z6.string(),
133
- status: z6.string(),
134
- deployed: z6.boolean(),
135
- hostname: z6.string(),
136
- organization: z6.object({
137
- name: z6.string(),
138
- slug: z6.string()
199
+ z7.object({
200
+ id: z7.string(),
201
+ name: z7.string(),
202
+ status: z7.string(),
203
+ deployed: z7.boolean(),
204
+ hostname: z7.string(),
205
+ organization: z7.object({
206
+ name: z7.string(),
207
+ slug: z7.string()
139
208
  }),
140
- currentRelease: z6.nullable(
141
- z6.object({
142
- status: z6.string(),
143
- createdAt: z6.string().datetime()
209
+ currentRelease: z7.nullable(
210
+ z7.object({
211
+ status: z7.string(),
212
+ createdAt: z7.string().datetime()
144
213
  })
145
214
  )
146
215
  })
@@ -148,46 +217,46 @@ var AppsListTransformedResponseSchema = z6.array(
148
217
  );
149
218
 
150
219
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
151
- import { z as z8 } from "zod";
220
+ import { z as z9 } from "zod";
152
221
 
153
222
  // packages/fly-node/src/lib/schemas/certs-list.schema.ts
154
- import { z as z7 } from "zod";
155
- var CertsListFlyResponseElementSchema = z7.object({
156
- createdAt: z7.string().datetime(),
157
- hostname: z7.string(),
158
- clientStatus: z7.string()
223
+ import { z as z8 } from "zod";
224
+ var CertsListFlyResponseElementSchema = z8.object({
225
+ createdAt: z8.string().datetime(),
226
+ hostname: z8.string(),
227
+ clientStatus: z8.string()
159
228
  });
160
- var CertsListTransformedResponseSchema = z7.array(
229
+ var CertsListTransformedResponseSchema = z8.array(
161
230
  withCamelCase(CertsListFlyResponseElementSchema)
162
231
  );
163
232
 
164
233
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
165
- var CertsListWithAppTransformedResponseSchema = z8.array(
234
+ var CertsListWithAppTransformedResponseSchema = z9.array(
166
235
  withCamelCase(
167
236
  CertsListFlyResponseElementSchema.extend({
168
- app: z8.string()
237
+ app: z9.string()
169
238
  })
170
239
  )
171
240
  );
172
241
 
173
242
  // packages/fly-node/src/lib/schemas/config-show.schema.ts
174
- import { z as z9 } from "zod";
243
+ import { z as z10 } from "zod";
175
244
  var ConfigShowResponseSchema = withCamelCase(
176
- z9.object({
177
- app: z9.string(),
178
- primaryRegion: z9.string().optional(),
179
- build: z9.record(z9.string(), z9.any()).optional().or(
180
- z9.object({
181
- args: z9.record(z9.string(), z9.string()).optional(),
182
- dockerfile: z9.string().optional(),
183
- image: z9.string().optional()
245
+ z10.object({
246
+ app: z10.string(),
247
+ primaryRegion: z10.string().optional(),
248
+ build: z10.record(z10.string(), z10.any()).optional().or(
249
+ z10.object({
250
+ args: z10.record(z10.string(), z10.string()).optional(),
251
+ dockerfile: z10.string().optional(),
252
+ image: z10.string().optional()
184
253
  })
185
254
  ),
186
- deploy: z9.record(z9.string(), z9.any()).optional().or(z9.object({ strategy: z9.string().optional() })),
187
- env: z9.record(z9.string(), z9.string()).optional(),
188
- httpService: z9.record(z9.string(), z9.any()).optional(),
189
- mounts: z9.record(z9.string(), z9.any()).optional(),
190
- services: z9.array(z9.record(z9.string(), z9.any())).optional()
255
+ deploy: z10.record(z10.string(), z10.any()).optional().or(z10.object({ strategy: z10.string().optional() })),
256
+ env: z10.record(z10.string(), z10.string()).optional(),
257
+ httpService: z10.record(z10.string(), z10.any()).optional(),
258
+ mounts: z10.record(z10.string(), z10.any()).optional(),
259
+ services: z10.array(z10.record(z10.string(), z10.any())).optional()
191
260
  }),
192
261
  {
193
262
  preserve: ["build.args", "env"]
@@ -195,115 +264,115 @@ var ConfigShowResponseSchema = withCamelCase(
195
264
  );
196
265
 
197
266
  // packages/fly-node/src/lib/schemas/deploy.schema.ts
198
- import { z as z10 } from "zod";
199
- var DeployResponseSchema = z10.object({
200
- app: z10.string(),
201
- hostname: z10.string(),
202
- url: z10.string().url()
267
+ import { z as z11 } from "zod";
268
+ var DeployResponseSchema = z11.object({
269
+ app: z11.string(),
270
+ hostname: z11.string(),
271
+ url: z11.string().url()
203
272
  });
204
273
 
205
274
  // packages/fly-node/src/lib/schemas/helper-schemas.ts
206
- import { z as z11 } from "zod";
207
- var AllowEmptyUrlSchema = z11.string().url().or(z11.literal(""));
208
- var NameSchema = z11.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
275
+ import { z as z12 } from "zod";
276
+ var AllowEmptyUrlSchema = z12.string().url().or(z12.literal(""));
277
+ var NameSchema = z12.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
209
278
 
210
279
  // packages/fly-node/src/lib/schemas/postgres-list.ts
211
- import { z as z12 } from "zod";
212
- var PostgresListTransformedResponseSchema = z12.array(
280
+ import { z as z13 } from "zod";
281
+ var PostgresListTransformedResponseSchema = z13.array(
213
282
  withCamelCase(
214
- z12.object({
215
- deployed: z12.boolean(),
216
- hostname: z12.string(),
217
- id: z12.string(),
218
- name: z12.string(),
219
- organization: z12.object({ id: z12.string(), slug: z12.string() }),
220
- status: z12.string(),
221
- version: z12.number()
283
+ z13.object({
284
+ deployed: z13.boolean(),
285
+ hostname: z13.string(),
286
+ id: z13.string(),
287
+ name: z13.string(),
288
+ organization: z13.object({ id: z13.string(), slug: z13.string() }),
289
+ status: z13.string(),
290
+ version: z13.number()
222
291
  })
223
292
  )
224
293
  );
225
294
 
226
295
  // packages/fly-node/src/lib/schemas/postgres-users-list.ts
227
- import { z as z13 } from "zod";
228
- var PostgresUsersListTransformedResponseSchema = z13.array(
296
+ import { z as z14 } from "zod";
297
+ var PostgresUsersListTransformedResponseSchema = z14.array(
229
298
  withCamelCase(
230
- z13.object({
231
- username: z13.string(),
232
- superuser: z13.boolean(),
233
- databases: z13.array(z13.string())
299
+ z14.object({
300
+ username: z14.string(),
301
+ superuser: z14.boolean(),
302
+ databases: z14.array(z14.string())
234
303
  })
235
304
  )
236
305
  );
237
306
 
238
307
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
239
- import { z as z15 } from "zod";
308
+ import { z as z16 } from "zod";
240
309
 
241
310
  // packages/fly-node/src/lib/schemas/secrets-list.schema.ts
242
- import { z as z14 } from "zod";
243
- var SecretsListFlyResponseElementSchema = z14.object({
244
- name: z14.string(),
245
- digest: z14.string(),
246
- createdAt: z14.string().datetime()
311
+ import { z as z15 } from "zod";
312
+ var SecretsListFlyResponseElementSchema = z15.object({
313
+ name: z15.string(),
314
+ digest: z15.string(),
315
+ createdAt: z15.string().datetime()
247
316
  });
248
- var SecretsListTransformedResponseSchema = z14.array(
317
+ var SecretsListTransformedResponseSchema = z15.array(
249
318
  withCamelCase(SecretsListFlyResponseElementSchema)
250
319
  );
251
320
 
252
321
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
253
- var SecretsListWithAppTransformedResponseSchema = z15.array(
322
+ var SecretsListWithAppTransformedResponseSchema = z16.array(
254
323
  withCamelCase(
255
324
  SecretsListFlyResponseElementSchema.extend({
256
- app: z15.string()
325
+ app: z16.string()
257
326
  })
258
327
  )
259
328
  );
260
329
 
261
330
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
262
- import { z as z17 } from "zod";
331
+ import { z as z18 } from "zod";
263
332
 
264
333
  // packages/fly-node/src/lib/schemas/status.schema.ts
265
- import { z as z16 } from "zod";
266
- var statusFlyResponseSchema = z16.object({
267
- deployed: z16.boolean(),
268
- hostname: z16.string(),
269
- id: z16.string(),
270
- machines: z16.array(
271
- z16.object({
272
- id: z16.string(),
273
- name: z16.string(),
274
- state: z16.string(),
275
- region: z16.string(),
276
- createdAt: z16.string().datetime(),
277
- updatedAt: z16.string().datetime(),
278
- config: z16.object({
279
- env: z16.record(z16.string()),
280
- metadata: z16.record(z16.string())
334
+ import { z as z17 } from "zod";
335
+ var statusFlyResponseSchema = z17.object({
336
+ deployed: z17.boolean(),
337
+ hostname: z17.string(),
338
+ id: z17.string(),
339
+ machines: z17.array(
340
+ z17.object({
341
+ id: z17.string(),
342
+ name: z17.string(),
343
+ state: z17.string(),
344
+ region: z17.string(),
345
+ createdAt: z17.string().datetime(),
346
+ updatedAt: z17.string().datetime(),
347
+ config: z17.object({
348
+ env: z17.record(z17.string()),
349
+ metadata: z17.record(z17.string())
281
350
  }),
282
- events: z16.array(
283
- z16.object({
284
- type: z16.string(),
285
- status: z16.string(),
286
- timestamp: z16.number()
351
+ events: z17.array(
352
+ z17.object({
353
+ type: z17.string(),
354
+ status: z17.string(),
355
+ timestamp: z17.number()
287
356
  })
288
357
  ),
289
- checks: z16.array(
290
- z16.object({
291
- name: z16.string(),
292
- status: z16.string(),
293
- output: z16.string(),
294
- updatedAt: z16.string().datetime()
358
+ checks: z17.array(
359
+ z17.object({
360
+ name: z17.string(),
361
+ status: z17.string(),
362
+ output: z17.string(),
363
+ updatedAt: z17.string().datetime()
295
364
  })
296
365
  ).optional(),
297
- hostStatus: z16.string()
366
+ hostStatus: z17.string()
298
367
  })
299
368
  ),
300
- name: z16.string(),
301
- organization: z16.object({
302
- id: z16.string(),
303
- slug: z16.string()
369
+ name: z17.string(),
370
+ organization: z17.object({
371
+ id: z17.string(),
372
+ slug: z17.string()
304
373
  }),
305
- status: z16.string(),
306
- version: z16.number()
374
+ status: z17.string(),
375
+ version: z17.number()
307
376
  });
308
377
  var StatusTransformedResponseSchema = withCamelCase(
309
378
  statusFlyResponseSchema,
@@ -316,8 +385,8 @@ var StatusTransformedResponseSchema = withCamelCase(
316
385
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
317
386
  var StatusExtendedTransformedResponseSchema = withCamelCase(
318
387
  statusFlyResponseSchema.extend({
319
- domains: z17.array(z17.object({ hostname: z17.string() })),
320
- secrets: z17.array(z17.object({ name: z17.string() }))
388
+ domains: z18.array(z18.object({ hostname: z18.string() })),
389
+ secrets: z18.array(z18.object({ name: z18.string() }))
321
390
  }),
322
391
  {
323
392
  preserve: ["machines.config.env", "machines.config.metadata"]
@@ -441,7 +510,8 @@ ${error}`
441
510
  this.logger.info(
442
511
  `Detaching Postgres cluster '${cluster}' from application '${app}'`
443
512
  );
444
- await this.detachPostgres(cluster, app);
513
+ const output = await this.detachPostgres(cluster, app);
514
+ this.logger.info(output);
445
515
  }
446
516
  await this.destroyApp(app, options?.force);
447
517
  this.logger.info(`Application '${app}' was destroyed`);
@@ -588,6 +658,11 @@ ${error}`
588
658
  );
589
659
  }
590
660
  };
661
+ postgres = {
662
+ detach: async (cluster, app) => {
663
+ await this.detachPostgres(cluster, app);
664
+ }
665
+ };
591
666
  /**
592
667
  * Manage application secrets
593
668
  */
@@ -830,6 +905,9 @@ ${error}`);
830
905
  for (const [key, value] of Object.entries(options?.env || {})) {
831
906
  args.push("--env", `${key}=${this.safeArg(value)}`);
832
907
  }
908
+ if (options?.optOutDepotBuilder) {
909
+ args.push("--depot=false");
910
+ }
833
911
  args.push("--yes");
834
912
  this.logger.info(`Deploying '${appName}'...`);
835
913
  await this.execFly(args);
@@ -855,11 +933,19 @@ ${error}`);
855
933
  }
856
934
  /**
857
935
  * @private
936
+ * @returns Log output from the detach process
858
937
  * @throws An error if the Postgres database cannot be detached from an app
859
938
  */
860
939
  async detachPostgres(postgres, app) {
861
940
  const args = ["postgres", "detach", postgres, "--app", app];
862
- await this.execFly(args);
941
+ return await this.execFly(args, {
942
+ prompt: (output) => {
943
+ if (output.match(/select .* detach/i)) {
944
+ return app.replace(/-/g, "_");
945
+ }
946
+ return;
947
+ }
948
+ });
863
949
  }
864
950
  /**
865
951
  * @private
@@ -1083,6 +1169,7 @@ ${JSON.stringify(response, null, 2)}`);
1083
1169
  this.logger.info("Authenticating with Fly.io...");
1084
1170
  let user = await this.execFly(
1085
1171
  ["auth", "whoami"],
1172
+ void 0,
1086
1173
  "nullOnError",
1087
1174
  true
1088
1175
  // won't use token
@@ -1100,34 +1187,43 @@ ${JSON.stringify(response, null, 2)}`);
1100
1187
  throw error;
1101
1188
  }
1102
1189
  }
1103
- async execFly(command, onError = "throwOnError", skipToken) {
1104
- const cmdArr = Array.isArray(command) ? command : [command];
1190
+ async execFly(command, options, onError = "throwOnError", skipToken) {
1191
+ const args = Array.isArray(command) ? command : command.split(" ");
1105
1192
  if (!skipToken && !this.authByLogin && this._config.token) {
1106
- cmdArr.push("--access-token", this._config.token);
1193
+ args.push("--access-token", this._config.token);
1107
1194
  }
1108
- const flyCmd = `flyctl ${cmdArr.filter(Boolean).join(" ")}`;
1109
- let stdout = "";
1195
+ const flyCmd = "flyctl";
1196
+ const toLogCmd = `${flyCmd} ${args.join(" ")}`;
1197
+ let output = "";
1110
1198
  try {
1111
- this.traceCLI("CALL", flyCmd);
1112
- const result = await exec(flyCmd);
1113
- stdout = result.stdout.trim();
1114
- this.traceCLI("RESULT", stdout);
1199
+ this.traceCLI("CALL", toLogCmd);
1200
+ if (options?.prompt) {
1201
+ output = await spawnPty(flyCmd, args, { prompt: options.prompt });
1202
+ this.traceCLI("RESULT", output);
1203
+ } else {
1204
+ const result = await spawn(flyCmd, args, options);
1205
+ output = result.stdout.trim();
1206
+ const stderr = result.stderr.trim();
1207
+ this.traceCLI("RESULT", `${output}${stderr ? `
1208
+ ${stderr}` : ""}`);
1209
+ }
1115
1210
  } catch (error) {
1116
- this.traceCLI("RESULT", error);
1211
+ const errorMsg = error.message;
1212
+ this.traceCLI("RESULT", errorMsg);
1117
1213
  if (onError === "throwOnError") {
1118
- throw new Error(`Command failed: ${flyCmd}
1119
- ${error}`);
1214
+ throw new Error(`Command failed: ${toLogCmd}
1215
+ ${errorMsg}`);
1120
1216
  }
1121
1217
  return null;
1122
1218
  }
1123
1219
  try {
1124
- return JSON.parse(stdout);
1220
+ return JSON.parse(output);
1125
1221
  } catch {
1126
- if (stdout) {
1222
+ if (output) {
1127
1223
  if (this.logger.traceCLI) {
1128
1224
  this.logger.info(`Failed to parse as JSON, returning raw output`);
1129
1225
  }
1130
- return stdout;
1226
+ return output;
1131
1227
  }
1132
1228
  }
1133
1229
  return void 0;
@@ -1197,7 +1293,7 @@ ${error}`);
1197
1293
  * @returns `true` if the Fly CLI is installed, `false` otherwise
1198
1294
  */
1199
1295
  async isInstalled() {
1200
- return await this.execFly("version", "nullOnError") !== null;
1296
+ return await this.execFly("version", void 0, "nullOnError") !== null;
1201
1297
  }
1202
1298
  /**
1203
1299
  * @private
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdwr/fly-node",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "The flyctl node wrapper for programmatic deployments to fly.io.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,6 @@
1
+ import { SpawnOptions, SpawnPtyOptions } from '@codeware/core/utils';
1
2
  import type { AppOrConfig, Config, CreateAppOptions, DeployAppOptions, DeployResponse, DestroyAppOptions, ListAppResponse, ListCertForAllResponse, ListCertForAppResponse, ListSecretForAllResponse, ListSecretForAppResponse, SetAppSecretsOptions, ShowConfigOptions, ShowConfigResponse, StatusExtendedResponse, StatusResponse, UnsetAppSecretsOptions } from './types';
3
+ export type ExecFlyOptions = SpawnOptions & SpawnPtyOptions;
2
4
  /**
3
5
  * Manages deployments to Fly.io using the `flyctl` CLI tool.
4
6
  */
@@ -131,6 +133,9 @@ export declare class Fly {
131
133
  * @throws An error if the deployment fails
132
134
  */
133
135
  deploy: (options?: DeployAppOptions) => Promise<DeployResponse>;
136
+ postgres: {
137
+ detach: (cluster: string, app: string) => Promise<void>;
138
+ };
134
139
  /**
135
140
  * Manage application secrets
136
141
  */
@@ -199,6 +204,7 @@ export declare class Fly {
199
204
  private destroyApp;
200
205
  /**
201
206
  * @private
207
+ * @returns Log output from the detach process
202
208
  * @throws An error if the Postgres database cannot be detached from an app
203
209
  */
204
210
  private detachPostgres;
@@ -173,6 +173,12 @@ export type DeployAppOptions = {
173
173
  * Spaces are supported in values.
174
174
  */
175
175
  secrets?: Record<string, string>;
176
+ /**
177
+ * Whether to opt out of the Depot Builder.
178
+ *
179
+ * Defaults to `false`.
180
+ */
181
+ optOutDepotBuilder?: boolean;
176
182
  };
177
183
  /**
178
184
  * Options for destroying an application