@cdwr/fly-node 0.2.3 โ†’ 0.3.1

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 CHANGED
@@ -1,3 +1,62 @@
1
+ ## 0.3.1 (2026-08-25)
2
+
3
+ ### โœจ Features
4
+
5
+ - **app-cms:** show the certificates Fly issued for a domain ([c7983c5d](https://github.com/codeware-sthlm/cdwr/commit/c7983c5d))
6
+ - **fly-node:** restart app machines over the rest api ([3367b887](https://github.com/codeware-sthlm/cdwr/commit/3367b887))
7
+ - **fly-node:** expose the graphql client as its own entry point ([52db8c26](https://github.com/codeware-sthlm/cdwr/commit/52db8c26))
8
+ - **fly-node:** manage certificates over the graphql api ([15c0b89c](https://github.com/codeware-sthlm/cdwr/commit/15c0b89c))
9
+ - **fly-node:** add ssh exec to run commands in a machine ([ba3ee3c6](https://github.com/codeware-sthlm/cdwr/commit/ba3ee3c6))
10
+ - **fly-node:** add build response schema and export missing types ([73ce64e8](https://github.com/codeware-sthlm/cdwr/commit/73ce64e8))
11
+ - **fly-node:** add machine management methods ([dbdf0f54](https://github.com/codeware-sthlm/cdwr/commit/dbdf0f54))
12
+ - **repo:** shared preview database ([f48d959e](https://github.com/codeware-sthlm/cdwr/commit/f48d959e))
13
+ - **fly-node:** add option to stream to console ([1bb02e33](https://github.com/codeware-sthlm/cdwr/commit/1bb02e33))
14
+ - **fly-node:** support build arguments in deploy command ([dfa1736a](https://github.com/codeware-sthlm/cdwr/commit/dfa1736a))
15
+
16
+ ### ๐Ÿž Bug Fixes
17
+
18
+ - **app-cms:** show fly's own prose for a failed certificate check ([3c047d0c](https://github.com/codeware-sthlm/cdwr/commit/3c047d0c))
19
+ - **fly-node:** match config save to fly's real api ([6af2597c](https://github.com/codeware-sthlm/cdwr/commit/6af2597c))
20
+ - **fly-node:** pin flyctl to one file ci and local both read ([c18203bf](https://github.com/codeware-sthlm/cdwr/commit/c18203bf))
21
+ - **fly-node:** match certificate check and add to fly's real api ([020b06a8](https://github.com/codeware-sthlm/cdwr/commit/020b06a8))
22
+ - **fly-node:** treat a missing certificate as an answer, not a fault ([75714e87](https://github.com/codeware-sthlm/cdwr/commit/75714e87))
23
+ - **repo:** import defineConfig from vitest/config in test configs ([69a6d471](https://github.com/codeware-sthlm/cdwr/commit/69a6d471))
24
+ - **core:** split vitest-only exports into separate entry point ([489f297a](https://github.com/codeware-sthlm/cdwr/commit/489f297a))
25
+ - **fly-node:** add machines.update for per-machine config updates ([a5498c8e](https://github.com/codeware-sthlm/cdwr/commit/a5498c8e))
26
+
27
+ ### ๐Ÿงน Code Refactoring
28
+
29
+ - **repo:** split @cdwr/core into shared util libs ([797f20d0](https://github.com/codeware-sthlm/cdwr/commit/797f20d0))
30
+
31
+ ### ๐Ÿ“„ Documentation
32
+
33
+ - **fly-node:** document machine restarts in the FlyApi readme ([7030a6ac](https://github.com/codeware-sthlm/cdwr/commit/7030a6ac))
34
+ - **fly-node:** update README with machine methods ([57cfce9c](https://github.com/codeware-sthlm/cdwr/commit/57cfce9c))
35
+
36
+ ### โš™๏ธ Miscellaneous Chores
37
+
38
+ - repoint repo urls to codeware-sthlm/cdwr ([969d3614](https://github.com/codeware-sthlm/cdwr/commit/969d3614))
39
+ - migrate to nx 23.1.0 ([1fd45d5b](https://github.com/codeware-sthlm/cdwr/commit/1fd45d5b))
40
+
41
+ ### โœ… Tests
42
+
43
+ - **fly-node:** cover the graphql client with fixtures and a drift check ([eef458aa](https://github.com/codeware-sthlm/cdwr/commit/eef458aa))
44
+
45
+ ## 0.3.0 (2026-01-02)
46
+
47
+ ### โœจ Features
48
+
49
+ - **fly-node:** redact secrets for trace cli ([d980611](https://github.com/codeware-sthlm/codeware/commit/d980611))
50
+ - **fly-node:** add integration tests and fix mismatched schemas ([a2eb288](https://github.com/codeware-sthlm/codeware/commit/a2eb288))
51
+
52
+ ### ๐Ÿž Bug Fixes
53
+
54
+ - **fly-node:** do not rely on access-token for authentication ([1a46ea0](https://github.com/codeware-sthlm/codeware/commit/1a46ea0))
55
+
56
+ ### ๐Ÿงฑ Updated Dependencies
57
+
58
+ - Updated core to 1.4.4
59
+
1
60
  ## 0.2.3 (2025-12-01)
2
61
 
3
62
  ### ๐Ÿงฑ Updated Dependencies
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Codeware Sthlm AB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -35,6 +35,7 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
35
35
 
36
36
  - [Installation](#installation)
37
37
  - [Usage](#usage)
38
+ - [Authentication](#authentication)
38
39
  - [Create a Fly instance](#create-a-fly-instance)
39
40
  - [Verify that the Fly client is ready](#verify-that-the-fly-client-is-ready)
40
41
  - [Deploying apps \& machines](#deploying-apps--machines)
@@ -43,14 +44,19 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
43
44
  - [Deploy an application](#deploy-an-application)
44
45
  - [Application status](#application-status)
45
46
  - [List applications](#list-applications)
47
+ - [Manage machines](#manage-machines)
46
48
  - [Configuration \& scaling](#configuration--scaling)
47
49
  - [Add a custom domain](#add-a-custom-domain)
48
50
  - [Remove a custom domain](#remove-a-custom-domain)
49
51
  - [List certificates](#list-certificates)
52
+ - [Save application configuration](#save-application-configuration)
50
53
  - [Show application configuration](#show-application-configuration)
51
54
  - [Add application secrets](#add-application-secrets)
52
55
  - [Remove application secrets](#remove-application-secrets)
53
56
  - [List secrets](#list-secrets)
57
+ - [Without the CLI: `FlyApi`](#without-the-cli-flyapi)
58
+ - [Manage certificates](#manage-certificates)
59
+ - [Restart machines](#restart-machines)
54
60
 
55
61
  ## Installation
56
62
 
@@ -58,14 +64,25 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
58
64
  npm install @cdwr/fly-node
59
65
  ```
60
66
 
61
- ### Fly CLI <!-- omit in toc -->
67
+ ### Fly CLI Requirements <!-- omit in toc -->
62
68
 
63
69
  > [!IMPORTANT]
64
- > It's required to have the Fly CLI installed to use this library.
70
+ > This library requires the Fly CLI (`flyctl`) to be installed and accessible in your PATH.
65
71
 
66
- Instructions to [install manually](https://github.com/superfly/flyctl?tab=readme-ov-file#installation).
72
+ **Version used in test**: see [`verified-version.json`](./verified-version.json) โ€” the same file CI installs from, so the two cannot drift apart.
67
73
 
68
- For using in GitHub actions it's best to use the [action](https://github.com/superfly/flyctl-actions) provided by the Fly CLI project.
74
+ **Installation Instructions**:
75
+
76
+ - **macOS**: `brew install flyctl`
77
+ - **Linux/WSL**: `curl -L https://fly.io/install.sh | sh`
78
+ - **Windows**: `pwsh -Command "iwr https://fly.io/install.ps1 -useb | iex"`
79
+ - **Manual Installation**: See [official docs](https://github.com/superfly/flyctl?tab=readme-ov-file#installation)
80
+
81
+ **Verify Installation**:
82
+
83
+ ```sh
84
+ flyctl version
85
+ ```
69
86
 
70
87
  ## Usage
71
88
 
@@ -73,21 +90,40 @@ The library behaves just like the Fly CLI tool regarding all default values.
73
90
 
74
91
  For any command you run, your local `flyctl` installation will be verified. If it's not present, the command will abort with exception.
75
92
 
76
- ### Create a Fly instance
93
+ > [!TIP]
94
+ > Instead of `flyctl` you can also use `fly` if preferred.
95
+
96
+ ### Authentication
97
+
98
+ Supported authentication methods to Fly.io in order:
99
+
100
+ 1. authenticate locally via `flyctl auth login`
101
+ 2. provide a token when creating the Fly instance
102
+ 3. set access token environment variable `FLY_ACCESS_TOKEN`
103
+ 4. set API token environment variable `FLY_API_TOKEN`
104
+
105
+ > [!NOTE]
106
+ > See [Fly Docs about security tokens](https://fly.io/docs/security/tokens/) for more details.
77
107
 
78
- Fly will try to connect to Fly.io in the following order:
108
+ **Flaky `--access-token` flag**
79
109
 
80
- 1. A user has already authenticated locally using `flyctl auth login`
81
- 2. The library authenticates using the provided Fly API `token`
82
- 3. The library authenticates using environment variable `FLY_API_TOKEN`
110
+ From version **0.3.210** the access token flag has a regression, reported in <https://github.com/superfly/flyctl/issues/4648>.
111
+
112
+ > [!IMPORTANT]
113
+ > To avoid pinning a previous version, this library no longer relies on the `--access-token` flag.
114
+ > When a token is provided to the Fly instance, the library will set `FLY_ACCESS_TOKEN` internally.
115
+ >
116
+ > This legitimate workaround might change depending on how the Fly team responds to the issue. The intention is to handle this internally without affecting the library api.
117
+
118
+ ### Create a Fly instance
83
119
 
84
120
  ```ts
85
121
  import { Fly } from '@cdwr/fly-node';
86
122
 
87
123
  const fly = new Fly();
88
124
 
89
- // Provide a Fly API token
90
- const fly = new Fly({ token: 'fly-api-token' });
125
+ // Provide a Fly token
126
+ const fly = new Fly({ token: 'my-fly-token' });
91
127
  ```
92
128
 
93
129
  > [!TIP]
@@ -121,7 +157,7 @@ const fly = new Fly({ token: 'fly-api-token' });
121
157
 
122
158
  | Name | Description |
123
159
  | ----------------- | ------------------------------------------------------------------------------------------------------------------------------- |
124
- | `token` | Fly API access token. |
160
+ | `token` | Fly access token, when none of `FLY_ACCESS_TOKEN` or `FLY_API_TOKEN` is provided. |
125
161
  | `app` or `config` | Name of the application or the path to the fly configuration file to run all commands on. |
126
162
  | `org` | Target organisation for your created apps. Defaults to your personal organisation. |
127
163
  | `region` | Target region for your deployed apps. Defaults to auto-detect the fastest location. |
@@ -148,6 +184,12 @@ Use this command to check if the Fly CLI is installed.
148
184
  const isInstalled = await fly.cli.isInstalled(); // true or false
149
185
  ```
150
186
 
187
+ This command gets the installed Fly CLI version.
188
+
189
+ ```ts
190
+ const { version } = await fly.cli.version();
191
+ ```
192
+
151
193
  ### Deploying apps & machines
152
194
 
153
195
  #### Create an application
@@ -158,13 +200,13 @@ This will create an application which is not deployed yet. You can add secrets,
158
200
  > Creating an application is not necessary before deploying, the library will do it for you.
159
201
 
160
202
  ```ts
161
- const name = await fly.apps.create(); // 'some-app-name-123'
203
+ await fly.apps.create(); // name: 'some-app-name-123'
162
204
 
163
205
  // Create application 'foo-app' in the instance organisation
164
- const name = await fly.apps.create({ app: 'foo-app' });
206
+ await fly.apps.create({ app: 'foo-app' });
165
207
 
166
208
  // Create application 'bar-app' in organisation 'baz'
167
- const name = await fly.apps.create({ app: 'bar-app', org: 'baz' });
209
+ await fly.apps.create({ app: 'bar-app', org: 'baz' });
168
210
  ```
169
211
 
170
212
  #### Destroy an application
@@ -176,9 +218,6 @@ This will destroy the application completely.
176
218
 
177
219
  ```ts
178
220
  await fly.apps.destroy('foo-app');
179
-
180
- // Force destroy 'foo-app'
181
- await fly.apps.destroy('foo-app', { force: true });
182
221
  ```
183
222
 
184
223
  #### Deploy an application
@@ -214,6 +253,28 @@ const response = await fly.deploy({
214
253
  optOutDepotBuilder: true
215
254
  });
216
255
 
256
+ // Use remote config for existing apps (useful to prevent overriding ad-hoc configurations)
257
+ const response = await fly.deploy({
258
+ app: 'tenant-foo-app',
259
+ config: 'apps/foo-app/fly.toml',
260
+ preferRemoteConfig: true
261
+ });
262
+ // For existing apps: saves remote config to fly.{appName}.toml and uses it
263
+ // For new apps: uses the local config file
264
+
265
+ // Deploy with existing image (skips build, useful for config-only updates)
266
+ const response = await fly.deploy({
267
+ app: 'foo-app',
268
+ config: 'apps/foo-app/fly.toml',
269
+ image: 'registry.fly.io/foo-app:deployment-01234567'
270
+ });
271
+ // Or use just the tag (will be expanded to full registry path)
272
+ const response = await fly.deploy({
273
+ app: 'foo-app',
274
+ config: 'apps/foo-app/fly.toml',
275
+ image: 'deployment-01234567'
276
+ });
277
+
217
278
  // With options that could be a pull request preview deployment
218
279
  const response = await fly.deploy({
219
280
  app: 'pr-19-foo-app',
@@ -222,6 +283,9 @@ const response = await fly.deploy({
222
283
  org: 'baz',
223
284
  postgres: 'db-preview',
224
285
  region: 'arn',
286
+ buildArgs: {
287
+ NEXT_PUBLIC_DEPLOY_ENV: 'preview'
288
+ },
225
289
  env: {
226
290
  DEPLOY_ID: 'qwerty'
227
291
  },
@@ -289,6 +353,21 @@ const status = await fly.statusExtended();
289
353
  const apps = await fly.apps.list();
290
354
  ```
291
355
 
356
+ #### Manage machines
357
+
358
+ Control individual machines within your applications.
359
+
360
+ ```ts
361
+ // Start a machine
362
+ await fly.machines.start('foo-app', 'machine-id-123');
363
+
364
+ // Stop a machine
365
+ await fly.machines.stop('foo-app', 'machine-id-123');
366
+
367
+ // Restart a machine (stop then start with delay)
368
+ await fly.machines.restart('foo-app', 'machine-id-123');
369
+ ```
370
+
292
371
  ### Configuration & scaling
293
372
 
294
373
  #### Add a custom domain
@@ -354,6 +433,18 @@ const certs = await fly.certs.list('all');
354
433
  // ]
355
434
  ```
356
435
 
436
+ #### Save application configuration
437
+
438
+ Save an application's remote configuration from Fly.io to a local TOML file. This is useful for backing up configurations or using remote configs for existing apps in deployments.
439
+
440
+ ```ts
441
+ // Save 'foo-app' remote config to local file
442
+ await fly.config.save({
443
+ app: 'foo-app',
444
+ config: 'apps/foo-app/fly.remote.toml'
445
+ });
446
+ ```
447
+
357
448
  #### Show application configuration
358
449
 
359
450
  The configuration is always fetched from Fly.io remote configuration, but you can also fetch the local configuration file.
@@ -420,29 +511,95 @@ const secrets = await fly.secrets.list();
420
511
  // List secrets for 'foo-app'
421
512
  const secrets = await fly.secrets.list({ app: 'foo-app' });
422
513
  const secrets = await fly.secrets.list({ config: 'apps/foo-app/fly.toml' });
514
+ ```
423
515
 
424
- // [
425
- // {
426
- // createdAt: '2024-01-01T00:00:00.000Z',
427
- // digest: '1234567890',
428
- // name: 'FOO',
429
- // },
430
- // ...
431
- // ]
516
+ ## Without the CLI: `FlyApi`
432
517
 
433
- // List secrets for all your applications
434
- const secrets = await fly.secrets.list('all');
518
+ `Fly` drives the `flyctl` binary. That is the right tool in CI โ€” it builds and
519
+ deploys, and a runner has the binary installed โ€” but it cannot run inside an
520
+ application server: there is no binary in the image, and the interactive paths
521
+ need a pty.
435
522
 
436
- // [
437
- // {
438
- // app: 'foo-app',
439
- // [secret details]
440
- // },
441
- // ...
442
- // {
443
- // app: 'bar-app',
444
- // [secret details]
445
- // },
446
- // ...
447
- // ]
523
+ `FlyApi` talks to Fly over its HTTP APIs instead. No binary, no subprocess,
524
+ usable from a running app. It is deliberately a small subset rather than a
525
+ second implementation of the CLI โ€” certificates, because a custom domain has
526
+ to be requested, checked and shown to a customer while they wait, and machine
527
+ restarts, because a setting read at boot needs a boot to take effect.
528
+
529
+ It has its own entry point, `@cdwr/fly-node/api`. Import from there rather than
530
+ the root barrel when the CLI half cannot come along: the root barrel reaches a
531
+ native pty module, which a slim application image does not have.
532
+
533
+ Fly splits the two operations across two APIs and so does `FlyApi` โ€”
534
+ certificates over GraphQL, machines over the REST Machines API. One token
535
+ authenticates both.
536
+
537
+ ### Manage certificates
538
+
539
+ ```ts
540
+ import { FlyApi } from '@cdwr/fly-node/api';
541
+
542
+ const fly = new FlyApi({ token: process.env.FLY_API_TOKEN });
543
+
544
+ // Request a certificate. Safe to call again โ€” Fly returns the existing one.
545
+ const { certificate, check } = await fly.certs.add('my-app', 'tours.example.com');
546
+
547
+ if (!certificate.isConfigured) {
548
+ // What the customer has to create, and what Fly resolves right now
549
+ console.log(FlyApi.dnsInstructions(certificate));
550
+ console.log(check?.dnsConfigured, check?.cnameRecords);
551
+ }
552
+
553
+ // Re-read issuance state โ€” the call behind a "check" button
554
+ await fly.certs.get('my-app', 'tours.example.com');
555
+
556
+ await fly.certs.list('my-app');
557
+ await fly.certs.remove('my-app', 'tours.example.com');
558
+ ```
559
+
560
+ Notes worth knowing:
561
+
562
+ - **Field names are Fly's own** (`isConfigured`, not `configured`), so results
563
+ can be read against Fly's schema without translating. Where the CLI covers
564
+ the same ground the shared fields agree.
565
+ - **Requesting before DNS exists is normal.** The certificate stays pending
566
+ until the records resolve; the validation fields are what you show meanwhile.
567
+ - **`rateLimitedUntil`** is set when Let's Encrypt has throttled further
568
+ attempts. It is the one failure correcting DNS will not fix, and retrying
569
+ makes it worse.
570
+ - **`list` does not resolve DNS.** `check` is only returned by `add`, because
571
+ resolving across every certificate on an app would turn one query into a
572
+ lookup per domain.
573
+ - **A hostname with no certificate is not an error.** Fly reports it as a
574
+ `NOT_FOUND` GraphQL error; `certs.get` translates that to `null`. Anything else
575
+ rejects with a `FlyApiError` carrying the codes Fly sent.
576
+
577
+ ### Restart machines
578
+
579
+ ```ts
580
+ import { FlyApi } from '@cdwr/fly-node/api';
581
+
582
+ const fly = new FlyApi({ token: process.env.FLY_API_TOKEN });
583
+
584
+ await fly.machines.list('my-app');
585
+
586
+ // Restart every machine on the app, one at a time
587
+ await fly.machines.restart('my-app');
588
+
589
+ // Or just one
590
+ await fly.machines.restart('my-app', 'e286000a123456');
448
591
  ```
592
+
593
+ Notes worth knowing:
594
+
595
+ - **Restarts are sequential, not parallel.** A setting that only takes effect
596
+ at boot should not cost the app its availability to apply โ€” restarting
597
+ together would drop every machine at once. The trade is that a large app
598
+ takes longer.
599
+ - **A failed restart stops the run.** It does not skip ahead to the next
600
+ machine: a half-restarted app is running two configurations at once, and
601
+ silently returning "some of them" invites calling that done.
602
+ - **This is the REST Machines API, not GraphQL.** Fly's GraphQL machine
603
+ mutations are Nomad-era and no longer apply, so this half of `FlyApi` has its
604
+ own request helper with its own failure shape โ€” a non-2xx status and an
605
+ `error` field in the body, rather than GraphQL's 200-with-an-`errors`-array.