@cdwr/fly-node 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +4 -0
- package/api.cjs +115 -58
- package/api.js +113 -58
- package/index.cjs +486 -277
- package/index.js +482 -275
- package/package.json +2 -2
- package/src/api.d.ts +1 -0
- package/src/lib/fly-api.class.d.ts +21 -1
- package/src/lib/fly.class.d.ts +38 -1
- package/src/lib/mocks.d.ts +62 -0
- package/src/lib/schemas/app-ip-addresses.schema.d.ts +38 -0
- package/src/lib/schemas/apps-create.schema.d.ts +2 -11
- package/src/lib/schemas/apps-list.schema.d.ts +4 -58
- package/src/lib/schemas/build-response.schema.d.ts +1 -7
- package/src/lib/schemas/certificate.schema.d.ts +16 -290
- package/src/lib/schemas/certs-list-with-app.schema.d.ts +2 -18
- package/src/lib/schemas/certs-list.schema.d.ts +3 -23
- package/src/lib/schemas/config-show.schema.d.ts +5 -62
- package/src/lib/schemas/deploy.schema.d.ts +1 -9
- package/src/lib/schemas/ip-type.schema.d.ts +19 -0
- package/src/lib/schemas/ips-list.schema.d.ts +15 -45
- package/src/lib/schemas/machine.schema.d.ts +2 -24
- package/src/lib/schemas/postgres-list.d.ts +3 -42
- package/src/lib/schemas/postgres-users-list.d.ts +3 -15
- package/src/lib/schemas/secrets-list-with-app.schema.d.ts +2 -15
- package/src/lib/schemas/secrets-list.schema.d.ts +3 -18
- package/src/lib/schemas/status-extended.schema.d.ts +11 -309
- package/src/lib/schemas/status.schema.d.ts +35 -512
- package/src/lib/schemas/version.schema.d.ts +2 -29
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/
|
|
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
|
|
48
|
-
|
|
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:
|
|
51
|
-
id:
|
|
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:
|
|
54
|
-
isWildcard:
|
|
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:
|
|
57
|
-
isAcmeAlpnConfigured:
|
|
58
|
-
isAcmeHttpConfigured:
|
|
59
|
-
certificateAuthority:
|
|
60
|
-
certificateRequestedAt:
|
|
61
|
-
createdAt:
|
|
62
|
-
domain:
|
|
63
|
-
dnsProvider:
|
|
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:
|
|
84
|
+
dnsValidationHostname: import_zod3.z.string().nullish(),
|
|
66
85
|
/** Value that record must contain */
|
|
67
|
-
dnsValidationTarget:
|
|
86
|
+
dnsValidationTarget: import_zod3.z.string().nullish(),
|
|
68
87
|
/** Fly's own prose describing the records to create */
|
|
69
|
-
dnsValidationInstructions:
|
|
88
|
+
dnsValidationInstructions: import_zod3.z.string().nullish(),
|
|
70
89
|
/** Fly's summary of where issuance has got to */
|
|
71
|
-
clientStatus:
|
|
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:
|
|
79
|
-
source:
|
|
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:
|
|
85
|
-
|
|
86
|
-
message:
|
|
87
|
-
timestamp:
|
|
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:
|
|
98
|
-
nodes:
|
|
99
|
-
|
|
100
|
-
id:
|
|
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:
|
|
103
|
-
hostname:
|
|
104
|
-
expiresAt:
|
|
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 =
|
|
110
|
-
aRecords:
|
|
111
|
-
aaaaRecords:
|
|
112
|
-
cnameRecords:
|
|
113
|
-
caaRecords:
|
|
114
|
-
soa:
|
|
115
|
-
dnsProvider:
|
|
116
|
-
dnsVerificationRecord:
|
|
117
|
-
dnsConfigured:
|
|
118
|
-
acmeDnsConfigured:
|
|
119
|
-
resolvedAddresses:
|
|
120
|
-
isProxied:
|
|
121
|
-
errors:
|
|
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 =
|
|
124
|
-
hostname:
|
|
125
|
-
target:
|
|
126
|
-
instructions:
|
|
127
|
-
isApex:
|
|
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 =
|
|
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
|
|
135
|
-
var MachineApiResponseSchema =
|
|
136
|
-
id:
|
|
137
|
-
name:
|
|
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:
|
|
140
|
-
region:
|
|
158
|
+
state: import_zod4.z.string().nullish(),
|
|
159
|
+
region: import_zod4.z.string().nullish()
|
|
141
160
|
});
|
|
142
|
-
var MachineListApiResponseSchema =
|
|
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
|
-
|
|
576
|
-
|
|
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,27 @@ Output: ${output}`)
|
|
|
615
686
|
}
|
|
616
687
|
|
|
617
688
|
// packages/fly-node/src/lib/fly.class.ts
|
|
618
|
-
var
|
|
689
|
+
var import_zod40 = require("zod");
|
|
619
690
|
|
|
620
691
|
// libs/shared/util/zod/src/lib/coerce-boolean.ts
|
|
621
|
-
var
|
|
692
|
+
var import_zod5 = require("zod");
|
|
622
693
|
|
|
623
694
|
// libs/shared/util/zod/src/lib/create-lowercase-schema.ts
|
|
624
|
-
var
|
|
695
|
+
var import_zod6 = require("zod");
|
|
625
696
|
|
|
626
697
|
// libs/shared/util/zod/src/lib/json.schema.ts
|
|
627
|
-
var
|
|
628
|
-
var LiteralSchema =
|
|
629
|
-
var JsonSchema =
|
|
630
|
-
() =>
|
|
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([
|
|
702
|
+
LiteralSchema,
|
|
703
|
+
import_zod7.z.array(JsonSchema),
|
|
704
|
+
import_zod7.z.record(import_zod7.z.string(), JsonSchema)
|
|
705
|
+
])
|
|
631
706
|
);
|
|
632
707
|
|
|
633
708
|
// libs/shared/util/zod/src/lib/with-camel-case.preprocess.ts
|
|
634
|
-
var
|
|
709
|
+
var import_zod8 = require("zod");
|
|
635
710
|
var toCamelCase = (str, specialCases = {}) => {
|
|
636
711
|
if (specialCases[str]) {
|
|
637
712
|
return specialCases[str];
|
|
@@ -681,7 +756,7 @@ var transformKeys = (options) => {
|
|
|
681
756
|
};
|
|
682
757
|
var withCamelCase = (schema, options = {}) => {
|
|
683
758
|
const { preserve = [], specialCases = {} } = options;
|
|
684
|
-
return
|
|
759
|
+
return import_zod8.z.preprocess(
|
|
685
760
|
(data) => transformKeys({
|
|
686
761
|
currentPath: [],
|
|
687
762
|
data,
|
|
@@ -693,38 +768,38 @@ var withCamelCase = (schema, options = {}) => {
|
|
|
693
768
|
};
|
|
694
769
|
|
|
695
770
|
// libs/shared/util/zod/src/lib/with-env-vars.preprocess.ts
|
|
696
|
-
var
|
|
771
|
+
var import_zod9 = require("zod");
|
|
697
772
|
|
|
698
773
|
// libs/shared/util/zod/src/lib/with-replace-all.preprocess.ts
|
|
699
|
-
var
|
|
774
|
+
var import_zod10 = require("zod");
|
|
700
775
|
|
|
701
776
|
// packages/fly-node/src/lib/schemas/apps-create.schema.ts
|
|
702
|
-
var
|
|
777
|
+
var import_zod12 = require("zod");
|
|
703
778
|
var AppsCreateTransformedResponseSchema = withCamelCase(
|
|
704
|
-
|
|
705
|
-
id:
|
|
706
|
-
name:
|
|
779
|
+
import_zod12.z.object({
|
|
780
|
+
id: import_zod12.z.string(),
|
|
781
|
+
name: import_zod12.z.string()
|
|
707
782
|
})
|
|
708
783
|
);
|
|
709
784
|
|
|
710
785
|
// packages/fly-node/src/lib/schemas/apps-list.schema.ts
|
|
711
|
-
var
|
|
712
|
-
var AppsListTransformedResponseSchema =
|
|
786
|
+
var import_zod14 = require("zod");
|
|
787
|
+
var AppsListTransformedResponseSchema = import_zod14.z.array(
|
|
713
788
|
withCamelCase(
|
|
714
|
-
|
|
715
|
-
id:
|
|
716
|
-
name:
|
|
717
|
-
status:
|
|
718
|
-
deployed:
|
|
719
|
-
hostname:
|
|
720
|
-
organization:
|
|
721
|
-
name:
|
|
722
|
-
slug:
|
|
789
|
+
import_zod14.z.object({
|
|
790
|
+
id: import_zod14.z.string(),
|
|
791
|
+
name: import_zod14.z.string(),
|
|
792
|
+
status: import_zod14.z.string(),
|
|
793
|
+
deployed: import_zod14.z.boolean(),
|
|
794
|
+
hostname: import_zod14.z.string(),
|
|
795
|
+
organization: import_zod14.z.object({
|
|
796
|
+
name: import_zod14.z.string(),
|
|
797
|
+
slug: import_zod14.z.string()
|
|
723
798
|
}),
|
|
724
|
-
currentRelease:
|
|
725
|
-
|
|
726
|
-
status:
|
|
727
|
-
createdAt:
|
|
799
|
+
currentRelease: import_zod14.z.nullable(
|
|
800
|
+
import_zod14.z.object({
|
|
801
|
+
status: import_zod14.z.string(),
|
|
802
|
+
createdAt: import_zod14.z.string().datetime()
|
|
728
803
|
})
|
|
729
804
|
)
|
|
730
805
|
})
|
|
@@ -732,53 +807,53 @@ var AppsListTransformedResponseSchema = import_zod12.z.array(
|
|
|
732
807
|
);
|
|
733
808
|
|
|
734
809
|
// packages/fly-node/src/lib/schemas/build-response.schema.ts
|
|
735
|
-
var
|
|
736
|
-
var BuildResponseSchema =
|
|
737
|
-
appName:
|
|
738
|
-
imageRef:
|
|
810
|
+
var import_zod15 = require("zod");
|
|
811
|
+
var BuildResponseSchema = import_zod15.z.object({
|
|
812
|
+
appName: import_zod15.z.string(),
|
|
813
|
+
imageRef: import_zod15.z.string()
|
|
739
814
|
});
|
|
740
815
|
|
|
741
816
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
742
|
-
var
|
|
817
|
+
var import_zod19 = require("zod");
|
|
743
818
|
|
|
744
819
|
// packages/fly-node/src/lib/schemas/certs-list.schema.ts
|
|
745
|
-
var
|
|
746
|
-
var CertsListFlyResponseElementSchema =
|
|
747
|
-
createdAt:
|
|
748
|
-
hostname:
|
|
749
|
-
clientStatus:
|
|
820
|
+
var import_zod17 = require("zod");
|
|
821
|
+
var CertsListFlyResponseElementSchema = import_zod17.z.object({
|
|
822
|
+
createdAt: import_zod17.z.string().datetime(),
|
|
823
|
+
hostname: import_zod17.z.string(),
|
|
824
|
+
clientStatus: import_zod17.z.string()
|
|
750
825
|
});
|
|
751
|
-
var CertsListTransformedResponseSchema =
|
|
826
|
+
var CertsListTransformedResponseSchema = import_zod17.z.array(
|
|
752
827
|
withCamelCase(CertsListFlyResponseElementSchema)
|
|
753
828
|
);
|
|
754
829
|
|
|
755
830
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
756
|
-
var CertsListWithAppTransformedResponseSchema =
|
|
831
|
+
var CertsListWithAppTransformedResponseSchema = import_zod19.z.array(
|
|
757
832
|
withCamelCase(
|
|
758
833
|
CertsListFlyResponseElementSchema.extend({
|
|
759
|
-
app:
|
|
834
|
+
app: import_zod19.z.string()
|
|
760
835
|
})
|
|
761
836
|
)
|
|
762
837
|
);
|
|
763
838
|
|
|
764
839
|
// packages/fly-node/src/lib/schemas/config-show.schema.ts
|
|
765
|
-
var
|
|
840
|
+
var import_zod21 = require("zod");
|
|
766
841
|
var ConfigShowResponseSchema = withCamelCase(
|
|
767
|
-
|
|
768
|
-
app:
|
|
769
|
-
primaryRegion:
|
|
770
|
-
build:
|
|
771
|
-
|
|
772
|
-
args:
|
|
773
|
-
dockerfile:
|
|
774
|
-
image:
|
|
842
|
+
import_zod21.z.object({
|
|
843
|
+
app: import_zod21.z.string(),
|
|
844
|
+
primaryRegion: import_zod21.z.string().optional(),
|
|
845
|
+
build: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any()).optional().or(
|
|
846
|
+
import_zod21.z.object({
|
|
847
|
+
args: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.string()).optional(),
|
|
848
|
+
dockerfile: import_zod21.z.string().optional(),
|
|
849
|
+
image: import_zod21.z.string().optional()
|
|
775
850
|
})
|
|
776
851
|
),
|
|
777
|
-
deploy:
|
|
778
|
-
env:
|
|
779
|
-
httpService:
|
|
780
|
-
mounts:
|
|
781
|
-
services:
|
|
852
|
+
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() })),
|
|
853
|
+
env: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.string()).optional(),
|
|
854
|
+
httpService: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any()).optional(),
|
|
855
|
+
mounts: import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any()).optional(),
|
|
856
|
+
services: import_zod21.z.array(import_zod21.z.record(import_zod21.z.string(), import_zod21.z.any())).optional()
|
|
782
857
|
}),
|
|
783
858
|
{
|
|
784
859
|
preserve: ["build.args", "env"]
|
|
@@ -786,140 +861,139 @@ var ConfigShowResponseSchema = withCamelCase(
|
|
|
786
861
|
);
|
|
787
862
|
|
|
788
863
|
// packages/fly-node/src/lib/schemas/deploy.schema.ts
|
|
789
|
-
var
|
|
790
|
-
var DeployResponseSchema =
|
|
791
|
-
app:
|
|
792
|
-
hostname:
|
|
793
|
-
url:
|
|
864
|
+
var import_zod22 = require("zod");
|
|
865
|
+
var DeployResponseSchema = import_zod22.z.object({
|
|
866
|
+
app: import_zod22.z.string(),
|
|
867
|
+
hostname: import_zod22.z.string(),
|
|
868
|
+
url: import_zod22.z.string().url()
|
|
794
869
|
});
|
|
795
870
|
|
|
796
871
|
// packages/fly-node/src/lib/schemas/helper-schemas.ts
|
|
797
|
-
var
|
|
798
|
-
var AllowEmptyUrlSchema =
|
|
799
|
-
var NameSchema =
|
|
872
|
+
var import_zod23 = require("zod");
|
|
873
|
+
var AllowEmptyUrlSchema = import_zod23.z.string().url().or(import_zod23.z.literal(""));
|
|
874
|
+
var NameSchema = import_zod23.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
|
|
800
875
|
|
|
801
876
|
// packages/fly-node/src/lib/schemas/ips-list.schema.ts
|
|
802
|
-
var
|
|
803
|
-
var
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
address: import_zod23.z.string(),
|
|
877
|
+
var import_zod25 = require("zod");
|
|
878
|
+
var IpsListFlyResponseElementSchema = import_zod25.z.object({
|
|
879
|
+
id: import_zod25.z.string(),
|
|
880
|
+
address: import_zod25.z.string(),
|
|
807
881
|
type: IpTypeSchema,
|
|
808
|
-
region:
|
|
809
|
-
createdAt:
|
|
882
|
+
region: import_zod25.z.string(),
|
|
883
|
+
createdAt: import_zod25.z.string()
|
|
810
884
|
});
|
|
811
|
-
var IpsListTransformedResponseSchema =
|
|
885
|
+
var IpsListTransformedResponseSchema = import_zod25.z.array(
|
|
812
886
|
withCamelCase(IpsListFlyResponseElementSchema)
|
|
813
887
|
);
|
|
814
888
|
|
|
815
889
|
// packages/fly-node/src/lib/schemas/postgres-list.ts
|
|
816
|
-
var
|
|
817
|
-
var PostgresListTransformedResponseSchema =
|
|
890
|
+
var import_zod27 = require("zod");
|
|
891
|
+
var PostgresListTransformedResponseSchema = import_zod27.z.array(
|
|
818
892
|
withCamelCase(
|
|
819
|
-
|
|
820
|
-
deployed:
|
|
821
|
-
hostname:
|
|
822
|
-
id:
|
|
823
|
-
name:
|
|
824
|
-
organization:
|
|
825
|
-
status:
|
|
826
|
-
version:
|
|
893
|
+
import_zod27.z.object({
|
|
894
|
+
deployed: import_zod27.z.boolean(),
|
|
895
|
+
hostname: import_zod27.z.string(),
|
|
896
|
+
id: import_zod27.z.string(),
|
|
897
|
+
name: import_zod27.z.string(),
|
|
898
|
+
organization: import_zod27.z.object({ id: import_zod27.z.string(), slug: import_zod27.z.string() }),
|
|
899
|
+
status: import_zod27.z.string(),
|
|
900
|
+
version: import_zod27.z.number()
|
|
827
901
|
})
|
|
828
902
|
)
|
|
829
|
-
).or(
|
|
903
|
+
).or(import_zod27.z.string());
|
|
830
904
|
|
|
831
905
|
// packages/fly-node/src/lib/schemas/postgres-users-list.ts
|
|
832
|
-
var
|
|
833
|
-
var PostgresUsersListTransformedResponseSchema =
|
|
906
|
+
var import_zod29 = require("zod");
|
|
907
|
+
var PostgresUsersListTransformedResponseSchema = import_zod29.z.array(
|
|
834
908
|
withCamelCase(
|
|
835
|
-
|
|
836
|
-
username:
|
|
837
|
-
superuser:
|
|
838
|
-
databases:
|
|
909
|
+
import_zod29.z.object({
|
|
910
|
+
username: import_zod29.z.string(),
|
|
911
|
+
superuser: import_zod29.z.boolean(),
|
|
912
|
+
databases: import_zod29.z.array(import_zod29.z.string())
|
|
839
913
|
})
|
|
840
914
|
)
|
|
841
915
|
);
|
|
842
916
|
|
|
843
917
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
844
|
-
var
|
|
918
|
+
var import_zod33 = require("zod");
|
|
845
919
|
|
|
846
920
|
// packages/fly-node/src/lib/schemas/secrets-list.schema.ts
|
|
847
|
-
var
|
|
848
|
-
var SecretsListFlyResponseElementSchema =
|
|
849
|
-
name:
|
|
850
|
-
digest:
|
|
921
|
+
var import_zod31 = require("zod");
|
|
922
|
+
var SecretsListFlyResponseElementSchema = import_zod31.z.object({
|
|
923
|
+
name: import_zod31.z.string(),
|
|
924
|
+
digest: import_zod31.z.string()
|
|
851
925
|
});
|
|
852
|
-
var SecretsListTransformedResponseSchema =
|
|
926
|
+
var SecretsListTransformedResponseSchema = import_zod31.z.array(
|
|
853
927
|
withCamelCase(SecretsListFlyResponseElementSchema)
|
|
854
928
|
);
|
|
855
929
|
|
|
856
930
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
857
|
-
var SecretsListWithAppTransformedResponseSchema =
|
|
931
|
+
var SecretsListWithAppTransformedResponseSchema = import_zod33.z.array(
|
|
858
932
|
withCamelCase(
|
|
859
933
|
SecretsListFlyResponseElementSchema.extend({
|
|
860
|
-
app:
|
|
934
|
+
app: import_zod33.z.string()
|
|
861
935
|
})
|
|
862
936
|
)
|
|
863
937
|
);
|
|
864
938
|
|
|
865
939
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
866
|
-
var
|
|
940
|
+
var import_zod37 = require("zod");
|
|
867
941
|
|
|
868
942
|
// packages/fly-node/src/lib/schemas/status.schema.ts
|
|
869
|
-
var
|
|
870
|
-
var statusFlyResponseSchema =
|
|
871
|
-
deployed:
|
|
872
|
-
hostname:
|
|
873
|
-
id:
|
|
874
|
-
machines:
|
|
875
|
-
|
|
876
|
-
id:
|
|
877
|
-
name:
|
|
878
|
-
state:
|
|
879
|
-
region:
|
|
880
|
-
imageRef:
|
|
881
|
-
registry:
|
|
882
|
-
repository:
|
|
883
|
-
tag:
|
|
884
|
-
digest:
|
|
885
|
-
labels:
|
|
943
|
+
var import_zod35 = require("zod");
|
|
944
|
+
var statusFlyResponseSchema = import_zod35.z.object({
|
|
945
|
+
deployed: import_zod35.z.boolean(),
|
|
946
|
+
hostname: import_zod35.z.string(),
|
|
947
|
+
id: import_zod35.z.string(),
|
|
948
|
+
machines: import_zod35.z.array(
|
|
949
|
+
import_zod35.z.object({
|
|
950
|
+
id: import_zod35.z.string(),
|
|
951
|
+
name: import_zod35.z.string(),
|
|
952
|
+
state: import_zod35.z.string(),
|
|
953
|
+
region: import_zod35.z.string(),
|
|
954
|
+
imageRef: import_zod35.z.object({
|
|
955
|
+
registry: import_zod35.z.string(),
|
|
956
|
+
repository: import_zod35.z.string(),
|
|
957
|
+
tag: import_zod35.z.string(),
|
|
958
|
+
digest: import_zod35.z.string(),
|
|
959
|
+
labels: import_zod35.z.record(import_zod35.z.string(), import_zod35.z.string()).optional()
|
|
886
960
|
}),
|
|
887
|
-
createdAt:
|
|
888
|
-
updatedAt:
|
|
889
|
-
config:
|
|
890
|
-
env:
|
|
891
|
-
metadata:
|
|
892
|
-
guest:
|
|
893
|
-
cpu_kind:
|
|
894
|
-
cpus:
|
|
895
|
-
memory_mb:
|
|
961
|
+
createdAt: import_zod35.z.string().datetime(),
|
|
962
|
+
updatedAt: import_zod35.z.string().datetime(),
|
|
963
|
+
config: import_zod35.z.object({
|
|
964
|
+
env: import_zod35.z.record(import_zod35.z.string(), import_zod35.z.string()),
|
|
965
|
+
metadata: import_zod35.z.record(import_zod35.z.string(), import_zod35.z.string()),
|
|
966
|
+
guest: import_zod35.z.object({
|
|
967
|
+
cpu_kind: import_zod35.z.string().optional(),
|
|
968
|
+
cpus: import_zod35.z.number().optional(),
|
|
969
|
+
memory_mb: import_zod35.z.number().optional()
|
|
896
970
|
}).optional()
|
|
897
971
|
}),
|
|
898
|
-
events:
|
|
899
|
-
|
|
900
|
-
type:
|
|
901
|
-
status:
|
|
902
|
-
timestamp:
|
|
972
|
+
events: import_zod35.z.array(
|
|
973
|
+
import_zod35.z.object({
|
|
974
|
+
type: import_zod35.z.string(),
|
|
975
|
+
status: import_zod35.z.string(),
|
|
976
|
+
timestamp: import_zod35.z.number()
|
|
903
977
|
})
|
|
904
978
|
),
|
|
905
|
-
checks:
|
|
906
|
-
|
|
907
|
-
name:
|
|
908
|
-
status:
|
|
909
|
-
output:
|
|
910
|
-
updatedAt:
|
|
979
|
+
checks: import_zod35.z.array(
|
|
980
|
+
import_zod35.z.object({
|
|
981
|
+
name: import_zod35.z.string(),
|
|
982
|
+
status: import_zod35.z.string(),
|
|
983
|
+
output: import_zod35.z.string(),
|
|
984
|
+
updatedAt: import_zod35.z.string().datetime()
|
|
911
985
|
})
|
|
912
986
|
).optional(),
|
|
913
|
-
hostStatus:
|
|
987
|
+
hostStatus: import_zod35.z.string()
|
|
914
988
|
})
|
|
915
989
|
),
|
|
916
|
-
name:
|
|
917
|
-
organization:
|
|
918
|
-
id:
|
|
919
|
-
slug:
|
|
990
|
+
name: import_zod35.z.string(),
|
|
991
|
+
organization: import_zod35.z.object({
|
|
992
|
+
id: import_zod35.z.string(),
|
|
993
|
+
slug: import_zod35.z.string()
|
|
920
994
|
}),
|
|
921
|
-
status:
|
|
922
|
-
version:
|
|
995
|
+
status: import_zod35.z.string(),
|
|
996
|
+
version: import_zod35.z.number()
|
|
923
997
|
});
|
|
924
998
|
var StatusTransformedResponseSchema = withCamelCase(
|
|
925
999
|
statusFlyResponseSchema,
|
|
@@ -932,12 +1006,24 @@ var StatusTransformedResponseSchema = withCamelCase(
|
|
|
932
1006
|
specialCases: { AppURL: "appUrl" }
|
|
933
1007
|
}
|
|
934
1008
|
);
|
|
1009
|
+
var statusLookupSchema = withCamelCase(
|
|
1010
|
+
import_zod35.z.object({
|
|
1011
|
+
name: import_zod35.z.string(),
|
|
1012
|
+
hostname: import_zod35.z.string(),
|
|
1013
|
+
machines: import_zod35.z.array(
|
|
1014
|
+
import_zod35.z.object({
|
|
1015
|
+
id: import_zod35.z.string(),
|
|
1016
|
+
state: import_zod35.z.string()
|
|
1017
|
+
}).passthrough()
|
|
1018
|
+
)
|
|
1019
|
+
}).passthrough()
|
|
1020
|
+
);
|
|
935
1021
|
|
|
936
1022
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
937
1023
|
var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
938
1024
|
statusFlyResponseSchema.extend({
|
|
939
|
-
domains:
|
|
940
|
-
secrets:
|
|
1025
|
+
domains: import_zod37.z.array(import_zod37.z.object({ hostname: import_zod37.z.string() })),
|
|
1026
|
+
secrets: import_zod37.z.array(import_zod37.z.object({ name: import_zod37.z.string() }))
|
|
941
1027
|
}),
|
|
942
1028
|
{
|
|
943
1029
|
preserve: [
|
|
@@ -949,21 +1035,33 @@ var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
|
949
1035
|
);
|
|
950
1036
|
|
|
951
1037
|
// packages/fly-node/src/lib/schemas/version.schema.ts
|
|
952
|
-
var
|
|
1038
|
+
var import_zod39 = require("zod");
|
|
953
1039
|
var VersionTransformedResponseSchema = withCamelCase(
|
|
954
|
-
|
|
955
|
-
name:
|
|
956
|
-
version:
|
|
957
|
-
commit:
|
|
958
|
-
branchName:
|
|
959
|
-
buildDate:
|
|
960
|
-
os:
|
|
961
|
-
architecture:
|
|
962
|
-
environment:
|
|
1040
|
+
import_zod39.z.object({
|
|
1041
|
+
name: import_zod39.z.string(),
|
|
1042
|
+
version: import_zod39.z.string(),
|
|
1043
|
+
commit: import_zod39.z.string(),
|
|
1044
|
+
branchName: import_zod39.z.string(),
|
|
1045
|
+
buildDate: import_zod39.z.string().datetime(),
|
|
1046
|
+
os: import_zod39.z.string(),
|
|
1047
|
+
architecture: import_zod39.z.string(),
|
|
1048
|
+
environment: import_zod39.z.string()
|
|
963
1049
|
})
|
|
964
1050
|
);
|
|
965
1051
|
|
|
966
1052
|
// packages/fly-node/src/lib/fly.class.ts
|
|
1053
|
+
var TRANSIENT_FLY_ERRORS = [
|
|
1054
|
+
{ cause: "no capacity available", pattern: /no capacity available/i },
|
|
1055
|
+
{ cause: "builder deadline exceeded", pattern: /deadline_exceeded/i },
|
|
1056
|
+
{
|
|
1057
|
+
cause: "timed out connecting to machine",
|
|
1058
|
+
pattern: /timed out connecting to machine/i
|
|
1059
|
+
},
|
|
1060
|
+
// The status text, not a bare 503: an app whose health check answers
|
|
1061
|
+
// 503 is broken, not unlucky, and must not be deployed three times
|
|
1062
|
+
{ cause: "Fly API 503", pattern: /503 Service Unavailable/i }
|
|
1063
|
+
];
|
|
1064
|
+
var TRANSIENT_RETRY_DELAYS_MS = [1e4, 3e4];
|
|
967
1065
|
var MACHINE_STATE_INTERVAL_MS = 2e3;
|
|
968
1066
|
var MACHINE_STATE_TIMEOUT_MS = 12e4;
|
|
969
1067
|
var Fly = class {
|
|
@@ -1049,7 +1147,9 @@ ${error}`);
|
|
|
1049
1147
|
return await this.version();
|
|
1050
1148
|
} catch (error) {
|
|
1051
1149
|
throw new Error(`[version] something broke
|
|
1052
|
-
${error}
|
|
1150
|
+
${error}`, {
|
|
1151
|
+
cause: error
|
|
1152
|
+
});
|
|
1053
1153
|
}
|
|
1054
1154
|
}
|
|
1055
1155
|
};
|
|
@@ -1076,7 +1176,8 @@ ${error}`);
|
|
|
1076
1176
|
} catch (error) {
|
|
1077
1177
|
throw new Error(
|
|
1078
1178
|
`[create app] something broke, check your apps
|
|
1079
|
-
${error}
|
|
1179
|
+
${error}`,
|
|
1180
|
+
{ cause: error }
|
|
1080
1181
|
);
|
|
1081
1182
|
}
|
|
1082
1183
|
},
|
|
@@ -1102,7 +1203,8 @@ ${error}`
|
|
|
1102
1203
|
} catch (error) {
|
|
1103
1204
|
throw new Error(
|
|
1104
1205
|
`[destroy app] something broke, check your apps
|
|
1105
|
-
${error}
|
|
1206
|
+
${error}`,
|
|
1207
|
+
{ cause: error }
|
|
1106
1208
|
);
|
|
1107
1209
|
}
|
|
1108
1210
|
},
|
|
@@ -1117,7 +1219,7 @@ ${error}`
|
|
|
1117
1219
|
return await this.fetchAllApps("throwOnError");
|
|
1118
1220
|
} catch (error) {
|
|
1119
1221
|
throw new Error(`[list] something broke
|
|
1120
|
-
${error}
|
|
1222
|
+
${error}`, { cause: error });
|
|
1121
1223
|
}
|
|
1122
1224
|
}
|
|
1123
1225
|
};
|
|
@@ -1142,7 +1244,8 @@ ${error}`);
|
|
|
1142
1244
|
} catch (error) {
|
|
1143
1245
|
throw new Error(
|
|
1144
1246
|
`[add certificate] something broke, check your app certificates
|
|
1145
|
-
${error}
|
|
1247
|
+
${error}`,
|
|
1248
|
+
{ cause: error }
|
|
1146
1249
|
);
|
|
1147
1250
|
}
|
|
1148
1251
|
},
|
|
@@ -1160,7 +1263,9 @@ ${error}`
|
|
|
1160
1263
|
return result;
|
|
1161
1264
|
} catch (error) {
|
|
1162
1265
|
throw new Error(`[list certificates] something broke
|
|
1163
|
-
${error}
|
|
1266
|
+
${error}`, {
|
|
1267
|
+
cause: error
|
|
1268
|
+
});
|
|
1164
1269
|
}
|
|
1165
1270
|
},
|
|
1166
1271
|
/**
|
|
@@ -1180,7 +1285,8 @@ ${error}`);
|
|
|
1180
1285
|
} catch (error) {
|
|
1181
1286
|
throw new Error(
|
|
1182
1287
|
`[remove certificate] something broke, check your app certificates
|
|
1183
|
-
${error}
|
|
1288
|
+
${error}`,
|
|
1289
|
+
{ cause: error }
|
|
1184
1290
|
);
|
|
1185
1291
|
}
|
|
1186
1292
|
}
|
|
@@ -1207,7 +1313,9 @@ ${error}`
|
|
|
1207
1313
|
);
|
|
1208
1314
|
} catch (error) {
|
|
1209
1315
|
throw new Error(`[save config] something broke
|
|
1210
|
-
${error}
|
|
1316
|
+
${error}`, {
|
|
1317
|
+
cause: error
|
|
1318
|
+
});
|
|
1211
1319
|
}
|
|
1212
1320
|
},
|
|
1213
1321
|
/**
|
|
@@ -1223,7 +1331,9 @@ ${error}`);
|
|
|
1223
1331
|
return await this.showConfig("throwOnError", options);
|
|
1224
1332
|
} catch (error) {
|
|
1225
1333
|
throw new Error(`[show config] something broke
|
|
1226
|
-
${error}
|
|
1334
|
+
${error}`, {
|
|
1335
|
+
cause: error
|
|
1336
|
+
});
|
|
1227
1337
|
}
|
|
1228
1338
|
}
|
|
1229
1339
|
};
|
|
@@ -1266,7 +1376,7 @@ ${error}`);
|
|
|
1266
1376
|
}
|
|
1267
1377
|
const { appName } = await this.deployApp(options);
|
|
1268
1378
|
this.logger.info(`Application '${appName}' was deployed`);
|
|
1269
|
-
const status = await this.
|
|
1379
|
+
const status = await this.fetchAppLookup("throwOnError", {
|
|
1270
1380
|
app: appName
|
|
1271
1381
|
});
|
|
1272
1382
|
return DeployResponseSchema.parse({
|
|
@@ -1277,7 +1387,8 @@ ${error}`);
|
|
|
1277
1387
|
} catch (error) {
|
|
1278
1388
|
throw new Error(
|
|
1279
1389
|
`[deploy] something broke, check your ${isBuildOnly ? "builds" : "deployments"}
|
|
1280
|
-
${error}
|
|
1390
|
+
${error}`,
|
|
1391
|
+
{ cause: error }
|
|
1281
1392
|
);
|
|
1282
1393
|
}
|
|
1283
1394
|
};
|
|
@@ -1298,7 +1409,9 @@ ${error}`
|
|
|
1298
1409
|
return await this.fetchAppIps("throwOnError", options);
|
|
1299
1410
|
} catch (error) {
|
|
1300
1411
|
throw new Error(`[list ips] something broke
|
|
1301
|
-
${error}
|
|
1412
|
+
${error}`, {
|
|
1413
|
+
cause: error
|
|
1414
|
+
});
|
|
1302
1415
|
}
|
|
1303
1416
|
},
|
|
1304
1417
|
/**
|
|
@@ -1308,7 +1421,8 @@ ${error}`);
|
|
|
1308
1421
|
* safe on every deploy rather than only on create. That matters because
|
|
1309
1422
|
* `flyctl` allocates addresses only for an app it creates itself — an app
|
|
1310
1423
|
* that arrives any other way, such as a registry push auto-creating it,
|
|
1311
|
-
* deploys green and answers nothing.
|
|
1424
|
+
* deploys green and answers nothing. `deploy` runs it before every
|
|
1425
|
+
* deploy that is not build-only.
|
|
1312
1426
|
*
|
|
1313
1427
|
* @param options - The application, and which addresses to ensure
|
|
1314
1428
|
* @returns The addresses the application holds afterwards
|
|
@@ -1320,19 +1434,23 @@ ${error}`);
|
|
|
1320
1434
|
const { sharedV4 = true, v6 = true } = options ?? {};
|
|
1321
1435
|
const existing = await this.fetchAppIps("throwOnError", options);
|
|
1322
1436
|
const has = (...types) => existing.some((ip) => types.includes(ip.type));
|
|
1437
|
+
let allocated = false;
|
|
1323
1438
|
if (sharedV4 && !has("v4", "shared_v4")) {
|
|
1324
1439
|
await this.allocateIp("allocate-v4", options);
|
|
1325
1440
|
this.logger.info("Allocated a shared IPv4 address");
|
|
1441
|
+
allocated = true;
|
|
1326
1442
|
}
|
|
1327
1443
|
if (v6 && !has("v6")) {
|
|
1328
1444
|
await this.allocateIp("allocate-v6", options);
|
|
1329
1445
|
this.logger.info("Allocated a dedicated IPv6 address");
|
|
1446
|
+
allocated = true;
|
|
1330
1447
|
}
|
|
1331
|
-
return await this.fetchAppIps("throwOnError", options);
|
|
1448
|
+
return allocated ? await this.fetchAppIps("throwOnError", options) : existing;
|
|
1332
1449
|
} catch (error) {
|
|
1333
1450
|
throw new Error(
|
|
1334
1451
|
`[ensure ips] something broke, check your app addresses
|
|
1335
|
-
${error}
|
|
1452
|
+
${error}`,
|
|
1453
|
+
{ cause: error }
|
|
1336
1454
|
);
|
|
1337
1455
|
}
|
|
1338
1456
|
}
|
|
@@ -1355,7 +1473,9 @@ ${error}`
|
|
|
1355
1473
|
this.logger.info(`Machine '${machineId}' in app '${app}' was started`);
|
|
1356
1474
|
} catch (error) {
|
|
1357
1475
|
throw new Error(`[start machine] something broke
|
|
1358
|
-
${error}
|
|
1476
|
+
${error}`, {
|
|
1477
|
+
cause: error
|
|
1478
|
+
});
|
|
1359
1479
|
}
|
|
1360
1480
|
},
|
|
1361
1481
|
/**
|
|
@@ -1372,7 +1492,9 @@ ${error}`);
|
|
|
1372
1492
|
this.logger.info(`Machine '${machineId}' in app '${app}' was stopped`);
|
|
1373
1493
|
} catch (error) {
|
|
1374
1494
|
throw new Error(`[stop machine] something broke
|
|
1375
|
-
${error}
|
|
1495
|
+
${error}`, {
|
|
1496
|
+
cause: error
|
|
1497
|
+
});
|
|
1376
1498
|
}
|
|
1377
1499
|
},
|
|
1378
1500
|
/**
|
|
@@ -1395,7 +1517,9 @@ ${error}`);
|
|
|
1395
1517
|
);
|
|
1396
1518
|
} catch (error) {
|
|
1397
1519
|
throw new Error(`[restart machine] something broke
|
|
1398
|
-
${error}
|
|
1520
|
+
${error}`, {
|
|
1521
|
+
cause: error
|
|
1522
|
+
});
|
|
1399
1523
|
}
|
|
1400
1524
|
},
|
|
1401
1525
|
/**
|
|
@@ -1416,7 +1540,9 @@ ${error}`);
|
|
|
1416
1540
|
this.logger.info(`Machine '${machineId}' in app '${app}' was updated`);
|
|
1417
1541
|
} catch (error) {
|
|
1418
1542
|
throw new Error(`[update machine] something broke
|
|
1419
|
-
${error}
|
|
1543
|
+
${error}`, {
|
|
1544
|
+
cause: error
|
|
1545
|
+
});
|
|
1420
1546
|
}
|
|
1421
1547
|
}
|
|
1422
1548
|
};
|
|
@@ -1450,7 +1576,9 @@ ${error}`);
|
|
|
1450
1576
|
return await this.sshExec(app, command);
|
|
1451
1577
|
} catch (error) {
|
|
1452
1578
|
throw new Error(`[ssh exec] something broke
|
|
1453
|
-
${error}
|
|
1579
|
+
${error}`, {
|
|
1580
|
+
cause: error
|
|
1581
|
+
});
|
|
1454
1582
|
}
|
|
1455
1583
|
}
|
|
1456
1584
|
};
|
|
@@ -1476,7 +1604,8 @@ ${error}`);
|
|
|
1476
1604
|
} catch (error) {
|
|
1477
1605
|
throw new Error(
|
|
1478
1606
|
`[set secrets] something broke, check your app secrets
|
|
1479
|
-
${error}
|
|
1607
|
+
${error}`,
|
|
1608
|
+
{ cause: error }
|
|
1480
1609
|
);
|
|
1481
1610
|
}
|
|
1482
1611
|
},
|
|
@@ -1499,7 +1628,9 @@ ${error}`
|
|
|
1499
1628
|
this.logger.info(`Staged secrets were deployed for '${app}'`);
|
|
1500
1629
|
} catch (error) {
|
|
1501
1630
|
throw new Error(`[deploy secrets] something broke
|
|
1502
|
-
${error}
|
|
1631
|
+
${error}`, {
|
|
1632
|
+
cause: error
|
|
1633
|
+
});
|
|
1503
1634
|
}
|
|
1504
1635
|
},
|
|
1505
1636
|
/**
|
|
@@ -1516,7 +1647,9 @@ ${error}`);
|
|
|
1516
1647
|
return result;
|
|
1517
1648
|
} catch (error) {
|
|
1518
1649
|
throw new Error(`[list secrets] something broke
|
|
1519
|
-
${error}
|
|
1650
|
+
${error}`, {
|
|
1651
|
+
cause: error
|
|
1652
|
+
});
|
|
1520
1653
|
}
|
|
1521
1654
|
},
|
|
1522
1655
|
/**
|
|
@@ -1537,7 +1670,8 @@ ${error}`);
|
|
|
1537
1670
|
} catch (error) {
|
|
1538
1671
|
throw new Error(
|
|
1539
1672
|
`[unset secrets] something broke, check your app secrets
|
|
1540
|
-
${error}
|
|
1673
|
+
${error}`,
|
|
1674
|
+
{ cause: error }
|
|
1541
1675
|
);
|
|
1542
1676
|
}
|
|
1543
1677
|
}
|
|
@@ -1650,7 +1784,7 @@ ${error}`);
|
|
|
1650
1784
|
lookupApp = appConfig.app;
|
|
1651
1785
|
}
|
|
1652
1786
|
if (lookupApp) {
|
|
1653
|
-
const status = await this.
|
|
1787
|
+
const status = await this.fetchAppLookup("nullOnError", {
|
|
1654
1788
|
app: lookupApp
|
|
1655
1789
|
});
|
|
1656
1790
|
if (status) {
|
|
@@ -1752,6 +1886,10 @@ ${error}`);
|
|
|
1752
1886
|
);
|
|
1753
1887
|
}
|
|
1754
1888
|
}
|
|
1889
|
+
const servesTraffic = !!appConfig.httpService || (appConfig.services?.length ?? 0) > 0;
|
|
1890
|
+
if (!options?.buildOnly && servesTraffic) {
|
|
1891
|
+
await this.ips.ensure({ app: appName });
|
|
1892
|
+
}
|
|
1755
1893
|
const args = ["deploy", "--app", appName, "--config", deployConfig];
|
|
1756
1894
|
if (options?.region) {
|
|
1757
1895
|
args.push("--region", options.region);
|
|
@@ -1778,10 +1916,10 @@ ${error}`);
|
|
|
1778
1916
|
this.logger.info(
|
|
1779
1917
|
options?.buildOnly ? `Building image for '${appName}'...` : `Deploying '${appName}'...`
|
|
1780
1918
|
);
|
|
1781
|
-
const output = await this.execFly(
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
);
|
|
1919
|
+
const output = await this.execFly(args, {
|
|
1920
|
+
streamStrategy: options?.buildOnly ? "combined" : "stdout",
|
|
1921
|
+
retry: true
|
|
1922
|
+
});
|
|
1785
1923
|
const imageRef = options?.buildOnly ? output?.match(/registry\.fly\.io\/\S+/)?.[0] : void 0;
|
|
1786
1924
|
return { appName, imageRef };
|
|
1787
1925
|
}
|
|
@@ -1827,7 +1965,7 @@ ${error}`);
|
|
|
1827
1965
|
* @throws An error if the secrets cannot be set
|
|
1828
1966
|
*/
|
|
1829
1967
|
async setAppSecrets(secrets, options) {
|
|
1830
|
-
const status = await this.
|
|
1968
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1831
1969
|
const args = ["secrets", "set"];
|
|
1832
1970
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1833
1971
|
if (options?.stage) {
|
|
@@ -1836,7 +1974,7 @@ ${error}`);
|
|
|
1836
1974
|
for (const [key, value] of Object.entries(secrets)) {
|
|
1837
1975
|
args.push(`${key}=${this.safeArg(value)}`);
|
|
1838
1976
|
}
|
|
1839
|
-
await this.execFly(args);
|
|
1977
|
+
await this.execFly(args, { retry: options?.stage === true });
|
|
1840
1978
|
return NameSchema.parse(status.name);
|
|
1841
1979
|
}
|
|
1842
1980
|
/**
|
|
@@ -1845,7 +1983,7 @@ ${error}`);
|
|
|
1845
1983
|
* @throws An error if the secrets cannot be unset
|
|
1846
1984
|
*/
|
|
1847
1985
|
async unsetAppSecrets(keys, options) {
|
|
1848
|
-
const status = await this.
|
|
1986
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1849
1987
|
const args = ["secrets", "unset"];
|
|
1850
1988
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1851
1989
|
if (options?.stage) {
|
|
@@ -1861,7 +1999,7 @@ ${error}`);
|
|
|
1861
1999
|
* @throws An error if the domain cannot be added
|
|
1862
2000
|
*/
|
|
1863
2001
|
async addAppCertificate(hostname, options) {
|
|
1864
|
-
const status = await this.
|
|
2002
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1865
2003
|
const args = ["certs", "add", hostname];
|
|
1866
2004
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1867
2005
|
args.push("--json");
|
|
@@ -1898,7 +2036,7 @@ ${error}`);
|
|
|
1898
2036
|
args.push("--json");
|
|
1899
2037
|
try {
|
|
1900
2038
|
return await IpsListTransformedResponseSchema.parseAsync(
|
|
1901
|
-
await this.execFly(args)
|
|
2039
|
+
await this.execFly(args, { retry: true })
|
|
1902
2040
|
);
|
|
1903
2041
|
} catch (error) {
|
|
1904
2042
|
if (onError === "throwOnError") {
|
|
@@ -1913,7 +2051,7 @@ ${error}`);
|
|
|
1913
2051
|
* @throws An error if the domain cannot be removed
|
|
1914
2052
|
*/
|
|
1915
2053
|
async removeAppCertificate(hostname, options) {
|
|
1916
|
-
const status = await this.
|
|
2054
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1917
2055
|
const args = ["certs", "remove", hostname];
|
|
1918
2056
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1919
2057
|
args.push("--yes");
|
|
@@ -1988,7 +2126,7 @@ ${error}`);
|
|
|
1988
2126
|
async waitForMachineState(app, machineId, states) {
|
|
1989
2127
|
const deadline = Date.now() + MACHINE_STATE_TIMEOUT_MS;
|
|
1990
2128
|
while (Date.now() < deadline) {
|
|
1991
|
-
const status = await this.
|
|
2129
|
+
const status = await this.fetchAppLookup("nullOnError", { app });
|
|
1992
2130
|
const machine = status?.machines.find(({ id }) => id === machineId);
|
|
1993
2131
|
if (machine && states.includes(machine.state)) {
|
|
1994
2132
|
return;
|
|
@@ -2095,7 +2233,28 @@ ${error}`);
|
|
|
2095
2233
|
if (onError === "throwOnError") {
|
|
2096
2234
|
throw error;
|
|
2097
2235
|
}
|
|
2098
|
-
if (error instanceof
|
|
2236
|
+
if (error instanceof import_zod40.ZodError) {
|
|
2237
|
+
this.logger.info(`Failed to parse response:
|
|
2238
|
+
${error.message}`);
|
|
2239
|
+
this.logger.info(`Raw response:
|
|
2240
|
+
${JSON.stringify(response, null, 2)}`);
|
|
2241
|
+
}
|
|
2242
|
+
return null;
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
async fetchAppLookup(onError, options) {
|
|
2246
|
+
const args = ["status"];
|
|
2247
|
+
args.push(...this.getAppOrConfigArgs(options));
|
|
2248
|
+
args.push("--json");
|
|
2249
|
+
let response = null;
|
|
2250
|
+
try {
|
|
2251
|
+
response = await this.execFly(args);
|
|
2252
|
+
return statusLookupSchema.parse(response);
|
|
2253
|
+
} catch (error) {
|
|
2254
|
+
if (onError === "throwOnError") {
|
|
2255
|
+
throw error;
|
|
2256
|
+
}
|
|
2257
|
+
if (error instanceof import_zod40.ZodError) {
|
|
2099
2258
|
this.logger.info(`Failed to parse response:
|
|
2100
2259
|
${error.message}`);
|
|
2101
2260
|
this.logger.info(`Raw response:
|
|
@@ -2231,33 +2390,32 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
2231
2390
|
}
|
|
2232
2391
|
const flyCmd = "flyctl";
|
|
2233
2392
|
const toLogCmd = `${flyCmd} ${args.join(" ")}`;
|
|
2393
|
+
const { retry = false, ...execOpts } = options ?? {};
|
|
2234
2394
|
let output = "";
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
const
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
${errorMsg}`);
|
|
2395
|
+
for (let attempt = 1; ; attempt++) {
|
|
2396
|
+
try {
|
|
2397
|
+
output = await this.spawnFly(flyCmd, args, toLogCmd, execOpts);
|
|
2398
|
+
break;
|
|
2399
|
+
} catch (error) {
|
|
2400
|
+
const errorMsg = error.message;
|
|
2401
|
+
this.traceCLI("RESULT", errorMsg);
|
|
2402
|
+
const cause = retry ? this.transientCause(error) : null;
|
|
2403
|
+
const delay = TRANSIENT_RETRY_DELAYS_MS[attempt - 1];
|
|
2404
|
+
if (cause && delay !== void 0) {
|
|
2405
|
+
this.logger.info(
|
|
2406
|
+
`Transient Fly error (${cause}), retrying in ${delay / 1e3}s (attempt ${attempt + 1} of ${TRANSIENT_RETRY_DELAYS_MS.length + 1}): ${toLogCmd}`
|
|
2407
|
+
);
|
|
2408
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2409
|
+
continue;
|
|
2410
|
+
}
|
|
2411
|
+
if (onError === "throwOnError") {
|
|
2412
|
+
throw new Error(`Command failed: ${toLogCmd}
|
|
2413
|
+
${errorMsg}`, {
|
|
2414
|
+
cause: error
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
return null;
|
|
2259
2418
|
}
|
|
2260
|
-
return null;
|
|
2261
2419
|
}
|
|
2262
2420
|
try {
|
|
2263
2421
|
return JSON.parse(output);
|
|
@@ -2271,6 +2429,55 @@ ${errorMsg}`);
|
|
|
2271
2429
|
}
|
|
2272
2430
|
return void 0;
|
|
2273
2431
|
}
|
|
2432
|
+
/**
|
|
2433
|
+
* @private
|
|
2434
|
+
* Run one fly command and assemble its output
|
|
2435
|
+
*
|
|
2436
|
+
* @returns The output selected by `streamStrategy`
|
|
2437
|
+
* @throws An error if the command fails
|
|
2438
|
+
*/
|
|
2439
|
+
async spawnFly(flyCmd, args, toLogCmd, options) {
|
|
2440
|
+
this.traceCLI("CALL", toLogCmd);
|
|
2441
|
+
if (options.prompt) {
|
|
2442
|
+
const output = await spawnPty(flyCmd, args, { prompt: options.prompt });
|
|
2443
|
+
this.traceCLI("RESULT", output);
|
|
2444
|
+
return output;
|
|
2445
|
+
}
|
|
2446
|
+
const { streamStrategy = "stdout", ...spawnOpts } = options;
|
|
2447
|
+
const result = await spawn(flyCmd, args, {
|
|
2448
|
+
...spawnOpts,
|
|
2449
|
+
streamToConsole: this.logger.streamToConsole
|
|
2450
|
+
});
|
|
2451
|
+
const stdout = result.stdout.trim();
|
|
2452
|
+
const stderr = result.stderr.trim();
|
|
2453
|
+
this.traceCLI("RESULT", `${stdout}${stderr ? `
|
|
2454
|
+
${stderr}` : ""}`);
|
|
2455
|
+
return streamStrategy === "combined" ? `${stdout}
|
|
2456
|
+
${stderr}` : streamStrategy === "stderr" ? stderr : stdout;
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* @private
|
|
2460
|
+
* Name the transient Fly error behind a failed command, if it was one.
|
|
2461
|
+
*
|
|
2462
|
+
* Only the error flyctl ended with counts: from its last `Error` line to
|
|
2463
|
+
* the end of stderr, or the last few lines when there is none. A deploy
|
|
2464
|
+
* streams the app's own output and errors flyctl recovered from, and
|
|
2465
|
+
* matching those would repeat a deploy that failed for a real reason.
|
|
2466
|
+
*
|
|
2467
|
+
* @returns The cause, or `null` when the failure is not a known transient one
|
|
2468
|
+
*/
|
|
2469
|
+
transientCause(error) {
|
|
2470
|
+
let text;
|
|
2471
|
+
if (error instanceof SpawnError) {
|
|
2472
|
+
const lines = error.stderr.split(/\r?\n/).filter((line) => line.trim());
|
|
2473
|
+
const errorLines = lines.map((line) => /^\s*Error\b/.test(line));
|
|
2474
|
+
const last = errorLines.lastIndexOf(true);
|
|
2475
|
+
text = lines.slice(last >= 0 ? last : -3).join("\n");
|
|
2476
|
+
} else {
|
|
2477
|
+
text = String(error?.message ?? error);
|
|
2478
|
+
}
|
|
2479
|
+
return TRANSIENT_FLY_ERRORS.find(({ pattern }) => pattern.test(text))?.cause ?? null;
|
|
2480
|
+
}
|
|
2274
2481
|
/**
|
|
2275
2482
|
* @private
|
|
2276
2483
|
* Get the arguments for `AppOrConfig` options
|
|
@@ -2419,6 +2626,8 @@ ${errorMsg}`);
|
|
|
2419
2626
|
};
|
|
2420
2627
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2421
2628
|
0 && (module.exports = {
|
|
2629
|
+
AppIpAddressSchema,
|
|
2630
|
+
AppIpAddressesApiResponseSchema,
|
|
2422
2631
|
CertificateApiResponseSchema,
|
|
2423
2632
|
CertificateListApiResponseSchema,
|
|
2424
2633
|
DnsInstructionsSchema,
|