@cdwr/fly-node 0.3.2 → 0.3.3

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,20 @@ 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([LiteralSchema, z7.array(JsonSchema), z7.record(JsonSchema)])
589
658
  );
590
659
 
591
660
  // libs/shared/util/zod/src/lib/with-camel-case.preprocess.ts
592
- import { z as z6 } from "zod";
661
+ import { z as z8 } from "zod";
593
662
  var toCamelCase = (str, specialCases = {}) => {
594
663
  if (specialCases[str]) {
595
664
  return specialCases[str];
@@ -639,7 +708,7 @@ var transformKeys = (options) => {
639
708
  };
640
709
  var withCamelCase = (schema, options = {}) => {
641
710
  const { preserve = [], specialCases = {} } = options;
642
- return z6.preprocess(
711
+ return z8.preprocess(
643
712
  (data) => transformKeys({
644
713
  currentPath: [],
645
714
  data,
@@ -651,38 +720,38 @@ var withCamelCase = (schema, options = {}) => {
651
720
  };
652
721
 
653
722
  // libs/shared/util/zod/src/lib/with-env-vars.preprocess.ts
654
- import { z as z7 } from "zod";
723
+ import { z as z9 } from "zod";
655
724
 
656
725
  // libs/shared/util/zod/src/lib/with-replace-all.preprocess.ts
657
- import { z as z8 } from "zod";
726
+ import { z as z10 } from "zod";
658
727
 
659
728
  // packages/fly-node/src/lib/schemas/apps-create.schema.ts
660
- import { z as z9 } from "zod";
729
+ import { z as z11 } from "zod";
661
730
  var AppsCreateTransformedResponseSchema = withCamelCase(
662
- z9.object({
663
- id: z9.string(),
664
- name: z9.string()
731
+ z11.object({
732
+ id: z11.string(),
733
+ name: z11.string()
665
734
  })
666
735
  );
667
736
 
668
737
  // packages/fly-node/src/lib/schemas/apps-list.schema.ts
669
- import { z as z10 } from "zod";
670
- var AppsListTransformedResponseSchema = z10.array(
738
+ import { z as z12 } from "zod";
739
+ var AppsListTransformedResponseSchema = z12.array(
671
740
  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()
741
+ z12.object({
742
+ id: z12.string(),
743
+ name: z12.string(),
744
+ status: z12.string(),
745
+ deployed: z12.boolean(),
746
+ hostname: z12.string(),
747
+ organization: z12.object({
748
+ name: z12.string(),
749
+ slug: z12.string()
681
750
  }),
682
- currentRelease: z10.nullable(
683
- z10.object({
684
- status: z10.string(),
685
- createdAt: z10.string().datetime()
751
+ currentRelease: z12.nullable(
752
+ z12.object({
753
+ status: z12.string(),
754
+ createdAt: z12.string().datetime()
686
755
  })
687
756
  )
688
757
  })
@@ -690,53 +759,53 @@ var AppsListTransformedResponseSchema = z10.array(
690
759
  );
691
760
 
692
761
  // 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()
762
+ import { z as z13 } from "zod";
763
+ var BuildResponseSchema = z13.object({
764
+ appName: z13.string(),
765
+ imageRef: z13.string()
697
766
  });
698
767
 
699
768
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
700
- import { z as z13 } from "zod";
769
+ import { z as z15 } from "zod";
701
770
 
702
771
  // 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()
772
+ import { z as z14 } from "zod";
773
+ var CertsListFlyResponseElementSchema = z14.object({
774
+ createdAt: z14.string().datetime(),
775
+ hostname: z14.string(),
776
+ clientStatus: z14.string()
708
777
  });
709
- var CertsListTransformedResponseSchema = z12.array(
778
+ var CertsListTransformedResponseSchema = z14.array(
710
779
  withCamelCase(CertsListFlyResponseElementSchema)
711
780
  );
712
781
 
713
782
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
714
- var CertsListWithAppTransformedResponseSchema = z13.array(
783
+ var CertsListWithAppTransformedResponseSchema = z15.array(
715
784
  withCamelCase(
716
785
  CertsListFlyResponseElementSchema.extend({
717
- app: z13.string()
786
+ app: z15.string()
718
787
  })
719
788
  )
720
789
  );
721
790
 
722
791
  // packages/fly-node/src/lib/schemas/config-show.schema.ts
723
- import { z as z14 } from "zod";
792
+ import { z as z16 } from "zod";
724
793
  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()
794
+ z16.object({
795
+ app: z16.string(),
796
+ primaryRegion: z16.string().optional(),
797
+ build: z16.record(z16.string(), z16.any()).optional().or(
798
+ z16.object({
799
+ args: z16.record(z16.string(), z16.string()).optional(),
800
+ dockerfile: z16.string().optional(),
801
+ image: z16.string().optional()
733
802
  })
734
803
  ),
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()
804
+ deploy: z16.record(z16.string(), z16.any()).optional().or(z16.object({ strategy: z16.string().optional() })),
805
+ env: z16.record(z16.string(), z16.string()).optional(),
806
+ httpService: z16.record(z16.string(), z16.any()).optional(),
807
+ mounts: z16.record(z16.string(), z16.any()).optional(),
808
+ services: z16.array(z16.record(z16.string(), z16.any())).optional()
740
809
  }),
741
810
  {
742
811
  preserve: ["build.args", "env"]
@@ -744,140 +813,139 @@ var ConfigShowResponseSchema = withCamelCase(
744
813
  );
745
814
 
746
815
  // 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()
816
+ import { z as z17 } from "zod";
817
+ var DeployResponseSchema = z17.object({
818
+ app: z17.string(),
819
+ hostname: z17.string(),
820
+ url: z17.string().url()
752
821
  });
753
822
 
754
823
  // 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-]+$/);
824
+ import { z as z18 } from "zod";
825
+ var AllowEmptyUrlSchema = z18.string().url().or(z18.literal(""));
826
+ var NameSchema = z18.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
758
827
 
759
828
  // 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(),
829
+ import { z as z19 } from "zod";
830
+ var IpsListFlyResponseElementSchema = z19.object({
831
+ id: z19.string(),
832
+ address: z19.string(),
765
833
  type: IpTypeSchema,
766
- region: z17.string(),
767
- createdAt: z17.string()
834
+ region: z19.string(),
835
+ createdAt: z19.string()
768
836
  });
769
- var IpsListTransformedResponseSchema = z17.array(
837
+ var IpsListTransformedResponseSchema = z19.array(
770
838
  withCamelCase(IpsListFlyResponseElementSchema)
771
839
  );
772
840
 
773
841
  // packages/fly-node/src/lib/schemas/postgres-list.ts
774
- import { z as z18 } from "zod";
775
- var PostgresListTransformedResponseSchema = z18.array(
842
+ import { z as z20 } from "zod";
843
+ var PostgresListTransformedResponseSchema = z20.array(
776
844
  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()
845
+ z20.object({
846
+ deployed: z20.boolean(),
847
+ hostname: z20.string(),
848
+ id: z20.string(),
849
+ name: z20.string(),
850
+ organization: z20.object({ id: z20.string(), slug: z20.string() }),
851
+ status: z20.string(),
852
+ version: z20.number()
785
853
  })
786
854
  )
787
- ).or(z18.string());
855
+ ).or(z20.string());
788
856
 
789
857
  // packages/fly-node/src/lib/schemas/postgres-users-list.ts
790
- import { z as z19 } from "zod";
791
- var PostgresUsersListTransformedResponseSchema = z19.array(
858
+ import { z as z21 } from "zod";
859
+ var PostgresUsersListTransformedResponseSchema = z21.array(
792
860
  withCamelCase(
793
- z19.object({
794
- username: z19.string(),
795
- superuser: z19.boolean(),
796
- databases: z19.array(z19.string())
861
+ z21.object({
862
+ username: z21.string(),
863
+ superuser: z21.boolean(),
864
+ databases: z21.array(z21.string())
797
865
  })
798
866
  )
799
867
  );
800
868
 
801
869
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
802
- import { z as z21 } from "zod";
870
+ import { z as z23 } from "zod";
803
871
 
804
872
  // 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()
873
+ import { z as z22 } from "zod";
874
+ var SecretsListFlyResponseElementSchema = z22.object({
875
+ name: z22.string(),
876
+ digest: z22.string()
809
877
  });
810
- var SecretsListTransformedResponseSchema = z20.array(
878
+ var SecretsListTransformedResponseSchema = z22.array(
811
879
  withCamelCase(SecretsListFlyResponseElementSchema)
812
880
  );
813
881
 
814
882
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
815
- var SecretsListWithAppTransformedResponseSchema = z21.array(
883
+ var SecretsListWithAppTransformedResponseSchema = z23.array(
816
884
  withCamelCase(
817
885
  SecretsListFlyResponseElementSchema.extend({
818
- app: z21.string()
886
+ app: z23.string()
819
887
  })
820
888
  )
821
889
  );
822
890
 
823
891
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
824
- import { z as z23 } from "zod";
892
+ import { z as z25 } from "zod";
825
893
 
826
894
  // 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()
895
+ import { z as z24 } from "zod";
896
+ var statusFlyResponseSchema = z24.object({
897
+ deployed: z24.boolean(),
898
+ hostname: z24.string(),
899
+ id: z24.string(),
900
+ machines: z24.array(
901
+ z24.object({
902
+ id: z24.string(),
903
+ name: z24.string(),
904
+ state: z24.string(),
905
+ region: z24.string(),
906
+ imageRef: z24.object({
907
+ registry: z24.string(),
908
+ repository: z24.string(),
909
+ tag: z24.string(),
910
+ digest: z24.string(),
911
+ labels: z24.record(z24.string()).optional()
844
912
  }),
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()
913
+ createdAt: z24.string().datetime(),
914
+ updatedAt: z24.string().datetime(),
915
+ config: z24.object({
916
+ env: z24.record(z24.string()),
917
+ metadata: z24.record(z24.string()),
918
+ guest: z24.object({
919
+ cpu_kind: z24.string().optional(),
920
+ cpus: z24.number().optional(),
921
+ memory_mb: z24.number().optional()
854
922
  }).optional()
855
923
  }),
856
- events: z22.array(
857
- z22.object({
858
- type: z22.string(),
859
- status: z22.string(),
860
- timestamp: z22.number()
924
+ events: z24.array(
925
+ z24.object({
926
+ type: z24.string(),
927
+ status: z24.string(),
928
+ timestamp: z24.number()
861
929
  })
862
930
  ),
863
- checks: z22.array(
864
- z22.object({
865
- name: z22.string(),
866
- status: z22.string(),
867
- output: z22.string(),
868
- updatedAt: z22.string().datetime()
931
+ checks: z24.array(
932
+ z24.object({
933
+ name: z24.string(),
934
+ status: z24.string(),
935
+ output: z24.string(),
936
+ updatedAt: z24.string().datetime()
869
937
  })
870
938
  ).optional(),
871
- hostStatus: z22.string()
939
+ hostStatus: z24.string()
872
940
  })
873
941
  ),
874
- name: z22.string(),
875
- organization: z22.object({
876
- id: z22.string(),
877
- slug: z22.string()
942
+ name: z24.string(),
943
+ organization: z24.object({
944
+ id: z24.string(),
945
+ slug: z24.string()
878
946
  }),
879
- status: z22.string(),
880
- version: z22.number()
947
+ status: z24.string(),
948
+ version: z24.number()
881
949
  });
882
950
  var StatusTransformedResponseSchema = withCamelCase(
883
951
  statusFlyResponseSchema,
@@ -890,12 +958,24 @@ var StatusTransformedResponseSchema = withCamelCase(
890
958
  specialCases: { AppURL: "appUrl" }
891
959
  }
892
960
  );
961
+ var statusLookupSchema = withCamelCase(
962
+ z24.object({
963
+ name: z24.string(),
964
+ hostname: z24.string(),
965
+ machines: z24.array(
966
+ z24.object({
967
+ id: z24.string(),
968
+ state: z24.string()
969
+ }).passthrough()
970
+ )
971
+ }).passthrough()
972
+ );
893
973
 
894
974
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
895
975
  var StatusExtendedTransformedResponseSchema = withCamelCase(
896
976
  statusFlyResponseSchema.extend({
897
- domains: z23.array(z23.object({ hostname: z23.string() })),
898
- secrets: z23.array(z23.object({ name: z23.string() }))
977
+ domains: z25.array(z25.object({ hostname: z25.string() })),
978
+ secrets: z25.array(z25.object({ name: z25.string() }))
899
979
  }),
900
980
  {
901
981
  preserve: [
@@ -907,21 +987,33 @@ var StatusExtendedTransformedResponseSchema = withCamelCase(
907
987
  );
908
988
 
909
989
  // packages/fly-node/src/lib/schemas/version.schema.ts
910
- import { z as z24 } from "zod";
990
+ import { z as z26 } from "zod";
911
991
  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()
992
+ z26.object({
993
+ name: z26.string(),
994
+ version: z26.string(),
995
+ commit: z26.string(),
996
+ branchName: z26.string(),
997
+ buildDate: z26.string().datetime(),
998
+ os: z26.string(),
999
+ architecture: z26.string(),
1000
+ environment: z26.string()
921
1001
  })
922
1002
  );
923
1003
 
924
1004
  // packages/fly-node/src/lib/fly.class.ts
1005
+ var TRANSIENT_FLY_ERRORS = [
1006
+ { cause: "no capacity available", pattern: /no capacity available/i },
1007
+ { cause: "builder deadline exceeded", pattern: /deadline_exceeded/i },
1008
+ {
1009
+ cause: "timed out connecting to machine",
1010
+ pattern: /timed out connecting to machine/i
1011
+ },
1012
+ // The status text, not a bare 503: an app whose health check answers
1013
+ // 503 is broken, not unlucky, and must not be deployed three times
1014
+ { cause: "Fly API 503", pattern: /503 Service Unavailable/i }
1015
+ ];
1016
+ var TRANSIENT_RETRY_DELAYS_MS = [1e4, 3e4];
925
1017
  var MACHINE_STATE_INTERVAL_MS = 2e3;
926
1018
  var MACHINE_STATE_TIMEOUT_MS = 12e4;
927
1019
  var Fly = class {
@@ -1007,7 +1099,9 @@ ${error}`);
1007
1099
  return await this.version();
1008
1100
  } catch (error) {
1009
1101
  throw new Error(`[version] something broke
1010
- ${error}`);
1102
+ ${error}`, {
1103
+ cause: error
1104
+ });
1011
1105
  }
1012
1106
  }
1013
1107
  };
@@ -1034,7 +1128,8 @@ ${error}`);
1034
1128
  } catch (error) {
1035
1129
  throw new Error(
1036
1130
  `[create app] something broke, check your apps
1037
- ${error}`
1131
+ ${error}`,
1132
+ { cause: error }
1038
1133
  );
1039
1134
  }
1040
1135
  },
@@ -1060,7 +1155,8 @@ ${error}`
1060
1155
  } catch (error) {
1061
1156
  throw new Error(
1062
1157
  `[destroy app] something broke, check your apps
1063
- ${error}`
1158
+ ${error}`,
1159
+ { cause: error }
1064
1160
  );
1065
1161
  }
1066
1162
  },
@@ -1075,7 +1171,7 @@ ${error}`
1075
1171
  return await this.fetchAllApps("throwOnError");
1076
1172
  } catch (error) {
1077
1173
  throw new Error(`[list] something broke
1078
- ${error}`);
1174
+ ${error}`, { cause: error });
1079
1175
  }
1080
1176
  }
1081
1177
  };
@@ -1100,7 +1196,8 @@ ${error}`);
1100
1196
  } catch (error) {
1101
1197
  throw new Error(
1102
1198
  `[add certificate] something broke, check your app certificates
1103
- ${error}`
1199
+ ${error}`,
1200
+ { cause: error }
1104
1201
  );
1105
1202
  }
1106
1203
  },
@@ -1118,7 +1215,9 @@ ${error}`
1118
1215
  return result;
1119
1216
  } catch (error) {
1120
1217
  throw new Error(`[list certificates] something broke
1121
- ${error}`);
1218
+ ${error}`, {
1219
+ cause: error
1220
+ });
1122
1221
  }
1123
1222
  },
1124
1223
  /**
@@ -1138,7 +1237,8 @@ ${error}`);
1138
1237
  } catch (error) {
1139
1238
  throw new Error(
1140
1239
  `[remove certificate] something broke, check your app certificates
1141
- ${error}`
1240
+ ${error}`,
1241
+ { cause: error }
1142
1242
  );
1143
1243
  }
1144
1244
  }
@@ -1165,7 +1265,9 @@ ${error}`
1165
1265
  );
1166
1266
  } catch (error) {
1167
1267
  throw new Error(`[save config] something broke
1168
- ${error}`);
1268
+ ${error}`, {
1269
+ cause: error
1270
+ });
1169
1271
  }
1170
1272
  },
1171
1273
  /**
@@ -1181,7 +1283,9 @@ ${error}`);
1181
1283
  return await this.showConfig("throwOnError", options);
1182
1284
  } catch (error) {
1183
1285
  throw new Error(`[show config] something broke
1184
- ${error}`);
1286
+ ${error}`, {
1287
+ cause: error
1288
+ });
1185
1289
  }
1186
1290
  }
1187
1291
  };
@@ -1224,7 +1328,7 @@ ${error}`);
1224
1328
  }
1225
1329
  const { appName } = await this.deployApp(options);
1226
1330
  this.logger.info(`Application '${appName}' was deployed`);
1227
- const status = await this.fetchAppStatus("throwOnError", {
1331
+ const status = await this.fetchAppLookup("throwOnError", {
1228
1332
  app: appName
1229
1333
  });
1230
1334
  return DeployResponseSchema.parse({
@@ -1235,7 +1339,8 @@ ${error}`);
1235
1339
  } catch (error) {
1236
1340
  throw new Error(
1237
1341
  `[deploy] something broke, check your ${isBuildOnly ? "builds" : "deployments"}
1238
- ${error}`
1342
+ ${error}`,
1343
+ { cause: error }
1239
1344
  );
1240
1345
  }
1241
1346
  };
@@ -1256,7 +1361,9 @@ ${error}`
1256
1361
  return await this.fetchAppIps("throwOnError", options);
1257
1362
  } catch (error) {
1258
1363
  throw new Error(`[list ips] something broke
1259
- ${error}`);
1364
+ ${error}`, {
1365
+ cause: error
1366
+ });
1260
1367
  }
1261
1368
  },
1262
1369
  /**
@@ -1266,7 +1373,8 @@ ${error}`);
1266
1373
  * safe on every deploy rather than only on create. That matters because
1267
1374
  * `flyctl` allocates addresses only for an app it creates itself — an app
1268
1375
  * that arrives any other way, such as a registry push auto-creating it,
1269
- * deploys green and answers nothing.
1376
+ * deploys green and answers nothing. `deploy` runs it before every
1377
+ * deploy that is not build-only.
1270
1378
  *
1271
1379
  * @param options - The application, and which addresses to ensure
1272
1380
  * @returns The addresses the application holds afterwards
@@ -1278,19 +1386,23 @@ ${error}`);
1278
1386
  const { sharedV4 = true, v6 = true } = options ?? {};
1279
1387
  const existing = await this.fetchAppIps("throwOnError", options);
1280
1388
  const has = (...types) => existing.some((ip) => types.includes(ip.type));
1389
+ let allocated = false;
1281
1390
  if (sharedV4 && !has("v4", "shared_v4")) {
1282
1391
  await this.allocateIp("allocate-v4", options);
1283
1392
  this.logger.info("Allocated a shared IPv4 address");
1393
+ allocated = true;
1284
1394
  }
1285
1395
  if (v6 && !has("v6")) {
1286
1396
  await this.allocateIp("allocate-v6", options);
1287
1397
  this.logger.info("Allocated a dedicated IPv6 address");
1398
+ allocated = true;
1288
1399
  }
1289
- return await this.fetchAppIps("throwOnError", options);
1400
+ return allocated ? await this.fetchAppIps("throwOnError", options) : existing;
1290
1401
  } catch (error) {
1291
1402
  throw new Error(
1292
1403
  `[ensure ips] something broke, check your app addresses
1293
- ${error}`
1404
+ ${error}`,
1405
+ { cause: error }
1294
1406
  );
1295
1407
  }
1296
1408
  }
@@ -1313,7 +1425,9 @@ ${error}`
1313
1425
  this.logger.info(`Machine '${machineId}' in app '${app}' was started`);
1314
1426
  } catch (error) {
1315
1427
  throw new Error(`[start machine] something broke
1316
- ${error}`);
1428
+ ${error}`, {
1429
+ cause: error
1430
+ });
1317
1431
  }
1318
1432
  },
1319
1433
  /**
@@ -1330,7 +1444,9 @@ ${error}`);
1330
1444
  this.logger.info(`Machine '${machineId}' in app '${app}' was stopped`);
1331
1445
  } catch (error) {
1332
1446
  throw new Error(`[stop machine] something broke
1333
- ${error}`);
1447
+ ${error}`, {
1448
+ cause: error
1449
+ });
1334
1450
  }
1335
1451
  },
1336
1452
  /**
@@ -1353,7 +1469,9 @@ ${error}`);
1353
1469
  );
1354
1470
  } catch (error) {
1355
1471
  throw new Error(`[restart machine] something broke
1356
- ${error}`);
1472
+ ${error}`, {
1473
+ cause: error
1474
+ });
1357
1475
  }
1358
1476
  },
1359
1477
  /**
@@ -1374,7 +1492,9 @@ ${error}`);
1374
1492
  this.logger.info(`Machine '${machineId}' in app '${app}' was updated`);
1375
1493
  } catch (error) {
1376
1494
  throw new Error(`[update machine] something broke
1377
- ${error}`);
1495
+ ${error}`, {
1496
+ cause: error
1497
+ });
1378
1498
  }
1379
1499
  }
1380
1500
  };
@@ -1408,7 +1528,9 @@ ${error}`);
1408
1528
  return await this.sshExec(app, command);
1409
1529
  } catch (error) {
1410
1530
  throw new Error(`[ssh exec] something broke
1411
- ${error}`);
1531
+ ${error}`, {
1532
+ cause: error
1533
+ });
1412
1534
  }
1413
1535
  }
1414
1536
  };
@@ -1434,7 +1556,8 @@ ${error}`);
1434
1556
  } catch (error) {
1435
1557
  throw new Error(
1436
1558
  `[set secrets] something broke, check your app secrets
1437
- ${error}`
1559
+ ${error}`,
1560
+ { cause: error }
1438
1561
  );
1439
1562
  }
1440
1563
  },
@@ -1457,7 +1580,9 @@ ${error}`
1457
1580
  this.logger.info(`Staged secrets were deployed for '${app}'`);
1458
1581
  } catch (error) {
1459
1582
  throw new Error(`[deploy secrets] something broke
1460
- ${error}`);
1583
+ ${error}`, {
1584
+ cause: error
1585
+ });
1461
1586
  }
1462
1587
  },
1463
1588
  /**
@@ -1474,7 +1599,9 @@ ${error}`);
1474
1599
  return result;
1475
1600
  } catch (error) {
1476
1601
  throw new Error(`[list secrets] something broke
1477
- ${error}`);
1602
+ ${error}`, {
1603
+ cause: error
1604
+ });
1478
1605
  }
1479
1606
  },
1480
1607
  /**
@@ -1495,7 +1622,8 @@ ${error}`);
1495
1622
  } catch (error) {
1496
1623
  throw new Error(
1497
1624
  `[unset secrets] something broke, check your app secrets
1498
- ${error}`
1625
+ ${error}`,
1626
+ { cause: error }
1499
1627
  );
1500
1628
  }
1501
1629
  }
@@ -1608,7 +1736,7 @@ ${error}`);
1608
1736
  lookupApp = appConfig.app;
1609
1737
  }
1610
1738
  if (lookupApp) {
1611
- const status = await this.fetchAppStatus("nullOnError", {
1739
+ const status = await this.fetchAppLookup("nullOnError", {
1612
1740
  app: lookupApp
1613
1741
  });
1614
1742
  if (status) {
@@ -1710,6 +1838,10 @@ ${error}`);
1710
1838
  );
1711
1839
  }
1712
1840
  }
1841
+ const servesTraffic = !!appConfig.httpService || (appConfig.services?.length ?? 0) > 0;
1842
+ if (!options?.buildOnly && servesTraffic) {
1843
+ await this.ips.ensure({ app: appName });
1844
+ }
1713
1845
  const args = ["deploy", "--app", appName, "--config", deployConfig];
1714
1846
  if (options?.region) {
1715
1847
  args.push("--region", options.region);
@@ -1736,10 +1868,10 @@ ${error}`);
1736
1868
  this.logger.info(
1737
1869
  options?.buildOnly ? `Building image for '${appName}'...` : `Deploying '${appName}'...`
1738
1870
  );
1739
- const output = await this.execFly(
1740
- args,
1741
- options?.buildOnly ? { streamStrategy: "combined" } : void 0
1742
- );
1871
+ const output = await this.execFly(args, {
1872
+ streamStrategy: options?.buildOnly ? "combined" : "stdout",
1873
+ retry: true
1874
+ });
1743
1875
  const imageRef = options?.buildOnly ? output?.match(/registry\.fly\.io\/\S+/)?.[0] : void 0;
1744
1876
  return { appName, imageRef };
1745
1877
  }
@@ -1785,7 +1917,7 @@ ${error}`);
1785
1917
  * @throws An error if the secrets cannot be set
1786
1918
  */
1787
1919
  async setAppSecrets(secrets, options) {
1788
- const status = await this.fetchAppStatus("throwOnError", options);
1920
+ const status = await this.fetchAppLookup("throwOnError", options);
1789
1921
  const args = ["secrets", "set"];
1790
1922
  args.push(...this.getAppOrConfigArgs(options));
1791
1923
  if (options?.stage) {
@@ -1794,7 +1926,7 @@ ${error}`);
1794
1926
  for (const [key, value] of Object.entries(secrets)) {
1795
1927
  args.push(`${key}=${this.safeArg(value)}`);
1796
1928
  }
1797
- await this.execFly(args);
1929
+ await this.execFly(args, { retry: options?.stage === true });
1798
1930
  return NameSchema.parse(status.name);
1799
1931
  }
1800
1932
  /**
@@ -1803,7 +1935,7 @@ ${error}`);
1803
1935
  * @throws An error if the secrets cannot be unset
1804
1936
  */
1805
1937
  async unsetAppSecrets(keys, options) {
1806
- const status = await this.fetchAppStatus("throwOnError", options);
1938
+ const status = await this.fetchAppLookup("throwOnError", options);
1807
1939
  const args = ["secrets", "unset"];
1808
1940
  args.push(...this.getAppOrConfigArgs(options));
1809
1941
  if (options?.stage) {
@@ -1819,7 +1951,7 @@ ${error}`);
1819
1951
  * @throws An error if the domain cannot be added
1820
1952
  */
1821
1953
  async addAppCertificate(hostname, options) {
1822
- const status = await this.fetchAppStatus("throwOnError", options);
1954
+ const status = await this.fetchAppLookup("throwOnError", options);
1823
1955
  const args = ["certs", "add", hostname];
1824
1956
  args.push(...this.getAppOrConfigArgs(options));
1825
1957
  args.push("--json");
@@ -1856,7 +1988,7 @@ ${error}`);
1856
1988
  args.push("--json");
1857
1989
  try {
1858
1990
  return await IpsListTransformedResponseSchema.parseAsync(
1859
- await this.execFly(args)
1991
+ await this.execFly(args, { retry: true })
1860
1992
  );
1861
1993
  } catch (error) {
1862
1994
  if (onError === "throwOnError") {
@@ -1871,7 +2003,7 @@ ${error}`);
1871
2003
  * @throws An error if the domain cannot be removed
1872
2004
  */
1873
2005
  async removeAppCertificate(hostname, options) {
1874
- const status = await this.fetchAppStatus("throwOnError", options);
2006
+ const status = await this.fetchAppLookup("throwOnError", options);
1875
2007
  const args = ["certs", "remove", hostname];
1876
2008
  args.push(...this.getAppOrConfigArgs(options));
1877
2009
  args.push("--yes");
@@ -1946,7 +2078,7 @@ ${error}`);
1946
2078
  async waitForMachineState(app, machineId, states) {
1947
2079
  const deadline = Date.now() + MACHINE_STATE_TIMEOUT_MS;
1948
2080
  while (Date.now() < deadline) {
1949
- const status = await this.fetchAppStatus("nullOnError", { app });
2081
+ const status = await this.fetchAppLookup("nullOnError", { app });
1950
2082
  const machine = status?.machines.find(({ id }) => id === machineId);
1951
2083
  if (machine && states.includes(machine.state)) {
1952
2084
  return;
@@ -2057,6 +2189,27 @@ ${error}`);
2057
2189
  this.logger.info(`Failed to parse response:
2058
2190
  ${error.message}`);
2059
2191
  this.logger.info(`Raw response:
2192
+ ${JSON.stringify(response, null, 2)}`);
2193
+ }
2194
+ return null;
2195
+ }
2196
+ }
2197
+ async fetchAppLookup(onError, options) {
2198
+ const args = ["status"];
2199
+ args.push(...this.getAppOrConfigArgs(options));
2200
+ args.push("--json");
2201
+ let response = null;
2202
+ try {
2203
+ response = await this.execFly(args);
2204
+ return statusLookupSchema.parse(response);
2205
+ } catch (error) {
2206
+ if (onError === "throwOnError") {
2207
+ throw error;
2208
+ }
2209
+ if (error instanceof ZodError) {
2210
+ this.logger.info(`Failed to parse response:
2211
+ ${error.message}`);
2212
+ this.logger.info(`Raw response:
2060
2213
  ${JSON.stringify(response, null, 2)}`);
2061
2214
  }
2062
2215
  return null;
@@ -2189,33 +2342,32 @@ ${JSON.stringify(response, null, 2)}`);
2189
2342
  }
2190
2343
  const flyCmd = "flyctl";
2191
2344
  const toLogCmd = `${flyCmd} ${args.join(" ")}`;
2345
+ const { retry = false, ...execOpts } = options ?? {};
2192
2346
  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}`);
2347
+ for (let attempt = 1; ; attempt++) {
2348
+ try {
2349
+ output = await this.spawnFly(flyCmd, args, toLogCmd, execOpts);
2350
+ break;
2351
+ } catch (error) {
2352
+ const errorMsg = error.message;
2353
+ this.traceCLI("RESULT", errorMsg);
2354
+ const cause = retry ? this.transientCause(error) : null;
2355
+ const delay = TRANSIENT_RETRY_DELAYS_MS[attempt - 1];
2356
+ if (cause && delay !== void 0) {
2357
+ this.logger.info(
2358
+ `Transient Fly error (${cause}), retrying in ${delay / 1e3}s (attempt ${attempt + 1} of ${TRANSIENT_RETRY_DELAYS_MS.length + 1}): ${toLogCmd}`
2359
+ );
2360
+ await new Promise((resolve) => setTimeout(resolve, delay));
2361
+ continue;
2362
+ }
2363
+ if (onError === "throwOnError") {
2364
+ throw new Error(`Command failed: ${toLogCmd}
2365
+ ${errorMsg}`, {
2366
+ cause: error
2367
+ });
2368
+ }
2369
+ return null;
2217
2370
  }
2218
- return null;
2219
2371
  }
2220
2372
  try {
2221
2373
  return JSON.parse(output);
@@ -2229,6 +2381,55 @@ ${errorMsg}`);
2229
2381
  }
2230
2382
  return void 0;
2231
2383
  }
2384
+ /**
2385
+ * @private
2386
+ * Run one fly command and assemble its output
2387
+ *
2388
+ * @returns The output selected by `streamStrategy`
2389
+ * @throws An error if the command fails
2390
+ */
2391
+ async spawnFly(flyCmd, args, toLogCmd, options) {
2392
+ this.traceCLI("CALL", toLogCmd);
2393
+ if (options.prompt) {
2394
+ const output = await spawnPty(flyCmd, args, { prompt: options.prompt });
2395
+ this.traceCLI("RESULT", output);
2396
+ return output;
2397
+ }
2398
+ const { streamStrategy = "stdout", ...spawnOpts } = options;
2399
+ const result = await spawn(flyCmd, args, {
2400
+ ...spawnOpts,
2401
+ streamToConsole: this.logger.streamToConsole
2402
+ });
2403
+ const stdout = result.stdout.trim();
2404
+ const stderr = result.stderr.trim();
2405
+ this.traceCLI("RESULT", `${stdout}${stderr ? `
2406
+ ${stderr}` : ""}`);
2407
+ return streamStrategy === "combined" ? `${stdout}
2408
+ ${stderr}` : streamStrategy === "stderr" ? stderr : stdout;
2409
+ }
2410
+ /**
2411
+ * @private
2412
+ * Name the transient Fly error behind a failed command, if it was one.
2413
+ *
2414
+ * Only the error flyctl ended with counts: from its last `Error` line to
2415
+ * the end of stderr, or the last few lines when there is none. A deploy
2416
+ * streams the app's own output and errors flyctl recovered from, and
2417
+ * matching those would repeat a deploy that failed for a real reason.
2418
+ *
2419
+ * @returns The cause, or `null` when the failure is not a known transient one
2420
+ */
2421
+ transientCause(error) {
2422
+ let text;
2423
+ if (error instanceof SpawnError) {
2424
+ const lines = error.stderr.split(/\r?\n/).filter((line) => line.trim());
2425
+ const errorLines = lines.map((line) => /^\s*Error\b/.test(line));
2426
+ const last = errorLines.lastIndexOf(true);
2427
+ text = lines.slice(last >= 0 ? last : -3).join("\n");
2428
+ } else {
2429
+ text = String(error?.message ?? error);
2430
+ }
2431
+ return TRANSIENT_FLY_ERRORS.find(({ pattern }) => pattern.test(text))?.cause ?? null;
2432
+ }
2232
2433
  /**
2233
2434
  * @private
2234
2435
  * Get the arguments for `AppOrConfig` options
@@ -2376,6 +2577,8 @@ ${errorMsg}`);
2376
2577
  }
2377
2578
  };
2378
2579
  export {
2580
+ AppIpAddressSchema,
2581
+ AppIpAddressesApiResponseSchema,
2379
2582
  CertificateApiResponseSchema,
2380
2583
  CertificateListApiResponseSchema,
2381
2584
  DnsInstructionsSchema,