@ancon/wildcat-utils 1.31.9 → 1.32.1
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/error/index.d.ts +2 -1
- package/error/index.js +1 -1
- package/error/index.mjs +4 -2
- package/error/isNotFoundError.d.ts +3 -0
- package/error/isNotFoundError.js +1 -0
- package/error/isNotFoundError.mjs +8 -0
- package/index.js +1 -1
- package/index.mjs +24 -22
- package/outlet/getListOutletOpeningHoursTable.js +1 -1
- package/outlet/getListOutletOpeningHoursTable.mjs +117 -102
- package/package.json +6 -1
package/error/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import createCodedError, { CodedError } from './createCodedError';
|
|
|
2
2
|
import isCodedError from './isCodedError';
|
|
3
3
|
import isNetworkError from './isNetworkError';
|
|
4
4
|
import isLockedError from './isLockedError';
|
|
5
|
+
import isNotFoundError from './isNotFoundError';
|
|
5
6
|
import serializeError, { SerializedAxiosError, SerializedCodedError, SerializedGenericError } from './serializeError';
|
|
6
7
|
export type { CodedError, SerializedAxiosError, SerializedCodedError, SerializedGenericError, };
|
|
7
|
-
export { createCodedError, isCodedError, isNetworkError, isLockedError, serializeError, };
|
|
8
|
+
export { createCodedError, isCodedError, isNetworkError, isLockedError, isNotFoundError, serializeError, };
|
package/error/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./createCodedError.js"),e=require("./isCodedError.js"),o=require("./isNetworkError.js"),i=require("./isLockedError.js"),s=require("./serializeError.js");require("axios");exports.createCodedError=r;exports.isCodedError=e;exports.isNetworkError=o;exports.isLockedError=i;exports.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./createCodedError.js"),e=require("./isCodedError.js"),o=require("./isNetworkError.js"),i=require("./isLockedError.js"),s=require("./isNotFoundError.js"),t=require("./serializeError.js");require("axios");exports.createCodedError=r;exports.isCodedError=e;exports.isNetworkError=o;exports.isLockedError=i;exports.isNotFoundError=s;exports.serializeError=t;
|
package/error/index.mjs
CHANGED
|
@@ -2,12 +2,14 @@ import { default as t } from "./createCodedError.mjs";
|
|
|
2
2
|
import { default as d } from "./isCodedError.mjs";
|
|
3
3
|
import { default as s } from "./isNetworkError.mjs";
|
|
4
4
|
import { default as l } from "./isLockedError.mjs";
|
|
5
|
-
import { default as p } from "./
|
|
5
|
+
import { default as p } from "./isNotFoundError.mjs";
|
|
6
|
+
import { default as x } from "./serializeError.mjs";
|
|
6
7
|
import "axios";
|
|
7
8
|
export {
|
|
8
9
|
t as createCodedError,
|
|
9
10
|
d as isCodedError,
|
|
10
11
|
l as isLockedError,
|
|
11
12
|
s as isNetworkError,
|
|
12
|
-
p as
|
|
13
|
+
p as isNotFoundError,
|
|
14
|
+
x as serializeError
|
|
13
15
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o=require("axios");function i(s){var t;return o.isAxiosError(s)&&(s.status===404||((t=s.response)==null?void 0:t.status)===404)}module.exports=i;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./shared/isWithinFlag.js"),r=require("./shared/generateId.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./shared/isWithinFlag.js"),r=require("./shared/generateId.js"),o=require("./shared/wait.js"),i=require("./outlet/getListOutletOpeningHoursTable.js"),u=require("./outlet/getOutletTagInformation.js"),s=require("./outlet/getOutletAvailabilityInfo.js"),n=require("./outlet/getOutletOfflineOrderFormats.js"),c=require("./outlet/getOutletAvailableOrderFormats.js"),a=require("./outlet/getOutletFormattedDistance.js"),l=require("./outlet/isOutletAcceptingPreOrders.js"),d=require("./outlet/getOutletDeliveryFee.js"),g=require("./outlet/getOutletTodayOpeningTimes.js"),q=require("./outlet/getOutletOrderFormats.js"),O=require("./outlet/serviceDateTimesFromOpeningHours.js"),_=require("./outlet/getPickerIntervalsForDay.js"),m=require("./outlet/getServiceIntervalRange.js"),k=require("./outlet/getServiceIntervalsForOrderFormat.js"),h=require("./outlet/getOutletFormattedAddress.js"),p=require("./outlet/getPartitionedOutletsList.js"),P=require("./outlet/getOutletPickerTimesForWeek.js"),S=require("./outlet/getOutletOrderPrepTime.js"),C=require("./outlet/getStructuredOutletAddress.js"),T=require("./outlet/getOutletNextOpeningTimeText.js"),F=require("./outlet/getOutletCurrentClosingTimeText.js"),f=require("./outlet/getOutletNextReadyToOrderTime.js"),y=require("./versioning/isVersionALessThanB.js"),v=require("./versioning/cleanVersionString.js"),I=require("./api/getUrlAndParams.js"),A=require("./api/getEndpointWithVersion.js"),R=require("./api/generateBackoffWithEqualJitter.js"),D=require("./api/isAcceptedResponse.js"),b=require("./api/isNoContentResponse.js"),E=require("./string/slugify.js"),N=require("./string/truncate.js"),V=require("./color/lighten.js"),M=require("./color/brighten.js"),H=require("./color/darken.js"),L=require("./color/isDarkBackground.js"),x=require("./user/getFullName.js"),W=require("./user/getFullAddressString.js"),B=require("./user/getCustomerAddressFromGeocoderResult.js"),G=require("./user/getFormattedPhoneNumber.js"),U=require("./user/getStructuredCustomerAddress.js"),w=require("./logger/Logger.js"),z=require("./logger/types.js"),J=require("./logger/sanitizeAsStringDict.js"),K=require("./logger/pascalCaseFormatter.js"),Q=require("./printing/getPrinterType.js"),j=require("./printing/isValidPrinter.js"),X=require("./printing/isValidNetworkPrinter.js"),Y=require("./printing/isValidStarCloudPrinter.js"),Z=require("./printing/isTerminalPrinter.js"),$=require("./printing/isCloudPrintModeEnabled.js"),ee=require("./number/randomIntFromInterval.js"),te=require("./tables/decodeTableQRPayload.js"),re=require("./checkout/getCheckoutItemModifications.js"),oe=require("./checkout/getCheckoutProductName.js"),e=require("./checkout/getCheckoutOrderStatusTexts.js"),ie=require("./checkout/getCheckoutItemsMappedByTicketItemStatus.js"),ue=require("./checkout/isCheckoutOrderSummary.js"),se=require("./checkout/buildCheckoutRequestItem.js"),ne=require("./checkout/getCheckoutGrandTotalAmount.js"),ce=require("./checkout/getCheckoutRequestItemFromCheckoutItem.js"),ae=require("./checkout/isCheckoutItemsAreEqual.js"),le=require("./checkout/checkoutHasWallet.js"),de=require("./checkout/getWalletMetaFromCheckout.js"),ge=require("./checkout/isPreOrderServiceTime.js"),qe=require("./checkout/isPreOrderCheckout.js"),Oe=require("./currency/getFormattedCurrency.js"),_e=require("./inventory/isDetailedProductOutOfStock.js"),me=require("./inventory/isDetailedProductVariantOutOfStocks.js"),ke=require("./inventory/isMenuTreeProductOutOfStock.js"),he=require("./inventory/isDetailedProductUpSellsOutOfStock.js"),pe=require("./inventory/isUpSellProductOutStock.js"),Pe=require("./inventory/isDetailedProductOutletStockOutOfStock.js"),Se=require("./inventory/getDetailedProductVariantStock.js"),Ce=require("./signalr/createUseSignalRHook.js"),Te=require("./signalr/SignalR.js"),Fe=require("./error/createCodedError.js"),fe=require("./error/isCodedError.js"),ye=require("./error/isNetworkError.js"),ve=require("./error/isLockedError.js"),Ie=require("./error/isNotFoundError.js"),Ae=require("./error/serializeError.js"),Re=require("./hangfire/isHangfireResponse.js"),De=require("./hangfire/createHangfirePoller.js"),be=require("./hangfire/createMakeHangfireRequest.js"),Ee=require("./product/extractProductsFromMenuTree.js"),Ne=require("./product/calculateIngredientsCost.js"),Ve=require("./product/calculateAddonGroupCost.js"),Me=require("./product/getAddonGroupInfoBySettings.js");require("moment");require("@ancon/wildcat-types");require("./outlet/constants.js");require("./outlet/getOutletCurrentActiveOperatingHour.js");require("./outlet/getMomentFromDateAndTimeString.js");require("./outlet/searchNextOpeningMoment.js");require("./_baseIsEqual-a66350f1.js");require("./isObjectLike-0cc89d64.js");require("./toString-c005c116.js");require("./shared/constants.js");require("./time/toMinutes.js");require("./time/getNextTenthMinute.js");require("./outlet/types.js");require("./outlet/getSettingsForOrderFormat.js");require("./outlet/getServiceIntervalStart.js");require("./outlet/getNextTenthMinute.js");require("./outlet/generatePickerTimesForDay.js");require("./outlet/getServiceIntervalEnd.js");require("./outlet/hoursAndMinutesToMinutes.js");require("compare-versions");require("tinycolor2");require("google-libphonenumber");require("@ancon/wildcat-printing");require("./currency/getFormattedCurrencyPostfix.js");require("react");require("react-redux");require("@microsoft/signalr");require("axios");exports.isWithinFlag=t;exports.generateId=r;exports.wait=o;exports.getListOutletOpeningHoursTable=i;exports.getOutletTagInformation=u.default;exports.getOutletAvailabilityInfo=s.default;exports.getOutletOfflineOrderFormats=n;exports.getOutletAvailableOrderFormats=c;exports.getOutletFormattedDistance=a;exports.isOutletAcceptingPreOrders=l;exports.getOutletDeliveryFee=d;exports.getOutletTodayOpeningTimes=g;exports.getOutletOrderFormats=q;exports.serviceDateTimesFromOpeningHours=O;exports.getPickerIntervalsForDay=_;exports.getServiceIntervalRange=m;exports.getServiceIntervalsForOrderFormat=k;exports.getOutletFormattedAddress=h;exports.getPartitionedOutletsList=p;exports.getOutletPickerTimesForWeek=P;exports.getOutletOrderPreparationTime=S;exports.getStructuredOutletAddress=C;exports.getOutletNextOpeningTimeText=T;exports.getOutletCurrentClosingTimeText=F;exports.getOutletNextReadyToOrderTime=f;exports.isVersionALessThanB=y;exports.cleanVersionString=v;exports.getUrlAndParams=I;exports.getEndpointWithVersion=A;exports.generateBackoffWithEqualJitter=R;exports.isAcceptedResponse=D;exports.isNoContentResponse=b;exports.slugify=E;exports.truncate=N;exports.lighten=V;exports.brighten=M;exports.darken=H;exports.isDarkBackground=L;exports.getFullName=x;exports.getFullAddressString=W;exports.getCustomerAddressFromGeocoderResult=B;exports.getFormattedPhoneNumber=G;exports.getStructuredCustomerAddress=U;exports.Logger=w;exports.LogLevel=z.LogLevel;exports.sanitizeAsStringDict=J;exports.pascalCaseFormatter=K;exports.getPrinterType=Q;exports.isValidPrinter=j;exports.isValidNetworkPrinter=X;exports.isValidStarCloudPrinter=Y;exports.isTerminalPrinter=Z;exports.isCloudPrintModeEnabled=$;exports.randomIntFromInterval=ee;exports.decodeTableQRPayload=te;exports.getCheckoutGroupedModifications=re;exports.getCheckoutProductName=oe;exports.TranslationKey=e.TranslationKey;exports.getCheckoutOrderStatusTexts=e.default;exports.getCheckoutItemsMappedByTicketItemStatus=ie;exports.isCheckoutOrderSummary=ue;exports.buildCheckoutRequestItem=se;exports.getCheckoutGrandTotalAmount=ne;exports.getCheckoutRequestItemFromCheckoutItem=ce;exports.isCheckoutItemsAreEqual=ae;exports.checkoutHasWallet=le;exports.getWalletMetaFromCheckout=de;exports.isPreOrderServiceTime=ge;exports.isPreOrderCheckout=qe;exports.getFormattedCurrency=Oe;exports.isDetailedProductOutOfStock=_e;exports.isDetailedProductVariantOutOfStocks=me;exports.isMenuTreeProductOutOfStock=ke;exports.isDetailedProductUpSellsOutOfStock=he;exports.isUpSellProductOutOfStock=pe;exports.isDetailedProductOutletStockOutOfStock=Pe;exports.getDetailedProductVariantStock=Se;exports.createUseSignalRHook=Ce;exports.SignalR=Te;exports.createCodedError=Fe;exports.isCodedError=fe;exports.isNetworkError=ye;exports.isLockedError=ve;exports.isNotFoundError=Ie;exports.serializeError=Ae;exports.isHangfireResponse=Re;exports.createHangfirePoller=De.default;exports.createMakeHangfireRequest=be;exports.extractProductsFromMenuTree=Ee;exports.calculateIngredientsCost=Ne;exports.calculateAddonGroupsCost=Ve;exports.getAddonGroupInfoBySettings=Me.default;
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as D } from "./shared/isWithinFlag.mjs";
|
|
2
|
-
import { default as
|
|
2
|
+
import { default as N } from "./shared/generateId.mjs";
|
|
3
3
|
import { default as V } from "./shared/wait.mjs";
|
|
4
4
|
import { default as L } from "./outlet/getListOutletOpeningHoursTable.mjs";
|
|
5
5
|
import { default as W } from "./outlet/getOutletTagInformation.mjs";
|
|
@@ -26,7 +26,7 @@ import { default as he } from "./outlet/getOutletNextReadyToOrderTime.mjs";
|
|
|
26
26
|
import { default as Ie } from "./versioning/isVersionALessThanB.mjs";
|
|
27
27
|
import { default as ve } from "./versioning/cleanVersionString.mjs";
|
|
28
28
|
import { default as De } from "./api/getUrlAndParams.mjs";
|
|
29
|
-
import { default as
|
|
29
|
+
import { default as Ne } from "./api/getEndpointWithVersion.mjs";
|
|
30
30
|
import { default as Ve } from "./api/generateBackoffWithEqualJitter.mjs";
|
|
31
31
|
import { default as Le } from "./api/isAcceptedResponse.mjs";
|
|
32
32
|
import { default as We } from "./api/isNoContentResponse.mjs";
|
|
@@ -53,7 +53,7 @@ import { default as ht } from "./printing/isTerminalPrinter.mjs";
|
|
|
53
53
|
import { default as It } from "./printing/isCloudPrintModeEnabled.mjs";
|
|
54
54
|
import { default as vt } from "./number/randomIntFromInterval.mjs";
|
|
55
55
|
import { default as Dt } from "./tables/decodeTableQRPayload.mjs";
|
|
56
|
-
import { default as
|
|
56
|
+
import { default as Nt } from "./checkout/getCheckoutItemModifications.mjs";
|
|
57
57
|
import { default as Vt } from "./checkout/getCheckoutProductName.mjs";
|
|
58
58
|
import { TranslationKey as Lt, default as Mt } from "./checkout/getCheckoutOrderStatusTexts.mjs";
|
|
59
59
|
import { default as qt } from "./checkout/getCheckoutItemsMappedByTicketItemStatus.mjs";
|
|
@@ -80,14 +80,15 @@ import { default as Ar } from "./error/createCodedError.mjs";
|
|
|
80
80
|
import { default as yr } from "./error/isCodedError.mjs";
|
|
81
81
|
import { default as Rr } from "./error/isNetworkError.mjs";
|
|
82
82
|
import { default as Er } from "./error/isLockedError.mjs";
|
|
83
|
-
import { default as
|
|
84
|
-
import { default as Hr } from "./
|
|
85
|
-
import { default as Mr } from "./hangfire/
|
|
86
|
-
import { default as qr } from "./hangfire/
|
|
87
|
-
import { default as Gr } from "./
|
|
88
|
-
import { default as wr } from "./product/
|
|
89
|
-
import { default as Jr } from "./product/
|
|
90
|
-
import { default as Qr } from "./product/
|
|
83
|
+
import { default as br } from "./error/isNotFoundError.mjs";
|
|
84
|
+
import { default as Hr } from "./error/serializeError.mjs";
|
|
85
|
+
import { default as Mr } from "./hangfire/isHangfireResponse.mjs";
|
|
86
|
+
import { default as qr } from "./hangfire/createHangfirePoller.mjs";
|
|
87
|
+
import { default as Gr } from "./hangfire/createMakeHangfireRequest.mjs";
|
|
88
|
+
import { default as wr } from "./product/extractProductsFromMenuTree.mjs";
|
|
89
|
+
import { default as Jr } from "./product/calculateIngredientsCost.mjs";
|
|
90
|
+
import { default as Qr } from "./product/calculateAddonGroupCost.mjs";
|
|
91
|
+
import { default as Xr } from "./product/getAddonGroupInfoBySettings.mjs";
|
|
91
92
|
import "moment";
|
|
92
93
|
import "@ancon/wildcat-types";
|
|
93
94
|
import "./outlet/constants.mjs";
|
|
@@ -123,29 +124,29 @@ export {
|
|
|
123
124
|
Lt as TranslationKey,
|
|
124
125
|
Ke as brighten,
|
|
125
126
|
wt as buildCheckoutRequestItem,
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
Qr as calculateAddonGroupsCost,
|
|
128
|
+
Jr as calculateIngredientsCost,
|
|
128
129
|
Zt as checkoutHasWallet,
|
|
129
130
|
ve as cleanVersionString,
|
|
130
131
|
Ar as createCodedError,
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
qr as createHangfirePoller,
|
|
133
|
+
Gr as createMakeHangfireRequest,
|
|
133
134
|
Sr as createUseSignalRHook,
|
|
134
135
|
je as darken,
|
|
135
136
|
Dt as decodeTableQRPayload,
|
|
136
|
-
|
|
137
|
+
wr as extractProductsFromMenuTree,
|
|
137
138
|
Ve as generateBackoffWithEqualJitter,
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
N as generateId,
|
|
140
|
+
Xr as getAddonGroupInfoBySettings,
|
|
140
141
|
Jt as getCheckoutGrandTotalAmount,
|
|
141
|
-
|
|
142
|
+
Nt as getCheckoutGroupedModifications,
|
|
142
143
|
qt as getCheckoutItemsMappedByTicketItemStatus,
|
|
143
144
|
Mt as getCheckoutOrderStatusTexts,
|
|
144
145
|
Vt as getCheckoutProductName,
|
|
145
146
|
Qt as getCheckoutRequestItemFromCheckoutItem,
|
|
146
147
|
rt as getCustomerAddressFromGeocoderResult,
|
|
147
148
|
Pr as getDetailedProductVariantStock,
|
|
148
|
-
|
|
149
|
+
Ne as getEndpointWithVersion,
|
|
149
150
|
fr as getFormattedCurrency,
|
|
150
151
|
at as getFormattedPhoneNumber,
|
|
151
152
|
et as getFullAddressString,
|
|
@@ -184,11 +185,12 @@ export {
|
|
|
184
185
|
Or as isDetailedProductOutletStockOutOfStock,
|
|
185
186
|
xr as isDetailedProductUpSellsOutOfStock,
|
|
186
187
|
dr as isDetailedProductVariantOutOfStocks,
|
|
187
|
-
|
|
188
|
+
Mr as isHangfireResponse,
|
|
188
189
|
Er as isLockedError,
|
|
189
190
|
pr as isMenuTreeProductOutOfStock,
|
|
190
191
|
Rr as isNetworkError,
|
|
191
192
|
We as isNoContentResponse,
|
|
193
|
+
br as isNotFoundError,
|
|
192
194
|
j as isOutletAcceptingPreOrders,
|
|
193
195
|
or as isPreOrderCheckout,
|
|
194
196
|
tr as isPreOrderServiceTime,
|
|
@@ -203,7 +205,7 @@ export {
|
|
|
203
205
|
nt as pascalCaseFormatter,
|
|
204
206
|
vt as randomIntFromInterval,
|
|
205
207
|
it as sanitizeAsStringDict,
|
|
206
|
-
|
|
208
|
+
Hr as serializeError,
|
|
207
209
|
re as serviceDateTimesFromOpeningHours,
|
|
208
210
|
Be as slugify,
|
|
209
211
|
Ue as truncate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const F=require("moment"),r=require("@ancon/wildcat-types"),g=require("../shared/isWithinFlag.js"),I=require("../shared/generateId.js"),c=[{id:r.OrderFormat.EatIn,name:"eatIn"},{id:r.OrderFormat.TakeAway,name:"takeaway"},{id:r.OrderFormat.TableOrder,name:"tableOrder"},{id:r.OrderFormat.Delivery,name:"delivery"}];function v(e){const o=F.utc(e).subtract(1,"day").startOf("day"),t=[];for(let s=0,d=o;s<7;s+=1)d=d.clone().add(1,"day").startOf("day"),t.push(d.clone());return t}function W(e){return[...e].sort((o,t)=>o.isoWeekday()-t.isoWeekday())}function k(e){return e.split(":").map(Number)}function T(e,o,t){const[s,d]=k(e.start),[p,m]=k(e.duration),[n,y]=k(t||"00:00:00");if(e.type===r.IntervalType.Interval){let i=o.clone().add(s,"hour").add(d,"minute");const a=i.clone().add(n,"hour").add(y,"minute").date()-o.date();a!==0&&(i=i.subtract(a,"day"));const f=i.clone().add(p,"hour").add(m,"minute");return{id:e.id,start:i.toISOString(),end:f.toISOString()}}if(e.type===r.IntervalType.Exception){const i=F(e.fromDate),u=F(e.toDate);if(o.isBetween(i,u,void 0,"[]")){const a=o.clone().add(s,"hour").add(d,"minute"),f=a.clone().add(p,"hour").add(m,"minute");return{id:e.id,start:a.toISOString(),end:f.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function S(e,o,t,s){const d={[r.DayOfWeek.Monday]:1,[r.DayOfWeek.Tuesday]:2,[r.DayOfWeek.Wednesday]:3,[r.DayOfWeek.Thursday]:4,[r.DayOfWeek.Friday]:5,[r.DayOfWeek.Saturday]:6,[r.DayOfWeek.Sunday]:7,[r.DayOfWeek.Everyday]:null};for(let p=0;p<o.length;p+=1){const m=o[p],n=m.isoWeekday(),y=e.dayOfWeek,u=(d[y]??null)===n||y===r.DayOfWeek.Everyday;if(t[n]||(t[n]={isoWeekday:n,key:"",open:[],adjusted:[],closed:[]}),u){const a=T(e,m,s);a&&(t[n].key+=a.id,e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Open?t[n].open.push(a):e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Closed?t[n].closed.push(a):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Open?t[n].adjusted.push(a):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Closed&&t[n].closed.push(a))}}}function h(e){switch(e.type){case r.IntervalType.Exception:return I("interval-exception");case r.IntervalType.Interval:return I("interval-normal");default:return I("interval-unknown")}}function D(e){const o=e.reduce((t,s)=>(c.forEach(d=>{g(d.id,s.orderFormats)&&(t[d.id]||(t[d.id]={orderFormat:d,intervals:[]}),t[d.id].intervals.push(...s.intervals.sort((p,m)=>p.dayOfWeek-m.dayOfWeek)))}),t),{});return Object.values(o)}function M(e,o){const t=o.reduce((s,d)=>d<=e?s+1:s,0);return e-t}function H(e){const{mergedTables:o}=e.reduce((t,s,d)=>{const p=t.mergedTables.findIndex(m=>m!==s&&!m.orderFormats.some(n=>s.orderFormats.some(y=>y.id===n.id))&&m.openingHours.every(n=>s.openingHours.some(y=>y.key===n.key))&&s.openingHours.every(n=>m.openingHours.some(y=>y.key===n.key)));if(p>=0){if(t.skipOrderFormats.some(u=>s.orderFormats.every(a=>a.id===u.id)))return t;const n=t.mergedTables[p];t.mergedTables.splice(p,1,{...n,orderFormats:[...s.orderFormats,...n.orderFormats]});const y=n.orderFormats.filter(u=>!t.skipOrderFormats.some(a=>a.id===u.id));y.length>0&&t.skipOrderFormats.push(...y);const i=M(d,[...t.removedIndexes]);return t.mergedTables.splice(i,1),t.removedIndexes.push(d),t}return t},{mergedTables:[...e],removedIndexes:[],skipOrderFormats:[]});return o}function x(e){return e.map(o=>({...o,intervals:o.intervals.map(t=>({...t,id:h(t)}))}))}function E(e,o){const t=D(x(e.serviceDateTimes)),s=v(o),d=W(s),p=t.reduce((i,u)=>(i[u.orderFormat.id]||(i[u.orderFormat.id]={}),u.intervals.reduce((a,f)=>(S(f,d,a,e.timeZoneOffset),a),i[u.orderFormat.id]),i),{}),m={[r.OrderFormat.EatIn]:c[0],[r.OrderFormat.TakeAway]:c[1],[r.OrderFormat.TableOrder]:c[2],[r.OrderFormat.Delivery]:c[3]},n=Object.entries(p).map(([i,u])=>({orderFormats:[m[Number(i)]],openingHours:Object.entries(u).map(([a,f])=>({isoWeekday:Number(a),key:f.key,open:f.open.sort((l,O)=>l.start.localeCompare(O.start)),adjusted:f.adjusted.sort((l,O)=>l.start.localeCompare(O.start)),closed:f.closed.sort((l,O)=>l.start.localeCompare(O.start))}))}));return H(n).sort((i,u)=>i.orderFormats[0].id-u.orderFormats[0].id)}module.exports=E;
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { OrderFormat as
|
|
1
|
+
import S from "moment";
|
|
2
|
+
import { OrderFormat as l, DayOfWeek as y, IntervalType as c, IntervalState as g } from "@ancon/wildcat-types";
|
|
3
3
|
import h from "../shared/isWithinFlag.mjs";
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
{ id:
|
|
7
|
-
{ id:
|
|
8
|
-
{ id:
|
|
9
|
-
{ id:
|
|
4
|
+
import F from "../shared/generateId.mjs";
|
|
5
|
+
const I = [
|
|
6
|
+
{ id: l.EatIn, name: "eatIn" },
|
|
7
|
+
{ id: l.TakeAway, name: "takeaway" },
|
|
8
|
+
{ id: l.TableOrder, name: "tableOrder" },
|
|
9
|
+
{ id: l.Delivery, name: "delivery" }
|
|
10
10
|
];
|
|
11
|
-
function
|
|
12
|
-
const
|
|
13
|
-
for (let
|
|
14
|
-
|
|
11
|
+
function v(e) {
|
|
12
|
+
const o = S.utc(e).subtract(1, "day").startOf("day"), t = [];
|
|
13
|
+
for (let n = 0, s = o; n < 7; n += 1)
|
|
14
|
+
s = s.clone().add(1, "day").startOf("day"), t.push(s.clone());
|
|
15
15
|
return t;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return [...e].sort((
|
|
17
|
+
function T(e) {
|
|
18
|
+
return [...e].sort((o, t) => o.isoWeekday() - t.isoWeekday());
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function W(e) {
|
|
21
21
|
return e.split(":").map(Number);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
const [
|
|
23
|
+
function M(e, o, t) {
|
|
24
|
+
const [n, s] = W(e.start), [m, u] = W(
|
|
25
25
|
e.duration
|
|
26
|
-
), [r,
|
|
26
|
+
), [r, p] = W(t || "00:00:00");
|
|
27
27
|
if (e.type === c.Interval) {
|
|
28
|
-
let
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
28
|
+
let a = o.clone().add(n, "hour").add(s, "minute");
|
|
29
|
+
const d = a.clone().add(r, "hour").add(p, "minute").date() - o.date();
|
|
30
|
+
d !== 0 && (a = a.subtract(d, "day"));
|
|
31
|
+
const f = a.clone().add(m, "hour").add(u, "minute");
|
|
32
32
|
return {
|
|
33
33
|
id: e.id,
|
|
34
|
-
start:
|
|
35
|
-
end:
|
|
34
|
+
start: a.toISOString(),
|
|
35
|
+
end: f.toISOString()
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
if (e.type === c.Exception) {
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
const
|
|
39
|
+
const a = S(e.fromDate), i = S(e.toDate);
|
|
40
|
+
if (o.isBetween(a, i, void 0, "[]")) {
|
|
41
|
+
const d = o.clone().add(n, "hour").add(s, "minute"), f = d.clone().add(m, "hour").add(u, "minute");
|
|
42
42
|
return {
|
|
43
43
|
id: e.id,
|
|
44
|
-
start:
|
|
45
|
-
end:
|
|
44
|
+
start: d.toISOString(),
|
|
45
|
+
end: f.toISOString(),
|
|
46
46
|
reason: e.reason
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -50,8 +50,8 @@ function H(e, n, t) {
|
|
|
50
50
|
}
|
|
51
51
|
throw new Error("Invalid interval type");
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
53
|
+
function H(e, o, t, n) {
|
|
54
|
+
const s = {
|
|
55
55
|
[y.Monday]: 1,
|
|
56
56
|
[y.Tuesday]: 2,
|
|
57
57
|
[y.Wednesday]: 3,
|
|
@@ -61,123 +61,138 @@ function E(e, n, t, u) {
|
|
|
61
61
|
[y.Sunday]: 7,
|
|
62
62
|
[y.Everyday]: null
|
|
63
63
|
};
|
|
64
|
-
for (let
|
|
65
|
-
const
|
|
64
|
+
for (let m = 0; m < o.length; m += 1) {
|
|
65
|
+
const u = o[m], r = u.isoWeekday(), p = e.dayOfWeek, i = (s[p] ?? null) === r || p === y.Everyday;
|
|
66
66
|
if (t[r] || (t[r] = {
|
|
67
67
|
isoWeekday: r,
|
|
68
68
|
key: "",
|
|
69
69
|
open: [],
|
|
70
70
|
adjusted: [],
|
|
71
71
|
closed: []
|
|
72
|
-
}),
|
|
73
|
-
const
|
|
72
|
+
}), i) {
|
|
73
|
+
const d = M(
|
|
74
74
|
e,
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
u,
|
|
76
|
+
n
|
|
77
77
|
);
|
|
78
|
-
|
|
78
|
+
d && (t[r].key += d.id, e.type === c.Interval && e.state === g.Open ? t[r].open.push(d) : e.type === c.Interval && e.state === g.Closed ? t[r].closed.push(d) : e.type === c.Exception && e.state === g.Open ? t[r].adjusted.push(d) : e.type === c.Exception && e.state === g.Closed && t[r].closed.push(d));
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function x(e) {
|
|
83
83
|
switch (e.type) {
|
|
84
84
|
case c.Exception:
|
|
85
|
-
return
|
|
85
|
+
return F("interval-exception");
|
|
86
86
|
case c.Interval:
|
|
87
|
-
return
|
|
87
|
+
return F("interval-normal");
|
|
88
88
|
default:
|
|
89
|
-
return
|
|
89
|
+
return F("interval-unknown");
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
(t,
|
|
95
|
-
h(
|
|
96
|
-
orderFormat:
|
|
92
|
+
function E(e) {
|
|
93
|
+
const o = e.reduce(
|
|
94
|
+
(t, n) => (I.forEach((s) => {
|
|
95
|
+
h(s.id, n.orderFormats) && (t[s.id] || (t[s.id] = {
|
|
96
|
+
orderFormat: s,
|
|
97
97
|
intervals: []
|
|
98
|
-
}), t[
|
|
99
|
-
...
|
|
100
|
-
(
|
|
98
|
+
}), t[s.id].intervals.push(
|
|
99
|
+
...n.intervals.sort(
|
|
100
|
+
(m, u) => m.dayOfWeek - u.dayOfWeek
|
|
101
101
|
)
|
|
102
102
|
));
|
|
103
103
|
}), t),
|
|
104
104
|
{}
|
|
105
105
|
);
|
|
106
|
-
return Object.values(
|
|
106
|
+
return Object.values(o);
|
|
107
|
+
}
|
|
108
|
+
function D(e, o) {
|
|
109
|
+
const t = o.reduce((n, s) => s <= e ? n + 1 : n, 0);
|
|
110
|
+
return e - t;
|
|
107
111
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
(
|
|
111
|
-
const
|
|
112
|
-
(
|
|
113
|
-
(
|
|
114
|
-
(
|
|
112
|
+
function b(e) {
|
|
113
|
+
const { mergedTables: o } = e.reduce(
|
|
114
|
+
(t, n, s) => {
|
|
115
|
+
const m = t.mergedTables.findIndex(
|
|
116
|
+
(u) => u !== n && !u.orderFormats.some(
|
|
117
|
+
(r) => n.orderFormats.some(
|
|
118
|
+
(p) => p.id === r.id
|
|
115
119
|
)
|
|
116
|
-
) &&
|
|
117
|
-
(
|
|
118
|
-
) &&
|
|
119
|
-
(
|
|
120
|
+
) && u.openingHours.every(
|
|
121
|
+
(r) => n.openingHours.some((p) => p.key === r.key)
|
|
122
|
+
) && n.openingHours.every(
|
|
123
|
+
(r) => u.openingHours.some((p) => p.key === r.key)
|
|
120
124
|
)
|
|
121
125
|
);
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
if (m >= 0) {
|
|
127
|
+
if (t.skipOrderFormats.some(
|
|
128
|
+
(i) => n.orderFormats.every((d) => d.id === i.id)
|
|
129
|
+
))
|
|
130
|
+
return t;
|
|
131
|
+
const r = t.mergedTables[m];
|
|
132
|
+
t.mergedTables.splice(m, 1, {
|
|
133
|
+
...r,
|
|
134
|
+
orderFormats: [...n.orderFormats, ...r.orderFormats]
|
|
135
|
+
});
|
|
136
|
+
const p = r.orderFormats.filter(
|
|
137
|
+
(i) => !t.skipOrderFormats.some((d) => d.id === i.id)
|
|
138
|
+
);
|
|
139
|
+
p.length > 0 && t.skipOrderFormats.push(...p);
|
|
140
|
+
const a = D(s, [...t.removedIndexes]);
|
|
141
|
+
return t.mergedTables.splice(a, 1), t.removedIndexes.push(s), t;
|
|
128
142
|
}
|
|
129
|
-
return
|
|
143
|
+
return t;
|
|
130
144
|
},
|
|
131
|
-
[...e]
|
|
145
|
+
{ mergedTables: [...e], removedIndexes: [], skipOrderFormats: [] }
|
|
132
146
|
);
|
|
147
|
+
return o;
|
|
133
148
|
}
|
|
134
149
|
function j(e) {
|
|
135
|
-
return e.map((
|
|
136
|
-
...
|
|
137
|
-
intervals:
|
|
150
|
+
return e.map((o) => ({
|
|
151
|
+
...o,
|
|
152
|
+
intervals: o.intervals.map((t) => ({
|
|
138
153
|
...t,
|
|
139
|
-
id:
|
|
154
|
+
id: x(t)
|
|
140
155
|
}))
|
|
141
156
|
}));
|
|
142
157
|
}
|
|
143
|
-
function R(e,
|
|
144
|
-
const t =
|
|
158
|
+
function R(e, o) {
|
|
159
|
+
const t = E(
|
|
145
160
|
j(e.serviceDateTimes)
|
|
146
|
-
),
|
|
147
|
-
(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
161
|
+
), n = v(o), s = T(n), m = t.reduce(
|
|
162
|
+
(a, i) => (a[i.orderFormat.id] || (a[i.orderFormat.id] = {}), i.intervals.reduce((d, f) => (H(
|
|
163
|
+
f,
|
|
164
|
+
s,
|
|
165
|
+
d,
|
|
151
166
|
e.timeZoneOffset
|
|
152
|
-
),
|
|
167
|
+
), d), a[i.orderFormat.id]), a),
|
|
153
168
|
{}
|
|
154
|
-
),
|
|
155
|
-
[
|
|
156
|
-
[
|
|
157
|
-
[
|
|
158
|
-
[
|
|
169
|
+
), u = {
|
|
170
|
+
[l.EatIn]: I[0],
|
|
171
|
+
[l.TakeAway]: I[1],
|
|
172
|
+
[l.TableOrder]: I[2],
|
|
173
|
+
[l.Delivery]: I[3]
|
|
159
174
|
}, r = Object.entries(
|
|
160
|
-
|
|
161
|
-
).map(([
|
|
162
|
-
orderFormats: [
|
|
163
|
-
openingHours: Object.entries(
|
|
164
|
-
([
|
|
165
|
-
isoWeekday: Number(
|
|
166
|
-
key:
|
|
167
|
-
open:
|
|
168
|
-
(
|
|
175
|
+
m
|
|
176
|
+
).map(([a, i]) => ({
|
|
177
|
+
orderFormats: [u[Number(a)]],
|
|
178
|
+
openingHours: Object.entries(i).map(
|
|
179
|
+
([d, f]) => ({
|
|
180
|
+
isoWeekday: Number(d),
|
|
181
|
+
key: f.key,
|
|
182
|
+
open: f.open.sort(
|
|
183
|
+
(O, k) => O.start.localeCompare(k.start)
|
|
169
184
|
),
|
|
170
|
-
adjusted:
|
|
171
|
-
(
|
|
185
|
+
adjusted: f.adjusted.sort(
|
|
186
|
+
(O, k) => O.start.localeCompare(k.start)
|
|
172
187
|
),
|
|
173
|
-
closed:
|
|
174
|
-
(
|
|
188
|
+
closed: f.closed.sort(
|
|
189
|
+
(O, k) => O.start.localeCompare(k.start)
|
|
175
190
|
)
|
|
176
191
|
})
|
|
177
192
|
)
|
|
178
193
|
}));
|
|
179
|
-
return
|
|
180
|
-
(
|
|
194
|
+
return b(r).sort(
|
|
195
|
+
(a, i) => a.orderFormats[0].id - i.orderFormats[0].id
|
|
181
196
|
);
|
|
182
197
|
}
|
|
183
198
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancon/wildcat-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -201,6 +201,11 @@
|
|
|
201
201
|
"require": "./error/isNetworkError.js",
|
|
202
202
|
"types": "./error/isNetworkError.d.ts"
|
|
203
203
|
},
|
|
204
|
+
"./error/isNotFoundError": {
|
|
205
|
+
"import": "./error/isNotFoundError.mjs",
|
|
206
|
+
"require": "./error/isNotFoundError.js",
|
|
207
|
+
"types": "./error/isNotFoundError.d.ts"
|
|
208
|
+
},
|
|
204
209
|
"./error/serializeError": {
|
|
205
210
|
"import": "./error/serializeError.mjs",
|
|
206
211
|
"require": "./error/serializeError.js",
|