@weft-framework/server 0.0.4 → 0.0.5
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 -1
- package/dist/index.js +1 -1
- package/dist/pg-stores.d.ts +0 -2
- package/dist/pg-stores.js +0 -30
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { LivePage, Redirect, redirect } from "./live.js";
|
|
|
11
11
|
export { ActionError, decodeForm, decodeJson, defineAction, fail, isAction } from "./action.js";
|
|
12
12
|
export type { Action, ActionContext, Decoded, ParamSpec, ParamType } from "./action.js";
|
|
13
13
|
export type { LivePageOptions } from "./live.js";
|
|
14
|
-
export { MIN_SECRET_LENGTH, RateLimiter, csrfToken, importSecret, parseCookies, randomId, sameOrigin, securityHeaders, checkCspSources, type CspSources, sessionCookie, signSession, timingSafeEqual, verifyCsrf, verifySession, } from "./security.js";
|
|
14
|
+
export { MIN_SECRET_LENGTH, RateLimiter, csrfToken, importSecret, parseCookies, randomId, sameOrigin, securityHeaders, checkCspSources, mergeCspSources, type CspSources, sessionCookie, signSession, timingSafeEqual, verifyCsrf, verifySession, } from "./security.js";
|
|
15
15
|
export type { RateLimitOptions, HeaderOptions, CookieOptions } from "./security.js";
|
|
16
16
|
export { external } from "./api.js";
|
|
17
17
|
export type { ApiHandler, ApiHandlers, ApiMethod } from "./api.js";
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { Router, parsePattern, patternForFile, splitPath } from "./router.js";
|
|
|
5
5
|
export { DEFAULT_SHELL, parseShell } from "./shell.js";
|
|
6
6
|
export { LivePage, Redirect, redirect } from "./live.js";
|
|
7
7
|
export { ActionError, decodeForm, decodeJson, defineAction, fail, isAction } from "./action.js";
|
|
8
|
-
export { MIN_SECRET_LENGTH, RateLimiter, csrfToken, importSecret, parseCookies, randomId, sameOrigin, securityHeaders, checkCspSources, sessionCookie, signSession, timingSafeEqual, verifyCsrf, verifySession, } from "./security.js";
|
|
8
|
+
export { MIN_SECRET_LENGTH, RateLimiter, csrfToken, importSecret, parseCookies, randomId, sameOrigin, securityHeaders, checkCspSources, mergeCspSources, sessionCookie, signSession, timingSafeEqual, verifyCsrf, verifySession, } from "./security.js";
|
|
9
9
|
export { external } from "./api.js";
|
|
10
10
|
export { MemorySessionStore, login, logout, switchTenant, viewAs, stopViewingAs, viewingAs, allowWhileViewing } from "./auth.js";
|
|
11
11
|
export { github, google, microsoft, oidc, SignInError } from "./oauth.js";
|
package/dist/pg-stores.d.ts
CHANGED
|
@@ -13,9 +13,7 @@ declare abstract class PgStore {
|
|
|
13
13
|
/** The quoted table name. */
|
|
14
14
|
protected readonly t: string;
|
|
15
15
|
constructor(pool: PgPool, table: string, ddl: (t: string, name: string) => string[]);
|
|
16
|
-
/** Run one statement (`?` placeholders) on the transaction's connection or the pool. */
|
|
17
16
|
protected q<R = Row>(sql: string, params?: unknown[]): Promise<R[]>;
|
|
18
|
-
/** Several statements atomically (joins an outer transaction as a savepoint). */
|
|
19
17
|
protected atomically<R>(fn: () => Promise<R>): Promise<R>;
|
|
20
18
|
}
|
|
21
19
|
export declare class PgSessionStore extends PgStore implements SessionStore {
|
package/dist/pg-stores.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
// Postgres versions of the server's SQL stores. Same interfaces and semantics as the `Sql*Store`
|
|
2
|
-
// classes (which take a synchronous SQLite `SqlDatabase`); every method returns a Promise.
|
|
3
|
-
//
|
|
4
|
-
// import { openPostgres } from "@weft-framework/data/postgres";
|
|
5
|
-
// import { PgSessionStore, PgJobStore } from "@weft-framework/server/pg-stores";
|
|
6
|
-
// const pool = await openPostgres(process.env.DATABASE_URL!);
|
|
7
|
-
// export const sessions = new PgSessionStore(pool);
|
|
8
|
-
//
|
|
9
|
-
// Tables are created on first use (one advisory-locked setup per store, safe across instances).
|
|
10
|
-
// Statements join the current `asyncTransaction` when there is one.
|
|
11
1
|
import { asyncTransaction, enlistAsync } from "@weft-framework/data";
|
|
12
2
|
import { numbered } from "@weft-framework/data/postgres";
|
|
13
3
|
import { SqlSessionStore } from "./auth.js";
|
|
14
4
|
import { jobFromRow } from "./jobs.js";
|
|
15
5
|
const TABLE_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
16
|
-
/** Lock key for store setup (`CREATE TABLE IF NOT EXISTS` races between instances otherwise). */
|
|
17
6
|
const SETUP_LOCK = 0x77656674; // "weft"
|
|
18
7
|
class PgStore {
|
|
19
8
|
#pool;
|
|
@@ -45,7 +34,6 @@ class PgStore {
|
|
|
45
34
|
c.release?.();
|
|
46
35
|
}
|
|
47
36
|
}
|
|
48
|
-
/** Run one statement (`?` placeholders) on the transaction's connection or the pool. */
|
|
49
37
|
async q(sql, params = []) {
|
|
50
38
|
if (!this.#ready) {
|
|
51
39
|
this.#ready = this.#setup();
|
|
@@ -57,14 +45,11 @@ class PgStore {
|
|
|
57
45
|
const res = tx ? await (await tx).query(text, params) : await this.#pool.query(text, params);
|
|
58
46
|
return res.rows;
|
|
59
47
|
}
|
|
60
|
-
/** Several statements atomically (joins an outer transaction as a savepoint). */
|
|
61
48
|
atomically(fn) {
|
|
62
49
|
return asyncTransaction(fn);
|
|
63
50
|
}
|
|
64
51
|
}
|
|
65
52
|
const num = (v) => Number(v);
|
|
66
|
-
// ---------------------------------------------------------------------------------------------
|
|
67
|
-
// Sessions
|
|
68
53
|
export class PgSessionStore extends PgStore {
|
|
69
54
|
constructor(pool, table = "weft_sessions") {
|
|
70
55
|
super(pool, table, (t, name) => [
|
|
@@ -93,9 +78,6 @@ export class PgSessionStore extends PgStore {
|
|
|
93
78
|
await this.q(`DELETE FROM ${this.t} WHERE seen < ?`, [before]);
|
|
94
79
|
}
|
|
95
80
|
}
|
|
96
|
-
// ---------------------------------------------------------------------------------------------
|
|
97
|
-
// Jobs: workers on several instances claim with FOR UPDATE SKIP LOCKED, so they never wait on
|
|
98
|
-
// each other's rows.
|
|
99
81
|
export class PgJobStore extends PgStore {
|
|
100
82
|
constructor(pool, table = "weft_jobs") {
|
|
101
83
|
super(pool, table, (t, name) => [
|
|
@@ -168,8 +150,6 @@ export class PgJobStore extends PgStore {
|
|
|
168
150
|
await this.q(`DELETE FROM ${this.t} WHERE status IN ('done', 'cancelled') AND updated < ?`, [before]);
|
|
169
151
|
}
|
|
170
152
|
}
|
|
171
|
-
// ---------------------------------------------------------------------------------------------
|
|
172
|
-
// Passkeys
|
|
173
153
|
function passkeyRow(o) {
|
|
174
154
|
if (!o)
|
|
175
155
|
return null;
|
|
@@ -224,8 +204,6 @@ export class PgPasskeyStore extends PgStore {
|
|
|
224
204
|
return (await this.q(`DELETE FROM ${this.t} WHERE id = ? RETURNING id`, [id])).length > 0;
|
|
225
205
|
}
|
|
226
206
|
}
|
|
227
|
-
// ---------------------------------------------------------------------------------------------
|
|
228
|
-
// TOTP 2FA
|
|
229
207
|
export class PgTwoFactorStore extends PgStore {
|
|
230
208
|
#r;
|
|
231
209
|
constructor(pool, table = "weft_two_factor") {
|
|
@@ -288,8 +266,6 @@ export class PgTwoFactorStore extends PgStore {
|
|
|
288
266
|
return num(row?.n ?? 0);
|
|
289
267
|
}
|
|
290
268
|
}
|
|
291
|
-
// ---------------------------------------------------------------------------------------------
|
|
292
|
-
// Email sign-in codes
|
|
293
269
|
function emailRow(o) {
|
|
294
270
|
if (!o)
|
|
295
271
|
return null;
|
|
@@ -336,8 +312,6 @@ export class PgEmailTokenStore extends PgStore {
|
|
|
336
312
|
await this.q(`DELETE FROM ${this.t} WHERE expires <= ?`, [now]);
|
|
337
313
|
}
|
|
338
314
|
}
|
|
339
|
-
// ---------------------------------------------------------------------------------------------
|
|
340
|
-
// Account tokens (password reset, email change, sign-up, verification)
|
|
341
315
|
function accountRow(r) {
|
|
342
316
|
if (!r)
|
|
343
317
|
return null;
|
|
@@ -372,8 +346,6 @@ export class PgAccountTokenStore extends PgStore {
|
|
|
372
346
|
await this.q(`DELETE FROM ${this.t} WHERE expires <= ?`, [now]);
|
|
373
347
|
}
|
|
374
348
|
}
|
|
375
|
-
// ---------------------------------------------------------------------------------------------
|
|
376
|
-
// Uploads
|
|
377
349
|
function fileRow(x) {
|
|
378
350
|
return {
|
|
379
351
|
id: String(x.id),
|
|
@@ -421,8 +393,6 @@ export class PgFileStore extends PgStore {
|
|
|
421
393
|
return rows.map(fileRow);
|
|
422
394
|
}
|
|
423
395
|
}
|
|
424
|
-
// ---------------------------------------------------------------------------------------------
|
|
425
|
-
// Webhooks (endpoints, messages, delivery attempts)
|
|
426
396
|
export class PgWebhookStore extends PgStore {
|
|
427
397
|
constructor(pool, table = "weft_webhooks") {
|
|
428
398
|
super(pool, table, (t, name) => [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weft-framework/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Weft server: live pages over WebSocket/SSE with signed sessions, CSRF, rate limiting and a strict CSP, on the Fetch API (Bun, Node, edge).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"weft",
|
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
},
|
|
179
179
|
"dependencies": {
|
|
180
180
|
"@weft-framework/data": "0.0.4",
|
|
181
|
-
"@weft-framework/runtime": "0.0.
|
|
181
|
+
"@weft-framework/runtime": "0.0.5",
|
|
182
182
|
"@xmldom/xmldom": "0.8.15",
|
|
183
183
|
"xml-crypto": "6.4.0"
|
|
184
184
|
},
|