@webiny/api-audit-logs 6.6.0-alpha.11 → 6.6.0-alpha.13

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.
@@ -8,6 +8,9 @@ class GetAuditLogUseCaseImpl {
8
8
  this.permissions = permissions;
9
9
  }
10
10
  async execute(id) {
11
+ if (!await this.permissions.canAccessAll()) return Result.fail(new NotAuthorizedError({
12
+ message: "You cannot access audit logs."
13
+ }));
11
14
  const result = await this.repository.get(id);
12
15
  if (result.isFail()) return Result.fail(result.error);
13
16
  const canAccess = await this.permissions.canAccess(result.value.action);
@@ -1 +1 @@
1
- {"version":3,"file":"features/GetAuditLog/GetAuditLogUseCase.js","sources":["../../../src/features/GetAuditLog/GetAuditLogUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/errors.js\";\nimport { AuditLogPermissions } from \"~/features/AuditLogPermissions/abstractions.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport { GetAuditLogUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetAuditLogRepository } from \"./abstractions.js\";\n\nclass GetAuditLogUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly repository: GetAuditLogRepository.Interface,\n private readonly permissions: AuditLogPermissions.Interface\n ) {}\n\n public async execute(id: string): Promise<Result<IAuditLog, UseCaseAbstraction.Error>> {\n const result = await this.repository.get(id);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const canAccess = await this.permissions.canAccess(result.value.action);\n if (!canAccess) {\n return Result.fail(\n new NotAuthorizedError({ message: \"You cannot access audit logs.\" })\n );\n }\n\n return Result.ok(result.value);\n }\n}\n\nexport const GetAuditLogUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetAuditLogUseCaseImpl,\n dependencies: [GetAuditLogRepository, AuditLogPermissions]\n});\n"],"names":["GetAuditLogUseCaseImpl","repository","permissions","id","result","Result","canAccess","NotAuthorizedError","GetAuditLogUseCase","UseCaseAbstraction","GetAuditLogRepository","AuditLogPermissions"],"mappings":";;;;AAOA,MAAMA;IACF,YACqBC,UAA2C,EAC3CC,WAA0C,CAC7D;aAFmBD,UAAU,GAAVA;aACAC,WAAW,GAAXA;IAClB;IAEH,MAAa,QAAQC,EAAU,EAAwD;QACnF,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACD;QACzC,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAACD,OAAO,KAAK;QAGnC,MAAME,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAACF,OAAO,KAAK,CAAC,MAAM;QACtE,IAAI,CAACE,WACD,OAAOD,OAAO,IAAI,CACd,IAAIE,mBAAmB;YAAE,SAAS;QAAgC;QAI1E,OAAOF,OAAO,EAAE,CAACD,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMI,wCAAqBC,mBAAAA,oBAAuC,CAAC;IACtE,gBAAgBT;IAChB,cAAc;QAACU;QAAuBC;KAAoB;AAC9D"}
1
+ {"version":3,"file":"features/GetAuditLog/GetAuditLogUseCase.js","sources":["../../../src/features/GetAuditLog/GetAuditLogUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/errors.js\";\nimport { AuditLogPermissions } from \"~/features/AuditLogPermissions/abstractions.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport { GetAuditLogUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetAuditLogRepository } from \"./abstractions.js\";\n\nclass GetAuditLogUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly repository: GetAuditLogRepository.Interface,\n private readonly permissions: AuditLogPermissions.Interface\n ) {}\n\n public async execute(id: string): Promise<Result<IAuditLog, UseCaseAbstraction.Error>> {\n // Checked before the record is loaded, so the response does not reveal whether the ID exists.\n if (!(await this.permissions.canAccessAll())) {\n return Result.fail(\n new NotAuthorizedError({ message: \"You cannot access audit logs.\" })\n );\n }\n\n const result = await this.repository.get(id);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const canAccess = await this.permissions.canAccess(result.value.action);\n if (!canAccess) {\n return Result.fail(\n new NotAuthorizedError({ message: \"You cannot access audit logs.\" })\n );\n }\n\n return Result.ok(result.value);\n }\n}\n\nexport const GetAuditLogUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetAuditLogUseCaseImpl,\n dependencies: [GetAuditLogRepository, AuditLogPermissions]\n});\n"],"names":["GetAuditLogUseCaseImpl","repository","permissions","id","Result","NotAuthorizedError","result","canAccess","GetAuditLogUseCase","UseCaseAbstraction","GetAuditLogRepository","AuditLogPermissions"],"mappings":";;;;AAOA,MAAMA;IACF,YACqBC,UAA2C,EAC3CC,WAA0C,CAC7D;aAFmBD,UAAU,GAAVA;aACAC,WAAW,GAAXA;IAClB;IAEH,MAAa,QAAQC,EAAU,EAAwD;QAEnF,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,IACrC,OAAOC,OAAO,IAAI,CACd,IAAIC,mBAAmB;YAAE,SAAS;QAAgC;QAI1E,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACH;QACzC,IAAIG,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAGnC,MAAMC,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAACD,OAAO,KAAK,CAAC,MAAM;QACtE,IAAI,CAACC,WACD,OAAOH,OAAO,IAAI,CACd,IAAIC,mBAAmB;YAAE,SAAS;QAAgC;QAI1E,OAAOD,OAAO,EAAE,CAACE,OAAO,KAAK;IACjC;AACJ;AAEO,MAAME,wCAAqBC,mBAAAA,oBAAuC,CAAC;IACtE,gBAAgBT;IAChB,cAAc;QAACU;QAAuBC;KAAoB;AAC9D"}
@@ -20,10 +20,6 @@ class RecordAuditLogUseCaseImpl {
20
20
  }
21
21
  async execute(input) {
22
22
  const { audit, message, content, entityId } = input;
23
- if (!this.identityContext.getIdentity()?.id) {
24
- this.logger.debug("No identity, skipping audit log creation.");
25
- return Result.ok(null);
26
- }
27
23
  const payload = {
28
24
  message,
29
25
  app: audit.app.app,
@@ -1 +1 @@
1
- {"version":3,"file":"features/RecordAuditLog/RecordAuditLogUseCase.js","sources":["../../../src/features/RecordAuditLog/RecordAuditLogUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { CreateAuditLogUseCase } from \"~/features/CreateAuditLog/abstractions.js\";\nimport { ListAuditLogsUseCase } from \"~/features/ListAuditLogs/abstractions.js\";\nimport { UpdateAuditLogUseCase } from \"~/features/UpdateAuditLog/abstractions.js\";\nimport type { AuditLogPayload } from \"~/types.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport { RecordAuditLogUseCase as UseCaseAbstraction } from \"./abstractions.js\";\n\nconst createAuditLogDelayDate = (delay: number): Date => {\n const date = new Date();\n date.setTime(date.getTime() - delay * 1000);\n return date;\n};\n\n/**\n * Records audit logs for things the current identity did. Writes happen without authorization,\n * because the identity doing the audited action doesn't need audit log permissions.\n *\n * An action with a `newEntryDelay` merges into the entity's latest audit log when that log is\n * newer than the delay, instead of creating a new one. A failure on that path is logged and\n * nothing is recorded.\n */\nclass RecordAuditLogUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly createAuditLog: CreateAuditLogUseCase.Interface,\n private readonly listAuditLogs: ListAuditLogsUseCase.Interface,\n private readonly updateAuditLog: UpdateAuditLogUseCase.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n public async execute(\n input: UseCaseAbstraction.Input\n ): Promise<Result<IAuditLog | null, UseCaseAbstraction.Error>> {\n const { audit, message, content, entityId } = input;\n\n if (!this.identityContext.getIdentity()?.id) {\n this.logger.debug(\"No identity, skipping audit log creation.\");\n return Result.ok(null);\n }\n\n const payload: AuditLogPayload = {\n message,\n app: audit.app.app,\n entityId,\n entity: audit.entity.type,\n action: audit.action.type,\n content,\n tags: []\n };\n\n const delay = audit.action.newEntryDelay || 0;\n\n return await this.identityContext.withoutAuthorization(async () => {\n if (delay > 0) {\n try {\n return await this.createOrMergeAuditLog(payload, delay);\n } catch (error) {\n this.logger.warn({ error }, \"Could not create or merge an audit log.\");\n return Result.ok(null);\n }\n }\n return await this.createAuditLog.execute(payload);\n });\n }\n\n private async createOrMergeAuditLog(\n payload: AuditLogPayload,\n delay: number\n ): Promise<Result<IAuditLog | null, UseCaseAbstraction.Error>> {\n const createdOnGte = createAuditLogDelayDate(delay);\n const listResult = await this.listAuditLogs.execute({\n app: payload.app,\n entityId: payload.entityId,\n limit: 1,\n createdOn_gte: createdOnGte,\n sort: \"DESC\"\n });\n if (listResult.isFail()) {\n this.logger.warn(\n { error: listResult.error },\n \"Could not list audit logs to merge into.\"\n );\n return Result.ok(null);\n }\n\n const original = listResult.value.items[0];\n if (!original) {\n const createResult = await this.createAuditLog.execute(payload);\n if (createResult.isFail()) {\n this.logger.warn({ error: createResult.error }, \"Could not create an audit log.\");\n return Result.ok(null);\n }\n return Result.ok(createResult.value);\n }\n\n // Update the latest audit log with the new \"after\" payload, keeping its original \"before\".\n // Only the message and the content change: the original log keeps everything else,\n // including any tags it was created with.\n let content = payload.content;\n if (original.content) {\n const beforePayloadData = JSON.parse(original.content)?.before;\n if (beforePayloadData) {\n content = {\n before: beforePayloadData,\n after: payload.content?.after\n };\n }\n }\n\n const updateResult = await this.updateAuditLog.execute(original, {\n message: payload.message,\n content\n });\n if (updateResult.isFail()) {\n this.logger.warn({ error: updateResult.error }, \"Could not merge an audit log.\");\n return Result.ok(null);\n }\n\n return Result.ok(updateResult.value);\n }\n}\n\nexport const RecordAuditLogUseCase = UseCaseAbstraction.createImplementation({\n implementation: RecordAuditLogUseCaseImpl,\n dependencies: [\n CreateAuditLogUseCase,\n ListAuditLogsUseCase,\n UpdateAuditLogUseCase,\n IdentityContext,\n Logger\n ]\n});\n"],"names":["createAuditLogDelayDate","delay","date","Date","RecordAuditLogUseCaseImpl","createAuditLog","listAuditLogs","updateAuditLog","identityContext","logger","input","audit","message","content","entityId","Result","payload","error","createdOnGte","listResult","original","createResult","beforePayloadData","JSON","updateResult","RecordAuditLogUseCase","UseCaseAbstraction","CreateAuditLogUseCase","ListAuditLogsUseCase","UpdateAuditLogUseCase","IdentityContext","Logger"],"mappings":";;;;;;;AAUA,MAAMA,0BAA0B,CAACC;IAC7B,MAAMC,OAAO,IAAIC;IACjBD,KAAK,OAAO,CAACA,KAAK,OAAO,KAAKD,AAAQ,OAARA;IAC9B,OAAOC;AACX;AAUA,MAAME;IACF,YACqBC,cAA+C,EAC/CC,aAA6C,EAC7CC,cAA+C,EAC/CC,eAA0C,EAC1CC,MAAwB,CAC3C;aALmBJ,cAAc,GAAdA;aACAC,aAAa,GAAbA;aACAC,cAAc,GAAdA;aACAC,eAAe,GAAfA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAa,QACTC,KAA+B,EAC4B;QAC3D,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGJ;QAE9C,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI,IAAI;YACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YAClB,OAAOK,OAAO,EAAE,CAAC;QACrB;QAEA,MAAMC,UAA2B;YAC7BJ;YACA,KAAKD,MAAM,GAAG,CAAC,GAAG;YAClBG;YACA,QAAQH,MAAM,MAAM,CAAC,IAAI;YACzB,QAAQA,MAAM,MAAM,CAAC,IAAI;YACzBE;YACA,MAAM,EAAE;QACZ;QAEA,MAAMZ,QAAQU,MAAM,MAAM,CAAC,aAAa,IAAI;QAE5C,OAAO,MAAM,IAAI,CAAC,eAAe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5B;QAER;QAEA,MAAMQ,eAAe,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACJ,UAAU;YAC7D,SAASJ,QAAQ,OAAO;YACxBH;QACJ;QACA,IAAIW,aAAa,MAAM,IAAI;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBAAE,OAAOA,aAAa,KAAK;YAAC,GAAG;YAChD,OAAOT,OAAO,EAAE,CAAC;QACrB;QAEA,OAAOA,OAAO,EAAE,CAACS,aAAa,KAAK;IACvC;AACJ;AAEO,MAAMC,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgBtB;IAChB,cAAc;QACVuB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/RecordAuditLog/RecordAuditLogUseCase.js","sources":["../../../src/features/RecordAuditLog/RecordAuditLogUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { CreateAuditLogUseCase } from \"~/features/CreateAuditLog/abstractions.js\";\nimport { ListAuditLogsUseCase } from \"~/features/ListAuditLogs/abstractions.js\";\nimport { UpdateAuditLogUseCase } from \"~/features/UpdateAuditLog/abstractions.js\";\nimport type { AuditLogPayload } from \"~/types.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport { RecordAuditLogUseCase as UseCaseAbstraction } from \"./abstractions.js\";\n\nconst createAuditLogDelayDate = (delay: number): Date => {\n const date = new Date();\n date.setTime(date.getTime() - delay * 1000);\n return date;\n};\n\n/**\n * Records audit logs for things the current identity did. Writes happen without authorization,\n * because the identity doing the audited action doesn't need audit log permissions.\n *\n * An action with a `newEntryDelay` merges into the entity's latest audit log when that log is\n * newer than the delay, instead of creating a new one. A failure on that path is logged and\n * nothing is recorded.\n */\nclass RecordAuditLogUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly createAuditLog: CreateAuditLogUseCase.Interface,\n private readonly listAuditLogs: ListAuditLogsUseCase.Interface,\n private readonly updateAuditLog: UpdateAuditLogUseCase.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n public async execute(\n input: UseCaseAbstraction.Input\n ): Promise<Result<IAuditLog | null, UseCaseAbstraction.Error>> {\n const { audit, message, content, entityId } = input;\n\n const payload: AuditLogPayload = {\n message,\n app: audit.app.app,\n entityId,\n entity: audit.entity.type,\n action: audit.action.type,\n content,\n tags: []\n };\n\n const delay = audit.action.newEntryDelay || 0;\n\n return await this.identityContext.withoutAuthorization(async () => {\n if (delay > 0) {\n try {\n return await this.createOrMergeAuditLog(payload, delay);\n } catch (error) {\n this.logger.warn({ error }, \"Could not create or merge an audit log.\");\n return Result.ok(null);\n }\n }\n return await this.createAuditLog.execute(payload);\n });\n }\n\n private async createOrMergeAuditLog(\n payload: AuditLogPayload,\n delay: number\n ): Promise<Result<IAuditLog | null, UseCaseAbstraction.Error>> {\n const createdOnGte = createAuditLogDelayDate(delay);\n const listResult = await this.listAuditLogs.execute({\n app: payload.app,\n entityId: payload.entityId,\n limit: 1,\n createdOn_gte: createdOnGte,\n sort: \"DESC\"\n });\n if (listResult.isFail()) {\n this.logger.warn(\n { error: listResult.error },\n \"Could not list audit logs to merge into.\"\n );\n return Result.ok(null);\n }\n\n const original = listResult.value.items[0];\n if (!original) {\n const createResult = await this.createAuditLog.execute(payload);\n if (createResult.isFail()) {\n this.logger.warn({ error: createResult.error }, \"Could not create an audit log.\");\n return Result.ok(null);\n }\n return Result.ok(createResult.value);\n }\n\n // Update the latest audit log with the new \"after\" payload, keeping its original \"before\".\n // Only the message and the content change: the original log keeps everything else,\n // including any tags it was created with.\n let content = payload.content;\n if (original.content) {\n const beforePayloadData = JSON.parse(original.content)?.before;\n if (beforePayloadData) {\n content = {\n before: beforePayloadData,\n after: payload.content?.after\n };\n }\n }\n\n const updateResult = await this.updateAuditLog.execute(original, {\n message: payload.message,\n content\n });\n if (updateResult.isFail()) {\n this.logger.warn({ error: updateResult.error }, \"Could not merge an audit log.\");\n return Result.ok(null);\n }\n\n return Result.ok(updateResult.value);\n }\n}\n\nexport const RecordAuditLogUseCase = UseCaseAbstraction.createImplementation({\n implementation: RecordAuditLogUseCaseImpl,\n dependencies: [\n CreateAuditLogUseCase,\n ListAuditLogsUseCase,\n UpdateAuditLogUseCase,\n IdentityContext,\n Logger\n ]\n});\n"],"names":["createAuditLogDelayDate","delay","date","Date","RecordAuditLogUseCaseImpl","createAuditLog","listAuditLogs","updateAuditLog","identityContext","logger","input","audit","message","content","entityId","payload","error","Result","createdOnGte","listResult","original","createResult","beforePayloadData","JSON","updateResult","RecordAuditLogUseCase","UseCaseAbstraction","CreateAuditLogUseCase","ListAuditLogsUseCase","UpdateAuditLogUseCase","IdentityContext","Logger"],"mappings":";;;;;;;AAUA,MAAMA,0BAA0B,CAACC;IAC7B,MAAMC,OAAO,IAAIC;IACjBD,KAAK,OAAO,CAACA,KAAK,OAAO,KAAKD,AAAQ,OAARA;IAC9B,OAAOC;AACX;AAUA,MAAME;IACF,YACqBC,cAA+C,EAC/CC,aAA6C,EAC7CC,cAA+C,EAC/CC,eAA0C,EAC1CC,MAAwB,CAC3C;aALmBJ,cAAc,GAAdA;aACAC,aAAa,GAAbA;aACAC,cAAc,GAAdA;aACAC,eAAe,GAAfA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAa,QACTC,KAA+B,EAC4B;QAC3D,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGJ;QAE9C,MAAMK,UAA2B;YAC7BH;YACA,KAAKD,MAAM,GAAG,CAAC,GAAG;YAClBG;YACA,QAAQH,MAAM,MAAM,CAAC,IAAI;YACzB,QAAQA,MAAM,MAAM,CAAC,IAAI;YACzBE;YACA,MAAM,EAAE;QACZ;QAEA,MAAMZ,QAAQU,MAAM,MAAM,CAAC,aAAa,IAAI;QAE5C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ACR,OAAOP,QAAQ,OAAO,EAAE;YAC5B;QAER;QAEA,MAAMS,eAAe,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACJ,UAAU;YAC7D,SAASL,QAAQ,OAAO;YACxBF;QACJ;QACA,IAAIW,aAAa,MAAM,IAAI;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBAAE,OAAOA,aAAa,KAAK;YAAC,GAAG;YAChD,OAAOP,OAAO,EAAE,CAAC;QACrB;QAEA,OAAOA,OAAO,EAAE,CAACO,aAAa,KAAK;IACvC;AACJ;AAEO,MAAMC,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgBtB;IAChB,cAAc;QACVuB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-audit-logs",
3
- "version": "6.6.0-alpha.11",
3
+ "version": "6.6.0-alpha.13",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./*": "./*"
@@ -22,32 +22,32 @@
22
22
  "access": "public"
23
23
  },
24
24
  "devDependencies": {
25
- "@webiny/api-core-testing": "6.6.0-alpha.11",
26
- "@webiny/api-headless-cms-testing": "6.6.0-alpha.11",
27
- "@webiny/db-dynamodb": "6.6.0-alpha.11",
25
+ "@webiny/api-core-testing": "6.6.0-alpha.13",
26
+ "@webiny/api-headless-cms-testing": "6.6.0-alpha.13",
27
+ "@webiny/api-kernel-core": "6.6.0-alpha.13",
28
+ "@webiny/db-dynamodb": "6.6.0-alpha.13",
28
29
  "@webiny/di": "2.0.0",
29
- "@webiny/event-handler-core": "6.6.0-alpha.11",
30
- "@webiny/handler": "6.6.0-alpha.11",
31
- "@webiny/plugins": "6.6.0-alpha.11",
32
- "graphql": "16.14.2",
30
+ "@webiny/handler": "6.6.0-alpha.13",
31
+ "@webiny/plugins": "6.6.0-alpha.13",
32
+ "graphql": "16.15.0",
33
33
  "typescript": "7.0.2",
34
- "vitest": "5.0.5"
34
+ "vitest": "5.1.1"
35
35
  },
36
36
  "dependencies": {
37
- "@webiny/api": "6.6.0-alpha.11",
38
- "@webiny/api-aco": "6.6.0-alpha.11",
39
- "@webiny/api-core": "6.6.0-alpha.11",
40
- "@webiny/api-file-manager": "6.6.0-alpha.11",
41
- "@webiny/api-graphql": "6.6.0-alpha.11",
42
- "@webiny/api-headless-cms": "6.6.0-alpha.11",
43
- "@webiny/api-mailer": "6.6.0-alpha.11",
44
- "@webiny/api-website-builder": "6.6.0-alpha.11",
45
- "@webiny/build-tools": "6.6.0-alpha.11",
46
- "@webiny/common-audit-logs": "6.6.0-alpha.11",
47
- "@webiny/error": "6.6.0-alpha.11",
48
- "@webiny/feature": "6.6.0-alpha.11",
49
- "@webiny/utils": "6.6.0-alpha.11",
50
- "@webiny/wcp": "6.6.0-alpha.11",
37
+ "@webiny/api": "6.6.0-alpha.13",
38
+ "@webiny/api-aco": "6.6.0-alpha.13",
39
+ "@webiny/api-core": "6.6.0-alpha.13",
40
+ "@webiny/api-file-manager": "6.6.0-alpha.13",
41
+ "@webiny/api-graphql": "6.6.0-alpha.13",
42
+ "@webiny/api-headless-cms": "6.6.0-alpha.13",
43
+ "@webiny/api-mailer": "6.6.0-alpha.13",
44
+ "@webiny/api-website-builder": "6.6.0-alpha.13",
45
+ "@webiny/build-tools": "6.6.0-alpha.13",
46
+ "@webiny/common-audit-logs": "6.6.0-alpha.13",
47
+ "@webiny/error": "6.6.0-alpha.13",
48
+ "@webiny/feature": "6.6.0-alpha.13",
49
+ "@webiny/utils": "6.6.0-alpha.13",
50
+ "@webiny/wcp": "6.6.0-alpha.13",
51
51
  "zod": "4.6.7"
52
52
  },
53
53
  "webiny": {
@@ -1,4 +1,4 @@
1
- import { MailerSettingsAfterSaveEventHandler } from "@webiny/api-mailer/features/SaveSettings/index.js";
1
+ import { MailerSettingsAfterSaveEventHandler } from "@webiny/api-mailer";
2
2
  import { RecordAuditLogUseCase } from "../../../features/RecordAuditLog/abstractions.js";
3
3
  declare class AuditLogMailerSettingsAfterSaveHandlerImpl implements MailerSettingsAfterSaveEventHandler.Interface {
4
4
  private recordAuditLog;
@@ -6,6 +6,6 @@ declare class AuditLogMailerSettingsAfterSaveHandlerImpl implements MailerSettin
6
6
  handle(event: MailerSettingsAfterSaveEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const AuditLogMailerSettingsAfterSaveHandler: typeof AuditLogMailerSettingsAfterSaveHandlerImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-core/features/eventPublisher").DomainEvent<import("@webiny/api-mailer/features/SaveSettings/abstractions").MailerSettingsAfterSavePayload>>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-core/features/eventPublisher").DomainEvent<import("@webiny/api-mailer").MailerSettingsAfterSavePayload>>>;
10
10
  };
11
11
  export {};
@@ -1,5 +1,5 @@
1
1
  import _webiny_error from "@webiny/error";
2
- import { MailerSettingsAfterSaveEventHandler } from "@webiny/api-mailer/features/SaveSettings/index.js";
2
+ import { MailerSettingsAfterSaveEventHandler } from "@webiny/api-mailer";
3
3
  import { RecordAuditLogUseCase } from "../../../features/RecordAuditLog/abstractions.js";
4
4
  import { AUDIT } from "../../../config.js";
5
5
  class AuditLogMailerSettingsAfterSaveHandlerImpl {
@@ -8,14 +8,17 @@ class AuditLogMailerSettingsAfterSaveHandlerImpl {
8
8
  }
9
9
  async handle(event) {
10
10
  try {
11
- const { settings } = event.payload;
11
+ const { transport, settings } = event.payload;
12
12
  const recordResult = await this.recordAuditLog.execute({
13
13
  audit: AUDIT.MAILER.SETTINGS.UPDATE,
14
14
  message: "Settings updated",
15
15
  content: {
16
- after: settings
16
+ after: {
17
+ transport,
18
+ ...settings
19
+ }
17
20
  },
18
- entityId: "-"
21
+ entityId: transport
19
22
  });
20
23
  if (recordResult.isFail()) throw recordResult.error;
21
24
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js","sources":["../../../../src/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { MailerSettingsAfterSaveEventHandler } from \"@webiny/api-mailer/features/SaveSettings/index.js\";\nimport { RecordAuditLogUseCase } from \"~/features/RecordAuditLog/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\n\nclass AuditLogMailerSettingsAfterSaveHandlerImpl\n implements MailerSettingsAfterSaveEventHandler.Interface\n{\n constructor(private recordAuditLog: RecordAuditLogUseCase.Interface) {}\n\n async handle(event: MailerSettingsAfterSaveEventHandler.Event): Promise<void> {\n try {\n const { settings } = event.payload;\n\n const recordResult = await this.recordAuditLog.execute({\n audit: AUDIT.MAILER.SETTINGS.UPDATE,\n message: \"Settings updated\",\n content: { after: settings },\n entityId: \"-\"\n });\n if (recordResult.isFail()) {\n throw recordResult.error;\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing AuditLogMailerSettingsAfterSaveHandler\",\n code: \"AUDIT_LOGS_AFTER_MAILER_SETTINGS_SAVE_HANDLER\"\n });\n }\n }\n}\n\nexport const AuditLogMailerSettingsAfterSaveHandler =\n MailerSettingsAfterSaveEventHandler.createImplementation({\n implementation: AuditLogMailerSettingsAfterSaveHandlerImpl,\n dependencies: [RecordAuditLogUseCase]\n });\n"],"names":["AuditLogMailerSettingsAfterSaveHandlerImpl","recordAuditLog","event","settings","recordResult","AUDIT","error","WebinyError","AuditLogMailerSettingsAfterSaveHandler","MailerSettingsAfterSaveEventHandler","RecordAuditLogUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YAAoBC,cAA+C,CAAE;aAAjDA,cAAc,GAAdA;IAAkD;IAEtE,MAAM,OAAOC,KAAgD,EAAiB;QAC1E,IAAI;YACA,MAAM,EAAEC,QAAQ,EAAE,GAAGD,MAAM,OAAO;YAElC,MAAME,eAAe,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;gBACnD,OAAOC,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM;gBACnC,SAAS;gBACT,SAAS;oBAAE,OAAOF;gBAAS;gBAC3B,UAAU;YACd;YACA,IAAIC,aAAa,MAAM,IACnB,MAAMA,aAAa,KAAK;QAEhC,EAAE,OAAOE,OAAO;YACZ,MAAMC,cAAAA,IAAgB,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,yCACTC,oCAAoC,oBAAoB,CAAC;IACrD,gBAAgBT;IAChB,cAAc;QAACU;KAAsB;AACzC"}
1
+ {"version":3,"file":"subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js","sources":["../../../../src/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { MailerSettingsAfterSaveEventHandler } from \"@webiny/api-mailer\";\nimport { RecordAuditLogUseCase } from \"~/features/RecordAuditLog/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\n\nclass AuditLogMailerSettingsAfterSaveHandlerImpl\n implements MailerSettingsAfterSaveEventHandler.Interface\n{\n constructor(private recordAuditLog: RecordAuditLogUseCase.Interface) {}\n\n async handle(event: MailerSettingsAfterSaveEventHandler.Event): Promise<void> {\n try {\n // Any transport with stored settings publishes this event; secrets are already left out.\n const { transport, settings } = event.payload;\n\n const recordResult = await this.recordAuditLog.execute({\n audit: AUDIT.MAILER.SETTINGS.UPDATE,\n message: \"Settings updated\",\n content: { after: { transport, ...settings } },\n entityId: transport\n });\n if (recordResult.isFail()) {\n throw recordResult.error;\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing AuditLogMailerSettingsAfterSaveHandler\",\n code: \"AUDIT_LOGS_AFTER_MAILER_SETTINGS_SAVE_HANDLER\"\n });\n }\n }\n}\n\nexport const AuditLogMailerSettingsAfterSaveHandler =\n MailerSettingsAfterSaveEventHandler.createImplementation({\n implementation: AuditLogMailerSettingsAfterSaveHandlerImpl,\n dependencies: [RecordAuditLogUseCase]\n });\n"],"names":["AuditLogMailerSettingsAfterSaveHandlerImpl","recordAuditLog","event","transport","settings","recordResult","AUDIT","error","WebinyError","AuditLogMailerSettingsAfterSaveHandler","MailerSettingsAfterSaveEventHandler","RecordAuditLogUseCase"],"mappings":";;;;AAKA,MAAMA;IAGF,YAAoBC,cAA+C,CAAE;aAAjDA,cAAc,GAAdA;IAAkD;IAEtE,MAAM,OAAOC,KAAgD,EAAiB;QAC1E,IAAI;YAEA,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAE,GAAGF,MAAM,OAAO;YAE7C,MAAMG,eAAe,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;gBACnD,OAAOC,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM;gBACnC,SAAS;gBACT,SAAS;oBAAE,OAAO;wBAAEH;wBAAW,GAAGC,QAAQ;oBAAC;gBAAE;gBAC7C,UAAUD;YACd;YACA,IAAIE,aAAa,MAAM,IACnB,MAAMA,aAAa,KAAK;QAEhC,EAAE,OAAOE,OAAO;YACZ,MAAMC,cAAAA,IAAgB,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,yCACTC,oCAAoC,oBAAoB,CAAC;IACrD,gBAAgBV;IAChB,cAAc;QAACW;KAAsB;AACzC"}
@@ -1,6 +1,6 @@
1
1
  const convertExpiresAtDaysToDate = (days)=>{
2
2
  const date = new Date();
3
- date.setTime(24 * days * 3600000 + date.getTime());
3
+ date.setTime(24 * days * 60 * 60 * 1000 + date.getTime());
4
4
  return date;
5
5
  };
6
6
  const convertExpiresAtToUnixTimestamp = (expiresAt)=>{
@@ -1 +1 @@
1
- {"version":3,"file":"utils/expiresAt.js","sources":["../../src/utils/expiresAt.ts"],"sourcesContent":["export const convertExpiresAtDaysToDate = (days: number): Date => {\n const date = new Date();\n date.setTime(days * 24 * 60 * 60 * 1000 + date.getTime());\n return date;\n};\n\nexport const convertExpiresAtToUnixTimestamp = (expiresAt: Date | string): number => {\n if (typeof expiresAt === \"string\") {\n expiresAt = new Date(expiresAt);\n }\n return Math.floor(expiresAt.getTime() / 1000);\n};\n\nexport const convertUnixTimestampToDate = (\n expiresAt: number | undefined | null\n): Date | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return new Date(expiresAt * 1000);\n};\n\nexport const convertUnixTimestampToISODateString = (\n expiresAt: number | undefined | null\n): string | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return convertUnixTimestampToDate(expiresAt)?.toISOString();\n};\n"],"names":["convertExpiresAtDaysToDate","days","date","Date","convertExpiresAtToUnixTimestamp","expiresAt","Math","convertUnixTimestampToDate","convertUnixTimestampToISODateString"],"mappings":"AAAO,MAAMA,6BAA6B,CAACC;IACvC,MAAMC,OAAO,IAAIC;IACjBD,KAAK,OAAO,CAACD,AAAO,KAAPA,OAAAA,UAA6BC,KAAK,OAAO;IACtD,OAAOA;AACX;AAEO,MAAME,kCAAkC,CAACC;IAC5C,IAAI,AAAqB,YAArB,OAAOA,WACPA,YAAY,IAAIF,KAAKE;IAEzB,OAAOC,KAAK,KAAK,CAACD,UAAU,OAAO,KAAK;AAC5C;AAEO,MAAME,6BAA6B,CACtCF;IAEA,IAAI,CAACA,WACD;IAEJ,OAAO,IAAIF,KAAKE,AAAY,OAAZA;AACpB;AAEO,MAAMG,sCAAsC,CAC/CH;IAEA,IAAI,CAACA,WACD;IAEJ,OAAOE,2BAA2BF,YAAY;AAClD"}
1
+ {"version":3,"file":"utils/expiresAt.js","sources":["../../src/utils/expiresAt.ts"],"sourcesContent":["export const convertExpiresAtDaysToDate = (days: number): Date => {\n const date = new Date();\n date.setTime(days * 24 * 60 * 60 * 1000 + date.getTime());\n return date;\n};\n\nexport const convertExpiresAtToUnixTimestamp = (expiresAt: Date | string): number => {\n if (typeof expiresAt === \"string\") {\n expiresAt = new Date(expiresAt);\n }\n return Math.floor(expiresAt.getTime() / 1000);\n};\n\nexport const convertUnixTimestampToDate = (\n expiresAt: number | undefined | null\n): Date | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return new Date(expiresAt * 1000);\n};\n\nexport const convertUnixTimestampToISODateString = (\n expiresAt: number | undefined | null\n): string | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return convertUnixTimestampToDate(expiresAt)?.toISOString();\n};\n"],"names":["convertExpiresAtDaysToDate","days","date","Date","convertExpiresAtToUnixTimestamp","expiresAt","Math","convertUnixTimestampToDate","convertUnixTimestampToISODateString"],"mappings":"AAAO,MAAMA,6BAA6B,CAACC;IACvC,MAAMC,OAAO,IAAIC;IACjBD,KAAK,OAAO,CAACD,AAAO,KAAPA,OAAY,KAAK,KAAK,OAAOC,KAAK,OAAO;IACtD,OAAOA;AACX;AAEO,MAAME,kCAAkC,CAACC;IAC5C,IAAI,AAAqB,YAArB,OAAOA,WACPA,YAAY,IAAIF,KAAKE;IAEzB,OAAOC,KAAK,KAAK,CAACD,UAAU,OAAO,KAAK;AAC5C;AAEO,MAAME,6BAA6B,CACtCF;IAEA,IAAI,CAACA,WACD;IAEJ,OAAO,IAAIF,KAAKE,AAAY,OAAZA;AACpB;AAEO,MAAMG,sCAAsC,CAC/CH;IAEA,IAAI,CAACA,WACD;IAEJ,OAAOE,2BAA2BF,YAAY;AAClD"}