/** Checkout guard (cart & checkout validation function) lookup, shared by Settings and the Today setup guide. */ export const GUARD_HANDLE = "datewise-checkout-guard"; export type AdminGraphql = { graphql: (q: string, o?: { variables?: Record }) => Promise }; export async function gql(admin: AdminGraphql, q: string, variables?: Record) { const r = await admin.graphql(q, { variables }); return ((await r.json()) as { data: T }).data; } export async function findGuard(admin: AdminGraphql) { const d = await gql<{ shopifyFunctions: { nodes: { id: string; title: string; apiType: string }[] }; validations: { nodes: { id: string; enabled: boolean; shopifyFunction: { id: string } }[] }; }>(admin, `#graphql query { shopifyFunctions(first: 50) { nodes { id title apiType } } validations(first: 25) { nodes { id enabled shopifyFunction { id } } } }`); const fn = d.shopifyFunctions.nodes.find((f) => f.title === GUARD_HANDLE || /datewise/i.test(f.title)); const validation = fn ? d.validations.nodes.find((v) => v.shopifyFunction.id === fn.id) : undefined; return { fn, validation }; }