@cdwr/fly-node 0.2.2 → 0.3.0

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,24 @@
1
+ ## 0.3.0 (2026-01-02)
2
+
3
+ ### ✨ Features
4
+
5
+ - **fly-node:** redact secrets for trace cli ([d980611](https://github.com/codeware-sthlm/codeware/commit/d980611))
6
+ - **fly-node:** add integration tests and fix mismatched schemas ([a2eb288](https://github.com/codeware-sthlm/codeware/commit/a2eb288))
7
+
8
+ ### 🐞 Bug Fixes
9
+
10
+ - **fly-node:** do not rely on access-token for authentication ([1a46ea0](https://github.com/codeware-sthlm/codeware/commit/1a46ea0))
11
+
12
+ ### 🧱 Updated Dependencies
13
+
14
+ - Updated core to 1.4.4
15
+
16
+ ## 0.2.3 (2025-12-01)
17
+
18
+ ### 🧱 Updated Dependencies
19
+
20
+ - Updated core to 1.4.3
21
+
1
22
  ## 0.2.2 (2025-10-03)
2
23
 
3
24
  ### ⚙️ Miscellaneous Chores
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)
@@ -47,6 +48,7 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
47
48
  - [Add a custom domain](#add-a-custom-domain)
48
49
  - [Remove a custom domain](#remove-a-custom-domain)
49
50
  - [List certificates](#list-certificates)
51
+ - [Save application configuration](#save-application-configuration)
50
52
  - [Show application configuration](#show-application-configuration)
51
53
  - [Add application secrets](#add-application-secrets)
52
54
  - [Remove application secrets](#remove-application-secrets)
@@ -58,14 +60,25 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
58
60
  npm install @cdwr/fly-node
59
61
  ```
60
62
 
61
- ### Fly CLI <!-- omit in toc -->
63
+ ### Fly CLI Requirements <!-- omit in toc -->
62
64
 
63
65
  > [!IMPORTANT]
64
- > It's required to have the Fly CLI installed to use this library.
66
+ > This library requires the Fly CLI (`flyctl`) to be installed and accessible in your PATH.
65
67
 
66
- Instructions to [install manually](https://github.com/superfly/flyctl?tab=readme-ov-file#installation).
68
+ **Version used in test**: v0.4.0
67
69
 
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.
70
+ **Installation Instructions**:
71
+
72
+ - **macOS**: `brew install flyctl`
73
+ - **Linux/WSL**: `curl -L https://fly.io/install.sh | sh`
74
+ - **Windows**: `pwsh -Command "iwr https://fly.io/install.ps1 -useb | iex"`
75
+ - **Manual Installation**: See [official docs](https://github.com/superfly/flyctl?tab=readme-ov-file#installation)
76
+
77
+ **Verify Installation**:
78
+
79
+ ```sh
80
+ flyctl version
81
+ ```
69
82
 
70
83
  ## Usage
71
84
 
@@ -73,21 +86,40 @@ The library behaves just like the Fly CLI tool regarding all default values.
73
86
 
74
87
  For any command you run, your local `flyctl` installation will be verified. If it's not present, the command will abort with exception.
75
88
 
76
- ### Create a Fly instance
89
+ > [!TIP]
90
+ > Instead of `flyctl` you can also use `fly` if preferred.
91
+
92
+ ### Authentication
77
93
 
78
- Fly will try to connect to Fly.io in the following order:
94
+ Supported authentication methods to Fly.io in order:
79
95
 
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`
96
+ 1. authenticate locally via `flyctl auth login`
97
+ 2. provide a token when creating the Fly instance
98
+ 3. set access token environment variable `FLY_ACCESS_TOKEN`
99
+ 4. set API token environment variable `FLY_API_TOKEN`
100
+
101
+ > [!NOTE]
102
+ > See [Fly Docs about security tokens](https://fly.io/docs/security/tokens/) for more details.
103
+
104
+ **Flaky `--access-token` flag**
105
+
106
+ From version **0.3.210** the access token flag has a regression, reported in <https://github.com/superfly/flyctl/issues/4648>.
107
+
108
+ > [!IMPORTANT]
109
+ > To avoid pinning a previous version, this library no longer relies on the `--access-token` flag.
110
+ > When a token is provided to the Fly instance, the library will set `FLY_ACCESS_TOKEN` internally.
111
+ >
112
+ > 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.
113
+
114
+ ### Create a Fly instance
83
115
 
84
116
  ```ts
85
117
  import { Fly } from '@cdwr/fly-node';
86
118
 
87
119
  const fly = new Fly();
88
120
 
89
- // Provide a Fly API token
90
- const fly = new Fly({ token: 'fly-api-token' });
121
+ // Provide a Fly token
122
+ const fly = new Fly({ token: 'my-fly-token' });
91
123
  ```
92
124
 
93
125
  > [!TIP]
@@ -121,7 +153,7 @@ const fly = new Fly({ token: 'fly-api-token' });
121
153
 
122
154
  | Name | Description |
123
155
  | ----------------- | ------------------------------------------------------------------------------------------------------------------------------- |
124
- | `token` | Fly API access token. |
156
+ | `token` | Fly access token, when none of `FLY_ACCESS_TOKEN` or `FLY_API_TOKEN` is provided. |
125
157
  | `app` or `config` | Name of the application or the path to the fly configuration file to run all commands on. |
126
158
  | `org` | Target organisation for your created apps. Defaults to your personal organisation. |
127
159
  | `region` | Target region for your deployed apps. Defaults to auto-detect the fastest location. |
@@ -148,6 +180,12 @@ Use this command to check if the Fly CLI is installed.
148
180
  const isInstalled = await fly.cli.isInstalled(); // true or false
149
181
  ```
150
182
 
183
+ This command gets the installed Fly CLI version.
184
+
185
+ ```ts
186
+ const { version } = await fly.cli.version();
187
+ ```
188
+
151
189
  ### Deploying apps & machines
152
190
 
153
191
  #### Create an application
@@ -158,13 +196,13 @@ This will create an application which is not deployed yet. You can add secrets,
158
196
  > Creating an application is not necessary before deploying, the library will do it for you.
159
197
 
160
198
  ```ts
161
- const name = await fly.apps.create(); // 'some-app-name-123'
199
+ await fly.apps.create(); // name: 'some-app-name-123'
162
200
 
163
201
  // Create application 'foo-app' in the instance organisation
164
- const name = await fly.apps.create({ app: 'foo-app' });
202
+ await fly.apps.create({ app: 'foo-app' });
165
203
 
166
204
  // Create application 'bar-app' in organisation 'baz'
167
- const name = await fly.apps.create({ app: 'bar-app', org: 'baz' });
205
+ await fly.apps.create({ app: 'bar-app', org: 'baz' });
168
206
  ```
169
207
 
170
208
  #### Destroy an application
@@ -176,9 +214,6 @@ This will destroy the application completely.
176
214
 
177
215
  ```ts
178
216
  await fly.apps.destroy('foo-app');
179
-
180
- // Force destroy 'foo-app'
181
- await fly.apps.destroy('foo-app', { force: true });
182
217
  ```
183
218
 
184
219
  #### Deploy an application
@@ -214,6 +249,15 @@ const response = await fly.deploy({
214
249
  optOutDepotBuilder: true
215
250
  });
216
251
 
252
+ // Use remote config for existing apps (useful to prevent overriding ad-hoc configurations)
253
+ const response = await fly.deploy({
254
+ app: 'tenant-foo-app',
255
+ config: 'apps/foo-app/fly.toml',
256
+ preferRemoteConfig: true
257
+ });
258
+ // For existing apps: saves remote config to fly.{appName}.toml and uses it
259
+ // For new apps: uses the local config file
260
+
217
261
  // With options that could be a pull request preview deployment
218
262
  const response = await fly.deploy({
219
263
  app: 'pr-19-foo-app',
@@ -354,6 +398,18 @@ const certs = await fly.certs.list('all');
354
398
  // ]
355
399
  ```
356
400
 
401
+ #### Save application configuration
402
+
403
+ 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.
404
+
405
+ ```ts
406
+ // Save 'foo-app' remote config to local file
407
+ await fly.config.save({
408
+ app: 'foo-app',
409
+ config: 'apps/foo-app/fly.remote.toml'
410
+ });
411
+ ```
412
+
357
413
  #### Show application configuration
358
414
 
359
415
  The configuration is always fetched from Fly.io remote configuration, but you can also fetch the local configuration file.
@@ -420,29 +476,4 @@ const secrets = await fly.secrets.list();
420
476
  // List secrets for 'foo-app'
421
477
  const secrets = await fly.secrets.list({ app: 'foo-app' });
422
478
  const secrets = await fly.secrets.list({ config: 'apps/foo-app/fly.toml' });
423
-
424
- // [
425
- // {
426
- // createdAt: '2024-01-01T00:00:00.000Z',
427
- // digest: '1234567890',
428
- // name: 'FOO',
429
- // },
430
- // ...
431
- // ]
432
-
433
- // List secrets for all your applications
434
- const secrets = await fly.secrets.list('all');
435
-
436
- // [
437
- // {
438
- // app: 'foo-app',
439
- // [secret details]
440
- // },
441
- // ...
442
- // {
443
- // app: 'bar-app',
444
- // [secret details]
445
- // },
446
- // ...
447
- // ]
448
479
  ```
package/index.cjs CHANGED
@@ -132,7 +132,7 @@ Output: ${output}`)
132
132
  var import_npm_whoami = __toESM(require("npm-whoami"), 1);
133
133
 
134
134
  // packages/fly-node/src/lib/fly.class.ts
135
- var import_zod28 = require("zod");
135
+ var import_zod30 = require("zod");
136
136
 
137
137
  // packages/core/src/lib/zod/json.schema.ts
138
138
  var import_zod = require("zod");
@@ -208,11 +208,7 @@ var import_zod5 = require("zod");
208
208
  var AppsCreateTransformedResponseSchema = withCamelCase(
209
209
  import_zod5.z.object({
210
210
  id: import_zod5.z.string(),
211
- name: import_zod5.z.string(),
212
- organization: import_zod5.z.object({
213
- id: import_zod5.z.string(),
214
- name: import_zod5.z.string()
215
- })
211
+ name: import_zod5.z.string()
216
212
  })
217
213
  );
218
214
 
@@ -314,7 +310,7 @@ var PostgresListTransformedResponseSchema = import_zod17.z.array(
314
310
  version: import_zod17.z.number()
315
311
  })
316
312
  )
317
- );
313
+ ).or(import_zod17.z.string());
318
314
 
319
315
  // packages/fly-node/src/lib/schemas/postgres-users-list.ts
320
316
  var import_zod19 = require("zod");
@@ -335,8 +331,7 @@ var import_zod23 = require("zod");
335
331
  var import_zod21 = require("zod");
336
332
  var SecretsListFlyResponseElementSchema = import_zod21.z.object({
337
333
  name: import_zod21.z.string(),
338
- digest: import_zod21.z.string(),
339
- createdAt: import_zod21.z.string().datetime()
334
+ digest: import_zod21.z.string()
340
335
  });
341
336
  var SecretsListTransformedResponseSchema = import_zod21.z.array(
342
337
  withCamelCase(SecretsListFlyResponseElementSchema)
@@ -417,15 +412,25 @@ var StatusExtendedTransformedResponseSchema = withCamelCase(
417
412
  }
418
413
  );
419
414
 
415
+ // packages/fly-node/src/lib/schemas/version.schema.ts
416
+ var import_zod29 = require("zod");
417
+ var VersionTransformedResponseSchema = withCamelCase(
418
+ import_zod29.z.object({
419
+ name: import_zod29.z.string(),
420
+ version: import_zod29.z.string(),
421
+ commit: import_zod29.z.string(),
422
+ branchName: import_zod29.z.string(),
423
+ buildDate: import_zod29.z.string().datetime(),
424
+ os: import_zod29.z.string(),
425
+ architecture: import_zod29.z.string(),
426
+ environment: import_zod29.z.string()
427
+ })
428
+ );
429
+
420
430
  // packages/fly-node/src/lib/fly.class.ts
421
431
  var Fly = class {
422
432
  /** Use underscore to avoid conflict with public `config` property */
423
433
  _config;
424
- /**
425
- * Whether a user is authenticated via local login.
426
- * In this case a token is not needed, though it can still have been provided.
427
- */
428
- authByLogin = false;
429
434
  initialized = false;
430
435
  logger;
431
436
  /**
@@ -451,10 +456,11 @@ var Fly = class {
451
456
  this.logger = {
452
457
  info: config?.logger?.info || console.log,
453
458
  error: config?.logger?.error || console.error,
454
- traceCLI: config?.logger?.traceCLI || false
459
+ traceCLI: config?.logger?.traceCLI ?? false,
460
+ redactSecrets: config?.logger?.redactSecrets ?? true
455
461
  };
456
- if (!this._config.token) {
457
- this._config.token = process.env["FLY_API_TOKEN"] || "";
462
+ if (this._config.token) {
463
+ process.env["FLY_ACCESS_TOKEN"] = this._config.token;
458
464
  }
459
465
  }
460
466
  /**
@@ -490,7 +496,21 @@ ${error}`);
490
496
  *
491
497
  * @returns `true` if the Fly CLI tool is installed, `false` otherwise
492
498
  */
493
- isInstalled: async () => await this.isInstalled()
499
+ isInstalled: async () => await this.isInstalled(),
500
+ /**
501
+ * Get version information about the installed Fly CLI
502
+ *
503
+ * @returns The installed Fly CLI version information
504
+ * @throws An error if the version cannot be retrieved
505
+ */
506
+ version: async () => {
507
+ try {
508
+ return await this.version();
509
+ } catch (error) {
510
+ throw new Error(`[version] something broke
511
+ ${error}`);
512
+ }
513
+ }
494
514
  };
495
515
  //
496
516
  // External API following the `flyctl` CLI commands structure
@@ -509,9 +529,9 @@ ${error}`);
509
529
  create: async (options) => {
510
530
  try {
511
531
  await this.ensureInitialized();
512
- const { name } = await this.createApp(options);
513
- this.logger.info(`Application '${name}' was created`);
514
- return name;
532
+ const response = await this.createApp(options);
533
+ this.logger.info(`Application '${response.name}' was created`);
534
+ return response;
515
535
  } catch (error) {
516
536
  throw new Error(
517
537
  `[create app] something broke, check your apps
@@ -523,10 +543,9 @@ ${error}`
523
543
  * Destroy an application and make sure it gets detached from any Postgres clusters
524
544
  *
525
545
  * @param app - The name of the app to destroy
526
- * @param options - Options for destroying an application
527
546
  * @throws An error if the app cannot be destroyed
528
547
  */
529
- destroy: async (app, options) => {
548
+ destroy: async (app) => {
530
549
  try {
531
550
  await this.ensureInitialized();
532
551
  const attachedClusters = await this.getAttachedPostgresClusters(app);
@@ -537,7 +556,7 @@ ${error}`
537
556
  const output = await this.detachPostgres(cluster, app);
538
557
  this.logger.info(output);
539
558
  }
540
- await this.destroyApp(app, options?.force);
559
+ await this.destroyApp(app);
541
560
  this.logger.info(`Application '${app}' was destroyed`);
542
561
  } catch (error) {
543
562
  throw new Error(
@@ -629,6 +648,24 @@ ${error}`
629
648
  * Manage an app's configuration
630
649
  */
631
650
  config = {
651
+ /**
652
+ * Save an application's remote configuration locally as TOML file.
653
+ *
654
+ * @param options - Options for saving an application's configuration
655
+ * @throws An error if the configuration cannot be saved
656
+ */
657
+ save: async (options) => {
658
+ try {
659
+ await this.ensureInitialized();
660
+ await this.saveConfig(options);
661
+ this.logger.info(
662
+ `Configuration for '${options.app}' was saved to '${options.config}'`
663
+ );
664
+ } catch (error) {
665
+ throw new Error(`[save config] something broke
666
+ ${error}`);
667
+ }
668
+ },
632
669
  /**
633
670
  * Show an application's configuration.
634
671
  *
@@ -714,7 +751,7 @@ ${error}`
714
751
  }
715
752
  },
716
753
  /**
717
- * List secrets for an application
754
+ * List secrets for an application or all secrets when options is 'all'
718
755
  *
719
756
  * @param options - List secrets for an application or all secrets
720
757
  * @returns A list of secrets
@@ -825,8 +862,9 @@ ${error}`);
825
862
  async deployApp(options) {
826
863
  let appName = "";
827
864
  let appSecrets = [];
865
+ let deployConfig = options?.config || this.instanceConfig;
828
866
  let lookupApp = options?.app || this.instanceApp;
829
- const lookupConfig = options?.config || this.instanceConfig;
867
+ const lookupConfig = deployConfig;
830
868
  if (!lookupConfig) {
831
869
  throw new Error(
832
870
  "Fly config file must be provided to options or class instance, unable to deploy"
@@ -859,6 +897,26 @@ ${error}`);
859
897
  );
860
898
  }
861
899
  }
900
+ if (options?.preferRemoteConfig && appName) {
901
+ const remoteConfigPath = (0, import_path.join)(
902
+ (0, import_path.dirname)(lookupConfig),
903
+ `fly.${appName}.toml`
904
+ );
905
+ try {
906
+ await this.saveConfig({
907
+ app: appName,
908
+ config: remoteConfigPath
909
+ });
910
+ deployConfig = remoteConfigPath;
911
+ this.logger.info(
912
+ `Using remote config for existing app '${appName}' (saved to ${remoteConfigPath})`
913
+ );
914
+ } catch (error) {
915
+ this.logger.info(
916
+ `Failed to save remote config, will use local config: ${error}`
917
+ );
918
+ }
919
+ }
862
920
  if (!appName) {
863
921
  this.logger.info("Creating a new application...");
864
922
  const { name } = await this.createApp({
@@ -919,7 +977,7 @@ ${error}`);
919
977
  await this.attachPostgres(options.postgres, appName);
920
978
  }
921
979
  }
922
- const args = ["deploy", "--app", appName, "--config", lookupConfig];
980
+ const args = ["deploy", "--app", appName, "--config", deployConfig];
923
981
  if (options?.region) {
924
982
  args.push("--region", options.region);
925
983
  }
@@ -949,10 +1007,8 @@ ${error}`);
949
1007
  * @private
950
1008
  * @throws An error if the app cannot be destroyed
951
1009
  */
952
- async destroyApp(app, force) {
1010
+ async destroyApp(app) {
953
1011
  const args = ["apps", "destroy", app, "--yes"];
954
- if (force)
955
- args.push("--force");
956
1012
  await this.execFly(args);
957
1013
  }
958
1014
  /**
@@ -1066,7 +1122,11 @@ ${error}`);
1066
1122
  const args = ["postgres", "list", "--json"];
1067
1123
  try {
1068
1124
  const response = await this.execFly(args);
1069
- return PostgresListTransformedResponseSchema.parse(response);
1125
+ const parsed = PostgresListTransformedResponseSchema.safeParse(response);
1126
+ if (parsed.success) {
1127
+ return Array.isArray(parsed.data) ? parsed.data : [];
1128
+ }
1129
+ throw parsed.error;
1070
1130
  } catch (error) {
1071
1131
  if (onError === "throwOnError") {
1072
1132
  throw error;
@@ -1106,7 +1166,7 @@ ${error}`);
1106
1166
  if (onError === "throwOnError") {
1107
1167
  throw error;
1108
1168
  }
1109
- if (error instanceof import_zod28.ZodError) {
1169
+ if (error instanceof import_zod30.ZodError) {
1110
1170
  this.logger.info(`Failed to parse response:
1111
1171
  ${error.message}`);
1112
1172
  this.logger.info(`Raw response:
@@ -1177,11 +1237,29 @@ ${JSON.stringify(response, null, 2)}`);
1177
1237
  return null;
1178
1238
  }
1179
1239
  }
1240
+ /**
1241
+ * @private
1242
+ * Save remote config to a local file
1243
+ *
1244
+ * @throws An error if the config cannot be saved
1245
+ */
1246
+ async saveConfig(options) {
1247
+ const args = [
1248
+ "config",
1249
+ "save",
1250
+ "--app",
1251
+ options.app,
1252
+ "--config",
1253
+ options.config,
1254
+ "--yes"
1255
+ ];
1256
+ await this.execFly(args);
1257
+ }
1180
1258
  /**
1181
1259
  * @private
1182
1260
  * Ensure Fly CLI is installed and authenticated
1183
1261
  *
1184
- * @throws An error if Fly CLI is not installed or authentication fails
1262
+ * @throws An error if Fly CLI is not installed or not authenticated
1185
1263
  */
1186
1264
  async ensureInitialized() {
1187
1265
  if (this.initialized)
@@ -1190,32 +1268,18 @@ ${JSON.stringify(response, null, 2)}`);
1190
1268
  if (!await this.isInstalled()) {
1191
1269
  throw new Error("Fly CLI must be installed to use this library");
1192
1270
  }
1193
- this.logger.info("Authenticating with Fly.io...");
1194
- let user = await this.execFly(
1195
- ["auth", "whoami"],
1196
- void 0,
1197
- "nullOnError",
1198
- true
1199
- // won't use token
1200
- );
1201
- if (user) {
1202
- this.logger.info(`Detected logged in user '${user}'`);
1203
- this.authByLogin = true;
1204
- } else {
1205
- user = await this.execFly(["auth", "whoami"]);
1206
- this.logger.info(`Authenticated by token as '${user}'`);
1207
- }
1271
+ const { version } = await this.version();
1272
+ this.logger.info(`Fly CLI ${version} is installed`);
1273
+ const user = await this.execFly(["auth", "whoami"]);
1274
+ this.logger.info(`Authenticated as '${user}'`);
1208
1275
  this.initialized = true;
1209
1276
  } catch (error) {
1210
1277
  this.logger.error("Failed to initialize Fly");
1211
1278
  throw error;
1212
1279
  }
1213
1280
  }
1214
- async execFly(command, options, onError = "throwOnError", skipToken) {
1281
+ async execFly(command, options, onError = "throwOnError") {
1215
1282
  const args = Array.isArray(command) ? command : command.split(" ");
1216
- if (!skipToken && !this.authByLogin && this._config.token) {
1217
- args.push("--access-token", this._config.token);
1218
- }
1219
1283
  const flyCmd = "flyctl";
1220
1284
  const toLogCmd = `${flyCmd} ${args.join(" ")}`;
1221
1285
  let output = "";
@@ -1319,6 +1383,18 @@ ${errorMsg}`);
1319
1383
  async isInstalled() {
1320
1384
  return await this.execFly("version", void 0, "nullOnError") !== null;
1321
1385
  }
1386
+ /**
1387
+ * @private
1388
+ * Get the installed Fly CLI version
1389
+ *
1390
+ * @returns The installed Fly CLI version information
1391
+ * @throws An error if the version cannot be retrieved
1392
+ */
1393
+ async version() {
1394
+ return VersionTransformedResponseSchema.parse(
1395
+ await this.execFly(["version", "--json"])
1396
+ );
1397
+ }
1322
1398
  /**
1323
1399
  * @private
1324
1400
  * Normalize the options matching `AppOrConfig` type.
@@ -1345,17 +1421,44 @@ ${errorMsg}`);
1345
1421
  safeArg(arg) {
1346
1422
  return arg.replace(/\\/g, "\\\\").replace(/ /g, "\\ ");
1347
1423
  }
1424
+ /**
1425
+ * @private
1426
+ * Redact sensitive values from text.
1427
+ *
1428
+ * Identifies and redacts:
1429
+ * - Secret values provided with `secrets set KEY1=VALUE1 KEY2=VALUE2 ...`
1430
+ *
1431
+ * @param text - The text to redact
1432
+ * @returns The redacted text
1433
+ */
1434
+ redactSensitiveData(text) {
1435
+ const maskValue = (value) => value.length > 10 ? `${value.slice(0, 3)}[REDACTED]${value.slice(-3)}` : "[REDACTED]";
1436
+ const valuePattern = "((?:\\\\ |\\S)+)";
1437
+ return text.replace(
1438
+ new RegExp(
1439
+ `(secrets\\s+set\\s+.*?)([A-Z_][A-Z0-9_]*)=${valuePattern}`,
1440
+ "g"
1441
+ ),
1442
+ (_, prefix, key, value) => `${prefix}${key}=${maskValue(value)}`
1443
+ );
1444
+ }
1348
1445
  /**
1349
1446
  * @private
1350
1447
  * Trace the CLI calls, mocks and results
1351
1448
  *
1449
+ * Redacts sensitive data from CALL messages when enabled in logger config.
1450
+ *
1352
1451
  * @param type - The type of trace
1353
1452
  * @param msg - The message to trace
1354
1453
  */
1355
1454
  traceCLI(type, msg) {
1356
1455
  if (this.logger.traceCLI) {
1357
1456
  const typeLabel = type === "CALL" ? " CALL " : type === "MOCK" ? " MOCK " : "RESULT";
1358
- this.logger.info(`[${typeLabel}] ${msg}`);
1457
+ let message = msg;
1458
+ if (type === "CALL" && this.logger.redactSecrets && msg) {
1459
+ message = this.redactSensitiveData(msg);
1460
+ }
1461
+ this.logger.info(`[${typeLabel}] ${message}`);
1359
1462
  }
1360
1463
  }
1361
1464
  };