magpie-multi-usage 0.3.1 → 0.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magpie-multi-usage",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Multi-device token usage dashboard plugin for Magpie using a dedicated private GitHub repository relay (no decryption passphrase required).",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
@@ -468,7 +468,7 @@ export function buildDeviceManifest({
468
468
  deviceId,
469
469
  displayName,
470
470
  platform = process.platform,
471
- pluginVersion = "0.3.1",
471
+ pluginVersion = "0.3.3",
472
472
  revision = 1,
473
473
  updatedAt = new Date().toISOString(),
474
474
  snapshots = [],
@@ -224,7 +224,7 @@ export function createGitHubRelayStore({
224
224
  apiBaseUrl = DEFAULT_API_BASE_URL,
225
225
  fetchImpl = globalThis.fetch,
226
226
  timeoutMs = 15000,
227
- pluginVersion = "0.3.1",
227
+ pluginVersion = "0.3.3",
228
228
  } = {}) {
229
229
  const normalizedRepo = normalizeRepo(repo);
230
230
  if (!normalizedRepo) {
@@ -19,7 +19,7 @@ import { createSyncEngine } from "./sync-engine.mjs";
19
19
 
20
20
  export const TOKEN_HEADER = "x-multi-usage-token";
21
21
  export const DEFAULT_PORT = DEFAULT_CONFIG.port;
22
- export const PLUGIN_VERSION = "0.3.1";
22
+ export const PLUGIN_VERSION = "0.3.3";
23
23
 
24
24
  const MAX_JSON_BODY_BYTES = 256 * 1024;
25
25
  const ALLOWED_RANGES = new Set(["today", "7d", "30d", "all"]);
@@ -160,7 +160,7 @@ export function createSyncEngine({
160
160
  fetchImpl = globalThis.fetch,
161
161
  apiBaseUrl,
162
162
  gatewayBaseUrl,
163
- pluginVersion = "0.3.1",
163
+ pluginVersion = "0.3.3",
164
164
  timeZone,
165
165
  now = () => Date.now(),
166
166
  storeFactory = createGitHubRelayStore,
package/src/ui/app.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  formatCoverageWindow,
11
11
  formatExactNumber,
12
12
  formatPercent,
13
+ formatTestConnectionFeedback,
13
14
  formatTimestamp,
14
15
  formatTrendPointTitle,
15
16
  formatUsd,
@@ -989,13 +990,7 @@ async function handleTestConnection() {
989
990
  githubToken: payload.githubToken,
990
991
  },
991
992
  });
992
- const permNote = res.permissions?.canPush
993
- ? t(state.lang, "readWriteNote")
994
- : t(state.lang, "readOnlyNote");
995
- const branchNote = res.branchExists
996
- ? `${res.branch}`
997
- : `${res.branch} (${t(state.lang, "branchMissingWarning")})`;
998
- setFeedback(`${t(state.lang, "testSuccess")}: ${res.repo} [${branchNote}, ${permNote}]`, "ok");
993
+ setFeedback(formatTestConnectionFeedback(res, state.lang), "ok");
999
994
  } catch (err) {
1000
995
  setFeedback(err.message, "err");
1001
996
  } finally {
@@ -1005,8 +1000,11 @@ async function handleTestConnection() {
1005
1000
  }
1006
1001
 
1007
1002
  async function handleSaveSettings(event) {
1008
- event.preventDefault();
1003
+ event?.preventDefault?.();
1009
1004
  const btn = document.getElementById("save-cfg-btn");
1005
+ if (btn.disabled) {
1006
+ return;
1007
+ }
1010
1008
  btn.disabled = true;
1011
1009
  btn.textContent = t(state.lang, "saving");
1012
1010
  setFeedback("");
@@ -1084,7 +1082,17 @@ function wireEvents() {
1084
1082
  document.getElementById("clear-token-btn").classList.add("hidden");
1085
1083
  });
1086
1084
  document.getElementById("test-conn-btn").addEventListener("click", handleTestConnection);
1085
+ document.getElementById("save-cfg-btn").addEventListener("click", handleSaveSettings);
1087
1086
  document.getElementById("settings-form").addEventListener("submit", handleSaveSettings);
1087
+ document.getElementById("settings-form").addEventListener("keydown", (event) => {
1088
+ if (event.key !== "Enter") {
1089
+ return;
1090
+ }
1091
+ const tag = event.target?.tagName?.toUpperCase();
1092
+ if (tag === "INPUT") {
1093
+ handleSaveSettings(event);
1094
+ }
1095
+ });
1088
1096
  document.addEventListener("keydown", (event) => {
1089
1097
  if (event.key === "Escape") {
1090
1098
  closeSettingsDrawer();
package/src/ui/index.html CHANGED
@@ -125,7 +125,7 @@
125
125
  <div id="drawer-feedback" class="feedback hidden" aria-live="polite"></div>
126
126
  <div class="sheet-footer">
127
127
  <button id="test-conn-btn" type="button" class="pill-btn"></button>
128
- <button id="save-cfg-btn" type="submit" class="pill-btn pill-btn-primary"></button>
128
+ <button id="save-cfg-btn" type="button" class="pill-btn pill-btn-primary"></button>
129
129
  </div>
130
130
  </form>
131
131
  </aside>
@@ -652,3 +652,22 @@ export function isUnverifiedEmptyTrendPoint(point, availability = "ok") {
652
652
  return ["totalTokens", "calls", "errors", "cost", "input", "output", "cacheRead", "cacheWrite"]
653
653
  .every((key) => !Number(point[key]));
654
654
  }
655
+
656
+ /**
657
+ * Format /api/test-connection success feedback using top-level canPush
658
+ * (true -> read/write, false -> read-only, null/absent -> omitted so unknown
659
+ * permissions are never mislabeled as read-only).
660
+ */
661
+ export function formatTestConnectionFeedback(res, lang = "en") {
662
+ const branch = res?.branch || "";
663
+ const branchNote = res?.branchExists
664
+ ? branch
665
+ : `${branch} (${t(lang, "branchMissingWarning")})`;
666
+ const parts = [branchNote];
667
+ if (res?.canPush === true) {
668
+ parts.push(t(lang, "readWriteNote"));
669
+ } else if (res?.canPush === false) {
670
+ parts.push(t(lang, "readOnlyNote"));
671
+ }
672
+ return `${t(lang, "testSuccess")}: ${res?.repo || ""} [${parts.join(", ")}]`;
673
+ }