@moneypot/hub 1.4.3 → 1.4.4
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/README.md
CHANGED
|
@@ -76,6 +76,10 @@ insert into hub.api_key default values returning key;
|
|
|
76
76
|
|
|
77
77
|
## Changelog
|
|
78
78
|
|
|
79
|
+
### 1.4.4
|
|
80
|
+
|
|
81
|
+
- Added `allowLossBeyondWager` option to `MakeOutcomeBetPlugin`. Must be set to `true` to allow outcome profits to be less than -1.
|
|
82
|
+
|
|
79
83
|
### 1.4.1
|
|
80
84
|
|
|
81
85
|
- Added `hubPutAlert` subscription
|
package/dist/src/db/public.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as pg from "pg";
|
|
2
1
|
import { DbBalance, DbBankroll, DbCurrency, DbSession } from "./types.js";
|
|
3
|
-
import { PgClientInTransaction } from "./index.js";
|
|
4
|
-
export declare function dbGetActiveSessionById(pgClient:
|
|
5
|
-
export declare function dbGetCasinoCurrencyByKey(pgClient:
|
|
2
|
+
import { PgClientInTransaction, QueryExecutor } from "./index.js";
|
|
3
|
+
export declare function dbGetActiveSessionById(pgClient: QueryExecutor, sessionId: string): Promise<DbSession | undefined>;
|
|
4
|
+
export declare function dbGetCasinoCurrencyByKey(pgClient: QueryExecutor, { currencyKey, casinoId }: {
|
|
6
5
|
currencyKey: string;
|
|
7
6
|
casinoId: string;
|
|
8
7
|
}): Promise<DbCurrency | undefined>;
|
package/dist/src/db/public.js
CHANGED
|
@@ -2,21 +2,21 @@ import { maybeOneRow } from "./util.js";
|
|
|
2
2
|
import { assert } from "tsafe";
|
|
3
3
|
export async function dbGetActiveSessionById(pgClient, sessionId) {
|
|
4
4
|
return pgClient
|
|
5
|
-
.query(
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
.query(`
|
|
6
|
+
SELECT *
|
|
7
|
+
FROM hub.active_session
|
|
8
|
+
WHERE id = $1
|
|
9
|
+
`, [sessionId])
|
|
8
10
|
.then(maybeOneRow);
|
|
9
11
|
}
|
|
10
12
|
export async function dbGetCasinoCurrencyByKey(pgClient, { currencyKey, casinoId }) {
|
|
11
13
|
return pgClient
|
|
12
|
-
.query(
|
|
13
|
-
text: `
|
|
14
|
+
.query(`
|
|
14
15
|
SELECT *
|
|
15
16
|
FROM hub.currency
|
|
16
|
-
WHERE key = $1
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
})
|
|
17
|
+
WHERE key = $1
|
|
18
|
+
AND casino_id = $2
|
|
19
|
+
`, [currencyKey, casinoId])
|
|
20
20
|
.then(maybeOneRow);
|
|
21
21
|
}
|
|
22
22
|
export async function dbLockPlayerBalanceAndHouseBankroll(pgClient, { userId, casinoId, experienceId, currencyKey, }) {
|
|
@@ -73,6 +73,7 @@ type FinalizeMetadataData = {
|
|
|
73
73
|
export type OutcomeBetConfig = {
|
|
74
74
|
houseEdge: number;
|
|
75
75
|
saveOutcomes: boolean;
|
|
76
|
+
allowLossBeyondWager: boolean;
|
|
76
77
|
initializeMetadataFromUntrustedUserInput?: (input: Input) => Result<Metadata, string>;
|
|
77
78
|
finalizeMetadata?: (validatedMetadata: Metadata, data: FinalizeMetadataData) => Metadata;
|
|
78
79
|
};
|
|
@@ -53,6 +53,7 @@ const BetConfigsSchema = z.record(BetKindSchema, z.object({
|
|
|
53
53
|
.gte(0, "House edge must be >= 0")
|
|
54
54
|
.lte(1, "House edge must be <= 1"),
|
|
55
55
|
saveOutcomes: z.boolean(),
|
|
56
|
+
allowLossBeyondWager: z.boolean().optional().default(false),
|
|
56
57
|
initializeMetadataFromUntrustedUserInput: z
|
|
57
58
|
.function()
|
|
58
59
|
.optional(),
|
|
@@ -119,6 +120,12 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
119
120
|
if (!betConfig) {
|
|
120
121
|
throw new GraphQLError(`Invalid bet kind`);
|
|
121
122
|
}
|
|
123
|
+
if (!betConfig.allowLossBeyondWager) {
|
|
124
|
+
const minProfit = Math.min(...input.outcomes.map((o) => o.profit));
|
|
125
|
+
if (minProfit < -1) {
|
|
126
|
+
throw new GraphQLError(`Loss beyond wager not allowed: outcome profit must be >= -1`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
122
129
|
let initializedMetadata;
|
|
123
130
|
if (betConfig.initializeMetadataFromUntrustedUserInput) {
|
|
124
131
|
const result = betConfig.initializeMetadataFromUntrustedUserInput(input);
|