@colveor/core 1.3.0 → 1.3.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/CHANGELOG.md +19 -0
- package/dist/database/migrations/1784284557960-audit-partitioning.d.ts +17 -0
- package/dist/database/migrations/1784284557960-audit-partitioning.d.ts.map +1 -0
- package/dist/database/migrations/1784284557960-audit-partitioning.js +427 -0
- package/dist/database/migrations/1784284557960-audit-partitioning.js.map +1 -0
- package/dist/database/migrations/1784284557961-audit-chain-seq-ensure.d.ts +14 -0
- package/dist/database/migrations/1784284557961-audit-chain-seq-ensure.d.ts.map +1 -0
- package/dist/database/migrations/1784284557961-audit-chain-seq-ensure.js +86 -0
- package/dist/database/migrations/1784284557961-audit-chain-seq-ensure.js.map +1 -0
- package/dist/database/seeds/settings.seed.d.ts.map +1 -1
- package/dist/database/seeds/settings.seed.js +4 -3
- package/dist/database/seeds/settings.seed.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/modules/audit/services/audit-write.service.d.ts.map +1 -1
- package/dist/modules/audit/services/audit-write.service.js +2 -4
- package/dist/modules/audit/services/audit-write.service.js.map +1 -1
- package/dist/modules/file-upload/constants/upload-categories.d.ts +41 -0
- package/dist/modules/file-upload/constants/upload-categories.d.ts.map +1 -0
- package/dist/modules/file-upload/constants/upload-categories.js +142 -0
- package/dist/modules/file-upload/constants/upload-categories.js.map +1 -0
- package/dist/modules/file-upload/constants/upload.types.d.ts +1 -0
- package/dist/modules/file-upload/constants/upload.types.d.ts.map +1 -1
- package/dist/modules/file-upload/constants/upload.types.js +2 -1
- package/dist/modules/file-upload/constants/upload.types.js.map +1 -1
- package/dist/modules/file-upload/index.d.ts +1 -0
- package/dist/modules/file-upload/index.d.ts.map +1 -1
- package/dist/modules/file-upload/index.js +1 -0
- package/dist/modules/file-upload/index.js.map +1 -1
- package/dist/modules/file-upload/services/file-upload.service.d.ts.map +1 -1
- package/dist/modules/file-upload/services/file-upload.service.js +5 -3
- package/dist/modules/file-upload/services/file-upload.service.js.map +1 -1
- package/dist/modules/settings/constants/settings.defaults.d.ts +7 -21
- package/dist/modules/settings/constants/settings.defaults.d.ts.map +1 -1
- package/dist/modules/settings/constants/settings.defaults.js +3 -46
- package/dist/modules/settings/constants/settings.defaults.js.map +1 -1
- package/dist/modules/settings/services/settings.service.d.ts.map +1 -1
- package/dist/modules/settings/services/settings.service.js +6 -0
- package/dist/modules/settings/services/settings.service.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [1.3.1](https://github.com/colveor/core/compare/v1.3.0...v1.3.1) (2026-07-31)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* ensure audit_events chain sequence exists ([c802f2b](https://github.com/colveor/core/commit/c802f2b4a118de8958926d8b06454bb483f5b132))
|
|
6
|
+
|
|
7
|
+
## [1.3.0](https://github.com/colveor/core/compare/v1.2.1...v1.3.0) (2026-07-31)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* export upload categories registry for host apps ([f42c631](https://github.com/colveor/core/commit/f42c631b3667c4044f67bda984e5495c4d20defd))
|
|
12
|
+
|
|
13
|
+
## [1.2.1](https://github.com/colveor/core/compare/v1.2.0...v1.2.1) (2026-07-30)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* correct formatting in audit partitioning migration and test ([5cafb19](https://github.com/colveor/core/commit/5cafb19b790868a412a7d19bc637fcf0c4497532))
|
|
18
|
+
* restore audit_events partitioning after full-schema ([57fd535](https://github.com/colveor/core/commit/57fd5354e26f0137d1ebe1b543e29c34e280ac45))
|
|
19
|
+
|
|
1
20
|
## [1.2.0](https://github.com/colveor/core/compare/v1.1.0...v1.2.0) (2026-07-30)
|
|
2
21
|
|
|
3
22
|
### Features
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MigrationInterface, type QueryRunner } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* Post–full-schema audit hardening (TypeORM generate cannot emit this):
|
|
4
|
+
* - range-partition `audit_events` by `created_at`
|
|
5
|
+
* - SECURITY DEFINER legal_hold / purge / seal / partition helpers
|
|
6
|
+
* - ownership split + REVOKE UPDATE/DELETE when privileges allow
|
|
7
|
+
* - immutability trigger + `colveor_audit_owner` schema CREATE for monthly partitions
|
|
8
|
+
*
|
|
9
|
+
* Idempotent: if `audit_events` is already partitioned, conversion is skipped and
|
|
10
|
+
* helpers/grants are still (re)applied.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AuditPartitioning1784284557960 implements MigrationInterface {
|
|
13
|
+
name: string;
|
|
14
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
15
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=1784284557960-audit-partitioning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1784284557960-audit-partitioning.d.ts","sourceRoot":"","sources":["../../../src/database/migrations/1784284557960-audit-partitioning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpE;;;;;;;;;GASG;AACH,qBAAa,8BAA+B,YAAW,kBAAkB;IACxE,IAAI,SAAoC;IAE3B,EAAE,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAoZ3C,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAwE1D"}
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuditPartitioning1784284557960 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Post–full-schema audit hardening (TypeORM generate cannot emit this):
|
|
6
|
+
* - range-partition `audit_events` by `created_at`
|
|
7
|
+
* - SECURITY DEFINER legal_hold / purge / seal / partition helpers
|
|
8
|
+
* - ownership split + REVOKE UPDATE/DELETE when privileges allow
|
|
9
|
+
* - immutability trigger + `colveor_audit_owner` schema CREATE for monthly partitions
|
|
10
|
+
*
|
|
11
|
+
* Idempotent: if `audit_events` is already partitioned, conversion is skipped and
|
|
12
|
+
* helpers/grants are still (re)applied.
|
|
13
|
+
*/
|
|
14
|
+
class AuditPartitioning1784284557960 {
|
|
15
|
+
name = 'AuditPartitioning1784284557960';
|
|
16
|
+
async up(queryRunner) {
|
|
17
|
+
await queryRunner.query(`
|
|
18
|
+
CREATE OR REPLACE FUNCTION audit_events_immutable_guard()
|
|
19
|
+
RETURNS trigger
|
|
20
|
+
LANGUAGE plpgsql
|
|
21
|
+
AS $$
|
|
22
|
+
DECLARE
|
|
23
|
+
mode text := current_setting('app.audit_mutation', true);
|
|
24
|
+
BEGIN
|
|
25
|
+
IF TG_OP = 'DELETE' THEN
|
|
26
|
+
IF mode = 'purge' THEN
|
|
27
|
+
RETURN OLD;
|
|
28
|
+
END IF;
|
|
29
|
+
RAISE EXCEPTION 'audit_events is append-only (DELETE denied)';
|
|
30
|
+
END IF;
|
|
31
|
+
|
|
32
|
+
IF TG_OP = 'UPDATE' THEN
|
|
33
|
+
IF mode = 'legal_hold' THEN
|
|
34
|
+
IF NEW.id IS DISTINCT FROM OLD.id
|
|
35
|
+
OR NEW.created_at IS DISTINCT FROM OLD.created_at
|
|
36
|
+
OR NEW.actor_type IS DISTINCT FROM OLD.actor_type
|
|
37
|
+
OR NEW.actor_id IS DISTINCT FROM OLD.actor_id
|
|
38
|
+
OR NEW.action IS DISTINCT FROM OLD.action
|
|
39
|
+
OR NEW.resource_type IS DISTINCT FROM OLD.resource_type
|
|
40
|
+
OR NEW.resource_id IS DISTINCT FROM OLD.resource_id
|
|
41
|
+
OR NEW.status IS DISTINCT FROM OLD.status
|
|
42
|
+
OR NEW.metadata IS DISTINCT FROM OLD.metadata
|
|
43
|
+
OR NEW.ip_address IS DISTINCT FROM OLD.ip_address
|
|
44
|
+
OR NEW.device_info IS DISTINCT FROM OLD.device_info
|
|
45
|
+
OR NEW.request_id IS DISTINCT FROM OLD.request_id
|
|
46
|
+
OR NEW.correlation_id IS DISTINCT FROM OLD.correlation_id
|
|
47
|
+
OR NEW.trace_id IS DISTINCT FROM OLD.trace_id
|
|
48
|
+
OR NEW.chain_seq IS DISTINCT FROM OLD.chain_seq
|
|
49
|
+
OR NEW.event_hash IS DISTINCT FROM OLD.event_hash
|
|
50
|
+
OR NEW.prev_hash IS DISTINCT FROM OLD.prev_hash
|
|
51
|
+
THEN
|
|
52
|
+
RAISE EXCEPTION 'audit_events legal_hold mode may only toggle legal_hold';
|
|
53
|
+
END IF;
|
|
54
|
+
RETURN NEW;
|
|
55
|
+
END IF;
|
|
56
|
+
|
|
57
|
+
IF mode = 'seal' THEN
|
|
58
|
+
IF OLD.event_hash IS NOT NULL THEN
|
|
59
|
+
RAISE EXCEPTION 'audit_events seal mode only allowed when event_hash is null';
|
|
60
|
+
END IF;
|
|
61
|
+
IF NEW.id IS DISTINCT FROM OLD.id
|
|
62
|
+
OR NEW.created_at IS DISTINCT FROM OLD.created_at
|
|
63
|
+
OR NEW.actor_type IS DISTINCT FROM OLD.actor_type
|
|
64
|
+
OR NEW.actor_id IS DISTINCT FROM OLD.actor_id
|
|
65
|
+
OR NEW.action IS DISTINCT FROM OLD.action
|
|
66
|
+
OR NEW.resource_type IS DISTINCT FROM OLD.resource_type
|
|
67
|
+
OR NEW.resource_id IS DISTINCT FROM OLD.resource_id
|
|
68
|
+
OR NEW.status IS DISTINCT FROM OLD.status
|
|
69
|
+
OR NEW.metadata IS DISTINCT FROM OLD.metadata
|
|
70
|
+
OR NEW.ip_address IS DISTINCT FROM OLD.ip_address
|
|
71
|
+
OR NEW.device_info IS DISTINCT FROM OLD.device_info
|
|
72
|
+
OR NEW.request_id IS DISTINCT FROM OLD.request_id
|
|
73
|
+
OR NEW.correlation_id IS DISTINCT FROM OLD.correlation_id
|
|
74
|
+
OR NEW.trace_id IS DISTINCT FROM OLD.trace_id
|
|
75
|
+
OR NEW.chain_seq IS DISTINCT FROM OLD.chain_seq
|
|
76
|
+
OR NEW.legal_hold IS DISTINCT FROM OLD.legal_hold
|
|
77
|
+
THEN
|
|
78
|
+
RAISE EXCEPTION 'audit_events seal mode may only set event_hash/prev_hash';
|
|
79
|
+
END IF;
|
|
80
|
+
RETURN NEW;
|
|
81
|
+
END IF;
|
|
82
|
+
|
|
83
|
+
RAISE EXCEPTION 'audit_events is append-only (UPDATE denied)';
|
|
84
|
+
END IF;
|
|
85
|
+
|
|
86
|
+
RETURN NEW;
|
|
87
|
+
END;
|
|
88
|
+
$$
|
|
89
|
+
`);
|
|
90
|
+
// Drop helpers before rename so RETURN SETOF does not pin the old type.
|
|
91
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_set_legal_hold(uuid, boolean)`);
|
|
92
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_purge_ids(uuid[])`);
|
|
93
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_seal_hashes(uuid, varchar, varchar)`);
|
|
94
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS audit_ensure_month_partition(date)`);
|
|
95
|
+
await queryRunner.query(`
|
|
96
|
+
DO $convert$
|
|
97
|
+
DECLARE
|
|
98
|
+
relkind "char";
|
|
99
|
+
start_month date;
|
|
100
|
+
end_month date;
|
|
101
|
+
cursor_month date;
|
|
102
|
+
part_name text;
|
|
103
|
+
from_ts timestamptz;
|
|
104
|
+
to_ts timestamptz;
|
|
105
|
+
BEGIN
|
|
106
|
+
SELECT c.relkind INTO relkind
|
|
107
|
+
FROM pg_class c
|
|
108
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
109
|
+
WHERE c.relname = 'audit_events' AND n.nspname = 'public';
|
|
110
|
+
|
|
111
|
+
IF relkind IS NULL THEN
|
|
112
|
+
RAISE EXCEPTION 'audit_events table does not exist; run full-schema first';
|
|
113
|
+
END IF;
|
|
114
|
+
|
|
115
|
+
-- Already partitioned — leave data/layout alone.
|
|
116
|
+
IF relkind = 'p' THEN
|
|
117
|
+
RETURN;
|
|
118
|
+
END IF;
|
|
119
|
+
|
|
120
|
+
ALTER TABLE audit_events RENAME TO audit_events_plain;
|
|
121
|
+
DROP TRIGGER IF EXISTS trg_audit_events_immutable ON audit_events_plain;
|
|
122
|
+
|
|
123
|
+
CREATE TABLE audit_events (
|
|
124
|
+
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
|
|
125
|
+
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
126
|
+
"actor_type" character varying(32) NOT NULL DEFAULT 'USER',
|
|
127
|
+
"actor_id" uuid,
|
|
128
|
+
"action" character varying(128) NOT NULL,
|
|
129
|
+
"resource_type" character varying(64),
|
|
130
|
+
"resource_id" character varying(128),
|
|
131
|
+
"status" character varying(16) NOT NULL DEFAULT 'SUCCESS',
|
|
132
|
+
"metadata" jsonb,
|
|
133
|
+
"ip_address" character varying(64),
|
|
134
|
+
"device_info" character varying(512),
|
|
135
|
+
"request_id" character varying(64),
|
|
136
|
+
"correlation_id" character varying(64),
|
|
137
|
+
"trace_id" character varying(64),
|
|
138
|
+
"chain_seq" bigint NOT NULL,
|
|
139
|
+
"event_hash" character varying(64),
|
|
140
|
+
"prev_hash" character varying(64),
|
|
141
|
+
"legal_hold" boolean NOT NULL DEFAULT false,
|
|
142
|
+
CONSTRAINT "PK_audit_events_id_created_at" PRIMARY KEY ("id", "created_at")
|
|
143
|
+
) PARTITION BY RANGE ("created_at");
|
|
144
|
+
|
|
145
|
+
SELECT date_trunc('month', COALESCE(MIN(created_at), now()))::date
|
|
146
|
+
INTO start_month
|
|
147
|
+
FROM audit_events_plain;
|
|
148
|
+
|
|
149
|
+
end_month := (date_trunc('month', now()) + interval '12 months')::date;
|
|
150
|
+
cursor_month := start_month;
|
|
151
|
+
|
|
152
|
+
WHILE cursor_month <= end_month LOOP
|
|
153
|
+
part_name := 'audit_events_' || to_char(cursor_month, 'YYYY_MM');
|
|
154
|
+
from_ts := cursor_month::timestamptz;
|
|
155
|
+
to_ts := (cursor_month + interval '1 month')::timestamptz;
|
|
156
|
+
EXECUTE format(
|
|
157
|
+
'CREATE TABLE IF NOT EXISTS %I PARTITION OF audit_events FOR VALUES FROM (%L) TO (%L)',
|
|
158
|
+
part_name,
|
|
159
|
+
from_ts,
|
|
160
|
+
to_ts
|
|
161
|
+
);
|
|
162
|
+
cursor_month := (cursor_month + interval '1 month')::date;
|
|
163
|
+
END LOOP;
|
|
164
|
+
|
|
165
|
+
CREATE TABLE IF NOT EXISTS audit_events_default PARTITION OF audit_events DEFAULT;
|
|
166
|
+
|
|
167
|
+
INSERT INTO audit_events (
|
|
168
|
+
id, created_at, actor_type, actor_id, action, resource_type, resource_id,
|
|
169
|
+
status, metadata, ip_address, device_info, request_id, correlation_id, trace_id,
|
|
170
|
+
chain_seq, event_hash, prev_hash, legal_hold
|
|
171
|
+
)
|
|
172
|
+
SELECT
|
|
173
|
+
id, created_at, actor_type, actor_id, action, resource_type, resource_id,
|
|
174
|
+
status, metadata, ip_address, device_info, request_id, correlation_id, trace_id,
|
|
175
|
+
chain_seq, event_hash, prev_hash, legal_hold
|
|
176
|
+
FROM audit_events_plain;
|
|
177
|
+
|
|
178
|
+
-- Detach sequence before DROP so OWNED BY does not cascade-drop it.
|
|
179
|
+
IF EXISTS (
|
|
180
|
+
SELECT 1 FROM pg_class c
|
|
181
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
182
|
+
WHERE c.relname = 'audit_events_chain_seq_seq'
|
|
183
|
+
AND n.nspname = 'public'
|
|
184
|
+
AND c.relkind = 'S'
|
|
185
|
+
) THEN
|
|
186
|
+
ALTER SEQUENCE public.audit_events_chain_seq_seq OWNED BY NONE;
|
|
187
|
+
END IF;
|
|
188
|
+
|
|
189
|
+
DROP TABLE audit_events_plain;
|
|
190
|
+
END
|
|
191
|
+
$convert$
|
|
192
|
+
`);
|
|
193
|
+
// Sequence must always exist after this migration (partitions alone are not enough).
|
|
194
|
+
await queryRunner.query(`
|
|
195
|
+
CREATE SEQUENCE IF NOT EXISTS public.audit_events_chain_seq_seq
|
|
196
|
+
`);
|
|
197
|
+
await queryRunner.query(`
|
|
198
|
+
SELECT setval(
|
|
199
|
+
'public.audit_events_chain_seq_seq',
|
|
200
|
+
GREATEST(COALESCE((SELECT MAX(chain_seq) FROM public.audit_events), 0), 1)
|
|
201
|
+
)
|
|
202
|
+
`);
|
|
203
|
+
await queryRunner.query(`
|
|
204
|
+
ALTER TABLE public.audit_events
|
|
205
|
+
ALTER COLUMN chain_seq SET DEFAULT nextval('public.audit_events_chain_seq_seq')
|
|
206
|
+
`);
|
|
207
|
+
await queryRunner.query(`ALTER SEQUENCE public.audit_events_chain_seq_seq OWNED BY public.audit_events.chain_seq`);
|
|
208
|
+
// Grant while CURRENT_USER still owns the sequence (before optional OWNER TO).
|
|
209
|
+
await queryRunner.query(`
|
|
210
|
+
GRANT USAGE, SELECT ON SEQUENCE public.audit_events_chain_seq_seq TO CURRENT_USER
|
|
211
|
+
`);
|
|
212
|
+
await queryRunner.query(`
|
|
213
|
+
DO $assert_seq$
|
|
214
|
+
BEGIN
|
|
215
|
+
IF NOT EXISTS (
|
|
216
|
+
SELECT 1 FROM pg_class c
|
|
217
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
218
|
+
WHERE c.relname = 'audit_events_chain_seq_seq'
|
|
219
|
+
AND n.nspname = 'public'
|
|
220
|
+
AND c.relkind = 'S'
|
|
221
|
+
) THEN
|
|
222
|
+
RAISE EXCEPTION 'public.audit_events_chain_seq_seq was not created';
|
|
223
|
+
END IF;
|
|
224
|
+
END
|
|
225
|
+
$assert_seq$
|
|
226
|
+
`);
|
|
227
|
+
await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "UQ_audit_events_chain_seq_created"
|
|
228
|
+
ON audit_events ("chain_seq", "created_at")`);
|
|
229
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_actor_type" ON audit_events ("actor_type")`);
|
|
230
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_actor_id" ON audit_events ("actor_id")`);
|
|
231
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_action" ON audit_events ("action")`);
|
|
232
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_resource_id" ON audit_events ("resource_id")`);
|
|
233
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_created_at" ON audit_events ("created_at")`);
|
|
234
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_correlation_id" ON audit_events ("correlation_id")`);
|
|
235
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_legal_hold" ON audit_events ("legal_hold") WHERE legal_hold = true`);
|
|
236
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_created_at_brin" ON audit_events USING BRIN ("created_at")`);
|
|
237
|
+
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_audit_events_chain_seq" ON audit_events ("chain_seq")`);
|
|
238
|
+
await queryRunner.query(`DROP TRIGGER IF EXISTS trg_audit_events_immutable ON audit_events`);
|
|
239
|
+
await queryRunner.query(`
|
|
240
|
+
CREATE TRIGGER trg_audit_events_immutable
|
|
241
|
+
BEFORE UPDATE OR DELETE ON audit_events
|
|
242
|
+
FOR EACH ROW
|
|
243
|
+
EXECUTE PROCEDURE audit_events_immutable_guard()
|
|
244
|
+
`);
|
|
245
|
+
await queryRunner.query(`
|
|
246
|
+
CREATE OR REPLACE FUNCTION audit_set_legal_hold(p_id uuid, p_hold boolean)
|
|
247
|
+
RETURNS SETOF audit_events
|
|
248
|
+
LANGUAGE plpgsql
|
|
249
|
+
SECURITY DEFINER
|
|
250
|
+
SET search_path = public
|
|
251
|
+
AS $$
|
|
252
|
+
BEGIN
|
|
253
|
+
PERFORM set_config('app.audit_mutation', 'legal_hold', true);
|
|
254
|
+
RETURN QUERY
|
|
255
|
+
UPDATE audit_events
|
|
256
|
+
SET legal_hold = p_hold
|
|
257
|
+
WHERE id = p_id
|
|
258
|
+
RETURNING *;
|
|
259
|
+
END;
|
|
260
|
+
$$
|
|
261
|
+
`);
|
|
262
|
+
await queryRunner.query(`
|
|
263
|
+
CREATE OR REPLACE FUNCTION audit_purge_ids(p_ids uuid[])
|
|
264
|
+
RETURNS integer
|
|
265
|
+
LANGUAGE plpgsql
|
|
266
|
+
SECURITY DEFINER
|
|
267
|
+
SET search_path = public
|
|
268
|
+
AS $$
|
|
269
|
+
DECLARE
|
|
270
|
+
deleted integer;
|
|
271
|
+
BEGIN
|
|
272
|
+
PERFORM set_config('app.audit_mutation', 'purge', true);
|
|
273
|
+
DELETE FROM audit_events
|
|
274
|
+
WHERE id = ANY(p_ids)
|
|
275
|
+
AND legal_hold = false;
|
|
276
|
+
GET DIAGNOSTICS deleted = ROW_COUNT;
|
|
277
|
+
RETURN deleted;
|
|
278
|
+
END;
|
|
279
|
+
$$
|
|
280
|
+
`);
|
|
281
|
+
await queryRunner.query(`
|
|
282
|
+
CREATE OR REPLACE FUNCTION audit_seal_hashes(
|
|
283
|
+
p_id uuid,
|
|
284
|
+
p_event_hash varchar,
|
|
285
|
+
p_prev_hash varchar
|
|
286
|
+
)
|
|
287
|
+
RETURNS void
|
|
288
|
+
LANGUAGE plpgsql
|
|
289
|
+
SECURITY DEFINER
|
|
290
|
+
SET search_path = public
|
|
291
|
+
AS $$
|
|
292
|
+
BEGIN
|
|
293
|
+
PERFORM set_config('app.audit_mutation', 'seal', true);
|
|
294
|
+
UPDATE audit_events
|
|
295
|
+
SET event_hash = p_event_hash,
|
|
296
|
+
prev_hash = p_prev_hash
|
|
297
|
+
WHERE id = p_id
|
|
298
|
+
AND event_hash IS NULL;
|
|
299
|
+
END;
|
|
300
|
+
$$
|
|
301
|
+
`);
|
|
302
|
+
await queryRunner.query(`
|
|
303
|
+
CREATE OR REPLACE FUNCTION audit_ensure_month_partition(p_month date)
|
|
304
|
+
RETURNS void
|
|
305
|
+
LANGUAGE plpgsql
|
|
306
|
+
SECURITY DEFINER
|
|
307
|
+
SET search_path = public
|
|
308
|
+
AS $$
|
|
309
|
+
DECLARE
|
|
310
|
+
part_name text;
|
|
311
|
+
from_ts timestamptz;
|
|
312
|
+
to_ts timestamptz;
|
|
313
|
+
month_start date := date_trunc('month', p_month)::date;
|
|
314
|
+
BEGIN
|
|
315
|
+
part_name := 'audit_events_' || to_char(month_start, 'YYYY_MM');
|
|
316
|
+
from_ts := month_start::timestamptz;
|
|
317
|
+
to_ts := (month_start + interval '1 month')::timestamptz;
|
|
318
|
+
EXECUTE format(
|
|
319
|
+
'CREATE TABLE IF NOT EXISTS %I PARTITION OF audit_events FOR VALUES FROM (%L) TO (%L)',
|
|
320
|
+
part_name,
|
|
321
|
+
from_ts,
|
|
322
|
+
to_ts
|
|
323
|
+
);
|
|
324
|
+
END;
|
|
325
|
+
$$
|
|
326
|
+
`);
|
|
327
|
+
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_set_legal_hold(uuid, boolean) FROM PUBLIC`);
|
|
328
|
+
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_purge_ids(uuid[]) FROM PUBLIC`);
|
|
329
|
+
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_seal_hashes(uuid, varchar, varchar) FROM PUBLIC`);
|
|
330
|
+
await queryRunner.query(`REVOKE ALL ON FUNCTION audit_ensure_month_partition(date) FROM PUBLIC`);
|
|
331
|
+
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_set_legal_hold(uuid, boolean) TO CURRENT_USER`);
|
|
332
|
+
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_purge_ids(uuid[]) TO CURRENT_USER`);
|
|
333
|
+
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_seal_hashes(uuid, varchar, varchar) TO CURRENT_USER`);
|
|
334
|
+
await queryRunner.query(`GRANT EXECUTE ON FUNCTION audit_ensure_month_partition(date) TO CURRENT_USER`);
|
|
335
|
+
// Best-effort ownership split. Sequence USAGE was already granted above while
|
|
336
|
+
// CURRENT_USER owned it; if OWNER TO succeeds, re-grant (superuser / grantor).
|
|
337
|
+
// On failure the whole block rolls back — sequence + prior GRANT remain intact.
|
|
338
|
+
await queryRunner.query(`
|
|
339
|
+
DO $body$
|
|
340
|
+
BEGIN
|
|
341
|
+
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'colveor_audit_owner') THEN
|
|
342
|
+
CREATE ROLE colveor_audit_owner NOLOGIN;
|
|
343
|
+
END IF;
|
|
344
|
+
|
|
345
|
+
ALTER TABLE public.audit_events OWNER TO colveor_audit_owner;
|
|
346
|
+
ALTER TABLE public.audit_outbox OWNER TO colveor_audit_owner;
|
|
347
|
+
ALTER FUNCTION public.audit_events_immutable_guard() OWNER TO colveor_audit_owner;
|
|
348
|
+
ALTER FUNCTION public.audit_set_legal_hold(uuid, boolean) OWNER TO colveor_audit_owner;
|
|
349
|
+
ALTER FUNCTION public.audit_purge_ids(uuid[]) OWNER TO colveor_audit_owner;
|
|
350
|
+
ALTER FUNCTION public.audit_seal_hashes(uuid, varchar, varchar) OWNER TO colveor_audit_owner;
|
|
351
|
+
ALTER FUNCTION public.audit_ensure_month_partition(date) OWNER TO colveor_audit_owner;
|
|
352
|
+
ALTER SEQUENCE public.audit_events_chain_seq_seq OWNER TO colveor_audit_owner;
|
|
353
|
+
|
|
354
|
+
REVOKE ALL ON TABLE public.audit_events FROM PUBLIC;
|
|
355
|
+
REVOKE UPDATE, DELETE ON TABLE public.audit_events FROM CURRENT_USER;
|
|
356
|
+
GRANT SELECT, INSERT ON TABLE public.audit_events TO CURRENT_USER;
|
|
357
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.audit_outbox TO CURRENT_USER;
|
|
358
|
+
GRANT USAGE, SELECT ON SEQUENCE public.audit_events_chain_seq_seq TO CURRENT_USER;
|
|
359
|
+
|
|
360
|
+
GRANT USAGE, CREATE ON SCHEMA public TO colveor_audit_owner;
|
|
361
|
+
EXCEPTION
|
|
362
|
+
WHEN insufficient_privilege OR invalid_grantor OR undefined_object THEN
|
|
363
|
+
RAISE NOTICE 'audit ownership/REVOKE skipped: %', SQLERRM;
|
|
364
|
+
END
|
|
365
|
+
$body$
|
|
366
|
+
`);
|
|
367
|
+
}
|
|
368
|
+
async down(queryRunner) {
|
|
369
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS public.audit_ensure_month_partition(date)`);
|
|
370
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS public.audit_seal_hashes(uuid, varchar, varchar)`);
|
|
371
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS public.audit_purge_ids(uuid[])`);
|
|
372
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS public.audit_set_legal_hold(uuid, boolean)`);
|
|
373
|
+
await queryRunner.query(`DROP FUNCTION IF EXISTS public.audit_events_immutable_guard() CASCADE`);
|
|
374
|
+
await queryRunner.query(`
|
|
375
|
+
DO $detach$
|
|
376
|
+
BEGIN
|
|
377
|
+
IF EXISTS (
|
|
378
|
+
SELECT 1 FROM pg_class c
|
|
379
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
380
|
+
WHERE c.relname = 'audit_events_chain_seq_seq'
|
|
381
|
+
AND n.nspname = 'public'
|
|
382
|
+
AND c.relkind = 'S'
|
|
383
|
+
) THEN
|
|
384
|
+
ALTER SEQUENCE public.audit_events_chain_seq_seq OWNED BY NONE;
|
|
385
|
+
END IF;
|
|
386
|
+
END
|
|
387
|
+
$detach$
|
|
388
|
+
`);
|
|
389
|
+
await queryRunner.query(`CREATE TABLE public.audit_events_merged (LIKE public.audit_events INCLUDING DEFAULTS INCLUDING CONSTRAINTS)`);
|
|
390
|
+
await queryRunner.query(`INSERT INTO public.audit_events_merged SELECT * FROM public.audit_events`);
|
|
391
|
+
await queryRunner.query(`DROP TABLE public.audit_events`);
|
|
392
|
+
await queryRunner.query(`ALTER TABLE public.audit_events_merged RENAME TO audit_events`);
|
|
393
|
+
// Restore composite PK shape expected by full-schema / entities.
|
|
394
|
+
await queryRunner.query(`
|
|
395
|
+
ALTER TABLE public.audit_events
|
|
396
|
+
DROP CONSTRAINT IF EXISTS "PK_audit_events_id_created_at"
|
|
397
|
+
`);
|
|
398
|
+
await queryRunner.query(`
|
|
399
|
+
DO $pk$
|
|
400
|
+
BEGIN
|
|
401
|
+
IF NOT EXISTS (
|
|
402
|
+
SELECT 1 FROM pg_constraint
|
|
403
|
+
WHERE conrelid = 'public.audit_events'::regclass AND contype = 'p'
|
|
404
|
+
) THEN
|
|
405
|
+
ALTER TABLE public.audit_events
|
|
406
|
+
ADD CONSTRAINT "PK_7a893600893f8f5086bffa23f2b" PRIMARY KEY ("id", "created_at");
|
|
407
|
+
END IF;
|
|
408
|
+
END
|
|
409
|
+
$pk$
|
|
410
|
+
`);
|
|
411
|
+
await queryRunner.query(`DROP SEQUENCE IF EXISTS public.audit_events_chain_seq_seq`);
|
|
412
|
+
await queryRunner.query(`
|
|
413
|
+
DO $body$
|
|
414
|
+
BEGIN
|
|
415
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'colveor_audit_owner') THEN
|
|
416
|
+
REVOKE CREATE ON SCHEMA public FROM colveor_audit_owner;
|
|
417
|
+
END IF;
|
|
418
|
+
EXCEPTION
|
|
419
|
+
WHEN insufficient_privilege OR undefined_object THEN
|
|
420
|
+
RAISE NOTICE 'audit owner schema revoke skipped: %', SQLERRM;
|
|
421
|
+
END
|
|
422
|
+
$body$
|
|
423
|
+
`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.AuditPartitioning1784284557960 = AuditPartitioning1784284557960;
|
|
427
|
+
//# sourceMappingURL=1784284557960-audit-partitioning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1784284557960-audit-partitioning.js","sourceRoot":"","sources":["../../../src/database/migrations/1784284557960-audit-partitioning.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MigrationInterface, type QueryRunner } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* Ensure `public.audit_events_chain_seq_seq` exists for DBs that already ran
|
|
4
|
+
* audit partitioning but are missing the chain sequence (causes
|
|
5
|
+
* `relation "audit_events_chain_seq_seq" does not exist` on audit seal).
|
|
6
|
+
*
|
|
7
|
+
* Safe / idempotent: no-op when the sequence is already present.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AuditChainSeqEnsure1784284557961 implements MigrationInterface {
|
|
10
|
+
name: string;
|
|
11
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
12
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=1784284557961-audit-chain-seq-ensure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1784284557961-audit-chain-seq-ensure.d.ts","sourceRoot":"","sources":["../../../src/database/migrations/1784284557961-audit-chain-seq-ensure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpE;;;;;;GAMG;AACH,qBAAa,gCAAiC,YAAW,kBAAkB;IAC1E,IAAI,SAAsC;IAE7B,EAAE,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuD3C,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAkB1D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuditChainSeqEnsure1784284557961 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Ensure `public.audit_events_chain_seq_seq` exists for DBs that already ran
|
|
6
|
+
* audit partitioning but are missing the chain sequence (causes
|
|
7
|
+
* `relation "audit_events_chain_seq_seq" does not exist` on audit seal).
|
|
8
|
+
*
|
|
9
|
+
* Safe / idempotent: no-op when the sequence is already present.
|
|
10
|
+
*/
|
|
11
|
+
class AuditChainSeqEnsure1784284557961 {
|
|
12
|
+
name = 'AuditChainSeqEnsure1784284557961';
|
|
13
|
+
async up(queryRunner) {
|
|
14
|
+
await queryRunner.query(`
|
|
15
|
+
DO $body$
|
|
16
|
+
BEGIN
|
|
17
|
+
IF NOT EXISTS (
|
|
18
|
+
SELECT 1 FROM pg_class c
|
|
19
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
20
|
+
WHERE c.relname = 'audit_events'
|
|
21
|
+
AND n.nspname = 'public'
|
|
22
|
+
) THEN
|
|
23
|
+
RAISE EXCEPTION 'public.audit_events does not exist; run full-schema + audit-partitioning first';
|
|
24
|
+
END IF;
|
|
25
|
+
|
|
26
|
+
IF NOT EXISTS (
|
|
27
|
+
SELECT 1 FROM pg_class c
|
|
28
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
29
|
+
WHERE c.relname = 'audit_events_chain_seq_seq'
|
|
30
|
+
AND n.nspname = 'public'
|
|
31
|
+
AND c.relkind = 'S'
|
|
32
|
+
) THEN
|
|
33
|
+
CREATE SEQUENCE public.audit_events_chain_seq_seq;
|
|
34
|
+
END IF;
|
|
35
|
+
|
|
36
|
+
PERFORM setval(
|
|
37
|
+
'public.audit_events_chain_seq_seq',
|
|
38
|
+
GREATEST(COALESCE((SELECT MAX(chain_seq) FROM public.audit_events), 0), 1)
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
ALTER TABLE public.audit_events
|
|
42
|
+
ALTER COLUMN chain_seq SET DEFAULT nextval('public.audit_events_chain_seq_seq');
|
|
43
|
+
|
|
44
|
+
ALTER SEQUENCE public.audit_events_chain_seq_seq
|
|
45
|
+
OWNED BY public.audit_events.chain_seq;
|
|
46
|
+
|
|
47
|
+
GRANT USAGE, SELECT ON SEQUENCE public.audit_events_chain_seq_seq TO CURRENT_USER;
|
|
48
|
+
END
|
|
49
|
+
$body$
|
|
50
|
+
`);
|
|
51
|
+
// Best-effort: align owner with audit partitioning when privileges allow.
|
|
52
|
+
await queryRunner.query(`
|
|
53
|
+
DO $owner$
|
|
54
|
+
BEGIN
|
|
55
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'colveor_audit_owner') THEN
|
|
56
|
+
ALTER SEQUENCE public.audit_events_chain_seq_seq OWNER TO colveor_audit_owner;
|
|
57
|
+
GRANT USAGE, SELECT ON SEQUENCE public.audit_events_chain_seq_seq TO CURRENT_USER;
|
|
58
|
+
END IF;
|
|
59
|
+
EXCEPTION
|
|
60
|
+
WHEN insufficient_privilege OR invalid_grantor OR undefined_object THEN
|
|
61
|
+
RAISE NOTICE 'audit chain seq ownership skipped: %', SQLERRM;
|
|
62
|
+
END
|
|
63
|
+
$owner$
|
|
64
|
+
`);
|
|
65
|
+
}
|
|
66
|
+
async down(queryRunner) {
|
|
67
|
+
// Keep the sequence — dropping it would break audit writes. Only detach OWNED BY.
|
|
68
|
+
await queryRunner.query(`
|
|
69
|
+
DO $detach$
|
|
70
|
+
BEGIN
|
|
71
|
+
IF EXISTS (
|
|
72
|
+
SELECT 1 FROM pg_class c
|
|
73
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
74
|
+
WHERE c.relname = 'audit_events_chain_seq_seq'
|
|
75
|
+
AND n.nspname = 'public'
|
|
76
|
+
AND c.relkind = 'S'
|
|
77
|
+
) THEN
|
|
78
|
+
ALTER SEQUENCE public.audit_events_chain_seq_seq OWNED BY NONE;
|
|
79
|
+
END IF;
|
|
80
|
+
END
|
|
81
|
+
$detach$
|
|
82
|
+
`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.AuditChainSeqEnsure1784284557961 = AuditChainSeqEnsure1784284557961;
|
|
86
|
+
//# sourceMappingURL=1784284557961-audit-chain-seq-ensure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1784284557961-audit-chain-seq-ensure.js","sourceRoot":"","sources":["../../../src/database/migrations/1784284557961-audit-chain-seq-ensure.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACH,MAAa,gCAAgC;IAC5C,IAAI,GAAG,kCAAkC,CAAC;IAEnC,KAAK,CAAC,EAAE,CAAC,WAAwB;QACvC,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCvB,CAAC,CAAC;QAEH,0EAA0E;QAC1E,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;GAYvB,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAwB;QACzC,kFAAkF;QAClF,MAAM,WAAW,CAAC,KAAK,CAAC;;;;;;;;;;;;;;GAcvB,CAAC,CAAC;IACJ,CAAC;CACD;AA5ED,4EA4EC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.seed.d.ts","sourceRoot":"","sources":["../../../src/database/seeds/settings.seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"settings.seed.d.ts","sourceRoot":"","sources":["../../../src/database/seeds/settings.seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,SAAS,CAAC;AAK3D,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAGhF,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW,GAAG,aAAa,CAAC,CAAC;AAErF,qBAAa,YAAY;IAIZ,OAAO,CAAC,UAAU;IAH9B,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;gBAE3C,UAAU,EAAE,UAAU;IAI1C;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAKtC;IAEG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IA6B1B,OAAO,CAAC,aAAa;IAmhCrB,OAAO,CAAC,aAAa;IAyBrB,OAAO,CAAC,0BAA0B;CA6ClC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SettingsSeed = void 0;
|
|
4
|
+
const upload_categories_1 = require("../../modules/file-upload/constants/upload-categories");
|
|
4
5
|
const settings_defaults_1 = require("../../modules/settings/constants/settings.defaults");
|
|
5
6
|
const settings_keys_1 = require("../../modules/settings/constants/settings.keys");
|
|
6
7
|
const app_setting_entity_1 = require("../../modules/settings/entities/app-setting.entity");
|
|
@@ -882,8 +883,7 @@ class SettingsSeed {
|
|
|
882
883
|
},
|
|
883
884
|
{
|
|
884
885
|
key: settings_keys_1.SETTING_KEYS.STORAGE_UPLOAD_CATEGORIES,
|
|
885
|
-
value: JSON.stringify(
|
|
886
|
-
settings_defaults_1.SETTING_DEFAULTS['storage.upload_categories']),
|
|
886
|
+
value: JSON.stringify((0, upload_categories_1.getDefaultUploadCategories)()),
|
|
887
887
|
type: 'arrayOfObject',
|
|
888
888
|
schema: {
|
|
889
889
|
slug: 'string',
|
|
@@ -897,7 +897,8 @@ class SettingsSeed {
|
|
|
897
897
|
},
|
|
898
898
|
group: 'storage',
|
|
899
899
|
description: 'Upload category definitions. Each entry controls allowed extensions, max size, ' +
|
|
900
|
-
'public visibility, and optional per-user file quota. Schema: UploadCategory[].'
|
|
900
|
+
'public visibility, and optional per-user file quota. Schema: UploadCategory[]. ' +
|
|
901
|
+
'Host apps can append via registerUploadCategories() before seed.',
|
|
901
902
|
isEditable: true,
|
|
902
903
|
},
|
|
903
904
|
// ─── File upload rate limiting ─────────────────────────────────────
|