@cdwr/fly-node 0.3.0 โ 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 +44 -0
- package/LICENSE +21 -0
- package/README.md +127 -1
- package/api.cjs +517 -0
- package/api.js +483 -0
- package/index.cjs +1002 -190
- package/index.js +992 -188
- package/package.json +7 -2
- package/src/api.d.ts +15 -0
- package/src/index.d.ts +2 -1
- package/src/lib/fly-api.class.d.ts +193 -0
- package/src/lib/fly.class.d.ts +166 -11
- package/src/lib/schemas/apps-create.schema.d.ts +3 -3
- package/src/lib/schemas/apps-list.schema.d.ts +14 -14
- package/src/lib/schemas/build-response.schema.d.ts +11 -0
- package/src/lib/schemas/certificate.schema.d.ts +392 -0
- package/src/lib/schemas/machine.schema.d.ts +44 -0
- package/src/lib/schemas/postgres-list.d.ts +9 -9
- package/src/lib/schemas/status-extended.schema.d.ts +123 -21
- package/src/lib/schemas/status.schema.d.ts +229 -37
- package/src/lib/types.d.ts +86 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
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
|
+
|
|
1
45
|
## 0.3.0 (2026-01-02)
|
|
2
46
|
|
|
3
47
|
### โจ Features
|
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
|
@@ -44,6 +44,7 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
|
|
|
44
44
|
- [Deploy an application](#deploy-an-application)
|
|
45
45
|
- [Application status](#application-status)
|
|
46
46
|
- [List applications](#list-applications)
|
|
47
|
+
- [Manage machines](#manage-machines)
|
|
47
48
|
- [Configuration \& scaling](#configuration--scaling)
|
|
48
49
|
- [Add a custom domain](#add-a-custom-domain)
|
|
49
50
|
- [Remove a custom domain](#remove-a-custom-domain)
|
|
@@ -53,6 +54,9 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
|
|
|
53
54
|
- [Add application secrets](#add-application-secrets)
|
|
54
55
|
- [Remove application secrets](#remove-application-secrets)
|
|
55
56
|
- [List secrets](#list-secrets)
|
|
57
|
+
- [Without the CLI: `FlyApi`](#without-the-cli-flyapi)
|
|
58
|
+
- [Manage certificates](#manage-certificates)
|
|
59
|
+
- [Restart machines](#restart-machines)
|
|
56
60
|
|
|
57
61
|
## Installation
|
|
58
62
|
|
|
@@ -65,7 +69,7 @@ npm install @cdwr/fly-node
|
|
|
65
69
|
> [!IMPORTANT]
|
|
66
70
|
> This library requires the Fly CLI (`flyctl`) to be installed and accessible in your PATH.
|
|
67
71
|
|
|
68
|
-
**Version used in test**:
|
|
72
|
+
**Version used in test**: see [`verified-version.json`](./verified-version.json) โ the same file CI installs from, so the two cannot drift apart.
|
|
69
73
|
|
|
70
74
|
**Installation Instructions**:
|
|
71
75
|
|
|
@@ -258,6 +262,19 @@ const response = await fly.deploy({
|
|
|
258
262
|
// For existing apps: saves remote config to fly.{appName}.toml and uses it
|
|
259
263
|
// For new apps: uses the local config file
|
|
260
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
|
+
|
|
261
278
|
// With options that could be a pull request preview deployment
|
|
262
279
|
const response = await fly.deploy({
|
|
263
280
|
app: 'pr-19-foo-app',
|
|
@@ -266,6 +283,9 @@ const response = await fly.deploy({
|
|
|
266
283
|
org: 'baz',
|
|
267
284
|
postgres: 'db-preview',
|
|
268
285
|
region: 'arn',
|
|
286
|
+
buildArgs: {
|
|
287
|
+
NEXT_PUBLIC_DEPLOY_ENV: 'preview'
|
|
288
|
+
},
|
|
269
289
|
env: {
|
|
270
290
|
DEPLOY_ID: 'qwerty'
|
|
271
291
|
},
|
|
@@ -333,6 +353,21 @@ const status = await fly.statusExtended();
|
|
|
333
353
|
const apps = await fly.apps.list();
|
|
334
354
|
```
|
|
335
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
|
+
|
|
336
371
|
### Configuration & scaling
|
|
337
372
|
|
|
338
373
|
#### Add a custom domain
|
|
@@ -477,3 +512,94 @@ const secrets = await fly.secrets.list();
|
|
|
477
512
|
const secrets = await fly.secrets.list({ app: 'foo-app' });
|
|
478
513
|
const secrets = await fly.secrets.list({ config: 'apps/foo-app/fly.toml' });
|
|
479
514
|
```
|
|
515
|
+
|
|
516
|
+
## Without the CLI: `FlyApi`
|
|
517
|
+
|
|
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.
|
|
522
|
+
|
|
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');
|
|
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.
|