@fabrika/iam 0.9.0-dev.35 → 0.9.0-dev.37
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/migrations/0035_grant_requests.sql +41 -0
- package/migrations/0036_grant_scope_sets.sql +14 -0
- package/migrations-postgres/0035_grant_requests.sql +41 -0
- package/migrations-postgres/0036_grant_scope_sets.sql +14 -0
- package/package.json +11 -11
- package/src/admin/api-keys.ts +8 -5
- package/src/admin/app-people.ts +54 -1
- package/src/admin/app-schema.ts +10 -2
- package/src/admin/grant-requests.ts +276 -0
- package/src/admin/grant-support.ts +56 -18
- package/src/admin/grants.ts +174 -46
- package/src/admin/rpc.ts +37 -0
- package/src/db.ts +5 -1
- package/src/oauth-http.ts +22 -2
- package/src/oauth.ts +52 -6
- package/src/repositories/app-schema.ts +9 -4
- package/src/repositories/audit.ts +5 -2
- package/src/repositories/grant-requests.ts +139 -0
- package/src/repositories/grants.ts +260 -30
- package/src/stored-permissions.ts +25 -1
- package/src/tokens.ts +1 -1
- package/types/src/admin/grant-requests.d.ts +42 -0
- package/types/src/admin/grant-support.d.ts +15 -6
- package/types/src/admin/grants.d.ts +4 -4
- package/types/src/db.d.ts +4 -1
- package/types/src/oauth.d.ts +20 -6
- package/types/src/repositories/app-schema.d.ts +4 -1
- package/types/src/repositories/audit.d.ts +2 -0
- package/types/src/repositories/grant-requests.d.ts +68 -0
- package/types/src/repositories/grants.d.ts +63 -2
- package/types/src/stored-permissions.d.ts +6 -0
- package/types/src/tokens.d.ts +7 -0
package/src/oauth.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
OAUTH_IDENTITY_SCOPE,
|
|
13
13
|
type OAuthAuthorizationRequest,
|
|
14
14
|
type OAuthClientMetadataDocument,
|
|
15
|
+
type OAuthIdentityRole,
|
|
15
16
|
type OAuthResourceDto,
|
|
16
17
|
type OAuthRevocationRequest,
|
|
17
18
|
type OAuthTokenRequest,
|
|
@@ -31,7 +32,7 @@ import { authorityDeadline, resolveAuthorityAt } from './resolve'
|
|
|
31
32
|
import { generateToken, hashToken, timingSafeEqualHex } from './secret'
|
|
32
33
|
import type { Services } from './services'
|
|
33
34
|
import { getSigner, verifyResourceAccessToken } from './signing'
|
|
34
|
-
import { boundedToken } from './tokens'
|
|
35
|
+
import { boundedToken, mailboxClaim } from './tokens'
|
|
35
36
|
|
|
36
37
|
/** An authorization code is redeemed by the client's back end within seconds of the redirect. */
|
|
37
38
|
export const OAUTH_CODE_TTL_SECONDS = 60
|
|
@@ -274,6 +275,7 @@ export async function mintForGrant(
|
|
|
274
275
|
scopes: authority.scopes,
|
|
275
276
|
grantId: grant.id,
|
|
276
277
|
tokenId: uuidv7(),
|
|
278
|
+
...(authority.identity === undefined ? {} : { ...mailboxClaim(authority.principal), ...authority.identity }),
|
|
277
279
|
})
|
|
278
280
|
const token = await boundedToken((await getSigner(env)).signResourceToken(claims), { app: grant.app, subject: authority.principal.id })
|
|
279
281
|
if (token === null) return null
|
|
@@ -285,6 +287,15 @@ export async function mintForGrant(
|
|
|
285
287
|
}
|
|
286
288
|
}
|
|
287
289
|
|
|
290
|
+
/** What a grant's next token carries. `identity` is present on an identity resource's: its roles, when it declares them. */
|
|
291
|
+
export interface GrantAuthority {
|
|
292
|
+
principal: PrincipalRow
|
|
293
|
+
scopes: string[]
|
|
294
|
+
permissions: PermissionEntry[]
|
|
295
|
+
expiresAt: number | null
|
|
296
|
+
identity?: { roles?: string[] }
|
|
297
|
+
}
|
|
298
|
+
|
|
288
299
|
/**
|
|
289
300
|
* Everything a grant needs to still mean something, checked at every code exchange and refresh: the
|
|
290
301
|
* grant live, its client and resource still configured, the IAM session it was given under live and
|
|
@@ -295,7 +306,7 @@ export async function grantAuthority(
|
|
|
295
306
|
grant: OAuthGrantRow,
|
|
296
307
|
now: number,
|
|
297
308
|
resourceUri: string = grant.resource,
|
|
298
|
-
): Promise<
|
|
309
|
+
): Promise<GrantAuthority | null> {
|
|
299
310
|
const config = services.config.oauth
|
|
300
311
|
if (config === null || grant.revoked_at !== null || grant.expires_at <= now || !grantResources(grant).includes(resourceUri)) return null
|
|
301
312
|
const scopes = parseOAuthScopes(parseJsonOrNull(grant.scopes))
|
|
@@ -307,8 +318,16 @@ export async function grantAuthority(
|
|
|
307
318
|
}
|
|
308
319
|
const principal = await services.repositories.principals.getPrincipalById(grant.principal_id)
|
|
309
320
|
if (principal === null || principal.type !== 'user' || principalStatus(principal) !== 'active') return null
|
|
310
|
-
|
|
311
|
-
|
|
321
|
+
if (ceiling.kind === 'identity') {
|
|
322
|
+
// An identity resource's token names the person and carries no permission. With declared roles it names those
|
|
323
|
+
// the person holds, and a person holding none gets no token: the grant stops at the next refresh.
|
|
324
|
+
const sessionEnd = sessionEndsAt(session, services.config)
|
|
325
|
+
if (ceiling.roles === undefined) return { principal, scopes, permissions: [], expiresAt: sessionEnd, identity: {} }
|
|
326
|
+
const held = await heldIdentityRoles(services, principal, grant.app, ceiling.roles)
|
|
327
|
+
if (held === null) return null
|
|
328
|
+
const expiresAt = Math.min(held.until ?? Number.POSITIVE_INFINITY, sessionEnd)
|
|
329
|
+
return { principal, scopes, permissions: [], expiresAt, identity: { roles: held.keys } }
|
|
330
|
+
}
|
|
312
331
|
const live = await resolveAuthorityAt(services, principal, grant.app)
|
|
313
332
|
const permissions = narrowPermissions(live.permissions, ceiling.permissions)
|
|
314
333
|
// A refreshed token ends with its login too: an OIDC login issued before the cap stores a later expiry than its end.
|
|
@@ -326,20 +345,47 @@ function grantCeiling(
|
|
|
326
345
|
grant: OAuthGrantRow,
|
|
327
346
|
resourceUri: string,
|
|
328
347
|
scopes: readonly string[],
|
|
329
|
-
): { kind: 'identity' } | { kind: 'scoped'; permissions: KeyGrant[] } | null {
|
|
348
|
+
): { kind: 'identity'; roles: readonly OAuthIdentityRole[] | undefined } | { kind: 'scoped'; permissions: KeyGrant[] } | null {
|
|
330
349
|
const cli = grant.client_id === OAUTH_CLI_CLIENT_ID
|
|
331
350
|
const client = config.clients.find((entry) => entry.clientId === grant.client_id)
|
|
332
351
|
if (!cli && client === undefined) return null
|
|
333
352
|
const identity = client?.identity
|
|
334
353
|
if (identity !== undefined) {
|
|
335
354
|
const matches = identity.resource === resourceUri && identity.app === grant.app && sameScopes(scopes, [OAUTH_IDENTITY_SCOPE])
|
|
336
|
-
return matches ? { kind: 'identity' } : null
|
|
355
|
+
return matches ? { kind: 'identity', roles: identity.roles } : null
|
|
337
356
|
}
|
|
338
357
|
const resource = config.resources.find((entry) => entry.resource === resourceUri && entry.app === grant.app && servesClient(entry, cli))
|
|
339
358
|
const permissions = resource === undefined ? null : scopeCeiling(resource, scopes)
|
|
340
359
|
return permissions === null ? null : { kind: 'scoped', permissions }
|
|
341
360
|
}
|
|
342
361
|
|
|
362
|
+
/**
|
|
363
|
+
* The declared roles `principal` holds at an external application, in declared order, and when the earliest of them
|
|
364
|
+
* ends (null: none ends); null when it holds none. Only a global grant of a declared role counts, and only for an
|
|
365
|
+
* internal principal: an external one holds nothing but roles its application declares external (ADR-0051).
|
|
366
|
+
*/
|
|
367
|
+
export async function heldIdentityRoles(
|
|
368
|
+
services: Services,
|
|
369
|
+
principal: PrincipalRow,
|
|
370
|
+
app: string,
|
|
371
|
+
declared: readonly OAuthIdentityRole[],
|
|
372
|
+
): Promise<{ keys: string[]; until: number | null } | null> {
|
|
373
|
+
if (principal.affiliation !== 'internal') return null
|
|
374
|
+
const grants = await services.repositories.grants.getActiveGrantsForApp(principal.id, app, { includeCrossApp: false })
|
|
375
|
+
const held = new Map<string, number | null>()
|
|
376
|
+
for (const grant of grants) {
|
|
377
|
+
const key = grant.role_key
|
|
378
|
+
if (key === null || grant.app !== app || grant.scope_type !== null || !declared.some((role) => role.key === key)) continue
|
|
379
|
+
const known = held.get(key)
|
|
380
|
+
// A role holds until the last of its grants ends.
|
|
381
|
+
held.set(key, known === undefined ? grant.expires_at : known === null || grant.expires_at === null ? null : Math.max(known, grant.expires_at))
|
|
382
|
+
}
|
|
383
|
+
const keys = declared.map((role) => role.key).filter((key) => held.has(key))
|
|
384
|
+
if (keys.length === 0) return null
|
|
385
|
+
const ends = [...held.values()].filter((until): until is number => until !== null)
|
|
386
|
+
return { keys, until: ends.length === 0 ? null : Math.min(...ends) }
|
|
387
|
+
}
|
|
388
|
+
|
|
343
389
|
function sameScopes(scopes: readonly string[], expected: readonly string[]): boolean {
|
|
344
390
|
return scopes.length === expected.length && scopes.every((scope, index) => scope === expected[index])
|
|
345
391
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseJsonStringArray, terminalIdentifyProblem, type WorkloadKind } from '@fabrika/auth-core'
|
|
1
|
+
import { type DimensionValue, parseJsonStringArray, terminalIdentifyProblem, type WorkloadKind } from '@fabrika/auth-core'
|
|
2
2
|
import { type SqlDatabase, type SqlStatement } from '@fabrika/platform'
|
|
3
3
|
|
|
4
4
|
import { type AuditEventInput, auditEventStatement, AuditWriter } from './audit'
|
|
@@ -40,6 +40,8 @@ export interface AppScopeRow {
|
|
|
40
40
|
members_directory: 'labels' | null
|
|
41
41
|
/** A JSON array of the actions that look up one member (`findMember`), or null for none. */
|
|
42
42
|
members_lookup: string | null
|
|
43
|
+
/** A JSON array of the `{ value, label? }` the console offers for a grant here (ADR-0085), or null for none. */
|
|
44
|
+
value_list: string | null
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
/** A share-link mount (the `app_link_mounts` table). `grants` is a JSON array of exact actions. */
|
|
@@ -350,6 +352,7 @@ export class AppSchemaRepository {
|
|
|
350
352
|
creatorRole?: string | null
|
|
351
353
|
members?: { manage: string; list: string } | null
|
|
352
354
|
directory?: 'labels' | null
|
|
355
|
+
values?: readonly DimensionValue[] | null
|
|
353
356
|
lookups?: string[] | null
|
|
354
357
|
}[]
|
|
355
358
|
actions: { action: string; description?: string | null }[]
|
|
@@ -436,8 +439,8 @@ export class AppSchemaRepository {
|
|
|
436
439
|
statements.push(
|
|
437
440
|
this.db
|
|
438
441
|
.prepare(
|
|
439
|
-
`INSERT INTO app_scopes (app, scope_type, label, parent_scope, creator_role, members_manage, members_list, members_directory, members_lookup)
|
|
440
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
442
|
+
`INSERT INTO app_scopes (app, scope_type, label, parent_scope, creator_role, members_manage, members_list, members_directory, members_lookup, value_list)
|
|
443
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
441
444
|
ON CONFLICT (app, scope_type) DO UPDATE SET
|
|
442
445
|
label = excluded.label,
|
|
443
446
|
parent_scope = excluded.parent_scope,
|
|
@@ -445,7 +448,8 @@ export class AppSchemaRepository {
|
|
|
445
448
|
members_manage = excluded.members_manage,
|
|
446
449
|
members_list = excluded.members_list,
|
|
447
450
|
members_directory = excluded.members_directory,
|
|
448
|
-
members_lookup = excluded.members_lookup
|
|
451
|
+
members_lookup = excluded.members_lookup,
|
|
452
|
+
value_list = excluded.value_list`,
|
|
449
453
|
)
|
|
450
454
|
.bind(
|
|
451
455
|
app,
|
|
@@ -457,6 +461,7 @@ export class AppSchemaRepository {
|
|
|
457
461
|
scope.members?.list ?? null,
|
|
458
462
|
scope.directory ?? null,
|
|
459
463
|
scope.lookups == null || scope.lookups.length === 0 ? null : JSON.stringify(scope.lookups),
|
|
464
|
+
scope.values == null ? null : JSON.stringify(scope.values),
|
|
460
465
|
),
|
|
461
466
|
)
|
|
462
467
|
}
|
|
@@ -148,6 +148,8 @@ export interface AuditedChange {
|
|
|
148
148
|
readonly statements: SqlStatement[]
|
|
149
149
|
/** The rows the LAST change returned, read from the results of a batch whose statements start at `offset`. */
|
|
150
150
|
rows<T>(results: SqlQueryResult<T>[], offset?: number): T[]
|
|
151
|
+
/** The id of the record, which exists after the batch exactly when the change changed a row; null without a record. */
|
|
152
|
+
readonly recordId: string | null
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
/**
|
|
@@ -176,6 +178,7 @@ export class AuditWriter {
|
|
|
176
178
|
return {
|
|
177
179
|
statements: changes.map((change) => this.db.prepare(change.sql).bind(...change.binds)),
|
|
178
180
|
rows: (results, offset = 0) => results[offset + last]?.results ?? [],
|
|
181
|
+
recordId: null,
|
|
179
182
|
}
|
|
180
183
|
}
|
|
181
184
|
const id = uuidv7()
|
|
@@ -188,7 +191,7 @@ export class AuditWriter {
|
|
|
188
191
|
INSERT INTO audit_events ${AUDIT_COLUMNS} SELECT ${AUDIT_PLACEHOLDERS} WHERE ${changed} RETURNING id
|
|
189
192
|
) SELECT * FROM c${changes.length - 1}`)
|
|
190
193
|
.bind(...changes.flatMap((change) => change.binds), ...values)
|
|
191
|
-
return { statements: [statement], rows: (results, offset = 0) => results[offset]?.results ?? [] }
|
|
194
|
+
return { statements: [statement], rows: (results, offset = 0) => results[offset]?.results ?? [], recordId: id }
|
|
192
195
|
}
|
|
193
196
|
const statements = changes.flatMap((change) => [
|
|
194
197
|
this.db.prepare(change.sql).bind(...change.binds),
|
|
@@ -198,7 +201,7 @@ export class AuditWriter {
|
|
|
198
201
|
.bind(...values, id),
|
|
199
202
|
])
|
|
200
203
|
const last = (changes.length - 1) * 2
|
|
201
|
-
return { statements, rows: (results, offset = 0) => results[offset + last]?.results ?? [] }
|
|
204
|
+
return { statements, rows: (results, offset = 0) => results[offset + last]?.results ?? [], recordId: id }
|
|
202
205
|
}
|
|
203
206
|
|
|
204
207
|
/** Run one audited group as its own batch and answer the rows its last change returned. */
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { type SqlDatabase, uuidv7 } from '@fabrika/platform'
|
|
2
|
+
import { type AuditEventInput, AuditWriter } from './audit'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One requested grant change at an application whose console grants wait for approval (ADR-0083). Nothing that resolves
|
|
6
|
+
* permissions reads it; `GrantRepository.applyRequest` writes the change when a person approves it.
|
|
7
|
+
*/
|
|
8
|
+
export interface GrantRequestRow {
|
|
9
|
+
id: string
|
|
10
|
+
app: string
|
|
11
|
+
kind: 'create' | 'update' | 'revoke'
|
|
12
|
+
principal_id: string
|
|
13
|
+
/** The grant an `update` edits or a `revoke` removes; null for `create`. */
|
|
14
|
+
grant_id: string | null
|
|
15
|
+
role_key: string | null
|
|
16
|
+
/** Inline action-pattern set (JSON array); XOR `role_key`. */
|
|
17
|
+
permissions: string | null
|
|
18
|
+
scope_type: string | null
|
|
19
|
+
/** The first of the requested values, or the only one; null for a global grant. */
|
|
20
|
+
scope_value: string | null
|
|
21
|
+
/** Every requested value (JSON array) when there are several (ADR-0085); read through `requestScopeValues`. */
|
|
22
|
+
scope_values: string | null
|
|
23
|
+
grant_expires_at: number | null
|
|
24
|
+
requested_by: string
|
|
25
|
+
requested_at: number
|
|
26
|
+
expires_at: number
|
|
27
|
+
status: 'pending' | 'approved' | 'rejected' | 'failed'
|
|
28
|
+
/** The approval that claimed it, which the change it wrote carries in its guard. */
|
|
29
|
+
decision_id: string | null
|
|
30
|
+
decided_by: string | null
|
|
31
|
+
decided_at: number | null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CreateGrantRequestInput {
|
|
35
|
+
app: string
|
|
36
|
+
kind: GrantRequestRow['kind']
|
|
37
|
+
principalId: string
|
|
38
|
+
grantId: string | null
|
|
39
|
+
roleKey: string | null
|
|
40
|
+
permissions: string[] | null
|
|
41
|
+
scopeType: string | null
|
|
42
|
+
/** Sorted and distinct; null for a global grant. */
|
|
43
|
+
scopeValues: string[] | null
|
|
44
|
+
grantExpiresAt: number | null
|
|
45
|
+
requestedBy: string
|
|
46
|
+
requestedAt: number
|
|
47
|
+
expiresAt: number
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class GrantRequestRepository {
|
|
51
|
+
constructor(
|
|
52
|
+
private readonly db: SqlDatabase,
|
|
53
|
+
private readonly writer: AuditWriter = new AuditWriter(db, 'sqlite'),
|
|
54
|
+
) {}
|
|
55
|
+
|
|
56
|
+
/** Whether a grant change at `app` waits for approval. */
|
|
57
|
+
async grantsWait(app: string): Promise<boolean> {
|
|
58
|
+
const row = await this.db.prepare('SELECT required FROM app_grant_approvals WHERE app = ?').bind(app).first<{ required: number }>()
|
|
59
|
+
return row?.required === 1
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Set whether grant changes at `app` wait, as of Control's protection `revision`. An older revision than the stored one
|
|
64
|
+
* changes nothing, so a caller that lost the environment's lease cannot undo its successor's gate. The record is written
|
|
65
|
+
* only when `required` changes.
|
|
66
|
+
*/
|
|
67
|
+
async setGrantsWait(
|
|
68
|
+
app: string,
|
|
69
|
+
required: boolean,
|
|
70
|
+
revision: number,
|
|
71
|
+
now: number,
|
|
72
|
+
audit: AuditEventInput,
|
|
73
|
+
): Promise<{ required: boolean; revision: number }> {
|
|
74
|
+
const current = this.db
|
|
75
|
+
.prepare(`INSERT INTO app_grant_approvals (app, required, revision, updated_at) VALUES (?, 0, ?, ?)
|
|
76
|
+
ON CONFLICT (app) DO UPDATE SET revision = excluded.revision, updated_at = excluded.updated_at
|
|
77
|
+
WHERE app_grant_approvals.revision <= excluded.revision`)
|
|
78
|
+
.bind(app, revision, now)
|
|
79
|
+
const change = this.writer.changed([{
|
|
80
|
+
sql: 'UPDATE app_grant_approvals SET required = ? WHERE app = ? AND revision = ? AND required <> ? RETURNING app',
|
|
81
|
+
binds: [required ? 1 : 0, app, revision, required ? 1 : 0],
|
|
82
|
+
}], audit)
|
|
83
|
+
const read = this.db.prepare('SELECT required, revision FROM app_grant_approvals WHERE app = ?').bind(app)
|
|
84
|
+
const results = await this.db.batch<{ required: number; revision: number }>([current, ...change.statements, read])
|
|
85
|
+
const [stored] = results[results.length - 1]?.results ?? []
|
|
86
|
+
if (stored === undefined) throw new Error('the grant gate row is missing after its upsert')
|
|
87
|
+
return { required: stored.required === 1, revision: stored.revision }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async create(input: CreateGrantRequestInput, audit: (requestId: string) => AuditEventInput): Promise<GrantRequestRow> {
|
|
91
|
+
const id = uuidv7()
|
|
92
|
+
const [created] = await this.writer.run<GrantRequestRow>([{
|
|
93
|
+
sql: `INSERT INTO grant_requests (id, app, kind, principal_id, grant_id, role_key, permissions, scope_type, scope_value,
|
|
94
|
+
scope_values, grant_expires_at, requested_by, requested_at, expires_at)
|
|
95
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
|
|
96
|
+
binds: [
|
|
97
|
+
id,
|
|
98
|
+
input.app,
|
|
99
|
+
input.kind,
|
|
100
|
+
input.principalId,
|
|
101
|
+
input.grantId,
|
|
102
|
+
input.roleKey,
|
|
103
|
+
input.permissions === null ? null : JSON.stringify(input.permissions),
|
|
104
|
+
input.scopeType,
|
|
105
|
+
input.scopeValues?.[0] ?? null,
|
|
106
|
+
input.scopeValues !== null && input.scopeValues.length > 1 ? JSON.stringify(input.scopeValues) : null,
|
|
107
|
+
input.grantExpiresAt,
|
|
108
|
+
input.requestedBy,
|
|
109
|
+
input.requestedAt,
|
|
110
|
+
input.expiresAt,
|
|
111
|
+
],
|
|
112
|
+
}], audit(id))
|
|
113
|
+
if (created === undefined) throw new Error('a grant request insert returned no row')
|
|
114
|
+
return created
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async get(id: string): Promise<GrantRequestRow | null> {
|
|
118
|
+
return await this.db.prepare('SELECT * FROM grant_requests WHERE id = ?').bind(id).first<GrantRequestRow>()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Every request still open at `now`, the oldest first. */
|
|
122
|
+
async listOpen(now: number): Promise<GrantRequestRow[]> {
|
|
123
|
+
const { results } = await this.db
|
|
124
|
+
.prepare(`SELECT * FROM grant_requests WHERE status = 'pending' AND expires_at > ? ORDER BY requested_at, id`)
|
|
125
|
+
.bind(now)
|
|
126
|
+
.all<GrantRequestRow>()
|
|
127
|
+
return results
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Reject an open request; null when it was decided or lapsed meanwhile. */
|
|
131
|
+
async reject(id: string, decidedBy: string, now: number, audit: AuditEventInput): Promise<GrantRequestRow | null> {
|
|
132
|
+
const [rejected] = await this.writer.run<GrantRequestRow>([{
|
|
133
|
+
sql: `UPDATE grant_requests SET status = 'rejected', decision_id = ?, decided_by = ?, decided_at = ?
|
|
134
|
+
WHERE id = ? AND status = 'pending' AND expires_at > ? RETURNING *`,
|
|
135
|
+
binds: [uuidv7(), decidedBy, now, id, now],
|
|
136
|
+
}], audit)
|
|
137
|
+
return rejected ?? null
|
|
138
|
+
}
|
|
139
|
+
}
|