@ancon/wildcat-utils 1.55.0-check-optimizations.3 → 1.56.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/check/getOrganizedCheckItemModifications.d.ts +2 -2
- package/check/getOrganizedCheckItemModifications.js +1 -1
- package/check/getOrganizedCheckItemModifications.mjs +68 -74
- package/check/getUniqueCheckItemModificationId.d.ts +2 -2
- package/check/getUniqueCheckItemModificationId.js +1 -1
- package/check/getUniqueCheckItemModificationId.mjs +5 -5
- package/checkout/getCheckoutAdyenAmount.d.ts +9 -0
- package/checkout/getCheckoutAdyenAmount.js +1 -0
- package/checkout/getCheckoutAdyenAmount.mjs +13 -0
- package/checkout/getCheckoutGrandTotalAmount.d.ts +6 -2
- package/checkout/getCheckoutGrandTotalAmount.js +1 -1
- package/checkout/getCheckoutGrandTotalAmount.mjs +8 -6
- package/checkout/getCheckoutMinimumOrderDifferenceAmount.d.ts +7 -0
- package/checkout/getCheckoutMinimumOrderDifferenceAmount.js +1 -0
- package/checkout/getCheckoutMinimumOrderDifferenceAmount.mjs +12 -0
- package/checkout/index.d.ts +3 -1
- package/checkout/index.js +1 -1
- package/checkout/index.mjs +59 -55
- package/checkout/types.d.ts +5 -0
- package/index.js +1 -1
- package/index.mjs +231 -225
- package/multilingual/createLocalizedCheckDetails.d.ts +2 -2
- package/multilingual/createLocalizedCheckDetails.js +1 -1
- package/multilingual/createLocalizedCheckDetails.mjs +27 -31
- package/package.json +16 -1
- package/signalr/SignalR.d.ts +3 -1
- package/signalr/SignalR.js +1 -1
- package/signalr/SignalR.mjs +93 -86
- package/signalr/createUseSignalRHook.js +1 -1
- package/signalr/createUseSignalRHook.mjs +38 -36
- package/signalr/index.d.ts +4 -3
- package/signalr/index.js +1 -1
- package/signalr/index.mjs +6 -4
- package/signalr/types.d.ts +12 -0
- package/signalr/useSignalRGroup.d.ts +13 -0
- package/signalr/useSignalRGroup.js +1 -0
- package/signalr/useSignalRGroup.mjs +13 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IETFLanguageTag as r } from "@ancon/wildcat-types";
|
|
2
|
-
function
|
|
2
|
+
function u(e) {
|
|
3
3
|
switch (e) {
|
|
4
4
|
case "sv":
|
|
5
5
|
return r.Swedish;
|
|
@@ -11,47 +11,43 @@ function m(e) {
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return n && (c.productName = n), o && (c.variantName = o), c;
|
|
19
|
-
}
|
|
20
|
-
return e;
|
|
14
|
+
function d(e, c) {
|
|
15
|
+
var i, n;
|
|
16
|
+
const t = e, a = (i = e.localizedProductNames) == null ? void 0 : i[c], o = (n = e.localizedVariantNames) == null ? void 0 : n[c];
|
|
17
|
+
return a && (t.productName = a), o && (t.variantName = o), t;
|
|
21
18
|
}
|
|
22
|
-
function
|
|
23
|
-
var
|
|
24
|
-
const t = e,
|
|
25
|
-
return
|
|
19
|
+
function m(e, c) {
|
|
20
|
+
var i, n;
|
|
21
|
+
const t = e, a = (i = e.localizedNames) == null ? void 0 : i[c], o = (n = e.localizedReplacementNames) == null ? void 0 : n[c];
|
|
22
|
+
return a && (t.name = a), o && (t.replacementName = o), t;
|
|
26
23
|
}
|
|
27
|
-
function f(e,
|
|
24
|
+
function f(e, c) {
|
|
28
25
|
const t = e;
|
|
29
|
-
return t.product =
|
|
26
|
+
return t.product = d(
|
|
30
27
|
e.product,
|
|
31
|
-
|
|
28
|
+
c
|
|
32
29
|
), t;
|
|
33
30
|
}
|
|
34
|
-
function
|
|
35
|
-
const t = e, { product:
|
|
36
|
-
return t.product =
|
|
37
|
-
(l) =>
|
|
38
|
-
)),
|
|
39
|
-
(l) => f(l,
|
|
40
|
-
)),
|
|
41
|
-
(l) =>
|
|
31
|
+
function s(e, c) {
|
|
32
|
+
const t = e, { product: a, modifications: o, addOnProducts: i, subCheckItems: n } = e;
|
|
33
|
+
return t.product = d(a, c), o.length && (t.modifications = o.map(
|
|
34
|
+
(l) => m(l, c)
|
|
35
|
+
)), i != null && i.length && (t.addOnProducts = i.map(
|
|
36
|
+
(l) => f(l, c)
|
|
37
|
+
)), n.length && (t.subCheckItems = n.map(
|
|
38
|
+
(l) => s(l, c)
|
|
42
39
|
)), t;
|
|
43
40
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
const t = m(a);
|
|
41
|
+
function p(e, c) {
|
|
42
|
+
const t = u(c);
|
|
47
43
|
if (t) {
|
|
48
|
-
const
|
|
49
|
-
return
|
|
50
|
-
(
|
|
51
|
-
),
|
|
44
|
+
const a = e;
|
|
45
|
+
return a.items = e.items.map(
|
|
46
|
+
(o) => s(o, t)
|
|
47
|
+
), a;
|
|
52
48
|
}
|
|
53
49
|
return e;
|
|
54
50
|
}
|
|
55
51
|
export {
|
|
56
|
-
|
|
52
|
+
p as default
|
|
57
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancon/wildcat-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.56.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.mjs",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -180,6 +180,11 @@
|
|
|
180
180
|
"require": "./checkout/checkoutHasWallet.js",
|
|
181
181
|
"types": "./checkout/checkoutHasWallet.d.ts"
|
|
182
182
|
},
|
|
183
|
+
"./checkout/getCheckoutAdyenAmount": {
|
|
184
|
+
"import": "./checkout/getCheckoutAdyenAmount.mjs",
|
|
185
|
+
"require": "./checkout/getCheckoutAdyenAmount.js",
|
|
186
|
+
"types": "./checkout/getCheckoutAdyenAmount.d.ts"
|
|
187
|
+
},
|
|
183
188
|
"./checkout/getCheckoutGiftCardMetaData": {
|
|
184
189
|
"import": "./checkout/getCheckoutGiftCardMetaData.mjs",
|
|
185
190
|
"require": "./checkout/getCheckoutGiftCardMetaData.js",
|
|
@@ -210,6 +215,11 @@
|
|
|
210
215
|
"require": "./checkout/getCheckoutItemsMappedByTicketItemStatus.js",
|
|
211
216
|
"types": "./checkout/getCheckoutItemsMappedByTicketItemStatus.d.ts"
|
|
212
217
|
},
|
|
218
|
+
"./checkout/getCheckoutMinimumOrderDifferenceAmount": {
|
|
219
|
+
"import": "./checkout/getCheckoutMinimumOrderDifferenceAmount.mjs",
|
|
220
|
+
"require": "./checkout/getCheckoutMinimumOrderDifferenceAmount.js",
|
|
221
|
+
"types": "./checkout/getCheckoutMinimumOrderDifferenceAmount.d.ts"
|
|
222
|
+
},
|
|
213
223
|
"./checkout/getCheckoutOrderStatusTexts": {
|
|
214
224
|
"import": "./checkout/getCheckoutOrderStatusTexts.mjs",
|
|
215
225
|
"require": "./checkout/getCheckoutOrderStatusTexts.js",
|
|
@@ -1220,6 +1230,11 @@
|
|
|
1220
1230
|
"require": "./signalr/types.js",
|
|
1221
1231
|
"types": "./signalr/types.d.ts"
|
|
1222
1232
|
},
|
|
1233
|
+
"./signalr/useSignalRGroup": {
|
|
1234
|
+
"import": "./signalr/useSignalRGroup.mjs",
|
|
1235
|
+
"require": "./signalr/useSignalRGroup.js",
|
|
1236
|
+
"types": "./signalr/useSignalRGroup.d.ts"
|
|
1237
|
+
},
|
|
1223
1238
|
"./string/base64Decode": {
|
|
1224
1239
|
"import": "./string/base64Decode.mjs",
|
|
1225
1240
|
"require": "./string/base64Decode.js",
|
package/signalr/SignalR.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare class SignalR {
|
|
|
14
14
|
private isReconnecting;
|
|
15
15
|
private pendingJoins;
|
|
16
16
|
private initialReconnectDelayMs;
|
|
17
|
+
private maxReconnectAttempts;
|
|
17
18
|
groups: string[];
|
|
18
19
|
constructor(options: SignalRConfig);
|
|
19
20
|
info: (message: string, data?: any) => void;
|
|
@@ -21,7 +22,8 @@ declare class SignalR {
|
|
|
21
22
|
private getNextBackoffMs;
|
|
22
23
|
private getInitialReconnectDelayMs;
|
|
23
24
|
/**
|
|
24
|
-
* Keep trying to connect, with backoff, until connected
|
|
25
|
+
* Keep trying to connect, with backoff, until connected, `disconnect()` is
|
|
26
|
+
* called or `maxReconnectAttempts` attempts in a row have failed.
|
|
25
27
|
* Only one reconnect loop runs at a time.
|
|
26
28
|
*
|
|
27
29
|
* @param withInitialDelay Wait a random `initialReconnectDelayMs` before the
|
package/signalr/SignalR.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var d=(c,e,
|
|
1
|
+
"use strict";var f=Object.defineProperty;var d=(c,e,t)=>e in c?f(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var n=(c,e,t)=>(d(c,typeof e!="symbol"?e+"":e,t),t);const a=require("@microsoft/signalr"),h=require("@ancon/wildcat-types"),l=require("../shared/wait.js"),u=require("../api/generateBackoffWithEqualJitter.js"),g=require("../number/randomIntFromInterval.js");require("axios");const v={min:500,max:5e3};class m{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,"shouldReconnect",!0);n(this,"isReconnecting",!1);n(this,"pendingJoins",new Map);n(this,"initialReconnectDelayMs");n(this,"maxReconnectAttempts");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,"getNextBackoffMs",()=>{this.backoff[this.reconnectAttempt]==null&&(this.reconnectAttempt>0&&this.info("Ran out of backoff intervals, restarting backoff..."),this.reconnectAttempt=0,this.generateBackoff());const e=this.backoff[this.reconnectAttempt];if(e==null)throw new Error("Could not resolve ms from backoff");return e});n(this,"getInitialReconnectDelayMs",()=>{const e=Math.max(0,this.initialReconnectDelayMs.min),t=Math.max(e,this.initialReconnectDelayMs.max);return g(e,t)});n(this,"reconnect",async(e=!1)=>{if(this.isReconnecting)return;this.isReconnecting=!0;let t=0;try{if(e){const i=this.getInitialReconnectDelayMs();this.info("Waiting before reconnecting...",{delayMs:i}),await l(i)}for(;this.shouldReconnect;)try{this.info("Attempting to reconnect...",{attempt:this.reconnectAttempt+1}),await this.connect(!0),this.info("Reconnected"),this.reconnectAttempt=0;return}catch{if(!this.shouldReconnect)break;if(t+=1,t>=this.maxReconnectAttempts){this.info(`Gave up reconnecting after ${t} attempts`),this.reconnectAttempt=0;break}await l(this.getNextBackoffMs()),this.reconnectAttempt+=1}}finally{this.isReconnecting=!1}});n(this,"buildInitialListeners",()=>{this.hubConnection.onclose(()=>{this.groups=[],this.info("Hub connection closed"),this.emitEvent("disconnected"),this.reconnect(!0)}),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),r=i&&o.clientId&&o.clientId===this.clientId;return r||this.info(`Received signal "${e}"`,s),r?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;this.shouldReconnect&&(this.emitEvent("disconnected"),await this.reconnect())}});n(this,"disconnect",async()=>{try{this.shouldReconnect=!1,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=>{const t=this.pendingJoins.get(e);if(t)return t;if(this.groups.includes(e))return!0;const i=this.invokeJoinGroup(e).finally(()=>{this.pendingJoins.delete(e)});return this.pendingJoins.set(e,i),i});n(this,"invokeJoinGroup",async e=>{this.info(`Joining group "${e}"...`),this.groups.push(e);try{return await this.hubConnection.invoke(h.SignalRMethodName.JoinGroup,e),this.info(`Joined group "${e}"`),!0}catch(t){this.info(`Failed to join group "${e}"`,t);const i=this.groups.indexOf(e);return i>=0&&this.groups.splice(i,1),!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(h.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=[],this.initialReconnectDelayMs=e.initialReconnectDelayMs??v,this.maxReconnectAttempts=e.maxReconnectAttempts??1/0,e.enableLogging&&(this.logger=e.logger),this.hubConnection=new a.HubConnectionBuilder().withUrl(`${e.signalRApiUrl}/${e.hub}`).configureLogging(a.LogLevel.None).build(),e.serverTimeoutInMilliseconds!=null&&(this.hubConnection.serverTimeoutInMilliseconds=e.serverTimeoutInMilliseconds),e.keepAliveIntervalInMilliseconds!=null&&(this.hubConnection.keepAliveIntervalInMilliseconds=e.keepAliveIntervalInMilliseconds),this.buildInitialListeners()}}module.exports=m;
|
package/signalr/SignalR.mjs
CHANGED
|
@@ -1,80 +1,87 @@
|
|
|
1
1
|
var l = Object.defineProperty;
|
|
2
|
-
var f = (c, e,
|
|
3
|
-
var
|
|
2
|
+
var f = (c, e, t) => e in c ? l(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
|
+
var n = (c, e, t) => (f(c, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
4
|
import { HubConnectionBuilder as d, LogLevel as u } from "@microsoft/signalr";
|
|
5
|
-
import { SignalRMethodName as
|
|
6
|
-
import
|
|
5
|
+
import { SignalRMethodName as a } from "@ancon/wildcat-types";
|
|
6
|
+
import h from "../shared/wait.mjs";
|
|
7
7
|
import g from "../api/generateBackoffWithEqualJitter.mjs";
|
|
8
|
-
import
|
|
8
|
+
import m from "../number/randomIntFromInterval.mjs";
|
|
9
9
|
import "axios";
|
|
10
|
-
const
|
|
10
|
+
const p = {
|
|
11
11
|
min: 500,
|
|
12
12
|
max: 5e3
|
|
13
13
|
};
|
|
14
|
-
class
|
|
14
|
+
class A {
|
|
15
15
|
constructor(e) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
n(this, "internalEvents");
|
|
17
|
+
n(this, "signalREvents");
|
|
18
|
+
n(this, "hubConnection");
|
|
19
|
+
n(this, "clientId");
|
|
20
|
+
n(this, "logger");
|
|
21
|
+
n(this, "backoff", []);
|
|
22
|
+
n(this, "reconnectAttempt", 0);
|
|
23
|
+
n(this, "shouldReconnect", !0);
|
|
24
|
+
n(this, "isReconnecting", !1);
|
|
25
|
+
n(this, "pendingJoins", /* @__PURE__ */ new Map());
|
|
26
|
+
n(this, "initialReconnectDelayMs");
|
|
27
|
+
n(this, "maxReconnectAttempts");
|
|
28
|
+
n(this, "groups");
|
|
29
|
+
n(this, "info", (e, t) => {
|
|
29
30
|
var i;
|
|
30
|
-
(i = this.logger) == null || i.info(e,
|
|
31
|
+
(i = this.logger) == null || i.info(e, t);
|
|
31
32
|
});
|
|
32
|
-
|
|
33
|
+
n(this, "generateBackoff", () => {
|
|
33
34
|
this.backoff = g(50, 500, 5e3), this.info("Generated new backoff");
|
|
34
35
|
});
|
|
35
|
-
|
|
36
|
+
n(this, "getNextBackoffMs", () => {
|
|
36
37
|
this.backoff[this.reconnectAttempt] == null && (this.reconnectAttempt > 0 && this.info("Ran out of backoff intervals, restarting backoff..."), this.reconnectAttempt = 0, this.generateBackoff());
|
|
37
38
|
const e = this.backoff[this.reconnectAttempt];
|
|
38
39
|
if (e == null)
|
|
39
40
|
throw new Error("Could not resolve ms from backoff");
|
|
40
41
|
return e;
|
|
41
42
|
});
|
|
42
|
-
|
|
43
|
-
const e = Math.max(0, this.initialReconnectDelayMs.min),
|
|
44
|
-
return
|
|
43
|
+
n(this, "getInitialReconnectDelayMs", () => {
|
|
44
|
+
const e = Math.max(0, this.initialReconnectDelayMs.min), t = Math.max(e, this.initialReconnectDelayMs.max);
|
|
45
|
+
return m(e, t);
|
|
45
46
|
});
|
|
46
47
|
/**
|
|
47
|
-
* Keep trying to connect, with backoff, until connected
|
|
48
|
+
* Keep trying to connect, with backoff, until connected, `disconnect()` is
|
|
49
|
+
* called or `maxReconnectAttempts` attempts in a row have failed.
|
|
48
50
|
* Only one reconnect loop runs at a time.
|
|
49
51
|
*
|
|
50
52
|
* @param withInitialDelay Wait a random `initialReconnectDelayMs` before the
|
|
51
53
|
* first attempt, so clients dropped at the same moment don't all reconnect at once.
|
|
52
54
|
*/
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
this.info("Attempting to reconnect...", {
|
|
64
|
-
attempt: this.reconnectAttempt + 1
|
|
65
|
-
}), await this.connect(!0), this.info("Reconnected"), this.reconnectAttempt = 0;
|
|
66
|
-
return;
|
|
67
|
-
} catch {
|
|
68
|
-
if (!this.shouldReconnect)
|
|
69
|
-
break;
|
|
70
|
-
await a(this.getNextBackoffMs()), this.reconnectAttempt += 1;
|
|
71
|
-
}
|
|
72
|
-
} finally {
|
|
73
|
-
this.isReconnecting = !1;
|
|
55
|
+
n(this, "reconnect", async (e = !1) => {
|
|
56
|
+
if (this.isReconnecting)
|
|
57
|
+
return;
|
|
58
|
+
this.isReconnecting = !0;
|
|
59
|
+
let t = 0;
|
|
60
|
+
try {
|
|
61
|
+
if (e) {
|
|
62
|
+
const i = this.getInitialReconnectDelayMs();
|
|
63
|
+
this.info("Waiting before reconnecting...", { delayMs: i }), await h(i);
|
|
74
64
|
}
|
|
65
|
+
for (; this.shouldReconnect; )
|
|
66
|
+
try {
|
|
67
|
+
this.info("Attempting to reconnect...", {
|
|
68
|
+
attempt: this.reconnectAttempt + 1
|
|
69
|
+
}), await this.connect(!0), this.info("Reconnected"), this.reconnectAttempt = 0;
|
|
70
|
+
return;
|
|
71
|
+
} catch {
|
|
72
|
+
if (!this.shouldReconnect)
|
|
73
|
+
break;
|
|
74
|
+
if (t += 1, t >= this.maxReconnectAttempts) {
|
|
75
|
+
this.info(`Gave up reconnecting after ${t} attempts`), this.reconnectAttempt = 0;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
await h(this.getNextBackoffMs()), this.reconnectAttempt += 1;
|
|
79
|
+
}
|
|
80
|
+
} finally {
|
|
81
|
+
this.isReconnecting = !1;
|
|
75
82
|
}
|
|
76
83
|
});
|
|
77
|
-
|
|
84
|
+
n(this, "buildInitialListeners", () => {
|
|
78
85
|
this.hubConnection.onclose(() => {
|
|
79
86
|
this.groups = [], this.info("Hub connection closed"), this.emitEvent("disconnected"), this.reconnect(!0);
|
|
80
87
|
}), this.hubConnection.onreconnected(() => this.emitEvent("reconnected"));
|
|
@@ -84,22 +91,22 @@ class w {
|
|
|
84
91
|
* @param event Event to emit
|
|
85
92
|
* @param args Arguments to send to the listeners
|
|
86
93
|
*/
|
|
87
|
-
|
|
94
|
+
n(this, "emitEvent", (e, ...t) => {
|
|
88
95
|
if (this.internalEvents.has(e)) {
|
|
89
96
|
this.info(`Emitting event "${e}"`);
|
|
90
97
|
const i = this.internalEvents.get(e);
|
|
91
|
-
i && i.forEach((s) => s(...
|
|
98
|
+
i && i.forEach((s) => s(...t));
|
|
92
99
|
} else
|
|
93
100
|
this.info(`Failed to emit event "${e}". There were no listeners.`);
|
|
94
101
|
});
|
|
95
|
-
|
|
96
|
-
this.info(`Skipped signal "${e}"`,
|
|
102
|
+
n(this, "skipSignal", (e, t) => {
|
|
103
|
+
this.info(`Skipped signal "${e}"`, t);
|
|
97
104
|
});
|
|
98
|
-
|
|
105
|
+
n(this, "enhanceListener", (e, t, i) => (s) => {
|
|
99
106
|
const o = JSON.parse(s), r = i && o.clientId && o.clientId === this.clientId;
|
|
100
|
-
return r || this.info(`Received signal "${e}"`, s), r ? this.skipSignal(e, s) :
|
|
107
|
+
return r || this.info(`Received signal "${e}"`, s), r ? this.skipSignal(e, s) : t(o);
|
|
101
108
|
});
|
|
102
|
-
|
|
109
|
+
n(this, "setClientId", (e) => {
|
|
103
110
|
this.clientId = e;
|
|
104
111
|
});
|
|
105
112
|
/**
|
|
@@ -110,16 +117,16 @@ class w {
|
|
|
110
117
|
* until it connects or `disconnect()` is called; the returned promise settles
|
|
111
118
|
* when that happens.
|
|
112
119
|
*/
|
|
113
|
-
|
|
120
|
+
n(this, "connect", async (e = !1) => {
|
|
114
121
|
try {
|
|
115
122
|
this.info("Connecting..."), await this.hubConnection.start(), this.info("Connected"), this.emitEvent("connected");
|
|
116
|
-
} catch (
|
|
123
|
+
} catch (t) {
|
|
117
124
|
if (this.info("Failed to connect"), e)
|
|
118
|
-
throw
|
|
125
|
+
throw t;
|
|
119
126
|
this.shouldReconnect && (this.emitEvent("disconnected"), await this.reconnect());
|
|
120
127
|
}
|
|
121
128
|
});
|
|
122
|
-
|
|
129
|
+
n(this, "disconnect", async () => {
|
|
123
130
|
try {
|
|
124
131
|
this.shouldReconnect = !1, this.info("Disconnecting..."), await this.hubConnection.stop(), this.info("Disconnected"), this.emitEvent("disconnected");
|
|
125
132
|
} catch {
|
|
@@ -131,20 +138,20 @@ class w {
|
|
|
131
138
|
* @param event Event to listen on
|
|
132
139
|
* @param listener Event listener function
|
|
133
140
|
*/
|
|
134
|
-
|
|
141
|
+
n(this, "addEventListener", (e, t) => {
|
|
135
142
|
this.internalEvents.has(e) || this.internalEvents.set(e, []);
|
|
136
143
|
const i = this.internalEvents.get(e);
|
|
137
|
-
return i && i.push(
|
|
144
|
+
return i && i.push(t), () => this.removeEventListener(e, t);
|
|
138
145
|
});
|
|
139
146
|
/**
|
|
140
147
|
* Remove internal event listener
|
|
141
148
|
* @param event Event to stop listening to
|
|
142
149
|
* @param listener Event listener function
|
|
143
150
|
*/
|
|
144
|
-
|
|
151
|
+
n(this, "removeEventListener", (e, t) => {
|
|
145
152
|
var i;
|
|
146
153
|
if (this.internalEvents.has(e)) {
|
|
147
|
-
const s = this.internalEvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s,
|
|
154
|
+
const s = this.internalEvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s, t)) ?? -1;
|
|
148
155
|
o >= 0 ? (s.splice(o, 1), this.info(`Removed event listener for event "${e}"`)) : this.info(
|
|
149
156
|
`Failed to remove event listener for event "${e}". Specified listener was not found.`
|
|
150
157
|
);
|
|
@@ -158,11 +165,11 @@ class w {
|
|
|
158
165
|
* @param signal Signal name
|
|
159
166
|
* @param listener Signal listener function
|
|
160
167
|
*/
|
|
161
|
-
|
|
168
|
+
n(this, "addSignalListener", (e, t, i = !0) => {
|
|
162
169
|
this.signalREvents.has(e) || this.signalREvents.set(e, []);
|
|
163
170
|
const s = this.signalREvents.get(e), o = this.enhanceListener(
|
|
164
171
|
e,
|
|
165
|
-
|
|
172
|
+
t,
|
|
166
173
|
i
|
|
167
174
|
);
|
|
168
175
|
return s && s.push(o), this.hubConnection.on(e, o), this.info(`Added signal listener for signal "${e}"`), () => this.removeSignalListener(e, o);
|
|
@@ -172,11 +179,11 @@ class w {
|
|
|
172
179
|
* @param signal Signal name
|
|
173
180
|
* @param listener Signal listener function
|
|
174
181
|
*/
|
|
175
|
-
|
|
182
|
+
n(this, "removeSignalListener", (e, t) => {
|
|
176
183
|
var i;
|
|
177
184
|
if (this.signalREvents.has(e)) {
|
|
178
|
-
const s = this.signalREvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s,
|
|
179
|
-
o >= 0 ? (this.hubConnection.off(e,
|
|
185
|
+
const s = this.signalREvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s, t)) ?? -1;
|
|
186
|
+
o >= 0 ? (this.hubConnection.off(e, t), s.splice(o, 1), this.info(`Removed signal listener for signal "${e}"`)) : this.info(
|
|
180
187
|
`Failed to remove signal listener for signal "${e}". Specified listener was not found.`
|
|
181
188
|
);
|
|
182
189
|
} else
|
|
@@ -188,10 +195,10 @@ class w {
|
|
|
188
195
|
* Join a group. A group that is already joined, or being joined, is not joined again.
|
|
189
196
|
* @returns Whether the group is joined
|
|
190
197
|
*/
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
return
|
|
198
|
+
n(this, "joinGroup", async (e) => {
|
|
199
|
+
const t = this.pendingJoins.get(e);
|
|
200
|
+
if (t)
|
|
201
|
+
return t;
|
|
195
202
|
if (this.groups.includes(e))
|
|
196
203
|
return !0;
|
|
197
204
|
const i = this.invokeJoinGroup(e).finally(() => {
|
|
@@ -199,35 +206,35 @@ class w {
|
|
|
199
206
|
});
|
|
200
207
|
return this.pendingJoins.set(e, i), i;
|
|
201
208
|
});
|
|
202
|
-
|
|
209
|
+
n(this, "invokeJoinGroup", async (e) => {
|
|
203
210
|
this.info(`Joining group "${e}"...`), this.groups.push(e);
|
|
204
211
|
try {
|
|
205
|
-
return await this.hubConnection.invoke(
|
|
206
|
-
} catch (
|
|
207
|
-
this.info(`Failed to join group "${e}"`,
|
|
212
|
+
return await this.hubConnection.invoke(a.JoinGroup, e), this.info(`Joined group "${e}"`), !0;
|
|
213
|
+
} catch (t) {
|
|
214
|
+
this.info(`Failed to join group "${e}"`, t);
|
|
208
215
|
const i = this.groups.indexOf(e);
|
|
209
216
|
return i >= 0 && this.groups.splice(i, 1), !1;
|
|
210
217
|
}
|
|
211
218
|
});
|
|
212
|
-
|
|
219
|
+
n(this, "leaveGroup", async (e) => {
|
|
213
220
|
this.info(`Leaving group "${e}"...`);
|
|
214
|
-
const
|
|
215
|
-
|
|
221
|
+
const t = this.groups.indexOf(e);
|
|
222
|
+
t >= 0 && this.groups.splice(t, 1);
|
|
216
223
|
try {
|
|
217
|
-
await this.hubConnection.invoke(
|
|
224
|
+
await this.hubConnection.invoke(a.LeaveGroup, e), this.info(`Left group "${e}"`);
|
|
218
225
|
} catch (i) {
|
|
219
226
|
this.groups.indexOf(e) < 0 && this.groups.push(e), this.info(`Failed to leave group "${e}"`, i);
|
|
220
227
|
}
|
|
221
228
|
});
|
|
222
|
-
|
|
229
|
+
n(this, "leaveAllGroups", async () => {
|
|
223
230
|
this.info(`Leaving all (${this.groups.length}) groups...`);
|
|
224
|
-
const e = [...this.groups].map((
|
|
231
|
+
const e = [...this.groups].map((t) => this.leaveGroup(t));
|
|
225
232
|
await Promise.all(e), this.info("Left all groups");
|
|
226
233
|
});
|
|
227
|
-
|
|
228
|
-
this.internalEvents = /* @__PURE__ */ new Map(), this.signalREvents = /* @__PURE__ */ new Map(), this.groups = [], this.initialReconnectDelayMs = e.initialReconnectDelayMs ??
|
|
234
|
+
n(this, "getHubConnectionId", () => this.hubConnection.connectionId);
|
|
235
|
+
this.internalEvents = /* @__PURE__ */ new Map(), this.signalREvents = /* @__PURE__ */ new Map(), this.groups = [], this.initialReconnectDelayMs = e.initialReconnectDelayMs ?? p, this.maxReconnectAttempts = e.maxReconnectAttempts ?? 1 / 0, e.enableLogging && (this.logger = e.logger), this.hubConnection = new d().withUrl(`${e.signalRApiUrl}/${e.hub}`).configureLogging(u.None).build(), e.serverTimeoutInMilliseconds != null && (this.hubConnection.serverTimeoutInMilliseconds = e.serverTimeoutInMilliseconds), e.keepAliveIntervalInMilliseconds != null && (this.hubConnection.keepAliveIntervalInMilliseconds = e.keepAliveIntervalInMilliseconds), this.buildInitialListeners();
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
238
|
export {
|
|
232
|
-
|
|
239
|
+
A as default
|
|
233
240
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("react"),I=require("react-redux"),h=require("../noop-7ea3b37b.js"),
|
|
1
|
+
"use strict";const n=require("react"),I=require("react-redux"),h=require("../noop-7ea3b37b.js"),Q=l=>Object.freeze(Object.defineProperty({__proto__:null,default:l},Symbol.toStringTag,{value:"Module"}));function V(l,m,D,M){const{logger:_,enableLogging:j,serverTimeoutInMilliseconds:q,keepAliveIntervalInMilliseconds:w,initialReconnectDelayMs:x,maxReconnectAttempts:G}=l;let{signalRApiUrl:v}=l;const{clientIdSelector:P,isSignalROnlineSelector:c}=m??{},{setIsSignalROnlineAction:a}=D??{},{useAppStore:T=I.useStore,useAppDispatch:z=I.useDispatch,useAppSelector:N=I.useSelector}=M??{},b=new Set;function B(o){const[f,F]=n.useState(v),[e,J]=n.useState(null),d=T(),p=z(),C=N(P??(()=>{})),[u,K]=n.useState(!1),[r,E]=n.useState(!1),k=n.useRef(u),S=n.useCallback(()=>{(c==null?void 0:c(d.getState()))===!1&&a&&p(a({isSignalROnline:!0})),r||E(!0)},[p,r,d]),A=S,y=n.useCallback(()=>{(c==null?void 0:c(d.getState()))===!0&&a&&p(a({isSignalROnline:!1})),r&&E(!1)},[p,r,d]),H=n.useCallback(async t=>e?e.joinGroup(t):!1,[e]),O=n.useCallback(async t=>{e&&e.groups.indexOf(t)>=0&&await(e==null?void 0:e.leaveGroup(t))},[e]),L=n.useCallback((t,s,i)=>e?e==null?void 0:e.addSignalListener(t,s,i):h.noop,[e]),U=n.useCallback((t,s)=>{e&&e.removeSignalListener(t,s)},[e]),g=n.useCallback(()=>e?e.getHubConnectionId():null,[e]);return n.useEffect(()=>{let t=!1;return Promise.resolve().then(()=>Q(require("./SignalR.js"))).then(({default:s})=>{t||J(new s({signalRApiUrl:f,hub:o,logger:_,enableLogging:j,serverTimeoutInMilliseconds:q,keepAliveIntervalInMilliseconds:w,initialReconnectDelayMs:x,maxReconnectAttempts:G}))}),()=>{t=!0}},[o,f]),n.useEffect(()=>{function t(s){F(s)}return b.add(t),()=>{b.delete(t)}},[]),n.useEffect(()=>{k.current=u},[u]),n.useEffect(()=>{const t=e==null?void 0:e.addEventListener("connected",S),s=e==null?void 0:e.addEventListener("reconnected",A),i=e==null?void 0:e.addEventListener("disconnected",y);return e&&!k.current&&K(!0),()=>{t==null||t(),s==null||s(),i==null||i()}},[e,S,y,A]),n.useEffect(()=>{e==null||e.setClientId(C||void 0)},[e,C]),n.useEffect(()=>{async function t(){await(e==null?void 0:e.connect())}u&&t()},[e,u]),n.useEffect(()=>()=>{e==null||e.leaveAllGroups().then(()=>{e==null||e.disconnect()}).catch(h.noop).finally(()=>{e==null||e.disconnect().catch(h.noop)})},[e]),n.useMemo(()=>({isHubConnected:r,join:H,leave:O,subscribe:L,unsubscribe:U,getHubConnectionId:g}),[r,H,O,L,U,g])}return{useSignalR:B,setUrl(o){v=o,b.forEach(f=>{f(o)})}}}module.exports=V;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { useState as I, useRef as
|
|
2
|
-
import { useStore as
|
|
1
|
+
import { useState as I, useRef as W, useCallback as s, useEffect as c, useMemo as X } from "react";
|
|
2
|
+
import { useStore as Y, useDispatch as Z, useSelector as _ } from "react-redux";
|
|
3
3
|
import { n as h } from "../noop-378485d5.mjs";
|
|
4
|
-
function
|
|
4
|
+
function ne(v, D, M, k) {
|
|
5
5
|
const {
|
|
6
|
-
logger:
|
|
7
|
-
enableLogging:
|
|
8
|
-
serverTimeoutInMilliseconds:
|
|
6
|
+
logger: x,
|
|
7
|
+
enableLogging: G,
|
|
8
|
+
serverTimeoutInMilliseconds: j,
|
|
9
9
|
keepAliveIntervalInMilliseconds: T,
|
|
10
|
-
initialReconnectDelayMs: q
|
|
10
|
+
initialReconnectDelayMs: q,
|
|
11
|
+
maxReconnectAttempts: z
|
|
11
12
|
} = v;
|
|
12
|
-
let { signalRApiUrl:
|
|
13
|
-
const { clientIdSelector:
|
|
14
|
-
useAppStore:
|
|
15
|
-
useAppDispatch:
|
|
16
|
-
useAppSelector:
|
|
13
|
+
let { signalRApiUrl: m } = v;
|
|
14
|
+
const { clientIdSelector: B, isSignalROnlineSelector: r } = D ?? {}, { setIsSignalROnlineAction: a } = M ?? {}, {
|
|
15
|
+
useAppStore: F = Y,
|
|
16
|
+
useAppDispatch: J = Z,
|
|
17
|
+
useAppSelector: K = _
|
|
17
18
|
} = k ?? {}, S = /* @__PURE__ */ new Set();
|
|
18
|
-
function
|
|
19
|
-
const [d,
|
|
20
|
-
})), [u,
|
|
21
|
-
(
|
|
19
|
+
function N(i) {
|
|
20
|
+
const [d, P] = I(m), [e, Q] = I(null), f = F(), p = J(), A = K(B ?? (() => {
|
|
21
|
+
})), [u, V] = I(!1), [o, H] = I(!1), L = W(u), b = s(() => {
|
|
22
|
+
(r == null ? void 0 : r(f.getState())) === !1 && a && p(a({ isSignalROnline: !0 })), o || H(!0);
|
|
22
23
|
}, [p, o, f]), U = b, C = s(() => {
|
|
23
|
-
(
|
|
24
|
+
(r == null ? void 0 : r(f.getState())) === !0 && a && p(a({ isSignalROnline: !1 })), o && H(!1);
|
|
24
25
|
}, [p, o, f]), y = s(
|
|
25
26
|
async (t) => e ? e.joinGroup(t) : !1,
|
|
26
27
|
[e]
|
|
@@ -42,33 +43,34 @@ function te(v, D, M, k) {
|
|
|
42
43
|
},
|
|
43
44
|
[e]
|
|
44
45
|
), w = s(() => e ? e.getHubConnectionId() : null, [e]);
|
|
45
|
-
return
|
|
46
|
+
return c(() => {
|
|
46
47
|
let t = !1;
|
|
47
48
|
return import("./SignalR.mjs").then(({ default: n }) => {
|
|
48
|
-
t ||
|
|
49
|
+
t || Q(
|
|
49
50
|
new n({
|
|
50
51
|
signalRApiUrl: d,
|
|
51
52
|
hub: i,
|
|
52
|
-
logger:
|
|
53
|
-
enableLogging:
|
|
54
|
-
serverTimeoutInMilliseconds:
|
|
53
|
+
logger: x,
|
|
54
|
+
enableLogging: G,
|
|
55
|
+
serverTimeoutInMilliseconds: j,
|
|
55
56
|
keepAliveIntervalInMilliseconds: T,
|
|
56
|
-
initialReconnectDelayMs: q
|
|
57
|
+
initialReconnectDelayMs: q,
|
|
58
|
+
maxReconnectAttempts: z
|
|
57
59
|
})
|
|
58
60
|
);
|
|
59
61
|
}), () => {
|
|
60
62
|
t = !0;
|
|
61
63
|
};
|
|
62
|
-
}, [i, d]),
|
|
64
|
+
}, [i, d]), c(() => {
|
|
63
65
|
function t(n) {
|
|
64
|
-
|
|
66
|
+
P(n);
|
|
65
67
|
}
|
|
66
68
|
return S.add(t), () => {
|
|
67
69
|
S.delete(t);
|
|
68
70
|
};
|
|
69
|
-
}, []),
|
|
71
|
+
}, []), c(() => {
|
|
70
72
|
L.current = u;
|
|
71
|
-
}, [u]),
|
|
73
|
+
}, [u]), c(() => {
|
|
72
74
|
const t = e == null ? void 0 : e.addEventListener(
|
|
73
75
|
"connected",
|
|
74
76
|
b
|
|
@@ -79,7 +81,7 @@ function te(v, D, M, k) {
|
|
|
79
81
|
"disconnected",
|
|
80
82
|
C
|
|
81
83
|
);
|
|
82
|
-
return e && !L.current &&
|
|
84
|
+
return e && !L.current && V(!0), () => {
|
|
83
85
|
t == null || t(), n == null || n(), l == null || l();
|
|
84
86
|
};
|
|
85
87
|
}, [
|
|
@@ -87,14 +89,14 @@ function te(v, D, M, k) {
|
|
|
87
89
|
b,
|
|
88
90
|
C,
|
|
89
91
|
U
|
|
90
|
-
]),
|
|
91
|
-
e == null || e.setClientId(
|
|
92
|
-
}, [e,
|
|
92
|
+
]), c(() => {
|
|
93
|
+
e == null || e.setClientId(A || void 0);
|
|
94
|
+
}, [e, A]), c(() => {
|
|
93
95
|
async function t() {
|
|
94
96
|
await (e == null ? void 0 : e.connect());
|
|
95
97
|
}
|
|
96
98
|
u && t();
|
|
97
|
-
}, [e, u]),
|
|
99
|
+
}, [e, u]), c(
|
|
98
100
|
() => () => {
|
|
99
101
|
e == null || e.leaveAllGroups().then(() => {
|
|
100
102
|
e == null || e.disconnect();
|
|
@@ -103,7 +105,7 @@ function te(v, D, M, k) {
|
|
|
103
105
|
});
|
|
104
106
|
},
|
|
105
107
|
[e]
|
|
106
|
-
),
|
|
108
|
+
), X(
|
|
107
109
|
() => ({
|
|
108
110
|
isHubConnected: o,
|
|
109
111
|
join: y,
|
|
@@ -116,14 +118,14 @@ function te(v, D, M, k) {
|
|
|
116
118
|
);
|
|
117
119
|
}
|
|
118
120
|
return {
|
|
119
|
-
useSignalR:
|
|
121
|
+
useSignalR: N,
|
|
120
122
|
setUrl(i) {
|
|
121
|
-
|
|
123
|
+
m = i, S.forEach((d) => {
|
|
122
124
|
d(i);
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
127
|
};
|
|
126
128
|
}
|
|
127
129
|
export {
|
|
128
|
-
|
|
130
|
+
ne as default
|
|
129
131
|
};
|