pterocli 1.1.4 → 1.2.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.
Files changed (2) hide show
  1. package/dist/cli.js +57 -37
  2. package/package.json +4 -1
package/dist/cli.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "module"; const require = createRequire(import.meta.url);
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -162,9 +163,9 @@ var require_main = __commonJS({
162
163
  const attrs = _instructions(result, key);
163
164
  decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
164
165
  break;
165
- } catch (error46) {
166
+ } catch (error47) {
166
167
  if (i + 1 >= length) {
167
- throw error46;
168
+ throw error47;
168
169
  }
169
170
  }
170
171
  }
@@ -192,13 +193,13 @@ var require_main = __commonJS({
192
193
  let uri;
193
194
  try {
194
195
  uri = new URL(dotenvKey);
195
- } catch (error46) {
196
- if (error46.code === "ERR_INVALID_URL") {
196
+ } catch (error47) {
197
+ if (error47.code === "ERR_INVALID_URL") {
197
198
  const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
198
199
  err.code = "INVALID_DOTENV_KEY";
199
200
  throw err;
200
201
  }
201
- throw error46;
202
+ throw error47;
202
203
  }
203
204
  const key = uri.password;
204
205
  if (!key) {
@@ -344,10 +345,10 @@ var require_main = __commonJS({
344
345
  const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
345
346
  aesgcm.setAuthTag(authTag);
346
347
  return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
347
- } catch (error46) {
348
- const isRange = error46 instanceof RangeError;
349
- const invalidKeyLength = error46.message === "Invalid key length";
350
- const decryptionFailed = error46.message === "Unsupported state or unable to authenticate data";
348
+ } catch (error47) {
349
+ const isRange = error47 instanceof RangeError;
350
+ const invalidKeyLength = error47.message === "Invalid key length";
351
+ const decryptionFailed = error47.message === "Unsupported state or unable to authenticate data";
351
352
  if (isRange || invalidKeyLength) {
352
353
  const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
353
354
  err.code = "INVALID_DOTENV_KEY";
@@ -357,7 +358,7 @@ var require_main = __commonJS({
357
358
  err.code = "DECRYPTION_FAILED";
358
359
  throw err;
359
360
  } else {
360
- throw error46;
361
+ throw error47;
361
362
  }
362
363
  }
363
364
  }
@@ -460,6 +461,7 @@ var require_cli_options = __commonJS({
460
461
 
461
462
  // src/cli.ts
462
463
  import { parseArgs } from "util";
464
+ import * as readline from "readline";
463
465
 
464
466
  // node_modules/zod/v4/classic/external.js
465
467
  var external_exports = {};
@@ -1674,10 +1676,10 @@ var initializer = (inst, def) => {
1674
1676
  };
1675
1677
  var $ZodError = $constructor("$ZodError", initializer);
1676
1678
  var $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
1677
- function flattenError(error46, mapper = (issue2) => issue2.message) {
1679
+ function flattenError(error47, mapper = (issue2) => issue2.message) {
1678
1680
  const fieldErrors = {};
1679
1681
  const formErrors = [];
1680
- for (const sub of error46.issues) {
1682
+ for (const sub of error47.issues) {
1681
1683
  if (sub.path.length > 0) {
1682
1684
  fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1683
1685
  fieldErrors[sub.path[0]].push(mapper(sub));
@@ -1687,10 +1689,10 @@ function flattenError(error46, mapper = (issue2) => issue2.message) {
1687
1689
  }
1688
1690
  return { formErrors, fieldErrors };
1689
1691
  }
1690
- function formatError(error46, mapper = (issue2) => issue2.message) {
1692
+ function formatError(error47, mapper = (issue2) => issue2.message) {
1691
1693
  const fieldErrors = { _errors: [] };
1692
- const processError = (error47) => {
1693
- for (const issue2 of error47.issues) {
1694
+ const processError = (error48) => {
1695
+ for (const issue2 of error48.issues) {
1694
1696
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1695
1697
  issue2.errors.map((issues) => processError({ issues }));
1696
1698
  } else if (issue2.code === "invalid_key") {
@@ -1717,14 +1719,14 @@ function formatError(error46, mapper = (issue2) => issue2.message) {
1717
1719
  }
1718
1720
  }
1719
1721
  };
1720
- processError(error46);
1722
+ processError(error47);
1721
1723
  return fieldErrors;
1722
1724
  }
1723
- function treeifyError(error46, mapper = (issue2) => issue2.message) {
1725
+ function treeifyError(error47, mapper = (issue2) => issue2.message) {
1724
1726
  const result = { errors: [] };
1725
- const processError = (error47, path = []) => {
1727
+ const processError = (error48, path = []) => {
1726
1728
  var _a, _b;
1727
- for (const issue2 of error47.issues) {
1729
+ for (const issue2 of error48.issues) {
1728
1730
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1729
1731
  issue2.errors.map((issues) => processError({ issues }, issue2.path));
1730
1732
  } else if (issue2.code === "invalid_key") {
@@ -1759,7 +1761,7 @@ function treeifyError(error46, mapper = (issue2) => issue2.message) {
1759
1761
  }
1760
1762
  }
1761
1763
  };
1762
- processError(error46);
1764
+ processError(error47);
1763
1765
  return result;
1764
1766
  }
1765
1767
  function toDotPath(_path) {
@@ -1780,9 +1782,9 @@ function toDotPath(_path) {
1780
1782
  }
1781
1783
  return segs.join("");
1782
1784
  }
1783
- function prettifyError(error46) {
1785
+ function prettifyError(error47) {
1784
1786
  const lines = [];
1785
- const issues = [...error46.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
1787
+ const issues = [...error47.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
1786
1788
  for (const issue2 of issues) {
1787
1789
  lines.push(`\u2716 ${issue2.message}`);
1788
1790
  if (issue2.path?.length)
@@ -13059,9 +13061,6 @@ function createServerContext(options) {
13059
13061
  };
13060
13062
  }
13061
13063
 
13062
- // src/cli.ts
13063
- import * as readline from "readline";
13064
-
13065
13064
  // node_modules/dotenv/config.js
13066
13065
  (function() {
13067
13066
  require_main().config(
@@ -13074,6 +13073,9 @@ import * as readline from "readline";
13074
13073
  })();
13075
13074
 
13076
13075
  // src/cli.ts
13076
+ import { join } from "path";
13077
+ import { tmpdir } from "os";
13078
+ import { existsSync, readFileSync, writeFileSync } from "fs";
13077
13079
  var { values, positionals } = parseArgs({
13078
13080
  args: process.argv,
13079
13081
  options: {
@@ -13117,20 +13119,39 @@ var socket = new WebSocket(socketUrl, {
13117
13119
  origin: API_URL
13118
13120
  }
13119
13121
  });
13122
+ socket.addEventListener("open", () => {
13123
+ socket.send(JSON.stringify({ event: "auth", args: [token] }));
13124
+ });
13125
+ var historyFile = join(tmpdir(), "ptcli_history");
13126
+ if (!existsSync(historyFile)) {
13127
+ writeFileSync(historyFile, "");
13128
+ }
13129
+ var history = readFileSync(historyFile, "utf-8").split("\n").filter(Boolean);
13120
13130
  var rl = readline.createInterface({
13121
13131
  input: process.stdin,
13122
13132
  output: process.stdout,
13123
13133
  prompt: "> ",
13124
- terminal: true
13125
- });
13126
- socket.addEventListener("open", () => {
13127
- socket.send(JSON.stringify({ event: "auth", args: [token] }));
13128
- });
13134
+ terminal: true,
13135
+ history,
13136
+ historySize: 100
13137
+ });
13138
+ function log(...args) {
13139
+ readline.clearLine(process.stdout, 0);
13140
+ readline.cursorTo(process.stdout, 0);
13141
+ console.log(...args);
13142
+ rl.prompt();
13143
+ }
13144
+ function error46(...args) {
13145
+ readline.clearLine(process.stdout, 0);
13146
+ readline.cursorTo(process.stdout, 0);
13147
+ console.error(...args);
13148
+ rl.prompt();
13149
+ }
13129
13150
  socket.addEventListener("message", (msg) => {
13130
13151
  const json2 = JSON.parse(msg.data);
13131
13152
  const parseResult = external_exports.safeParse(websocketResponseSchema, json2);
13132
13153
  if (!parseResult.success) {
13133
- console.error(`Error parsing socket event: ${parseResult.error.message}`);
13154
+ error46(`Error parsing socket event: ${parseResult.error.message}`);
13134
13155
  return;
13135
13156
  }
13136
13157
  const data = parseResult.data;
@@ -13138,17 +13159,13 @@ socket.addEventListener("message", (msg) => {
13138
13159
  socket.send(JSON.stringify({ event: "send logs", args: [null] }));
13139
13160
  }
13140
13161
  if (data.event == "console output") {
13141
- readline.cursorTo(process.stdout, 0);
13142
- readline.clearLine(process.stdout, 0);
13143
- console.log(data.args[0]);
13144
- rl.prompt(true);
13162
+ log(data.args[0]);
13145
13163
  }
13146
13164
  });
13147
13165
  socket.addEventListener("close", (e) => {
13148
- console.log(e.reason);
13166
+ error46(e.reason);
13149
13167
  });
13150
13168
  rl.on("line", (line) => {
13151
- console.log("found line", line);
13152
13169
  socket.send(
13153
13170
  JSON.stringify({
13154
13171
  event: "send command",
@@ -13156,3 +13173,6 @@ rl.on("line", (line) => {
13156
13173
  })
13157
13174
  );
13158
13175
  });
13176
+ rl.addListener("history", (history2) => {
13177
+ writeFileSync(historyFile, history2.join("\n"));
13178
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pterocli",
3
3
  "module": "src/cli.ts",
4
- "version": "1.1.4",
4
+ "version": "1.2.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup",
@@ -24,5 +24,8 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@types/node": "^25.2.3"
27
+ },
28
+ "allowScripts": {
29
+ "esbuild@0.27.3": true
27
30
  }
28
31
  }