@webiny/api-audit-logs-sql 0.0.0-unstable.9f53ea597d

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @webiny/api-audit-logs-sql
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
@@ -0,0 +1,15 @@
1
+ import type { Knex } from "knex";
2
+ import type { TableManager } from "@webiny/api-core-sql/TableManager.js";
3
+ import type { IStorage, IStorageFetchParams, IStorageFetchResult, IStorageStoreParams, IStorageStoreResult, IStorageListParams, IStorageListResult } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
4
+ export declare class SqliteStorage implements IStorage {
5
+ private readonly knex;
6
+ private readonly tableManager;
7
+ constructor(params: {
8
+ knex: Knex;
9
+ tableManager: TableManager;
10
+ });
11
+ fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;
12
+ store(params: IStorageStoreParams): Promise<IStorageStoreResult>;
13
+ list(params: IStorageListParams): Promise<IStorageListResult>;
14
+ private ensureTable;
15
+ }
@@ -0,0 +1,136 @@
1
+ const TABLE_NAME = "webiny_audit_logs";
2
+ const toRow = (data)=>({
3
+ id: data.id,
4
+ tenant: data.tenant,
5
+ createdBy: JSON.stringify(data.createdBy),
6
+ createdOn: data.createdOn.toISOString(),
7
+ app: data.app,
8
+ action: data.action,
9
+ message: data.message,
10
+ entity: data.entity,
11
+ entityId: data.entityId,
12
+ tags: JSON.stringify(data.tags),
13
+ expiresAt: data.expiresAt.toISOString(),
14
+ content: data.content
15
+ });
16
+ const fromRow = (row)=>({
17
+ id: row.id,
18
+ tenant: row.tenant,
19
+ createdBy: JSON.parse(row.createdBy),
20
+ createdOn: new Date(row.createdOn),
21
+ app: row.app,
22
+ action: row.action,
23
+ message: row.message,
24
+ entity: row.entity,
25
+ entityId: row.entityId,
26
+ tags: JSON.parse(row.tags),
27
+ expiresAt: new Date(row.expiresAt),
28
+ content: row.content
29
+ });
30
+ class SqliteStorage {
31
+ constructor(params){
32
+ this.knex = params.knex;
33
+ this.tableManager = params.tableManager;
34
+ }
35
+ async fetch(params) {
36
+ await this.ensureTable();
37
+ try {
38
+ const row = await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.id).andWhere("tenant", params.tenant).first();
39
+ if (!row) return {
40
+ error: new Error(`Audit log with id "${params.id}" not found.`),
41
+ success: false
42
+ };
43
+ const auditLog = fromRow(row);
44
+ return {
45
+ data: auditLog,
46
+ success: true
47
+ };
48
+ } catch (error) {
49
+ return {
50
+ error: error,
51
+ success: false
52
+ };
53
+ }
54
+ }
55
+ async store(params) {
56
+ await this.ensureTable();
57
+ try {
58
+ const row = toRow(params.data);
59
+ const existing = await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.data.id).first();
60
+ if (existing) await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.data.id).update(row);
61
+ else await this.knex(this.tableManager.resolve(TABLE_NAME)).insert(row);
62
+ return {
63
+ data: params.data,
64
+ success: true
65
+ };
66
+ } catch (error) {
67
+ return {
68
+ error: error,
69
+ success: false
70
+ };
71
+ }
72
+ }
73
+ async list(params) {
74
+ await this.ensureTable();
75
+ try {
76
+ const limit = params.limit || 100;
77
+ const query = this.knex(this.tableManager.resolve(TABLE_NAME)).where("tenant", params.tenant);
78
+ if (params.app) query.andWhere("app", params.app);
79
+ if (params.entity) query.andWhere("entity", params.entity);
80
+ if (params.action) query.andWhere("action", params.action);
81
+ if (params.entityId) {
82
+ const entityPrefix = params.entityId.split("#")[0];
83
+ query.andWhere("entityId", "LIKE", `${entityPrefix}%`);
84
+ }
85
+ if (params.createdBy) query.andWhere("createdBy", "LIKE", `%"id":"${params.createdBy}"%`);
86
+ if ("createdOn_gte" in params && params.createdOn_gte) query.andWhere("createdOn", ">=", params.createdOn_gte.toISOString());
87
+ if ("createdOn_lte" in params && params.createdOn_lte) query.andWhere("createdOn", "<=", params.createdOn_lte.toISOString());
88
+ const sortDirection = "DESC" === params.sort ? "desc" : "asc";
89
+ query.orderBy("createdOn", sortDirection);
90
+ query.limit(limit + 1);
91
+ if (params.after) {
92
+ const afterRow = await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.after).first();
93
+ if (afterRow) if ("asc" === sortDirection) query.andWhere("createdOn", ">", afterRow.createdOn);
94
+ else query.andWhere("createdOn", "<", afterRow.createdOn);
95
+ }
96
+ const rows = await query;
97
+ const hasMoreItems = rows.length > limit;
98
+ if (hasMoreItems) rows.pop();
99
+ const data = rows.map(fromRow);
100
+ const lastItem = data[data.length - 1];
101
+ const after = hasMoreItems && lastItem ? lastItem.id : void 0;
102
+ return {
103
+ data,
104
+ meta: {
105
+ after,
106
+ hasMoreItems
107
+ },
108
+ success: true
109
+ };
110
+ } catch (error) {
111
+ return {
112
+ error: error,
113
+ success: false
114
+ };
115
+ }
116
+ }
117
+ async ensureTable() {
118
+ return this.tableManager.ensure(TABLE_NAME, (table)=>{
119
+ table.text("id").primary();
120
+ table.text("tenant").notNullable();
121
+ table.text("createdBy").notNullable();
122
+ table.datetime("createdOn").notNullable();
123
+ table.text("app").notNullable();
124
+ table.text("action").notNullable();
125
+ table.text("message").notNullable();
126
+ table.text("entity").notNullable();
127
+ table.text("entityId").notNullable();
128
+ table.text("tags").notNullable();
129
+ table.datetime("expiresAt").notNullable();
130
+ table.text("content").notNullable();
131
+ });
132
+ }
133
+ }
134
+ export { SqliteStorage };
135
+
136
+ //# sourceMappingURL=SqliteStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteStorage.js","sources":["../src/SqliteStorage.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { TableManager } from \"@webiny/api-core-sql/TableManager.js\";\nimport type { IAuditLog, IAuditLogCreatedBy } from \"@webiny/api-audit-logs/storage/types.js\";\nimport type {\n IStorage,\n IStorageFetchParams,\n IStorageFetchResult,\n IStorageStoreParams,\n IStorageStoreResult,\n IStorageListParams,\n IStorageListResult\n} from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\n\ninterface AuditLogRow {\n id: string;\n tenant: string;\n createdBy: string;\n createdOn: string;\n app: string;\n action: string;\n message: string;\n entity: string;\n entityId: string;\n tags: string;\n expiresAt: string;\n content: string;\n}\n\nconst TABLE_NAME = \"webiny_audit_logs\";\n\n/* Convert an IAuditLog to a flat database row. */\nconst toRow = (data: IAuditLog): AuditLogRow => {\n return {\n id: data.id,\n tenant: data.tenant,\n createdBy: JSON.stringify(data.createdBy),\n createdOn: data.createdOn.toISOString(),\n app: data.app,\n action: data.action,\n message: data.message,\n entity: data.entity,\n entityId: data.entityId,\n tags: JSON.stringify(data.tags),\n expiresAt: data.expiresAt.toISOString(),\n content: data.content\n };\n};\n\n/* Convert a database row back to an IAuditLog. */\nconst fromRow = (row: AuditLogRow): IAuditLog => {\n return {\n id: row.id,\n tenant: row.tenant,\n createdBy: JSON.parse(row.createdBy) as IAuditLogCreatedBy,\n createdOn: new Date(row.createdOn),\n app: row.app,\n action: row.action,\n message: row.message,\n entity: row.entity,\n entityId: row.entityId,\n tags: JSON.parse(row.tags) as string[],\n expiresAt: new Date(row.expiresAt),\n content: row.content\n };\n};\n\nexport class SqliteStorage implements IStorage {\n private readonly knex: Knex;\n private readonly tableManager: TableManager;\n\n public constructor(params: { knex: Knex; tableManager: TableManager }) {\n this.knex = params.knex;\n this.tableManager = params.tableManager;\n }\n\n public async fetch(params: IStorageFetchParams): Promise<IStorageFetchResult> {\n await this.ensureTable();\n\n try {\n const row = await this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME))\n .where(\"id\", params.id)\n .andWhere(\"tenant\", params.tenant)\n .first();\n\n if (!row) {\n return {\n error: new Error(`Audit log with id \"${params.id}\" not found.`),\n success: false\n };\n }\n\n const auditLog = fromRow(row);\n\n return {\n data: auditLog,\n success: true\n };\n } catch (error) {\n return {\n error: error as Error,\n success: false\n };\n }\n }\n\n public async store(params: IStorageStoreParams): Promise<IStorageStoreResult> {\n await this.ensureTable();\n\n try {\n const row = toRow(params.data);\n\n const existing = await this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME))\n .where(\"id\", params.data.id)\n .first();\n\n if (existing) {\n await this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME))\n .where(\"id\", params.data.id)\n .update(row);\n } else {\n await this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME)).insert(row);\n }\n\n return {\n data: params.data,\n success: true\n };\n } catch (error) {\n return {\n error: error as Error,\n success: false\n };\n }\n }\n\n public async list(params: IStorageListParams): Promise<IStorageListResult> {\n await this.ensureTable();\n\n try {\n const limit = params.limit || 100;\n\n const query = this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME)).where(\n \"tenant\",\n params.tenant\n );\n\n if (params.app) {\n query.andWhere(\"app\", params.app);\n }\n\n if (params.entity) {\n query.andWhere(\"entity\", params.entity);\n }\n\n if (params.action) {\n query.andWhere(\"action\", params.action);\n }\n\n if (params.entityId) {\n /* Match by entity type prefix — strip the record ID after #. */\n const entityPrefix = params.entityId.split(\"#\")[0];\n query.andWhere(\"entityId\", \"LIKE\", `${entityPrefix}%`);\n }\n\n if (params.createdBy) {\n query.andWhere(\"createdBy\", \"LIKE\", `%\"id\":\"${params.createdBy}\"%`);\n }\n\n if (\"createdOn_gte\" in params && params.createdOn_gte) {\n query.andWhere(\"createdOn\", \">=\", params.createdOn_gte.toISOString());\n }\n\n if (\"createdOn_lte\" in params && params.createdOn_lte) {\n query.andWhere(\"createdOn\", \"<=\", params.createdOn_lte.toISOString());\n }\n\n const sortDirection = params.sort === \"DESC\" ? \"desc\" : \"asc\";\n\n query.orderBy(\"createdOn\", sortDirection);\n\n // Fetch one extra row to detect if there are more items.\n query.limit(limit + 1);\n\n if (params.after) {\n const afterRow = await this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME))\n .where(\"id\", params.after)\n .first();\n\n if (afterRow) {\n if (sortDirection === \"asc\") {\n query.andWhere(\"createdOn\", \">\", afterRow.createdOn);\n } else {\n query.andWhere(\"createdOn\", \"<\", afterRow.createdOn);\n }\n }\n }\n\n const rows = await query;\n\n const hasMoreItems = rows.length > limit;\n\n if (hasMoreItems) {\n rows.pop();\n }\n\n const data = rows.map(fromRow);\n\n const lastItem = data[data.length - 1];\n const after = hasMoreItems && lastItem ? lastItem.id : undefined;\n\n return {\n data,\n meta: {\n after,\n hasMoreItems\n },\n success: true\n };\n } catch (error) {\n return {\n error: error as Error,\n success: false\n };\n }\n }\n\n private async ensureTable(): Promise<void> {\n return this.tableManager.ensure(TABLE_NAME, table => {\n table.text(\"id\").primary();\n table.text(\"tenant\").notNullable();\n table.text(\"createdBy\").notNullable();\n table.datetime(\"createdOn\").notNullable();\n table.text(\"app\").notNullable();\n table.text(\"action\").notNullable();\n table.text(\"message\").notNullable();\n table.text(\"entity\").notNullable();\n table.text(\"entityId\").notNullable();\n table.text(\"tags\").notNullable();\n table.datetime(\"expiresAt\").notNullable();\n table.text(\"content\").notNullable();\n });\n }\n}\n"],"names":["TABLE_NAME","toRow","data","JSON","fromRow","row","Date","SqliteStorage","params","Error","auditLog","error","existing","limit","query","entityPrefix","sortDirection","afterRow","rows","hasMoreItems","lastItem","after","undefined","table"],"mappings":"AA4BA,MAAMA,aAAa;AAGnB,MAAMC,QAAQ,CAACC,OACJ;QACH,IAAIA,KAAK,EAAE;QACX,QAAQA,KAAK,MAAM;QACnB,WAAWC,KAAK,SAAS,CAACD,KAAK,SAAS;QACxC,WAAWA,KAAK,SAAS,CAAC,WAAW;QACrC,KAAKA,KAAK,GAAG;QACb,QAAQA,KAAK,MAAM;QACnB,SAASA,KAAK,OAAO;QACrB,QAAQA,KAAK,MAAM;QACnB,UAAUA,KAAK,QAAQ;QACvB,MAAMC,KAAK,SAAS,CAACD,KAAK,IAAI;QAC9B,WAAWA,KAAK,SAAS,CAAC,WAAW;QACrC,SAASA,KAAK,OAAO;IACzB;AAIJ,MAAME,UAAU,CAACC,MACN;QACH,IAAIA,IAAI,EAAE;QACV,QAAQA,IAAI,MAAM;QAClB,WAAWF,KAAK,KAAK,CAACE,IAAI,SAAS;QACnC,WAAW,IAAIC,KAAKD,IAAI,SAAS;QACjC,KAAKA,IAAI,GAAG;QACZ,QAAQA,IAAI,MAAM;QAClB,SAASA,IAAI,OAAO;QACpB,QAAQA,IAAI,MAAM;QAClB,UAAUA,IAAI,QAAQ;QACtB,MAAMF,KAAK,KAAK,CAACE,IAAI,IAAI;QACzB,WAAW,IAAIC,KAAKD,IAAI,SAAS;QACjC,SAASA,IAAI,OAAO;I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d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { Knex } from "knex";
2
+ interface RegisterAuditLogsSqlStorageOperationsParams {
3
+ knex: Knex;
4
+ tableNamePrefix?: string;
5
+ }
6
+ export declare const registerAuditLogsSqlStorageOperations: (params: RegisterAuditLogsSqlStorageOperationsParams) => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types").Context>;
7
+ export {};
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { TableManager } from "@webiny/api-core-sql/TableManager.js";
2
+ import { createRegisterExtensionPlugin } from "@webiny/handler";
3
+ import { SqliteStorage } from "./SqliteStorage.js";
4
+ import { AuditLogsStorage } from "@webiny/api-audit-logs/abstractions.js";
5
+ const registerAuditLogsSqlStorageOperations = (params)=>createRegisterExtensionPlugin((context)=>{
6
+ const tableManager = new TableManager(params.knex, params.tableNamePrefix);
7
+ const storage = new SqliteStorage({
8
+ knex: params.knex,
9
+ tableManager
10
+ });
11
+ context.container.registerInstance(AuditLogsStorage, storage);
12
+ });
13
+ export { registerAuditLogsSqlStorageOperations };
14
+
15
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { TableManager } from \"@webiny/api-core-sql/TableManager.js\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { SqliteStorage } from \"~/SqliteStorage.js\";\nimport { AuditLogsStorage } from \"@webiny/api-audit-logs/abstractions.js\";\n\ninterface RegisterAuditLogsSqlStorageOperationsParams {\n knex: Knex;\n tableNamePrefix?: string;\n}\n\nexport const registerAuditLogsSqlStorageOperations = (\n params: RegisterAuditLogsSqlStorageOperationsParams\n) => {\n return createRegisterExtensionPlugin(context => {\n const tableManager = new TableManager(params.knex, params.tableNamePrefix);\n const storage = new SqliteStorage({\n knex: params.knex,\n tableManager\n });\n context.container.registerInstance(AuditLogsStorage, storage);\n });\n};\n"],"names":["registerAuditLogsSqlStorageOperations","params","createRegisterExtensionPlugin","context","tableManager","TableManager","storage","SqliteStorage","AuditLogsStorage"],"mappings":";;;;AAWO,MAAMA,wCAAwC,CACjDC,SAEOC,8BAA8BC,CAAAA;QACjC,MAAMC,eAAe,IAAIC,aAAaJ,OAAO,IAAI,EAAEA,OAAO,eAAe;QACzE,MAAMK,UAAU,IAAIC,cAAc;YAC9B,MAAMN,OAAO,IAAI;YACjBG;QACJ;QACAD,QAAQ,SAAS,CAAC,gBAAgB,CAACK,kBAAkBF;IACzD"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@webiny/api-audit-logs-sql",
3
+ "version": "0.0.0-unstable.9f53ea597d",
4
+ "type": "module",
5
+ "keywords": [
6
+ "@webiny/api-audit-logs",
7
+ "storage-operations",
8
+ "sql",
9
+ "sau:sql"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/webiny/webiny-js.git"
14
+ },
15
+ "description": "SQL storage operations for @webiny/api-audit-logs.",
16
+ "author": "Webiny Ltd.",
17
+ "license": "MIT",
18
+ "exports": {
19
+ ".": "./index.js",
20
+ "./*": "./*"
21
+ },
22
+ "dependencies": {
23
+ "@webiny/api-audit-logs": "0.0.0-unstable.9f53ea597d",
24
+ "@webiny/api-core-sql": "0.0.0-unstable.9f53ea597d",
25
+ "@webiny/handler": "0.0.0-unstable.9f53ea597d",
26
+ "knex": "3.3.0"
27
+ },
28
+ "devDependencies": {
29
+ "@webiny/build-tools": "0.0.0-unstable.9f53ea597d",
30
+ "@webiny/project-utils": "0.0.0-unstable.9f53ea597d",
31
+ "better-sqlite3": "13.0.1",
32
+ "rimraf": "6.1.3",
33
+ "typescript": "7.0.2"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "webiny": {
39
+ "publishFrom": "dist"
40
+ }
41
+ }