@murumets-ee/logging 0.1.3 → 0.1.5
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/dist/plugin.d.ts +4 -3
- package/dist/plugin.js +1 -1
- package/package.json +1 -4
- package/dist/admin.cjs +0 -1
- package/dist/admin.d.cts +0 -44
- package/dist/admin.js.map +0 -1
- package/dist/chunk-XTE6WERT.js +0 -31
- package/dist/chunk-XTE6WERT.js.map +0 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -121
- package/dist/index.js.map +0 -1
- package/dist/plugin.cjs +0 -17
- package/dist/plugin.d.cts +0 -17
- package/dist/schema-codegen.cjs +0 -17
- package/dist/schema-codegen.d.cts +0 -7
- package/dist/schema.cjs +0 -1
- package/dist/schema.d.cts +0 -178
- package/dist/schema.js.map +0 -1
package/dist/plugin.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Plugin } from '@murumets-ee/core';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Logging plugin — registers the audit log table schema for migration generation.
|
|
5
3
|
*
|
|
@@ -12,6 +10,9 @@ import { Plugin } from '@murumets-ee/core';
|
|
|
12
10
|
* })
|
|
13
11
|
* ```
|
|
14
12
|
*/
|
|
15
|
-
declare function logging():
|
|
13
|
+
declare function logging(): {
|
|
14
|
+
name: string;
|
|
15
|
+
schemaCode: string;
|
|
16
|
+
};
|
|
16
17
|
|
|
17
18
|
export { logging };
|
package/dist/plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-3M2SQ6QE.js";function
|
|
1
|
+
import{a as e}from"./chunk-3M2SQ6QE.js";function n(){return{name:"@murumets-ee/logging",schemaCode:e()}}export{n as logging};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@murumets-ee/logging",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -34,9 +34,6 @@
|
|
|
34
34
|
"typescript": "^5.7.2",
|
|
35
35
|
"vitest": "^2.1.8"
|
|
36
36
|
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"@murumets-ee/core": "^0.1.0"
|
|
39
|
-
},
|
|
40
37
|
"scripts": {
|
|
41
38
|
"build": "tsup",
|
|
42
39
|
"dev": "tsup --watch",
|
package/dist/admin.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var r in e)u(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of I(e))!R.call(t,o)&&o!==r&&u(t,o,{get:()=>e[o],enumerable:!(i=y(e,o))||i.enumerable});return t};var T=t=>x(u({},"__esModule",{value:!0}),t);var D={};w(D,{logRoutes:()=>m});module.exports=T(D);var n=require("zod"),c=/^[a-zA-Z0-9_-]{1,255}$/,A=n.z.object({action:n.z.string().max(100).optional(),entityType:n.z.string().max(100).optional(),entityId:n.z.string().regex(c,"Invalid ID format").optional(),userId:n.z.string().regex(c,"Invalid user ID format").optional(),dateFrom:n.z.string().datetime({offset:!0,message:"Invalid ISO date"}).optional(),dateTo:n.z.string().datetime({offset:!0,message:"Invalid ISO date"}).optional(),search:n.z.string().max(200).optional(),limit:n.z.coerce.number().min(1).max(100).default(50),offset:n.z.coerce.number().min(0).default(0),sortField:n.z.enum(["createdAt","action","entityType"]).default("createdAt"),sortDirection:n.z.enum(["asc","desc"]).default("desc")});function d(t,e=200){return new Response(JSON.stringify(t),{status:e,headers:{"Content-Type":"application/json"}})}function l(t,e){return d({error:t},e)}function m(t){return{prefix:"logs",resource:"audit-logs",actions:["view"],handlers:{GET:async(e,{segments:r})=>{let i=t();if(r.length===1&&r[0]==="filters"){let[a,p]=await Promise.all([i.getDistinctEntityTypes(),i.getDistinctActions()]);return d({entityTypes:a,actions:p})}if(r.length===1&&r[0]!=="filters"){let a=await i.findById(r[0]);return a?d(a):l("Audit log entry not found",404)}let o=new URL(e.url),g=Object.fromEntries(o.searchParams),s=A.safeParse(g);if(!s.success)return l(`Invalid query params: ${s.error.issues.map(a=>a.message).join(", ")}`,400);let f=await i.query({...s.data,dateFrom:s.data.dateFrom?new Date(s.data.dateFrom):void 0,dateTo:s.data.dateTo?new Date(s.data.dateTo):void 0});return d(f)}}}}0&&(module.exports={logRoutes});
|
package/dist/admin.d.cts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audit log admin routes for the centralized admin API handler.
|
|
3
|
-
*
|
|
4
|
-
* Read-only: only GET handlers. Audit logs are immutable.
|
|
5
|
-
* Admin-only: explicit role check before any data access.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { createAdminApiHandler } from '@murumets-ee/admin-ui/server'
|
|
10
|
-
* import { logRoutes } from '@murumets-ee/logging/admin'
|
|
11
|
-
* import { AuditLogClient } from '@murumets-ee/logging'
|
|
12
|
-
*
|
|
13
|
-
* const handler = createAdminApiHandler({
|
|
14
|
-
* authenticate: async (req) => { ... },
|
|
15
|
-
* entities: [...],
|
|
16
|
-
* routes: [logRoutes(() => new AuditLogClient(db))],
|
|
17
|
-
* })
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
interface AdminRoute {
|
|
21
|
-
prefix: string;
|
|
22
|
-
resource?: string;
|
|
23
|
-
actions?: readonly string[];
|
|
24
|
-
handlers: Partial<Record<string, (req: Request, ctx: {
|
|
25
|
-
segments: string[];
|
|
26
|
-
user: {
|
|
27
|
-
id: string;
|
|
28
|
-
role?: string;
|
|
29
|
-
};
|
|
30
|
-
checkPermission: (resource: string, action: string) => boolean;
|
|
31
|
-
}) => Promise<Response>>>;
|
|
32
|
-
}
|
|
33
|
-
interface AuditLogClientLike {
|
|
34
|
-
query(options: Record<string, unknown>): Promise<{
|
|
35
|
-
items: unknown[];
|
|
36
|
-
total: number;
|
|
37
|
-
}>;
|
|
38
|
-
findById(id: string): Promise<unknown | null>;
|
|
39
|
-
getDistinctEntityTypes(): Promise<string[]>;
|
|
40
|
-
getDistinctActions(): Promise<string[]>;
|
|
41
|
-
}
|
|
42
|
-
declare function logRoutes(getClient: () => AuditLogClientLike): AdminRoute;
|
|
43
|
-
|
|
44
|
-
export { logRoutes };
|
package/dist/admin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/admin/routes.ts"],"sourcesContent":["/**\n * Audit log admin routes for the centralized admin API handler.\n *\n * Read-only: only GET handlers. Audit logs are immutable.\n * Admin-only: explicit role check before any data access.\n *\n * @example\n * ```typescript\n * import { createAdminApiHandler } from '@murumets-ee/admin-ui/server'\n * import { logRoutes } from '@murumets-ee/logging/admin'\n * import { AuditLogClient } from '@murumets-ee/logging'\n *\n * const handler = createAdminApiHandler({\n * authenticate: async (req) => { ... },\n * entities: [...],\n * routes: [logRoutes(() => new AuditLogClient(db))],\n * })\n * ```\n */\n\nimport { z } from 'zod'\n\n// ---------------------------------------------------------------------------\n// Local route type — avoids circular build dep: logging → core → logging.\n// Structurally compatible with AdminRoute from @murumets-ee/core.\n// ---------------------------------------------------------------------------\n\ninterface AdminRoute {\n prefix: string\n resource?: string\n actions?: readonly string[]\n handlers: Partial<\n Record<\n string,\n (\n req: Request,\n ctx: {\n segments: string[]\n user: { id: string; role?: string }\n checkPermission: (resource: string, action: string) => boolean\n },\n ) => Promise<Response>\n >\n >\n}\n\n// ---------------------------------------------------------------------------\n// Query param validation\n// ---------------------------------------------------------------------------\n\nconst ID_REGEX = /^[a-zA-Z0-9_-]{1,255}$/\n\nconst auditLogQuerySchema = z.object({\n action: z.string().max(100).optional(),\n entityType: z.string().max(100).optional(),\n entityId: z.string().regex(ID_REGEX, 'Invalid ID format').optional(),\n userId: z.string().regex(ID_REGEX, 'Invalid user ID format').optional(),\n dateFrom: z.string().datetime({ offset: true, message: 'Invalid ISO date' }).optional(),\n dateTo: z.string().datetime({ offset: true, message: 'Invalid ISO date' }).optional(),\n search: z.string().max(200).optional(),\n limit: z.coerce.number().min(1).max(100).default(50),\n offset: z.coerce.number().min(0).default(0),\n sortField: z.enum(['createdAt', 'action', 'entityType']).default('createdAt'),\n sortDirection: z.enum(['asc', 'desc']).default('desc'),\n})\n\n// ---------------------------------------------------------------------------\n// Response helpers\n// ---------------------------------------------------------------------------\n\nfunction json(data: unknown, status = 200): Response {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n })\n}\n\nfunction errorJson(message: string, status: number): Response {\n return json({ error: message }, status)\n}\n\n// ---------------------------------------------------------------------------\n// AuditLogClient interface (avoids importing from ../audit-client.js)\n// ---------------------------------------------------------------------------\n\ninterface AuditLogClientLike {\n query(options: Record<string, unknown>): Promise<{ items: unknown[]; total: number }>\n findById(id: string): Promise<unknown | null>\n getDistinctEntityTypes(): Promise<string[]>\n getDistinctActions(): Promise<string[]>\n}\n\n// ---------------------------------------------------------------------------\n// Route factory\n// ---------------------------------------------------------------------------\n\nexport function logRoutes(getClient: () => AuditLogClientLike): AdminRoute {\n return {\n prefix: 'logs',\n resource: 'audit-logs',\n actions: ['view'],\n handlers: {\n GET: async (req, { segments }) => {\n // Permission check handled by framework via resource: 'audit-logs'\n const client = getClient()\n\n // GET /logs/filters — distinct values for filter dropdowns\n if (segments.length === 1 && segments[0] === 'filters') {\n const [entityTypes, actions] = await Promise.all([\n client.getDistinctEntityTypes(),\n client.getDistinctActions(),\n ])\n return json({ entityTypes, actions })\n }\n\n // GET /logs/:id — single entry detail\n if (segments.length === 1 && segments[0] !== 'filters') {\n const entry = await client.findById(segments[0])\n if (!entry) return errorJson('Audit log entry not found', 404)\n return json(entry)\n }\n\n // GET /logs — list with filters + pagination\n const url = new URL(req.url)\n const params = Object.fromEntries(url.searchParams)\n const parsed = auditLogQuerySchema.safeParse(params)\n if (!parsed.success) {\n return errorJson(\n `Invalid query params: ${parsed.error.issues.map((i) => i.message).join(', ')}`,\n 400,\n )\n }\n\n const result = await client.query({\n ...parsed.data,\n dateFrom: parsed.data.dateFrom ? new Date(parsed.data.dateFrom) : undefined,\n dateTo: parsed.data.dateTo ? new Date(parsed.data.dateTo) : undefined,\n })\n\n return json(result)\n },\n // No POST, PATCH, DELETE — audit logs are append-only\n },\n }\n}\n"],"mappings":";AAoBA,SAAS,SAAS;AA8BlB,IAAM,WAAW;AAEjB,IAAM,sBAAsB,EAAE,OAAO;AAAA,EACnC,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS;AAAA,EACrC,YAAY,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS;AAAA,EACzC,UAAU,EAAE,OAAO,EAAE,MAAM,UAAU,mBAAmB,EAAE,SAAS;AAAA,EACnE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,wBAAwB,EAAE,SAAS;AAAA,EACtE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,MAAM,SAAS,mBAAmB,CAAC,EAAE,SAAS;AAAA,EACtF,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,MAAM,SAAS,mBAAmB,CAAC,EAAE,SAAS;AAAA,EACpF,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS;AAAA,EACrC,OAAO,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,EAAE;AAAA,EACnD,QAAQ,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC;AAAA,EAC1C,WAAW,EAAE,KAAK,CAAC,aAAa,UAAU,YAAY,CAAC,EAAE,QAAQ,WAAW;AAAA,EAC5E,eAAe,EAAE,KAAK,C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AEA,cAAM,SAAS,MAAM,OAAO,MAAM;AAAA,UAChC,GAAG,OAAO;AAAA,UACV,UAAU,OAAO,KAAK,WAAW,IAAI,KAAK,OAAO,KAAK,QAAQ,IAAI;AAAA,UAClE,QAAQ,OAAO,KAAK,SAAS,IAAI,KAAK,OAAO,KAAK,MAAM,IAAI;AAAA,QAC9D,CAAC;AAED,eAAO,KAAK,MAAM;AAAA,MACpB;AAAA;AAAA,IAEF;AAAA,EACF;AACF;","names":[]}
|
package/dist/chunk-XTE6WERT.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// src/schema.ts
|
|
2
|
-
import { index, jsonb, pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
|
3
|
-
var toolkitAuditLogs = pgTable(
|
|
4
|
-
"toolkit_audit_logs",
|
|
5
|
-
{
|
|
6
|
-
id: uuid("id").primaryKey().defaultRandom(),
|
|
7
|
-
action: varchar("action", { length: 100 }).notNull(),
|
|
8
|
-
entityType: varchar("entity_type", { length: 100 }),
|
|
9
|
-
entityId: varchar("entity_id", { length: 255 }),
|
|
10
|
-
userId: varchar("user_id", { length: 255 }),
|
|
11
|
-
userName: varchar("user_name", { length: 255 }),
|
|
12
|
-
changes: jsonb("changes").$type(),
|
|
13
|
-
metadata: jsonb("metadata").$type(),
|
|
14
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
15
|
-
},
|
|
16
|
-
(table) => ({
|
|
17
|
-
entityTypeCreatedAtIdx: index("audit_entity_type_created_at_idx").on(
|
|
18
|
-
table.entityType,
|
|
19
|
-
table.createdAt
|
|
20
|
-
),
|
|
21
|
-
userIdCreatedAtIdx: index("audit_user_id_created_at_idx").on(table.userId, table.createdAt),
|
|
22
|
-
actionCreatedAtIdx: index("audit_action_created_at_idx").on(table.action, table.createdAt),
|
|
23
|
-
createdAtIdx: index("audit_created_at_idx").on(table.createdAt),
|
|
24
|
-
entityIdIdx: index("audit_entity_id_idx").on(table.entityId)
|
|
25
|
-
})
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
toolkitAuditLogs
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=chunk-XTE6WERT.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema.ts"],"sourcesContent":["import { index, jsonb, pgTable, timestamp, uuid, varchar } from 'drizzle-orm/pg-core'\n\nexport const toolkitAuditLogs = pgTable(\n 'toolkit_audit_logs',\n {\n id: uuid('id').primaryKey().defaultRandom(),\n action: varchar('action', { length: 100 }).notNull(),\n entityType: varchar('entity_type', { length: 100 }),\n entityId: varchar('entity_id', { length: 255 }),\n userId: varchar('user_id', { length: 255 }),\n userName: varchar('user_name', { length: 255 }),\n changes: jsonb('changes').$type<Record<string, unknown>>(),\n metadata: jsonb('metadata').$type<Record<string, unknown>>(),\n createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),\n },\n (table) => ({\n entityTypeCreatedAtIdx: index('audit_entity_type_created_at_idx').on(\n table.entityType,\n table.createdAt,\n ),\n userIdCreatedAtIdx: index('audit_user_id_created_at_idx').on(table.userId, table.createdAt),\n actionCreatedAtIdx: index('audit_action_created_at_idx').on(table.action, table.createdAt),\n createdAtIdx: index('audit_created_at_idx').on(table.createdAt),\n entityIdIdx: index('audit_entity_id_idx').on(table.entityId),\n }),\n)\n"],"mappings":";AAAA,SAAS,OAAO,OAAO,SAAS,WAAW,MAAM,eAAe;AAEzD,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,IACE,IAAI,KAAK,IAAI,EAAE,WAAW,EAAE,cAAc;AAAA,IAC1C,QAAQ,QAAQ,UAAU,EAAE,QAAQ,IAAI,CAAC,EAAE,QAAQ;AAAA,IACnD,YAAY,QAAQ,eAAe,EAAE,QAAQ,IAAI,CAAC;AAAA,IAClD,UAAU,QAAQ,aAAa,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC9C,QAAQ,QAAQ,WAAW,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC1C,UAAU,QAAQ,aAAa,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC9C,SAAS,MAAM,SAAS,EAAE,MAA+B;AAAA,IACzD,UAAU,MAAM,UAAU,EAAE,MAA+B;AAAA,IAC3D,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,EAAE,QAAQ,EAAE,WAAW;AAAA,EAClF;AAAA,EACA,CAAC,WAAW;AAAA,IACV,wBAAwB,MAAM,kCAAkC,EAAE;AAAA,MAChE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA,oBAAoB,MAAM,8BAA8B,EAAE,GAAG,MAAM,QAAQ,MAAM,SAAS;AAAA,IAC1F,oBAAoB,MAAM,6BAA6B,EAAE,GAAG,MAAM,QAAQ,MAAM,SAAS;AAAA,IACzF,cAAc,MAAM,sBAAsB,EAAE,GAAG,MAAM,SAAS;AAAA,IAC9D,aAAa,MAAM,qBAAqB,EAAE,GAAG,MAAM,QAAQ;AAAA,EAC7D;AACF;","names":[]}
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var T=Object.create;var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var r in t)u(e,r,{get:t[r],enumerable:!0})},l=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of _(t))!C.call(e,a)&&a!==r&&u(e,a,{get:()=>t[a],enumerable:!(s=w(t,a))||s.enumerable});return e};var R=(e,t,r)=>(r=e!=null?T(b(e)):{},l(t||!e||!e.__esModule?u(r,"default",{value:e,enumerable:!0}):r,e)),v=e=>l(u({},"__esModule",{value:!0}),e);var N={};E(N,{AuditLogClient:()=>d,bindRequestContext:()=>p,createAuditDbWriter:()=>y,createAuditLogger:()=>m,createChildLogger:()=>A,createLogger:()=>L,toolkitAuditLogs:()=>n});module.exports=v(N);var i=require("drizzle-orm");var o=require("drizzle-orm/pg-core"),n=(0,o.pgTable)("toolkit_audit_logs",{id:(0,o.uuid)("id").primaryKey().defaultRandom(),action:(0,o.varchar)("action",{length:100}).notNull(),entityType:(0,o.varchar)("entity_type",{length:100}),entityId:(0,o.varchar)("entity_id",{length:255}),userId:(0,o.varchar)("user_id",{length:255}),userName:(0,o.varchar)("user_name",{length:255}),changes:(0,o.jsonb)("changes").$type(),metadata:(0,o.jsonb)("metadata").$type(),createdAt:(0,o.timestamp)("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>({entityTypeCreatedAtIdx:(0,o.index)("audit_entity_type_created_at_idx").on(e.entityType,e.createdAt),userIdCreatedAtIdx:(0,o.index)("audit_user_id_created_at_idx").on(e.userId,e.createdAt),actionCreatedAtIdx:(0,o.index)("audit_action_created_at_idx").on(e.action,e.createdAt),createdAtIdx:(0,o.index)("audit_created_at_idx").on(e.createdAt),entityIdIdx:(0,o.index)("audit_entity_id_idx").on(e.entityId)}));var D=100,k=50,d=class{constructor(t){this.db=t}async write(t){await this.db.insert(n).values({action:t.action,entityType:t.entityType,entityId:t.entityId,userId:t.userId,userName:t.userName,changes:t.changes,metadata:t.metadata})}async query(t={}){let r=Math.min(Math.max(t.limit??k,1),D),s=Math.max(t.offset??0,0),a=this.buildConditions(t),g=a.length>0?(0,i.and)(...a):void 0,h=this.buildOrderBy(t.sortField,t.sortDirection),[I,x]=await Promise.all([this.db.select().from(n).where(g).orderBy(h).limit(r).offset(s),this.db.select({count:(0,i.count)()}).from(n).where(g)]);return{items:I,total:x[0]?.count??0}}async findById(t){return(await this.db.select().from(n).where((0,i.eq)(n.id,t)).limit(1))[0]??null}async getDistinctEntityTypes(){return(await this.db.selectDistinct({entityType:n.entityType}).from(n).where((0,i.isNotNull)(n.entityType)).orderBy((0,i.asc)(n.entityType))).map(r=>r.entityType).filter(Boolean)}async getDistinctActions(){return(await this.db.selectDistinct({action:n.action}).from(n).orderBy((0,i.asc)(n.action))).map(r=>r.action)}buildConditions(t){let r=[];if(t.action&&r.push((0,i.eq)(n.action,t.action)),t.entityType&&r.push((0,i.eq)(n.entityType,t.entityType)),t.entityId&&r.push((0,i.eq)(n.entityId,t.entityId)),t.userId&&r.push((0,i.eq)(n.userId,t.userId)),t.dateFrom&&r.push((0,i.gte)(n.createdAt,t.dateFrom)),t.dateTo&&r.push((0,i.lte)(n.createdAt,t.dateTo)),t.search){let s=`%${t.search}%`;r.push((0,i.or)((0,i.ilike)(n.action,s),(0,i.ilike)(n.entityType,s),(0,i.ilike)(n.userName,s)))}return r}buildOrderBy(t,r){let s=r==="asc"?i.asc:i.desc;switch(t){case"action":return s(n.action);case"entityType":return s(n.entityType);default:return s(n.createdAt)}}};function y(e){let t=new d(e);return r=>t.write({action:r.action,entityType:r.entityType??null,entityId:r.entityId??null,userId:r.userId??null,userName:r.userName??null,changes:r.changes??null,metadata:r.metadata??null})}function m(e){return{log:async t=>{e.logger.info({audit:!0,action:t.action,entityType:t.entityType,entityId:t.entityId,userId:t.userId,userName:t.userName,changes:t.changes,metadata:t.metadata},`Audit: ${t.action}`),e.dbWriter&&e.dbWriter(t).catch(r=>{e.logger.error({err:r,auditEntry:t},"Failed to write audit log to database")})}}}function p(e,t){return e.child(t)}var c=R(require("pino"),1),f=(0,c.default)({level:process.env.LOG_LEVEL||"info",formatters:{level:e=>({level:e})},timestamp:!1,serializers:{err:c.default.stdSerializers.err,error:c.default.stdSerializers.err},redact:{paths:["password","token","secret","apiKey","accessToken","refreshToken"],censor:"[REDACTED]"}});function L(e){if(!e)return f;let t={};e.name&&(t.name=e.name);let r={};return e.level&&(r.level=e.level),f.child(t,r)}function A(e,t){return e.child(t)}0&&(module.exports={AuditLogClient,bindRequestContext,createAuditDbWriter,createAuditLogger,createChildLogger,createLogger,toolkitAuditLogs});
|
package/dist/index.d.cts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
2
|
-
import { Logger as Logger$1 } from 'pino';
|
|
3
|
-
export { toolkitAuditLogs } from './schema.cjs';
|
|
4
|
-
import 'drizzle-orm/pg-core';
|
|
5
|
-
|
|
6
|
-
type Logger = Logger$1;
|
|
7
|
-
interface LoggerConfig {
|
|
8
|
-
name?: string;
|
|
9
|
-
level?: string;
|
|
10
|
-
redact?: string[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Create a logger instance
|
|
14
|
-
* If no config provided, returns the root logger
|
|
15
|
-
* If config provided, returns a child logger with the specified context
|
|
16
|
-
*/
|
|
17
|
-
declare function createLogger(config?: LoggerConfig): Logger;
|
|
18
|
-
/**
|
|
19
|
-
* Create a child logger from an existing logger with additional context
|
|
20
|
-
*/
|
|
21
|
-
declare function createChildLogger(parent: Logger, context: Record<string, unknown>): Logger;
|
|
22
|
-
|
|
23
|
-
interface AuditEntry {
|
|
24
|
-
action: string;
|
|
25
|
-
entityType?: string;
|
|
26
|
-
entityId?: string;
|
|
27
|
-
userId?: string;
|
|
28
|
-
userName?: string;
|
|
29
|
-
changes?: Record<string, unknown>;
|
|
30
|
-
metadata?: Record<string, unknown>;
|
|
31
|
-
}
|
|
32
|
-
interface AuditConfig {
|
|
33
|
-
logger: Logger;
|
|
34
|
-
dbWriter?: (entry: AuditEntry) => Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
interface AuditLogger {
|
|
37
|
-
log: (entry: AuditEntry) => Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Create a dbWriter callback wired to AuditLogClient.
|
|
41
|
-
*
|
|
42
|
-
* Pass the returned function as `dbWriter` to `createAuditLogger`:
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const auditLogger = createAuditLogger({
|
|
45
|
-
* logger,
|
|
46
|
-
* dbWriter: createAuditDbWriter(db),
|
|
47
|
-
* })
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
declare function createAuditDbWriter(db: PostgresJsDatabase): (entry: AuditEntry) => Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Create an audit logger
|
|
53
|
-
*
|
|
54
|
-
* Audit logs are written to stdout immediately (non-blocking).
|
|
55
|
-
* Optionally, they can also be written to the database if dbWriter is provided.
|
|
56
|
-
*
|
|
57
|
-
* Database writes are fire-and-forget to avoid blocking the main operation.
|
|
58
|
-
* If DB write fails, it's logged to stderr but doesn't throw.
|
|
59
|
-
*/
|
|
60
|
-
declare function createAuditLogger(config: AuditConfig): AuditLogger;
|
|
61
|
-
|
|
62
|
-
interface AuditLogQueryOptions {
|
|
63
|
-
action?: string;
|
|
64
|
-
entityType?: string;
|
|
65
|
-
entityId?: string;
|
|
66
|
-
userId?: string;
|
|
67
|
-
dateFrom?: Date;
|
|
68
|
-
dateTo?: Date;
|
|
69
|
-
/** Free-text search across action, entityType, userName */
|
|
70
|
-
search?: string;
|
|
71
|
-
/** Default 50, max 100 */
|
|
72
|
-
limit?: number;
|
|
73
|
-
offset?: number;
|
|
74
|
-
sortField?: 'createdAt' | 'action' | 'entityType';
|
|
75
|
-
sortDirection?: 'asc' | 'desc';
|
|
76
|
-
}
|
|
77
|
-
interface AuditLogEntry {
|
|
78
|
-
id: string;
|
|
79
|
-
action: string;
|
|
80
|
-
entityType: string | null;
|
|
81
|
-
entityId: string | null;
|
|
82
|
-
userId: string | null;
|
|
83
|
-
userName: string | null;
|
|
84
|
-
changes: Record<string, unknown> | null;
|
|
85
|
-
metadata: Record<string, unknown> | null;
|
|
86
|
-
createdAt: Date;
|
|
87
|
-
}
|
|
88
|
-
interface AuditLogListResult {
|
|
89
|
-
items: AuditLogEntry[];
|
|
90
|
-
total: number;
|
|
91
|
-
}
|
|
92
|
-
declare class AuditLogClient {
|
|
93
|
-
private db;
|
|
94
|
-
constructor(db: PostgresJsDatabase);
|
|
95
|
-
/** Write a single audit log entry */
|
|
96
|
-
write(entry: Omit<AuditLogEntry, 'id' | 'createdAt'>): Promise<void>;
|
|
97
|
-
/** Query audit logs with filters and pagination */
|
|
98
|
-
query(options?: AuditLogQueryOptions): Promise<AuditLogListResult>;
|
|
99
|
-
/** Get a single audit log entry by ID */
|
|
100
|
-
findById(id: string): Promise<AuditLogEntry | null>;
|
|
101
|
-
/** Get distinct entity types present in the audit log */
|
|
102
|
-
getDistinctEntityTypes(): Promise<string[]>;
|
|
103
|
-
/** Get distinct actions present in the audit log */
|
|
104
|
-
getDistinctActions(): Promise<string[]>;
|
|
105
|
-
private buildConditions;
|
|
106
|
-
private buildOrderBy;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
interface RequestContext {
|
|
110
|
-
requestId?: string;
|
|
111
|
-
userId?: string;
|
|
112
|
-
teamId?: string;
|
|
113
|
-
locale?: string;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Bind request context to a logger
|
|
117
|
-
* Returns a child logger with the context automatically included in all log entries
|
|
118
|
-
*/
|
|
119
|
-
declare function bindRequestContext(logger: Logger, context: RequestContext): Logger;
|
|
120
|
-
|
|
121
|
-
export { type AuditConfig, type AuditEntry, AuditLogClient, type AuditLogEntry, type AuditLogListResult, type AuditLogQueryOptions, type AuditLogger, type Logger, type LoggerConfig, type RequestContext, bindRequestContext, createAuditDbWriter, createAuditLogger, createChildLogger, createLogger };
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/audit-client.ts","../src/audit.ts","../src/context.ts","../src/logger.ts"],"sourcesContent":["import { and, asc, count, desc, eq, gte, ilike, isNotNull, lte, or, type SQL } from 'drizzle-orm'\nimport type { PostgresJsDatabase } from 'drizzle-orm/postgres-js'\nimport { toolkitAuditLogs } from './schema.js'\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface AuditLogQueryOptions {\n action?: string\n entityType?: string\n entityId?: string\n userId?: string\n dateFrom?: Date\n dateTo?: Date\n /** Free-text search across action, entityType, userName */\n search?: string\n /** Default 50, max 100 */\n limit?: number\n offset?: number\n sortField?: 'createdAt' | 'action' | 'entityType'\n sortDirection?: 'asc' | 'desc'\n}\n\nexport interface AuditLogEntry {\n id: string\n action: string\n entityType: string | null\n entityId: string | null\n userId: string | null\n userName: string | null\n changes: Record<string, unknown> | null\n metadata: Record<string, unknown> | null\n createdAt: Date\n}\n\nexport interface AuditLogListResult {\n items: AuditLogEntry[]\n total: number\n}\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst MAX_LIMIT = 100\nconst DEFAULT_LIMIT = 50\n\n// ---------------------------------------------------------------------------\n// Client\n// ---------------------------------------------------------------------------\n\nexport class AuditLogClient {\n constructor(private db: PostgresJsDatabase) {}\n\n /** Write a single audit log entry */\n async write(entry: Omit<AuditLogEntry, 'id' | 'createdAt'>): Promise<void> {\n await this.db.insert(toolkitAuditLogs).values({\n action: entry.action,\n entityType: entry.entityType,\n entityId: entry.entityId,\n userId: entry.userId,\n userName: entry.userName,\n changes: entry.changes,\n metadata: entry.metadata,\n })\n }\n\n /** Query audit logs with filters and pagination */\n async query(options: AuditLogQueryOptions = {}): Promise<AuditLogListResult> {\n const limit = Math.min(Math.max(options.limit ?? DEFAULT_LIMIT, 1), MAX_LIMIT)\n const offset = Math.max(options.offset ?? 0, 0)\n\n const conditions = this.buildConditions(options)\n const where = conditions.length > 0 ? and(...conditions) : undefined\n const orderBy = this.buildOrderBy(options.sortField, options.sortDirection)\n\n const [items, totalResult] = await Promise.all([\n this.db\n .select()\n .from(toolkitAuditLogs)\n .where(where)\n .orderBy(orderBy)\n .limit(limit)\n .offset(offset),\n this.db.select({ count: count() }).from(toolkitAuditLogs).where(where),\n ])\n\n return {\n items: items as AuditLogEntry[],\n total: totalResult[0]?.count ?? 0,\n }\n }\n\n /** Get a single audit log entry by ID */\n async findById(id: string): Promise<AuditLogEntry | null> {\n const rows = await this.db\n .select()\n .from(toolkitAuditLogs)\n .where(eq(toolkitAuditLogs.id, id))\n .limit(1)\n\n return (rows[0] as AuditLogEntry) ?? null\n }\n\n /** Get distinct entity types present in the audit log */\n async getDistinctEntityTypes(): Promise<string[]> {\n const rows = await this.db\n .selectDistinct({ entityType: toolkitAuditLogs.entityType })\n .from(toolkitAuditLogs)\n .where(isNotNull(toolkitAuditLogs.entityType))\n .orderBy(asc(toolkitAuditLogs.entityType))\n\n return rows.map((r) => r.entityType!).filter(Boolean)\n }\n\n /** Get distinct actions present in the audit log */\n async getDistinctActions(): Promise<string[]> {\n const rows = await this.db\n .selectDistinct({ action: toolkitAuditLogs.action })\n .from(toolkitAuditLogs)\n .orderBy(asc(toolkitAuditLogs.action))\n\n return rows.map((r) => r.action)\n }\n\n // -------------------------------------------------------------------------\n // Private helpers\n // -------------------------------------------------------------------------\n\n private buildConditions(options: AuditLogQueryOptions): SQL[] {\n const conditions: SQL[] = []\n\n if (options.action) {\n conditions.push(eq(toolkitAuditLogs.action, options.action))\n }\n if (options.entityType) {\n conditions.push(eq(toolkitAuditLogs.entityType, options.entityType))\n }\n if (options.entityId) {\n conditions.push(eq(toolkitAuditLogs.entityId, options.entityId))\n }\n if (options.userId) {\n conditions.push(eq(toolkitAuditLogs.userId, options.userId))\n }\n if (options.dateFrom) {\n conditions.push(gte(toolkitAuditLogs.createdAt, options.dateFrom))\n }\n if (options.dateTo) {\n conditions.push(lte(toolkitAuditLogs.createdAt, options.dateTo))\n }\n if (options.search) {\n const pattern = `%${options.search}%`\n conditions.push(\n or(\n ilike(toolkitAuditLogs.action, pattern),\n ilike(toolkitAuditLogs.entityType, pattern),\n ilike(toolkitAuditLogs.userName, pattern),\n )!,\n )\n }\n\n return conditions\n }\n\n private buildOrderBy(sortField?: string, sortDirection?: string): SQL {\n const dirFn = sortDirection === 'asc' ? asc : desc\n switch (sortField) {\n case 'action':\n return dirFn(toolkitAuditLogs.action)\n case 'entityType':\n return dirFn(toolkitAuditLogs.entityType)\n case 'createdAt':\n default:\n return dirFn(toolkitAuditLogs.createdAt)\n }\n }\n}\n","import type { PostgresJsDatabase } from 'drizzle-orm/postgres-js'\nimport { AuditLogClient } from './audit-client.js'\nimport type { Logger } from './logger.js'\n\nexport interface AuditEntry {\n action: string\n entityType?: string\n entityId?: string\n userId?: string\n userName?: string\n changes?: Record<string, unknown>\n metadata?: Record<string, unknown>\n}\n\nexport interface AuditConfig {\n logger: Logger\n dbWriter?: (entry: AuditEntry) => Promise<void>\n}\n\nexport interface AuditLogger {\n log: (entry: AuditEntry) => Promise<void>\n}\n\n/**\n * Create a dbWriter callback wired to AuditLogClient.\n *\n * Pass the returned function as `dbWriter` to `createAuditLogger`:\n * ```typescript\n * const auditLogger = createAuditLogger({\n * logger,\n * dbWriter: createAuditDbWriter(db),\n * })\n * ```\n */\nexport function createAuditDbWriter(db: PostgresJsDatabase): (entry: AuditEntry) => Promise<void> {\n const client = new AuditLogClient(db)\n return (entry) =>\n client.write({\n action: entry.action,\n entityType: entry.entityType ?? null,\n entityId: entry.entityId ?? null,\n userId: entry.userId ?? null,\n userName: entry.userName ?? null,\n changes: entry.changes ?? null,\n metadata: entry.metadata ?? null,\n })\n}\n\n/**\n * Create an audit logger\n *\n * Audit logs are written to stdout immediately (non-blocking).\n * Optionally, they can also be written to the database if dbWriter is provided.\n *\n * Database writes are fire-and-forget to avoid blocking the main operation.\n * If DB write fails, it's logged to stderr but doesn't throw.\n */\nexport function createAuditLogger(config: AuditConfig): AuditLogger {\n return {\n log: async (entry: AuditEntry) => {\n // Log to stdout immediately (structured log with audit: true marker)\n config.logger.info(\n {\n audit: true,\n action: entry.action,\n entityType: entry.entityType,\n entityId: entry.entityId,\n userId: entry.userId,\n userName: entry.userName,\n changes: entry.changes,\n metadata: entry.metadata,\n },\n `Audit: ${entry.action}`,\n )\n\n // Write to DB if configured (fire and forget)\n if (config.dbWriter) {\n config.dbWriter(entry).catch((err) => {\n config.logger.error({ err, auditEntry: entry }, 'Failed to write audit log to database')\n })\n }\n },\n }\n}\n","import type { Logger } from './logger.js'\n\nexport interface RequestContext {\n requestId?: string\n userId?: string\n teamId?: string\n locale?: string\n}\n\n/**\n * Bind request context to a logger\n * Returns a child logger with the context automatically included in all log entries\n */\nexport function bindRequestContext(logger: Logger, context: RequestContext): Logger {\n return logger.child(context)\n}\n","import pino, { type Logger as PinoLogger } from 'pino'\n\nexport type Logger = PinoLogger\n\nexport interface LoggerConfig {\n name?: string\n level?: string\n redact?: string[]\n}\n\n/**\n * Root logger instance\n *\n * IMPORTANT: No transports are used to avoid Next.js bundler issues.\n * Pino transports use worker threads that break webpack/turbopack.\n *\n * For dev pretty-printing, pipe to pino-pretty:\n * pnpm dev | pnpm pino-pretty\n */\nconst rootLogger = pino({\n level: process.env.LOG_LEVEL || 'info',\n formatters: {\n level: (label) => ({ level: label }),\n },\n timestamp: false,\n serializers: {\n err: pino.stdSerializers.err,\n error: pino.stdSerializers.err,\n },\n redact: {\n paths: ['password', 'token', 'secret', 'apiKey', 'accessToken', 'refreshToken'],\n censor: '[REDACTED]',\n },\n})\n\n/**\n * Create a logger instance\n * If no config provided, returns the root logger\n * If config provided, returns a child logger with the specified context\n */\nexport function createLogger(config?: LoggerConfig): Logger {\n if (!config) {\n return rootLogger\n }\n\n const bindings: Record<string, unknown> = {}\n if (config.name) {\n bindings.name = config.name\n }\n\n const options: { level?: string } = {}\n if (config.level) {\n options.level = config.level\n }\n\n return rootLogger.child(bindings, options)\n}\n\n/**\n * Create a child logger from an existing logger with additional context\n */\nexport function createChildLogger(parent: Logger, context: Record<string, unknown>): Logger {\n return parent.child(context)\n}\n"],"mappings":";;;;;AAAA,SAAS,KAAK,KAAK,OAAO,MAAM,IAAI,KAAK,OAAO,WAAW,KAAK,UAAoB;AA6CpF,IAAM,YAAY;AAClB,IAAM,gBAAgB;AAMf,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YAAoB,IAAwB;AAAxB;AAAA,EAAyB;AAAA;AAAA,EAG7C,MAAM,MAAM,OAA+D;AACzE,UAAM,KAAK,GAAG,OAAO,gBAAgB,EAAE,OAAO;AAAA,MAC5C,QA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F;;;ACtEO,SAAS,mBAAmB,QAAgB,SAAiC;AAClF,SAAO,OAAO,MAAM,OAAO;AAC7B;;;ACfA,OAAO,UAAyC;AAmBhD,IAAM,aAAa,KAAK;AAAA,EACtB,OAAO,QAAQ,IAAI,aAAa;AAAA,EAChC,YAAY;AAAA,IACV,OAAO,CAAC,WAAW,EAAE,OAAO,MAAM;AAAA,EACpC;AAAA,EACA,WAAW;AAAA,EACX,aAAa;AAAA,IACX,KAAK,KAAK,eAAe;AAAA,IACzB,OAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EACA,QAAQ;AAAA,IACN,OAAO,CAAC,YAAY,SAAS,UAAU,UAAU,eAAe,cAAc;AAAA,IAC9E,QAAQ;AAAA,EACV;AACF,CAAC;AAOM,SAAS,aAAa,QAA+B;AAC1D,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,WAAoC,CAAC;AAC3C,MAAI,OAAO,MAAM;AACf,aAAS,OAAO,OAAO;AAAA,EACzB;AAEA,QAAM,UAA8B,CAAC;AACrC,MAAI,OAAO,OAAO;AAChB,YAAQ,QAAQ,OAAO;AAAA,EACzB;AAEA,SAAO,WAAW,MAAM,UAAU,OAAO;AAC3C;AAKO,SAAS,kBAAkB,QAAgB,SAA0C;AAC1F,SAAO,OAAO,MAAM,OAAO;AAC7B;","names":[]}
|
package/dist/plugin.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(t,e)=>{for(var d in e)i(t,d,{get:e[d],enumerable:!0})},g=(t,e,d,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of u(e))!c.call(t,a)&&a!==d&&i(t,a,{get:()=>e[a],enumerable:!(n=o(e,a))||n.enumerable});return t};var _=t=>g(i({},"__esModule",{value:!0}),t);var s={};l(s,{logging:()=>m});module.exports=_(s);function r(){return`export const toolkitAuditLogs = pgTable('toolkit_audit_logs', {
|
|
2
|
-
id: uuid('id').primaryKey().defaultRandom(),
|
|
3
|
-
action: varchar('action', { length: 100 }).notNull(),
|
|
4
|
-
entityType: varchar('entity_type', { length: 100 }),
|
|
5
|
-
entityId: varchar('entity_id', { length: 255 }),
|
|
6
|
-
userId: varchar('user_id', { length: 255 }),
|
|
7
|
-
userName: varchar('user_name', { length: 255 }),
|
|
8
|
-
changes: jsonb('changes'),
|
|
9
|
-
metadata: jsonb('metadata'),
|
|
10
|
-
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
11
|
-
}, (table) => ({
|
|
12
|
-
entityTypeCreatedAtIdx: index('audit_entity_type_created_at_idx').on(table.entityType, table.createdAt),
|
|
13
|
-
userIdCreatedAtIdx: index('audit_user_id_created_at_idx').on(table.userId, table.createdAt),
|
|
14
|
-
actionCreatedAtIdx: index('audit_action_created_at_idx').on(table.action, table.createdAt),
|
|
15
|
-
createdAtIdx: index('audit_created_at_idx').on(table.createdAt),
|
|
16
|
-
entityIdIdx: index('audit_entity_id_idx').on(table.entityId),
|
|
17
|
-
}))`}function m(){return{name:"@murumets-ee/logging",schemaCode:r()}}0&&(module.exports={logging});
|
package/dist/plugin.d.cts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@murumets-ee/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Logging plugin — registers the audit log table schema for migration generation.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* import { logging } from '@murumets-ee/logging/plugin'
|
|
9
|
-
*
|
|
10
|
-
* export default defineConfig({
|
|
11
|
-
* plugins: [logging()],
|
|
12
|
-
* })
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
declare function logging(): Plugin;
|
|
16
|
-
|
|
17
|
-
export { logging };
|
package/dist/schema-codegen.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var c=(e,t)=>{for(var d in t)i(e,d,{get:t[d],enumerable:!0})},l=(e,t,d,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of o(t))!_.call(e,a)&&a!==d&&i(e,a,{get:()=>t[a],enumerable:!(n=r(t,a))||n.enumerable});return e};var u=e=>l(i({},"__esModule",{value:!0}),e);var y={};c(y,{generateLoggingSchemaCode:()=>x});module.exports=u(y);function x(){return`export const toolkitAuditLogs = pgTable('toolkit_audit_logs', {
|
|
2
|
-
id: uuid('id').primaryKey().defaultRandom(),
|
|
3
|
-
action: varchar('action', { length: 100 }).notNull(),
|
|
4
|
-
entityType: varchar('entity_type', { length: 100 }),
|
|
5
|
-
entityId: varchar('entity_id', { length: 255 }),
|
|
6
|
-
userId: varchar('user_id', { length: 255 }),
|
|
7
|
-
userName: varchar('user_name', { length: 255 }),
|
|
8
|
-
changes: jsonb('changes'),
|
|
9
|
-
metadata: jsonb('metadata'),
|
|
10
|
-
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
11
|
-
}, (table) => ({
|
|
12
|
-
entityTypeCreatedAtIdx: index('audit_entity_type_created_at_idx').on(table.entityType, table.createdAt),
|
|
13
|
-
userIdCreatedAtIdx: index('audit_user_id_created_at_idx').on(table.userId, table.createdAt),
|
|
14
|
-
actionCreatedAtIdx: index('audit_action_created_at_idx').on(table.action, table.createdAt),
|
|
15
|
-
createdAtIdx: index('audit_created_at_idx').on(table.createdAt),
|
|
16
|
-
entityIdIdx: index('audit_entity_id_idx').on(table.entityId),
|
|
17
|
-
}))`}0&&(module.exports={generateLoggingSchemaCode});
|
package/dist/schema.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(e,d)=>{for(var n in d)a(e,n,{get:d[n],enumerable:!0})},y=(e,d,n,r)=>{if(d&&typeof d=="object"||typeof d=="function")for(let i of _(d))!u.call(e,i)&&i!==n&&a(e,i,{get:()=>d[i],enumerable:!(r=o(d,i))||r.enumerable});return e};var s=e=>y(a({},"__esModule",{value:!0}),e);var p={};c(p,{toolkitAuditLogs:()=>g});module.exports=s(p);var t=require("drizzle-orm/pg-core"),g=(0,t.pgTable)("toolkit_audit_logs",{id:(0,t.uuid)("id").primaryKey().defaultRandom(),action:(0,t.varchar)("action",{length:100}).notNull(),entityType:(0,t.varchar)("entity_type",{length:100}),entityId:(0,t.varchar)("entity_id",{length:255}),userId:(0,t.varchar)("user_id",{length:255}),userName:(0,t.varchar)("user_name",{length:255}),changes:(0,t.jsonb)("changes").$type(),metadata:(0,t.jsonb)("metadata").$type(),createdAt:(0,t.timestamp)("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>({entityTypeCreatedAtIdx:(0,t.index)("audit_entity_type_created_at_idx").on(e.entityType,e.createdAt),userIdCreatedAtIdx:(0,t.index)("audit_user_id_created_at_idx").on(e.userId,e.createdAt),actionCreatedAtIdx:(0,t.index)("audit_action_created_at_idx").on(e.action,e.createdAt),createdAtIdx:(0,t.index)("audit_created_at_idx").on(e.createdAt),entityIdIdx:(0,t.index)("audit_entity_id_idx").on(e.entityId)}));0&&(module.exports={toolkitAuditLogs});
|
package/dist/schema.d.cts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
|
-
|
|
3
|
-
declare const toolkitAuditLogs: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
4
|
-
name: "toolkit_audit_logs";
|
|
5
|
-
schema: undefined;
|
|
6
|
-
columns: {
|
|
7
|
-
id: drizzle_orm_pg_core.PgColumn<{
|
|
8
|
-
name: "id";
|
|
9
|
-
tableName: "toolkit_audit_logs";
|
|
10
|
-
dataType: "string";
|
|
11
|
-
columnType: "PgUUID";
|
|
12
|
-
data: string;
|
|
13
|
-
driverParam: string;
|
|
14
|
-
notNull: true;
|
|
15
|
-
hasDefault: true;
|
|
16
|
-
isPrimaryKey: true;
|
|
17
|
-
isAutoincrement: false;
|
|
18
|
-
hasRuntimeDefault: false;
|
|
19
|
-
enumValues: undefined;
|
|
20
|
-
baseColumn: never;
|
|
21
|
-
identity: undefined;
|
|
22
|
-
generated: undefined;
|
|
23
|
-
}, {}, {}>;
|
|
24
|
-
action: drizzle_orm_pg_core.PgColumn<{
|
|
25
|
-
name: "action";
|
|
26
|
-
tableName: "toolkit_audit_logs";
|
|
27
|
-
dataType: "string";
|
|
28
|
-
columnType: "PgVarchar";
|
|
29
|
-
data: string;
|
|
30
|
-
driverParam: string;
|
|
31
|
-
notNull: true;
|
|
32
|
-
hasDefault: false;
|
|
33
|
-
isPrimaryKey: false;
|
|
34
|
-
isAutoincrement: false;
|
|
35
|
-
hasRuntimeDefault: false;
|
|
36
|
-
enumValues: [string, ...string[]];
|
|
37
|
-
baseColumn: never;
|
|
38
|
-
identity: undefined;
|
|
39
|
-
generated: undefined;
|
|
40
|
-
}, {}, {
|
|
41
|
-
length: 100;
|
|
42
|
-
}>;
|
|
43
|
-
entityType: drizzle_orm_pg_core.PgColumn<{
|
|
44
|
-
name: "entity_type";
|
|
45
|
-
tableName: "toolkit_audit_logs";
|
|
46
|
-
dataType: "string";
|
|
47
|
-
columnType: "PgVarchar";
|
|
48
|
-
data: string;
|
|
49
|
-
driverParam: string;
|
|
50
|
-
notNull: false;
|
|
51
|
-
hasDefault: false;
|
|
52
|
-
isPrimaryKey: false;
|
|
53
|
-
isAutoincrement: false;
|
|
54
|
-
hasRuntimeDefault: false;
|
|
55
|
-
enumValues: [string, ...string[]];
|
|
56
|
-
baseColumn: never;
|
|
57
|
-
identity: undefined;
|
|
58
|
-
generated: undefined;
|
|
59
|
-
}, {}, {
|
|
60
|
-
length: 100;
|
|
61
|
-
}>;
|
|
62
|
-
entityId: drizzle_orm_pg_core.PgColumn<{
|
|
63
|
-
name: "entity_id";
|
|
64
|
-
tableName: "toolkit_audit_logs";
|
|
65
|
-
dataType: "string";
|
|
66
|
-
columnType: "PgVarchar";
|
|
67
|
-
data: string;
|
|
68
|
-
driverParam: string;
|
|
69
|
-
notNull: false;
|
|
70
|
-
hasDefault: false;
|
|
71
|
-
isPrimaryKey: false;
|
|
72
|
-
isAutoincrement: false;
|
|
73
|
-
hasRuntimeDefault: false;
|
|
74
|
-
enumValues: [string, ...string[]];
|
|
75
|
-
baseColumn: never;
|
|
76
|
-
identity: undefined;
|
|
77
|
-
generated: undefined;
|
|
78
|
-
}, {}, {
|
|
79
|
-
length: 255;
|
|
80
|
-
}>;
|
|
81
|
-
userId: drizzle_orm_pg_core.PgColumn<{
|
|
82
|
-
name: "user_id";
|
|
83
|
-
tableName: "toolkit_audit_logs";
|
|
84
|
-
dataType: "string";
|
|
85
|
-
columnType: "PgVarchar";
|
|
86
|
-
data: string;
|
|
87
|
-
driverParam: string;
|
|
88
|
-
notNull: false;
|
|
89
|
-
hasDefault: false;
|
|
90
|
-
isPrimaryKey: false;
|
|
91
|
-
isAutoincrement: false;
|
|
92
|
-
hasRuntimeDefault: false;
|
|
93
|
-
enumValues: [string, ...string[]];
|
|
94
|
-
baseColumn: never;
|
|
95
|
-
identity: undefined;
|
|
96
|
-
generated: undefined;
|
|
97
|
-
}, {}, {
|
|
98
|
-
length: 255;
|
|
99
|
-
}>;
|
|
100
|
-
userName: drizzle_orm_pg_core.PgColumn<{
|
|
101
|
-
name: "user_name";
|
|
102
|
-
tableName: "toolkit_audit_logs";
|
|
103
|
-
dataType: "string";
|
|
104
|
-
columnType: "PgVarchar";
|
|
105
|
-
data: string;
|
|
106
|
-
driverParam: string;
|
|
107
|
-
notNull: false;
|
|
108
|
-
hasDefault: false;
|
|
109
|
-
isPrimaryKey: false;
|
|
110
|
-
isAutoincrement: false;
|
|
111
|
-
hasRuntimeDefault: false;
|
|
112
|
-
enumValues: [string, ...string[]];
|
|
113
|
-
baseColumn: never;
|
|
114
|
-
identity: undefined;
|
|
115
|
-
generated: undefined;
|
|
116
|
-
}, {}, {
|
|
117
|
-
length: 255;
|
|
118
|
-
}>;
|
|
119
|
-
changes: drizzle_orm_pg_core.PgColumn<{
|
|
120
|
-
name: "changes";
|
|
121
|
-
tableName: "toolkit_audit_logs";
|
|
122
|
-
dataType: "json";
|
|
123
|
-
columnType: "PgJsonb";
|
|
124
|
-
data: Record<string, unknown>;
|
|
125
|
-
driverParam: unknown;
|
|
126
|
-
notNull: false;
|
|
127
|
-
hasDefault: false;
|
|
128
|
-
isPrimaryKey: false;
|
|
129
|
-
isAutoincrement: false;
|
|
130
|
-
hasRuntimeDefault: false;
|
|
131
|
-
enumValues: undefined;
|
|
132
|
-
baseColumn: never;
|
|
133
|
-
identity: undefined;
|
|
134
|
-
generated: undefined;
|
|
135
|
-
}, {}, {
|
|
136
|
-
$type: Record<string, unknown>;
|
|
137
|
-
}>;
|
|
138
|
-
metadata: drizzle_orm_pg_core.PgColumn<{
|
|
139
|
-
name: "metadata";
|
|
140
|
-
tableName: "toolkit_audit_logs";
|
|
141
|
-
dataType: "json";
|
|
142
|
-
columnType: "PgJsonb";
|
|
143
|
-
data: Record<string, unknown>;
|
|
144
|
-
driverParam: unknown;
|
|
145
|
-
notNull: false;
|
|
146
|
-
hasDefault: false;
|
|
147
|
-
isPrimaryKey: false;
|
|
148
|
-
isAutoincrement: false;
|
|
149
|
-
hasRuntimeDefault: false;
|
|
150
|
-
enumValues: undefined;
|
|
151
|
-
baseColumn: never;
|
|
152
|
-
identity: undefined;
|
|
153
|
-
generated: undefined;
|
|
154
|
-
}, {}, {
|
|
155
|
-
$type: Record<string, unknown>;
|
|
156
|
-
}>;
|
|
157
|
-
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
158
|
-
name: "created_at";
|
|
159
|
-
tableName: "toolkit_audit_logs";
|
|
160
|
-
dataType: "date";
|
|
161
|
-
columnType: "PgTimestamp";
|
|
162
|
-
data: Date;
|
|
163
|
-
driverParam: string;
|
|
164
|
-
notNull: true;
|
|
165
|
-
hasDefault: true;
|
|
166
|
-
isPrimaryKey: false;
|
|
167
|
-
isAutoincrement: false;
|
|
168
|
-
hasRuntimeDefault: false;
|
|
169
|
-
enumValues: undefined;
|
|
170
|
-
baseColumn: never;
|
|
171
|
-
identity: undefined;
|
|
172
|
-
generated: undefined;
|
|
173
|
-
}, {}, {}>;
|
|
174
|
-
};
|
|
175
|
-
dialect: "pg";
|
|
176
|
-
}>;
|
|
177
|
-
|
|
178
|
-
export { toolkitAuditLogs };
|
package/dist/schema.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|