@settlemint/sdk-utils 2.3.2-pref69a5a3 → 2.3.2-preff27199

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.
Files changed (98) hide show
  1. package/README.md +51 -7
  2. package/dist/environment.cjs +17705 -384
  3. package/dist/environment.cjs.map +1 -1
  4. package/dist/environment.d.cts +263 -98
  5. package/dist/environment.d.ts +263 -98
  6. package/dist/environment.js +17743 -0
  7. package/dist/environment.js.map +1 -0
  8. package/dist/filesystem.cjs +6746 -113
  9. package/dist/filesystem.cjs.map +1 -1
  10. package/dist/filesystem.d.cts +22 -1
  11. package/dist/filesystem.d.ts +22 -1
  12. package/dist/filesystem.js +6766 -0
  13. package/dist/filesystem.js.map +1 -0
  14. package/dist/http.cjs +214 -94
  15. package/dist/http.cjs.map +1 -1
  16. package/dist/http.d.cts +9 -1
  17. package/dist/http.d.ts +9 -1
  18. package/dist/http.js +226 -0
  19. package/dist/http.js.map +1 -0
  20. package/dist/index.cjs +292 -110
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +9 -0
  23. package/dist/index.d.ts +9 -0
  24. package/dist/index.js +306 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/json.cjs +83 -0
  27. package/dist/json.cjs.map +1 -0
  28. package/dist/json.d.cts +56 -0
  29. package/dist/json.d.ts +56 -0
  30. package/dist/json.js +80 -0
  31. package/dist/json.js.map +1 -0
  32. package/dist/logging.cjs +209 -137
  33. package/dist/logging.cjs.map +1 -1
  34. package/dist/logging.d.cts +23 -14
  35. package/dist/logging.d.ts +23 -14
  36. package/dist/logging.js +221 -0
  37. package/dist/logging.js.map +1 -0
  38. package/dist/package-manager.cjs +7350 -173
  39. package/dist/package-manager.cjs.map +1 -1
  40. package/dist/package-manager.d.cts +26 -3
  41. package/dist/package-manager.d.ts +26 -3
  42. package/dist/package-manager.js +7382 -0
  43. package/dist/package-manager.js.map +1 -0
  44. package/dist/retry.cjs +137 -0
  45. package/dist/retry.cjs.map +1 -0
  46. package/dist/retry.d.cts +19 -0
  47. package/dist/retry.d.ts +19 -0
  48. package/dist/retry.js +136 -0
  49. package/dist/retry.js.map +1 -0
  50. package/dist/runtime.cjs +58 -40
  51. package/dist/runtime.cjs.map +1 -1
  52. package/dist/runtime.d.cts +3 -0
  53. package/dist/runtime.d.ts +3 -0
  54. package/dist/runtime.js +45 -0
  55. package/dist/runtime.js.map +1 -0
  56. package/dist/string.cjs +76 -0
  57. package/dist/string.cjs.map +1 -0
  58. package/dist/string.d.cts +58 -0
  59. package/dist/string.d.ts +58 -0
  60. package/dist/string.js +72 -0
  61. package/dist/string.js.map +1 -0
  62. package/dist/terminal.cjs +423 -229
  63. package/dist/terminal.cjs.map +1 -1
  64. package/dist/terminal.d.cts +54 -24
  65. package/dist/terminal.d.ts +54 -24
  66. package/dist/terminal.js +438 -0
  67. package/dist/terminal.js.map +1 -0
  68. package/dist/url.cjs +25 -0
  69. package/dist/url.cjs.map +1 -0
  70. package/dist/url.d.cts +20 -0
  71. package/dist/url.d.ts +20 -0
  72. package/dist/url.js +24 -0
  73. package/dist/url.js.map +1 -0
  74. package/dist/validation.cjs +10486 -193
  75. package/dist/validation.cjs.map +1 -1
  76. package/dist/validation.d.cts +124 -94
  77. package/dist/validation.d.ts +124 -94
  78. package/dist/validation.js +10482 -0
  79. package/dist/validation.js.map +1 -0
  80. package/package.json +6 -6
  81. package/dist/environment.mjs +0 -384
  82. package/dist/environment.mjs.map +0 -1
  83. package/dist/filesystem.mjs +0 -105
  84. package/dist/filesystem.mjs.map +0 -1
  85. package/dist/http.mjs +0 -80
  86. package/dist/http.mjs.map +0 -1
  87. package/dist/index.mjs +0 -98
  88. package/dist/index.mjs.map +0 -1
  89. package/dist/logging.mjs +0 -123
  90. package/dist/logging.mjs.map +0 -1
  91. package/dist/package-manager.mjs +0 -167
  92. package/dist/package-manager.mjs.map +0 -1
  93. package/dist/runtime.mjs +0 -23
  94. package/dist/runtime.mjs.map +0 -1
  95. package/dist/terminal.mjs +0 -230
  96. package/dist/terminal.mjs.map +0 -1
  97. package/dist/validation.mjs +0 -161
  98. package/dist/validation.mjs.map +0 -1
package/dist/terminal.cjs CHANGED
@@ -1,279 +1,473 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
8
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/terminal.ts
31
- var terminal_exports = {};
32
- __export(terminal_exports, {
33
- CancelError: () => CancelError,
34
- CommandError: () => CommandError,
35
- SpinnerError: () => SpinnerError,
36
- ascii: () => ascii,
37
- cancel: () => cancel,
38
- executeCommand: () => executeCommand,
39
- intro: () => intro,
40
- list: () => list,
41
- maskTokens: () => maskTokens,
42
- note: () => note,
43
- outro: () => outro,
44
- spinner: () => spinner,
45
- table: () => table
46
- });
47
- module.exports = __toCommonJS(terminal_exports);
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
48
22
 
49
- // src/terminal/ascii.ts
50
- var import_yoctocolors = require("yoctocolors");
23
+ //#endregion
24
+ const yoctocolors = __toESM(require("yoctocolors"));
25
+ const node_child_process = __toESM(require("node:child_process"));
26
+ const is_in_ci = __toESM(require("is-in-ci"));
27
+ const yocto_spinner = __toESM(require("yocto-spinner"));
28
+ const console_table_printer = __toESM(require("console-table-printer"));
51
29
 
52
- // src/terminal/should-print.ts
30
+ //#region src/terminal/should-print.ts
31
+ /**
32
+ * Returns true if the terminal should print, false otherwise.
33
+ * @returns true if the terminal should print, false otherwise.
34
+ */
53
35
  function shouldPrint() {
54
- return process.env.SETTLEMINT_DISABLE_TERMINAL !== "true";
36
+ return process.env.SETTLEMINT_DISABLE_TERMINAL !== "true";
55
37
  }
56
38
 
57
- // src/terminal/ascii.ts
58
- var ascii = () => {
59
- if (!shouldPrint()) {
60
- return;
61
- }
62
- console.log(
63
- (0, import_yoctocolors.magentaBright)(`
39
+ //#endregion
40
+ //#region src/terminal/ascii.ts
41
+ /**
42
+ * Prints the SettleMint ASCII art logo to the console in magenta color.
43
+ * Used for CLI branding and visual identification.
44
+ *
45
+ * @example
46
+ * import { ascii } from "@settlemint/sdk-utils/terminal";
47
+ *
48
+ * // Prints the SettleMint logo
49
+ * ascii();
50
+ */
51
+ const ascii = () => {
52
+ if (!shouldPrint()) {
53
+ return;
54
+ }
55
+ console.log((0, yoctocolors.magentaBright)(`
64
56
  _________ __ __ .__ _____ .__ __
65
57
  / _____/ _____/ |__/ |_| | ____ / \\ |__| _____/ |_
66
58
  \\_____ \\_/ __ \\ __\\ __\\ | _/ __ \\ / \\ / \\| |/ \\ __\\
67
59
  / \\ ___/| | | | | |_\\ ___// Y \\ | | \\ |
68
60
  /_________/\\_____>__| |__| |____/\\_____>____|____/__|___|__/__|
69
- `)
70
- );
61
+ `));
71
62
  };
72
63
 
73
- // src/logging/mask-tokens.ts
74
- var maskTokens = (output) => {
75
- return output.replace(/sm_(pat|aat|sat)_[0-9a-zA-Z]+/g, "***");
64
+ //#endregion
65
+ //#region src/logging/mask-tokens.ts
66
+ /**
67
+ * Masks sensitive SettleMint tokens in output text by replacing them with asterisks.
68
+ * Handles personal access tokens (PAT), application access tokens (AAT), and service account tokens (SAT).
69
+ *
70
+ * @param output - The text string that may contain sensitive tokens
71
+ * @returns The text with any sensitive tokens masked with asterisks
72
+ * @example
73
+ * import { maskTokens } from "@settlemint/sdk-utils/terminal";
74
+ *
75
+ * // Masks a token in text
76
+ * const masked = maskTokens("Token: sm_pat_****"); // "Token: ***"
77
+ */
78
+ const maskTokens = (output) => {
79
+ return output.replace(/sm_(pat|aat|sat)_[0-9a-zA-Z]+/g, "***");
76
80
  };
77
81
 
78
- // src/terminal/cancel.ts
79
- var import_yoctocolors2 = require("yoctocolors");
80
- var CancelError = class extends Error {
81
- };
82
- var cancel = (msg) => {
83
- console.log("");
84
- console.log((0, import_yoctocolors2.inverse)((0, import_yoctocolors2.redBright)(maskTokens(msg))));
85
- console.log("");
86
- throw new CancelError(msg);
82
+ //#endregion
83
+ //#region src/terminal/cancel.ts
84
+ /**
85
+ * Error class used to indicate that the operation was cancelled.
86
+ * This error is used to signal that the operation should be aborted.
87
+ */
88
+ var CancelError = class extends Error {};
89
+ /**
90
+ * Displays an error message in red inverse text and throws a CancelError.
91
+ * Used to terminate execution with a visible error message.
92
+ * Any sensitive tokens in the message are masked before display.
93
+ *
94
+ * @param msg - The error message to display
95
+ * @returns never - Function does not return as it throws an error
96
+ * @example
97
+ * import { cancel } from "@settlemint/sdk-utils/terminal";
98
+ *
99
+ * // Exits process with error message
100
+ * cancel("An error occurred");
101
+ */
102
+ const cancel = (msg) => {
103
+ console.log("");
104
+ console.log((0, yoctocolors.inverse)((0, yoctocolors.redBright)(maskTokens(msg))));
105
+ console.log("");
106
+ throw new CancelError(msg);
87
107
  };
88
108
 
89
- // src/terminal/execute-command.ts
90
- var import_node_child_process = require("child_process");
109
+ //#endregion
110
+ //#region src/terminal/execute-command.ts
111
+ /**
112
+ * Error class for command execution errors
113
+ * @extends Error
114
+ */
91
115
  var CommandError = class extends Error {
92
- /**
93
- * Constructs a new CommandError
94
- * @param message - The error message
95
- * @param code - The exit code of the command
96
- * @param output - The output of the command
97
- */
98
- constructor(message, code, output) {
99
- super(message);
100
- this.code = code;
101
- this.output = output;
102
- }
116
+ /**
117
+ * Constructs a new CommandError
118
+ * @param message - The error message
119
+ * @param code - The exit code of the command
120
+ * @param output - The output of the command
121
+ */
122
+ constructor(message, code, output) {
123
+ super(message);
124
+ this.code = code;
125
+ this.output = output;
126
+ }
103
127
  };
128
+ /**
129
+ * Executes a command with the given arguments in a child process.
130
+ * Pipes stdin to the child process and captures stdout/stderr output.
131
+ * Masks any sensitive tokens in the output before displaying or returning.
132
+ *
133
+ * @param command - The command to execute
134
+ * @param args - Array of arguments to pass to the command
135
+ * @param options - Options for customizing command execution
136
+ * @returns Array of output strings from stdout and stderr
137
+ * @throws {CommandError} If the process fails to start or exits with non-zero code
138
+ * @example
139
+ * import { executeCommand } from "@settlemint/sdk-utils/terminal";
140
+ *
141
+ * // Execute git clone
142
+ * await executeCommand("git", ["clone", "repo-url"]);
143
+ *
144
+ * // Execute silently
145
+ * await executeCommand("npm", ["install"], { silent: true });
146
+ */
104
147
  async function executeCommand(command, args, options) {
105
- const { silent, ...spawnOptions } = options ?? {};
106
- const child = (0, import_node_child_process.spawn)(command, args, { ...spawnOptions, env: { ...process.env, ...options?.env } });
107
- process.stdin.pipe(child.stdin);
108
- const output = [];
109
- return new Promise((resolve, reject) => {
110
- child.stdout.on("data", (data) => {
111
- const maskedData = maskTokens(data.toString());
112
- if (!silent) {
113
- process.stdout.write(maskedData);
114
- }
115
- output.push(maskedData);
116
- });
117
- child.stderr.on("data", (data) => {
118
- const maskedData = maskTokens(data.toString());
119
- if (!silent) {
120
- process.stderr.write(maskedData);
121
- }
122
- output.push(maskedData);
123
- });
124
- child.on(
125
- "error",
126
- (err) => reject(new CommandError(err.message, "code" in err && typeof err.code === "number" ? err.code : 1, output))
127
- );
128
- child.on("close", (code) => {
129
- if (code === 0 || code === null || code === 143) {
130
- process.stdin.unpipe(child.stdin);
131
- resolve(output);
132
- return;
133
- }
134
- reject(new CommandError(`Command "${command}" exited with code ${code}`, code, output));
135
- });
136
- });
148
+ const { silent,...spawnOptions } = options ?? {};
149
+ const child = (0, node_child_process.spawn)(command, args, {
150
+ ...spawnOptions,
151
+ env: {
152
+ ...process.env,
153
+ ...options?.env
154
+ }
155
+ });
156
+ process.stdin.pipe(child.stdin);
157
+ const output = [];
158
+ return new Promise((resolve, reject) => {
159
+ child.stdout.on("data", (data) => {
160
+ const maskedData = maskTokens(data.toString());
161
+ if (!silent) {
162
+ process.stdout.write(maskedData);
163
+ }
164
+ output.push(maskedData);
165
+ });
166
+ child.stderr.on("data", (data) => {
167
+ const maskedData = maskTokens(data.toString());
168
+ if (!silent) {
169
+ process.stderr.write(maskedData);
170
+ }
171
+ output.push(maskedData);
172
+ });
173
+ child.on("error", (err) => reject(new CommandError(err.message, "code" in err && typeof err.code === "number" ? err.code : 1, output)));
174
+ child.on("close", (code) => {
175
+ if (code === 0 || code === null || code === 143) {
176
+ process.stdin.unpipe(child.stdin);
177
+ resolve(output);
178
+ return;
179
+ }
180
+ reject(new CommandError(`Command "${command}" exited with code ${code}`, code, output));
181
+ });
182
+ });
137
183
  }
138
184
 
139
- // src/terminal/intro.ts
140
- var import_yoctocolors3 = require("yoctocolors");
141
- var intro = (msg) => {
142
- if (!shouldPrint()) {
143
- return;
144
- }
145
- console.log("");
146
- console.log((0, import_yoctocolors3.magentaBright)(maskTokens(msg)));
147
- console.log("");
185
+ //#endregion
186
+ //#region src/terminal/intro.ts
187
+ /**
188
+ * Displays an introductory message in magenta text with padding.
189
+ * Any sensitive tokens in the message are masked before display.
190
+ *
191
+ * @param msg - The message to display as introduction
192
+ * @example
193
+ * import { intro } from "@settlemint/sdk-utils/terminal";
194
+ *
195
+ * // Display intro message
196
+ * intro("Starting deployment...");
197
+ */
198
+ const intro = (msg) => {
199
+ if (!shouldPrint()) {
200
+ return;
201
+ }
202
+ console.log("");
203
+ console.log((0, yoctocolors.magentaBright)(maskTokens(msg)));
204
+ console.log("");
148
205
  };
149
206
 
150
- // src/terminal/note.ts
151
- var import_yoctocolors4 = require("yoctocolors");
152
- var note = (message, level = "info") => {
153
- if (!shouldPrint()) {
154
- return;
155
- }
156
- const maskedMessage = maskTokens(message);
157
- console.log("");
158
- if (level === "warn") {
159
- console.warn((0, import_yoctocolors4.yellowBright)(maskedMessage));
160
- return;
161
- }
162
- console.log(maskedMessage);
207
+ //#endregion
208
+ //#region src/terminal/note.ts
209
+ /**
210
+ * Displays a note message with optional warning level formatting.
211
+ * Regular notes are displayed in normal text, while warnings are shown in yellow.
212
+ * Any sensitive tokens in the message are masked before display.
213
+ *
214
+ * @param message - The message to display as a note
215
+ * @param level - The note level: "info" (default) or "warn" for warning styling
216
+ * @example
217
+ * import { note } from "@settlemint/sdk-utils/terminal";
218
+ *
219
+ * // Display info note
220
+ * note("Operation completed successfully");
221
+ *
222
+ * // Display warning note
223
+ * note("Low disk space remaining", "warn");
224
+ */
225
+ const note = (message, level = "info") => {
226
+ if (!shouldPrint()) {
227
+ return;
228
+ }
229
+ const maskedMessage = maskTokens(message);
230
+ console.log("");
231
+ if (level === "warn") {
232
+ console.warn((0, yoctocolors.yellowBright)(maskedMessage));
233
+ return;
234
+ }
235
+ console.log(maskedMessage);
163
236
  };
164
237
 
165
- // src/terminal/list.ts
238
+ //#endregion
239
+ //#region src/terminal/list.ts
240
+ /**
241
+ * Displays a list of items in a formatted manner, supporting nested items.
242
+ *
243
+ * @param title - The title of the list
244
+ * @param items - The items to display, can be strings or arrays for nested items
245
+ * @returns The formatted list
246
+ * @example
247
+ * import { list } from "@settlemint/sdk-utils/terminal";
248
+ *
249
+ * // Simple list
250
+ * list("Use cases", ["use case 1", "use case 2", "use case 3"]);
251
+ *
252
+ * // Nested list
253
+ * list("Providers", [
254
+ * "AWS",
255
+ * ["us-east-1", "eu-west-1"],
256
+ * "Azure",
257
+ * ["eastus", "westeurope"]
258
+ * ]);
259
+ */
166
260
  function list(title, items) {
167
- const formatItems = (items2) => {
168
- return items2.map((item) => {
169
- if (Array.isArray(item)) {
170
- return item.map((subItem) => ` \u2022 ${subItem}`).join("\n");
171
- }
172
- return ` \u2022 ${item}`;
173
- }).join("\n");
174
- };
175
- return note(`${title}:
176
-
177
- ${formatItems(items)}`);
261
+ const formatItems = (items$1) => {
262
+ return items$1.map((item) => {
263
+ if (Array.isArray(item)) {
264
+ return item.map((subItem) => ` ${subItem}`).join("\n");
265
+ }
266
+ return ` ${item}`;
267
+ }).join("\n");
268
+ };
269
+ return note(`${title}:\n\n${formatItems(items)}`);
178
270
  }
179
271
 
180
- // src/terminal/outro.ts
181
- var import_yoctocolors5 = require("yoctocolors");
182
- var outro = (msg) => {
183
- if (!shouldPrint()) {
184
- return;
185
- }
186
- console.log("");
187
- console.log((0, import_yoctocolors5.inverse)((0, import_yoctocolors5.greenBright)(maskTokens(msg))));
188
- console.log("");
272
+ //#endregion
273
+ //#region src/terminal/outro.ts
274
+ /**
275
+ * Displays a closing message in green inverted text with padding.
276
+ * Any sensitive tokens in the message are masked before display.
277
+ *
278
+ * @param msg - The message to display as conclusion
279
+ * @example
280
+ * import { outro } from "@settlemint/sdk-utils/terminal";
281
+ *
282
+ * // Display outro message
283
+ * outro("Deployment completed successfully!");
284
+ */
285
+ const outro = (msg) => {
286
+ if (!shouldPrint()) {
287
+ return;
288
+ }
289
+ console.log("");
290
+ console.log((0, yoctocolors.inverse)((0, yoctocolors.greenBright)(maskTokens(msg))));
291
+ console.log("");
189
292
  };
190
293
 
191
- // src/terminal/spinner.ts
192
- var import_is_in_ci = __toESM(require("is-in-ci"), 1);
193
- var import_yocto_spinner = __toESM(require("yocto-spinner"), 1);
194
- var import_yoctocolors6 = require("yoctocolors");
294
+ //#endregion
295
+ //#region src/terminal/spinner.ts
296
+ /**
297
+ * Error class used to indicate that the spinner operation failed.
298
+ * This error is used to signal that the operation should be aborted.
299
+ */
195
300
  var SpinnerError = class extends Error {
196
- constructor(message, originalError) {
197
- super(message);
198
- this.originalError = originalError;
199
- this.name = "SpinnerError";
200
- }
301
+ constructor(message, originalError) {
302
+ super(message);
303
+ this.originalError = originalError;
304
+ this.name = "SpinnerError";
305
+ }
201
306
  };
202
- var spinner = async (options) => {
203
- const handleError = (error) => {
204
- const errorMessage = maskTokens(error.message);
205
- note((0, import_yoctocolors6.redBright)(`${errorMessage}
206
-
207
- ${error.stack}`));
208
- throw new SpinnerError(errorMessage, error);
209
- };
210
- if (import_is_in_ci.default || !shouldPrint()) {
211
- try {
212
- return await options.task();
213
- } catch (err) {
214
- return handleError(err);
215
- }
216
- }
217
- const spinner2 = (0, import_yocto_spinner.default)({ stream: process.stdout }).start(options.startMessage);
218
- try {
219
- const result = await options.task(spinner2);
220
- spinner2.success(options.stopMessage);
221
- await new Promise((resolve) => process.nextTick(resolve));
222
- return result;
223
- } catch (err) {
224
- spinner2.error((0, import_yoctocolors6.redBright)(`${options.startMessage} --> Error!`));
225
- return handleError(err);
226
- }
307
+ /**
308
+ * Displays a loading spinner while executing an async task.
309
+ * Shows progress with start/stop messages and handles errors.
310
+ * Spinner is disabled in CI environments.
311
+ *
312
+ * @param options - Configuration options for the spinner
313
+ * @returns The result from the executed task
314
+ * @throws Will exit process with code 1 if task fails
315
+ * @example
316
+ * import { spinner } from "@settlemint/sdk-utils/terminal";
317
+ *
318
+ * // Show spinner during async task
319
+ * const result = await spinner({
320
+ * startMessage: "Deploying...",
321
+ * task: async () => {
322
+ * // Async work here
323
+ * return "success";
324
+ * },
325
+ * stopMessage: "Deployed successfully!"
326
+ * });
327
+ */
328
+ const spinner = async (options) => {
329
+ const handleError = (error) => {
330
+ const errorMessage = maskTokens(error.message);
331
+ note((0, yoctocolors.redBright)(`${errorMessage}\n\n${error.stack}`));
332
+ throw new SpinnerError(errorMessage, error);
333
+ };
334
+ if (is_in_ci.default || !shouldPrint()) {
335
+ try {
336
+ return await options.task();
337
+ } catch (err) {
338
+ return handleError(err);
339
+ }
340
+ }
341
+ const spinner$1 = (0, yocto_spinner.default)({ stream: process.stdout }).start(options.startMessage);
342
+ try {
343
+ const result = await options.task(spinner$1);
344
+ spinner$1.success(options.stopMessage);
345
+ await new Promise((resolve) => process.nextTick(resolve));
346
+ return result;
347
+ } catch (err) {
348
+ spinner$1.error((0, yoctocolors.redBright)(`${options.startMessage} --> Error!`));
349
+ return handleError(err);
350
+ }
227
351
  };
228
352
 
229
- // src/string.ts
353
+ //#endregion
354
+ //#region src/string.ts
355
+ /**
356
+ * Capitalizes the first letter of a string.
357
+ *
358
+ * @param val - The string to capitalize
359
+ * @returns The input string with its first letter capitalized
360
+ *
361
+ * @example
362
+ * import { capitalizeFirstLetter } from "@settlemint/sdk-utils";
363
+ *
364
+ * const capitalized = capitalizeFirstLetter("hello");
365
+ * // Returns: "Hello"
366
+ */
230
367
  function capitalizeFirstLetter(val) {
231
- return String(val).charAt(0).toUpperCase() + String(val).slice(1);
368
+ return String(val).charAt(0).toUpperCase() + String(val).slice(1);
232
369
  }
370
+ /**
371
+ * Converts a camelCase string to a human-readable string.
372
+ *
373
+ * @param s - The camelCase string to convert
374
+ * @returns The human-readable string
375
+ *
376
+ * @example
377
+ * import { camelCaseToWords } from "@settlemint/sdk-utils";
378
+ *
379
+ * const words = camelCaseToWords("camelCaseString");
380
+ * // Returns: "Camel Case String"
381
+ */
233
382
  function camelCaseToWords(s) {
234
- const result = s.replace(/([a-z])([A-Z])/g, "$1 $2");
235
- const withSpaces = result.replace(/([A-Z])([a-z])/g, " $1$2");
236
- const capitalized = capitalizeFirstLetter(withSpaces);
237
- return capitalized.replace(/\s+/g, " ").trim();
383
+ const result = s.replace(/([a-z])([A-Z])/g, "$1 $2");
384
+ const withSpaces = result.replace(/([A-Z])([a-z])/g, " $1$2");
385
+ const capitalized = capitalizeFirstLetter(withSpaces);
386
+ return capitalized.replace(/\s+/g, " ").trim();
387
+ }
388
+ /**
389
+ * Replaces underscores and hyphens with spaces.
390
+ *
391
+ * @param s - The string to replace underscores and hyphens with spaces
392
+ * @returns The input string with underscores and hyphens replaced with spaces
393
+ *
394
+ * @example
395
+ * import { replaceUnderscoresAndHyphensWithSpaces } from "@settlemint/sdk-utils";
396
+ *
397
+ * const result = replaceUnderscoresAndHyphensWithSpaces("Already_Spaced-Second");
398
+ * // Returns: "Already Spaced Second"
399
+ */
400
+ function replaceUnderscoresAndHyphensWithSpaces(s) {
401
+ return s.replace(/[-_]/g, " ");
402
+ }
403
+ /**
404
+ * Truncates a string to a maximum length and appends "..." if it is longer.
405
+ *
406
+ * @param value - The string to truncate
407
+ * @param maxLength - The maximum length of the string
408
+ * @returns The truncated string or the original string if it is shorter than the maximum length
409
+ *
410
+ * @example
411
+ * import { truncate } from "@settlemint/sdk-utils";
412
+ *
413
+ * const truncated = truncate("Hello, world!", 10);
414
+ * // Returns: "Hello, wor..."
415
+ */
416
+ function truncate(value, maxLength) {
417
+ if (value.length <= maxLength) {
418
+ return value;
419
+ }
420
+ return `${value.slice(0, maxLength)}...`;
238
421
  }
239
422
 
240
- // src/terminal/table.ts
241
- var import_console_table_printer = require("console-table-printer");
242
- var import_yoctocolors7 = require("yoctocolors");
423
+ //#endregion
424
+ //#region src/terminal/table.ts
425
+ /**
426
+ * Displays data in a formatted table in the terminal.
427
+ *
428
+ * @param title - Title to display above the table
429
+ * @param data - Array of objects to display in table format
430
+ * @example
431
+ * import { table } from "@settlemint/sdk-utils/terminal";
432
+ *
433
+ * const data = [
434
+ * { name: "Item 1", value: 100 },
435
+ * { name: "Item 2", value: 200 }
436
+ * ];
437
+ *
438
+ * table("My Table", data);
439
+ */
243
440
  function table(title, data) {
244
- if (!shouldPrint()) {
245
- return;
246
- }
247
- note(title);
248
- if (!data || data.length === 0) {
249
- note("No data to display");
250
- return;
251
- }
252
- const columnKeys = Object.keys(data[0]);
253
- const table2 = new import_console_table_printer.Table({
254
- columns: columnKeys.map((key) => ({
255
- name: key,
256
- title: (0, import_yoctocolors7.whiteBright)(camelCaseToWords(key)),
257
- alignment: "left"
258
- }))
259
- });
260
- table2.addRows(data);
261
- table2.printTable();
441
+ if (!shouldPrint()) {
442
+ return;
443
+ }
444
+ note(title);
445
+ if (!data || data.length === 0) {
446
+ note("No data to display");
447
+ return;
448
+ }
449
+ const columnKeys = Object.keys(data[0]);
450
+ const table$1 = new console_table_printer.Table({ columns: columnKeys.map((key) => ({
451
+ name: key,
452
+ title: (0, yoctocolors.whiteBright)(camelCaseToWords(key)),
453
+ alignment: "left"
454
+ })) });
455
+ table$1.addRows(data);
456
+ table$1.printTable();
262
457
  }
263
- // Annotate the CommonJS export names for ESM import in node:
264
- 0 && (module.exports = {
265
- CancelError,
266
- CommandError,
267
- SpinnerError,
268
- ascii,
269
- cancel,
270
- executeCommand,
271
- intro,
272
- list,
273
- maskTokens,
274
- note,
275
- outro,
276
- spinner,
277
- table
278
- });
458
+
459
+ //#endregion
460
+ exports.CancelError = CancelError;
461
+ exports.CommandError = CommandError;
462
+ exports.SpinnerError = SpinnerError;
463
+ exports.ascii = ascii;
464
+ exports.cancel = cancel;
465
+ exports.executeCommand = executeCommand;
466
+ exports.intro = intro;
467
+ exports.list = list;
468
+ exports.maskTokens = maskTokens;
469
+ exports.note = note;
470
+ exports.outro = outro;
471
+ exports.spinner = spinner;
472
+ exports.table = table;
279
473
  //# sourceMappingURL=terminal.cjs.map