@moneypot/hub 1.19.14 → 1.19.16

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.
@@ -4,8 +4,8 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Dashboard</title>
7
- <script type="module" crossorigin src="/dashboard/assets/index-BlgWJql2.js"></script>
8
- <link rel="stylesheet" crossorigin href="/dashboard/assets/index-32DtKox_.css">
7
+ <script type="module" crossorigin src="/dashboard/assets/index-QbfKgHTj.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/dashboard/assets/index-Bl5lLFHa.css">
9
9
  </head>
10
10
  <body>
11
11
  <div id="root"></div>
@@ -8,5 +8,6 @@ export interface ServerContext {
8
8
  export declare function createServerContext(overrides?: {
9
9
  superuserDatabaseUrl?: string;
10
10
  postgraphileDatabaseUrl?: string;
11
+ poolMax?: number;
11
12
  }): ServerContext;
12
13
  export declare function closeServerContext(context: ServerContext): Promise<void>;
@@ -8,9 +8,11 @@ export function createServerContext(overrides) {
8
8
  const context = {
9
9
  postgraphilePool: new pg.Pool({
10
10
  connectionString: postgraphileDatabaseUrl,
11
+ max: overrides?.poolMax,
11
12
  }),
12
13
  superuserPool: new pg.Pool({
13
14
  connectionString: superuserDatabaseUrl,
15
+ max: overrides?.poolMax,
14
16
  }),
15
17
  notifier: new DatabaseNotifier(postgraphileDatabaseUrl),
16
18
  };
@@ -56,6 +56,7 @@ export const HubAddCasinoPlugin = makeExtendSchemaPlugin((build) => {
56
56
  throw new GraphQLError("Unauthorized");
57
57
  }
58
58
  assert(is(input));
59
+ logger.info(input, "Input");
59
60
  const { name, baseUrl, graphqlUrl, apiKey } = input;
60
61
  const graphqlClient = new GraphQLClient(graphqlUrl, {
61
62
  headers: {
@@ -68,7 +69,7 @@ export const HubAddCasinoPlugin = makeExtendSchemaPlugin((build) => {
68
69
  .catch((e) => {
69
70
  if (e.cause?.code === "ECONNREFUSED" ||
70
71
  e.cause?.code === "ENOTFOUND") {
71
- throw new GraphQLError(`Cannot connect to graphqlUrl`);
72
+ throw new GraphQLError(`Cannot connect to casino graphql url: ${graphqlUrl}`);
72
73
  }
73
74
  throw e;
74
75
  });
@@ -145,6 +146,9 @@ export const HubAddCasinoPlugin = makeExtendSchemaPlugin((build) => {
145
146
  pool: superuserPool,
146
147
  });
147
148
  return casino.id;
149
+ }).catch((e) => {
150
+ logger.error(e, "Error adding casino");
151
+ throw e;
148
152
  });
149
153
  });
150
154
  return object({
@@ -26,7 +26,7 @@ export function HubRiskLimitsPlugin({ outcomeBetConfigs, customGameConfigs, }) {
26
26
  mergedConfigs[kind] = customGameConfigs[kind];
27
27
  }
28
28
  }
29
- return extendSchema((build) => {
29
+ return extendSchema(() => {
30
30
  const typeDefs = gql `
31
31
  enum AnyGameKind {
32
32
  ${anyGameKindEnumValues.join("\n")}
@@ -1 +1,8 @@
1
+ import z from "zod/v4";
2
+ export declare const AddCasinoSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ baseUrl: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<URL, string>>, z.ZodTransform<string, URL>>;
5
+ graphqlUrl: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<URL, string>>, z.ZodTransform<string, URL>>;
6
+ apiKey: z.ZodUUID;
7
+ }, z.core.$strict>;
1
8
  export declare const ValidateCasinoFieldsPlugin: GraphileConfig.Plugin;
@@ -23,7 +23,7 @@ const CasinoPatchSchema = z.strictObject({
23
23
  graphqlUrl: v.graphqlUrl().optional(),
24
24
  baseUrl: v.baseUrl().optional(),
25
25
  });
26
- const AddCasinoSchema = z.strictObject({
26
+ export const AddCasinoSchema = z.strictObject({
27
27
  name: z.string().trim().min(1),
28
28
  baseUrl: v.baseUrl(),
29
29
  graphqlUrl: v.graphqlUrl(),
@@ -29,7 +29,7 @@ export declare const requiredPlugins: readonly GraphileConfig.Plugin[];
29
29
  export declare const defaultPlugins: readonly GraphileConfig.Plugin[];
30
30
  import { HubGameConfigPlugin } from "../plugins/hub-game-config-plugin.js";
31
31
  export type HubPlugin = GraphileConfig.Plugin | HubGameConfigPlugin;
32
- export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, }: {
32
+ export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, poolMax, }: {
33
33
  plugins: readonly HubPlugin[];
34
34
  exportSchemaSDLPath?: string;
35
35
  extraPgSchemas: string[];
@@ -38,6 +38,7 @@ export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSche
38
38
  enableChat: boolean;
39
39
  enablePlayground: boolean;
40
40
  postgraphileDatabaseUrl: string;
41
+ poolMax?: number;
41
42
  }): {
42
43
  preset: GraphileConfig.Preset;
43
44
  pgService: GraphileConfig.PgServiceConfiguration<"@dataplan/pg/adaptors/pg">;
@@ -57,7 +57,7 @@ export const defaultPlugins = [
57
57
  ...requiredPlugins,
58
58
  ];
59
59
  import { HubGameConfigPlugin, isHubGameConfigPlugin, expandHubGameConfigPlugin, } from "../plugins/hub-game-config-plugin.js";
60
- export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, }) {
60
+ export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, context, enableChat, enablePlayground, postgraphileDatabaseUrl, poolMax, }) {
61
61
  if (exportSchemaSDLPath) {
62
62
  if (!exportSchemaSDLPath.startsWith("/")) {
63
63
  throw new Error("exportSchemaSDLPath must be an absolute path");
@@ -95,6 +95,7 @@ export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abo
95
95
  const pgService = makePgService({
96
96
  connectionString: postgraphileDatabaseUrl,
97
97
  schemas: [...extraPgSchemas, "hub"],
98
+ poolConfig: poolMax ? { max: poolMax } : undefined,
98
99
  });
99
100
  const preset = {
100
101
  extends: [PostGraphileAmberPreset],
@@ -22,5 +22,6 @@ export type CreateHubServerOptions = {
22
22
  runProcessors: boolean;
23
23
  superuserDatabaseUrl: string;
24
24
  postgraphileDatabaseUrl: string;
25
+ poolMax?: number;
25
26
  };
26
- export declare function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, }: CreateHubServerOptions): HubServer;
27
+ export declare function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, poolMax, }: CreateHubServerOptions): HubServer;
@@ -46,11 +46,12 @@ function createExpressServer(context) {
46
46
  });
47
47
  return app;
48
48
  }
49
- export function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, }) {
49
+ export function createHubServer({ configureApp, plugins, exportSchemaSDLPath, extraPgSchemas, enableChat, enablePlayground, port, runProcessors, superuserDatabaseUrl, postgraphileDatabaseUrl, poolMax, }) {
50
50
  const abortController = new AbortController();
51
51
  const context = createServerContext({
52
52
  superuserDatabaseUrl,
53
53
  postgraphileDatabaseUrl,
54
+ poolMax,
54
55
  });
55
56
  const expressServer = createExpressServer(context);
56
57
  const { preset, pgService } = createPreset({
@@ -62,6 +63,7 @@ export function createHubServer({ configureApp, plugins, exportSchemaSDLPath, ex
62
63
  context,
63
64
  enableChat,
64
65
  enablePlayground,
66
+ poolMax,
65
67
  });
66
68
  const pgl = postgraphile.default(preset);
67
69
  const serv = pgl.createServ(grafserv);
@@ -5,6 +5,7 @@ import { ServerOptions } from "../index.js";
5
5
  export type HubTestServer = {
6
6
  port: number;
7
7
  stop: () => Promise<void>;
8
+ destroy: () => Promise<void>;
8
9
  dbPool: Pool;
9
10
  playgroundCasinoId: string;
10
11
  authenticate: (userId: DbUser["id"], experienceId: DbExperience["id"]) => Promise<{
@@ -1,20 +1,18 @@
1
1
  import { Client, Pool } from "pg";
2
2
  import { randomBytes, randomUUID } from "node:crypto";
3
- import { execSync } from "node:child_process";
3
+ import { exec } from "node:child_process";
4
+ import { promisify } from "node:util";
5
+ const execAsync = promisify(exec);
4
6
  import { DbHashKind, } from "../db/types.js";
5
- import { exactlyOneRow, maybeOneRow, } from "../db/index.js";
7
+ import { exactlyOneRow, maybeOneRow } from "../db/index.js";
6
8
  import { GraphQLClient } from "graphql-request";
7
9
  import { defaultPlugins, runMigrations } from "../index.js";
8
10
  import { createHubServer } from "../server/index.js";
9
- const createdDatabases = new Set();
10
11
  export async function startTestServer({ plugins = [...defaultPlugins], userDatabaseMigrationsPath, databaseName, extraPgSchemas = [], } = {}) {
11
12
  const dbName = databaseName ?? `hub-test-${randomUUID().slice(0, 8)}`;
12
13
  const connectionString = `postgres://postgres@localhost/${dbName}`;
13
14
  try {
14
- execSync(`psql -U postgres -c "CREATE DATABASE \\"${dbName}\\""`, {
15
- stdio: "pipe",
16
- });
17
- createdDatabases.add(dbName);
15
+ await execAsync(`psql -U postgres -c "CREATE DATABASE \\"${dbName}\\""`);
18
16
  }
19
17
  catch (_e) {
20
18
  const pool = new Pool({ connectionString });
@@ -66,13 +64,23 @@ export async function startTestServer({ plugins = [...defaultPlugins], userDatab
66
64
  if (!playgroundCasinoId) {
67
65
  throw new Error("Playground casino not found - migrations may have failed");
68
66
  }
67
+ const stop = async () => {
68
+ await dbPool.end();
69
+ await hubServer.shutdown();
70
+ };
69
71
  return {
70
72
  port,
71
73
  dbPool,
72
74
  playgroundCasinoId,
73
- stop: async () => {
74
- await dbPool.end();
75
- await hubServer.shutdown();
75
+ stop,
76
+ destroy: async () => {
77
+ await stop();
78
+ try {
79
+ await execAsync(`psql -U postgres -c "DROP DATABASE \\"${dbName}\\""`);
80
+ }
81
+ catch (e) {
82
+ console.warn(`Failed to drop test database ${dbName}:`, e);
83
+ }
76
84
  },
77
85
  authenticate: async (userId, experienceId) => {
78
86
  const user = await dbPool
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.19.14",
3
+ "version": "1.19.16",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [