Initial electronics inventory webapp
KV-store backed Express 5 app for tracking electronic components, their arbitrary fields, and inventory locations (physical, BOM, digital). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
29
public/lib/api.mjs
Normal file
29
public/lib/api.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
async function req(method, path, body) {
|
||||
const opts = { method, headers: {} };
|
||||
if (body !== undefined) {
|
||||
opts.headers['Content-Type'] = 'application/json';
|
||||
opts.body = JSON.stringify(body);
|
||||
}
|
||||
const res = await fetch(path, opts);
|
||||
const data = await res.json();
|
||||
if (!data.ok) throw new Error(data.error ?? 'Request failed');
|
||||
return data;
|
||||
}
|
||||
|
||||
// Fields
|
||||
export const get_fields = () => req('GET', '/api/fields');
|
||||
export const create_field = (body) => req('POST', '/api/fields', body);
|
||||
export const update_field = (id, body) => req('PUT', `/api/fields/${id}`, body);
|
||||
export const delete_field = (id) => req('DELETE', `/api/fields/${id}`);
|
||||
|
||||
// Components
|
||||
export const get_components = () => req('GET', '/api/components');
|
||||
export const create_component = (body) => req('POST', '/api/components', body);
|
||||
export const update_component = (id, body) => req('PUT', `/api/components/${id}`, body);
|
||||
export const delete_component = (id) => req('DELETE', `/api/components/${id}`);
|
||||
|
||||
// Inventory
|
||||
export const get_inventory = () => req('GET', '/api/inventory');
|
||||
export const create_inventory = (body) => req('POST', '/api/inventory', body);
|
||||
export const update_inventory = (id, body) => req('PUT', `/api/inventory/${id}`, body);
|
||||
export const delete_inventory = (id) => req('DELETE', `/api/inventory/${id}`);
|
||||
16
public/lib/dom.mjs
Normal file
16
public/lib/dom.mjs
Normal file
@@ -0,0 +1,16 @@
|
||||
export function qs(scope, selector) {
|
||||
if (typeof scope === 'string') return document.querySelector(scope);
|
||||
return scope.querySelector(selector);
|
||||
}
|
||||
|
||||
export function clone(template_id) {
|
||||
return document.getElementById(template_id).content.cloneNode(true).firstElementChild;
|
||||
}
|
||||
|
||||
export function set_text(el, selector, text) {
|
||||
const target = typeof selector === 'string' ? el.querySelector(selector) : selector;
|
||||
target.textContent = text;
|
||||
}
|
||||
|
||||
export function show(el) { el.hidden = false; }
|
||||
export function hide(el) { el.hidden = true; }
|
||||
Reference in New Issue
Block a user