@dokebi/oauth 0.0.0-stage → 0.1.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.
@@ -0,0 +1,363 @@
1
+ import { OAuthError } from './errors.js';
2
+ import { checkClient, checkCode, checkGrant, } from './store.js';
3
+ export const DEFAULT_TABLE_PREFIX = 'dokebi_oauth';
4
+ /** The statements that create the three tables (what the migration runs; also in AI.md). */
5
+ export function oauthTableStatements(dialect, prefix = DEFAULT_TABLE_PREFIX) {
6
+ const index = prefix.replace('.', '_');
7
+ if (dialect === 'postgres')
8
+ return [
9
+ `CREATE TABLE IF NOT EXISTS ${prefix}_grants (
10
+ id varchar(22) NOT NULL PRIMARY KEY,
11
+ realm varchar(32) NOT NULL,
12
+ user_id varchar(255) NOT NULL,
13
+ client_id text NOT NULL,
14
+ client_name text NOT NULL,
15
+ resource varchar(64) NOT NULL,
16
+ scopes text NOT NULL,
17
+ kind varchar(64),
18
+ binding text,
19
+ created_at bigint NOT NULL,
20
+ expires_at bigint NOT NULL,
21
+ last_used_at bigint,
22
+ revoked_at bigint
23
+ )`,
24
+ `CREATE INDEX IF NOT EXISTS ${index}_grants_user ON ${prefix}_grants (realm, user_id)`,
25
+ `CREATE INDEX IF NOT EXISTS ${index}_grants_expires ON ${prefix}_grants (expires_at)`,
26
+ `CREATE TABLE IF NOT EXISTS ${prefix}_codes (
27
+ code_hash varchar(43) NOT NULL PRIMARY KEY,
28
+ grant_id varchar(22) NOT NULL,
29
+ realm varchar(32) NOT NULL,
30
+ user_id varchar(255) NOT NULL,
31
+ client_id text NOT NULL,
32
+ redirect_uri text NOT NULL,
33
+ challenge varchar(43) NOT NULL,
34
+ resource varchar(64) NOT NULL,
35
+ scopes text NOT NULL,
36
+ created_at bigint NOT NULL,
37
+ expires_at bigint NOT NULL,
38
+ used_at bigint
39
+ )`,
40
+ `CREATE INDEX IF NOT EXISTS ${index}_codes_expires ON ${prefix}_codes (expires_at)`,
41
+ `CREATE TABLE IF NOT EXISTS ${prefix}_clients (
42
+ client_id varchar(64) NOT NULL PRIMARY KEY,
43
+ name text NOT NULL,
44
+ redirect_uris text NOT NULL,
45
+ created_at bigint NOT NULL,
46
+ last_used_at bigint NOT NULL
47
+ )`,
48
+ `CREATE INDEX IF NOT EXISTS ${index}_clients_used ON ${prefix}_clients (last_used_at)`,
49
+ ];
50
+ return [
51
+ `CREATE TABLE IF NOT EXISTS ${prefix}_grants (
52
+ id VARCHAR(22) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
53
+ realm VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
54
+ user_id VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
55
+ client_id TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
56
+ client_name TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
57
+ resource VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
58
+ scopes TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
59
+ kind VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
60
+ binding TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
61
+ created_at BIGINT NOT NULL,
62
+ expires_at BIGINT NOT NULL,
63
+ last_used_at BIGINT NULL,
64
+ revoked_at BIGINT NULL,
65
+ KEY ${index}_grants_user (realm, user_id),
66
+ KEY ${index}_grants_expires (expires_at)
67
+ ) ENGINE=InnoDB`,
68
+ `CREATE TABLE IF NOT EXISTS ${prefix}_codes (
69
+ code_hash VARCHAR(43) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
70
+ grant_id VARCHAR(22) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
71
+ realm VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
72
+ user_id VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
73
+ client_id TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
74
+ redirect_uri TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
75
+ challenge VARCHAR(43) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
76
+ resource VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
77
+ scopes TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
78
+ created_at BIGINT NOT NULL,
79
+ expires_at BIGINT NOT NULL,
80
+ used_at BIGINT NULL,
81
+ KEY ${index}_codes_expires (expires_at)
82
+ ) ENGINE=InnoDB`,
83
+ `CREATE TABLE IF NOT EXISTS ${prefix}_clients (
84
+ client_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
85
+ name TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
86
+ redirect_uris TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
87
+ created_at BIGINT NOT NULL,
88
+ last_used_at BIGINT NOT NULL,
89
+ KEY ${index}_clients_used (last_used_at)
90
+ ) ENGINE=InnoDB`,
91
+ ];
92
+ }
93
+ /** The statements that remove the three tables (the migration's `down`). */
94
+ export function dropOAuthTableStatements(prefix = DEFAULT_TABLE_PREFIX) {
95
+ return ['clients', 'codes', 'grants'].map((table) => `DROP TABLE IF EXISTS ${prefix}_${table}`);
96
+ }
97
+ const isQueryable = (value) => value !== null &&
98
+ typeof value === 'object' &&
99
+ typeof value.query === 'function';
100
+ /** `?` placeholders as `$1, $2, …` for pg. */
101
+ function numbered(sql) {
102
+ let index = 0;
103
+ return sql.replace(/\?/g, () => `$${++index}`);
104
+ }
105
+ /**
106
+ * Finds which driver a pool is by the shape of one `SELECT 1` answer (no DDL, no write): pg
107
+ * answers `{ rows }`, mysql2/promise `[rows, fields]`, mariadb an array of rows. Anything else
108
+ * (a MongoDB client has no `query`) is undefined.
109
+ */
110
+ export async function sqlQuery(resource) {
111
+ if (!isQueryable(resource))
112
+ return undefined;
113
+ const probe = await Promise.resolve(resource.query('SELECT 1 AS one'));
114
+ if (probe !== null && typeof probe === 'object' && Array.isArray(probe.rows))
115
+ return {
116
+ dialect: 'postgres',
117
+ query: async (sql, values) => {
118
+ const result = (await resource.query(numbered(sql), [...values]));
119
+ return { rows: result.rows, affected: Number(result.rowCount ?? 0) };
120
+ },
121
+ };
122
+ if (Array.isArray(probe) && Array.isArray(probe[0]))
123
+ return {
124
+ dialect: 'mysql',
125
+ query: async (sql, values) => {
126
+ const [result] = (await resource.query(sql, [...values]));
127
+ return Array.isArray(result)
128
+ ? { rows: result, affected: 0 }
129
+ : { rows: [], affected: Number(result.affectedRows) };
130
+ },
131
+ };
132
+ if (Array.isArray(probe))
133
+ return {
134
+ dialect: 'mariadb',
135
+ query: async (sql, values) => {
136
+ const result = (await resource.query(sql, [...values]));
137
+ return Array.isArray(result)
138
+ ? { rows: [...result], affected: 0 }
139
+ : { rows: [], affected: Number(result.affectedRows) };
140
+ },
141
+ };
142
+ return undefined;
143
+ }
144
+ const time = (value) => value === null || value === undefined ? null : Number(value);
145
+ const nullable = (value) => value === null || value === undefined ? null : String(value);
146
+ const strings = (value) => JSON.parse(String(value));
147
+ const MISSING_TABLE = new Set([
148
+ '42P01',
149
+ 'ER_NO_SUCH_TABLE',
150
+ 1146,
151
+ '1146',
152
+ '42703',
153
+ 'ER_BAD_FIELD_ERROR',
154
+ 1054,
155
+ '1054',
156
+ ]);
157
+ function missingTable(error) {
158
+ const value = error;
159
+ return MISSING_TABLE.has(value?.code) || MISSING_TABLE.has(value?.errno);
160
+ }
161
+ export class SqlOAuthStore {
162
+ name = 'sql';
163
+ /** 'unknown' in a describing app (D-0133): the pool was never asked. */
164
+ dialect;
165
+ #query;
166
+ #grants;
167
+ #codes;
168
+ #clients;
169
+ constructor(query, dialect, prefix) {
170
+ this.#query = query;
171
+ this.dialect = dialect;
172
+ this.#grants = `${prefix}_grants`;
173
+ this.#codes = `${prefix}_codes`;
174
+ this.#clients = `${prefix}_clients`;
175
+ }
176
+ /** Start: the three tables must exist (a migration made them). */
177
+ async check(connection) {
178
+ for (const [table, column] of [
179
+ [this.#grants, 'binding'],
180
+ [this.#codes, 'challenge'],
181
+ [this.#clients, 'redirect_uris'],
182
+ ])
183
+ try {
184
+ await this.#query(`SELECT ${column} FROM ${table} WHERE 1 = 0`, []);
185
+ }
186
+ catch (cause) {
187
+ if (missingTable(cause))
188
+ throw new OAuthError('TABLE_MISSING', `The OAuth table ${table} does not exist`, {
189
+ cause,
190
+ fix: `Run the migration that creates it, then npx dokebi-migrate up and restart. dokebi add wrote src/infra/db/migrations/${connection}/<time>_dokebi_oauth.ts, or copy the SQL from the @dokebi/oauth AI.md "SQL tables" section into npx dokebi-migrate make dokebi_oauth --connection ${connection}. The app never creates tables at start.`,
191
+ data: { table, connection },
192
+ });
193
+ throw cause;
194
+ }
195
+ }
196
+ #grant(record) {
197
+ return checkGrant({
198
+ id: record.id,
199
+ realm: record.realm,
200
+ userId: record.user_id,
201
+ clientId: record.client_id,
202
+ clientName: record.client_name,
203
+ resource: record.resource,
204
+ scopes: strings(record.scopes),
205
+ kind: nullable(record.kind),
206
+ binding: nullable(record.binding),
207
+ createdAt: Number(record.created_at),
208
+ expiresAt: Number(record.expires_at),
209
+ lastUsedAt: time(record.last_used_at),
210
+ revokedAt: time(record.revoked_at),
211
+ }, this.name);
212
+ }
213
+ #code(record) {
214
+ return checkCode({
215
+ hash: record.code_hash,
216
+ grantId: record.grant_id,
217
+ realm: record.realm,
218
+ userId: record.user_id,
219
+ clientId: record.client_id,
220
+ redirectUri: record.redirect_uri,
221
+ challenge: record.challenge,
222
+ resource: record.resource,
223
+ scopes: strings(record.scopes),
224
+ createdAt: Number(record.created_at),
225
+ expiresAt: Number(record.expires_at),
226
+ usedAt: time(record.used_at),
227
+ }, this.name);
228
+ }
229
+ #client(record) {
230
+ return checkClient({
231
+ id: record.client_id,
232
+ name: record.name,
233
+ redirectUris: strings(record.redirect_uris),
234
+ createdAt: Number(record.created_at),
235
+ lastUsedAt: Number(record.last_used_at),
236
+ }, this.name);
237
+ }
238
+ async insertGrant(row) {
239
+ await this.#query(`INSERT INTO ${this.#grants} (id, realm, user_id, client_id, client_name, resource, scopes, kind, binding, created_at, expires_at, last_used_at, revoked_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
240
+ row.id,
241
+ row.realm,
242
+ row.userId,
243
+ row.clientId,
244
+ row.clientName,
245
+ row.resource,
246
+ JSON.stringify(row.scopes),
247
+ row.kind,
248
+ row.binding,
249
+ row.createdAt,
250
+ row.expiresAt,
251
+ row.lastUsedAt,
252
+ row.revokedAt,
253
+ ]);
254
+ }
255
+ async findGrant(id) {
256
+ const { rows } = await this.#query(`SELECT * FROM ${this.#grants} WHERE id = ?`, [id]);
257
+ return rows[0] ? this.#grant(rows[0]) : undefined;
258
+ }
259
+ async listGrants(realm, userId) {
260
+ const { rows } = await this.#query(`SELECT * FROM ${this.#grants} WHERE realm = ? AND user_id = ? ORDER BY created_at`, [realm, userId]);
261
+ return rows.map((row) => this.#grant(row));
262
+ }
263
+ async revokeGrant(id, at) {
264
+ const { affected } = await this.#query(`UPDATE ${this.#grants} SET revoked_at = ? WHERE id = ? AND revoked_at IS NULL`, [at, id]);
265
+ return affected === 1;
266
+ }
267
+ async touchGrant(id, at) {
268
+ await this.#query(`UPDATE ${this.#grants} SET last_used_at = ? WHERE id = ?`, [at, id]);
269
+ }
270
+ async insertCode(row) {
271
+ await this.#query(`INSERT INTO ${this.#codes} (code_hash, grant_id, realm, user_id, client_id, redirect_uri, challenge, resource, scopes, created_at, expires_at, used_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
272
+ row.hash,
273
+ row.grantId,
274
+ row.realm,
275
+ row.userId,
276
+ row.clientId,
277
+ row.redirectUri,
278
+ row.challenge,
279
+ row.resource,
280
+ JSON.stringify(row.scopes),
281
+ row.createdAt,
282
+ row.expiresAt,
283
+ row.usedAt,
284
+ ]);
285
+ }
286
+ async findCode(hash) {
287
+ const { rows } = await this.#query(`SELECT * FROM ${this.#codes} WHERE code_hash = ?`, [hash]);
288
+ return rows[0] ? this.#code(rows[0]) : undefined;
289
+ }
290
+ async consumeCode(hash, at) {
291
+ const update = `UPDATE ${this.#codes} SET used_at = ? WHERE code_hash = ? AND used_at IS NULL`;
292
+ if (this.dialect === 'postgres') {
293
+ const { rows } = await this.#query(`${update} RETURNING *`, [at, hash]);
294
+ if (rows[0])
295
+ return { row: { ...this.#code(rows[0]), usedAt: null }, first: true };
296
+ }
297
+ else {
298
+ const { affected } = await this.#query(update, [at, hash]);
299
+ if (affected === 1) {
300
+ const row = await this.findCode(hash);
301
+ if (row)
302
+ return { row: { ...row, usedAt: null }, first: true };
303
+ }
304
+ }
305
+ // Lost: either nobody has this code, or it was used already (a replay).
306
+ const row = await this.findCode(hash);
307
+ return row ? { row, first: false } : undefined;
308
+ }
309
+ async insertClient(row) {
310
+ await this.#query(`INSERT INTO ${this.#clients} (client_id, name, redirect_uris, created_at, last_used_at) VALUES (?, ?, ?, ?, ?)`, [row.id, row.name, JSON.stringify(row.redirectUris), row.createdAt, row.lastUsedAt]);
311
+ }
312
+ async findClient(id) {
313
+ const { rows } = await this.#query(`SELECT * FROM ${this.#clients} WHERE client_id = ?`, [id]);
314
+ return rows[0] ? this.#client(rows[0]) : undefined;
315
+ }
316
+ async touchClient(id, at) {
317
+ await this.#query(`UPDATE ${this.#clients} SET last_used_at = ? WHERE client_id = ?`, [at, id]);
318
+ }
319
+ async purge(settings) {
320
+ const grants = await this.#query(`DELETE FROM ${this.#grants} WHERE revoked_at IS NOT NULL OR expires_at <= ?`, [settings.now]);
321
+ const codes = await this.#query(`DELETE FROM ${this.#codes} WHERE expires_at <= ?`, [
322
+ settings.now - settings.codeGraceMs,
323
+ ]);
324
+ const clients = await this.#query(`DELETE FROM ${this.#clients} WHERE last_used_at <= ?`, [
325
+ settings.now - settings.clientUnusedMs,
326
+ ]);
327
+ return { grants: grants.affected, codes: codes.affected, clients: clients.affected };
328
+ }
329
+ }
330
+ /** Opens the sql store on a dokebi-db resource (checked: the driver and the tables). */
331
+ /** The connection is not a SQL pool this store can use. */
332
+ function unsupported(connection) {
333
+ return new OAuthError('UNSUPPORTED_RESOURCE', `Connection ${connection} is not a pg, mysql2/promise or mariadb pool`, {
334
+ fix: 'Give store.connection a dokebi-db connection whose adapter returns a pg Pool, a mysql2/promise Pool or a mariadb Pool. MongoDB is not supported: use the redis or memory store.',
335
+ data: { connection },
336
+ });
337
+ }
338
+ /** The query of a store in a describing app (D-0133): nothing reaches the database. */
339
+ const describedQuery = () => Promise.reject(new OAuthError('DESCRIBING', 'The OAuth SQL store is being described (dokebi describe): no query runs'));
340
+ export async function openSqlStore(resource, options, logger, describing = false) {
341
+ // D-0133: a describing app opened no connection (D-0077 B). The pool is not asked which
342
+ // driver it is (a query) and the tables are not checked; only its shape is.
343
+ if (describing) {
344
+ if (!isQueryable(resource))
345
+ throw unsupported(options.connection);
346
+ logger.log('debug', 'OAuth SQL store not opened in describe mode', {
347
+ connection: options.connection,
348
+ tablePrefix: options.tablePrefix,
349
+ });
350
+ return new SqlOAuthStore(describedQuery, 'unknown', options.tablePrefix);
351
+ }
352
+ const opened = await sqlQuery(resource);
353
+ if (!opened)
354
+ throw unsupported(options.connection);
355
+ const store = new SqlOAuthStore(opened.query, opened.dialect, options.tablePrefix);
356
+ await store.check(options.connection);
357
+ logger.log('debug', 'OAuth SQL store ready', {
358
+ connection: options.connection,
359
+ dialect: opened.dialect,
360
+ tablePrefix: options.tablePrefix,
361
+ });
362
+ return store;
363
+ }
@@ -0,0 +1,126 @@
1
+ import type { Awaitable } from '@dokebi/core';
2
+ /** One grant: one authorization of a client by a user for a resource with some scopes (D-0124). */
3
+ export interface GrantRow {
4
+ /** The grant id, also the dokebi-auth token family of its tokens (22 base64url characters). */
5
+ readonly id: string;
6
+ readonly realm: string;
7
+ readonly userId: string;
8
+ readonly clientId: string;
9
+ /** The display name at the consent (client host first). */
10
+ readonly clientName: string;
11
+ /** The resource id (an options key; the audience of the tokens). */
12
+ readonly resource: string;
13
+ readonly scopes: readonly string[];
14
+ /** The kind of connection the application chose at the consent (a short word), or null. */
15
+ readonly kind: string | null;
16
+ /** What the connection reaches, as the application's JSON text (at most 4 KB), or null. */
17
+ readonly binding: string | null;
18
+ /** Epoch ms of the consent. */
19
+ readonly createdAt: number;
20
+ /** The absolute end (`createdAt + grant.maxDays`): no refresh moves it. */
21
+ readonly expiresAt: number;
22
+ /** Last use on a protected route or the token endpoint (written at most once a minute). */
23
+ readonly lastUsedAt: number | null;
24
+ readonly revokedAt: number | null;
25
+ }
26
+ /** One authorization code (stored as sha256; bound to everything the exchange checks). */
27
+ export interface CodeRow {
28
+ /** sha256 of the code, base64url (43 characters). */
29
+ readonly hash: string;
30
+ readonly grantId: string;
31
+ readonly realm: string;
32
+ readonly userId: string;
33
+ readonly clientId: string;
34
+ readonly redirectUri: string;
35
+ /** The PKCE S256 challenge. */
36
+ readonly challenge: string;
37
+ readonly resource: string;
38
+ readonly scopes: readonly string[];
39
+ readonly createdAt: number;
40
+ readonly expiresAt: number;
41
+ readonly usedAt: number | null;
42
+ }
43
+ /** A client registered through dynamic client registration (public: no secret). */
44
+ export interface ClientRow {
45
+ readonly id: string;
46
+ readonly name: string;
47
+ readonly redirectUris: readonly string[];
48
+ readonly createdAt: number;
49
+ readonly lastUsedAt: number;
50
+ }
51
+ /** What `consumeCode` answers: the row and whether this call was the first use. */
52
+ export interface ConsumedCode {
53
+ readonly row: CodeRow;
54
+ /** False: the code was used before (a replay; the caller revokes what it issued). */
55
+ readonly first: boolean;
56
+ }
57
+ /** What `purge` deletes. */
58
+ export interface PurgeSettings {
59
+ /** Now (epoch ms). */
60
+ readonly now: number;
61
+ /** Codes are kept this long after they expire (a late replay is still recognized). */
62
+ readonly codeGraceMs: number;
63
+ /** Registered clients unused this long are deleted. */
64
+ readonly clientUnusedMs: number;
65
+ }
66
+ /**
67
+ * How long a registered client is kept after its last use (R5-OAUTH-5, user decision c):
68
+ * `clientUnusedMs`, but never less than `refreshMs` — its last use at the token endpoint may have
69
+ * given it a refresh token that runs that long. Every store and purge use this one value.
70
+ */
71
+ export declare function clientKeptMs(clientUnusedMs: number, refreshMs: number | undefined): number;
72
+ export interface PurgeCounts {
73
+ readonly grants: number;
74
+ readonly codes: number;
75
+ readonly clients: number;
76
+ }
77
+ export interface OAuthStore {
78
+ /** `memory`, `sql` or `redis`, for logs. */
79
+ readonly name: string;
80
+ insertGrant(row: GrantRow): Promise<void>;
81
+ findGrant(id: string): Promise<GrantRow | undefined>;
82
+ /** Every grant of a user in a realm (revoked and expired ones too; the plugin filters). */
83
+ listGrants(realm: string, userId: string): Promise<GrantRow[]>;
84
+ /** Marks a grant revoked; true when it existed and was not revoked yet. */
85
+ revokeGrant(id: string, at: number): Promise<boolean>;
86
+ touchGrant(id: string, at: number): Promise<void>;
87
+ insertCode(row: CodeRow): Promise<void>;
88
+ /** The code with this hash (used ones too), or undefined; uses nothing. */
89
+ findCode(hash: string): Promise<CodeRow | undefined>;
90
+ /** Marks a code used, atomically; undefined for an unknown code. */
91
+ consumeCode(hash: string, at: number): Promise<ConsumedCode | undefined>;
92
+ insertClient(row: ClientRow): Promise<void>;
93
+ findClient(id: string): Promise<ClientRow | undefined>;
94
+ touchClient(id: string, at: number): Promise<void>;
95
+ /** Deletes expired codes and grants, revoked grants and unused clients. */
96
+ purge(settings: PurgeSettings): Promise<PurgeCounts>;
97
+ close?(): Awaitable<void>;
98
+ }
99
+ export declare function checkGrant(value: unknown, store: string): GrantRow;
100
+ export declare function checkCode(value: unknown, store: string): CodeRow;
101
+ export declare function checkClient(value: unknown, store: string): ClientRow;
102
+ /** In process memory: exact and atomic in one process, gone on restart, not shared by workers. */
103
+ export declare class MemoryOAuthStore implements OAuthStore {
104
+ #private;
105
+ readonly name = "memory";
106
+ /**
107
+ * `maxGrants`, `maxGrantsPerUser`, `maxClients`, `maxCodes` and `fullRetryAfterMs`
108
+ * (`storeFullRetryAfterMs`) come from dokebi.yaml (D-0113 §5).
109
+ */
110
+ constructor(maxGrants?: number, maxGrantsPerUser?: number, maxClients?: number, limits?: {
111
+ readonly maxCodes?: number;
112
+ readonly fullRetryAfterMs?: number;
113
+ });
114
+ insertGrant(row: GrantRow): Promise<void>;
115
+ findGrant(id: string): Promise<GrantRow | undefined>;
116
+ listGrants(realm: string, userId: string): Promise<GrantRow[]>;
117
+ revokeGrant(id: string, at: number): Promise<boolean>;
118
+ touchGrant(id: string, at: number): Promise<void>;
119
+ insertCode(row: CodeRow): Promise<void>;
120
+ findCode(hash: string): Promise<CodeRow | undefined>;
121
+ consumeCode(hash: string, at: number): Promise<ConsumedCode | undefined>;
122
+ insertClient(row: ClientRow): Promise<void>;
123
+ findClient(id: string): Promise<ClientRow | undefined>;
124
+ touchClient(id: string, at: number): Promise<void>;
125
+ purge(settings: PurgeSettings): Promise<PurgeCounts>;
126
+ }