@danylohotvianskyi/bobra-framework 0.1.9 → 0.2.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/batteries/auth/hash.ts +102 -36
- package/batteries/auth/token-metadata.ts +25 -8
- package/batteries/auth/token.ts +5 -5
- package/batteries/openapi/index.ts +62 -41
- package/batteries/openapi/merge-openapi.ts +125 -33
- package/core/config.ts +40 -14
- package/core/discovery.ts +16 -10
- package/core/env-resolver.ts +25 -11
- package/core/factory.ts +150 -77
- package/core/spa.ts +14 -8
- package/db/client.ts +80 -415
- package/db/drizzle-clients.ts +65 -0
- package/db/failover.ts +318 -0
- package/db/index.ts +1 -0
- package/db/migrate.ts +7 -6
- package/db/pgedge.ts +307 -0
- package/db/test/client.test.ts +346 -0
- package/db/token-auth.ts +40 -0
- package/db/types.ts +96 -0
- package/dist/batteries/auth/hash.d.ts +10 -2
- package/dist/batteries/auth/hash.js +78 -43
- package/dist/batteries/auth/hash.js.map +1 -1
- package/dist/batteries/auth/token-metadata.d.ts +3 -3
- package/dist/batteries/auth/token-metadata.js +14 -6
- package/dist/batteries/auth/token-metadata.js.map +1 -1
- package/dist/batteries/auth/token.d.ts +3 -3
- package/dist/batteries/auth/token.js +2 -2
- package/dist/batteries/auth/token.js.map +1 -1
- package/dist/batteries/openapi/index.d.ts +51 -13
- package/dist/batteries/openapi/index.js +25 -15
- package/dist/batteries/openapi/index.js.map +1 -1
- package/dist/batteries/openapi/merge-openapi.d.ts +26 -2
- package/dist/batteries/openapi/merge-openapi.js +83 -26
- package/dist/batteries/openapi/merge-openapi.js.map +1 -1
- package/dist/core/config.d.ts +26 -9
- package/dist/core/config.js +8 -7
- package/dist/core/config.js.map +1 -1
- package/dist/core/discovery.d.ts +18 -9
- package/dist/core/discovery.js +1 -1
- package/dist/core/discovery.js.map +1 -1
- package/dist/core/env-resolver.d.ts +7 -4
- package/dist/core/env-resolver.js +7 -5
- package/dist/core/env-resolver.js.map +1 -1
- package/dist/core/factory.d.ts +36 -16
- package/dist/core/factory.js +70 -38
- package/dist/core/factory.js.map +1 -1
- package/dist/core/spa.js +9 -4
- package/dist/core/spa.js.map +1 -1
- package/dist/db/client.d.ts +16 -66
- package/dist/db/client.js +40 -311
- package/dist/db/client.js.map +1 -1
- package/dist/db/drizzle-clients.d.ts +6 -0
- package/dist/db/drizzle-clients.js +42 -0
- package/dist/db/drizzle-clients.js.map +1 -0
- package/dist/db/failover.d.ts +39 -0
- package/dist/db/failover.js +267 -0
- package/dist/db/failover.js.map +1 -0
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +1 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrate.js +4 -4
- package/dist/db/migrate.js.map +1 -1
- package/dist/db/pgedge.d.ts +14 -0
- package/dist/db/pgedge.js +218 -0
- package/dist/db/pgedge.js.map +1 -0
- package/dist/db/token-auth.d.ts +34 -0
- package/dist/db/token-auth.js +15 -0
- package/dist/db/token-auth.js.map +1 -0
- package/dist/db/types.d.ts +82 -0
- package/dist/db/types.js +2 -0
- package/dist/db/types.js.map +1 -0
- package/dist/logging/logger.d.ts +13 -13
- package/dist/logging/logger.js +11 -2
- package/dist/logging/logger.js.map +1 -1
- package/dist/logging/logging-middleware.d.ts +1 -1
- package/dist/logging/logging-middleware.js +6 -6
- package/dist/logging/logging-middleware.js.map +1 -1
- package/dist/middleware/ensure-api-token.d.ts +33 -4
- package/dist/middleware/ensure-api-token.js.map +1 -1
- package/dist/middleware/utils.d.ts +5 -1
- package/dist/middleware/utils.js +11 -7
- package/dist/middleware/utils.js.map +1 -1
- package/dist/network/router.d.ts +9 -6
- package/dist/network/router.js +3 -1
- package/dist/network/router.js.map +1 -1
- package/dist/network/service-discovery.d.ts +1 -1
- package/dist/network/service-discovery.js.map +1 -1
- package/dist/network/service-fetch.d.ts +6 -9
- package/dist/network/service-fetch.js +14 -4
- package/dist/network/service-fetch.js.map +1 -1
- package/dist/node/generate-wrangler-config.d.ts +28 -4
- package/dist/node/generate-wrangler-config.js +75 -20
- package/dist/node/generate-wrangler-config.js.map +1 -1
- package/logging/logger.ts +31 -21
- package/logging/logging-middleware.ts +12 -9
- package/middleware/ensure-api-token.ts +8 -6
- package/middleware/utils.ts +26 -8
- package/network/router.ts +17 -13
- package/network/service-discovery.ts +1 -1
- package/network/service-fetch.ts +26 -17
- package/node/generate-wrangler-config.ts +160 -24
- package/package.json +10 -7
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { describe, expect, it, beforeAll } from 'vitest';
|
|
2
|
+
import { Pool, type PoolClient, type QueryResult, type QueryResultRow } from 'pg';
|
|
3
|
+
import {
|
|
4
|
+
buildOrderedPostgresCandidates,
|
|
5
|
+
type FailoverDirectClientAdapter,
|
|
6
|
+
FailoverPgPool,
|
|
7
|
+
type FailoverPoolAdapter,
|
|
8
|
+
isTransientConnectionOrUnavailableError,
|
|
9
|
+
resolvePgFailoverOptions,
|
|
10
|
+
type AppEnvBindings,
|
|
11
|
+
type PgFailoverOptions,
|
|
12
|
+
type PostgresCandidate,
|
|
13
|
+
} from '../client';
|
|
14
|
+
import { initializeLogger, LogLevel } from '../../logging/logger';
|
|
15
|
+
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
initializeLogger({
|
|
18
|
+
level: LogLevel.SILENT,
|
|
19
|
+
colorize: false,
|
|
20
|
+
includeContext: false,
|
|
21
|
+
includeTimestamp: false,
|
|
22
|
+
format: 'text',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function createQueryResult<R extends QueryResultRow>(rows: R[]): QueryResult<R> {
|
|
27
|
+
return {
|
|
28
|
+
command: 'SELECT',
|
|
29
|
+
rowCount: rows.length,
|
|
30
|
+
oid: 0,
|
|
31
|
+
rows,
|
|
32
|
+
fields: [],
|
|
33
|
+
} as QueryResult<R>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createMockPoolAdapter(
|
|
37
|
+
connectImpl: () => Promise<PoolClient>,
|
|
38
|
+
): FailoverPoolAdapter {
|
|
39
|
+
return {
|
|
40
|
+
query: async () => createQueryResult([]),
|
|
41
|
+
connect: connectImpl,
|
|
42
|
+
end: async () => undefined,
|
|
43
|
+
on: () => undefined,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createMockPoolClient(
|
|
48
|
+
queryImpl: (...args: unknown[]) => Promise<QueryResult<QueryResultRow>>,
|
|
49
|
+
): PoolClient {
|
|
50
|
+
return {
|
|
51
|
+
query: (...args: unknown[]) => queryImpl(...args),
|
|
52
|
+
release: () => undefined,
|
|
53
|
+
} as PoolClient;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createMockDirectClient(
|
|
57
|
+
queryImpl: (...args: unknown[]) => Promise<QueryResult<QueryResultRow>>,
|
|
58
|
+
connectImpl: () => Promise<void> = async () => undefined,
|
|
59
|
+
): FailoverDirectClientAdapter {
|
|
60
|
+
return {
|
|
61
|
+
connect: connectImpl,
|
|
62
|
+
query: (...args: unknown[]) => queryImpl(...args),
|
|
63
|
+
end: async () => undefined,
|
|
64
|
+
release: () => undefined,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('db/client failover', () => {
|
|
69
|
+
it('identifies nested transient network errors', () => {
|
|
70
|
+
const err = {
|
|
71
|
+
code: '58000',
|
|
72
|
+
message: 'Failed to acquire a connection from the pool.',
|
|
73
|
+
cause: {
|
|
74
|
+
code: 'ECONNRESET',
|
|
75
|
+
message: 'socket hang up',
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
expect(isTransientConnectionOrUnavailableError(err)).toBe(true);
|
|
80
|
+
expect(isTransientConnectionOrUnavailableError(new Error('Connection terminated unexpectedly'))).toBe(true);
|
|
81
|
+
expect(
|
|
82
|
+
isTransientConnectionOrUnavailableError(
|
|
83
|
+
new Error('Connecting to database via Cloudflare Tunnel failed: 502 Bad Gateway')
|
|
84
|
+
)
|
|
85
|
+
).toBe(true);
|
|
86
|
+
expect(isTransientConnectionOrUnavailableError({ code: '23505', message: 'duplicate key' })).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('keeps router-preferred location first in candidate ordering', () => {
|
|
90
|
+
const env: AppEnvBindings = {
|
|
91
|
+
POSTGRES_EU: { connectionString: 'postgres://eu' },
|
|
92
|
+
POSTGRES_US: { connectionString: 'postgres://us' },
|
|
93
|
+
POSTGRES: { connectionString: 'postgres://fallback' },
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const { candidates, orderedLocations } = buildOrderedPostgresCandidates(
|
|
97
|
+
env,
|
|
98
|
+
undefined,
|
|
99
|
+
['eu', 'us'],
|
|
100
|
+
() => 'us',
|
|
101
|
+
'NA',
|
|
102
|
+
{ continent: 'NA' },
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(orderedLocations).toEqual(['us', 'eu']);
|
|
106
|
+
expect(candidates[0]?.bindingName).toBe('POSTGRES_US');
|
|
107
|
+
expect(candidates[1]?.bindingName).toBe('POSTGRES_EU');
|
|
108
|
+
expect(candidates[2]?.bindingName).toBe('POSTGRES');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('disables failover when PGEDGE_FAILOVER_ENABLED is false', () => {
|
|
112
|
+
expect(resolvePgFailoverOptions({
|
|
113
|
+
PGEDGE_FAILOVER_ENABLED: 'false',
|
|
114
|
+
}, 2)).toEqual({
|
|
115
|
+
enabled: false,
|
|
116
|
+
connectionTimeoutMs: 2000,
|
|
117
|
+
warnLogging: true,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('falls back on transient query errors', async () => {
|
|
122
|
+
const calls: string[] = [];
|
|
123
|
+
const options: PgFailoverOptions = {
|
|
124
|
+
enabled: true,
|
|
125
|
+
connectionTimeoutMs: 2000,
|
|
126
|
+
warnLogging: false,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const candidates: PostgresCandidate[] = [
|
|
130
|
+
{ bindingName: 'POSTGRES_EU', binding: { connectionString: 'postgres://eu' }, location: 'eu' },
|
|
131
|
+
{ bindingName: 'POSTGRES_US', binding: { connectionString: 'postgres://us' }, location: 'us' },
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
const pool = new FailoverPgPool(
|
|
135
|
+
candidates,
|
|
136
|
+
options,
|
|
137
|
+
() => createMockPoolAdapter(async () => {
|
|
138
|
+
throw new Error('pool connect should not be used before the candidate is proven healthy');
|
|
139
|
+
}),
|
|
140
|
+
(candidate) => {
|
|
141
|
+
if (candidate.bindingName === 'POSTGRES_EU') {
|
|
142
|
+
return createMockDirectClient(async () => {
|
|
143
|
+
calls.push('eu-query');
|
|
144
|
+
const error = new Error('connection reset');
|
|
145
|
+
(error as Error & { code?: string }).code = 'ECONNRESET';
|
|
146
|
+
throw error;
|
|
147
|
+
}, async () => {
|
|
148
|
+
calls.push('eu-connect');
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return createMockDirectClient(async () => {
|
|
153
|
+
calls.push('us-query');
|
|
154
|
+
return createQueryResult([{ ok: 1 }]);
|
|
155
|
+
}, async () => {
|
|
156
|
+
calls.push('us-connect');
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const result = await pool.query('select 1');
|
|
162
|
+
expect(result.rows).toHaveLength(1);
|
|
163
|
+
expect(calls).toEqual(['eu-connect', 'eu-query', 'us-connect', 'us-query']);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('falls back on pg connection termination errors without an error code', async () => {
|
|
167
|
+
const calls: string[] = [];
|
|
168
|
+
const options: PgFailoverOptions = {
|
|
169
|
+
enabled: true,
|
|
170
|
+
connectionTimeoutMs: 2000,
|
|
171
|
+
warnLogging: false,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const candidates: PostgresCandidate[] = [
|
|
175
|
+
{ bindingName: 'POSTGRES_US', binding: { connectionString: 'postgres://us' }, location: 'us' },
|
|
176
|
+
{ bindingName: 'POSTGRES_EU', binding: { connectionString: 'postgres://eu' }, location: 'eu' },
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
const pool = new FailoverPgPool(
|
|
180
|
+
candidates,
|
|
181
|
+
options,
|
|
182
|
+
() => createMockPoolAdapter(async () => {
|
|
183
|
+
throw new Error('pool connect should not be used before the candidate is proven healthy');
|
|
184
|
+
}),
|
|
185
|
+
(candidate) => {
|
|
186
|
+
if (candidate.bindingName === 'POSTGRES_US') {
|
|
187
|
+
return createMockDirectClient(async () => {
|
|
188
|
+
calls.push('us-query');
|
|
189
|
+
throw new Error('Connection terminated unexpectedly');
|
|
190
|
+
}, async () => {
|
|
191
|
+
calls.push('us-connect');
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return createMockDirectClient(async () => {
|
|
196
|
+
calls.push('eu-query');
|
|
197
|
+
return createQueryResult([{ ok: 1 }]);
|
|
198
|
+
}, async () => {
|
|
199
|
+
calls.push('eu-connect');
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const result = await pool.query('select 1');
|
|
205
|
+
expect(result.rows).toHaveLength(1);
|
|
206
|
+
expect(calls).toEqual(['us-connect', 'us-query', 'eu-connect', 'eu-query']);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('does not fallback on non-transient connect errors', async () => {
|
|
210
|
+
const calls: string[] = [];
|
|
211
|
+
const options: PgFailoverOptions = {
|
|
212
|
+
enabled: true,
|
|
213
|
+
connectionTimeoutMs: 2000,
|
|
214
|
+
warnLogging: false,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const candidates: PostgresCandidate[] = [
|
|
218
|
+
{ bindingName: 'POSTGRES_EU', binding: { connectionString: 'postgres://eu' }, location: 'eu' },
|
|
219
|
+
{ bindingName: 'POSTGRES_US', binding: { connectionString: 'postgres://us' }, location: 'us' },
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
const pool = new FailoverPgPool(
|
|
223
|
+
candidates,
|
|
224
|
+
options,
|
|
225
|
+
() => createMockPoolAdapter(async () => {
|
|
226
|
+
throw new Error('pool connect should not be used before the candidate is proven healthy');
|
|
227
|
+
}),
|
|
228
|
+
(candidate) => {
|
|
229
|
+
if (candidate.bindingName === 'POSTGRES_EU') {
|
|
230
|
+
return createMockDirectClient(
|
|
231
|
+
async () => createQueryResult([{ ok: 1 }]),
|
|
232
|
+
async () => {
|
|
233
|
+
calls.push('eu-connect');
|
|
234
|
+
const error = new Error('duplicate key');
|
|
235
|
+
(error as Error & { code?: string }).code = '23505';
|
|
236
|
+
throw error;
|
|
237
|
+
},
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return createMockDirectClient(
|
|
242
|
+
async () => createQueryResult([{ ok: 1 }]),
|
|
243
|
+
async () => {
|
|
244
|
+
calls.push('us-connect');
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
},
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
await expect(pool.connect()).rejects.toMatchObject({ code: '23505' });
|
|
251
|
+
expect(calls).toEqual(['eu-connect']);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('falls back when reading the primary connection string throws', async () => {
|
|
255
|
+
const calls: string[] = [];
|
|
256
|
+
const options: PgFailoverOptions = {
|
|
257
|
+
enabled: true,
|
|
258
|
+
connectionTimeoutMs: 2000,
|
|
259
|
+
warnLogging: false,
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const failingBinding = Object.create(null) as { connectionString: string };
|
|
263
|
+
Object.defineProperty(failingBinding, 'connectionString', {
|
|
264
|
+
get() {
|
|
265
|
+
const error = new Error('connection refused during binding access');
|
|
266
|
+
(error as Error & { code?: string }).code = 'ECONNREFUSED';
|
|
267
|
+
throw error;
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const candidates: PostgresCandidate[] = [
|
|
272
|
+
{ bindingName: 'POSTGRES_EU', binding: failingBinding, location: 'eu' },
|
|
273
|
+
{ bindingName: 'POSTGRES_US', binding: { connectionString: 'postgres://us' }, location: 'us' },
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
const pool = new FailoverPgPool(
|
|
277
|
+
candidates,
|
|
278
|
+
options,
|
|
279
|
+
() => createMockPoolAdapter(async () => {
|
|
280
|
+
throw new Error('pool connect should not be used before the candidate is proven healthy');
|
|
281
|
+
}),
|
|
282
|
+
(candidate) => {
|
|
283
|
+
calls.push(candidate.bindingName);
|
|
284
|
+
void candidate.binding.connectionString;
|
|
285
|
+
return createMockDirectClient(
|
|
286
|
+
async () => createQueryResult([{ ok: 1 }]),
|
|
287
|
+
async () => {
|
|
288
|
+
calls.push(`${candidate.bindingName}-connect`);
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
},
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const result = await pool.query('select 1');
|
|
295
|
+
expect(result.rows).toHaveLength(1);
|
|
296
|
+
expect(calls).toEqual(['POSTGRES_EU', 'POSTGRES_US', 'POSTGRES_US-connect']);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('is a Pool instance so Drizzle transactions pin a single client', () => {
|
|
300
|
+
const pool = new FailoverPgPool([], {
|
|
301
|
+
enabled: true,
|
|
302
|
+
connectionTimeoutMs: 2000,
|
|
303
|
+
warnLogging: false,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
expect(pool).toBeInstanceOf(Pool);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('switches to pooled connections after a candidate proves healthy', async () => {
|
|
310
|
+
const calls: string[] = [];
|
|
311
|
+
const options: PgFailoverOptions = {
|
|
312
|
+
enabled: true,
|
|
313
|
+
connectionTimeoutMs: 2000,
|
|
314
|
+
warnLogging: false,
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const candidates: PostgresCandidate[] = [
|
|
318
|
+
{ bindingName: 'POSTGRES_US', binding: { connectionString: 'postgres://us' }, location: 'us' },
|
|
319
|
+
];
|
|
320
|
+
|
|
321
|
+
const pool = new FailoverPgPool(
|
|
322
|
+
candidates,
|
|
323
|
+
options,
|
|
324
|
+
() => createMockPoolAdapter(async () => {
|
|
325
|
+
calls.push('pool-connect');
|
|
326
|
+
return createMockPoolClient(async () => {
|
|
327
|
+
calls.push('pool-query');
|
|
328
|
+
return createQueryResult([{ ok: 2 }]);
|
|
329
|
+
});
|
|
330
|
+
}),
|
|
331
|
+
() => createMockDirectClient(async () => {
|
|
332
|
+
calls.push('direct-query');
|
|
333
|
+
return createQueryResult([{ ok: 1 }]);
|
|
334
|
+
}, async () => {
|
|
335
|
+
calls.push('direct-connect');
|
|
336
|
+
}),
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const firstResult = await pool.query('select 1');
|
|
340
|
+
const secondResult = await pool.query('select 2');
|
|
341
|
+
|
|
342
|
+
expect(firstResult.rows).toEqual([{ ok: 1 }]);
|
|
343
|
+
expect(secondResult.rows).toEqual([{ ok: 2 }]);
|
|
344
|
+
expect(calls).toEqual(['direct-connect', 'direct-query', 'pool-connect', 'pool-query']);
|
|
345
|
+
});
|
|
346
|
+
});
|
package/db/token-auth.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import type { TokenTableColumns } from './client';
|
|
3
|
+
|
|
4
|
+
export const dateLikeSchema = v.union([v.date(), v.string(), v.number()]);
|
|
5
|
+
export const ipAddressListSchema = v.array(v.string());
|
|
6
|
+
export const ipAddressesSchema = v.union([ipAddressListSchema, v.string(), v.null()]);
|
|
7
|
+
|
|
8
|
+
export const tokenRecordRawSchema = v.object({
|
|
9
|
+
uid: v.string(),
|
|
10
|
+
tokenHash: v.string(),
|
|
11
|
+
tokenSalt: v.string(),
|
|
12
|
+
expiresAt: dateLikeSchema,
|
|
13
|
+
createdAt: dateLikeSchema,
|
|
14
|
+
lastUsedAt: v.optional(v.union([dateLikeSchema, v.null()])),
|
|
15
|
+
ipAddresses: v.optional(ipAddressesSchema),
|
|
16
|
+
initToken: v.optional(v.union([v.boolean(), v.number(), v.null()])),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type TokenRecordRaw = v.InferOutput<typeof tokenRecordRawSchema>;
|
|
20
|
+
export type DateLike = v.InferOutput<typeof dateLikeSchema>;
|
|
21
|
+
export type IpAddressesLike = v.InferOutput<typeof ipAddressesSchema>;
|
|
22
|
+
|
|
23
|
+
export type TokenRecordInput = {
|
|
24
|
+
uid: string;
|
|
25
|
+
tokenHash: string;
|
|
26
|
+
tokenSalt: string;
|
|
27
|
+
expiresAt: Date | string | number;
|
|
28
|
+
createdAt: Date | string | number;
|
|
29
|
+
lastUsedAt?: Date | string | number | null;
|
|
30
|
+
ipAddresses?: string[] | string | null;
|
|
31
|
+
initToken?: boolean | number | null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type SelectFromLike = {
|
|
35
|
+
from(table: TokenTableColumns): Promise<TokenRecordInput[]>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type SelectableDbLike = {
|
|
39
|
+
select(fields: TokenTableColumns): SelectFromLike;
|
|
40
|
+
};
|
package/db/types.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { drizzle as drizzlePg } from 'drizzle-orm/node-postgres';
|
|
2
|
+
import { drizzle as drizzleD1 } from 'drizzle-orm/d1';
|
|
3
|
+
import type { AnyPgTable, AnyPgColumn } from 'drizzle-orm/pg-core';
|
|
4
|
+
import type { AnySQLiteTable, AnySQLiteColumn } from 'drizzle-orm/sqlite-core';
|
|
5
|
+
import type { D1Database, Hyperdrive } from '@cloudflare/workers-types';
|
|
6
|
+
|
|
7
|
+
export interface AppEnvBindings {
|
|
8
|
+
D1?: D1Database;
|
|
9
|
+
POSTGRES?: { connectionString: string };
|
|
10
|
+
DB_ENGINE?: string;
|
|
11
|
+
POSTGRES_URL?: string;
|
|
12
|
+
HYPERDRIVE?: Hyperdrive;
|
|
13
|
+
DEPLOYMENT_CONTEXT?: 'cloudflare' | 'self-hosted';
|
|
14
|
+
PGEDGE_ENABLED?: boolean | string;
|
|
15
|
+
PGEDGE_LOCATIONS?: string;
|
|
16
|
+
PGEDGE_DEBUG_LOGGING?: boolean | string;
|
|
17
|
+
PGEDGE_FAILOVER_ENABLED?: boolean | string;
|
|
18
|
+
PGEDGE_FAILOVER_CONNECTION_TIMEOUT_MS?: number | string;
|
|
19
|
+
PGEDGE_FAILOVER_WARN_LOGGING?: boolean | string;
|
|
20
|
+
__cfContinent?: string;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type DrizzleSchema = Record<string, unknown>;
|
|
25
|
+
|
|
26
|
+
export type DrizzleD1Client<S extends DrizzleSchema = DrizzleSchema> = ReturnType<typeof drizzleD1<S>>;
|
|
27
|
+
export type DrizzlePgClient<S extends DrizzleSchema = DrizzleSchema> = ReturnType<typeof drizzlePg<S>>;
|
|
28
|
+
|
|
29
|
+
export type TokenPgColumns = {
|
|
30
|
+
uid: AnyPgColumn;
|
|
31
|
+
tokenHash: AnyPgColumn;
|
|
32
|
+
tokenSalt: AnyPgColumn;
|
|
33
|
+
expiresAt: AnyPgColumn;
|
|
34
|
+
createdAt: AnyPgColumn;
|
|
35
|
+
lastUsedAt: AnyPgColumn;
|
|
36
|
+
initToken: AnyPgColumn;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type TokenSQLiteColumns = {
|
|
40
|
+
uid: AnySQLiteColumn;
|
|
41
|
+
tokenHash: AnySQLiteColumn;
|
|
42
|
+
tokenSalt: AnySQLiteColumn;
|
|
43
|
+
expiresAt: AnySQLiteColumn;
|
|
44
|
+
createdAt: AnySQLiteColumn;
|
|
45
|
+
lastUsedAt: AnySQLiteColumn;
|
|
46
|
+
initToken: AnySQLiteColumn;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type TokenTableColumns = TokenPgColumns | TokenSQLiteColumns;
|
|
50
|
+
|
|
51
|
+
export type TokenPgTable = AnyPgTable & TokenPgColumns;
|
|
52
|
+
export type TokenSQLiteTable = AnySQLiteTable & TokenSQLiteColumns;
|
|
53
|
+
|
|
54
|
+
export type TokenSchemaBindings = {
|
|
55
|
+
tokens: TokenPgTable;
|
|
56
|
+
tokensSqlite: TokenSQLiteTable;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export interface DatabaseContext<S extends DrizzleSchema = DrizzleSchema> {
|
|
60
|
+
type: 'postgres' | 'd1-sqlite';
|
|
61
|
+
db: DrizzleD1Client<S> | DrizzlePgClient<S>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface CfInfo {
|
|
65
|
+
continent?: string;
|
|
66
|
+
colo?: string;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type PgEdgeRouter = (locations: string[], cfContinentStr?: string, cfInfo?: unknown) => string;
|
|
71
|
+
export type PostgresBindingRole = string;
|
|
72
|
+
|
|
73
|
+
export interface DbContextOptions {
|
|
74
|
+
cfInfo?: CfInfo;
|
|
75
|
+
pgEdgeRouter?: PgEdgeRouter;
|
|
76
|
+
postgresBindingRole?: PostgresBindingRole;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface PostgresBinding {
|
|
80
|
+
connectionString: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ResolvedPostgresBinding {
|
|
84
|
+
bindingName: string;
|
|
85
|
+
binding: PostgresBinding;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface PostgresCandidate extends ResolvedPostgresBinding {
|
|
89
|
+
location?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface PgFailoverOptions {
|
|
93
|
+
enabled: boolean;
|
|
94
|
+
connectionTimeoutMs: number;
|
|
95
|
+
warnLogging: boolean;
|
|
96
|
+
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import { type DatabaseContext } from '../../db
|
|
1
|
+
import { type DatabaseContext, type DrizzleSchema, type TokenSchemaBindings, type TokenRecordInput, type TokenRecordRaw } from '../../db';
|
|
2
|
+
export declare function parseTokenRecord(input: TokenRecordInput): TokenRecordRaw | undefined;
|
|
3
|
+
export declare function parseIpAddressList(input: string[]): string[] | undefined;
|
|
2
4
|
export declare function hashToken(token: string, salt: string): Promise<string>;
|
|
3
|
-
export
|
|
5
|
+
export type MatchedTokenRecord = Omit<TokenRecordRaw, 'createdAt' | 'expiresAt' | 'lastUsedAt' | 'ipAddresses'> & {
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
expiresAt: Date;
|
|
8
|
+
lastUsedAt?: Date;
|
|
9
|
+
ipAddresses?: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function findTokenByHash(ctx: DatabaseContext<DrizzleSchema>, token: string, schema: TokenSchemaBindings): Promise<MatchedTokenRecord | null>;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { getLogger } from '../../logging/logger';
|
|
2
|
-
import {
|
|
2
|
+
import { isSQLiteContext, isPostgresContext, tokenRecordRawSchema, ipAddressListSchema, } from '../../db';
|
|
3
|
+
import * as v from 'valibot';
|
|
4
|
+
export function parseTokenRecord(input) {
|
|
5
|
+
const parsed = v.safeParse(tokenRecordRawSchema, input);
|
|
6
|
+
return parsed.success ? parsed.output : undefined;
|
|
7
|
+
}
|
|
8
|
+
export function parseIpAddressList(input) {
|
|
9
|
+
const parsed = v.safeParse(ipAddressListSchema, input);
|
|
10
|
+
return parsed.success ? parsed.output : undefined;
|
|
11
|
+
}
|
|
3
12
|
// Token hash algorithm configuration
|
|
4
13
|
const HASH_CONFIG = {
|
|
5
14
|
ALGORITHM: 'SHA-256'
|
|
@@ -12,56 +21,82 @@ export async function hashToken(token, salt) {
|
|
|
12
21
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
13
22
|
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
14
23
|
}
|
|
24
|
+
function normalizeDate(value) {
|
|
25
|
+
if (!value)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (value instanceof Date)
|
|
28
|
+
return value;
|
|
29
|
+
if (typeof value === 'number')
|
|
30
|
+
return new Date(value);
|
|
31
|
+
if (typeof value === 'string')
|
|
32
|
+
return new Date(value);
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function parseIps(value) {
|
|
36
|
+
if (!value)
|
|
37
|
+
return undefined;
|
|
38
|
+
if (Array.isArray(value))
|
|
39
|
+
return value;
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(value);
|
|
43
|
+
return parseIpAddressList(parsed);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
15
51
|
// Find a token record by computing hash against all stored records
|
|
16
52
|
export async function findTokenByHash(ctx, token, schema) {
|
|
17
53
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
54
|
+
let tokenRecords;
|
|
55
|
+
if (isSQLiteContext(ctx)) {
|
|
56
|
+
tokenRecords = await ctx.db.select({
|
|
57
|
+
uid: schema.tokensSqlite.uid,
|
|
58
|
+
tokenHash: schema.tokensSqlite.tokenHash,
|
|
59
|
+
tokenSalt: schema.tokensSqlite.tokenSalt,
|
|
60
|
+
expiresAt: schema.tokensSqlite.expiresAt,
|
|
61
|
+
createdAt: schema.tokensSqlite.createdAt,
|
|
62
|
+
lastUsedAt: schema.tokensSqlite.lastUsedAt,
|
|
63
|
+
initToken: schema.tokensSqlite.initToken
|
|
64
|
+
}).from(schema.tokensSqlite);
|
|
65
|
+
}
|
|
66
|
+
else if (isPostgresContext(ctx)) {
|
|
67
|
+
tokenRecords = await ctx.db.select({
|
|
68
|
+
uid: schema.tokens.uid,
|
|
69
|
+
tokenHash: schema.tokens.tokenHash,
|
|
70
|
+
tokenSalt: schema.tokens.tokenSalt,
|
|
71
|
+
expiresAt: schema.tokens.expiresAt,
|
|
72
|
+
createdAt: schema.tokens.createdAt,
|
|
73
|
+
lastUsedAt: schema.tokens.lastUsedAt,
|
|
74
|
+
initToken: schema.tokens.initToken
|
|
75
|
+
}).from(schema.tokens);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new Error('Unsupported database context type');
|
|
79
|
+
}
|
|
80
|
+
for (const rawRecord of tokenRecords) {
|
|
30
81
|
try {
|
|
82
|
+
const record = parseTokenRecord(rawRecord);
|
|
83
|
+
if (!record) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (typeof record.tokenSalt !== 'string' || typeof record.tokenHash !== 'string') {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
31
89
|
const computedHash = await hashToken(token, record.tokenSalt);
|
|
32
90
|
if (computedHash === record.tokenHash) {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return d;
|
|
39
|
-
if (typeof d === 'number')
|
|
40
|
-
return new Date(d);
|
|
41
|
-
if (typeof d === 'string')
|
|
42
|
-
return new Date(d);
|
|
43
|
-
return undefined;
|
|
44
|
-
};
|
|
45
|
-
// Parse ipAddresses if stored as text (sqlite)
|
|
46
|
-
const parseIps = (ips) => {
|
|
47
|
-
if (!ips)
|
|
48
|
-
return undefined;
|
|
49
|
-
if (Array.isArray(ips))
|
|
50
|
-
return ips;
|
|
51
|
-
if (typeof ips === 'string') {
|
|
52
|
-
try {
|
|
53
|
-
return JSON.parse(ips);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
60
|
-
};
|
|
91
|
+
const createdAt = normalizeDate(record.createdAt);
|
|
92
|
+
const expiresAt = normalizeDate(record.expiresAt);
|
|
93
|
+
if (!createdAt || !expiresAt) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
61
96
|
return {
|
|
62
97
|
...record,
|
|
63
|
-
createdAt
|
|
64
|
-
expiresAt
|
|
98
|
+
createdAt,
|
|
99
|
+
expiresAt,
|
|
65
100
|
lastUsedAt: normalizeDate(record.lastUsedAt),
|
|
66
101
|
ipAddresses: parseIps(record.ipAddresses)
|
|
67
102
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../batteries/auth/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../batteries/auth/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,eAAe,EACf,iBAAiB,EAQjB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACtD,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAe;IAChD,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC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C,KAAK,CAAC,gCAAgC,EAAE,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC3H,SAAS;YACX,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAS,EAAE,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7G,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type DatabaseContext } from '../../db/client';
|
|
1
|
+
import { type DatabaseContext, type DrizzleSchema, type TokenSchemaBindings } from '../../db/client';
|
|
2
2
|
export interface TokenMetadataUpdateClient {
|
|
3
|
-
ctx: DatabaseContext<
|
|
4
|
-
schema:
|
|
3
|
+
ctx: DatabaseContext<DrizzleSchema>;
|
|
4
|
+
schema: TokenSchemaBindings;
|
|
5
5
|
}
|
|
6
6
|
export declare function updateTokenLastUsed(client: TokenMetadataUpdateClient, tokenUid: string): Promise<void>;
|