@vonosan/logging 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ export { activityLogs } from './schema.js';
11
+ export { LoggingService } from './service/logging.service.js';
12
+ export type { LogQueryFilters } from './service/logging.service.js';
13
+ export { default as loggingRouter } from './routes/logging.routes.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,YAAY,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AACnE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ export { activityLogs } from './schema.js';
11
+ export { LoggingService } from './service/logging.service.js';
12
+ export { default as loggingRouter } from './routes/logging.routes.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ import { Hono } from 'hono';
11
+ import type { AppVariables } from 'vonosan/types';
12
+ /**
13
+ * Admin-only activity log query endpoint.
14
+ * Mount behind `isAdmin` middleware.
15
+ */
16
+ declare const loggingRouter: Hono<{
17
+ Variables: AppVariables;
18
+ }, import("hono/types").BlankSchema, "/">;
19
+ export default loggingRouter;
20
+ //# sourceMappingURL=logging.routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.routes.d.ts","sourceRoot":"","sources":["../../src/routes/logging.routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAKjD;;;GAGG;AACH,QAAA,MAAM,aAAa;eAAyB,YAAY;yCAAK,CAAA;AAiB7D,eAAe,aAAa,CAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ import { Hono } from 'hono';
11
+ import { ApiResponse } from 'vonosan/server';
12
+ import { LoggingService } from '../service/logging.service.js';
13
+ /**
14
+ * Admin-only activity log query endpoint.
15
+ * Mount behind `isAdmin` middleware.
16
+ */
17
+ const loggingRouter = new Hono();
18
+ loggingRouter.get('/', async (c) => {
19
+ const service = new LoggingService(c.var.db);
20
+ const page = Number(c.req.query('page') ?? 1);
21
+ const limit = Number(c.req.query('limit') ?? 50);
22
+ const actorId = c.req.query('actorId');
23
+ const action = c.req.query('action');
24
+ const resourceType = c.req.query('resourceType');
25
+ const startDate = c.req.query('startDate') ? new Date(c.req.query('startDate')) : undefined;
26
+ const endDate = c.req.query('endDate') ? new Date(c.req.query('endDate')) : undefined;
27
+ const result = await service.query({ actorId, action, resourceType, startDate, endDate, page, limit });
28
+ return c.json(ApiResponse.success(result, 'Activity logs retrieved'));
29
+ });
30
+ export default loggingRouter;
31
+ //# sourceMappingURL=logging.routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.routes.js","sourceRoot":"","sources":["../../src/routes/logging.routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D;;;GAGG;AACH,MAAM,aAAa,GAAG,IAAI,IAAI,EAA+B,CAAA;AAE7D,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACjC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,EAAwB,CAAC,CAAA;IAElE,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IAChD,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACtC,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACpC,MAAM,YAAY,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IAChD,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC5F,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAEtF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IACtG,OAAO,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC,CAAA;AACvE,CAAC,CAAC,CAAA;AAEF,eAAe,aAAa,CAAA"}
@@ -0,0 +1,174 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ /**
11
+ * activity_logs — immutable audit trail of actor actions on resources.
12
+ * Never soft-deleted; records are permanent for compliance.
13
+ */
14
+ export declare const activityLogs: import("drizzle-orm/pg-core").PgTableWithColumns<{
15
+ name: "activity_logs";
16
+ schema: undefined;
17
+ columns: {
18
+ id: import("drizzle-orm/pg-core").PgColumn<{
19
+ name: "id";
20
+ tableName: "activity_logs";
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
+ actor_id: import("drizzle-orm/pg-core").PgColumn<{
36
+ name: "actor_id";
37
+ tableName: "activity_logs";
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
+ action: import("drizzle-orm/pg-core").PgColumn<{
53
+ name: "action";
54
+ tableName: "activity_logs";
55
+ dataType: "string";
56
+ columnType: "PgText";
57
+ data: string;
58
+ driverParam: string;
59
+ notNull: true;
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
+ resource_type: import("drizzle-orm/pg-core").PgColumn<{
70
+ name: "resource_type";
71
+ tableName: "activity_logs";
72
+ dataType: "string";
73
+ columnType: "PgText";
74
+ data: string;
75
+ driverParam: string;
76
+ notNull: false;
77
+ hasDefault: false;
78
+ isPrimaryKey: false;
79
+ isAutoincrement: false;
80
+ hasRuntimeDefault: false;
81
+ enumValues: [string, ...string[]];
82
+ baseColumn: never;
83
+ identity: undefined;
84
+ generated: undefined;
85
+ }, {}, {}>;
86
+ resource_id: import("drizzle-orm/pg-core").PgColumn<{
87
+ name: "resource_id";
88
+ tableName: "activity_logs";
89
+ dataType: "string";
90
+ columnType: "PgText";
91
+ data: string;
92
+ driverParam: string;
93
+ notNull: false;
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
+ ip: import("drizzle-orm/pg-core").PgColumn<{
104
+ name: "ip";
105
+ tableName: "activity_logs";
106
+ dataType: "string";
107
+ columnType: "PgText";
108
+ data: string;
109
+ driverParam: string;
110
+ notNull: false;
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
+ user_agent: import("drizzle-orm/pg-core").PgColumn<{
121
+ name: "user_agent";
122
+ tableName: "activity_logs";
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
+ metadata: import("drizzle-orm/pg-core").PgColumn<{
138
+ name: "metadata";
139
+ tableName: "activity_logs";
140
+ dataType: "json";
141
+ columnType: "PgJsonb";
142
+ data: unknown;
143
+ driverParam: unknown;
144
+ notNull: false;
145
+ hasDefault: false;
146
+ isPrimaryKey: false;
147
+ isAutoincrement: false;
148
+ hasRuntimeDefault: false;
149
+ enumValues: undefined;
150
+ baseColumn: never;
151
+ identity: undefined;
152
+ generated: undefined;
153
+ }, {}, {}>;
154
+ created_at: import("drizzle-orm/pg-core").PgColumn<{
155
+ name: "created_at";
156
+ tableName: "activity_logs";
157
+ dataType: "date";
158
+ columnType: "PgTimestamp";
159
+ data: Date;
160
+ driverParam: string;
161
+ notNull: true;
162
+ hasDefault: true;
163
+ isPrimaryKey: false;
164
+ isAutoincrement: false;
165
+ hasRuntimeDefault: false;
166
+ enumValues: undefined;
167
+ baseColumn: never;
168
+ identity: undefined;
169
+ generated: undefined;
170
+ }, {}, {}>;
171
+ };
172
+ dialect: "pg";
173
+ }>;
174
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBxB,CAAA"}
package/dist/schema.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ import { pgTable, text, timestamp, jsonb, index, } from 'drizzle-orm/pg-core';
11
+ // ─── activity_logs ────────────────────────────────────────────────────────────
12
+ /**
13
+ * activity_logs — immutable audit trail of actor actions on resources.
14
+ * Never soft-deleted; records are permanent for compliance.
15
+ */
16
+ export const activityLogs = pgTable('activity_logs', {
17
+ id: text('id').primaryKey(),
18
+ actor_id: text('actor_id'),
19
+ action: text('action').notNull(),
20
+ resource_type: text('resource_type'),
21
+ resource_id: text('resource_id'),
22
+ ip: text('ip'),
23
+ user_agent: text('user_agent'),
24
+ metadata: jsonb('metadata'),
25
+ created_at: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull().defaultNow(),
26
+ }, (t) => [
27
+ index('activity_logs_actor_id_idx').on(t.actor_id),
28
+ index('activity_logs_action_idx').on(t.action),
29
+ index('activity_logs_resource_type_idx').on(t.resource_type),
30
+ index('activity_logs_created_at_idx').on(t.created_at),
31
+ ]);
32
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,OAAO,EACP,IAAI,EACJ,SAAS,EACT,KAAK,EACL,KAAK,GACN,MAAM,qBAAqB,CAAA;AAE5B,iFAAiF;AAEjF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CACjC,eAAe,EACf;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC;IAC1B,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;IAChC,aAAa,EAAE,IAAI,CAAC,eAAe,CAAC;IACpC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC;IAChC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC;IACd,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC;IAC9B,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC;IAC3B,UAAU,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CACjG,EACD,CAAC,CAAC,EAAE,EAAE,CAAC;IACL,KAAK,CAAC,4BAA4B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClD,KAAK,CAAC,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9C,KAAK,CAAC,iCAAiC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;IAC5D,KAAK,CAAC,8BAA8B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;CACvD,CACF,CAAA"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ import type { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
11
+ export interface LogQueryFilters {
12
+ actorId?: string;
13
+ action?: string;
14
+ resourceType?: string;
15
+ startDate?: Date;
16
+ endDate?: Date;
17
+ page: number;
18
+ limit: number;
19
+ }
20
+ /**
21
+ * LoggingService — creates and queries activity audit logs.
22
+ */
23
+ export declare class LoggingService {
24
+ private readonly db;
25
+ constructor(db: PostgresJsDatabase);
26
+ /**
27
+ * Create an activity log entry.
28
+ * Dispatches to queue if available, otherwise inserts synchronously.
29
+ */
30
+ log(actorId: string | null, action: string, resourceType?: string, resourceId?: string, ip?: string, userAgent?: string, metadata?: Record<string, unknown>): Promise<void>;
31
+ /**
32
+ * Paginated query of activity logs with optional filters.
33
+ */
34
+ query(filters: LogQueryFilters): Promise<{
35
+ items: {
36
+ id: string;
37
+ actor_id: string | null;
38
+ action: string;
39
+ resource_type: string | null;
40
+ resource_id: string | null;
41
+ ip: string | null;
42
+ user_agent: string | null;
43
+ metadata: unknown;
44
+ created_at: Date;
45
+ }[];
46
+ meta: import("packages/vonosan/src/shared/utils/pagination.js").PaginationMeta;
47
+ }>;
48
+ }
49
+ //# sourceMappingURL=logging.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.service.d.ts","sourceRoot":"","sources":["../../src/service/logging.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAMjE,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAID;;GAEG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,kBAAkB;IAInD;;;OAGG;IACG,GAAG,CACP,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,EAAE,CAAC,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,IAAI,CAAC;IAoBhB;;OAEG;IACG,KAAK,CAAC,OAAO,EAAE,eAAe;;;;;;;;;;;;;;CA6BrC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * ──────────────────────────────────────────────────────────────────
3
+ * 🏢 Company Name: Bonifade Technologies
4
+ * 👨‍💻 Developer: Bowofade Oyerinde
5
+ * 🐙 GitHub: oyenet1
6
+ * 📅 Created Date: 2026-04-05
7
+ * 🔄 Updated Date: 2026-04-05
8
+ * ──────────────────────────────────────────────────────────────────
9
+ */
10
+ import { eq, and, gte, lte, desc } from 'drizzle-orm';
11
+ import { generateId, buildPaginationMeta, Logger } from 'vonosan/server';
12
+ import { activityLogs } from '../schema.js';
13
+ // ─── LoggingService ───────────────────────────────────────────────────────────
14
+ /**
15
+ * LoggingService — creates and queries activity audit logs.
16
+ */
17
+ export class LoggingService {
18
+ db;
19
+ constructor(db) {
20
+ this.db = db;
21
+ }
22
+ // ─── log ────────────────────────────────────────────────────────────────────
23
+ /**
24
+ * Create an activity log entry.
25
+ * Dispatches to queue if available, otherwise inserts synchronously.
26
+ */
27
+ async log(actorId, action, resourceType, resourceId, ip, userAgent, metadata) {
28
+ const id = generateId();
29
+ // Synchronous insert (queue dispatch would be wired here when available)
30
+ await this.db.insert(activityLogs).values({
31
+ id,
32
+ actor_id: actorId,
33
+ action,
34
+ resource_type: resourceType ?? null,
35
+ resource_id: resourceId ?? null,
36
+ ip: ip ?? null,
37
+ user_agent: userAgent ?? null,
38
+ metadata: metadata ?? null,
39
+ });
40
+ Logger.debug('[logging] Activity logged', { id, actorId, action, resourceType });
41
+ }
42
+ // ─── query ──────────────────────────────────────────────────────────────────
43
+ /**
44
+ * Paginated query of activity logs with optional filters.
45
+ */
46
+ async query(filters) {
47
+ const { actorId, action, resourceType, startDate, endDate, page, limit } = filters;
48
+ const offset = (page - 1) * limit;
49
+ const conditions = [];
50
+ if (actorId)
51
+ conditions.push(eq(activityLogs.actor_id, actorId));
52
+ if (action)
53
+ conditions.push(eq(activityLogs.action, action));
54
+ if (resourceType)
55
+ conditions.push(eq(activityLogs.resource_type, resourceType));
56
+ if (startDate)
57
+ conditions.push(gte(activityLogs.created_at, startDate));
58
+ if (endDate)
59
+ conditions.push(lte(activityLogs.created_at, endDate));
60
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
61
+ const rows = await this.db
62
+ .select()
63
+ .from(activityLogs)
64
+ .where(where)
65
+ .orderBy(desc(activityLogs.created_at))
66
+ .limit(limit)
67
+ .offset(offset);
68
+ const countRows = await this.db
69
+ .select({ id: activityLogs.id })
70
+ .from(activityLogs)
71
+ .where(where);
72
+ const total = countRows.length;
73
+ return { items: rows, meta: buildPaginationMeta(page, limit, total) };
74
+ }
75
+ }
76
+ //# sourceMappingURL=logging.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.service.js","sourceRoot":"","sources":["../../src/service/logging.service.ts"],"names":[],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@vonosan/logging",
3
+ "version": "0.2.1",
4
+ "type": "module",
5
+ "description": "Vono activity and audit logging module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/oyenet1/vonosan.git",
9
+ "directory": "packages/logging"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "dev": "tsc -p tsconfig.json --watch"
28
+ },
29
+ "peerDependencies": {
30
+ "drizzle-orm": ">=0.44.0",
31
+ "hono": ">=4.8.0",
32
+ "vonosan": ">=0.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/bun": "1.2.14",
36
+ "@types/node": "25.5.2",
37
+ "drizzle-orm": "0.44.5",
38
+ "hono": "4.8.10",
39
+ "typescript": "5.8.3",
40
+ "vonosan": "0.2.1"
41
+ }
42
+ }