@zappie/sdk 0.30.4 → 0.31.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,13 @@
1
1
  # @zappie/sdk
2
2
 
3
+ ## 0.31.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cebd31d: `shopWords(branch)` from `@zappie/sdk/display` gives the words a storefront shows shoppers for what the branch sells. A restaurant branch keeps food words, such as "Search the menu" and the note hint "No onions, extra sauce". Every other branch, and a branch without a category, gets words that fit any shop, such as "Search the shop", "Products, categories" and "Anything we should know?".
8
+
9
+ The kit's search and menu page, and the starter's menu and About page, word their titles, labels and loading text with it, so a shop no longer reads as a restaurant.
10
+
3
11
  ## 0.30.4
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -328,6 +328,12 @@ written without a country code.
328
328
  `inVenueLabel(branch)` says what an order placed at the branch is called:
329
329
  "Walk-in" when `branch.category` is `"RETAIL"`, and "Dine-in" otherwise.
330
330
 
331
+ `shopWords(branch)` gives the words to show shoppers for what the branch sells:
332
+ `menu` ("menu" or "catalog"), `search`, `searchHint`, `noteHint` and `browse`.
333
+ A branch whose `category` is `"RESTAURANT"` gets food words, such as "Search
334
+ the menu". Every other branch gets words that fit any shop, such as "Search
335
+ the shop" and "Anything we should know?".
336
+
331
337
  ### Menu model
332
338
 
333
339
  `@zappie/sdk/menu` reads a `Menu` the way a menu page lists it, with no React:
package/dist/debug.js CHANGED
@@ -1 +1 @@
1
- var VERSION=true?"0.30.4":"0.0.0-development";function installDebug(client){if(typeof window==="undefined"||client.mode!=="test"){return}const events=[];let quote;const emit=(name,detail)=>{const event={name,detail,at:new Date().toISOString()};events.push(event);window.dispatchEvent(new CustomEvent("zappie:event",{detail:event}))};globalThis.__zappieEmit=emit;window.__zappie={version:VERSION,store:client.config.store,async catalogue(){await client.cart.hydrate();const branch=(await client.store.get()).branches.find(value=>value.id===client.cart.getSnapshot().branchId);return{branch,menu:await client.menu.get({branch:branch.id})}},cart:Object.assign(()=>client.cart.getSnapshot(),{async inject(input){await client.cart.hydrate();if(input.lines.length>100||input.lines.some(line=>!Number.isInteger(line.quantity??1)||(line.quantity??1)<1||(line.quantity??1)>99)){throw new Error("Use up to 100 cart lines with whole quantities from 1 to 99.")}const snapshot=client.cart.getSnapshot();const value={v:1,menuVersion:client._internal.cartCatalogue().version,updatedAt:Date.now(),fulfilment:snapshot.fulfilment,promoCode:snapshot.promoCode,lines:input.lines.map((line,index)=>({...line,id:`debug_${index}`,name:line.itemId,quantity:line.quantity??1,choices:(line.choices??[]).map(choice=>({...choice,quantity:choice.quantity??1})),inputs:line.inputs??{},addedAt:new Date().toISOString()}))};const scope=client.config.cart?.storageScope;(client.config.storage??window.localStorage).setItem(`zappie:cart:v1:${client.config.store}:${snapshot.branchId}${scope?`:${scope}`:""}`,JSON.stringify(value))}}),quote:()=>quote,events};client.on("add_to_cart",detail=>emit("add_to_cart",detail));client.cart.subscribe(()=>{const state=client.cart.state;const next="quote"in state?state.quote:void 0;if(next&&next!==quote){quote=next;emit("quote",next)}})}export{installDebug};
1
+ var VERSION=true?"0.31.0":"0.0.0-development";function installDebug(client){if(typeof window==="undefined"||client.mode!=="test"){return}const events=[];let quote;const emit=(name,detail)=>{const event={name,detail,at:new Date().toISOString()};events.push(event);window.dispatchEvent(new CustomEvent("zappie:event",{detail:event}))};globalThis.__zappieEmit=emit;window.__zappie={version:VERSION,store:client.config.store,async catalogue(){await client.cart.hydrate();const branch=(await client.store.get()).branches.find(value=>value.id===client.cart.getSnapshot().branchId);return{branch,menu:await client.menu.get({branch:branch.id})}},cart:Object.assign(()=>client.cart.getSnapshot(),{async inject(input){await client.cart.hydrate();if(input.lines.length>100||input.lines.some(line=>!Number.isInteger(line.quantity??1)||(line.quantity??1)<1||(line.quantity??1)>99)){throw new Error("Use up to 100 cart lines with whole quantities from 1 to 99.")}const snapshot=client.cart.getSnapshot();const value={v:1,menuVersion:client._internal.cartCatalogue().version,updatedAt:Date.now(),fulfilment:snapshot.fulfilment,promoCode:snapshot.promoCode,lines:input.lines.map((line,index)=>({...line,id:`debug_${index}`,name:line.itemId,quantity:line.quantity??1,choices:(line.choices??[]).map(choice=>({...choice,quantity:choice.quantity??1})),inputs:line.inputs??{},addedAt:new Date().toISOString()}))};const scope=client.config.cart?.storageScope;(client.config.storage??window.localStorage).setItem(`zappie:cart:v1:${client.config.store}:${snapshot.branchId}${scope?`:${scope}`:""}`,JSON.stringify(value))}}),quote:()=>quote,events};client.on("add_to_cart",detail=>emit("add_to_cart",detail));client.cart.subscribe(()=>{const state=client.cart.state;const next="quote"in state?state.quote:void 0;if(next&&next!==quote){quote=next;emit("quote",next)}})}export{installDebug};
@@ -13,6 +13,30 @@ type InVenueLabel =
13
13
  * @param branch - The branch the order is for.
14
14
  */
15
15
  declare function inVenueLabel(branch: Pick<Branch, "category">): InVenueLabel;
16
+ /** The words a storefront shows shoppers for what the branch sells. */
17
+ type ShopWords = {
18
+ /**
19
+ * What the shopper chooses items from: "menu" at a restaurant and "catalog"
20
+ * elsewhere, as the dashboard names it.
21
+ */
22
+ menu: "menu" | "catalog";
23
+ /** The search title and label: "Search the menu" or "Search the shop". */
24
+ search: string;
25
+ /** The search placeholder: "Dishes, drinks, categories" or "Products, categories". */
26
+ searchHint: string;
27
+ /** An item note's placeholder: "No onions, extra sauce" or "Anything we should know?". */
28
+ noteHint: string;
29
+ /** The link back to the items: "Browse the menu" or "Browse the shop". */
30
+ browse: string;
31
+ };
32
+ /**
33
+ * The words to show shoppers for what the branch sells. A restaurant branch
34
+ * gets food words, such as "Search the menu". Every other branch, and a branch
35
+ * without a category, gets words that fit any shop, such as "Search the shop".
36
+ *
37
+ * @param branch - The branch the shopper is ordering from.
38
+ */
39
+ declare function shopWords(branch: Pick<Branch, "category"> | null | undefined): ShopWords;
16
40
  /** Options for `formatPhone`. */
17
41
  type FormatPhoneOptions = {
18
42
  /**
@@ -32,5 +56,5 @@ type FormatPhoneOptions = {
32
56
  */
33
57
  declare function formatPhone(phone: string, options?: FormatPhoneOptions): string;
34
58
 
35
- export { formatPhone, inVenueLabel };
36
- export type { FormatPhoneOptions, InVenueLabel };
59
+ export { formatPhone, inVenueLabel, shopWords };
60
+ export type { FormatPhoneOptions, InVenueLabel, ShopWords };
@@ -1 +1 @@
1
- function inVenueLabel(branch){return branch.category==="RETAIL"?"Walk-in":"Dine-in"}var PLANS={NG:["234",[3,3,4]],GH:["233",[2,3,4]]};function formatPhone(phone,options={}){const compact=phone.replace(/[\s().-]/g,"");const plan=compact[0]==="+"?Object.values(PLANS).find(([code2])=>compact.startsWith(code2,1)):PLANS[options.country?.toUpperCase()??""];if(!plan){return phone}const[code,groups]=plan;const length=groups.reduce((sum,size)=>sum+size,0);const national=(compact[0]==="+"?compact.slice(1+code.length):compact.length===code.length+length&&compact.startsWith(code)?compact.slice(code.length):compact).replace(/^0/,"");if(national.length!==length||!/^\d+$/.test(national)){return phone}let at=0;return[`+${code}`,...groups.map(size=>national.slice(at,at+=size))].join(" ")}export{formatPhone,inVenueLabel};
1
+ function inVenueLabel(branch){return branch.category==="RETAIL"?"Walk-in":"Dine-in"}var RESTAURANT_WORDS={menu:"menu",search:"Search the menu",searchHint:"Dishes, drinks, categories",noteHint:"No onions, extra sauce",browse:"Browse the menu"};var SHOP_WORDS={menu:"catalog",search:"Search the shop",searchHint:"Products, categories",noteHint:"Anything we should know?",browse:"Browse the shop"};function shopWords(branch){return branch?.category==="RESTAURANT"?RESTAURANT_WORDS:SHOP_WORDS}var PLANS={NG:["234",[3,3,4]],GH:["233",[2,3,4]]};function formatPhone(phone,options={}){const compact=phone.replace(/[\s().-]/g,"");const plan=compact[0]==="+"?Object.values(PLANS).find(([code2])=>compact.startsWith(code2,1)):PLANS[options.country?.toUpperCase()??""];if(!plan){return phone}const[code,groups]=plan;const length=groups.reduce((sum,size)=>sum+size,0);const national=(compact[0]==="+"?compact.slice(1+code.length):compact.length===code.length+length&&compact.startsWith(code)?compact.slice(code.length):compact).replace(/^0/,"");if(national.length!==length||!/^\d+$/.test(national)){return phone}let at=0;return[`+${code}`,...groups.map(size=>national.slice(at,at+=size))].join(" ")}export{formatPhone,inVenueLabel,shopWords};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{ZappieCartError}from"./cart/errors.js";import{holdsForLater,isHeldQuote}from"./cart/held.js";import{previewItem}from"./cart/preview.js";import{estimateUnitPrice}from"./cart/price.js";import{resolveSourceMenu,withDefaultMenu}from"./cart/source-menu.js";import{validateLine}from"./cart/validate.js";import{createZappie}from"./client.js";import{API_VERSION}from"./config.js";import{ZappieError,isZappieError}from"./errors.js";export*from"./models.js";import{format,money}from"./money.js";import{RestTransport}from"./transport/rest.js";var VERSION=true?"0.30.4":"0.0.0-development";export{API_VERSION,RestTransport,VERSION,ZappieCartError,ZappieError,createZappie,estimateUnitPrice,format,holdsForLater,isHeldQuote,isZappieError,money,previewItem,resolveSourceMenu,validateLine,withDefaultMenu};
1
+ import{ZappieCartError}from"./cart/errors.js";import{holdsForLater,isHeldQuote}from"./cart/held.js";import{previewItem}from"./cart/preview.js";import{estimateUnitPrice}from"./cart/price.js";import{resolveSourceMenu,withDefaultMenu}from"./cart/source-menu.js";import{validateLine}from"./cart/validate.js";import{createZappie}from"./client.js";import{API_VERSION}from"./config.js";import{ZappieError,isZappieError}from"./errors.js";export*from"./models.js";import{format,money}from"./money.js";import{RestTransport}from"./transport/rest.js";var VERSION=true?"0.31.0":"0.0.0-development";export{API_VERSION,RestTransport,VERSION,ZappieCartError,ZappieError,createZappie,estimateUnitPrice,format,holdsForLater,isHeldQuote,isZappieError,money,previewItem,resolveSourceMenu,validateLine,withDefaultMenu};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/sdk",
3
- "version": "0.30.4",
3
+ "version": "0.31.0",
4
4
  "description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
5
5
  "type": "module",
6
6
  "sideEffects": [