nvii 1.0.2 → 1.0.3

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/index.js +782 -470
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -937,8 +937,8 @@ var require_command = __commonJS({
937
937
  "use strict";
938
938
  var EventEmitter = require("events").EventEmitter;
939
939
  var childProcess = require("child_process");
940
- var path4 = require("path");
941
- var fs3 = require("fs");
940
+ var path5 = require("path");
941
+ var fs4 = require("fs");
942
942
  var process4 = require("process");
943
943
  var { Argument: Argument2, humanReadableArgName } = require_argument();
944
944
  var { CommanderError: CommanderError2 } = require_error();
@@ -1770,12 +1770,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
1770
1770
  let launchWithNode = false;
1771
1771
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1772
1772
  function findFile(baseDir, baseName) {
1773
- const localBin = path4.resolve(baseDir, baseName);
1774
- if (fs3.existsSync(localBin))
1773
+ const localBin = path5.resolve(baseDir, baseName);
1774
+ if (fs4.existsSync(localBin))
1775
1775
  return localBin;
1776
- if (sourceExt.includes(path4.extname(baseName)))
1776
+ if (sourceExt.includes(path5.extname(baseName)))
1777
1777
  return void 0;
1778
- const foundExt = sourceExt.find((ext) => fs3.existsSync(`${localBin}${ext}`));
1778
+ const foundExt = sourceExt.find((ext) => fs4.existsSync(`${localBin}${ext}`));
1779
1779
  if (foundExt)
1780
1780
  return `${localBin}${foundExt}`;
1781
1781
  return void 0;
@@ -1787,23 +1787,23 @@ Expecting one of '${allowedValues.join("', '")}'`);
1787
1787
  if (this._scriptPath) {
1788
1788
  let resolvedScriptPath;
1789
1789
  try {
1790
- resolvedScriptPath = fs3.realpathSync(this._scriptPath);
1790
+ resolvedScriptPath = fs4.realpathSync(this._scriptPath);
1791
1791
  } catch (err) {
1792
1792
  resolvedScriptPath = this._scriptPath;
1793
1793
  }
1794
- executableDir = path4.resolve(path4.dirname(resolvedScriptPath), executableDir);
1794
+ executableDir = path5.resolve(path5.dirname(resolvedScriptPath), executableDir);
1795
1795
  }
1796
1796
  if (executableDir) {
1797
1797
  let localFile = findFile(executableDir, executableFile);
1798
1798
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
1799
- const legacyName = path4.basename(this._scriptPath, path4.extname(this._scriptPath));
1799
+ const legacyName = path5.basename(this._scriptPath, path5.extname(this._scriptPath));
1800
1800
  if (legacyName !== this._name) {
1801
1801
  localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1802
1802
  }
1803
1803
  }
1804
1804
  executableFile = localFile || executableFile;
1805
1805
  }
1806
- launchWithNode = sourceExt.includes(path4.extname(executableFile));
1806
+ launchWithNode = sourceExt.includes(path5.extname(executableFile));
1807
1807
  let proc;
1808
1808
  if (process4.platform !== "win32") {
1809
1809
  if (launchWithNode) {
@@ -2605,7 +2605,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2605
2605
  * @return {Command}
2606
2606
  */
2607
2607
  nameFromFilename(filename) {
2608
- this._name = path4.basename(filename, path4.extname(filename));
2608
+ this._name = path5.basename(filename, path5.extname(filename));
2609
2609
  return this;
2610
2610
  }
2611
2611
  /**
@@ -2619,10 +2619,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
2619
2619
  * @param {string} [path]
2620
2620
  * @return {string|null|Command}
2621
2621
  */
2622
- executableDir(path5) {
2623
- if (path5 === void 0)
2622
+ executableDir(path6) {
2623
+ if (path6 === void 0)
2624
2624
  return this._executableDir;
2625
- this._executableDir = path5;
2625
+ this._executableDir = path6;
2626
2626
  return this;
2627
2627
  }
2628
2628
  /**
@@ -3979,15 +3979,15 @@ var require_route = __commonJS({
3979
3979
  };
3980
3980
  }
3981
3981
  function wrapConversion(toModel, graph) {
3982
- const path4 = [graph[toModel].parent, toModel];
3982
+ const path5 = [graph[toModel].parent, toModel];
3983
3983
  let fn = conversions[graph[toModel].parent][toModel];
3984
3984
  let cur = graph[toModel].parent;
3985
3985
  while (graph[cur].parent) {
3986
- path4.unshift(graph[cur].parent);
3986
+ path5.unshift(graph[cur].parent);
3987
3987
  fn = link(conversions[graph[cur].parent][cur], fn);
3988
3988
  cur = graph[cur].parent;
3989
3989
  }
3990
- fn.conversion = path4;
3990
+ fn.conversion = path5;
3991
3991
  return fn;
3992
3992
  }
3993
3993
  module2.exports = function(fromModel) {
@@ -9932,7 +9932,7 @@ var require_iso2022 = __commonJS({
9932
9932
  var require_chardet = __commonJS({
9933
9933
  "../../node_modules/.pnpm/chardet@0.7.0/node_modules/chardet/index.js"(exports2, module2) {
9934
9934
  "use strict";
9935
- var fs3 = require("fs");
9935
+ var fs4 = require("fs");
9936
9936
  var utf8 = require_utf8();
9937
9937
  var unicode = require_unicode();
9938
9938
  var mbcs = require_mbcs();
@@ -10006,29 +10006,29 @@ var require_chardet = __commonJS({
10006
10006
  var fd;
10007
10007
  var handler = function(err, buffer) {
10008
10008
  if (fd) {
10009
- fs3.closeSync(fd);
10009
+ fs4.closeSync(fd);
10010
10010
  }
10011
10011
  if (err)
10012
10012
  return cb(err, null);
10013
10013
  cb(null, self.detect(buffer, opts));
10014
10014
  };
10015
10015
  if (opts && opts.sampleSize) {
10016
- fd = fs3.openSync(filepath, "r"), sample = Buffer.allocUnsafe(opts.sampleSize);
10017
- fs3.read(fd, sample, 0, opts.sampleSize, null, function(err) {
10016
+ fd = fs4.openSync(filepath, "r"), sample = Buffer.allocUnsafe(opts.sampleSize);
10017
+ fs4.read(fd, sample, 0, opts.sampleSize, null, function(err) {
10018
10018
  handler(err, sample);
10019
10019
  });
10020
10020
  return;
10021
10021
  }
10022
- fs3.readFile(filepath, handler);
10022
+ fs4.readFile(filepath, handler);
10023
10023
  };
10024
10024
  module2.exports.detectFileSync = function(filepath, opts) {
10025
10025
  if (opts && opts.sampleSize) {
10026
- var fd = fs3.openSync(filepath, "r"), sample2 = Buffer.allocUnsafe(opts.sampleSize);
10027
- fs3.readSync(fd, sample2, 0, opts.sampleSize);
10028
- fs3.closeSync(fd);
10026
+ var fd = fs4.openSync(filepath, "r"), sample2 = Buffer.allocUnsafe(opts.sampleSize);
10027
+ fs4.readSync(fd, sample2, 0, opts.sampleSize);
10028
+ fs4.closeSync(fd);
10029
10029
  return self.detect(sample2, opts);
10030
10030
  }
10031
- return self.detect(fs3.readFileSync(filepath), opts);
10031
+ return self.detect(fs4.readFileSync(filepath), opts);
10032
10032
  };
10033
10033
  module2.exports.detectAll = function(buffer, opts) {
10034
10034
  if (typeof opts !== "object") {
@@ -13514,16 +13514,16 @@ var require_os_tmpdir = __commonJS({
13514
13514
  var isWindows = process.platform === "win32";
13515
13515
  var trailingSlashRe = isWindows ? /[^:]\\$/ : /.\/$/;
13516
13516
  module2.exports = function() {
13517
- var path4;
13517
+ var path5;
13518
13518
  if (isWindows) {
13519
- path4 = process.env.TEMP || process.env.TMP || (process.env.SystemRoot || process.env.windir) + "\\temp";
13519
+ path5 = process.env.TEMP || process.env.TMP || (process.env.SystemRoot || process.env.windir) + "\\temp";
13520
13520
  } else {
13521
- path4 = process.env.TMPDIR || process.env.TMP || process.env.TEMP || "/tmp";
13521
+ path5 = process.env.TMPDIR || process.env.TMP || process.env.TEMP || "/tmp";
13522
13522
  }
13523
- if (trailingSlashRe.test(path4)) {
13524
- path4 = path4.slice(0, -1);
13523
+ if (trailingSlashRe.test(path5)) {
13524
+ path5 = path5.slice(0, -1);
13525
13525
  }
13526
- return path4;
13526
+ return path5;
13527
13527
  };
13528
13528
  }
13529
13529
  });
@@ -13532,8 +13532,8 @@ var require_os_tmpdir = __commonJS({
13532
13532
  var require_tmp = __commonJS({
13533
13533
  "../../node_modules/.pnpm/tmp@0.0.33/node_modules/tmp/lib/tmp.js"(exports2, module2) {
13534
13534
  "use strict";
13535
- var fs3 = require("fs");
13536
- var path4 = require("path");
13535
+ var fs4 = require("fs");
13536
+ var path5 = require("path");
13537
13537
  var crypto = require("crypto");
13538
13538
  var osTmpDir = require_os_tmpdir();
13539
13539
  var _c = process.binding("constants");
@@ -13575,7 +13575,7 @@ var require_tmp = __commonJS({
13575
13575
  }
13576
13576
  function _generateTmpName(opts) {
13577
13577
  if (opts.name) {
13578
- return path4.join(opts.dir || tmpDir, opts.name);
13578
+ return path5.join(opts.dir || tmpDir, opts.name);
13579
13579
  }
13580
13580
  if (opts.template) {
13581
13581
  return opts.template.replace(TEMPLATE_PATTERN, _randomChars(6));
@@ -13586,7 +13586,7 @@ var require_tmp = __commonJS({
13586
13586
  _randomChars(12),
13587
13587
  opts.postfix || ""
13588
13588
  ].join("");
13589
- return path4.join(opts.dir || tmpDir, name);
13589
+ return path5.join(opts.dir || tmpDir, name);
13590
13590
  }
13591
13591
  function tmpName(options, callback) {
13592
13592
  var args = _parseArguments(options, callback), opts = args[0], cb = args[1], tries = opts.name ? 1 : opts.tries || DEFAULT_TRIES;
@@ -13596,7 +13596,7 @@ var require_tmp = __commonJS({
13596
13596
  return cb(new Error("Invalid template provided"));
13597
13597
  (function _getUniqueName() {
13598
13598
  const name = _generateTmpName(opts);
13599
- fs3.stat(name, function(err) {
13599
+ fs4.stat(name, function(err) {
13600
13600
  if (!err) {
13601
13601
  if (tries-- > 0)
13602
13602
  return _getUniqueName();
@@ -13615,7 +13615,7 @@ var require_tmp = __commonJS({
13615
13615
  do {
13616
13616
  const name = _generateTmpName(opts);
13617
13617
  try {
13618
- fs3.statSync(name);
13618
+ fs4.statSync(name);
13619
13619
  } catch (e) {
13620
13620
  return name;
13621
13621
  }
@@ -13628,14 +13628,14 @@ var require_tmp = __commonJS({
13628
13628
  tmpName(opts, function _tmpNameCreated(err, name) {
13629
13629
  if (err)
13630
13630
  return cb(err);
13631
- fs3.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err2, fd) {
13631
+ fs4.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err2, fd) {
13632
13632
  if (err2)
13633
13633
  return cb(err2);
13634
13634
  if (opts.discardDescriptor) {
13635
- return fs3.close(fd, function _discardCallback(err3) {
13635
+ return fs4.close(fd, function _discardCallback(err3) {
13636
13636
  if (err3) {
13637
13637
  try {
13638
- fs3.unlinkSync(name);
13638
+ fs4.unlinkSync(name);
13639
13639
  } catch (e) {
13640
13640
  if (!isENOENT(e)) {
13641
13641
  err3 = e;
@@ -13658,9 +13658,9 @@ var require_tmp = __commonJS({
13658
13658
  opts.postfix = opts.postfix || ".tmp";
13659
13659
  const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
13660
13660
  const name = tmpNameSync(opts);
13661
- var fd = fs3.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
13661
+ var fd = fs4.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
13662
13662
  if (opts.discardDescriptor) {
13663
- fs3.closeSync(fd);
13663
+ fs4.closeSync(fd);
13664
13664
  fd = void 0;
13665
13665
  }
13666
13666
  return {
@@ -13672,9 +13672,9 @@ var require_tmp = __commonJS({
13672
13672
  function _rmdirRecursiveSync(root) {
13673
13673
  const dirs = [root];
13674
13674
  do {
13675
- var dir2 = dirs.pop(), deferred = false, files = fs3.readdirSync(dir2);
13675
+ var dir2 = dirs.pop(), deferred = false, files = fs4.readdirSync(dir2);
13676
13676
  for (var i = 0, length = files.length; i < length; i++) {
13677
- var file2 = path4.join(dir2, files[i]), stat = fs3.lstatSync(file2);
13677
+ var file2 = path5.join(dir2, files[i]), stat = fs4.lstatSync(file2);
13678
13678
  if (stat.isDirectory()) {
13679
13679
  if (!deferred) {
13680
13680
  deferred = true;
@@ -13682,11 +13682,11 @@ var require_tmp = __commonJS({
13682
13682
  }
13683
13683
  dirs.push(file2);
13684
13684
  } else {
13685
- fs3.unlinkSync(file2);
13685
+ fs4.unlinkSync(file2);
13686
13686
  }
13687
13687
  }
13688
13688
  if (!deferred) {
13689
- fs3.rmdirSync(dir2);
13689
+ fs4.rmdirSync(dir2);
13690
13690
  }
13691
13691
  } while (dirs.length !== 0);
13692
13692
  }
@@ -13695,7 +13695,7 @@ var require_tmp = __commonJS({
13695
13695
  tmpName(opts, function _tmpNameCreated(err, name) {
13696
13696
  if (err)
13697
13697
  return cb(err);
13698
- fs3.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err2) {
13698
+ fs4.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err2) {
13699
13699
  if (err2)
13700
13700
  return cb(err2);
13701
13701
  cb(null, name, _prepareTmpDirRemoveCallback(name, opts));
@@ -13705,7 +13705,7 @@ var require_tmp = __commonJS({
13705
13705
  function dirSync(options) {
13706
13706
  var args = _parseArguments(options), opts = args[0];
13707
13707
  const name = tmpNameSync(opts);
13708
- fs3.mkdirSync(name, opts.mode || DIR_MODE);
13708
+ fs4.mkdirSync(name, opts.mode || DIR_MODE);
13709
13709
  return {
13710
13710
  name,
13711
13711
  removeCallback: _prepareTmpDirRemoveCallback(name, opts)
@@ -13715,7 +13715,7 @@ var require_tmp = __commonJS({
13715
13715
  const removeCallback = _prepareRemoveCallback(function _removeCallback(fdPath) {
13716
13716
  try {
13717
13717
  if (0 <= fdPath[0]) {
13718
- fs3.closeSync(fdPath[0]);
13718
+ fs4.closeSync(fdPath[0]);
13719
13719
  }
13720
13720
  } catch (e) {
13721
13721
  if (!isEBADF(e) && !isENOENT(e)) {
@@ -13723,7 +13723,7 @@ var require_tmp = __commonJS({
13723
13723
  }
13724
13724
  }
13725
13725
  try {
13726
- fs3.unlinkSync(fdPath[1]);
13726
+ fs4.unlinkSync(fdPath[1]);
13727
13727
  } catch (e) {
13728
13728
  if (!isENOENT(e)) {
13729
13729
  throw e;
@@ -13736,7 +13736,7 @@ var require_tmp = __commonJS({
13736
13736
  return removeCallback;
13737
13737
  }
13738
13738
  function _prepareTmpDirRemoveCallback(name, opts) {
13739
- const removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs3.rmdirSync.bind(fs3);
13739
+ const removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs4.rmdirSync.bind(fs4);
13740
13740
  const removeCallback = _prepareRemoveCallback(removeFunction, name);
13741
13741
  if (!opts.keep) {
13742
13742
  _removeObjects.unshift(removeCallback);
@@ -23916,103 +23916,13 @@ var {
23916
23916
  Help
23917
23917
  } = import_index.default;
23918
23918
 
23919
- // src/commands/crypt.ts
23920
- var import_env_helpers = require("@nvii/env-helpers");
23921
- var import_picocolors = __toESM(require_picocolors());
23922
- async function testEncryption() {
23923
- try {
23924
- const config = await (0, import_env_helpers.readConfigFile)();
23925
- if (!config?.userId) {
23926
- console.error(
23927
- "You must be logged in to test encryption. Run 'nvii login' first."
23928
- );
23929
- process.exit(1);
23930
- }
23931
- const envs = await (0, import_env_helpers.readEnvFile)();
23932
- const encryptedEnv = (0, import_env_helpers.encryptEnvValues)(envs, config.userId);
23933
- const decryptedEnv = (0, import_env_helpers.decryptEnvValues)(encryptedEnv, config.userId);
23934
- console.log("Encrypted Env:", encryptedEnv);
23935
- console.log("Decrypted Env:", decryptedEnv);
23936
- } catch (error) {
23937
- console.error(import_picocolors.default.red("\nError testing encryption:"), error.message);
23938
- process.exit(1);
23939
- }
23940
- }
23941
-
23942
- // src/commands/generate.ts
23943
- var import_env_helpers2 = require("@nvii/env-helpers");
23919
+ // ../env-helpers/dist/index.mjs
23920
+ var import_crypto = __toESM(require("crypto"), 1);
23944
23921
  var import_fs = require("fs");
23945
- var import_path = require("path");
23946
- var import_picocolors2 = __toESM(require_picocolors());
23947
- async function generateExample(args) {
23948
- let outPutPath = "";
23949
- let resultFormat = "";
23950
- if (args) {
23951
- if (args.format) {
23952
- resultFormat = args.format;
23953
- }
23954
- if (args.output) {
23955
- outPutPath = args.output;
23956
- }
23957
- }
23958
- try {
23959
- const cwd = process.cwd();
23960
- const envPath = (0, import_path.join)(cwd, ".env");
23961
- const envLocalPath = (0, import_path.join)(cwd, ".env.local");
23962
- const examplePath = ".env.example";
23963
- let envContent;
23964
- let sourceFile;
23965
- if ((0, import_fs.existsSync)(envPath)) {
23966
- envContent = (0, import_fs.readFileSync)(envPath, "utf-8");
23967
- sourceFile = ".env";
23968
- } else if ((0, import_fs.existsSync)(envLocalPath)) {
23969
- envContent = (0, import_fs.readFileSync)(envLocalPath, "utf-8");
23970
- sourceFile = ".env.local";
23971
- } else {
23972
- throw new Error(
23973
- "No .env or .env.local file found in the current directory"
23974
- );
23975
- }
23976
- const existingEnvs = await (0, import_env_helpers2.readEnvFile)();
23977
- let newEnvContent = envContent.split("\n").filter((line) => line.trim() !== "").map((line) => {
23978
- if (line.startsWith("#")) {
23979
- return line;
23980
- }
23981
- const key = line.split("=")[0];
23982
- if (!key)
23983
- return null;
23984
- return `${key}=""`;
23985
- }).filter(Boolean).join("\n");
23986
- let filePath = examplePath;
23987
- if (outPutPath && outPutPath.trim() !== "") {
23988
- filePath = outPutPath;
23989
- } else if (resultFormat && resultFormat.trim() !== "") {
23990
- const content = { content: existingEnvs };
23991
- newEnvContent = (0, import_env_helpers2.generateEnvVersion)(content, resultFormat);
23992
- filePath = `${resultFormat === "env" ? examplePath : `.env.${resultFormat}`}`;
23993
- }
23994
- (0, import_fs.writeFileSync)(filePath, newEnvContent);
23995
- console.log(import_picocolors2.default.green("\u2713"), ` Generated ${filePath} file successfully!`);
23996
- console.log(import_picocolors2.default.dim("Source:"), sourceFile);
23997
- console.log(import_picocolors2.default.dim("Location:"), filePath);
23998
- } catch (error) {
23999
- const fileError = error;
24000
- if (fileError.code === "ENOENT") {
24001
- console.error(import_picocolors2.default.red("\u2717"), fileError.message);
24002
- return;
24003
- }
24004
- console.error(
24005
- import_picocolors2.default.red("\u2717"),
24006
- "Failed to generate .env.<format> file:",
24007
- fileError.message
24008
- );
24009
- process.exit(1);
24010
- }
24011
- }
24012
-
24013
- // src/commands/link.ts
24014
- var import_env_helpers4 = require("@nvii/env-helpers");
24015
- var import_fs3 = require("fs");
23922
+ var import_os = __toESM(require("os"), 1);
23923
+ var import_path = __toESM(require("path"), 1);
23924
+ var import_picocolors = __toESM(require_picocolors(), 1);
23925
+ var import_axios = __toESM(require("axios"), 1);
24016
23926
 
24017
23927
  // ../../node_modules/.pnpm/@inquirer+core@10.1.15_@types+node@20.19.9/node_modules/@inquirer/core/dist/esm/lib/key.js
24018
23928
  var isUpKey = (key) => (
@@ -26176,9 +26086,9 @@ var import_run_async = __toESM(require_run_async(), 1);
26176
26086
  var import_mute_stream2 = __toESM(require_lib(), 1);
26177
26087
  var import_ansi_escapes5 = __toESM(require_ansi_escapes(), 1);
26178
26088
  var _ = {
26179
- set: (obj, path4 = "", value) => {
26089
+ set: (obj, path5 = "", value) => {
26180
26090
  let pointer = obj;
26181
- path4.split(".").forEach((key, index, arr) => {
26091
+ path5.split(".").forEach((key, index, arr) => {
26182
26092
  if (key === "__proto__" || key === "constructor")
26183
26093
  return;
26184
26094
  if (index === arr.length - 1) {
@@ -26189,8 +26099,8 @@ var _ = {
26189
26099
  pointer = pointer[key];
26190
26100
  });
26191
26101
  },
26192
- get: (obj, path4 = "", defaultValue) => {
26193
- const travel = (regexp) => String.prototype.split.call(path4, regexp).filter(Boolean).reduce(
26102
+ get: (obj, path5 = "", defaultValue) => {
26103
+ const travel = (regexp) => String.prototype.split.call(path5, regexp).filter(Boolean).reduce(
26194
26104
  // @ts-expect-error implicit any on res[key]
26195
26105
  (res, key) => res == null ? res : res[key],
26196
26106
  obj
@@ -26437,21 +26347,435 @@ var inquirer = {
26437
26347
  };
26438
26348
  var esm_default12 = inquirer;
26439
26349
 
26350
+ // ../env-helpers/dist/index.mjs
26351
+ var API_URLS = {
26352
+ BASE_URL: "https://nvii.bossadizenith.me/api",
26353
+ AUTH_DEVICES_URL: "https://nvii.bossadizenith.me/auth/devices"
26354
+ };
26355
+ var apiClient = import_axios.default.create({
26356
+ baseURL: API_URLS.BASE_URL,
26357
+ headers: {}
26358
+ });
26359
+ async function getConfiguredClient() {
26360
+ const config = await readConfigFile();
26361
+ if (!config) {
26362
+ return apiClient;
26363
+ }
26364
+ return import_axios.default.create({
26365
+ baseURL: API_URLS.BASE_URL,
26366
+ headers: {
26367
+ "X-Auth-Code": config.code,
26368
+ "X-User-Id": config.userId,
26369
+ "X-Device-Id": config.deviceId
26370
+ }
26371
+ });
26372
+ }
26373
+ async function fetchVersions(userId, projectId, limit) {
26374
+ const client = await getConfiguredClient();
26375
+ if (!client) {
26376
+ throw new Error("Failed to obtain configured API client.");
26377
+ }
26378
+ const limitQuery = limit ? `?limit=${limit}` : "";
26379
+ const response = await client.get(
26380
+ `/projects/${userId}/${projectId}/versions${limitQuery}`
26381
+ );
26382
+ return response.data;
26383
+ }
26384
+ function generateDiff(oldContent, newContent) {
26385
+ const oldKeys = new Set(Object.keys(oldContent));
26386
+ const newKeys = new Set(Object.keys(newContent));
26387
+ const added = [...newKeys].filter((key) => !oldKeys.has(key));
26388
+ const removed = [...oldKeys].filter((key) => !newKeys.has(key));
26389
+ const updated = [];
26390
+ for (const key of oldKeys) {
26391
+ if (newKeys.has(key) && oldContent[key] !== newContent[key]) {
26392
+ updated.push([key, { old: oldContent[key], new: newContent[key] }]);
26393
+ }
26394
+ }
26395
+ return { added, removed, updated };
26396
+ }
26397
+ function generateEnvVersion(version, format = "env") {
26398
+ switch (format) {
26399
+ case "json": {
26400
+ let content = {};
26401
+ Object.entries(version.content || {}).map(([key]) => {
26402
+ content = { ...content, [key]: "" };
26403
+ });
26404
+ return JSON.stringify(content, null, 2);
26405
+ }
26406
+ case "yaml":
26407
+ return "nvii:\n" + Object.entries(version.content || {}).map(([key]) => ` ${key}: ${'""'}`).join("\n");
26408
+ case "env":
26409
+ default:
26410
+ return Object.entries(version.content || {}).map(([key]) => `${key}=${'""'}`).join("\n");
26411
+ }
26412
+ }
26413
+ var FILENAME = process.env.FILENAME || ".nvii";
26414
+ var ENCRYPTION_KEY = Buffer.from(
26415
+ process.env.ENCRYPTION_KEY || "KRHW2MSHGJ5HC2KXHFKDKNZSPBATQ4DD",
26416
+ "utf8"
26417
+ ).slice(0, 32);
26418
+ var IV_LENGTH = 16;
26419
+ async function readConfigFile() {
26420
+ try {
26421
+ const homeDir = import_os.default.homedir();
26422
+ const filePath = import_path.default.join(homeDir, FILENAME);
26423
+ const fileContent = await import_fs.promises.readFile(filePath, "utf-8");
26424
+ return JSON.parse(fileContent);
26425
+ } catch (error) {
26426
+ console.error(
26427
+ import_picocolors.default.red("Oups! you're not yet logged-in. run npm install -g @nvii/cli")
26428
+ );
26429
+ return null;
26430
+ }
26431
+ }
26432
+ async function checkLoginStats() {
26433
+ try {
26434
+ const homeDir = import_os.default.homedir();
26435
+ const filePath = import_path.default.join(homeDir, FILENAME);
26436
+ const fileContent = await import_fs.promises.readFile(filePath, "utf-8");
26437
+ if (!fileContent) {
26438
+ return { success: false };
26439
+ }
26440
+ const file = JSON.parse(fileContent);
26441
+ console.log(import_picocolors.default.green(`Logged in as ${file.username} (${file.email})`));
26442
+ return { success: true };
26443
+ } catch (error) {
26444
+ return { success: false };
26445
+ }
26446
+ }
26447
+ function isLogedIn() {
26448
+ const filePath = import_path.default.join(import_os.default.homedir(), FILENAME);
26449
+ return (0, import_fs.existsSync)(filePath);
26450
+ }
26451
+ async function readEnvFile() {
26452
+ try {
26453
+ const envPath = import_path.default.join(process.cwd(), ".env");
26454
+ if (!(0, import_fs.existsSync)(envPath)) {
26455
+ console.log(import_picocolors.default.yellow(".env file not found."));
26456
+ return {};
26457
+ }
26458
+ const envContent = await import_fs.promises.readFile(envPath, "utf-8");
26459
+ return envContent.split("\n").filter((line) => line.trim() && !line.startsWith("#")).reduce(
26460
+ (acc, line) => {
26461
+ const [key, value] = line.replace(/^"(.*)"$/, "$1").split("=");
26462
+ if (key && value) {
26463
+ acc[key.trim()] = value.trim();
26464
+ }
26465
+ return acc;
26466
+ },
26467
+ {}
26468
+ );
26469
+ } catch (error) {
26470
+ console.error(import_picocolors.default.yellow("\u26A0\uFE0F No .env file found or unable to read it."));
26471
+ return {};
26472
+ }
26473
+ }
26474
+ async function writeEnvFile(envs) {
26475
+ try {
26476
+ const envPath = import_path.default.join(process.cwd(), ".env");
26477
+ if (!(0, import_fs.existsSync)(envPath)) {
26478
+ console.log(import_picocolors.default.yellow(".env file not found. A new one will be created."));
26479
+ (0, import_fs.writeFileSync)(envPath, "");
26480
+ }
26481
+ const envContent = await import_fs.promises.readFile(envPath, "utf-8");
26482
+ let newEnvContent = {};
26483
+ Object.entries(envs).map((item) => {
26484
+ envContent.split("\n").map(
26485
+ (line) => {
26486
+ const [key, value] = line.replace(/^"(.*)"$/, "$1").split("=");
26487
+ if (!key && !value && line.startsWith("#")) {
26488
+ newEnvContent = { ...newEnvContent, "#": "" };
26489
+ }
26490
+ if (key && value) {
26491
+ if (line.startsWith("#")) {
26492
+ newEnvContent[key.trim()] = value.trim();
26493
+ } else {
26494
+ if (envs[key.trim()]) {
26495
+ newEnvContent[key.trim()] = envs[key.trim()];
26496
+ }
26497
+ }
26498
+ }
26499
+ },
26500
+ {}
26501
+ );
26502
+ newEnvContent[item[0]] = item[1];
26503
+ });
26504
+ const finalEnvContent = Object.entries(newEnvContent).map(([key, value]) => `${key}=${value}`).join("\n");
26505
+ (0, import_fs.writeFileSync)(envPath, finalEnvContent);
26506
+ return envs;
26507
+ } catch (error) {
26508
+ console.log(import_picocolors.default.red(error));
26509
+ console.error(import_picocolors.default.yellow("\u26A0\uFE0F No .env file found or unable to write in it."));
26510
+ return {};
26511
+ }
26512
+ }
26513
+ function deriveKey(userId) {
26514
+ return import_crypto.default.createHash("sha256").update(ENCRYPTION_KEY).update(userId).digest().slice(0, 32);
26515
+ }
26516
+ function encrypt(text, userId) {
26517
+ const key = deriveKey(userId);
26518
+ const iv = import_crypto.default.randomBytes(IV_LENGTH);
26519
+ const cipher = import_crypto.default.createCipheriv("aes-256-cbc", key, iv);
26520
+ let encrypted = cipher.update(text, "utf8", "hex");
26521
+ encrypted += cipher.final("hex");
26522
+ return iv.toString("hex") + ":" + encrypted;
26523
+ }
26524
+ function decrypt(text, userId) {
26525
+ const key = deriveKey(userId);
26526
+ const textParts = text.split(":");
26527
+ const iv = Buffer.from(textParts[0], "hex");
26528
+ const encryptedText = Buffer.from(textParts[1], "hex");
26529
+ const decipher = import_crypto.default.createDecipheriv("aes-256-cbc", key, iv);
26530
+ let decrypted = decipher.update(encryptedText, void 0, "utf8");
26531
+ decrypted += decipher.final("utf8");
26532
+ return decrypted;
26533
+ }
26534
+ function encryptEnvValues(envObject, userId) {
26535
+ const encryptedEnv = {};
26536
+ for (const key in envObject) {
26537
+ encryptedEnv[key] = encrypt(envObject[key], userId);
26538
+ }
26539
+ return encryptedEnv;
26540
+ }
26541
+ function decryptEnvValues(encryptedEnv, userId) {
26542
+ const decryptedEnv = {};
26543
+ for (const key in encryptedEnv) {
26544
+ decryptedEnv[key] = decrypt(encryptedEnv[key], userId);
26545
+ }
26546
+ return decryptedEnv;
26547
+ }
26548
+ async function readProjectConfig() {
26549
+ try {
26550
+ const currentDir = process.cwd();
26551
+ const enviDirPath = import_path.default.join(currentDir, ".nvii");
26552
+ const enviFilePath = import_path.default.join(enviDirPath, "nvii.json");
26553
+ if (!(0, import_fs.existsSync)(enviDirPath) || !(0, import_fs.existsSync)(enviFilePath)) {
26554
+ console.warn(
26555
+ import_picocolors.default.yellow("No project configuration found. A new one will be created.")
26556
+ );
26557
+ return null;
26558
+ }
26559
+ const fileContent = await import_fs.promises.readFile(enviFilePath, "utf-8");
26560
+ const config = JSON.parse(fileContent);
26561
+ if (!config.projectId) {
26562
+ console.warn(
26563
+ import_picocolors.default.yellow(
26564
+ "\u26A0\uFE0F Invalid project configuration: missing projectId for some projects."
26565
+ )
26566
+ );
26567
+ return null;
26568
+ }
26569
+ return config;
26570
+ } catch (error) {
26571
+ console.error(import_picocolors.default.red("Error reading project configuration:"), error);
26572
+ return null;
26573
+ }
26574
+ }
26575
+ async function updateGitignore() {
26576
+ try {
26577
+ const currentDir = process.cwd();
26578
+ const gitignorePath = import_path.default.join(currentDir, ".gitignore");
26579
+ const enviEntry = ".nvii/";
26580
+ let content = "";
26581
+ if ((0, import_fs.existsSync)(gitignorePath)) {
26582
+ content = await import_fs.promises.readFile(gitignorePath, "utf-8");
26583
+ if (content.split("\n").some((line) => line.trim() === enviEntry)) {
26584
+ return;
26585
+ }
26586
+ if (content.length > 0 && !content.endsWith("\n")) {
26587
+ content += "\n";
26588
+ }
26589
+ }
26590
+ content += `${enviEntry}
26591
+ `;
26592
+ await import_fs.promises.writeFile(gitignorePath, content, "utf-8");
26593
+ console.log(import_picocolors.default.green("\u2705 Updated .gitignore to exclude .nvii folder"));
26594
+ } catch (error) {
26595
+ console.error(import_picocolors.default.red("Error updating .gitignore:"), error);
26596
+ }
26597
+ }
26598
+ async function writeProjectConfig(projectId, branchName) {
26599
+ try {
26600
+ const currentDir = process.cwd();
26601
+ const enviDirPath = import_path.default.join(currentDir, ".nvii");
26602
+ const enviFilePath = import_path.default.join(enviDirPath, "nvii.json");
26603
+ if (!projectId || projectId.trim() === "") {
26604
+ console.log(
26605
+ import_picocolors.default.red(
26606
+ "Invalid project id. To write project config, a valid project Id must be provided."
26607
+ )
26608
+ );
26609
+ process.exit(1);
26610
+ }
26611
+ if (!(0, import_fs.existsSync)(enviDirPath)) {
26612
+ await import_fs.promises.mkdir(enviDirPath, { recursive: true });
26613
+ }
26614
+ await updateGitignore();
26615
+ const updatedConfig = {
26616
+ projectId
26617
+ };
26618
+ if (branchName && branchName.trim() !== "") {
26619
+ updatedConfig.branch = branchName;
26620
+ }
26621
+ await import_fs.promises.writeFile(
26622
+ enviFilePath,
26623
+ JSON.stringify(updatedConfig, null, 2),
26624
+ "utf-8"
26625
+ );
26626
+ console.log(
26627
+ import_picocolors.default.green(
26628
+ `\u2705 Project configuration ${projectId ? "updated" : "saved"} at ${enviFilePath}`
26629
+ )
26630
+ );
26631
+ } catch (error) {
26632
+ console.error(import_picocolors.default.red("Error writing project configuration:"), error);
26633
+ throw error;
26634
+ }
26635
+ }
26636
+ async function unlinkProjectConfig(projectId) {
26637
+ let success = false;
26638
+ try {
26639
+ const currentDir = process.cwd();
26640
+ const enviDirPath = import_path.default.join(currentDir, ".nvii");
26641
+ const enviFilePath = import_path.default.join(enviDirPath, "nvii.json");
26642
+ if ((0, import_fs.existsSync)(enviDirPath)) {
26643
+ if ((0, import_fs.existsSync)(enviFilePath)) {
26644
+ try {
26645
+ const config = await readProjectConfig();
26646
+ if (config) {
26647
+ await import_fs.promises.unlink(enviFilePath);
26648
+ await import_fs.promises.rmdir(enviDirPath);
26649
+ }
26650
+ success = true;
26651
+ } catch (error) {
26652
+ console.warn(import_picocolors.default.yellow("Warning: Could not delete nvii.json."));
26653
+ return success;
26654
+ }
26655
+ }
26656
+ } else {
26657
+ console.warn(import_picocolors.default.yellow("Warning: .nvii directory not found."));
26658
+ return success;
26659
+ }
26660
+ console.log(
26661
+ import_picocolors.default.green(
26662
+ `\u2705 Project configuration for ${projectId} unlinked successfully.`
26663
+ )
26664
+ );
26665
+ return success;
26666
+ } catch (error) {
26667
+ console.error(import_picocolors.default.red("Error writing project configuration:"), error);
26668
+ return success;
26669
+ }
26670
+ }
26671
+
26672
+ // src/commands/crypt.ts
26673
+ var import_picocolors2 = __toESM(require_picocolors());
26674
+ async function testEncryption() {
26675
+ try {
26676
+ const config = await readConfigFile();
26677
+ if (!config?.userId) {
26678
+ console.error(
26679
+ "You must be logged in to test encryption. Run 'nvii login' first."
26680
+ );
26681
+ process.exit(1);
26682
+ }
26683
+ const envs = await readEnvFile();
26684
+ const encryptedEnv = encryptEnvValues(envs, config.userId);
26685
+ const decryptedEnv = decryptEnvValues(encryptedEnv, config.userId);
26686
+ console.log("Encrypted Env:", encryptedEnv);
26687
+ console.log("Decrypted Env:", decryptedEnv);
26688
+ } catch (error) {
26689
+ console.error(import_picocolors2.default.red("\nError testing encryption:"), error.message);
26690
+ process.exit(1);
26691
+ }
26692
+ }
26693
+
26694
+ // src/commands/generate.ts
26695
+ var import_fs2 = require("fs");
26696
+ var import_path2 = require("path");
26697
+ var import_picocolors3 = __toESM(require_picocolors());
26698
+ async function generateExample(args) {
26699
+ let outPutPath = "";
26700
+ let resultFormat = "";
26701
+ if (args) {
26702
+ if (args.format) {
26703
+ resultFormat = args.format;
26704
+ }
26705
+ if (args.output) {
26706
+ outPutPath = args.output;
26707
+ }
26708
+ }
26709
+ try {
26710
+ const cwd = process.cwd();
26711
+ const envPath = (0, import_path2.join)(cwd, ".env");
26712
+ const envLocalPath = (0, import_path2.join)(cwd, ".env.local");
26713
+ const examplePath = ".env.example";
26714
+ let envContent;
26715
+ let sourceFile;
26716
+ if ((0, import_fs2.existsSync)(envPath)) {
26717
+ envContent = (0, import_fs2.readFileSync)(envPath, "utf-8");
26718
+ sourceFile = ".env";
26719
+ } else if ((0, import_fs2.existsSync)(envLocalPath)) {
26720
+ envContent = (0, import_fs2.readFileSync)(envLocalPath, "utf-8");
26721
+ sourceFile = ".env.local";
26722
+ } else {
26723
+ throw new Error(
26724
+ "No .env or .env.local file found in the current directory"
26725
+ );
26726
+ }
26727
+ const existingEnvs = await readEnvFile();
26728
+ let newEnvContent = envContent.split("\n").filter((line) => line.trim() !== "").map((line) => {
26729
+ if (line.startsWith("#")) {
26730
+ return line;
26731
+ }
26732
+ const key = line.split("=")[0];
26733
+ if (!key)
26734
+ return null;
26735
+ return `${key}=""`;
26736
+ }).filter(Boolean).join("\n");
26737
+ let filePath = examplePath;
26738
+ if (outPutPath && outPutPath.trim() !== "") {
26739
+ filePath = outPutPath;
26740
+ } else if (resultFormat && resultFormat.trim() !== "") {
26741
+ const content = { content: existingEnvs };
26742
+ newEnvContent = generateEnvVersion(content, resultFormat);
26743
+ filePath = `${resultFormat === "env" ? examplePath : `.env.${resultFormat}`}`;
26744
+ }
26745
+ (0, import_fs2.writeFileSync)(filePath, newEnvContent);
26746
+ console.log(import_picocolors3.default.green("\u2713"), ` Generated ${filePath} file successfully!`);
26747
+ console.log(import_picocolors3.default.dim("Source:"), sourceFile);
26748
+ console.log(import_picocolors3.default.dim("Location:"), filePath);
26749
+ } catch (error) {
26750
+ const fileError = error;
26751
+ if (fileError.code === "ENOENT") {
26752
+ console.error(import_picocolors3.default.red("\u2717"), fileError.message);
26753
+ return;
26754
+ }
26755
+ console.error(
26756
+ import_picocolors3.default.red("\u2717"),
26757
+ "Failed to generate .env.<format> file:",
26758
+ fileError.message
26759
+ );
26760
+ process.exit(1);
26761
+ }
26762
+ }
26763
+
26440
26764
  // src/commands/link.ts
26441
- var import_path3 = __toESM(require("path"));
26442
- var import_picocolors4 = __toESM(require_picocolors());
26765
+ var import_fs4 = require("fs");
26766
+ var import_path4 = __toESM(require("path"));
26767
+ var import_picocolors5 = __toESM(require_picocolors());
26443
26768
 
26444
26769
  // src/commands/auth/login.ts
26445
- var import_env_helpers3 = require("@nvii/env-helpers");
26446
26770
  var import_async_listen = require("async-listen");
26447
26771
  var import_child_process = require("child_process");
26448
26772
  var import_config = require("dotenv/config");
26449
- var import_fs2 = require("fs");
26773
+ var import_fs3 = require("fs");
26450
26774
  var import_http = __toESM(require("http"));
26451
26775
  var import_nanoid = require("nanoid");
26452
- var import_os = __toESM(require("os"));
26453
- var import_path2 = __toESM(require("path"));
26454
- var import_picocolors3 = __toESM(require_picocolors());
26776
+ var import_os2 = __toESM(require("os"));
26777
+ var import_path3 = __toESM(require("path"));
26778
+ var import_picocolors4 = __toESM(require_picocolors());
26455
26779
  var import_url = __toESM(require("url"));
26456
26780
  var UserCancellationError = class extends Error {
26457
26781
  constructor(message) {
@@ -26461,11 +26785,11 @@ var UserCancellationError = class extends Error {
26461
26785
  };
26462
26786
  async function writeToConfigFile(data) {
26463
26787
  try {
26464
- const homeDir = import_os.default.homedir();
26465
- const filePath = import_path2.default.join(homeDir, import_env_helpers3.FILENAME);
26466
- (0, import_fs2.writeFileSync)(filePath, JSON.stringify(data, null, 2));
26467
- const userData = (0, import_fs2.readFileSync)(filePath, "utf-8");
26468
- const dirname = import_path2.default.dirname(filePath);
26788
+ const homeDir = import_os2.default.homedir();
26789
+ const filePath = import_path3.default.join(homeDir, FILENAME);
26790
+ (0, import_fs3.writeFileSync)(filePath, JSON.stringify(data, null, 2));
26791
+ const userData = (0, import_fs3.readFileSync)(filePath, "utf-8");
26792
+ const dirname = import_path3.default.dirname(filePath);
26469
26793
  return {
26470
26794
  filePath,
26471
26795
  userData,
@@ -26477,7 +26801,7 @@ async function writeToConfigFile(data) {
26477
26801
  }
26478
26802
  var nanoid = (0, import_nanoid.customAlphabet)("123456789QAZWSXEDCRFVTGBYHNUJMIKOLP", 8);
26479
26803
  async function login() {
26480
- const res = await (0, import_env_helpers3.checkLoginStats)();
26804
+ const res = await checkLoginStats();
26481
26805
  if (res?.success) {
26482
26806
  return;
26483
26807
  }
@@ -26506,7 +26830,7 @@ async function login() {
26506
26830
  const isValidCode = parsedUrl.query.authCode === code;
26507
26831
  if (!isValidCode) {
26508
26832
  console.log(
26509
- import_picocolors3.default.yellow(
26833
+ import_picocolors4.default.yellow(
26510
26834
  "Login failed. Use a valid url, refresh your browser and try again."
26511
26835
  )
26512
26836
  );
@@ -26527,14 +26851,14 @@ async function login() {
26527
26851
  });
26528
26852
  const redirect = `http://127.0.0.1:${port}`;
26529
26853
  const code = nanoid();
26530
- const confirmationUrl = new URL(import_env_helpers3.API_URLS.AUTH_DEVICES_URL);
26854
+ const confirmationUrl = new URL(API_URLS.AUTH_DEVICES_URL);
26531
26855
  confirmationUrl.searchParams.append("code", code);
26532
26856
  confirmationUrl.searchParams.append("redirect", redirect);
26533
- console.log(`Confirmation code: ${import_picocolors3.default.bold(code)}
26857
+ console.log(`Confirmation code: ${import_picocolors4.default.bold(code)}
26534
26858
  `);
26535
26859
  console.log(
26536
26860
  `If something goes wrong, copy and paste this URL into your browser:
26537
- ${import_picocolors3.default.bold(confirmationUrl.toString())}
26861
+ ${import_picocolors4.default.bold(confirmationUrl.toString())}
26538
26862
  `
26539
26863
  );
26540
26864
  (0, import_child_process.spawn)("open", [confirmationUrl.toString()]);
@@ -26543,8 +26867,8 @@ ${import_picocolors3.default.bold(confirmationUrl.toString())}
26543
26867
  const authData = await authPromise;
26544
26868
  spinner.stop();
26545
26869
  await writeToConfigFile(authData);
26546
- console.log(import_picocolors3.default.green("Authentication successful!"));
26547
- console.log(`Config saved at: ~/ ${import_env_helpers3.FILENAME}
26870
+ console.log(import_picocolors4.default.green("Authentication successful!"));
26871
+ console.log(`Config saved at: ~/ ${FILENAME}
26548
26872
  `);
26549
26873
  server.close();
26550
26874
  process.exit(0);
@@ -26552,14 +26876,14 @@ ${import_picocolors3.default.bold(confirmationUrl.toString())}
26552
26876
  spinner.stop();
26553
26877
  server.close();
26554
26878
  if (error.response) {
26555
- console.error(import_picocolors3.default.yellow(`
26879
+ console.error(import_picocolors4.default.yellow(`
26556
26880
  ${error.response.data.error}`));
26557
26881
  return;
26558
26882
  }
26559
26883
  if (error instanceof UserCancellationError) {
26560
- console.log(import_picocolors3.default.yellow("Authentication cancelled.\n"));
26884
+ console.log(import_picocolors4.default.yellow("Authentication cancelled.\n"));
26561
26885
  } else {
26562
- console.error(import_picocolors3.default.red("Authentication failed:"), error);
26886
+ console.error(import_picocolors4.default.red("Authentication failed:"), error);
26563
26887
  }
26564
26888
  process.exit(1);
26565
26889
  }
@@ -26567,10 +26891,10 @@ ${error.response.data.error}`));
26567
26891
 
26568
26892
  // src/commands/link.ts
26569
26893
  var createEnvFiles = (enviDirPath, enviFilePath) => {
26570
- if (!(0, import_fs3.existsSync)(enviDirPath)) {
26571
- (0, import_fs3.mkdirSync)(enviDirPath);
26572
- if (!(0, import_fs3.existsSync)(enviFilePath)) {
26573
- (0, import_fs3.writeFileSync)(enviFilePath, "", { encoding: "utf-8" });
26894
+ if (!(0, import_fs4.existsSync)(enviDirPath)) {
26895
+ (0, import_fs4.mkdirSync)(enviDirPath);
26896
+ if (!(0, import_fs4.existsSync)(enviFilePath)) {
26897
+ (0, import_fs4.writeFileSync)(enviFilePath, "", { encoding: "utf-8" });
26574
26898
  }
26575
26899
  }
26576
26900
  console.log("\n");
@@ -26583,25 +26907,25 @@ async function linkProject(args) {
26583
26907
  }
26584
26908
  }
26585
26909
  try {
26586
- if (!(0, import_env_helpers4.isLogedIn)()) {
26587
- console.log(import_picocolors4.default.red("You must be logged in to link a project."));
26910
+ if (!isLogedIn()) {
26911
+ console.log(import_picocolors5.default.red("You must be logged in to link a project."));
26588
26912
  await login();
26589
26913
  return;
26590
26914
  }
26591
- const userConfig = await (0, import_env_helpers4.readConfigFile)();
26915
+ const userConfig = await readConfigFile();
26592
26916
  if (!userConfig?.userId) {
26593
- console.log(import_picocolors4.default.red("No user ID found. Please log in again."));
26917
+ console.log(import_picocolors5.default.red("No user ID found. Please log in again."));
26594
26918
  return;
26595
26919
  }
26596
- const client = await (0, import_env_helpers4.getConfiguredClient)();
26920
+ const client = await getConfiguredClient();
26597
26921
  const currentDir = process.cwd();
26598
- const enviDirPath = import_path3.default.join(currentDir, ".nvii");
26599
- const enviFilePath = import_path3.default.join(enviDirPath, "nvii.json");
26922
+ const enviDirPath = import_path4.default.join(currentDir, ".nvii");
26923
+ const enviFilePath = import_path4.default.join(enviDirPath, "nvii.json");
26600
26924
  const response = await client.get(`/projects/${userConfig.userId}`);
26601
26925
  const projects = response.data;
26602
26926
  if (!projects.length) {
26603
26927
  console.log(
26604
- import_picocolors4.default.yellow("No projects found for this directory. Run 'nvii new'.")
26928
+ import_picocolors5.default.yellow("No projects found for this directory. Run 'nvii new'.")
26605
26929
  );
26606
26930
  return;
26607
26931
  }
@@ -26621,53 +26945,51 @@ async function linkProject(args) {
26621
26945
  }
26622
26946
  const selectedProject = projects.find((proj) => proj.id === projectId);
26623
26947
  if (!selectedProject) {
26624
- console.log(import_picocolors4.default.red(`Project with id <${projectId}> not found.`));
26948
+ console.log(import_picocolors5.default.red(`Project with id <${projectId}> not found.`));
26625
26949
  process.exit(1);
26626
26950
  }
26627
26951
  createEnvFiles(enviDirPath, enviFilePath);
26628
- await (0, import_env_helpers4.writeProjectConfig)(projectId, "main");
26629
- console.log(import_picocolors4.default.green("Project linked successfully!"));
26952
+ await writeProjectConfig(projectId, "main");
26953
+ console.log(import_picocolors5.default.green("Project linked successfully!"));
26630
26954
  } catch (error) {
26631
26955
  if (error.response) {
26632
- console.error(import_picocolors4.default.yellow(`
26956
+ console.error(import_picocolors5.default.yellow(`
26633
26957
  ${error.response.data.error}`));
26634
26958
  return;
26635
26959
  }
26636
26960
  if (error.message.includes("User force closed the prompt with SIGINT")) {
26637
- console.log(import_picocolors4.default.yellow("\nLink process cancelled."));
26961
+ console.log(import_picocolors5.default.yellow("\nLink process cancelled."));
26638
26962
  return;
26639
26963
  }
26640
- console.error(import_picocolors4.default.red("\nError linking project:"), error.message);
26964
+ console.error(import_picocolors5.default.red("\nError linking project:"), error.message);
26641
26965
  process.exit(1);
26642
26966
  }
26643
26967
  }
26644
26968
 
26645
26969
  // src/commands/new.ts
26646
- var import_env_helpers6 = require("@nvii/env-helpers");
26647
- var import_picocolors6 = __toESM(require_picocolors());
26970
+ var import_picocolors7 = __toESM(require_picocolors());
26648
26971
 
26649
26972
  // src/commands/unlink.ts
26650
- var import_env_helpers5 = require("@nvii/env-helpers");
26651
- var import_picocolors5 = __toESM(require_picocolors());
26973
+ var import_picocolors6 = __toESM(require_picocolors());
26652
26974
  async function unlinkProject(checkProjects = true) {
26653
26975
  try {
26654
- if (!(0, import_env_helpers5.isLogedIn)()) {
26655
- console.log(import_picocolors5.default.red("You must be logged in to link a project."));
26976
+ if (!isLogedIn()) {
26977
+ console.log(import_picocolors6.default.red("You must be logged in to link a project."));
26656
26978
  await login();
26657
26979
  return;
26658
26980
  }
26659
- const userConfig = await (0, import_env_helpers5.readConfigFile)();
26981
+ const userConfig = await readConfigFile();
26660
26982
  if (!userConfig?.userId) {
26661
- console.log(import_picocolors5.default.red("No user ID found. Please log in again."));
26983
+ console.log(import_picocolors6.default.red("No user ID found. Please log in again."));
26662
26984
  return;
26663
26985
  }
26664
- const projectConfig = await (0, import_env_helpers5.readProjectConfig)();
26665
- const client = await (0, import_env_helpers5.getConfiguredClient)();
26986
+ const projectConfig = await readProjectConfig();
26987
+ const client = await getConfiguredClient();
26666
26988
  const response = await client.get(`/projects/${userConfig.userId}`);
26667
26989
  const projects = response.data;
26668
26990
  if (checkProjects && !projects.length) {
26669
26991
  console.log(
26670
- import_picocolors5.default.yellow("No projects found for current user. Run 'nvii new'.")
26992
+ import_picocolors6.default.yellow("No projects found for current user. Run 'nvii new'.")
26671
26993
  );
26672
26994
  return;
26673
26995
  }
@@ -26676,7 +26998,7 @@ async function unlinkProject(checkProjects = true) {
26676
26998
  );
26677
26999
  if (checkProjects) {
26678
27000
  if (!project) {
26679
- console.log(import_picocolors5.default.red("Project is not linked to a remote project yet."));
27001
+ console.log(import_picocolors6.default.red("Project is not linked to a remote project yet."));
26680
27002
  return;
26681
27003
  }
26682
27004
  }
@@ -26687,7 +27009,7 @@ async function unlinkProject(checkProjects = true) {
26687
27009
  {
26688
27010
  type: "confirm",
26689
27011
  name: "unLinkProject",
26690
- message: `Are you sure you want to unlink from ${import_picocolors5.default.dim(project?.name)}`
27012
+ message: `Are you sure you want to unlink from ${import_picocolors6.default.dim(project?.name)}`
26691
27013
  }
26692
27014
  ]);
26693
27015
  if (!unLinkProject) {
@@ -26695,27 +27017,27 @@ async function unlinkProject(checkProjects = true) {
26695
27017
  return;
26696
27018
  }
26697
27019
  console.log("\n");
26698
- const result = await (0, import_env_helpers5.unlinkProjectConfig)(project.id);
27020
+ const result = await unlinkProjectConfig(project.id);
26699
27021
  if (!result) {
26700
27022
  console.log(
26701
- import_picocolors5.default.yellow(
27023
+ import_picocolors6.default.yellow(
26702
27024
  "Oops. An error occurred deleting the local .nvii directory. You can delete it manually."
26703
27025
  )
26704
27026
  );
26705
27027
  process.exit(1);
26706
27028
  }
26707
- console.log(import_picocolors5.default.green(`Project unlinked successfully!`));
27029
+ console.log(import_picocolors6.default.green(`Project unlinked successfully!`));
26708
27030
  } catch (error) {
26709
27031
  if (error.response) {
26710
- console.error(import_picocolors5.default.yellow(`
27032
+ console.error(import_picocolors6.default.yellow(`
26711
27033
  ${error.response.data.error}`));
26712
27034
  return;
26713
27035
  }
26714
27036
  if (error.message.includes("User force closed the prompt with SIGINT")) {
26715
- console.log(import_picocolors5.default.yellow("\nUnlink cancelled."));
27037
+ console.log(import_picocolors6.default.yellow("\nUnlink cancelled."));
26716
27038
  return;
26717
27039
  }
26718
- console.error(import_picocolors5.default.red("\nError linking project:"), error.message);
27040
+ console.error(import_picocolors6.default.red("\nError linking project:"), error.message);
26719
27041
  process.exit(1);
26720
27042
  }
26721
27043
  }
@@ -26726,37 +27048,37 @@ async function promptUser(message) {
26726
27048
  {
26727
27049
  type: "input",
26728
27050
  name: "answer",
26729
- message: import_picocolors6.default.cyan(message)
27051
+ message: import_picocolors7.default.cyan(message)
26730
27052
  }
26731
27053
  ]);
26732
27054
  return response.answer.trim();
26733
27055
  }
26734
27056
  async function createProject() {
26735
27057
  try {
26736
- if (!(0, import_env_helpers6.isLogedIn)()) {
26737
- console.log(import_picocolors6.default.red("You must be logged in to create a new project."));
27058
+ if (!isLogedIn()) {
27059
+ console.log(import_picocolors7.default.red("You must be logged in to create a new project."));
26738
27060
  await login();
26739
27061
  }
26740
27062
  const projectName = await promptUser("Enter your project name:");
26741
27063
  if (!projectName) {
26742
- console.error(import_picocolors6.default.red("\u274C Project name cannot be empty."));
27064
+ console.error(import_picocolors7.default.red("\u274C Project name cannot be empty."));
26743
27065
  process.exit(1);
26744
27066
  }
26745
27067
  const projectDescription = await promptUser(
26746
27068
  "Enter project description (optional):"
26747
27069
  );
26748
- const userConfig = await (0, import_env_helpers6.readConfigFile)();
27070
+ const userConfig = await readConfigFile();
26749
27071
  if (!userConfig?.userId || !userConfig?.deviceId) {
26750
27072
  console.error(
26751
- import_picocolors6.default.red("\u274C Invalid user credentials. Please log in again.")
27073
+ import_picocolors7.default.red("\u274C Invalid user credentials. Please log in again.")
26752
27074
  );
26753
27075
  await login();
26754
27076
  return;
26755
27077
  }
26756
- const envs = await (0, import_env_helpers6.readEnvFile)();
26757
- const encryptedEnvs = (0, import_env_helpers6.encryptEnvValues)(envs, userConfig.userId);
27078
+ const envs = await readEnvFile();
27079
+ const encryptedEnvs = encryptEnvValues(envs, userConfig.userId);
26758
27080
  await unlinkProject(false);
26759
- const client = await (0, import_env_helpers6.getConfiguredClient)();
27081
+ const client = await getConfiguredClient();
26760
27082
  const response = await client.post(`/projects/${userConfig.userId}`, {
26761
27083
  name: projectName,
26762
27084
  content: encryptedEnvs,
@@ -26765,100 +27087,98 @@ async function createProject() {
26765
27087
  });
26766
27088
  const projectId = response.data.data.id;
26767
27089
  const branchName = "main";
26768
- await (0, import_env_helpers6.writeProjectConfig)(projectId, branchName);
27090
+ await writeProjectConfig(projectId, branchName);
26769
27091
  } catch (error) {
26770
27092
  if (error.response) {
26771
- console.error(import_picocolors6.default.yellow(`
27093
+ console.error(import_picocolors7.default.yellow(`
26772
27094
  ${error.response.data.error}`));
26773
27095
  return;
26774
27096
  }
26775
27097
  if (error.message.includes("User force closed the prompt with SIGINT")) {
26776
- console.log(import_picocolors6.default.yellow("\nProject create cancelled."));
27098
+ console.log(import_picocolors7.default.yellow("\nProject create cancelled."));
26777
27099
  return;
26778
27100
  }
26779
- console.error(import_picocolors6.default.red("\u274C Error creating project:"), error.message);
27101
+ console.error(import_picocolors7.default.red("\u274C Error creating project:"), error.message);
26780
27102
  process.exit(1);
26781
27103
  }
26782
27104
  }
26783
27105
 
26784
27106
  // src/commands/update.ts
26785
- var import_picocolors7 = __toESM(require_picocolors());
26786
- var import_env_helpers7 = require("@nvii/env-helpers");
27107
+ var import_picocolors8 = __toESM(require_picocolors());
26787
27108
  async function updateProject() {
26788
27109
  try {
26789
- const userData = await (0, import_env_helpers7.readConfigFile)();
26790
- if (!(0, import_env_helpers7.isLogedIn)()) {
26791
- console.log(import_picocolors7.default.red("You must be logged in to update a project."));
27110
+ const userData = await readConfigFile();
27111
+ if (!isLogedIn()) {
27112
+ console.log(import_picocolors8.default.red("You must be logged in to update a project."));
26792
27113
  await login();
26793
27114
  }
26794
27115
  if (!userData) {
26795
- console.log(import_picocolors7.default.red("You must be logged in to update a project."));
27116
+ console.log(import_picocolors8.default.red("You must be logged in to update a project."));
26796
27117
  await login();
26797
27118
  }
26798
- const config = await (0, import_env_helpers7.readProjectConfig)();
27119
+ const config = await readProjectConfig();
26799
27120
  if (!config) {
26800
27121
  console.log(
26801
- import_picocolors7.default.red("Cannot read local .nvii folder currently. Try again.")
27122
+ import_picocolors8.default.red("Cannot read local .nvii folder currently. Try again.")
26802
27123
  );
26803
27124
  process.exit(1);
26804
27125
  }
26805
27126
  const projectId = config.projectId;
26806
27127
  if (!projectId) {
26807
27128
  console.error(
26808
- import_picocolors7.default.red(
27129
+ import_picocolors8.default.red(
26809
27130
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
26810
27131
  )
26811
27132
  );
26812
27133
  process.exit(1);
26813
27134
  }
26814
- const envVars = await (0, import_env_helpers7.readEnvFile)();
26815
- const encryptedEnv = (0, import_env_helpers7.encryptEnvValues)(envVars, userData.userId);
26816
- const client = await (0, import_env_helpers7.getConfiguredClient)();
27135
+ const envVars = await readEnvFile();
27136
+ const encryptedEnv = encryptEnvValues(envVars, userData.userId);
27137
+ const client = await getConfiguredClient();
26817
27138
  const versions = await client.get(
26818
27139
  `/projects/${userData.userId}/${projectId}/versions/latest`
26819
27140
  );
26820
27141
  if (!versions || !versions.data) {
26821
- console.error(import_picocolors7.default.red("\u274C Project not found or no data available."));
27142
+ console.error(import_picocolors8.default.red("\u274C Project not found or no data available."));
26822
27143
  process.exit(1);
26823
27144
  }
26824
27145
  const versionToUpdateTo = versions.data[0];
26825
27146
  if (!versionToUpdateTo.content) {
26826
- console.error(import_picocolors7.default.red("\u274C No content found for this project envs."));
27147
+ console.error(import_picocolors8.default.red("\u274C No content found for this project envs."));
26827
27148
  process.exit(1);
26828
27149
  }
26829
- const decryptedEnv = (0, import_env_helpers7.decryptEnvValues)(
27150
+ const decryptedEnv = decryptEnvValues(
26830
27151
  versionToUpdateTo?.content,
26831
27152
  userData?.userId
26832
27153
  );
26833
- const data = await (0, import_env_helpers7.writeEnvFile)(decryptedEnv);
27154
+ const data = await writeEnvFile(decryptedEnv);
26834
27155
  if (!data) {
26835
27156
  console.error(
26836
- import_picocolors7.default.red("\u274C Failed to write environment variables to .env file.")
27157
+ import_picocolors8.default.red("\u274C Failed to write environment variables to .env file.")
26837
27158
  );
26838
27159
  process.exit(1);
26839
27160
  }
26840
- console.log(import_picocolors7.default.cyan("Updated environment variables:"));
27161
+ console.log(import_picocolors8.default.cyan("Updated environment variables:"));
26841
27162
  console.log(
26842
- import_picocolors7.default.green("\u2705 Project updated successfully with new .env variables.")
27163
+ import_picocolors8.default.green("\u2705 Project updated successfully with new .env variables.")
26843
27164
  );
26844
27165
  } catch (error) {
26845
27166
  if (error.response) {
26846
- console.error(import_picocolors7.default.yellow(`
27167
+ console.error(import_picocolors8.default.yellow(`
26847
27168
  ${error.response.data.error}`));
26848
27169
  return;
26849
27170
  }
26850
27171
  if (error.message.includes("User force closed the prompt with SIGINT")) {
26851
- console.log(import_picocolors7.default.yellow("\nUpdate cancelled."));
27172
+ console.log(import_picocolors8.default.yellow("\nUpdate cancelled."));
26852
27173
  return;
26853
27174
  }
26854
- console.error(import_picocolors7.default.red("\u274C Error updating project:"), error.message);
27175
+ console.error(import_picocolors8.default.red("\u274C Error updating project:"), error.message);
26855
27176
  process.exit(1);
26856
27177
  }
26857
27178
  }
26858
27179
 
26859
27180
  // src/commands/pull.ts
26860
- var import_picocolors8 = __toESM(require_picocolors());
26861
- var import_env_helpers8 = require("@nvii/env-helpers");
27181
+ var import_picocolors9 = __toESM(require_picocolors());
26862
27182
 
26863
27183
  // src/lib/conflict.ts
26864
27184
  function detectConflicts(localEnv, remoteEnv) {
@@ -26910,13 +27230,12 @@ function mergeEnvironments(localEnv, remoteEnv) {
26910
27230
  }
26911
27231
 
26912
27232
  // src/commands/pull.ts
26913
- var import_env_helpers9 = require("@nvii/env-helpers");
26914
27233
  var handleSummary = ({
26915
27234
  projectId,
26916
27235
  localEnvs,
26917
27236
  prevVersion
26918
27237
  }) => {
26919
- const diff = (0, import_env_helpers9.generateDiff)(prevVersion, localEnvs);
27238
+ const diff = generateDiff(prevVersion, localEnvs);
26920
27239
  const changesSummary = {
26921
27240
  added: diff.added,
26922
27241
  modified: diff.updated.map(([key, { old, new: newValue }]) => ({
@@ -26928,35 +27247,35 @@ var handleSummary = ({
26928
27247
  };
26929
27248
  if (changesSummary.added.length > 0 || changesSummary.modified.length > 0 || changesSummary.removed.length > 0) {
26930
27249
  console.log(
26931
- import_picocolors8.default.bold(`
26932
- \u{1F4DC} Change summary for project: ${import_picocolors8.default.cyan(`${projectId}`)}`)
27250
+ import_picocolors9.default.bold(`
27251
+ \u{1F4DC} Change summary for project: ${import_picocolors9.default.cyan(`${projectId}`)}`)
26933
27252
  );
26934
- console.log(import_picocolors8.default.dim("--------------------------------------------------"));
27253
+ console.log(import_picocolors9.default.dim("--------------------------------------------------"));
26935
27254
  changesSummary.added.forEach((key) => {
26936
27255
  console.log(
26937
- `${import_picocolors8.default.yellow(`${key}:`)} added with value: ${localEnvs[key]}`
27256
+ `${import_picocolors9.default.yellow(`${key}:`)} added with value: ${localEnvs[key]}`
26938
27257
  );
26939
27258
  console.log(`Date: ${new Date(Date.now()).toLocaleString()}`);
26940
- console.log(import_picocolors8.default.dim("--------------------------------------------------"));
27259
+ console.log(import_picocolors9.default.dim("--------------------------------------------------"));
26941
27260
  });
26942
27261
  changesSummary.modified.forEach((change) => {
26943
27262
  console.log(
26944
- `${import_picocolors8.default.yellow(`${change.key}:`)} changed from ${change.value} (local) to ${change.original} (remote)`
27263
+ `${import_picocolors9.default.yellow(`${change.key}:`)} changed from ${change.value} (local) to ${change.original} (remote)`
26945
27264
  );
26946
27265
  console.log(`Date: ${new Date(Date.now()).toLocaleString()}`);
26947
- console.log(import_picocolors8.default.dim("--------------------------------------------------"));
27266
+ console.log(import_picocolors9.default.dim("--------------------------------------------------"));
26948
27267
  });
26949
27268
  changesSummary.removed.forEach((key) => {
26950
27269
  console.log(
26951
- `${import_picocolors8.default.yellow(`${key}:`)} deleted with prev value: ${prevVersion[key]}`
27270
+ `${import_picocolors9.default.yellow(`${key}:`)} deleted with prev value: ${prevVersion[key]}`
26952
27271
  );
26953
27272
  console.log(`Date: ${new Date(Date.now()).toLocaleString()}`);
26954
- console.log(import_picocolors8.default.dim("--------------------------------------------------"));
27273
+ console.log(import_picocolors9.default.dim("--------------------------------------------------"));
26955
27274
  });
26956
27275
  } else {
26957
27276
  console.log(
26958
- import_picocolors8.default.bold(`
26959
- No changes detected for project: ${import_picocolors8.default.cyan(`${projectId}`)}`)
27277
+ import_picocolors9.default.bold(`
27278
+ No changes detected for project: ${import_picocolors9.default.cyan(`${projectId}`)}`)
26960
27279
  );
26961
27280
  }
26962
27281
  };
@@ -26976,38 +27295,38 @@ async function pullRemoteChanges(args) {
26976
27295
  }
26977
27296
  }
26978
27297
  try {
26979
- if (!(0, import_env_helpers8.isLogedIn)()) {
26980
- console.log(import_picocolors8.default.red("You must be logged in to pull a project."));
27298
+ if (!isLogedIn()) {
27299
+ console.log(import_picocolors9.default.red("You must be logged in to pull a project."));
26981
27300
  await login();
26982
27301
  return;
26983
27302
  }
26984
- const userConfig = await (0, import_env_helpers8.readConfigFile)();
27303
+ const userConfig = await readConfigFile();
26985
27304
  if (!userConfig?.userId) {
26986
- console.log(import_picocolors8.default.red("No user ID found. Please log in again."));
27305
+ console.log(import_picocolors9.default.red("No user ID found. Please log in again."));
26987
27306
  return;
26988
27307
  }
26989
- const existingEnv = await (0, import_env_helpers8.readEnvFile)();
26990
- const config = await (0, import_env_helpers8.readProjectConfig)();
27308
+ const existingEnv = await readEnvFile();
27309
+ const config = await readProjectConfig();
26991
27310
  if (!config) {
26992
27311
  console.log(
26993
- import_picocolors8.default.red("Cannot read local .nvii folder currently. Try again.")
27312
+ import_picocolors9.default.red("Cannot read local .nvii folder currently. Try again.")
26994
27313
  );
26995
27314
  process.exit(1);
26996
27315
  }
26997
27316
  const projectId = config.projectId;
26998
27317
  if (!projectId) {
26999
27318
  console.error(
27000
- import_picocolors8.default.red(
27319
+ import_picocolors9.default.red(
27001
27320
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27002
27321
  )
27003
27322
  );
27004
27323
  process.exit(1);
27005
27324
  }
27006
- const client = await (0, import_env_helpers8.getConfiguredClient)();
27325
+ const client = await getConfiguredClient();
27007
27326
  const response = await client.get(`/projects/${userConfig.userId}/${projectId}`);
27008
27327
  let { versions, project } = response.data;
27009
27328
  if (!project) {
27010
- console.log(import_picocolors8.default.yellow("No project found for this user or repository."));
27329
+ console.log(import_picocolors9.default.yellow("No project found for this user or repository."));
27011
27330
  process.exit(1);
27012
27331
  }
27013
27332
  versions = versions.sort(
@@ -27015,7 +27334,7 @@ async function pullRemoteChanges(args) {
27015
27334
  );
27016
27335
  const newVersion = versions[versions.length - 1];
27017
27336
  if (!project.content) {
27018
- console.log(import_picocolors8.default.yellow("No content found for this project envs."));
27337
+ console.log(import_picocolors9.default.yellow("No content found for this project envs."));
27019
27338
  process.exit(1);
27020
27339
  }
27021
27340
  if (dryRun) {
@@ -27034,7 +27353,7 @@ async function pullRemoteChanges(args) {
27034
27353
  if (!skipResolve) {
27035
27354
  if (conflicts.length > 0) {
27036
27355
  console.log(
27037
- import_picocolors8.default.yellow(
27356
+ import_picocolors9.default.yellow(
27038
27357
  `
27039
27358
  \u26A0\uFE0F Found ${conflicts.length} conflict(s) between local and remote versions.`
27040
27359
  )
@@ -27052,9 +27371,9 @@ async function pullRemoteChanges(args) {
27052
27371
  );
27053
27372
  }
27054
27373
  }
27055
- const values = await (0, import_env_helpers8.writeEnvFile)(finalContent);
27374
+ const values = await writeEnvFile(finalContent);
27056
27375
  if (!values) {
27057
- console.error(import_picocolors8.default.red("\nOops an unexpected error occurred."));
27376
+ console.error(import_picocolors9.default.red("\nOops an unexpected error occurred."));
27058
27377
  process.exit(1);
27059
27378
  }
27060
27379
  handleSummary({
@@ -27062,54 +27381,53 @@ async function pullRemoteChanges(args) {
27062
27381
  localEnvs: existingEnv,
27063
27382
  prevVersion: finalContent
27064
27383
  });
27065
- console.log(import_picocolors8.default.green(".env file updated successfully!"));
27384
+ console.log(import_picocolors9.default.green(".env file updated successfully!"));
27066
27385
  } catch (error) {
27067
27386
  if (error.response) {
27068
- console.error(import_picocolors8.default.yellow(`
27387
+ console.error(import_picocolors9.default.yellow(`
27069
27388
  ${error.response.data.error}`));
27070
27389
  return;
27071
27390
  }
27072
27391
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27073
- console.log(import_picocolors8.default.yellow("\nPull cancelled."));
27392
+ console.log(import_picocolors9.default.yellow("\nPull cancelled."));
27074
27393
  return;
27075
27394
  }
27076
- console.error(import_picocolors8.default.red("\nError linking project:"), error.message);
27395
+ console.error(import_picocolors9.default.red("\nError linking project:"), error.message);
27077
27396
  process.exit(1);
27078
27397
  }
27079
27398
  }
27080
27399
 
27081
27400
  // src/commands/some.ts
27082
- var import_picocolors9 = __toESM(require_picocolors());
27401
+ var import_picocolors10 = __toESM(require_picocolors());
27083
27402
  async function some() {
27084
27403
  try {
27085
27404
  } catch (error) {
27086
27405
  if (error.response) {
27087
- console.error(import_picocolors9.default.yellow(`
27406
+ console.error(import_picocolors10.default.yellow(`
27088
27407
  ${error.response.data.error}`));
27089
27408
  return;
27090
27409
  }
27091
27410
  console.error(
27092
- import_picocolors9.default.red("\nError merging env branches (versions):"),
27411
+ import_picocolors10.default.red("\nError merging env branches (versions):"),
27093
27412
  error.message
27094
27413
  );
27095
27414
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27096
- console.log(import_picocolors9.default.yellow("\nSome cancelled."));
27415
+ console.log(import_picocolors10.default.yellow("\nSome cancelled."));
27097
27416
  return;
27098
27417
  }
27099
- console.error(import_picocolors9.default.red("Error soming versions:"), error.message);
27418
+ console.error(import_picocolors10.default.red("Error soming versions:"), error.message);
27100
27419
  process.exit(1);
27101
27420
  }
27102
27421
  }
27103
27422
 
27104
27423
  // src/commands/push.ts
27105
- var import_env_helpers10 = require("@nvii/env-helpers");
27106
- var import_picocolors10 = __toESM(require_picocolors());
27424
+ var import_picocolors11 = __toESM(require_picocolors());
27107
27425
  var handleSummary2 = ({
27108
27426
  projectId,
27109
27427
  localEnvs,
27110
27428
  prevVersion
27111
27429
  }) => {
27112
- const diff = (0, import_env_helpers10.generateDiff)(prevVersion, localEnvs);
27430
+ const diff = generateDiff(prevVersion, localEnvs);
27113
27431
  const changesSummary = {
27114
27432
  added: diff.added,
27115
27433
  modified: diff.updated.map(([key, { old, new: newValue }]) => ({
@@ -27121,35 +27439,35 @@ var handleSummary2 = ({
27121
27439
  };
27122
27440
  if (changesSummary.added.length > 0 || changesSummary.modified.length > 0 || changesSummary.removed.length > 0) {
27123
27441
  console.log(
27124
- import_picocolors10.default.bold(`
27125
- \u{1F4DC} Change summary for project: ${import_picocolors10.default.cyan(`${projectId}`)}`)
27442
+ import_picocolors11.default.bold(`
27443
+ \u{1F4DC} Change summary for project: ${import_picocolors11.default.cyan(`${projectId}`)}`)
27126
27444
  );
27127
- console.log(import_picocolors10.default.dim("--------------------------------------------------"));
27445
+ console.log(import_picocolors11.default.dim("--------------------------------------------------"));
27128
27446
  changesSummary.added.forEach((key) => {
27129
27447
  console.log(
27130
- `${import_picocolors10.default.yellow(`${key}:`)} added with value: ${localEnvs[key]}`
27448
+ `${import_picocolors11.default.yellow(`${key}:`)} added with value: ${localEnvs[key]}`
27131
27449
  );
27132
27450
  console.log(`Date: ${new Date(Date.now()).toLocaleString()}`);
27133
- console.log(import_picocolors10.default.dim("--------------------------------------------------"));
27451
+ console.log(import_picocolors11.default.dim("--------------------------------------------------"));
27134
27452
  });
27135
27453
  changesSummary.modified.forEach((change) => {
27136
27454
  console.log(
27137
- `${import_picocolors10.default.yellow(`${change.key}:`)} changed from ${change.original} (remote) to ${change.value} (local)`
27455
+ `${import_picocolors11.default.yellow(`${change.key}:`)} changed from ${change.original} (remote) to ${change.value} (local)`
27138
27456
  );
27139
27457
  console.log(`Date: ${new Date(Date.now()).toLocaleString()}`);
27140
- console.log(import_picocolors10.default.dim("--------------------------------------------------"));
27458
+ console.log(import_picocolors11.default.dim("--------------------------------------------------"));
27141
27459
  });
27142
27460
  changesSummary.removed.forEach((key) => {
27143
27461
  console.log(
27144
- `${import_picocolors10.default.yellow(`${key}:`)} deleted with prev value: ${prevVersion[key]}`
27462
+ `${import_picocolors11.default.yellow(`${key}:`)} deleted with prev value: ${prevVersion[key]}`
27145
27463
  );
27146
27464
  console.log(`Date: ${new Date(Date.now()).toLocaleString()}`);
27147
- console.log(import_picocolors10.default.dim("--------------------------------------------------"));
27465
+ console.log(import_picocolors11.default.dim("--------------------------------------------------"));
27148
27466
  });
27149
27467
  } else {
27150
27468
  console.log(
27151
- import_picocolors10.default.bold(`
27152
- No changes detected for project: ${import_picocolors10.default.cyan(`${projectId}`)}`)
27469
+ import_picocolors11.default.bold(`
27470
+ No changes detected for project: ${import_picocolors11.default.cyan(`${projectId}`)}`)
27153
27471
  );
27154
27472
  }
27155
27473
  };
@@ -27169,24 +27487,24 @@ async function pushLatestChanges(args) {
27169
27487
  }
27170
27488
  }
27171
27489
  try {
27172
- if (!(0, import_env_helpers10.isLogedIn)()) {
27173
- console.log(import_picocolors10.default.red("You must be logged in to push changes."));
27490
+ if (!isLogedIn()) {
27491
+ console.log(import_picocolors11.default.red("You must be logged in to push changes."));
27174
27492
  await login();
27175
27493
  return;
27176
27494
  }
27177
- const userConfig = await (0, import_env_helpers10.readConfigFile)();
27495
+ const userConfig = await readConfigFile();
27178
27496
  if (!userConfig?.userId) {
27179
- console.log(import_picocolors10.default.red("No user ID found. Please log in again."));
27497
+ console.log(import_picocolors11.default.red("No user ID found. Please log in again."));
27180
27498
  return;
27181
27499
  }
27182
- let config = await (0, import_env_helpers10.readProjectConfig)();
27500
+ let config = await readProjectConfig();
27183
27501
  if (!config) {
27184
27502
  await linkProject();
27185
27503
  }
27186
- config = await (0, import_env_helpers10.readProjectConfig)();
27504
+ config = await readProjectConfig();
27187
27505
  if (!config) {
27188
27506
  console.log(
27189
- import_picocolors10.default.red(
27507
+ import_picocolors11.default.red(
27190
27508
  "An error occurred reading local .nvii folder currently. Try again."
27191
27509
  )
27192
27510
  );
@@ -27195,15 +27513,15 @@ async function pushLatestChanges(args) {
27195
27513
  const projectId = config.projectId;
27196
27514
  if (!projectId) {
27197
27515
  console.error(
27198
- import_picocolors10.default.red(
27516
+ import_picocolors11.default.red(
27199
27517
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27200
27518
  )
27201
27519
  );
27202
27520
  process.exit(1);
27203
27521
  }
27204
- const localEnvs = await (0, import_env_helpers10.readEnvFile)();
27522
+ const localEnvs = await readEnvFile();
27205
27523
  if (Object.keys(localEnvs).length === 0) {
27206
- console.log(import_picocolors10.default.yellow("Local .env file is empty. Nothing to push."));
27524
+ console.log(import_picocolors11.default.yellow("Local .env file is empty. Nothing to push."));
27207
27525
  return;
27208
27526
  }
27209
27527
  if (message.trim() === "" && !dryRun) {
@@ -27217,14 +27535,14 @@ async function pushLatestChanges(args) {
27217
27535
  ]);
27218
27536
  message = description;
27219
27537
  }
27220
- const client = await (0, import_env_helpers10.getConfiguredClient)();
27538
+ const client = await getConfiguredClient();
27221
27539
  if (dryRun) {
27222
27540
  const response = await client.get(
27223
27541
  `/projects/${userConfig.userId}/${projectId}/versions`
27224
27542
  );
27225
27543
  if (!response) {
27226
27544
  console.log(
27227
- import_picocolors10.default.red(`bad: unable to access '${process.env.CLIENT_URL}'`)
27545
+ import_picocolors11.default.red(`bad: unable to access '${process.env.CLIENT_URL}'`)
27228
27546
  );
27229
27547
  }
27230
27548
  let versions = response.data;
@@ -27244,26 +27562,25 @@ async function pushLatestChanges(args) {
27244
27562
  message
27245
27563
  });
27246
27564
  console.log(
27247
- import_picocolors10.default.green("\n\u2705 Successfully pushed changes and created a new version.")
27565
+ import_picocolors11.default.green("\n\u2705 Successfully pushed changes and created a new version.")
27248
27566
  );
27249
27567
  } catch (error) {
27250
27568
  if (error.response) {
27251
- console.error(import_picocolors10.default.yellow(`
27569
+ console.error(import_picocolors11.default.yellow(`
27252
27570
  ${error.response.data.error}`));
27253
27571
  return;
27254
27572
  }
27255
27573
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27256
- console.log(import_picocolors10.default.yellow("\nPush cancelled."));
27574
+ console.log(import_picocolors11.default.yellow("\nPush cancelled."));
27257
27575
  return;
27258
27576
  }
27259
- console.error(import_picocolors10.default.red("\nError pushing local changes:"), error.message);
27577
+ console.error(import_picocolors11.default.red("\nError pushing local changes:"), error.message);
27260
27578
  process.exit(1);
27261
27579
  }
27262
27580
  }
27263
27581
 
27264
27582
  // src/commands/history.ts
27265
- var import_env_helpers11 = require("@nvii/env-helpers");
27266
- var import_picocolors11 = __toESM(require_picocolors());
27583
+ var import_picocolors12 = __toESM(require_picocolors());
27267
27584
  async function getHistory(args) {
27268
27585
  let limit = 0;
27269
27586
  let oneline = false;
@@ -27274,12 +27591,12 @@ async function getHistory(args) {
27274
27591
  }
27275
27592
  if (args.limit) {
27276
27593
  if (!Number(args.limit)) {
27277
- console.warn(import_picocolors11.default.yellow("Invalid limit (must be of type number)"));
27594
+ console.warn(import_picocolors12.default.yellow("Invalid limit (must be of type number)"));
27278
27595
  process.exit(1);
27279
27596
  }
27280
27597
  const limitNumber = Number(args.limit);
27281
27598
  if (limitNumber <= 0) {
27282
- console.warn(import_picocolors11.default.yellow("Invalid limit (must be at least 1)"));
27599
+ console.warn(import_picocolors12.default.yellow("Invalid limit (must be at least 1)"));
27283
27600
  process.exit(1);
27284
27601
  }
27285
27602
  limit = limitNumber;
@@ -27289,48 +27606,48 @@ async function getHistory(args) {
27289
27606
  }
27290
27607
  }
27291
27608
  try {
27292
- if (!(0, import_env_helpers11.isLogedIn)()) {
27293
- console.log(import_picocolors11.default.red("You must be logged in to view project history."));
27609
+ if (!isLogedIn()) {
27610
+ console.log(import_picocolors12.default.red("You must be logged in to view project history."));
27294
27611
  await login();
27295
27612
  return;
27296
27613
  }
27297
- const userConfig = await (0, import_env_helpers11.readConfigFile)();
27614
+ const userConfig = await readConfigFile();
27298
27615
  if (!userConfig?.userId) {
27299
- console.log(import_picocolors11.default.red("No user ID found. Please log in again."));
27616
+ console.log(import_picocolors12.default.red("No user ID found. Please log in again."));
27300
27617
  return;
27301
27618
  }
27302
- const config = await (0, import_env_helpers11.readProjectConfig)();
27619
+ const config = await readProjectConfig();
27303
27620
  if (!config) {
27304
27621
  console.log(
27305
- import_picocolors11.default.red("Cannot read local .nvii folder currently. Try again.")
27622
+ import_picocolors12.default.red("Cannot read local .nvii folder currently. Try again.")
27306
27623
  );
27307
27624
  process.exit(1);
27308
27625
  }
27309
27626
  const projectId = config.projectId;
27310
27627
  if (!projectId) {
27311
27628
  console.error(
27312
- import_picocolors11.default.red(
27629
+ import_picocolors12.default.red(
27313
27630
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27314
27631
  )
27315
27632
  );
27316
27633
  process.exit(1);
27317
27634
  }
27318
- const client = await (0, import_env_helpers11.getConfiguredClient)();
27635
+ const client = await getConfiguredClient();
27319
27636
  const response = await client.get(
27320
27637
  `/projects/${userConfig.userId}/${projectId}`
27321
27638
  );
27322
27639
  const project = response.data.project;
27323
27640
  if (!project) {
27324
- console.log(import_picocolors11.default.yellow("No project found for this user or repository."));
27641
+ console.log(import_picocolors12.default.yellow("No project found for this user or repository."));
27325
27642
  process.exit(1);
27326
27643
  }
27327
27644
  if (!project.content) {
27328
- console.log(import_picocolors11.default.yellow("No content found for this project envs."));
27645
+ console.log(import_picocolors12.default.yellow("No content found for this project envs."));
27329
27646
  process.exit(1);
27330
27647
  }
27331
- const versions = await (0, import_env_helpers11.fetchVersions)(userConfig.userId, projectId, limit);
27648
+ const versions = await fetchVersions(userConfig.userId, projectId, limit);
27332
27649
  if (!versions || versions.length === 0) {
27333
- console.log(import_picocolors11.default.yellow("No version history found for this project."));
27650
+ console.log(import_picocolors12.default.yellow("No version history found for this project."));
27334
27651
  return;
27335
27652
  }
27336
27653
  let filteredVersions = versions;
@@ -27339,21 +27656,21 @@ async function getHistory(args) {
27339
27656
  (version) => version.user.email?.toLowerCase().includes(author.toLowerCase()) || version.user.name && version.user.name.toLowerCase().includes(author.toLowerCase())
27340
27657
  );
27341
27658
  if (filteredVersions.length === 0) {
27342
- console.log(import_picocolors11.default.yellow(`No versions found for author: ${author}`));
27659
+ console.log(import_picocolors12.default.yellow(`No versions found for author: ${author}`));
27343
27660
  return;
27344
27661
  }
27345
27662
  }
27346
27663
  console.log(
27347
- import_picocolors11.default.bold(
27664
+ import_picocolors12.default.bold(
27348
27665
  `
27349
- \u{1F4DC} Version history for project ${import_picocolors11.default.cyan(`${project.name} - ${project.id}`)}`
27666
+ \u{1F4DC} Version history for project ${import_picocolors12.default.cyan(`${project.name} - ${project.id}`)}`
27350
27667
  )
27351
27668
  );
27352
27669
  if (author) {
27353
- console.log(import_picocolors11.default.dim(`Filtered by author: ${author}`));
27670
+ console.log(import_picocolors12.default.dim(`Filtered by author: ${author}`));
27354
27671
  }
27355
27672
  if (!oneline) {
27356
- console.log(import_picocolors11.default.dim("--------------------------------------------------"));
27673
+ console.log(import_picocolors12.default.dim("--------------------------------------------------"));
27357
27674
  }
27358
27675
  filteredVersions.forEach((version) => {
27359
27676
  if (oneline) {
@@ -27362,49 +27679,48 @@ async function getHistory(args) {
27362
27679
  const date = new Date(version.createdAt).toLocaleDateString();
27363
27680
  const message = version.description || "No description";
27364
27681
  console.log(
27365
- `${import_picocolors11.default.yellow(shortId)} ${import_picocolors11.default.dim(date)} ${import_picocolors11.default.cyan(author2)} ${message}`
27682
+ `${import_picocolors12.default.yellow(shortId)} ${import_picocolors12.default.dim(date)} ${import_picocolors12.default.cyan(author2)} ${message}`
27366
27683
  );
27367
27684
  } else {
27368
27685
  console.log(
27369
- `${import_picocolors11.default.yellow(`version ${version.id}`)} ${import_picocolors11.default.dim(`(by ${version.user.name || version.user.email})`)}`
27686
+ `${import_picocolors12.default.yellow(`version ${version.id}`)} ${import_picocolors12.default.dim(`(by ${version.user.name || version.user.email})`)}`
27370
27687
  );
27371
27688
  console.log(`Date: ${new Date(version.createdAt).toLocaleString()}`);
27372
27689
  console.log(
27373
- `Message: ${version.description || import_picocolors11.default.dim("No description")}`
27690
+ `Message: ${version.description || import_picocolors12.default.dim("No description")}`
27374
27691
  );
27375
27692
  console.log(
27376
- import_picocolors11.default.dim("--------------------------------------------------")
27693
+ import_picocolors12.default.dim("--------------------------------------------------")
27377
27694
  );
27378
27695
  }
27379
27696
  });
27380
27697
  } catch (error) {
27381
27698
  if (error.response) {
27382
- console.error(import_picocolors11.default.yellow(`
27699
+ console.error(import_picocolors12.default.yellow(`
27383
27700
  ${error.response.data.error}`));
27384
27701
  return;
27385
27702
  }
27386
27703
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27387
- console.log(import_picocolors11.default.yellow("\nHistory log cancelled."));
27704
+ console.log(import_picocolors12.default.yellow("\nHistory log cancelled."));
27388
27705
  return;
27389
27706
  }
27390
- console.error(import_picocolors11.default.red("\nError fetching history:"), error.message);
27707
+ console.error(import_picocolors12.default.red("\nError fetching history:"), error.message);
27391
27708
  process.exit(1);
27392
27709
  }
27393
27710
  }
27394
27711
 
27395
27712
  // src/commands/auth/logout.ts
27396
- var import_env_helpers12 = require("@nvii/env-helpers");
27397
- var import_os2 = __toESM(require("os"));
27398
- var import_path4 = __toESM(require("path"));
27399
- var import_picocolors12 = __toESM(require_picocolors());
27400
- var import_fs4 = __toESM(require("fs"));
27713
+ var import_os3 = __toESM(require("os"));
27714
+ var import_path5 = __toESM(require("path"));
27715
+ var import_picocolors13 = __toESM(require_picocolors());
27716
+ var import_fs5 = __toESM(require("fs"));
27401
27717
  async function logout(args) {
27402
27718
  let username = "";
27403
27719
  let email = "";
27404
27720
  if (args) {
27405
27721
  if (args.username && args.email) {
27406
27722
  console.log(
27407
- import_picocolors12.default.yellow(
27723
+ import_picocolors13.default.yellow(
27408
27724
  "Unexpected input. Ether provide your email or username to logout. NOT BOTH"
27409
27725
  )
27410
27726
  );
@@ -27418,9 +27734,9 @@ async function logout(args) {
27418
27734
  }
27419
27735
  }
27420
27736
  try {
27421
- const config = await (0, import_env_helpers12.readConfigFile)();
27737
+ const config = await readConfigFile();
27422
27738
  if (!config) {
27423
- console.log(import_picocolors12.default.yellow("You are not logged in."));
27739
+ console.log(import_picocolors13.default.yellow("You are not logged in."));
27424
27740
  return;
27425
27741
  }
27426
27742
  if (!username && !email) {
@@ -27455,12 +27771,12 @@ async function logout(args) {
27455
27771
  ]);
27456
27772
  email = userId;
27457
27773
  }
27458
- const homeDir = import_os2.default.homedir();
27459
- const filePath = import_path4.default.join(homeDir, import_env_helpers12.FILENAME);
27774
+ const homeDir = import_os3.default.homedir();
27775
+ const filePath = import_path5.default.join(homeDir, FILENAME);
27460
27776
  if (email) {
27461
27777
  if (config.email !== email) {
27462
27778
  console.log(
27463
- import_picocolors12.default.redBright("Oops, Invalid email. Check your email and try again.")
27779
+ import_picocolors13.default.redBright("Oops, Invalid email. Check your email and try again.")
27464
27780
  );
27465
27781
  process.exit(1);
27466
27782
  }
@@ -27468,7 +27784,7 @@ async function logout(args) {
27468
27784
  if (username) {
27469
27785
  if (config.username !== username) {
27470
27786
  console.log(
27471
- import_picocolors12.default.redBright(
27787
+ import_picocolors13.default.redBright(
27472
27788
  "Oops, Invalid username. Check your username and try again."
27473
27789
  )
27474
27790
  );
@@ -27484,38 +27800,37 @@ async function logout(args) {
27484
27800
  }
27485
27801
  ]);
27486
27802
  if (!confirm) {
27487
- console.log(import_picocolors12.default.yellow("Logout cancelled."));
27803
+ console.log(import_picocolors13.default.yellow("Logout cancelled."));
27488
27804
  return;
27489
27805
  }
27490
- import_fs4.default.unlinkSync(filePath);
27491
- console.log(import_picocolors12.default.green("Successfully logged out!"));
27806
+ import_fs5.default.unlinkSync(filePath);
27807
+ console.log(import_picocolors13.default.green("Successfully logged out!"));
27492
27808
  } catch (error) {
27493
27809
  if (error.response) {
27494
- console.error(import_picocolors12.default.yellow(`
27810
+ console.error(import_picocolors13.default.yellow(`
27495
27811
  ${error.response.data.error}`));
27496
27812
  return;
27497
27813
  }
27498
27814
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27499
- console.log(import_picocolors12.default.yellow("\nLogout cancelled."));
27815
+ console.log(import_picocolors13.default.yellow("\nLogout cancelled."));
27500
27816
  return;
27501
27817
  }
27502
- console.error(import_picocolors12.default.red("Error during logout:"), error.message);
27818
+ console.error(import_picocolors13.default.red("Error during logout:"), error.message);
27503
27819
  process.exit(1);
27504
27820
  }
27505
27821
  }
27506
27822
 
27507
27823
  // src/commands/auth/whoami.ts
27508
- var import_env_helpers13 = require("@nvii/env-helpers");
27509
- var import_picocolors13 = __toESM(require_picocolors());
27824
+ var import_picocolors14 = __toESM(require_picocolors());
27510
27825
  var whoami = async () => {
27511
27826
  try {
27512
- const file = await (0, import_env_helpers13.readConfigFile)();
27827
+ const file = await readConfigFile();
27513
27828
  if (!file)
27514
27829
  return;
27515
- console.log(import_picocolors13.default.green(`Logged in as ${file.username} (${file.email})`));
27830
+ console.log(import_picocolors14.default.green(`Logged in as ${file.username} (${file.email})`));
27516
27831
  } catch (error) {
27517
27832
  if (error.response) {
27518
- console.error(import_picocolors13.default.yellow(`
27833
+ console.error(import_picocolors14.default.yellow(`
27519
27834
  ${error.response.data.error}`));
27520
27835
  return;
27521
27836
  }
@@ -27525,8 +27840,7 @@ ${error.response.data.error}`));
27525
27840
  };
27526
27841
 
27527
27842
  // src/commands/tag.ts
27528
- var import_env_helpers14 = require("@nvii/env-helpers");
27529
- var import_picocolors14 = __toESM(require_picocolors());
27843
+ var import_picocolors15 = __toESM(require_picocolors());
27530
27844
  async function createTag(args) {
27531
27845
  const oraModule = await import("ora");
27532
27846
  const ora = oraModule.spinners.aesthetic;
@@ -27541,40 +27855,40 @@ async function createTag(args) {
27541
27855
  }
27542
27856
  }
27543
27857
  try {
27544
- if (!(0, import_env_helpers14.isLogedIn)()) {
27545
- console.log(import_picocolors14.default.red("You must be logged in to create tags."));
27858
+ if (!isLogedIn()) {
27859
+ console.log(import_picocolors15.default.red("You must be logged in to create tags."));
27546
27860
  await login();
27547
27861
  return;
27548
27862
  }
27549
- const userConfig = await (0, import_env_helpers14.readConfigFile)();
27863
+ const userConfig = await readConfigFile();
27550
27864
  if (!userConfig?.userId) {
27551
- console.log(import_picocolors14.default.red("No user ID found. Please log in again."));
27865
+ console.log(import_picocolors15.default.red("No user ID found. Please log in again."));
27552
27866
  return;
27553
27867
  }
27554
- const config = await (0, import_env_helpers14.readProjectConfig)();
27868
+ const config = await readProjectConfig();
27555
27869
  if (!config) {
27556
27870
  console.log(
27557
- import_picocolors14.default.red("Cannot read local .nvii folder currently. Try again.")
27871
+ import_picocolors15.default.red("Cannot read local .nvii folder currently. Try again.")
27558
27872
  );
27559
27873
  process.exit(1);
27560
27874
  }
27561
27875
  const projectId = config.projectId;
27562
27876
  if (!projectId) {
27563
27877
  console.error(
27564
- import_picocolors14.default.red(
27878
+ import_picocolors15.default.red(
27565
27879
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27566
27880
  )
27567
27881
  );
27568
27882
  process.exit(1);
27569
27883
  }
27570
- const client = await (0, import_env_helpers14.getConfiguredClient)();
27884
+ const client = await getConfiguredClient();
27571
27885
  if (!versionId) {
27572
27886
  const versionsResponse = await client.get(
27573
27887
  `/projects/${userConfig.userId}/${projectId}/versions?limit=1`
27574
27888
  );
27575
27889
  const versions = versionsResponse.data;
27576
27890
  if (versions.length === 0) {
27577
- console.log(import_picocolors14.default.yellow("No versions available to tag."));
27891
+ console.log(import_picocolors15.default.yellow("No versions available to tag."));
27578
27892
  return;
27579
27893
  }
27580
27894
  versionId = versions[0].id;
@@ -27604,87 +27918,86 @@ async function createTag(args) {
27604
27918
  }
27605
27919
  );
27606
27920
  console.log(
27607
- import_picocolors14.default.green(
27921
+ import_picocolors15.default.green(
27608
27922
  `\u2705 Successfully created tag '${tagName}' for version ${versionId?.slice(0, 8)}`
27609
27923
  )
27610
27924
  );
27611
27925
  } catch (error) {
27612
27926
  if (error.response?.status === 409) {
27613
27927
  console.error(
27614
- import_picocolors14.default.red("\u274C Tag name already exists. Choose a different name.")
27928
+ import_picocolors15.default.red("\u274C Tag name already exists. Choose a different name.")
27615
27929
  );
27616
27930
  } else {
27617
- console.error(import_picocolors14.default.red("Error creating tag:"), error.message);
27931
+ console.error(import_picocolors15.default.red("Error creating tag:"), error.message);
27618
27932
  }
27619
27933
  process.exit(1);
27620
27934
  }
27621
27935
  }
27622
27936
  async function listTags() {
27623
27937
  try {
27624
- if (!(0, import_env_helpers14.isLogedIn)()) {
27625
- console.log(import_picocolors14.default.red("You must be logged in to list tags."));
27938
+ if (!isLogedIn()) {
27939
+ console.log(import_picocolors15.default.red("You must be logged in to list tags."));
27626
27940
  await login();
27627
27941
  return;
27628
27942
  }
27629
- const userConfig = await (0, import_env_helpers14.readConfigFile)();
27943
+ const userConfig = await readConfigFile();
27630
27944
  if (!userConfig?.userId) {
27631
- console.log(import_picocolors14.default.red("No user ID found. Please log in again."));
27945
+ console.log(import_picocolors15.default.red("No user ID found. Please log in again."));
27632
27946
  return;
27633
27947
  }
27634
- const config = await (0, import_env_helpers14.readProjectConfig)();
27948
+ const config = await readProjectConfig();
27635
27949
  if (!config) {
27636
27950
  console.log(
27637
- import_picocolors14.default.red("Cannot read local .nvii folder currently. Try again.")
27951
+ import_picocolors15.default.red("Cannot read local .nvii folder currently. Try again.")
27638
27952
  );
27639
27953
  process.exit(1);
27640
27954
  }
27641
27955
  const projectId = config.projectId;
27642
27956
  if (!projectId) {
27643
27957
  console.error(
27644
- import_picocolors14.default.red(
27958
+ import_picocolors15.default.red(
27645
27959
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27646
27960
  )
27647
27961
  );
27648
27962
  process.exit(1);
27649
27963
  }
27650
- const client = await (0, import_env_helpers14.getConfiguredClient)();
27964
+ const client = await getConfiguredClient();
27651
27965
  const response = await client.get(
27652
27966
  `/projects/${userConfig.userId}/${projectId}/versions/tags`
27653
27967
  );
27654
27968
  const tags = response.data;
27655
27969
  if (!tags || tags.length === 0) {
27656
- console.log(import_picocolors14.default.yellow("No tags found for this project."));
27970
+ console.log(import_picocolors15.default.yellow("No tags found for this project."));
27657
27971
  return;
27658
27972
  }
27659
- console.log(import_picocolors14.default.bold(`
27660
- \u{1F3F7}\uFE0F Tags for project ${import_picocolors14.default.cyan(projectId)}`));
27661
- console.log(import_picocolors14.default.dim("--------------------------------------------------"));
27973
+ console.log(import_picocolors15.default.bold(`
27974
+ \u{1F3F7}\uFE0F Tags for project ${import_picocolors15.default.cyan(projectId)}`));
27975
+ console.log(import_picocolors15.default.dim("--------------------------------------------------"));
27662
27976
  tags.forEach((tag) => {
27663
27977
  console.log(
27664
- `${import_picocolors14.default.yellow(tag.name)} -> ${import_picocolors14.default.dim(`version ${tag.versionId.slice(0, 8)}`)}`
27978
+ `${import_picocolors15.default.yellow(tag.name)} -> ${import_picocolors15.default.dim(`version ${tag.versionId.slice(0, 8)}`)}`
27665
27979
  );
27666
27980
  console.log(` ${tag.description || "No description"}`);
27667
27981
  console.log(` ${new Date(tag.createdAt).toLocaleDateString()}`);
27668
- console.log(import_picocolors14.default.dim("--------------------------------------------------"));
27982
+ console.log(import_picocolors15.default.dim("--------------------------------------------------"));
27669
27983
  });
27670
27984
  } catch (error) {
27671
27985
  if (error.response) {
27672
- console.error(import_picocolors14.default.yellow(`
27986
+ console.error(import_picocolors15.default.yellow(`
27673
27987
  ${error.response.data.error}`));
27674
27988
  return;
27675
27989
  }
27676
27990
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27677
- console.log(import_picocolors14.default.yellow("\nTag cancelled."));
27991
+ console.log(import_picocolors15.default.yellow("\nTag cancelled."));
27678
27992
  return;
27679
27993
  }
27680
- console.error(import_picocolors14.default.red("Error listing tags:"), error.message);
27994
+ console.error(import_picocolors15.default.red("Error listing tags:"), error.message);
27681
27995
  process.exit(1);
27682
27996
  }
27683
27997
  }
27684
27998
 
27685
27999
  // src/commands/branch.ts
27686
- var import_env_helpers15 = require("@nvii/env-helpers");
27687
- var import_picocolors15 = __toESM(require_picocolors());
28000
+ var import_picocolors16 = __toESM(require_picocolors());
27688
28001
  async function createBranch(args) {
27689
28002
  let branchName = "";
27690
28003
  let baseVersionId = "";
@@ -27697,33 +28010,33 @@ async function createBranch(args) {
27697
28010
  }
27698
28011
  }
27699
28012
  try {
27700
- if (!(0, import_env_helpers15.isLogedIn)()) {
27701
- console.log(import_picocolors15.default.red("You must be logged in to create branches."));
28013
+ if (!isLogedIn()) {
28014
+ console.log(import_picocolors16.default.red("You must be logged in to create branches."));
27702
28015
  await login();
27703
28016
  return;
27704
28017
  }
27705
- const userConfig = await (0, import_env_helpers15.readConfigFile)();
28018
+ const userConfig = await readConfigFile();
27706
28019
  if (!userConfig?.userId) {
27707
- console.log(import_picocolors15.default.red("No user ID found. Please log in again."));
28020
+ console.log(import_picocolors16.default.red("No user ID found. Please log in again."));
27708
28021
  return;
27709
28022
  }
27710
- const config = await (0, import_env_helpers15.readProjectConfig)();
28023
+ const config = await readProjectConfig();
27711
28024
  if (!config) {
27712
28025
  console.log(
27713
- import_picocolors15.default.red("Cannot read local .nvii folder currently. Try again.")
28026
+ import_picocolors16.default.red("Cannot read local .nvii folder currently. Try again.")
27714
28027
  );
27715
28028
  process.exit(1);
27716
28029
  }
27717
28030
  const projectId = config.projectId;
27718
28031
  if (!projectId) {
27719
28032
  console.error(
27720
- import_picocolors15.default.red(
28033
+ import_picocolors16.default.red(
27721
28034
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27722
28035
  )
27723
28036
  );
27724
28037
  process.exit(1);
27725
28038
  }
27726
- const client = await (0, import_env_helpers15.getConfiguredClient)();
28039
+ const client = await getConfiguredClient();
27727
28040
  if (!branchName) {
27728
28041
  const { inputBranchName } = await esm_default12.prompt([
27729
28042
  {
@@ -27747,7 +28060,7 @@ async function createBranch(args) {
27747
28060
  );
27748
28061
  const versions = versionsResponse.data;
27749
28062
  if (versions.length === 0) {
27750
- console.log(import_picocolors15.default.yellow("No versions available to branch from."));
28063
+ console.log(import_picocolors16.default.yellow("No versions available to branch from."));
27751
28064
  return;
27752
28065
  }
27753
28066
  baseVersionId = versions[0].id;
@@ -27761,21 +28074,21 @@ async function createBranch(args) {
27761
28074
  }
27762
28075
  );
27763
28076
  if (!response || !response.data) {
27764
- console.log(import_picocolors15.default.yellow("Oops an error occurred creating new branch."));
28077
+ console.log(import_picocolors16.default.yellow("Oops an error occurred creating new branch."));
27765
28078
  process.exit(1);
27766
28079
  }
27767
28080
  console.log(
27768
- import_picocolors15.default.green(
28081
+ import_picocolors16.default.green(
27769
28082
  `\u2705 Successfully created branch '${branchName}' from version ${baseVersionId?.slice(0, 8)}`
27770
28083
  )
27771
28084
  );
27772
28085
  } catch (error) {
27773
28086
  if (error.response?.status === 409) {
27774
28087
  console.error(
27775
- import_picocolors15.default.red("\u274C Branch name already exists. Choose a different name.")
28088
+ import_picocolors16.default.red("\u274C Branch name already exists. Choose a different name.")
27776
28089
  );
27777
28090
  } else {
27778
- console.error(import_picocolors15.default.red("Error creating branch:"), error.message);
28091
+ console.error(import_picocolors16.default.red("Error creating branch:"), error.message);
27779
28092
  }
27780
28093
  process.exit(1);
27781
28094
  }
@@ -27784,33 +28097,33 @@ async function listBranches() {
27784
28097
  const oraModule = await import("ora");
27785
28098
  const ora = oraModule.default;
27786
28099
  try {
27787
- if (!(0, import_env_helpers15.isLogedIn)()) {
27788
- console.log(import_picocolors15.default.red("You must be logged in to list branches."));
28100
+ if (!isLogedIn()) {
28101
+ console.log(import_picocolors16.default.red("You must be logged in to list branches."));
27789
28102
  await login();
27790
28103
  return;
27791
28104
  }
27792
- const userConfig = await (0, import_env_helpers15.readConfigFile)();
28105
+ const userConfig = await readConfigFile();
27793
28106
  if (!userConfig?.userId) {
27794
- console.log(import_picocolors15.default.red("No user ID found. Please log in again."));
28107
+ console.log(import_picocolors16.default.red("No user ID found. Please log in again."));
27795
28108
  return;
27796
28109
  }
27797
- const config = await (0, import_env_helpers15.readProjectConfig)();
28110
+ const config = await readProjectConfig();
27798
28111
  if (!config) {
27799
28112
  console.log(
27800
- import_picocolors15.default.red("Cannot read local .nvii folder currently. Try again.")
28113
+ import_picocolors16.default.red("Cannot read local .nvii folder currently. Try again.")
27801
28114
  );
27802
28115
  process.exit(1);
27803
28116
  }
27804
28117
  const projectId = config.projectId;
27805
28118
  if (!projectId) {
27806
28119
  console.error(
27807
- import_picocolors15.default.red(
28120
+ import_picocolors16.default.red(
27808
28121
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27809
28122
  )
27810
28123
  );
27811
28124
  process.exit(1);
27812
28125
  }
27813
- const client = await (0, import_env_helpers15.getConfiguredClient)();
28126
+ const client = await getConfiguredClient();
27814
28127
  const spinner = ora("Fetching project branches...\n").start();
27815
28128
  const response = await client.get(
27816
28129
  `/projects/${userConfig.userId}/${projectId}/versions/branches`
@@ -27818,34 +28131,34 @@ async function listBranches() {
27818
28131
  spinner.stop();
27819
28132
  const branches = response.data;
27820
28133
  if (!branches || branches.length === 0) {
27821
- console.log(import_picocolors15.default.yellow("No branches found for this project."));
28134
+ console.log(import_picocolors16.default.yellow("No branches found for this project."));
27822
28135
  return;
27823
28136
  }
27824
- console.log(import_picocolors15.default.bold(`
27825
- \u{1F33F} Branches for project ${import_picocolors15.default.cyan(projectId)}`));
27826
- console.log(import_picocolors15.default.dim("--------------------------------------------------"));
27827
- const projectConfig = await (0, import_env_helpers15.readProjectConfig)();
28137
+ console.log(import_picocolors16.default.bold(`
28138
+ \u{1F33F} Branches for project ${import_picocolors16.default.cyan(projectId)}`));
28139
+ console.log(import_picocolors16.default.dim("--------------------------------------------------"));
28140
+ const projectConfig = await readProjectConfig();
27828
28141
  branches.forEach((branch) => {
27829
- const isActive = branch.isActive ? import_picocolors15.default.green("* ") : " ";
28142
+ const isActive = branch.isActive ? import_picocolors16.default.green("* ") : " ";
27830
28143
  console.log(
27831
- `${isActive}${import_picocolors15.default.cyan(projectConfig?.branch === branch.name ? `*${branch.name}` : branch.name)} -> ${import_picocolors15.default.dim(`version ${branch.baseVersionId.slice(0, 8)}`)}`
28144
+ `${isActive}${import_picocolors16.default.cyan(projectConfig?.branch === branch.name ? `*${branch.name}` : branch.name)} -> ${import_picocolors16.default.dim(`version ${branch.baseVersionId.slice(0, 8)}`)}`
27832
28145
  );
27833
28146
  console.log(
27834
28147
  ` Created: ${new Date(branch.createdAt).toLocaleDateString()}`
27835
28148
  );
27836
- console.log(import_picocolors15.default.dim("--------------------------------------------------"));
28149
+ console.log(import_picocolors16.default.dim("--------------------------------------------------"));
27837
28150
  });
27838
28151
  } catch (error) {
27839
28152
  if (error.response) {
27840
- console.error(import_picocolors15.default.yellow(`
28153
+ console.error(import_picocolors16.default.yellow(`
27841
28154
  ${error.response.data.error}`));
27842
28155
  return;
27843
28156
  }
27844
28157
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27845
- console.log(import_picocolors15.default.yellow("\nBranch create cancelled."));
28158
+ console.log(import_picocolors16.default.yellow("\nBranch create cancelled."));
27846
28159
  return;
27847
28160
  }
27848
- console.error(import_picocolors15.default.red("Error listing branches:"), error.message);
28161
+ console.error(import_picocolors16.default.red("Error listing branches:"), error.message);
27849
28162
  process.exit(1);
27850
28163
  }
27851
28164
  }
@@ -27857,40 +28170,40 @@ async function switchBranch(args) {
27857
28170
  }
27858
28171
  }
27859
28172
  try {
27860
- if (!(0, import_env_helpers15.isLogedIn)()) {
27861
- console.log(import_picocolors15.default.red("You must be logged in to switch branches."));
28173
+ if (!isLogedIn()) {
28174
+ console.log(import_picocolors16.default.red("You must be logged in to switch branches."));
27862
28175
  await login();
27863
28176
  return;
27864
28177
  }
27865
- const userConfig = await (0, import_env_helpers15.readConfigFile)();
28178
+ const userConfig = await readConfigFile();
27866
28179
  if (!userConfig?.userId) {
27867
- console.log(import_picocolors15.default.red("No user ID found. Please log in again."));
28180
+ console.log(import_picocolors16.default.red("No user ID found. Please log in again."));
27868
28181
  return;
27869
28182
  }
27870
- const config = await (0, import_env_helpers15.readProjectConfig)();
28183
+ const config = await readProjectConfig();
27871
28184
  if (!config) {
27872
28185
  console.log(
27873
- import_picocolors15.default.red("Cannot read local .nvii folder currently. Try again.")
28186
+ import_picocolors16.default.red("Cannot read local .nvii folder currently. Try again.")
27874
28187
  );
27875
28188
  process.exit(1);
27876
28189
  }
27877
28190
  const projectId = config.projectId;
27878
28191
  if (!projectId) {
27879
28192
  console.error(
27880
- import_picocolors15.default.red(
28193
+ import_picocolors16.default.red(
27881
28194
  "\u274C Project not linked. Please run 'nvii link' to link your project first."
27882
28195
  )
27883
28196
  );
27884
28197
  process.exit(1);
27885
28198
  }
27886
- const client = await (0, import_env_helpers15.getConfiguredClient)();
28199
+ const client = await getConfiguredClient();
27887
28200
  if (!branchName) {
27888
28201
  const branchesResponse = await client.get(
27889
28202
  `/projects/${userConfig.userId}/${projectId}/versions/branches`
27890
28203
  );
27891
28204
  const branches = branchesResponse.data;
27892
28205
  if (!branches || branches.length === 0) {
27893
- console.log(import_picocolors15.default.yellow("No branches found for this project."));
28206
+ console.log(import_picocolors16.default.yellow("No branches found for this project."));
27894
28207
  return;
27895
28208
  }
27896
28209
  const { selectedBranch } = await esm_default12.prompt([
@@ -27910,41 +28223,40 @@ async function switchBranch(args) {
27910
28223
  `/projects/${userConfig.userId}/${projectId}/versions/branches/${branchName}`
27911
28224
  );
27912
28225
  branchName = remoteUpdateResponse.data.name;
27913
- await (0, import_env_helpers15.writeProjectConfig)(projectId, branchName);
27914
- console.log(import_picocolors15.default.green(`\u2705 Switched to branch '${branchName}'`));
28226
+ await writeProjectConfig(projectId, branchName);
28227
+ console.log(import_picocolors16.default.green(`\u2705 Switched to branch '${branchName}'`));
27915
28228
  } catch (error) {
27916
28229
  if (error.response) {
27917
- console.error(import_picocolors15.default.yellow(`
28230
+ console.error(import_picocolors16.default.yellow(`
27918
28231
  ${error.response.data.error}`));
27919
28232
  return;
27920
28233
  }
27921
28234
  if (error.message.includes("User force closed the prompt with SIGINT")) {
27922
- console.log(import_picocolors15.default.yellow("\nBranch switch cancelled."));
28235
+ console.log(import_picocolors16.default.yellow("\nBranch switch cancelled."));
27923
28236
  return;
27924
28237
  }
27925
28238
  if (error.response?.status === 404) {
27926
- console.error(import_picocolors15.default.red("\u274C Branch not found."));
28239
+ console.error(import_picocolors16.default.red("\u274C Branch not found."));
27927
28240
  } else {
27928
- console.error(import_picocolors15.default.red("Error switching branch:"), error.message);
28241
+ console.error(import_picocolors16.default.red("Error switching branch:"), error.message);
27929
28242
  }
27930
28243
  process.exit(1);
27931
28244
  }
27932
28245
  }
27933
28246
 
27934
28247
  // src/commands/rollback.ts
27935
- var import_env_helpers16 = require("@nvii/env-helpers");
27936
- var import_picocolors16 = __toESM(require_picocolors());
28248
+ var import_picocolors17 = __toESM(require_picocolors());
27937
28249
  var skipConfirmationPrompt = async (skipConfirmation, description, id) => {
27938
28250
  if (!skipConfirmation) {
27939
28251
  const { confirmRollback } = await esm_default12.prompt([
27940
28252
  {
27941
28253
  type: "confirm",
27942
28254
  name: "confirmRollback",
27943
- message: `Are you sure you want to rollback to <${import_picocolors16.default.dim(`${description} - id: ${id}`)}>?`
28255
+ message: `Are you sure you want to rollback to <${import_picocolors17.default.dim(`${description} - id: ${id}`)}>?`
27944
28256
  }
27945
28257
  ]);
27946
28258
  if (!confirmRollback) {
27947
- console.log(import_picocolors16.default.cyan("Skipping rollback..."));
28259
+ console.log(import_picocolors17.default.cyan("Skipping rollback..."));
27948
28260
  process.exit(0);
27949
28261
  }
27950
28262
  }
@@ -27961,36 +28273,36 @@ async function rollback(args) {
27961
28273
  }
27962
28274
  }
27963
28275
  try {
27964
- if (!(0, import_env_helpers16.isLogedIn)()) {
27965
- console.log(import_picocolors16.default.red("You must be logged in to roll back."));
28276
+ if (!isLogedIn()) {
28277
+ console.log(import_picocolors17.default.red("You must be logged in to roll back."));
27966
28278
  await login();
27967
28279
  return;
27968
28280
  }
27969
- const userConfig = await (0, import_env_helpers16.readConfigFile)();
27970
- const config = await (0, import_env_helpers16.readProjectConfig)();
28281
+ const userConfig = await readConfigFile();
28282
+ const config = await readProjectConfig();
27971
28283
  if (!config) {
27972
28284
  console.log(
27973
- import_picocolors16.default.red("Cannot read local .nvii folder currently. Try again.")
28285
+ import_picocolors17.default.red("Cannot read local .nvii folder currently. Try again.")
27974
28286
  );
27975
28287
  process.exit(1);
27976
28288
  }
27977
28289
  const projectId = config.projectId;
27978
28290
  if (!userConfig?.userId || !projectId) {
27979
28291
  console.error(
27980
- import_picocolors16.default.red(
28292
+ import_picocolors17.default.red(
27981
28293
  "Project not linked or user not configured. Please run 'nvii link'."
27982
28294
  )
27983
28295
  );
27984
28296
  process.exit(1);
27985
28297
  }
27986
- const client = await (0, import_env_helpers16.getConfiguredClient)();
28298
+ const client = await getConfiguredClient();
27987
28299
  if (versionId && versionId.trim() !== "") {
27988
28300
  const response2 = await client.get(
27989
28301
  `/projects/${userConfig.userId}/${projectId}/versions/${versionId}`
27990
28302
  );
27991
28303
  const version = response2.data;
27992
28304
  if (!version) {
27993
- console.log(import_picocolors16.default.red(`Version with id <${versionId}> not found.`));
28305
+ console.log(import_picocolors17.default.red(`Version with id <${versionId}> not found.`));
27994
28306
  return;
27995
28307
  }
27996
28308
  await skipConfirmationPrompt(
@@ -27998,16 +28310,16 @@ async function rollback(args) {
27998
28310
  version.description,
27999
28311
  version.id
28000
28312
  );
28001
- console.log(import_picocolors16.default.cyan("Updating local .env file..."));
28002
- const values2 = await (0, import_env_helpers16.writeEnvFile)(
28313
+ console.log(import_picocolors17.default.cyan("Updating local .env file..."));
28314
+ const values2 = await writeEnvFile(
28003
28315
  version?.content
28004
28316
  );
28005
28317
  if (!values2) {
28006
- console.error(import_picocolors16.default.red("\nOops an unexpected error occurred."));
28318
+ console.error(import_picocolors17.default.red("\nOops an unexpected error occurred."));
28007
28319
  process.exit(1);
28008
28320
  }
28009
28321
  console.log(
28010
- import_picocolors16.default.green(
28322
+ import_picocolors17.default.green(
28011
28323
  "\u2705 Local .env file has been updated to match the rollback version."
28012
28324
  )
28013
28325
  );
@@ -28018,7 +28330,7 @@ async function rollback(args) {
28018
28330
  );
28019
28331
  const versions = versionsResponse.data;
28020
28332
  if (versions.length < 2) {
28021
- console.log(import_picocolors16.default.yellow("Not enough versions to roll back."));
28333
+ console.log(import_picocolors17.default.yellow("Not enough versions to roll back."));
28022
28334
  return;
28023
28335
  }
28024
28336
  const { versionIdToRollback } = await esm_default12.prompt([
@@ -28038,7 +28350,7 @@ async function rollback(args) {
28038
28350
  const versionToRollback = response.data;
28039
28351
  if (!versionToRollback.content) {
28040
28352
  console.error(
28041
- import_picocolors16.default.red("Selected version has no content. Cannot roll back.")
28353
+ import_picocolors17.default.red("Selected version has no content. Cannot roll back.")
28042
28354
  );
28043
28355
  return;
28044
28356
  }
@@ -28047,30 +28359,30 @@ async function rollback(args) {
28047
28359
  versionToRollback.description,
28048
28360
  versionToRollback.id
28049
28361
  );
28050
- console.log(import_picocolors16.default.cyan("Updating local .env file..."));
28051
- const values = await (0, import_env_helpers16.writeEnvFile)(
28362
+ console.log(import_picocolors17.default.cyan("Updating local .env file..."));
28363
+ const values = await writeEnvFile(
28052
28364
  versionToRollback?.content
28053
28365
  );
28054
28366
  if (!values) {
28055
- console.error(import_picocolors16.default.red("\nOops an unexpected error occurred."));
28367
+ console.error(import_picocolors17.default.red("\nOops an unexpected error occurred."));
28056
28368
  process.exit(1);
28057
28369
  }
28058
28370
  console.log(
28059
- import_picocolors16.default.green(
28371
+ import_picocolors17.default.green(
28060
28372
  "\u2705 Local .env file has been updated to match the rollback version."
28061
28373
  )
28062
28374
  );
28063
28375
  } catch (error) {
28064
28376
  if (error.response) {
28065
- console.error(import_picocolors16.default.yellow(`
28377
+ console.error(import_picocolors17.default.yellow(`
28066
28378
  ${error.response.data.error}`));
28067
28379
  return;
28068
28380
  }
28069
28381
  if (error.message.includes("User force closed the prompt with SIGINT")) {
28070
- console.log(import_picocolors16.default.yellow("\nRollback cancelled."));
28382
+ console.log(import_picocolors17.default.yellow("\nRollback cancelled."));
28071
28383
  return;
28072
28384
  }
28073
- console.error(import_picocolors16.default.red("\nError during rollback:"), error.message);
28385
+ console.error(import_picocolors17.default.red("\nError during rollback:"), error.message);
28074
28386
  process.exit(1);
28075
28387
  }
28076
28388
  }