@webiny/api-audit-logs-sql 0.0.0-unstable.33e4fd9647 → 0.0.0-unstable.3fddf667ea
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/AuditLogsSqlSchemaSetup.d.ts +13 -0
- package/AuditLogsSqlSchemaSetup.js +33 -0
- package/AuditLogsSqlSchemaSetup.js.map +1 -0
- package/SqlAuditLogsStorage.d.ts +11 -0
- package/SqlAuditLogsStorage.js +28 -0
- package/SqlAuditLogsStorage.js.map +1 -0
- package/SqliteStorage.d.ts +1 -1
- package/SqliteStorage.js +14 -16
- package/SqliteStorage.js.map +1 -1
- package/createTableManager.d.ts +4 -0
- package/createTableManager.js +7 -0
- package/createTableManager.js.map +1 -0
- package/feature.d.ts +11 -0
- package/feature.js +17 -0
- package/feature.js.map +1 -0
- package/index.d.ts +1 -7
- package/index.js +1 -15
- package/package.json +7 -6
- package/index.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
|
|
2
|
+
/** The `auditLogs` schema setup step: the audit logs table. */
|
|
3
|
+
declare class AuditLogsSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {
|
|
4
|
+
private readonly knex;
|
|
5
|
+
private readonly schemaConfig?;
|
|
6
|
+
readonly name = "auditLogs";
|
|
7
|
+
constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
|
|
8
|
+
setup(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare const AuditLogsSqlSchemaSetup: typeof AuditLogsSqlSchemaSetupImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core-sql/schemaSetup/abstractions").ISqlSchemaSetup>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
|
|
2
|
+
import { SqliteStorage } from "./SqliteStorage.js";
|
|
3
|
+
import { createTableManager } from "./createTableManager.js";
|
|
4
|
+
class AuditLogsSqlSchemaSetupImpl {
|
|
5
|
+
constructor(knex, schemaConfig){
|
|
6
|
+
this.knex = knex;
|
|
7
|
+
this.schemaConfig = schemaConfig;
|
|
8
|
+
this.name = "auditLogs";
|
|
9
|
+
}
|
|
10
|
+
async setup() {
|
|
11
|
+
const tableManager = createTableManager(this.knex, this.schemaConfig, false);
|
|
12
|
+
new SqliteStorage({
|
|
13
|
+
knex: this.knex.client,
|
|
14
|
+
tableManager
|
|
15
|
+
});
|
|
16
|
+
await tableManager.setup();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const AuditLogsSqlSchemaSetup = SqlSchemaSetup.createImplementation({
|
|
20
|
+
implementation: AuditLogsSqlSchemaSetupImpl,
|
|
21
|
+
dependencies: [
|
|
22
|
+
KnexClient,
|
|
23
|
+
[
|
|
24
|
+
SqlSchemaConfig,
|
|
25
|
+
{
|
|
26
|
+
optional: true
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
export { AuditLogsSqlSchemaSetup };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=AuditLogsSqlSchemaSetup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuditLogsSqlSchemaSetup.js","sources":["../src/AuditLogsSqlSchemaSetup.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from \"@webiny/api-core-sql\";\nimport { SqliteStorage } from \"~/SqliteStorage.js\";\nimport { createTableManager } from \"~/createTableManager.js\";\n\n/** The `auditLogs` schema setup step: the audit logs table. */\nclass AuditLogsSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {\n public readonly name = \"auditLogs\";\n\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public async setup(): Promise<void> {\n const tableManager = createTableManager(this.knex, this.schemaConfig, false);\n // Building the storage declares its table on the manager.\n new SqliteStorage({ knex: this.knex.client, tableManager });\n await tableManager.setup();\n }\n}\n\nexport const AuditLogsSqlSchemaSetup = SqlSchemaSetup.createImplementation({\n implementation: AuditLogsSqlSchemaSetupImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["AuditLogsSqlSchemaSetupImpl","knex","schemaConfig","tableManager","createTableManager","SqliteStorage","AuditLogsSqlSchemaSetup","SqlSchemaSetup","KnexClient","SqlSchemaConfig"],"mappings":";;;AAKA,MAAMA;IAGF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;aAJL,IAAI,GAAG;IAKpB;IAEH,MAAa,QAAuB;QAChC,MAAMC,eAAeC,mBAAmB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE;QAEtE,IAAIC,cAAc;YAAE,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;YAAEF;QAAa;QACzD,MAAMA,aAAa,KAAK;IAC5B;AACJ;AAEO,MAAMG,0BAA0BC,eAAe,oBAAoB,CAAC;IACvE,gBAAgBP;IAChB,cAAc;QAACQ;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { KnexClient, SqlSchemaConfig } from "@webiny/api-core-sql";
|
|
2
|
+
import { AuditLogsStorage } from "@webiny/api-audit-logs/abstractions.js";
|
|
3
|
+
import { SqliteStorage } from "./SqliteStorage.js";
|
|
4
|
+
/** The audit logs storage on the container's connection and table prefix. */
|
|
5
|
+
declare class SqlAuditLogsStorageImpl extends SqliteStorage implements AuditLogsStorage.Interface {
|
|
6
|
+
constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface);
|
|
7
|
+
}
|
|
8
|
+
export declare const SqlAuditLogsStorage: typeof SqlAuditLogsStorageImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-audit-logs/storage/abstractions/Storage").IStorage>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KnexClient, SqlSchemaConfig } from "@webiny/api-core-sql";
|
|
2
|
+
import { AuditLogsStorage } from "@webiny/api-audit-logs/abstractions.js";
|
|
3
|
+
import { SqliteStorage } from "./SqliteStorage.js";
|
|
4
|
+
import { createTableManager } from "./createTableManager.js";
|
|
5
|
+
class SqlAuditLogsStorageImpl extends SqliteStorage {
|
|
6
|
+
constructor(knex, schemaConfig){
|
|
7
|
+
const schemaManaged = schemaConfig?.isManaged() === true;
|
|
8
|
+
super({
|
|
9
|
+
knex: knex.client,
|
|
10
|
+
tableManager: createTableManager(knex, schemaConfig, schemaManaged)
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const SqlAuditLogsStorage = AuditLogsStorage.createImplementation({
|
|
15
|
+
implementation: SqlAuditLogsStorageImpl,
|
|
16
|
+
dependencies: [
|
|
17
|
+
KnexClient,
|
|
18
|
+
[
|
|
19
|
+
SqlSchemaConfig,
|
|
20
|
+
{
|
|
21
|
+
optional: true
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
export { SqlAuditLogsStorage };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=SqlAuditLogsStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlAuditLogsStorage.js","sources":["../src/SqlAuditLogsStorage.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig } from \"@webiny/api-core-sql\";\nimport { AuditLogsStorage } from \"@webiny/api-audit-logs/abstractions.js\";\nimport { SqliteStorage } from \"~/SqliteStorage.js\";\nimport { createTableManager } from \"~/createTableManager.js\";\n\n/** The audit logs storage on the container's connection and table prefix. */\nclass SqlAuditLogsStorageImpl extends SqliteStorage implements AuditLogsStorage.Interface {\n public constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface) {\n const schemaManaged = schemaConfig?.isManaged() === true;\n super({\n knex: knex.client,\n tableManager: createTableManager(knex, schemaConfig, schemaManaged)\n });\n }\n}\n\nexport const SqlAuditLogsStorage = AuditLogsStorage.createImplementation({\n implementation: SqlAuditLogsStorageImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["SqlAuditLogsStorageImpl","SqliteStorage","knex","schemaConfig","schemaManaged","createTableManager","SqlAuditLogsStorage","AuditLogsStorage","KnexClient","SqlSchemaConfig"],"mappings":";;;;AAMA,MAAMA,gCAAgCC;IAClC,YAAmBC,IAA0B,EAAEC,YAAwC,CAAE;QACrF,MAAMC,gBAAgBD,cAAc,gBAAgB;QACpD,KAAK,CAAC;YACF,MAAMD,KAAK,MAAM;YACjB,cAAcG,mBAAmBH,MAAMC,cAAcC;QACzD;IACJ;AACJ;AAEO,MAAME,sBAAsBC,iBAAiB,oBAAoB,CAAC;IACrE,gBAAgBP;IAChB,cAAc;QAACQ;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
|
package/SqliteStorage.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { IStorage, IStorageFetchParams, IStorageFetchResult, IStorageStoreP
|
|
|
4
4
|
export declare class SqliteStorage implements IStorage {
|
|
5
5
|
private readonly knex;
|
|
6
6
|
private readonly tableManager;
|
|
7
|
+
private readonly ensureTable;
|
|
7
8
|
constructor(params: {
|
|
8
9
|
knex: Knex;
|
|
9
10
|
tableManager: TableManager;
|
|
@@ -11,5 +12,4 @@ export declare class SqliteStorage implements IStorage {
|
|
|
11
12
|
fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;
|
|
12
13
|
store(params: IStorageStoreParams): Promise<IStorageStoreResult>;
|
|
13
14
|
list(params: IStorageListParams): Promise<IStorageListResult>;
|
|
14
|
-
private ensureTable;
|
|
15
15
|
}
|
package/SqliteStorage.js
CHANGED
|
@@ -31,6 +31,20 @@ class SqliteStorage {
|
|
|
31
31
|
constructor(params){
|
|
32
32
|
this.knex = params.knex;
|
|
33
33
|
this.tableManager = params.tableManager;
|
|
34
|
+
this.ensureTable = params.tableManager.define(TABLE_NAME, (table)=>{
|
|
35
|
+
table.text("id").primary();
|
|
36
|
+
table.text("tenant").notNullable();
|
|
37
|
+
table.text("createdBy").notNullable();
|
|
38
|
+
table.datetime("createdOn").notNullable();
|
|
39
|
+
table.text("app").notNullable();
|
|
40
|
+
table.text("action").notNullable();
|
|
41
|
+
table.text("message").notNullable();
|
|
42
|
+
table.text("entity").notNullable();
|
|
43
|
+
table.text("entityId").notNullable();
|
|
44
|
+
table.text("tags").notNullable();
|
|
45
|
+
table.datetime("expiresAt").notNullable();
|
|
46
|
+
table.text("content").notNullable();
|
|
47
|
+
});
|
|
34
48
|
}
|
|
35
49
|
async fetch(params) {
|
|
36
50
|
await this.ensureTable();
|
|
@@ -114,22 +128,6 @@ class SqliteStorage {
|
|
|
114
128
|
};
|
|
115
129
|
}
|
|
116
130
|
}
|
|
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
131
|
}
|
|
134
132
|
export { SqliteStorage };
|
|
135
133
|
|
package/SqliteStorage.js.map
CHANGED
|
@@ -1 +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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oBACFmB;oBACAF;gBACJ;gBACA,SAAS;YACb;QACJ,EAAE,OAAOR,OAAO;YACZ,OAAO;gBACH,OAAOA;gBACP,SAAS;YACb;QACJ;IACJ;IAEA,MAAc,cAA6B;QACvC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAACX,YAAYuB,CAAAA;YACxCA,MAAM,IAAI,CAAC,MAAM,OAAO;YACxBA,MAAM,IAAI,CAAC,UAAU,WAAW;YAChCA,MAAM,IAAI,CAAC,aAAa,WAAW;YACnCA,MAAM,QAAQ,CAAC,aAAa,WAAW;YACvCA,MAAM,IAAI,CAAC,OAAO,WAAW;YAC7BA,MAAM,IAAI,CAAC,UAAU,WAAW;YAChCA,MAAM,IAAI,CAAC,WAAW,WAAW;YACjCA,MAAM,IAAI,CAAC,UAAU,WAAW;YAChCA,MAAM,IAAI,CAAC,YAAY,WAAW;YAClCA,MAAM,IAAI,CAAC,QAAQ,WAAW;YAC9BA,MAAM,QAAQ,CAAC,aAAa,WAAW;YACvCA,MAAM,IAAI,CAAC,WAAW,WAAW;QACrC;IACJ;AACJ"}
|
|
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 private readonly ensureTable: () => Promise<void>;\n\n public constructor(params: { knex: Knex; tableManager: TableManager }) {\n this.knex = params.knex;\n this.tableManager = params.tableManager;\n this.ensureTable = params.tableManager.define(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 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"],"names":["TABLE_NAME","toRow","data","JSON","fromRow","row","Date","SqliteStorage","params","table","Error","auditLog","error","existing","limit","query","entityPrefix","sortDirection","afterRow","rows","hasMoreItems","lastItem","after","undefined"],"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,CA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AO;YACZ,OAAO;gBACH,OAAOA;gBACP,SAAS;YACb;QACJ;IACJ;AACJ"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { KnexClient, SqlSchemaConfig } from "@webiny/api-core-sql";
|
|
2
|
+
import { TableManager } from "@webiny/api-core-sql/TableManager.js";
|
|
3
|
+
/** The audit logs' table manager, on the container's connection and table prefix. */
|
|
4
|
+
export declare const createTableManager: (knex: KnexClient.Interface, schemaConfig: SqlSchemaConfig.Interface | undefined, schemaManaged: boolean) => TableManager;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TableManager } from "@webiny/api-core-sql/TableManager.js";
|
|
2
|
+
const createTableManager = (knex, schemaConfig, schemaManaged)=>new TableManager(knex.client, schemaConfig?.tableNamePrefix, {
|
|
3
|
+
schemaManaged
|
|
4
|
+
});
|
|
5
|
+
export { createTableManager };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=createTableManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTableManager.js","sources":["../src/createTableManager.ts"],"sourcesContent":["import type { KnexClient, SqlSchemaConfig } from \"@webiny/api-core-sql\";\nimport { TableManager } from \"@webiny/api-core-sql/TableManager.js\";\n\n/** The audit logs' table manager, on the container's connection and table prefix. */\nexport const createTableManager = (\n knex: KnexClient.Interface,\n schemaConfig: SqlSchemaConfig.Interface | undefined,\n schemaManaged: boolean\n): TableManager => {\n return new TableManager(knex.client, schemaConfig?.tableNamePrefix, { schemaManaged });\n};\n"],"names":["createTableManager","knex","schemaConfig","schemaManaged","TableManager"],"mappings":";AAIO,MAAMA,qBAAqB,CAC9BC,MACAC,cACAC,gBAEO,IAAIC,aAAaH,KAAK,MAAM,EAAEC,cAAc,iBAAiB;QAAEC;IAAc"}
|
package/feature.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SQL audit logs storage and its `auditLogs` schema setup step. Registered per request, it runs
|
|
3
|
+
* on the connection (`KnexClient`) and the table settings (`SqlSchemaConfig`) the SQL storage keeps
|
|
4
|
+
* in the root.
|
|
5
|
+
*/
|
|
6
|
+
export declare const AuditLogsSqlFeature: {
|
|
7
|
+
name: string;
|
|
8
|
+
register(container: import("@webiny/di").Container): void;
|
|
9
|
+
};
|
|
10
|
+
/** `AuditLogsSqlFeature` as an extension plugin, for setups that register storages that way. */
|
|
11
|
+
export declare const registerAuditLogsSqlStorageOperations: () => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types").Context>;
|
package/feature.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { createRegisterExtensionPlugin } from "@webiny/handler";
|
|
3
|
+
import { SqlAuditLogsStorage } from "./SqlAuditLogsStorage.js";
|
|
4
|
+
import { AuditLogsSqlSchemaSetup } from "./AuditLogsSqlSchemaSetup.js";
|
|
5
|
+
const AuditLogsSqlFeature = createFeature({
|
|
6
|
+
name: "AuditLogsSql",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(SqlAuditLogsStorage);
|
|
9
|
+
container.register(AuditLogsSqlSchemaSetup);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const registerAuditLogsSqlStorageOperations = ()=>createRegisterExtensionPlugin((context)=>{
|
|
13
|
+
AuditLogsSqlFeature.register(context.container);
|
|
14
|
+
});
|
|
15
|
+
export { AuditLogsSqlFeature, registerAuditLogsSqlStorageOperations };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=feature.js.map
|
package/feature.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature.js","sources":["../src/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { SqlAuditLogsStorage } from \"~/SqlAuditLogsStorage.js\";\nimport { AuditLogsSqlSchemaSetup } from \"~/AuditLogsSqlSchemaSetup.js\";\n\n/**\n * The SQL audit logs storage and its `auditLogs` schema setup step. Registered per request, it runs\n * on the connection (`KnexClient`) and the table settings (`SqlSchemaConfig`) the SQL storage keeps\n * in the root.\n */\nexport const AuditLogsSqlFeature = createFeature({\n name: \"AuditLogsSql\",\n register(container) {\n container.register(SqlAuditLogsStorage);\n container.register(AuditLogsSqlSchemaSetup);\n }\n});\n\n/** `AuditLogsSqlFeature` as an extension plugin, for setups that register storages that way. */\nexport const registerAuditLogsSqlStorageOperations = () => {\n return createRegisterExtensionPlugin(context => {\n AuditLogsSqlFeature.register(context.container);\n });\n};\n"],"names":["AuditLogsSqlFeature","createFeature","container","SqlAuditLogsStorage","AuditLogsSqlSchemaSetup","registerAuditLogsSqlStorageOperations","createRegisterExtensionPlugin","context"],"mappings":";;;;AAUO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ;AAGO,MAAMC,wCAAwC,IAC1CC,8BAA8BC,CAAAA;QACjCP,oBAAoB,QAAQ,CAACO,QAAQ,SAAS;IAClD"}
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
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 {};
|
|
1
|
+
export { AuditLogsSqlFeature, registerAuditLogsSqlStorageOperations } from "./feature.js";
|
package/index.js
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
export { AuditLogsSqlFeature, registerAuditLogsSqlStorageOperations } from "./feature.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-audit-logs-sql",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.3fddf667ea",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-audit-logs",
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
"./*": "./*"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@webiny/api-audit-logs": "0.0.0-unstable.
|
|
24
|
-
"@webiny/api-core-sql": "0.0.0-unstable.
|
|
25
|
-
"@webiny/
|
|
23
|
+
"@webiny/api-audit-logs": "0.0.0-unstable.3fddf667ea",
|
|
24
|
+
"@webiny/api-core-sql": "0.0.0-unstable.3fddf667ea",
|
|
25
|
+
"@webiny/feature": "0.0.0-unstable.3fddf667ea",
|
|
26
|
+
"@webiny/handler": "0.0.0-unstable.3fddf667ea",
|
|
26
27
|
"knex": "3.3.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
30
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
30
|
+
"@webiny/api-core": "0.0.0-unstable.3fddf667ea",
|
|
31
|
+
"@webiny/build-tools": "0.0.0-unstable.3fddf667ea",
|
|
31
32
|
"better-sqlite3": "13.0.3",
|
|
32
33
|
"rimraf": "6.1.3",
|
|
33
34
|
"typescript": "7.0.2"
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|