@webiny/api-audit-logs 6.3.0 → 6.4.0-beta.1
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.js +115 -125
- package/context/AuditLogsContextValue.js.map +1 -1
- package/context/index.js +21 -27
- package/context/index.js.map +1 -1
- package/events/AuditLogAfterCreateEvent.js +8 -5
- package/events/AuditLogAfterCreateEvent.js.map +1 -1
- package/events/AuditLogAfterUpdateEvent.js +8 -5
- package/events/AuditLogAfterUpdateEvent.js.map +1 -1
- package/events/AuditLogBeforeCreateEvent.js +8 -5
- package/events/AuditLogBeforeCreateEvent.js.map +1 -1
- package/events/AuditLogBeforeUpdateEvent.js +8 -5
- package/events/AuditLogBeforeUpdateEvent.js.map +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 +3 -3
- 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 +26 -26
- package/storage/AccessPatternHandler.js +31 -52
- package/storage/AccessPatternHandler.js.map +1 -1
- package/storage/Converter.js +45 -48
- package/storage/Converter.js.map +1 -1
- 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 -70
- 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.js +26 -25
- package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js.map +1 -1
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js +29 -28
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js.map +1 -1
- package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js +32 -32
- 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.js +21 -20
- package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js +21 -20
- package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js +24 -24
- package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js +24 -24
- 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.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js +26 -29
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js +24 -27
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js +24 -24
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js.map +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.js +23 -22
- 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.js +31 -37
- package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js +31 -37
- package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js +35 -42
- package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js +24 -24
- package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js +24 -24
- package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js +24 -24
- 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.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js +23 -23
- package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js +23 -23
- package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js +20 -19
- package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js +20 -19
- package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js +20 -19
- package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js +23 -23
- 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
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 extends Omit<\n IStorageListByAppParams,\n \"createdBy\"\n> {\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 extends Omit<\n IStorageListByAppParams,\n \"action\" | \"entity\" | \"createdBy\"\n> {\n createdBy: string;\n entity: string;\n action: string;\n}\n// GSI7_PK / GSI7_SK\nexport interface IStorageListByAppEntityActionParams extends Omit<\n IStorageListByAppParams,\n \"entity\" | \"action\"\n> {\n entity: string;\n action: string;\n}\n// GSI8_PK / GSI8_SK\nexport interface IStorageListByAppEntityCreatedByParams extends Omit<\n IStorageListByAppParams,\n \"createdBy\" | \"entity\"\n> {\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 extends Omit<\n IAuditLog,\n \"id\" | \"tenant\" | \"createdOn\" | \"createdBy\" | \"expiresAt\" | \"content\"\n> {\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":[]}
|