@intelligo-dev/audit 1.0.0-beta.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/LICENSE +201 -0
- package/dist/db/schema.d.ts +195 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +43 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/memory-audit.d.ts +56 -0
- package/dist/memory-audit.d.ts.map +1 -0
- package/dist/memory-audit.js +36 -0
- package/dist/memory-audit.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Intelligo
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @intelligo-dev/audit database schema.
|
|
3
|
+
*
|
|
4
|
+
* One append-only table recording who did what to which resource.
|
|
5
|
+
* Owned by this package per ADR-0004; scanned by drizzle-kit alongside
|
|
6
|
+
* the core schema directory (see packages/core/drizzle.config.ts) so
|
|
7
|
+
* the migration history stays unified in one database.
|
|
8
|
+
*
|
|
9
|
+
* Distinct from `user_memory_audit` in core/identity, which records
|
|
10
|
+
* mutations to a user's memory graph and predates this table. That one
|
|
11
|
+
* folds in here once the memory subsystem's ownership is settled
|
|
12
|
+
* (see docs/inventory/export-classification.md).
|
|
13
|
+
*/
|
|
14
|
+
export declare const auditEvents: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
15
|
+
name: "audit_events";
|
|
16
|
+
schema: undefined;
|
|
17
|
+
columns: {
|
|
18
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
19
|
+
name: "id";
|
|
20
|
+
tableName: "audit_events";
|
|
21
|
+
dataType: "string";
|
|
22
|
+
columnType: "PgText";
|
|
23
|
+
data: string;
|
|
24
|
+
driverParam: string;
|
|
25
|
+
notNull: true;
|
|
26
|
+
hasDefault: false;
|
|
27
|
+
isPrimaryKey: true;
|
|
28
|
+
isAutoincrement: false;
|
|
29
|
+
hasRuntimeDefault: false;
|
|
30
|
+
enumValues: [string, ...string[]];
|
|
31
|
+
baseColumn: never;
|
|
32
|
+
identity: undefined;
|
|
33
|
+
generated: undefined;
|
|
34
|
+
}, {}, {}>;
|
|
35
|
+
workspaceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
36
|
+
name: "workspace_id";
|
|
37
|
+
tableName: "audit_events";
|
|
38
|
+
dataType: "string";
|
|
39
|
+
columnType: "PgText";
|
|
40
|
+
data: string;
|
|
41
|
+
driverParam: string;
|
|
42
|
+
notNull: false;
|
|
43
|
+
hasDefault: false;
|
|
44
|
+
isPrimaryKey: false;
|
|
45
|
+
isAutoincrement: false;
|
|
46
|
+
hasRuntimeDefault: false;
|
|
47
|
+
enumValues: [string, ...string[]];
|
|
48
|
+
baseColumn: never;
|
|
49
|
+
identity: undefined;
|
|
50
|
+
generated: undefined;
|
|
51
|
+
}, {}, {}>;
|
|
52
|
+
actorId: import("drizzle-orm/pg-core").PgColumn<{
|
|
53
|
+
name: "actor_id";
|
|
54
|
+
tableName: "audit_events";
|
|
55
|
+
dataType: "string";
|
|
56
|
+
columnType: "PgText";
|
|
57
|
+
data: string;
|
|
58
|
+
driverParam: string;
|
|
59
|
+
notNull: false;
|
|
60
|
+
hasDefault: false;
|
|
61
|
+
isPrimaryKey: false;
|
|
62
|
+
isAutoincrement: false;
|
|
63
|
+
hasRuntimeDefault: false;
|
|
64
|
+
enumValues: [string, ...string[]];
|
|
65
|
+
baseColumn: never;
|
|
66
|
+
identity: undefined;
|
|
67
|
+
generated: undefined;
|
|
68
|
+
}, {}, {}>;
|
|
69
|
+
actorKind: import("drizzle-orm/pg-core").PgColumn<{
|
|
70
|
+
name: "actor_kind";
|
|
71
|
+
tableName: "audit_events";
|
|
72
|
+
dataType: "string";
|
|
73
|
+
columnType: "PgText";
|
|
74
|
+
data: string;
|
|
75
|
+
driverParam: string;
|
|
76
|
+
notNull: true;
|
|
77
|
+
hasDefault: true;
|
|
78
|
+
isPrimaryKey: false;
|
|
79
|
+
isAutoincrement: false;
|
|
80
|
+
hasRuntimeDefault: false;
|
|
81
|
+
enumValues: [string, ...string[]];
|
|
82
|
+
baseColumn: never;
|
|
83
|
+
identity: undefined;
|
|
84
|
+
generated: undefined;
|
|
85
|
+
}, {}, {}>;
|
|
86
|
+
action: import("drizzle-orm/pg-core").PgColumn<{
|
|
87
|
+
name: "action";
|
|
88
|
+
tableName: "audit_events";
|
|
89
|
+
dataType: "string";
|
|
90
|
+
columnType: "PgText";
|
|
91
|
+
data: string;
|
|
92
|
+
driverParam: string;
|
|
93
|
+
notNull: true;
|
|
94
|
+
hasDefault: false;
|
|
95
|
+
isPrimaryKey: false;
|
|
96
|
+
isAutoincrement: false;
|
|
97
|
+
hasRuntimeDefault: false;
|
|
98
|
+
enumValues: [string, ...string[]];
|
|
99
|
+
baseColumn: never;
|
|
100
|
+
identity: undefined;
|
|
101
|
+
generated: undefined;
|
|
102
|
+
}, {}, {}>;
|
|
103
|
+
resourceKind: import("drizzle-orm/pg-core").PgColumn<{
|
|
104
|
+
name: "resource_kind";
|
|
105
|
+
tableName: "audit_events";
|
|
106
|
+
dataType: "string";
|
|
107
|
+
columnType: "PgText";
|
|
108
|
+
data: string;
|
|
109
|
+
driverParam: string;
|
|
110
|
+
notNull: true;
|
|
111
|
+
hasDefault: false;
|
|
112
|
+
isPrimaryKey: false;
|
|
113
|
+
isAutoincrement: false;
|
|
114
|
+
hasRuntimeDefault: false;
|
|
115
|
+
enumValues: [string, ...string[]];
|
|
116
|
+
baseColumn: never;
|
|
117
|
+
identity: undefined;
|
|
118
|
+
generated: undefined;
|
|
119
|
+
}, {}, {}>;
|
|
120
|
+
resourceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
121
|
+
name: "resource_id";
|
|
122
|
+
tableName: "audit_events";
|
|
123
|
+
dataType: "string";
|
|
124
|
+
columnType: "PgText";
|
|
125
|
+
data: string;
|
|
126
|
+
driverParam: string;
|
|
127
|
+
notNull: false;
|
|
128
|
+
hasDefault: false;
|
|
129
|
+
isPrimaryKey: false;
|
|
130
|
+
isAutoincrement: false;
|
|
131
|
+
hasRuntimeDefault: false;
|
|
132
|
+
enumValues: [string, ...string[]];
|
|
133
|
+
baseColumn: never;
|
|
134
|
+
identity: undefined;
|
|
135
|
+
generated: undefined;
|
|
136
|
+
}, {}, {}>;
|
|
137
|
+
outcome: import("drizzle-orm/pg-core").PgColumn<{
|
|
138
|
+
name: "outcome";
|
|
139
|
+
tableName: "audit_events";
|
|
140
|
+
dataType: "string";
|
|
141
|
+
columnType: "PgText";
|
|
142
|
+
data: string;
|
|
143
|
+
driverParam: string;
|
|
144
|
+
notNull: true;
|
|
145
|
+
hasDefault: true;
|
|
146
|
+
isPrimaryKey: false;
|
|
147
|
+
isAutoincrement: false;
|
|
148
|
+
hasRuntimeDefault: false;
|
|
149
|
+
enumValues: [string, ...string[]];
|
|
150
|
+
baseColumn: never;
|
|
151
|
+
identity: undefined;
|
|
152
|
+
generated: undefined;
|
|
153
|
+
}, {}, {}>;
|
|
154
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
155
|
+
name: "metadata";
|
|
156
|
+
tableName: "audit_events";
|
|
157
|
+
dataType: "json";
|
|
158
|
+
columnType: "PgJsonb";
|
|
159
|
+
data: Record<string, unknown>;
|
|
160
|
+
driverParam: unknown;
|
|
161
|
+
notNull: false;
|
|
162
|
+
hasDefault: false;
|
|
163
|
+
isPrimaryKey: false;
|
|
164
|
+
isAutoincrement: false;
|
|
165
|
+
hasRuntimeDefault: false;
|
|
166
|
+
enumValues: undefined;
|
|
167
|
+
baseColumn: never;
|
|
168
|
+
identity: undefined;
|
|
169
|
+
generated: undefined;
|
|
170
|
+
}, {}, {
|
|
171
|
+
$type: Record<string, unknown>;
|
|
172
|
+
}>;
|
|
173
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
174
|
+
name: "created_at";
|
|
175
|
+
tableName: "audit_events";
|
|
176
|
+
dataType: "date";
|
|
177
|
+
columnType: "PgTimestamp";
|
|
178
|
+
data: Date;
|
|
179
|
+
driverParam: string;
|
|
180
|
+
notNull: true;
|
|
181
|
+
hasDefault: true;
|
|
182
|
+
isPrimaryKey: false;
|
|
183
|
+
isAutoincrement: false;
|
|
184
|
+
hasRuntimeDefault: false;
|
|
185
|
+
enumValues: undefined;
|
|
186
|
+
baseColumn: never;
|
|
187
|
+
identity: undefined;
|
|
188
|
+
generated: undefined;
|
|
189
|
+
}, {}, {}>;
|
|
190
|
+
};
|
|
191
|
+
dialect: "pg";
|
|
192
|
+
}>;
|
|
193
|
+
export type AuditEvent = typeof auditEvents.$inferSelect;
|
|
194
|
+
export type InsertAuditEvent = typeof auditEvents.$inferInsert;
|
|
195
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCvB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,WAAW,CAAC,YAAY,CAAC;AACzD,MAAM,MAAM,gBAAgB,GAAG,OAAO,WAAW,CAAC,YAAY,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @intelligo-dev/audit database schema.
|
|
3
|
+
*
|
|
4
|
+
* One append-only table recording who did what to which resource.
|
|
5
|
+
* Owned by this package per ADR-0004; scanned by drizzle-kit alongside
|
|
6
|
+
* the core schema directory (see packages/core/drizzle.config.ts) so
|
|
7
|
+
* the migration history stays unified in one database.
|
|
8
|
+
*
|
|
9
|
+
* Distinct from `user_memory_audit` in core/identity, which records
|
|
10
|
+
* mutations to a user's memory graph and predates this table. That one
|
|
11
|
+
* folds in here once the memory subsystem's ownership is settled
|
|
12
|
+
* (see docs/inventory/export-classification.md).
|
|
13
|
+
*/
|
|
14
|
+
import { pgTable, text, timestamp, jsonb, index } from "drizzle-orm/pg-core";
|
|
15
|
+
import { organization, users } from "@intelligo-dev/core/db/schema";
|
|
16
|
+
export const auditEvents = pgTable("audit_events", {
|
|
17
|
+
id: text("id").primaryKey(),
|
|
18
|
+
/** Null for platform-level events with no tenant. */
|
|
19
|
+
workspaceId: text("workspace_id").references(() => organization.id, {
|
|
20
|
+
onDelete: "cascade",
|
|
21
|
+
}),
|
|
22
|
+
/** Null for system actors (cron, webhook, job runner). */
|
|
23
|
+
actorId: text("actor_id").references(() => users.id, {
|
|
24
|
+
onDelete: "set null",
|
|
25
|
+
}),
|
|
26
|
+
/** "user" | "system" | "support" — who initiated the action. */
|
|
27
|
+
actorKind: text("actor_kind").notNull().default("user"),
|
|
28
|
+
/** Dotted verb: "execution.completed", "credits.reserved", … */
|
|
29
|
+
action: text("action").notNull(),
|
|
30
|
+
/** Resource type the action applied to: "execution", "workspace", … */
|
|
31
|
+
resourceKind: text("resource_kind").notNull(),
|
|
32
|
+
/** Identifier of that resource; free-form (uuid, slug, email). */
|
|
33
|
+
resourceId: text("resource_id"),
|
|
34
|
+
/** "ok" | "failed" — outcome of the audited action. */
|
|
35
|
+
outcome: text("outcome").notNull().default("ok"),
|
|
36
|
+
metadata: jsonb("metadata").$type(),
|
|
37
|
+
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
38
|
+
}, (table) => [
|
|
39
|
+
index("audit_events_workspace_created_idx").on(table.workspaceId, table.createdAt),
|
|
40
|
+
index("audit_events_action_idx").on(table.action, table.createdAt),
|
|
41
|
+
index("audit_events_resource_idx").on(table.resourceKind, table.resourceId),
|
|
42
|
+
]);
|
|
43
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAEpE,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAChC,cAAc,EACd;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,qDAAqD;IACrD,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE;QAClE,QAAQ,EAAE,SAAS;KACpB,CAAC;IACF,0DAA0D;IAC1D,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,UAAU;KACrB,CAAC;IACF,gEAAgE;IAChE,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;IACvD,gEAAgE;IAChE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;IAChC,uEAAuE;IACvE,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE;IAC7C,kEAAkE;IAClE,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;IAC/B,uDAAuD;IACvD,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAChD,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAA2B;IAC5D,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CAC1D,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,KAAK,CAAC,oCAAoC,CAAC,CAAC,EAAE,CAC5C,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,SAAS,CAChB;IACD,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC;IAClE,KAAK,CAAC,2BAA2B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC;CAC5E,CACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @intelligo-dev/audit — append-only record of who did what.
|
|
3
|
+
*
|
|
4
|
+
* Emitting is deliberately failure-tolerant: an audit write must never
|
|
5
|
+
* break the operation being audited. `recordAuditEvent` swallows and
|
|
6
|
+
* logs; callers that need the guarantee (impersonation, destructive
|
|
7
|
+
* support actions — Phase 5) use `recordAuditEventOrThrow`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Called after an event is durably recorded.
|
|
11
|
+
*
|
|
12
|
+
* This is an extension point, not a plugin system: sinks are
|
|
13
|
+
* registered by the composition root, never by being imported
|
|
14
|
+
* (ADR-0005). What it exists for is the governance work that does not
|
|
15
|
+
* belong in a permissively-licensed package — tamper-evidence,
|
|
16
|
+
* retention policy, shipping the trail to a customer's SIEM — so that
|
|
17
|
+
* a closed module can add it without this package knowing it exists,
|
|
18
|
+
* and without anyone forking this file.
|
|
19
|
+
*
|
|
20
|
+
* A sink runs after the write, so it cannot corrupt or delay the audit
|
|
21
|
+
* row itself, and its failures are isolated: an exporter with an
|
|
22
|
+
* expired credential must not break the operation being audited, nor
|
|
23
|
+
* the other sinks.
|
|
24
|
+
*/
|
|
25
|
+
export type AuditSink = (event: RecordedAuditEvent) => Promise<void> | void;
|
|
26
|
+
/**
|
|
27
|
+
* The row as written, which is what a sink needs to act on.
|
|
28
|
+
*
|
|
29
|
+
* Spelled out rather than inferred from `toRow`: inference gives `id`
|
|
30
|
+
* the template-literal type of `crypto.randomUUID()`, which is not
|
|
31
|
+
* what comes back out of the database, so every consumer would have to
|
|
32
|
+
* widen it.
|
|
33
|
+
*/
|
|
34
|
+
export type RecordedAuditEvent = {
|
|
35
|
+
id: string;
|
|
36
|
+
workspaceId: string | null;
|
|
37
|
+
actorId: string | null;
|
|
38
|
+
actorKind: string;
|
|
39
|
+
action: string;
|
|
40
|
+
resourceKind: string;
|
|
41
|
+
resourceId: string | null;
|
|
42
|
+
outcome: string;
|
|
43
|
+
metadata: Record<string, unknown> | null;
|
|
44
|
+
createdAt: Date;
|
|
45
|
+
};
|
|
46
|
+
/** Register (or replace) a sink under a stable name. */
|
|
47
|
+
export declare function registerAuditSink(name: string, sink: AuditSink): void;
|
|
48
|
+
export declare function registeredAuditSinks(): string[];
|
|
49
|
+
export declare function clearAuditSinks(): void;
|
|
50
|
+
export type AuditActorKind = "user" | "system" | "support";
|
|
51
|
+
export type AuditOutcome = "ok" | "failed";
|
|
52
|
+
export type AuditEventInput = {
|
|
53
|
+
/** Omit for platform-level events with no tenant. */
|
|
54
|
+
workspaceId?: string | null;
|
|
55
|
+
/** Omit for system actors (cron, webhook, job runner). */
|
|
56
|
+
actorId?: string | null;
|
|
57
|
+
actorKind?: AuditActorKind;
|
|
58
|
+
/** Dotted verb, e.g. "execution.completed". */
|
|
59
|
+
action: string;
|
|
60
|
+
/** Resource type, e.g. "execution". */
|
|
61
|
+
resourceKind: string;
|
|
62
|
+
resourceId?: string | null;
|
|
63
|
+
outcome?: AuditOutcome;
|
|
64
|
+
metadata?: Record<string, unknown>;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Record an audit event. Never throws — a failed audit write is logged
|
|
68
|
+
* and swallowed so it cannot take down the audited operation.
|
|
69
|
+
*/
|
|
70
|
+
export declare function recordAuditEvent(event: AuditEventInput): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Record an audit event, propagating failures. Use where the audit
|
|
73
|
+
* trail is part of the contract (impersonation, destructive support
|
|
74
|
+
* actions) and the operation must abort if it cannot be recorded.
|
|
75
|
+
*/
|
|
76
|
+
export declare function recordAuditEventOrThrow(event: AuditEventInput): Promise<void>;
|
|
77
|
+
export type QueryAuditEventsOptions = {
|
|
78
|
+
workspaceId?: string;
|
|
79
|
+
action?: string;
|
|
80
|
+
resourceKind?: string;
|
|
81
|
+
resourceId?: string;
|
|
82
|
+
/** Keyset pagination: return events created strictly before this. */
|
|
83
|
+
before?: Date;
|
|
84
|
+
limit?: number;
|
|
85
|
+
};
|
|
86
|
+
/** Most-recent-first query for the admin console (Phase 5). */
|
|
87
|
+
export declare function queryAuditEvents(options?: QueryAuditEventsOptions): Promise<{
|
|
88
|
+
id: string;
|
|
89
|
+
workspaceId: string | null;
|
|
90
|
+
actorId: string | null;
|
|
91
|
+
actorKind: string;
|
|
92
|
+
action: string;
|
|
93
|
+
resourceKind: string;
|
|
94
|
+
resourceId: string | null;
|
|
95
|
+
outcome: string;
|
|
96
|
+
metadata: Record<string, unknown> | null;
|
|
97
|
+
createdAt: Date;
|
|
98
|
+
}[]>;
|
|
99
|
+
export { auditEvents } from "./db/schema";
|
|
100
|
+
export type { AuditEvent, InsertAuditEvent } from "./db/schema";
|
|
101
|
+
export type { AuditTargetKind as MemoryAuditTargetKind, AuditAction as MemoryAuditAction, AuditActorKind as MemoryAuditActorKind, UserMemoryAuditRow, InsertUserMemoryAudit, RecordMemoryAuditInput, } from "./memory-audit";
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE5E;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAIF,wDAAwD;AACxD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,CAErE;AAED,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C;AAED,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAoBD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,QAAQ,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG;IAC5B,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI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|
|
|
1
|
+
/**
|
|
2
|
+
* @intelligo-dev/audit — append-only record of who did what.
|
|
3
|
+
*
|
|
4
|
+
* Emitting is deliberately failure-tolerant: an audit write must never
|
|
5
|
+
* break the operation being audited. `recordAuditEvent` swallows and
|
|
6
|
+
* logs; callers that need the guarantee (impersonation, destructive
|
|
7
|
+
* support actions — Phase 5) use `recordAuditEventOrThrow`.
|
|
8
|
+
*/
|
|
9
|
+
import { db } from "@intelligo-dev/core/db";
|
|
10
|
+
import { createLogger } from "@intelligo-dev/core/logger";
|
|
11
|
+
import { and, desc, eq, lt } from "drizzle-orm";
|
|
12
|
+
import { auditEvents } from "./db/schema";
|
|
13
|
+
const log = createLogger("Audit");
|
|
14
|
+
const sinks = new Map();
|
|
15
|
+
/** Register (or replace) a sink under a stable name. */
|
|
16
|
+
export function registerAuditSink(name, sink) {
|
|
17
|
+
sinks.set(name, sink);
|
|
18
|
+
}
|
|
19
|
+
export function registeredAuditSinks() {
|
|
20
|
+
return [...sinks.keys()];
|
|
21
|
+
}
|
|
22
|
+
export function clearAuditSinks() {
|
|
23
|
+
sinks.clear();
|
|
24
|
+
}
|
|
25
|
+
async function fanOut(event) {
|
|
26
|
+
if (sinks.size === 0)
|
|
27
|
+
return;
|
|
28
|
+
await Promise.all([...sinks.entries()].map(async ([name, sink]) => {
|
|
29
|
+
try {
|
|
30
|
+
await sink(event);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
log.error("Audit sink failed", {
|
|
34
|
+
sink: name,
|
|
35
|
+
action: event.action,
|
|
36
|
+
error: error instanceof Error ? error.message : String(error),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
function toRow(event) {
|
|
42
|
+
return {
|
|
43
|
+
id: crypto.randomUUID(),
|
|
44
|
+
workspaceId: event.workspaceId ?? null,
|
|
45
|
+
actorId: event.actorId ?? null,
|
|
46
|
+
actorKind: event.actorKind ?? (event.actorId ? "user" : "system"),
|
|
47
|
+
action: event.action,
|
|
48
|
+
resourceKind: event.resourceKind,
|
|
49
|
+
resourceId: event.resourceId ?? null,
|
|
50
|
+
outcome: event.outcome ?? "ok",
|
|
51
|
+
metadata: event.metadata ?? null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Record an audit event. Never throws — a failed audit write is logged
|
|
56
|
+
* and swallowed so it cannot take down the audited operation.
|
|
57
|
+
*/
|
|
58
|
+
export async function recordAuditEvent(event) {
|
|
59
|
+
try {
|
|
60
|
+
const row = toRow(event);
|
|
61
|
+
await db.insert(auditEvents).values(row);
|
|
62
|
+
await fanOut({ ...row, createdAt: new Date() });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
log.error("Audit write failed", {
|
|
66
|
+
action: event.action,
|
|
67
|
+
resourceKind: event.resourceKind,
|
|
68
|
+
error: error instanceof Error ? error.message : String(error),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Record an audit event, propagating failures. Use where the audit
|
|
74
|
+
* trail is part of the contract (impersonation, destructive support
|
|
75
|
+
* actions) and the operation must abort if it cannot be recorded.
|
|
76
|
+
*/
|
|
77
|
+
export async function recordAuditEventOrThrow(event) {
|
|
78
|
+
const row = toRow(event);
|
|
79
|
+
await db.insert(auditEvents).values(row);
|
|
80
|
+
// Sinks stay failure-isolated even here. The contract this function
|
|
81
|
+
// adds is that the *event was recorded*; a downstream exporter being
|
|
82
|
+
// unreachable does not make it unrecorded, and failing the caller
|
|
83
|
+
// over it would mean an expired SIEM token could block impersonation
|
|
84
|
+
// and every destructive support action.
|
|
85
|
+
await fanOut({ ...row, createdAt: new Date() });
|
|
86
|
+
}
|
|
87
|
+
/** Most-recent-first query for the admin console (Phase 5). */
|
|
88
|
+
export async function queryAuditEvents(options = {}) {
|
|
89
|
+
const filters = [
|
|
90
|
+
options.workspaceId
|
|
91
|
+
? eq(auditEvents.workspaceId, options.workspaceId)
|
|
92
|
+
: undefined,
|
|
93
|
+
options.action ? eq(auditEvents.action, options.action) : undefined,
|
|
94
|
+
options.resourceKind
|
|
95
|
+
? eq(auditEvents.resourceKind, options.resourceKind)
|
|
96
|
+
: undefined,
|
|
97
|
+
options.resourceId
|
|
98
|
+
? eq(auditEvents.resourceId, options.resourceId)
|
|
99
|
+
: undefined,
|
|
100
|
+
options.before ? lt(auditEvents.createdAt, options.before) : undefined,
|
|
101
|
+
].filter(Boolean);
|
|
102
|
+
return db
|
|
103
|
+
.select()
|
|
104
|
+
.from(auditEvents)
|
|
105
|
+
.where(filters.length > 0 ? and(...filters) : undefined)
|
|
106
|
+
.orderBy(desc(auditEvents.createdAt))
|
|
107
|
+
.limit(Math.min(options.limit ?? 50, 500));
|
|
108
|
+
}
|
|
109
|
+
export { auditEvents } from "./db/schema";
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;AA6ClC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;AAE3C,wDAAwD;AACxD,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,IAAe;IAC7D,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,C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W,EAAE,OAAO,CAAC,WAAW,CAAC;YAClD,CAAC,CAAC,SAAS;QACb,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;QACnE,OAAO,CAAC,YAAY;YAClB,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;YACpD,CAAC,CAAC,SAAS;QACb,OAAO,CAAC,UAAU;YAChB,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC;YAChD,CAAC,CAAC,SAAS;QACb,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;KACvE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,OAAO,EAAE;SACN,MAAM,EAAE;SACR,IAAI,CAAC,WAAW,CAAC;SACjB,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;SACvD,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;SACpC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory-audit event contract (ADR-0008).
|
|
3
|
+
*
|
|
4
|
+
* ADR-0008 names `@intelligo-dev/audit` as `recordMemoryAudit`'s
|
|
5
|
+
* destination ("`recordMemoryAudit` to `audit`"). The dependency
|
|
6
|
+
* allowlist doesn't cooperate with a literal move, though
|
|
7
|
+
* (tests/architecture/dependency-direction.test.ts): this package may
|
|
8
|
+
* depend on `@intelligo-dev/core` (`audit: ["@intelligo-dev/core"]`), but
|
|
9
|
+
* `@intelligo-dev/core` may depend on nothing (`core: []`) — the same
|
|
10
|
+
* constraint `packages/core/src/documents/service.ts` and
|
|
11
|
+
* `.../conversations/service.ts` already document for
|
|
12
|
+
* `@intelligo-dev/auth`. `user_facts`/`user_memories`/
|
|
13
|
+
* `user_profile_snapshots`/`user_memory_audit` are owned by
|
|
14
|
+
* `packages/core/src/identity` (see that module's doc comment), and
|
|
15
|
+
* that module cannot import this package to call a writer defined
|
|
16
|
+
* here — the allowlist only grants the audit -> core edge, never
|
|
17
|
+
* core -> audit.
|
|
18
|
+
*
|
|
19
|
+
* What actually lands here, then, is the event *contract*: the shape a
|
|
20
|
+
* memory-audit write takes, re-exported from the schema module that
|
|
21
|
+
* already owns it. The write itself is a faithful, in-package port at
|
|
22
|
+
* `packages/core/src/identity/audit.ts`, used internally by the
|
|
23
|
+
* identity service (`deleteFact`, `exportIdentity`) so it never
|
|
24
|
+
* crosses the disallowed core -> audit edge. This module is the public
|
|
25
|
+
* seam for anyone else who depends on `@intelligo-dev/audit` (executions,
|
|
26
|
+
* admin, billing) and wants to describe a memory-audit event without
|
|
27
|
+
* reaching into `@intelligo-dev/core/identity`'s internals.
|
|
28
|
+
*
|
|
29
|
+
* `packages/audit/src/db/schema.ts` already documents where this
|
|
30
|
+
* settles: `user_memory_audit` folds into `audit_events` once the
|
|
31
|
+
* memory subsystem's ownership question closes (see
|
|
32
|
+
* docs/inventory/export-classification.md), and this contract
|
|
33
|
+
* graduates to backing that table's writer directly.
|
|
34
|
+
*/
|
|
35
|
+
import type { AuditTargetKind, AuditAction, AuditActorKind, UserMemoryAuditRow, InsertUserMemoryAudit } from "@intelligo-dev/core/db/schema";
|
|
36
|
+
export type { AuditTargetKind, AuditAction, AuditActorKind, UserMemoryAuditRow, InsertUserMemoryAudit, };
|
|
37
|
+
/**
|
|
38
|
+
* The shape `recordMemoryAudit`
|
|
39
|
+
* (`packages/core/src/identity/audit.ts`) accepts. Kept here — not in
|
|
40
|
+
* `@intelligo-dev/core/identity` — so a package that depends on
|
|
41
|
+
* `@intelligo-dev/audit` but not on the identity service directly has a
|
|
42
|
+
* stable type to code against.
|
|
43
|
+
*/
|
|
44
|
+
export type RecordMemoryAuditInput = {
|
|
45
|
+
userId: string;
|
|
46
|
+
workspaceId: string;
|
|
47
|
+
targetKind: AuditTargetKind;
|
|
48
|
+
targetId: string;
|
|
49
|
+
action: AuditAction;
|
|
50
|
+
actorKind: AuditActorKind;
|
|
51
|
+
actorId?: string;
|
|
52
|
+
beforeValue?: unknown;
|
|
53
|
+
afterValue?: unknown;
|
|
54
|
+
reason?: string;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=memory-audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-audit.d.ts","sourceRoot":"","sources":["../src/memory-audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EACV,eAAe,EACf,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,qBAAqB,GACtB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,eAAe,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory-audit event contract (ADR-0008).
|
|
3
|
+
*
|
|
4
|
+
* ADR-0008 names `@intelligo-dev/audit` as `recordMemoryAudit`'s
|
|
5
|
+
* destination ("`recordMemoryAudit` to `audit`"). The dependency
|
|
6
|
+
* allowlist doesn't cooperate with a literal move, though
|
|
7
|
+
* (tests/architecture/dependency-direction.test.ts): this package may
|
|
8
|
+
* depend on `@intelligo-dev/core` (`audit: ["@intelligo-dev/core"]`), but
|
|
9
|
+
* `@intelligo-dev/core` may depend on nothing (`core: []`) — the same
|
|
10
|
+
* constraint `packages/core/src/documents/service.ts` and
|
|
11
|
+
* `.../conversations/service.ts` already document for
|
|
12
|
+
* `@intelligo-dev/auth`. `user_facts`/`user_memories`/
|
|
13
|
+
* `user_profile_snapshots`/`user_memory_audit` are owned by
|
|
14
|
+
* `packages/core/src/identity` (see that module's doc comment), and
|
|
15
|
+
* that module cannot import this package to call a writer defined
|
|
16
|
+
* here — the allowlist only grants the audit -> core edge, never
|
|
17
|
+
* core -> audit.
|
|
18
|
+
*
|
|
19
|
+
* What actually lands here, then, is the event *contract*: the shape a
|
|
20
|
+
* memory-audit write takes, re-exported from the schema module that
|
|
21
|
+
* already owns it. The write itself is a faithful, in-package port at
|
|
22
|
+
* `packages/core/src/identity/audit.ts`, used internally by the
|
|
23
|
+
* identity service (`deleteFact`, `exportIdentity`) so it never
|
|
24
|
+
* crosses the disallowed core -> audit edge. This module is the public
|
|
25
|
+
* seam for anyone else who depends on `@intelligo-dev/audit` (executions,
|
|
26
|
+
* admin, billing) and wants to describe a memory-audit event without
|
|
27
|
+
* reaching into `@intelligo-dev/core/identity`'s internals.
|
|
28
|
+
*
|
|
29
|
+
* `packages/audit/src/db/schema.ts` already documents where this
|
|
30
|
+
* settles: `user_memory_audit` folds into `audit_events` once the
|
|
31
|
+
* memory subsystem's ownership question closes (see
|
|
32
|
+
* docs/inventory/export-classification.md), and this contract
|
|
33
|
+
* graduates to backing that table's writer directly.
|
|
34
|
+
*/
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=memory-audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-audit.js","sourceRoot":"","sources":["../src/memory-audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@intelligo-dev/audit",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/intelligo-mn/framework.git",
|
|
8
|
+
"directory": "packages/audit"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/intelligo-mn/framework#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/intelligo-mn/framework/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./db": {
|
|
21
|
+
"types": "./dist/db/schema.d.ts",
|
|
22
|
+
"default": "./dist/db/schema.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"drizzle-orm": "^0.45.1",
|
|
27
|
+
"@intelligo-dev/core": "1.0.0-beta.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.0.0",
|
|
31
|
+
"typescript": "^5.7.2"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"type-check": "tsc --noEmit",
|
|
41
|
+
"lint": "eslint .",
|
|
42
|
+
"build": "tsc -p tsconfig.build.json"
|
|
43
|
+
}
|
|
44
|
+
}
|