diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e8ff0f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +node_modules/ +npm-debug.log +data/*.db +data/*.db-journal +.env +.DS_Store diff --git a/barcode.js b/barcode.js new file mode 100644 index 0000000..ed128ce --- /dev/null +++ b/barcode.js @@ -0,0 +1,165 @@ +/** + * Open Food Facts Barcode API integration + * Extracts product name, brand, package quantity & unit, image, and category. + * Intentionally omits macro nutrients to keep interface clean & fast. + */ + +function parseQuantityString(quantityStr) { + if (!quantityStr || typeof quantityStr !== 'string') { + return { quantity: 1, unit: 'pcs' }; + } + + const clean = quantityStr.trim().toLowerCase(); + + // Pattern: e.g. "250g", "250 g", "1.5 kg", "1,5kg", "500 ml", "1 l", "1.5l", "6x100g", "4 x 125 g" + // Multi-pack: e.g. 6 x 100 g -> 600 g or total 6 pcs + const multiMatch = clean.match(/^(\d+)\s*[xX*]\s*([\d.,]+)\s*([a-zA-Z%]+)?/); + if (multiMatch) { + const count = parseInt(multiMatch[1], 10); + const itemQty = parseFloat(multiMatch[2].replace(',', '.')); + const itemUnit = multiMatch[3] ? normalizeUnit(multiMatch[3]) : 'g'; + if (!isNaN(count) && !isNaN(itemQty)) { + return { + quantity: Math.round(count * itemQty), + unit: itemUnit, + raw: quantityStr + }; + } + } + + // Single quantity: e.g. "250 g", "500ml", "1kg", "0.75 l" + const singleMatch = clean.match(/^([\d.,]+)\s*([a-zA-Z%]+)?/); + if (singleMatch) { + let num = parseFloat(singleMatch[1].replace(',', '.')); + let unit = singleMatch[2] ? normalizeUnit(singleMatch[2]) : 'g'; + + // Normalize kg to g or l to ml if preferred, or keep as is. Grams / ml are most convenient for fine adjustments! + if (unit === 'kg') { + num = Math.round(num * 1000); + unit = 'g'; + } else if (unit === 'l' || unit === 'liter' || unit === 'litre') { + num = Math.round(num * 1000); + unit = 'ml'; + } + + if (!isNaN(num) && num > 0) { + return { + quantity: num, + unit: unit, + raw: quantityStr + }; + } + } + + return { quantity: 1, unit: 'pcs', raw: quantityStr }; +} + +function normalizeUnit(u) { + const unit = u.toLowerCase().trim(); + if (unit === 'g' || unit === 'gr' || unit === 'gram' || unit === 'gramm' || unit === 'grams') return 'g'; + if (unit === 'kg' || unit === 'kilogram' || unit === 'kilo') return 'kg'; + if (unit === 'ml' || unit === 'milliliter') return 'ml'; + if (unit === 'l' || unit === 'liter' || unit === 'litre') return 'l'; + if (unit === 'cl' || unit === 'centiliter') return 'ml'; + if (unit === 'dl' || unit === 'deciliter') return 'ml'; + if (unit === 'oz') return 'g'; + if (unit === 'stk' || unit === 'stck' || unit === 'stueck' || unit === 'stück' || unit === 'pcs' || unit === 'pc' || unit === 'piece' || unit === 'pieces') return 'pcs'; + if (unit === 'pkg' || unit === 'pack' || unit === 'packung' || unit === 'pkt') return 'pack'; + if (unit === 'fl' || unit === 'flasche' || unit === 'bottle') return 'pcs'; + if (unit === 'dose' || unit === 'can') return 'pcs'; + return unit || 'g'; +} + +function inferCategory(categoriesTags = [], productName = '', categoriesStr = '') { + const combined = [ + ...(Array.isArray(categoriesTags) ? categoriesTags : []), + productName, + categoriesStr + ].join(' ').toLowerCase(); + + if (/getränk|beverage|drink|saft|juice|cola|soda|wasser|water|bier|beer|wein|wine|milchshake|smoothie|tee|tea|energy|sirup/i.test(combined)) { + return 'Beverages'; + } + if (/milch|käse|kaese|cheese|dairy|joghurt|yogurt|butter|quark|sahne|creme|schmand|mozzarella|parmesan|gouda|cheddar|feta|camembert|pudding/i.test(combined)) { + return 'Dairy & Cheese'; + } + if (/fleisch|meat|wurst|sausage|schinken|ham|hähnchen|chicken|rind|beef|schwein|pork|bacon|salami|speck|fisch|fish|lachs|salmon|thunfisch|tuna|seafood|garnelen/i.test(combined)) { + return 'Meat & Fish'; + } + if (/sauce|soße|senf|mustard|ketchup|mayo|mayonnaise|dressing|pesto|dip|essig|vinegar|öl|oil|gewürz|spice|curry|tabasco|remoulade/i.test(combined)) { + return 'Sauces & Condiments'; + } + if (/gemüse|vegetable|obst|fruit|salat|salad|tomate|tomato|gurke|cucumber|apfel|apple|banane|banana|zwiebel|onion|karotte|carrot|kartoffel|potato|beeren|berry|zitrus|citrus|spinat|spinach/i.test(combined)) { + return 'Produce'; + } + if (/brot|bread|toast|brötchen|bun|teig|dough|hefe|yeast|croissant|tortilla|wrap/i.test(combined)) { + return 'Bakery'; + } + if (/snack|schokolade|chocolate|chips|keks|cookie|süß|sweet|candy|nuss|nut|eis|ice cream/i.test(combined)) { + return 'Snacks & Sweets'; + } + if (/reste|leftover|fertiggericht|meal|pizza|suppen|soup|pasta|nudeln|noodle/i.test(combined)) { + return 'Prepared & Leftovers'; + } + + return 'General'; +} + +async function lookupBarcode(barcode) { + if (!barcode || typeof barcode !== 'string') return null; + const cleanBarcode = barcode.trim(); + if (!cleanBarcode) return null; + + try { + const url = `https://world.openfoodfacts.org/api/v2/product/${encodeURIComponent(cleanBarcode)}.json?fields=product_name,product_name_de,product_name_en,brands,quantity,categories_tags,categories,image_front_small_url,image_url,image_front_url`; + + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), 6000); // 6s timeout + + const res = await fetch(url, { + headers: { + 'User-Agent': 'Fridger - Fridge Inventory Manager (https://gitea.eibl.tech/me0nline/Fridger)' + }, + signal: controller.signal + }); + clearTimeout(timeout); + + if (!res.ok) { + return null; + } + + const data = await res.json(); + if (data.status !== 1 || !data.product) { + return null; + } + + const p = data.product; + const name = p.product_name_de || p.product_name || p.product_name_en || ''; + const brand = p.brands || ''; + const parsedQty = parseQuantityString(p.quantity); + const category = inferCategory(p.categories_tags, name, p.categories); + const imageUrl = p.image_front_small_url || p.image_front_url || p.image_url || ''; + + return { + found: true, + barcode: cleanBarcode, + name: name.trim() || 'Unknown Product', + brand: brand.trim(), + quantity: parsedQty.quantity, + initial_quantity: parsedQty.quantity, + unit: parsedQty.unit, + category: category, + image_url: imageUrl, + raw_quantity: p.quantity || '' + }; + } catch (err) { + console.warn(`Barcode lookup error for ${cleanBarcode}:`, err.message); + return null; + } +} + +module.exports = { + lookupBarcode, + parseQuantityString, + inferCategory +}; diff --git a/db.js b/db.js new file mode 100644 index 0000000..b5ee9f9 --- /dev/null +++ b/db.js @@ -0,0 +1,353 @@ +const { DatabaseSync } = require('node:sqlite'); +const path = require('node:path'); +const fs = require('node:fs'); + +const DATA_DIR = process.env.FRIDGER_DATA_DIR || path.join(__dirname, 'data'); +if (!fs.existsSync(DATA_DIR)) { + fs.mkdirSync(DATA_DIR, { recursive: true }); +} + +const DB_PATH = process.env.FRIDGER_DB_PATH || path.join(DATA_DIR, 'fridger.db'); +const db = new DatabaseSync(DB_PATH); + +// Initialize Tables +db.exec(` + CREATE TABLE IF NOT EXISTS items ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + barcode TEXT, + brand TEXT, + category TEXT DEFAULT 'General', + location TEXT DEFAULT 'Fridge - Middle Shelf', + quantity REAL NOT NULL, + initial_quantity REAL NOT NULL, + unit TEXT NOT NULL DEFAULT 'g', + expiry_date TEXT, + image_url TEXT, + notes TEXT, + is_opened INTEGER DEFAULT 0, + opened_at TEXT, + created_at TEXT DEFAULT (datetime('now', 'localtime')), + updated_at TEXT DEFAULT (datetime('now', 'localtime')) + ); + + CREATE TABLE IF NOT EXISTS activity_log ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + item_id INTEGER, + item_name TEXT, + action TEXT NOT NULL, + amount_change REAL, + unit TEXT, + timestamp TEXT DEFAULT (datetime('now', 'localtime')), + note TEXT + ); + + CREATE INDEX IF NOT EXISTS idx_items_barcode ON items(barcode); + CREATE INDEX IF NOT EXISTS idx_items_expiry ON items(expiry_date); + CREATE INDEX IF NOT EXISTS idx_items_category ON items(category); +`); + +// Item functions +function getAllItems({ search = '', category = '', location = '', status = 'all' } = {}) { + let query = `SELECT * FROM items WHERE 1=1`; + const params = []; + + if (search) { + query += ` AND (name LIKE ? OR brand LIKE ? OR barcode LIKE ? OR notes LIKE ?)`; + const s = `%${search}%`; + params.push(s, s, s, s); + } + + if (category && category !== 'All') { + query += ` AND category = ?`; + params.push(category); + } + + if (location && location !== 'All') { + query += ` AND location = ?`; + params.push(location); + } + + const today = new Date().toISOString().slice(0, 10); + + if (status === 'expired') { + query += ` AND expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date < ?`; + params.push(today); + } else if (status === 'expiring_soon') { + const next3Days = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); + query += ` AND expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date >= ? AND expiry_date <= ?`; + params.push(today, next3Days); + } else if (status === 'fresh') { + const next3Days = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); + query += ` AND (expiry_date IS NULL OR expiry_date = '' OR expiry_date > ?)`; + params.push(next3Days); + } else if (status === 'low') { + query += ` AND (quantity <= (initial_quantity * 0.25) OR quantity = 0)`; + } + + query += ` ORDER BY + CASE + WHEN expiry_date IS NULL OR expiry_date = '' THEN 1 + ELSE 0 + END, + expiry_date ASC, + updated_at DESC`; + + const stmt = db.prepare(query); + return stmt.all(...params); +} + +function getItemById(id) { + const stmt = db.prepare(`SELECT * FROM items WHERE id = ?`); + return stmt.get(id); +} + +function getItemByBarcode(barcode) { + const stmt = db.prepare(`SELECT * FROM items WHERE barcode = ? ORDER BY updated_at DESC LIMIT 1`); + return stmt.get(barcode); +} + +function createItem(item) { + const initial_qty = Number(item.initial_quantity) || Number(item.quantity) || 1; + const current_qty = Number(item.quantity) ?? initial_qty; + const unit = (item.unit || 'g').trim(); + const is_opened = item.is_opened ? 1 : 0; + const opened_at = is_opened ? (item.opened_at || new Date().toISOString().slice(0, 10)) : null; + + const stmt = db.prepare(` + INSERT INTO items ( + name, barcode, brand, category, location, + quantity, initial_quantity, unit, expiry_date, + image_url, notes, is_opened, opened_at + ) VALUES ( + ?, ?, ?, ?, ?, + ?, ?, ?, ?, + ?, ?, ?, ? + ) + `); + + const result = stmt.run( + item.name, + item.barcode || null, + item.brand || null, + item.category || 'General', + item.location || 'Fridge - Middle Shelf', + current_qty, + initial_qty, + unit, + item.expiry_date || null, + item.image_url || null, + item.notes || null, + is_opened, + opened_at + ); + + const newId = result.lastInsertRowid; + + // Log activity + logActivity({ + item_id: newId, + item_name: item.name, + action: 'add', + amount_change: current_qty, + unit: unit, + note: `Added ${current_qty} ${unit}` + }); + + return getItemById(newId); +} + +function updateItem(id, item) { + const existing = getItemById(id); + if (!existing) return null; + + const qty = item.quantity !== undefined ? Number(item.quantity) : existing.quantity; + const init_qty = item.initial_quantity !== undefined ? Number(item.initial_quantity) : existing.initial_quantity; + const is_opened = item.is_opened !== undefined ? (item.is_opened ? 1 : 0) : existing.is_opened; + let opened_at = existing.opened_at; + if (is_opened && !existing.is_opened) { + opened_at = new Date().toISOString().slice(0, 10); + } else if (!is_opened) { + opened_at = null; + } + + const stmt = db.prepare(` + UPDATE items SET + name = ?, + barcode = ?, + brand = ?, + category = ?, + location = ?, + quantity = ?, + initial_quantity = ?, + unit = ?, + expiry_date = ?, + image_url = ?, + notes = ?, + is_opened = ?, + opened_at = ?, + updated_at = datetime('now', 'localtime') + WHERE id = ? + `); + + stmt.run( + item.name ?? existing.name, + item.barcode !== undefined ? item.barcode : existing.barcode, + item.brand !== undefined ? item.brand : existing.brand, + item.category ?? existing.category, + item.location ?? existing.location, + qty, + init_qty, + item.unit ?? existing.unit, + item.expiry_date !== undefined ? item.expiry_date : existing.expiry_date, + item.image_url !== undefined ? item.image_url : existing.image_url, + item.notes !== undefined ? item.notes : existing.notes, + is_opened, + opened_at, + id + ); + + if (qty !== existing.quantity) { + const diff = qty - existing.quantity; + logActivity({ + item_id: id, + item_name: item.name || existing.name, + action: diff < 0 ? 'consume_part' : 'restock', + amount_change: diff, + unit: item.unit || existing.unit, + note: `Adjusted quantity from ${existing.quantity} to ${qty} ${item.unit || existing.unit}` + }); + } + + return getItemById(id); +} + +function adjustQuantity(id, { newQuantity, delta, markOpened }) { + const item = getItemById(id); + if (!item) return null; + + let targetQty = item.quantity; + if (newQuantity !== undefined) { + targetQty = Number(newQuantity); + } else if (delta !== undefined) { + targetQty = item.quantity + Number(delta); + } + + // Prevent negative quantity + if (targetQty < 0) targetQty = 0; + + const is_opened = markOpened !== undefined ? (markOpened ? 1 : 0) : (item.is_opened || (targetQty < item.initial_quantity ? 1 : 0)); + const opened_at = is_opened && !item.opened_at ? new Date().toISOString().slice(0, 10) : item.opened_at; + + const diff = targetQty - item.quantity; + + const stmt = db.prepare(` + UPDATE items SET + quantity = ?, + is_opened = ?, + opened_at = ?, + updated_at = datetime('now', 'localtime') + WHERE id = ? + `); + + stmt.run(targetQty, is_opened, opened_at, id); + + logActivity({ + item_id: id, + item_name: item.name, + action: targetQty === 0 ? 'consume_all' : (diff < 0 ? 'consume_part' : 'restock'), + amount_change: diff, + unit: item.unit, + note: targetQty === 0 + ? `Consumed all (${item.quantity} ${item.unit})` + : `${diff < 0 ? 'Consumed' : 'Added'} ${Math.abs(diff)} ${item.unit} (remaining: ${targetQty} ${item.unit})` + }); + + return getItemById(id); +} + +function deleteItem(id) { + const item = getItemById(id); + if (!item) return false; + + logActivity({ + item_id: id, + item_name: item.name, + action: 'delete', + amount_change: -item.quantity, + unit: item.unit, + note: `Deleted item from fridge` + }); + + const stmt = db.prepare(`DELETE FROM items WHERE id = ?`); + stmt.run(id); + return true; +} + +function logActivity({ item_id, item_name, action, amount_change, unit, note }) { + try { + const stmt = db.prepare(` + INSERT INTO activity_log (item_id, item_name, action, amount_change, unit, note) + VALUES (?, ?, ?, ?, ?, ?) + `); + stmt.run(item_id || null, item_name || null, action, amount_change || 0, unit || '', note || ''); + } catch (err) { + console.error('Error logging activity:', err); + } +} + +function getActivityLogs(limit = 50) { + const stmt = db.prepare(`SELECT * FROM activity_log ORDER BY timestamp DESC, id DESC LIMIT ?`); + return stmt.all(limit); +} + +function getStats() { + const today = new Date().toISOString().slice(0, 10); + const next3Days = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); + + const totalStmt = db.prepare(`SELECT COUNT(*) as count FROM items`); + const total = totalStmt.get().count; + + const expiredStmt = db.prepare(` + SELECT COUNT(*) as count FROM items + WHERE expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date < ? + `); + const expired = expiredStmt.get(today).count; + + const expiringSoonStmt = db.prepare(` + SELECT COUNT(*) as count FROM items + WHERE expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date >= ? AND expiry_date <= ? + `); + const expiringSoon = expiringSoonStmt.get(today, next3Days).count; + + const openedStmt = db.prepare(`SELECT COUNT(*) as count FROM items WHERE is_opened = 1`); + const opened = openedStmt.get().count; + + const lowStmt = db.prepare(` + SELECT COUNT(*) as count FROM items + WHERE quantity <= (initial_quantity * 0.25) AND quantity > 0 + `); + const low = lowStmt.get().count; + + return { + total, + expired, + expiringSoon, + opened, + low, + fresh: total - expired - expiringSoon + }; +} + +module.exports = { + db, + getAllItems, + getItemById, + getItemByBarcode, + createItem, + updateItem, + adjustQuantity, + deleteItem, + getActivityLogs, + getStats +}; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e8eec41 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,860 @@ +{ + "name": "fridger", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fridger", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "cors": "^2.8.5", + "express": "^4.21.2" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/body-parser": { + "version": "1.20.8", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.8.tgz", + "integrity": "sha512-JNcyFQ64OiijEkPzUBTCe+hyPXUD/3LEldGQ6iF5LR1w00mx9o7xtDWHXBY2iItjdCFGoilOLNQbH943ut7pHA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.16.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.22.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.3.tgz", + "integrity": "sha512-Bdcs4+3qlpVlx2NRn6fgX2Ue2/gGRaPeawebgclM0ERSCqDpA+owF1fdPwjJUTAJWMTuAaxjDf+hzb0/4eKvvw==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.5", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.13", + "proxy-addr": "~2.0.7", + "qs": "~6.16.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz", + "integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", + "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/qs": { + "version": "6.16.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", + "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==", + "license": "BSD-3-Clause", + "dependencies": { + "es-define-property": "^1.0.1", + "side-channel": "^1.1.1" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..a6a1f07 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "fridger", + "version": "1.0.0", + "description": "Smart Fridge Inventory & Management Web App with Barcode Scanner and Weight Tracking", + "main": "server.js", + "scripts": { + "start": "node server.js", + "dev": "node --watch server.js" + }, + "dependencies": { + "cors": "^2.8.5", + "express": "^4.21.2" + }, + "keywords": [ + "fridge", + "inventory", + "barcode", + "openfoodfacts", + "docker" + ], + "author": "me0nline", + "license": "MIT" +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..f618ff0 --- /dev/null +++ b/server.js @@ -0,0 +1,376 @@ +const express = require('express'); +const cors = require('cors'); +const path = require('node:path'); +const db = require('./db'); +const { lookupBarcode } = require('./barcode'); + +const app = express(); +const PORT = process.env.PORT || 3000; + +app.use(cors()); +app.use(express.json()); +app.use(express.static(path.join(__dirname, 'public'))); + +// Metadata definitions +const CATEGORIES = [ + { id: 'Dairy & Cheese', name: 'Dairy & Cheese', icon: 'milk', color: '#3b82f6' }, + { id: 'Meat & Fish', name: 'Meat & Fish', icon: 'beef', color: '#ef4444' }, + { id: 'Produce', name: 'Fruits & Veggies', icon: 'apple', color: '#10b981' }, + { id: 'Beverages', name: 'Drinks & Beverages', icon: 'cup-soda', color: '#06b6d4' }, + { id: 'Sauces & Condiments', name: 'Sauces & Condiments', icon: 'flask-conical', color: '#f59e0b' }, + { id: 'Bakery', name: 'Bakery & Bread', icon: 'croissant', color: '#d97706' }, + { id: 'Prepared & Leftovers', name: 'Leftovers & Meals', icon: 'utensils', color: '#8b5cf6' }, + { id: 'Snacks & Sweets', name: 'Snacks & Sweets', icon: 'cookie', color: '#ec4899' }, + { id: 'General', name: 'General / Other', icon: 'package', color: '#6b7280' } +]; + +const LOCATIONS = [ + 'Fridge - Top Shelf', + 'Fridge - Middle Shelf', + 'Fridge - Bottom Shelf', + 'Fridge - Crisper Drawer', + 'Fridge - Door Rack', + 'Freezer - Top Drawer', + 'Freezer - Bottom Drawer', + 'Pantry / Cupboard' +]; + +const UNITS = [ + { id: 'g', label: 'Grams (g)', isWeight: true, step: 50 }, + { id: 'kg', label: 'Kilograms (kg)', isWeight: true, step: 0.1 }, + { id: 'ml', label: 'Milliliters (ml)', isVolume: true, step: 100 }, + { id: 'l', label: 'Liters (L)', isVolume: true, step: 0.5 }, + { id: 'pcs', label: 'Pieces (Stk / pcs)', isCount: true, step: 1 }, + { id: 'slices', label: 'Slices', isCount: true, step: 1 }, + { id: 'pack', label: 'Pack / Package', isCount: true, step: 1 } +]; + +// Health Check +app.get('/health', (req, res) => { + res.json({ status: 'ok', uptime: process.uptime(), timestamp: new Date().toISOString() }); +}); + +// Meta endpoint +app.get('/api/meta', (req, res) => { + res.json({ + categories: CATEGORIES, + locations: LOCATIONS, + units: UNITS + }); +}); + +// Stats endpoint +app.get('/api/stats', (req, res) => { + try { + const stats = db.getStats(); + res.json(stats); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Activity logs +app.get('/api/activity', (req, res) => { + try { + const limit = parseInt(req.query.limit, 10) || 50; + const logs = db.getActivityLogs(limit); + res.json(logs); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Barcode lookup +app.get('/api/barcode/:code', async (req, res) => { + const barcode = req.params.code; + if (!barcode) { + return res.status(400).json({ error: 'Barcode parameter is required' }); + } + + // First check if user previously stored an item with this barcode + const existing = db.getItemByBarcode(barcode); + if (existing) { + return res.json({ + found: true, + fromLocal: true, + barcode: existing.barcode, + name: existing.name, + brand: existing.brand || '', + category: existing.category || 'General', + location: existing.location || 'Fridge - Middle Shelf', + quantity: existing.initial_quantity || existing.quantity, + initial_quantity: existing.initial_quantity || existing.quantity, + unit: existing.unit || 'g', + image_url: existing.image_url || '' + }); + } + + // Lookup in Open Food Facts + const product = await lookupBarcode(barcode); + if (product) { + return res.json({ + ...product, + fromLocal: false + }); + } + + res.status(404).json({ + found: false, + barcode: barcode, + message: 'Barcode not found in database or Open Food Facts' + }); +}); + +// List items +app.get('/api/items', (req, res) => { + try { + const { search, category, location, status } = req.query; + const items = db.getAllItems({ search, category, location, status }); + res.json(items); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Get single item +app.get('/api/items/:id', (req, res) => { + try { + const item = db.getItemById(req.params.id); + if (!item) return res.status(404).json({ error: 'Item not found' }); + res.json(item); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Create item +app.post('/api/items', (req, res) => { + try { + const { name, quantity } = req.body; + if (!name || name.trim() === '') { + return res.status(400).json({ error: 'Item name is required' }); + } + if (quantity === undefined || isNaN(Number(quantity)) || Number(quantity) < 0) { + return res.status(400).json({ error: 'Valid quantity is required' }); + } + + const item = db.createItem(req.body); + res.status(201).json(item); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Update item +app.put('/api/items/:id', (req, res) => { + try { + const item = db.updateItem(req.params.id, req.body); + if (!item) return res.status(404).json({ error: 'Item not found' }); + res.json(item); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Quick adjust quantity (grams / count / delta / slider) +app.patch('/api/items/:id/quantity', (req, res) => { + try { + const { newQuantity, delta, markOpened } = req.body; + if (newQuantity === undefined && delta === undefined) { + return res.status(400).json({ error: 'Either newQuantity or delta must be provided' }); + } + + const item = db.adjustQuantity(req.params.id, { newQuantity, delta, markOpened }); + if (!item) return res.status(404).json({ error: 'Item not found' }); + res.json(item); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Delete item +app.delete('/api/items/:id', (req, res) => { + try { + const success = db.deleteItem(req.params.id); + if (!success) return res.status(404).json({ error: 'Item not found' }); + res.json({ success: true, message: 'Item removed' }); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Seed sample fridge data if empty +app.post('/api/seed', (req, res) => { + try { + const existing = db.getAllItems(); + if (existing.length > 0 && !req.query.force) { + return res.json({ message: 'Fridge already contains items', count: existing.length }); + } + + const today = new Date(); + const addDays = (d) => { + const target = new Date(today.getTime() + d * 24 * 60 * 60 * 1000); + return target.toISOString().slice(0, 10); + }; + + const samples = [ + { + name: 'Gouda Cheese (Jung)', + brand: 'Milbona', + barcode: '4056489123456', + category: 'Dairy & Cheese', + location: 'Fridge - Middle Shelf', + quantity: 200, + initial_quantity: 400, + unit: 'g', + is_opened: 1, + opened_at: addDays(-2), + expiry_date: addDays(6), + notes: 'Opened, about half remaining for sandwiches' + }, + { + name: 'Whole Milk 3.5%', + brand: 'Weihenstephan', + barcode: '4008452023451', + category: 'Dairy & Cheese', + location: 'Fridge - Door Rack', + quantity: 650, + initial_quantity: 1000, + unit: 'ml', + is_opened: 1, + opened_at: addDays(-1), + expiry_date: addDays(3), + notes: 'Carton opened yesterday' + }, + { + name: 'Organic Greek Yogurt', + brand: 'Andechser Natur', + barcode: '4005040001234', + category: 'Dairy & Cheese', + location: 'Fridge - Top Shelf', + quantity: 500, + initial_quantity: 500, + unit: 'g', + is_opened: 0, + expiry_date: addDays(12), + notes: 'Unopened 500g cup' + }, + { + name: 'Chicken Breast Fillet', + brand: 'Bauerngut', + barcode: '4012345678901', + category: 'Meat & Fish', + location: 'Fridge - Bottom Shelf', + quantity: 350, + initial_quantity: 400, + unit: 'g', + is_opened: 1, + opened_at: addDays(0), + expiry_date: addDays(1), + notes: 'Cook today or freeze!' + }, + { + name: 'Fresh Cherry Tomatoes', + brand: 'Bio', + category: 'Produce', + location: 'Fridge - Crisper Drawer', + quantity: 180, + initial_quantity: 250, + unit: 'g', + is_opened: 1, + expiry_date: addDays(4), + notes: 'Sweet snack tomatoes' + }, + { + name: 'Dijon Mustard', + brand: 'Maille', + barcode: '3036810200028', + category: 'Sauces & Condiments', + location: 'Fridge - Door Rack', + quantity: 140, + initial_quantity: 215, + unit: 'g', + is_opened: 1, + expiry_date: addDays(90), + notes: 'In door rack' + }, + { + name: 'Butter (Irish Pure)', + brand: 'Kerrygold', + barcode: '5011010001018', + category: 'Dairy & Cheese', + location: 'Fridge - Door Rack', + quantity: 190, + initial_quantity: 250, + unit: 'g', + is_opened: 1, + expiry_date: addDays(25), + notes: 'In butter dish' + }, + { + name: 'Homemade Pasta Bolognese', + brand: '', + category: 'Prepared & Leftovers', + location: 'Fridge - Top Shelf', + quantity: 1, + initial_quantity: 1, + unit: 'pack', + is_opened: 1, + opened_at: addDays(-1), + expiry_date: addDays(1), + notes: 'Glass container, 1 portion' + }, + { + name: 'Orange Juice 100%', + brand: 'Innocent', + barcode: '5038862112345', + category: 'Beverages', + location: 'Fridge - Door Rack', + quantity: 900, + initial_quantity: 900, + unit: 'ml', + is_opened: 0, + expiry_date: addDays(14) + } + ]; + + for (const sample of samples) { + db.createItem(sample); + } + + res.json({ message: 'Seed complete', created: samples.length }); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +// Catch-all route to serve the Single Page Application +app.get('*', (req, res) => { + res.sendFile(path.join(__dirname, 'public', 'index.html')); +}); + +// Start Server +if (require.main === module) { + // Check if initial seed is needed on first launch + const items = db.getAllItems(); + if (items.length === 0) { + console.log('Fridge is empty. Pre-seeding sample items for initial experience...'); + // Seed initial items + const today = new Date(); + const addDays = (d) => new Date(today.getTime() + d * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); + [ + { name: 'Gouda Cheese', brand: 'Milbona', barcode: '4056489123456', category: 'Dairy & Cheese', location: 'Fridge - Middle Shelf', quantity: 200, initial_quantity: 400, unit: 'g', is_opened: 1, expiry_date: addDays(5), notes: 'Half pack left' }, + { name: 'Fresh Milk 3.5%', brand: 'Weihenstephan', barcode: '4008452023451', category: 'Dairy & Cheese', location: 'Fridge - Door Rack', quantity: 700, initial_quantity: 1000, unit: 'ml', is_opened: 1, expiry_date: addDays(3), notes: 'Opened' }, + { name: 'Butter', brand: 'Kerrygold', barcode: '5011010001018', category: 'Dairy & Cheese', location: 'Fridge - Door Rack', quantity: 210, initial_quantity: 250, unit: 'g', is_opened: 1, expiry_date: addDays(20) }, + { name: 'Chicken Breast', brand: 'Bio', category: 'Meat & Fish', location: 'Fridge - Bottom Shelf', quantity: 400, initial_quantity: 400, unit: 'g', is_opened: 0, expiry_date: addDays(2), notes: 'Cook soon' }, + { name: 'Cherry Tomatoes', category: 'Produce', location: 'Fridge - Crisper Drawer', quantity: 180, initial_quantity: 250, unit: 'g', is_opened: 1, expiry_date: addDays(4) }, + { name: 'Dijon Mustard', brand: 'Maille', barcode: '3036810200028', category: 'Sauces & Condiments', location: 'Fridge - Door Rack', quantity: 150, initial_quantity: 215, unit: 'g', is_opened: 1, expiry_date: addDays(60) } + ].forEach(item => db.createItem(item)); + } + + app.listen(PORT, '0.0.0.0', () => { + console.log(`🧊 Fridger server running at http://0.0.0.0:${PORT}`); + }); +} + +module.exports = app; diff --git a/test.js b/test.js new file mode 100644 index 0000000..6f034ff --- /dev/null +++ b/test.js @@ -0,0 +1,77 @@ +const assert = require('node:assert'); +const db = require('./db'); +const { parseQuantityString, inferCategory } = require('./barcode'); + +console.log('🧪 Running Fridger Backend Unit Tests...'); + +// 1. Test quantity parsing +console.log('1. Testing quantity parsing...'); +assert.strictEqual(parseQuantityString('250 g').quantity, 250); +assert.strictEqual(parseQuantityString('250 g').unit, 'g'); +assert.strictEqual(parseQuantityString('1.5 kg').quantity, 1500); +assert.strictEqual(parseQuantityString('1.5 kg').unit, 'g'); +assert.strictEqual(parseQuantityString('500ml').quantity, 500); +assert.strictEqual(parseQuantityString('500ml').unit, 'ml'); +assert.strictEqual(parseQuantityString('6 x 100g').quantity, 600); +assert.strictEqual(parseQuantityString('4 Stk').quantity, 4); +assert.strictEqual(parseQuantityString('4 Stk').unit, 'pcs'); +console.log('✓ Quantity parsing tests passed!'); + +// 2. Test category inference +console.log('2. Testing category inference...'); +assert.strictEqual(inferCategory([], 'Frische Vollmilch 3.5%'), 'Dairy & Cheese'); +assert.strictEqual(inferCategory([], 'Gouda Käse in Scheiben'), 'Dairy & Cheese'); +assert.strictEqual(inferCategory([], 'Rinderhackfleisch'), 'Meat & Fish'); +assert.strictEqual(inferCategory([], 'Bio Tomaten'), 'Produce'); +assert.strictEqual(inferCategory([], 'Apfelsaft 100%'), 'Beverages'); +assert.strictEqual(inferCategory([], 'Senf mittelscharf'), 'Sauces & Condiments'); +console.log('✓ Category inference tests passed!'); + +// 3. Test Database CRUD & Quantity adjustments +console.log('3. Testing Database operations...'); +const newItem = db.createItem({ + name: 'Test Yogurt', + brand: 'TestBrand', + barcode: '999999999999', + category: 'Dairy & Cheese', + location: 'Fridge - Top Shelf', + quantity: 500, + initial_quantity: 500, + unit: 'g', + expiry_date: '2026-10-20', + notes: 'Test note' +}); + +assert(newItem.id, 'Item should have an ID'); +assert.strictEqual(newItem.name, 'Test Yogurt'); +assert.strictEqual(newItem.quantity, 500); +assert.strictEqual(newItem.unit, 'g'); + +// Adjust grams: e.g. consumed 150g -> remaining 350g +console.log('Testing partial consumption (-150g)...'); +const adjusted = db.adjustQuantity(newItem.id, { delta: -150 }); +assert.strictEqual(adjusted.quantity, 350); +assert.strictEqual(adjusted.is_opened, 1, 'Should automatically mark as opened when grams reduced'); + +// Slider or direct set: e.g. set remaining to 100g +console.log('Testing absolute set (100g remaining)...'); +const updatedAbs = db.adjustQuantity(newItem.id, { newQuantity: 100 }); +assert.strictEqual(updatedAbs.quantity, 100); + +// Consume remaining +console.log('Testing consume all...'); +const finished = db.adjustQuantity(newItem.id, { newQuantity: 0 }); +assert.strictEqual(finished.quantity, 0); + +// Delete test item +const deleted = db.deleteItem(newItem.id); +assert.strictEqual(deleted, true); +assert.strictEqual(db.getItemById(newItem.id), undefined); + +// Test stats +const stats = db.getStats(); +assert(typeof stats.total === 'number'); +assert(typeof stats.fresh === 'number'); + +console.log('✓ All database operations passed!'); +console.log('🎉 All backend tests completed successfully!');