Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
Address review: reject whitespace-only FIREBILL_SECRET, preserve URL base path
Rakshith Ramprakash5de7f292f85f
diff --git a/apps/api/src/config.ts b/apps/api/src/config.tsindex e03c4d4f5..b103a4577 100644--- a/apps/api/src/config.ts+++ b/apps/api/src/config.ts@@ -383,7 +383,7 @@ const configSchema = z.object({// FIREBILL_ORG_IDS (comma-separated org UUIDs) is routed through firebill// instead of directly to Autumn (gradual rollout).FIREBILL_URL: emptyStringAsUndefined(z.string().url()),- FIREBILL_SECRET: emptyStringAsUndefined(z.string()),+ FIREBILL_SECRET: emptyStringAsUndefined(z.string().trim().min(1)),FIREBILL_ORG_IDS: delimitedList(",").optional(),// Miscellaneousdiff --git a/apps/api/src/services/autumn/__tests__/autumn.service.test.ts b/apps/api/src/services/autumn/__tests__/autumn.service.test.tsindex 0702be9ab..bf0598cd9 100644--- a/apps/api/src/services/autumn/__tests__/autumn.service.test.ts+++ b/apps/api/src/services/autumn/__tests__/autumn.service.test.ts@@ -698,6 +698,23 @@ describe("firebill routing", () => {vi.unstubAllGlobals();});+ it("preserves a base-path prefix in FIREBILL_URL", async () => {+ state.configRef = {+ ...firebillConfig(),+ FIREBILL_URL: "http://proxy.test/firebill/",+ };++ const svc = makeService();+ await svc.trackCredits({+ teamId: "team-1",+ value: 3,+ properties: { source: "billTeam", endpoint: "scrape" },+ });++ const [url] = mockFetch.mock.calls[0]!;+ expect(String(url)).toBe("http://proxy.test/firebill/v1/track");+ });+it("routes trackCredits for an allowlisted org to firebill, not Autumn", async () => {state.configRef = firebillConfig();const svc = makeService();diff --git a/apps/api/src/services/autumn/firebill.ts b/apps/api/src/services/autumn/firebill.tsindex 0ab167d54..044e19cdb 100644--- a/apps/api/src/services/autumn/firebill.ts+++ b/apps/api/src/services/autumn/firebill.ts@@ -55,13 +55,19 @@ export async function firebillTrack({properties,}: TrackParams): Promise<boolean> {const path = value < 0 ? "/v1/refund" : "/v1/track";+ // Plain concatenation rather than new URL(path, base): a leading-slash path+ // would drop any base-path prefix (e.g. a reverse proxy at /firebill).+ const url = `${config.FIREBILL_URL!.replace(/\/+$/, "")}${path}`;try {- const response = await fetch(new URL(path, config.FIREBILL_URL), {+ const response = await fetch(url, {method: "POST",headers: {authorization: `Bearer ${config.FIREBILL_SECRET}`,"content-type": "application/json",},+ // No overage flag needed: firebill itself pins Autumn's+ // overage_behavior to "overflow" on every upstream call, matching the+ // direct-Autumn path below.body: JSON.stringify({customer_id: customerId,entity_id: entityId,