@webiny/api-audit-logs 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9
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/abstractions.js +2 -3
- package/abstractions.js.map +1 -1
- package/config.js +2 -1
- package/config.js.map +1 -1
- package/context/AuditLogsContextValue.d.ts +1 -1
- package/context/AuditLogsContextValue.js +115 -125
- package/context/AuditLogsContextValue.js.map +1 -1
- package/context/index.js +23 -27
- package/context/index.js.map +1 -1
- package/events/AuditLogAfterCreateEvent.d.ts +2 -2
- package/events/AuditLogAfterCreateEvent.js +9 -6
- package/events/AuditLogAfterCreateEvent.js.map +1 -1
- package/events/AuditLogAfterUpdateEvent.d.ts +2 -2
- package/events/AuditLogAfterUpdateEvent.js +9 -6
- package/events/AuditLogAfterUpdateEvent.js.map +1 -1
- package/events/AuditLogBeforeCreateEvent.d.ts +2 -2
- package/events/AuditLogBeforeCreateEvent.js +9 -6
- package/events/AuditLogBeforeCreateEvent.js.map +1 -1
- package/events/AuditLogBeforeUpdateEvent.d.ts +2 -2
- package/events/AuditLogBeforeUpdateEvent.js +9 -6
- package/events/AuditLogBeforeUpdateEvent.js.map +1 -1
- package/events/abstractions.d.ts +1 -1
- package/events/abstractions.js +5 -24
- package/events/abstractions.js.map +1 -1
- package/events/index.js +0 -2
- package/graphql/schema.js +37 -48
- package/graphql/schema.js.map +1 -1
- package/graphql/validation.d.ts +10 -53
- package/graphql/validation.js +26 -30
- package/graphql/validation.js.map +1 -1
- package/index.js +18 -15
- package/index.js.map +1 -1
- package/package.json +34 -30
- package/storage/AccessPatternHandler.js +31 -52
- package/storage/AccessPatternHandler.js.map +1 -1
- package/storage/Converter.d.ts +3 -3
- package/storage/Converter.js +45 -48
- package/storage/Converter.js.map +1 -1
- package/storage/Storage.d.ts +2 -2
- package/storage/Storage.js +69 -77
- package/storage/Storage.js.map +1 -1
- package/storage/abstractions/AccessPattern.js +0 -3
- package/storage/abstractions/AccessPatternHandler.js +0 -3
- package/storage/abstractions/Converter.js +0 -3
- package/storage/abstractions/Storage.js +0 -3
- package/storage/accessPatterns/AppAccessPattern.js +31 -25
- package/storage/accessPatterns/AppAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppCreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/AppCreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityAccessPattern.js +31 -25
- package/storage/accessPatterns/AppEntityAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityActionAccessPattern.js +31 -25
- package/storage/accessPatterns/AppEntityActionAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/BaseAccessPattern.js +47 -69
- package/storage/accessPatterns/BaseAccessPattern.js.map +1 -1
- package/storage/accessPatterns/CreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/CreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/CreatedOnAccessPattern.js +34 -26
- package/storage/accessPatterns/CreatedOnAccessPattern.js.map +1 -1
- package/storage/accessPatterns/DefaultAccessPattern.js +31 -32
- package/storage/accessPatterns/DefaultAccessPattern.js.map +1 -1
- package/storage/accessPatterns/EntityIdAccessPattern.js +32 -27
- package/storage/accessPatterns/EntityIdAccessPattern.js.map +1 -1
- package/storage/accessPatterns/index.js +44 -34
- package/storage/accessPatterns/index.js.map +1 -1
- package/storage/cursorSchema.js +15 -18
- package/storage/cursorSchema.js.map +1 -1
- package/storage/entity.js +115 -122
- package/storage/entity.js.map +1 -1
- package/storage/results/ListErrorResult.js +9 -8
- package/storage/results/ListErrorResult.js.map +1 -1
- package/storage/results/ListSuccessResult.js +13 -12
- package/storage/results/ListSuccessResult.js.map +1 -1
- package/storage/results/index.js +0 -2
- package/storage/startKey.js +4 -5
- package/storage/startKey.js.map +1 -1
- package/storage/types.js +0 -3
- package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.d.ts +4 -4
- package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js +27 -26
- package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js.map +1 -1
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js +30 -29
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js.map +1 -1
- package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js +33 -33
- package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js.map +1 -1
- package/subscriptions/aco/index.js +5 -4
- package/subscriptions/aco/index.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.d.ts +4 -4
- package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js +22 -21
- package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js +22 -21
- package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js +25 -25
- package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js +25 -25
- package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js.map +1 -1
- package/subscriptions/fileManager/index.js +6 -8
- package/subscriptions/fileManager/index.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js +26 -29
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js +24 -27
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js +24 -24
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.d.ts +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.js +24 -24
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/index.js +16 -20
- package/subscriptions/headlessCms/index.js.map +1 -1
- package/subscriptions/index.js +8 -7
- package/subscriptions/index.js.map +1 -1
- package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.d.ts +4 -4
- package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js +24 -23
- package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js.map +1 -1
- package/subscriptions/mailer/index.js +3 -3
- package/subscriptions/mailer/index.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js +32 -38
- package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js +32 -38
- package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js +36 -43
- package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js +22 -21
- package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js +22 -21
- package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js +25 -25
- package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js +22 -21
- package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js +22 -21
- package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js +25 -25
- package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js +22 -21
- package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js +22 -21
- package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js +25 -25
- package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/cleanupApiKey.js +10 -16
- package/subscriptions/security/handlers/cleanupApiKey.js.map +1 -1
- package/subscriptions/security/index.js +14 -20
- package/subscriptions/security/index.js.map +1 -1
- package/subscriptions/websiteBuilder/index.js +14 -16
- package/subscriptions/websiteBuilder/index.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js +21 -20
- package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js +21 -20
- package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js +21 -20
- package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js +24 -24
- package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js +21 -20
- package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js +21 -20
- package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js +21 -20
- package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js +24 -24
- package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js +21 -20
- package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js +21 -20
- package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js +21 -20
- package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.d.ts +4 -4
- package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js +24 -24
- package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js.map +1 -1
- package/types.js +0 -3
- package/utils/expiresAt.js +14 -19
- package/utils/expiresAt.js.map +1 -1
- package/utils/getAuditConfig.js +79 -98
- package/utils/getAuditConfig.js.map +1 -1
- package/utils/getAuditObject.js +14 -15
- package/utils/getAuditObject.js.map +1 -1
- package/events/index.js.map +0 -1
- package/storage/abstractions/AccessPattern.js.map +0 -1
- package/storage/abstractions/AccessPatternHandler.js.map +0 -1
- package/storage/abstractions/Converter.js.map +0 -1
- package/storage/abstractions/Storage.js.map +0 -1
- package/storage/results/index.js.map +0 -1
- package/storage/types.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
|
-
import {
|
|
2
|
+
import { RedirectAfterMoveEventHandler } from "@webiny/api-website-builder/features/redirects/MoveRedirect/index.js";
|
|
3
3
|
import { AuditLogsContext } from "../../../abstractions.js";
|
|
4
4
|
import { getAuditConfig } from "../../../utils/getAuditConfig.js";
|
|
5
5
|
import { AUDIT } from "../../../config.js";
|
|
6
6
|
class RedirectAfterMoveHandlerImpl {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
7
|
+
constructor(context){
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
async handle(event) {
|
|
11
|
+
try {
|
|
12
|
+
const { redirect } = event.payload;
|
|
13
|
+
const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.REDIRECT.MOVE);
|
|
14
|
+
await createAuditLog("Website Redirect Moved", redirect, redirect.id, this.context);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
throw WebinyError.from(error, {
|
|
17
|
+
message: "Error while executing RedirectAfterMoveEventHandler",
|
|
18
|
+
code: "AUDIT_LOGS_AFTER_REDIRECT_MOVE_HANDLER"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
22
21
|
}
|
|
23
|
-
}
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const RedirectAfterMoveAuditHandler = RedirectAfterMoveEventHandler.createImplementation({
|
|
24
|
+
implementation: RedirectAfterMoveHandlerImpl,
|
|
25
|
+
dependencies: [
|
|
26
|
+
AuditLogsContext
|
|
27
|
+
]
|
|
28
28
|
});
|
|
29
|
+
export { RedirectAfterMoveAuditHandler };
|
|
29
30
|
|
|
30
31
|
//# sourceMappingURL=RedirectAfterMoveHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js","sources":["../../../../src/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { RedirectAfterMoveEventHandler } from \"@webiny/api-website-builder/features/redirects/MoveRedirect/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\nimport { AUDIT } from \"~/config.js\";\n\nclass RedirectAfterMoveHandlerImpl implements RedirectAfterMoveEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: RedirectAfterMoveEventHandler.Event): Promise<void> {\n try {\n const { redirect } = event.payload;\n const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.REDIRECT.MOVE);\n await createAuditLog(\"Website Redirect Moved\", redirect, redirect.id, this.context);\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing RedirectAfterMoveEventHandler\",\n code: \"AUDIT_LOGS_AFTER_REDIRECT_MOVE_HANDLER\"\n });\n }\n }\n}\n\nexport const RedirectAfterMoveAuditHandler = RedirectAfterMoveEventHandler.createImplementation({\n implementation: RedirectAfterMoveHandlerImpl,\n dependencies: [AuditLogsContext]\n});\n"],"names":["RedirectAfterMoveHandlerImpl","context","event","redirect","createAuditLog","getAuditConfig","AUDIT","error","WebinyError","RedirectAfterMoveAuditHandler","RedirectAfterMoveEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IACF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA0C,EAAiB;QACpE,IAAI;YACA,MAAM,EAAEC,QAAQ,EAAE,GAAGD,MAAM,OAAO;YAClC,MAAME,iBAAiBC,eAAeC,MAAM,eAAe,CAAC,QAAQ,CAAC,IAAI;YACzE,MAAMF,eAAe,0BAA0BD,UAAUA,SAAS,EAAE,EAAE,IAAI,CAAC,OAAO;QACtF,EAAE,OAAOI,OAAO;YACZ,MAAMC,YAAY,IAAI,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,gCAAgCC,8BAA8B,oBAAoB,CAAC;IAC5F,gBAAgBV;IAChB,cAAc;QAACW;KAAiB;AACpC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RedirectAfterUpdateEventHandler } from "@webiny/api-website-builder/features/redirects/UpdateRedirect/index.js";
|
|
2
2
|
import { AuditLogsContext } from "../../../abstractions.js";
|
|
3
|
-
declare class RedirectAfterUpdateHandlerImpl implements
|
|
3
|
+
declare class RedirectAfterUpdateHandlerImpl implements RedirectAfterUpdateEventHandler.Interface {
|
|
4
4
|
private context;
|
|
5
5
|
constructor(context: AuditLogsContext.Interface);
|
|
6
|
-
handle(event:
|
|
6
|
+
handle(event: RedirectAfterUpdateEventHandler.Event): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export declare const RedirectAfterUpdateAuditHandler: typeof RedirectAfterUpdateHandlerImpl & {
|
|
9
|
-
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-core/features/eventPublisher").DomainEvent<import("@webiny/api-website-builder/features/redirects/UpdateRedirect/abstractions").RedirectAfterUpdatePayload>>>;
|
|
10
10
|
};
|
|
11
11
|
export {};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
|
-
import {
|
|
2
|
+
import { RedirectAfterUpdateEventHandler } from "@webiny/api-website-builder/features/redirects/UpdateRedirect/index.js";
|
|
3
3
|
import { AuditLogsContext } from "../../../abstractions.js";
|
|
4
4
|
import { getAuditConfig } from "../../../utils/getAuditConfig.js";
|
|
5
5
|
import { AUDIT } from "../../../config.js";
|
|
6
6
|
class RedirectAfterUpdateHandlerImpl {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
code: "AUDIT_LOGS_AFTER_REDIRECT_UPDATE_HANDLER"
|
|
25
|
-
});
|
|
7
|
+
constructor(context){
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
async handle(event) {
|
|
11
|
+
try {
|
|
12
|
+
const { redirect, original } = event.payload;
|
|
13
|
+
const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.REDIRECT.UPDATE);
|
|
14
|
+
await createAuditLog("Website Redirect Updated", {
|
|
15
|
+
before: original,
|
|
16
|
+
after: redirect
|
|
17
|
+
}, redirect.id, this.context);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw WebinyError.from(error, {
|
|
20
|
+
message: "Error while executing RedirectAfterUpdateEventHandler",
|
|
21
|
+
code: "AUDIT_LOGS_AFTER_REDIRECT_UPDATE_HANDLER"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
26
24
|
}
|
|
27
|
-
}
|
|
28
25
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const RedirectAfterUpdateAuditHandler = RedirectAfterUpdateEventHandler.createImplementation({
|
|
27
|
+
implementation: RedirectAfterUpdateHandlerImpl,
|
|
28
|
+
dependencies: [
|
|
29
|
+
AuditLogsContext
|
|
30
|
+
]
|
|
32
31
|
});
|
|
32
|
+
export { RedirectAfterUpdateAuditHandler };
|
|
33
33
|
|
|
34
34
|
//# sourceMappingURL=RedirectAfterUpdateHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js","sources":["../../../../src/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { RedirectAfterUpdateEventHandler } from \"@webiny/api-website-builder/features/redirects/UpdateRedirect/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\nimport { AUDIT } from \"~/config.js\";\n\nclass RedirectAfterUpdateHandlerImpl implements RedirectAfterUpdateEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: RedirectAfterUpdateEventHandler.Event): Promise<void> {\n try {\n const { redirect, original } = event.payload;\n const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.REDIRECT.UPDATE);\n await createAuditLog(\n \"Website Redirect Updated\",\n { before: original, after: redirect },\n redirect.id,\n this.context\n );\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing RedirectAfterUpdateEventHandler\",\n code: \"AUDIT_LOGS_AFTER_REDIRECT_UPDATE_HANDLER\"\n });\n }\n }\n}\n\nexport const RedirectAfterUpdateAuditHandler = RedirectAfterUpdateEventHandler.createImplementation(\n {\n implementation: RedirectAfterUpdateHandlerImpl,\n dependencies: [AuditLogsContext]\n }\n);\n"],"names":["RedirectAfterUpdateHandlerImpl","context","event","redirect","original","createAuditLog","getAuditConfig","AUDIT","error","WebinyError","RedirectAfterUpdateAuditHandler","RedirectAfterUpdateEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IACF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA4C,EAAiB;QACtE,IAAI;YACA,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGF,MAAM,OAAO;YAC5C,MAAMG,iBAAiBC,eAAeC,MAAM,eAAe,CAAC,QAAQ,CAAC,MAAM;YAC3E,MAAMF,eACF,4BACA;gBAAE,QAAQD;gBAAU,OAAOD;YAAS,GACpCA,SAAS,EAAE,EACX,IAAI,CAAC,OAAO;QAEpB,EAAE,OAAOK,OAAO;YACZ,MAAMC,YAAY,IAAI,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,kCAAkCC,gCAAgC,oBAAoB,CAC/F;IACI,gBAAgBX;IAChB,cAAc;QAACY;KAAiB;AACpC"}
|
package/types.js
CHANGED
package/utils/expiresAt.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const convertExpiresAtDaysToDate = (days)=>{
|
|
2
|
+
const date = new Date();
|
|
3
|
+
date.setTime(24 * days * 3600000 + date.getTime());
|
|
4
|
+
return date;
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return Math.floor(expiresAt.getTime() / 1000);
|
|
6
|
+
const convertExpiresAtToUnixTimestamp = (expiresAt)=>{
|
|
7
|
+
if ("string" == typeof expiresAt) expiresAt = new Date(expiresAt);
|
|
8
|
+
return Math.floor(expiresAt.getTime() / 1000);
|
|
11
9
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
return new Date(expiresAt * 1000);
|
|
10
|
+
const convertUnixTimestampToDate = (expiresAt)=>{
|
|
11
|
+
if (!expiresAt) return;
|
|
12
|
+
return new Date(1000 * expiresAt);
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
return convertUnixTimestampToDate(expiresAt)?.toISOString();
|
|
14
|
+
const convertUnixTimestampToISODateString = (expiresAt)=>{
|
|
15
|
+
if (!expiresAt) return;
|
|
16
|
+
return convertUnixTimestampToDate(expiresAt)?.toISOString();
|
|
23
17
|
};
|
|
18
|
+
export { convertExpiresAtDaysToDate, convertExpiresAtToUnixTimestamp, convertUnixTimestampToDate, convertUnixTimestampToISODateString };
|
|
24
19
|
|
|
25
20
|
//# sourceMappingURL=expiresAt.js.map
|
package/utils/expiresAt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
package/utils/getAuditConfig.js
CHANGED
|
@@ -1,105 +1,86 @@
|
|
|
1
|
-
import
|
|
2
|
-
const createAuditLog = async params
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} catch (error) {
|
|
10
|
-
throw WebinyError.from(error);
|
|
11
|
-
}
|
|
1
|
+
import _webiny_error from "@webiny/error";
|
|
2
|
+
const createAuditLog = async (params)=>{
|
|
3
|
+
const { context, payload } = params;
|
|
4
|
+
try {
|
|
5
|
+
return await context.auditLogs.createAuditLog(payload);
|
|
6
|
+
} catch (error) {
|
|
7
|
+
throw _webiny_error.from(error);
|
|
8
|
+
}
|
|
12
9
|
};
|
|
13
|
-
const createAuditLogDelayDate = delay
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
date.setTime(date.getTime() - delay * 1000);
|
|
19
|
-
return date;
|
|
10
|
+
const createAuditLogDelayDate = (delay)=>{
|
|
11
|
+
if (!delay) return;
|
|
12
|
+
const date = new Date();
|
|
13
|
+
date.setTime(date.getTime() - 1000 * delay);
|
|
14
|
+
return date;
|
|
20
15
|
};
|
|
21
|
-
const createOrMergeAuditLog = async params
|
|
22
|
-
|
|
23
|
-
context
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
entityId: payload.entityId,
|
|
30
|
-
limit: 1,
|
|
31
|
-
createdOn_gte: createAuditLogDelayDate(delay),
|
|
32
|
-
sort: "DESC"
|
|
33
|
-
});
|
|
34
|
-
if (results.error) {
|
|
35
|
-
throw WebinyError.from(results.error);
|
|
36
|
-
}
|
|
37
|
-
const original = results.items?.[0];
|
|
38
|
-
if (!original) {
|
|
39
|
-
return createAuditLog(params);
|
|
40
|
-
}
|
|
41
|
-
// Update latest audit log with new "after" payload.
|
|
42
|
-
const beforePayloadData = original.content ? JSON.parse(original.content)?.before : undefined;
|
|
43
|
-
/**
|
|
44
|
-
* We can assume that there is a possible "after" in the payload data.
|
|
45
|
-
*/
|
|
46
|
-
const afterPayloadData = payload.content?.after;
|
|
47
|
-
const updatedPayloadData = beforePayloadData ? {
|
|
48
|
-
before: beforePayloadData,
|
|
49
|
-
after: afterPayloadData
|
|
50
|
-
} : payload.content;
|
|
51
|
-
try {
|
|
52
|
-
return await context.auditLogs.updateAuditLog(original, {
|
|
53
|
-
...payload,
|
|
54
|
-
content: updatedPayloadData
|
|
16
|
+
const createOrMergeAuditLog = async (params)=>{
|
|
17
|
+
const { context, payload, delay } = params;
|
|
18
|
+
const results = await context.auditLogs.listAuditLogs({
|
|
19
|
+
app: payload.app,
|
|
20
|
+
entityId: payload.entityId,
|
|
21
|
+
limit: 1,
|
|
22
|
+
createdOn_gte: createAuditLogDelayDate(delay),
|
|
23
|
+
sort: "DESC"
|
|
55
24
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
25
|
+
if (results.error) throw _webiny_error.from(results.error);
|
|
26
|
+
const original = results.items?.[0];
|
|
27
|
+
if (!original) return createAuditLog(params);
|
|
28
|
+
const beforePayloadData = original.content ? JSON.parse(original.content)?.before : void 0;
|
|
29
|
+
const afterPayloadData = payload.content?.after;
|
|
30
|
+
const updatedPayloadData = beforePayloadData ? {
|
|
31
|
+
before: beforePayloadData,
|
|
32
|
+
after: afterPayloadData
|
|
33
|
+
} : payload.content;
|
|
34
|
+
try {
|
|
35
|
+
return await context.auditLogs.updateAuditLog(original, {
|
|
36
|
+
...payload,
|
|
37
|
+
content: updatedPayloadData
|
|
38
|
+
});
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
throw _webiny_error.from(ex);
|
|
68
41
|
}
|
|
69
|
-
const payload = {
|
|
70
|
-
message,
|
|
71
|
-
app: audit.app.app,
|
|
72
|
-
entityId,
|
|
73
|
-
entity: audit.entity.type,
|
|
74
|
-
action: audit.action.type,
|
|
75
|
-
content,
|
|
76
|
-
tags: []
|
|
77
|
-
};
|
|
78
|
-
const delay = audit.action.newEntryDelay || 0;
|
|
79
|
-
if (!context.security.getIdentity()?.id) {
|
|
80
|
-
console.log("No identity - skipping audit log creation.");
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return await context.security.withoutAuthorization(async () => {
|
|
84
|
-
// Check if there is delay on audit log creation for this action.
|
|
85
|
-
if (delay > 0) {
|
|
86
|
-
try {
|
|
87
|
-
return await createOrMergeAuditLog({
|
|
88
|
-
context,
|
|
89
|
-
payload,
|
|
90
|
-
delay
|
|
91
|
-
});
|
|
92
|
-
} catch {
|
|
93
|
-
// Don't care at this point!
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
return await createAuditLog({
|
|
98
|
-
context,
|
|
99
|
-
payload
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
42
|
};
|
|
43
|
+
const getAuditConfig = (audit)=>async (message, content, entityId, context)=>{
|
|
44
|
+
if (context.auditLogs) {
|
|
45
|
+
if (!audit) {
|
|
46
|
+
console.log("No Audit Action defined!");
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
console.log("No AuditLogs defined.");
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const payload = {
|
|
54
|
+
message,
|
|
55
|
+
app: audit.app.app,
|
|
56
|
+
entityId,
|
|
57
|
+
entity: audit.entity.type,
|
|
58
|
+
action: audit.action.type,
|
|
59
|
+
content,
|
|
60
|
+
tags: []
|
|
61
|
+
};
|
|
62
|
+
const delay = audit.action.newEntryDelay || 0;
|
|
63
|
+
if (!context.security.getIdentity()?.id) {
|
|
64
|
+
console.log("No identity - skipping audit log creation.");
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return await context.security.withoutAuthorization(async ()=>{
|
|
68
|
+
if (delay > 0) {
|
|
69
|
+
try {
|
|
70
|
+
return await createOrMergeAuditLog({
|
|
71
|
+
context,
|
|
72
|
+
payload,
|
|
73
|
+
delay
|
|
74
|
+
});
|
|
75
|
+
} catch {}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return await createAuditLog({
|
|
79
|
+
context,
|
|
80
|
+
payload
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export { getAuditConfig };
|
|
104
85
|
|
|
105
86
|
//# sourceMappingURL=getAuditConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/getAuditConfig.js","sources":["../../src/utils/getAuditConfig.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { AuditAction, AuditLogPayload, AuditLogsContext } from \"~/types.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\ninterface CreateAuditLogParams {\n context: Pick<AuditLogsContext, \"auditLogs\">;\n payload: AuditLogPayload;\n}\n\nconst createAuditLog = async (params: CreateAuditLogParams): Promise<IAuditLog> => {\n const { context, payload } = params;\n\n try {\n return await context.auditLogs.createAuditLog(payload);\n } catch (error) {\n throw WebinyError.from(error);\n }\n};\n\ninterface CreateOrMergeAuditLogParams {\n context: AuditLogsContext;\n payload: AuditLogPayload;\n delay: number;\n}\n\nconst createAuditLogDelayDate = (delay: number | undefined) => {\n if (!delay) {\n return undefined;\n }\n const date = new Date();\n date.setTime(date.getTime() - delay * 1000);\n return date;\n};\n\nconst createOrMergeAuditLog = async (params: CreateOrMergeAuditLogParams): Promise<IAuditLog> => {\n const { context, payload, delay } = params;\n\n const results = await context.auditLogs.listAuditLogs({\n app: payload.app,\n entityId: payload.entityId,\n limit: 1,\n createdOn_gte: createAuditLogDelayDate(delay),\n sort: \"DESC\"\n });\n if (results.error) {\n throw WebinyError.from(results.error);\n }\n const original = results.items?.[0];\n if (!original) {\n return createAuditLog(params);\n }\n // Update latest audit log with new \"after\" payload.\n const beforePayloadData = original.content ? JSON.parse(original.content)?.before : undefined;\n /**\n * We can assume that there is a possible \"after\" in the payload data.\n */\n const afterPayloadData = payload.content?.after;\n const updatedPayloadData = beforePayloadData\n ? {\n before: beforePayloadData,\n after: afterPayloadData\n }\n : payload.content;\n\n try {\n return await context.auditLogs.updateAuditLog(original, {\n ...payload,\n content: updatedPayloadData\n });\n } catch (ex) {\n throw WebinyError.from(ex);\n }\n};\n\nexport const getAuditConfig = (audit: AuditAction) => {\n return async (\n message: string,\n content: GenericRecord,\n entityId: string,\n context: AuditLogsContext\n ): Promise<IAuditLog | null> => {\n if (!context.auditLogs) {\n console.log(\"No AuditLogs defined.\");\n return null;\n } else if (!audit) {\n console.log(`No Audit Action defined!`);\n return 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 if (!context.security.getIdentity()?.id) {\n console.log(\"No identity - skipping audit log creation.\");\n return null;\n }\n\n return await context.security.withoutAuthorization(async () => {\n // Check if there is delay on audit log creation for this action.\n if (delay > 0) {\n try {\n return await createOrMergeAuditLog({\n context,\n payload,\n delay\n });\n } catch {\n // Don't care at this point!\n }\n return null;\n }\n return await createAuditLog({\n context,\n payload\n });\n });\n };\n};\n"],"names":["createAuditLog","params","context","payload","error","WebinyError","createAuditLogDelayDate","delay","date","Date","createOrMergeAuditLog","results","original","beforePayloadData","JSON","undefined","afterPayloadData","updatedPayloadData","ex","getAuditConfig","audit","message","content","entityId","console"],"mappings":";AAUA,MAAMA,iBAAiB,OAAOC;IAC1B,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;IAE7B,IAAI;QACA,OAAO,MAAMC,QAAQ,SAAS,CAAC,cAAc,CAACC;IAClD,EAAE,OAAOC,OAAO;QACZ,MAAMC,cAAAA,IAAgB,CAACD;IAC3B;AACJ;AAQA,MAAME,0BAA0B,CAACC;IAC7B,IAAI,CAACA,OACD;IAEJ,MAAMC,OAAO,IAAIC;IACjBD,KAAK,OAAO,CAACA,KAAK,OAAO,KAAKD,AAAQ,OAARA;IAC9B,OAAOC;AACX;AAEA,MAAME,wBAAwB,OAAOT;IACjC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAEI,KAAK,EAAE,GAAGN;IAEpC,MAAMU,UAAU,MAAMT,QAAQ,SAAS,CAAC,aAAa,CAAC;QAClD,KAAKC,QAAQ,GAAG;QAChB,UAAUA,QAAQ,QAAQ;QAC1B,OAAO;QACP,eAAeG,wBAAwBC;QACvC,MAAM;IACV;IACA,IAAII,QAAQ,KAAK,EACb,MAAMN,cAAAA,IAAgB,CAACM,QAAQ,KAAK;IAExC,MAAMC,WAAWD,QAAQ,KAAK,EAAE,CAAC,EAAE;IACnC,IAAI,CAACC,UACD,OAAOZ,eAAeC;IAG1B,MAAMY,oBAAoBD,SAAS,OAAO,GAAGE,KAAK,KAAK,CAACF,SAAS,OAAO,GAAG,SAASG;IAIpF,MAAMC,mBAAmBb,QAAQ,OAAO,EAAE;IAC1C,MAAMc,qBAAqBJ,oBACrB;QACI,QAAQA;QACR,OAAOG;IACX,IACAb,QAAQ,OAAO;IAErB,IAAI;QACA,OAAO,MAAMD,QAAQ,SAAS,CAAC,cAAc,CAACU,UAAU;YACpD,GAAGT,OAAO;YACV,SAASc;QACb;IACJ,EAAE,OAAOC,IAAI;QACT,MAAMb,cAAAA,IAAgB,CAACa;IAC3B;AACJ;AAEO,MAAMC,iBAAiB,CAACC,QACpB,OACHC,SACAC,SACAC,UACArB;QAEA,IAAKA,QAAQ,SAAS,EAGf;YAAA,IAAI,CAACkB,OAAO;gBACfI,QAAQ,GAAG,CAAC;gBACZ,OAAO;YACX;QAAA,OANwB;YACpBA,QAAQ,GAAG,CAAC;YACZ,OAAO;QACX;QAKA,MAAMrB,UAA2B;YAC7BkB;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,MAAMf,QAAQa,MAAM,MAAM,CAAC,aAAa,IAAI;QAE5C,IAAI,CAAClB,QAAQ,QAAQ,CAAC,WAAW,IAAI,IAAI;YACrCsB,QAAQ,GAAG,CAAC;YACZ,OAAO;QACX;QAEA,OAAO,MAAMtB,QAAQ,QAAQ,CAAC,oBAAoB,CAAC;YAE/C,IAAIK,QAAQ,GAAG;gBACX,IAAI;oBACA,OAAO,MAAMG,sBAAsB;wBAC/BR;wBACAC;wBACAI;oBACJ;gBACJ,EAAE,OAAM,CAER;gBACA,OAAO;YACX;YACA,OAAO,MAAMP,eAAe;gBACxBE;gBACAC;YACJ;QACJ;IACJ"}
|
package/utils/getAuditObject.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
const getAuditObject = (apps)=>apps.reduce((result, app)=>{
|
|
2
|
+
result[app.app] = app.entities.reduce((entities, entity)=>{
|
|
3
|
+
entities[entity.type] = entity.actions.reduce((actions, action)=>{
|
|
4
|
+
actions[action.type] = {
|
|
5
|
+
app,
|
|
6
|
+
entity,
|
|
7
|
+
action
|
|
8
|
+
};
|
|
9
|
+
return actions;
|
|
10
|
+
}, {});
|
|
11
|
+
return entities;
|
|
12
|
+
}, {});
|
|
13
|
+
return result;
|
|
13
14
|
}, {});
|
|
14
|
-
|
|
15
|
-
}, {});
|
|
16
|
-
};
|
|
15
|
+
export { getAuditObject };
|
|
17
16
|
|
|
18
17
|
//# sourceMappingURL=getAuditObject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/getAuditObject.js","sources":["../../src/utils/getAuditObject.ts"],"sourcesContent":["import type { ActionObject, AuditObject, EntityObject } from \"~/types.js\";\nimport type { App } from \"@webiny/common-audit-logs/types.js\";\n\nexport const getAuditObject = (apps: App[]) => {\n return apps.reduce<AuditObject>((result, app) => {\n result[app.app] = app.entities.reduce<EntityObject>((entities, entity) => {\n entities[entity.type] = entity.actions.reduce<ActionObject>((actions, action) => {\n actions[action.type] = {\n app,\n entity,\n action\n };\n\n return actions;\n }, {});\n\n return entities;\n }, {});\n\n return result;\n }, {});\n};\n"],"names":["getAuditObject","apps","result","app","entities","entity","actions","action"],"mappings":"AAGO,MAAMA,iBAAiB,CAACC,OACpBA,KAAK,MAAM,CAAc,CAACC,QAAQC;QACrCD,MAAM,CAACC,IAAI,GAAG,CAAC,GAAGA,IAAI,QAAQ,CAAC,MAAM,CAAe,CAACC,UAAUC;YAC3DD,QAAQ,CAACC,OAAO,IAAI,CAAC,GAAGA,OAAO,OAAO,CAAC,MAAM,CAAe,CAACC,SAASC;gBAClED,OAAO,CAACC,OAAO,IAAI,CAAC,GAAG;oBACnBJ;oBACAE;oBACAE;gBACJ;gBAEA,OAAOD;YACX,GAAG,CAAC;YAEJ,OAAOF;QACX,GAAG,CAAC;QAEJ,OAAOF;IACX,GAAG,CAAC"}
|
package/events/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./abstractions.js\";\nexport * from \"./AuditLogBeforeCreateEvent.js\";\nexport * from \"./AuditLogAfterCreateEvent.js\";\nexport * from \"./AuditLogBeforeUpdateEvent.js\";\nexport * from \"./AuditLogAfterUpdateEvent.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["AccessPattern.ts"],"sourcesContent":["import type { IAuditLog, IStorageItem } from \"~/storage/types.js\";\nimport type { IStorageListParams } from \"./Storage.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface IAccessPatternCreateKeysResult {\n partitionKey: string;\n sortKey: string | number;\n}\n\nexport interface IAccessPatternListResult {\n items: IStorageItem[];\n lastEvaluatedKey?: GenericRecord;\n}\n\nexport type IAccessPatternHandlesKeys = keyof IStorageListParams;\n\nexport interface IAccessPatternHandles {\n shouldInclude?: IAccessPatternHandlesKeys[];\n mustInclude: IAccessPatternHandlesKeys[];\n mustNotInclude: IAccessPatternHandlesKeys[];\n}\n\nexport interface IAccessPattern<T> {\n index: string | undefined;\n handles(): IAccessPatternHandles;\n canHandle(params: IStorageListParams): boolean;\n list(params: T): Promise<IAccessPatternListResult>;\n createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["AccessPatternHandler.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IStorageItem } from \"../types.js\";\nimport type { IAccessPattern } from \"./AccessPattern.js\";\nimport type { IStorageListParams } from \"./Storage.js\";\n\nexport interface IAccessPatternHandlerHandleResult {\n items: IStorageItem[];\n lastEvaluatedKey?: GenericRecord;\n}\n\nexport interface IAccessPatternHandler {\n handle(params: IStorageListParams): Promise<IAccessPatternHandlerHandleResult>;\n getDefaultPattern(): IAccessPattern<unknown>;\n listIndexPatterns(): IAccessPattern<unknown>[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["Converter.ts"],"sourcesContent":["import type { IAuditLog, IStorageItem } from \"~/storage/types.js\";\n\nexport interface IConverter {\n oneFromStorage(item: IStorageItem): Promise<IAuditLog>;\n listFromStorage(items: IStorageItem[]): Promise<IAuditLog[]>;\n oneToStorage(auditLog: IAuditLog): Promise<IStorageItem>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["Storage.ts"],"sourcesContent":["import type { IAuditLog } from \"~/storage/types.js\";\n\nexport interface IStorageFetchParams {\n id: string;\n tenant: string;\n}\n\nexport interface IStorageFetchErrorResult {\n error: Error;\n data?: never;\n success: false;\n}\n\nexport interface IStorageFetchSuccessResult {\n data: IAuditLog;\n success: true;\n error?: never;\n}\n\nexport type IStorageFetchResult = IStorageFetchErrorResult | IStorageFetchSuccessResult;\n\nexport interface IStorageStoreParams {\n data: IAuditLog;\n}\n\nexport interface IStorageStoreErrorResult {\n error: Error;\n data?: never;\n success: false;\n}\n\nexport interface IStorageStoreSuccessResult {\n data: IAuditLog;\n success: true;\n error?: never;\n}\n\nexport type IStorageStoreResult = IStorageStoreErrorResult | IStorageStoreSuccessResult;\n\n// PK / SK\nexport interface IStorageListDefaultParams {\n tenant: string;\n sort?: \"ASC\" | \"DESC\";\n after?: string;\n limit: number | undefined;\n\n app?: never;\n createdBy?: never;\n action?: never;\n entityId?: never;\n}\n\n// GSI1_PK / GSI1_SK\nexport interface IStorageListByAppParams {\n tenant: string;\n app: string;\n after?: string;\n sort?: \"ASC\" | \"DESC\";\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n limit: number | undefined;\n\n entity?: never;\n createdBy?: never;\n action?: never;\n entityId?: never;\n}\n\n// GSI2_PK / GSI2_SK\nexport interface IStorageListByAppCreatedByParams\n extends Omit<IStorageListByAppParams, \"createdBy\"> {\n createdBy: string;\n}\n\n// GSI3_PK / GSI3_SK\nexport interface IStorageListByAppEntityParams extends Omit<IStorageListByAppParams, \"entity\"> {\n entity: string;\n}\n// GSI4_PK / GSI4_SK\nexport interface IStorageListByEntityIdParams extends Omit<IStorageListByAppParams, \"entityId\"> {\n entityId: string;\n}\n// GSI5_PK / GSI5_SK\nexport interface IStorageListByActionParams extends Omit<IStorageListByAppParams, \"action\"> {\n action: string;\n}\n\n// GSI6_PK / GSI6_SK\nexport interface IStorageListByAppEntityActionCreatedByParams\n extends Omit<IStorageListByAppParams, \"action\" | \"entity\" | \"createdBy\"> {\n createdBy: string;\n entity: string;\n action: string;\n}\n// GSI7_PK / GSI7_SK\nexport interface IStorageListByAppEntityActionParams\n extends Omit<IStorageListByAppParams, \"entity\" | \"action\"> {\n entity: string;\n action: string;\n}\n// GSI8_PK / GSI8_SK\nexport interface IStorageListByAppEntityCreatedByParams\n extends Omit<IStorageListByAppParams, \"createdBy\" | \"entity\"> {\n createdBy: string;\n entity: string;\n}\n\n// GSI9_PK / GSI9_SK\nexport interface IStorageListByCreatedByParams extends Omit<IStorageListByAppParams, \"createdBy\"> {\n createdBy: string;\n}\n\n// GSI10_PK / GSI10_SK\nexport interface IStorageListByCreatedOnParams extends IStorageListByAppParams {\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n}\n\nexport type IStorageListParams =\n | IStorageListByAppParams\n | IStorageListByAppCreatedByParams\n | IStorageListByAppEntityParams\n | IStorageListByEntityIdParams\n | IStorageListByActionParams\n | IStorageListByAppEntityActionCreatedByParams\n | IStorageListByAppEntityActionParams\n | IStorageListByAppEntityCreatedByParams\n | IStorageListByCreatedByParams\n | IStorageListByCreatedOnParams;\n\nexport interface IStorageListSuccessResultMeta {\n after?: string;\n hasMoreItems: boolean;\n}\n\nexport interface IStorageListSuccessResult {\n data: IAuditLog[];\n meta: IStorageListSuccessResultMeta;\n success: true;\n error?: never;\n}\n\nexport interface IStorageListErrorResult {\n error: Error;\n data?: never;\n meta?: never;\n success: false;\n}\n\nexport type IStorageListResult = IStorageListErrorResult | IStorageListSuccessResult;\n\nexport interface IStorage {\n fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;\n store(params: IStorageStoreParams): Promise<IStorageStoreResult>;\n list(params: IStorageListParams): Promise<IStorageListResult>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ListErrorResult.js\";\nexport * from \"./ListSuccessResult.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
|
package/storage/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface IAuditLogCreatedBy {\n id: string;\n type: string;\n displayName: string;\n}\n\nexport interface IAuditLog {\n id: string;\n tenant: string;\n createdBy: IAuditLogCreatedBy;\n createdOn: Date;\n app: string;\n action: string;\n message: string;\n entity: string;\n entityId: string;\n tags: string[];\n expiresAt: Date;\n content: string;\n}\n\nexport interface IStorageAuditLog extends Omit<IAuditLog, \"createdOn\" | \"content\" | \"expiresAt\"> {\n expiresAt: string;\n createdOn: string;\n content: string;\n}\n\nexport interface IStorageItem {\n PK: string;\n SK: string;\n TYPE: string;\n GSI_TENANT: string;\n GSI1_PK: string;\n GSI1_SK: number;\n GSI2_PK: string;\n GSI2_SK: number;\n GSI3_PK: string;\n GSI3_SK: number;\n GSI4_PK: string;\n GSI4_SK: number;\n GSI5_PK: string;\n GSI5_SK: number;\n GSI6_PK: string;\n GSI6_SK: number;\n GSI7_PK: string;\n GSI7_SK: number;\n GSI8_PK: string;\n GSI8_SK: number;\n GSI9_PK: string;\n GSI9_SK: number;\n\n data: IStorageAuditLog;\n expiresAt: number;\n}\n\nexport interface IIndexStorageItem {\n PK: string;\n SK: string;\n}\n"],"mappings":"","ignoreList":[]}
|
package/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { Action, App, Entity } from \"@webiny/common-audit-logs/types.js\";\nimport type { DbContext } from \"@webiny/handler-db/types.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport type { IStorageListParams } from \"~/storage/abstractions/Storage.js\";\n\nexport interface AuditLogPayload\n extends Omit<IAuditLog, \"id\" | \"tenant\" | \"createdOn\" | \"createdBy\" | \"expiresAt\" | \"content\"> {\n content: GenericRecord;\n}\n\nexport interface IListAuditLogsParams extends Omit<IStorageListParams, \"tenant\" | \"limit\" | \"app\"> {\n app?: string;\n limit?: number;\n}\n\nexport interface IListAuditLogsResultMeta {\n cursor: string | null;\n hasMoreItems: boolean;\n}\n\nexport interface IListAuditLogsSuccessResult {\n items: IAuditLog[];\n meta: IListAuditLogsResultMeta;\n error?: never;\n}\n\nexport interface IListAuditLogsErrorResult {\n items?: never;\n meta?: never;\n error: Error;\n}\n\nexport type IListAuditLogsResult = IListAuditLogsSuccessResult | IListAuditLogsErrorResult;\n\nexport interface AuditLogsContextValue {\n deleteLogsAfterDays: number | undefined;\n createAuditLog(payload: AuditLogPayload): Promise<IAuditLog>;\n updateAuditLog(original: IAuditLog, payload: Partial<AuditLogPayload>): Promise<IAuditLog>;\n getAuditLog(id: string): Promise<IAuditLog | null>;\n listAuditLogs(params: IListAuditLogsParams): Promise<IListAuditLogsResult>;\n}\n\nexport interface AuditLogsContext extends ApiCoreContext, Pick<DbContext, \"db\"> {\n auditLogs: AuditLogsContextValue;\n}\n\nexport interface AuditObject {\n [app: string]: EntityObject;\n}\n\nexport interface EntityObject {\n [entity: string]: ActionObject;\n}\n\nexport interface ActionObject {\n [action: string]: AuditAction;\n}\n\nexport interface AuditAction {\n app: App;\n entity: Entity;\n action: Action;\n}\n"],"mappings":"","ignoreList":[]}
|