@zappie/foundations 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @zappie/foundations
2
2
 
3
+ ## 0.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bc9580f: `@zappie/sdk/server` holds the server side every site repeats. `pageCacheRules({ menu })` returns the page cache rules and headers for the pages you name. `siteWorker` is the whole site Worker: the closed page, an early redirect, the edge page cache and the error page. `robotsResponse` and `sitemapResponse` answer robots and the sitemap, `allMenus` reads each branch's menu for it, `storeRedirect` reads the merchant's own redirects, `originFetch` names the shopper's origin on each API call, and `legacyRedirects({ business })` moves the classic storefront's addresses onto your site.
8
+
9
+ `@zappie/foundations/site/server` holds what needs React Router: `siteContext`, `createServerClient`, `siteEnv`, `siteMode`, `isPreview`, `requestOrigin`, `documentHandler` (the whole of `entry.server.tsx`) and `closedPageData`. `@zappie/foundations/site` has `PageViews`, `useAtTable`, `IN_VENUE_HANDLE`, `pageTitle` and `isClosedPage`. `@zappie/foundations/site/customer` has `CustomerGate` and `useCheckoutReturn`.
10
+
11
+ The starter's cache rules, server client, `entry.server.tsx`, Worker, robots, sitemap, customer gate, checkout return and page views use them, and its copies are gone.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [bc9580f]
16
+ - @zappie/sdk@0.20.0
17
+
3
18
  ## 0.20.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -31,21 +31,24 @@ Want ready-made, styled components instead? Copy them into your project from the
31
31
 
32
32
  ## Entry points
33
33
 
34
- | Import | For |
35
- | ----------------------------------- | ----------------------------------------------------------------------- |
36
- | `@zappie/foundations` | Every part |
37
- | `@zappie/foundations/next` | Keeping overlays in step with Back and Forward in a Next.js app |
38
- | `@zappie/foundations/branch-switch` | Choosing a branch in a React Router site without waiting for the server |
39
- | `@zappie/foundations/branch-finder` | Opening the site's branch picker or locator from any control |
40
- | `@zappie/foundations/branch-list` | Nearest-first branch lists and what each branch sells |
41
- | `@zappie/foundations/hours` | Open now, opening labels, closed for orders and a week of hours |
42
- | `@zappie/foundations/checkout` | Checkout behaviour for a bag or a cart page, with no markup |
43
- | `@zappie/foundations/loyalty` | The rewards sheet's parts, the bag's rewards row and the claim toast |
44
- | `@zappie/foundations/order` | A customer's order details page, as parts or one default layout |
45
- | `@zappie/foundations/item-sheet` | A product sheet over the current page in a React Router site |
46
- | `@zappie/foundations/bag` | The bag over the page, its address and the "added" notice |
47
- | `@zappie/foundations/bag/server` | The `/cart` and `/checkout` redirects that open the bag |
48
- | `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
34
+ | Import | For |
35
+ | ----------------------------------- | ---------------------------------------------------------------------------------------- |
36
+ | `@zappie/foundations` | Every part |
37
+ | `@zappie/foundations/next` | Keeping overlays in step with Back and Forward in a Next.js app |
38
+ | `@zappie/foundations/branch-switch` | Choosing a branch in a React Router site without waiting for the server |
39
+ | `@zappie/foundations/branch-finder` | Opening the site's branch picker or locator from any control |
40
+ | `@zappie/foundations/branch-list` | Nearest-first branch lists and what each branch sells |
41
+ | `@zappie/foundations/hours` | Open now, opening labels, closed for orders and a week of hours |
42
+ | `@zappie/foundations/checkout` | Checkout behaviour for a bag or a cart page, with no markup |
43
+ | `@zappie/foundations/loyalty` | The rewards sheet's parts, the bag's rewards row and the claim toast |
44
+ | `@zappie/foundations/order` | A customer's order details page, as parts or one default layout |
45
+ | `@zappie/foundations/item-sheet` | A product sheet over the current page in a React Router site |
46
+ | `@zappie/foundations/bag` | The bag over the page, its address and the "added" notice |
47
+ | `@zappie/foundations/bag/server` | The `/cart` and `/checkout` redirects that open the bag |
48
+ | `@zappie/foundations/site` | Page views, the table page check, page titles and the closed page's data type |
49
+ | `@zappie/foundations/site/customer` | The signed-in pages' gate and the checkout return page's state |
50
+ | `@zappie/foundations/site/server` | A React Router site's load context, server client, document handler and closed page data |
51
+ | `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
49
52
 
50
53
  ## Docs
51
54
 
@@ -838,3 +841,54 @@ is the themed dot. Like `BranchMap`, it renders nothing without a key, loads
838
841
  Maps after mount, calls `onLoadError(error)` on a failure and shows “Map location
839
842
  unavailable” when either point has no valid coordinates. It fits again when the
840
843
  points, the route or its size change.
844
+
845
+ ## Site plumbing
846
+
847
+ Every React Router site runs the same plumbing around its own pages. These parts hold it, so a site keeps only its
848
+ choices and its markup. The framework-free pieces (the page cache rules, the Worker, robots, the sitemap and the old
849
+ address redirects) are in `@zappie/sdk/server`.
850
+
851
+ `@zappie/foundations/site/server` runs on the server only:
852
+
853
+ - `siteContext(env, ctx)` is the load context for React Router's request handler. `envContext` and `edgeContext`
854
+ read it back.
855
+ - `createServerClient({ store, branch })` returns the site's `serverClient(context, request)`: one Zappie client per
856
+ request, `{ client, env, origin }`. It reads the store and its menus through the Worker's edge cache, except for a
857
+ draft, a review or `ZAPPIE_EDGE_CACHE=off`. `siteEnv`, `siteMode`, `isPreview` and `requestOrigin` are there for
858
+ your own loaders.
859
+ - `documentHandler({ config, cache, isBot })` is the whole of `app/entry.server.tsx`: a CSP nonce, Zappie's security
860
+ headers, and cache headers from your `pageCacheRules`. Pass `page` when your root's data isn't the usual
861
+ `{ mode, menu, store }`.
862
+ - `closedPageData(store, closed)` is what your closed page shows, formatted on the server. `branches`, `hours` and
863
+ `title` change the order, the hours and the title.
864
+
865
+ `@zappie/foundations/site` runs on both sides:
866
+
867
+ - `<PageViews storeName enabled />` counts a visit for each page, and skips the bag's `?bag=open` address.
868
+ - `useAtTable()` is true on a route whose `handle` is `IN_VENUE_HANDLE`.
869
+ - `pageTitle(store, page)` titles a page in the store's own pattern.
870
+ - `isClosedPage(data)` tells the closed page's data from the shop's.
871
+
872
+ `@zappie/foundations/site/customer` is for the customer's pages:
873
+
874
+ - `<CustomerGate returnTo>` signs a shopper in once, then renders your page with the customer client. Pass
875
+ `checking` and `signedOut` for your own markup.
876
+ - `useCheckoutReturn()` waits for the payment on `/checkout/return`, then clears the cart and opens the order. It
877
+ returns `{ state, title, body }`, and you draw the page.
878
+
879
+ ```tsx
880
+ // app/entry.server.tsx
881
+ export default documentHandler({
882
+ config: siteConfig,
883
+ cache: pageCache,
884
+ isBot: isbot,
885
+ });
886
+
887
+ // app/server.ts
888
+ export const serverClient = createServerClient({ store: "my-shop" });
889
+
890
+ // app/routes/orders.tsx
891
+ <CustomerGate returnTo="/orders" className="status-page">
892
+ {(customer) => <Orders customer={customer} />}
893
+ </CustomerGate>;
894
+ ```
@@ -0,0 +1,2 @@
1
+ "use client";import{useMatches}from"react-router";var IN_VENUE_HANDLE=Object.freeze({inVenue:true});function useAtTable(){return useMatches().some(match=>match.handle?.inVenue===true)}export{IN_VENUE_HANDLE,useAtTable};
2
+ //# sourceMappingURL=at-table.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/site/at-table.ts"],
4
+ "mappings": "aACA,OAAS,eAAkB,eAMpB,IAAM,gBAA8C,OAAO,OAAO,CACvE,QAAS,IACX,CAAC,EAMM,SAAS,YAAsB,CACpC,OAAO,WAAW,EAAE,KACjB,OACE,MAAM,QAA8C,UAAY,IACrE,CACF",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ var isClosedPage=data=>typeof data==="object"&&data!==null&&"closed"in data;export{isClosedPage};
2
+ //# sourceMappingURL=closed.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/site/closed.ts"],
4
+ "mappings": "AAuBO,IAAM,aAAgB,MAC3B,OAAO,OAAS,UAAY,OAAS,MAAQ,WAAY",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ "use client";import{createCheckout}from"@zappie/sdk/checkout";import{useCart}from"@zappie/sdk/react";import{useEffect,useMemo,useRef,useState}from"react";import{useNavigate,useSearchParams}from"react-router";var CHECKOUT_RETURN_WORDS=Object.freeze({waiting:{title:"Confirming your payment",body:"This takes a few seconds."},ended:{title:"That payment ended",body:"Nothing was charged. Your cart is unchanged."},missing:{title:"Nothing to confirm",body:"This page opens after a payment."},unknown:{title:"We could not confirm it here",body:"If you paid, the order is in your orders."}});function useCheckoutReturn({words,orderHref=id=>`/orders/${encodeURIComponent(id)}`}={}){const[query]=useSearchParams();const sessionId=query.get("session")??"";const[state,setState]=useState(sessionId?"waiting":"missing");const checkout=useMemo(()=>createCheckout(),[]);const cart=useCart();const navigate=useNavigate();const href=useRef(orderHref);href.current=orderHref;useEffect(()=>{if(!sessionId){return}const abort=new AbortController;void checkout.awaitCompletion(sessionId,{signal:abort.signal}).then(session=>{if(session.status==="completed"){cart.actions.clear();navigate(href.current(session.order_id),{replace:true})}else{setState("ended")}},()=>{if(!abort.signal.aborted){setState("unknown")}});return()=>abort.abort()},[cart.actions,checkout,navigate,sessionId]);return{state,...{...CHECKOUT_RETURN_WORDS,...words}[state]}}export{CHECKOUT_RETURN_WORDS,useCheckoutReturn};
2
+ //# sourceMappingURL=checkout-return.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/site/customer/checkout-return.ts"],
4
+ "mappings": "aACA,OAAS,mBAAsB,uBAC/B,OAAS,YAAe,oBACxB,OAAS,UAAW,QAAS,OAAQ,aAAgB,QACrD,OAAS,YAAa,oBAAuB,eAYtC,IAAM,sBACX,OAAO,OAAO,CACZ,QAAS,CACP,MAAO,0BACP,KAAM,2BACR,EACA,MAAO,CACL,MAAO,qBACP,KAAM,8CACR,EACA,QAAS,CACP,MAAO,qBACP,KAAM,kCACR,EACA,QAAS,CACP,MAAO,+BACP,KAAM,2CACR,CACF,CAAC,EA0BI,SAAS,kBAAkB,CAChC,MACA,UAAa,IAAO,WAAW,mBAAmB,EAAE,CAAC,EACvD,EAA2B,CAAC,EAI1B,CACA,KAAM,CAAC,KAAK,EAAI,gBAAgB,EAChC,MAAM,UAAY,MAAM,IAAI,SAAS,GAAK,GAC1C,KAAM,CAAC,MAAO,QAAQ,EAAI,SACxB,UAAY,UAAY,SAC1B,EACA,MAAM,SAAW,QAAQ,IAAM,eAAe,EAAG,CAAC,CAAC,EACnD,MAAM,KAAO,QAAQ,EACrB,MAAM,SAAW,YAAY,EAC7B,MAAM,KAAO,OAAO,SAAS,EAC7B,KAAK,QAAU,UACf,UAAU,IAAM,CACd,GAAI,CAAC,UAAW,CACd,MACF,CACA,MAAM,MAAQ,IAAI,gBAClB,KAAK,SAAS,gBAAgB,UAAW,CAAE,OAAQ,MAAM,MAAO,CAAC,EAAE,KAChE,SAAY,CACX,GAAI,QAAQ,SAAW,YAAa,CAClC,KAAK,QAAQ,MAAM,EACnB,SAAS,KAAK,QAAQ,QAAQ,QAAQ,EAAG,CAAE,QAAS,IAAK,CAAC,CAC5D,KAAO,CACL,SAAS,OAAO,CAClB,CACF,EACA,IAAM,CACJ,GAAI,CAAC,MAAM,OAAO,QAAS,CACzB,SAAS,SAAS,CACpB,CACF,CACF,EACA,MAAO,IAAM,MAAM,MAAM,CAC3B,EAAG,CAAC,KAAK,QAAS,SAAU,SAAU,SAAS,CAAC,EAChD,MAAO,CAAE,MAAO,GAAG,CAAE,GAAG,sBAAuB,GAAG,KAAM,EAAE,KAAK,CAAE,CACnE",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ "use client";import{createCustomer}from"@zappie/sdk/customer";import{CustomerProvider,useAuth}from"@zappie/sdk/customer/react";import{useEffect,useMemo,useState}from"react";import{signInOnce}from"../../checkout/sign-in.js";import{jsx,jsxs}from"react/jsx-runtime";function Gate({returnTo,children,checking,signedOut,className}){const auth=useAuth();const[failed,setFailed]=useState(false);useEffect(()=>{if(auth.state==="anonymous"){setFailed(!signInOnce(returnTo))}},[auth.state,returnTo]);if(failed){const again=()=>setFailed(!signInOnce(returnTo));return signedOut?signedOut(again):jsxs("div",{className,role:"alert",children:[jsx("p",{children:"You're not signed in yet."}),jsx("button",{type:"button",onClick:again,children:"Sign in again"})]})}if(auth.state!=="authenticated"||!auth.customer){return checking??jsx("p",{className,role:"status",children:"Checking your account\u2026"})}return children}function CustomerGate({children,...props}){const client=useMemo(()=>createCustomer(),[]);return jsx(CustomerProvider,{client,children:jsx(Gate,{...props,children:children(client)})})}export{CustomerGate};
2
+ //# sourceMappingURL=gate.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/site/customer/gate.tsx"],
4
+ "mappings": "aACA,OAAS,mBAA2C,uBACpD,OAAS,iBAAkB,YAAe,6BAC1C,OAAS,UAAW,QAAS,aAAgC,QAC7D,OAAS,eAAkB,4BAsCrB,OACE,IADF,6BAnBN,SAAS,KAAK,CACZ,SACA,SACA,SACA,UACA,SACF,EAAkE,CAChE,MAAM,KAAO,QAAQ,EACrB,KAAM,CAAC,OAAQ,SAAS,EAAI,SAAS,KAAK,EAC1C,UAAU,IAAM,CACd,GAAI,KAAK,QAAU,YAAa,CAC9B,UAAU,CAAC,WAAW,QAAQ,CAAC,CACjC,CACF,EAAG,CAAC,KAAK,MAAO,QAAQ,CAAC,EACzB,GAAI,OAAQ,CACV,MAAM,MAAQ,IAAM,UAAU,CAAC,WAAW,QAAQ,CAAC,EACnD,OAAO,UACL,UAAU,KAAK,EAEf,KAAC,OAAI,UAAsB,KAAK,QAC9B,cAAC,KAAE,qCAA8B,EACjC,IAAC,UAAO,KAAK,SAAS,QAAS,MAAO,yBAEtC,GACF,CAEJ,CACA,GAAI,KAAK,QAAU,iBAAmB,CAAC,KAAK,SAAU,CACpD,OACE,UACE,IAAC,KAAE,UAAsB,KAAK,SAAS,uCAEvC,CAGN,CACA,OAAO,QACT,CAYO,SAAS,aAAa,CAAE,SAAU,GAAG,KAAM,EAAsB,CACtE,MAAM,OAAS,QAAQ,IAAM,eAAe,EAAG,CAAC,CAAC,EACjD,OACE,IAAC,kBAAiB,OAChB,aAAC,MAAM,GAAG,MAAQ,kBAAS,MAAM,EAAE,EACrC,CAEJ",
5
+ "names": []
6
+ }
@@ -0,0 +1,72 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { CustomerClient } from '@zappie/sdk/customer';
4
+
5
+ /** Where a return from Zappie's hosted checkout stands. */
6
+ type CheckoutReturnState = "waiting" | "ended" | "missing" | "unknown";
7
+ /** A state's heading and the sentence under it. */
8
+ type CheckoutReturnWords = Record<CheckoutReturnState, {
9
+ title: string;
10
+ body: string;
11
+ }>;
12
+ /** The default words for each state. */
13
+ declare const CHECKOUT_RETURN_WORDS: Readonly<CheckoutReturnWords>;
14
+ /** Options for {@link useCheckoutReturn}. */
15
+ type CheckoutReturnOptions = {
16
+ /** Your own words for any state. */
17
+ words?: Partial<CheckoutReturnWords>;
18
+ /** The order's page. Defaults to `/orders/<id>`. */
19
+ orderHref?: (orderId: string) => string;
20
+ };
21
+ /**
22
+ * The `/checkout/return` page's state, for Zappie's hosted checkout to come back to with `?session=`. It waits for
23
+ * the payment, then clears the cart and replaces the page with the order's. A payment that ended without one is
24
+ * `ended`, a page opened without a session is `missing`, and a session it could not confirm is `unknown`. You draw
25
+ * the page.
26
+ *
27
+ * @example
28
+ * const { state, title, body } = useCheckoutReturn();
29
+ * return (
30
+ * <main aria-live="polite">
31
+ * <h1>{title}</h1>
32
+ * <p>{body}</p>
33
+ * {state !== "waiting" && <Link to={state === "unknown" ? "/orders" : "/"}>Continue</Link>}
34
+ * </main>
35
+ * );
36
+ */
37
+ declare function useCheckoutReturn({ words, orderHref, }?: CheckoutReturnOptions): {
38
+ state: CheckoutReturnState;
39
+ title: string;
40
+ body: string;
41
+ };
42
+
43
+ /** Props for {@link CustomerGate}. */
44
+ type CustomerGateProps = {
45
+ /** The page to come back to after signing in, such as `/orders`. */
46
+ returnTo: string;
47
+ /** The page, given the signed-in customer's client. Renders only once the customer is signed in. */
48
+ children: (client: CustomerClient) => ReactNode;
49
+ /** What shows while the account is checked. Defaults to "Checking your account…" in a status paragraph. */
50
+ checking?: ReactNode;
51
+ /**
52
+ * What shows when a sign-in came back without a session the site can use, given the function that signs in again.
53
+ * Defaults to "You're not signed in yet." and a "Sign in again" button in an alert.
54
+ */
55
+ signedOut?: (signInAgain: () => void) => ReactNode;
56
+ /** The class of the default `checking` and `signedOut` elements. */
57
+ className?: string;
58
+ };
59
+ /**
60
+ * A page for a signed-in customer only, such as their orders or account. It provides a customer client and sends a
61
+ * shopper who isn't signed in to sign in, once: when that sign-in comes back without a session, it says so and
62
+ * offers to sign in again instead of looping.
63
+ *
64
+ * @example
65
+ * <CustomerGate returnTo="/orders" className="status-page">
66
+ * {(client) => <Orders client={client} />}
67
+ * </CustomerGate>
68
+ */
69
+ declare function CustomerGate({ children, ...props }: CustomerGateProps): react.JSX.Element;
70
+
71
+ export { CHECKOUT_RETURN_WORDS, CustomerGate, useCheckoutReturn };
72
+ export type { CheckoutReturnOptions, CheckoutReturnState, CheckoutReturnWords, CustomerGateProps };
@@ -0,0 +1,2 @@
1
+ "use client";import{CHECKOUT_RETURN_WORDS,useCheckoutReturn}from"./checkout-return.js";import{CustomerGate}from"./gate.js";export{CHECKOUT_RETURN_WORDS,CustomerGate,useCheckoutReturn};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/site/customer/index.ts"],
4
+ "mappings": "aACA,OACE,sBACA,sBAIK,uBACP,OAAS,iBAA4C",
5
+ "names": []
6
+ }
@@ -0,0 +1,35 @@
1
+ export { C as ClosedPageData, i as isClosedPage, p as pageTitle } from '../title-CgphFqNB.js';
2
+ import '@zappie/sdk';
3
+
4
+ /**
5
+ * The route `handle` for a table page (`/pay-point/:id`, `/dine-in/…`): export it from the route that renders the
6
+ * SDK's `InVenuePage`, so {@link useAtTable} knows the page is at a table.
7
+ */
8
+ declare const IN_VENUE_HANDLE: {
9
+ readonly inVenue: true;
10
+ };
11
+ /**
12
+ * True on a table page, a route whose `handle` has `inVenue: true`. There the SDK's order panel is the table's bag,
13
+ * so the shell hides its own bag button and bag.
14
+ */
15
+ declare function useAtTable(): boolean;
16
+
17
+ /** Props for {@link PageViews}. */
18
+ type PageViewsProps = {
19
+ /** The store's name, which the visit records. */
20
+ storeName: string;
21
+ /**
22
+ * Whether this page counts visits. Pass `mode === "site"`: a draft or review runs where no hosting layer answers
23
+ * `/_zappie/view`.
24
+ */
25
+ enabled: boolean;
26
+ };
27
+ /**
28
+ * Counts a visit for each page the shopper opens, through `countPage` from `@zappie/sdk/visits`. An address with
29
+ * `?bag=open`, where `/cart` and `/checkout` land, is not counted: the bag takes the parameter off at once, and the
30
+ * address it leaves counts. Render it once, in the root. It renders nothing.
31
+ */
32
+ declare function PageViews({ storeName, enabled }: PageViewsProps): null;
33
+
34
+ export { IN_VENUE_HANDLE, PageViews, useAtTable };
35
+ export type { PageViewsProps };
@@ -0,0 +1,2 @@
1
+ "use client";import{IN_VENUE_HANDLE,useAtTable}from"./at-table.js";import{isClosedPage}from"./closed.js";import{PageViews}from"./page-views.js";import{pageTitle}from"./title.js";export{IN_VENUE_HANDLE,PageViews,isClosedPage,pageTitle,useAtTable};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/site/index.ts"],
4
+ "mappings": "aACA,OAAS,gBAAiB,eAAkB,gBAC5C,OAAS,iBAAyC,cAClD,OAAS,cAAsC,kBAC/C,OAAS,cAAiB",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ "use client";import{countPage}from"@zappie/sdk/visits";import{useEffect}from"react";import{useLocation}from"react-router";import{hasBagParam}from"../bag/index.js";function PageViews({storeName,enabled}){const location=useLocation();useEffect(()=>{if(hasBagParam(location.search)){return}countPage({path:location.pathname,search:location.search,title:document.title,referrer:document.referrer,storeName,enabled})},[enabled,location.pathname,location.search,storeName]);return null}export{PageViews};
2
+ //# sourceMappingURL=page-views.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/site/page-views.tsx"],
4
+ "mappings": "aACA,OAAS,cAAiB,qBAC1B,OAAS,cAAiB,QAC1B,OAAS,gBAAmB,eAC5B,OAAS,gBAAmB,kBAkBrB,SAAS,UAAU,CAAE,UAAW,OAAQ,EAAyB,CACtE,MAAM,SAAW,YAAY,EAC7B,UAAU,IAAM,CACd,GAAI,YAAY,SAAS,MAAM,EAAG,CAChC,MACF,CACA,UAAU,CACR,KAAM,SAAS,SACf,OAAQ,SAAS,OACjB,MAAO,SAAS,MAChB,SAAU,SAAS,SACnB,UACA,OACF,CAAC,CACH,EAAG,CAAC,QAAS,SAAS,SAAU,SAAS,OAAQ,SAAS,CAAC,EAC3D,OAAO,IACT",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ import{formatPhone}from"@zappie/sdk/display";import{siteClosedCopy}from"@zappie/sdk/site-closed";import{contactLinks}from"../../status/contact.js";import{formatOpeningHours}from"../../status/hours.js";import{pageTitle}from"../title.js";function closedPageData(store,closed,{copy,title=pageTitle,branches=all=>all,hours=branch=>formatOpeningHours(branch.openingTimes).map(group=>({days:group.dayLabel,hours:group.hoursLabel}))}={}){const words=siteClosedCopy(closed,copy);return{closed:words,title:title(store,words.title),store:{name:store.name,...store.brand.logoUrl?{logoUrl:store.brand.logoUrl}:{},...store.templateSettings?{templateSettings:store.templateSettings}:{}},branches:branches(store.branches).map(branch=>({id:branch.id,name:branch.name,...branch.address?{address:branch.address}:{},contact:contactLinks(branch).map(link=>({href:link.href,label:link.type==="phone"&&branch.phone?formatPhone(branch.phone,branch.country?{country:branch.country}:{}):link.label})),hours:hours(branch)}))}}export{closedPageData};
2
+ //# sourceMappingURL=closed.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/site/server/closed.ts"],
4
+ "mappings": "AACA,OAAS,gBAAmB,sBAC5B,OAAS,mBAAuC,0BAChD,OAAS,iBAAoB,0BAC7B,OAAS,uBAA0B,wBAEnC,OAAS,cAAiB,cA4BnB,SAAS,eACd,MACA,OACA,CACE,KACA,MAAQ,UACR,SAAY,KAAQ,IACpB,MAAS,QACP,mBAAmB,OAAO,YAAY,EAAE,IAAK,QAAW,CACtD,KAAM,MAAM,SACZ,MAAO,MAAM,UACf,EAAE,CACN,EAAuB,CAAC,EACR,CAChB,MAAM,MAAQ,eAAe,OAAQ,IAAI,EACzC,MAAO,CACL,OAAQ,MACR,MAAO,MAAM,MAAO,MAAM,KAAK,EAC/B,MAAO,CACL,KAAM,MAAM,KACZ,GAAI,MAAM,MAAM,QAAU,CAAE,QAAS,MAAM,MAAM,OAAQ,EAAI,CAAC,EAC9D,GAAI,MAAM,iBACN,CAAE,iBAAkB,MAAM,gBAAiB,EAC3C,CAAC,CACP,EACA,SAAU,SAAS,MAAM,QAAQ,EAAE,IAAK,SAAY,CAClD,GAAI,OAAO,GACX,KAAM,OAAO,KACb,GAAI,OAAO,QAAU,CAAE,QAAS,OAAO,OAAQ,EAAI,CAAC,EACpD,QAAS,aAAa,MAAM,EAAE,IAAK,OAAU,CAC3C,KAAM,KAAK,KACX,MACE,KAAK,OAAS,SAAW,OAAO,MAC5B,YACE,OAAO,MACP,OAAO,QAAU,CAAE,QAAS,OAAO,OAAQ,EAAI,CAAC,CAClD,EACA,KAAK,KACb,EAAE,EACF,MAAO,MAAM,MAAM,CACrB,EAAE,CACJ,CACF",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ import{createZappie}from"@zappie/sdk";import{cachedApiFetch,originFetch}from"@zappie/sdk/server";import{createContext,RouterContextProvider}from"react-router";var envContext=createContext({});var edgeContext=createContext(void 0);function siteContext(env,ctx){const context=new RouterContextProvider;context.set(envContext,env);context.set(edgeContext,ctx);return context}var read=(context,key)=>{const get=context?.get;try{return typeof get==="function"?get.call(context,key):void 0}catch{return void 0}};function siteEnv(context,request){const provided=read(context,envContext)??{};const cloudflare=context?.cloudflare?.env??{};const processEnv=globalThis.process?.env??{};const value={...processEnv,...cloudflare,...provided};const baseUrl=value.ZAPPIE_API?.replace(/\/+$/,"");const key=value.ZAPPIE_KEY||request.headers.get("x-zappie-key")||void 0;if(!baseUrl||!key){throw new Error("The site has no ZAPPIE_API or ZAPPIE_KEY binding.")}return{...value,ZAPPIE_API:baseUrl,ZAPPIE_KEY:key,ZAPPIE_DRAFT:value.ZAPPIE_DRAFT??request.headers.get("x-zappie-draft")??"",ZAPPIE_REVIEW:value.ZAPPIE_REVIEW??request.headers.get("x-zappie-review")??""}}function isPreview(env){return env.ZAPPIE_DRAFT==="1"||env.ZAPPIE_REVIEW==="1"}function siteMode(env,{dev=false}={}){if(env.ZAPPIE_REVIEW==="1"){return"review"}return env.ZAPPIE_DRAFT==="1"||dev?"draft":"site"}function requestOrigin(request){const forwardedHost=request.headers.get("x-forwarded-host");if(!forwardedHost){return new URL(request.url).origin}return`${request.headers.get("x-forwarded-proto")??"https"}://${forwardedHost}`}function createServerClient(options={}){const made=new WeakMap;const make=(context,request)=>{const env=siteEnv(context,request);const store=env.ZAPPIE_STORE??options.store;if(!store){throw new Error("The site has no ZAPPIE_STORE binding.")}const branch=env.ZAPPIE_BRANCH??options.branch;const origin=requestOrigin(request);const cached=!isPreview(env)&&env.ZAPPIE_EDGE_CACHE!=="off";const ctx=read(context,edgeContext);const plain=originFetch(origin);return{client:createZappie({store,key:env.ZAPPIE_KEY,...branch?{branch}:{},baseUrl:env.ZAPPIE_API,customerBase:`${origin}/_zappie/api`,fetch:cached?cachedApiFetch({...ctx?{ctx}:{},fetch:plain}):plain,telemetry:false}),env:{...env,ZAPPIE_STORE:store,...branch?{ZAPPIE_BRANCH:branch}:{}},origin}};return(context,request)=>{if(typeof context!=="object"||context===null){return make(context,request)}const existing=made.get(context);if(existing){return existing}const shared=make(context,request);made.set(context,shared);return shared}}export{createServerClient,edgeContext,envContext,isPreview,requestOrigin,siteContext,siteEnv,siteMode};
2
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/site/server/context.ts"],
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O,QACT,CACA,MAAM,OAAS,KAAK,QAAS,OAAO,EACpC,KAAK,IAAI,QAAS,MAAM,EACxB,OAAO,MACT,CACF",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ import{createSecurityNonce,deferredDataFailed,securityHeaders,sharedCacheControl,snapshotHash}from"@zappie/sdk/server";import{renderToReadableStream}from"react-dom/server.edge";import{ServerRouter}from"react-router";import{isClosedPage}from"../closed.js";import{envContext}from"./context.js";import{jsx}from"react/jsx-runtime";function defaultPage(root){if(isClosedPage(root)){return{closed:true}}if(typeof root!=="object"||root===null){return{closed:false}}const shop=root;return{closed:false,...shop.mode?{mode:shop.mode}:{},...shop.menu?.version?{menuVersion:shop.menu.version}:{},...shop.store?{store:shop.store}:{}}}function documentHandler({config,cache,isBot,page=defaultPage}){return async function handleRequest(request,status,headers,routerContext,loadContext){const nonce=createSecurityNonce();let shell=false;let failed=false;const body=await renderToReadableStream(jsx(ServerRouter,{context:routerContext,url:request.url,nonce}),{nonce,onError(error){status=500;failed=true;if(shell){console.error(error)}}});shell=true;const{loaderData,errors}=routerContext.staticHandlerContext;const shop=page(loaderData.root);const pathname=new URL(request.url).pathname;const preview=shop.closed||shop.mode!=="site";const own=headers.get("cache-control");const shareable=own?sharedCacheControl(own):cache.documentCacheRule({pathname,status,preview})!=="private";if(shop.closed||shareable||isBot(request.headers.get("user-agent")??"")||routerContext.isSpaMode){await body.allReady}const apiUrl=loadContext.get(envContext).ZAPPIE_API;const responseHeaders=securityHeaders({nonce,config,...apiUrl?{apiUrl}:{},headers,hosted:["x-zappie-site","x-zappie-review","x-zappie-draft","x-zappie-key"].some(name=>request.headers.has(name))});responseHeaders.set("content-type","text/html; charset=utf-8");const setsCookie=responseHeaders.has("set-cookie");const errored=failed||Boolean(errors)||shareable&&await deferredDataFailed(loaderData);if(!own||setsCookie||shareable&&errored){const values=cache.documentCacheHeaders({pathname,status,preview,setsCookie,failed:errored,...shop.menuVersion&&shop.store?{menuVersion:shop.menuVersion,storeVersion:await snapshotHash(shop.store)}:{},deployId:routerContext.manifest.version});for(const[name,value]of Object.entries(values)){responseHeaders.set(name,value)}}return new Response(body,{status,headers:responseHeaders})}}export{documentHandler};
2
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/site/server/document.tsx"],
4
+ "mappings": "AACA,OACE,oBACA,mBACA,gBACA,mBACA,iBAEK,qBACP,OAAS,2BAA8B,wBACvC,OACE,iBAGK,eACP,OAAS,iBAAoB,eAC7B,OAAS,eAAkB,eAiFrB,mCApDN,SAAS,YAAY,KAA6B,CAChD,GAAI,aAAa,IAAI,EAAG,CACtB,MAAO,CAAE,OAAQ,IAAK,CACxB,CACA,GAAI,OAAO,OAAS,UAAY,OAAS,KAAM,CAC7C,MAAO,CAAE,OAAQ,KAAM,CACzB,CACA,MAAM,KAAO,KAKb,MAAO,CACL,OAAQ,MACR,GAAI,KAAK,KAAO,CAAE,KAAM,KAAK,IAAK,EAAI,CAAC,EACvC,GAAI,KAAK,MAAM,QAAU,CAAE,YAAa,KAAK,KAAK,OAAQ,EAAI,CAAC,EAC/D,GAAI,KAAK,MAAQ,CAAE,MAAO,KAAK,KAAM,EAAI,CAAC,CAC5C,CACF,CAiBO,SAAS,gBAAgB,CAC9B,OACA,MACA,MACA,KAAO,WACT,EAA2B,CACzB,OAAO,eAAe,cACpB,QACA,OACA,QACA,cACA,YACmB,CACnB,MAAM,MAAQ,oBAAoB,EAClC,IAAI,MAAQ,MACZ,IAAI,OAAS,MACb,MAAM,KAAO,MAAM,uBACjB,IAAC,cAAa,QAAS,cAAe,IAAK,QAAQ,IAAK,MAAc,EACtE,CAGE,MACA,QAAQ,MAAgB,CACtB,OAAS,IACT,OAAS,KACT,GAAI,MAAO,CACT,QAAQ,MAAM,KAAK,CACrB,CACF,CACF,CACF,EACA,MAAQ,KACR,KAAM,CAAE,WAAY,MAAO,EAAI,cAAc,qBAC7C,MAAM,KAAO,KAAK,W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{ i as isClosedPage, p as pageTitle } from '../../title-CgphFqNB.js';
3
+ import { Store, Zappie } from '@zappie/sdk';
4
+ import { siteClosedCopy, SiteClosed } from '@zappie/sdk/site-closed';
5
+ import * as react_router from 'react-router';
6
+ import { RouterContextProvider, EntryContext } from 'react-router';
7
+ import { EdgeContext, PageCacheRules } from '@zappie/sdk/server';
8
+ import { ZappieSiteConfig } from '@zappie/sdk/config';
9
+
10
+ type Branch = Store["branches"][number];
11
+ /** Options for {@link closedPageData}. */
12
+ type ClosedPageOptions = {
13
+ /** The page's words when the merchant set no message. */
14
+ copy?: Parameters<typeof siteClosedCopy>[1];
15
+ /** The page's title. Defaults to the words' title in the store's own title pattern. */
16
+ title?: (store: Store, page: string) => string;
17
+ /** The branches in the order the page lists them. Defaults to the store's order. */
18
+ branches?: (branches: Branch[]) => Branch[];
19
+ /** A branch's week of hours. Defaults to `formatOpeningHours`' groups. */
20
+ hours?: (branch: Branch) => {
21
+ days: string;
22
+ hours: string;
23
+ }[];
24
+ };
25
+ /**
26
+ * What the closed page shows, from the store alone: never the menu or the shop's redirects. The words, phone numbers
27
+ * and hours are formatted on the server, so the browser's code carries none of it. Return it from the root loader
28
+ * when `siteClosed(request)` says the storefront is off.
29
+ *
30
+ * @example
31
+ * const closed = siteClosed(request);
32
+ * if (closed) {
33
+ * const { client } = serverClient(context, request);
34
+ * return closedPageData(await client.store.get(), closed);
35
+ * }
36
+ */
37
+ declare function closedPageData(store: Store, closed: SiteClosed, { copy, title, branches, hours, }?: ClosedPageOptions): ClosedPageData;
38
+
39
+ /** The Worker's variables a site reads. Zappie hosting sets them; a self-hosted site sets them on its Worker. */
40
+ type SiteEnv = {
41
+ ZAPPIE_API?: string;
42
+ ZAPPIE_KEY?: string;
43
+ ZAPPIE_STORE?: string;
44
+ ZAPPIE_BRANCH?: string;
45
+ ZAPPIE_DRAFT?: string;
46
+ ZAPPIE_REVIEW?: string;
47
+ ZAPPIE_IMAGES?: string;
48
+ /** `off` renders every page and reads the API afresh, as an end-to-end test's own Worker does. */
49
+ ZAPPIE_EDGE_CACHE?: string;
50
+ };
51
+ /** {@link SiteEnv} with the API, the key and the preview flags resolved. */
52
+ type ResolvedSiteEnv<Env extends SiteEnv = SiteEnv> = Env & {
53
+ ZAPPIE_API: string;
54
+ ZAPPIE_KEY: string;
55
+ /** `1` for a draft: the Worker's variable, else the request's `x-zappie-draft`, else empty. */
56
+ ZAPPIE_DRAFT: string;
57
+ /** `1` for a review: the Worker's variable, else the request's `x-zappie-review`, else empty. */
58
+ ZAPPIE_REVIEW: string;
59
+ };
60
+ /** The Worker's variables, in the load context {@link siteContext} makes. */
61
+ declare const envContext: react_router.RouterContext<SiteEnv>;
62
+ /** The Worker's execution context, for cache refreshes that finish after the response. */
63
+ declare const edgeContext: react_router.RouterContext<EdgeContext | undefined>;
64
+ /**
65
+ * The load context for React Router's request handler, holding the Worker's variables and its execution context.
66
+ *
67
+ * @example
68
+ * siteWorker({ render: (request, env, ctx) => handle(request, siteContext(env, ctx)), … });
69
+ */
70
+ declare function siteContext(env: SiteEnv, ctx?: EdgeContext): RouterContextProvider;
71
+ /**
72
+ * The site's variables for a request: the process's, then Cloudflare's `context.cloudflare.env`, then the load
73
+ * context's, the last one winning. The key falls back to the request's `x-zappie-key`, which the Studio preview sends,
74
+ * and the draft and review flags to the request's headers.
75
+ *
76
+ * @throws When there is no `ZAPPIE_API` or `ZAPPIE_KEY`.
77
+ */
78
+ declare function siteEnv<Env extends SiteEnv = SiteEnv>(context: unknown, request: Request): ResolvedSiteEnv<Env>;
79
+ /** Whether the request is a draft or a review, which is never shared or counted. */
80
+ declare function isPreview(env: Pick<ResolvedSiteEnv, "ZAPPIE_DRAFT" | "ZAPPIE_REVIEW">): boolean;
81
+ /**
82
+ * Whether the request is the live site, a draft or a review. Pass `dev: import.meta.env.DEV` so a dev server runs as
83
+ * a draft, which the editor can follow and restyle and whose visits go uncounted.
84
+ */
85
+ declare function siteMode(env: Pick<ResolvedSiteEnv, "ZAPPIE_DRAFT" | "ZAPPIE_REVIEW">, { dev }?: {
86
+ dev?: boolean;
87
+ }): "site" | "draft" | "review";
88
+ /** The origin the shopper opened: the proxy's `x-forwarded-host` when there is one, else the request's own. */
89
+ declare function requestOrigin(request: Request): string;
90
+ /** Options for {@link createServerClient}. */
91
+ type ServerClientOptions = {
92
+ /** The store's slug when the Worker has no `ZAPPIE_STORE`. */
93
+ store?: string;
94
+ /** The branch when the Worker has no `ZAPPIE_BRANCH`. Without either, the client names no branch. */
95
+ branch?: string;
96
+ };
97
+ /** What a server client function returns: the client, the resolved variables and the shopper's origin. */
98
+ type ServerClient<Env extends SiteEnv = SiteEnv> = {
99
+ client: Zappie;
100
+ /** The resolved variables, with `ZAPPIE_STORE` and `ZAPPIE_BRANCH` taking the fallbacks. */
101
+ env: ResolvedSiteEnv<Env> & {
102
+ ZAPPIE_STORE: string;
103
+ };
104
+ origin: string;
105
+ };
106
+ /**
107
+ * The site's `serverClient(context, request)` for loaders: a Zappie client for the request, made once per load
108
+ * context. The live site reads the store and its menus through the Worker's edge cache, for as long as the API's own
109
+ * `Cache-Control` allows; a draft, a review and `ZAPPIE_EDGE_CACHE=off` read afresh, so each saved change shows. Each
110
+ * API call names the shopper's origin, and the customer API goes through the site host's `/_zappie/api`, which adds
111
+ * the signed-in shopper.
112
+ *
113
+ * @example
114
+ * export const serverClient = createServerClient({ store: "my-shop" });
115
+ * // in a loader
116
+ * const { client, env, origin } = serverClient(context, request);
117
+ */
118
+ declare function createServerClient<Env extends SiteEnv = SiteEnv>(options?: ServerClientOptions): (context: unknown, request: Request) => ServerClient<Env>;
119
+
120
+ /** What the document handler reads from the root route's loader data. */
121
+ type DocumentPage = {
122
+ /** The closed page, which is never shared and renders in full. */
123
+ closed: boolean;
124
+ /** The shop's mode. Anything but `site`, or none, is a preview, which is never shared. */
125
+ mode?: "site" | "draft" | "review";
126
+ /** The menu version the page rendered, for the ETag. */
127
+ menuVersion?: string;
128
+ /** The store details the page rendered, hashed into the ETag. */
129
+ store?: unknown;
130
+ };
131
+ /** Options for {@link documentHandler}. */
132
+ type DocumentHandlerOptions = {
133
+ /** The site's `zappie.config.ts`, for the security headers. */
134
+ config: ZappieSiteConfig;
135
+ /** The site's page cache rules, from `pageCacheRules`. */
136
+ cache: Pick<PageCacheRules, "documentCacheRule" | "documentCacheHeaders">;
137
+ /** Whether a user agent is a crawler, which gets the page in full. Pass `isbot` from the `isbot` package. */
138
+ isBot: (userAgent: string) => boolean;
139
+ /**
140
+ * Reads the root's loader data. By default, data `isClosedPage` accepts is the closed page, and otherwise its
141
+ * `mode`, `menu.version` and `store` are read.
142
+ */
143
+ page?: (root: unknown) => DocumentPage;
144
+ };
145
+ /**
146
+ * The site's `app/entry.server.tsx` default export. It streams the page with a CSP nonce and Zappie's security
147
+ * headers, and sets the cache headers from the site's rules:
148
+ *
149
+ * - a page a shared cache may keep, the closed page, a crawler's page and SPA mode render in full before the headers
150
+ * go out, so an error after the shell can still make the page private;
151
+ * - a page that errored, sets a cookie, is a preview or whose deferred data failed is private;
152
+ * - a route that exports its own `headers()` keeps its `Cache-Control`, unless the response sets a cookie or the
153
+ * page errored;
154
+ * - a shared menu page gets a weak ETag of its menu version, its store details and the deploy.
155
+ *
156
+ * @example
157
+ * // app/entry.server.tsx
158
+ * export default documentHandler({ config: siteConfig, cache: pageCache, isBot: isbot });
159
+ */
160
+ declare function documentHandler({ config, cache, isBot, page, }: DocumentHandlerOptions): (request: Request, status: number, headers: Headers, routerContext: EntryContext, loadContext: RouterContextProvider) => Promise<Response>;
161
+
162
+ export { ClosedPageData, closedPageData, createServerClient, documentHandler, edgeContext, envContext, isPreview, requestOrigin, siteContext, siteEnv, siteMode };
163
+ export type { ClosedPageOptions, DocumentHandlerOptions, DocumentPage, ResolvedSiteEnv, ServerClient, ServerClientOptions, SiteEnv };
@@ -0,0 +1,2 @@
1
+ import{isClosedPage}from"../closed.js";import{pageTitle}from"../title.js";import{closedPageData}from"./closed.js";import{createServerClient,edgeContext,envContext,isPreview,requestOrigin,siteContext,siteEnv,siteMode}from"./context.js";import{documentHandler}from"./document.js";export{closedPageData,createServerClient,documentHandler,edgeContext,envContext,isClosedPage,isPreview,pageTitle,requestOrigin,siteContext,siteEnv,siteMode};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/site/server/index.ts"],
4
+ "mappings": "AAAA,OAAS,iBAAyC,eAClD,OAAS,cAAiB,cAC1B,OAAS,mBAA8C,cACvD,OACE,mBACA,YACA,WACA,UACA,cACA,YACA,QACA,aAKK,eACP,OACE,oBAGK",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ function pageTitle(store,page){if(!page){return store.name}return(store.seo?.titlePattern||"{page} \xB7 {store}").replaceAll("{page}",page).replaceAll("{store}",store.name).trim()}export{pageTitle};
2
+ //# sourceMappingURL=title.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/site/title.ts"],
4
+ "mappings": "AASO,SAAS,UACd,MACA,KACQ,CACR,GAAI,CAAC,KAAM,CACT,OAAO,MAAM,IACf,CACA,OAAQ,MAAM,KAAK,cAAgB,uBAChC,WAAW,SAAU,IAAI,EACzB,WAAW,UAAW,MAAM,IAAI,EAChC,KAAK,CACV",
5
+ "names": []
6
+ }
@@ -0,0 +1,44 @@
1
+ import { Store } from '@zappie/sdk';
2
+
3
+ /** What a closed page shows: the words, the page's title, the store's name and logo, and how to reach each branch. */
4
+ type ClosedPageData = {
5
+ closed: {
6
+ title: string;
7
+ message: string;
8
+ };
9
+ /** The page's title, in the store's own title pattern. */
10
+ title: string;
11
+ /** The store's name and logo, and its template settings, which carry the merchant's colours and logo style. */
12
+ store: {
13
+ name: string;
14
+ logoUrl?: string;
15
+ templateSettings?: Store["templateSettings"];
16
+ };
17
+ branches: {
18
+ id: string;
19
+ name: string;
20
+ address?: string;
21
+ contact: {
22
+ label: string;
23
+ href: string;
24
+ }[];
25
+ hours: {
26
+ days: string;
27
+ hours: string;
28
+ }[];
29
+ }[];
30
+ };
31
+ /** Whether the root's loader data is the closed page's, from `closedPageData`, rather than the shop's. */
32
+ declare const isClosedPage: (data: unknown) => data is ClosedPageData;
33
+
34
+ /**
35
+ * A page's title in the store's own title pattern (`seo.titlePattern`, such as `{page} | {store}`), or
36
+ * `{page} · {store}` when it has none. Without a page it is the store's name.
37
+ *
38
+ * @param store - The store, with its name and search settings.
39
+ * @param page - The page's own name, such as "About".
40
+ */
41
+ declare function pageTitle(store: Pick<Store, "name" | "seo">, page?: string): string;
42
+
43
+ export { isClosedPage as i, pageTitle as p };
44
+ export type { ClosedPageData as C };
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- var PACKAGE_VERSION=true?"0.20.0":"0.0.0-development";export{PACKAGE_VERSION};
1
+ var PACKAGE_VERSION=true?"0.21.0":"0.0.0-development";export{PACKAGE_VERSION};
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/foundations",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "UI-less React primitives for Zappie storefronts: behaviour, state and accessibility without styles.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -57,6 +57,18 @@
57
57
  "types": "./dist/bag/server.d.ts",
58
58
  "import": "./dist/bag/server.js"
59
59
  },
60
+ "./site": {
61
+ "types": "./dist/site/index.d.ts",
62
+ "import": "./dist/site/index.js"
63
+ },
64
+ "./site/customer": {
65
+ "types": "./dist/site/customer/index.d.ts",
66
+ "import": "./dist/site/customer/index.js"
67
+ },
68
+ "./site/server": {
69
+ "types": "./dist/site/server/index.d.ts",
70
+ "import": "./dist/site/server/index.js"
71
+ },
60
72
  "./phone": {
61
73
  "types": "./dist/phone/index.d.ts",
62
74
  "import": "./dist/phone/index.js"
@@ -89,7 +101,7 @@
89
101
  "peerDependencies": {
90
102
  "react": "^18.2.0 || ^19.0.0",
91
103
  "react-dom": "^18.2.0 || ^19.0.0",
92
- "@zappie/sdk": "^0.19.0",
104
+ "@zappie/sdk": "^0.20.0",
93
105
  "react-router": "^8.4.0"
94
106
  },
95
107
  "peerDependenciesMeta": {
@@ -106,7 +118,7 @@
106
118
  "@types/google.maps": "^3.66.7",
107
119
  "esbuild": "^0.28.2",
108
120
  "react-router": "8.5.0",
109
- "@zappie/sdk": "0.19.0"
121
+ "@zappie/sdk": "0.20.0"
110
122
  },
111
123
  "license": "MIT",
112
124
  "homepage": "https://github.com/zappie/storefront-packages#readme",