Closes remaining DS-parity gaps from the feature audit: - ProductRule model (product/collection/vendor/type/tag scoping) with real server-side enforcement in hold-request.server.ts, plus shaped availability in availability-request.server.ts. Covers per-product prep time, cart-content-based slot blocking, and product-restricted locations in one mechanism. New /app/rules admin page (Growth+). - Driving-distance delivery zones via Google's Distance Matrix API, cached like existing geocoding results. - SHIPPING-only estimated arrival range (transitMinDays/transitMaxDays on SlotTemplate) — widget shows "Arrives Thu-Sat" instead of a meaningless ship-out time slot; carried through to the order metafield write-back. Storefront widget and POS extension now send cart contents (vendor/ type from cart.js, product ids for Admin-API-resolved collection/tag rules) to both availability and hold endpoints. checkout-datetime remains excluded from this deploy pending Shopify's Network Access approval (unrelated to this work) — re-add from ../checkout-datetime-disabled and redeploy once granted. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
import type { LoaderFunctionArgs } from "@remix-run/node";
|
|
import type { Method } from "@prisma/client";
|
|
import { authenticate } from "../shopify.server";
|
|
import { resolveAvailabilityRequest } from "../services/availability-request.server";
|
|
import { parseCartLinesParam } from "../lib/cart-rule-params";
|
|
|
|
// POS UI Extension endpoint — session-token authenticated (POS extensions
|
|
// can't use the storefront's app-proxy signature scheme), CORS-enabled
|
|
// since POS calls this cross-origin. Calls the exact same
|
|
// resolveAvailabilityRequest() as the storefront's
|
|
// apps.scheduling.availability.tsx — CLAUDE.md: "the same capacity pool
|
|
// feeds every surface... behavior must never diverge between channels."
|
|
|
|
const VALID_METHODS = new Set<Method>(["SHIPPING", "LOCAL_DELIVERY", "PICKUP"]);
|
|
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
const { sessionToken, cors } = await authenticate.public.pos(request);
|
|
const shopDomain = sessionToken.dest.replace(/^https?:\/\//, "");
|
|
|
|
const url = new URL(request.url);
|
|
const methodParam = url.searchParams.get("method");
|
|
if (!methodParam || !VALID_METHODS.has(methodParam as Method)) {
|
|
return cors(Response.json({ error: "Invalid or missing method" }, { status: 400 }));
|
|
}
|
|
|
|
const result = await resolveAvailabilityRequest(shopDomain, {
|
|
method: methodParam as Method,
|
|
locationId: url.searchParams.get("locationId") || undefined,
|
|
postalCode: url.searchParams.get("postalCode") || undefined,
|
|
address: url.searchParams.get("address") || undefined,
|
|
days: Number(url.searchParams.get("days")) || undefined,
|
|
// POS session-token auth has no Admin API client (unlike the storefront's
|
|
// app-proxy auth), so only vendor/type-scoped ProductRules apply here —
|
|
// product/collection/tag rules need the Admin API round trip that's only
|
|
// available on the app-proxy path (apps.scheduling.availability.tsx).
|
|
cartLines: parseCartLinesParam(url.searchParams.get("cartLines")),
|
|
});
|
|
|
|
return cors(Response.json(result));
|
|
};
|