@moneypot/hub 1.4.9 → 1.5.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.
@@ -10,19 +10,21 @@ export const HubUserBalanceByCurrencyPlugin = makeExtendSchemaPlugin((build) =>
10
10
  hubBalanceByCurrency(currency: String!): HubBalance
11
11
  }
12
12
  `,
13
- plans: {
13
+ objects: {
14
14
  HubUser: {
15
- hubBalanceByCurrency: ($record, { $currency }) => {
16
- const $identity = context().get("identity");
17
- const $balances = balanceTable.find();
18
- $balances.where(sql `
15
+ plans: {
16
+ hubBalanceByCurrency: ($record, { $currency }) => {
17
+ const $identity = context().get("identity");
18
+ const $balances = balanceTable.find();
19
+ $balances.where(sql `
19
20
  ${$balances}.currency_key = ${$balances.placeholder($currency, TYPES.text)}
20
21
  AND ${$balances}.user_id = ${$balances.placeholder($record.get("id"), TYPES.uuid)}
21
22
  AND ${$balances}.casino_id = ${$balances.placeholder(access($identity, ["session", "casino_id"]), TYPES.uuid)}
22
23
  AND ${$balances}.experience_id = ${$balances.placeholder(access($identity, ["session", "experience_id"]), TYPES.uuid)}
23
24
  `);
24
- $balances.setFirst(constant(1));
25
- return $balances.single();
25
+ $balances.setFirst(constant(1));
26
+ return $balances.single();
27
+ },
26
28
  },
27
29
  },
28
30
  },
@@ -21,39 +21,40 @@ export const HubWithdrawPlugin = makeExtendSchemaPlugin((build) => {
21
21
  hubWithdraw(input: HubWithdrawInput!): HubWithdrawPayload
22
22
  }
23
23
  `,
24
- plans: {
24
+ objects: {
25
25
  Mutation: {
26
- hubWithdraw(_, { $input }) {
27
- const $identity = context().get("identity");
28
- const $withdrawalRequestId = sideEffect([$input, $identity], ([input, identity]) => {
29
- if (identity?.kind !== "user") {
30
- throw new GraphQLError("You must be logged in");
31
- }
32
- const { session } = identity;
33
- return withPgPoolTransaction(superuserPool, async (pgClient) => {
34
- const { amount, currency } = input;
35
- if (amount < 1) {
36
- throw new GraphQLError("Withdraw amount must be at least 1");
26
+ plans: {
27
+ hubWithdraw(_, { $input }) {
28
+ const $identity = context().get("identity");
29
+ const $withdrawalRequestId = sideEffect([$input, $identity], ([input, identity]) => {
30
+ if (identity?.kind !== "user") {
31
+ throw new GraphQLError("You must be logged in");
37
32
  }
38
- if (!Number.isInteger(amount)) {
39
- throw new GraphQLError("Withdraw amount must be an integer");
40
- }
41
- const dbCurrency = await pgClient
42
- .query({
43
- text: `
33
+ const { session } = identity;
34
+ return withPgPoolTransaction(superuserPool, async (pgClient) => {
35
+ const { amount, currency } = input;
36
+ if (amount < 1) {
37
+ throw new GraphQLError("Withdraw amount must be at least 1");
38
+ }
39
+ if (!Number.isInteger(amount)) {
40
+ throw new GraphQLError("Withdraw amount must be an integer");
41
+ }
42
+ const dbCurrency = await pgClient
43
+ .query({
44
+ text: `
44
45
  SELECT key
45
46
  FROM hub.currency
46
47
  WHERE key = $1 AND casino_id = $2
47
48
  `,
48
- values: [currency, session.casino_id],
49
- })
50
- .then(maybeOneRow);
51
- if (!dbCurrency) {
52
- throw new GraphQLError("Currency not supported");
53
- }
54
- const balance = await pgClient
55
- .query({
56
- text: `
49
+ values: [currency, session.casino_id],
50
+ })
51
+ .then(maybeOneRow);
52
+ if (!dbCurrency) {
53
+ throw new GraphQLError("Currency not supported");
54
+ }
55
+ const balance = await pgClient
56
+ .query({
57
+ text: `
57
58
  select *
58
59
  from hub.balance
59
60
  where currency_key = $1
@@ -63,20 +64,20 @@ export const HubWithdrawPlugin = makeExtendSchemaPlugin((build) => {
63
64
 
64
65
  FOR UPDATE
65
66
  `,
66
- values: [
67
- currency,
68
- session.user_id,
69
- session.casino_id,
70
- session.experience_id,
71
- ],
72
- })
73
- .then(maybeOneRow);
74
- if (!balance || balance.amount < amount) {
75
- throw new GraphQLError("Insufficient funds for withdrawal");
76
- }
77
- const dbWithdrawalRequest = await pgClient
78
- .query({
79
- text: `
67
+ values: [
68
+ currency,
69
+ session.user_id,
70
+ session.casino_id,
71
+ session.experience_id,
72
+ ],
73
+ })
74
+ .then(maybeOneRow);
75
+ if (!balance || balance.amount < amount) {
76
+ throw new GraphQLError("Insufficient funds for withdrawal");
77
+ }
78
+ const dbWithdrawalRequest = await pgClient
79
+ .query({
80
+ text: `
80
81
  insert into hub.withdrawal_request(
81
82
  user_id,
82
83
  experience_id,
@@ -87,17 +88,17 @@ export const HubWithdrawPlugin = makeExtendSchemaPlugin((build) => {
87
88
  values ($1, $2, $3, $4, $5)
88
89
  returning id
89
90
  `,
90
- values: [
91
- session.user_id,
92
- session.experience_id,
93
- session.casino_id,
94
- amount,
95
- currency,
96
- ],
97
- })
98
- .then(exactlyOneRow);
99
- await pgClient.query({
100
- text: `
91
+ values: [
92
+ session.user_id,
93
+ session.experience_id,
94
+ session.casino_id,
95
+ amount,
96
+ currency,
97
+ ],
98
+ })
99
+ .then(exactlyOneRow);
100
+ await pgClient.query({
101
+ text: `
101
102
  update hub.balance
102
103
  set amount = amount - $1
103
104
  where user_id = $2
@@ -105,27 +106,30 @@ export const HubWithdrawPlugin = makeExtendSchemaPlugin((build) => {
105
106
  and currency_key = $4
106
107
  and casino_id = $5
107
108
  `,
108
- values: [
109
- amount,
110
- session.user_id,
111
- session.experience_id,
112
- currency,
113
- session.casino_id,
114
- ],
109
+ values: [
110
+ amount,
111
+ session.user_id,
112
+ session.experience_id,
113
+ currency,
114
+ session.casino_id,
115
+ ],
116
+ });
117
+ return dbWithdrawalRequest.id;
115
118
  });
116
- return dbWithdrawalRequest.id;
117
119
  });
118
- });
119
- return object({
120
- withdrawalRequestId: $withdrawalRequestId,
121
- query: constant(true),
122
- });
120
+ return object({
121
+ withdrawalRequestId: $withdrawalRequestId,
122
+ query: constant(true),
123
+ });
124
+ },
123
125
  },
124
126
  },
125
127
  HubWithdrawPayload: {
126
- withdrawalRequest($data) {
127
- const $id = $data.get("withdrawalRequestId");
128
- return hubWithdrawalRequests.get({ id: $id });
128
+ plans: {
129
+ withdrawalRequest($data) {
130
+ const $id = $data.get("withdrawalRequestId");
131
+ return hubWithdrawalRequests.get({ id: $id });
132
+ },
129
133
  },
130
134
  },
131
135
  },
@@ -13,18 +13,7 @@ export type PluginIdentity = {
13
13
  } | {
14
14
  kind: "operator";
15
15
  };
16
- export type PluginContext = Grafast.Context & {
17
- identity?: PluginIdentity;
18
- abortSignal: AbortSignal;
19
- };
20
16
  export declare const requiredPlugins: readonly GraphileConfig.Plugin[];
21
- declare global {
22
- namespace GraphileBuild {
23
- interface SchemaOptions {
24
- pgDeletedColumnName?: string;
25
- }
26
- }
27
- }
28
17
  export declare const defaultPlugins: readonly GraphileConfig.Plugin[];
29
18
  export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, }: {
30
19
  plugins: readonly GraphileConfig.Plugin[];
@@ -94,7 +94,7 @@ export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abo
94
94
  grafast: {
95
95
  context(ctx, _args) {
96
96
  if (ctx.ws) {
97
- return handleWebsocketContext(ctx) || {};
97
+ return handleWebsocketContext(ctx.ws);
98
98
  }
99
99
  const expressReq = ctx.expressv4.req;
100
100
  const reqIdentity = expressReq.identity;
@@ -137,16 +137,16 @@ export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abo
137
137
  };
138
138
  return preset;
139
139
  }
140
- function getSessionIdFromWebsocketCtx(ctx) {
141
- const value = Object.entries(ctx.ws.connectionParams).find(([key]) => key.toLowerCase() === "authorization")?.[1];
140
+ function getSessionIdFromWebsocketCtx(ws) {
141
+ const value = ws.normalizedConnectionParams?.authorization;
142
142
  if (typeof value !== "string") {
143
143
  return "";
144
144
  }
145
145
  const uuid = value.slice("session:".length);
146
146
  return isUuid(uuid) ? uuid : "";
147
147
  }
148
- async function handleWebsocketContext(ctx) {
149
- const sessionId = getSessionIdFromWebsocketCtx(ctx);
148
+ async function handleWebsocketContext(ws) {
149
+ const sessionId = getSessionIdFromWebsocketCtx(ws);
150
150
  if (!sessionId) {
151
151
  throw new Error("Unauthorized");
152
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.4.9",
3
+ "version": "1.5.0",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [
@@ -33,7 +33,7 @@
33
33
  "build": "tsc && cp -R src/pg-versions dist/src/ && npm run build-dashboard",
34
34
  "check": "tsc --noEmit && npm run check-dashboard",
35
35
  "check-dashboard": "cd ./dashboard && npm run check",
36
- "lint": "eslint . && npm run lint-dashboard",
36
+ "lint": "eslint --fix . && npm run lint-dashboard",
37
37
  "lint-dashboard": "cd ./dashboard && npm run lint",
38
38
  "prepublishOnly": "npm run build",
39
39
  "codegen": "npx graphql-codegen",
@@ -52,7 +52,7 @@
52
52
  "jose": "^6.0.11",
53
53
  "pg": "^8.12.0",
54
54
  "pg-connection-string": "^2.6.4",
55
- "postgraphile": "^5.0.0-beta.40",
55
+ "postgraphile": "^5.0.0-beta.42",
56
56
  "tsafe": "^1.6.6",
57
57
  "yup": "^1.6.1",
58
58
  "zod": "^3.23.5"
@@ -66,7 +66,7 @@
66
66
  "@types/node": "^22.1.0",
67
67
  "@types/pg": "^8.11.5",
68
68
  "eslint": "^9.8.0",
69
- "globals": "^15.9.0",
69
+ "globals": "^16.0.0",
70
70
  "typescript": "^5.4.5",
71
71
  "typescript-eslint": "^8.0.1"
72
72
  },