feat: configure http pricing provider boundary
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-09 21:58:32 -04:00
parent 82ca54ddc3
commit b9ff7445a6
3 changed files with 33 additions and 0 deletions
@@ -0,0 +1,28 @@
import { createPricingProvider } from './pricing-provider.js';
export function createHttpPricingProvider({
id,
endpoint,
token,
fetchImplementation = fetch,
}) {
if (typeof endpoint !== 'string' || endpoint.trim().length === 0) {
throw new Error('Pricing provider endpoint is required.');
}
return createPricingProvider({
id,
async observe(input) {
const url = new URL(endpoint);
for (const [key, value] of Object.entries(input)) {
if (value) url.searchParams.set(key, value);
}
const response = await fetchImplementation(url, {
headers: token ? { authorization: `Bearer ${token}` } : {},
});
if (!response.ok) throw new Error(`Pricing provider returned HTTP ${response.status}.`);
const payload = await response.json();
return payload?.observations ?? payload;
},
});
}