@webiny/api-audit-logs-sql 0.0.0-unstable.33e4fd9647 → 0.0.0-unstable.48a4e5b6c1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,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,35 @@
1
+ import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
2
+ import { tenantNeutralScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
3
+ import { SqliteStorage } from "./SqliteStorage.js";
4
+ import { createTableManager } from "./createTableManager.js";
5
+ class AuditLogsSqlSchemaSetupImpl {
6
+ constructor(knex, schemaConfig){
7
+ this.knex = knex;
8
+ this.schemaConfig = schemaConfig;
9
+ this.name = "auditLogs";
10
+ }
11
+ async setup() {
12
+ const tableManager = createTableManager(this.knex, this.schemaConfig, false);
13
+ new SqliteStorage({
14
+ knex: this.knex.client,
15
+ tableManager,
16
+ scopeTenant: tenantNeutralScopeTenant
17
+ });
18
+ await tableManager.setup();
19
+ }
20
+ }
21
+ const AuditLogsSqlSchemaSetup = SqlSchemaSetup.createImplementation({
22
+ implementation: AuditLogsSqlSchemaSetupImpl,
23
+ dependencies: [
24
+ KnexClient,
25
+ [
26
+ SqlSchemaConfig,
27
+ {
28
+ optional: true
29
+ }
30
+ ]
31
+ ]
32
+ });
33
+ export { AuditLogsSqlSchemaSetup };
34
+
35
+ //# 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 { tenantNeutralScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\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({\n knex: this.knex.client,\n tableManager,\n // The setup runs in no tenant, and only declares the table.\n scopeTenant: tenantNeutralScopeTenant\n });\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","tenantNeutralScopeTenant","AuditLogsSqlSchemaSetup","SqlSchemaSetup","KnexClient","SqlSchemaConfig"],"mappings":";;;;AAMA,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;YACd,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;YACtBF;YAEA,aAAaG;QACjB;QACA,MAAMH,aAAa,KAAK;IAC5B;AACJ;AAEO,MAAMI,0BAA0BC,eAAe,oBAAoB,CAAC;IACvE,gBAAgBR;IAChB,cAAc;QAACS;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
@@ -0,0 +1,12 @@
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 { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
5
+ /** The audit logs storage on the container's connection and table prefix, for its scope's tenant. */
6
+ declare class SqlAuditLogsStorageImpl extends SqliteStorage implements AuditLogsStorage.Interface {
7
+ constructor(knex: KnexClient.Interface, scopeTenant: ScopeTenant.Interface, schemaConfig?: SqlSchemaConfig.Interface);
8
+ }
9
+ export declare const SqlAuditLogsStorage: typeof SqlAuditLogsStorageImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-audit-logs/storage/abstractions/Storage").IStorage>;
11
+ };
12
+ export {};
@@ -0,0 +1,31 @@
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
+ import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
6
+ class SqlAuditLogsStorageImpl extends SqliteStorage {
7
+ constructor(knex, scopeTenant, schemaConfig){
8
+ const schemaManaged = schemaConfig?.isManaged() === true;
9
+ super({
10
+ knex: knex.client,
11
+ scopeTenant,
12
+ tableManager: createTableManager(knex, schemaConfig, schemaManaged)
13
+ });
14
+ }
15
+ }
16
+ const SqlAuditLogsStorage = AuditLogsStorage.createImplementation({
17
+ implementation: SqlAuditLogsStorageImpl,
18
+ dependencies: [
19
+ KnexClient,
20
+ ScopeTenant,
21
+ [
22
+ SqlSchemaConfig,
23
+ {
24
+ optional: true
25
+ }
26
+ ]
27
+ ]
28
+ });
29
+ export { SqlAuditLogsStorage };
30
+
31
+ //# 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\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\n/** The audit logs storage on the container's connection and table prefix, for its scope's tenant. */\nclass SqlAuditLogsStorageImpl extends SqliteStorage implements AuditLogsStorage.Interface {\n public constructor(\n knex: KnexClient.Interface,\n scopeTenant: ScopeTenant.Interface,\n schemaConfig?: SqlSchemaConfig.Interface\n ) {\n const schemaManaged = schemaConfig?.isManaged() === true;\n super({\n knex: knex.client,\n scopeTenant,\n tableManager: createTableManager(knex, schemaConfig, schemaManaged)\n });\n }\n}\n\nexport const SqlAuditLogsStorage = AuditLogsStorage.createImplementation({\n implementation: SqlAuditLogsStorageImpl,\n dependencies: [KnexClient, ScopeTenant, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["SqlAuditLogsStorageImpl","SqliteStorage","knex","scopeTenant","schemaConfig","schemaManaged","createTableManager","SqlAuditLogsStorage","AuditLogsStorage","KnexClient","ScopeTenant","SqlSchemaConfig"],"mappings":";;;;;AAOA,MAAMA,gCAAgCC;IAClC,YACIC,IAA0B,EAC1BC,WAAkC,EAClCC,YAAwC,CAC1C;QACE,MAAMC,gBAAgBD,cAAc,gBAAgB;QACpD,KAAK,CAAC;YACF,MAAMF,KAAK,MAAM;YACjBC;YACA,cAAcG,mBAAmBJ,MAAME,cAAcC;QACzD;IACJ;AACJ;AAEO,MAAME,sBAAsBC,iBAAiB,oBAAoB,CAAC;IACrE,gBAAgBR;IAChB,cAAc;QAACS;QAAYC;QAAa;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAClF"}
@@ -1,15 +1,19 @@
1
1
  import type { Knex } from "knex";
2
+ import type { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
2
3
  import type { TableManager } from "@webiny/api-core-sql/TableManager.js";
3
4
  import type { IStorage, IStorageFetchParams, IStorageFetchResult, IStorageStoreParams, IStorageStoreResult, IStorageListParams, IStorageListResult } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
4
5
  export declare class SqliteStorage implements IStorage {
5
6
  private readonly knex;
6
7
  private readonly tableManager;
8
+ private readonly ensureTable;
9
+ private readonly scopeTenant;
7
10
  constructor(params: {
8
11
  knex: Knex;
9
12
  tableManager: TableManager;
13
+ /** The tenant the storage acts on: its tenant scope's. The schema setup runs without one. */
14
+ scopeTenant: ScopeTenant.Interface;
10
15
  });
11
16
  fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;
12
17
  store(params: IStorageStoreParams): Promise<IStorageStoreResult>;
13
18
  list(params: IStorageListParams): Promise<IStorageListResult>;
14
- private ensureTable;
15
19
  }
package/SqliteStorage.js CHANGED
@@ -31,11 +31,26 @@ class SqliteStorage {
31
31
  constructor(params){
32
32
  this.knex = params.knex;
33
33
  this.tableManager = params.tableManager;
34
+ this.scopeTenant = params.scopeTenant;
35
+ this.ensureTable = params.tableManager.define(TABLE_NAME, (table)=>{
36
+ table.text("id").primary();
37
+ table.text("tenant").notNullable();
38
+ table.text("createdBy").notNullable();
39
+ table.datetime("createdOn").notNullable();
40
+ table.text("app").notNullable();
41
+ table.text("action").notNullable();
42
+ table.text("message").notNullable();
43
+ table.text("entity").notNullable();
44
+ table.text("entityId").notNullable();
45
+ table.text("tags").notNullable();
46
+ table.datetime("expiresAt").notNullable();
47
+ table.text("content").notNullable();
48
+ });
34
49
  }
35
50
  async fetch(params) {
36
51
  await this.ensureTable();
37
52
  try {
38
- const row = await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.id).andWhere("tenant", params.tenant).first();
53
+ const row = await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.id).andWhere("tenant", this.scopeTenant.getId()).first();
39
54
  if (!row) return {
40
55
  error: new Error(`Audit log with id "${params.id}" not found.`),
41
56
  success: false
@@ -55,12 +70,19 @@ class SqliteStorage {
55
70
  async store(params) {
56
71
  await this.ensureTable();
57
72
  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);
73
+ const tenant = this.scopeTenant.getId();
74
+ const row = toRow({
75
+ ...params.data,
76
+ tenant
77
+ });
78
+ const existing = await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.data.id).andWhere("tenant", tenant).first();
79
+ if (existing) await this.knex(this.tableManager.resolve(TABLE_NAME)).where("id", params.data.id).andWhere("tenant", tenant).update(row);
61
80
  else await this.knex(this.tableManager.resolve(TABLE_NAME)).insert(row);
62
81
  return {
63
- data: params.data,
82
+ data: {
83
+ ...params.data,
84
+ tenant
85
+ },
64
86
  success: true
65
87
  };
66
88
  } catch (error) {
@@ -74,7 +96,7 @@ class SqliteStorage {
74
96
  await this.ensureTable();
75
97
  try {
76
98
  const limit = params.limit || 100;
77
- const query = this.knex(this.tableManager.resolve(TABLE_NAME)).where("tenant", params.tenant);
99
+ const query = this.knex(this.tableManager.resolve(TABLE_NAME)).where("tenant", this.scopeTenant.getId());
78
100
  if (params.app) query.andWhere("app", params.app);
79
101
  if (params.entity) query.andWhere("entity", params.entity);
80
102
  if (params.action) query.andWhere("action", params.action);
@@ -114,22 +136,6 @@ class SqliteStorage {
114
136
  };
115
137
  }
116
138
  }
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
139
  }
134
140
  export { SqliteStorage };
135
141
 
@@ -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,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;IACxB;AAGG,MAAME;IAIT,YAAmBC,MAAkD,CAAE;QACnE,IAAI,CAAC,IAAI,GAAGA,OAAO,IAAI;QACvB,IAAI,CAAC,YAAY,GAAGA,OAAO,YAAY;IAC3C;IAEA,MAAa,MAAMA,MAA2B,EAAgC;QAC1E,M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G,SAAS,SAAS;qBAEnDH,MAAM,QAAQ,CAAC,aAAa,KAAKG,SAAS,SAAS;YAG/D;YAEA,MAAMC,OAAO,MAAMJ;YAEnB,MAAMK,eAAeD,KAAK,MAAM,GAAGL;YAEnC,IAAIM,cACAD,KAAK,GAAG;YAGZ,MAAMhB,OAAOgB,KAAK,GAAG,CAACd;YAEtB,MAAMgB,WAAWlB,IAAI,CAACA,KAAK,MAAM,GAAG,EAAE;YACtC,MAAMmB,QAAQF,gBAAgBC,WAAWA,SAAS,EAAE,GAAGE;YAEvD,OAAO;gBACHpB;gBACA,MAAM;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 { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\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 private readonly scopeTenant: ScopeTenant.Interface;\n\n public constructor(params: {\n knex: Knex;\n tableManager: TableManager;\n /** The tenant the storage acts on: its tenant scope's. The schema setup runs without one. */\n scopeTenant: ScopeTenant.Interface;\n }) {\n this.knex = params.knex;\n this.tableManager = params.tableManager;\n this.scopeTenant = params.scopeTenant;\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\", this.scopeTenant.getId())\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 // Stored with its scope's tenant, whatever tenant it carries.\n const tenant = this.scopeTenant.getId();\n const row = toRow({ ...params.data, tenant });\n\n const existing = await this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME))\n .where(\"id\", params.data.id)\n .andWhere(\"tenant\", tenant)\n .first();\n\n if (existing) {\n await this.knex<AuditLogRow>(this.tableManager.resolve(TABLE_NAME))\n .where(\"id\", params.data.id)\n .andWhere(\"tenant\", tenant)\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, tenant },\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 this.scopeTenant.getId()\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","tenant","existing","limit","query","entityPrefix","sortDirection","afterRow","rows","hasMoreItems","lastItem","after","undefined"],"mappings":"AA6BA,MAAMA,aAAa;AAGnB,MAAMC,QAAQ,CAACC,OAC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,CAAC,WAAW;YAGtE,IAAI,mBAAmBA,UAAUA,OAAO,aAAa,EACjDQ,MAAM,QAAQ,CAAC,aAAa,MAAMR,OAAO,aAAa,CAAC,WAAW;YAGtE,MAAMU,gBAAgBV,AAAgB,WAAhBA,OAAO,IAAI,GAAc,SAAS;YAExDQ,MAAM,OAAO,CAAC,aAAaE;YAG3BF,MAAM,KAAK,CAACD,QAAQ;YAEpB,IAAIP,OAAO,KAAK,EAAE;gBACd,MAAMW,WAAW,MAAM,IAAI,CAAC,IAAI,CAAc,IAAI,CAAC,YAAY,CAAC,OAAO,CAACnB,aACnE,KAAK,CAAC,MAAMQ,OAAO,KAAK,EACxB,KAAK;gBAEV,IAAIW,UACA,IAAID,AAAkB,UAAlBA,eACAF,MAAM,QAAQ,CAAC,aAAa,KAAKG,SAAS,SAAS;qBAEnDH,MAAM,QAAQ,CAAC,aAAa,KAAKG,SAAS,SAAS;YAG/D;YAEA,MAAMC,OAAO,MAAMJ;YAEnB,MAAMK,eAAeD,KAAK,MAAM,GAAGL;YAEnC,IAAIM,cACAD,KAAK,GAAG;YAGZ,MAAMlB,OAAOkB,KAAK,GAAG,CAAChB;YAEtB,MAAMkB,WAAWpB,IAAI,CAACA,KAAK,MAAM,GAAG,EAAE;YACtC,MAAMqB,QAAQF,gBAAgBC,WAAWA,SAAS,EAAE,GAAGE;YAEvD,OAAO;gBACHtB;gBACA,MAAM;oBACFqB;oBACAF;gBACJ;gBACA,SAAS;YACb;QACJ,EAAE,OAAOT,OAAO;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
- 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 {};
1
+ export { AuditLogsSqlFeature, registerAuditLogsSqlStorageOperations } from "./feature.js";
package/index.js CHANGED
@@ -1,15 +1 @@
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
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.33e4fd9647",
3
+ "version": "0.0.0-unstable.48a4e5b6c1",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "@webiny/api-audit-logs",
@@ -20,16 +20,17 @@
20
20
  "./*": "./*"
21
21
  },
22
22
  "dependencies": {
23
- "@webiny/api-audit-logs": "0.0.0-unstable.33e4fd9647",
24
- "@webiny/api-core-sql": "0.0.0-unstable.33e4fd9647",
25
- "@webiny/handler": "0.0.0-unstable.33e4fd9647",
23
+ "@webiny/api-audit-logs": "0.0.0-unstable.48a4e5b6c1",
24
+ "@webiny/api-core": "0.0.0-unstable.48a4e5b6c1",
25
+ "@webiny/api-core-sql": "0.0.0-unstable.48a4e5b6c1",
26
+ "@webiny/feature": "0.0.0-unstable.48a4e5b6c1",
27
+ "@webiny/handler": "0.0.0-unstable.48a4e5b6c1",
26
28
  "knex": "3.3.0"
27
29
  },
28
30
  "devDependencies": {
29
- "@webiny/api-core": "0.0.0-unstable.33e4fd9647",
30
- "@webiny/build-tools": "0.0.0-unstable.33e4fd9647",
31
- "better-sqlite3": "13.0.3",
32
- "rimraf": "6.1.3",
31
+ "@webiny/build-tools": "0.0.0-unstable.48a4e5b6c1",
32
+ "better-sqlite3": "13.2.0",
33
+ "rimraf": "6.1.4",
33
34
  "typescript": "7.0.2"
34
35
  },
35
36
  "publishConfig": {
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"}