@envmanager-cli/cli 0.1.6 → 0.1.8

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.
@@ -2,6 +2,9 @@
2
2
 
3
3
  // src/bin/envmanager.ts
4
4
  import { Command as Command15 } from "commander";
5
+ import { readFileSync as readFileSync10 } from "fs";
6
+ import { dirname as dirname3, resolve as resolve9 } from "path";
7
+ import { fileURLToPath as fileURLToPath2 } from "url";
5
8
 
6
9
  // src/commands/login.ts
7
10
  import { Command } from "commander";
@@ -88,7 +91,7 @@ function escapeHtml(str) {
88
91
  return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
89
92
  }
90
93
  async function startCallbackServer(expectedState, port = 8976) {
91
- return new Promise((resolve9, reject) => {
94
+ return new Promise((resolve10, reject) => {
92
95
  const timeout = setTimeout(() => {
93
96
  server.close();
94
97
  reject(new Error("Authentication timed out after 5 minutes"));
@@ -161,9 +164,9 @@ async function startCallbackServer(expectedState, port = 8976) {
161
164
  clearTimeout(timeout);
162
165
  server.close();
163
166
  if (apiKey) {
164
- resolve9({ apiKey });
167
+ resolve10({ apiKey });
165
168
  } else {
166
- resolve9({
169
+ resolve10({
167
170
  accessToken,
168
171
  refreshToken,
169
172
  expiresIn: parseInt(expiresIn || "3600", 10)
@@ -1479,7 +1482,9 @@ async function subscribeToVariableChanges(environmentId, onEvent, onStatus) {
1479
1482
  table: "variables"
1480
1483
  },
1481
1484
  (payload) => {
1482
- const record = payload.new || payload.old;
1485
+ const newRecord = payload.new;
1486
+ const oldRecord = payload.old;
1487
+ const record = newRecord && Object.keys(newRecord).length > 0 ? newRecord : oldRecord;
1483
1488
  if (!record) return;
1484
1489
  const recordEnvId = record.environment_id;
1485
1490
  if (recordEnvId !== environmentId) {
@@ -1493,8 +1498,7 @@ async function subscribeToVariableChanges(environmentId, onEvent, onStatus) {
1493
1498
  is_secret: record.is_secret,
1494
1499
  timestamp: Date.now() / 1e3
1495
1500
  };
1496
- if (payload.eventType === "UPDATE" && payload.old) {
1497
- const oldRecord = payload.old;
1501
+ if (payload.eventType === "UPDATE" && oldRecord) {
1498
1502
  if (oldRecord.key !== record.key) {
1499
1503
  event.old_key = oldRecord.key;
1500
1504
  }
@@ -1511,11 +1515,11 @@ async function subscribeToVariableChanges(environmentId, onEvent, onStatus) {
1511
1515
  onStatus?.("connected");
1512
1516
  }
1513
1517
  });
1514
- const subscription = await new Promise((resolve9, reject) => {
1518
+ const subscription = await new Promise((resolve10, reject) => {
1515
1519
  channel.subscribe(async (status, err) => {
1516
1520
  if (status === "SUBSCRIBED") {
1517
1521
  onStatus?.("connected");
1518
- resolve9({
1522
+ resolve10({
1519
1523
  channel,
1520
1524
  environmentId,
1521
1525
  unsubscribe: async () => {
@@ -1664,9 +1668,12 @@ function mergeWithRemote(local, remoteVariables, strategy) {
1664
1668
  result.set(key, value);
1665
1669
  }
1666
1670
  break;
1667
- case "remote_wins":
1671
+ case "remote_wins": {
1672
+ const remoteKeys = new Set(remoteVariables.map((v) => v.key));
1668
1673
  for (const [key, value] of local) {
1669
- result.set(key, value);
1674
+ if (remoteKeys.has(key)) {
1675
+ result.set(key, value);
1676
+ }
1670
1677
  }
1671
1678
  for (const v of remoteVariables) {
1672
1679
  if (v.value !== null) {
@@ -1674,6 +1681,7 @@ function mergeWithRemote(local, remoteVariables, strategy) {
1674
1681
  }
1675
1682
  }
1676
1683
  break;
1684
+ }
1677
1685
  case "merge_new":
1678
1686
  for (const [key, value] of local) {
1679
1687
  result.set(key, value);
@@ -2986,9 +2994,9 @@ import { fileURLToPath } from "url";
2986
2994
  import { dirname as dirname2, resolve as resolve8 } from "path";
2987
2995
  function getCliVersion() {
2988
2996
  try {
2989
- const __dirname2 = dirname2(fileURLToPath(import.meta.url));
2990
- const pkg = JSON.parse(readFileSync9(resolve8(__dirname2, "../../package.json"), "utf-8"));
2991
- return pkg.version || "unknown";
2997
+ const __dirname3 = dirname2(fileURLToPath(import.meta.url));
2998
+ const pkg2 = JSON.parse(readFileSync9(resolve8(__dirname3, "../../package.json"), "utf-8"));
2999
+ return pkg2.version || "unknown";
2992
3000
  } catch {
2993
3001
  return "unknown";
2994
3002
  }
@@ -3080,8 +3088,10 @@ var debugCommand = new Command14("debug").description("Collect diagnostic info f
3080
3088
  });
3081
3089
 
3082
3090
  // src/bin/envmanager.ts
3091
+ var __dirname2 = dirname3(fileURLToPath2(import.meta.url));
3092
+ var pkg = JSON.parse(readFileSync10(resolve9(__dirname2, "../../package.json"), "utf-8"));
3083
3093
  var program = new Command15();
3084
- program.name("envmanager").description("CLI for EnvManager - secure environment variable management").version("0.1.0");
3094
+ program.name("envmanager").description("CLI for EnvManager - secure environment variable management").version(pkg.version);
3085
3095
  program.addCommand(loginCommand);
3086
3096
  program.addCommand(logoutCommand);
3087
3097
  program.addCommand(whoamiCommand);