@webiny/api-audit-logs 6.3.0 → 6.4.0-beta.0

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.
Files changed (196) hide show
  1. package/abstractions.js +2 -3
  2. package/abstractions.js.map +1 -1
  3. package/config.js +2 -1
  4. package/config.js.map +1 -1
  5. package/context/AuditLogsContextValue.js +115 -125
  6. package/context/AuditLogsContextValue.js.map +1 -1
  7. package/context/index.js +21 -27
  8. package/context/index.js.map +1 -1
  9. package/events/AuditLogAfterCreateEvent.js +8 -5
  10. package/events/AuditLogAfterCreateEvent.js.map +1 -1
  11. package/events/AuditLogAfterUpdateEvent.js +8 -5
  12. package/events/AuditLogAfterUpdateEvent.js.map +1 -1
  13. package/events/AuditLogBeforeCreateEvent.js +8 -5
  14. package/events/AuditLogBeforeCreateEvent.js.map +1 -1
  15. package/events/AuditLogBeforeUpdateEvent.js +8 -5
  16. package/events/AuditLogBeforeUpdateEvent.js.map +1 -1
  17. package/events/abstractions.js +5 -24
  18. package/events/abstractions.js.map +1 -1
  19. package/events/index.js +0 -2
  20. package/graphql/schema.js +37 -48
  21. package/graphql/schema.js.map +1 -1
  22. package/graphql/validation.d.ts +3 -3
  23. package/graphql/validation.js +26 -30
  24. package/graphql/validation.js.map +1 -1
  25. package/index.js +18 -15
  26. package/index.js.map +1 -1
  27. package/package.json +26 -26
  28. package/storage/AccessPatternHandler.js +31 -52
  29. package/storage/AccessPatternHandler.js.map +1 -1
  30. package/storage/Converter.js +45 -48
  31. package/storage/Converter.js.map +1 -1
  32. package/storage/Storage.js +69 -77
  33. package/storage/Storage.js.map +1 -1
  34. package/storage/abstractions/AccessPattern.js +0 -3
  35. package/storage/abstractions/AccessPatternHandler.js +0 -3
  36. package/storage/abstractions/Converter.js +0 -3
  37. package/storage/abstractions/Storage.js +0 -3
  38. package/storage/accessPatterns/AppAccessPattern.js +31 -25
  39. package/storage/accessPatterns/AppAccessPattern.js.map +1 -1
  40. package/storage/accessPatterns/AppCreatedByAccessPattern.js +34 -28
  41. package/storage/accessPatterns/AppCreatedByAccessPattern.js.map +1 -1
  42. package/storage/accessPatterns/AppEntityAccessPattern.js +31 -25
  43. package/storage/accessPatterns/AppEntityAccessPattern.js.map +1 -1
  44. package/storage/accessPatterns/AppEntityActionAccessPattern.js +31 -25
  45. package/storage/accessPatterns/AppEntityActionAccessPattern.js.map +1 -1
  46. package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js +34 -28
  47. package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js.map +1 -1
  48. package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js +34 -28
  49. package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js.map +1 -1
  50. package/storage/accessPatterns/BaseAccessPattern.js +47 -70
  51. package/storage/accessPatterns/BaseAccessPattern.js.map +1 -1
  52. package/storage/accessPatterns/CreatedByAccessPattern.js +34 -28
  53. package/storage/accessPatterns/CreatedByAccessPattern.js.map +1 -1
  54. package/storage/accessPatterns/CreatedOnAccessPattern.js +34 -26
  55. package/storage/accessPatterns/CreatedOnAccessPattern.js.map +1 -1
  56. package/storage/accessPatterns/DefaultAccessPattern.js +31 -32
  57. package/storage/accessPatterns/DefaultAccessPattern.js.map +1 -1
  58. package/storage/accessPatterns/EntityIdAccessPattern.js +32 -27
  59. package/storage/accessPatterns/EntityIdAccessPattern.js.map +1 -1
  60. package/storage/accessPatterns/index.js +44 -34
  61. package/storage/accessPatterns/index.js.map +1 -1
  62. package/storage/cursorSchema.js +15 -18
  63. package/storage/cursorSchema.js.map +1 -1
  64. package/storage/entity.js +115 -122
  65. package/storage/entity.js.map +1 -1
  66. package/storage/results/ListErrorResult.js +9 -8
  67. package/storage/results/ListErrorResult.js.map +1 -1
  68. package/storage/results/ListSuccessResult.js +13 -12
  69. package/storage/results/ListSuccessResult.js.map +1 -1
  70. package/storage/results/index.js +0 -2
  71. package/storage/startKey.js +4 -5
  72. package/storage/startKey.js.map +1 -1
  73. package/storage/types.js +0 -3
  74. package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js +26 -25
  75. package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js.map +1 -1
  76. package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js +29 -28
  77. package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js.map +1 -1
  78. package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js +32 -32
  79. package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js.map +1 -1
  80. package/subscriptions/aco/index.js +5 -4
  81. package/subscriptions/aco/index.js.map +1 -1
  82. package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js +21 -20
  83. package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js.map +1 -1
  84. package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js +21 -20
  85. package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js.map +1 -1
  86. package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js +24 -24
  87. package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js.map +1 -1
  88. package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js +24 -24
  89. package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js.map +1 -1
  90. package/subscriptions/fileManager/index.js +6 -8
  91. package/subscriptions/fileManager/index.js.map +1 -1
  92. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.js +21 -23
  93. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.js.map +1 -1
  94. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js +26 -29
  95. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js.map +1 -1
  96. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js +21 -23
  97. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js.map +1 -1
  98. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js +21 -23
  99. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js.map +1 -1
  100. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js +21 -23
  101. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js.map +1 -1
  102. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js +24 -27
  103. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js.map +1 -1
  104. package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js +21 -23
  105. package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js.map +1 -1
  106. package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js +21 -23
  107. package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js.map +1 -1
  108. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js +21 -20
  109. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js.map +1 -1
  110. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js +21 -20
  111. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js.map +1 -1
  112. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js +24 -24
  113. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js.map +1 -1
  114. package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js +21 -20
  115. package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js.map +1 -1
  116. package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js +21 -20
  117. package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js.map +1 -1
  118. package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.js +24 -24
  119. package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.js.map +1 -1
  120. package/subscriptions/headlessCms/index.js +16 -20
  121. package/subscriptions/headlessCms/index.js.map +1 -1
  122. package/subscriptions/index.js +8 -7
  123. package/subscriptions/index.js.map +1 -1
  124. package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js +23 -22
  125. package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js.map +1 -1
  126. package/subscriptions/mailer/index.js +3 -3
  127. package/subscriptions/mailer/index.js.map +1 -1
  128. package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js +31 -37
  129. package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js.map +1 -1
  130. package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js +31 -37
  131. package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js.map +1 -1
  132. package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js +35 -42
  133. package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js.map +1 -1
  134. package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js +21 -20
  135. package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js.map +1 -1
  136. package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js +21 -20
  137. package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js.map +1 -1
  138. package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js +24 -24
  139. package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js.map +1 -1
  140. package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js +21 -20
  141. package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js.map +1 -1
  142. package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js +21 -20
  143. package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js.map +1 -1
  144. package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js +24 -24
  145. package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js.map +1 -1
  146. package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js +21 -20
  147. package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js.map +1 -1
  148. package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js +21 -20
  149. package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js.map +1 -1
  150. package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js +24 -24
  151. package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js.map +1 -1
  152. package/subscriptions/security/handlers/cleanupApiKey.js +10 -16
  153. package/subscriptions/security/handlers/cleanupApiKey.js.map +1 -1
  154. package/subscriptions/security/index.js +14 -20
  155. package/subscriptions/security/index.js.map +1 -1
  156. package/subscriptions/websiteBuilder/index.js +14 -16
  157. package/subscriptions/websiteBuilder/index.js.map +1 -1
  158. package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js +20 -19
  159. package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js.map +1 -1
  160. package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js +20 -19
  161. package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js.map +1 -1
  162. package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js +20 -19
  163. package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js.map +1 -1
  164. package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js +23 -23
  165. package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js.map +1 -1
  166. package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js +20 -19
  167. package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js.map +1 -1
  168. package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js +20 -19
  169. package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js.map +1 -1
  170. package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js +20 -19
  171. package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js.map +1 -1
  172. package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js +23 -23
  173. package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js.map +1 -1
  174. package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js +20 -19
  175. package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js.map +1 -1
  176. package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js +20 -19
  177. package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js.map +1 -1
  178. package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js +20 -19
  179. package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js.map +1 -1
  180. package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js +23 -23
  181. package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js.map +1 -1
  182. package/types.js +0 -3
  183. package/utils/expiresAt.js +14 -19
  184. package/utils/expiresAt.js.map +1 -1
  185. package/utils/getAuditConfig.js +79 -98
  186. package/utils/getAuditConfig.js.map +1 -1
  187. package/utils/getAuditObject.js +14 -15
  188. package/utils/getAuditObject.js.map +1 -1
  189. package/events/index.js.map +0 -1
  190. package/storage/abstractions/AccessPattern.js.map +0 -1
  191. package/storage/abstractions/AccessPatternHandler.js.map +0 -1
  192. package/storage/abstractions/Converter.js.map +0 -1
  193. package/storage/abstractions/Storage.js.map +0 -1
  194. package/storage/results/index.js.map +0 -1
  195. package/storage/types.js.map +0 -1
  196. package/types.js.map +0 -1
@@ -1,105 +1,86 @@
1
- import WebinyError from "@webiny/error";
2
- const createAuditLog = async params => {
3
- const {
4
- context,
5
- payload
6
- } = params;
7
- try {
8
- return await context.auditLogs.createAuditLog(payload);
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
- if (!delay) {
15
- return undefined;
16
- }
17
- const date = new Date();
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
- const {
23
- context,
24
- payload,
25
- delay
26
- } = params;
27
- const results = await context.auditLogs.listAuditLogs({
28
- app: payload.app,
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
- } catch (ex) {
57
- throw WebinyError.from(ex);
58
- }
59
- };
60
- export const getAuditConfig = audit => {
61
- return async (message, content, entityId, context) => {
62
- if (!context.auditLogs) {
63
- console.log("No AuditLogs defined.");
64
- return null;
65
- } else if (!audit) {
66
- console.log(`No Audit Action defined!`);
67
- return null;
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,"names":["WebinyError","createAuditLog","params","context","payload","auditLogs","error","from","createAuditLogDelayDate","delay","undefined","date","Date","setTime","getTime","createOrMergeAuditLog","results","listAuditLogs","app","entityId","limit","createdOn_gte","sort","original","items","beforePayloadData","content","JSON","parse","before","afterPayloadData","after","updatedPayloadData","updateAuditLog","ex","getAuditConfig","audit","message","console","log","entity","type","action","tags","newEntryDelay","security","getIdentity","id","withoutAuthorization"],"sources":["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"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAUvC,MAAMC,cAAc,GAAG,MAAOC,MAA4B,IAAyB;EAC/E,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEnC,IAAI;IACA,OAAO,MAAMC,OAAO,CA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C,OAAO,CAAC0C,QAAQ,CAACG,oBAAoB,CAAC,YAAY;MAC3D;MACA,IAAIvC,KAAK,GAAG,CAAC,EAAE;QACX,IAAI;UACA,OAAO,MAAMM,qBAAqB,CAAC;YAC/BZ,OAAO;YACPC,OAAO;YACPK;UACJ,CAAC,CAAC;QACN,CAAC,CAAC,MAAM;UACJ;QAAA;QAEJ,OAAO,IAAI;MACf;MACA,OAAO,MAAMR,cAAc,CAAC;QACxBE,OAAO;QACPC;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
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,MAA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BG;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"}
@@ -1,18 +1,17 @@
1
- export const getAuditObject = apps => {
2
- return apps.reduce((result, app) => {
3
- result[app.app] = app.entities.reduce((entities, entity) => {
4
- entities[entity.type] = entity.actions.reduce((actions, action) => {
5
- actions[action.type] = {
6
- app,
7
- entity,
8
- action
9
- };
10
- return actions;
11
- }, {});
12
- return entities;
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
- return result;
15
- }, {});
16
- };
15
+ export { getAuditObject };
17
16
 
18
17
  //# sourceMappingURL=getAuditObject.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getAuditObject","apps","reduce","result","app","entities","entity","type","actions","action"],"sources":["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"],"mappings":"AAGA,OAAO,MAAMA,cAAc,GAAIC,IAAW,IAAK;EAC3C,OAAOA,IAAI,CAACC,MAAM,CAAc,CAACC,MAAM,EAAEC,GAAG,KAAK;IAC7CD,MAAM,CAACC,GAAG,CAACA,GAAG,CAAC,GAAGA,GAAG,CAACC,QAAQ,CAACH,MAAM,CAAe,CAACG,QAAQ,EAAEC,MAAM,KAAK;MACtED,QAAQ,CAACC,MAAM,CAACC,IAAI,CAAC,GAAGD,MAAM,CAACE,OAAO,CAACN,MAAM,CAAe,CAACM,OAAO,EAAEC,MAAM,KAAK;QAC7ED,OAAO,CAACC,MAAM,CAACF,IAAI,CAAC,GAAG;UACnBH,GAAG;UACHE,MAAM;UACNG;QACJ,CAAC;QAED,OAAOD,OAAO;MAClB,CAAC,EAAE,CAAC,CAAC,CAAC;MAEN,OAAOH,QAAQ;IACnB,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,OAAOF,MAAM;EACjB,CAAC,EAAE,CAAC,CAAC,CAAC;AACV,CAAC","ignoreList":[]}
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"}
@@ -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":[]}
@@ -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":[]}