@basaltkit/api-keys-ui 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/dist/html.js +30 -10
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -54,6 +54,10 @@ The page is served by `GET /apikeys/ui` (requires login). In the browser, it cal
54
54
  ### `apiKeysUiRoutes({ path?, apiBase?, title? })`
55
55
 
56
56
  Returns the route that serves the page. `path` (default `/apikeys/ui`), `apiBase` (where the JSON routes are, default same-origin), `title`.
57
+ The page relies on same-origin session credentials. `authRoutes()` issues a
58
+ `HttpOnly` session cookie on login, and the browser sends it automatically to
59
+ the JSON API routes. The access JWT remains in the login response for
60
+ non-browser clients and is not copied to `localStorage` by this UI.
57
61
 
58
62
  ### `apiKeysPageHtml({ apiBase?, title? })`
59
63
 
package/dist/html.js CHANGED
@@ -8,9 +8,21 @@ const pageScript = (apiBase) => `
8
8
  const API = ${scriptJson(apiBase)};
9
9
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
10
10
  const opts = { credentials: 'same-origin', headers: { 'content-type': 'application/json' } };
11
+ const showError = (message) => {
12
+ const error = document.getElementById('error');
13
+ error.textContent = message;
14
+ error.style.display = 'block';
15
+ };
16
+ const json = async (response) => {
17
+ const value = await response.json().catch(() => ({}));
18
+ if (!response.ok) throw new Error(value.message || value.error || ('Request failed (' + response.status + ')'));
19
+ return value;
20
+ };
11
21
 
12
22
  async function list() {
13
- const keys = await fetch(API + '/apikeys', opts).then((r) => r.json());
23
+ try {
24
+ const keys = await fetch(API + '/apikeys', opts).then(json);
25
+ document.getElementById('error').style.display = 'none';
14
26
  const rows = document.getElementById('rows');
15
27
  if (!Array.isArray(keys) || keys.length === 0) {
16
28
  rows.innerHTML = '<tr><td colspan="4" class="empty muted">No API keys yet.</td></tr>';
@@ -24,10 +36,13 @@ async function list() {
24
36
  for (const b of rows.querySelectorAll('button[data-id]')) {
25
37
  b.addEventListener('click', async () => {
26
38
  if (!confirm('Revoke this key? Any client using it will stop working.')) return;
27
- await fetch(API + '/apikeys/' + b.dataset.id, { ...opts, method: 'DELETE' });
28
- list();
39
+ try {
40
+ await fetch(API + '/apikeys/' + b.dataset.id, { ...opts, method: 'DELETE' }).then(json);
41
+ list();
42
+ } catch (error) { showError(error.message); }
29
43
  });
30
44
  }
45
+ } catch (error) { showError(error.message); }
31
46
  }
32
47
 
33
48
  document.getElementById('create').addEventListener('submit', async (e) => {
@@ -35,13 +50,16 @@ document.getElementById('create').addEventListener('submit', async (e) => {
35
50
  const f = new FormData(e.target);
36
51
  const scopes = String(f.get('scopes') || '').split(',').map((s) => s.trim()).filter(Boolean);
37
52
  const body = JSON.stringify({ name: f.get('name'), ...(scopes.length ? { scopes } : {}) });
38
- const created = await fetch(API + '/apikeys', { ...opts, method: 'POST', body }).then((r) => r.json());
39
- if (created && created.key) {
40
- document.getElementById('newkey').textContent = created.key;
41
- document.getElementById('reveal').style.display = 'block';
42
- }
43
- e.target.reset();
44
- list();
53
+ try {
54
+ const created = await fetch(API + '/apikeys', { ...opts, method: 'POST', body }).then(json);
55
+ document.getElementById('error').style.display = 'none';
56
+ if (created && created.key) {
57
+ document.getElementById('newkey').textContent = created.key;
58
+ document.getElementById('reveal').style.display = 'block';
59
+ }
60
+ e.target.reset();
61
+ list();
62
+ } catch (error) { showError(error.message); }
45
63
  });
46
64
 
47
65
  document.getElementById('copy').addEventListener('click', () => {
@@ -97,6 +115,7 @@ export function apiKeysPageHtml(options = {}) {
97
115
  .reveal { border: 1px solid var(--ok); background: #16a34a18; border-radius: 8px; padding: .75rem 1rem; margin-top: .75rem; display: none; }
98
116
  .reveal code { word-break: break-all; }
99
117
  .empty { padding: 1rem; text-align: center; }
118
+ .error { color: var(--danger); margin-top: .75rem; display: none; }
100
119
  </style>
101
120
  </head>
102
121
  <body>
@@ -114,6 +133,7 @@ export function apiKeysPageHtml(options = {}) {
114
133
  <code id="newkey"></code><button id="copy" type="button">Copy</button>
115
134
  </div>
116
135
  </div>
136
+ <div class="error" id="error" role="alert"></div>
117
137
  </div>
118
138
 
119
139
  <table>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/api-keys-ui",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "engines": {
5
5
  "node": ">=22.5.0"
6
6
  },
@@ -18,17 +18,17 @@
18
18
  "dist"
19
19
  ],
20
20
  "dependencies": {
21
- "@basaltkit/core": "^1.3.1",
22
- "@basaltkit/http": "^2.0.0"
21
+ "@basaltkit/http": "^2.0.0",
22
+ "@basaltkit/core": "^1.3.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^26.4.0",
26
26
  "typescript": "^7.0.2",
27
27
  "vitest": "^4.1.11",
28
28
  "zod": "^4.5.4",
29
- "@basaltkit/auth": "^2.0.0",
29
+ "@basaltkit/auth": "^2.1.0",
30
30
  "@basaltkit/fastify": "^2.0.0",
31
- "@basaltkit/tenancy": "^1.8.0",
31
+ "@basaltkit/tenancy": "^1.10.0",
32
32
  "@basaltkit/tsconfig": "^0.24.0"
33
33
  },
34
34
  "publishConfig": {