30 lines
853 B
JavaScript
30 lines
853 B
JavaScript
// Simple supplier adapter registry.
|
|
// Add new adapters here. Missing adapters are ignored to prevent hard crashes.
|
|
const adapters = {};
|
|
|
|
try {
|
|
// Optional: example adapter. Remove or replace with real adapters.
|
|
// eslint-disable-next-line global-require
|
|
const ExampleSupplier = require("./example-supplier");
|
|
adapters["example-supplier"] = new ExampleSupplier({
|
|
apiKey: process.env.SUPPLIER_API_KEY || "",
|
|
});
|
|
} catch (err) {
|
|
// Keep registry usable even when optional adapters are absent.
|
|
}
|
|
|
|
const getAdapter = (id) => {
|
|
const adapter = adapters[id];
|
|
if (!adapter) {
|
|
const available = Object.keys(adapters);
|
|
const hint = available.length ? available.join(", ") : "none";
|
|
throw new Error(`Unknown supplier adapter "${id}". Available: ${hint}`);
|
|
}
|
|
return adapter;
|
|
};
|
|
|
|
module.exports = {
|
|
adapters,
|
|
getAdapter,
|
|
};
|