@ancon/wildcat-utils 1.20.14 → 1.20.16

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("@ancon/wildcat-types"),g=require("./getCheckoutItemsMappedByTicketItemStatus.js");var f=(e=>(e.YourOrderIsBeingProcessed="yourOrderIsBeingProcessed",e.YourOrderWasCancelled="yourOrderWasCancelled",e.ProcessingPayment="processingPayment",e.YourOrderIsBeingPrepared="yourOrderIsBeingPrepared",e.YourOrderIsReadyToCollect="yourOrderIsReadyToCollect",e.YourOrderHasBeenCompleted="yourOrderHasBeenCompleted",e.YourOrderWillArriveAtYourTable="yourOrderWillArriveAtYourTable",e.ModifiedDeliveryStartTime="modifiedDeliveryStartTime",e.ModifiedPickUpTime="modifiedPickUpTime",e.YourOrderHasBeenAcceptedEstimatedDeliveryStartTime="yourOrderHasBeenAcceptedEstimatedDeliveryStartTime",e.YourOrderHasBeenAcceptedEstimatedTime="yourOrderHasBeenAcceptedEstimatedTime",e.YourOrderHasBeenAcceptedPickupTime="yourOrderHasBeenAcceptedPickupTime",e.DeliveryWasCompleted="deliveryWasCompleted",e.OneItemIsReadyToCollect="oneItemIsReadyToCollect",e.MultipleItemsAreReadyToCollect="multipleItemsAreReadyToCollect",e.EnjoyMealWhileOtherItemsBeingPrepared="enjoyMealWhileOtherItemsBeingPrepared",e))(f||{});function C(e){switch(e){case r.CheckoutStatus.Created:case r.CheckoutStatus.Ready:case r.CheckoutStatus.Processing:case r.CheckoutStatus.Authorized:return"yourOrderIsBeingProcessed";case r.CheckoutStatus.Canceled:return"yourOrderWasCancelled";case r.CheckoutStatus.Received:return"processingPayment";case r.CheckoutStatus.ReadyToCollect:return"yourOrderIsReadyToCollect";default:return null}}function m(e){switch(e){case r.TicketStatus.Pending:case r.TicketStatus.PendingAccept:return"yourOrderIsBeingProcessed";case r.TicketStatus.Preparing:return"yourOrderIsBeingPrepared";case r.TicketStatus.Ready:return"yourOrderIsReadyToCollect";case r.TicketStatus.Closed:return"yourOrderHasBeenCompleted";case r.TicketStatus.Canceled:return"yourOrderWasCancelled";default:throw new Error(`Unhandled ticket status "${e}" in getTranslationKeyByTicketStatus()`)}}function T(e,{checkoutStatus:o,ticketStatus:a,customersFetchTableOrders:i}){const d=(e==null?void 0:e.orderFormat)===r.OrderFormat.Delivery,t=(e==null?void 0:e.orderFormat)===r.OrderFormat.TakeAway,l=(e==null?void 0:e.orderFormat)===r.OrderFormat.TableOrder;if(d||t||l&&!i)return!1;const u=o!=null,c=a!=null;if(u){const n=o===r.CheckoutStatus.Captured,s=o===r.CheckoutStatus.InProgress;return n||s}if(c){const n=a===r.TicketStatus.Preparing,s=a===r.TicketStatus.Ready;return n||s}return!1}function P(e,{checkoutStatus:o,ticketStatus:a,customersFetchTableOrders:i,pickupTimeUpdated:d},t){if(T(e,{checkoutStatus:o,ticketStatus:a,customersFetchTableOrders:i})){if(t.ready>0)return t.ready===t.all?["yourOrderIsReadyToCollect"]:t.ready<2?["oneItemIsReadyToCollect"]:["multipleItemsAreReadyToCollect",{count:t.ready}];if(t.done>0&&t.done<t.all)return["enjoyMealWhileOtherItemsBeingPrepared",{count:Math.max(0,t.all-t.done-t.ready)}]}if(a!=null)return[m(a)];const l=C(o);if(l)return[l];const u=o===r.CheckoutStatus.Captured,c=o===r.CheckoutStatus.InProgress,n=o===r.CheckoutStatus.Done,s=(e==null?void 0:e.orderFormat)===r.OrderFormat.EatIn,O=(e==null?void 0:e.orderFormat)===r.OrderFormat.TakeAway,y=(e==null?void 0:e.orderFormat)===r.OrderFormat.TableOrder,p=(e==null?void 0:e.orderFormat)===r.OrderFormat.Delivery;if(u)return y&&!i?["yourOrderWillArriveAtYourTable"]:p?d?["modifiedDeliveryStartTime"]:["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"]:d?["modifiedPickUpTime"]:["yourOrderHasBeenAcceptedPickupTime"];if(c){if(p)return d?["modifiedDeliveryStartTime"]:["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"];if(s||O){if(t.ready===t.all)return["yourOrderIsReadyToCollect"];if(t.done===t.all)return["yourOrderHasBeenCompleted"]}return y?t.ready===t.all?i?["yourOrderIsReadyToCollect"]:["yourOrderWillArriveAtYourTable"]:t.done===t.all?i?["yourOrderHasBeenCompleted"]:["yourOrderWillArriveAtYourTable"]:d?["modifiedPickUpTime"]:i?["yourOrderIsBeingPrepared"]:["yourOrderWillArriveAtYourTable"]:d?["modifiedPickUpTime"]:["yourOrderIsBeingPrepared"]}if(n){if(s||O)return["yourOrderHasBeenCompleted"];if(p)return["deliveryWasCompleted"];if(y)return i?["yourOrderHasBeenCompleted"]:["yourOrderWillArriveAtYourTable"]}throw new Error("Could not resolve translation key in getTranslationKey()")}const h={yourOrderIsBeingProcessed:()=>({title:"Your order is being processed"}),yourOrderWasCancelled:()=>({title:"Your order was canceled",message:"Sorry. Your order could not go through."}),processingPayment:()=>({title:"Processing payment",message:"Please wait while your payment is being processed"}),yourOrderIsBeingPrepared:()=>({title:"Your order is now being prepared!",message:"We will let you know when it is ready for pickup."}),yourOrderIsReadyToCollect:()=>({title:"Your order is ready to be collected!",message:"Please go ahead and show this screen at the collection point"}),yourOrderHasBeenCompleted:()=>({title:"Enjoy your meal!",message:"Your order has been completed!"}),yourOrderWillArriveAtYourTable:()=>({title:"Your order has been accepted!",message:"It will arrive at your table shortly"}),modifiedDeliveryStartTime:()=>({title:"Your delivery time was modified",message:"Delivery will start at approximately 00:00."}),modifiedPickUpTime:()=>({title:"Your pickup time was modified",message:"Pickup time: 00:00"}),yourOrderHasBeenAcceptedEstimatedDeliveryStartTime:()=>({title:"Your order has been accepted",message:"Estimated delivery start time: 00:00"}),yourOrderHasBeenAcceptedEstimatedTime:()=>({title:"Your order has been accepted",message:"Estimated time: 00:00"}),yourOrderHasBeenAcceptedPickupTime:()=>({title:"Your order has been accepted",message:"Pickup time: 00:00"}),deliveryWasCompleted:()=>({title:"Your order was completed",message:"Enjoy your meal!"}),oneItemIsReadyToCollect:()=>({title:"One item is ready to pick up!",message:"Please allow cashier or waiter to confirm that the prepared item has been successfully issued."}),multipleItemsAreReadyToCollect:()=>({title:"Multiple items are ready to pick up!",message:"Please allow cashier or waiter to confirm that the prepared items have been successfully issued."}),enjoyMealWhileOtherItemsBeingPrepared:({meta:e})=>({title:"Enjoy your meal while the rest of the items are being prepared!",message:`${e.count} more items are being prepared`})};function I(e,o,a=h){const i=g((e==null?void 0:e.items)??[]),[d,t]=P(e,o,{all:i.all.length,ready:i.ready.length,done:i.done.length}),l=a[d]({key:d,meta:t});if(!l)throw new Error("Could not resolve translation in getOrderStatusTexts()");return[l,d]}exports.TranslationKey=f;exports.default=I;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("@ancon/wildcat-types"),f=require("./getCheckoutItemsMappedByTicketItemStatus.js");var g=(e=>(e.YourOrderIsBeingProcessed="yourOrderIsBeingProcessed",e.YourOrderWasCancelled="yourOrderWasCancelled",e.ProcessingPayment="processingPayment",e.YourOrderIsBeingPrepared="yourOrderIsBeingPrepared",e.YourOrderIsReadyToCollect="yourOrderIsReadyToCollect",e.YourOrderHasBeenCompleted="yourOrderHasBeenCompleted",e.YourOrderWillArriveAtYourTable="yourOrderWillArriveAtYourTable",e.ModifiedDeliveryStartTime="modifiedDeliveryStartTime",e.ModifiedPickUpTime="modifiedPickUpTime",e.YourOrderHasBeenAcceptedEstimatedDeliveryStartTime="yourOrderHasBeenAcceptedEstimatedDeliveryStartTime",e.YourOrderHasBeenAcceptedEstimatedTime="yourOrderHasBeenAcceptedEstimatedTime",e.YourOrderHasBeenAcceptedPickupTime="yourOrderHasBeenAcceptedPickupTime",e.DeliveryWasCompleted="deliveryWasCompleted",e.OneItemIsReadyToCollect="oneItemIsReadyToCollect",e.MultipleItemsAreReadyToCollect="multipleItemsAreReadyToCollect",e.EnjoyMealWhileOtherItemsBeingPrepared="enjoyMealWhileOtherItemsBeingPrepared",e))(g||{});function C(e){switch(e){case r.CheckoutStatus.Created:case r.CheckoutStatus.Ready:case r.CheckoutStatus.Processing:case r.CheckoutStatus.Authorized:return"yourOrderIsBeingProcessed";case r.CheckoutStatus.Canceled:return"yourOrderWasCancelled";case r.CheckoutStatus.Received:return"processingPayment";case r.CheckoutStatus.ReadyToCollect:return"yourOrderIsReadyToCollect";default:return null}}function m(e){switch(e){case r.TicketStatus.Pending:case r.TicketStatus.PendingAccept:return"yourOrderIsBeingProcessed";case r.TicketStatus.Preparing:return"yourOrderIsBeingPrepared";case r.TicketStatus.Ready:return"yourOrderIsReadyToCollect";case r.TicketStatus.Closed:return"yourOrderHasBeenCompleted";case r.TicketStatus.Canceled:return"yourOrderWasCancelled";default:throw new Error(`Unhandled ticket status "${e}" in getTranslationKeyByTicketStatus()`)}}function T(e,{checkoutStatus:i,ticketStatus:a,customersFetchTableOrders:o}){const d=(e==null?void 0:e.orderFormat)===r.OrderFormat.Delivery,t=(e==null?void 0:e.orderFormat)===r.OrderFormat.TakeAway,l=(e==null?void 0:e.orderFormat)===r.OrderFormat.TableOrder;if(d||t||l&&!o)return!1;const u=i!=null,c=a!=null;if(u){const n=i===r.CheckoutStatus.Captured,s=i===r.CheckoutStatus.InProgress;return n||s}if(c){const n=a===r.TicketStatus.Preparing,s=a===r.TicketStatus.Ready;return n||s}return!1}function P(e,{checkoutStatus:i,ticketStatus:a,customersFetchTableOrders:o,pickupTimeUpdated:d},t){if(T(e,{checkoutStatus:i,ticketStatus:a,customersFetchTableOrders:o})){if(t.ready>0)return t.ready===t.all?["yourOrderIsReadyToCollect"]:t.ready<2?["oneItemIsReadyToCollect"]:["multipleItemsAreReadyToCollect",{count:t.ready}];if(t.done>0&&t.done<t.all)return["enjoyMealWhileOtherItemsBeingPrepared",{count:Math.max(0,t.all-t.done-t.ready)}]}if(a!=null)return[m(a)];const l=C(i);if(l)return[l];const u=i===r.CheckoutStatus.Captured,c=i===r.CheckoutStatus.InProgress,n=i===r.CheckoutStatus.Done,s=(e==null?void 0:e.orderFormat)===r.OrderFormat.EatIn,p=(e==null?void 0:e.orderFormat)===r.OrderFormat.TakeAway,O=(e==null?void 0:e.orderFormat)===r.OrderFormat.TableOrder,y=(e==null?void 0:e.orderFormat)===r.OrderFormat.Delivery;if(u)return O&&!o?["yourOrderWillArriveAtYourTable"]:y?d?["modifiedDeliveryStartTime"]:["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"]:d?["modifiedPickUpTime"]:["yourOrderHasBeenAcceptedPickupTime"];if(c){if(y)return d?["modifiedDeliveryStartTime"]:["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"];if(s||p){if(t.ready===t.all)return["yourOrderIsReadyToCollect"];if(t.done===t.all)return["yourOrderHasBeenCompleted"]}return O?t.ready===t.all?o?["yourOrderIsReadyToCollect"]:["yourOrderWillArriveAtYourTable"]:t.done===t.all?o?["yourOrderHasBeenCompleted"]:["yourOrderWillArriveAtYourTable"]:d?["modifiedPickUpTime"]:o?["yourOrderIsBeingPrepared"]:["yourOrderWillArriveAtYourTable"]:d?["modifiedPickUpTime"]:["yourOrderIsBeingPrepared"]}if(n)return s||p?["yourOrderHasBeenCompleted"]:y?["deliveryWasCompleted"]:["yourOrderHasBeenCompleted"];throw new Error("Could not resolve translation key in getTranslationKey()")}const h={yourOrderIsBeingProcessed:()=>({title:"Your order is being processed"}),yourOrderWasCancelled:()=>({title:"Your order was canceled",message:"Sorry. Your order could not go through."}),processingPayment:()=>({title:"Processing payment",message:"Please wait while your payment is being processed"}),yourOrderIsBeingPrepared:()=>({title:"Your order is now being prepared!",message:"We will let you know when it is ready for pickup."}),yourOrderIsReadyToCollect:()=>({title:"Your order is ready to be collected!",message:"Please go ahead and show this screen at the collection point"}),yourOrderHasBeenCompleted:()=>({title:"Enjoy your meal!",message:"Your order has been completed!"}),yourOrderWillArriveAtYourTable:()=>({title:"Your order has been accepted!",message:"It will arrive at your table shortly"}),modifiedDeliveryStartTime:()=>({title:"Your delivery time was modified",message:"Delivery will start at approximately 00:00."}),modifiedPickUpTime:()=>({title:"Your pickup time was modified",message:"Pickup time: 00:00"}),yourOrderHasBeenAcceptedEstimatedDeliveryStartTime:()=>({title:"Your order has been accepted",message:"Estimated delivery start time: 00:00"}),yourOrderHasBeenAcceptedEstimatedTime:()=>({title:"Your order has been accepted",message:"Estimated time: 00:00"}),yourOrderHasBeenAcceptedPickupTime:()=>({title:"Your order has been accepted",message:"Pickup time: 00:00"}),deliveryWasCompleted:()=>({title:"Your order was completed",message:"Enjoy your meal!"}),oneItemIsReadyToCollect:()=>({title:"One item is ready to pick up!",message:"Please allow cashier or waiter to confirm that the prepared item has been successfully issued."}),multipleItemsAreReadyToCollect:()=>({title:"Multiple items are ready to pick up!",message:"Please allow cashier or waiter to confirm that the prepared items have been successfully issued."}),enjoyMealWhileOtherItemsBeingPrepared:({meta:e})=>({title:"Enjoy your meal while the rest of the items are being prepared!",message:`${e.count} more items are being prepared`})};function I(e,i,a=h){const o=f((e==null?void 0:e.items)??[]),[d,t]=P(e,i,{all:o.all.length,ready:o.ready.length,done:o.done.length}),l=a[d]({key:d,meta:t});if(!l)throw new Error("Could not resolve translation in getOrderStatusTexts()");return[l,d]}exports.TranslationKey=g;exports.default=I;
@@ -1,18 +1,18 @@
1
- import { CheckoutStatus as i, OrderFormat as s, TicketStatus as a } from "@ancon/wildcat-types";
1
+ import { CheckoutStatus as t, OrderFormat as s, TicketStatus as a } from "@ancon/wildcat-types";
2
2
  import m from "./getCheckoutItemsMappedByTicketItemStatus.mjs";
3
3
  var C = /* @__PURE__ */ ((e) => (e.YourOrderIsBeingProcessed = "yourOrderIsBeingProcessed", e.YourOrderWasCancelled = "yourOrderWasCancelled", e.ProcessingPayment = "processingPayment", e.YourOrderIsBeingPrepared = "yourOrderIsBeingPrepared", e.YourOrderIsReadyToCollect = "yourOrderIsReadyToCollect", e.YourOrderHasBeenCompleted = "yourOrderHasBeenCompleted", e.YourOrderWillArriveAtYourTable = "yourOrderWillArriveAtYourTable", e.ModifiedDeliveryStartTime = "modifiedDeliveryStartTime", e.ModifiedPickUpTime = "modifiedPickUpTime", e.YourOrderHasBeenAcceptedEstimatedDeliveryStartTime = "yourOrderHasBeenAcceptedEstimatedDeliveryStartTime", e.YourOrderHasBeenAcceptedEstimatedTime = "yourOrderHasBeenAcceptedEstimatedTime", e.YourOrderHasBeenAcceptedPickupTime = "yourOrderHasBeenAcceptedPickupTime", e.DeliveryWasCompleted = "deliveryWasCompleted", e.OneItemIsReadyToCollect = "oneItemIsReadyToCollect", e.MultipleItemsAreReadyToCollect = "multipleItemsAreReadyToCollect", e.EnjoyMealWhileOtherItemsBeingPrepared = "enjoyMealWhileOtherItemsBeingPrepared", e))(C || {});
4
4
  function P(e) {
5
5
  switch (e) {
6
- case i.Created:
7
- case i.Ready:
8
- case i.Processing:
9
- case i.Authorized:
6
+ case t.Created:
7
+ case t.Ready:
8
+ case t.Processing:
9
+ case t.Authorized:
10
10
  return "yourOrderIsBeingProcessed";
11
- case i.Canceled:
11
+ case t.Canceled:
12
12
  return "yourOrderWasCancelled";
13
- case i.Received:
13
+ case t.Received:
14
14
  return "processingPayment";
15
- case i.ReadyToCollect:
15
+ case t.ReadyToCollect:
16
16
  return "yourOrderIsReadyToCollect";
17
17
  default:
18
18
  return null;
@@ -38,16 +38,16 @@ function I(e) {
38
38
  }
39
39
  }
40
40
  function T(e, {
41
- checkoutStatus: o,
41
+ checkoutStatus: i,
42
42
  ticketStatus: l,
43
- customersFetchTableOrders: t
43
+ customersFetchTableOrders: o
44
44
  }) {
45
45
  const d = (e == null ? void 0 : e.orderFormat) === s.Delivery, r = (e == null ? void 0 : e.orderFormat) === s.TakeAway, n = (e == null ? void 0 : e.orderFormat) === s.TableOrder;
46
- if (d || r || n && !t)
46
+ if (d || r || n && !o)
47
47
  return !1;
48
- const y = o != null, p = l != null;
48
+ const y = i != null, p = l != null;
49
49
  if (y) {
50
- const u = o === i.Captured, c = o === i.InProgress;
50
+ const u = i === t.Captured, c = i === t.InProgress;
51
51
  return u || c;
52
52
  }
53
53
  if (p) {
@@ -57,15 +57,15 @@ function T(e, {
57
57
  return !1;
58
58
  }
59
59
  function B(e, {
60
- checkoutStatus: o,
60
+ checkoutStatus: i,
61
61
  ticketStatus: l,
62
- customersFetchTableOrders: t,
62
+ customersFetchTableOrders: o,
63
63
  pickupTimeUpdated: d
64
64
  }, r) {
65
65
  if (T(e, {
66
- checkoutStatus: o,
66
+ checkoutStatus: i,
67
67
  ticketStatus: l,
68
- customersFetchTableOrders: t
68
+ customersFetchTableOrders: o
69
69
  })) {
70
70
  if (r.ready > 0)
71
71
  return r.ready === r.all ? ["yourOrderIsReadyToCollect"] : r.ready < 2 ? ["oneItemIsReadyToCollect"] : [
@@ -80,34 +80,28 @@ function B(e, {
80
80
  }
81
81
  if (l != null)
82
82
  return [I(l)];
83
- const n = P(o);
83
+ const n = P(i);
84
84
  if (n)
85
85
  return [n];
86
- const y = o === i.Captured, p = o === i.InProgress, u = o === i.Done, c = (e == null ? void 0 : e.orderFormat) === s.EatIn, O = (e == null ? void 0 : e.orderFormat) === s.TakeAway, f = (e == null ? void 0 : e.orderFormat) === s.TableOrder, g = (e == null ? void 0 : e.orderFormat) === s.Delivery;
86
+ const y = i === t.Captured, p = i === t.InProgress, u = i === t.Done, c = (e == null ? void 0 : e.orderFormat) === s.EatIn, g = (e == null ? void 0 : e.orderFormat) === s.TakeAway, O = (e == null ? void 0 : e.orderFormat) === s.TableOrder, f = (e == null ? void 0 : e.orderFormat) === s.Delivery;
87
87
  if (y)
88
- return f && !t ? ["yourOrderWillArriveAtYourTable"] : g ? d ? ["modifiedDeliveryStartTime"] : ["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"] : d ? ["modifiedPickUpTime"] : ["yourOrderHasBeenAcceptedPickupTime"];
88
+ return O && !o ? ["yourOrderWillArriveAtYourTable"] : f ? d ? ["modifiedDeliveryStartTime"] : ["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"] : d ? ["modifiedPickUpTime"] : ["yourOrderHasBeenAcceptedPickupTime"];
89
89
  if (p) {
90
- if (g)
90
+ if (f)
91
91
  return d ? ["modifiedDeliveryStartTime"] : ["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"];
92
- if (c || O) {
92
+ if (c || g) {
93
93
  if (r.ready === r.all)
94
94
  return ["yourOrderIsReadyToCollect"];
95
95
  if (r.done === r.all)
96
96
  return ["yourOrderHasBeenCompleted"];
97
97
  }
98
- return f ? r.ready === r.all ? t ? ["yourOrderIsReadyToCollect"] : ["yourOrderWillArriveAtYourTable"] : r.done === r.all ? t ? ["yourOrderHasBeenCompleted"] : ["yourOrderWillArriveAtYourTable"] : d ? ["modifiedPickUpTime"] : t ? ["yourOrderIsBeingPrepared"] : ["yourOrderWillArriveAtYourTable"] : d ? ["modifiedPickUpTime"] : ["yourOrderIsBeingPrepared"];
99
- }
100
- if (u) {
101
- if (c || O)
102
- return ["yourOrderHasBeenCompleted"];
103
- if (g)
104
- return ["deliveryWasCompleted"];
105
- if (f)
106
- return t ? ["yourOrderHasBeenCompleted"] : ["yourOrderWillArriveAtYourTable"];
98
+ return O ? r.ready === r.all ? o ? ["yourOrderIsReadyToCollect"] : ["yourOrderWillArriveAtYourTable"] : r.done === r.all ? o ? ["yourOrderHasBeenCompleted"] : ["yourOrderWillArriveAtYourTable"] : d ? ["modifiedPickUpTime"] : o ? ["yourOrderIsBeingPrepared"] : ["yourOrderWillArriveAtYourTable"] : d ? ["modifiedPickUpTime"] : ["yourOrderIsBeingPrepared"];
107
99
  }
100
+ if (u)
101
+ return c || g ? ["yourOrderHasBeenCompleted"] : f ? ["deliveryWasCompleted"] : ["yourOrderHasBeenCompleted"];
108
102
  throw new Error("Could not resolve translation key in getTranslationKey()");
109
103
  }
110
- const A = {
104
+ const h = {
111
105
  yourOrderIsBeingProcessed: () => ({
112
106
  title: "Your order is being processed"
113
107
  }),
@@ -172,13 +166,13 @@ const A = {
172
166
  message: `${e.count} more items are being prepared`
173
167
  })
174
168
  };
175
- function w(e, o, l = A) {
176
- const t = m(
169
+ function w(e, i, l = h) {
170
+ const o = m(
177
171
  (e == null ? void 0 : e.items) ?? []
178
- ), [d, r] = B(e, o, {
179
- all: t.all.length,
180
- ready: t.ready.length,
181
- done: t.done.length
172
+ ), [d, r] = B(e, i, {
173
+ all: o.all.length,
174
+ ready: o.ready.length,
175
+ done: o.done.length
182
176
  }), n = l[d]({ key: d, meta: r });
183
177
  if (!n)
184
178
  throw new Error("Could not resolve translation in getOrderStatusTexts()");
@@ -29,5 +29,6 @@ export declare type OpeningHoursTable = {
29
29
  */
30
30
  export default function getListOutletOpeningHoursTable(outlet: {
31
31
  serviceDateTimes: ServiceDateTime[];
32
+ timeZoneOffset?: string;
32
33
  }, nowISOString?: string): OpeningHoursTable[];
33
34
  export {};
@@ -1 +1 @@
1
- "use strict";const W=require("moment"),p=require("@ancon/wildcat-types"),s=require("../shared/enums.js"),F=require("../shared/isWithinFlag.js"),k=require("../shared/generateId.js"),l=[{id:p.OrderFormat.EatIn,name:"eatIn"},{id:p.OrderFormat.TakeAway,name:"takeaway"},{id:p.OrderFormat.TableOrder,name:"tableOrder"},{id:p.OrderFormat.Delivery,name:"delivery"}];function v(e){const r=W.utc(e).subtract(1,"day").startOf("day"),t=[];for(let i=0,o=r;i<7;i+=1)o=o.clone().add(1,"day").startOf("day"),t.push(o.clone());return t}function S(e){return[...e].sort((r,t)=>r.isoWeekday()-t.isoWeekday())}function g(e){return e.split(":").map(Number)}function T(e,r){const[t,i]=g(e.start),[o,a]=g(e.duration);if(e.type===s.IntervalType.Interval){const n=r.clone().add(t,"hour").add(i,"minute"),u=n.clone().add(o,"hour").add(a,"minute");return{id:e.id,start:n.toISOString(),end:u.toISOString()}}if(e.type===s.IntervalType.Exception){const n=W(e.fromDate),u=W(e.toDate);if(r.isBetween(n,u,void 0,"[]")){const O=r.clone().add(t,"hour").add(i,"minute"),y=O.clone().add(o,"hour").add(a,"minute");return{id:e.id,start:O.toISOString(),end:y.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function h(e,r,t){const i={[s.DayOfWeek.Monday]:1,[s.DayOfWeek.Tuesday]:2,[s.DayOfWeek.Wednesday]:3,[s.DayOfWeek.Thursday]:4,[s.DayOfWeek.Friday]:5,[s.DayOfWeek.Saturday]:6,[s.DayOfWeek.Sunday]:7};for(let o=0;o<r.length;o+=1){const a=r[o],n=a.isoWeekday(),u=e.dayOfWeek,y=(i[u]??null)===n||u===s.DayOfWeek.Everyday;if(t[n]||(t[n]={isoWeekday:n,key:"",open:[],adjusted:[],closed:[]}),y){const d=T(e,a);d&&(t[n].key+=d.id,e.type===s.IntervalType.Interval&&e.state===s.IntervalState.Open?t[n].open.push(d):e.type===s.IntervalType.Interval&&e.state===s.IntervalState.Closed?t[n].closed.push(d):e.type===s.IntervalType.Exception&&e.state===s.IntervalState.Open?t[n].adjusted.push(d):e.type===s.IntervalType.Exception&&e.state===s.IntervalState.Closed&&t[n].closed.push(d))}}}function D(e){switch(e.type){case s.IntervalType.Exception:return k("interval-exception");case s.IntervalType.Interval:return k("interval-normal");default:return k("interval-unknown")}}function M(e){const r=e.reduce((t,i)=>(l.forEach(o=>{F(o.id,i.orderFormats)&&(t[o.id]||(t[o.id]={orderFormat:o,intervals:[]}),t[o.id].intervals.push(...i.intervals.sort((a,n)=>a.dayOfWeek-n.dayOfWeek)))}),t),{});return Object.values(r)}function H(e){return e.reduce((r,t,i)=>{const o=r.findIndex(a=>a!==t&&!a.orderFormats.some(n=>t.orderFormats.some(u=>u.id===n.id))&&a.openingHours.every(n=>t.openingHours.some(u=>u.key===n.key))&&t.openingHours.every(n=>a.openingHours.some(u=>u.key===n.key)));if(o>=0){const a=r[o];return r.splice(o,1,{...a,orderFormats:[...t.orderFormats,...a.orderFormats]}),r.splice(i,1),r}return r},[...e])}function E(e){return e.map(r=>({...r,intervals:r.intervals.map(t=>({...t,id:D(t)}))}))}function w(e,r){const t=M(E(e.serviceDateTimes)),i=v(r),o=S(i),a=t.reduce((y,d)=>(y[d.orderFormat.id]||(y[d.orderFormat.id]={}),d.intervals.reduce((I,m)=>(h(m,o,I),I),y[d.orderFormat.id]),y),{}),n={[p.OrderFormat.EatIn]:l[0],[p.OrderFormat.TakeAway]:l[1],[p.OrderFormat.TableOrder]:l[2],[p.OrderFormat.Delivery]:l[3]},u=Object.entries(a).map(([y,d])=>({orderFormats:[n[Number(y)]],openingHours:Object.entries(d).map(([I,m])=>({isoWeekday:Number(I),key:m.key,open:m.open.sort((c,f)=>c.start.localeCompare(f.start)),adjusted:m.adjusted.sort((c,f)=>c.start.localeCompare(f.start)),closed:m.closed.sort((c,f)=>c.start.localeCompare(f.start))}))}));return H(u).sort((y,d)=>y.orderFormats[0].id-d.orderFormats[0].id)}module.exports=w;
1
+ "use strict";const g=require("moment"),f=require("@ancon/wildcat-types"),o=require("../shared/enums.js"),F=require("../shared/isWithinFlag.js"),k=require("../shared/generateId.js"),I=[{id:f.OrderFormat.EatIn,name:"eatIn"},{id:f.OrderFormat.TakeAway,name:"takeaway"},{id:f.OrderFormat.TableOrder,name:"tableOrder"},{id:f.OrderFormat.Delivery,name:"delivery"}];function v(e){const r=g.utc(e).subtract(1,"day").startOf("day"),t=[];for(let y=0,n=r;y<7;y+=1)n=n.clone().add(1,"day").startOf("day"),t.push(n.clone());return t}function T(e){return[...e].sort((r,t)=>r.isoWeekday()-t.isoWeekday())}function W(e){return e.split(":").map(Number)}function h(e,r,t){const[y,n]=W(e.start),[a,u]=W(e.duration),[s,l]=W(t||"00:00:00");if(e.type===o.IntervalType.Interval){let d=r.clone().add(y,"hour").add(n,"minute");const i=d.clone().add(s,"hour").add(l,"minute").date()-r.date();i!==0&&(d=d.subtract(i,"day"));const p=d.clone().add(a,"hour").add(u,"minute");return{id:e.id,start:d.toISOString(),end:p.toISOString()}}if(e.type===o.IntervalType.Exception){const d=g(e.fromDate),m=g(e.toDate);if(r.isBetween(d,m,void 0,"[]")){const i=r.clone().add(y,"hour").add(n,"minute"),p=i.clone().add(a,"hour").add(u,"minute");return{id:e.id,start:i.toISOString(),end:p.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function S(e,r,t,y){const n={[o.DayOfWeek.Monday]:1,[o.DayOfWeek.Tuesday]:2,[o.DayOfWeek.Wednesday]:3,[o.DayOfWeek.Thursday]:4,[o.DayOfWeek.Friday]:5,[o.DayOfWeek.Saturday]:6,[o.DayOfWeek.Sunday]:7};for(let a=0;a<r.length;a+=1){const u=r[a],s=u.isoWeekday(),l=e.dayOfWeek,m=(n[l]??null)===s||l===o.DayOfWeek.Everyday;if(t[s]||(t[s]={isoWeekday:s,key:"",open:[],adjusted:[],closed:[]}),m){const i=h(e,u,y);i&&(t[s].key+=i.id,e.type===o.IntervalType.Interval&&e.state===o.IntervalState.Open?t[s].open.push(i):e.type===o.IntervalType.Interval&&e.state===o.IntervalState.Closed?t[s].closed.push(i):e.type===o.IntervalType.Exception&&e.state===o.IntervalState.Open?t[s].adjusted.push(i):e.type===o.IntervalType.Exception&&e.state===o.IntervalState.Closed&&t[s].closed.push(i))}}}function D(e){switch(e.type){case o.IntervalType.Exception:return k("interval-exception");case o.IntervalType.Interval:return k("interval-normal");default:return k("interval-unknown")}}function M(e){const r=e.reduce((t,y)=>(I.forEach(n=>{F(n.id,y.orderFormats)&&(t[n.id]||(t[n.id]={orderFormat:n,intervals:[]}),t[n.id].intervals.push(...y.intervals.sort((a,u)=>a.dayOfWeek-u.dayOfWeek)))}),t),{});return Object.values(r)}function H(e){return e.reduce((r,t,y)=>{const n=r.findIndex(a=>a!==t&&!a.orderFormats.some(u=>t.orderFormats.some(s=>s.id===u.id))&&a.openingHours.every(u=>t.openingHours.some(s=>s.key===u.key))&&t.openingHours.every(u=>a.openingHours.some(s=>s.key===u.key)));if(n>=0){const a=r[n];return r.splice(n,1,{...a,orderFormats:[...t.orderFormats,...a.orderFormats]}),r.splice(y,1),r}return r},[...e])}function E(e){return e.map(r=>({...r,intervals:r.intervals.map(t=>({...t,id:D(t)}))}))}function x(e,r){const t=M(E(e.serviceDateTimes)),y=v(r),n=T(y),a=t.reduce((d,m)=>(d[m.orderFormat.id]||(d[m.orderFormat.id]={}),m.intervals.reduce((i,p)=>(S(p,n,i,e.timeZoneOffset),i),d[m.orderFormat.id]),d),{}),u={[f.OrderFormat.EatIn]:I[0],[f.OrderFormat.TakeAway]:I[1],[f.OrderFormat.TableOrder]:I[2],[f.OrderFormat.Delivery]:I[3]},s=Object.entries(a).map(([d,m])=>({orderFormats:[u[Number(d)]],openingHours:Object.entries(m).map(([i,p])=>({isoWeekday:Number(i),key:p.key,open:p.open.sort((c,O)=>c.start.localeCompare(O.start)),adjusted:p.adjusted.sort((c,O)=>c.start.localeCompare(O.start)),closed:p.closed.sort((c,O)=>c.start.localeCompare(O.start))}))}));return H(s).sort((d,m)=>d.orderFormats[0].id-m.orderFormats[0].id)}module.exports=x;
@@ -1,46 +1,49 @@
1
- import F from "moment";
2
- import { OrderFormat as p } from "@ancon/wildcat-types";
3
- import { DayOfWeek as m, IntervalType as y, IntervalState as O } from "../shared/enums.mjs";
1
+ import M from "moment";
2
+ import { OrderFormat as f } from "@ancon/wildcat-types";
3
+ import { DayOfWeek as y, IntervalType as c, IntervalState as g } from "../shared/enums.mjs";
4
4
  import h from "../shared/isWithinFlag.mjs";
5
5
  import W from "../shared/generateId.mjs";
6
6
  const k = [
7
- { id: p.EatIn, name: "eatIn" },
8
- { id: p.TakeAway, name: "takeaway" },
9
- { id: p.TableOrder, name: "tableOrder" },
10
- { id: p.Delivery, name: "delivery" }
7
+ { id: f.EatIn, name: "eatIn" },
8
+ { id: f.TakeAway, name: "takeaway" },
9
+ { id: f.TableOrder, name: "tableOrder" },
10
+ { id: f.Delivery, name: "delivery" }
11
11
  ];
12
- function M(e) {
13
- const r = F.utc(e).subtract(1, "day").startOf("day"), t = [];
14
- for (let a = 0, n = r; a < 7; a += 1)
15
- n = n.clone().add(1, "day").startOf("day"), t.push(n.clone());
12
+ function S(e) {
13
+ const n = M.utc(e).subtract(1, "day").startOf("day"), t = [];
14
+ for (let u = 0, o = n; u < 7; u += 1)
15
+ o = o.clone().add(1, "day").startOf("day"), t.push(o.clone());
16
16
  return t;
17
17
  }
18
- function v(e) {
19
- return [...e].sort((r, t) => r.isoWeekday() - t.isoWeekday());
18
+ function H(e) {
19
+ return [...e].sort((n, t) => n.isoWeekday() - t.isoWeekday());
20
20
  }
21
- function S(e) {
21
+ function F(e) {
22
22
  return e.split(":").map(Number);
23
23
  }
24
- function H(e, r) {
25
- const [t, a] = S(e.start), [n, s] = S(
24
+ function v(e, n, t) {
25
+ const [u, o] = F(e.start), [s, i] = F(
26
26
  e.duration
27
- );
28
- if (e.type === y.Interval) {
29
- const o = r.clone().add(t, "hour").add(a, "minute"), i = o.clone().add(n, "hour").add(s, "minute");
27
+ ), [r, l] = F(t || "00:00:00");
28
+ if (e.type === c.Interval) {
29
+ let d = n.clone().add(u, "hour").add(o, "minute");
30
+ const a = d.clone().add(r, "hour").add(l, "minute").date() - n.date();
31
+ a !== 0 && (d = d.subtract(a, "day"));
32
+ const p = d.clone().add(s, "hour").add(i, "minute");
30
33
  return {
31
34
  id: e.id,
32
- start: o.toISOString(),
33
- end: i.toISOString()
35
+ start: d.toISOString(),
36
+ end: p.toISOString()
34
37
  };
35
38
  }
36
- if (e.type === y.Exception) {
37
- const o = F(e.fromDate), i = F(e.toDate);
38
- if (r.isBetween(o, i, void 0, "[]")) {
39
- const I = r.clone().add(t, "hour").add(a, "minute"), u = I.clone().add(n, "hour").add(s, "minute");
39
+ if (e.type === c.Exception) {
40
+ const d = M(e.fromDate), m = M(e.toDate);
41
+ if (n.isBetween(d, m, void 0, "[]")) {
42
+ const a = n.clone().add(u, "hour").add(o, "minute"), p = a.clone().add(s, "hour").add(i, "minute");
40
43
  return {
41
44
  id: e.id,
42
- start: I.toISOString(),
43
- end: u.toISOString(),
45
+ start: a.toISOString(),
46
+ end: p.toISOString(),
44
47
  reason: e.reason
45
48
  };
46
49
  }
@@ -48,126 +51,135 @@ function H(e, r) {
48
51
  }
49
52
  throw new Error("Invalid interval type");
50
53
  }
51
- function E(e, r, t) {
52
- const a = {
53
- [m.Monday]: 1,
54
- [m.Tuesday]: 2,
55
- [m.Wednesday]: 3,
56
- [m.Thursday]: 4,
57
- [m.Friday]: 5,
58
- [m.Saturday]: 6,
59
- [m.Sunday]: 7
54
+ function E(e, n, t, u) {
55
+ const o = {
56
+ [y.Monday]: 1,
57
+ [y.Tuesday]: 2,
58
+ [y.Wednesday]: 3,
59
+ [y.Thursday]: 4,
60
+ [y.Friday]: 5,
61
+ [y.Saturday]: 6,
62
+ [y.Sunday]: 7
60
63
  };
61
- for (let n = 0; n < r.length; n += 1) {
62
- const s = r[n], o = s.isoWeekday(), i = e.dayOfWeek, u = (a[i] ?? null) === o || i === m.Everyday;
63
- if (t[o] || (t[o] = {
64
- isoWeekday: o,
64
+ for (let s = 0; s < n.length; s += 1) {
65
+ const i = n[s], r = i.isoWeekday(), l = e.dayOfWeek, m = (o[l] ?? null) === r || l === y.Everyday;
66
+ if (t[r] || (t[r] = {
67
+ isoWeekday: r,
65
68
  key: "",
66
69
  open: [],
67
70
  adjusted: [],
68
71
  closed: []
69
- }), u) {
70
- const d = H(e, s);
71
- d && (t[o].key += d.id, e.type === y.Interval && e.state === O.Open ? t[o].open.push(d) : e.type === y.Interval && e.state === O.Closed ? t[o].closed.push(d) : e.type === y.Exception && e.state === O.Open ? t[o].adjusted.push(d) : e.type === y.Exception && e.state === O.Closed && t[o].closed.push(d));
72
+ }), m) {
73
+ const a = v(
74
+ e,
75
+ i,
76
+ u
77
+ );
78
+ a && (t[r].key += a.id, e.type === c.Interval && e.state === g.Open ? t[r].open.push(a) : e.type === c.Interval && e.state === g.Closed ? t[r].closed.push(a) : e.type === c.Exception && e.state === g.Open ? t[r].adjusted.push(a) : e.type === c.Exception && e.state === g.Closed && t[r].closed.push(a));
72
79
  }
73
80
  }
74
81
  }
75
82
  function T(e) {
76
83
  switch (e.type) {
77
- case y.Exception:
84
+ case c.Exception:
78
85
  return W("interval-exception");
79
- case y.Interval:
86
+ case c.Interval:
80
87
  return W("interval-normal");
81
88
  default:
82
89
  return W("interval-unknown");
83
90
  }
84
91
  }
85
92
  function x(e) {
86
- const r = e.reduce(
87
- (t, a) => (k.forEach((n) => {
88
- h(n.id, a.orderFormats) && (t[n.id] || (t[n.id] = {
89
- orderFormat: n,
93
+ const n = e.reduce(
94
+ (t, u) => (k.forEach((o) => {
95
+ h(o.id, u.orderFormats) && (t[o.id] || (t[o.id] = {
96
+ orderFormat: o,
90
97
  intervals: []
91
- }), t[n.id].intervals.push(
92
- ...a.intervals.sort(
93
- (s, o) => s.dayOfWeek - o.dayOfWeek
98
+ }), t[o.id].intervals.push(
99
+ ...u.intervals.sort(
100
+ (s, i) => s.dayOfWeek - i.dayOfWeek
94
101
  )
95
102
  ));
96
103
  }), t),
97
104
  {}
98
105
  );
99
- return Object.values(r);
106
+ return Object.values(n);
100
107
  }
101
- function j(e) {
108
+ function D(e) {
102
109
  return e.reduce(
103
- (r, t, a) => {
104
- const n = r.findIndex(
110
+ (n, t, u) => {
111
+ const o = n.findIndex(
105
112
  (s) => s !== t && !s.orderFormats.some(
106
- (o) => t.orderFormats.some(
107
- (i) => i.id === o.id
113
+ (i) => t.orderFormats.some(
114
+ (r) => r.id === i.id
108
115
  )
109
116
  ) && s.openingHours.every(
110
- (o) => t.openingHours.some((i) => i.key === o.key)
117
+ (i) => t.openingHours.some((r) => r.key === i.key)
111
118
  ) && t.openingHours.every(
112
- (o) => s.openingHours.some((i) => i.key === o.key)
119
+ (i) => s.openingHours.some((r) => r.key === i.key)
113
120
  )
114
121
  );
115
- if (n >= 0) {
116
- const s = r[n];
117
- return r.splice(n, 1, {
122
+ if (o >= 0) {
123
+ const s = n[o];
124
+ return n.splice(o, 1, {
118
125
  ...s,
119
126
  orderFormats: [...t.orderFormats, ...s.orderFormats]
120
- }), r.splice(a, 1), r;
127
+ }), n.splice(u, 1), n;
121
128
  }
122
- return r;
129
+ return n;
123
130
  },
124
131
  [...e]
125
132
  );
126
133
  }
127
- function w(e) {
128
- return e.map((r) => ({
129
- ...r,
130
- intervals: r.intervals.map((t) => ({
134
+ function j(e) {
135
+ return e.map((n) => ({
136
+ ...n,
137
+ intervals: n.intervals.map((t) => ({
131
138
  ...t,
132
139
  id: T(t)
133
140
  }))
134
141
  }));
135
142
  }
136
- function B(e, r) {
143
+ function Z(e, n) {
137
144
  const t = x(
138
- w(e.serviceDateTimes)
139
- ), a = M(r), n = v(a), s = t.reduce(
140
- (u, d) => (u[d.orderFormat.id] || (u[d.orderFormat.id] = {}), d.intervals.reduce((g, f) => (E(f, n, g), g), u[d.orderFormat.id]), u),
145
+ j(e.serviceDateTimes)
146
+ ), u = S(n), o = H(u), s = t.reduce(
147
+ (d, m) => (d[m.orderFormat.id] || (d[m.orderFormat.id] = {}), m.intervals.reduce((a, p) => (E(
148
+ p,
149
+ o,
150
+ a,
151
+ e.timeZoneOffset
152
+ ), a), d[m.orderFormat.id]), d),
141
153
  {}
142
- ), o = {
143
- [p.EatIn]: k[0],
144
- [p.TakeAway]: k[1],
145
- [p.TableOrder]: k[2],
146
- [p.Delivery]: k[3]
147
- }, i = Object.entries(
154
+ ), i = {
155
+ [f.EatIn]: k[0],
156
+ [f.TakeAway]: k[1],
157
+ [f.TableOrder]: k[2],
158
+ [f.Delivery]: k[3]
159
+ }, r = Object.entries(
148
160
  s
149
- ).map(([u, d]) => ({
150
- orderFormats: [o[Number(u)]],
151
- openingHours: Object.entries(d).map(
152
- ([g, f]) => ({
153
- isoWeekday: Number(g),
154
- key: f.key,
155
- open: f.open.sort(
156
- (c, l) => c.start.localeCompare(l.start)
161
+ ).map(([d, m]) => ({
162
+ orderFormats: [i[Number(d)]],
163
+ openingHours: Object.entries(m).map(
164
+ ([a, p]) => ({
165
+ isoWeekday: Number(a),
166
+ key: p.key,
167
+ open: p.open.sort(
168
+ (I, O) => I.start.localeCompare(O.start)
157
169
  ),
158
- adjusted: f.adjusted.sort(
159
- (c, l) => c.start.localeCompare(l.start)
170
+ adjusted: p.adjusted.sort(
171
+ (I, O) => I.start.localeCompare(O.start)
160
172
  ),
161
- closed: f.closed.sort(
162
- (c, l) => c.start.localeCompare(l.start)
173
+ closed: p.closed.sort(
174
+ (I, O) => I.start.localeCompare(O.start)
163
175
  )
164
176
  })
165
177
  )
166
178
  }));
167
- return j(i).sort(
168
- (u, d) => u.orderFormats[0].id - d.orderFormats[0].id
179
+ return D(r).sort(
180
+ (d, m) => d.orderFormats[0].id - m.orderFormats[0].id
169
181
  );
170
182
  }
171
183
  export {
172
- B as default
184
+ Z as default
173
185
  };
@@ -12,5 +12,5 @@ export declare const DaysOfWeekMap: {
12
12
  7: number;
13
13
  };
14
14
  declare function getOutletTagInformation(operatingHours: ServiceDateTimeInterval[], open: boolean, // Derived by the `state` given by the server
15
- specificTime: Moment, currentTime: Moment): OutletTagInformation;
15
+ specificTime: Moment, currentTime: Moment, outletTimeZoneOffset?: string): OutletTagInformation;
16
16
  export default getOutletTagInformation;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("moment"),x=require("./types.js"),d=require("./constants.js"),D=require("./getOutletCurrentActiveOperatingHour.js"),g=require("./getMomentFromDateAndTimeString.js"),v=require("./searchNextOpeningMoment.js");require("@ancon/wildcat-types");const O={0:127,1:1,2:2,3:4,4:8,5:16,6:32,7:64};function k(n,e){const a=n.isSame(e,"d"),o={[e.format(d.OutletMapKeyFormatter)]:{intervals:[],exception:null,metadata:{dayOfWeek:O[e.isoWeekday()]}}};for(let r=a?1:0;r<d.OutletTimelineDayCount;r+=1){const s=u(n).add(r,"d");o[s.format(d.OutletMapKeyFormatter)]={intervals:[],exception:null,metadata:{dayOfWeek:O[s.isoWeekday()]}}}return o}function S(n,e){const a=u().utcOffset(),t=u(e.fromDate).utc(!1).subtract(a,"minutes"),o=u(e.toDate).utc(!1).subtract(a,"minutes");if(!t.isSame(o,"d"))Object.keys(n).forEach(s=>{const i=u(s);if(i.isSame(t,"d")||i.isSame(o,"d")||i.isBetween(t,o)){const c=n[s],l=c.exception?c.exception.position:0;e.position>l&&(c.exception=e)}});else{const s=t.format(d.OutletMapKeyFormatter),i=n[s];if(i){const m=i.exception?i.exception.position:0;e.position>m&&(i.exception=e)}}}function W(n,e){Object.keys(n).forEach(a=>{const t=n[a],{dayOfWeek:o}=t.metadata,{dayOfWeek:r}=e;(o&r)===o&&t.intervals.push(e)})}function E(n,e,a){const t=k(e,a);return n.forEach(o=>{o.type===x.OperatingHourType.Exception?S(t,o):W(t,o)}),t}function M(n,e,a,t){const o=E(n,a,t),r=t.format(d.OutletMapKeyFormatter),s=D(r,o[r],t)!==null,i=e;let m=null,c=null;if(e){const l=a.format(d.OutletMapKeyFormatter),p=D(l,o[l],a);if(p){const[f,y]=p.duration.split(":").map(Number);c=g(l,p.start),m=c.clone().add(f,"hours").add(y,"minutes")}}else c=v(o,a);if(!e&&!c){const l=n.filter(f=>f.state&&u(f.toDate).isAfter(a)),[p]=l.sort((f,y)=>t.valueOf()-(u(f.toDate).valueOf()-u(y.toDate).valueOf()));if(p)return M(n,e,u(p.toDate),t)}return{closingTime:m,openingTime:c,openDuringSpecifiedTime:i,openNow:s}}exports.DaysOfWeekMap=O;exports.default=M;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("moment"),g=require("./types.js"),d=require("./constants.js"),M=require("./getOutletCurrentActiveOperatingHour.js"),v=require("./getMomentFromDateAndTimeString.js"),k=require("./searchNextOpeningMoment.js");require("@ancon/wildcat-types");const D={0:127,1:1,2:2,3:4,4:8,5:16,6:32,7:64};function S(o,e){const a=o.isSame(e,"d"),n={[e.format(d.OutletMapKeyFormatter)]:{intervals:[],exception:null,metadata:{dayOfWeek:D[e.isoWeekday()]}}};for(let i=a?1:0;i<d.OutletTimelineDayCount;i+=1){const s=c(o).add(i,"d");n[s.format(d.OutletMapKeyFormatter)]={intervals:[],exception:null,metadata:{dayOfWeek:D[s.isoWeekday()]}}}return n}function W(o,e){const a=c().utcOffset(),t=c(e.fromDate).utc(!1).subtract(a,"minutes"),n=c(e.toDate).utc(!1).subtract(a,"minutes");if(!t.isSame(n,"d"))Object.keys(o).forEach(s=>{const r=c(s);if(r.isSame(t,"d")||r.isSame(n,"d")||r.isBetween(t,n)){const l=o[s],u=l.exception?l.exception.position:0;e.position>u&&(l.exception=e)}});else{const s=t.format(d.OutletMapKeyFormatter),r=o[s];if(r){const y=r.exception?r.exception.position:0;e.position>y&&(r.exception=e)}}}function E(o,e){Object.keys(o).forEach(a=>{const t=o[a],{dayOfWeek:n}=t.metadata,{dayOfWeek:i}=e;(n&i)===n&&t.intervals.push(e)})}function K(o,e,a){const t=S(e,a);return o.forEach(n=>{n.type===g.OperatingHourType.Exception?W(t,n):E(t,n)}),t}function x(o,e,a,t,n){const i=K(o,a,t),s=t.format(d.OutletMapKeyFormatter),r=M(s,i[s],t)!==null,y=e;let l=null,u=null;if(e){const m=a.format(d.OutletMapKeyFormatter),p=M(m,i[m],a);if(p){const[f,O]=p.duration.split(":").map(Number);u=v(m,p.start),l=u.clone().add(f,"hours").add(O,"minutes")}}else u=k(i,a,n);if(!e&&!u){const m=o.filter(f=>f.state&&c(f.toDate).isAfter(a)),[p]=m.sort((f,O)=>t.valueOf()-(c(f.toDate).valueOf()-c(O.toDate).valueOf()));if(p)return x(o,e,c(p.toDate),t)}return{closingTime:l,openingTime:u,openDuringSpecifiedTime:y,openNow:r}}exports.DaysOfWeekMap=D;exports.default=x;
@@ -1,11 +1,11 @@
1
- import p from "moment";
2
- import { OperatingHourType as x } from "./types.mjs";
3
- import { OutletMapKeyFormatter as d, OutletTimelineDayCount as g } from "./constants.mjs";
4
- import O from "./getOutletCurrentActiveOperatingHour.mjs";
5
- import k from "./getMomentFromDateAndTimeString.mjs";
6
- import v from "./searchNextOpeningMoment.mjs";
1
+ import c from "moment";
2
+ import { OperatingHourType as g } from "./types.mjs";
3
+ import { OutletMapKeyFormatter as d, OutletTimelineDayCount as k } from "./constants.mjs";
4
+ import D from "./getOutletCurrentActiveOperatingHour.mjs";
5
+ import v from "./getMomentFromDateAndTimeString.mjs";
6
+ import M from "./searchNextOpeningMoment.mjs";
7
7
  import "@ancon/wildcat-types";
8
- const D = {
8
+ const x = {
9
9
  0: 127,
10
10
  1: 1,
11
11
  2: 2,
@@ -15,100 +15,104 @@ const D = {
15
15
  6: 32,
16
16
  7: 64
17
17
  };
18
- function M(n, t) {
19
- const a = n.isSame(t, "d"), o = {
18
+ function S(o, t) {
19
+ const a = o.isSame(t, "d"), n = {
20
20
  [t.format(d)]: {
21
21
  intervals: [],
22
22
  exception: null,
23
- metadata: { dayOfWeek: D[t.isoWeekday()] }
23
+ metadata: { dayOfWeek: x[t.isoWeekday()] }
24
24
  }
25
25
  };
26
- for (let r = a ? 1 : 0; r < g; r += 1) {
27
- const s = p(n).add(r, "d");
28
- o[s.format(d)] = {
26
+ for (let i = a ? 1 : 0; i < k; i += 1) {
27
+ const s = c(o).add(i, "d");
28
+ n[s.format(d)] = {
29
29
  intervals: [],
30
30
  exception: null,
31
- metadata: { dayOfWeek: D[s.isoWeekday()] }
31
+ metadata: { dayOfWeek: x[s.isoWeekday()] }
32
32
  };
33
33
  }
34
- return o;
34
+ return n;
35
35
  }
36
- function S(n, t) {
37
- const a = p().utcOffset(), e = p(t.fromDate).utc(!1).subtract(a, "minutes"), o = p(t.toDate).utc(!1).subtract(a, "minutes");
36
+ function W(o, t) {
37
+ const a = c().utcOffset(), e = c(t.fromDate).utc(!1).subtract(a, "minutes"), n = c(t.toDate).utc(!1).subtract(a, "minutes");
38
38
  if (!e.isSame(
39
- o,
39
+ n,
40
40
  "d"
41
41
  ))
42
- Object.keys(n).forEach((s) => {
43
- const i = p(s);
44
- if (i.isSame(e, "d") || i.isSame(o, "d") || i.isBetween(e, o)) {
45
- const c = n[s], f = c.exception ? c.exception.position : 0;
46
- t.position > f && (c.exception = t);
42
+ Object.keys(o).forEach((s) => {
43
+ const r = c(s);
44
+ if (r.isSame(e, "d") || r.isSame(n, "d") || r.isBetween(e, n)) {
45
+ const f = o[s], p = f.exception ? f.exception.position : 0;
46
+ t.position > p && (f.exception = t);
47
47
  }
48
48
  });
49
49
  else {
50
- const s = e.format(d), i = n[s];
51
- if (i) {
52
- const u = i.exception ? i.exception.position : 0;
53
- t.position > u && (i.exception = t);
50
+ const s = e.format(d), r = o[s];
51
+ if (r) {
52
+ const y = r.exception ? r.exception.position : 0;
53
+ t.position > y && (r.exception = t);
54
54
  }
55
55
  }
56
56
  }
57
- function W(n, t) {
58
- Object.keys(n).forEach((a) => {
59
- const e = n[a], { dayOfWeek: o } = e.metadata, { dayOfWeek: r } = t;
60
- (o & r) === o && e.intervals.push(t);
57
+ function E(o, t) {
58
+ Object.keys(o).forEach((a) => {
59
+ const e = o[a], { dayOfWeek: n } = e.metadata, { dayOfWeek: i } = t;
60
+ (n & i) === n && e.intervals.push(t);
61
61
  });
62
62
  }
63
- function E(n, t, a) {
64
- const e = M(t, a);
65
- return n.forEach((o) => {
66
- o.type === x.Exception ? S(e, o) : W(e, o);
63
+ function I(o, t, a) {
64
+ const e = S(t, a);
65
+ return o.forEach((n) => {
66
+ n.type === g.Exception ? W(e, n) : E(e, n);
67
67
  }), e;
68
68
  }
69
- function I(n, t, a, e) {
70
- const o = E(
71
- n,
69
+ function h(o, t, a, e, n) {
70
+ const i = I(
71
+ o,
72
72
  a,
73
73
  e
74
- ), r = e.format(d), s = O(
75
- r,
76
- o[r],
74
+ ), s = e.format(d), r = D(
75
+ s,
76
+ i[s],
77
77
  e
78
- ) !== null, i = t;
79
- let u = null, c = null;
78
+ ) !== null, y = t;
79
+ let f = null, p = null;
80
80
  if (t) {
81
- const f = a.format(d), l = O(
82
- f,
83
- o[f],
81
+ const u = a.format(d), l = D(
82
+ u,
83
+ i[u],
84
84
  a
85
85
  );
86
86
  if (l) {
87
- const [m, y] = l.duration.split(":").map(Number);
88
- c = k(
89
- f,
87
+ const [m, O] = l.duration.split(":").map(Number);
88
+ p = v(
89
+ u,
90
90
  l.start
91
- ), u = c.clone().add(m, "hours").add(y, "minutes");
91
+ ), f = p.clone().add(m, "hours").add(O, "minutes");
92
92
  }
93
93
  } else
94
- c = v(o, a);
95
- if (!t && !c) {
96
- const f = n.filter(
97
- (m) => m.state && p(m.toDate).isAfter(a)
98
- ), [l] = f.sort(
99
- (m, y) => e.valueOf() - (p(m.toDate).valueOf() - p(y.toDate).valueOf())
94
+ p = M(
95
+ i,
96
+ a,
97
+ n
98
+ );
99
+ if (!t && !p) {
100
+ const u = o.filter(
101
+ (m) => m.state && c(m.toDate).isAfter(a)
102
+ ), [l] = u.sort(
103
+ (m, O) => e.valueOf() - (c(m.toDate).valueOf() - c(O.toDate).valueOf())
100
104
  );
101
105
  if (l)
102
- return I(
103
- n,
106
+ return h(
107
+ o,
104
108
  t,
105
- p(l.toDate),
109
+ c(l.toDate),
106
110
  e
107
111
  );
108
112
  }
109
- return { closingTime: u, openingTime: c, openDuringSpecifiedTime: i, openNow: s };
113
+ return { closingTime: f, openingTime: p, openDuringSpecifiedTime: y, openNow: r };
110
114
  }
111
115
  export {
112
- D as DaysOfWeekMap,
113
- I as default
116
+ x as DaysOfWeekMap,
117
+ h as default
114
118
  };
@@ -6,8 +6,9 @@ import { OperatingHourFormattedMap } from './types';
6
6
  *
7
7
  * @param {OperatingHourFormattedMap} operatingHourMap The map of formatted intervals and exceptions indexed against the date
8
8
  * @param {Moment} relevantMoment The relevant moment to compare
9
+ * @param {String} outletTimeZoneOffset
9
10
  *
10
11
  * @return {Moment}
11
12
  */
12
- declare function searchNextOpeningMoment(operatingHourMap: OperatingHourFormattedMap, relevantMoment: Moment): Moment | null;
13
+ declare function searchNextOpeningMoment(operatingHourMap: OperatingHourFormattedMap, relevantMoment: Moment, outletTimeZoneOffset?: string): Moment | null;
13
14
  export default searchNextOpeningMoment;
@@ -1 +1 @@
1
- "use strict";const f=require("moment"),O=require("@ancon/wildcat-types"),c=require("./constants.js"),a=require("./getMomentFromDateAndTimeString.js");function m(i){const[t]=i.split(":").map(Number)??[];return t??0}function y(i){let t=null;const{intervals:r,exception:e}=i;if(e){const{state:o}=e;o||(t=e)}else{const o=r.sort((n,l)=>m(n.start)-m(l.start)),[s]=o;return s}return t}function p(i,t,r){var o,s;const e=[];if(t.exception){if(t.exception.state===O.OutletState.Open){const n=a(i,t.exception.start);r.isBefore(n)&&e.push({interval:t.exception,moment:n})}}else for(let n=0;n<t.intervals.length;n+=1){const l=t.intervals[n],u=a(i,l.start);r.isBefore(u)&&e.push({interval:l,moment:u})}return e.length<2?((o=e[0])==null?void 0:o.interval)??null:((s=e.sort((n,l)=>n.moment-r-(l.moment-r))[0])==null?void 0:s.interval)??null}function g(i,t){let r=null;const e=f(t).format(c.OutletMapKeyFormatter),o=p(e,i[e],t);if(o&&(r=a(e,o.start)),!r)for(let s=1;s<c.OutletTimelineDayCount;s+=1){const n=f(t).add(s,"d").format(c.OutletMapKeyFormatter),l=i[n],u=y(l);if(u){r=a(n,u.start);break}}return r}module.exports=g;
1
+ "use strict";const m=require("moment"),p=require("@ancon/wildcat-types"),c=require("./constants.js"),a=require("./getMomentFromDateAndTimeString.js");function O(i){const[e]=i.split(":").map(Number)??[];return e??0}function d(i,e,r="00:00:00"){const[t,o]=r.split(":"),n=i.clone().add(t,"hour").add(o,"minute").date()-e.date();return n!==0?i.subtract(n,"day"):i}function g(i){let e=null;const{intervals:r,exception:t}=i;if(t){const{state:o}=t;o||(e=t)}else{const o=r.sort((n,s)=>O(n.start)-O(s.start)),[u]=o;return u}return e}function h(i,e,r){var o,u;const t=[];if(e.exception){if(e.exception.state===p.OutletState.Open){const n=a(i,e.exception.start);r.isBefore(n)&&t.push({interval:e.exception,moment:n})}}else for(let n=0;n<e.intervals.length;n+=1){const s=e.intervals[n],l=a(i,s.start);r.isBefore(l)&&t.push({interval:s,moment:l})}return t.length<2?((o=t[0])==null?void 0:o.interval)??null:((u=t.sort((n,s)=>n.moment-r-(s.moment-r))[0])==null?void 0:u.interval)??null}function x(i,e,r){let t=null;const o=m(e).format(c.OutletMapKeyFormatter),u=h(o,i[o],e);if(u&&(t=a(o,u.start),t=d(t,e,r)),!t)for(let n=1;n<c.OutletTimelineDayCount;n+=1){const s=m(e).add(n,"d"),l=s.format(c.OutletMapKeyFormatter),y=i[l],f=g(y);if(f){t=a(l,f.start),t=d(t,s,r);break}}return t}module.exports=x;
@@ -1,74 +1,86 @@
1
- import f from "moment";
2
- import { OutletState as p } from "@ancon/wildcat-types";
3
- import { OutletMapKeyFormatter as m, OutletTimelineDayCount as O } from "./constants.mjs";
1
+ import c from "moment";
2
+ import { OutletState as y } from "@ancon/wildcat-types";
3
+ import { OutletMapKeyFormatter as m, OutletTimelineDayCount as g } from "./constants.mjs";
4
4
  import a from "./getMomentFromDateAndTimeString.mjs";
5
- function c(o) {
6
- const [t] = o.split(":").map(Number) ?? [];
7
- return t ?? 0;
5
+ function O(i) {
6
+ const [e] = i.split(":").map(Number) ?? [];
7
+ return e ?? 0;
8
8
  }
9
- function g(o) {
10
- let t = null;
11
- const { intervals: i, exception: e } = o;
12
- if (e) {
13
- const { state: r } = e;
14
- r || (t = e);
9
+ function p(i, e, r = "00:00:00") {
10
+ const [t, o] = r.split(":"), n = i.clone().add(t, "hour").add(o, "minute").date() - e.date();
11
+ return n !== 0 ? i.subtract(n, "day") : i;
12
+ }
13
+ function h(i) {
14
+ let e = null;
15
+ const { intervals: r, exception: t } = i;
16
+ if (t) {
17
+ const { state: o } = t;
18
+ o || (e = t);
15
19
  } else {
16
- const r = i.sort(
17
- (n, l) => c(n.start) - c(l.start)
18
- ), [s] = r;
19
- return s;
20
+ const o = r.sort(
21
+ (n, s) => O(n.start) - O(s.start)
22
+ ), [l] = o;
23
+ return l;
20
24
  }
21
- return t;
25
+ return e;
22
26
  }
23
- function x(o, t, i) {
24
- var r, s;
25
- const e = [];
26
- if (t.exception) {
27
- if (t.exception.state === p.Open) {
27
+ function x(i, e, r) {
28
+ var o, l;
29
+ const t = [];
30
+ if (e.exception) {
31
+ if (e.exception.state === y.Open) {
28
32
  const n = a(
29
- o,
30
- t.exception.start
33
+ i,
34
+ e.exception.start
31
35
  );
32
- i.isBefore(n) && e.push({
33
- interval: t.exception,
36
+ r.isBefore(n) && t.push({
37
+ interval: e.exception,
34
38
  moment: n
35
39
  });
36
40
  }
37
41
  } else
38
- for (let n = 0; n < t.intervals.length; n += 1) {
39
- const l = t.intervals[n], u = a(
40
- o,
41
- l.start
42
+ for (let n = 0; n < e.intervals.length; n += 1) {
43
+ const s = e.intervals[n], u = a(
44
+ i,
45
+ s.start
42
46
  );
43
- i.isBefore(u) && e.push({ interval: l, moment: u });
47
+ r.isBefore(u) && t.push({ interval: s, moment: u });
44
48
  }
45
- return e.length < 2 ? ((r = e[0]) == null ? void 0 : r.interval) ?? null : ((s = e.sort(
46
- (n, l) => n.moment - i - (l.moment - i)
47
- )[0]) == null ? void 0 : s.interval) ?? null;
49
+ return t.length < 2 ? ((o = t[0]) == null ? void 0 : o.interval) ?? null : ((l = t.sort(
50
+ (n, s) => n.moment - r - (s.moment - r)
51
+ )[0]) == null ? void 0 : l.interval) ?? null;
48
52
  }
49
- function d(o, t) {
50
- let i = null;
51
- const e = f(t).format(m), r = x(
52
- e,
53
- o[e],
54
- t
53
+ function b(i, e, r) {
54
+ let t = null;
55
+ const o = c(e).format(m), l = x(
56
+ o,
57
+ i[o],
58
+ e
55
59
  );
56
- if (r && (i = a(
60
+ if (l && (t = a(
61
+ o,
62
+ l.start
63
+ ), t = p(
64
+ t,
57
65
  e,
58
- r.start
59
- )), !i)
60
- for (let s = 1; s < O; s += 1) {
61
- const n = f(t).add(s, "d").format(m), l = o[n], u = g(l);
62
- if (u) {
63
- i = a(
64
- n,
65
- u.start
66
+ r
67
+ )), !t)
68
+ for (let n = 1; n < g; n += 1) {
69
+ const s = c(e).add(n, "d"), u = s.format(m), d = i[u], f = h(d);
70
+ if (f) {
71
+ t = a(
72
+ u,
73
+ f.start
74
+ ), t = p(
75
+ t,
76
+ s,
77
+ r
66
78
  );
67
79
  break;
68
80
  }
69
81
  }
70
- return i;
82
+ return t;
71
83
  }
72
84
  export {
73
- d as default
85
+ b as default
74
86
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.20.14",
3
+ "version": "1.20.16",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",