@moneypot/hub 1.18.0-dev.3 → 1.18.0-dev.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 +8 -0
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js +2 -3
- package/dist/src/plugins/hub-game-config-plugin.d.ts +15 -0
- package/dist/src/plugins/hub-game-config-plugin.js +25 -0
- package/dist/src/plugins/hub-make-outcome-bet.js +2 -1
- package/dist/src/plugins/hub-risk-limits.js +6 -2
- package/dist/src/server/graphile.config.d.ts +3 -1
- package/dist/src/server/graphile.config.js +14 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,6 +77,14 @@ insert into hub.api_key default values returning key;
|
|
|
77
77
|
|
|
78
78
|
You should always keep your hub server up to date as soon as possible. Never install an old, intermediate version: it may leave you without an automatic upgrade path.
|
|
79
79
|
|
|
80
|
+
### 1.18.x
|
|
81
|
+
|
|
82
|
+
- `MakeOutcomeBetPlugin` replaced by `HubGameConfigPlugin({ outcomeBetConfigs,
|
|
83
|
+
customGameConfigs })`
|
|
84
|
+
- Added graphql query `hubRiskLimits(gameKinds: [DICE])` to get risk limits for
|
|
85
|
+
the game kinds configured in `HubGameConfigPlugin`.
|
|
86
|
+
- This lets experiences display the max payout for each kind of bet.
|
|
87
|
+
|
|
80
88
|
### 1.17.x
|
|
81
89
|
|
|
82
90
|
- Postgres transactions now default to read committed (postgres default)
|
package/dist/src/index.d.ts
CHANGED
|
@@ -17,19 +17,19 @@ declare global {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
export {
|
|
21
|
-
export { HubRiskLimitsPlugin } from "./plugins/hub-risk-limits.js";
|
|
20
|
+
export { HubGameConfigPlugin, type OutcomeBetConfigMap, type OutcomeBetConfig, } from "./plugins/hub-game-config-plugin.js";
|
|
22
21
|
export { type CustomGameConfig, type CustomGameConfigMap, } from "./custom-game-config.js";
|
|
23
22
|
export { validateRisk, type RiskPolicy, type RiskPolicyArgs, type RiskLimits, } from "./risk-policy.js";
|
|
24
23
|
export type PluginContext = Grafast.Context;
|
|
25
|
-
export { defaultPlugins, type PluginIdentity, type UserSessionContext, } from "./server/graphile.config.js";
|
|
24
|
+
export { defaultPlugins, type PluginIdentity, type UserSessionContext, type HubPlugin, } from "./server/graphile.config.js";
|
|
26
25
|
export type ConfigureAppArgs = {
|
|
27
26
|
app: Express;
|
|
28
27
|
superuserPool: ServerContext["superuserPool"];
|
|
29
28
|
};
|
|
29
|
+
import type { HubPlugin } from "./server/graphile.config.js";
|
|
30
30
|
export type ServerOptions = {
|
|
31
31
|
configureApp?: (args: ConfigureAppArgs) => void;
|
|
32
|
-
plugins?: readonly
|
|
32
|
+
plugins?: readonly HubPlugin[];
|
|
33
33
|
extraPgSchemas?: string[];
|
|
34
34
|
exportSchemaSDLPath?: string;
|
|
35
35
|
userDatabaseMigrationsPath?: string;
|
package/dist/src/index.js
CHANGED
|
@@ -6,8 +6,7 @@ import { initializeTransferProcessors } from "./process-transfers/index.js";
|
|
|
6
6
|
import { join } from "path";
|
|
7
7
|
import { logger } from "./logger.js";
|
|
8
8
|
import { createServerContext, closeServerContext, } from "./context.js";
|
|
9
|
-
export {
|
|
10
|
-
export { HubRiskLimitsPlugin } from "./plugins/hub-risk-limits.js";
|
|
9
|
+
export { HubGameConfigPlugin, } from "./plugins/hub-game-config-plugin.js";
|
|
11
10
|
export { validateRisk, } from "./risk-policy.js";
|
|
12
11
|
export { defaultPlugins, } from "./server/graphile.config.js";
|
|
13
12
|
export async function runMigrations(options) {
|
|
@@ -74,7 +73,7 @@ async function initialize(options) {
|
|
|
74
73
|
}
|
|
75
74
|
export async function startAndListen(options) {
|
|
76
75
|
if (options.plugins && options.plugins.some((p) => typeof p === "function")) {
|
|
77
|
-
throw new Error("`plugins` should be an array of
|
|
76
|
+
throw new Error("`plugins` should be an array of HubPlugin but one of the items is a function. Did you forget to call it?");
|
|
78
77
|
}
|
|
79
78
|
if (options.userDatabaseMigrationsPath &&
|
|
80
79
|
!options.userDatabaseMigrationsPath.startsWith("/")) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type OutcomeBetConfig, type OutcomeBetConfigMap } from "./hub-make-outcome-bet.js";
|
|
2
|
+
import { CustomGameConfigMap } from "../custom-game-config.js";
|
|
3
|
+
export type { OutcomeBetConfig, OutcomeBetConfigMap };
|
|
4
|
+
declare const HUB_GAME_CONFIG_PLUGIN_BRAND: unique symbol;
|
|
5
|
+
export type HubGameConfigPlugin = {
|
|
6
|
+
readonly [HUB_GAME_CONFIG_PLUGIN_BRAND]: true;
|
|
7
|
+
readonly outcomeBetConfigs: OutcomeBetConfigMap<string>;
|
|
8
|
+
readonly customGameConfigs?: CustomGameConfigMap<string>;
|
|
9
|
+
};
|
|
10
|
+
export declare function isHubGameConfigPlugin(p: unknown): p is HubGameConfigPlugin;
|
|
11
|
+
export declare function expandHubGameConfigPlugin(config: HubGameConfigPlugin): GraphileConfig.Plugin[];
|
|
12
|
+
export declare function HubGameConfigPlugin<OutcomeBetKind extends string, CustomGameKind extends string = never>({ outcomeBetConfigs, customGameConfigs, }: {
|
|
13
|
+
outcomeBetConfigs: OutcomeBetConfigMap<OutcomeBetKind>;
|
|
14
|
+
customGameConfigs?: CustomGameConfigMap<CustomGameKind>;
|
|
15
|
+
}): HubGameConfigPlugin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MakeOutcomeBetPlugin, } from "./hub-make-outcome-bet.js";
|
|
2
|
+
import { HubRiskLimitsPlugin } from "./hub-risk-limits.js";
|
|
3
|
+
const HUB_GAME_CONFIG_PLUGIN_BRAND = Symbol("HubGameConfigPlugin");
|
|
4
|
+
export function isHubGameConfigPlugin(p) {
|
|
5
|
+
return (typeof p === "object" &&
|
|
6
|
+
p !== null &&
|
|
7
|
+
HUB_GAME_CONFIG_PLUGIN_BRAND in p &&
|
|
8
|
+
p[HUB_GAME_CONFIG_PLUGIN_BRAND] === true);
|
|
9
|
+
}
|
|
10
|
+
export function expandHubGameConfigPlugin(config) {
|
|
11
|
+
return [
|
|
12
|
+
MakeOutcomeBetPlugin({ outcomeBetConfigs: config.outcomeBetConfigs }),
|
|
13
|
+
HubRiskLimitsPlugin({
|
|
14
|
+
outcomeBetConfigs: config.outcomeBetConfigs,
|
|
15
|
+
customGameConfigs: config.customGameConfigs,
|
|
16
|
+
}),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
export function HubGameConfigPlugin({ outcomeBetConfigs, customGameConfigs, }) {
|
|
20
|
+
return {
|
|
21
|
+
[HUB_GAME_CONFIG_PLUGIN_BRAND]: true,
|
|
22
|
+
outcomeBetConfigs,
|
|
23
|
+
customGameConfigs,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -71,11 +71,12 @@ const BetConfigsSchema = z.record(BetKindSchema, z.object({
|
|
|
71
71
|
export function MakeOutcomeBetPlugin({ outcomeBetConfigs, }) {
|
|
72
72
|
BetConfigsSchema.parse(outcomeBetConfigs);
|
|
73
73
|
const outcomeBetKinds = Object.keys(outcomeBetConfigs);
|
|
74
|
+
const outcomeBetKindEnumValues = outcomeBetKinds.length > 0 ? outcomeBetKinds : ["_NONE"];
|
|
74
75
|
return extendSchema((build) => {
|
|
75
76
|
const outcomeBetTable = build.input.pgRegistry.pgResources.hub_outcome_bet;
|
|
76
77
|
const typeDefs = gql `
|
|
77
78
|
enum OutcomeBetKind {
|
|
78
|
-
${
|
|
79
|
+
${outcomeBetKindEnumValues.join("\n")}
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
input HubMakeOutcomeBetInput {
|
|
@@ -16,6 +16,7 @@ export function HubRiskLimitsPlugin({ outcomeBetConfigs, customGameConfigs, }) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
const anyGameKinds = [...outcomeBetKinds, ...customGameKinds];
|
|
19
|
+
const anyGameKindEnumValues = anyGameKinds.length > 0 ? anyGameKinds : ["_NONE"];
|
|
19
20
|
const mergedConfigs = {};
|
|
20
21
|
for (const kind of outcomeBetKinds) {
|
|
21
22
|
mergedConfigs[kind] = outcomeBetConfigs[kind];
|
|
@@ -28,7 +29,7 @@ export function HubRiskLimitsPlugin({ outcomeBetConfigs, customGameConfigs, }) {
|
|
|
28
29
|
return extendSchema((build) => {
|
|
29
30
|
const typeDefs = gql `
|
|
30
31
|
enum AnyGameKind {
|
|
31
|
-
${
|
|
32
|
+
${anyGameKindEnumValues.join("\n")}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
${customGameKinds.length > 0
|
|
@@ -70,10 +71,13 @@ export function HubRiskLimitsPlugin({ outcomeBetConfigs, customGameConfigs, }) {
|
|
|
70
71
|
throw new GraphQLError("Duplicate game kinds not allowed");
|
|
71
72
|
}
|
|
72
73
|
for (const kind of inputGameKinds) {
|
|
73
|
-
if (!mergedConfigs[kind]) {
|
|
74
|
+
if (kind === "_NONE" || !mergedConfigs[kind]) {
|
|
74
75
|
throw new GraphQLError(`Invalid game kind: ${kind}`);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
78
|
+
if (anyGameKinds.length === 0) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
77
81
|
const dbHouseBankrolls = await dbGetHouseBankrolls(superuserPool, {
|
|
78
82
|
casinoId: identity.session.casino_id,
|
|
79
83
|
});
|
|
@@ -27,8 +27,10 @@ export type OurPgSettings = {
|
|
|
27
27
|
};
|
|
28
28
|
export declare const requiredPlugins: readonly GraphileConfig.Plugin[];
|
|
29
29
|
export declare const defaultPlugins: readonly GraphileConfig.Plugin[];
|
|
30
|
+
import { HubGameConfigPlugin } from "../plugins/hub-game-config-plugin.js";
|
|
31
|
+
export type HubPlugin = GraphileConfig.Plugin | HubGameConfigPlugin;
|
|
30
32
|
export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, }: {
|
|
31
|
-
plugins: readonly
|
|
33
|
+
plugins: readonly HubPlugin[];
|
|
32
34
|
exportSchemaSDLPath?: string;
|
|
33
35
|
extraPgSchemas: string[];
|
|
34
36
|
abortSignal: AbortSignal;
|
|
@@ -56,6 +56,7 @@ export const defaultPlugins = [
|
|
|
56
56
|
HubPreimageHashFieldPlugin,
|
|
57
57
|
customPgOmitArchivedPlugin("deleted"),
|
|
58
58
|
];
|
|
59
|
+
import { HubGameConfigPlugin, isHubGameConfigPlugin, expandHubGameConfigPlugin, } from "../plugins/hub-game-config-plugin.js";
|
|
59
60
|
export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, }) {
|
|
60
61
|
if (exportSchemaSDLPath) {
|
|
61
62
|
if (!exportSchemaSDLPath.startsWith("/")) {
|
|
@@ -66,9 +67,20 @@ export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abo
|
|
|
66
67
|
}
|
|
67
68
|
logger.info(`Will save generated graphql schema to ${exportSchemaSDLPath}`);
|
|
68
69
|
}
|
|
69
|
-
const
|
|
70
|
+
const pluginsWithDefault = plugins.some(isHubGameConfigPlugin)
|
|
71
|
+
? plugins
|
|
72
|
+
: [...plugins, HubGameConfigPlugin({ outcomeBetConfigs: {} })];
|
|
73
|
+
const mutablePlugins = [];
|
|
74
|
+
for (const p of pluginsWithDefault) {
|
|
75
|
+
if (isHubGameConfigPlugin(p)) {
|
|
76
|
+
mutablePlugins.push(...expandHubGameConfigPlugin(p));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
mutablePlugins.push(p);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
70
82
|
for (const requiredPlugin of requiredPlugins) {
|
|
71
|
-
if (!
|
|
83
|
+
if (!mutablePlugins.some((plugin) => plugin === requiredPlugin)) {
|
|
72
84
|
logger.warn(`Adding required plugin "${requiredPlugin.name}"`);
|
|
73
85
|
mutablePlugins.unshift(requiredPlugin);
|
|
74
86
|
}
|