From b6a826dc46a3fd35e7e7f386bce501f82a24095a Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 31 Jul 2026 15:41:01 +0000 Subject: [PATCH] Replace hand-duplicated VIES/VAT-ID/PLZ/tracking logic with shared package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deletes app/lib/vies.ts, vatId.ts, tracking.ts in favor of the newly unified @einfach-produktiv/invoicing modules — fixes the actual PLZ inconsistency (this repo already validated per-country digit counts; the backend hardcoded German-only) rather than just deduplicating code. Co-Authored-By: Claude Sonnet 5 --- app/api/account/profile/route.ts | 2 +- app/api/checkout/route.ts | 4 +- app/api/checkout/validate-vat/route.ts | 4 +- app/checkout/components/CheckoutContent.tsx | 7 +-- app/konto/bestellungen/[orderNumber]/page.tsx | 4 +- app/lib/shippingDhl.ts | 4 +- app/lib/tracking.ts | 26 --------- app/lib/vatId.ts | 15 ----- app/lib/vies.ts | 58 ------------------- package-lock.json | 4 +- 10 files changed, 15 insertions(+), 113 deletions(-) delete mode 100644 app/lib/tracking.ts delete mode 100644 app/lib/vatId.ts delete mode 100644 app/lib/vies.ts diff --git a/app/api/account/profile/route.ts b/app/api/account/profile/route.ts index 5fba295..05d4b20 100644 --- a/app/api/account/profile/route.ts +++ b/app/api/account/profile/route.ts @@ -1,6 +1,6 @@ import { NextResponse } from "next/server"; import { getSessionCustomer, updateCustomerProfile } from "../../../lib/customerAuth"; -import { normalizeVatId, isValidVatId } from "../../../lib/vatId"; +import { normalizeVatId, isValidVatId } from "@einfach-produktiv/invoicing"; export async function GET() { const session = await getSessionCustomer(); diff --git a/app/api/checkout/route.ts b/app/api/checkout/route.ts index 2ce1939..16fe40b 100644 --- a/app/api/checkout/route.ts +++ b/app/api/checkout/route.ts @@ -8,8 +8,8 @@ import { fetchProductsBySlug } from "../../lib/productsServer"; import { describeBundleContents } from "../../lib/bundleContents"; import { sendCriticalAlert } from "../../lib/alertAdmin"; import { sendOrderConfirmationEmail } from "../../lib/orderEmail"; -import { normalizeVatId, isValidVatId } from "../../lib/vatId"; -import { checkVatIdViaVies } from "../../lib/vies"; +import { normalizeVatId, isValidVatId } from "@einfach-produktiv/invoicing"; +import { checkVatIdViaVies } from "@einfach-produktiv/invoicing/vies"; import { computeExemptTotals, destinationCountry, isExemptionEligibleCountry } from "../../lib/vatExemption"; import { upsertNewsletterContact } from "../../lib/brevo"; import { paymentProvider, isPaymentTestMode } from "../../lib/payments"; diff --git a/app/api/checkout/validate-vat/route.ts b/app/api/checkout/validate-vat/route.ts index e8e545c..ab02f16 100644 --- a/app/api/checkout/validate-vat/route.ts +++ b/app/api/checkout/validate-vat/route.ts @@ -1,6 +1,6 @@ import { NextResponse } from "next/server"; -import { normalizeVatId, isValidVatId } from "../../../lib/vatId"; -import { checkVatIdViaVies } from "../../../lib/vies"; +import { normalizeVatId, isValidVatId } from "@einfach-produktiv/invoicing"; +import { checkVatIdViaVies } from "@einfach-produktiv/invoicing/vies"; // Called from CheckoutContent.tsx on the USt-IdNr. field's blur, whenever // the billing country is Österreich — the only cross-border-EU option this diff --git a/app/checkout/components/CheckoutContent.tsx b/app/checkout/components/CheckoutContent.tsx index 5f59742..f0be638 100644 --- a/app/checkout/components/CheckoutContent.tsx +++ b/app/checkout/components/CheckoutContent.tsx @@ -20,7 +20,7 @@ import { ORDER_KEY, PENDING_ORDER_KEY, type OrderSnapshot } from "../../lib/orde import { PaymentStep } from "./PaymentStep"; import { dispatchAuthChanged } from "../../lib/auth"; import { readCheckoutDraft, writeCheckoutDraft, clearCheckoutDraft } from "../../lib/checkoutDraft"; -import { normalizeVatId, isValidVatId } from "../../lib/vatId"; +import { normalizeVatId, isValidVatId, isValidPlz, plzInputPattern } from "@einfach-produktiv/invoicing"; import { computeExemptTotals, destinationCountry, isExemptionEligibleCountry } from "../../lib/vatExemption"; import { validateEmailFormat } from "../../lib/email"; import type { ShippingMethod, ShippingCountry, PaymentMethod, TrustBadge, ShippingSettings } from "../../lib/payload"; @@ -37,8 +37,7 @@ import type { CustomerProfile } from "../../lib/customerAuth"; // here. `?? 4` only matters if a country somehow isn't in the map at all // (shouldn't happen — the