@zappie/foundations 0.20.0 → 0.22.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +85 -15
  3. package/dist/index.d.ts +2 -1
  4. package/dist/rich-text/index.d.ts +5 -1
  5. package/dist/rich-text/index.js +1 -1
  6. package/dist/rich-text/index.js.map +1 -1
  7. package/dist/rich-text/string.js +2 -0
  8. package/dist/rich-text/string.js.map +6 -0
  9. package/dist/search/engine.js +1 -1
  10. package/dist/search/engine.js.map +1 -1
  11. package/dist/site/at-table.js +2 -0
  12. package/dist/site/at-table.js.map +6 -0
  13. package/dist/site/category-spy.js +2 -0
  14. package/dist/site/category-spy.js.map +6 -0
  15. package/dist/site/closed.js +2 -0
  16. package/dist/site/closed.js.map +6 -0
  17. package/dist/site/customer/checkout-return.js +2 -0
  18. package/dist/site/customer/checkout-return.js.map +6 -0
  19. package/dist/site/customer/gate.js +2 -0
  20. package/dist/site/customer/gate.js.map +6 -0
  21. package/dist/site/customer/index.d.ts +72 -0
  22. package/dist/site/customer/index.js +2 -0
  23. package/dist/site/customer/index.js.map +6 -0
  24. package/dist/site/index.d.ts +52 -0
  25. package/dist/site/index.js +2 -0
  26. package/dist/site/index.js.map +6 -0
  27. package/dist/site/page-views.js +2 -0
  28. package/dist/site/page-views.js.map +6 -0
  29. package/dist/site/server/closed.js +2 -0
  30. package/dist/site/server/closed.js.map +6 -0
  31. package/dist/site/server/context.js +2 -0
  32. package/dist/site/server/context.js.map +6 -0
  33. package/dist/site/server/document.js +2 -0
  34. package/dist/site/server/document.js.map +6 -0
  35. package/dist/site/server/index.d.ts +163 -0
  36. package/dist/site/server/index.js +2 -0
  37. package/dist/site/server/index.js.map +6 -0
  38. package/dist/site/title.js +2 -0
  39. package/dist/site/title.js.map +6 -0
  40. package/dist/title-CgphFqNB.d.ts +44 -0
  41. package/dist/version.js +1 -1
  42. package/package.json +15 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # @zappie/foundations
2
2
 
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a6f2200: `useCategorySpy` in `@zappie/foundations/site` returns the menu's active category: the last one whose heading has scrolled up to its `scroll-margin-top`, or to a `line` you pass. Arriving with `?category=` scrolls to that category, except on Back or Forward to a page already shown, where the restored scroll stands.
8
+
9
+ The starter's category links mark the category the shopper has scrolled to.
10
+
11
+ - e93e157: `@zappie/sdk/rich-text` reads merchant rich text without a DOM, so it runs in a loader, a Worker or SSR: `parseRichText` gives its nodes with the entities decoded, and `plainText` its text on one line. `@zappie/foundations/rich-text` re-exports both and adds `sanitizeRichText`, the shared sanitizer on that parser. `zappie/no-unsafe-html` accepts HTML passed through the imported `sanitizeRichText`.
12
+
13
+ The starter's item sheet shows a description's formatting, and the About page shows descriptions as text, never as tags.
14
+
15
+ - 8182c0c: `createSearchIndex` also matches a word inside a word ("cake" finds "Cheesecake"), ranked under a prefix, and no longer searches the tags and entities in a description's HTML.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [50fb80a]
20
+ - Updated dependencies [e93e157]
21
+ - @zappie/sdk@0.21.0
22
+
23
+ ## 0.21.0
24
+
25
+ ### Minor Changes
26
+
27
+ - 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.
28
+
29
+ `@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`.
30
+
31
+ 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.
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies [bc9580f]
36
+ - @zappie/sdk@0.20.0
37
+
3
38
  ## 0.20.0
4
39
 
5
40
  ### 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, titles, the active category and the closed page's data |
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,70 @@ 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
+ ## Search
846
+
847
+ `createSearchIndex(menu)` returns `search(query)`: items and categories, best first. Every word must match a name,
848
+ tag or description at the start of a word, inside a word, or with one typo from four letters. Accents, case and
849
+ description markup are ignored. Pass its results, filtered and grouped your way, to `<Search.Root source={{ results }}>`
850
+ for the listbox, its keys and its announcement.
851
+
852
+ ## Rich text
853
+
854
+ `@zappie/foundations/rich-text` runs on the server and in the browser with no DOM: `sanitizeRichText(html)` keeps
855
+ the formatting tags without attributes and drops the rest, and `parseRichText` and `plainText` are the SDK's. Use
856
+ `createSanitizeRichText` with `rich-text/browser`'s parser for the DOM's.
857
+
858
+ ## Site plumbing
859
+
860
+ Every React Router site runs the same plumbing around its own pages. These parts hold it, so a site keeps only its
861
+ choices and its markup. The framework-free pieces (the page cache rules, the Worker, robots, the sitemap and the old
862
+ address redirects) are in `@zappie/sdk/server`.
863
+
864
+ `@zappie/foundations/site/server` runs on the server only:
865
+
866
+ - `siteContext(env, ctx)` is the load context for React Router's request handler. `envContext` and `edgeContext`
867
+ read it back.
868
+ - `createServerClient({ store, branch })` returns the site's `serverClient(context, request)`: one Zappie client per
869
+ request, `{ client, env, origin }`. It reads the store and its menus through the Worker's edge cache, except for a
870
+ draft, a review or `ZAPPIE_EDGE_CACHE=off`. `siteEnv`, `siteMode`, `isPreview` and `requestOrigin` are there for
871
+ your own loaders.
872
+ - `documentHandler({ config, cache, isBot })` is the whole of `app/entry.server.tsx`: a CSP nonce, Zappie's security
873
+ headers, and cache headers from your `pageCacheRules`. Pass `page` when your root's data isn't the usual
874
+ `{ mode, menu, store }`.
875
+ - `closedPageData(store, closed)` is what your closed page shows, formatted on the server. `branches`, `hours` and
876
+ `title` change the order, the hours and the title.
877
+
878
+ `@zappie/foundations/site` runs on both sides:
879
+
880
+ - `<PageViews storeName enabled />` counts a visit for each page, and skips the bag's `?bag=open` address.
881
+ - `useAtTable()` is true on a route whose `handle` is `IN_VENUE_HANDLE`.
882
+ - `pageTitle(store, page)` titles a page in the store's own pattern.
883
+ - `isClosedPage(data)` tells the closed page's data from the shop's.
884
+ - `useCategorySpy(ids, { prefix, line, jump })` returns `[active, setActive]`: the last category whose heading
885
+ (`id={prefix + id}`, `c-` by default) has scrolled up to its `scroll-margin-top`, or to `line`. It jumps to
886
+ `?category=` on arrival, but not on Back or Forward, so the restored scroll stands.
887
+
888
+ `@zappie/foundations/site/customer` is for the customer's pages:
889
+
890
+ - `<CustomerGate returnTo>` signs a shopper in once, then renders your page with the customer client. Pass
891
+ `checking` and `signedOut` for your own markup.
892
+ - `useCheckoutReturn()` waits for the payment on `/checkout/return`, then clears the cart and opens the order. It
893
+ returns `{ state, title, body }`, and you draw the page.
894
+
895
+ ```tsx
896
+ // app/entry.server.tsx
897
+ export default documentHandler({
898
+ config: siteConfig,
899
+ cache: pageCache,
900
+ isBot: isbot,
901
+ });
902
+
903
+ // app/server.ts
904
+ export const serverClient = createServerClient({ store: "my-shop" });
905
+
906
+ // app/routes/orders.tsx
907
+ <CustomerGate returnTo="/orders" className="status-page">
908
+ {(customer) => <Orders customer={customer} />}
909
+ </CustomerGate>;
910
+ ```
package/dist/index.d.ts CHANGED
@@ -927,7 +927,8 @@ type SearchResult = {
927
927
  };
928
928
  /**
929
929
  * Index item names, tags and descriptions plus category names and descriptions for local search.
930
- * Matches case- and accent-insensitive prefixes and allows a single edit for query tokens of at least four characters.
930
+ * Matches case- and accent-insensitive prefixes, then words containing the token, and allows a single edit for query
931
+ * tokens of at least four characters. Description HTML tags and entities are not indexed.
931
932
  *
932
933
  * @param menu - The menu snapshot you want to search.
933
934
  * @returns A search function that requires every query token to match and sorts results by descending score.
@@ -1,4 +1,5 @@
1
1
  export { a as ParseRichText, P as ParsedRichTextNode, c as createSanitizeRichText } from '../core-Cd-_zlQx.js';
2
+ export { parseRichText, plainText } from '@zappie/sdk/rich-text';
2
3
 
3
4
  /**
4
5
  * The separator used to store multiple menu info banners in a single string.
@@ -7,4 +8,7 @@ declare const BANNER_DELIMITER = "<::>";
7
8
  /** Split a stored info-banner value into individual banner HTML fragments. */
8
9
  declare const splitInfoBanner: (infoBanner?: string | null) => string[];
9
10
 
10
- export { BANNER_DELIMITER, splitInfoBanner };
11
+ /** Sanitize merchant rich text with the shared policy, on the server or in the browser, with no DOM. */
12
+ declare const sanitizeRichText: (html?: string | null) => string;
13
+
14
+ export { BANNER_DELIMITER, sanitizeRichText, splitInfoBanner };
@@ -1,2 +1,2 @@
1
- export*from"./banners.js";export*from"./core.js";
1
+ export*from"./banners.js";export*from"./core.js";export*from"./string.js";
2
2
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/rich-text/index.ts"],
4
- "mappings": "AAAA,WAAc,eACd,WAAc",
4
+ "mappings": "AAAA,WAAc,eACd,WAAc,YACd,WAAc",
5
5
  "names": []
6
6
  }
@@ -0,0 +1,2 @@
1
+ import{parseRichText}from"@zappie/sdk/rich-text";import{createSanitizeRichText}from"./core.js";import{parseRichText as parseRichText2,plainText}from"@zappie/sdk/rich-text";var sanitizeRichText=/*@__PURE__ */createSanitizeRichText(parseRichText);export{parseRichText2 as parseRichText,plainText,sanitizeRichText};
2
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/rich-text/string.ts"],
4
+ "mappings": "AAAA,OAAS,kBAAqB,wBAC9B,OAAS,2BAA8B,YAEvC,OAAS,iBAAAA,eAAe,cAAiB,wBAGlC,IAAM,iBACX,eAAgB,uBAAuB,aAAa",
5
+ "names": ["parseRichText"]
6
+ }
@@ -1,2 +1,2 @@
1
- function normalizeSearch(text){return text.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean)}function near(a,b){if(Math.abs(a.length-b.length)>1){return false}let i=0;let j=0;let edits=0;while(i<a.length&&j<b.length){if(a[i]===b[j]){i++;j++;continue}if(++edits>1){return false}if(a.length===b.length){if(a[i]===b[j+1]&&a[i+1]===b[j]){i+=2;j+=2}else{i++;j++}}else if(a.length>b.length){i++}else{j++}}return edits+(a.length-i)+(b.length-j)<=1}function createSearchIndex(menu){const entries=[...Object.values(menu.items).map(item=>({result:{type:"item",item},fields:[normalizeSearch(item.name),normalizeSearch(item.tags.join(" ")),normalizeSearch(item.description??"")]})),...menu.categories.map(category=>({result:{type:"category",category},fields:[normalizeSearch(category.name),[],normalizeSearch(category.description??"")]}))];return query=>{const tokens=normalizeSearch(query);if(!tokens.length){return[]}const results=[];for(const entry of entries){let score=0;for(const token of tokens){let best=0;for(let field=0;field<entry.fields.length;field++){const weight=[30,20,10][field];for(const word of entry.fields[field]){if(word.startsWith(token)){best=Math.max(best,weight+(word===token?3:2))}else if(token.length>=4&&near(token,word)){best=Math.max(best,weight)}}}if(!best){score=0;break}score+=best}if(score){results.push({...entry.result,score})}}return results.sort((a,b)=>b.score-a.score)}}export{createSearchIndex,normalizeSearch};
1
+ function normalizeSearch(text){return text.replace(/<[^>]*>|&#?\w+;/g," ").normalize("NFD").replace(/\p{M}/gu,"").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean)}function near(a,b){if(Math.abs(a.length-b.length)>1){return false}let i=0;let j=0;let edits=0;while(i<a.length&&j<b.length){if(a[i]===b[j]){i++;j++;continue}if(++edits>1){return false}if(a.length===b.length){if(a[i]===b[j+1]&&a[i+1]===b[j]){i+=2;j+=2}else{i++;j++}}else if(a.length>b.length){i++}else{j++}}return edits+(a.length-i)+(b.length-j)<=1}function createSearchIndex(menu){const entries=[...Object.values(menu.items).map(item=>({result:{type:"item",item},fields:[normalizeSearch(item.name),normalizeSearch(item.tags.join(" ")),normalizeSearch(item.description??"")]})),...menu.categories.map(category=>({result:{type:"category",category},fields:[normalizeSearch(category.name),[],normalizeSearch(category.description??"")]}))];return query=>{const tokens=normalizeSearch(query);if(!tokens.length){return[]}const results=[];for(const entry of entries){let score=0;for(const token of tokens){let best=0;for(let field=0;field<entry.fields.length;field++){const weight=[30,20,10][field];for(const word of entry.fields[field]){if(word.startsWith(token)){best=Math.max(best,weight+(word===token?3:2))}else if(token.length>=4&&near(token,word)){best=Math.max(best,weight)}else if(word.includes(token)){best=Math.max(best,weight-1)}}}if(!best){score=0;break}score+=best}if(score){results.push({...entry.result,score})}}return results.sort((a,b)=>b.score-a.score)}}export{createSearchIndex,normalizeSearch};
2
2
  //# sourceMappingURL=engine.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/search/engine.ts"],
4
- "mappings": "AAOO,SAAS,gBAAgB,KAAc,CAC5C,OAAO,KACJ,UAAU,KAAK,EACf,QAAQ,UAAW,EAAE,E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GAAK,KAAK,MAAO,IAAI,EAAG,CACjD,KAAO,KAAK,IAAI,KAAM,MAAM,CAC9B,SAAW,KAAK,SAAS,KAAK,EAAG,CAE/B,KAAO,KAAK,IAAI,KAAM,OAAS,CAAC,CAClC,CACF,CACF,CACA,GAAI,CAAC,KAAM,CACT,MAAQ,EACR,KACF,CACA,OAAS,IACX,CACA,GAAI,MAAO,CACT,QAAQ,KAAK,CAAE,GAAG,MAAM,OAAQ,KAAM,CAAC,CACzC,CACF,CACA,OAAO,QAAQ,KAAK,CAAC,EAAG,IAAM,EAAE,MAAQ,EAAE,KAAK,CACjD,CACF",
5
5
  "names": []
6
6
  }
@@ -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
+ import{useEffect,useState}from"react";import{useLocation,useNavigationType,useSearchParams}from"react-router";var shown=new Set;function useCategorySpy(ids,{prefix="c-",line,jump=true}={}){const[query]=useSearchParams();const{key}=useLocation();const returning=useNavigationType()==="POP"&&shown.has(key);const wanted=query.get("category");const[active,setActive]=useState(wanted&&ids.includes(wanted)?wanted:ids[0]);const list=ids.join("\n");useEffect(()=>{shown.add(key);if(jump&&wanted&&!returning){document.getElementById(prefix+wanted)?.scrollIntoView({block:"start"})}},[wanted]);useEffect(()=>{const ids2=list?list.split("\n"):[];const onScroll=()=>{let current=ids2[0];for(const id of ids2){const heading=document.getElementById(prefix+id);if(heading&&heading.getBoundingClientRect().top<=(line??parseFloat(getComputedStyle(heading).scrollMarginTop)+4)){current=id}}setActive(current)};onScroll();addEventListener("scroll",onScroll,{passive:true});return()=>removeEventListener("scroll",onScroll)},[list,prefix,line]);return[active,setActive]}export{useCategorySpy};
2
+ //# sourceMappingURL=category-spy.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/site/category-spy.ts"],
4
+ "mappings": "AAAA,OAAS,UAAW,aAAgB,QACpC,OAAS,YAAa,kBAAmB,oBAAuB,eAGhE,IAAM,MAAQ,IAAI,IAiBX,SAAS,eACd,IACA,CAAE,OAAS,KAAM,KAAM,KAAO,IAAK,EAAwB,CAAC,EAC5D,CACA,KAAM,CAAC,KAAK,EAAI,gBAAgB,EAChC,KAAM,CAAE,GAAI,EAAI,YAAY,EAC5B,MAAM,UAAY,kBAAkB,IAAM,OAAS,MAAM,IAAI,GAAG,EAChE,MAAM,OAAS,MAAM,IAAI,UAAU,EACnC,KAAM,CAAC,OAAQ,SAAS,EAAI,SAC1B,QAAU,IAAI,SAAS,MAAM,EAAI,OAAS,IAAI,CAAC,CACjD,EACA,MAAM,KAAO,IAAI,KAAK,IAAI,EAC1B,UAAU,IAAM,CACd,MAAM,IAAI,GAAG,EACb,GAAI,MAAQ,QAAU,CAAC,UAAW,CAChC,SACG,eAAe,OAAS,MAAM,GAC7B,eAAe,CAAE,MAAO,OAAQ,CAAC,CACvC,CACF,EAAG,CAAC,MAAM,CAAC,EACX,UAAU,IAAM,CACd,MAAMA,KAAM,KAAO,KAAK,MAAM,IAAI,EAAI,CAAC,EACvC,MAAM,SAAW,IAAM,CACrB,IAAI,QAAUA,KAAI,CAAC,EACnB,UAAW,MAAMA,KAAK,CACpB,MAAM,QAAU,SAAS,eAAe,OAAS,EAAE,EACnD,GACE,SACA,QAAQ,sBAAsB,EAAE,MAC7B,MAAQ,WAAW,iBAAiB,OAAO,EAAE,eAAe,EAAI,GACnE,CACA,QAAU,EACZ,CACF,CACA,UAAU,OAAO,CACnB,EACA,SAAS,EACT,iBAAiB,SAAU,SAAU,CAAE,QAAS,IAAK,CAAC,EACtD,MAAO,IAAM,oBAAoB,SAAU,QAAQ,CACrD,EAAG,CAAC,KAAM,OAAQ,IAAI,CAAC,EACvB,MAAO,CAAC,OAAQ,SAAS,CAC3B",
5
+ "names": ["ids"]
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,52 @@
1
+ import * as react from 'react';
2
+ export { C as ClosedPageData, i as isClosedPage, p as pageTitle } from '../title-CgphFqNB.js';
3
+ import '@zappie/sdk';
4
+
5
+ /**
6
+ * The route `handle` for a table page (`/pay-point/:id`, `/dine-in/…`): export it from the route that renders the
7
+ * SDK's `InVenuePage`, so {@link useAtTable} knows the page is at a table.
8
+ */
9
+ declare const IN_VENUE_HANDLE: {
10
+ readonly inVenue: true;
11
+ };
12
+ /**
13
+ * True on a table page, a route whose `handle` has `inVenue: true`. There the SDK's order panel is the table's bag,
14
+ * so the shell hides its own bag button and bag.
15
+ */
16
+ declare function useAtTable(): boolean;
17
+
18
+ /** Where useCategorySpy finds a category's heading and when it counts as reached. */
19
+ type CategorySpyOptions = {
20
+ /** A category's heading id is this prefix and its id. Defaults to "c-". */
21
+ prefix?: string;
22
+ /** The line, in px from the top of the viewport, a heading has reached. Defaults to its scroll-margin-top plus 4. */
23
+ line?: number;
24
+ /** Whether arriving with `?category=` scrolls to that category. Defaults to true. */
25
+ jump?: boolean;
26
+ };
27
+ /**
28
+ * The menu's active category: the last one whose heading has scrolled up to the line under the sticky controls.
29
+ * Arriving with `?category=` scrolls to it, except on Back or Forward to a page already shown, where the restored
30
+ * scroll stands. Set the active category yourself when a tab is chosen.
31
+ */
32
+ declare function useCategorySpy(ids: readonly string[], { prefix, line, jump }?: CategorySpyOptions): readonly [string | undefined, react.Dispatch<react.SetStateAction<string | undefined>>];
33
+
34
+ /** Props for {@link PageViews}. */
35
+ type PageViewsProps = {
36
+ /** The store's name, which the visit records. */
37
+ storeName: string;
38
+ /**
39
+ * Whether this page counts visits. Pass `mode === "site"`: a draft or review runs where no hosting layer answers
40
+ * `/_zappie/view`.
41
+ */
42
+ enabled: boolean;
43
+ };
44
+ /**
45
+ * Counts a visit for each page the shopper opens, through `countPage` from `@zappie/sdk/visits`. An address with
46
+ * `?bag=open`, where `/cart` and `/checkout` land, is not counted: the bag takes the parameter off at once, and the
47
+ * address it leaves counts. Render it once, in the root. It renders nothing.
48
+ */
49
+ declare function PageViews({ storeName, enabled }: PageViewsProps): null;
50
+
51
+ export { IN_VENUE_HANDLE, PageViews, useAtTable, useCategorySpy };
52
+ export type { CategorySpyOptions, PageViewsProps };
@@ -0,0 +1,2 @@
1
+ "use client";import{IN_VENUE_HANDLE,useAtTable}from"./at-table.js";import{useCategorySpy}from"./category-spy.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,useCategorySpy};
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,mBAA+C,oBACxD,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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B,CACA,MAAM,SAAW,KAAK,IAAI,OAAO,EACjC,GAAI,SAAU,CACZ,OAAO,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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@@ -0,0 +1,163 @@
1
+ import { C as ClosedPageData } from '../../title-CgphFqNB.js';
2
+ export { 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.22.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.22.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.21.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.21.0"
110
122
  },
111
123
  "license": "MIT",
112
124
  "homepage": "https://github.com/zappie/storefront-packages#readme",