@moneypot/hub 1.19.6 → 1.19.8
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/dist/src/audit-log.js
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { logger } from "./logger.js";
|
|
2
|
+
const DELTA_TOLERANCE = 0.0001;
|
|
2
3
|
export async function insertAuditLog(pgClient, type, audit) {
|
|
4
|
+
if (type === "player-balance" || type === "both") {
|
|
5
|
+
const { balanceOld, balanceNew, balanceDelta } = audit;
|
|
6
|
+
const expected = balanceOld + balanceDelta;
|
|
7
|
+
if (Math.abs(balanceNew - expected) > DELTA_TOLERANCE) {
|
|
8
|
+
logger.warn({ balanceOld, balanceDelta, balanceNew, expected, action: audit.action }, "Audit balance delta mismatch");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (type === "house-bankroll" || type === "both") {
|
|
12
|
+
const { bankrollOld, bankrollNew, bankrollDelta } = audit;
|
|
13
|
+
const expected = bankrollOld + bankrollDelta;
|
|
14
|
+
if (Math.abs(bankrollNew - expected) > DELTA_TOLERANCE) {
|
|
15
|
+
logger.warn({
|
|
16
|
+
bankrollOld,
|
|
17
|
+
bankrollDelta,
|
|
18
|
+
bankrollNew,
|
|
19
|
+
expected,
|
|
20
|
+
action: audit.action,
|
|
21
|
+
}, "Audit bankroll delta mismatch");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
3
24
|
await pgClient.query(`
|
|
4
25
|
INSERT INTO hub.audit_log (
|
|
5
26
|
balance_id,
|
|
@@ -76,6 +76,12 @@ export const HubChatSubscriptionPlugin = extendSchema((build) => {
|
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
78
|
if (typeof item !== "string") {
|
|
79
|
+
if (typeof item === "object" &&
|
|
80
|
+
item !== null &&
|
|
81
|
+
"done" in item &&
|
|
82
|
+
item.done === true) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
79
85
|
logger.warn(item, `hubChatAlert: item is not a string`);
|
|
80
86
|
return false;
|
|
81
87
|
}
|
|
@@ -32,6 +32,12 @@ export const HubPutAlertPlugin = extendSchema((_build) => {
|
|
|
32
32
|
});
|
|
33
33
|
return listenWithFilter($pgSubscriber, $channelKey, jsonParse, $identity, (item, identity) => {
|
|
34
34
|
if (typeof item !== "string") {
|
|
35
|
+
if (typeof item === "object" &&
|
|
36
|
+
item !== null &&
|
|
37
|
+
"done" in item &&
|
|
38
|
+
item.done === true) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
35
41
|
logger.warn(item, `hubPutAlert: item is not a string`);
|
|
36
42
|
return false;
|
|
37
43
|
}
|