fix: ship sales tax rates with production runtime
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
export interface SalesTaxAddressInput {
|
||||
line1?: string | null;
|
||||
@@ -25,18 +26,26 @@ interface StateTaxRecord {
|
||||
local_jurisdictions?: LocalJurisdiction[];
|
||||
}
|
||||
|
||||
const taxDataPath = new URL("./salesTaxRates.json", import.meta.url);
|
||||
const TAX_DATA_FALLBACK_URL = new URL("./salesTaxRates.json", import.meta.url);
|
||||
|
||||
const TAX_DATA_CANDIDATE_PATHS: Array<string | URL> = [
|
||||
process.env.SALES_TAX_RATES_PATH ?? "",
|
||||
join(process.cwd(), "salesTaxRates.json"),
|
||||
TAX_DATA_FALLBACK_URL,
|
||||
].filter(Boolean);
|
||||
|
||||
const parseTaxData = (): StateTaxRecord[] => {
|
||||
try {
|
||||
const raw = readFileSync(taxDataPath, "utf-8");
|
||||
const parsed = JSON.parse(raw) as StateTaxRecord[];
|
||||
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
return parsed;
|
||||
} catch {
|
||||
return [];
|
||||
for (const source of TAX_DATA_CANDIDATE_PATHS) {
|
||||
try {
|
||||
const raw = readFileSync(source, "utf-8");
|
||||
const parsed = JSON.parse(raw) as StateTaxRecord[];
|
||||
if (Array.isArray(parsed)) return parsed;
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
const SALES_TAX_DATA = parseTaxData();
|
||||
|
||||
Reference in New Issue
Block a user