@orthacms/activity-server 0.0.0-reserve.0
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 +21 -0
- package/README.md +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/lib/activity/activity-filter.d.ts +14 -0
- package/dist/lib/activity/activity-filter.d.ts.map +1 -0
- package/dist/lib/activity/activity-filter.js +25 -0
- package/dist/lib/activity/activity.constants.d.ts +18 -0
- package/dist/lib/activity/activity.constants.d.ts.map +1 -0
- package/dist/lib/activity/activity.constants.js +16 -0
- package/dist/lib/activity/controllers/list-activity.controller.d.ts +14 -0
- package/dist/lib/activity/controllers/list-activity.controller.d.ts.map +1 -0
- package/dist/lib/activity/controllers/list-activity.controller.js +36 -0
- package/dist/lib/activity/dto/list-activity-query.dto.d.ts +46 -0
- package/dist/lib/activity/dto/list-activity-query.dto.d.ts.map +1 -0
- package/dist/lib/activity/dto/list-activity-query.dto.js +197 -0
- package/dist/lib/activity/infrastructure/audit-event-mapping.d.ts +60 -0
- package/dist/lib/activity/infrastructure/audit-event-mapping.d.ts.map +1 -0
- package/dist/lib/activity/infrastructure/audit-event-mapping.js +402 -0
- package/dist/lib/activity/infrastructure/audit-event.subscriber.d.ts +29 -0
- package/dist/lib/activity/infrastructure/audit-event.subscriber.d.ts.map +1 -0
- package/dist/lib/activity/infrastructure/audit-event.subscriber.js +54 -0
- package/dist/lib/activity/services/activity.service.d.ts +55 -0
- package/dist/lib/activity/services/activity.service.d.ts.map +1 -0
- package/dist/lib/activity/services/activity.service.js +147 -0
- package/dist/lib/activity/types/activity-view.d.ts +37 -0
- package/dist/lib/activity/types/activity-view.d.ts.map +1 -0
- package/dist/lib/activity/types/activity-view.js +2 -0
- package/dist/lib/activity.module.d.ts +20 -0
- package/dist/lib/activity.module.d.ts.map +1 -0
- package/dist/lib/activity.module.js +49 -0
- package/dist/lib/copilot/activity-tool.provider.d.ts +40 -0
- package/dist/lib/copilot/activity-tool.provider.d.ts.map +1 -0
- package/dist/lib/copilot/activity-tool.provider.js +157 -0
- package/dist/lib/schema/activity-events.d.ts +178 -0
- package/dist/lib/schema/activity-events.d.ts.map +1 -0
- package/dist/lib/schema/activity-events.js +38 -0
- package/dist/lib/schema/index.d.ts +2 -0
- package/dist/lib/schema/index.d.ts.map +1 -0
- package/dist/lib/schema/index.js +5 -0
- package/dist/lib/utils/activity-plugin.d.ts +26 -0
- package/dist/lib/utils/activity-plugin.d.ts.map +1 -0
- package/dist/lib/utils/activity-plugin.js +38 -0
- package/migrations/0000_init.sql +15 -0
- package/migrations/meta/0000_snapshot.json +159 -0
- package/migrations/meta/_journal.json +13 -0
- package/package.json +46 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.activityEvents = void 0;
|
|
4
|
+
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
5
|
+
/**
|
|
6
|
+
* The append-only audit trail. One row per recorded action.
|
|
7
|
+
*
|
|
8
|
+
* Deliberate isolation choices (the audit log must outlive what it records):
|
|
9
|
+
* - `actorId` is a uuid with **no FK** — the actor may later be deleted, but
|
|
10
|
+
* the audit row must remain.
|
|
11
|
+
* - `actorEmail` is a frozen snapshot of the actor's email at record time, so
|
|
12
|
+
* the trail stays readable even after the user row is gone or renamed.
|
|
13
|
+
* - `subjectId` is **text**, not uuid — subjects are not always users and not
|
|
14
|
+
* always uuid-keyed.
|
|
15
|
+
* - `meta` is an open jsonb payload; each emitting plugin owns its shape.
|
|
16
|
+
* - `at` is the logical event time (defaults to now); `createdAt` is the
|
|
17
|
+
* immutable write time, dropped from the read API.
|
|
18
|
+
*
|
|
19
|
+
* Indexed for the three query shapes the read API serves: a subject's history,
|
|
20
|
+
* an actor's history, and a kind's history — each time-ordered.
|
|
21
|
+
*/
|
|
22
|
+
exports.activityEvents = (0, pg_core_1.pgTable)('activity_events', {
|
|
23
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
24
|
+
kind: (0, pg_core_1.text)('kind').notNull(),
|
|
25
|
+
subjectType: (0, pg_core_1.text)('subject_type').notNull(),
|
|
26
|
+
subjectId: (0, pg_core_1.text)('subject_id').notNull(),
|
|
27
|
+
actorId: (0, pg_core_1.uuid)('actor_id'),
|
|
28
|
+
actorEmail: (0, pg_core_1.text)('actor_email'),
|
|
29
|
+
meta: (0, pg_core_1.jsonb)('meta'),
|
|
30
|
+
at: (0, pg_core_1.timestamp)('at', { withTimezone: true }).notNull().defaultNow(),
|
|
31
|
+
createdAt: (0, pg_core_1.timestamp)('created_at', { withTimezone: true })
|
|
32
|
+
.notNull()
|
|
33
|
+
.defaultNow()
|
|
34
|
+
}, (table) => [
|
|
35
|
+
(0, pg_core_1.index)('activity_events_subject_idx').on(table.subjectType, table.subjectId, table.at),
|
|
36
|
+
(0, pg_core_1.index)('activity_events_actor_idx').on(table.actorId, table.at),
|
|
37
|
+
(0, pg_core_1.index)('activity_events_kind_idx').on(table.kind, table.at)
|
|
38
|
+
]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.activityEvents = void 0;
|
|
4
|
+
var activity_events_1 = require("./activity-events");
|
|
5
|
+
Object.defineProperty(exports, "activityEvents", { enumerable: true, get: function () { return activity_events_1.activityEvents; } });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ServerPlugin } from '@orthacms/bootstrap-server';
|
|
2
|
+
/**
|
|
3
|
+
* Server plugin for the audit log. A plain {@link ServerPlugin} — the feature
|
|
4
|
+
* carries no host config.
|
|
5
|
+
*
|
|
6
|
+
* Owns the `activity_events` schema and **ships its own migrations**, so the
|
|
7
|
+
* `migrations` descriptor points the host's `db:migrate` at this package's
|
|
8
|
+
* committed SQL, tracked under its own table. Conventionally registered
|
|
9
|
+
* **after** `DatabasePlugin` (whose client it injects) and `IdentityPlugin`
|
|
10
|
+
* (whose guards gate its read API and whose `activity:read` permission it
|
|
11
|
+
* relies on).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* createServer({
|
|
16
|
+
* plugins: [
|
|
17
|
+
* DatabasePlugin({ connectionString: config.database.url }),
|
|
18
|
+
* IdentityPlugin(config.plugins.identity),
|
|
19
|
+
* ActivityPlugin(),
|
|
20
|
+
* UsersPlugin(),
|
|
21
|
+
* ],
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function ActivityPlugin(): ServerPlugin;
|
|
26
|
+
//# sourceMappingURL=activity-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/activity-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,IAAI,YAAY,CAS7C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActivityPlugin = ActivityPlugin;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const activity_module_1 = require("../activity.module");
|
|
6
|
+
/**
|
|
7
|
+
* Server plugin for the audit log. A plain {@link ServerPlugin} — the feature
|
|
8
|
+
* carries no host config.
|
|
9
|
+
*
|
|
10
|
+
* Owns the `activity_events` schema and **ships its own migrations**, so the
|
|
11
|
+
* `migrations` descriptor points the host's `db:migrate` at this package's
|
|
12
|
+
* committed SQL, tracked under its own table. Conventionally registered
|
|
13
|
+
* **after** `DatabasePlugin` (whose client it injects) and `IdentityPlugin`
|
|
14
|
+
* (whose guards gate its read API and whose `activity:read` permission it
|
|
15
|
+
* relies on).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* createServer({
|
|
20
|
+
* plugins: [
|
|
21
|
+
* DatabasePlugin({ connectionString: config.database.url }),
|
|
22
|
+
* IdentityPlugin(config.plugins.identity),
|
|
23
|
+
* ActivityPlugin(),
|
|
24
|
+
* UsersPlugin(),
|
|
25
|
+
* ],
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function ActivityPlugin() {
|
|
30
|
+
return {
|
|
31
|
+
name: 'activity',
|
|
32
|
+
module: activity_module_1.ActivityModule.forRoot(),
|
|
33
|
+
migrations: {
|
|
34
|
+
dir: () => (0, node_path_1.join)(__dirname, '../../../migrations'),
|
|
35
|
+
table: '__drizzle_migrations_activity'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
CREATE TABLE "activity_events" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"kind" text NOT NULL,
|
|
4
|
+
"subject_type" text NOT NULL,
|
|
5
|
+
"subject_id" text NOT NULL,
|
|
6
|
+
"actor_id" uuid,
|
|
7
|
+
"actor_email" text,
|
|
8
|
+
"meta" jsonb,
|
|
9
|
+
"at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
10
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
CREATE INDEX "activity_events_subject_idx" ON "activity_events" USING btree ("subject_type","subject_id","at");--> statement-breakpoint
|
|
14
|
+
CREATE INDEX "activity_events_actor_idx" ON "activity_events" USING btree ("actor_id","at");--> statement-breakpoint
|
|
15
|
+
CREATE INDEX "activity_events_kind_idx" ON "activity_events" USING btree ("kind","at");
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "307cf643-5557-4bda-8d14-b999159984bd",
|
|
3
|
+
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
4
|
+
"version": "7",
|
|
5
|
+
"dialect": "postgresql",
|
|
6
|
+
"tables": {
|
|
7
|
+
"public.activity_events": {
|
|
8
|
+
"name": "activity_events",
|
|
9
|
+
"schema": "",
|
|
10
|
+
"columns": {
|
|
11
|
+
"id": {
|
|
12
|
+
"name": "id",
|
|
13
|
+
"type": "uuid",
|
|
14
|
+
"primaryKey": true,
|
|
15
|
+
"notNull": true,
|
|
16
|
+
"default": "gen_random_uuid()"
|
|
17
|
+
},
|
|
18
|
+
"kind": {
|
|
19
|
+
"name": "kind",
|
|
20
|
+
"type": "text",
|
|
21
|
+
"primaryKey": false,
|
|
22
|
+
"notNull": true
|
|
23
|
+
},
|
|
24
|
+
"subject_type": {
|
|
25
|
+
"name": "subject_type",
|
|
26
|
+
"type": "text",
|
|
27
|
+
"primaryKey": false,
|
|
28
|
+
"notNull": true
|
|
29
|
+
},
|
|
30
|
+
"subject_id": {
|
|
31
|
+
"name": "subject_id",
|
|
32
|
+
"type": "text",
|
|
33
|
+
"primaryKey": false,
|
|
34
|
+
"notNull": true
|
|
35
|
+
},
|
|
36
|
+
"actor_id": {
|
|
37
|
+
"name": "actor_id",
|
|
38
|
+
"type": "uuid",
|
|
39
|
+
"primaryKey": false,
|
|
40
|
+
"notNull": false
|
|
41
|
+
},
|
|
42
|
+
"actor_email": {
|
|
43
|
+
"name": "actor_email",
|
|
44
|
+
"type": "text",
|
|
45
|
+
"primaryKey": false,
|
|
46
|
+
"notNull": false
|
|
47
|
+
},
|
|
48
|
+
"meta": {
|
|
49
|
+
"name": "meta",
|
|
50
|
+
"type": "jsonb",
|
|
51
|
+
"primaryKey": false,
|
|
52
|
+
"notNull": false
|
|
53
|
+
},
|
|
54
|
+
"at": {
|
|
55
|
+
"name": "at",
|
|
56
|
+
"type": "timestamp with time zone",
|
|
57
|
+
"primaryKey": false,
|
|
58
|
+
"notNull": true,
|
|
59
|
+
"default": "now()"
|
|
60
|
+
},
|
|
61
|
+
"created_at": {
|
|
62
|
+
"name": "created_at",
|
|
63
|
+
"type": "timestamp with time zone",
|
|
64
|
+
"primaryKey": false,
|
|
65
|
+
"notNull": true,
|
|
66
|
+
"default": "now()"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"indexes": {
|
|
70
|
+
"activity_events_subject_idx": {
|
|
71
|
+
"name": "activity_events_subject_idx",
|
|
72
|
+
"columns": [
|
|
73
|
+
{
|
|
74
|
+
"expression": "subject_type",
|
|
75
|
+
"isExpression": false,
|
|
76
|
+
"asc": true,
|
|
77
|
+
"nulls": "last"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"expression": "subject_id",
|
|
81
|
+
"isExpression": false,
|
|
82
|
+
"asc": true,
|
|
83
|
+
"nulls": "last"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"expression": "at",
|
|
87
|
+
"isExpression": false,
|
|
88
|
+
"asc": true,
|
|
89
|
+
"nulls": "last"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"isUnique": false,
|
|
93
|
+
"concurrently": false,
|
|
94
|
+
"method": "btree",
|
|
95
|
+
"with": {}
|
|
96
|
+
},
|
|
97
|
+
"activity_events_actor_idx": {
|
|
98
|
+
"name": "activity_events_actor_idx",
|
|
99
|
+
"columns": [
|
|
100
|
+
{
|
|
101
|
+
"expression": "actor_id",
|
|
102
|
+
"isExpression": false,
|
|
103
|
+
"asc": true,
|
|
104
|
+
"nulls": "last"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"expression": "at",
|
|
108
|
+
"isExpression": false,
|
|
109
|
+
"asc": true,
|
|
110
|
+
"nulls": "last"
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"isUnique": false,
|
|
114
|
+
"concurrently": false,
|
|
115
|
+
"method": "btree",
|
|
116
|
+
"with": {}
|
|
117
|
+
},
|
|
118
|
+
"activity_events_kind_idx": {
|
|
119
|
+
"name": "activity_events_kind_idx",
|
|
120
|
+
"columns": [
|
|
121
|
+
{
|
|
122
|
+
"expression": "kind",
|
|
123
|
+
"isExpression": false,
|
|
124
|
+
"asc": true,
|
|
125
|
+
"nulls": "last"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"expression": "at",
|
|
129
|
+
"isExpression": false,
|
|
130
|
+
"asc": true,
|
|
131
|
+
"nulls": "last"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"isUnique": false,
|
|
135
|
+
"concurrently": false,
|
|
136
|
+
"method": "btree",
|
|
137
|
+
"with": {}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"foreignKeys": {},
|
|
141
|
+
"compositePrimaryKeys": {},
|
|
142
|
+
"uniqueConstraints": {},
|
|
143
|
+
"policies": {},
|
|
144
|
+
"checkConstraints": {},
|
|
145
|
+
"isRLSEnabled": false
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"enums": {},
|
|
149
|
+
"schemas": {},
|
|
150
|
+
"sequences": {},
|
|
151
|
+
"roles": {},
|
|
152
|
+
"policies": {},
|
|
153
|
+
"views": {},
|
|
154
|
+
"_meta": {
|
|
155
|
+
"columns": {},
|
|
156
|
+
"schemas": {},
|
|
157
|
+
"tables": {}
|
|
158
|
+
}
|
|
159
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orthacms/activity-server",
|
|
3
|
+
"version": "0.0.0-reserve.0",
|
|
4
|
+
"description": "@orthacms/activity-server — part of Ortha CMS.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/ortha-source/ortha-cms/tree/main/packages/activity/server",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ortha-source/ortha-cms.git",
|
|
10
|
+
"directory": "packages/activity/server"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ortha-source/ortha-cms/issues"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"migrations"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@nestjs/common": "^11.0.0",
|
|
30
|
+
"@nestjs/swagger": "^11.4.6",
|
|
31
|
+
"@orthacms/bootstrap-server": "^0.0.1",
|
|
32
|
+
"@orthacms/copilot-domain": "^0.0.1",
|
|
33
|
+
"@orthacms/copilot-server": "^0.0.1",
|
|
34
|
+
"@orthacms/database": "^0.0.1",
|
|
35
|
+
"@orthacms/identity-server": "^0.0.1",
|
|
36
|
+
"@orthacms/tools-server": "^0.0.1",
|
|
37
|
+
"@orthacms/utils-server": "^0.0.1",
|
|
38
|
+
"class-transformer": "^0.5.1",
|
|
39
|
+
"class-validator": "^0.15.1",
|
|
40
|
+
"drizzle-orm": "^0.45.0",
|
|
41
|
+
"tslib": "^2.3.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|