@kontrolia/db 1.0.0 → 1.0.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,28 @@
|
|
|
1
|
+
-- log_device_revoked() (0013_audit_log_triggers.sql) falls back to the
|
|
2
|
+
-- device's own user_id as the actor when there's no session context, e.g.
|
|
3
|
+
-- an admin calling revoke_session() on someone else's device. That fallback
|
|
4
|
+
-- breaks when the DELETE on kontrolia.devices is itself the product of
|
|
5
|
+
-- `delete from auth.users ... on delete cascade`: by the time this AFTER
|
|
6
|
+
-- DELETE trigger's INSERT runs, the user's row is already gone from
|
|
7
|
+
-- auth.users (deleted earlier in the same transaction, and command-counter
|
|
8
|
+
-- visibility makes that immediate), so falling back to old.user_id trips
|
|
9
|
+
-- audit_logs_actor_user_id_fkey and the whole `delete from auth.users`
|
|
10
|
+
-- fails. Only use the fallback if that user still exists; otherwise log the
|
|
11
|
+
-- device revocation with a null actor, same as any other audit row for an
|
|
12
|
+
-- actor we can't identify.
|
|
13
|
+
create or replace function kontrolia.log_device_revoked()
|
|
14
|
+
returns trigger
|
|
15
|
+
language plpgsql
|
|
16
|
+
security definer
|
|
17
|
+
set search_path = ''
|
|
18
|
+
as $$
|
|
19
|
+
declare
|
|
20
|
+
fallback_actor uuid;
|
|
21
|
+
begin
|
|
22
|
+
select id into fallback_actor from auth.users where id = old.user_id;
|
|
23
|
+
|
|
24
|
+
insert into kontrolia.audit_logs (organization_id, actor_user_id, action, target_type, target_id, metadata)
|
|
25
|
+
values (null, coalesce(auth.uid(), fallback_actor), 'device.revoked', 'device', old.session_id::text, jsonb_build_object('label', old.label));
|
|
26
|
+
return old;
|
|
27
|
+
end;
|
|
28
|
+
$$;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontrolia/db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "KontrolIA Auth database layer: SQL migrations for the `kontrolia` schema (organizations, RBAC, Custom Access Token Hook) and a connection-string-agnostic migration runner.",
|
|
6
6
|
"keywords": [
|