covara 0.9.2 → 0.10.1
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 -13
- package/dist/auth/api-keys.d.ts +17 -0
- package/dist/auth/api-keys.d.ts.map +1 -1
- package/dist/auth/api-keys.js +75 -0
- package/dist/auth/api-keys.js.map +1 -1
- package/dist/auth/config.d.ts +7 -3
- package/dist/auth/config.d.ts.map +1 -1
- package/dist/auth/config.js +8 -5
- package/dist/auth/config.js.map +1 -1
- package/dist/auth/index.d.ts +4 -4
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +3 -3
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/stores/drizzle.d.ts +6 -2
- package/dist/auth/stores/drizzle.d.ts.map +1 -1
- package/dist/auth/stores/drizzle.js +68 -70
- package/dist/auth/stores/drizzle.js.map +1 -1
- package/dist/auth/stores/index.d.ts +4 -2
- package/dist/auth/stores/index.d.ts.map +1 -1
- package/dist/auth/stores/index.js +3 -1
- package/dist/auth/stores/index.js.map +1 -1
- package/dist/auth/stores/kv.d.ts +31 -0
- package/dist/auth/stores/kv.d.ts.map +1 -0
- package/dist/auth/stores/{redis.js → kv.js} +8 -4
- package/dist/auth/stores/kv.js.map +1 -0
- package/dist/auth/verification.d.ts +12 -0
- package/dist/auth/verification.d.ts.map +1 -1
- package/dist/auth/verification.js +0 -0
- package/dist/auth/verification.js.map +1 -1
- package/dist/cli/commands/env.d.ts.map +1 -1
- package/dist/cli/commands/env.js +1 -13
- package/dist/cli/commands/env.js.map +1 -1
- package/dist/cli/dotenv.d.ts +3 -0
- package/dist/cli/dotenv.d.ts.map +1 -0
- package/dist/cli/dotenv.js +34 -0
- package/dist/cli/dotenv.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +13 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/options.d.ts +3 -0
- package/dist/cli/options.d.ts.map +1 -1
- package/dist/cli/options.js +1 -0
- package/dist/cli/options.js.map +1 -1
- package/dist/cli/templates/configs.d.ts.map +1 -1
- package/dist/cli/templates/configs.js +15 -1
- package/dist/cli/templates/configs.js.map +1 -1
- package/dist/cli/templates/deploy.d.ts +1 -1
- package/dist/cli/templates/deploy.d.ts.map +1 -1
- package/dist/cli/templates/deploy.js +10 -2
- package/dist/cli/templates/deploy.js.map +1 -1
- package/dist/cli/templates/frontend.d.ts +11 -0
- package/dist/cli/templates/frontend.d.ts.map +1 -0
- package/dist/cli/templates/frontend.js +254 -0
- package/dist/cli/templates/frontend.js.map +1 -0
- package/dist/cli/templates/index.d.ts +1 -0
- package/dist/cli/templates/index.d.ts.map +1 -1
- package/dist/cli/templates/index.js +6 -1
- package/dist/cli/templates/index.js.map +1 -1
- package/dist/cli/templates/package-json.d.ts.map +1 -1
- package/dist/cli/templates/package-json.js +66 -64
- package/dist/cli/templates/package-json.js.map +1 -1
- package/dist/cli/templates/source.d.ts.map +1 -1
- package/dist/cli/templates/source.js +79 -1
- package/dist/cli/templates/source.js.map +1 -1
- package/dist/cli/templates/versions.d.ts +24 -0
- package/dist/cli/templates/versions.d.ts.map +1 -0
- package/dist/cli/templates/versions.js +53 -0
- package/dist/cli/templates/versions.js.map +1 -0
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/internal-schema.d.ts +39 -0
- package/dist/db/internal-schema.d.ts.map +1 -1
- package/dist/db/internal-schema.js +97 -0
- package/dist/db/internal-schema.js.map +1 -1
- package/dist/db/migrate.d.ts +11 -2
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +166 -31
- package/dist/db/migrate.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/kv/index.d.ts +1 -1
- package/dist/kv/index.d.ts.map +1 -1
- package/dist/kv/index.js +1 -1
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/types.d.ts +1 -0
- package/dist/kv/types.d.ts.map +1 -1
- package/dist/kv/types.js +3 -0
- package/dist/kv/types.js.map +1 -1
- package/dist/middleware/observability.d.ts +1 -0
- package/dist/middleware/observability.d.ts.map +1 -1
- package/dist/middleware/observability.js +41 -27
- package/dist/middleware/observability.js.map +1 -1
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +2 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/log-adapter.d.ts +50 -0
- package/dist/observability/log-adapter.d.ts.map +1 -0
- package/dist/observability/log-adapter.js +174 -0
- package/dist/observability/log-adapter.js.map +1 -0
- package/dist/server/app.d.ts +3 -0
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/app.js +1 -0
- package/dist/server/app.js.map +1 -1
- package/dist/ui/admin-auth.d.ts +3 -0
- package/dist/ui/admin-auth.d.ts.map +1 -1
- package/dist/ui/admin-auth.js +56 -26
- package/dist/ui/admin-auth.js.map +1 -1
- package/dist/ui/index.d.ts +2 -2
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/middleware.d.ts +9 -1
- package/dist/ui/middleware.d.ts.map +1 -1
- package/dist/ui/middleware.js +44 -24
- package/dist/ui/middleware.js.map +1 -1
- package/package.json +2 -2
- package/dist/auth/stores/redis.d.ts +0 -25
- package/dist/auth/stores/redis.d.ts.map +0 -1
- package/dist/auth/stores/redis.js.map +0 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ function TodoList() {
|
|
|
91
91
|
### File Storage
|
|
92
92
|
- **Storage Adapters** - Local disk, S3, Cloudflare R2 (native binding or S3-compat), and in-memory behind one `StorageAdapter` interface
|
|
93
93
|
- **File Resources** - First-class resources with an upload/download layer: `app.fileResource(...)` chains like any resource and inherits the full CRUD/hooks/procedures/relations/subscriptions/scopes surface, plus MIME/size validation, per-user keys, and storage cleanup on delete
|
|
94
|
-
- **Zero-config local serving** - `createCovara` auto-serves a local adapter's `baseUrl
|
|
94
|
+
- **Zero-config local serving** - `createCovara` auto-serves a local adapter's `baseUrl`; admin data explorer gets a per-row Download action
|
|
95
95
|
- **Presigned URLs** - Optional direct-to-bucket uploads/downloads with configurable expiry
|
|
96
96
|
- **React Hooks** - `useFileUpload` (with progress), `useFile`, `useFiles`; `getDownloadUrl()` for React Native
|
|
97
97
|
|
|
@@ -139,10 +139,12 @@ function TodoList() {
|
|
|
139
139
|
- **Client Access** - Typed `fetchPublicEnv` / `createEnvClient` and a `usePublicEnv` React hook
|
|
140
140
|
|
|
141
141
|
### Developer Experience
|
|
142
|
-
- **Project Scaffolding** - `npx covara create my-app` (Node/Workers templates, SQLite/Postgres), plus `covara generate resource|migration`
|
|
142
|
+
- **Project Scaffolding** - `npx covara create my-app` (Node/Workers templates, SQLite/Postgres), optional live React SPA with `--frontend react`, plus `covara generate resource|migration`
|
|
143
143
|
- **`covara dev` Loop** - Dev watcher: streams schema changes to the DB (additive auto-applied, destructive gated), regenerates the typed client, runs the server — no manual push. Plus `covara db` connection profiles (local/remote/Turso/Postgres), `push`/`migrate`/`studio`, and `data`/`import`/`export`/`run`/`types`
|
|
144
144
|
- **Deploy-Ready Output** - Generated Dockerfile, docker-compose, complete wrangler.toml, GitHub Actions CI, `.env.example`
|
|
145
145
|
- **Framework Migrations** - `covara/db` ships canonical internal-table schemas, an idempotent `autoMigrate`/`migrateInternal`, a generic seeder, and pool-sizing helpers
|
|
146
|
+
- **Shapeable Internal Tables** - bring your own auth tables (custom names + column remapping) with `defineInternalSchema`; every internal/system table and its required columns is documented
|
|
147
|
+
- **Pluggable Observability Storage** - the admin audit log, request/error logs, and metrics persist to KV (or your own adapter) when configured, in-memory otherwise
|
|
146
148
|
- **App Factory** - `createCovara()` wires errors, auth, security headers, health, OpenAPI, admin UI
|
|
147
149
|
- **Graceful Shutdown** - SIGTERM/SIGINT draining with `/readyz` 503 and clean SSE close
|
|
148
150
|
- **Admin UI** - Built-in dashboard at `/__covara/ui`
|
|
@@ -157,6 +159,7 @@ function TodoList() {
|
|
|
157
159
|
|
|
158
160
|
```bash
|
|
159
161
|
npx covara create my-app # Node + SQLite
|
|
162
|
+
npx covara create my-app --frontend react # + a live React SPA on the same server
|
|
160
163
|
npx covara create my-app --db postgres # Node + PostgreSQL
|
|
161
164
|
npx covara create my-app --template cloudflare # Cloudflare Workers + D1
|
|
162
165
|
```
|
|
@@ -484,7 +487,7 @@ const app = createCovara()
|
|
|
484
487
|
|
|
485
488
|
## File Storage
|
|
486
489
|
|
|
487
|
-
Configure a storage backend once, then chain a file resource like any other. Local uploads are auto-served at `baseUrl
|
|
490
|
+
Configure a storage backend once, then chain a file resource like any other. Local uploads are auto-served at `baseUrl`:
|
|
488
491
|
|
|
489
492
|
```typescript
|
|
490
493
|
import { createCovara, initializeStorage } from "covara";
|
|
@@ -852,7 +855,7 @@ expect(res.status).toBe(201);
|
|
|
852
855
|
|
|
853
856
|
📚 **Full documentation: [kahveciderin.github.io/covara](https://kahveciderin.github.io/covara)**
|
|
854
857
|
|
|
855
|
-
|
|
858
|
+
Highlights:
|
|
856
859
|
|
|
857
860
|
- **Get started** — [Introduction](https://kahveciderin.github.io/covara/), [Quick Start](https://kahveciderin.github.io/covara/quick-start), [Tutorial](https://kahveciderin.github.io/covara/tutorial)
|
|
858
861
|
- **Core** — [Resources](https://kahveciderin.github.io/covara/core/resources-and-app), [Filtering](https://kahveciderin.github.io/covara/core/filtering), [Pagination](https://kahveciderin.github.io/covara/core/pagination), [Aggregations](https://kahveciderin.github.io/covara/core/aggregations), [Relations](https://kahveciderin.github.io/covara/core/relations), [Search](https://kahveciderin.github.io/covara/core/search)
|
|
@@ -861,16 +864,8 @@ The docs site is built with Docusaurus from the [`website/`](./website) folder a
|
|
|
861
864
|
- **Platform** — [Storage](https://kahveciderin.github.io/covara/platform/storage), [Email](https://kahveciderin.github.io/covara/platform/email), [Billing](https://kahveciderin.github.io/covara/platform/billing), [Tasks](https://kahveciderin.github.io/covara/platform/tasks), [KV](https://kahveciderin.github.io/covara/platform/kv)
|
|
862
865
|
- **Client** — [Overview](https://kahveciderin.github.io/covara/client/overview), [React hooks](https://kahveciderin.github.io/covara/client/react-hooks), [Offline](https://kahveciderin.github.io/covara/client/offline), [Type generation](https://kahveciderin.github.io/covara/client/typegen)
|
|
863
866
|
- **Deploy** — [Node](https://kahveciderin.github.io/covara/deployment/node), [Cloudflare Workers](https://kahveciderin.github.io/covara/deployment/workers), [Databases](https://kahveciderin.github.io/covara/deployment/databases)
|
|
864
|
-
- **Reference** — [Contracts (invariants)](https://kahveciderin.github.io/covara/contracts/overview), [Error handling](https://kahveciderin.github.io/covara/tooling/error-handling)
|
|
867
|
+
- **Reference** — [Contracts (invariants)](https://kahveciderin.github.io/covara/contracts/overview), [Error handling](https://kahveciderin.github.io/covara/tooling/error-handling)
|
|
865
868
|
|
|
866
|
-
Run the docs locally:
|
|
867
|
-
|
|
868
|
-
```bash
|
|
869
|
-
cd website
|
|
870
|
-
pnpm install
|
|
871
|
-
pnpm start # dev server with hot reload
|
|
872
|
-
pnpm build # production build (validates all internal links)
|
|
873
|
-
```
|
|
874
869
|
|
|
875
870
|
## Requirements
|
|
876
871
|
|
package/dist/auth/api-keys.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KVAdapter } from "../kv/types.js";
|
|
1
2
|
export interface ApiKeyMetadata {
|
|
2
3
|
id: string;
|
|
3
4
|
label?: string;
|
|
@@ -29,6 +30,22 @@ export declare class InMemoryApiKeyStore implements ApiKeyStore {
|
|
|
29
30
|
delete(id: string): Promise<void>;
|
|
30
31
|
touch(id: string, lastUsedAt: Date): Promise<void>;
|
|
31
32
|
}
|
|
33
|
+
export declare class KVApiKeyStore implements ApiKeyStore {
|
|
34
|
+
private kv;
|
|
35
|
+
private prefix;
|
|
36
|
+
constructor(kv: KVAdapter, prefix?: string);
|
|
37
|
+
private recordKey;
|
|
38
|
+
private allKey;
|
|
39
|
+
private userKey;
|
|
40
|
+
create(record: StoredApiKey): Promise<void>;
|
|
41
|
+
list(filter?: {
|
|
42
|
+
userId?: string;
|
|
43
|
+
}): Promise<StoredApiKey[]>;
|
|
44
|
+
findById(id: string): Promise<StoredApiKey | null>;
|
|
45
|
+
delete(id: string): Promise<void>;
|
|
46
|
+
touch(id: string, lastUsedAt: Date): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare const createKVApiKeyStore: (kv: KVAdapter, prefix?: string) => KVApiKeyStore;
|
|
32
49
|
export interface CreateApiKeyOptions {
|
|
33
50
|
store: ApiKeyStore;
|
|
34
51
|
label?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-keys.d.ts","sourceRoot":"","sources":["../../src/auth/api-keys.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-keys.d.ts","sourceRoot":"","sources":["../../src/auth/api-keys.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA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AC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC/C,OAAO,CAAC,cAAc,EAAE,CAK1B,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,IAAI,MAAM,EACV,SAAS;IAAE,KAAK,EAAE,WAAW,CAAA;CAAE,KAC9B,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,YAAY,GAAU,SAAS,mBAAmB,KAAG,OAAO,CAAC,aAAa,CAatF,CAAC"}
|
package/dist/auth/api-keys.js
CHANGED
|
@@ -27,6 +27,81 @@ export class InMemoryApiKeyStore {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
const serializeApiKey = (k) => JSON.stringify({
|
|
31
|
+
...k,
|
|
32
|
+
createdAt: k.createdAt.toISOString(),
|
|
33
|
+
lastUsedAt: k.lastUsedAt ? k.lastUsedAt.toISOString() : null,
|
|
34
|
+
expiresAt: k.expiresAt ? k.expiresAt.toISOString() : null,
|
|
35
|
+
});
|
|
36
|
+
const deserializeApiKey = (raw) => {
|
|
37
|
+
const s = JSON.parse(raw);
|
|
38
|
+
return {
|
|
39
|
+
id: s.id,
|
|
40
|
+
label: s.label,
|
|
41
|
+
userId: s.userId,
|
|
42
|
+
scopes: s.scopes,
|
|
43
|
+
hash: s.hash,
|
|
44
|
+
createdAt: new Date(s.createdAt),
|
|
45
|
+
lastUsedAt: s.lastUsedAt ? new Date(s.lastUsedAt) : null,
|
|
46
|
+
expiresAt: s.expiresAt ? new Date(s.expiresAt) : null,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
// KV-backed API-key store — works with any KV adapter (memory/redis/durable
|
|
50
|
+
// object), so API keys survive restarts and are shared across instances.
|
|
51
|
+
export class KVApiKeyStore {
|
|
52
|
+
constructor(kv, prefix = "apikey") {
|
|
53
|
+
this.kv = kv;
|
|
54
|
+
this.prefix = prefix;
|
|
55
|
+
}
|
|
56
|
+
recordKey(id) {
|
|
57
|
+
return `${this.prefix}:${id}`;
|
|
58
|
+
}
|
|
59
|
+
allKey() {
|
|
60
|
+
return `${this.prefix}:all`;
|
|
61
|
+
}
|
|
62
|
+
userKey(userId) {
|
|
63
|
+
return `${this.prefix}:user:${userId}`;
|
|
64
|
+
}
|
|
65
|
+
async create(record) {
|
|
66
|
+
await this.kv.set(this.recordKey(record.id), serializeApiKey(record));
|
|
67
|
+
await this.kv.sadd(this.allKey(), record.id);
|
|
68
|
+
if (record.userId !== undefined) {
|
|
69
|
+
await this.kv.sadd(this.userKey(record.userId), record.id);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async list(filter) {
|
|
73
|
+
const ids = filter?.userId !== undefined
|
|
74
|
+
? await this.kv.smembers(this.userKey(filter.userId))
|
|
75
|
+
: await this.kv.smembers(this.allKey());
|
|
76
|
+
const out = [];
|
|
77
|
+
for (const id of ids) {
|
|
78
|
+
const raw = await this.kv.get(this.recordKey(id));
|
|
79
|
+
if (raw)
|
|
80
|
+
out.push(deserializeApiKey(raw));
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
async findById(id) {
|
|
85
|
+
const raw = await this.kv.get(this.recordKey(id));
|
|
86
|
+
return raw ? deserializeApiKey(raw) : null;
|
|
87
|
+
}
|
|
88
|
+
async delete(id) {
|
|
89
|
+
const existing = await this.findById(id);
|
|
90
|
+
await this.kv.del(this.recordKey(id));
|
|
91
|
+
await this.kv.srem(this.allKey(), id);
|
|
92
|
+
if (existing?.userId !== undefined) {
|
|
93
|
+
await this.kv.srem(this.userKey(existing.userId), id);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async touch(id, lastUsedAt) {
|
|
97
|
+
const existing = await this.findById(id);
|
|
98
|
+
if (existing) {
|
|
99
|
+
existing.lastUsedAt = lastUsedAt;
|
|
100
|
+
await this.kv.set(this.recordKey(id), serializeApiKey(existing));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export const createKVApiKeyStore = (kv, prefix) => new KVApiKeyStore(kv, prefix);
|
|
30
105
|
const generateRawKey = (prefix, byteLength) => {
|
|
31
106
|
const id = randomBytes(8).toString("hex");
|
|
32
107
|
const secret = randomBytes(byteLength).toString("base64url");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-keys.js","sourceRoot":"","sources":["../../src/auth/api-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"api-keys.js","sourceRoot":"","sources":["../../src/auth/api-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAyB1D,MAAM,OAAO,mBAAmB;IAAhC;QACU,SAAI,GAAG,IAAI,GAAG,EAAwB,CAAC;IA4BjD,CAAC;IA1BC,KAAK,CAAC,MAAM,CAAC,MAAoB;QAC/B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAA4B;QACrC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3C,IAAI,MAAM,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,QAA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AAK,EAAE,OAAO,CAAC,KAAK,IAAI,QAAQ,EAAE,KAAK;QACvC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE,MAAM;QAC1C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE,MAAM;QAC1C,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,QAAQ,EAAE,SAAS,IAAI,IAAI;QAC3D,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/auth/config.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { AuthAdapter, SessionStore } from "./types.js";
|
|
2
2
|
import { JWTConfig } from "./adapters/jwt.js";
|
|
3
|
-
import {
|
|
3
|
+
import { KVSessionStoreOptions } from "./stores/kv.js";
|
|
4
4
|
import { DrizzleSessionStoreOptions } from "./stores/drizzle.js";
|
|
5
5
|
import { KVAdapter } from "../kv/types.js";
|
|
6
6
|
export type AuthMode = "session" | "jwt";
|
|
7
7
|
export interface SessionStoreConfig {
|
|
8
|
-
type: "memory" | "redis" | "drizzle";
|
|
9
|
-
|
|
8
|
+
type: "memory" | "kv" | "redis" | "drizzle";
|
|
9
|
+
kv?: Omit<KVSessionStoreOptions, "kv"> & {
|
|
10
|
+
kv: KVAdapter;
|
|
11
|
+
};
|
|
12
|
+
/** @deprecated Use `kv` — the KV session store works with any KV adapter, not only Redis. */
|
|
13
|
+
redis?: Omit<KVSessionStoreOptions, "kv"> & {
|
|
10
14
|
kv: KVAdapter;
|
|
11
15
|
};
|
|
12
16
|
drizzle?: DrizzleSessionStoreOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/auth/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAw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Q,CAAC;IACf,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC5D,gBAAgB,CAAC,EAAE,CACjB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,KACb,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,CACf,MAAM,EAAE,MAAM,KACX,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CAC5D;AAED,eAAO,MAAM,kBAAkB,GAAI,SAAS,kBAAkB,KAAG,YAyBhE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,QAAQ,UAAU,KAAG,WAyBtD,CAAC"}
|
package/dist/auth/config.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { InMemorySessionStore } from "./types.js";
|
|
2
2
|
import { PassportAdapter } from "./adapters/passport.js";
|
|
3
3
|
import { JWTAdapter } from "./adapters/jwt.js";
|
|
4
|
-
import {
|
|
4
|
+
import { KVSessionStore } from "./stores/kv.js";
|
|
5
5
|
import { DrizzleSessionStore, } from "./stores/drizzle.js";
|
|
6
6
|
export const createSessionStore = (config) => {
|
|
7
7
|
if (!config) {
|
|
8
8
|
return new InMemorySessionStore();
|
|
9
9
|
}
|
|
10
10
|
switch (config.type) {
|
|
11
|
-
case "
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
case "kv":
|
|
12
|
+
case "redis": {
|
|
13
|
+
const kvConfig = config.kv ?? config.redis;
|
|
14
|
+
if (!kvConfig?.kv) {
|
|
15
|
+
throw new Error("KV adapter required for kv session store");
|
|
14
16
|
}
|
|
15
|
-
return new
|
|
17
|
+
return new KVSessionStore(kvConfig);
|
|
18
|
+
}
|
|
16
19
|
case "drizzle":
|
|
17
20
|
if (!config.drizzle) {
|
|
18
21
|
throw new Error("Drizzle config required for drizzle session store");
|
package/dist/auth/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/auth/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAa,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/auth/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAa,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAyB,MAAM,aAAa,CAAC;AACpE,OAAO,EACL,mBAAmB,GAEpB,MAAM,kBAAkB,CAAC;AAqC1B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAA2B,EAAgB,EAAE;IAC9E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,oBAAoB,EAAE,CAAC;IACpC,CAAC;IAED,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,IAAI,CAAC;QACV,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,KAAK,CAAC;YAC3C,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAC9D,CAAC;YACD,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;QAED,KAAK,SAAS;YACZ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACvE,CAAC;YACD,OAAO,IAAI,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEjD,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,IAAI,oBAAoB,EAAE,CAAC;IACtC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAkB,EAAe,EAAE;IACnE,MAAM,YAAY,GAAG,kBAAkB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAE7D,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,KAAK;YACR,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;YACtD,CAAC;YACD,OAAO,IAAI,UAAU,CAAC;gBACpB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;gBACzC,iBAAiB,EAAE,YAAY;aAChC,CAAC,CAAC;QAEL,KAAK,SAAS,CAAC;QACf;YACE,OAAO,IAAI,eAAe,CAAC;gBACzB,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;gBACzC,cAAc,EAAE,MAAM,CAAC,cAAc;gBACrC,YAAY;gBACZ,YAAY,EAAE,MAAM,CAAC,YAAY;aAClC,CAAC,CAAC;IACP,CAAC;AACH,CAAC,CAAC"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ export * from "./middleware.js";
|
|
|
7
7
|
export * from "./routes.js";
|
|
8
8
|
export { createCsrfMiddleware, issueCsrfToken, generateCsrfToken, type CsrfOptions, } from "./csrf.js";
|
|
9
9
|
export { LoginThrottle, type LoginThrottleOptions, type ThrottleCheck, } from "./login-throttle.js";
|
|
10
|
-
export { InMemoryVerificationTokenStore, issueToken, verifyToken, hashToken, generateToken, type VerificationTokenStore, type VerificationTokenRecord, } from "./verification.js";
|
|
10
|
+
export { InMemoryVerificationTokenStore, KVVerificationTokenStore, createKVVerificationTokenStore, issueToken, verifyToken, hashToken, generateToken, type VerificationTokenStore, type VerificationTokenRecord, } from "./verification.js";
|
|
11
11
|
export { issuePasswordResetToken, verifyPasswordResetToken, hashNewPassword, type PasswordResetOptions, } from "./password-reset.js";
|
|
12
12
|
export { base32Encode, base32Decode, generateTotpSecret, generateTotp, verifyTotp, getTotpUri, generateBackupCodes, verifyBackupCode, type TotpOptions, type TotpUriParams, type BackupCodesResult, } from "./totp.js";
|
|
13
13
|
export { issueMagicLinkToken, consumeMagicLinkToken, type MagicLinkOptions, } from "./magic-link.js";
|
|
14
|
-
export { createApiKey, verifyApiKey, rotateApiKey, revokeApiKey, listApiKeys, InMemoryApiKeyStore, type ApiKeyStore, type StoredApiKey, type ApiKeyMetadata, type CreatedApiKey, type CreateApiKeyOptions, type RotateApiKeyOptions, type VerifyApiKeyResult, } from "./api-keys.js";
|
|
14
|
+
export { createApiKey, verifyApiKey, rotateApiKey, revokeApiKey, listApiKeys, InMemoryApiKeyStore, KVApiKeyStore, createKVApiKeyStore, type ApiKeyStore, type StoredApiKey, type ApiKeyMetadata, type CreatedApiKey, type CreateApiKeyOptions, type RotateApiKeyOptions, type VerifyApiKeyResult, } from "./api-keys.js";
|
|
15
15
|
export { validatePasswordStrength, enforcePasswordStrength, builtInPasswordDenylist, type PasswordPolicyOptions, type PasswordStrengthResult, } from "./password-policy.js";
|
|
16
16
|
export { createAuthAdapter, createSessionStore, type AuthMode, type AuthConfig, type AuthConfigUser, type SessionStoreConfig, } from "./config.js";
|
|
17
17
|
export { AuthJsAdapter, createAuthJsAdapter } from "./adapters/authjs.js";
|
|
@@ -20,6 +20,6 @@ export { JWTAdapter, createJWTAdapter } from "./adapters/jwt.js";
|
|
|
20
20
|
export type { JWTConfig, JWTAdapterOptions, JWTPayload, JWTUser } from "./adapters/jwt.js";
|
|
21
21
|
export { OIDCAdapter, createOIDCAdapter, oidcProviders } from "./adapters/oidc.js";
|
|
22
22
|
export type { OIDCProviderConfig, OIDCAdapterOptions, OIDCUserInfo, OIDCAccount, OIDCUser, } from "./adapters/oidc.js";
|
|
23
|
-
export { RedisSessionStore, createRedisSessionStore, DrizzleSessionStore, createDrizzleSessionStore, } from "./stores/index.js";
|
|
24
|
-
export type { RedisSessionStoreOptions, DrizzleSessionStoreOptions, SessionsTableColumns, } from "./stores/index.js";
|
|
23
|
+
export { KVSessionStore, createKVSessionStore, RedisSessionStore, createRedisSessionStore, DrizzleSessionStore, createDrizzleSessionStore, } from "./stores/index.js";
|
|
24
|
+
export type { KVSessionStoreOptions, RedisSessionStoreOptions, DrizzleSessionStoreOptions, SessionsTableColumns, } from "./stores/index.js";
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,KAAK,WAAW,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,aAAa,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,8BAA8B,EAC9B,UAAU,EACV,WAAW,EACX,SAAS,EACT,aAAa,EACb,KAAK,sB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AAC;AAClB,YAAY,EACV,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,UAAU,CAAC"}
|
package/dist/auth/index.js
CHANGED
|
@@ -7,16 +7,16 @@ export * from "./middleware.js";
|
|
|
7
7
|
export * from "./routes.js";
|
|
8
8
|
export { createCsrfMiddleware, issueCsrfToken, generateCsrfToken, } from "./csrf.js";
|
|
9
9
|
export { LoginThrottle, } from "./login-throttle.js";
|
|
10
|
-
export { InMemoryVerificationTokenStore, issueToken, verifyToken, hashToken, generateToken, } from "./verification.js";
|
|
10
|
+
export { InMemoryVerificationTokenStore, KVVerificationTokenStore, createKVVerificationTokenStore, issueToken, verifyToken, hashToken, generateToken, } from "./verification.js";
|
|
11
11
|
export { issuePasswordResetToken, verifyPasswordResetToken, hashNewPassword, } from "./password-reset.js";
|
|
12
12
|
export { base32Encode, base32Decode, generateTotpSecret, generateTotp, verifyTotp, getTotpUri, generateBackupCodes, verifyBackupCode, } from "./totp.js";
|
|
13
13
|
export { issueMagicLinkToken, consumeMagicLinkToken, } from "./magic-link.js";
|
|
14
|
-
export { createApiKey, verifyApiKey, rotateApiKey, revokeApiKey, listApiKeys, InMemoryApiKeyStore, } from "./api-keys.js";
|
|
14
|
+
export { createApiKey, verifyApiKey, rotateApiKey, revokeApiKey, listApiKeys, InMemoryApiKeyStore, KVApiKeyStore, createKVApiKeyStore, } from "./api-keys.js";
|
|
15
15
|
export { validatePasswordStrength, enforcePasswordStrength, builtInPasswordDenylist, } from "./password-policy.js";
|
|
16
16
|
export { createAuthAdapter, createSessionStore, } from "./config.js";
|
|
17
17
|
export { AuthJsAdapter, createAuthJsAdapter } from "./adapters/authjs.js";
|
|
18
18
|
export { PassportAdapter, createPassportAdapter, fromPassportUser } from "./adapters/passport.js";
|
|
19
19
|
export { JWTAdapter, createJWTAdapter } from "./adapters/jwt.js";
|
|
20
20
|
export { OIDCAdapter, createOIDCAdapter, oidcProviders } from "./adapters/oidc.js";
|
|
21
|
-
export { RedisSessionStore, createRedisSessionStore, DrizzleSessionStore, createDrizzleSessionStore, } from "./stores/index.js";
|
|
21
|
+
export { KVSessionStore, createKVSessionStore, RedisSessionStore, createRedisSessionStore, DrizzleSessionStore, createDrizzleSessionStore, } from "./stores/index.js";
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,iBAAiB,GAElB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,aAAa,GAGd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,8BAA8B,EAC9B,UAAU,EACV,WAAW,EACX,SAAS,EACT,aAAa,GAGd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,GAEhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,mBAAmB,EACnB,gBAAgB,GAIjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,mBAAmB,GAQpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,GAGxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,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YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,mBAAmB,GAQpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,GAGxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAKnB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAShF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,UAAU,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SessionData, SessionStore } from "../types.js";
|
|
2
2
|
import { DrizzleDatabase } from "../../resource/types.js";
|
|
3
|
+
import { type SessionKey, type TableResolver } from "../../db/internal-schema.js";
|
|
3
4
|
export interface SessionsTableColumns {
|
|
4
5
|
id: unknown;
|
|
5
6
|
userId: unknown;
|
|
@@ -9,22 +10,25 @@ export interface SessionsTableColumns {
|
|
|
9
10
|
}
|
|
10
11
|
export interface DrizzleSessionStoreOptions {
|
|
11
12
|
db: DrizzleDatabase;
|
|
12
|
-
table
|
|
13
|
+
table?: {
|
|
13
14
|
id: unknown;
|
|
14
15
|
userId: unknown;
|
|
15
16
|
createdAt: unknown;
|
|
16
17
|
expiresAt: unknown;
|
|
17
18
|
data: unknown;
|
|
18
19
|
} & Record<string, unknown>;
|
|
20
|
+
resolver?: TableResolver<SessionKey>;
|
|
19
21
|
cleanupIntervalMs?: number;
|
|
20
22
|
onError?: (error: Error) => void;
|
|
21
23
|
}
|
|
22
24
|
export declare class DrizzleSessionStore implements SessionStore {
|
|
23
25
|
private db;
|
|
24
|
-
private
|
|
26
|
+
private resolver;
|
|
25
27
|
private cleanupInterval?;
|
|
26
28
|
private onError?;
|
|
27
29
|
constructor(options: DrizzleSessionStoreOptions);
|
|
30
|
+
private get table();
|
|
31
|
+
private toSession;
|
|
28
32
|
get(sessionId: string): Promise<SessionData | null>;
|
|
29
33
|
set(sessionId: string, session: SessionData, _ttlMs: number): Promise<void>;
|
|
30
34
|
delete(sessionId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../src/auth/stores/drizzle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../src/auth/stores/drizzle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,eAAe,CAAC;IACpB,KAAK,CAAC,EAAE;QACN,EAAE,EAAE,OAAO,CAAC;QACZ,MAAM,EAAE,OAAO,CAAC;QAChB,SAAS,EAAE,OAAO,C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|
|
@@ -1,38 +1,57 @@
|
|
|
1
1
|
import { eq, and, gt, lt } from "drizzle-orm";
|
|
2
|
+
import { SESSION_KEYS, makeIdentityResolver, } from "../../db/internal-schema.js";
|
|
2
3
|
export class DrizzleSessionStore {
|
|
3
4
|
constructor(options) {
|
|
4
5
|
this.db = options.db;
|
|
5
|
-
|
|
6
|
+
if (options.resolver) {
|
|
7
|
+
this.resolver = options.resolver;
|
|
8
|
+
}
|
|
9
|
+
else if (options.table) {
|
|
10
|
+
this.resolver = makeIdentityResolver(options.table, SESSION_KEYS, "sessions");
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
throw new Error("DrizzleSessionStore requires either `resolver` or `table`");
|
|
14
|
+
}
|
|
6
15
|
this.onError = options.onError;
|
|
7
16
|
if (options.cleanupIntervalMs) {
|
|
8
17
|
this.cleanupInterval = setInterval(() => this.cleanup(), options.cleanupIntervalMs);
|
|
9
18
|
}
|
|
10
19
|
}
|
|
20
|
+
get table() {
|
|
21
|
+
return this.resolver.table;
|
|
22
|
+
}
|
|
23
|
+
toSession(row) {
|
|
24
|
+
const r = this.resolver;
|
|
25
|
+
const createdAt = row[r.prop("createdAt")];
|
|
26
|
+
const expiresAt = row[r.prop("expiresAt")];
|
|
27
|
+
const data = r.has("data") ? row[r.prop("data")] : undefined;
|
|
28
|
+
return {
|
|
29
|
+
id: row[r.prop("id")],
|
|
30
|
+
userId: row[r.prop("userId")],
|
|
31
|
+
createdAt: createdAt instanceof Date
|
|
32
|
+
? createdAt
|
|
33
|
+
: new Date(createdAt),
|
|
34
|
+
expiresAt: expiresAt instanceof Date
|
|
35
|
+
? expiresAt
|
|
36
|
+
: new Date(expiresAt),
|
|
37
|
+
data: data
|
|
38
|
+
? typeof data === "string"
|
|
39
|
+
? JSON.parse(data)
|
|
40
|
+
: data
|
|
41
|
+
: undefined,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
11
44
|
async get(sessionId) {
|
|
12
45
|
try {
|
|
46
|
+
const r = this.resolver;
|
|
13
47
|
const results = await this.db
|
|
14
48
|
.select()
|
|
15
49
|
.from(this.table)
|
|
16
|
-
.where(and(eq(
|
|
50
|
+
.where(and(eq(r.col("id"), sessionId), gt(r.col("expiresAt"), new Date())))
|
|
17
51
|
.limit(1);
|
|
18
52
|
if (results.length === 0)
|
|
19
53
|
return null;
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
id: row.id,
|
|
23
|
-
userId: row.userId,
|
|
24
|
-
createdAt: row.createdAt instanceof Date
|
|
25
|
-
? row.createdAt
|
|
26
|
-
: new Date(row.createdAt),
|
|
27
|
-
expiresAt: row.expiresAt instanceof Date
|
|
28
|
-
? row.expiresAt
|
|
29
|
-
: new Date(row.expiresAt),
|
|
30
|
-
data: row.data
|
|
31
|
-
? typeof row.data === "string"
|
|
32
|
-
? JSON.parse(row.data)
|
|
33
|
-
: row.data
|
|
34
|
-
: undefined,
|
|
35
|
-
};
|
|
54
|
+
return this.toSession(results[0]);
|
|
36
55
|
}
|
|
37
56
|
catch (error) {
|
|
38
57
|
this.onError?.(error);
|
|
@@ -41,30 +60,35 @@ export class DrizzleSessionStore {
|
|
|
41
60
|
}
|
|
42
61
|
async set(sessionId, session, _ttlMs) {
|
|
43
62
|
try {
|
|
63
|
+
const r = this.resolver;
|
|
44
64
|
const existing = await this.db
|
|
45
|
-
.select({ id:
|
|
65
|
+
.select({ id: r.col("id") })
|
|
46
66
|
.from(this.table)
|
|
47
|
-
.where(eq(
|
|
67
|
+
.where(eq(r.col("id"), sessionId))
|
|
48
68
|
.limit(1);
|
|
49
69
|
const dataValue = session.data ? JSON.stringify(session.data) : null;
|
|
50
70
|
if (existing.length > 0) {
|
|
71
|
+
const set = {
|
|
72
|
+
[r.prop("userId")]: session.userId,
|
|
73
|
+
[r.prop("expiresAt")]: session.expiresAt,
|
|
74
|
+
};
|
|
75
|
+
if (r.has("data"))
|
|
76
|
+
set[r.prop("data")] = dataValue;
|
|
51
77
|
await this.db
|
|
52
78
|
.update(this.table)
|
|
53
|
-
.set(
|
|
54
|
-
|
|
55
|
-
expiresAt: session.expiresAt,
|
|
56
|
-
data: dataValue,
|
|
57
|
-
})
|
|
58
|
-
.where(eq(this.table.id, sessionId));
|
|
79
|
+
.set(set)
|
|
80
|
+
.where(eq(r.col("id"), sessionId));
|
|
59
81
|
}
|
|
60
82
|
else {
|
|
61
|
-
|
|
62
|
-
id: session.id,
|
|
63
|
-
userId: session.userId,
|
|
64
|
-
createdAt: session.createdAt,
|
|
65
|
-
expiresAt: session.expiresAt,
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
const values = {
|
|
84
|
+
[r.prop("id")]: session.id,
|
|
85
|
+
[r.prop("userId")]: session.userId,
|
|
86
|
+
[r.prop("createdAt")]: session.createdAt,
|
|
87
|
+
[r.prop("expiresAt")]: session.expiresAt,
|
|
88
|
+
};
|
|
89
|
+
if (r.has("data"))
|
|
90
|
+
values[r.prop("data")] = dataValue;
|
|
91
|
+
await this.db.insert(this.table).values(values);
|
|
68
92
|
}
|
|
69
93
|
}
|
|
70
94
|
catch (error) {
|
|
@@ -76,7 +100,7 @@ export class DrizzleSessionStore {
|
|
|
76
100
|
try {
|
|
77
101
|
await this.db
|
|
78
102
|
.delete(this.table)
|
|
79
|
-
.where(eq(this.
|
|
103
|
+
.where(eq(this.resolver.col("id"), sessionId));
|
|
80
104
|
}
|
|
81
105
|
catch (error) {
|
|
82
106
|
this.onError?.(error);
|
|
@@ -84,10 +108,11 @@ export class DrizzleSessionStore {
|
|
|
84
108
|
}
|
|
85
109
|
async touch(sessionId, ttlMs) {
|
|
86
110
|
try {
|
|
111
|
+
const r = this.resolver;
|
|
87
112
|
await this.db
|
|
88
113
|
.update(this.table)
|
|
89
|
-
.set({ expiresAt: new Date(Date.now() + ttlMs) })
|
|
90
|
-
.where(eq(
|
|
114
|
+
.set({ [r.prop("expiresAt")]: new Date(Date.now() + ttlMs) })
|
|
115
|
+
.where(eq(r.col("id"), sessionId));
|
|
91
116
|
}
|
|
92
117
|
catch (error) {
|
|
93
118
|
this.onError?.(error);
|
|
@@ -98,22 +123,8 @@ export class DrizzleSessionStore {
|
|
|
98
123
|
const rows = (await this.db
|
|
99
124
|
.select()
|
|
100
125
|
.from(this.table)
|
|
101
|
-
.where(gt(this.
|
|
102
|
-
return rows.map((row) => (
|
|
103
|
-
id: row.id,
|
|
104
|
-
userId: row.userId,
|
|
105
|
-
createdAt: row.createdAt instanceof Date
|
|
106
|
-
? row.createdAt
|
|
107
|
-
: new Date(row.createdAt),
|
|
108
|
-
expiresAt: row.expiresAt instanceof Date
|
|
109
|
-
? row.expiresAt
|
|
110
|
-
: new Date(row.expiresAt),
|
|
111
|
-
data: row.data
|
|
112
|
-
? typeof row.data === "string"
|
|
113
|
-
? JSON.parse(row.data)
|
|
114
|
-
: row.data
|
|
115
|
-
: undefined,
|
|
116
|
-
}));
|
|
126
|
+
.where(gt(this.resolver.col("expiresAt"), new Date())));
|
|
127
|
+
return rows.map((row) => this.toSession(row));
|
|
117
128
|
}
|
|
118
129
|
catch (error) {
|
|
119
130
|
this.onError?.(error);
|
|
@@ -122,25 +133,12 @@ export class DrizzleSessionStore {
|
|
|
122
133
|
}
|
|
123
134
|
async getByUser(userId) {
|
|
124
135
|
try {
|
|
136
|
+
const r = this.resolver;
|
|
125
137
|
const rows = (await this.db
|
|
126
138
|
.select()
|
|
127
139
|
.from(this.table)
|
|
128
|
-
.where(and(eq(
|
|
129
|
-
return rows.map((row) => (
|
|
130
|
-
id: row.id,
|
|
131
|
-
userId: row.userId,
|
|
132
|
-
createdAt: row.createdAt instanceof Date
|
|
133
|
-
? row.createdAt
|
|
134
|
-
: new Date(row.createdAt),
|
|
135
|
-
expiresAt: row.expiresAt instanceof Date
|
|
136
|
-
? row.expiresAt
|
|
137
|
-
: new Date(row.expiresAt),
|
|
138
|
-
data: row.data
|
|
139
|
-
? typeof row.data === "string"
|
|
140
|
-
? JSON.parse(row.data)
|
|
141
|
-
: row.data
|
|
142
|
-
: undefined,
|
|
143
|
-
}));
|
|
140
|
+
.where(and(eq(r.col("userId"), userId), gt(r.col("expiresAt"), new Date()))));
|
|
141
|
+
return rows.map((row) => this.toSession(row));
|
|
144
142
|
}
|
|
145
143
|
catch (error) {
|
|
146
144
|
this.onError?.(error);
|
|
@@ -151,7 +149,7 @@ export class DrizzleSessionStore {
|
|
|
151
149
|
try {
|
|
152
150
|
const result = await this.db
|
|
153
151
|
.delete(this.table)
|
|
154
|
-
.where(eq(this.
|
|
152
|
+
.where(eq(this.resolver.col("userId"), userId));
|
|
155
153
|
return result.changes ?? 0;
|
|
156
154
|
}
|
|
157
155
|
catch (error) {
|
|
@@ -163,7 +161,7 @@ export class DrizzleSessionStore {
|
|
|
163
161
|
try {
|
|
164
162
|
const result = await this.db
|
|
165
163
|
.delete(this.table)
|
|
166
|
-
.where(lt(this.
|
|
164
|
+
.where(lt(this.resolver.col("expiresAt"), new Date()));
|
|
167
165
|
return result.changes ?? 0;
|
|
168
166
|
}
|
|
169
167
|
catch (error) {
|