This commit is contained in:
seb
2026-10-10 06:39:32 +02:00
parent 7fb7435779
commit 188b8efe09
7 changed files with 422 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
// @applet-input-schema {"type":"object","properties":{"sku":{"type":"string","title":"Article SKU","default":"","description":"Exact SKU to inspect. Leave empty for a single-row manifest summary."}}}
// @applet-output-schema key:string;value:string
//
// Article lookup — the raw `GET /article/{sku}` payload as a key/value sheet.
//
// Demonstrates: returning a single object (one row per key) and embedding `console.log` for a
// human-readable summary alongside the machine-readable table.
// Endpoints: GET /article/{sku}.
//
// Tip: this applet is small on purpose — copy it as a starting point for your own lookups.
module.exports = async function (applet_input) {
const sku = String(applet_input.sku || '').trim();
if (!sku) {
throw new Error('Please provide a SKU (e.g. "42000009").');
}
const res = await fetch(`/article/${encodeURIComponent(sku)}`);
if (res.status === 404) throw new Error(`Article "${sku}" was not found.`);
if (!res.ok) throw new Error(`GET /article/${sku} failed: ${res.status}`);
const { article } = await res.json();
const price = (article.prices || [])[0];
const brand = article.brand?.name || '(no brand)';
const categoryIds = (article.categoryIds || []).join(', ') || '(none)';
console.log(`${sku}: ${article.name} — brand ${brand}, ${article.eans?.length || 0} EAN(s).`);
const rows = [
{ key: 'sku', value: article.sku },
{ key: 'name', value: article.name },
{ key: 'brand', value: brand },
{ key: 'categoryIds', value: categoryIds },
{ key: 'unit', value: article.unit?.si ?? '' },
{ key: 'unitamount', value: article.unitamount ?? '' },
{ key: 'weight', value: article.weight ?? '' },
{ key: 'track_stock', value: article.track_stock },
{ key: 'net', value: price?.net ?? '' },
{ key: 'taxRate', value: price?.taxRate ?? '' },
{ key: 'eans', value: (article.eans || []).join(', ') },
{ key: 'suppliers', value: (article.suppliers || []).length },
];
return rows;
};