Initial import of zappier-accounting-export from zapier monorepo

This commit is contained in:
George Lambert 2026-09-11 18:20:06 -04:00
commit 0f6e06c589
8 changed files with 352 additions and 0 deletions

37
src/names.js Normal file
View file

@ -0,0 +1,37 @@
/** Join ledger ids to zappier-edge customer display names. */
export async function listCustomers(edge, key) {
try {
const r = await fetch(`${edge.replace(/\/$/, '')}/admin/api/customers`, {
headers: { 'x-admin-key': key },
});
const body = await r.json();
return (body.customers || []).map(({ passwordHash, apiKey, totpSecret, ...rest }) => rest);
} catch {
return [];
}
}
export async function withCustomerName(st, idOrName, edge, key) {
const out = { ...(st || {}) };
if (out.name && out.customerId) return out;
try {
const r = await fetch(`${edge.replace(/\/$/, '')}/admin/api/customers`, {
headers: { 'x-admin-key': key },
});
const { customers } = await r.json();
const want = String(idOrName || out.customerId || '').toLowerCase();
const c = (customers || []).find(
(x) =>
x.id === idOrName ||
x.id === out.customerId ||
String(x.name || '').toLowerCase() === want,
);
if (c) {
out.name = c.name;
out.customerId = c.id;
}
} catch {
/* edge optional */
}
return out;
}