@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdwr/fly-node",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "The flyctl node wrapper for programmatic deployments to fly.io.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "type": "module",
27
27
  "dependencies": {
28
- "zod": "^3.23.8"
28
+ "zod": "^4.6.7"
29
29
  },
30
30
  "devDependencies": {
31
31
  "dotenv": "^16.4.7",
package/src/api.d.ts CHANGED
@@ -11,5 +11,6 @@
11
11
  * `fetch` does.
12
12
  */
13
13
  export { FlyApi, FlyApiError, type FlyApiConfig } from './lib/fly-api.class';
14
+ export { type AppIpAddress, AppIpAddressesApiResponseSchema, AppIpAddressSchema } from './lib/schemas/app-ip-addresses.schema';
14
15
  export { type Certificate, CertificateApiResponseSchema, CertificateListApiResponseSchema, type DnsInstructions, DnsInstructionsSchema, type HostnameCheck, HostnameCheckApiResponseSchema } from './lib/schemas/certificate.schema';
15
16
  export { type Machine, MachineApiResponseSchema, MachineListApiResponseSchema } from './lib/schemas/machine.schema';
@@ -1,3 +1,4 @@
1
+ import { type AppIpAddress } from './schemas/app-ip-addresses.schema';
1
2
  import { type Certificate, type DnsInstructions, type HostnameCheck } from './schemas/certificate.schema';
2
3
  import { type Machine } from './schemas/machine.schema';
3
4
  export type FlyApiConfig = {
@@ -51,7 +52,8 @@ export declare class FlyApiError extends Error {
51
52
  * itself at runtime. It is deliberately a small subset rather than a second
52
53
  * implementation of the whole CLI: certificates, because a custom domain has to
53
54
  * be requested, checked and shown to a customer while they wait, and machine
54
- * restarts, because a setting read at boot needs a boot to take effect.
55
+ * restarts, because a setting read at boot needs a boot to take effect. And
56
+ * addresses, because an apex domain points A and AAAA records at them.
55
57
  *
56
58
  * Fly splits those across two APIs and so does this class — certificates over
57
59
  * GraphQL, machines over the REST Machines API. One token authenticates both.
@@ -135,6 +137,24 @@ export declare class FlyApi {
135
137
  */
136
138
  remove: (app: string, hostname: string) => Promise<void>;
137
139
  };
140
+ /** Read an app's addresses */
141
+ ips: {
142
+ /**
143
+ * The addresses an app answers on: `shared_v4`, `v4`, `v6`, and its
144
+ * `private_v6`.
145
+ *
146
+ * The shared v4 is folded in as a `shared_v4` row, the way `fly ips list`
147
+ * shows it; Fly's API keeps it in a separate field. Egress addresses,
148
+ * which the CLI also lists, are not part of this API and never appear.
149
+ * Pick the public types before pointing DNS at them.
150
+ *
151
+ * Rejects for an unknown app, like `certs.list`: a typo in an app name
152
+ * must not read as "this app has no addresses".
153
+ *
154
+ * @returns The addresses, empty when the app has none
155
+ */
156
+ list: (app: string) => Promise<Array<AppIpAddress>>;
157
+ };
138
158
  /**
139
159
  * Operate an app's machines.
140
160
  *
@@ -9,6 +9,12 @@ export type ExecFlyOptions = SpawnOptions & SpawnPtyOptions & {
9
9
  * may appear in either stream (e.g. `fly deploy --build-only`)
10
10
  */
11
11
  streamStrategy?: 'stdout' | 'stderr' | 'combined';
12
+ /**
13
+ * Run the command again when it fails on a transient Fly error
14
+ * (see `TRANSIENT_FLY_ERRORS`). Only for commands that are safe to repeat:
15
+ * a command that may have taken effect before it failed must not set this.
16
+ */
17
+ retry?: boolean;
12
18
  };
13
19
  /**
14
20
  * Manages deployments to Fly.io using the `flyctl` CLI tool.
@@ -178,7 +184,8 @@ export declare class Fly {
178
184
  * safe on every deploy rather than only on create. That matters because
179
185
  * `flyctl` allocates addresses only for an app it creates itself — an app
180
186
  * that arrives any other way, such as a registry push auto-creating it,
181
- * deploys green and answers nothing.
187
+ * deploys green and answers nothing. `deploy` runs it before every
188
+ * deploy that is not build-only.
182
189
  *
183
190
  * @param options - The application, and which addresses to ensure
184
191
  * @returns The addresses the application holds afterwards
@@ -478,6 +485,16 @@ export declare class Fly {
478
485
  * @throws An error if the app cannot be found and `throwOnError` is used
479
486
  */
480
487
  private fetchAppStatus;
488
+ /**
489
+ * @private
490
+ * Like `fetchAppStatus`, but only requires what a lookup needs (name,
491
+ * hostname and each machine's id and state), so a machine Fly reports
492
+ * mid-update does not fail it.
493
+ *
494
+ * @returns The app lookup or `null` if the app cannot be found and `nullOnError` is used
495
+ * @throws An error if the app cannot be found and `throwOnError` is used
496
+ */
497
+ private fetchAppLookup;
481
498
  /**
482
499
  * @private
483
500
  * @returns The certificates for an app or `null` if the certificates cannot be retrieved and `nullOnError` is used
@@ -535,6 +552,26 @@ export declare class Fly {
535
552
  * @throws An error if the command fails
536
553
  */
537
554
  private execFly;
555
+ /**
556
+ * @private
557
+ * Run one fly command and assemble its output
558
+ *
559
+ * @returns The output selected by `streamStrategy`
560
+ * @throws An error if the command fails
561
+ */
562
+ private spawnFly;
563
+ /**
564
+ * @private
565
+ * Name the transient Fly error behind a failed command, if it was one.
566
+ *
567
+ * Only the error flyctl ended with counts: from its last `Error` line to
568
+ * the end of stderr, or the last few lines when there is none. A deploy
569
+ * streams the app's own output and errors flyctl recovered from, and
570
+ * matching those would repeat a deploy that failed for a real reason.
571
+ *
572
+ * @returns The cause, or `null` when the failure is not a known transient one
573
+ */
574
+ private transientCause;
538
575
  /**
539
576
  * @private
540
577
  * Get the arguments for `AppOrConfig` options
@@ -93,6 +93,68 @@ export declare const mockShowConfigResponse: (app?: string) => {
93
93
  * @param app - The app name to use in the response (defaults to `mockDefs.testApp`)
94
94
  */
95
95
  export declare const mockStatusResponse: (app?: string) => StatusResponse;
96
+ /**
97
+ * Mock `fly status --json` response where one of two machines is reported
98
+ * mid-update, without `image_ref`, `config` and `events`.
99
+ *
100
+ * @param app - The app name to use in the response (defaults to `mockDefs.testApp`)
101
+ */
102
+ export declare const mockPartialStatusResponse: (app?: string) => {
103
+ hostname: string;
104
+ id: string;
105
+ name: string;
106
+ machines: ({
107
+ id: string;
108
+ name: string;
109
+ state: string;
110
+ region: string;
111
+ imageRef: {
112
+ registry: string;
113
+ repository: string;
114
+ tag: string;
115
+ digest: string;
116
+ labels?: Record<string, string> | undefined;
117
+ };
118
+ createdAt: string;
119
+ updatedAt: string;
120
+ config: {
121
+ env: Record<string, string>;
122
+ metadata: Record<string, string>;
123
+ guest?: {
124
+ cpu_kind?: string | undefined;
125
+ cpus?: number | undefined;
126
+ memory_mb?: number | undefined;
127
+ } | undefined;
128
+ };
129
+ events: {
130
+ type: string;
131
+ status: string;
132
+ timestamp: number;
133
+ }[];
134
+ hostStatus: string;
135
+ checks?: {
136
+ name: string;
137
+ status: string;
138
+ output: string;
139
+ updatedAt: string;
140
+ }[] | undefined;
141
+ } | {
142
+ id: string;
143
+ name: string;
144
+ state: string;
145
+ region: string;
146
+ createdAt: string;
147
+ updatedAt: string;
148
+ hostStatus: string;
149
+ })[];
150
+ deployed: boolean;
151
+ organization: {
152
+ id: string;
153
+ slug: string;
154
+ };
155
+ status: string;
156
+ version: number;
157
+ };
96
158
  /**
97
159
  * Mock `fly version` response for testing.
98
160
  */
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * One address an app holds, in the shape `fly ips list` reports it.
4
+ *
5
+ * Only `address` and `type`: a shared v4 carries no id, region or creation
6
+ * time, and a caller pointing DNS at an app needs nothing else.
7
+ */
8
+ export declare const AppIpAddressSchema: z.ZodObject<{
9
+ address: z.ZodString;
10
+ type: z.ZodUnion<[z.ZodEnum<{
11
+ v4: "v4";
12
+ v6: "v6";
13
+ shared_v4: "shared_v4";
14
+ private_v6: "private_v6";
15
+ }>, z.ZodString]>;
16
+ }, z.core.$strip>;
17
+ export type AppIpAddress = z.infer<typeof AppIpAddressSchema>;
18
+ /**
19
+ * An app's addresses as the Fly GraphQL API returns them.
20
+ *
21
+ * Fly keeps the shared v4 apart from the rest: `sharedIpAddress` is a plain
22
+ * string, null when the app has none, and never appears in `ipAddresses`.
23
+ * A dedicated v4 does appear there, with type `v4`.
24
+ */
25
+ export declare const AppIpAddressesApiResponseSchema: z.ZodObject<{
26
+ sharedIpAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
27
+ ipAddresses: z.ZodObject<{
28
+ nodes: z.ZodArray<z.ZodObject<{
29
+ address: z.ZodString;
30
+ type: z.ZodUnion<[z.ZodEnum<{
31
+ v4: "v4";
32
+ v6: "v6";
33
+ shared_v4: "shared_v4";
34
+ private_v6: "private_v6";
35
+ }>, z.ZodString]>;
36
+ }, z.core.$strip>>;
37
+ }, z.core.$strip>;
38
+ }, z.core.$strip>;
@@ -6,16 +6,7 @@ import { z } from 'zod';
6
6
  * fly apps create --app [name] --json
7
7
  * ```
8
8
  */
9
- export declare const AppsCreateTransformedResponseSchema: z.ZodEffects<z.ZodObject<{
9
+ export declare const AppsCreateTransformedResponseSchema: z.ZodPreprocess<z.ZodObject<{
10
10
  id: z.ZodString;
11
11
  name: z.ZodString;
12
- }, "strip", z.ZodTypeAny, {
13
- id: string;
14
- name: string;
15
- }, {
16
- id: string;
17
- name: string;
18
- }>, {
19
- id: string;
20
- name: string;
21
- }, unknown>;
12
+ }, z.core.$strip>, unknown>;
@@ -6,7 +6,7 @@ import { z } from 'zod';
6
6
  * fly apps list --json
7
7
  * ```
8
8
  */
9
- export declare const AppsListTransformedResponseSchema: z.ZodArray<z.ZodEffects<z.ZodObject<{
9
+ export declare const AppsListTransformedResponseSchema: z.ZodArray<z.ZodPreprocess<z.ZodObject<{
10
10
  id: z.ZodString;
11
11
  name: z.ZodString;
12
12
  status: z.ZodString;
@@ -15,63 +15,9 @@ export declare const AppsListTransformedResponseSchema: z.ZodArray<z.ZodEffects<
15
15
  organization: z.ZodObject<{
16
16
  name: z.ZodString;
17
17
  slug: z.ZodString;
18
- }, "strip", z.ZodTypeAny, {
19
- name: string;
20
- slug: string;
21
- }, {
22
- name: string;
23
- slug: string;
24
- }>;
18
+ }, z.core.$strip>;
25
19
  currentRelease: z.ZodNullable<z.ZodObject<{
26
20
  status: z.ZodString;
27
21
  createdAt: z.ZodString;
28
- }, "strip", z.ZodTypeAny, {
29
- createdAt: string;
30
- status: string;
31
- }, {
32
- createdAt: string;
33
- status: string;
34
- }>>;
35
- }, "strip", z.ZodTypeAny, {
36
- hostname: string;
37
- id: string;
38
- status: string;
39
- name: string;
40
- deployed: boolean;
41
- organization: {
42
- name: string;
43
- slug: string;
44
- };
45
- currentRelease: {
46
- createdAt: string;
47
- status: string;
48
- } | null;
49
- }, {
50
- hostname: string;
51
- id: string;
52
- status: string;
53
- name: string;
54
- deployed: boolean;
55
- organization: {
56
- name: string;
57
- slug: string;
58
- };
59
- currentRelease: {
60
- createdAt: string;
61
- status: string;
62
- } | null;
63
- }>, {
64
- hostname: string;
65
- id: string;
66
- status: string;
67
- name: string;
68
- deployed: boolean;
69
- organization: {
70
- name: string;
71
- slug: string;
72
- };
73
- currentRelease: {
74
- createdAt: string;
75
- status: string;
76
- } | null;
77
- }, unknown>, "many">;
22
+ }, z.core.$strip>>;
23
+ }, z.core.$strip>, unknown>>;
@@ -2,10 +2,4 @@ import { z } from 'zod';
2
2
  export declare const BuildResponseSchema: z.ZodObject<{
3
3
  appName: z.ZodString;
4
4
  imageRef: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
6
- appName: string;
7
- imageRef: string;
8
- }, {
9
- appName: string;
10
- imageRef: string;
11
- }>;
5
+ }, z.core.$strip>;