@cdwr/fly-node 0.3.6 → 0.3.7

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,9 @@
1
+ ## 0.3.7 (2026-11-26)
2
+
3
+ ### ✨ Features
4
+
5
+ - **fly-node:** apps.destroy can allow a failed postgres detach ([1ff50a98](https://github.com/codeware-sthlm/codeware/commit/1ff50a98))
6
+
1
7
  ## 0.3.6 (2026-11-23)
2
8
 
3
9
  ### 🐞 Bug Fixes
package/README.md CHANGED
@@ -220,6 +220,15 @@ This will destroy the application completely.
220
220
  await fly.apps.destroy('foo-app');
221
221
  ```
222
222
 
223
+ A failed detach throws and leaves the application in place. Pass `allowDetachFailure` to destroy it anyway. Each failed detach is logged and returned, and a failed destroy still throws.
224
+
225
+ ```ts
226
+ const { detachFailures } = await fly.apps.destroy('foo-app', {
227
+ allowDetachFailure: true
228
+ });
229
+ // [{ cluster: 'pg-cluster', error: '...' }]
230
+ ```
231
+
223
232
  #### Deploy an application
224
233
 
225
234
  > [!IMPORTANT]
package/index.cjs CHANGED
@@ -1194,21 +1194,37 @@ ${error}`,
1194
1194
  * Destroy an application and make sure it gets detached from any Postgres clusters
1195
1195
  *
1196
1196
  * @param app - The name of the app to destroy
1197
- * @throws An error if the app cannot be destroyed
1197
+ * @param options - Options for destroying an application
1198
+ * @returns The Postgres clusters that could not be detached, when `allowDetachFailure` is set
1199
+ * @throws An error if the app cannot be destroyed, or a cluster cannot be detached without `allowDetachFailure`
1198
1200
  */
1199
- destroy: async (app) => {
1201
+ destroy: async (app, options) => {
1200
1202
  try {
1201
1203
  await this.ensureInitialized();
1204
+ const detachFailures = [];
1202
1205
  const attachedClusters = await this.getAttachedPostgresClusters(app);
1203
1206
  for (const cluster of attachedClusters) {
1204
1207
  this.logger.info(
1205
1208
  `Detaching Postgres cluster '${cluster}' from application '${app}'`
1206
1209
  );
1207
- const output = await this.detachPostgres(cluster, app);
1208
- this.logger.info(output);
1210
+ try {
1211
+ const output = await this.detachPostgres(cluster, app);
1212
+ this.logger.info(output);
1213
+ } catch (error) {
1214
+ if (!options?.allowDetachFailure) {
1215
+ throw error;
1216
+ }
1217
+ const message = error instanceof Error ? error.message : String(error);
1218
+ this.logger.info(
1219
+ `Failed to detach Postgres cluster '${cluster}' from application '${app}', destroying it anyway
1220
+ ${message}`
1221
+ );
1222
+ detachFailures.push({ cluster, error: message });
1223
+ }
1209
1224
  }
1210
1225
  await this.destroyApp(app);
1211
1226
  this.logger.info(`Application '${app}' was destroyed`);
1227
+ return { detachFailures };
1212
1228
  } catch (error) {
1213
1229
  throw new Error(
1214
1230
  `[destroy app] something broke, check your apps
package/index.js CHANGED
@@ -1150,21 +1150,37 @@ ${error}`,
1150
1150
  * Destroy an application and make sure it gets detached from any Postgres clusters
1151
1151
  *
1152
1152
  * @param app - The name of the app to destroy
1153
- * @throws An error if the app cannot be destroyed
1153
+ * @param options - Options for destroying an application
1154
+ * @returns The Postgres clusters that could not be detached, when `allowDetachFailure` is set
1155
+ * @throws An error if the app cannot be destroyed, or a cluster cannot be detached without `allowDetachFailure`
1154
1156
  */
1155
- destroy: async (app) => {
1157
+ destroy: async (app, options) => {
1156
1158
  try {
1157
1159
  await this.ensureInitialized();
1160
+ const detachFailures = [];
1158
1161
  const attachedClusters = await this.getAttachedPostgresClusters(app);
1159
1162
  for (const cluster of attachedClusters) {
1160
1163
  this.logger.info(
1161
1164
  `Detaching Postgres cluster '${cluster}' from application '${app}'`
1162
1165
  );
1163
- const output = await this.detachPostgres(cluster, app);
1164
- this.logger.info(output);
1166
+ try {
1167
+ const output = await this.detachPostgres(cluster, app);
1168
+ this.logger.info(output);
1169
+ } catch (error) {
1170
+ if (!options?.allowDetachFailure) {
1171
+ throw error;
1172
+ }
1173
+ const message = error instanceof Error ? error.message : String(error);
1174
+ this.logger.info(
1175
+ `Failed to detach Postgres cluster '${cluster}' from application '${app}', destroying it anyway
1176
+ ${message}`
1177
+ );
1178
+ detachFailures.push({ cluster, error: message });
1179
+ }
1165
1180
  }
1166
1181
  await this.destroyApp(app);
1167
1182
  this.logger.info(`Application '${app}' was destroyed`);
1183
+ return { detachFailures };
1168
1184
  } catch (error) {
1169
1185
  throw new Error(
1170
1186
  `[destroy app] something broke, check your apps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdwr/fly-node",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "The flyctl node wrapper for programmatic deployments to fly.io.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from './api';
2
2
  export * from './lib/fly.class';
3
- export type { AllocateIpOptions, BuildResponse, Config, DeployAppOptions, DeployResponse, ListIpResponse, MachineOperationOptions, SaveConfigOptions, StatusResponse } from './lib/types';
3
+ export type { AllocateIpOptions, BuildResponse, Config, DeployAppOptions, DeployResponse, DestroyAppOptions, DestroyAppResponse, ListIpResponse, MachineOperationOptions, SaveConfigOptions, StatusResponse } from './lib/types';
@@ -1,5 +1,5 @@
1
1
  import { SpawnOptions, SpawnPtyOptions } from '@codeware/shared/util/misc';
2
- import type { AllocateIpOptions, AppOrConfig, BuildResponse, Config, CreateAppOptions, CreateAppResponse, DeployAppOptions, DeployResponse, ListAppResponse, ListCertForAllResponse, ListCertForAppResponse, ListIpResponse, ListSecretForAllResponse, ListSecretForAppResponse, SaveConfigOptions, SetAppSecretsOptions, ShowConfigOptions, ShowConfigResponse, StatusExtendedResponse, StatusResponse, UnsetAppSecretsOptions, VersionResponse } from './types';
2
+ import type { AllocateIpOptions, AppOrConfig, BuildResponse, Config, CreateAppOptions, CreateAppResponse, DeployAppOptions, DeployResponse, DestroyAppOptions, DestroyAppResponse, ListAppResponse, ListCertForAllResponse, ListCertForAppResponse, ListIpResponse, ListSecretForAllResponse, ListSecretForAppResponse, SaveConfigOptions, SetAppSecretsOptions, ShowConfigOptions, ShowConfigResponse, StatusExtendedResponse, StatusResponse, UnsetAppSecretsOptions, VersionResponse } from './types';
3
3
  export type ExecFlyOptions = SpawnOptions & SpawnPtyOptions & {
4
4
  /**
5
5
  * How to assemble the returned output string from the spawned process.
@@ -79,9 +79,11 @@ export declare class Fly {
79
79
  * Destroy an application and make sure it gets detached from any Postgres clusters
80
80
  *
81
81
  * @param app - The name of the app to destroy
82
- * @throws An error if the app cannot be destroyed
82
+ * @param options - Options for destroying an application
83
+ * @returns The Postgres clusters that could not be detached, when `allowDetachFailure` is set
84
+ * @throws An error if the app cannot be destroyed, or a cluster cannot be detached without `allowDetachFailure`
83
85
  */
84
- destroy: (app: string) => Promise<void>;
86
+ destroy: (app: string, options?: DestroyAppOptions) => Promise<DestroyAppResponse>;
85
87
  /**
86
88
  * List all applications
87
89
  *
@@ -135,6 +135,34 @@ export type CreateAppOptions = {
135
135
  */
136
136
  org?: string;
137
137
  };
138
+ /**
139
+ * Options for destroying an application
140
+ */
141
+ export type DestroyAppOptions = {
142
+ /**
143
+ * Destroy the application even when detaching it from a Postgres cluster fails.
144
+ *
145
+ * Each failed detach is logged and returned in `detachFailures`.
146
+ * A failed destroy still throws.
147
+ *
148
+ * @default false
149
+ */
150
+ allowDetachFailure?: boolean;
151
+ };
152
+ /**
153
+ * Result of destroying an application
154
+ */
155
+ export type DestroyAppResponse = {
156
+ /**
157
+ * Postgres clusters that could not be detached before the application was destroyed.
158
+ *
159
+ * Always empty unless `allowDetachFailure` is set, since a failed detach throws.
160
+ */
161
+ detachFailures: Array<{
162
+ cluster: string;
163
+ error: string;
164
+ }>;
165
+ };
138
166
  /**
139
167
  * Options for deploying an application
140
168
  */