@ancon/wildcat-utils 1.20.19 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/generateBackoffWithEqualJitter.d.ts +5 -3
- package/checkout/getCheckoutOrderStatusTexts.js +1 -1
- package/checkout/getCheckoutOrderStatusTexts.mjs +14 -14
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/index.mjs +105 -96
- package/package.json +26 -1
- package/shared/index.d.ts +5 -3
- package/shared/index.js +1 -1
- package/shared/index.mjs +8 -6
- package/shared/wait.d.ts +2 -0
- package/shared/wait.js +1 -0
- package/shared/wait.mjs +8 -0
- package/signalr/SignalR.d.ts +59 -0
- package/signalr/SignalR.js +1 -0
- package/signalr/SignalR.mjs +155 -0
- package/signalr/createUseSignalRHook.d.ts +28 -0
- package/signalr/createUseSignalRHook.js +1 -0
- package/signalr/createUseSignalRHook.mjs +94 -0
- package/signalr/index.d.ts +5 -0
- package/signalr/index.js +1 -0
- package/signalr/index.mjs +13 -0
- package/signalr/types.d.ts +13 -0
- package/signalr/types.js +1 -0
- package/signalr/types.mjs +1 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generate backoff array with number of ms to sleep
|
|
2
|
+
* Generate backoff array with number of ms to sleep.
|
|
3
|
+
* Intervals are increased semi-exponentially from `baseSleep` but capped at `maxSleep`.
|
|
4
|
+
* It's not entirely exponential because there is added jitter.
|
|
3
5
|
* https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
|
4
6
|
*
|
|
5
7
|
* @param numIntervals Number of intervals to generate
|
|
6
|
-
* @param baseSleep Base ms jitter
|
|
7
|
-
* @param maxSleep Max ms jitter
|
|
8
|
+
* @param baseSleep Base ms (first interval +/- jitter)
|
|
9
|
+
* @param maxSleep Max ms (greatest allowed interval - jitter)
|
|
8
10
|
* @returns Array with milliseconds entries
|
|
9
11
|
*/
|
|
10
12
|
declare function generateBackoffWithEqualJitter(numIntervals?: number, baseSleep?: number, maxSleep?: number): number[];
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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 m(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 C(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<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[C(a)];const l=m(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;
|
|
@@ -45,12 +45,12 @@ function T(e, {
|
|
|
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
46
|
if (d || r || n && !o)
|
|
47
47
|
return !1;
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
const u = i === t.Captured, c = i === t.InProgress
|
|
51
|
-
return u || c
|
|
48
|
+
const p = i != null, y = l != null;
|
|
49
|
+
if (p) {
|
|
50
|
+
const u = i === t.Captured, c = i === t.InProgress;
|
|
51
|
+
return u || c;
|
|
52
52
|
}
|
|
53
|
-
if (
|
|
53
|
+
if (y) {
|
|
54
54
|
const u = l === a.Preparing, c = l === a.Ready;
|
|
55
55
|
return u || c;
|
|
56
56
|
}
|
|
@@ -83,13 +83,13 @@ function B(e, {
|
|
|
83
83
|
const n = C(i);
|
|
84
84
|
if (n)
|
|
85
85
|
return [n];
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
return O && !o ? ["yourOrderWillArriveAtYourTable"] :
|
|
89
|
-
if (
|
|
90
|
-
if (
|
|
86
|
+
const p = i === t.Captured, y = 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
|
+
if (p)
|
|
88
|
+
return O && !o ? ["yourOrderWillArriveAtYourTable"] : f ? d ? ["modifiedDeliveryStartTime"] : ["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"] : d ? ["modifiedPickUpTime"] : ["yourOrderHasBeenAcceptedPickupTime"];
|
|
89
|
+
if (y) {
|
|
90
|
+
if (f)
|
|
91
91
|
return d ? ["modifiedDeliveryStartTime"] : ["yourOrderHasBeenAcceptedEstimatedDeliveryStartTime"];
|
|
92
|
-
if (c ||
|
|
92
|
+
if (c || g) {
|
|
93
93
|
if (r.ready === r.all)
|
|
94
94
|
return ["yourOrderIsReadyToCollect"];
|
|
95
95
|
if (r.done === r.all)
|
|
@@ -98,10 +98,10 @@ function B(e, {
|
|
|
98
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"];
|
|
99
99
|
}
|
|
100
100
|
if (u)
|
|
101
|
-
return c ||
|
|
101
|
+
return c || g ? ["yourOrderHasBeenCompleted"] : f ? ["deliveryWasCompleted"] : ["yourOrderHasBeenCompleted"];
|
|
102
102
|
throw new Error("Could not resolve translation key in getTranslationKey()");
|
|
103
103
|
}
|
|
104
|
-
const
|
|
104
|
+
const h = {
|
|
105
105
|
yourOrderIsBeingProcessed: () => ({
|
|
106
106
|
title: "Your order is being processed"
|
|
107
107
|
}),
|
|
@@ -166,7 +166,7 @@ const v = {
|
|
|
166
166
|
message: `${e.count} more items are being prepared`
|
|
167
167
|
})
|
|
168
168
|
};
|
|
169
|
-
function w(e, i, l =
|
|
169
|
+
function w(e, i, l = h) {
|
|
170
170
|
const o = m(
|
|
171
171
|
(e == null ? void 0 : e.items) ?? []
|
|
172
172
|
), [d, r] = B(e, i, {
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./shared/enums.js"),r=require("./shared/isWithinFlag.js"),i=require("./shared/generateId.js"),n=require("./outlet/getListOutletOpeningHoursTable.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./shared/enums.js"),r=require("./shared/isWithinFlag.js"),i=require("./shared/generateId.js"),n=require("./shared/wait.js"),o=require("./outlet/getListOutletOpeningHoursTable.js"),u=require("./outlet/getOutletTagInformation.js"),s=require("./outlet/getOutletAvailabilityInfo.js"),a=require("./outlet/getOutletOfflineOrderFormats.js"),c=require("./outlet/getOutletAvailableOrderFormats.js"),l=require("./outlet/getOutletFormattedDistance.js"),g=require("./outlet/isOutletAcceptingPreOrders.js"),d=require("./outlet/getOutletDeliveryFee.js"),q=require("./outlet/getOutletTodayOpeningTimes.js"),O=require("./outlet/getOutletOrderFormats.js"),_=require("./outlet/serviceDateTimesFromOpeningHours.js"),m=require("./versioning/isVersionALessThanB.js"),k=require("./versioning/cleanVersionString.js"),h=require("./api/getUrlAndParams.js"),y=require("./api/getEndpointWithVersion.js"),p=require("./api/generateBackoffWithEqualJitter.js"),T=require("./string/slugify.js"),f=require("./string/truncate.js"),S=require("./color/lighten.js"),P=require("./color/brighten.js"),F=require("./color/darken.js"),v=require("./color/isDarkBackground.js"),I=require("./user/getFullName.js"),D=require("./user/getFullAddressString.js"),b=require("./logger/Logger.js"),A=require("./logger/types.js"),C=require("./logger/sanitizeAsStringDict.js"),V=require("./printing/getPrinterType.js"),L=require("./printing/isValidPrinter.js"),B=require("./printing/isValidNetworkPrinter.js"),W=require("./printing/isValidStarCloudPrinter.js"),M=require("./printing/isTerminalPrinter.js"),H=require("./number/randomIntFromInterval.js"),N=require("./tables/decodeTableQRPayload.js"),R=require("./checkout/getCheckoutItemModifications.js"),w=require("./checkout/getCheckoutProductName.js"),t=require("./checkout/getCheckoutOrderStatusTexts.js"),E=require("./checkout/getCheckoutItemsMappedByTicketItemStatus.js"),U=require("./checkout/isCheckoutOrderSummary.js"),x=require("./currency/getFormattedCurrency.js"),z=require("./inventory/isDetailedProductOutOfStock.js"),J=require("./inventory/isDetailedProductVariantOutOfStocks.js"),K=require("./inventory/isMenuTreeProductOutOfStock.js"),Q=require("./signalr/createUseSignalRHook.js"),j=require("./signalr/SignalR.js");require("moment");require("@ancon/wildcat-types");require("./outlet/types.js");require("./outlet/constants.js");require("./outlet/getOutletCurrentActiveOperatingHour.js");require("./outlet/getMomentFromDateAndTimeString.js");require("./outlet/searchNextOpeningMoment.js");require("lodash");require("compare-versions");require("tinycolor2");require("@ancon/wildcat-printing");require("./currency/getFormattedCurrencyPostfix.js");require("react");require("react-redux");require("@microsoft/signalr");exports.DayOfWeek=e.DayOfWeek;exports.IntervalState=e.IntervalState;exports.IntervalType=e.IntervalType;exports.OrderFormat=e.OrderFormat;exports.isWithinFlag=r;exports.generateId=i;exports.wait=n;exports.getListOutletOpeningHoursTable=o;exports.getOutletTagInformation=u.default;exports.getOutletAvailabilityInfo=s.default;exports.getOutletOfflineOrderFormats=a;exports.getOutletAvailableOrderFormats=c;exports.getOutletFormattedDistance=l;exports.isOutletAcceptingPreOrders=g;exports.getOutletDeliveryFee=d;exports.getOutletTodayOpeningTimes=q;exports.getOutletOrderFormats=O;exports.serviceDateTimesFromOpeningHours=_;exports.isVersionALessThanB=m;exports.cleanVersionString=k;exports.getUrlAndParams=h;exports.getEndpointWithVersion=y;exports.generateBackoffWithEqualJitter=p;exports.slugify=T;exports.truncate=f;exports.lighten=S;exports.brighten=P;exports.darken=F;exports.isDarkBackground=v;exports.getFullName=I;exports.getFullAddressString=D;exports.Logger=b;exports.LogLevel=A.LogLevel;exports.sanitizeAsStringDict=C;exports.getPrinterType=V;exports.isValidPrinter=L;exports.isValidNetworkPrinter=B;exports.isValidStarCloudPrinter=W;exports.isTerminalPrinter=M;exports.randomIntFromInterval=H;exports.decodeTableQRPayload=N;exports.getCheckoutGroupedModifications=R;exports.getCheckoutProductName=w;exports.TranslationKey=t.TranslationKey;exports.getCheckoutOrderStatusTexts=t.default;exports.getCheckoutItemsMappedByTicketItemStatus=E;exports.isCheckoutOrderSummary=U;exports.getFormattedCurrency=x;exports.isDetailedProductOutOfStock=z;exports.isDetailedProductVariantOutOfStocks=J;exports.isMenuTreeProductOutOfStock=K;exports.createUseSignalRHook=Q;exports.SignalR=j;
|
package/index.mjs
CHANGED
|
@@ -1,49 +1,52 @@
|
|
|
1
|
-
import { DayOfWeek as
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
7
|
-
import { default as
|
|
8
|
-
import { default as
|
|
9
|
-
import { default as
|
|
10
|
-
import { default as
|
|
11
|
-
import { default as E } from "./outlet/
|
|
12
|
-
import { default as q } from "./outlet/
|
|
13
|
-
import { default as
|
|
14
|
-
import { default as
|
|
15
|
-
import { default as
|
|
16
|
-
import { default as
|
|
17
|
-
import { default as
|
|
18
|
-
import { default as
|
|
19
|
-
import { default as
|
|
20
|
-
import { default as
|
|
21
|
-
import { default as
|
|
22
|
-
import { default as
|
|
23
|
-
import { default as
|
|
24
|
-
import { default as
|
|
25
|
-
import { default as
|
|
26
|
-
import { default as
|
|
27
|
-
import { default as
|
|
28
|
-
import { default as
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { default as
|
|
32
|
-
import { default as
|
|
33
|
-
import { default as
|
|
34
|
-
import { default as
|
|
35
|
-
import { default as
|
|
36
|
-
import { default as
|
|
37
|
-
import { default as
|
|
38
|
-
import { default as Et } from "./
|
|
39
|
-
import { default as qt } from "./checkout/
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import { default as
|
|
43
|
-
import { default as
|
|
44
|
-
import { default as
|
|
45
|
-
import { default as
|
|
46
|
-
import { default as
|
|
1
|
+
import { DayOfWeek as c, IntervalState as k, IntervalType as T, OrderFormat as S } from "./shared/enums.mjs";
|
|
2
|
+
import { default as F } from "./shared/isWithinFlag.mjs";
|
|
3
|
+
import { default as h } from "./shared/generateId.mjs";
|
|
4
|
+
import { default as v } from "./shared/wait.mjs";
|
|
5
|
+
import { default as A } from "./outlet/getListOutletOpeningHoursTable.mjs";
|
|
6
|
+
import { default as V } from "./outlet/getOutletTagInformation.mjs";
|
|
7
|
+
import { default as L } from "./outlet/getOutletAvailabilityInfo.mjs";
|
|
8
|
+
import { default as W } from "./outlet/getOutletOfflineOrderFormats.mjs";
|
|
9
|
+
import { default as M } from "./outlet/getOutletAvailableOrderFormats.mjs";
|
|
10
|
+
import { default as R } from "./outlet/getOutletFormattedDistance.mjs";
|
|
11
|
+
import { default as E } from "./outlet/isOutletAcceptingPreOrders.mjs";
|
|
12
|
+
import { default as q } from "./outlet/getOutletDeliveryFee.mjs";
|
|
13
|
+
import { default as G } from "./outlet/getOutletTodayOpeningTimes.mjs";
|
|
14
|
+
import { default as K } from "./outlet/getOutletOrderFormats.mjs";
|
|
15
|
+
import { default as j } from "./outlet/serviceDateTimesFromOpeningHours.mjs";
|
|
16
|
+
import { default as Y } from "./versioning/isVersionALessThanB.mjs";
|
|
17
|
+
import { default as _ } from "./versioning/cleanVersionString.mjs";
|
|
18
|
+
import { default as tt } from "./api/getUrlAndParams.mjs";
|
|
19
|
+
import { default as rt } from "./api/getEndpointWithVersion.mjs";
|
|
20
|
+
import { default as at } from "./api/generateBackoffWithEqualJitter.mjs";
|
|
21
|
+
import { default as lt } from "./string/slugify.mjs";
|
|
22
|
+
import { default as mt } from "./string/truncate.mjs";
|
|
23
|
+
import { default as dt } from "./color/lighten.mjs";
|
|
24
|
+
import { default as pt } from "./color/brighten.mjs";
|
|
25
|
+
import { default as xt } from "./color/darken.mjs";
|
|
26
|
+
import { default as Ot } from "./color/isDarkBackground.mjs";
|
|
27
|
+
import { default as kt } from "./user/getFullName.mjs";
|
|
28
|
+
import { default as St } from "./user/getFullAddressString.mjs";
|
|
29
|
+
import { default as Ft } from "./logger/Logger.mjs";
|
|
30
|
+
import { LogLevel as ht } from "./logger/types.mjs";
|
|
31
|
+
import { default as vt } from "./logger/sanitizeAsStringDict.mjs";
|
|
32
|
+
import { default as At } from "./printing/getPrinterType.mjs";
|
|
33
|
+
import { default as Vt } from "./printing/isValidPrinter.mjs";
|
|
34
|
+
import { default as Lt } from "./printing/isValidNetworkPrinter.mjs";
|
|
35
|
+
import { default as Wt } from "./printing/isValidStarCloudPrinter.mjs";
|
|
36
|
+
import { default as Mt } from "./printing/isTerminalPrinter.mjs";
|
|
37
|
+
import { default as Rt } from "./number/randomIntFromInterval.mjs";
|
|
38
|
+
import { default as Et } from "./tables/decodeTableQRPayload.mjs";
|
|
39
|
+
import { default as qt } from "./checkout/getCheckoutItemModifications.mjs";
|
|
40
|
+
import { default as Gt } from "./checkout/getCheckoutProductName.mjs";
|
|
41
|
+
import { TranslationKey as Kt, default as Qt } from "./checkout/getCheckoutOrderStatusTexts.mjs";
|
|
42
|
+
import { default as Xt } from "./checkout/getCheckoutItemsMappedByTicketItemStatus.mjs";
|
|
43
|
+
import { default as Zt } from "./checkout/isCheckoutOrderSummary.mjs";
|
|
44
|
+
import { default as $t } from "./currency/getFormattedCurrency.mjs";
|
|
45
|
+
import { default as ee } from "./inventory/isDetailedProductOutOfStock.mjs";
|
|
46
|
+
import { default as oe } from "./inventory/isDetailedProductVariantOutOfStocks.mjs";
|
|
47
|
+
import { default as fe } from "./inventory/isMenuTreeProductOutOfStock.mjs";
|
|
48
|
+
import { default as se } from "./signalr/createUseSignalRHook.mjs";
|
|
49
|
+
import { default as ue } from "./signalr/SignalR.mjs";
|
|
47
50
|
import "moment";
|
|
48
51
|
import "@ancon/wildcat-types";
|
|
49
52
|
import "./outlet/types.mjs";
|
|
@@ -56,55 +59,61 @@ import "compare-versions";
|
|
|
56
59
|
import "tinycolor2";
|
|
57
60
|
import "@ancon/wildcat-printing";
|
|
58
61
|
import "./currency/getFormattedCurrencyPostfix.mjs";
|
|
62
|
+
import "react";
|
|
63
|
+
import "react-redux";
|
|
64
|
+
import "@microsoft/signalr";
|
|
59
65
|
export {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
66
|
+
c as DayOfWeek,
|
|
67
|
+
k as IntervalState,
|
|
68
|
+
T as IntervalType,
|
|
69
|
+
ht as LogLevel,
|
|
70
|
+
Ft as Logger,
|
|
71
|
+
S as OrderFormat,
|
|
72
|
+
ue as SignalR,
|
|
73
|
+
Kt as TranslationKey,
|
|
74
|
+
pt as brighten,
|
|
75
|
+
_ as cleanVersionString,
|
|
76
|
+
se as createUseSignalRHook,
|
|
77
|
+
xt as darken,
|
|
78
|
+
Et as decodeTableQRPayload,
|
|
79
|
+
at as generateBackoffWithEqualJitter,
|
|
80
|
+
h as generateId,
|
|
81
|
+
qt as getCheckoutGroupedModifications,
|
|
82
|
+
Xt as getCheckoutItemsMappedByTicketItemStatus,
|
|
83
|
+
Qt as getCheckoutOrderStatusTexts,
|
|
84
|
+
Gt as getCheckoutProductName,
|
|
85
|
+
rt as getEndpointWithVersion,
|
|
86
|
+
$t as getFormattedCurrency,
|
|
87
|
+
St as getFullAddressString,
|
|
88
|
+
kt as getFullName,
|
|
89
|
+
A as getListOutletOpeningHoursTable,
|
|
90
|
+
L as getOutletAvailabilityInfo,
|
|
91
|
+
M as getOutletAvailableOrderFormats,
|
|
92
|
+
q as getOutletDeliveryFee,
|
|
93
|
+
R as getOutletFormattedDistance,
|
|
94
|
+
W as getOutletOfflineOrderFormats,
|
|
95
|
+
K as getOutletOrderFormats,
|
|
96
|
+
V as getOutletTagInformation,
|
|
97
|
+
G as getOutletTodayOpeningTimes,
|
|
98
|
+
At as getPrinterType,
|
|
99
|
+
tt as getUrlAndParams,
|
|
100
|
+
Zt as isCheckoutOrderSummary,
|
|
101
|
+
Ot as isDarkBackground,
|
|
102
|
+
ee as isDetailedProductOutOfStock,
|
|
103
|
+
oe as isDetailedProductVariantOutOfStocks,
|
|
104
|
+
fe as isMenuTreeProductOutOfStock,
|
|
105
|
+
E as isOutletAcceptingPreOrders,
|
|
106
|
+
Mt as isTerminalPrinter,
|
|
107
|
+
Lt as isValidNetworkPrinter,
|
|
108
|
+
Vt as isValidPrinter,
|
|
109
|
+
Wt as isValidStarCloudPrinter,
|
|
110
|
+
Y as isVersionALessThanB,
|
|
111
|
+
F as isWithinFlag,
|
|
112
|
+
dt as lighten,
|
|
113
|
+
Rt as randomIntFromInterval,
|
|
114
|
+
vt as sanitizeAsStringDict,
|
|
115
|
+
j as serviceDateTimesFromOpeningHours,
|
|
116
|
+
lt as slugify,
|
|
117
|
+
mt as truncate,
|
|
118
|
+
v as wait
|
|
110
119
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancon/wildcat-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -286,6 +286,31 @@
|
|
|
286
286
|
"require": "./shared/isWithinFlag.js",
|
|
287
287
|
"types": "./shared/isWithinFlag.d.ts"
|
|
288
288
|
},
|
|
289
|
+
"./shared/wait": {
|
|
290
|
+
"import": "./shared/wait.mjs",
|
|
291
|
+
"require": "./shared/wait.js",
|
|
292
|
+
"types": "./shared/wait.d.ts"
|
|
293
|
+
},
|
|
294
|
+
"./signalr/SignalR": {
|
|
295
|
+
"import": "./signalr/SignalR.mjs",
|
|
296
|
+
"require": "./signalr/SignalR.js",
|
|
297
|
+
"types": "./signalr/SignalR.d.ts"
|
|
298
|
+
},
|
|
299
|
+
"./signalr/createUseSignalRHook": {
|
|
300
|
+
"import": "./signalr/createUseSignalRHook.mjs",
|
|
301
|
+
"require": "./signalr/createUseSignalRHook.js",
|
|
302
|
+
"types": "./signalr/createUseSignalRHook.d.ts"
|
|
303
|
+
},
|
|
304
|
+
"./signalr": {
|
|
305
|
+
"import": "./signalr/index.mjs",
|
|
306
|
+
"require": "./signalr/index.js",
|
|
307
|
+
"types": "./signalr/index.d.ts"
|
|
308
|
+
},
|
|
309
|
+
"./signalr/types": {
|
|
310
|
+
"import": "./signalr/types.mjs",
|
|
311
|
+
"require": "./signalr/types.js",
|
|
312
|
+
"types": "./signalr/types.d.ts"
|
|
313
|
+
},
|
|
289
314
|
"./string": {
|
|
290
315
|
"import": "./string/index.mjs",
|
|
291
316
|
"require": "./string/index.js",
|
package/shared/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IntervalState, DayOfWeek, IntervalType, OrderFormat } from './enums';
|
|
2
|
+
import isWithinFlag from './isWithinFlag';
|
|
3
|
+
import generateId from './generateId';
|
|
4
|
+
import wait from './wait';
|
|
5
|
+
export { IntervalState, DayOfWeek, IntervalType, OrderFormat, isWithinFlag, generateId, wait, };
|
package/shared/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./enums.js"),r=require("./isWithinFlag.js"),t=require("./generateId.js");exports.DayOfWeek=e.DayOfWeek;exports.IntervalState=e.IntervalState;exports.IntervalType=e.IntervalType;exports.OrderFormat=e.OrderFormat;exports.isWithinFlag=r;exports.generateId=t;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./enums.js"),r=require("./isWithinFlag.js"),t=require("./generateId.js"),a=require("./wait.js");exports.DayOfWeek=e.DayOfWeek;exports.IntervalState=e.IntervalState;exports.IntervalType=e.IntervalType;exports.OrderFormat=e.OrderFormat;exports.isWithinFlag=r;exports.generateId=t;exports.wait=a;
|
package/shared/index.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { DayOfWeek as
|
|
1
|
+
import { DayOfWeek as a, IntervalState as r, IntervalType as o, OrderFormat as f } from "./enums.mjs";
|
|
2
2
|
import { default as d } from "./isWithinFlag.mjs";
|
|
3
|
-
import { default as
|
|
3
|
+
import { default as p } from "./generateId.mjs";
|
|
4
|
+
import { default as n } from "./wait.mjs";
|
|
4
5
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
a as DayOfWeek,
|
|
7
|
+
r as IntervalState,
|
|
7
8
|
o as IntervalType,
|
|
8
9
|
f as OrderFormat,
|
|
9
|
-
|
|
10
|
-
d as isWithinFlag
|
|
10
|
+
p as generateId,
|
|
11
|
+
d as isWithinFlag,
|
|
12
|
+
n as wait
|
|
11
13
|
};
|
package/shared/wait.d.ts
ADDED
package/shared/wait.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function i(t){return new Promise(e=>{setTimeout(e,t)})}module.exports=i;
|
package/shared/wait.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SignalRSignalName } from '@ancon/wildcat-types';
|
|
2
|
+
import { SignalRConfig, SignalREventListener } from './types';
|
|
3
|
+
declare type InternalEvent = 'connected' | 'disconnected' | 'reconnected';
|
|
4
|
+
declare type InternalEventListener = (...payload: any[]) => any;
|
|
5
|
+
declare class SignalR {
|
|
6
|
+
private internalEvents;
|
|
7
|
+
private signalREvents;
|
|
8
|
+
private hubConnection;
|
|
9
|
+
private clientId;
|
|
10
|
+
private logger;
|
|
11
|
+
private backoff;
|
|
12
|
+
private reconnectAttempt;
|
|
13
|
+
groups: string[];
|
|
14
|
+
constructor(options: SignalRConfig);
|
|
15
|
+
info: (message: string, data?: any) => void;
|
|
16
|
+
private generateBackoff;
|
|
17
|
+
private reconnect;
|
|
18
|
+
private buildInitialListeners;
|
|
19
|
+
/**
|
|
20
|
+
* Emit event
|
|
21
|
+
* @param event Event to emit
|
|
22
|
+
* @param args Arguments to send to the listeners
|
|
23
|
+
*/
|
|
24
|
+
private emitEvent;
|
|
25
|
+
private skipSignal;
|
|
26
|
+
private enhanceListener;
|
|
27
|
+
setClientId: (clientId: string | undefined) => void;
|
|
28
|
+
connect: (throwError?: boolean) => Promise<void>;
|
|
29
|
+
disconnect: () => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Add internal event listener
|
|
32
|
+
* @param event Event to listen on
|
|
33
|
+
* @param listener Event listener function
|
|
34
|
+
*/
|
|
35
|
+
addEventListener: (event: InternalEvent, listener: InternalEventListener) => () => void;
|
|
36
|
+
/**
|
|
37
|
+
* Remove internal event listener
|
|
38
|
+
* @param event Event to stop listening to
|
|
39
|
+
* @param listener Event listener function
|
|
40
|
+
*/
|
|
41
|
+
removeEventListener: (event: InternalEvent, listener: InternalEventListener) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Add signal listener
|
|
44
|
+
* @param signal Signal name
|
|
45
|
+
* @param listener Signal listener function
|
|
46
|
+
*/
|
|
47
|
+
addSignalListener: (signal: SignalRSignalName, listener: SignalREventListener, shouldSkipOwnClient?: boolean) => () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Remove signal listener
|
|
50
|
+
* @param signal Signal name
|
|
51
|
+
* @param listener Signal listener function
|
|
52
|
+
*/
|
|
53
|
+
removeSignalListener: (signal: SignalRSignalName, listener: SignalREventListener) => void;
|
|
54
|
+
joinGroup: (group: string) => Promise<void>;
|
|
55
|
+
leaveGroup: (group: string) => Promise<void>;
|
|
56
|
+
leaveAllGroups: () => Promise<void>;
|
|
57
|
+
getHubConnectionId: () => string | null;
|
|
58
|
+
}
|
|
59
|
+
export default SignalR;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var d=(r,e,t)=>e in r?l(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(d(r,typeof e!="symbol"?e+"":e,t),t);const h=require("@microsoft/signalr"),a=require("@ancon/wildcat-types"),f=require("../shared/wait.js"),u=require("../api/generateBackoffWithEqualJitter.js");require("../number/randomIntFromInterval.js");class g{constructor(e){n(this,"internalEvents");n(this,"signalREvents");n(this,"hubConnection");n(this,"clientId");n(this,"logger");n(this,"backoff",[]);n(this,"reconnectAttempt",0);n(this,"groups");n(this,"info",(e,t)=>{var i;(i=this.logger)==null||i.info(e,t)});n(this,"generateBackoff",()=>{this.backoff=u(50,500,5e3),this.info("Generated new backoff")});n(this,"reconnect",async()=>{try{this.info("Attempting to reconnect...",{attempt:this.reconnectAttempt+1}),await this.connect(!0),this.info("Reconnected"),this.reconnectAttempt=0}catch{if(this.backoff[this.reconnectAttempt]!=null){const t=this.backoff[this.reconnectAttempt];if(t!=null)await f(t);else throw new Error("Could not resolve ms from backoff")}else{this.reconnectAttempt>0&&this.info("Ran out of backoff intervals, restarting backoff..."),this.reconnectAttempt=0,this.generateBackoff();const t=this.backoff[this.reconnectAttempt];if(t!=null)await f(t);else throw new Error("Could not resolve ms from backoff")}this.reconnectAttempt+=1,await this.reconnect()}});n(this,"buildInitialListeners",()=>{this.hubConnection.onclose(()=>{this.groups=[],this.info("Hub connection closed"),this.emitEvent("disconnected"),this.reconnect()}),this.hubConnection.onreconnected(()=>this.emitEvent("reconnected"))});n(this,"emitEvent",(e,...t)=>{if(this.internalEvents.has(e)){this.info(`Emitting event "${e}"`);const i=this.internalEvents.get(e);i&&i.forEach(s=>s(...t))}else this.info(`Failed to emit event "${e}". There were no listeners.`)});n(this,"skipSignal",(e,t)=>{this.info(`Skipped signal "${e}"`,t)});n(this,"enhanceListener",(e,t,i)=>s=>{const o=JSON.parse(s),c=i&&o.clientId&&o.clientId===this.clientId;return c||this.info(`Received signal "${e}"`,s),c?this.skipSignal(e,s):t(o)});n(this,"setClientId",e=>{this.clientId=e});n(this,"connect",async(e=!1)=>{try{this.info("Connecting..."),await this.hubConnection.start(),this.info("Connected"),this.emitEvent("connected")}catch(t){if(this.info("Failed to connect"),e)throw t}});n(this,"disconnect",async()=>{try{this.info("Disconnecting..."),await this.hubConnection.stop(),this.info("Disconnected"),this.emitEvent("disconnected")}catch{this.info("Failed to disconnect")}});n(this,"addEventListener",(e,t)=>{this.internalEvents.has(e)||this.internalEvents.set(e,[]);const i=this.internalEvents.get(e);return i&&i.push(t),()=>this.removeEventListener(e,t)});n(this,"removeEventListener",(e,t)=>{var i;if(this.internalEvents.has(e)){const s=this.internalEvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,t))??-1;o>=0?(s.splice(o,1),this.info(`Removed event listener for event "${e}"`)):this.info(`Failed to remove event listener for event "${e}". Specified listener was not found.`)}else this.info(`Failed to remove event listener for event "${e}". Event doesn't have any listeners.`)});n(this,"addSignalListener",(e,t,i=!0)=>{this.signalREvents.has(e)||this.signalREvents.set(e,[]);const s=this.signalREvents.get(e),o=this.enhanceListener(e,t,i);return s&&s.push(o),this.hubConnection.on(e,o),this.info(`Added signal listener for signal "${e}"`),()=>this.removeSignalListener(e,o)});n(this,"removeSignalListener",(e,t)=>{var i;if(this.signalREvents.has(e)){const s=this.signalREvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,t))??-1;o>=0?(this.hubConnection.off(e,t),s.splice(o,1),this.info(`Removed signal listener for signal "${e}"`)):this.info(`Failed to remove signal listener for signal "${e}". Specified listener was not found.`)}else this.info(`Failed to remove signal listener for signal "${e}". Signal doesn't have any listeners.`)});n(this,"joinGroup",async e=>{this.info(`Joining group "${e}"...`);const t=this.groups.push(e)-1;try{await this.hubConnection.invoke(a.SignalRMethodName.JoinGroup,e),this.info(`Joined group "${e}"`)}catch(i){this.info(`Failed to join group "${e}"`,i),t>=0&&this.groups.splice(t,1)}});n(this,"leaveGroup",async e=>{this.info(`Leaving group "${e}"...`);const t=this.groups.indexOf(e);t>=0&&this.groups.splice(t,1);try{await this.hubConnection.invoke(a.SignalRMethodName.LeaveGroup,e),this.info(`Left group "${e}"`)}catch(i){this.groups.indexOf(e)<0&&this.groups.push(e),this.info(`Failed to leave group "${e}"`,i)}});n(this,"leaveAllGroups",async()=>{this.info(`Leaving all (${this.groups.length}) groups...`);const e=[...this.groups].map(t=>this.leaveGroup(t));await Promise.all(e),this.info("Left all groups")});n(this,"getHubConnectionId",()=>this.hubConnection.connectionId);this.internalEvents=new Map,this.signalREvents=new Map,this.groups=[],e.enableLogging&&(this.logger=e.logger),this.hubConnection=new h.HubConnectionBuilder().withUrl(`${e.signalRApiUrl}/${e.hub}`).configureLogging(h.LogLevel.None).build(),this.buildInitialListeners()}}module.exports=g;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var f = Object.defineProperty;
|
|
2
|
+
var l = (r, t, e) => t in r ? f(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var n = (r, t, e) => (l(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
import { HubConnectionBuilder as d, LogLevel as g } from "@microsoft/signalr";
|
|
5
|
+
import { SignalRMethodName as h } from "@ancon/wildcat-types";
|
|
6
|
+
import a from "../shared/wait.mjs";
|
|
7
|
+
import u from "../api/generateBackoffWithEqualJitter.mjs";
|
|
8
|
+
import "../number/randomIntFromInterval.mjs";
|
|
9
|
+
class L {
|
|
10
|
+
constructor(t) {
|
|
11
|
+
n(this, "internalEvents");
|
|
12
|
+
n(this, "signalREvents");
|
|
13
|
+
n(this, "hubConnection");
|
|
14
|
+
n(this, "clientId");
|
|
15
|
+
n(this, "logger");
|
|
16
|
+
n(this, "backoff", []);
|
|
17
|
+
n(this, "reconnectAttempt", 0);
|
|
18
|
+
n(this, "groups");
|
|
19
|
+
n(this, "info", (t, e) => {
|
|
20
|
+
var i;
|
|
21
|
+
(i = this.logger) == null || i.info(t, e);
|
|
22
|
+
});
|
|
23
|
+
n(this, "generateBackoff", () => {
|
|
24
|
+
this.backoff = u(50, 500, 5e3), this.info("Generated new backoff");
|
|
25
|
+
});
|
|
26
|
+
n(this, "reconnect", async () => {
|
|
27
|
+
try {
|
|
28
|
+
this.info("Attempting to reconnect...", {
|
|
29
|
+
attempt: this.reconnectAttempt + 1
|
|
30
|
+
}), await this.connect(!0), this.info("Reconnected"), this.reconnectAttempt = 0;
|
|
31
|
+
} catch {
|
|
32
|
+
if (this.backoff[this.reconnectAttempt] != null) {
|
|
33
|
+
const e = this.backoff[this.reconnectAttempt];
|
|
34
|
+
if (e != null)
|
|
35
|
+
await a(e);
|
|
36
|
+
else
|
|
37
|
+
throw new Error("Could not resolve ms from backoff");
|
|
38
|
+
} else {
|
|
39
|
+
this.reconnectAttempt > 0 && this.info("Ran out of backoff intervals, restarting backoff..."), this.reconnectAttempt = 0, this.generateBackoff();
|
|
40
|
+
const e = this.backoff[this.reconnectAttempt];
|
|
41
|
+
if (e != null)
|
|
42
|
+
await a(e);
|
|
43
|
+
else
|
|
44
|
+
throw new Error("Could not resolve ms from backoff");
|
|
45
|
+
}
|
|
46
|
+
this.reconnectAttempt += 1, await this.reconnect();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
n(this, "buildInitialListeners", () => {
|
|
50
|
+
this.hubConnection.onclose(() => {
|
|
51
|
+
this.groups = [], this.info("Hub connection closed"), this.emitEvent("disconnected"), this.reconnect();
|
|
52
|
+
}), this.hubConnection.onreconnected(() => this.emitEvent("reconnected"));
|
|
53
|
+
});
|
|
54
|
+
n(this, "emitEvent", (t, ...e) => {
|
|
55
|
+
if (this.internalEvents.has(t)) {
|
|
56
|
+
this.info(`Emitting event "${t}"`);
|
|
57
|
+
const i = this.internalEvents.get(t);
|
|
58
|
+
i && i.forEach((s) => s(...e));
|
|
59
|
+
} else
|
|
60
|
+
this.info(`Failed to emit event "${t}". There were no listeners.`);
|
|
61
|
+
});
|
|
62
|
+
n(this, "skipSignal", (t, e) => {
|
|
63
|
+
this.info(`Skipped signal "${t}"`, e);
|
|
64
|
+
});
|
|
65
|
+
n(this, "enhanceListener", (t, e, i) => (s) => {
|
|
66
|
+
const o = JSON.parse(s), c = i && o.clientId && o.clientId === this.clientId;
|
|
67
|
+
return c || this.info(`Received signal "${t}"`, s), c ? this.skipSignal(t, s) : e(o);
|
|
68
|
+
});
|
|
69
|
+
n(this, "setClientId", (t) => {
|
|
70
|
+
this.clientId = t;
|
|
71
|
+
});
|
|
72
|
+
n(this, "connect", async (t = !1) => {
|
|
73
|
+
try {
|
|
74
|
+
this.info("Connecting..."), await this.hubConnection.start(), this.info("Connected"), this.emitEvent("connected");
|
|
75
|
+
} catch (e) {
|
|
76
|
+
if (this.info("Failed to connect"), t)
|
|
77
|
+
throw e;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
n(this, "disconnect", async () => {
|
|
81
|
+
try {
|
|
82
|
+
this.info("Disconnecting..."), await this.hubConnection.stop(), this.info("Disconnected"), this.emitEvent("disconnected");
|
|
83
|
+
} catch {
|
|
84
|
+
this.info("Failed to disconnect");
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
n(this, "addEventListener", (t, e) => {
|
|
88
|
+
this.internalEvents.has(t) || this.internalEvents.set(t, []);
|
|
89
|
+
const i = this.internalEvents.get(t);
|
|
90
|
+
return i && i.push(e), () => this.removeEventListener(t, e);
|
|
91
|
+
});
|
|
92
|
+
n(this, "removeEventListener", (t, e) => {
|
|
93
|
+
var i;
|
|
94
|
+
if (this.internalEvents.has(t)) {
|
|
95
|
+
const s = this.internalEvents.get(t), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s, e)) ?? -1;
|
|
96
|
+
o >= 0 ? (s.splice(o, 1), this.info(`Removed event listener for event "${t}"`)) : this.info(
|
|
97
|
+
`Failed to remove event listener for event "${t}". Specified listener was not found.`
|
|
98
|
+
);
|
|
99
|
+
} else
|
|
100
|
+
this.info(
|
|
101
|
+
`Failed to remove event listener for event "${t}". Event doesn't have any listeners.`
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
n(this, "addSignalListener", (t, e, i = !0) => {
|
|
105
|
+
this.signalREvents.has(t) || this.signalREvents.set(t, []);
|
|
106
|
+
const s = this.signalREvents.get(t), o = this.enhanceListener(
|
|
107
|
+
t,
|
|
108
|
+
e,
|
|
109
|
+
i
|
|
110
|
+
);
|
|
111
|
+
return s && s.push(o), this.hubConnection.on(t, o), this.info(`Added signal listener for signal "${t}"`), () => this.removeSignalListener(t, o);
|
|
112
|
+
});
|
|
113
|
+
n(this, "removeSignalListener", (t, e) => {
|
|
114
|
+
var i;
|
|
115
|
+
if (this.signalREvents.has(t)) {
|
|
116
|
+
const s = this.signalREvents.get(t), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s, e)) ?? -1;
|
|
117
|
+
o >= 0 ? (this.hubConnection.off(t, e), s.splice(o, 1), this.info(`Removed signal listener for signal "${t}"`)) : this.info(
|
|
118
|
+
`Failed to remove signal listener for signal "${t}". Specified listener was not found.`
|
|
119
|
+
);
|
|
120
|
+
} else
|
|
121
|
+
this.info(
|
|
122
|
+
`Failed to remove signal listener for signal "${t}". Signal doesn't have any listeners.`
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
n(this, "joinGroup", async (t) => {
|
|
126
|
+
this.info(`Joining group "${t}"...`);
|
|
127
|
+
const e = this.groups.push(t) - 1;
|
|
128
|
+
try {
|
|
129
|
+
await this.hubConnection.invoke(h.JoinGroup, t), this.info(`Joined group "${t}"`);
|
|
130
|
+
} catch (i) {
|
|
131
|
+
this.info(`Failed to join group "${t}"`, i), e >= 0 && this.groups.splice(e, 1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
n(this, "leaveGroup", async (t) => {
|
|
135
|
+
this.info(`Leaving group "${t}"...`);
|
|
136
|
+
const e = this.groups.indexOf(t);
|
|
137
|
+
e >= 0 && this.groups.splice(e, 1);
|
|
138
|
+
try {
|
|
139
|
+
await this.hubConnection.invoke(h.LeaveGroup, t), this.info(`Left group "${t}"`);
|
|
140
|
+
} catch (i) {
|
|
141
|
+
this.groups.indexOf(t) < 0 && this.groups.push(t), this.info(`Failed to leave group "${t}"`, i);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
n(this, "leaveAllGroups", async () => {
|
|
145
|
+
this.info(`Leaving all (${this.groups.length}) groups...`);
|
|
146
|
+
const t = [...this.groups].map((e) => this.leaveGroup(e));
|
|
147
|
+
await Promise.all(t), this.info("Left all groups");
|
|
148
|
+
});
|
|
149
|
+
n(this, "getHubConnectionId", () => this.hubConnection.connectionId);
|
|
150
|
+
this.internalEvents = /* @__PURE__ */ new Map(), this.signalREvents = /* @__PURE__ */ new Map(), this.groups = [], t.enableLogging && (this.logger = t.logger), this.hubConnection = new d().withUrl(`${t.signalRApiUrl}/${t.hub}`).configureLogging(g.None).build(), this.buildInitialListeners();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
L as default
|
|
155
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SignalRHubName, SignalRSignalName } from '@ancon/wildcat-types';
|
|
2
|
+
import { SignalRConfig, SignalREventListener } from './types';
|
|
3
|
+
declare type SignalRConfigArg = Omit<SignalRConfig, 'hub'>;
|
|
4
|
+
declare type ReduxSelectorsArg<RootState = unknown> = {
|
|
5
|
+
clientIdSelector: (state: RootState) => string | null;
|
|
6
|
+
isSignalROnlineSelector: (state: RootState) => boolean;
|
|
7
|
+
};
|
|
8
|
+
declare type ReduxActionsArg = {
|
|
9
|
+
setIsSignalROnlineAction: (payload: {
|
|
10
|
+
isSignalROnline: boolean;
|
|
11
|
+
}) => unknown;
|
|
12
|
+
};
|
|
13
|
+
declare type ReduxHooksArg = Partial<{
|
|
14
|
+
useAppDispatch: () => (action: unknown) => unknown;
|
|
15
|
+
useAppStore: <T = {}>() => {
|
|
16
|
+
getState: () => T;
|
|
17
|
+
};
|
|
18
|
+
useAppSelector: <T extends (...args: any[]) => any>(selector: T) => ReturnType<T>;
|
|
19
|
+
}>;
|
|
20
|
+
declare function createUseSignalRHook(signalRConfig: SignalRConfigArg, selectors: ReduxSelectorsArg, actions: ReduxActionsArg, hooks?: ReduxHooksArg): (hub: SignalRHubName) => {
|
|
21
|
+
isHubConnected: boolean;
|
|
22
|
+
join: (group: string) => Promise<void>;
|
|
23
|
+
leave: (group: string) => Promise<void>;
|
|
24
|
+
subscribe: (signal: SignalRSignalName, listener: SignalREventListener, shouldSkipOwnClient?: boolean) => () => void;
|
|
25
|
+
unsubscribe: (signal: SignalRSignalName, listener: SignalREventListener) => void;
|
|
26
|
+
getHubConnectionId: () => string | null;
|
|
27
|
+
};
|
|
28
|
+
export default createUseSignalRHook;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("react"),l=require("react-redux"),U=require("./SignalR.js");require("@microsoft/signalr");require("@ancon/wildcat-types");require("../shared/wait.js");require("../api/generateBackoffWithEqualJitter.js");require("../number/randomIntFromInterval.js");function M(O,k,q,H){const{signalRApiUrl:h,logger:A,enableLogging:m}=O,{clientIdSelector:D,isSignalROnlineSelector:d}=k,{setIsSignalROnlineAction:f}=q,{useAppStore:w=l.useStore,useAppDispatch:x=l.useDispatch,useAppSelector:y=l.useSelector}=H??{};return function(G){const n=e.useRef(new U({signalRApiUrl:h,hub:G,logger:A,enableLogging:m})),i=w(),u=x(),g=y(D),[c,j]=e.useState(!1),[s,S]=e.useState(!1),R=e.useRef(c),o=e.useCallback(()=>{d(i.getState())||u(f({isSignalROnline:!0})),s||S(!0)},[u,s,i]),b=o,v=e.useCallback(()=>{d(i.getState())&&u(f({isSignalROnline:!1})),s&&S(!1)},[u,s,i]),p=e.useCallback(async t=>{n.current.groups.indexOf(t)<0&&await n.current.joinGroup(t)},[]),C=e.useCallback(async t=>{n.current.groups.indexOf(t)>=0&&await n.current.leaveGroup(t)},[]),E=e.useCallback((t,r,a)=>n.current.addSignalListener(t,r,a),[]),L=e.useCallback((t,r)=>n.current.removeSignalListener(t,r),[]),I=e.useCallback(()=>n.current.getHubConnectionId(),[]);return e.useEffect(()=>{R.current=c},[c]),e.useEffect(()=>{const t=n.current.addEventListener("connected",o),r=n.current.addEventListener("reconnected",b),a=n.current.addEventListener("disconnected",v);return R.current||j(!0),()=>{t(),r(),a()}},[o,v,b]),e.useEffect(()=>{n.current.setClientId(g||void 0)},[g]),e.useEffect(()=>{async function t(){await n.current.connect()}c&&t()},[c]),e.useEffect(()=>()=>{n.current.leaveAllGroups().then(()=>{n.current.disconnect()})},[n]),e.useMemo(()=>({isHubConnected:s,join:p,leave:C,subscribe:E,unsubscribe:L,getHubConnectionId:I}),[s,p,C,E,L,I])}}module.exports=M;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useRef as O, useState as C, useCallback as t, useEffect as i, useMemo as z } from "react";
|
|
2
|
+
import { useStore as B, useDispatch as F, useSelector as J } from "react-redux";
|
|
3
|
+
import K from "./SignalR.mjs";
|
|
4
|
+
import "@microsoft/signalr";
|
|
5
|
+
import "@ancon/wildcat-types";
|
|
6
|
+
import "../shared/wait.mjs";
|
|
7
|
+
import "../api/generateBackoffWithEqualJitter.mjs";
|
|
8
|
+
import "../number/randomIntFromInterval.mjs";
|
|
9
|
+
function $(H, h, A, D) {
|
|
10
|
+
const { signalRApiUrl: w, logger: x, enableLogging: y } = H, { clientIdSelector: G, isSignalROnlineSelector: d } = h, { setIsSignalROnlineAction: g } = A, {
|
|
11
|
+
useAppStore: j = B,
|
|
12
|
+
useAppDispatch: k = F,
|
|
13
|
+
useAppSelector: U = J
|
|
14
|
+
} = D ?? {};
|
|
15
|
+
return function(M) {
|
|
16
|
+
const e = O(
|
|
17
|
+
new K({
|
|
18
|
+
signalRApiUrl: w,
|
|
19
|
+
hub: M,
|
|
20
|
+
logger: x,
|
|
21
|
+
enableLogging: y
|
|
22
|
+
})
|
|
23
|
+
), o = j(), u = k(), f = U(G), [s, q] = C(!1), [r, p] = C(!1), S = O(s), a = t(() => {
|
|
24
|
+
d(o.getState()) || u(g({ isSignalROnline: !0 })), r || p(!0);
|
|
25
|
+
}, [u, r, o]), R = a, v = t(() => {
|
|
26
|
+
d(o.getState()) && u(g({ isSignalROnline: !1 })), r && p(!1);
|
|
27
|
+
}, [u, r, o]), m = t(async (n) => {
|
|
28
|
+
e.current.groups.indexOf(n) < 0 && await e.current.joinGroup(n);
|
|
29
|
+
}, []), b = t(async (n) => {
|
|
30
|
+
e.current.groups.indexOf(n) >= 0 && await e.current.leaveGroup(n);
|
|
31
|
+
}, []), L = t(
|
|
32
|
+
(n, c, l) => e.current.addSignalListener(
|
|
33
|
+
n,
|
|
34
|
+
c,
|
|
35
|
+
l
|
|
36
|
+
),
|
|
37
|
+
[]
|
|
38
|
+
), I = t(
|
|
39
|
+
(n, c) => e.current.removeSignalListener(n, c),
|
|
40
|
+
[]
|
|
41
|
+
), E = t(
|
|
42
|
+
() => e.current.getHubConnectionId(),
|
|
43
|
+
[]
|
|
44
|
+
);
|
|
45
|
+
return i(() => {
|
|
46
|
+
S.current = s;
|
|
47
|
+
}, [s]), i(() => {
|
|
48
|
+
const n = e.current.addEventListener(
|
|
49
|
+
"connected",
|
|
50
|
+
a
|
|
51
|
+
), c = e.current.addEventListener(
|
|
52
|
+
"reconnected",
|
|
53
|
+
R
|
|
54
|
+
), l = e.current.addEventListener(
|
|
55
|
+
"disconnected",
|
|
56
|
+
v
|
|
57
|
+
);
|
|
58
|
+
return S.current || q(!0), () => {
|
|
59
|
+
n(), c(), l();
|
|
60
|
+
};
|
|
61
|
+
}, [
|
|
62
|
+
a,
|
|
63
|
+
v,
|
|
64
|
+
R
|
|
65
|
+
]), i(() => {
|
|
66
|
+
e.current.setClientId(f || void 0);
|
|
67
|
+
}, [f]), i(() => {
|
|
68
|
+
async function n() {
|
|
69
|
+
await e.current.connect();
|
|
70
|
+
}
|
|
71
|
+
s && n();
|
|
72
|
+
}, [s]), i(
|
|
73
|
+
() => () => {
|
|
74
|
+
e.current.leaveAllGroups().then(() => {
|
|
75
|
+
e.current.disconnect();
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
[e]
|
|
79
|
+
), z(
|
|
80
|
+
() => ({
|
|
81
|
+
isHubConnected: r,
|
|
82
|
+
join: m,
|
|
83
|
+
leave: b,
|
|
84
|
+
subscribe: L,
|
|
85
|
+
unsubscribe: I,
|
|
86
|
+
getHubConnectionId: E
|
|
87
|
+
}),
|
|
88
|
+
[r, m, b, L, I, E]
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
$ as default
|
|
94
|
+
};
|
package/signalr/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createUseSignalRHook.js"),r=require("./SignalR.js");require("react");require("react-redux");require("@microsoft/signalr");require("@ancon/wildcat-types");require("../shared/wait.js");require("../api/generateBackoffWithEqualJitter.js");require("../number/randomIntFromInterval.js");exports.createUseSignalRHook=e;exports.SignalR=r;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as l } from "./createUseSignalRHook.mjs";
|
|
2
|
+
import { default as d } from "./SignalR.mjs";
|
|
3
|
+
import "react";
|
|
4
|
+
import "react-redux";
|
|
5
|
+
import "@microsoft/signalr";
|
|
6
|
+
import "@ancon/wildcat-types";
|
|
7
|
+
import "../shared/wait.mjs";
|
|
8
|
+
import "../api/generateBackoffWithEqualJitter.mjs";
|
|
9
|
+
import "../number/randomIntFromInterval.mjs";
|
|
10
|
+
export {
|
|
11
|
+
d as SignalR,
|
|
12
|
+
l as createUseSignalRHook
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SignalRHubName } from '@ancon/wildcat-types';
|
|
2
|
+
import Logger from '../logger/Logger';
|
|
3
|
+
export declare type SignalREventListener<T = unknown> = (data: T) => void;
|
|
4
|
+
export declare type SignalRConfig = {
|
|
5
|
+
/** @example "https://notification-api.ancon.io" */
|
|
6
|
+
signalRApiUrl: string;
|
|
7
|
+
/** @example "TicketHub" */
|
|
8
|
+
hub: SignalRHubName;
|
|
9
|
+
/** You need to set `enableLogging: true` too to enable logging */
|
|
10
|
+
logger?: Logger;
|
|
11
|
+
/** @default false */
|
|
12
|
+
enableLogging?: boolean;
|
|
13
|
+
};
|
package/signalr/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|