@moneypot/hub 1.18.3 → 1.18.6
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/dist/dashboard/assets/index-BlgWJql2.js +418 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/src/pg-sql2.d.ts +1 -0
- package/dist/src/pg-sql2.js +1 -0
- package/dist/src/pg-versions/001-schema.sql +23 -70
- package/dist/src/pg-versions/002-balance-id.sql +0 -3
- package/dist/src/pg-versions/003-take-request.sql +25 -47
- package/dist/src/pg-versions/004-rls-scope-to-experience.sql +8 -21
- package/dist/src/pg-versions/005-hash-chain.sql +8 -21
- package/dist/src/pg-versions/006-outcome-bet.sql +0 -11
- package/dist/src/pg-versions/007-notify-put.sql +1 -3
- package/dist/src/pg-versions/008-outcome-bet-hash.sql +5 -19
- package/dist/src/pg-versions/009-take-request-retry.sql +1 -2
- package/dist/src/pg-versions/011-audit-log.sql +11 -24
- package/dist/src/pg-versions/012-playground.sql +3 -11
- package/dist/src/pg-versions/013-chat.sql +8 -70
- package/dist/src/plugins/id-to-node-id.js +0 -3
- package/package.json +12 -8
- package/dist/dashboard/assets/index-DGxc3Ja9.js +0 -412
|
@@ -9,31 +9,22 @@ create type hub.outcome as (
|
|
|
9
9
|
create table hub.outcome_bet (
|
|
10
10
|
id uuid primary key default hub_hidden.uuid_generate_v7(),
|
|
11
11
|
|
|
12
|
-
-- Operator-given kind like "WHEEL", "PLINKO",
|
|
13
|
-
-- Probably not worth using a postgres enum here since they are not flexible.
|
|
14
12
|
kind text not null,
|
|
15
13
|
|
|
16
14
|
user_id uuid not null references hub.user(id),
|
|
17
15
|
experience_id uuid not null references hub.experience(id),
|
|
18
16
|
casino_id uuid not null references hub.casino(id),
|
|
19
17
|
|
|
20
|
-
-- provably fair hash chain
|
|
21
18
|
hash_chain_id uuid not null references hub.hash_chain(id),
|
|
22
19
|
|
|
23
20
|
currency_key text not null,
|
|
24
21
|
wager float not null,
|
|
25
22
|
|
|
26
|
-
-- -1 = lose wager, -2 = lose 2x wager
|
|
27
|
-
-- 0.5 = 1.5x wager, 1 = 2x wager
|
|
28
|
-
-- In other words, a multiplier in a game might say "2.5x",
|
|
29
|
-
-- but the profit is multiplier-1 = 1.5 profit
|
|
30
23
|
profit float not null,
|
|
31
24
|
|
|
32
|
-
-- null when no outcomes saved
|
|
33
25
|
outcome_idx smallint null check (outcome_idx between 0 and array_length(outcomes,1)-1),
|
|
34
26
|
outcomes hub.outcome[] not null default '{}',
|
|
35
27
|
|
|
36
|
-
-- Operator-provided data per bet
|
|
37
28
|
metadata jsonb not null default '{}',
|
|
38
29
|
|
|
39
30
|
foreign key (currency_key, casino_id) references hub.currency(key, casino_id)
|
|
@@ -45,11 +36,9 @@ create index outcome_bet_casino_id_idx on hub.outcome_bet(casino_id);
|
|
|
45
36
|
create index outcome_bet_kind_idx on hub.outcome_bet(kind);
|
|
46
37
|
create index outcome_bet_hash_chain_id_idx on hub.outcome_bet(hash_chain_id);
|
|
47
38
|
|
|
48
|
-
-- GRANT
|
|
49
39
|
|
|
50
40
|
grant select on hub.outcome_bet to app_postgraphile;
|
|
51
41
|
|
|
52
|
-
-- RLS
|
|
53
42
|
|
|
54
43
|
alter table hub.outcome_bet enable row level security;
|
|
55
44
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
-- Let experience know when user successfully puts money into their balance
|
|
2
|
-
-- A put is a successful deposit
|
|
3
1
|
|
|
4
2
|
CREATE OR REPLACE FUNCTION notify_put() RETURNS TRIGGER AS $$
|
|
5
3
|
BEGIN
|
|
6
|
-
PERFORM pg_notify('hub:user:' || NEW.user_id || ':put',
|
|
4
|
+
PERFORM pg_notify('hub:user:' || NEW.user_id || ':put',
|
|
7
5
|
json_build_object(
|
|
8
6
|
'currency_key', NEW.currency_key,
|
|
9
7
|
'experience_id', NEW.experience_id,
|
|
@@ -1,34 +1,25 @@
|
|
|
1
|
-
-- Migration: Add hash_id to hub.outcome_bet table
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
ALTER TABLE hub.outcome_bet
|
|
2
|
+
ALTER TABLE hub.outcome_bet
|
|
5
3
|
ADD COLUMN hash_id uuid REFERENCES hub.hash(id);
|
|
6
4
|
|
|
7
|
-
-- Index
|
|
8
5
|
CREATE INDEX outcome_bet_hash_id_idx ON hub.outcome_bet(hash_id);
|
|
9
6
|
|
|
10
|
-
-- Update existing rows to set hash_id based on hash_chain_id
|
|
11
|
-
-- This uses a window function to assign row numbers within each hash_chain_id group
|
|
12
|
-
-- ordered by the bet creation time (id)
|
|
13
7
|
WITH bet_iterations AS (
|
|
14
|
-
SELECT
|
|
8
|
+
SELECT
|
|
15
9
|
ob.id,
|
|
16
10
|
ob.hash_chain_id,
|
|
17
11
|
hc.max_iteration,
|
|
18
|
-
-- Row number starting from 1 for each hash_chain_id group
|
|
19
|
-
-- Ordered by id (which is uuid v7, so it's time-ordered)
|
|
20
12
|
ROW_NUMBER() OVER (PARTITION BY ob.hash_chain_id ORDER BY ob.id) as bet_sequence
|
|
21
13
|
FROM hub.outcome_bet ob
|
|
22
14
|
JOIN hub.hash_chain hc ON hc.id = ob.hash_chain_id
|
|
23
15
|
),
|
|
24
16
|
hash_mapping AS (
|
|
25
|
-
SELECT
|
|
17
|
+
SELECT
|
|
26
18
|
bi.id as bet_id,
|
|
27
19
|
h.id as hash_id
|
|
28
20
|
FROM bet_iterations bi
|
|
29
|
-
JOIN hub.hash h ON
|
|
30
|
-
h.hash_chain_id = bi.hash_chain_id AND
|
|
31
|
-
-- Calculate the iteration: max_iteration - bet_sequence
|
|
21
|
+
JOIN hub.hash h ON
|
|
22
|
+
h.hash_chain_id = bi.hash_chain_id AND
|
|
32
23
|
h.iteration = bi.max_iteration - bi.bet_sequence
|
|
33
24
|
WHERE h.kind = 'INTERMEDIATE'
|
|
34
25
|
)
|
|
@@ -37,21 +28,16 @@ SET hash_id = hm.hash_id
|
|
|
37
28
|
FROM hash_mapping hm
|
|
38
29
|
WHERE ob.id = hm.bet_id;
|
|
39
30
|
|
|
40
|
-
-- Make hash_id NOT NULL after populating it
|
|
41
31
|
ALTER TABLE hub.outcome_bet ALTER COLUMN hash_id SET NOT NULL;
|
|
42
32
|
|
|
43
|
-
-- Add client_seed column to hash table
|
|
44
33
|
ALTER TABLE hub.hash ADD COLUMN client_seed text null;
|
|
45
34
|
|
|
46
|
-
-- Update hash table with client_seed from hash_chain for each outcome_bet
|
|
47
35
|
UPDATE hub.hash h
|
|
48
36
|
SET client_seed = hc.client_seed
|
|
49
37
|
FROM hub.outcome_bet ob
|
|
50
38
|
JOIN hub.hash_chain hc ON hc.id = ob.hash_chain_id
|
|
51
39
|
WHERE h.id = ob.hash_id;
|
|
52
40
|
|
|
53
|
-
-- Drop hash chain id
|
|
54
41
|
ALTER TABLE hub.outcome_bet DROP COLUMN hash_chain_id;
|
|
55
42
|
|
|
56
|
-
-- Drop hash_chain.client_seed
|
|
57
43
|
ALTER TABLE hub.hash_chain DROP COLUMN client_seed;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
ALTER TABLE hub.take_request
|
|
2
|
-
-- How many times we've tried to complete the transfer on MP (completeTransfer calls)
|
|
1
|
+
ALTER TABLE hub.take_request
|
|
3
2
|
ADD COLUMN completion_attempt_count int default 0,
|
|
4
3
|
ADD COLUMN insufficient_balance_error boolean default false,
|
|
5
4
|
ADD COLUMN debug text;
|
|
@@ -5,9 +5,6 @@ create table hub.audit_log (
|
|
|
5
5
|
balance_id uuid null references hub.balance(id),
|
|
6
6
|
bankroll_id uuid null references hub.bankroll(id),
|
|
7
7
|
|
|
8
|
-
-- how much?
|
|
9
|
-
-- we require all three fields to force callsite to assert its assumptions and
|
|
10
|
-
-- catch potential desync between assumption and data
|
|
11
8
|
balance_old float null,
|
|
12
9
|
balance_new float null,
|
|
13
10
|
balance_delta float null,
|
|
@@ -16,38 +13,31 @@ create table hub.audit_log (
|
|
|
16
13
|
bankroll_new float null,
|
|
17
14
|
bankroll_delta float null,
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
action text not null, -- hub:init, hub:deposit, hub:take_request:pending, hub:take_request:refund, hub:outcome_bet, etc.
|
|
16
|
+
action text not null,
|
|
21
17
|
metadata jsonb null,
|
|
22
18
|
|
|
23
|
-
-- link to the item that caused the change, i.e. deposit, payout, send, take, etc.
|
|
24
19
|
ref_type text null,
|
|
25
|
-
ref_id text null,
|
|
20
|
+
ref_id text null,
|
|
26
21
|
|
|
27
|
-
-- Ensure we have at least one type of change
|
|
28
22
|
CHECK (balance_id IS NOT NULL OR bankroll_id IS NOT NULL),
|
|
29
|
-
|
|
30
|
-
-- If balance_id is set, all balance columns must be filled
|
|
23
|
+
|
|
31
24
|
CHECK (
|
|
32
|
-
(balance_id IS NULL) OR
|
|
25
|
+
(balance_id IS NULL) OR
|
|
33
26
|
(balance_old IS NOT NULL AND balance_new IS NOT NULL AND balance_delta IS NOT NULL)
|
|
34
27
|
),
|
|
35
|
-
|
|
36
|
-
-- If bankroll_id is set, all bankroll columns must be filled
|
|
28
|
+
|
|
37
29
|
CHECK (
|
|
38
|
-
(bankroll_id IS NULL) OR
|
|
30
|
+
(bankroll_id IS NULL) OR
|
|
39
31
|
(bankroll_old IS NOT NULL AND bankroll_new IS NOT NULL AND bankroll_delta IS NOT NULL)
|
|
40
32
|
),
|
|
41
|
-
|
|
42
|
-
-- If balance_id is null, all balance columns must be null
|
|
33
|
+
|
|
43
34
|
CHECK (
|
|
44
|
-
(balance_id IS NOT NULL) OR
|
|
35
|
+
(balance_id IS NOT NULL) OR
|
|
45
36
|
(balance_old IS NULL AND balance_new IS NULL AND balance_delta IS NULL)
|
|
46
37
|
),
|
|
47
|
-
|
|
48
|
-
-- If bankroll_id is null, all bankroll columns must be null
|
|
38
|
+
|
|
49
39
|
CHECK (
|
|
50
|
-
(bankroll_id IS NOT NULL) OR
|
|
40
|
+
(bankroll_id IS NOT NULL) OR
|
|
51
41
|
(bankroll_old IS NULL AND bankroll_new IS NULL AND bankroll_delta IS NULL)
|
|
52
42
|
)
|
|
53
43
|
);
|
|
@@ -57,14 +47,13 @@ create index on hub.audit_log(bankroll_id) where bankroll_id is not null;
|
|
|
57
47
|
|
|
58
48
|
|
|
59
49
|
|
|
60
|
-
-- seed audit_log with current balances
|
|
61
50
|
insert into hub.audit_log (
|
|
62
51
|
bankroll_id,
|
|
63
52
|
bankroll_old,
|
|
64
53
|
bankroll_new,
|
|
65
54
|
bankroll_delta,
|
|
66
55
|
action
|
|
67
|
-
)
|
|
56
|
+
)
|
|
68
57
|
select
|
|
69
58
|
b.id,
|
|
70
59
|
b.amount,
|
|
@@ -74,7 +63,6 @@ select
|
|
|
74
63
|
from hub.bankroll b;
|
|
75
64
|
|
|
76
65
|
|
|
77
|
-
-- seed audit_log with current balances
|
|
78
66
|
insert into hub.audit_log (
|
|
79
67
|
balance_id,
|
|
80
68
|
balance_old,
|
|
@@ -92,7 +80,6 @@ from hub.balance b
|
|
|
92
80
|
join hub.user u on u.id = b.user_id
|
|
93
81
|
;
|
|
94
82
|
|
|
95
|
-
-- This view adds convenience fields that can be derived from the row data.
|
|
96
83
|
create view hub.audit_log_view as
|
|
97
84
|
select
|
|
98
85
|
al.*,
|
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
-- insert a global playground app.casino record that all playground users and experiences are associated with
|
|
2
1
|
|
|
3
|
-
-- add is_playground boolean to the casino table with default=false for existing casinos
|
|
4
2
|
alter table hub.casino add column is_playground boolean not null default false;
|
|
5
3
|
|
|
6
4
|
insert into hub.casino (name, base_url, graphql_url, is_playground)
|
|
7
5
|
values (
|
|
8
|
-
'Playground',
|
|
9
|
-
'https://not-found.moneypot.com',
|
|
10
|
-
'https://not-found.moneypot.com/graphql',
|
|
6
|
+
'Playground',
|
|
7
|
+
'https://not-found.moneypot.com',
|
|
8
|
+
'https://not-found.moneypot.com/graphql',
|
|
11
9
|
true
|
|
12
10
|
);
|
|
13
11
|
|
|
14
|
-
-- make it so that only one row can have is_playground=true and the rest are false
|
|
15
12
|
CREATE UNIQUE INDEX single_playground_casino_idx
|
|
16
13
|
ON hub.casino ((true))
|
|
17
14
|
WHERE is_playground;
|
|
18
15
|
|
|
19
|
-
-- insert HOUSE hub.currency for casino
|
|
20
16
|
insert into hub.currency (key, casino_id, display_unit_name, display_unit_scale)
|
|
21
17
|
select 'HOUSE', (select id from hub.casino where is_playground = true limit 1), 'token', 1;
|
|
22
18
|
|
|
23
|
-
-- insert 10_000_000 HOUSE bankroll for casino
|
|
24
19
|
insert into hub.bankroll (casino_id, currency_key, amount)
|
|
25
20
|
select (select id from hub.casino where is_playground = true limit 1), 'HOUSE', 10_000_000;
|
|
26
21
|
|
|
27
|
-
-- Update the notify_new_casino trigger function to exclude playground casinos
|
|
28
|
-
-- TODO: Seems weird that this even is a trigger... oh well, just porting it for now
|
|
29
22
|
CREATE OR REPLACE FUNCTION notify_new_casino()
|
|
30
23
|
RETURNS TRIGGER AS $$
|
|
31
24
|
BEGIN
|
|
32
|
-
-- Only notify for non-playground casinos
|
|
33
25
|
IF NEW.is_playground = false THEN
|
|
34
26
|
PERFORM pg_notify('hub:new_casino', json_build_object(
|
|
35
27
|
'id', NEW.id
|
|
@@ -1,44 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
-- Quick revert:
|
|
4
|
-
-- drop table if exists hub.chat_message;
|
|
5
|
-
-- drop view if exists hub.active_chat_mute;
|
|
6
|
-
-- drop table if exists hub.chat_mute;
|
|
7
|
-
-- drop table if exists hub.chat_rate_bucket;
|
|
8
|
-
-- drop table if exists hub.chat_mod;
|
|
9
|
-
-- drop type if exists hub.chat_message_type;
|
|
10
|
-
-- alter table hub.experience drop column if exists user_id;
|
|
11
|
-
-- alter table hub.user drop column if exists client_id;
|
|
12
|
-
-- alter table hub.experience drop column if exists client_id;
|
|
13
|
-
|
|
14
|
-
-- New helper function for RLS so we don't have to do a subquery
|
|
1
|
+
|
|
2
|
+
|
|
15
3
|
create or replace function hub_hidden.is_experience_owner() returns boolean as $$
|
|
16
4
|
select nullif(current_setting('session.is_experience_owner', true), '') = '1';
|
|
17
5
|
$$ language sql stable;
|
|
18
6
|
|
|
19
|
-
-- We want to know which hub.user is the MP owner of the hub.experience
|
|
20
|
-
-- Ideally it would be not-null but we can't do that in this migration
|
|
21
|
-
-- since that info must be queried from MP.
|
|
22
7
|
alter table hub.experience add column user_id uuid null references hub.user(id);
|
|
23
8
|
|
|
24
9
|
create type hub.chat_message_type as enum ('user', 'system');
|
|
25
10
|
|
|
26
|
-
-- chat message type is 'user' or 'system'
|
|
27
|
-
-- system messages don't have a user_id
|
|
28
11
|
create table hub.chat_message (
|
|
29
|
-
-- uuidv7 has creation timestamp in it
|
|
30
12
|
id uuid primary key default hub_hidden.uuid_generate_v7(),
|
|
31
13
|
|
|
32
|
-
-- fks
|
|
33
14
|
casino_id uuid not null references hub.casino(id),
|
|
34
15
|
experience_id uuid not null references hub.experience(id),
|
|
35
|
-
-- system messages don't have a user_id
|
|
36
16
|
user_id uuid null references hub.user(id),
|
|
37
17
|
|
|
38
18
|
type hub.chat_message_type not null,
|
|
39
19
|
|
|
40
|
-
|
|
41
|
-
client_id uuid not null, -- idempotent id
|
|
20
|
+
client_id uuid not null,
|
|
42
21
|
body text not null,
|
|
43
22
|
hidden_at timestamptz null,
|
|
44
23
|
|
|
@@ -47,12 +26,10 @@ create table hub.chat_message (
|
|
|
47
26
|
)
|
|
48
27
|
);
|
|
49
28
|
|
|
50
|
-
-- fk indexes
|
|
51
29
|
create index chat_message_casino_id_idx on hub.chat_message(casino_id);
|
|
52
30
|
create index chat_message_user_id_idx on hub.chat_message(user_id);
|
|
53
31
|
create index chat_message_experience_id_idx on hub.chat_message(experience_id);
|
|
54
32
|
|
|
55
|
-
-- support idempotency
|
|
56
33
|
create unique index chat_idempotent_user_message_idx
|
|
57
34
|
on hub.chat_message(casino_id, experience_id, user_id, client_id)
|
|
58
35
|
where type = 'user';
|
|
@@ -60,43 +37,35 @@ create unique index chat_idempotent_system_message_idx
|
|
|
60
37
|
on hub.chat_message(casino_id, experience_id, client_id)
|
|
61
38
|
where type = 'system';
|
|
62
39
|
|
|
63
|
-
-- append-only table
|
|
64
40
|
create table hub.chat_mute (
|
|
65
41
|
id uuid primary key default hub_hidden.uuid_generate_v7(),
|
|
66
42
|
casino_id uuid not null references hub.casino(id),
|
|
67
43
|
experience_id uuid not null references hub.experience(id),
|
|
68
44
|
user_id uuid not null references hub.user(id),
|
|
69
45
|
expired_at timestamptz null,
|
|
70
|
-
-- set on unmute
|
|
71
46
|
revoked_at timestamptz null,
|
|
72
47
|
reason text null
|
|
73
48
|
);
|
|
74
49
|
|
|
75
|
-
-- fk indexes
|
|
76
50
|
create index chat_mute_casino_id_idx on hub.chat_mute(casino_id);
|
|
77
51
|
create index chat_mute_user_id_idx on hub.chat_mute(user_id);
|
|
78
52
|
create index chat_mute_experience_id_idx on hub.chat_mute(experience_id);
|
|
79
53
|
|
|
80
|
-
-- One unrevoked row per key; expiry handled in code/view.
|
|
81
54
|
create unique index if not exists chat_mute_one_unrevoked_per_key
|
|
82
55
|
on hub.chat_mute (casino_id, experience_id, user_id)
|
|
83
56
|
where revoked_at is null;
|
|
84
57
|
|
|
85
|
-
-- "Active" means not revoked AND not expired (null = indefinite).
|
|
86
|
-
-- order by id desc determines which key is picked for `distinct on`: the latest one
|
|
87
58
|
create or replace view hub.active_chat_mute as
|
|
88
59
|
select distinct on (casino_id, experience_id, user_id) *
|
|
89
60
|
from hub.chat_mute
|
|
90
61
|
where revoked_at is null
|
|
91
62
|
and (expired_at is null or expired_at > now())
|
|
92
|
-
order by casino_id, experience_id, user_id, id desc;
|
|
63
|
+
order by casino_id, experience_id, user_id, id desc;
|
|
93
64
|
|
|
94
|
-
-- for active chat mute lookup
|
|
95
65
|
create index if not exists chat_mute_lookup_idx
|
|
96
66
|
on hub.chat_mute (casino_id, experience_id, user_id)
|
|
97
67
|
where revoked_at is null;
|
|
98
68
|
|
|
99
|
-
-- not exposed to graphql
|
|
100
69
|
create table hub.chat_rate_bucket (
|
|
101
70
|
id uuid primary key default hub_hidden.uuid_generate_v7(),
|
|
102
71
|
casino_id uuid not null references hub.casino(id),
|
|
@@ -108,14 +77,12 @@ create table hub.chat_rate_bucket (
|
|
|
108
77
|
count int not null default 0
|
|
109
78
|
);
|
|
110
79
|
|
|
111
|
-
-- fk indexes
|
|
112
80
|
create index chat_rate_bucket_casino_id_idx on hub.chat_rate_bucket(casino_id);
|
|
113
81
|
create index chat_rate_bucket_user_id_idx on hub.chat_rate_bucket(user_id);
|
|
114
82
|
create index chat_rate_bucket_experience_id_idx on hub.chat_rate_bucket(experience_id);
|
|
115
83
|
|
|
116
84
|
create unique index chat_rate_bucket_window_idx on hub.chat_rate_bucket(casino_id, experience_id, user_id, window_seconds, bucket_start);
|
|
117
85
|
|
|
118
|
-
-- not exposed to graphql
|
|
119
86
|
create table hub.chat_mod (
|
|
120
87
|
id uuid primary key default hub_hidden.uuid_generate_v7(),
|
|
121
88
|
casino_id uuid not null references hub.casino(id),
|
|
@@ -123,51 +90,40 @@ create table hub.chat_mod (
|
|
|
123
90
|
user_id uuid not null references hub.user(id)
|
|
124
91
|
);
|
|
125
92
|
|
|
126
|
-
-- fk indexes
|
|
127
93
|
create index chat_mod_casino_id_idx on hub.chat_mod(casino_id);
|
|
128
94
|
create index chat_mod_user_id_idx on hub.chat_mod(user_id);
|
|
129
95
|
create index chat_mod_experience_id_idx on hub.chat_mod(experience_id);
|
|
130
|
-
-- a user can only be a chat mod once per experience
|
|
131
96
|
create unique index chat_mod_unique_idx on hub.chat_mod(casino_id, experience_id, user_id);
|
|
132
97
|
|
|
133
|
-
-- grant
|
|
134
98
|
grant select on hub.chat_message to app_postgraphile;
|
|
135
99
|
grant select on hub.chat_mute to app_postgraphile;
|
|
136
100
|
grant select on hub.chat_mod to app_postgraphile;
|
|
137
101
|
|
|
138
|
-
-- rls
|
|
139
102
|
alter table hub.chat_message enable row level security;
|
|
140
103
|
alter table hub.chat_mute enable row level security;
|
|
141
104
|
alter table hub.chat_mod enable row level security;
|
|
142
105
|
|
|
143
106
|
drop policy if exists select_chat_message on hub.chat_message;
|
|
144
107
|
create policy select_chat_message on hub.chat_message for select using (
|
|
145
|
-
|
|
146
|
-
hub_hidden.is_operator()
|
|
108
|
+
hub_hidden.is_operator()
|
|
147
109
|
|
|
148
|
-
-- normal users can only see non-hidden rows in the current experience
|
|
149
110
|
or (
|
|
150
|
-
hidden_at is null
|
|
111
|
+
hidden_at is null
|
|
151
112
|
and experience_id = hub_hidden.current_experience_id()
|
|
152
113
|
and casino_id = hub_hidden.current_casino_id()
|
|
153
114
|
)
|
|
154
115
|
|
|
155
|
-
-- experience owner can see all messages no matter hidden status
|
|
156
116
|
or hub_hidden.is_experience_owner()
|
|
157
117
|
);
|
|
158
118
|
|
|
159
119
|
drop policy if exists select_chat_mute on hub.chat_mute;
|
|
160
120
|
create policy select_chat_mute on hub.chat_mute for select using (
|
|
161
|
-
-- operator can see all rows
|
|
162
121
|
hub_hidden.is_operator()
|
|
163
122
|
|
|
164
|
-
-- users can see their own mutes
|
|
165
123
|
or hub_hidden.current_user_id() = hub.chat_mute.user_id
|
|
166
124
|
|
|
167
|
-
-- experience owner can see all mutes
|
|
168
125
|
or hub_hidden.is_experience_owner()
|
|
169
126
|
|
|
170
|
-
-- anyone in chat_mod can see all mutes
|
|
171
127
|
or exists (
|
|
172
128
|
select 1
|
|
173
129
|
from hub.chat_mod
|
|
@@ -178,43 +134,25 @@ create policy select_chat_mute on hub.chat_mute for select using (
|
|
|
178
134
|
);
|
|
179
135
|
|
|
180
136
|
create policy select_chat_mod on hub.chat_mod for select using (
|
|
181
|
-
-- operator can see all rows
|
|
182
137
|
hub_hidden.is_operator()
|
|
183
138
|
|
|
184
|
-
-- experience owner can see all mods
|
|
185
139
|
or hub_hidden.is_experience_owner()
|
|
186
140
|
);
|
|
187
141
|
|
|
188
|
-
-- relax the select_experience policy so that it's public
|
|
189
|
-
-- this lets us use hubCurrentExperience { hubChatMessages { ... } }
|
|
190
|
-
-- previously (in 001-schema.sql) this was scoped to operator only
|
|
191
142
|
alter policy select_experience on hub.experience using (true);
|
|
192
143
|
|
|
193
|
-
----
|
|
194
144
|
|
|
195
|
-
-- add client_id to hub.user and hub.experience for playground sessions
|
|
196
145
|
alter table hub.user add column client_id uuid null;
|
|
197
146
|
alter table hub.experience add column client_id uuid null;
|
|
198
147
|
|
|
199
|
-
|
|
200
|
-
create unique index user_playground_client_id_idx on hub.user(casino_id, client_id)
|
|
148
|
+
create unique index user_playground_client_id_idx on hub.user(casino_id, client_id)
|
|
201
149
|
where client_id is not null;
|
|
202
|
-
create unique index experience_playground_client_id_idx on hub.experience(casino_id, client_id)
|
|
150
|
+
create unique index experience_playground_client_id_idx on hub.experience(casino_id, client_id)
|
|
203
151
|
where client_id is not null;
|
|
204
152
|
|
|
205
|
-
-- Update select_user policy so users can see other users
|
|
206
|
-
-- This way they can see user info {id, uname} on chat messages
|
|
207
153
|
drop policy if exists select_user on hub.user;
|
|
208
154
|
create policy select_user on hub.user for select using (
|
|
209
|
-
-- Old:
|
|
210
|
-
-- hub_hidden.is_operator() or (id = hub_hidden.current_user_id())
|
|
211
155
|
|
|
212
|
-
-- New:
|
|
213
156
|
true
|
|
214
157
|
);
|
|
215
158
|
|
|
216
|
-
-- Here's how we could clean up rate limit buckets periodically
|
|
217
|
-
-- create or replace function hub_hidden.gc_chat_buckets() returns void language sql as $$
|
|
218
|
-
-- delete from hub.chat_rate_bucket
|
|
219
|
-
-- where bucket_start < now() - interval '2 days';
|
|
220
|
-
-- $$;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneypot/hub",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.6",
|
|
4
4
|
"author": "moneypot.com",
|
|
5
5
|
"homepage": "https://moneypot.com/hub",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"moneypot"
|
|
8
8
|
],
|
|
9
9
|
"description": "Official MoneyPot hub server",
|
|
10
|
+
"packageManager": "pnpm@10.25.0",
|
|
10
11
|
"type": "module",
|
|
11
12
|
"main": "dist/src/index.js",
|
|
12
13
|
"types": "dist/src/index.d.ts",
|
|
@@ -34,17 +35,17 @@
|
|
|
34
35
|
"db-migrate": "./dist/cli/db-migrate.js"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
|
-
"build": "tsc && cp -R src/pg-versions dist/src/ &&
|
|
38
|
-
"check": "tsc --noEmit &&
|
|
38
|
+
"build": "rm -rf dist && tsc && cp -R src/pg-versions dist/src/ && ./scripts/strip-sql.sh && pnpm run build-dashboard",
|
|
39
|
+
"check": "tsc --noEmit && pnpm run check-dashboard",
|
|
39
40
|
"check-tests": "tsc -p tests/tsconfig.json --noEmit",
|
|
40
|
-
"check-dashboard": "cd ./dashboard &&
|
|
41
|
+
"check-dashboard": "cd ./dashboard && pnpm run check",
|
|
41
42
|
"format": "prettier --write \"**/*.ts\"",
|
|
42
|
-
"lint": "eslint --fix . &&
|
|
43
|
-
"lint-dashboard": "cd ./dashboard &&
|
|
44
|
-
"prepublishOnly": "
|
|
43
|
+
"lint": "eslint --fix . && pnpm run lint-dashboard",
|
|
44
|
+
"lint-dashboard": "cd ./dashboard && pnpm run lint",
|
|
45
|
+
"prepublishOnly": "pnpm run build",
|
|
45
46
|
"codegen": "npx graphql-codegen",
|
|
46
47
|
"codegen-watch": "graphql-codegen --watch",
|
|
47
|
-
"build-dashboard": "cd ./dashboard &&
|
|
48
|
+
"build-dashboard": "cd ./dashboard && pnpm run build && rm -rf ../dist/dashboard && cp -Rv dist ../dist/dashboard",
|
|
48
49
|
"test:startup": "dropdb --if-exists hub-test && createdb hub-test && SUPERUSER_DATABASE_URL=postgres://localhost:5432/hub-test DATABASE_URL=postgres://localhost:5432/hub-test tsx src/test-startup.ts",
|
|
49
50
|
"test": "vitest run",
|
|
50
51
|
"test:watch": "vitest"
|
|
@@ -86,5 +87,8 @@
|
|
|
86
87
|
"typescript-eslint": "^8.0.1",
|
|
87
88
|
"vitest": "^1.2.0"
|
|
88
89
|
},
|
|
90
|
+
"peerDependencies": {
|
|
91
|
+
"graphile-config": "^1.0.0-rc.2"
|
|
92
|
+
},
|
|
89
93
|
"license": "UNLICENSED"
|
|
90
94
|
}
|