@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.cjs CHANGED
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // packages/fly-node/src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ AppIpAddressSchema: () => AppIpAddressSchema,
34
+ AppIpAddressesApiResponseSchema: () => AppIpAddressesApiResponseSchema,
33
35
  CertificateApiResponseSchema: () => CertificateApiResponseSchema,
34
36
  CertificateListApiResponseSchema: () => CertificateListApiResponseSchema,
35
37
  DnsInstructionsSchema: () => DnsInstructionsSchema,
@@ -42,49 +44,66 @@ __export(index_exports, {
42
44
  });
43
45
  module.exports = __toCommonJS(index_exports);
44
46
 
45
- // packages/fly-node/src/lib/schemas/certificate.schema.ts
47
+ // packages/fly-node/src/lib/schemas/app-ip-addresses.schema.ts
48
+ var import_zod2 = require("zod");
49
+
50
+ // packages/fly-node/src/lib/schemas/ip-type.schema.ts
46
51
  var import_zod = require("zod");
47
- var CertificateApiResponseSchema = import_zod.z.object({
48
- hostname: import_zod.z.string(),
52
+ var IpTypeSchema = import_zod.z.enum(["v4", "v6", "shared_v4", "private_v6"]).or(import_zod.z.string());
53
+
54
+ // packages/fly-node/src/lib/schemas/app-ip-addresses.schema.ts
55
+ var AppIpAddressSchema = import_zod2.z.object({
56
+ address: import_zod2.z.string(),
57
+ type: IpTypeSchema
58
+ });
59
+ var AppIpAddressesApiResponseSchema = import_zod2.z.object({
60
+ sharedIpAddress: import_zod2.z.string().nullish(),
61
+ ipAddresses: import_zod2.z.object({ nodes: import_zod2.z.array(AppIpAddressSchema) })
62
+ });
63
+
64
+ // packages/fly-node/src/lib/schemas/certificate.schema.ts
65
+ var import_zod3 = require("zod");
66
+ var CertificateApiResponseSchema = import_zod3.z.object({
67
+ hostname: import_zod3.z.string(),
49
68
  /** Issued and serving. This is what decides whether a domain is usable */
50
- isConfigured: import_zod.z.boolean(),
51
- id: import_zod.z.string().optional(),
69
+ isConfigured: import_zod3.z.boolean(),
70
+ id: import_zod3.z.string().optional(),
52
71
  /** The apex or a subdomain — apex domains cannot use a CNAME */
53
- isApex: import_zod.z.boolean().optional(),
54
- isWildcard: import_zod.z.boolean().optional(),
72
+ isApex: import_zod3.z.boolean().optional(),
73
+ isWildcard: import_zod3.z.boolean().optional(),
55
74
  /** Which ACME challenge has been satisfied, if any */
56
- isAcmeDnsConfigured: import_zod.z.boolean().optional(),
57
- isAcmeAlpnConfigured: import_zod.z.boolean().optional(),
58
- isAcmeHttpConfigured: import_zod.z.boolean().optional(),
59
- certificateAuthority: import_zod.z.string().nullish(),
60
- certificateRequestedAt: import_zod.z.string().nullish(),
61
- createdAt: import_zod.z.string().nullish(),
62
- domain: import_zod.z.string().nullish(),
63
- dnsProvider: import_zod.z.string().nullish(),
75
+ isAcmeDnsConfigured: import_zod3.z.boolean().optional(),
76
+ isAcmeAlpnConfigured: import_zod3.z.boolean().optional(),
77
+ isAcmeHttpConfigured: import_zod3.z.boolean().optional(),
78
+ certificateAuthority: import_zod3.z.string().nullish(),
79
+ certificateRequestedAt: import_zod3.z.string().nullish(),
80
+ createdAt: import_zod3.z.string().nullish(),
81
+ domain: import_zod3.z.string().nullish(),
82
+ dnsProvider: import_zod3.z.string().nullish(),
64
83
  /** Hostname the validation record must be created on */
65
- dnsValidationHostname: import_zod.z.string().nullish(),
84
+ dnsValidationHostname: import_zod3.z.string().nullish(),
66
85
  /** Value that record must contain */
67
- dnsValidationTarget: import_zod.z.string().nullish(),
86
+ dnsValidationTarget: import_zod3.z.string().nullish(),
68
87
  /** Fly's own prose describing the records to create */
69
- dnsValidationInstructions: import_zod.z.string().nullish(),
88
+ dnsValidationInstructions: import_zod3.z.string().nullish(),
70
89
  /** Fly's summary of where issuance has got to */
71
- clientStatus: import_zod.z.string().nullish(),
90
+ clientStatus: import_zod3.z.string().nullish(),
72
91
  /**
73
92
  * Set when Let's Encrypt has rate-limited further attempts for this domain.
74
93
  *
75
94
  * Worth surfacing rather than swallowing: it is the one failure a customer
76
95
  * cannot fix by correcting DNS, and retrying only makes it worse.
77
96
  */
78
- rateLimitedUntil: import_zod.z.string().nullish(),
79
- source: import_zod.z.string().nullish(),
97
+ rateLimitedUntil: import_zod3.z.string().nullish(),
98
+ source: import_zod3.z.string().nullish(),
80
99
  /**
81
100
  * Fly's own prose for a failed issuance attempt — what the dashboard shows,
82
101
  * unlike `HostnameCheck.errors`, which is SCREAMING_SNAKE_CASE codes
83
102
  */
84
- validationErrors: import_zod.z.array(
85
- import_zod.z.object({
86
- message: import_zod.z.string(),
87
- timestamp: import_zod.z.string()
103
+ validationErrors: import_zod3.z.array(
104
+ import_zod3.z.object({
105
+ message: import_zod3.z.string(),
106
+ timestamp: import_zod3.z.string()
88
107
  })
89
108
  ).nullish(),
90
109
  /**
@@ -94,52 +113,52 @@ var CertificateApiResponseSchema = import_zod.z.object({
94
113
  * nodes is the normal count — one RSA and one ECDSA — sharing an expiry,
95
114
  * which is why a caller usually wants the expiry rather than the rows.
96
115
  */
97
- issued: import_zod.z.object({
98
- nodes: import_zod.z.array(
99
- import_zod.z.object({
100
- id: import_zod.z.string().nullish(),
116
+ issued: import_zod3.z.object({
117
+ nodes: import_zod3.z.array(
118
+ import_zod3.z.object({
119
+ id: import_zod3.z.string().nullish(),
101
120
  /** Key type, e.g. `RSA` or `ECDSA` */
102
- type: import_zod.z.string().nullish(),
103
- hostname: import_zod.z.string().nullish(),
104
- expiresAt: import_zod.z.string().nullish()
121
+ type: import_zod3.z.string().nullish(),
122
+ hostname: import_zod3.z.string().nullish(),
123
+ expiresAt: import_zod3.z.string().nullish()
105
124
  })
106
125
  ).nullish()
107
126
  }).nullish()
108
127
  });
109
- var HostnameCheckApiResponseSchema = import_zod.z.object({
110
- aRecords: import_zod.z.array(import_zod.z.string()).nullish(),
111
- aaaaRecords: import_zod.z.array(import_zod.z.string()).nullish(),
112
- cnameRecords: import_zod.z.array(import_zod.z.string()).nullish(),
113
- caaRecords: import_zod.z.array(import_zod.z.string()).nullish(),
114
- soa: import_zod.z.string().nullish(),
115
- dnsProvider: import_zod.z.string().nullish(),
116
- dnsVerificationRecord: import_zod.z.string().nullish(),
117
- dnsConfigured: import_zod.z.boolean().nullish(),
118
- acmeDnsConfigured: import_zod.z.boolean().nullish(),
119
- resolvedAddresses: import_zod.z.array(import_zod.z.string()).nullish(),
120
- isProxied: import_zod.z.boolean().nullish(),
121
- errors: import_zod.z.array(import_zod.z.string()).nullish()
128
+ var HostnameCheckApiResponseSchema = import_zod3.z.object({
129
+ aRecords: import_zod3.z.array(import_zod3.z.string()).nullish(),
130
+ aaaaRecords: import_zod3.z.array(import_zod3.z.string()).nullish(),
131
+ cnameRecords: import_zod3.z.array(import_zod3.z.string()).nullish(),
132
+ caaRecords: import_zod3.z.array(import_zod3.z.string()).nullish(),
133
+ soa: import_zod3.z.string().nullish(),
134
+ dnsProvider: import_zod3.z.string().nullish(),
135
+ dnsVerificationRecord: import_zod3.z.string().nullish(),
136
+ dnsConfigured: import_zod3.z.boolean().nullish(),
137
+ acmeDnsConfigured: import_zod3.z.boolean().nullish(),
138
+ resolvedAddresses: import_zod3.z.array(import_zod3.z.string()).nullish(),
139
+ isProxied: import_zod3.z.boolean().nullish(),
140
+ errors: import_zod3.z.array(import_zod3.z.string()).nullish()
122
141
  });
123
- var DnsInstructionsSchema = import_zod.z.object({
124
- hostname: import_zod.z.string().nullish(),
125
- target: import_zod.z.string().nullish(),
126
- instructions: import_zod.z.string().nullish(),
127
- isApex: import_zod.z.boolean().optional()
142
+ var DnsInstructionsSchema = import_zod3.z.object({
143
+ hostname: import_zod3.z.string().nullish(),
144
+ target: import_zod3.z.string().nullish(),
145
+ instructions: import_zod3.z.string().nullish(),
146
+ isApex: import_zod3.z.boolean().optional()
128
147
  });
129
- var CertificateListApiResponseSchema = import_zod.z.array(
148
+ var CertificateListApiResponseSchema = import_zod3.z.array(
130
149
  CertificateApiResponseSchema
131
150
  );
132
151
 
133
152
  // packages/fly-node/src/lib/schemas/machine.schema.ts
134
- var import_zod2 = require("zod");
135
- var MachineApiResponseSchema = import_zod2.z.object({
136
- id: import_zod2.z.string(),
137
- name: import_zod2.z.string().nullish(),
153
+ var import_zod4 = require("zod");
154
+ var MachineApiResponseSchema = import_zod4.z.object({
155
+ id: import_zod4.z.string(),
156
+ name: import_zod4.z.string().nullish(),
138
157
  /** `started`, `stopped`, `suspended`, … — Fly owns this vocabulary */
139
- state: import_zod2.z.string().nullish(),
140
- region: import_zod2.z.string().nullish()
158
+ state: import_zod4.z.string().nullish(),
159
+ region: import_zod4.z.string().nullish()
141
160
  });
142
- var MachineListApiResponseSchema = import_zod2.z.array(MachineApiResponseSchema);
161
+ var MachineListApiResponseSchema = import_zod4.z.array(MachineApiResponseSchema);
143
162
 
144
163
  // packages/fly-node/src/lib/fly-api.class.ts
145
164
  var FLY_API_URL = "https://api.fly.io/graphql";
@@ -332,6 +351,42 @@ var FlyApi = class {
332
351
  );
333
352
  }
334
353
  };
354
+ /** Read an app's addresses */
355
+ ips = {
356
+ /**
357
+ * The addresses an app answers on: `shared_v4`, `v4`, `v6`, and its
358
+ * `private_v6`.
359
+ *
360
+ * The shared v4 is folded in as a `shared_v4` row, the way `fly ips list`
361
+ * shows it; Fly's API keeps it in a separate field. Egress addresses,
362
+ * which the CLI also lists, are not part of this API and never appear.
363
+ * Pick the public types before pointing DNS at them.
364
+ *
365
+ * Rejects for an unknown app, like `certs.list`: a typo in an app name
366
+ * must not read as "this app has no addresses".
367
+ *
368
+ * @returns The addresses, empty when the app has none
369
+ */
370
+ list: async (app) => {
371
+ const data = await this.request(
372
+ `query AppIpAddresses($appName: String!) {
373
+ app(name: $appName) {
374
+ sharedIpAddress
375
+ ipAddresses { nodes { address type } }
376
+ }
377
+ }`,
378
+ { appName: app }
379
+ );
380
+ if (!data.app) {
381
+ return [];
382
+ }
383
+ const { sharedIpAddress, ipAddresses } = AppIpAddressesApiResponseSchema.parse(data.app);
384
+ return [
385
+ ...sharedIpAddress ? [{ address: sharedIpAddress, type: "shared_v4" }] : [],
386
+ ...ipAddresses.nodes
387
+ ];
388
+ }
389
+ };
335
390
  /**
336
391
  * Operate an app's machines.
337
392
  *
@@ -545,6 +600,18 @@ var killProcessTree = (0, import_util2.promisify)(import_tree_kill.default);
545
600
 
546
601
  // libs/shared/util/misc/src/lib/promisified-spawn.ts
547
602
  var import_child_process2 = require("child_process");
603
+ var STREAMED_STDERR_TAIL_LINES = 20;
604
+ var SpawnError = class extends Error {
605
+ exitCode;
606
+ stdout;
607
+ stderr;
608
+ constructor(message, details) {
609
+ super(message);
610
+ this.exitCode = details.exitCode;
611
+ this.stdout = details.stdout;
612
+ this.stderr = details.stderr;
613
+ }
614
+ };
548
615
  function spawn(command, args, options) {
549
616
  return new Promise((resolve, reject) => {
550
617
  const { streamToConsole, ...spawnOptions } = options || {};
@@ -572,8 +639,12 @@ function spawn(command, args, options) {
572
639
  if (code === 0) {
573
640
  resolve({ stdout, stderr });
574
641
  } else {
575
- reject(new Error(`Process exited with code ${code}
576
- Error: ${stderr}`));
642
+ const lines = stderr.replace(/\r?\n$/, "").split(/\r?\n/);
643
+ const message = streamToConsole && lines.length > STREAMED_STDERR_TAIL_LINES ? `Process exited with code ${code}
644
+ Error (last ${STREAMED_STDERR_TAIL_LINES} lines; the full output is above):
645
+ ${lines.slice(-STREAMED_STDERR_TAIL_LINES).join("\n")}` : `Process exited with code ${code}
646
+ Error: ${stderr}`;
647
+ reject(new SpawnError(message, { exitCode: code, stdout, stderr }));
577
648
  }
578
649
  });
579
650
  process2.on("error", reject);
@@ -615,23 +686,23 @@ Output: ${output}`)
615
686
  }
616
687
 
617
688
  // packages/fly-node/src/lib/fly.class.ts
618
- var import_zod38 = require("zod");
689
+ var import_zod40 = require("zod");
619
690
 
620
691
  // libs/shared/util/zod/src/lib/coerce-boolean.ts
621
- var import_zod3 = require("zod");
692
+ var import_zod5 = require("zod");
622
693
 
623
694
  // libs/shared/util/zod/src/lib/create-lowercase-schema.ts
624
- var import_zod4 = require("zod");
695
+ var import_zod6 = require("zod");
625
696
 
626
697
  // libs/shared/util/zod/src/lib/json.schema.ts
627
- var import_zod5 = require("zod");
628
- var LiteralSchema = import_zod5.z.union([import_zod5.z.string(), import_zod5.z.number(), import_zod5.z.boolean(), import_zod5.z.null()]);
629
- var JsonSchema = import_zod5.z.lazy(
630
- () => import_zod5.z.union([LiteralSchema, import_zod5.z.array(JsonSchema), import_zod5.z.record(JsonSchema)])
698
+ var import_zod7 = require("zod");
699
+ var LiteralSchema = import_zod7.z.union([import_zod7.z.string(), import_zod7.z.number(), import_zod7.z.boolean(), import_zod7.z.null()]);
700
+ var JsonSchema = import_zod7.z.lazy(
701
+ () => import_zod7.z.union([LiteralSchema, import_zod7.z.array(JsonSchema), import_zod7.z.record(JsonSchema)])
631
702
  );
632
703
 
633
704
  // libs/shared/util/zod/src/lib/with-camel-case.preprocess.ts
634
- var import_zod6 = require("zod");
705
+ var import_zod8 = require("zod");
635
706
  var toCamelCase = (str, specialCases = {}) => {
636
707
  if (specialCases[str]) {
637
708
  return specialCases[str];
@@ -681,7 +752,7 @@ var transformKeys = (options) => {
681
752
  };
682
753
  var withCamelCase = (schema, options = {}) => {
683
754
  const { preserve = [], specialCases = {} } = options;
684
- return import_zod6.z.preprocess(
755
+ return import_zod8.z.preprocess(
685
756
  (data) => transformKeys({
686
757
  currentPath: [],
687
758
  data,
@@ -693,38 +764,38 @@ var withCamelCase = (schema, options = {}) => {
693
764
  };
694
765
 
695
766
  // libs/shared/util/zod/src/lib/with-env-vars.preprocess.ts
696
- var import_zod7 = require("zod");
767
+ var import_zod9 = require("zod");
697
768
 
698
769
  // libs/shared/util/zod/src/lib/with-replace-all.preprocess.ts
699
- var import_zod8 = require("zod");
770
+ var import_zod10 = require("zod");
700
771
 
701
772
  // packages/fly-node/src/lib/schemas/apps-create.schema.ts
702
- var import_zod10 = require("zod");
773
+ var import_zod12 = require("zod");
703
774
  var AppsCreateTransformedResponseSchema = withCamelCase(
704
- import_zod10.z.object({
705
- id: import_zod10.z.string(),
706
- name: import_zod10.z.string()
775
+ import_zod12.z.object({
776
+ id: import_zod12.z.string(),
777
+ name: import_zod12.z.string()
707
778
  })
708
779
  );
709
780
 
710
781
  // packages/fly-node/src/lib/schemas/apps-list.schema.ts
711
- var import_zod12 = require("zod");
712
- var AppsListTransformedResponseSchema = import_zod12.z.array(
782
+ var import_zod14 = require("zod");
783
+ var AppsListTransformedResponseSchema = import_zod14.z.array(
713
784
  withCamelCase(
714
- import_zod12.z.object({
715
- id: import_zod12.z.string(),
716
- name: import_zod12.z.string(),
717
- status: import_zod12.z.string(),
718
- deployed: import_zod12.z.boolean(),
719
- hostname: import_zod12.z.string(),
720
- organization: import_zod12.z.object({
721
- name: import_zod12.z.string(),
722
- slug: import_zod12.z.string()
785
+ import_zod14.z.object({
786
+ id: import_zod14.z.string(),
787
+ name: import_zod14.z.string(),
788
+ status: import_zod14.z.string(),
789
+ deployed: import_zod14.z.boolean(),
790
+ hostname: import_zod14.z.string(),
791
+ organization: import_zod14.z.object({
792
+ name: import_zod14.z.string(),
793
+ slug: import_zod14.z.string()
723
794
  }),
724
- currentRelease: import_zod12.z.nullable(
725
- import_zod12.z.object({
726
- status: import_zod12.z.string(),
727
- createdAt: import_zod12.z.string().datetime()
795
+ currentRelease: import_zod14.z.nullable(
796
+ import_zod14.z.object({
797
+ status: import_zod14.z.string(),
798
+ createdAt: import_zod14.z.string().datetime()
728
799
  })
729
800
  )
730
801
  })
@@ -732,53 +803,53 @@ var AppsListTransformedResponseSchema = import_zod12.z.array(
732
803
  );
733
804
 
734
805
  // packages/fly-node/src/lib/schemas/build-response.schema.ts
735
- var import_zod13 = require("zod");
736
- var BuildResponseSchema = import_zod13.z.object({
737
- appName: import_zod13.z.string(),
738
- imageRef: import_zod13.z.string()
806
+ var import_zod15 = require("zod");
807
+ var BuildResponseSchema = import_zod15.z.object({
808
+ appName: import_zod15.z.string(),
809
+ imageRef: import_zod15.z.string()
739
810
  });
740
811
 
741
812
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
742
- var import_zod17 = require("zod");
813
+ var import_zod19 = require("zod");
743
814
 
744
815
  // packages/fly-node/src/lib/schemas/certs-list.schema.ts
745
- var import_zod15 = require("zod");
746
- var CertsListFlyResponseElementSchema = import_zod15.z.object({
747
- createdAt: import_zod15.z.string().datetime(),
748
- hostname: import_zod15.z.string(),
749
- clientStatus: import_zod15.z.string()
816
+ var import_zod17 = require("zod");
817
+ var CertsListFlyResponseElementSchema = import_zod17.z.object({
818
+ createdAt: import_zod17.z.string().datetime(),
819
+ hostname: import_zod17.z.string(),
820
+ clientStatus: import_zod17.z.string()
750
821
  });
751
- var CertsListTransformedResponseSchema = import_zod15.z.array(
822
+ var CertsListTransformedResponseSchema = import_zod17.z.array(
752
823
  withCamelCase(CertsListFlyResponseElementSchema)
753
824
  );
754
825
 
755
826
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
756
- var CertsListWithAppTransformedResponseSchema = import_zod17.z.array(
827
+ var CertsListWithAppTransformedResponseSchema = import_zod19.z.array(
757
828
  withCamelCase(
758
829
  CertsListFlyResponseElementSchema.extend({
759
- app: import_zod17.z.string()
830
+ app: import_zod19.z.string()
760
831
  })
761
832
  )
762
833
  );
763
834
 
764
835
  // packages/fly-node/src/lib/schemas/config-show.schema.ts
765
- var import_zod19 = require("zod");
836
+ var import_zod21 = require("zod");
766
837
  var ConfigShowResponseSchema = withCamelCase(
767
- import_zod19.z.object({
768
- app: import_zod19.z.string(),
769
- primaryRegion: import_zod19.z.string().optional(),
770
- build: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).optional().or(
771
- import_zod19.z.object({
772
- args: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.string()).optional(),
773
- dockerfile: import_zod19.z.string().optional(),
774
- image: import_zod19.z.string().optional()
838
+ import_zod21.z.object({
839
+ app: import_zod21.z.string(),
840
+ primaryRegion: import_zod21.z.string().optional(),
841
+ build: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any()).optional().or(
842
+ import_zod21.z.object({
843
+ args: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.string()).optional(),
844
+ dockerfile: import_zod21.z.string().optional(),
845
+ image: import_zod21.z.string().optional()
775
846
  })
776
847
  ),
777
- deploy: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).optional().or(import_zod19.z.object({ strategy: import_zod19.z.string().optional() })),
778
- env: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.string()).optional(),
779
- httpService: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).optional(),
780
- mounts: import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any()).optional(),
781
- services: import_zod19.z.array(import_zod19.z.record(import_zod19.z.string(), import_zod19.z.any())).optional()
848
+ deploy: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any()).optional().or(import_zod21.z.object({ strategy: import_zod21.z.string().optional() })),
849
+ env: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.string()).optional(),
850
+ httpService: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any()).optional(),
851
+ mounts: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any()).optional(),
852
+ services: import_zod21.z.array(import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any())).optional()
782
853
  }),
783
854
  {
784
855
  preserve: ["build.args", "env"]
@@ -786,140 +857,139 @@ var ConfigShowResponseSchema = withCamelCase(
786
857
  );
787
858
 
788
859
  // packages/fly-node/src/lib/schemas/deploy.schema.ts
789
- var import_zod20 = require("zod");
790
- var DeployResponseSchema = import_zod20.z.object({
791
- app: import_zod20.z.string(),
792
- hostname: import_zod20.z.string(),
793
- url: import_zod20.z.string().url()
860
+ var import_zod22 = require("zod");
861
+ var DeployResponseSchema = import_zod22.z.object({
862
+ app: import_zod22.z.string(),
863
+ hostname: import_zod22.z.string(),
864
+ url: import_zod22.z.string().url()
794
865
  });
795
866
 
796
867
  // packages/fly-node/src/lib/schemas/helper-schemas.ts
797
- var import_zod21 = require("zod");
798
- var AllowEmptyUrlSchema = import_zod21.z.string().url().or(import_zod21.z.literal(""));
799
- var NameSchema = import_zod21.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
868
+ var import_zod23 = require("zod");
869
+ var AllowEmptyUrlSchema = import_zod23.z.string().url().or(import_zod23.z.literal(""));
870
+ var NameSchema = import_zod23.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
800
871
 
801
872
  // packages/fly-node/src/lib/schemas/ips-list.schema.ts
802
- var import_zod23 = require("zod");
803
- var IpTypeSchema = import_zod23.z.enum(["v4", "v6", "shared_v4", "private_v6"]).or(import_zod23.z.string());
804
- var IpsListFlyResponseElementSchema = import_zod23.z.object({
805
- id: import_zod23.z.string(),
806
- address: import_zod23.z.string(),
873
+ var import_zod25 = require("zod");
874
+ var IpsListFlyResponseElementSchema = import_zod25.z.object({
875
+ id: import_zod25.z.string(),
876
+ address: import_zod25.z.string(),
807
877
  type: IpTypeSchema,
808
- region: import_zod23.z.string(),
809
- createdAt: import_zod23.z.string()
878
+ region: import_zod25.z.string(),
879
+ createdAt: import_zod25.z.string()
810
880
  });
811
- var IpsListTransformedResponseSchema = import_zod23.z.array(
881
+ var IpsListTransformedResponseSchema = import_zod25.z.array(
812
882
  withCamelCase(IpsListFlyResponseElementSchema)
813
883
  );
814
884
 
815
885
  // packages/fly-node/src/lib/schemas/postgres-list.ts
816
- var import_zod25 = require("zod");
817
- var PostgresListTransformedResponseSchema = import_zod25.z.array(
886
+ var import_zod27 = require("zod");
887
+ var PostgresListTransformedResponseSchema = import_zod27.z.array(
818
888
  withCamelCase(
819
- import_zod25.z.object({
820
- deployed: import_zod25.z.boolean(),
821
- hostname: import_zod25.z.string(),
822
- id: import_zod25.z.string(),
823
- name: import_zod25.z.string(),
824
- organization: import_zod25.z.object({ id: import_zod25.z.string(), slug: import_zod25.z.string() }),
825
- status: import_zod25.z.string(),
826
- version: import_zod25.z.number()
889
+ import_zod27.z.object({
890
+ deployed: import_zod27.z.boolean(),
891
+ hostname: import_zod27.z.string(),
892
+ id: import_zod27.z.string(),
893
+ name: import_zod27.z.string(),
894
+ organization: import_zod27.z.object({ id: import_zod27.z.string(), slug: import_zod27.z.string() }),
895
+ status: import_zod27.z.string(),
896
+ version: import_zod27.z.number()
827
897
  })
828
898
  )
829
- ).or(import_zod25.z.string());
899
+ ).or(import_zod27.z.string());
830
900
 
831
901
  // packages/fly-node/src/lib/schemas/postgres-users-list.ts
832
- var import_zod27 = require("zod");
833
- var PostgresUsersListTransformedResponseSchema = import_zod27.z.array(
902
+ var import_zod29 = require("zod");
903
+ var PostgresUsersListTransformedResponseSchema = import_zod29.z.array(
834
904
  withCamelCase(
835
- import_zod27.z.object({
836
- username: import_zod27.z.string(),
837
- superuser: import_zod27.z.boolean(),
838
- databases: import_zod27.z.array(import_zod27.z.string())
905
+ import_zod29.z.object({
906
+ username: import_zod29.z.string(),
907
+ superuser: import_zod29.z.boolean(),
908
+ databases: import_zod29.z.array(import_zod29.z.string())
839
909
  })
840
910
  )
841
911
  );
842
912
 
843
913
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
844
- var import_zod31 = require("zod");
914
+ var import_zod33 = require("zod");
845
915
 
846
916
  // packages/fly-node/src/lib/schemas/secrets-list.schema.ts
847
- var import_zod29 = require("zod");
848
- var SecretsListFlyResponseElementSchema = import_zod29.z.object({
849
- name: import_zod29.z.string(),
850
- digest: import_zod29.z.string()
917
+ var import_zod31 = require("zod");
918
+ var SecretsListFlyResponseElementSchema = import_zod31.z.object({
919
+ name: import_zod31.z.string(),
920
+ digest: import_zod31.z.string()
851
921
  });
852
- var SecretsListTransformedResponseSchema = import_zod29.z.array(
922
+ var SecretsListTransformedResponseSchema = import_zod31.z.array(
853
923
  withCamelCase(SecretsListFlyResponseElementSchema)
854
924
  );
855
925
 
856
926
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
857
- var SecretsListWithAppTransformedResponseSchema = import_zod31.z.array(
927
+ var SecretsListWithAppTransformedResponseSchema = import_zod33.z.array(
858
928
  withCamelCase(
859
929
  SecretsListFlyResponseElementSchema.extend({
860
- app: import_zod31.z.string()
930
+ app: import_zod33.z.string()
861
931
  })
862
932
  )
863
933
  );
864
934
 
865
935
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
866
- var import_zod35 = require("zod");
936
+ var import_zod37 = require("zod");
867
937
 
868
938
  // packages/fly-node/src/lib/schemas/status.schema.ts
869
- var import_zod33 = require("zod");
870
- var statusFlyResponseSchema = import_zod33.z.object({
871
- deployed: import_zod33.z.boolean(),
872
- hostname: import_zod33.z.string(),
873
- id: import_zod33.z.string(),
874
- machines: import_zod33.z.array(
875
- import_zod33.z.object({
876
- id: import_zod33.z.string(),
877
- name: import_zod33.z.string(),
878
- state: import_zod33.z.string(),
879
- region: import_zod33.z.string(),
880
- imageRef: import_zod33.z.object({
881
- registry: import_zod33.z.string(),
882
- repository: import_zod33.z.string(),
883
- tag: import_zod33.z.string(),
884
- digest: import_zod33.z.string(),
885
- labels: import_zod33.z.record(import_zod33.z.string()).optional()
939
+ var import_zod35 = require("zod");
940
+ var statusFlyResponseSchema = import_zod35.z.object({
941
+ deployed: import_zod35.z.boolean(),
942
+ hostname: import_zod35.z.string(),
943
+ id: import_zod35.z.string(),
944
+ machines: import_zod35.z.array(
945
+ import_zod35.z.object({
946
+ id: import_zod35.z.string(),
947
+ name: import_zod35.z.string(),
948
+ state: import_zod35.z.string(),
949
+ region: import_zod35.z.string(),
950
+ imageRef: import_zod35.z.object({
951
+ registry: import_zod35.z.string(),
952
+ repository: import_zod35.z.string(),
953
+ tag: import_zod35.z.string(),
954
+ digest: import_zod35.z.string(),
955
+ labels: import_zod35.z.record(import_zod35.z.string()).optional()
886
956
  }),
887
- createdAt: import_zod33.z.string().datetime(),
888
- updatedAt: import_zod33.z.string().datetime(),
889
- config: import_zod33.z.object({
890
- env: import_zod33.z.record(import_zod33.z.string()),
891
- metadata: import_zod33.z.record(import_zod33.z.string()),
892
- guest: import_zod33.z.object({
893
- cpu_kind: import_zod33.z.string().optional(),
894
- cpus: import_zod33.z.number().optional(),
895
- memory_mb: import_zod33.z.number().optional()
957
+ createdAt: import_zod35.z.string().datetime(),
958
+ updatedAt: import_zod35.z.string().datetime(),
959
+ config: import_zod35.z.object({
960
+ env: import_zod35.z.record(import_zod35.z.string()),
961
+ metadata: import_zod35.z.record(import_zod35.z.string()),
962
+ guest: import_zod35.z.object({
963
+ cpu_kind: import_zod35.z.string().optional(),
964
+ cpus: import_zod35.z.number().optional(),
965
+ memory_mb: import_zod35.z.number().optional()
896
966
  }).optional()
897
967
  }),
898
- events: import_zod33.z.array(
899
- import_zod33.z.object({
900
- type: import_zod33.z.string(),
901
- status: import_zod33.z.string(),
902
- timestamp: import_zod33.z.number()
968
+ events: import_zod35.z.array(
969
+ import_zod35.z.object({
970
+ type: import_zod35.z.string(),
971
+ status: import_zod35.z.string(),
972
+ timestamp: import_zod35.z.number()
903
973
  })
904
974
  ),
905
- checks: import_zod33.z.array(
906
- import_zod33.z.object({
907
- name: import_zod33.z.string(),
908
- status: import_zod33.z.string(),
909
- output: import_zod33.z.string(),
910
- updatedAt: import_zod33.z.string().datetime()
975
+ checks: import_zod35.z.array(
976
+ import_zod35.z.object({
977
+ name: import_zod35.z.string(),
978
+ status: import_zod35.z.string(),
979
+ output: import_zod35.z.string(),
980
+ updatedAt: import_zod35.z.string().datetime()
911
981
  })
912
982
  ).optional(),
913
- hostStatus: import_zod33.z.string()
983
+ hostStatus: import_zod35.z.string()
914
984
  })
915
985
  ),
916
- name: import_zod33.z.string(),
917
- organization: import_zod33.z.object({
918
- id: import_zod33.z.string(),
919
- slug: import_zod33.z.string()
986
+ name: import_zod35.z.string(),
987
+ organization: import_zod35.z.object({
988
+ id: import_zod35.z.string(),
989
+ slug: import_zod35.z.string()
920
990
  }),
921
- status: import_zod33.z.string(),
922
- version: import_zod33.z.number()
991
+ status: import_zod35.z.string(),
992
+ version: import_zod35.z.number()
923
993
  });
924
994
  var StatusTransformedResponseSchema = withCamelCase(
925
995
  statusFlyResponseSchema,
@@ -932,12 +1002,24 @@ var StatusTransformedResponseSchema = withCamelCase(
932
1002
  specialCases: { AppURL: "appUrl" }
933
1003
  }
934
1004
  );
1005
+ var statusLookupSchema = withCamelCase(
1006
+ import_zod35.z.object({
1007
+ name: import_zod35.z.string(),
1008
+ hostname: import_zod35.z.string(),
1009
+ machines: import_zod35.z.array(
1010
+ import_zod35.z.object({
1011
+ id: import_zod35.z.string(),
1012
+ state: import_zod35.z.string()
1013
+ }).passthrough()
1014
+ )
1015
+ }).passthrough()
1016
+ );
935
1017
 
936
1018
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
937
1019
  var StatusExtendedTransformedResponseSchema = withCamelCase(
938
1020
  statusFlyResponseSchema.extend({
939
- domains: import_zod35.z.array(import_zod35.z.object({ hostname: import_zod35.z.string() })),
940
- secrets: import_zod35.z.array(import_zod35.z.object({ name: import_zod35.z.string() }))
1021
+ domains: import_zod37.z.array(import_zod37.z.object({ hostname: import_zod37.z.string() })),
1022
+ secrets: import_zod37.z.array(import_zod37.z.object({ name: import_zod37.z.string() }))
941
1023
  }),
942
1024
  {
943
1025
  preserve: [
@@ -949,21 +1031,33 @@ var StatusExtendedTransformedResponseSchema = withCamelCase(
949
1031
  );
950
1032
 
951
1033
  // packages/fly-node/src/lib/schemas/version.schema.ts
952
- var import_zod37 = require("zod");
1034
+ var import_zod39 = require("zod");
953
1035
  var VersionTransformedResponseSchema = withCamelCase(
954
- import_zod37.z.object({
955
- name: import_zod37.z.string(),
956
- version: import_zod37.z.string(),
957
- commit: import_zod37.z.string(),
958
- branchName: import_zod37.z.string(),
959
- buildDate: import_zod37.z.string().datetime(),
960
- os: import_zod37.z.string(),
961
- architecture: import_zod37.z.string(),
962
- environment: import_zod37.z.string()
1036
+ import_zod39.z.object({
1037
+ name: import_zod39.z.string(),
1038
+ version: import_zod39.z.string(),
1039
+ commit: import_zod39.z.string(),
1040
+ branchName: import_zod39.z.string(),
1041
+ buildDate: import_zod39.z.string().datetime(),
1042
+ os: import_zod39.z.string(),
1043
+ architecture: import_zod39.z.string(),
1044
+ environment: import_zod39.z.string()
963
1045
  })
964
1046
  );
965
1047
 
966
1048
  // packages/fly-node/src/lib/fly.class.ts
1049
+ var TRANSIENT_FLY_ERRORS = [
1050
+ { cause: "no capacity available", pattern: /no capacity available/i },
1051
+ { cause: "builder deadline exceeded", pattern: /deadline_exceeded/i },
1052
+ {
1053
+ cause: "timed out connecting to machine",
1054
+ pattern: /timed out connecting to machine/i
1055
+ },
1056
+ // The status text, not a bare 503: an app whose health check answers
1057
+ // 503 is broken, not unlucky, and must not be deployed three times
1058
+ { cause: "Fly API 503", pattern: /503 Service Unavailable/i }
1059
+ ];
1060
+ var TRANSIENT_RETRY_DELAYS_MS = [1e4, 3e4];
967
1061
  var MACHINE_STATE_INTERVAL_MS = 2e3;
968
1062
  var MACHINE_STATE_TIMEOUT_MS = 12e4;
969
1063
  var Fly = class {
@@ -1049,7 +1143,9 @@ ${error}`);
1049
1143
  return await this.version();
1050
1144
  } catch (error) {
1051
1145
  throw new Error(`[version] something broke
1052
- ${error}`);
1146
+ ${error}`, {
1147
+ cause: error
1148
+ });
1053
1149
  }
1054
1150
  }
1055
1151
  };
@@ -1076,7 +1172,8 @@ ${error}`);
1076
1172
  } catch (error) {
1077
1173
  throw new Error(
1078
1174
  `[create app] something broke, check your apps
1079
- ${error}`
1175
+ ${error}`,
1176
+ { cause: error }
1080
1177
  );
1081
1178
  }
1082
1179
  },
@@ -1102,7 +1199,8 @@ ${error}`
1102
1199
  } catch (error) {
1103
1200
  throw new Error(
1104
1201
  `[destroy app] something broke, check your apps
1105
- ${error}`
1202
+ ${error}`,
1203
+ { cause: error }
1106
1204
  );
1107
1205
  }
1108
1206
  },
@@ -1117,7 +1215,7 @@ ${error}`
1117
1215
  return await this.fetchAllApps("throwOnError");
1118
1216
  } catch (error) {
1119
1217
  throw new Error(`[list] something broke
1120
- ${error}`);
1218
+ ${error}`, { cause: error });
1121
1219
  }
1122
1220
  }
1123
1221
  };
@@ -1142,7 +1240,8 @@ ${error}`);
1142
1240
  } catch (error) {
1143
1241
  throw new Error(
1144
1242
  `[add certificate] something broke, check your app certificates
1145
- ${error}`
1243
+ ${error}`,
1244
+ { cause: error }
1146
1245
  );
1147
1246
  }
1148
1247
  },
@@ -1160,7 +1259,9 @@ ${error}`
1160
1259
  return result;
1161
1260
  } catch (error) {
1162
1261
  throw new Error(`[list certificates] something broke
1163
- ${error}`);
1262
+ ${error}`, {
1263
+ cause: error
1264
+ });
1164
1265
  }
1165
1266
  },
1166
1267
  /**
@@ -1180,7 +1281,8 @@ ${error}`);
1180
1281
  } catch (error) {
1181
1282
  throw new Error(
1182
1283
  `[remove certificate] something broke, check your app certificates
1183
- ${error}`
1284
+ ${error}`,
1285
+ { cause: error }
1184
1286
  );
1185
1287
  }
1186
1288
  }
@@ -1207,7 +1309,9 @@ ${error}`
1207
1309
  );
1208
1310
  } catch (error) {
1209
1311
  throw new Error(`[save config] something broke
1210
- ${error}`);
1312
+ ${error}`, {
1313
+ cause: error
1314
+ });
1211
1315
  }
1212
1316
  },
1213
1317
  /**
@@ -1223,7 +1327,9 @@ ${error}`);
1223
1327
  return await this.showConfig("throwOnError", options);
1224
1328
  } catch (error) {
1225
1329
  throw new Error(`[show config] something broke
1226
- ${error}`);
1330
+ ${error}`, {
1331
+ cause: error
1332
+ });
1227
1333
  }
1228
1334
  }
1229
1335
  };
@@ -1266,7 +1372,7 @@ ${error}`);
1266
1372
  }
1267
1373
  const { appName } = await this.deployApp(options);
1268
1374
  this.logger.info(`Application '${appName}' was deployed`);
1269
- const status = await this.fetchAppStatus("throwOnError", {
1375
+ const status = await this.fetchAppLookup("throwOnError", {
1270
1376
  app: appName
1271
1377
  });
1272
1378
  return DeployResponseSchema.parse({
@@ -1277,7 +1383,8 @@ ${error}`);
1277
1383
  } catch (error) {
1278
1384
  throw new Error(
1279
1385
  `[deploy] something broke, check your ${isBuildOnly ? "builds" : "deployments"}
1280
- ${error}`
1386
+ ${error}`,
1387
+ { cause: error }
1281
1388
  );
1282
1389
  }
1283
1390
  };
@@ -1298,7 +1405,9 @@ ${error}`
1298
1405
  return await this.fetchAppIps("throwOnError", options);
1299
1406
  } catch (error) {
1300
1407
  throw new Error(`[list ips] something broke
1301
- ${error}`);
1408
+ ${error}`, {
1409
+ cause: error
1410
+ });
1302
1411
  }
1303
1412
  },
1304
1413
  /**
@@ -1308,7 +1417,8 @@ ${error}`);
1308
1417
  * safe on every deploy rather than only on create. That matters because
1309
1418
  * `flyctl` allocates addresses only for an app it creates itself — an app
1310
1419
  * that arrives any other way, such as a registry push auto-creating it,
1311
- * deploys green and answers nothing.
1420
+ * deploys green and answers nothing. `deploy` runs it before every
1421
+ * deploy that is not build-only.
1312
1422
  *
1313
1423
  * @param options - The application, and which addresses to ensure
1314
1424
  * @returns The addresses the application holds afterwards
@@ -1320,19 +1430,23 @@ ${error}`);
1320
1430
  const { sharedV4 = true, v6 = true } = options ?? {};
1321
1431
  const existing = await this.fetchAppIps("throwOnError", options);
1322
1432
  const has = (...types) => existing.some((ip) => types.includes(ip.type));
1433
+ let allocated = false;
1323
1434
  if (sharedV4 && !has("v4", "shared_v4")) {
1324
1435
  await this.allocateIp("allocate-v4", options);
1325
1436
  this.logger.info("Allocated a shared IPv4 address");
1437
+ allocated = true;
1326
1438
  }
1327
1439
  if (v6 && !has("v6")) {
1328
1440
  await this.allocateIp("allocate-v6", options);
1329
1441
  this.logger.info("Allocated a dedicated IPv6 address");
1442
+ allocated = true;
1330
1443
  }
1331
- return await this.fetchAppIps("throwOnError", options);
1444
+ return allocated ? await this.fetchAppIps("throwOnError", options) : existing;
1332
1445
  } catch (error) {
1333
1446
  throw new Error(
1334
1447
  `[ensure ips] something broke, check your app addresses
1335
- ${error}`
1448
+ ${error}`,
1449
+ { cause: error }
1336
1450
  );
1337
1451
  }
1338
1452
  }
@@ -1355,7 +1469,9 @@ ${error}`
1355
1469
  this.logger.info(`Machine '${machineId}' in app '${app}' was started`);
1356
1470
  } catch (error) {
1357
1471
  throw new Error(`[start machine] something broke
1358
- ${error}`);
1472
+ ${error}`, {
1473
+ cause: error
1474
+ });
1359
1475
  }
1360
1476
  },
1361
1477
  /**
@@ -1372,7 +1488,9 @@ ${error}`);
1372
1488
  this.logger.info(`Machine '${machineId}' in app '${app}' was stopped`);
1373
1489
  } catch (error) {
1374
1490
  throw new Error(`[stop machine] something broke
1375
- ${error}`);
1491
+ ${error}`, {
1492
+ cause: error
1493
+ });
1376
1494
  }
1377
1495
  },
1378
1496
  /**
@@ -1395,7 +1513,9 @@ ${error}`);
1395
1513
  );
1396
1514
  } catch (error) {
1397
1515
  throw new Error(`[restart machine] something broke
1398
- ${error}`);
1516
+ ${error}`, {
1517
+ cause: error
1518
+ });
1399
1519
  }
1400
1520
  },
1401
1521
  /**
@@ -1416,7 +1536,9 @@ ${error}`);
1416
1536
  this.logger.info(`Machine '${machineId}' in app '${app}' was updated`);
1417
1537
  } catch (error) {
1418
1538
  throw new Error(`[update machine] something broke
1419
- ${error}`);
1539
+ ${error}`, {
1540
+ cause: error
1541
+ });
1420
1542
  }
1421
1543
  }
1422
1544
  };
@@ -1450,7 +1572,9 @@ ${error}`);
1450
1572
  return await this.sshExec(app, command);
1451
1573
  } catch (error) {
1452
1574
  throw new Error(`[ssh exec] something broke
1453
- ${error}`);
1575
+ ${error}`, {
1576
+ cause: error
1577
+ });
1454
1578
  }
1455
1579
  }
1456
1580
  };
@@ -1476,7 +1600,8 @@ ${error}`);
1476
1600
  } catch (error) {
1477
1601
  throw new Error(
1478
1602
  `[set secrets] something broke, check your app secrets
1479
- ${error}`
1603
+ ${error}`,
1604
+ { cause: error }
1480
1605
  );
1481
1606
  }
1482
1607
  },
@@ -1499,7 +1624,9 @@ ${error}`
1499
1624
  this.logger.info(`Staged secrets were deployed for '${app}'`);
1500
1625
  } catch (error) {
1501
1626
  throw new Error(`[deploy secrets] something broke
1502
- ${error}`);
1627
+ ${error}`, {
1628
+ cause: error
1629
+ });
1503
1630
  }
1504
1631
  },
1505
1632
  /**
@@ -1516,7 +1643,9 @@ ${error}`);
1516
1643
  return result;
1517
1644
  } catch (error) {
1518
1645
  throw new Error(`[list secrets] something broke
1519
- ${error}`);
1646
+ ${error}`, {
1647
+ cause: error
1648
+ });
1520
1649
  }
1521
1650
  },
1522
1651
  /**
@@ -1537,7 +1666,8 @@ ${error}`);
1537
1666
  } catch (error) {
1538
1667
  throw new Error(
1539
1668
  `[unset secrets] something broke, check your app secrets
1540
- ${error}`
1669
+ ${error}`,
1670
+ { cause: error }
1541
1671
  );
1542
1672
  }
1543
1673
  }
@@ -1650,7 +1780,7 @@ ${error}`);
1650
1780
  lookupApp = appConfig.app;
1651
1781
  }
1652
1782
  if (lookupApp) {
1653
- const status = await this.fetchAppStatus("nullOnError", {
1783
+ const status = await this.fetchAppLookup("nullOnError", {
1654
1784
  app: lookupApp
1655
1785
  });
1656
1786
  if (status) {
@@ -1752,6 +1882,10 @@ ${error}`);
1752
1882
  );
1753
1883
  }
1754
1884
  }
1885
+ const servesTraffic = !!appConfig.httpService || (appConfig.services?.length ?? 0) > 0;
1886
+ if (!options?.buildOnly && servesTraffic) {
1887
+ await this.ips.ensure({ app: appName });
1888
+ }
1755
1889
  const args = ["deploy", "--app", appName, "--config", deployConfig];
1756
1890
  if (options?.region) {
1757
1891
  args.push("--region", options.region);
@@ -1778,10 +1912,10 @@ ${error}`);
1778
1912
  this.logger.info(
1779
1913
  options?.buildOnly ? `Building image for '${appName}'...` : `Deploying '${appName}'...`
1780
1914
  );
1781
- const output = await this.execFly(
1782
- args,
1783
- options?.buildOnly ? { streamStrategy: "combined" } : void 0
1784
- );
1915
+ const output = await this.execFly(args, {
1916
+ streamStrategy: options?.buildOnly ? "combined" : "stdout",
1917
+ retry: true
1918
+ });
1785
1919
  const imageRef = options?.buildOnly ? output?.match(/registry\.fly\.io\/\S+/)?.[0] : void 0;
1786
1920
  return { appName, imageRef };
1787
1921
  }
@@ -1827,7 +1961,7 @@ ${error}`);
1827
1961
  * @throws An error if the secrets cannot be set
1828
1962
  */
1829
1963
  async setAppSecrets(secrets, options) {
1830
- const status = await this.fetchAppStatus("throwOnError", options);
1964
+ const status = await this.fetchAppLookup("throwOnError", options);
1831
1965
  const args = ["secrets", "set"];
1832
1966
  args.push(...this.getAppOrConfigArgs(options));
1833
1967
  if (options?.stage) {
@@ -1836,7 +1970,7 @@ ${error}`);
1836
1970
  for (const [key, value] of Object.entries(secrets)) {
1837
1971
  args.push(`${key}=${this.safeArg(value)}`);
1838
1972
  }
1839
- await this.execFly(args);
1973
+ await this.execFly(args, { retry: options?.stage === true });
1840
1974
  return NameSchema.parse(status.name);
1841
1975
  }
1842
1976
  /**
@@ -1845,7 +1979,7 @@ ${error}`);
1845
1979
  * @throws An error if the secrets cannot be unset
1846
1980
  */
1847
1981
  async unsetAppSecrets(keys, options) {
1848
- const status = await this.fetchAppStatus("throwOnError", options);
1982
+ const status = await this.fetchAppLookup("throwOnError", options);
1849
1983
  const args = ["secrets", "unset"];
1850
1984
  args.push(...this.getAppOrConfigArgs(options));
1851
1985
  if (options?.stage) {
@@ -1861,7 +1995,7 @@ ${error}`);
1861
1995
  * @throws An error if the domain cannot be added
1862
1996
  */
1863
1997
  async addAppCertificate(hostname, options) {
1864
- const status = await this.fetchAppStatus("throwOnError", options);
1998
+ const status = await this.fetchAppLookup("throwOnError", options);
1865
1999
  const args = ["certs", "add", hostname];
1866
2000
  args.push(...this.getAppOrConfigArgs(options));
1867
2001
  args.push("--json");
@@ -1898,7 +2032,7 @@ ${error}`);
1898
2032
  args.push("--json");
1899
2033
  try {
1900
2034
  return await IpsListTransformedResponseSchema.parseAsync(
1901
- await this.execFly(args)
2035
+ await this.execFly(args, { retry: true })
1902
2036
  );
1903
2037
  } catch (error) {
1904
2038
  if (onError === "throwOnError") {
@@ -1913,7 +2047,7 @@ ${error}`);
1913
2047
  * @throws An error if the domain cannot be removed
1914
2048
  */
1915
2049
  async removeAppCertificate(hostname, options) {
1916
- const status = await this.fetchAppStatus("throwOnError", options);
2050
+ const status = await this.fetchAppLookup("throwOnError", options);
1917
2051
  const args = ["certs", "remove", hostname];
1918
2052
  args.push(...this.getAppOrConfigArgs(options));
1919
2053
  args.push("--yes");
@@ -1988,7 +2122,7 @@ ${error}`);
1988
2122
  async waitForMachineState(app, machineId, states) {
1989
2123
  const deadline = Date.now() + MACHINE_STATE_TIMEOUT_MS;
1990
2124
  while (Date.now() < deadline) {
1991
- const status = await this.fetchAppStatus("nullOnError", { app });
2125
+ const status = await this.fetchAppLookup("nullOnError", { app });
1992
2126
  const machine = status?.machines.find(({ id }) => id === machineId);
1993
2127
  if (machine && states.includes(machine.state)) {
1994
2128
  return;
@@ -2095,7 +2229,28 @@ ${error}`);
2095
2229
  if (onError === "throwOnError") {
2096
2230
  throw error;
2097
2231
  }
2098
- if (error instanceof import_zod38.ZodError) {
2232
+ if (error instanceof import_zod40.ZodError) {
2233
+ this.logger.info(`Failed to parse response:
2234
+ ${error.message}`);
2235
+ this.logger.info(`Raw response:
2236
+ ${JSON.stringify(response, null, 2)}`);
2237
+ }
2238
+ return null;
2239
+ }
2240
+ }
2241
+ async fetchAppLookup(onError, options) {
2242
+ const args = ["status"];
2243
+ args.push(...this.getAppOrConfigArgs(options));
2244
+ args.push("--json");
2245
+ let response = null;
2246
+ try {
2247
+ response = await this.execFly(args);
2248
+ return statusLookupSchema.parse(response);
2249
+ } catch (error) {
2250
+ if (onError === "throwOnError") {
2251
+ throw error;
2252
+ }
2253
+ if (error instanceof import_zod40.ZodError) {
2099
2254
  this.logger.info(`Failed to parse response:
2100
2255
  ${error.message}`);
2101
2256
  this.logger.info(`Raw response:
@@ -2231,33 +2386,32 @@ ${JSON.stringify(response, null, 2)}`);
2231
2386
  }
2232
2387
  const flyCmd = "flyctl";
2233
2388
  const toLogCmd = `${flyCmd} ${args.join(" ")}`;
2389
+ const { retry = false, ...execOpts } = options ?? {};
2234
2390
  let output = "";
2235
- try {
2236
- this.traceCLI("CALL", toLogCmd);
2237
- if (options?.prompt) {
2238
- output = await spawnPty(flyCmd, args, { prompt: options.prompt });
2239
- this.traceCLI("RESULT", output);
2240
- } else {
2241
- const { streamStrategy = "stdout", ...spawnOpts } = options ?? {};
2242
- const result = await spawn(flyCmd, args, {
2243
- ...spawnOpts,
2244
- streamToConsole: this.logger.streamToConsole
2245
- });
2246
- const stdout = result.stdout.trim();
2247
- const stderr = result.stderr.trim();
2248
- this.traceCLI("RESULT", `${stdout}${stderr ? `
2249
- ${stderr}` : ""}`);
2250
- output = streamStrategy === "combined" ? `${stdout}
2251
- ${stderr}` : streamStrategy === "stderr" ? stderr : stdout;
2252
- }
2253
- } catch (error) {
2254
- const errorMsg = error.message;
2255
- this.traceCLI("RESULT", errorMsg);
2256
- if (onError === "throwOnError") {
2257
- throw new Error(`Command failed: ${toLogCmd}
2258
- ${errorMsg}`);
2391
+ for (let attempt = 1; ; attempt++) {
2392
+ try {
2393
+ output = await this.spawnFly(flyCmd, args, toLogCmd, execOpts);
2394
+ break;
2395
+ } catch (error) {
2396
+ const errorMsg = error.message;
2397
+ this.traceCLI("RESULT", errorMsg);
2398
+ const cause = retry ? this.transientCause(error) : null;
2399
+ const delay = TRANSIENT_RETRY_DELAYS_MS[attempt - 1];
2400
+ if (cause && delay !== void 0) {
2401
+ this.logger.info(
2402
+ `Transient Fly error (${cause}), retrying in ${delay / 1e3}s (attempt ${attempt + 1} of ${TRANSIENT_RETRY_DELAYS_MS.length + 1}): ${toLogCmd}`
2403
+ );
2404
+ await new Promise((resolve) => setTimeout(resolve, delay));
2405
+ continue;
2406
+ }
2407
+ if (onError === "throwOnError") {
2408
+ throw new Error(`Command failed: ${toLogCmd}
2409
+ ${errorMsg}`, {
2410
+ cause: error
2411
+ });
2412
+ }
2413
+ return null;
2259
2414
  }
2260
- return null;
2261
2415
  }
2262
2416
  try {
2263
2417
  return JSON.parse(output);
@@ -2271,6 +2425,55 @@ ${errorMsg}`);
2271
2425
  }
2272
2426
  return void 0;
2273
2427
  }
2428
+ /**
2429
+ * @private
2430
+ * Run one fly command and assemble its output
2431
+ *
2432
+ * @returns The output selected by `streamStrategy`
2433
+ * @throws An error if the command fails
2434
+ */
2435
+ async spawnFly(flyCmd, args, toLogCmd, options) {
2436
+ this.traceCLI("CALL", toLogCmd);
2437
+ if (options.prompt) {
2438
+ const output = await spawnPty(flyCmd, args, { prompt: options.prompt });
2439
+ this.traceCLI("RESULT", output);
2440
+ return output;
2441
+ }
2442
+ const { streamStrategy = "stdout", ...spawnOpts } = options;
2443
+ const result = await spawn(flyCmd, args, {
2444
+ ...spawnOpts,
2445
+ streamToConsole: this.logger.streamToConsole
2446
+ });
2447
+ const stdout = result.stdout.trim();
2448
+ const stderr = result.stderr.trim();
2449
+ this.traceCLI("RESULT", `${stdout}${stderr ? `
2450
+ ${stderr}` : ""}`);
2451
+ return streamStrategy === "combined" ? `${stdout}
2452
+ ${stderr}` : streamStrategy === "stderr" ? stderr : stdout;
2453
+ }
2454
+ /**
2455
+ * @private
2456
+ * Name the transient Fly error behind a failed command, if it was one.
2457
+ *
2458
+ * Only the error flyctl ended with counts: from its last `Error` line to
2459
+ * the end of stderr, or the last few lines when there is none. A deploy
2460
+ * streams the app's own output and errors flyctl recovered from, and
2461
+ * matching those would repeat a deploy that failed for a real reason.
2462
+ *
2463
+ * @returns The cause, or `null` when the failure is not a known transient one
2464
+ */
2465
+ transientCause(error) {
2466
+ let text;
2467
+ if (error instanceof SpawnError) {
2468
+ const lines = error.stderr.split(/\r?\n/).filter((line) => line.trim());
2469
+ const errorLines = lines.map((line) => /^\s*Error\b/.test(line));
2470
+ const last = errorLines.lastIndexOf(true);
2471
+ text = lines.slice(last >= 0 ? last : -3).join("\n");
2472
+ } else {
2473
+ text = String(error?.message ?? error);
2474
+ }
2475
+ return TRANSIENT_FLY_ERRORS.find(({ pattern }) => pattern.test(text))?.cause ?? null;
2476
+ }
2274
2477
  /**
2275
2478
  * @private
2276
2479
  * Get the arguments for `AppOrConfig` options
@@ -2419,6 +2622,8 @@ ${errorMsg}`);
2419
2622
  };
2420
2623
  // Annotate the CommonJS export names for ESM import in node:
2421
2624
  0 && (module.exports = {
2625
+ AppIpAddressSchema,
2626
+ AppIpAddressesApiResponseSchema,
2422
2627
  CertificateApiResponseSchema,
2423
2628
  CertificateListApiResponseSchema,
2424
2629
  DnsInstructionsSchema,