@rine-kit/pubg-postgres 0.1.2 → 0.1.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/migrate.js +1 -1
- package/dist/review-share-store.d.ts +19 -0
- package/dist/review-share-store.js +62 -0
- package/migrations/0003_review_shares.sql +18 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/migrate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
-
const MIGRATIONS = ['0001_pubg_schema.sql', '0002_pubg_account_claims.sql'];
|
|
2
|
+
const MIGRATIONS = ['0001_pubg_schema.sql', '0002_pubg_account_claims.sql', '0003_review_shares.sql'];
|
|
3
3
|
const LOCK_ID = 7192041303;
|
|
4
4
|
/** Applies the schema to an empty or existing database; safe to run on every start. */
|
|
5
5
|
export async function migratePubgDatabase(pool) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Pool } from 'pg';
|
|
2
|
+
import type { ReviewShareRecord, ReviewShareStore } from '@rine-kit/pubg-domain';
|
|
3
|
+
/** Share pages of one tenant. Writes are queued by the synchronous ReviewShareStore methods; `flush()` stores them. */
|
|
4
|
+
export declare class PostgresReviewShareStore implements ReviewShareStore {
|
|
5
|
+
private readonly pool;
|
|
6
|
+
private readonly tenantId;
|
|
7
|
+
private queue;
|
|
8
|
+
constructor(pool: Pool, tenantId: string);
|
|
9
|
+
putReviewShare(record: ReviewShareRecord): void;
|
|
10
|
+
revokeReviewShares(squadId: string, sessionKey: string, revokedAt: string): number;
|
|
11
|
+
getReviewShare(): ReviewShareRecord | null;
|
|
12
|
+
latestReviewShare(): ReviewShareRecord | null;
|
|
13
|
+
/** Stores everything queued so far, in order. Call it before the link is shown to anyone. */
|
|
14
|
+
flush(): Promise<void>;
|
|
15
|
+
/** The share behind a token hash (any tenant of this database: the public page only has the token). */
|
|
16
|
+
static find(pool: Pool, tokenHash: string): Promise<(ReviewShareRecord & {
|
|
17
|
+
tenantId: string;
|
|
18
|
+
}) | null>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const toRecord = (row) => ({
|
|
2
|
+
tokenHash: row.token_hash,
|
|
3
|
+
kind: row.kind,
|
|
4
|
+
squadId: row.team_id,
|
|
5
|
+
sessionKey: row.session_key,
|
|
6
|
+
matchIds: JSON.parse(row.match_ids_json),
|
|
7
|
+
presentationJson: row.presentation_json,
|
|
8
|
+
createdAt: row.created_at.toISOString(),
|
|
9
|
+
expiresAt: row.expires_at.toISOString(),
|
|
10
|
+
revokedAt: row.revoked_at ? row.revoked_at.toISOString() : null,
|
|
11
|
+
});
|
|
12
|
+
/** Share pages of one tenant. Writes are queued by the synchronous ReviewShareStore methods; `flush()` stores them. */
|
|
13
|
+
export class PostgresReviewShareStore {
|
|
14
|
+
pool;
|
|
15
|
+
tenantId;
|
|
16
|
+
queue = [];
|
|
17
|
+
constructor(pool, tenantId) {
|
|
18
|
+
this.pool = pool;
|
|
19
|
+
this.tenantId = tenantId;
|
|
20
|
+
}
|
|
21
|
+
putReviewShare(record) {
|
|
22
|
+
this.queue.push(() => this.pool.query(`INSERT INTO pubg_review_shares(tenant_id, token_hash, kind, team_id, session_key, match_ids_json, presentation_json, created_at, expires_at, revoked_at)
|
|
23
|
+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
|
24
|
+
ON CONFLICT (tenant_id, token_hash) DO NOTHING`, [
|
|
25
|
+
this.tenantId,
|
|
26
|
+
record.tokenHash,
|
|
27
|
+
record.kind,
|
|
28
|
+
record.squadId,
|
|
29
|
+
record.sessionKey,
|
|
30
|
+
JSON.stringify(record.matchIds),
|
|
31
|
+
record.presentationJson,
|
|
32
|
+
record.createdAt,
|
|
33
|
+
record.expiresAt,
|
|
34
|
+
record.revokedAt,
|
|
35
|
+
]));
|
|
36
|
+
}
|
|
37
|
+
revokeReviewShares(squadId, sessionKey, revokedAt) {
|
|
38
|
+
this.queue.push(() => this.pool.query(`UPDATE pubg_review_shares SET revoked_at=$4
|
|
39
|
+
WHERE tenant_id=$1 AND team_id=$2 AND session_key=$3 AND revoked_at IS NULL`, [this.tenantId, squadId, sessionKey, revokedAt]));
|
|
40
|
+
return 0; // the count is only known after flush(); issueReviewShare ignores it
|
|
41
|
+
}
|
|
42
|
+
// The synchronous readers of the interface are not used when issuing; reading goes through the async methods.
|
|
43
|
+
getReviewShare() {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
latestReviewShare() {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
/** Stores everything queued so far, in order. Call it before the link is shown to anyone. */
|
|
50
|
+
async flush() {
|
|
51
|
+
const work = this.queue;
|
|
52
|
+
this.queue = [];
|
|
53
|
+
for (const step of work)
|
|
54
|
+
await step();
|
|
55
|
+
}
|
|
56
|
+
/** The share behind a token hash (any tenant of this database: the public page only has the token). */
|
|
57
|
+
static async find(pool, tokenHash) {
|
|
58
|
+
const { rows } = await pool.query('SELECT * FROM pubg_review_shares WHERE token_hash=$1 LIMIT 1', [tokenHash]);
|
|
59
|
+
const row = rows[0];
|
|
60
|
+
return row ? { ...toRecord(row), tenantId: row.tenant_id } : null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Share pages (no login) for a query answer: the matches it may show and the answer exactly as it was sent. Only the
|
|
2
|
+
-- SHA-256 of the token is stored, so a copy of this table cannot be turned back into a working link.
|
|
3
|
+
-- Same record as pubg-domain's ReviewShareRecord (Lab keeps it in SQLite `review_shares`); team_id is the squad.
|
|
4
|
+
CREATE TABLE IF NOT EXISTS pubg_review_shares (
|
|
5
|
+
tenant_id TEXT NOT NULL,
|
|
6
|
+
token_hash TEXT NOT NULL,
|
|
7
|
+
kind TEXT NOT NULL CHECK (kind IN ('session', 'match', 'query')),
|
|
8
|
+
team_id TEXT NOT NULL,
|
|
9
|
+
session_key TEXT NOT NULL,
|
|
10
|
+
match_ids_json TEXT NOT NULL,
|
|
11
|
+
presentation_json TEXT NOT NULL,
|
|
12
|
+
created_at TIMESTAMPTZ NOT NULL,
|
|
13
|
+
expires_at TIMESTAMPTZ NOT NULL,
|
|
14
|
+
revoked_at TIMESTAMPTZ,
|
|
15
|
+
PRIMARY KEY (tenant_id, token_hash)
|
|
16
|
+
);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS idx_pubg_review_shares_session ON pubg_review_shares(tenant_id, team_id, session_key, created_at);
|
|
18
|
+
CREATE INDEX IF NOT EXISTS idx_pubg_review_shares_token ON pubg_review_shares(token_hash);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rine-kit/pubg-postgres",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "PostgreSQL storage for PUBG team data (matches, telemetry features, sync queue, query sessions) behind @rine-kit/pubg-domain's PubgRepositoryPort. Extracted from Gate; tenancy is a host-supplied scope, no KOOK dependency.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"pg": "^8.13.0",
|
|
23
23
|
"zod": "^4.6.7",
|
|
24
|
-
"@rine-kit/pubg-domain": "0.1.
|
|
24
|
+
"@rine-kit/pubg-domain": "0.1.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^26.6.5",
|