@cdwr/fly-node 0.3.2 → 0.3.4

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/index.js CHANGED
@@ -1,46 +1,63 @@
1
- // packages/fly-node/src/lib/schemas/certificate.schema.ts
1
+ // packages/fly-node/src/lib/schemas/app-ip-addresses.schema.ts
2
+ import { z as z2 } from "zod";
3
+
4
+ // packages/fly-node/src/lib/schemas/ip-type.schema.ts
2
5
  import { z } from "zod";
3
- var CertificateApiResponseSchema = z.object({
4
- hostname: z.string(),
6
+ var IpTypeSchema = z.enum(["v4", "v6", "shared_v4", "private_v6"]).or(z.string());
7
+
8
+ // packages/fly-node/src/lib/schemas/app-ip-addresses.schema.ts
9
+ var AppIpAddressSchema = z2.object({
10
+ address: z2.string(),
11
+ type: IpTypeSchema
12
+ });
13
+ var AppIpAddressesApiResponseSchema = z2.object({
14
+ sharedIpAddress: z2.string().nullish(),
15
+ ipAddresses: z2.object({ nodes: z2.array(AppIpAddressSchema) })
16
+ });
17
+
18
+ // packages/fly-node/src/lib/schemas/certificate.schema.ts
19
+ import { z as z3 } from "zod";
20
+ var CertificateApiResponseSchema = z3.object({
21
+ hostname: z3.string(),
5
22
  /** Issued and serving. This is what decides whether a domain is usable */
6
- isConfigured: z.boolean(),
7
- id: z.string().optional(),
23
+ isConfigured: z3.boolean(),
24
+ id: z3.string().optional(),
8
25
  /** The apex or a subdomain — apex domains cannot use a CNAME */
9
- isApex: z.boolean().optional(),
10
- isWildcard: z.boolean().optional(),
26
+ isApex: z3.boolean().optional(),
27
+ isWildcard: z3.boolean().optional(),
11
28
  /** Which ACME challenge has been satisfied, if any */
12
- isAcmeDnsConfigured: z.boolean().optional(),
13
- isAcmeAlpnConfigured: z.boolean().optional(),
14
- isAcmeHttpConfigured: z.boolean().optional(),
15
- certificateAuthority: z.string().nullish(),
16
- certificateRequestedAt: z.string().nullish(),
17
- createdAt: z.string().nullish(),
18
- domain: z.string().nullish(),
19
- dnsProvider: z.string().nullish(),
29
+ isAcmeDnsConfigured: z3.boolean().optional(),
30
+ isAcmeAlpnConfigured: z3.boolean().optional(),
31
+ isAcmeHttpConfigured: z3.boolean().optional(),
32
+ certificateAuthority: z3.string().nullish(),
33
+ certificateRequestedAt: z3.string().nullish(),
34
+ createdAt: z3.string().nullish(),
35
+ domain: z3.string().nullish(),
36
+ dnsProvider: z3.string().nullish(),
20
37
  /** Hostname the validation record must be created on */
21
- dnsValidationHostname: z.string().nullish(),
38
+ dnsValidationHostname: z3.string().nullish(),
22
39
  /** Value that record must contain */
23
- dnsValidationTarget: z.string().nullish(),
40
+ dnsValidationTarget: z3.string().nullish(),
24
41
  /** Fly's own prose describing the records to create */
25
- dnsValidationInstructions: z.string().nullish(),
42
+ dnsValidationInstructions: z3.string().nullish(),
26
43
  /** Fly's summary of where issuance has got to */
27
- clientStatus: z.string().nullish(),
44
+ clientStatus: z3.string().nullish(),
28
45
  /**
29
46
  * Set when Let's Encrypt has rate-limited further attempts for this domain.
30
47
  *
31
48
  * Worth surfacing rather than swallowing: it is the one failure a customer
32
49
  * cannot fix by correcting DNS, and retrying only makes it worse.
33
50
  */
34
- rateLimitedUntil: z.string().nullish(),
35
- source: z.string().nullish(),
51
+ rateLimitedUntil: z3.string().nullish(),
52
+ source: z3.string().nullish(),
36
53
  /**
37
54
  * Fly's own prose for a failed issuance attempt — what the dashboard shows,
38
55
  * unlike `HostnameCheck.errors`, which is SCREAMING_SNAKE_CASE codes
39
56
  */
40
- validationErrors: z.array(
41
- z.object({
42
- message: z.string(),
43
- timestamp: z.string()
57
+ validationErrors: z3.array(
58
+ z3.object({
59
+ message: z3.string(),
60
+ timestamp: z3.string()
44
61
  })
45
62
  ).nullish(),
46
63
  /**
@@ -50,52 +67,52 @@ var CertificateApiResponseSchema = z.object({
50
67
  * nodes is the normal count — one RSA and one ECDSA — sharing an expiry,
51
68
  * which is why a caller usually wants the expiry rather than the rows.
52
69
  */
53
- issued: z.object({
54
- nodes: z.array(
55
- z.object({
56
- id: z.string().nullish(),
70
+ issued: z3.object({
71
+ nodes: z3.array(
72
+ z3.object({
73
+ id: z3.string().nullish(),
57
74
  /** Key type, e.g. `RSA` or `ECDSA` */
58
- type: z.string().nullish(),
59
- hostname: z.string().nullish(),
60
- expiresAt: z.string().nullish()
75
+ type: z3.string().nullish(),
76
+ hostname: z3.string().nullish(),
77
+ expiresAt: z3.string().nullish()
61
78
  })
62
79
  ).nullish()
63
80
  }).nullish()
64
81
  });
65
- var HostnameCheckApiResponseSchema = z.object({
66
- aRecords: z.array(z.string()).nullish(),
67
- aaaaRecords: z.array(z.string()).nullish(),
68
- cnameRecords: z.array(z.string()).nullish(),
69
- caaRecords: z.array(z.string()).nullish(),
70
- soa: z.string().nullish(),
71
- dnsProvider: z.string().nullish(),
72
- dnsVerificationRecord: z.string().nullish(),
73
- dnsConfigured: z.boolean().nullish(),
74
- acmeDnsConfigured: z.boolean().nullish(),
75
- resolvedAddresses: z.array(z.string()).nullish(),
76
- isProxied: z.boolean().nullish(),
77
- errors: z.array(z.string()).nullish()
82
+ var HostnameCheckApiResponseSchema = z3.object({
83
+ aRecords: z3.array(z3.string()).nullish(),
84
+ aaaaRecords: z3.array(z3.string()).nullish(),
85
+ cnameRecords: z3.array(z3.string()).nullish(),
86
+ caaRecords: z3.array(z3.string()).nullish(),
87
+ soa: z3.string().nullish(),
88
+ dnsProvider: z3.string().nullish(),
89
+ dnsVerificationRecord: z3.string().nullish(),
90
+ dnsConfigured: z3.boolean().nullish(),
91
+ acmeDnsConfigured: z3.boolean().nullish(),
92
+ resolvedAddresses: z3.array(z3.string()).nullish(),
93
+ isProxied: z3.boolean().nullish(),
94
+ errors: z3.array(z3.string()).nullish()
78
95
  });
79
- var DnsInstructionsSchema = z.object({
80
- hostname: z.string().nullish(),
81
- target: z.string().nullish(),
82
- instructions: z.string().nullish(),
83
- isApex: z.boolean().optional()
96
+ var DnsInstructionsSchema = z3.object({
97
+ hostname: z3.string().nullish(),
98
+ target: z3.string().nullish(),
99
+ instructions: z3.string().nullish(),
100
+ isApex: z3.boolean().optional()
84
101
  });
85
- var CertificateListApiResponseSchema = z.array(
102
+ var CertificateListApiResponseSchema = z3.array(
86
103
  CertificateApiResponseSchema
87
104
  );
88
105
 
89
106
  // packages/fly-node/src/lib/schemas/machine.schema.ts
90
- import { z as z2 } from "zod";
91
- var MachineApiResponseSchema = z2.object({
92
- id: z2.string(),
93
- name: z2.string().nullish(),
107
+ import { z as z4 } from "zod";
108
+ var MachineApiResponseSchema = z4.object({
109
+ id: z4.string(),
110
+ name: z4.string().nullish(),
94
111
  /** `started`, `stopped`, `suspended`, … — Fly owns this vocabulary */
95
- state: z2.string().nullish(),
96
- region: z2.string().nullish()
112
+ state: z4.string().nullish(),
113
+ region: z4.string().nullish()
97
114
  });
98
- var MachineListApiResponseSchema = z2.array(MachineApiResponseSchema);
115
+ var MachineListApiResponseSchema = z4.array(MachineApiResponseSchema);
99
116
 
100
117
  // packages/fly-node/src/lib/fly-api.class.ts
101
118
  var FLY_API_URL = "https://api.fly.io/graphql";
@@ -288,6 +305,42 @@ var FlyApi = class {
288
305
  );
289
306
  }
290
307
  };
308
+ /** Read an app's addresses */
309
+ ips = {
310
+ /**
311
+ * The addresses an app answers on: `shared_v4`, `v4`, `v6`, and its
312
+ * `private_v6`.
313
+ *
314
+ * The shared v4 is folded in as a `shared_v4` row, the way `fly ips list`
315
+ * shows it; Fly's API keeps it in a separate field. Egress addresses,
316
+ * which the CLI also lists, are not part of this API and never appear.
317
+ * Pick the public types before pointing DNS at them.
318
+ *
319
+ * Rejects for an unknown app, like `certs.list`: a typo in an app name
320
+ * must not read as "this app has no addresses".
321
+ *
322
+ * @returns The addresses, empty when the app has none
323
+ */
324
+ list: async (app) => {
325
+ const data = await this.request(
326
+ `query AppIpAddresses($appName: String!) {
327
+ app(name: $appName) {
328
+ sharedIpAddress
329
+ ipAddresses { nodes { address type } }
330
+ }
331
+ }`,
332
+ { appName: app }
333
+ );
334
+ if (!data.app) {
335
+ return [];
336
+ }
337
+ const { sharedIpAddress, ipAddresses } = AppIpAddressesApiResponseSchema.parse(data.app);
338
+ return [
339
+ ...sharedIpAddress ? [{ address: sharedIpAddress, type: "shared_v4" }] : [],
340
+ ...ipAddresses.nodes
341
+ ];
342
+ }
343
+ };
291
344
  /**
292
345
  * Operate an app's machines.
293
346
  *
@@ -503,6 +556,18 @@ var killProcessTree = promisify2(treeKill);
503
556
  import {
504
557
  spawn as cpSpawn
505
558
  } from "child_process";
559
+ var STREAMED_STDERR_TAIL_LINES = 20;
560
+ var SpawnError = class extends Error {
561
+ exitCode;
562
+ stdout;
563
+ stderr;
564
+ constructor(message, details) {
565
+ super(message);
566
+ this.exitCode = details.exitCode;
567
+ this.stdout = details.stdout;
568
+ this.stderr = details.stderr;
569
+ }
570
+ };
506
571
  function spawn(command, args, options) {
507
572
  return new Promise((resolve, reject) => {
508
573
  const { streamToConsole, ...spawnOptions } = options || {};
@@ -530,8 +595,12 @@ function spawn(command, args, options) {
530
595
  if (code === 0) {
531
596
  resolve({ stdout, stderr });
532
597
  } else {
533
- reject(new Error(`Process exited with code ${code}
534
- Error: ${stderr}`));
598
+ const lines = stderr.replace(/\r?\n$/, "").split(/\r?\n/);
599
+ const message = streamToConsole && lines.length > STREAMED_STDERR_TAIL_LINES ? `Process exited with code ${code}
600
+ Error (last ${STREAMED_STDERR_TAIL_LINES} lines; the full output is above):
601
+ ${lines.slice(-STREAMED_STDERR_TAIL_LINES).join("\n")}` : `Process exited with code ${code}
602
+ Error: ${stderr}`;
603
+ reject(new SpawnError(message, { exitCode: code, stdout, stderr }));
535
604
  }
536
605
  });
537
606
  process2.on("error", reject);
@@ -576,20 +645,24 @@ Output: ${output}`)
576
645
  import { ZodError } from "zod";
577
646
 
578
647
  // libs/shared/util/zod/src/lib/coerce-boolean.ts
579
- import { z as z3 } from "zod";
648
+ import { z as z5 } from "zod";
580
649
 
581
650
  // libs/shared/util/zod/src/lib/create-lowercase-schema.ts
582
- import { z as z4 } from "zod";
651
+ import { z as z6 } from "zod";
583
652
 
584
653
  // libs/shared/util/zod/src/lib/json.schema.ts
585
- import { z as z5 } from "zod";
586
- var LiteralSchema = z5.union([z5.string(), z5.number(), z5.boolean(), z5.null()]);
587
- var JsonSchema = z5.lazy(
588
- () => z5.union([LiteralSchema, z5.array(JsonSchema), z5.record(JsonSchema)])
654
+ import { z as z7 } from "zod";
655
+ var LiteralSchema = z7.union([z7.string(), z7.number(), z7.boolean(), z7.null()]);
656
+ var JsonSchema = z7.lazy(
657
+ () => z7.union([
658
+ LiteralSchema,
659
+ z7.array(JsonSchema),
660
+ z7.record(z7.string(), JsonSchema)
661
+ ])
589
662
  );
590
663
 
591
664
  // libs/shared/util/zod/src/lib/with-camel-case.preprocess.ts
592
- import { z as z6 } from "zod";
665
+ import { z as z8 } from "zod";
593
666
  var toCamelCase = (str, specialCases = {}) => {
594
667
  if (specialCases[str]) {
595
668
  return specialCases[str];
@@ -639,7 +712,7 @@ var transformKeys = (options) => {
639
712
  };
640
713
  var withCamelCase = (schema, options = {}) => {
641
714
  const { preserve = [], specialCases = {} } = options;
642
- return z6.preprocess(
715
+ return z8.preprocess(
643
716
  (data) => transformKeys({
644
717
  currentPath: [],
645
718
  data,
@@ -651,38 +724,38 @@ var withCamelCase = (schema, options = {}) => {
651
724
  };
652
725
 
653
726
  // libs/shared/util/zod/src/lib/with-env-vars.preprocess.ts
654
- import { z as z7 } from "zod";
727
+ import { z as z9 } from "zod";
655
728
 
656
729
  // libs/shared/util/zod/src/lib/with-replace-all.preprocess.ts
657
- import { z as z8 } from "zod";
730
+ import { z as z10 } from "zod";
658
731
 
659
732
  // packages/fly-node/src/lib/schemas/apps-create.schema.ts
660
- import { z as z9 } from "zod";
733
+ import { z as z11 } from "zod";
661
734
  var AppsCreateTransformedResponseSchema = withCamelCase(
662
- z9.object({
663
- id: z9.string(),
664
- name: z9.string()
735
+ z11.object({
736
+ id: z11.string(),
737
+ name: z11.string()
665
738
  })
666
739
  );
667
740
 
668
741
  // packages/fly-node/src/lib/schemas/apps-list.schema.ts
669
- import { z as z10 } from "zod";
670
- var AppsListTransformedResponseSchema = z10.array(
742
+ import { z as z12 } from "zod";
743
+ var AppsListTransformedResponseSchema = z12.array(
671
744
  withCamelCase(
672
- z10.object({
673
- id: z10.string(),
674
- name: z10.string(),
675
- status: z10.string(),
676
- deployed: z10.boolean(),
677
- hostname: z10.string(),
678
- organization: z10.object({
679
- name: z10.string(),
680
- slug: z10.string()
745
+ z12.object({
746
+ id: z12.string(),
747
+ name: z12.string(),
748
+ status: z12.string(),
749
+ deployed: z12.boolean(),
750
+ hostname: z12.string(),
751
+ organization: z12.object({
752
+ name: z12.string(),
753
+ slug: z12.string()
681
754
  }),
682
- currentRelease: z10.nullable(
683
- z10.object({
684
- status: z10.string(),
685
- createdAt: z10.string().datetime()
755
+ currentRelease: z12.nullable(
756
+ z12.object({
757
+ status: z12.string(),
758
+ createdAt: z12.string().datetime()
686
759
  })
687
760
  )
688
761
  })
@@ -690,53 +763,53 @@ var AppsListTransformedResponseSchema = z10.array(
690
763
  );
691
764
 
692
765
  // packages/fly-node/src/lib/schemas/build-response.schema.ts
693
- import { z as z11 } from "zod";
694
- var BuildResponseSchema = z11.object({
695
- appName: z11.string(),
696
- imageRef: z11.string()
766
+ import { z as z13 } from "zod";
767
+ var BuildResponseSchema = z13.object({
768
+ appName: z13.string(),
769
+ imageRef: z13.string()
697
770
  });
698
771
 
699
772
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
700
- import { z as z13 } from "zod";
773
+ import { z as z15 } from "zod";
701
774
 
702
775
  // packages/fly-node/src/lib/schemas/certs-list.schema.ts
703
- import { z as z12 } from "zod";
704
- var CertsListFlyResponseElementSchema = z12.object({
705
- createdAt: z12.string().datetime(),
706
- hostname: z12.string(),
707
- clientStatus: z12.string()
776
+ import { z as z14 } from "zod";
777
+ var CertsListFlyResponseElementSchema = z14.object({
778
+ createdAt: z14.string().datetime(),
779
+ hostname: z14.string(),
780
+ clientStatus: z14.string()
708
781
  });
709
- var CertsListTransformedResponseSchema = z12.array(
782
+ var CertsListTransformedResponseSchema = z14.array(
710
783
  withCamelCase(CertsListFlyResponseElementSchema)
711
784
  );
712
785
 
713
786
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
714
- var CertsListWithAppTransformedResponseSchema = z13.array(
787
+ var CertsListWithAppTransformedResponseSchema = z15.array(
715
788
  withCamelCase(
716
789
  CertsListFlyResponseElementSchema.extend({
717
- app: z13.string()
790
+ app: z15.string()
718
791
  })
719
792
  )
720
793
  );
721
794
 
722
795
  // packages/fly-node/src/lib/schemas/config-show.schema.ts
723
- import { z as z14 } from "zod";
796
+ import { z as z16 } from "zod";
724
797
  var ConfigShowResponseSchema = withCamelCase(
725
- z14.object({
726
- app: z14.string(),
727
- primaryRegion: z14.string().optional(),
728
- build: z14.record(z14.string(), z14.any()).optional().or(
729
- z14.object({
730
- args: z14.record(z14.string(), z14.string()).optional(),
731
- dockerfile: z14.string().optional(),
732
- image: z14.string().optional()
798
+ z16.object({
799
+ app: z16.string(),
800
+ primaryRegion: z16.string().optional(),
801
+ build: z16.record(z16.string(), z16.any()).optional().or(
802
+ z16.object({
803
+ args: z16.record(z16.string(), z16.string()).optional(),
804
+ dockerfile: z16.string().optional(),
805
+ image: z16.string().optional()
733
806
  })
734
807
  ),
735
- deploy: z14.record(z14.string(), z14.any()).optional().or(z14.object({ strategy: z14.string().optional() })),
736
- env: z14.record(z14.string(), z14.string()).optional(),
737
- httpService: z14.record(z14.string(), z14.any()).optional(),
738
- mounts: z14.record(z14.string(), z14.any()).optional(),
739
- services: z14.array(z14.record(z14.string(), z14.any())).optional()
808
+ deploy: z16.record(z16.string(), z16.any()).optional().or(z16.object({ strategy: z16.string().optional() })),
809
+ env: z16.record(z16.string(), z16.string()).optional(),
810
+ httpService: z16.record(z16.string(), z16.any()).optional(),
811
+ mounts: z16.record(z16.string(), z16.any()).optional(),
812
+ services: z16.array(z16.record(z16.string(), z16.any())).optional()
740
813
  }),
741
814
  {
742
815
  preserve: ["build.args", "env"]
@@ -744,140 +817,139 @@ var ConfigShowResponseSchema = withCamelCase(
744
817
  );
745
818
 
746
819
  // packages/fly-node/src/lib/schemas/deploy.schema.ts
747
- import { z as z15 } from "zod";
748
- var DeployResponseSchema = z15.object({
749
- app: z15.string(),
750
- hostname: z15.string(),
751
- url: z15.string().url()
820
+ import { z as z17 } from "zod";
821
+ var DeployResponseSchema = z17.object({
822
+ app: z17.string(),
823
+ hostname: z17.string(),
824
+ url: z17.string().url()
752
825
  });
753
826
 
754
827
  // packages/fly-node/src/lib/schemas/helper-schemas.ts
755
- import { z as z16 } from "zod";
756
- var AllowEmptyUrlSchema = z16.string().url().or(z16.literal(""));
757
- var NameSchema = z16.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
828
+ import { z as z18 } from "zod";
829
+ var AllowEmptyUrlSchema = z18.string().url().or(z18.literal(""));
830
+ var NameSchema = z18.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
758
831
 
759
832
  // packages/fly-node/src/lib/schemas/ips-list.schema.ts
760
- import { z as z17 } from "zod";
761
- var IpTypeSchema = z17.enum(["v4", "v6", "shared_v4", "private_v6"]).or(z17.string());
762
- var IpsListFlyResponseElementSchema = z17.object({
763
- id: z17.string(),
764
- address: z17.string(),
833
+ import { z as z19 } from "zod";
834
+ var IpsListFlyResponseElementSchema = z19.object({
835
+ id: z19.string(),
836
+ address: z19.string(),
765
837
  type: IpTypeSchema,
766
- region: z17.string(),
767
- createdAt: z17.string()
838
+ region: z19.string(),
839
+ createdAt: z19.string()
768
840
  });
769
- var IpsListTransformedResponseSchema = z17.array(
841
+ var IpsListTransformedResponseSchema = z19.array(
770
842
  withCamelCase(IpsListFlyResponseElementSchema)
771
843
  );
772
844
 
773
845
  // packages/fly-node/src/lib/schemas/postgres-list.ts
774
- import { z as z18 } from "zod";
775
- var PostgresListTransformedResponseSchema = z18.array(
846
+ import { z as z20 } from "zod";
847
+ var PostgresListTransformedResponseSchema = z20.array(
776
848
  withCamelCase(
777
- z18.object({
778
- deployed: z18.boolean(),
779
- hostname: z18.string(),
780
- id: z18.string(),
781
- name: z18.string(),
782
- organization: z18.object({ id: z18.string(), slug: z18.string() }),
783
- status: z18.string(),
784
- version: z18.number()
849
+ z20.object({
850
+ deployed: z20.boolean(),
851
+ hostname: z20.string(),
852
+ id: z20.string(),
853
+ name: z20.string(),
854
+ organization: z20.object({ id: z20.string(), slug: z20.string() }),
855
+ status: z20.string(),
856
+ version: z20.number()
785
857
  })
786
858
  )
787
- ).or(z18.string());
859
+ ).or(z20.string());
788
860
 
789
861
  // packages/fly-node/src/lib/schemas/postgres-users-list.ts
790
- import { z as z19 } from "zod";
791
- var PostgresUsersListTransformedResponseSchema = z19.array(
862
+ import { z as z21 } from "zod";
863
+ var PostgresUsersListTransformedResponseSchema = z21.array(
792
864
  withCamelCase(
793
- z19.object({
794
- username: z19.string(),
795
- superuser: z19.boolean(),
796
- databases: z19.array(z19.string())
865
+ z21.object({
866
+ username: z21.string(),
867
+ superuser: z21.boolean(),
868
+ databases: z21.array(z21.string())
797
869
  })
798
870
  )
799
871
  );
800
872
 
801
873
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
802
- import { z as z21 } from "zod";
874
+ import { z as z23 } from "zod";
803
875
 
804
876
  // packages/fly-node/src/lib/schemas/secrets-list.schema.ts
805
- import { z as z20 } from "zod";
806
- var SecretsListFlyResponseElementSchema = z20.object({
807
- name: z20.string(),
808
- digest: z20.string()
877
+ import { z as z22 } from "zod";
878
+ var SecretsListFlyResponseElementSchema = z22.object({
879
+ name: z22.string(),
880
+ digest: z22.string()
809
881
  });
810
- var SecretsListTransformedResponseSchema = z20.array(
882
+ var SecretsListTransformedResponseSchema = z22.array(
811
883
  withCamelCase(SecretsListFlyResponseElementSchema)
812
884
  );
813
885
 
814
886
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
815
- var SecretsListWithAppTransformedResponseSchema = z21.array(
887
+ var SecretsListWithAppTransformedResponseSchema = z23.array(
816
888
  withCamelCase(
817
889
  SecretsListFlyResponseElementSchema.extend({
818
- app: z21.string()
890
+ app: z23.string()
819
891
  })
820
892
  )
821
893
  );
822
894
 
823
895
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
824
- import { z as z23 } from "zod";
896
+ import { z as z25 } from "zod";
825
897
 
826
898
  // packages/fly-node/src/lib/schemas/status.schema.ts
827
- import { z as z22 } from "zod";
828
- var statusFlyResponseSchema = z22.object({
829
- deployed: z22.boolean(),
830
- hostname: z22.string(),
831
- id: z22.string(),
832
- machines: z22.array(
833
- z22.object({
834
- id: z22.string(),
835
- name: z22.string(),
836
- state: z22.string(),
837
- region: z22.string(),
838
- imageRef: z22.object({
839
- registry: z22.string(),
840
- repository: z22.string(),
841
- tag: z22.string(),
842
- digest: z22.string(),
843
- labels: z22.record(z22.string()).optional()
899
+ import { z as z24 } from "zod";
900
+ var statusFlyResponseSchema = z24.object({
901
+ deployed: z24.boolean(),
902
+ hostname: z24.string(),
903
+ id: z24.string(),
904
+ machines: z24.array(
905
+ z24.object({
906
+ id: z24.string(),
907
+ name: z24.string(),
908
+ state: z24.string(),
909
+ region: z24.string(),
910
+ imageRef: z24.object({
911
+ registry: z24.string(),
912
+ repository: z24.string(),
913
+ tag: z24.string(),
914
+ digest: z24.string(),
915
+ labels: z24.record(z24.string(), z24.string()).optional()
844
916
  }),
845
- createdAt: z22.string().datetime(),
846
- updatedAt: z22.string().datetime(),
847
- config: z22.object({
848
- env: z22.record(z22.string()),
849
- metadata: z22.record(z22.string()),
850
- guest: z22.object({
851
- cpu_kind: z22.string().optional(),
852
- cpus: z22.number().optional(),
853
- memory_mb: z22.number().optional()
917
+ createdAt: z24.string().datetime(),
918
+ updatedAt: z24.string().datetime(),
919
+ config: z24.object({
920
+ env: z24.record(z24.string(), z24.string()),
921
+ metadata: z24.record(z24.string(), z24.string()),
922
+ guest: z24.object({
923
+ cpu_kind: z24.string().optional(),
924
+ cpus: z24.number().optional(),
925
+ memory_mb: z24.number().optional()
854
926
  }).optional()
855
927
  }),
856
- events: z22.array(
857
- z22.object({
858
- type: z22.string(),
859
- status: z22.string(),
860
- timestamp: z22.number()
928
+ events: z24.array(
929
+ z24.object({
930
+ type: z24.string(),
931
+ status: z24.string(),
932
+ timestamp: z24.number()
861
933
  })
862
934
  ),
863
- checks: z22.array(
864
- z22.object({
865
- name: z22.string(),
866
- status: z22.string(),
867
- output: z22.string(),
868
- updatedAt: z22.string().datetime()
935
+ checks: z24.array(
936
+ z24.object({
937
+ name: z24.string(),
938
+ status: z24.string(),
939
+ output: z24.string(),
940
+ updatedAt: z24.string().datetime()
869
941
  })
870
942
  ).optional(),
871
- hostStatus: z22.string()
943
+ hostStatus: z24.string()
872
944
  })
873
945
  ),
874
- name: z22.string(),
875
- organization: z22.object({
876
- id: z22.string(),
877
- slug: z22.string()
946
+ name: z24.string(),
947
+ organization: z24.object({
948
+ id: z24.string(),
949
+ slug: z24.string()
878
950
  }),
879
- status: z22.string(),
880
- version: z22.number()
951
+ status: z24.string(),
952
+ version: z24.number()
881
953
  });
882
954
  var StatusTransformedResponseSchema = withCamelCase(
883
955
  statusFlyResponseSchema,
@@ -890,12 +962,24 @@ var StatusTransformedResponseSchema = withCamelCase(
890
962
  specialCases: { AppURL: "appUrl" }
891
963
  }
892
964
  );
965
+ var statusLookupSchema = withCamelCase(
966
+ z24.object({
967
+ name: z24.string(),
968
+ hostname: z24.string(),
969
+ machines: z24.array(
970
+ z24.object({
971
+ id: z24.string(),
972
+ state: z24.string()
973
+ }).passthrough()
974
+ )
975
+ }).passthrough()
976
+ );
893
977
 
894
978
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
895
979
  var StatusExtendedTransformedResponseSchema = withCamelCase(
896
980
  statusFlyResponseSchema.extend({
897
- domains: z23.array(z23.object({ hostname: z23.string() })),
898
- secrets: z23.array(z23.object({ name: z23.string() }))
981
+ domains: z25.array(z25.object({ hostname: z25.string() })),
982
+ secrets: z25.array(z25.object({ name: z25.string() }))
899
983
  }),
900
984
  {
901
985
  preserve: [
@@ -907,21 +991,33 @@ var StatusExtendedTransformedResponseSchema = withCamelCase(
907
991
  );
908
992
 
909
993
  // packages/fly-node/src/lib/schemas/version.schema.ts
910
- import { z as z24 } from "zod";
994
+ import { z as z26 } from "zod";
911
995
  var VersionTransformedResponseSchema = withCamelCase(
912
- z24.object({
913
- name: z24.string(),
914
- version: z24.string(),
915
- commit: z24.string(),
916
- branchName: z24.string(),
917
- buildDate: z24.string().datetime(),
918
- os: z24.string(),
919
- architecture: z24.string(),
920
- environment: z24.string()
996
+ z26.object({
997
+ name: z26.string(),
998
+ version: z26.string(),
999
+ commit: z26.string(),
1000
+ branchName: z26.string(),
1001
+ buildDate: z26.string().datetime(),
1002
+ os: z26.string(),
1003
+ architecture: z26.string(),
1004
+ environment: z26.string()
921
1005
  })
922
1006
  );
923
1007
 
924
1008
  // packages/fly-node/src/lib/fly.class.ts
1009
+ var TRANSIENT_FLY_ERRORS = [
1010
+ { cause: "no capacity available", pattern: /no capacity available/i },
1011
+ { cause: "builder deadline exceeded", pattern: /deadline_exceeded/i },
1012
+ {
1013
+ cause: "timed out connecting to machine",
1014
+ pattern: /timed out connecting to machine/i
1015
+ },
1016
+ // The status text, not a bare 503: an app whose health check answers
1017
+ // 503 is broken, not unlucky, and must not be deployed three times
1018
+ { cause: "Fly API 503", pattern: /503 Service Unavailable/i }
1019
+ ];
1020
+ var TRANSIENT_RETRY_DELAYS_MS = [1e4, 3e4];
925
1021
  var MACHINE_STATE_INTERVAL_MS = 2e3;
926
1022
  var MACHINE_STATE_TIMEOUT_MS = 12e4;
927
1023
  var Fly = class {
@@ -1007,7 +1103,9 @@ ${error}`);
1007
1103
  return await this.version();
1008
1104
  } catch (error) {
1009
1105
  throw new Error(`[version] something broke
1010
- ${error}`);
1106
+ ${error}`, {
1107
+ cause: error
1108
+ });
1011
1109
  }
1012
1110
  }
1013
1111
  };
@@ -1034,7 +1132,8 @@ ${error}`);
1034
1132
  } catch (error) {
1035
1133
  throw new Error(
1036
1134
  `[create app] something broke, check your apps
1037
- ${error}`
1135
+ ${error}`,
1136
+ { cause: error }
1038
1137
  );
1039
1138
  }
1040
1139
  },
@@ -1060,7 +1159,8 @@ ${error}`
1060
1159
  } catch (error) {
1061
1160
  throw new Error(
1062
1161
  `[destroy app] something broke, check your apps
1063
- ${error}`
1162
+ ${error}`,
1163
+ { cause: error }
1064
1164
  );
1065
1165
  }
1066
1166
  },
@@ -1075,7 +1175,7 @@ ${error}`
1075
1175
  return await this.fetchAllApps("throwOnError");
1076
1176
  } catch (error) {
1077
1177
  throw new Error(`[list] something broke
1078
- ${error}`);
1178
+ ${error}`, { cause: error });
1079
1179
  }
1080
1180
  }
1081
1181
  };
@@ -1100,7 +1200,8 @@ ${error}`);
1100
1200
  } catch (error) {
1101
1201
  throw new Error(
1102
1202
  `[add certificate] something broke, check your app certificates
1103
- ${error}`
1203
+ ${error}`,
1204
+ { cause: error }
1104
1205
  );
1105
1206
  }
1106
1207
  },
@@ -1118,7 +1219,9 @@ ${error}`
1118
1219
  return result;
1119
1220
  } catch (error) {
1120
1221
  throw new Error(`[list certificates] something broke
1121
- ${error}`);
1222
+ ${error}`, {
1223
+ cause: error
1224
+ });
1122
1225
  }
1123
1226
  },
1124
1227
  /**
@@ -1138,7 +1241,8 @@ ${error}`);
1138
1241
  } catch (error) {
1139
1242
  throw new Error(
1140
1243
  `[remove certificate] something broke, check your app certificates
1141
- ${error}`
1244
+ ${error}`,
1245
+ { cause: error }
1142
1246
  );
1143
1247
  }
1144
1248
  }
@@ -1165,7 +1269,9 @@ ${error}`
1165
1269
  );
1166
1270
  } catch (error) {
1167
1271
  throw new Error(`[save config] something broke
1168
- ${error}`);
1272
+ ${error}`, {
1273
+ cause: error
1274
+ });
1169
1275
  }
1170
1276
  },
1171
1277
  /**
@@ -1181,7 +1287,9 @@ ${error}`);
1181
1287
  return await this.showConfig("throwOnError", options);
1182
1288
  } catch (error) {
1183
1289
  throw new Error(`[show config] something broke
1184
- ${error}`);
1290
+ ${error}`, {
1291
+ cause: error
1292
+ });
1185
1293
  }
1186
1294
  }
1187
1295
  };
@@ -1224,7 +1332,7 @@ ${error}`);
1224
1332
  }
1225
1333
  const { appName } = await this.deployApp(options);
1226
1334
  this.logger.info(`Application '${appName}' was deployed`);
1227
- const status = await this.fetchAppStatus("throwOnError", {
1335
+ const status = await this.fetchAppLookup("throwOnError", {
1228
1336
  app: appName
1229
1337
  });
1230
1338
  return DeployResponseSchema.parse({
@@ -1235,7 +1343,8 @@ ${error}`);
1235
1343
  } catch (error) {
1236
1344
  throw new Error(
1237
1345
  `[deploy] something broke, check your ${isBuildOnly ? "builds" : "deployments"}
1238
- ${error}`
1346
+ ${error}`,
1347
+ { cause: error }
1239
1348
  );
1240
1349
  }
1241
1350
  };
@@ -1256,7 +1365,9 @@ ${error}`
1256
1365
  return await this.fetchAppIps("throwOnError", options);
1257
1366
  } catch (error) {
1258
1367
  throw new Error(`[list ips] something broke
1259
- ${error}`);
1368
+ ${error}`, {
1369
+ cause: error
1370
+ });
1260
1371
  }
1261
1372
  },
1262
1373
  /**
@@ -1266,7 +1377,8 @@ ${error}`);
1266
1377
  * safe on every deploy rather than only on create. That matters because
1267
1378
  * `flyctl` allocates addresses only for an app it creates itself — an app
1268
1379
  * that arrives any other way, such as a registry push auto-creating it,
1269
- * deploys green and answers nothing.
1380
+ * deploys green and answers nothing. `deploy` runs it before every
1381
+ * deploy that is not build-only.
1270
1382
  *
1271
1383
  * @param options - The application, and which addresses to ensure
1272
1384
  * @returns The addresses the application holds afterwards
@@ -1278,19 +1390,23 @@ ${error}`);
1278
1390
  const { sharedV4 = true, v6 = true } = options ?? {};
1279
1391
  const existing = await this.fetchAppIps("throwOnError", options);
1280
1392
  const has = (...types) => existing.some((ip) => types.includes(ip.type));
1393
+ let allocated = false;
1281
1394
  if (sharedV4 && !has("v4", "shared_v4")) {
1282
1395
  await this.allocateIp("allocate-v4", options);
1283
1396
  this.logger.info("Allocated a shared IPv4 address");
1397
+ allocated = true;
1284
1398
  }
1285
1399
  if (v6 && !has("v6")) {
1286
1400
  await this.allocateIp("allocate-v6", options);
1287
1401
  this.logger.info("Allocated a dedicated IPv6 address");
1402
+ allocated = true;
1288
1403
  }
1289
- return await this.fetchAppIps("throwOnError", options);
1404
+ return allocated ? await this.fetchAppIps("throwOnError", options) : existing;
1290
1405
  } catch (error) {
1291
1406
  throw new Error(
1292
1407
  `[ensure ips] something broke, check your app addresses
1293
- ${error}`
1408
+ ${error}`,
1409
+ { cause: error }
1294
1410
  );
1295
1411
  }
1296
1412
  }
@@ -1313,7 +1429,9 @@ ${error}`
1313
1429
  this.logger.info(`Machine '${machineId}' in app '${app}' was started`);
1314
1430
  } catch (error) {
1315
1431
  throw new Error(`[start machine] something broke
1316
- ${error}`);
1432
+ ${error}`, {
1433
+ cause: error
1434
+ });
1317
1435
  }
1318
1436
  },
1319
1437
  /**
@@ -1330,7 +1448,9 @@ ${error}`);
1330
1448
  this.logger.info(`Machine '${machineId}' in app '${app}' was stopped`);
1331
1449
  } catch (error) {
1332
1450
  throw new Error(`[stop machine] something broke
1333
- ${error}`);
1451
+ ${error}`, {
1452
+ cause: error
1453
+ });
1334
1454
  }
1335
1455
  },
1336
1456
  /**
@@ -1353,7 +1473,9 @@ ${error}`);
1353
1473
  );
1354
1474
  } catch (error) {
1355
1475
  throw new Error(`[restart machine] something broke
1356
- ${error}`);
1476
+ ${error}`, {
1477
+ cause: error
1478
+ });
1357
1479
  }
1358
1480
  },
1359
1481
  /**
@@ -1374,7 +1496,9 @@ ${error}`);
1374
1496
  this.logger.info(`Machine '${machineId}' in app '${app}' was updated`);
1375
1497
  } catch (error) {
1376
1498
  throw new Error(`[update machine] something broke
1377
- ${error}`);
1499
+ ${error}`, {
1500
+ cause: error
1501
+ });
1378
1502
  }
1379
1503
  }
1380
1504
  };
@@ -1408,7 +1532,9 @@ ${error}`);
1408
1532
  return await this.sshExec(app, command);
1409
1533
  } catch (error) {
1410
1534
  throw new Error(`[ssh exec] something broke
1411
- ${error}`);
1535
+ ${error}`, {
1536
+ cause: error
1537
+ });
1412
1538
  }
1413
1539
  }
1414
1540
  };
@@ -1434,7 +1560,8 @@ ${error}`);
1434
1560
  } catch (error) {
1435
1561
  throw new Error(
1436
1562
  `[set secrets] something broke, check your app secrets
1437
- ${error}`
1563
+ ${error}`,
1564
+ { cause: error }
1438
1565
  );
1439
1566
  }
1440
1567
  },
@@ -1457,7 +1584,9 @@ ${error}`
1457
1584
  this.logger.info(`Staged secrets were deployed for '${app}'`);
1458
1585
  } catch (error) {
1459
1586
  throw new Error(`[deploy secrets] something broke
1460
- ${error}`);
1587
+ ${error}`, {
1588
+ cause: error
1589
+ });
1461
1590
  }
1462
1591
  },
1463
1592
  /**
@@ -1474,7 +1603,9 @@ ${error}`);
1474
1603
  return result;
1475
1604
  } catch (error) {
1476
1605
  throw new Error(`[list secrets] something broke
1477
- ${error}`);
1606
+ ${error}`, {
1607
+ cause: error
1608
+ });
1478
1609
  }
1479
1610
  },
1480
1611
  /**
@@ -1495,7 +1626,8 @@ ${error}`);
1495
1626
  } catch (error) {
1496
1627
  throw new Error(
1497
1628
  `[unset secrets] something broke, check your app secrets
1498
- ${error}`
1629
+ ${error}`,
1630
+ { cause: error }
1499
1631
  );
1500
1632
  }
1501
1633
  }
@@ -1608,7 +1740,7 @@ ${error}`);
1608
1740
  lookupApp = appConfig.app;
1609
1741
  }
1610
1742
  if (lookupApp) {
1611
- const status = await this.fetchAppStatus("nullOnError", {
1743
+ const status = await this.fetchAppLookup("nullOnError", {
1612
1744
  app: lookupApp
1613
1745
  });
1614
1746
  if (status) {
@@ -1710,6 +1842,10 @@ ${error}`);
1710
1842
  );
1711
1843
  }
1712
1844
  }
1845
+ const servesTraffic = !!appConfig.httpService || (appConfig.services?.length ?? 0) > 0;
1846
+ if (!options?.buildOnly && servesTraffic) {
1847
+ await this.ips.ensure({ app: appName });
1848
+ }
1713
1849
  const args = ["deploy", "--app", appName, "--config", deployConfig];
1714
1850
  if (options?.region) {
1715
1851
  args.push("--region", options.region);
@@ -1736,10 +1872,10 @@ ${error}`);
1736
1872
  this.logger.info(
1737
1873
  options?.buildOnly ? `Building image for '${appName}'...` : `Deploying '${appName}'...`
1738
1874
  );
1739
- const output = await this.execFly(
1740
- args,
1741
- options?.buildOnly ? { streamStrategy: "combined" } : void 0
1742
- );
1875
+ const output = await this.execFly(args, {
1876
+ streamStrategy: options?.buildOnly ? "combined" : "stdout",
1877
+ retry: true
1878
+ });
1743
1879
  const imageRef = options?.buildOnly ? output?.match(/registry\.fly\.io\/\S+/)?.[0] : void 0;
1744
1880
  return { appName, imageRef };
1745
1881
  }
@@ -1785,7 +1921,7 @@ ${error}`);
1785
1921
  * @throws An error if the secrets cannot be set
1786
1922
  */
1787
1923
  async setAppSecrets(secrets, options) {
1788
- const status = await this.fetchAppStatus("throwOnError", options);
1924
+ const status = await this.fetchAppLookup("throwOnError", options);
1789
1925
  const args = ["secrets", "set"];
1790
1926
  args.push(...this.getAppOrConfigArgs(options));
1791
1927
  if (options?.stage) {
@@ -1794,7 +1930,7 @@ ${error}`);
1794
1930
  for (const [key, value] of Object.entries(secrets)) {
1795
1931
  args.push(`${key}=${this.safeArg(value)}`);
1796
1932
  }
1797
- await this.execFly(args);
1933
+ await this.execFly(args, { retry: options?.stage === true });
1798
1934
  return NameSchema.parse(status.name);
1799
1935
  }
1800
1936
  /**
@@ -1803,7 +1939,7 @@ ${error}`);
1803
1939
  * @throws An error if the secrets cannot be unset
1804
1940
  */
1805
1941
  async unsetAppSecrets(keys, options) {
1806
- const status = await this.fetchAppStatus("throwOnError", options);
1942
+ const status = await this.fetchAppLookup("throwOnError", options);
1807
1943
  const args = ["secrets", "unset"];
1808
1944
  args.push(...this.getAppOrConfigArgs(options));
1809
1945
  if (options?.stage) {
@@ -1819,7 +1955,7 @@ ${error}`);
1819
1955
  * @throws An error if the domain cannot be added
1820
1956
  */
1821
1957
  async addAppCertificate(hostname, options) {
1822
- const status = await this.fetchAppStatus("throwOnError", options);
1958
+ const status = await this.fetchAppLookup("throwOnError", options);
1823
1959
  const args = ["certs", "add", hostname];
1824
1960
  args.push(...this.getAppOrConfigArgs(options));
1825
1961
  args.push("--json");
@@ -1856,7 +1992,7 @@ ${error}`);
1856
1992
  args.push("--json");
1857
1993
  try {
1858
1994
  return await IpsListTransformedResponseSchema.parseAsync(
1859
- await this.execFly(args)
1995
+ await this.execFly(args, { retry: true })
1860
1996
  );
1861
1997
  } catch (error) {
1862
1998
  if (onError === "throwOnError") {
@@ -1871,7 +2007,7 @@ ${error}`);
1871
2007
  * @throws An error if the domain cannot be removed
1872
2008
  */
1873
2009
  async removeAppCertificate(hostname, options) {
1874
- const status = await this.fetchAppStatus("throwOnError", options);
2010
+ const status = await this.fetchAppLookup("throwOnError", options);
1875
2011
  const args = ["certs", "remove", hostname];
1876
2012
  args.push(...this.getAppOrConfigArgs(options));
1877
2013
  args.push("--yes");
@@ -1946,7 +2082,7 @@ ${error}`);
1946
2082
  async waitForMachineState(app, machineId, states) {
1947
2083
  const deadline = Date.now() + MACHINE_STATE_TIMEOUT_MS;
1948
2084
  while (Date.now() < deadline) {
1949
- const status = await this.fetchAppStatus("nullOnError", { app });
2085
+ const status = await this.fetchAppLookup("nullOnError", { app });
1950
2086
  const machine = status?.machines.find(({ id }) => id === machineId);
1951
2087
  if (machine && states.includes(machine.state)) {
1952
2088
  return;
@@ -2057,6 +2193,27 @@ ${error}`);
2057
2193
  this.logger.info(`Failed to parse response:
2058
2194
  ${error.message}`);
2059
2195
  this.logger.info(`Raw response:
2196
+ ${JSON.stringify(response, null, 2)}`);
2197
+ }
2198
+ return null;
2199
+ }
2200
+ }
2201
+ async fetchAppLookup(onError, options) {
2202
+ const args = ["status"];
2203
+ args.push(...this.getAppOrConfigArgs(options));
2204
+ args.push("--json");
2205
+ let response = null;
2206
+ try {
2207
+ response = await this.execFly(args);
2208
+ return statusLookupSchema.parse(response);
2209
+ } catch (error) {
2210
+ if (onError === "throwOnError") {
2211
+ throw error;
2212
+ }
2213
+ if (error instanceof ZodError) {
2214
+ this.logger.info(`Failed to parse response:
2215
+ ${error.message}`);
2216
+ this.logger.info(`Raw response:
2060
2217
  ${JSON.stringify(response, null, 2)}`);
2061
2218
  }
2062
2219
  return null;
@@ -2189,33 +2346,32 @@ ${JSON.stringify(response, null, 2)}`);
2189
2346
  }
2190
2347
  const flyCmd = "flyctl";
2191
2348
  const toLogCmd = `${flyCmd} ${args.join(" ")}`;
2349
+ const { retry = false, ...execOpts } = options ?? {};
2192
2350
  let output = "";
2193
- try {
2194
- this.traceCLI("CALL", toLogCmd);
2195
- if (options?.prompt) {
2196
- output = await spawnPty(flyCmd, args, { prompt: options.prompt });
2197
- this.traceCLI("RESULT", output);
2198
- } else {
2199
- const { streamStrategy = "stdout", ...spawnOpts } = options ?? {};
2200
- const result = await spawn(flyCmd, args, {
2201
- ...spawnOpts,
2202
- streamToConsole: this.logger.streamToConsole
2203
- });
2204
- const stdout = result.stdout.trim();
2205
- const stderr = result.stderr.trim();
2206
- this.traceCLI("RESULT", `${stdout}${stderr ? `
2207
- ${stderr}` : ""}`);
2208
- output = streamStrategy === "combined" ? `${stdout}
2209
- ${stderr}` : streamStrategy === "stderr" ? stderr : stdout;
2210
- }
2211
- } catch (error) {
2212
- const errorMsg = error.message;
2213
- this.traceCLI("RESULT", errorMsg);
2214
- if (onError === "throwOnError") {
2215
- throw new Error(`Command failed: ${toLogCmd}
2216
- ${errorMsg}`);
2351
+ for (let attempt = 1; ; attempt++) {
2352
+ try {
2353
+ output = await this.spawnFly(flyCmd, args, toLogCmd, execOpts);
2354
+ break;
2355
+ } catch (error) {
2356
+ const errorMsg = error.message;
2357
+ this.traceCLI("RESULT", errorMsg);
2358
+ const cause = retry ? this.transientCause(error) : null;
2359
+ const delay = TRANSIENT_RETRY_DELAYS_MS[attempt - 1];
2360
+ if (cause && delay !== void 0) {
2361
+ this.logger.info(
2362
+ `Transient Fly error (${cause}), retrying in ${delay / 1e3}s (attempt ${attempt + 1} of ${TRANSIENT_RETRY_DELAYS_MS.length + 1}): ${toLogCmd}`
2363
+ );
2364
+ await new Promise((resolve) => setTimeout(resolve, delay));
2365
+ continue;
2366
+ }
2367
+ if (onError === "throwOnError") {
2368
+ throw new Error(`Command failed: ${toLogCmd}
2369
+ ${errorMsg}`, {
2370
+ cause: error
2371
+ });
2372
+ }
2373
+ return null;
2217
2374
  }
2218
- return null;
2219
2375
  }
2220
2376
  try {
2221
2377
  return JSON.parse(output);
@@ -2229,6 +2385,55 @@ ${errorMsg}`);
2229
2385
  }
2230
2386
  return void 0;
2231
2387
  }
2388
+ /**
2389
+ * @private
2390
+ * Run one fly command and assemble its output
2391
+ *
2392
+ * @returns The output selected by `streamStrategy`
2393
+ * @throws An error if the command fails
2394
+ */
2395
+ async spawnFly(flyCmd, args, toLogCmd, options) {
2396
+ this.traceCLI("CALL", toLogCmd);
2397
+ if (options.prompt) {
2398
+ const output = await spawnPty(flyCmd, args, { prompt: options.prompt });
2399
+ this.traceCLI("RESULT", output);
2400
+ return output;
2401
+ }
2402
+ const { streamStrategy = "stdout", ...spawnOpts } = options;
2403
+ const result = await spawn(flyCmd, args, {
2404
+ ...spawnOpts,
2405
+ streamToConsole: this.logger.streamToConsole
2406
+ });
2407
+ const stdout = result.stdout.trim();
2408
+ const stderr = result.stderr.trim();
2409
+ this.traceCLI("RESULT", `${stdout}${stderr ? `
2410
+ ${stderr}` : ""}`);
2411
+ return streamStrategy === "combined" ? `${stdout}
2412
+ ${stderr}` : streamStrategy === "stderr" ? stderr : stdout;
2413
+ }
2414
+ /**
2415
+ * @private
2416
+ * Name the transient Fly error behind a failed command, if it was one.
2417
+ *
2418
+ * Only the error flyctl ended with counts: from its last `Error` line to
2419
+ * the end of stderr, or the last few lines when there is none. A deploy
2420
+ * streams the app's own output and errors flyctl recovered from, and
2421
+ * matching those would repeat a deploy that failed for a real reason.
2422
+ *
2423
+ * @returns The cause, or `null` when the failure is not a known transient one
2424
+ */
2425
+ transientCause(error) {
2426
+ let text;
2427
+ if (error instanceof SpawnError) {
2428
+ const lines = error.stderr.split(/\r?\n/).filter((line) => line.trim());
2429
+ const errorLines = lines.map((line) => /^\s*Error\b/.test(line));
2430
+ const last = errorLines.lastIndexOf(true);
2431
+ text = lines.slice(last >= 0 ? last : -3).join("\n");
2432
+ } else {
2433
+ text = String(error?.message ?? error);
2434
+ }
2435
+ return TRANSIENT_FLY_ERRORS.find(({ pattern }) => pattern.test(text))?.cause ?? null;
2436
+ }
2232
2437
  /**
2233
2438
  * @private
2234
2439
  * Get the arguments for `AppOrConfig` options
@@ -2376,6 +2581,8 @@ ${errorMsg}`);
2376
2581
  }
2377
2582
  };
2378
2583
  export {
2584
+ AppIpAddressSchema,
2585
+ AppIpAddressesApiResponseSchema,
2379
2586
  CertificateApiResponseSchema,
2380
2587
  CertificateListApiResponseSchema,
2381
2588
  DnsInstructionsSchema,