@webiny/api-audit-logs 6.5.0-beta.3 → 6.5.0-beta.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.
@@ -105,7 +105,7 @@ class AuditLogsContextValueImpl {
105
105
  for (const permission of permissions){
106
106
  if ("*" === permission.name) return;
107
107
  if ("al.*" === permission.name) return;
108
- if (permission.name === `al.${auditLog.action}`) return;
108
+ else if (permission.name === `al.${auditLog.action}`) return;
109
109
  }
110
110
  throw new NotAuthorizedError({
111
111
  message: "You cannot access audit logs."
@@ -1 +1 @@
1
- {"version":3,"file":"context/AuditLogsContextValue.js","sources":["../../src/context/AuditLogsContextValue.ts"],"sourcesContent":["import type {\n AuditLogPayload,\n AuditLogsContext,\n AuditLogsContextValue,\n IListAuditLogsParams,\n IListAuditLogsResult\n} from \"~/types.js\";\nimport { convertExpiresAtDaysToDate } from \"~/utils/expiresAt.js\";\nimport type { IAuditLog, IAuditLogCreatedBy } from \"~/storage/types.js\";\nimport { mdbid } from \"@webiny/utils/mdbid.js\";\nimport type { IStorage, IStorageListParams } from \"~/storage/abstractions/Storage.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport type { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n AuditLogBeforeCreateEvent,\n AuditLogAfterCreateEvent,\n AuditLogBeforeUpdateEvent,\n AuditLogAfterUpdateEvent\n} from \"~/events/index.js\";\n\nexport interface IAuditLogsContextValueParams {\n getContext: () => AuditLogsContext;\n deleteLogsAfterDays: number;\n storage: IStorage;\n eventPublisher: EventPublisher.Interface;\n}\n\nclass AuditLogsContextValueImpl implements AuditLogsContextValue {\n private readonly getContext;\n public readonly deleteLogsAfterDays;\n private readonly storage: IStorage;\n private readonly eventPublisher: EventPublisher.Interface;\n\n public constructor(params: IAuditLogsContextValueParams) {\n this.getContext = params.getContext;\n this.deleteLogsAfterDays = params.deleteLogsAfterDays;\n this.storage = params.storage;\n this.eventPublisher = params.eventPublisher;\n }\n\n public async createAuditLog(payload: AuditLogPayload): Promise<IAuditLog> {\n const context = this.getContext();\n const expiresAt = convertExpiresAtDaysToDate(this.deleteLogsAfterDays);\n\n const auditLog: IAuditLog = {\n id: mdbid(),\n tenant: this.getTenantId(),\n createdBy: this.getIdentity(),\n createdOn: new Date(),\n ...payload,\n content: JSON.stringify(payload.content),\n expiresAt\n };\n await this.checkPermissions(auditLog);\n\n const beforeCreateEvent = new AuditLogBeforeCreateEvent({\n auditLog: auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeCreateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterCreateEvent = new AuditLogAfterCreateEvent({\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterCreateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async updateAuditLog(\n original: IAuditLog,\n payload: Partial<AuditLogPayload>\n ): Promise<IAuditLog> {\n const context = this.getContext();\n const auditLog: IAuditLog = {\n ...original,\n ...payload,\n content: payload.content ? JSON.stringify(payload.content) : original.content\n };\n await this.checkPermissions(auditLog);\n\n const beforeUpdateEvent = new AuditLogBeforeUpdateEvent({\n original,\n auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeUpdateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterUpdateEvent = new AuditLogAfterUpdateEvent({\n original: original,\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterUpdateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async getAuditLog(id: string): Promise<IAuditLog | null> {\n const result = await this.storage.fetch({\n id,\n tenant: this.getTenantId()\n });\n if (result.success) {\n await this.checkPermissions(result.data);\n return result.data;\n }\n throw result.error;\n }\n\n public async listAuditLogs(params: IListAuditLogsParams): Promise<IListAuditLogsResult> {\n const result = await this.storage.list({\n ...params,\n tenant: this.getTenantId()\n } as unknown as IStorageListParams);\n if (result.success) {\n return {\n items: result.data,\n meta: {\n cursor: result.meta.after || null,\n hasMoreItems: result.meta.hasMoreItems\n }\n };\n }\n throw result.error;\n }\n\n private async checkPermissions(auditLog: Pick<IAuditLog, \"action\">): Promise<void> {\n if (!auditLog.action) {\n throw new Error(\"Audit log action is not defined. Cannot check permissions.\");\n }\n const permissions = await this.getContext().security.getPermissions(\"al.*\");\n for (const permission of permissions) {\n if (permission.name === \"*\") {\n return;\n }\n if (permission.name === \"al.*\") {\n return;\n } else if (permission.name === `al.${auditLog.action}`) {\n return;\n }\n }\n\n throw new NotAuthorizedError({\n message: \"You cannot access audit logs.\"\n });\n }\n\n private getTenantId(): string {\n return this.getContext().tenancy.getCurrentTenant().id;\n }\n\n private getIdentity(): IAuditLogCreatedBy {\n const identity = this.getContext().security.getIdentity();\n return {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName || \"unknown\"\n };\n }\n}\n\nexport const createAuditLogsContextValue = (\n params: IAuditLogsContextValueParams\n): AuditLogsContextValue => {\n return new AuditLogsContextValueImpl(params);\n};\n"],"names":["AuditLogsContextValueImpl","params","payload","context","expiresAt","convertExpiresAtDaysToDate","auditLog","mdbid","Date","JSON","beforeCreateEvent","AuditLogBeforeCreateEvent","input","Object","result","afterCreateEvent","AuditLogAfterCreateEvent","original","beforeUpdateEvent","AuditLogBeforeUpdateEvent","afterUpdateEvent","AuditLogAfterUpdateEvent","id","Error","permissions","permission","NotAuthorizedError","identity","createAuditLogsContextValue"],"mappings":";;;;AA2BA,MAAMA;IAMF,YAAmBC,MAAoC,CAAE;QACrD,IAAI,CAAC,UAAU,GAAGA,OAAO,UAAU;QACnC,IAAI,CAAC,mBAAmB,GAAGA,OAAO,mBAAmB;QACrD,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,cAAc,GAAGA,OAAO,cAAc;IAC/C;IAEA,MAAa,eAAeC,OAAwB,EAAsB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C,GAAG,EAAEnB,SAAS,MAAM,EAAE,EAClD;QAER;QAEA,MAAM,IAAIoB,mBAAmB;YACzB,SAAS;QACb;IACJ;IAEQ,cAAsB;QAC1B,OAAO,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,gBAAgB,GAAG,EAAE;IAC1D;IAEQ,cAAkC;QACtC,MAAMC,WAAW,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,WAAW;QACvD,OAAO;YACH,IAAIA,SAAS,EAAE;YACf,MAAMA,SAAS,IAAI;YACnB,aAAaA,SAAS,WAAW,IAAI;QACzC;IACJ;AACJ;AAEO,MAAMC,8BAA8B,CACvC3B,SAEO,IAAID,0BAA0BC"}
1
+ {"version":3,"file":"context/AuditLogsContextValue.js","sources":["../../src/context/AuditLogsContextValue.ts"],"sourcesContent":["import type {\n AuditLogPayload,\n AuditLogsContext,\n AuditLogsContextValue,\n IListAuditLogsParams,\n IListAuditLogsResult\n} from \"~/types.js\";\nimport { convertExpiresAtDaysToDate } from \"~/utils/expiresAt.js\";\nimport type { IAuditLog, IAuditLogCreatedBy } from \"~/storage/types.js\";\nimport { mdbid } from \"@webiny/utils/mdbid.js\";\nimport type { IStorage, IStorageListParams } from \"~/storage/abstractions/Storage.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport type { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n AuditLogBeforeCreateEvent,\n AuditLogAfterCreateEvent,\n AuditLogBeforeUpdateEvent,\n AuditLogAfterUpdateEvent\n} from \"~/events/index.js\";\n\nexport interface IAuditLogsContextValueParams {\n getContext: () => AuditLogsContext;\n deleteLogsAfterDays: number;\n storage: IStorage;\n eventPublisher: EventPublisher.Interface;\n}\n\nclass AuditLogsContextValueImpl implements AuditLogsContextValue {\n private readonly getContext;\n public readonly deleteLogsAfterDays;\n private readonly storage: IStorage;\n private readonly eventPublisher: EventPublisher.Interface;\n\n public constructor(params: IAuditLogsContextValueParams) {\n this.getContext = params.getContext;\n this.deleteLogsAfterDays = params.deleteLogsAfterDays;\n this.storage = params.storage;\n this.eventPublisher = params.eventPublisher;\n }\n\n public async createAuditLog(payload: AuditLogPayload): Promise<IAuditLog> {\n const context = this.getContext();\n const expiresAt = convertExpiresAtDaysToDate(this.deleteLogsAfterDays);\n\n const auditLog: IAuditLog = {\n id: mdbid(),\n tenant: this.getTenantId(),\n createdBy: this.getIdentity(),\n createdOn: new Date(),\n ...payload,\n content: JSON.stringify(payload.content),\n expiresAt\n };\n await this.checkPermissions(auditLog);\n\n const beforeCreateEvent = new AuditLogBeforeCreateEvent({\n auditLog: auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeCreateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterCreateEvent = new AuditLogAfterCreateEvent({\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterCreateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async updateAuditLog(\n original: IAuditLog,\n payload: Partial<AuditLogPayload>\n ): Promise<IAuditLog> {\n const context = this.getContext();\n const auditLog: IAuditLog = {\n ...original,\n ...payload,\n content: payload.content ? JSON.stringify(payload.content) : original.content\n };\n await this.checkPermissions(auditLog);\n\n const beforeUpdateEvent = new AuditLogBeforeUpdateEvent({\n original,\n auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeUpdateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterUpdateEvent = new AuditLogAfterUpdateEvent({\n original: original,\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterUpdateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async getAuditLog(id: string): Promise<IAuditLog | null> {\n const result = await this.storage.fetch({\n id,\n tenant: this.getTenantId()\n });\n if (result.success) {\n await this.checkPermissions(result.data);\n return result.data;\n }\n throw result.error;\n }\n\n public async listAuditLogs(params: IListAuditLogsParams): Promise<IListAuditLogsResult> {\n const result = await this.storage.list({\n ...params,\n tenant: this.getTenantId()\n } as unknown as IStorageListParams);\n if (result.success) {\n return {\n items: result.data,\n meta: {\n cursor: result.meta.after || null,\n hasMoreItems: result.meta.hasMoreItems\n }\n };\n }\n throw result.error;\n }\n\n private async checkPermissions(auditLog: Pick<IAuditLog, \"action\">): Promise<void> {\n if (!auditLog.action) {\n throw new Error(\"Audit log action is not defined. Cannot check permissions.\");\n }\n const permissions = await this.getContext().security.getPermissions(\"al.*\");\n for (const permission of permissions) {\n if (permission.name === \"*\") {\n return;\n }\n if (permission.name === \"al.*\") {\n return;\n } else if (permission.name === `al.${auditLog.action}`) {\n return;\n }\n }\n\n throw new NotAuthorizedError({\n message: \"You cannot access audit logs.\"\n });\n }\n\n private getTenantId(): string {\n return this.getContext().tenancy.getCurrentTenant().id;\n }\n\n private getIdentity(): IAuditLogCreatedBy {\n const identity = this.getContext().security.getIdentity();\n return {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName || \"unknown\"\n };\n }\n}\n\nexport const createAuditLogsContextValue = (\n params: IAuditLogsContextValueParams\n): AuditLogsContextValue => {\n return new AuditLogsContextValueImpl(params);\n};\n"],"names":["AuditLogsContextValueImpl","params","payload","context","expiresAt","convertExpiresAtDaysToDate","auditLog","mdbid","Date","JSON","beforeCreateEvent","AuditLogBeforeCreateEvent","input","Object","result","afterCreateEvent","AuditLogAfterCreateEvent","original","beforeUpdateEvent","AuditLogBeforeUpdateEvent","afterUpdateEvent","AuditLogAfterUpdateEvent","id","Error","permissions","permission","NotAuthorizedError","identity","createAuditLogsContextValue"],"mappings":";;;;AA2BA,MAAMA;IAMF,YAAmBC,MAAoC,CAAE;QACrD,IAAI,CAAC,UAAU,GAAGA,OAAO,UAAU;QACnC,IAAI,CAAC,mBAAmB,GAAGA,OAAO,mBAAmB;QACrD,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,c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AAoB,WAApBA,WAAW,IAAI,EACf;iBACG,IAAIA,WAAW,IAAI,KAAK,CAAC,GAAG,EAAEnB,SAAS,MAAM,EAAE,EAClD;QAER;QAEA,MAAM,IAAIoB,mBAAmB;YACzB,SAAS;QACb;IACJ;IAEQ,cAAsB;QAC1B,OAAO,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,gBAAgB,GAAG,EAAE;IAC1D;IAEQ,cAAkC;QACtC,MAAMC,WAAW,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,WAAW;QACvD,OAAO;YACH,IAAIA,SAAS,EAAE;YACf,MAAMA,SAAS,IAAI;YACnB,aAAaA,SAAS,WAAW,IAAI;QACzC;IACJ;AACJ;AAEO,MAAMC,8BAA8B,CACvC3B,SAEO,IAAID,0BAA0BC"}
@@ -7,8 +7,8 @@ export declare const listValidationSchema: zod.ZodObject<{
7
7
  app: zod.ZodOptional<zod.ZodString>;
8
8
  entity: zod.ZodOptional<zod.ZodString>;
9
9
  entityId: zod.ZodOptional<zod.ZodString>;
10
- createdOn_gte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
11
- createdOn_lte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
10
+ createdOn_gte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>, unknown>;
11
+ createdOn_lte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>, unknown>;
12
12
  createdBy: zod.ZodOptional<zod.ZodString>;
13
13
  action: zod.ZodOptional<zod.ZodString>;
14
14
  }, zod.core.$strip>;
@@ -17,5 +17,5 @@ export declare const listValidationSchema: zod.ZodObject<{
17
17
  ASC: "ASC";
18
18
  DESC: "DESC";
19
19
  }>>;
20
- limit: zod.ZodDefault<zod.ZodPreprocess<zod.ZodOptional<zod.ZodNumber>>>;
20
+ limit: zod.ZodDefault<zod.ZodPreprocess<zod.ZodOptional<zod.ZodNumber>, unknown>>;
21
21
  }, zod.core.$strip>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-audit-logs",
3
- "version": "6.5.0-beta.3",
3
+ "version": "6.5.0-beta.5",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./*": "./*"
@@ -22,31 +22,31 @@
22
22
  "access": "public"
23
23
  },
24
24
  "devDependencies": {
25
- "@webiny/handler-aws": "6.5.0-beta.3",
26
- "@webiny/plugins": "6.5.0-beta.3",
27
- "@webiny/project-utils": "6.5.0-beta.3",
25
+ "@webiny/handler-aws": "6.5.0-beta.5",
26
+ "@webiny/plugins": "6.5.0-beta.5",
27
+ "@webiny/project-utils": "6.5.0-beta.5",
28
28
  "graphql": "16.14.2",
29
29
  "typescript": "7.0.2",
30
- "vitest": "4.1.10"
30
+ "vitest": "5.0.2"
31
31
  },
32
32
  "dependencies": {
33
- "@webiny/api": "6.5.0-beta.3",
34
- "@webiny/api-aco": "6.5.0-beta.3",
35
- "@webiny/api-core": "6.5.0-beta.3",
36
- "@webiny/api-file-manager": "6.5.0-beta.3",
37
- "@webiny/api-headless-cms": "6.5.0-beta.3",
38
- "@webiny/api-mailer": "6.5.0-beta.3",
39
- "@webiny/api-website-builder": "6.5.0-beta.3",
40
- "@webiny/build-tools": "6.5.0-beta.3",
41
- "@webiny/common-audit-logs": "6.5.0-beta.3",
42
- "@webiny/error": "6.5.0-beta.3",
43
- "@webiny/feature": "6.5.0-beta.3",
44
- "@webiny/handler": "6.5.0-beta.3",
45
- "@webiny/handler-db": "6.5.0-beta.3",
46
- "@webiny/handler-graphql": "6.5.0-beta.3",
47
- "@webiny/utils": "6.5.0-beta.3",
48
- "@webiny/wcp": "6.5.0-beta.3",
49
- "zod": "4.4.3"
33
+ "@webiny/api": "6.5.0-beta.5",
34
+ "@webiny/api-aco": "6.5.0-beta.5",
35
+ "@webiny/api-core": "6.5.0-beta.5",
36
+ "@webiny/api-file-manager": "6.5.0-beta.5",
37
+ "@webiny/api-headless-cms": "6.5.0-beta.5",
38
+ "@webiny/api-mailer": "6.5.0-beta.5",
39
+ "@webiny/api-website-builder": "6.5.0-beta.5",
40
+ "@webiny/build-tools": "6.5.0-beta.5",
41
+ "@webiny/common-audit-logs": "6.5.0-beta.5",
42
+ "@webiny/error": "6.5.0-beta.5",
43
+ "@webiny/feature": "6.5.0-beta.5",
44
+ "@webiny/handler": "6.5.0-beta.5",
45
+ "@webiny/handler-db": "6.5.0-beta.5",
46
+ "@webiny/handler-graphql": "6.5.0-beta.5",
47
+ "@webiny/utils": "6.5.0-beta.5",
48
+ "@webiny/wcp": "6.5.0-beta.5",
49
+ "zod": "4.6.5"
50
50
  },
51
51
  "webiny": {
52
52
  "publishFrom": "dist"
@@ -10,15 +10,18 @@ class AuditLogFolderAfterDeleteHandlerImpl {
10
10
  async handle(event) {
11
11
  try {
12
12
  const { folder } = event.payload;
13
- if ("PbPage" === folder.type) {
14
- const createAuditLog = getAuditConfig(AUDIT.PAGE_BUILDER.PAGE_FOLDER.DELETE);
15
- await createAuditLog("Folder deleted", folder, folder.id, this.context);
16
- } else if ("FmFile" === folder.type) {
13
+ if ("FmFile" === folder.type) {
17
14
  const createAuditLog = getAuditConfig(AUDIT.FILE_MANAGER.FILE_FOLDER.DELETE);
18
15
  await createAuditLog("Folder deleted", folder, folder.id, this.context);
19
16
  } else if (folder.type.startsWith("cms:")) {
20
17
  const createAuditLog = getAuditConfig(AUDIT.HEADLESS_CMS.MODEL_FOLDER.DELETE);
21
18
  await createAuditLog("Folder deleted", folder, folder.id, this.context);
19
+ } else if ("wb:page" === folder.type) {
20
+ const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.PAGE_FOLDER.DELETE);
21
+ await createAuditLog("Folder deleted", folder, folder.id, this.context);
22
+ } else if ("wb:redirect" === folder.type) {
23
+ const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.REDIRECT_FOLDER.DELETE);
24
+ await createAuditLog("Folder deleted", folder, folder.id, this.context);
22
25
  }
23
26
  } catch (error) {
24
27
  throw _webiny_error.from(error, {
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js","sources":["../../../../src/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FolderAfterDeleteEventHandler } from \"@webiny/api-aco/features/folder/DeleteFolder/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\n\nclass AuditLogFolderAfterDeleteHandlerImpl implements FolderAfterDeleteEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: FolderAfterDeleteEventHandler.Event): Promise<void> {\n try {\n const { folder } = event.payload;\n if (folder.type === \"PbPage\") {\n const createAuditLog = getAuditConfig(AUDIT.PAGE_BUILDER.PAGE_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n } else if (folder.type === \"FmFile\") {\n const createAuditLog = getAuditConfig(AUDIT.FILE_MANAGER.FILE_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n } else if (folder.type.startsWith(\"cms:\")) {\n const createAuditLog = getAuditConfig(AUDIT.HEADLESS_CMS.MODEL_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing AuditLogFolderAfterDeleteHandler\",\n code: \"AUDIT_LOGS_AFTER_FOLDER_DELETE_HANDLER\"\n });\n }\n }\n}\n\nexport const AuditLogFolderAfterDeleteHandler = FolderAfterDeleteEventHandler.createImplementation({\n implementation: AuditLogFolderAfterDeleteHandlerImpl,\n dependencies: [AuditLogsContext]\n});\n"],"names":["AuditLogFolderAfterDeleteHandlerImpl","context","event","folder","createAuditLog","getAuditConfig","AUDIT","error","WebinyError","AuditLogFolderAfterDeleteHandler","FolderAfterDeleteEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IACF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA0C,EAAiB;QACpE,IAAI;YACA,MAAM,EAAEC,MAAM,EAAE,GAAGD,MAAM,OAAO;YAChC,IAAIC,AAAgB,aAAhBA,OAAO,IAAI,EAAe;gBAC1B,MAAMC,iBAAiBC,eAAeC,MAAM,YAAY,CAAC,WAAW,CAAC,MAAM;gBAC3E,MAAMF,eAAe,kBAAkBD,QAAQA,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO;YAC1E,OAAO,IAAIA,AAAgB,aAAhBA,OAAO,IAAI,EAAe;gBACjC,MAAMC,iBAAiBC,eAAeC,MAAM,YAAY,CAAC,WAAW,CAAC,MAAM;gBAC3E,MAAMF,eAAe,kBAAkBD,QAAQA,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO;YAC1E,OAAO,IAAIA,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS;gBACvC,MAAMC,iBAAiBC,eAAeC,MAAM,YAAY,CAAC,YAAY,CAAC,MAAM;gBAC5E,MAAMF,eAAe,kBAAkBD,QAAQA,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO;YAC1E;QACJ,EAAE,OAAOI,OAAO;YACZ,MAAMC,cAAAA,IAAgB,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,mCAAmCC,8BAA8B,oBAAoB,CAAC;IAC/F,gBAAgBV;IAChB,cAAc;QAACW;KAAiB;AACpC"}
1
+ {"version":3,"file":"subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js","sources":["../../../../src/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FolderAfterDeleteEventHandler } from \"@webiny/api-aco/features/folder/DeleteFolder/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\n\nclass AuditLogFolderAfterDeleteHandlerImpl implements FolderAfterDeleteEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: FolderAfterDeleteEventHandler.Event): Promise<void> {\n try {\n const { folder } = event.payload;\n if (folder.type === \"FmFile\") {\n const createAuditLog = getAuditConfig(AUDIT.FILE_MANAGER.FILE_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n } else if (folder.type.startsWith(\"cms:\")) {\n const createAuditLog = getAuditConfig(AUDIT.HEADLESS_CMS.MODEL_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n } else if (folder.type === \"wb:page\") {\n const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.PAGE_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n } else if (folder.type === \"wb:redirect\") {\n const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.REDIRECT_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing AuditLogFolderAfterDeleteHandler\",\n code: \"AUDIT_LOGS_AFTER_FOLDER_DELETE_HANDLER\"\n });\n }\n }\n}\n\nexport const AuditLogFolderAfterDeleteHandler = FolderAfterDeleteEventHandler.createImplementation({\n implementation: AuditLogFolderAfterDeleteHandlerImpl,\n dependencies: [AuditLogsContext]\n});\n"],"names":["AuditLogFolderAfterDeleteHandlerImpl","context","event","folder","createAuditLog","getAuditConfig","AUDIT","error","WebinyError","AuditLogFolderAfterDeleteHandler","FolderAfterDeleteEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IACF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA0C,EAAiB;QACpE,IAAI;YACA,MAAM,EAAE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