@settlemint/sdk-utils 2.3.2-pre186542e → 2.3.2-prede7bc05

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 +17708 -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 +17746 -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 +295 -104
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +26 -1
  23. package/dist/index.d.ts +26 -1
  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 +7353 -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 +7385 -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 +426 -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 +441 -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 -90
  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,476 @@
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) => {
174
+ process.stdin.unpipe(child.stdin);
175
+ reject(new CommandError(err.message, "code" in err && typeof err.code === "number" ? err.code : 1, output));
176
+ });
177
+ child.on("close", (code) => {
178
+ process.stdin.unpipe(child.stdin);
179
+ if (code === 0 || code === null || code === 143) {
180
+ resolve(output);
181
+ return;
182
+ }
183
+ reject(new CommandError(`Command "${command}" exited with code ${code}`, code, output));
184
+ });
185
+ });
137
186
  }
138
187
 
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("");
188
+ //#endregion
189
+ //#region src/terminal/intro.ts
190
+ /**
191
+ * Displays an introductory message in magenta text with padding.
192
+ * Any sensitive tokens in the message are masked before display.
193
+ *
194
+ * @param msg - The message to display as introduction
195
+ * @example
196
+ * import { intro } from "@settlemint/sdk-utils/terminal";
197
+ *
198
+ * // Display intro message
199
+ * intro("Starting deployment...");
200
+ */
201
+ const intro = (msg) => {
202
+ if (!shouldPrint()) {
203
+ return;
204
+ }
205
+ console.log("");
206
+ console.log((0, yoctocolors.magentaBright)(maskTokens(msg)));
207
+ console.log("");
148
208
  };
149
209
 
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);
210
+ //#endregion
211
+ //#region src/terminal/note.ts
212
+ /**
213
+ * Displays a note message with optional warning level formatting.
214
+ * Regular notes are displayed in normal text, while warnings are shown in yellow.
215
+ * Any sensitive tokens in the message are masked before display.
216
+ *
217
+ * @param message - The message to display as a note
218
+ * @param level - The note level: "info" (default) or "warn" for warning styling
219
+ * @example
220
+ * import { note } from "@settlemint/sdk-utils/terminal";
221
+ *
222
+ * // Display info note
223
+ * note("Operation completed successfully");
224
+ *
225
+ * // Display warning note
226
+ * note("Low disk space remaining", "warn");
227
+ */
228
+ const note = (message, level = "info") => {
229
+ if (!shouldPrint()) {
230
+ return;
231
+ }
232
+ const maskedMessage = maskTokens(message);
233
+ console.log("");
234
+ if (level === "warn") {
235
+ console.warn((0, yoctocolors.yellowBright)(maskedMessage));
236
+ return;
237
+ }
238
+ console.log(maskedMessage);
163
239
  };
164
240
 
165
- // src/terminal/list.ts
241
+ //#endregion
242
+ //#region src/terminal/list.ts
243
+ /**
244
+ * Displays a list of items in a formatted manner, supporting nested items.
245
+ *
246
+ * @param title - The title of the list
247
+ * @param items - The items to display, can be strings or arrays for nested items
248
+ * @returns The formatted list
249
+ * @example
250
+ * import { list } from "@settlemint/sdk-utils/terminal";
251
+ *
252
+ * // Simple list
253
+ * list("Use cases", ["use case 1", "use case 2", "use case 3"]);
254
+ *
255
+ * // Nested list
256
+ * list("Providers", [
257
+ * "AWS",
258
+ * ["us-east-1", "eu-west-1"],
259
+ * "Azure",
260
+ * ["eastus", "westeurope"]
261
+ * ]);
262
+ */
166
263
  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)}`);
264
+ const formatItems = (items$1) => {
265
+ return items$1.map((item) => {
266
+ if (Array.isArray(item)) {
267
+ return item.map((subItem) => ` ${subItem}`).join("\n");
268
+ }
269
+ return ` ${item}`;
270
+ }).join("\n");
271
+ };
272
+ return note(`${title}:\n\n${formatItems(items)}`);
178
273
  }
179
274
 
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("");
275
+ //#endregion
276
+ //#region src/terminal/outro.ts
277
+ /**
278
+ * Displays a closing message in green inverted text with padding.
279
+ * Any sensitive tokens in the message are masked before display.
280
+ *
281
+ * @param msg - The message to display as conclusion
282
+ * @example
283
+ * import { outro } from "@settlemint/sdk-utils/terminal";
284
+ *
285
+ * // Display outro message
286
+ * outro("Deployment completed successfully!");
287
+ */
288
+ const outro = (msg) => {
289
+ if (!shouldPrint()) {
290
+ return;
291
+ }
292
+ console.log("");
293
+ console.log((0, yoctocolors.inverse)((0, yoctocolors.greenBright)(maskTokens(msg))));
294
+ console.log("");
189
295
  };
190
296
 
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");
297
+ //#endregion
298
+ //#region src/terminal/spinner.ts
299
+ /**
300
+ * Error class used to indicate that the spinner operation failed.
301
+ * This error is used to signal that the operation should be aborted.
302
+ */
195
303
  var SpinnerError = class extends Error {
196
- constructor(message, originalError) {
197
- super(message);
198
- this.originalError = originalError;
199
- this.name = "SpinnerError";
200
- }
304
+ constructor(message, originalError) {
305
+ super(message);
306
+ this.originalError = originalError;
307
+ this.name = "SpinnerError";
308
+ }
201
309
  };
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
- }
310
+ /**
311
+ * Displays a loading spinner while executing an async task.
312
+ * Shows progress with start/stop messages and handles errors.
313
+ * Spinner is disabled in CI environments.
314
+ *
315
+ * @param options - Configuration options for the spinner
316
+ * @returns The result from the executed task
317
+ * @throws Will exit process with code 1 if task fails
318
+ * @example
319
+ * import { spinner } from "@settlemint/sdk-utils/terminal";
320
+ *
321
+ * // Show spinner during async task
322
+ * const result = await spinner({
323
+ * startMessage: "Deploying...",
324
+ * task: async () => {
325
+ * // Async work here
326
+ * return "success";
327
+ * },
328
+ * stopMessage: "Deployed successfully!"
329
+ * });
330
+ */
331
+ const spinner = async (options) => {
332
+ const handleError = (error) => {
333
+ const errorMessage = maskTokens(error.message);
334
+ note((0, yoctocolors.redBright)(`${errorMessage}\n\n${error.stack}`));
335
+ throw new SpinnerError(errorMessage, error);
336
+ };
337
+ if (is_in_ci.default || !shouldPrint()) {
338
+ try {
339
+ return await options.task();
340
+ } catch (err) {
341
+ return handleError(err);
342
+ }
343
+ }
344
+ const spinner$1 = (0, yocto_spinner.default)({ stream: process.stdout }).start(options.startMessage);
345
+ try {
346
+ const result = await options.task(spinner$1);
347
+ spinner$1.success(options.stopMessage);
348
+ await new Promise((resolve) => process.nextTick(resolve));
349
+ return result;
350
+ } catch (err) {
351
+ spinner$1.error((0, yoctocolors.redBright)(`${options.startMessage} --> Error!`));
352
+ return handleError(err);
353
+ }
227
354
  };
228
355
 
229
- // src/string.ts
356
+ //#endregion
357
+ //#region src/string.ts
358
+ /**
359
+ * Capitalizes the first letter of a string.
360
+ *
361
+ * @param val - The string to capitalize
362
+ * @returns The input string with its first letter capitalized
363
+ *
364
+ * @example
365
+ * import { capitalizeFirstLetter } from "@settlemint/sdk-utils";
366
+ *
367
+ * const capitalized = capitalizeFirstLetter("hello");
368
+ * // Returns: "Hello"
369
+ */
230
370
  function capitalizeFirstLetter(val) {
231
- return String(val).charAt(0).toUpperCase() + String(val).slice(1);
371
+ return String(val).charAt(0).toUpperCase() + String(val).slice(1);
232
372
  }
373
+ /**
374
+ * Converts a camelCase string to a human-readable string.
375
+ *
376
+ * @param s - The camelCase string to convert
377
+ * @returns The human-readable string
378
+ *
379
+ * @example
380
+ * import { camelCaseToWords } from "@settlemint/sdk-utils";
381
+ *
382
+ * const words = camelCaseToWords("camelCaseString");
383
+ * // Returns: "Camel Case String"
384
+ */
233
385
  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();
386
+ const result = s.replace(/([a-z])([A-Z])/g, "$1 $2");
387
+ const withSpaces = result.replace(/([A-Z])([a-z])/g, " $1$2");
388
+ const capitalized = capitalizeFirstLetter(withSpaces);
389
+ return capitalized.replace(/\s+/g, " ").trim();
390
+ }
391
+ /**
392
+ * Replaces underscores and hyphens with spaces.
393
+ *
394
+ * @param s - The string to replace underscores and hyphens with spaces
395
+ * @returns The input string with underscores and hyphens replaced with spaces
396
+ *
397
+ * @example
398
+ * import { replaceUnderscoresAndHyphensWithSpaces } from "@settlemint/sdk-utils";
399
+ *
400
+ * const result = replaceUnderscoresAndHyphensWithSpaces("Already_Spaced-Second");
401
+ * // Returns: "Already Spaced Second"
402
+ */
403
+ function replaceUnderscoresAndHyphensWithSpaces(s) {
404
+ return s.replace(/[-_]/g, " ");
405
+ }
406
+ /**
407
+ * Truncates a string to a maximum length and appends "..." if it is longer.
408
+ *
409
+ * @param value - The string to truncate
410
+ * @param maxLength - The maximum length of the string
411
+ * @returns The truncated string or the original string if it is shorter than the maximum length
412
+ *
413
+ * @example
414
+ * import { truncate } from "@settlemint/sdk-utils";
415
+ *
416
+ * const truncated = truncate("Hello, world!", 10);
417
+ * // Returns: "Hello, wor..."
418
+ */
419
+ function truncate(value, maxLength) {
420
+ if (value.length <= maxLength) {
421
+ return value;
422
+ }
423
+ return `${value.slice(0, maxLength)}...`;
238
424
  }
239
425
 
240
- // src/terminal/table.ts
241
- var import_console_table_printer = require("console-table-printer");
242
- var import_yoctocolors7 = require("yoctocolors");
426
+ //#endregion
427
+ //#region src/terminal/table.ts
428
+ /**
429
+ * Displays data in a formatted table in the terminal.
430
+ *
431
+ * @param title - Title to display above the table
432
+ * @param data - Array of objects to display in table format
433
+ * @example
434
+ * import { table } from "@settlemint/sdk-utils/terminal";
435
+ *
436
+ * const data = [
437
+ * { name: "Item 1", value: 100 },
438
+ * { name: "Item 2", value: 200 }
439
+ * ];
440
+ *
441
+ * table("My Table", data);
442
+ */
243
443
  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();
444
+ if (!shouldPrint()) {
445
+ return;
446
+ }
447
+ note(title);
448
+ if (!data || data.length === 0) {
449
+ note("No data to display");
450
+ return;
451
+ }
452
+ const columnKeys = Object.keys(data[0]);
453
+ const table$1 = new console_table_printer.Table({ columns: columnKeys.map((key) => ({
454
+ name: key,
455
+ title: (0, yoctocolors.whiteBright)(camelCaseToWords(key)),
456
+ alignment: "left"
457
+ })) });
458
+ table$1.addRows(data);
459
+ table$1.printTable();
262
460
  }
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
- });
461
+
462
+ //#endregion
463
+ exports.CancelError = CancelError;
464
+ exports.CommandError = CommandError;
465
+ exports.SpinnerError = SpinnerError;
466
+ exports.ascii = ascii;
467
+ exports.cancel = cancel;
468
+ exports.executeCommand = executeCommand;
469
+ exports.intro = intro;
470
+ exports.list = list;
471
+ exports.maskTokens = maskTokens;
472
+ exports.note = note;
473
+ exports.outro = outro;
474
+ exports.spinner = spinner;
475
+ exports.table = table;
279
476
  //# sourceMappingURL=terminal.cjs.map