@tinycloud/cli 1.3.0-beta.37 → 1.3.0-beta.39

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/dist/index.js CHANGED
@@ -152,6 +152,35 @@ var init_constants = __esm({
152
152
  }
153
153
  });
154
154
 
155
+ // src/output/safe-text.ts
156
+ function escape(match) {
157
+ return `\\u{${match.codePointAt(0).toString(16)}}`;
158
+ }
159
+ function safeBlock(text) {
160
+ return text.replace(UNSAFE_BLOCK, escape);
161
+ }
162
+ function safeInline(text) {
163
+ return text.replace(UNSAFE_INLINE, escape);
164
+ }
165
+ function safeClipped(text, max = ECHO_FIELD_MAX) {
166
+ const escaped = Array.from(safeInline(text));
167
+ return escaped.length <= max ? escaped.join("") : `${escaped.slice(0, max).join("")}\u2026`;
168
+ }
169
+ function safeJsonStringify(value, space) {
170
+ const text = JSON.stringify(value, null, space);
171
+ return text === void 0 ? text : text.replace(JSON_UNSAFE, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
172
+ }
173
+ var UNSAFE_BLOCK, UNSAFE_INLINE, ECHO_FIELD_MAX, JSON_UNSAFE;
174
+ var init_safe_text = __esm({
175
+ "src/output/safe-text.ts"() {
176
+ "use strict";
177
+ UNSAFE_BLOCK = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200b-\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069\ufeff]/g;
178
+ UNSAFE_INLINE = /[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069\ufeff]/g;
179
+ ECHO_FIELD_MAX = 80;
180
+ JSON_UNSAFE = /[\u007f-\u009f\u061c\u200b-\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069\ufeff]/g;
181
+ }
182
+ });
183
+
155
184
  // src/output/theme.ts
156
185
  import chalk from "chalk";
157
186
  var TC_PALETTE, theme;
@@ -236,12 +265,12 @@ function outputError(code4, message, hint, details = {}) {
236
265
  const { meta, warnings = [], setup, recovery, progress } = details;
237
266
  if (!shouldOutputJson()) {
238
267
  process.stderr.write(
239
- `${theme.error("\u2717")} ${theme.label(code4)}: ${message}
268
+ `${theme.error("\u2717")} ${theme.label(safeInline(code4))}: ${safeBlock(message)}
240
269
  `
241
270
  );
242
271
  if (hint) {
243
272
  for (const line of hint.split("\n")) {
244
- process.stderr.write(` ${theme.hint(line)}
273
+ process.stderr.write(` ${theme.hint(safeBlock(line))}
245
274
  `);
246
275
  }
247
276
  }
@@ -257,13 +286,13 @@ function outputError(code4, message, hint, details = {}) {
257
286
  if (progress) payload.error.progress = progress;
258
287
  if (meta) payload.error.meta = meta;
259
288
  if (warnings.length > 0) payload.error.warnings = warnings;
260
- process.stderr.write(JSON.stringify(payload, null, 2) + "\n");
289
+ process.stderr.write(safeJsonStringify(payload, 2) + "\n");
261
290
  }
262
291
  }
263
292
  function outputWarnings(warnings) {
264
293
  const combined = mergeWarnings(drainWarnings(), operationWarnings(warnings));
265
294
  if (combined.length === 0) return;
266
- process.stderr.write(shouldOutputJson() ? `${JSON.stringify({ warnings: combined })}
295
+ process.stderr.write(shouldOutputJson() ? `${safeJsonStringify({ warnings: combined })}
267
296
  ` : `${theme.warn("!")} ${warningLine(combined)}
268
297
  `);
269
298
  }
@@ -291,6 +320,7 @@ var WARNING_CODE, WARNING_REASON, DELEGATION_CID, JSON_REQUESTED;
291
320
  var init_formatter = __esm({
292
321
  "src/output/formatter.ts"() {
293
322
  "use strict";
323
+ init_safe_text();
294
324
  init_theme();
295
325
  init_warnings();
296
326
  WARNING_CODE = /^[A-Z][A-Z_]{0,63}$/;
@@ -747,6 +777,13 @@ var init_types = __esm({
747
777
 
748
778
  // src/lib/space.ts
749
779
  import { CLI_NAME as CLI_NAME5 } from "@tinycloud/operations/cli-name";
780
+ function invalidSpaceError(input) {
781
+ return new CLIError(
782
+ "INVALID_SPACE",
783
+ `Invalid space "${safeClipped(input)}". Use a short name ([A-Za-z0-9_-]) or a full tinycloud:... URI.`,
784
+ ExitCode.USAGE_ERROR
785
+ );
786
+ }
750
787
  function canonicalizeAddress(address) {
751
788
  const trimmed = address.trim();
752
789
  return trimmed.startsWith("0x") ? `0x${trimmed.slice(2).toLowerCase()}` : trimmed.toLowerCase();
@@ -804,22 +841,10 @@ async function resolveSpaceUri(input, profileName, options = {}) {
804
841
  if (!effective) return void 0;
805
842
  if (effective.startsWith("tinycloud:")) {
806
843
  const parsed = parseSpaceUri(effective);
807
- if (!parsed) {
808
- throw new CLIError(
809
- "INVALID_SPACE",
810
- `Invalid space "${effective}". Use a short name ([A-Za-z0-9_-]) or a full tinycloud:... URI.`,
811
- ExitCode.USAGE_ERROR
812
- );
813
- }
844
+ if (!parsed) throw invalidSpaceError(effective);
814
845
  return buildSpaceUri(parsed.owner, parsed.name);
815
846
  }
816
- if (!/^[A-Za-z0-9_-]+$/.test(effective)) {
817
- throw new CLIError(
818
- "INVALID_SPACE",
819
- `Invalid space "${effective}". Use a short name ([A-Za-z0-9_-]) or a full tinycloud:... URI.`,
820
- ExitCode.USAGE_ERROR
821
- );
822
- }
847
+ if (!/^[A-Za-z0-9_-]+$/.test(effective)) throw invalidSpaceError(effective);
823
848
  const session = await ProfileManager.getSession(profileName);
824
849
  const address = resolveAddress(profile, session);
825
850
  const chainId = resolveChainId(profile, session);
@@ -830,6 +855,7 @@ var init_space = __esm({
830
855
  "use strict";
831
856
  init_errors();
832
857
  init_constants();
858
+ init_safe_text();
833
859
  init_profiles();
834
860
  }
835
861
  });