@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.
- package/README.md +8 -1
- package/dist/src/hash-chain/index.d.ts +1 -1
- package/dist/src/hash-chain/index.js +1 -1
- package/dist/src/hash-chain/plugins/hub-bad-hash-chain-error.js +7 -5
- package/dist/src/hash-chain/plugins/hub-create-hash-chain.js +42 -40
- package/dist/src/hash-chain/plugins/hub-user-active-hash-chain.js +19 -17
- package/dist/src/hash-chain/util.d.ts +1 -3
- package/dist/src/hash-chain/util.js +2 -3
- package/dist/src/index.d.ts +1 -1
- package/dist/src/plugins/hub-add-casino.js +89 -87
- package/dist/src/plugins/hub-authenticate.js +120 -118
- package/dist/src/plugins/hub-balance-alert.js +23 -19
- package/dist/src/plugins/hub-claim-faucet.js +43 -39
- package/dist/src/plugins/hub-current-x.js +43 -41
- package/dist/src/plugins/hub-make-outcome-bet.js +230 -227
- package/dist/src/plugins/hub-put-alert.js +38 -34
- package/dist/src/plugins/hub-user-balance-by-currency.js +9 -7
- package/dist/src/plugins/hub-withdraw.js +72 -68
- package/dist/src/server/graphile.config.d.ts +0 -11
- package/dist/src/server/graphile.config.js +5 -5
- package/package.json +4 -4
|
@@ -10,19 +10,21 @@ export const HubUserBalanceByCurrencyPlugin = makeExtendSchemaPlugin((build) =>
|
|
|
10
10
|
hubBalanceByCurrency(currency: String!): HubBalance
|
|
11
11
|
}
|
|
12
12
|
`,
|
|
13
|
-
|
|
13
|
+
objects: {
|
|
14
14
|
HubUser: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
24
|
+
objects: {
|
|
25
25
|
Mutation: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
120
|
+
return object({
|
|
121
|
+
withdrawalRequestId: $withdrawalRequestId,
|
|
122
|
+
query: constant(true),
|
|
123
|
+
});
|
|
124
|
+
},
|
|
123
125
|
},
|
|
124
126
|
},
|
|
125
127
|
HubWithdrawPayload: {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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(
|
|
141
|
-
const value =
|
|
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(
|
|
149
|
-
const sessionId = getSessionIdFromWebsocketCtx(
|
|
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.
|
|
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.
|
|
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": "^
|
|
69
|
+
"globals": "^16.0.0",
|
|
70
70
|
"typescript": "^5.4.5",
|
|
71
71
|
"typescript-eslint": "^8.0.1"
|
|
72
72
|
},
|