@webiny/api-audit-logs 0.0.0-unstable.e622468070 → 0.0.0-unstable.e6f0dc8ca7

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 (143) hide show
  1. package/context/AuditLogsContextValue.d.ts +1 -1
  2. package/context/AuditLogsContextValue.js.map +1 -1
  3. package/context/index.js +4 -2
  4. package/context/index.js.map +1 -1
  5. package/events/AuditLogAfterCreateEvent.d.ts +2 -2
  6. package/events/AuditLogAfterCreateEvent.js +1 -1
  7. package/events/AuditLogAfterCreateEvent.js.map +1 -1
  8. package/events/AuditLogAfterUpdateEvent.d.ts +2 -2
  9. package/events/AuditLogAfterUpdateEvent.js +1 -1
  10. package/events/AuditLogAfterUpdateEvent.js.map +1 -1
  11. package/events/AuditLogBeforeCreateEvent.d.ts +2 -2
  12. package/events/AuditLogBeforeCreateEvent.js +1 -1
  13. package/events/AuditLogBeforeCreateEvent.js.map +1 -1
  14. package/events/AuditLogBeforeUpdateEvent.d.ts +2 -2
  15. package/events/AuditLogBeforeUpdateEvent.js +1 -1
  16. package/events/AuditLogBeforeUpdateEvent.js.map +1 -1
  17. package/events/abstractions.d.ts +1 -1
  18. package/events/abstractions.js.map +1 -1
  19. package/graphql/validation.d.ts +10 -53
  20. package/index.js.map +1 -1
  21. package/package.json +31 -28
  22. package/storage/Converter.d.ts +3 -3
  23. package/storage/Converter.js +3 -3
  24. package/storage/Converter.js.map +1 -1
  25. package/storage/Storage.d.ts +2 -2
  26. package/storage/Storage.js +1 -1
  27. package/storage/Storage.js.map +1 -1
  28. package/storage/abstractions/Storage.js.map +1 -1
  29. package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js.map +1 -1
  30. package/storage/accessPatterns/BaseAccessPattern.js +1 -0
  31. package/storage/accessPatterns/BaseAccessPattern.js.map +1 -1
  32. package/storage/entity.js.map +1 -1
  33. package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.d.ts +4 -4
  34. package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js +2 -2
  35. package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js.map +1 -1
  36. package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.d.ts +4 -4
  37. package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js +2 -2
  38. package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js.map +1 -1
  39. package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.d.ts +4 -4
  40. package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js +2 -2
  41. package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js.map +1 -1
  42. package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.d.ts +4 -4
  43. package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js +2 -2
  44. package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js.map +1 -1
  45. package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.d.ts +4 -4
  46. package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js +2 -2
  47. package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js.map +1 -1
  48. package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.d.ts +4 -4
  49. package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js +2 -2
  50. package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js.map +1 -1
  51. package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.d.ts +4 -4
  52. package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js +2 -2
  53. package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js.map +1 -1
  54. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.d.ts +1 -1
  55. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.d.ts +1 -1
  56. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.d.ts +1 -1
  57. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.d.ts +1 -1
  58. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.d.ts +1 -1
  59. package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.d.ts +1 -1
  60. package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.d.ts +1 -1
  61. package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.d.ts +1 -1
  62. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.d.ts +1 -1
  63. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.d.ts +1 -1
  64. package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.d.ts +1 -1
  65. package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.d.ts +1 -1
  66. package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.d.ts +1 -1
  67. package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.d.ts +1 -1
  68. package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.d.ts +4 -4
  69. package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js +2 -2
  70. package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js.map +1 -1
  71. package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.d.ts +4 -4
  72. package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js +2 -2
  73. package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js.map +1 -1
  74. package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.d.ts +4 -4
  75. package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js +2 -2
  76. package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js.map +1 -1
  77. package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.d.ts +4 -4
  78. package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js +2 -2
  79. package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js.map +1 -1
  80. package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.d.ts +4 -4
  81. package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js +2 -2
  82. package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js.map +1 -1
  83. package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.d.ts +4 -4
  84. package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js +2 -2
  85. package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js.map +1 -1
  86. package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.d.ts +4 -4
  87. package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js +2 -2
  88. package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js.map +1 -1
  89. package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.d.ts +4 -4
  90. package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js +2 -2
  91. package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js.map +1 -1
  92. package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.d.ts +4 -4
  93. package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js +2 -2
  94. package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js.map +1 -1
  95. package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.d.ts +4 -4
  96. package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js +2 -2
  97. package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js.map +1 -1
  98. package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.d.ts +4 -4
  99. package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js +2 -2
  100. package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js.map +1 -1
  101. package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.d.ts +4 -4
  102. package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js +2 -2
  103. package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js.map +1 -1
  104. package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.d.ts +4 -4
  105. package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js +2 -2
  106. package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js.map +1 -1
  107. package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.d.ts +4 -4
  108. package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js +3 -3
  109. package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js.map +1 -1
  110. package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.d.ts +4 -4
  111. package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js +3 -3
  112. package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js.map +1 -1
  113. package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.d.ts +4 -4
  114. package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js +3 -3
  115. package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js.map +1 -1
  116. package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.d.ts +4 -4
  117. package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js +3 -3
  118. package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js.map +1 -1
  119. package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.d.ts +4 -4
  120. package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js +3 -3
  121. package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js.map +1 -1
  122. package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.d.ts +4 -4
  123. package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js +3 -3
  124. package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js.map +1 -1
  125. package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.d.ts +4 -4
  126. package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js +3 -3
  127. package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js.map +1 -1
  128. package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.d.ts +4 -4
  129. package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js +3 -3
  130. package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js.map +1 -1
  131. package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.d.ts +4 -4
  132. package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js +3 -3
  133. package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js.map +1 -1
  134. package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.d.ts +4 -4
  135. package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js +3 -3
  136. package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js.map +1 -1
  137. package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.d.ts +4 -4
  138. package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js +3 -3
  139. package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js.map +1 -1
  140. package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.d.ts +4 -4
  141. package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js +3 -3
  142. package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js.map +1 -1
  143. package/types.js.map +1 -1
@@ -1,6 +1,6 @@
1
1
  import type { AuditLogsContext, AuditLogsContextValue } from "../types.js";
2
2
  import type { IStorage } from "../storage/abstractions/Storage.js";
3
- import type { EventPublisher } from "@webiny/api-core/features/EventPublisher";
3
+ import type { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
4
4
  export interface IAuditLogsContextValueParams {
5
5
  getContext: () => AuditLogsContext;
6
6
  deleteLogsAfterDays: number;
@@ -1 +1 @@
1
- {"version":3,"names":["convertExpiresAtDaysToDate","mdbid","NotAuthorizedError","AuditLogBeforeCreateEvent","AuditLogAfterCreateEvent","AuditLogBeforeUpdateEvent","AuditLogAfterUpdateEvent","AuditLogsContextValueImpl","constructor","params","getContext","deleteLogsAfterDays","storage","eventPublisher","createAuditLog","payload","context","expiresAt","auditLog","id","tenant","getTenantId","createdBy","getIdentity","createdOn","Date","content","JSON","stringify","checkPermissions","beforeCreateEvent","setAuditLog","input","Object","assign","publish","result","store","data","success","afterCreateEvent","error","updateAuditLog","original","beforeUpdateEvent","afterUpdateEvent","getAuditLog","fetch","listAuditLogs","list","items","meta","cursor","after","hasMoreItems","action","Error","permissions","security","getPermissions","permission","name","message","tenancy","getCurrentTenant","identity","type","displayName","createAuditLogsContextValue"],"sources":["AuditLogsContextValue.ts"],"sourcesContent":["import type {\n AuditLogPayload,\n AuditLogsContext,\n AuditLogsContextValue,\n IListAuditLogsParams,\n IListAuditLogsResult\n} from \"~/types.js\";\nimport { convertExpiresAtDaysToDate } from \"~/utils/expiresAt.js\";\nimport type { IAuditLog, IAuditLogCreatedBy } from \"~/storage/types.js\";\nimport { mdbid } from \"@webiny/utils/mdbid.js\";\nimport type { IStorage, IStorageListParams } from \"~/storage/abstractions/Storage.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport type { EventPublisher } from \"@webiny/api-core/features/EventPublisher\";\nimport {\n AuditLogBeforeCreateEvent,\n AuditLogAfterCreateEvent,\n AuditLogBeforeUpdateEvent,\n AuditLogAfterUpdateEvent\n} from \"~/events/index.js\";\n\nexport interface IAuditLogsContextValueParams {\n getContext: () => AuditLogsContext;\n deleteLogsAfterDays: number;\n storage: IStorage;\n eventPublisher: EventPublisher.Interface;\n}\n\nclass AuditLogsContextValueImpl implements AuditLogsContextValue {\n private readonly getContext;\n public readonly deleteLogsAfterDays;\n private readonly storage: IStorage;\n private readonly eventPublisher: EventPublisher.Interface;\n\n public constructor(params: IAuditLogsContextValueParams) {\n this.getContext = params.getContext;\n this.deleteLogsAfterDays = params.deleteLogsAfterDays;\n this.storage = params.storage;\n this.eventPublisher = params.eventPublisher;\n }\n\n public async createAuditLog(payload: AuditLogPayload): Promise<IAuditLog> {\n const context = this.getContext();\n const expiresAt = convertExpiresAtDaysToDate(this.deleteLogsAfterDays);\n\n const auditLog: IAuditLog = {\n id: mdbid(),\n tenant: this.getTenantId(),\n createdBy: this.getIdentity(),\n createdOn: new Date(),\n ...payload,\n content: JSON.stringify(payload.content),\n expiresAt\n };\n await this.checkPermissions(auditLog);\n\n const beforeCreateEvent = new AuditLogBeforeCreateEvent({\n auditLog: auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeCreateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterCreateEvent = new AuditLogAfterCreateEvent({\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterCreateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async updateAuditLog(\n original: IAuditLog,\n payload: Partial<AuditLogPayload>\n ): Promise<IAuditLog> {\n const context = this.getContext();\n const auditLog: IAuditLog = {\n ...original,\n ...payload,\n content: payload.content ? JSON.stringify(payload.content) : original.content\n };\n await this.checkPermissions(auditLog);\n\n const beforeUpdateEvent = new AuditLogBeforeUpdateEvent({\n original,\n auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeUpdateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterUpdateEvent = new AuditLogAfterUpdateEvent({\n original: original,\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterUpdateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async getAuditLog(id: string): Promise<IAuditLog | null> {\n const result = await this.storage.fetch({\n id,\n tenant: this.getTenantId()\n });\n if (result.success) {\n await this.checkPermissions(result.data);\n return result.data;\n }\n throw result.error;\n }\n\n public async listAuditLogs(params: IListAuditLogsParams): Promise<IListAuditLogsResult> {\n const result = await this.storage.list({\n ...params,\n tenant: this.getTenantId()\n } as unknown as IStorageListParams);\n if (result.success) {\n return {\n items: result.data,\n meta: {\n cursor: result.meta.after || null,\n hasMoreItems: result.meta.hasMoreItems\n }\n };\n }\n throw result.error;\n }\n\n private async checkPermissions(auditLog: Pick<IAuditLog, \"action\">): Promise<void> {\n if (!auditLog.action) {\n throw new Error(\"Audit log action is not defined. Cannot check permissions.\");\n }\n const permissions = await this.getContext().security.getPermissions(\"al.*\");\n for (const permission of permissions) {\n if (permission.name === \"*\") {\n return;\n }\n if (permission.name === \"al.*\") {\n return;\n } else if (permission.name === `al.${auditLog.action}`) {\n return;\n }\n }\n\n throw new NotAuthorizedError({\n message: \"You cannot access audit logs.\"\n });\n }\n\n private getTenantId(): string {\n return this.getContext().tenancy.getCurrentTenant().id;\n }\n\n private getIdentity(): IAuditLogCreatedBy {\n const identity = this.getContext().security.getIdentity();\n return {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName || \"unknown\"\n };\n }\n}\n\nexport const createAuditLogsContextValue = (\n params: IAuditLogsContextValueParams\n): AuditLogsContextValue => {\n return new AuditLogsContextValueImpl(params);\n};\n"],"mappings":"AAOA,SAASA,0BAA0B;AAEnC,SAASC,KAAK,QAAQ,wBAAwB;AAE9C,SAASC,kBAAkB,QAAQ,oDAAoD;AAEvF,SACIC,yBAAyB,EACzBC,wBAAwB,EACxBC,yBAAyB,EACzBC,wBAAwB;AAU5B,MAAMC,yBAAyB,CAAkC;EAMtDC,WAAWA,CAACC,MAAoC,EAAE;IACrD,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,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K,MAAM3C,QAAQ,CAACqC,MAAM,EAAE,EAAE;QACpD;MACJ;IACJ;IAEA,MAAM,IAAIrD,kBAAkB,CAAC;MACzB4D,OAAO,EAAE;IACb,CAAC,CAAC;EACN;EAEQzC,WAAWA,CAAA,EAAW;IAC1B,OAAO,IAAI,CAACX,UAAU,CAAC,CAAC,CAACqD,OAAO,CAACC,gBAAgB,CAAC,CAAC,CAAC7C,EAAE;EAC1D;EAEQI,WAAWA,CAAA,EAAuB;IACtC,MAAM0C,QAAQ,GAAG,IAAI,CAACvD,UAAU,CAAC,CAAC,CAACgD,QAAQ,CAACnC,WAAW,CAAC,CAAC;IACzD,OAAO;MACHJ,EAAE,EAAE8C,QAAQ,CAAC9C,EAAE;MACf+C,IAAI,EAAED,QAAQ,CAACC,IAAI;MACnBC,WAAW,EAAEF,QAAQ,CAACE,WAAW,IAAI;IACzC,CAAC;EACL;AACJ;AAEA,OAAO,MAAMC,2BAA2B,GACpC3D,MAAoC,IACZ;EACxB,OAAO,IAAIF,yBAAyB,CAACE,MAAM,CAAC;AAChD,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["convertExpiresAtDaysToDate","mdbid","NotAuthorizedError","AuditLogBeforeCreateEvent","AuditLogAfterCreateEvent","AuditLogBeforeUpdateEvent","AuditLogAfterUpdateEvent","AuditLogsContextValueImpl","constructor","params","getContext","deleteLogsAfterDays","storage","eventPublisher","createAuditLog","payload","context","expiresAt","auditLog","id","tenant","getTenantId","createdBy","getIdentity","createdOn","Date","content","JSON","stringify","checkPermissions","beforeCreateEvent","setAuditLog","input","Object","assign","publish","result","store","data","success","afterCreateEvent","error","updateAuditLog","original","beforeUpdateEvent","afterUpdateEvent","getAuditLog","fetch","listAuditLogs","list","items","meta","cursor","after","hasMoreItems","action","Error","permissions","security","getPermissions","permission","name","message","tenancy","getCurrentTenant","identity","type","displayName","createAuditLogsContextValue"],"sources":["AuditLogsContextValue.ts"],"sourcesContent":["import type {\n AuditLogPayload,\n AuditLogsContext,\n AuditLogsContextValue,\n IListAuditLogsParams,\n IListAuditLogsResult\n} from \"~/types.js\";\nimport { convertExpiresAtDaysToDate } from \"~/utils/expiresAt.js\";\nimport type { IAuditLog, IAuditLogCreatedBy } from \"~/storage/types.js\";\nimport { mdbid } from \"@webiny/utils/mdbid.js\";\nimport type { IStorage, IStorageListParams } from \"~/storage/abstractions/Storage.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport type { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n AuditLogBeforeCreateEvent,\n AuditLogAfterCreateEvent,\n AuditLogBeforeUpdateEvent,\n AuditLogAfterUpdateEvent\n} from \"~/events/index.js\";\n\nexport interface IAuditLogsContextValueParams {\n getContext: () => AuditLogsContext;\n deleteLogsAfterDays: number;\n storage: IStorage;\n eventPublisher: EventPublisher.Interface;\n}\n\nclass AuditLogsContextValueImpl implements AuditLogsContextValue {\n private readonly getContext;\n public readonly deleteLogsAfterDays;\n private readonly storage: IStorage;\n private readonly eventPublisher: EventPublisher.Interface;\n\n public constructor(params: IAuditLogsContextValueParams) {\n this.getContext = params.getContext;\n this.deleteLogsAfterDays = params.deleteLogsAfterDays;\n this.storage = params.storage;\n this.eventPublisher = params.eventPublisher;\n }\n\n public async createAuditLog(payload: AuditLogPayload): Promise<IAuditLog> {\n const context = this.getContext();\n const expiresAt = convertExpiresAtDaysToDate(this.deleteLogsAfterDays);\n\n const auditLog: IAuditLog = {\n id: mdbid(),\n tenant: this.getTenantId(),\n createdBy: this.getIdentity(),\n createdOn: new Date(),\n ...payload,\n content: JSON.stringify(payload.content),\n expiresAt\n };\n await this.checkPermissions(auditLog);\n\n const beforeCreateEvent = new AuditLogBeforeCreateEvent({\n auditLog: auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeCreateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterCreateEvent = new AuditLogAfterCreateEvent({\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterCreateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async updateAuditLog(\n original: IAuditLog,\n payload: Partial<AuditLogPayload>\n ): Promise<IAuditLog> {\n const context = this.getContext();\n const auditLog: IAuditLog = {\n ...original,\n ...payload,\n content: payload.content ? JSON.stringify(payload.content) : original.content\n };\n await this.checkPermissions(auditLog);\n\n const beforeUpdateEvent = new AuditLogBeforeUpdateEvent({\n original,\n auditLog,\n context,\n setAuditLog(input) {\n Object.assign(auditLog, input);\n }\n });\n await this.eventPublisher.publish(beforeUpdateEvent);\n\n const result = await this.storage.store({\n data: auditLog\n });\n if (result.success) {\n const afterUpdateEvent = new AuditLogAfterUpdateEvent({\n original: original,\n auditLog: auditLog,\n context\n });\n await this.eventPublisher.publish(afterUpdateEvent);\n return result.data;\n }\n throw result.error;\n }\n\n public async getAuditLog(id: string): Promise<IAuditLog | null> {\n const result = await this.storage.fetch({\n id,\n tenant: this.getTenantId()\n });\n if (result.success) {\n await this.checkPermissions(result.data);\n return result.data;\n }\n throw result.error;\n }\n\n public async listAuditLogs(params: IListAuditLogsParams): Promise<IListAuditLogsResult> {\n const result = await this.storage.list({\n ...params,\n tenant: this.getTenantId()\n } as unknown as IStorageListParams);\n if (result.success) {\n return {\n items: result.data,\n meta: {\n cursor: result.meta.after || null,\n hasMoreItems: result.meta.hasMoreItems\n }\n };\n }\n throw result.error;\n }\n\n private async checkPermissions(auditLog: Pick<IAuditLog, \"action\">): Promise<void> {\n if (!auditLog.action) {\n throw new Error(\"Audit log action is not defined. Cannot check permissions.\");\n }\n const permissions = await this.getContext().security.getPermissions(\"al.*\");\n for (const permission of permissions) {\n if (permission.name === \"*\") {\n return;\n }\n if (permission.name === \"al.*\") {\n return;\n } else if (permission.name === `al.${auditLog.action}`) {\n return;\n }\n }\n\n throw new NotAuthorizedError({\n message: \"You cannot access audit logs.\"\n });\n }\n\n private getTenantId(): string {\n return this.getContext().tenancy.getCurrentTenant().id;\n }\n\n private getIdentity(): IAuditLogCreatedBy {\n const identity = this.getContext().security.getIdentity();\n return {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName || \"unknown\"\n };\n }\n}\n\nexport const createAuditLogsContextValue = (\n params: IAuditLogsContextValueParams\n): AuditLogsContextValue => {\n return new AuditLogsContextValueImpl(params);\n};\n"],"mappings":"AAOA,SAASA,0BAA0B;AAEnC,SAASC,KAAK,QAAQ,wBAAwB;AAE9C,SAASC,kBAAkB,QAAQ,oDAAoD;AAEvF,SACIC,yBAAyB,EACzBC,wBAAwB,EACxBC,yBAAyB,EACzBC,wBAAwB;AAU5B,MAAMC,yBAAyB,CAAkC;EAMtDC,WAAWA,CAACC,MAAoC,EAAE;IACrD,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;IACnC,IAAI,CAACC,mBAAmB,GAAGF,MAAM,CAACE,mBAAmB;IACrD,IAAI,CAACC,OAAO,GAAGH,MAAM,CAACG,OAAO;IAC7B,IAAI,CAACC,cAAc,GAAGJ,MAAM,CAACI,cAAc;EAC/C;EAEA,MAAaC,cAAcA,CAACC,OAAwB,EAAsB;IACtE,MAAMC,OAAO,GAAG,IAAI,CAACN,UAAU,CAAC,CAAC;IACjC,MAAMO,SAAS,GAAGjB,0BAA0B,CAAC,IAAI,CAACW,mBAAmB,CAAC;IAEtE,MAAMO,QAAmB,GAAG;MACxBC,EAAE,EAAElB,KAAK,CAAC,CAAC;MACXmB,MAAM,EAAE,IAAI,CAACC,WAAW,CAAC,CAAC;MAC1BC,SAAS,EAAE,IAAI,CAACC,WAAW,CAAC,CAAC;MAC7BC,SAAS,EAAE,IAAIC,IAAI,CAAC,CAAC;MACrB,GAAGV,OAAO;MACVW,OAAO,EAAEC,IAAI,CAACC,SAAS,CAACb,OAAO,CAACW,OAAO,CAAC;MACxCT;IACJ,CAAC;IACD,MAAM,IAAI,CAACY,gBAAgB,CAACX,QAAQ,CAAC;IAErC,MAAMY,iBAAiB,GAAG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ugin } from "@webiny/api";
2
- import { EventPublisher } from "@webiny/api-core/features/EventPublisher";
2
+ import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
3
3
  import { createAuditLogsContextValue } from "./AuditLogsContextValue.js";
4
4
  import { createStorage } from "../storage/Storage.js";
5
+ import { CompressionHandler } from "@webiny/utils/exports/api.js";
5
6
  const getDeleteLogsAfterDays = days => {
6
7
  if (days && days > 0) {
7
8
  return days;
@@ -13,10 +14,11 @@ const getDeleteLogsAfterDays = days => {
13
14
  };
14
15
  export const createAuditLogsContext = params => {
15
16
  const plugin = new ContextPlugin(async context => {
17
+ const compressionHandler = context.container.resolve(CompressionHandler);
16
18
  const storage = createStorage({
17
19
  tableName: params?.tableName,
18
20
  client: params?.documentClient || context.db.driver.getClient(),
19
- compressor: context.compressor
21
+ compressionHandler
20
22
  });
21
23
  const eventPublisher = context.container.resolve(EventPublisher);
22
24
  context.auditLogs = createAuditLogsContextValue({
@@ -1 +1 @@
1
- {"version":3,"names":["ContextPlugin","EventPublisher","createAuditLogsContextValue","createStorage","getDeleteLogsAfterDays","days","createAuditLogsContext","params","plugin","context","storage","tableName","client","documentClient","db","driver","getClient","compressor","eventPublisher","container","resolve","auditLogs","getContext","deleteLogsAfterDays","name"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/EventPublisher\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\nimport { createAuditLogsContextValue } from \"./AuditLogsContextValue.js\";\nimport { createStorage } from \"~/storage/Storage.js\";\n\nexport interface ISetupContextOptions {\n deleteLogsAfterDays: number | undefined;\n tableName: string | undefined;\n documentClient: DynamoDBDocument | undefined;\n}\n\nconst getDeleteLogsAfterDays = (days?: number): number => {\n if (days && days > 0) {\n return days;\n }\n /**\n * Default days to delete logs after.\n */\n return 60;\n};\n\nexport const createAuditLogsContext = (params?: ISetupContextOptions) => {\n const plugin = new ContextPlugin<AuditLogsContext>(async context => {\n const storage = createStorage({\n tableName: params?.tableName,\n client: params?.documentClient || (context.db.driver.getClient() as DynamoDBDocument),\n compressor: context.compressor\n });\n\n const eventPublisher = context.container.resolve(EventPublisher);\n\n context.auditLogs = createAuditLogsContextValue({\n getContext: () => {\n return context;\n },\n deleteLogsAfterDays: getDeleteLogsAfterDays(params?.deleteLogsAfterDays),\n storage,\n eventPublisher\n });\n });\n\n plugin.name = \"audit-logs.createContext\";\n\n return plugin;\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAC3C,SAASC,cAAc,QAAQ,0CAA0C;AAGzE,SAASC,2BAA2B;AACpC,SAASC,aAAa;AAQtB,MAAMC,sBAAsB,GAAIC,IAAa,IAAa;EACtD,IAAIA,IAAI,IAAIA,IAAI,GAAG,CAAC,EAAE;IAClB,OAAOA,IAAI;EACf;EACA;AACJ;AACA;EACI,OAAO,EAAE;AACb,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAIC,MAA6B,IAAK;EACrE,MAAMC,MAAM,GAAG,IAAIR,aAAa,CAAmB,MAAMS,OAAO,IAAI;IAChE,MAAMC,OAAO,GAAGP,aAAa,CAAC;MAC1BQ,SAAS,EAAEJ,MAAM,EAAEI,SAAS;MAC5BC,MAAM,EAAEL,MAAM,EAAEM,cAAc,IAAKJ,OAAO,CAACK,EAAE,CAACC,MAAM,CAACC,SAAS,CAAC,CAAsB;MACrFC,UAAU,EAAER,OAAO,CAACQ;IACxB,CAAC,CAAC;IAEF,MAAMC,cAAc,GAAGT,OAAO,CAACU,SAAS,CAACC,OAAO,CAACnB,cAAc,CAAC;IAEhEQ,OAAO,CAACY,SAAS,GAAGnB,2BAA2B,CAAC;MAC5CoB,UAAU,EAAEA,CAAA,KAAM;QACd,OAAOb,OAAO;MAClB,CAAC;MACDc,mBAAmB,EAAEnB,sBAAsB,CAACG,MAAM,EAAEgB,mBAAmB,CAAC;MACxEb,OAAO;MACPQ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFV,MAAM,CAACgB,IAAI,GAAG,0BAA0B;EAExC,OAAOhB,MAAM;AACjB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["ContextPlugin","EventPublisher","createAuditLogsContextValue","createStorage","CompressionHandler","getDeleteLogsAfterDays","days","createAuditLogsContext","params","plugin","context","compressionHandler","container","resolve","storage","tableName","client","documentClient","db","driver","getClient","eventPublisher","auditLogs","getContext","deleteLogsAfterDays","name"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\nimport { createAuditLogsContextValue } from \"./AuditLogsContextValue.js\";\nimport { createStorage } from \"~/storage/Storage.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\nexport interface ISetupContextOptions {\n deleteLogsAfterDays: number | undefined;\n tableName: string | undefined;\n documentClient: DynamoDBDocument | undefined;\n}\n\nconst getDeleteLogsAfterDays = (days?: number): number => {\n if (days && days > 0) {\n return days;\n }\n /**\n * Default days to delete logs after.\n */\n return 60;\n};\n\nexport const createAuditLogsContext = (params?: ISetupContextOptions) => {\n const plugin = new ContextPlugin<AuditLogsContext>(async context => {\n const compressionHandler = context.container.resolve(CompressionHandler);\n\n const storage = createStorage({\n tableName: params?.tableName,\n client: params?.documentClient || (context.db.driver.getClient() as DynamoDBDocument),\n compressionHandler\n });\n\n const eventPublisher = context.container.resolve(EventPublisher);\n\n context.auditLogs = createAuditLogsContextValue({\n getContext: () => {\n return context;\n },\n deleteLogsAfterDays: getDeleteLogsAfterDays(params?.deleteLogsAfterDays),\n storage,\n eventPublisher\n });\n });\n\n plugin.name = \"audit-logs.createContext\";\n\n return plugin;\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAC3C,SAASC,cAAc,QAAQ,mDAAmD;AAGlF,SAASC,2BAA2B;AACpC,SAASC,aAAa;AACtB,SAASC,kBAAkB,QAAQ,8BAA8B;AAQjE,MAAMC,sBAAsB,GAAIC,IAAa,IAAa;EACtD,IAAIA,IAAI,IAAIA,IAAI,GAAG,CAAC,EAAE;IAClB,OAAOA,IAAI;EACf;EACA;AACJ;AACA;EACI,OAAO,EAAE;AACb,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAIC,MAA6B,IAAK;EACrE,MAAMC,MAAM,GAAG,IAAIT,aAAa,CAAmB,MAAMU,OAAO,IAAI;IAChE,MAAMC,kBAAkB,GAAGD,OAAO,CAACE,SAAS,CAACC,OAAO,CAACT,kBAAkB,CAAC;IAExE,MAAMU,OAAO,GAAGX,aAAa,CAAC;MAC1BY,SAAS,EAAEP,MAAM,EAAEO,SAAS;MAC5BC,MAAM,EAAER,MAAM,EAAES,cAAc,IAAKP,OAAO,CAACQ,EAAE,CAACC,MAAM,CAACC,SAAS,CAAC,CAAsB;MACrFT;IACJ,CAAC,CAAC;IAEF,MAAMU,cAAc,GAAGX,OAAO,CAACE,SAAS,CAACC,OAAO,CAACZ,cAAc,CAAC;IAEhES,OAAO,CAACY,SAAS,GAAGpB,2BAA2B,CAAC;MAC5CqB,UAAU,EAAEA,CAAA,KAAM;QACd,OAAOb,OAAO;MAClB,CAAC;MACDc,mBAAmB,EAAEnB,sBAAsB,CAACG,MAAM,EAAEgB,mBAAmB,CAAC;MACxEV,OAAO;MACPO;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFZ,MAAM,CAACgB,IAAI,GAAG,0BAA0B;EAExC,OAAOhB,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogAfterCreatePayload } from "./abstractions.js";
3
3
  export declare class AuditLogAfterCreateEvent extends DomainEvent<AuditLogAfterCreatePayload> {
4
4
  eventType: "auditLog.afterCreate";
5
- getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<DomainEvent<AuditLogAfterCreatePayload>>>;
5
+ getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<AuditLogAfterCreatePayload>>>;
6
6
  }
@@ -1,4 +1,4 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogAfterCreateHandler } from "./abstractions.js";
3
3
  export class AuditLogAfterCreateEvent extends DomainEvent {
4
4
  eventType = "auditLog.afterCreate";
@@ -1 +1 @@
1
- {"version":3,"names":["DomainEvent","AuditLogAfterCreateHandler","AuditLogAfterCreateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogAfterCreateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/EventPublisher\";\nimport { AuditLogAfterCreateHandler, AuditLogAfterCreatePayload } from \"./abstractions.js\";\n\nexport class AuditLogAfterCreateEvent extends DomainEvent<AuditLogAfterCreatePayload> {\n eventType = \"auditLog.afterCreate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogAfterCreateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0CAA0C;AACtE,SAASC,0BAA0B;AAEnC,OAAO,MAAMC,wBAAwB,SAASF,WAAW,CAA6B;EAClFG,SAAS,GAAG,sBAAsB;EAElCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,0BAA0B;EACrC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["DomainEvent","AuditLogAfterCreateHandler","AuditLogAfterCreateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogAfterCreateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { AuditLogAfterCreateHandler, AuditLogAfterCreatePayload } from \"./abstractions.js\";\n\nexport class AuditLogAfterCreateEvent extends DomainEvent<AuditLogAfterCreatePayload> {\n eventType = \"auditLog.afterCreate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogAfterCreateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SAASC,0BAA0B;AAEnC,OAAO,MAAMC,wBAAwB,SAASF,WAAW,CAA6B;EAClFG,SAAS,GAAG,sBAAsB;EAElCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,0BAA0B;EACrC;AACJ","ignoreList":[]}
@@ -1,6 +1,6 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogAfterUpdatePayload } from "./abstractions.js";
3
3
  export declare class AuditLogAfterUpdateEvent extends DomainEvent<AuditLogAfterUpdatePayload> {
4
4
  eventType: "auditLog.afterUpdate";
5
- getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<DomainEvent<AuditLogAfterUpdatePayload>>>;
5
+ getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<AuditLogAfterUpdatePayload>>>;
6
6
  }
@@ -1,4 +1,4 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogAfterUpdateHandler } from "./abstractions.js";
3
3
  export class AuditLogAfterUpdateEvent extends DomainEvent {
4
4
  eventType = "auditLog.afterUpdate";
@@ -1 +1 @@
1
- {"version":3,"names":["DomainEvent","AuditLogAfterUpdateHandler","AuditLogAfterUpdateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogAfterUpdateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/EventPublisher\";\nimport { AuditLogAfterUpdateHandler, AuditLogAfterUpdatePayload } from \"./abstractions.js\";\n\nexport class AuditLogAfterUpdateEvent extends DomainEvent<AuditLogAfterUpdatePayload> {\n eventType = \"auditLog.afterUpdate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogAfterUpdateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0CAA0C;AACtE,SAASC,0BAA0B;AAEnC,OAAO,MAAMC,wBAAwB,SAASF,WAAW,CAA6B;EAClFG,SAAS,GAAG,sBAAsB;EAElCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,0BAA0B;EACrC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["DomainEvent","AuditLogAfterUpdateHandler","AuditLogAfterUpdateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogAfterUpdateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { AuditLogAfterUpdateHandler, AuditLogAfterUpdatePayload } from \"./abstractions.js\";\n\nexport class AuditLogAfterUpdateEvent extends DomainEvent<AuditLogAfterUpdatePayload> {\n eventType = \"auditLog.afterUpdate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogAfterUpdateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SAASC,0BAA0B;AAEnC,OAAO,MAAMC,wBAAwB,SAASF,WAAW,CAA6B;EAClFG,SAAS,GAAG,sBAAsB;EAElCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,0BAA0B;EACrC;AACJ","ignoreList":[]}
@@ -1,6 +1,6 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogBeforeCreatePayload } from "./abstractions.js";
3
3
  export declare class AuditLogBeforeCreateEvent extends DomainEvent<AuditLogBeforeCreatePayload> {
4
4
  eventType: "auditLog.beforeCreate";
5
- getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<DomainEvent<AuditLogBeforeCreatePayload>>>;
5
+ getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<AuditLogBeforeCreatePayload>>>;
6
6
  }
@@ -1,4 +1,4 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogBeforeCreateHandler } from "./abstractions.js";
3
3
  export class AuditLogBeforeCreateEvent extends DomainEvent {
4
4
  eventType = "auditLog.beforeCreate";
@@ -1 +1 @@
1
- {"version":3,"names":["DomainEvent","AuditLogBeforeCreateHandler","AuditLogBeforeCreateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogBeforeCreateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/EventPublisher\";\nimport { AuditLogBeforeCreateHandler, AuditLogBeforeCreatePayload } from \"./abstractions.js\";\n\nexport class AuditLogBeforeCreateEvent extends DomainEvent<AuditLogBeforeCreatePayload> {\n eventType = \"auditLog.beforeCreate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogBeforeCreateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0CAA0C;AACtE,SAASC,2BAA2B;AAEpC,OAAO,MAAMC,yBAAyB,SAASF,WAAW,CAA8B;EACpFG,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,2BAA2B;EACtC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["DomainEvent","AuditLogBeforeCreateHandler","AuditLogBeforeCreateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogBeforeCreateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { AuditLogBeforeCreateHandler, AuditLogBeforeCreatePayload } from \"./abstractions.js\";\n\nexport class AuditLogBeforeCreateEvent extends DomainEvent<AuditLogBeforeCreatePayload> {\n eventType = \"auditLog.beforeCreate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogBeforeCreateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SAASC,2BAA2B;AAEpC,OAAO,MAAMC,yBAAyB,SAASF,WAAW,CAA8B;EACpFG,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,2BAA2B;EACtC;AACJ","ignoreList":[]}
@@ -1,6 +1,6 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogBeforeUpdatePayload } from "./abstractions.js";
3
3
  export declare class AuditLogBeforeUpdateEvent extends DomainEvent<AuditLogBeforeUpdatePayload> {
4
4
  eventType: "auditLog.beforeUpdate";
5
- getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<DomainEvent<AuditLogBeforeUpdatePayload>>>;
5
+ getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<AuditLogBeforeUpdatePayload>>>;
6
6
  }
@@ -1,4 +1,4 @@
1
- import { DomainEvent } from "@webiny/api-core/features/EventPublisher";
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import { AuditLogBeforeUpdateHandler } from "./abstractions.js";
3
3
  export class AuditLogBeforeUpdateEvent extends DomainEvent {
4
4
  eventType = "auditLog.beforeUpdate";
@@ -1 +1 @@
1
- {"version":3,"names":["DomainEvent","AuditLogBeforeUpdateHandler","AuditLogBeforeUpdateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogBeforeUpdateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/EventPublisher\";\nimport { AuditLogBeforeUpdateHandler, AuditLogBeforeUpdatePayload } from \"./abstractions.js\";\n\nexport class AuditLogBeforeUpdateEvent extends DomainEvent<AuditLogBeforeUpdatePayload> {\n eventType = \"auditLog.beforeUpdate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogBeforeUpdateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0CAA0C;AACtE,SAASC,2BAA2B;AAEpC,OAAO,MAAMC,yBAAyB,SAASF,WAAW,CAA8B;EACpFG,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,2BAA2B;EACtC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["DomainEvent","AuditLogBeforeUpdateHandler","AuditLogBeforeUpdateEvent","eventType","getHandlerAbstraction"],"sources":["AuditLogBeforeUpdateEvent.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { AuditLogBeforeUpdateHandler, AuditLogBeforeUpdatePayload } from \"./abstractions.js\";\n\nexport class AuditLogBeforeUpdateEvent extends DomainEvent<AuditLogBeforeUpdatePayload> {\n eventType = \"auditLog.beforeUpdate\" as const;\n\n getHandlerAbstraction() {\n return AuditLogBeforeUpdateHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SAASC,2BAA2B;AAEpC,OAAO,MAAMC,yBAAyB,SAASF,WAAW,CAA8B;EACpFG,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,2BAA2B;EACtC;AACJ","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/EventPublisher";
1
+ import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
2
2
  import type { IAuditLog } from "../storage/types.js";
3
3
  import type { AuditLogsContext } from "../types.js";
4
4
  export interface AuditLogBeforeCreatePayload {
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","AuditLogBeforeCreateHandler","AuditLogAfterCreateHandler","AuditLogBeforeUpdateHandler","AuditLogAfterUpdateHandler"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/EventPublisher\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\n\n// ============================================================================\n// AuditLogBeforeCreate Event\n// ============================================================================\n\nexport interface AuditLogBeforeCreatePayload {\n auditLog: IAuditLog;\n context: AuditLogsContext;\n setAuditLog(auditLog: Partial<IAuditLog>): void;\n}\n\nexport const AuditLogBeforeCreateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogBeforeCreatePayload>>\n>(\"AuditLogBeforeCreateHandler\");\n\nexport namespace AuditLogBeforeCreateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogBeforeCreatePayload>>;\n export type Event = DomainEvent<AuditLogBeforeCreatePayload>;\n}\n\n// ============================================================================\n// AuditLogAfterCreate Event\n// ============================================================================\n\nexport interface AuditLogAfterCreatePayload {\n auditLog: IAuditLog;\n context: AuditLogsContext;\n}\n\nexport const AuditLogAfterCreateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogAfterCreatePayload>>\n>(\"AuditLogAfterCreateHandler\");\n\nexport namespace AuditLogAfterCreateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogAfterCreatePayload>>;\n export type Event = DomainEvent<AuditLogAfterCreatePayload>;\n}\n\n// ============================================================================\n// AuditLogBeforeUpdate Event\n// ============================================================================\n\nexport interface AuditLogBeforeUpdatePayload {\n auditLog: IAuditLog;\n original: IAuditLog;\n context: AuditLogsContext;\n setAuditLog(auditLog: Partial<IAuditLog>): void;\n}\n\nexport const AuditLogBeforeUpdateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogBeforeUpdatePayload>>\n>(\"AuditLogBeforeUpdateHandler\");\n\nexport namespace AuditLogBeforeUpdateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogBeforeUpdatePayload>>;\n export type Event = DomainEvent<AuditLogBeforeUpdatePayload>;\n}\n\n// ============================================================================\n// AuditLogAfterUpdate Event\n// ============================================================================\n\nexport interface AuditLogAfterUpdatePayload {\n auditLog: IAuditLog;\n original: IAuditLog;\n context: AuditLogsContext;\n}\n\nexport const AuditLogAfterUpdateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogAfterUpdatePayload>>\n>(\"AuditLogAfterUpdateHandler\");\n\nexport namespace AuditLogAfterUpdateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogAfterUpdatePayload>>;\n export type Event = DomainEvent<AuditLogAfterUpdatePayload>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAKvD;AACA;AACA;;AAQA,OAAO,MAAMC,2BAA2B,GAAGD,iBAAiB,CAE1D,6BAA6B,CAAC;;AAOhC;AACA;AACA;;AAOA,OAAO,MAAME,0BAA0B,GAAGF,iBAAiB,CAEzD,4BAA4B,CAAC;;AAO/B;AACA;AACA;;AASA,OAAO,MAAMG,2BAA2B,GAAGH,iBAAiB,CAE1D,6BAA6B,CAAC;;AAOhC;AACA;AACA;;AAQA,OAAO,MAAMI,0BAA0B,GAAGJ,iBAAiB,CAEzD,4BAA4B,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createAbstraction","AuditLogBeforeCreateHandler","AuditLogAfterCreateHandler","AuditLogBeforeUpdateHandler","AuditLogAfterUpdateHandler"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\n\n// ============================================================================\n// AuditLogBeforeCreate Event\n// ============================================================================\n\nexport interface AuditLogBeforeCreatePayload {\n auditLog: IAuditLog;\n context: AuditLogsContext;\n setAuditLog(auditLog: Partial<IAuditLog>): void;\n}\n\nexport const AuditLogBeforeCreateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogBeforeCreatePayload>>\n>(\"AuditLogBeforeCreateHandler\");\n\nexport namespace AuditLogBeforeCreateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogBeforeCreatePayload>>;\n export type Event = DomainEvent<AuditLogBeforeCreatePayload>;\n}\n\n// ============================================================================\n// AuditLogAfterCreate Event\n// ============================================================================\n\nexport interface AuditLogAfterCreatePayload {\n auditLog: IAuditLog;\n context: AuditLogsContext;\n}\n\nexport const AuditLogAfterCreateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogAfterCreatePayload>>\n>(\"AuditLogAfterCreateHandler\");\n\nexport namespace AuditLogAfterCreateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogAfterCreatePayload>>;\n export type Event = DomainEvent<AuditLogAfterCreatePayload>;\n}\n\n// ============================================================================\n// AuditLogBeforeUpdate Event\n// ============================================================================\n\nexport interface AuditLogBeforeUpdatePayload {\n auditLog: IAuditLog;\n original: IAuditLog;\n context: AuditLogsContext;\n setAuditLog(auditLog: Partial<IAuditLog>): void;\n}\n\nexport const AuditLogBeforeUpdateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogBeforeUpdatePayload>>\n>(\"AuditLogBeforeUpdateHandler\");\n\nexport namespace AuditLogBeforeUpdateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogBeforeUpdatePayload>>;\n export type Event = DomainEvent<AuditLogBeforeUpdatePayload>;\n}\n\n// ============================================================================\n// AuditLogAfterUpdate Event\n// ============================================================================\n\nexport interface AuditLogAfterUpdatePayload {\n auditLog: IAuditLog;\n original: IAuditLog;\n context: AuditLogsContext;\n}\n\nexport const AuditLogAfterUpdateHandler = createAbstraction<\n IEventHandler<DomainEvent<AuditLogAfterUpdatePayload>>\n>(\"AuditLogAfterUpdateHandler\");\n\nexport namespace AuditLogAfterUpdateHandler {\n export type Interface = IEventHandler<DomainEvent<AuditLogAfterUpdatePayload>>;\n export type Event = DomainEvent<AuditLogAfterUpdatePayload>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAKvD;AACA;AACA;;AAQA,OAAO,MAAMC,2BAA2B,GAAGD,iBAAiB,CAE1D,6BAA6B,CAAC;;AAOhC;AACA;AACA;;AAOA,OAAO,MAAME,0BAA0B,GAAGF,iBAAiB,CAEzD,4BAA4B,CAAC;;AAO/B;AACA;AACA;;AASA,OAAO,MAAMG,2BAA2B,GAAGH,iBAAiB,CAE1D,6BAA6B,CAAC;;AAOhC;AACA;AACA;;AAQA,OAAO,MAAMI,0BAA0B,GAAGJ,iBAAiB,CAEzD,4BAA4B,CAAC","ignoreList":[]}
@@ -1,64 +1,21 @@
1
1
  import zod from "zod";
2
2
  export declare const getValidationSchema: zod.ZodObject<{
3
3
  id: zod.ZodString;
4
- }, "strip", zod.ZodTypeAny, {
5
- id: string;
6
- }, {
7
- id: string;
8
- }>;
4
+ }, zod.core.$strip>;
9
5
  export declare const listValidationSchema: zod.ZodObject<{
10
6
  where: zod.ZodObject<{
11
7
  app: zod.ZodOptional<zod.ZodString>;
12
8
  entity: zod.ZodOptional<zod.ZodString>;
13
9
  entityId: zod.ZodOptional<zod.ZodString>;
14
- createdOn_gte: zod.ZodEffects<zod.ZodOptional<zod.ZodDate>, Date | undefined, unknown>;
15
- createdOn_lte: zod.ZodEffects<zod.ZodOptional<zod.ZodDate>, Date | undefined, unknown>;
10
+ createdOn_gte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
11
+ createdOn_lte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
16
12
  createdBy: zod.ZodOptional<zod.ZodString>;
17
13
  action: zod.ZodOptional<zod.ZodString>;
18
- }, "strip", zod.ZodTypeAny, {
19
- createdBy?: string | undefined;
20
- app?: string | undefined;
21
- action?: string | undefined;
22
- entity?: string | undefined;
23
- entityId?: string | undefined;
24
- createdOn_gte?: Date | undefined;
25
- createdOn_lte?: Date | undefined;
26
- }, {
27
- createdBy?: string | undefined;
28
- app?: string | undefined;
29
- action?: string | undefined;
30
- entity?: string | undefined;
31
- entityId?: string | undefined;
32
- createdOn_gte?: unknown;
33
- createdOn_lte?: unknown;
34
- }>;
14
+ }, zod.core.$strip>;
35
15
  after: zod.ZodOptional<zod.ZodString>;
36
- sort: zod.ZodOptional<zod.ZodEnum<["ASC", "DESC"]>>;
37
- limit: zod.ZodDefault<zod.ZodEffects<zod.ZodOptional<zod.ZodNumber>, number | undefined, unknown>>;
38
- }, "strip", zod.ZodTypeAny, {
39
- limit: number;
40
- where: {
41
- createdBy?: string | undefined;
42
- app?: string | undefined;
43
- action?: string | undefined;
44
- entity?: string | undefined;
45
- entityId?: string | undefined;
46
- createdOn_gte?: Date | undefined;
47
- createdOn_lte?: Date | undefined;
48
- };
49
- after?: string | undefined;
50
- sort?: "ASC" | "DESC" | undefined;
51
- }, {
52
- where: {
53
- createdBy?: string | undefined;
54
- app?: string | undefined;
55
- action?: string | undefined;
56
- entity?: string | undefined;
57
- entityId?: string | undefined;
58
- createdOn_gte?: unknown;
59
- createdOn_lte?: unknown;
60
- };
61
- after?: string | undefined;
62
- sort?: "ASC" | "DESC" | undefined;
63
- limit?: unknown;
64
- }>;
16
+ sort: zod.ZodOptional<zod.ZodEnum<{
17
+ ASC: "ASC";
18
+ DESC: "DESC";
19
+ }>>;
20
+ limit: zod.ZodDefault<zod.ZodPreprocess<zod.ZodOptional<zod.ZodNumber>>>;
21
+ }, zod.core.$strip>;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["ContextPlugin","createSubscriptionHooks","createAuditLogsContext","createGraphQLSchema","AuditLogsContext","createAuditLogs","params","subscriptionsPlugin","context","wcp","canUseFeature","container","registerInstance","name","tableName","deleteLogsAfterDays","documentClient"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { createSubscriptionHooks } from \"~/subscriptions/index.js\";\nimport { createAuditLogsContext } from \"~/context/index.js\";\nimport { createGraphQLSchema } from \"~/graphql/schema.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { AuditLogsContext } from \"./abstractions.js\";\n\nexport interface ICreateAuditLogsParams {\n deleteLogsAfterDays: number | undefined;\n tableName?: string;\n documentClient?: DynamoDBDocument;\n}\n\nexport const createAuditLogs = (params?: ICreateAuditLogsParams) => {\n const subscriptionsPlugin = new ContextPlugin<AuditLogsContext.Interface>(context => {\n if (!context.wcp.canUseFeature(\"auditLogs\")) {\n return;\n }\n\n context.container.registerInstance(AuditLogsContext, context);\n\n createSubscriptionHooks(context);\n });\n\n subscriptionsPlugin.name = \"auditLogs.context.subscriptions\";\n\n return [\n subscriptionsPlugin,\n createGraphQLSchema(),\n createAuditLogsContext({\n tableName: params?.tableName,\n deleteLogsAfterDays: params?.deleteLogsAfterDays,\n documentClient: params?.documentClient\n })\n ];\n};\nexport * from \"~/config.js\";\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAC3C,SAASC,uBAAuB;AAChC,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;AAE5B,SAASC,gBAAgB;AAQzB,OAAO,MAAMC,eAAe,GAAIC,MAA+B,IAAK;EAChE,MAAMC,mBAAmB,GAAG,IAAIP,aAAa,CAA6BQ,OAAO,IAAI;IACjF,IAAI,CAACA,OAAO,CAACC,GAAG,CAACC,aAAa,CAAC,WAAW,CAAC,EAAE;MACzC;IACJ;IAEAF,OAAO,CAACG,SAAS,CAACC,gBAAgB,CAACR,gBAAgB,EAAEI,OAAO,CAAC;IAE7DP,uBAAuB,CAACO,OAAO,CAAC;EACpC,CAAC,CAAC;EAEFD,mBAAmB,CAACM,IAAI,GAAG,iCAAiC;EAE5D,OAAO,CACHN,mBAAmB,EACnBJ,mBAAmB,CAAC,CAAC,EACrBD,sBAAsB,CAAC;IACnBY,SAAS,EAAER,MAAM,EAAEQ,SAAS;IAC5BC,mBAAmB,EAAET,MAAM,EAAES,mBAAmB;IAChDC,cAAc,EAAEV,MAAM,EAAEU;EAC5B,CAAC,CAAC,CACL;AACL,CAAC;AACD","ignoreList":[]}
1
+ {"version":3,"names":["ContextPlugin","createSubscriptionHooks","createAuditLogsContext","createGraphQLSchema","AuditLogsContext","createAuditLogs","params","subscriptionsPlugin","context","wcp","canUseFeature","container","registerInstance","name","tableName","deleteLogsAfterDays","documentClient"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { createSubscriptionHooks } from \"~/subscriptions/index.js\";\nimport { createAuditLogsContext } from \"~/context/index.js\";\nimport { createGraphQLSchema } from \"~/graphql/schema.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { AuditLogsContext } from \"./abstractions.js\";\n\nexport interface ICreateAuditLogsParams {\n deleteLogsAfterDays: number | undefined;\n tableName?: string;\n documentClient?: DynamoDBDocument;\n}\n\nexport const createAuditLogs = (params?: ICreateAuditLogsParams) => {\n const subscriptionsPlugin = new ContextPlugin<AuditLogsContext.Interface>(context => {\n if (!context.wcp.canUseFeature(\"auditLogs\")) {\n return;\n }\n\n context.container.registerInstance(AuditLogsContext, context);\n\n createSubscriptionHooks(context);\n });\n\n subscriptionsPlugin.name = \"auditLogs.context.subscriptions\";\n return [\n subscriptionsPlugin,\n createGraphQLSchema(),\n createAuditLogsContext({\n tableName: params?.tableName,\n deleteLogsAfterDays: params?.deleteLogsAfterDays,\n documentClient: params?.documentClient\n })\n ];\n};\nexport * from \"~/config.js\";\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAC3C,SAASC,uBAAuB;AAChC,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;AAE5B,SAASC,gBAAgB;AAQzB,OAAO,MAAMC,eAAe,GAAIC,MAA+B,IAAK;EAChE,MAAMC,mBAAmB,GAAG,IAAIP,aAAa,CAA6BQ,OAAO,IAAI;IACjF,IAAI,CAACA,OAAO,CAACC,GAAG,CAACC,aAAa,CAAC,WAAW,CAAC,EAAE;MACzC;IACJ;IAEAF,OAAO,CAACG,SAAS,CAACC,gBAAgB,CAACR,gBAAgB,EAAEI,OAAO,CAAC;IAE7DP,uBAAuB,CAACO,OAAO,CAAC;EACpC,CAAC,CAAC;EAEFD,mBAAmB,CAACM,IAAI,GAAG,iCAAiC;EAC5D,OAAO,CACHN,mBAAmB,EACnBJ,mBAAmB,CAAC,CAAC,EACrBD,sBAAsB,CAAC;IACnBY,SAAS,EAAER,MAAM,EAAEQ,SAAS;IAC5BC,mBAAmB,EAAET,MAAM,EAAES,mBAAmB;IAChDC,cAAc,EAAEV,MAAM,EAAEU;EAC5B,CAAC,CAAC,CACL;AACL,CAAC;AACD","ignoreList":[]}
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@webiny/api-audit-logs",
3
- "version": "0.0.0-unstable.e622468070",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.e6f0dc8ca7",
4
+ "exports": {
5
+ ".": "./index.js",
6
+ "./*": "./*"
7
+ },
5
8
  "type": "module",
6
9
  "repository": {
7
10
  "type": "git",
@@ -20,33 +23,33 @@
20
23
  "directory": "dist"
21
24
  },
22
25
  "devDependencies": {
23
- "@webiny/handler-aws": "0.0.0-unstable.e622468070",
24
- "@webiny/plugins": "0.0.0-unstable.e622468070",
25
- "@webiny/project-utils": "0.0.0-unstable.e622468070",
26
- "graphql": "16.12.0",
27
- "typescript": "5.9.3",
28
- "vitest": "3.2.4"
26
+ "@webiny/handler-aws": "0.0.0-unstable.e6f0dc8ca7",
27
+ "@webiny/plugins": "0.0.0-unstable.e6f0dc8ca7",
28
+ "@webiny/project-utils": "0.0.0-unstable.e6f0dc8ca7",
29
+ "graphql": "16.14.0",
30
+ "typescript": "6.0.3",
31
+ "vitest": "4.1.5"
29
32
  },
30
33
  "dependencies": {
31
- "@webiny/api": "0.0.0-unstable.e622468070",
32
- "@webiny/api-aco": "0.0.0-unstable.e622468070",
33
- "@webiny/api-core": "0.0.0-unstable.e622468070",
34
- "@webiny/api-file-manager": "0.0.0-unstable.e622468070",
35
- "@webiny/api-headless-cms": "0.0.0-unstable.e622468070",
36
- "@webiny/api-mailer": "0.0.0-unstable.e622468070",
37
- "@webiny/api-website-builder": "0.0.0-unstable.e622468070",
38
- "@webiny/aws-sdk": "0.0.0-unstable.e622468070",
39
- "@webiny/build-tools": "0.0.0-unstable.e622468070",
40
- "@webiny/common-audit-logs": "0.0.0-unstable.e622468070",
41
- "@webiny/db-dynamodb": "0.0.0-unstable.e622468070",
42
- "@webiny/error": "0.0.0-unstable.e622468070",
43
- "@webiny/feature": "0.0.0-unstable.e622468070",
44
- "@webiny/handler": "0.0.0-unstable.e622468070",
45
- "@webiny/handler-db": "0.0.0-unstable.e622468070",
46
- "@webiny/handler-graphql": "0.0.0-unstable.e622468070",
47
- "@webiny/utils": "0.0.0-unstable.e622468070",
48
- "@webiny/wcp": "0.0.0-unstable.e622468070",
49
- "zod": "3.25.76"
34
+ "@webiny/api": "0.0.0-unstable.e6f0dc8ca7",
35
+ "@webiny/api-aco": "0.0.0-unstable.e6f0dc8ca7",
36
+ "@webiny/api-core": "0.0.0-unstable.e6f0dc8ca7",
37
+ "@webiny/api-file-manager": "0.0.0-unstable.e6f0dc8ca7",
38
+ "@webiny/api-headless-cms": "0.0.0-unstable.e6f0dc8ca7",
39
+ "@webiny/api-mailer": "0.0.0-unstable.e6f0dc8ca7",
40
+ "@webiny/api-website-builder": "0.0.0-unstable.e6f0dc8ca7",
41
+ "@webiny/aws-sdk": "0.0.0-unstable.e6f0dc8ca7",
42
+ "@webiny/build-tools": "0.0.0-unstable.e6f0dc8ca7",
43
+ "@webiny/common-audit-logs": "0.0.0-unstable.e6f0dc8ca7",
44
+ "@webiny/db-dynamodb": "0.0.0-unstable.e6f0dc8ca7",
45
+ "@webiny/error": "0.0.0-unstable.e6f0dc8ca7",
46
+ "@webiny/feature": "0.0.0-unstable.e6f0dc8ca7",
47
+ "@webiny/handler": "0.0.0-unstable.e6f0dc8ca7",
48
+ "@webiny/handler-db": "0.0.0-unstable.e6f0dc8ca7",
49
+ "@webiny/handler-graphql": "0.0.0-unstable.e6f0dc8ca7",
50
+ "@webiny/utils": "0.0.0-unstable.e6f0dc8ca7",
51
+ "@webiny/wcp": "0.0.0-unstable.e6f0dc8ca7",
52
+ "zod": "4.4.3"
50
53
  },
51
- "gitHead": "e622468070839dc3f9552c85bf2bbac12d2ef88f"
54
+ "gitHead": "e6f0dc8ca741c1fcc3fec9a5b9e86fdd49544641"
52
55
  }
@@ -1,13 +1,13 @@
1
1
  import type { IConverter } from "../storage/abstractions/Converter.js";
2
- import type { ICompressor } from "@webiny/utils/compression/index.js";
3
2
  import type { IAuditLog, IStorageItem } from "../storage/types.js";
4
3
  import type { IAccessPatternHandler } from "../storage/abstractions/AccessPatternHandler.js";
4
+ import { CompressionHandler } from "@webiny/utils/exports/api.js";
5
5
  export interface IConverterParams {
6
- compressor: ICompressor;
6
+ compressionHandler: CompressionHandler.Interface;
7
7
  patternHandler: IAccessPatternHandler;
8
8
  }
9
9
  export declare class Converter implements IConverter {
10
- private readonly compressor;
10
+ private readonly compressionHandler;
11
11
  private readonly patternHandler;
12
12
  constructor(params: IConverterParams);
13
13
  oneFromStorage(item: IStorageItem): Promise<IAuditLog>;
@@ -4,14 +4,14 @@ const convertToDateTime = value => {
4
4
  };
5
5
  export class Converter {
6
6
  constructor(params) {
7
- this.compressor = params.compressor;
7
+ this.compressionHandler = params.compressionHandler;
8
8
  this.patternHandler = params.patternHandler;
9
9
  }
10
10
  async oneFromStorage(item) {
11
11
  return {
12
12
  ...item.data,
13
13
  expiresAt: convertToDateTime(item.data.expiresAt),
14
- content: await this.compressor.decompress(JSON.parse(item.data.content)),
14
+ content: await this.compressionHandler.decompress(JSON.parse(item.data.content)),
15
15
  createdOn: new Date(item.data.createdOn)
16
16
  };
17
17
  }
@@ -41,7 +41,7 @@ export class Converter {
41
41
  data: {
42
42
  ...auditLog,
43
43
  expiresAt: auditLog.expiresAt.toISOString(),
44
- content: JSON.stringify(await this.compressor.compress(auditLog.content)),
44
+ content: JSON.stringify(await this.compressionHandler.compress(auditLog.content)),
45
45
  createdOn: auditLog.createdOn.toISOString()
46
46
  },
47
47
  expiresAt: convertExpiresAtToUnixTimestamp(auditLog.expiresAt)
@@ -1 +1 @@
1
- {"version":3,"names":["convertExpiresAtToUnixTimestamp","convertToDateTime","value","Date","Converter","constructor","params","compressor","patternHandler","oneFromStorage","item","data","expiresAt","content","decompress","JSON","parse","createdOn","listFromStorage","items","Promise","all","map","oneToStorage","auditLog","defaultPattern","getDefaultPattern","defaultKeys","createKeys","patterns","listIndexPatterns","keys","reduce","output","pattern","patternKeys","index","partitionKey","sortKey","PK","SK","TYPE","GSI_TENANT","tenant","toISOString","stringify","compress"],"sources":["Converter.ts"],"sourcesContent":["import type { IConverter } from \"~/storage/abstractions/Converter.js\";\nimport type { ICompressor } from \"@webiny/utils/compression/index.js\";\nimport type { IAuditLog, IStorageItem } from \"~/storage/types.js\";\nimport type { IAccessPatternHandler } from \"~/storage/abstractions/AccessPatternHandler.js\";\nimport { convertExpiresAtToUnixTimestamp } from \"~/utils/expiresAt.js\";\n\nconst convertToDateTime = (value: string): Date => {\n return new Date(value);\n};\n\nexport interface IConverterParams {\n compressor: ICompressor;\n patternHandler: IAccessPatternHandler;\n}\n\ntype PickOnlyGSIKeys<T> = {\n [K in keyof T]: K extends `GSI${string}` ? K : never;\n}[keyof T];\n\ntype PickedGSIKeys = Pick<IStorageItem, PickOnlyGSIKeys<IStorageItem>>;\n\nexport class Converter implements IConverter {\n private readonly compressor;\n private readonly patternHandler;\n\n public constructor(params: IConverterParams) {\n this.compressor = params.compressor;\n this.patternHandler = params.patternHandler;\n }\n\n public async oneFromStorage(item: IStorageItem): Promise<IAuditLog> {\n return {\n ...item.data,\n expiresAt: convertToDateTime(item.data.expiresAt),\n content: await this.compressor.decompress(JSON.parse(item.data.content)),\n createdOn: new Date(item.data.createdOn)\n };\n }\n\n public async listFromStorage(items: IStorageItem[]): Promise<IAuditLog[]> {\n return await Promise.all(\n items.map(async item => {\n return await this.oneFromStorage(item);\n })\n );\n }\n\n public async oneToStorage(auditLog: IAuditLog): Promise<IStorageItem> {\n const defaultPattern = this.patternHandler.getDefaultPattern();\n\n const defaultKeys = defaultPattern.createKeys(auditLog);\n\n const patterns = this.patternHandler.listIndexPatterns();\n\n const keys = patterns.reduce<PickedGSIKeys>((output, pattern) => {\n const patternKeys = pattern.createKeys(auditLog);\n return {\n ...output,\n [`${pattern.index}_PK`]: patternKeys.partitionKey,\n [`${pattern.index}_SK`]: patternKeys.sortKey\n };\n }, {} as PickedGSIKeys);\n\n return {\n PK: defaultKeys.partitionKey,\n SK: defaultKeys.sortKey as unknown as string,\n ...keys,\n TYPE: \"auditLog.log\",\n GSI_TENANT: auditLog.tenant,\n data: {\n ...auditLog,\n expiresAt: auditLog.expiresAt.toISOString(),\n content: JSON.stringify(await this.compressor.compress(auditLog.content)),\n createdOn: auditLog.createdOn.toISOString()\n },\n expiresAt: convertExpiresAtToUnixTimestamp(auditLog.expiresAt)\n };\n }\n}\n"],"mappings":"AAIA,SAASA,+BAA+B;AAExC,MAAMC,iBAAiB,GAAIC,KAAa,IAAW;EAC/C,OAAO,IAAIC,IAAI,CAACD,KAAK,CAAC;AAC1B,CAAC;AAaD,OAAO,MAAME,SAAS,CAAuB;EAIlCC,WAAWA,CAACC,MAAwB,EAAE;IACzC,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;IACnC,IAAI,CAACC,cAAc,GAAGF,MAAM,CAACE,cAAc;EAC/C;EAEA,MAAaC,cAAcA,CAACC,IAAkB,EAAsB;IAChE,OAAO;MACH,GAAGA,IAAI,CAACC,IAAI;MACZC,SAAS,EAAEX,iBAAiB,CAACS,IAAI,CAACC,IAAI,CAACC,SAAS,CAAC;MACjDC,OAAO,EAAE,MAAM,IAAI,CAACN,UAAU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EY,QAAQ,CAACZ,SAAS,CAACgC,WAAW,CAAC,CAAC;QAC3C/B,OAAO,EAAEE,IAAI,CAAC8B,SAAS,CAAC,MAAM,IAAI,CAACtC,UAAU,CAACuC,QAAQ,CAACtB,QAAQ,CAACX,OAAO,CAAC,CAAC;QACzEI,SAAS,EAAEO,QAAQ,CAACP,SAAS,CAAC2B,WAAW,CAAC;MAC9C,CAAC;MACDhC,SAAS,EAAEZ,+BAA+B,CAACwB,QAAQ,CAACZ,SAAS;IACjE,CAAC;EACL;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["convertExpiresAtToUnixTimestamp","convertToDateTime","value","Date","Converter","constructor","params","compressionHandler","patternHandler","oneFromStorage","item","data","expiresAt","content","decompress","JSON","parse","createdOn","listFromStorage","items","Promise","all","map","oneToStorage","auditLog","defaultPattern","getDefaultPattern","defaultKeys","createKeys","patterns","listIndexPatterns","keys","reduce","output","pattern","patternKeys","index","partitionKey","sortKey","PK","SK","TYPE","GSI_TENANT","tenant","toISOString","stringify","compress"],"sources":["Converter.ts"],"sourcesContent":["import type { IConverter } from \"~/storage/abstractions/Converter.js\";\nimport type { IAuditLog, IStorageItem } from \"~/storage/types.js\";\nimport type { IAccessPatternHandler } from \"~/storage/abstractions/AccessPatternHandler.js\";\nimport { convertExpiresAtToUnixTimestamp } from \"~/utils/expiresAt.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\nconst convertToDateTime = (value: string): Date => {\n return new Date(value);\n};\n\nexport interface IConverterParams {\n compressionHandler: CompressionHandler.Interface;\n patternHandler: IAccessPatternHandler;\n}\n\ntype PickOnlyGSIKeys<T> = {\n [K in keyof T]: K extends `GSI${string}` ? K : never;\n}[keyof T];\n\ntype PickedGSIKeys = Pick<IStorageItem, PickOnlyGSIKeys<IStorageItem>>;\n\nexport class Converter implements IConverter {\n private readonly compressionHandler;\n private readonly patternHandler;\n\n public constructor(params: IConverterParams) {\n this.compressionHandler = params.compressionHandler;\n this.patternHandler = params.patternHandler;\n }\n\n public async oneFromStorage(item: IStorageItem): Promise<IAuditLog> {\n return {\n ...item.data,\n expiresAt: convertToDateTime(item.data.expiresAt),\n content: await this.compressionHandler.decompress(JSON.parse(item.data.content)),\n createdOn: new Date(item.data.createdOn)\n };\n }\n\n public async listFromStorage(items: IStorageItem[]): Promise<IAuditLog[]> {\n return await Promise.all(\n items.map(async item => {\n return await this.oneFromStorage(item);\n })\n );\n }\n\n public async oneToStorage(auditLog: IAuditLog): Promise<IStorageItem> {\n const defaultPattern = this.patternHandler.getDefaultPattern();\n\n const defaultKeys = defaultPattern.createKeys(auditLog);\n\n const patterns = this.patternHandler.listIndexPatterns();\n\n const keys = patterns.reduce<PickedGSIKeys>((output, pattern) => {\n const patternKeys = pattern.createKeys(auditLog);\n return {\n ...output,\n [`${pattern.index}_PK`]: patternKeys.partitionKey,\n [`${pattern.index}_SK`]: patternKeys.sortKey\n };\n }, {} as PickedGSIKeys);\n\n return {\n PK: defaultKeys.partitionKey,\n SK: defaultKeys.sortKey as unknown as string,\n ...keys,\n TYPE: \"auditLog.log\",\n GSI_TENANT: auditLog.tenant,\n data: {\n ...auditLog,\n expiresAt: auditLog.expiresAt.toISOString(),\n content: JSON.stringify(await this.compressionHandler.compress(auditLog.content)),\n createdOn: auditLog.createdOn.toISOString()\n },\n expiresAt: convertExpiresAtToUnixTimestamp(auditLog.expiresAt)\n };\n }\n}\n"],"mappings":"AAGA,SAASA,+BAA+B;AAGxC,MAAMC,iBAAiB,GAAIC,KAAa,IAAW;EAC/C,OAAO,IAAIC,IAAI,CAACD,KAAK,CAAC;AAC1B,CAAC;AAaD,OAAO,MAAME,SAAS,CAAuB;EAIlCC,WAAWA,CAACC,MAAwB,EAAE;IACzC,IAAI,CAACC,kBAAkB,GAAGD,MAAM,CAACC,kBAAkB;IACnD,IAAI,CAACC,cAAc,GAAGF,MAAM,CAACE,cAAc;EAC/C;EAEA,MAAaC,cAAcA,CAACC,IAAkB,EAAsB;IAChE,OAAO;MACH,GA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,GAAGP,IAAI;MACPU,IAAI,EAAE,cAAc;MACpBC,UAAU,EAAElB,QAAQ,CAACmB,MAAM;MAC3BhC,IAAI,EAAE;QACF,GAAGa,QAAQ;QACXZ,SAAS,EAAEY,QAAQ,CAACZ,SAAS,CAACgC,WAAW,CAAC,CAAC;QAC3C/B,OAAO,EAAEE,IAAI,CAAC8B,SAAS,CAAC,MAAM,IAAI,CAACtC,kBAAkB,CAACuC,QAAQ,CAACtB,QAAQ,CAACX,OAAO,CAAC,CAAC;QACjFI,SAAS,EAAEO,QAAQ,CAACP,SAAS,CAAC2B,WAAW,CAAC;MAC9C,CAAC;MACDhC,SAAS,EAAEZ,+BAA+B,CAACwB,QAAQ,CAACZ,SAAS;IACjE,CAAC;EACL;AACJ","ignoreList":[]}
@@ -1,8 +1,8 @@
1
1
  import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
2
  import type { IStorage, IStorageFetchParams, IStorageFetchResult, IStorageListParams, IStorageListResult, IStorageStoreParams, IStorageStoreResult } from "../storage/abstractions/Storage.js";
3
- import type { ICompressor } from "@webiny/utils/compression/index.js";
3
+ import { CompressionHandler } from "@webiny/utils/exports/api.js";
4
4
  export interface IStorageParams {
5
- compressor: ICompressor;
5
+ compressionHandler: CompressionHandler.Interface;
6
6
  client: DynamoDBDocument;
7
7
  tableName: string | undefined;
8
8
  }
@@ -20,7 +20,7 @@ export class Storage {
20
20
  patterns
21
21
  });
22
22
  this.converter = new Converter({
23
- compressor: params.compressor,
23
+ compressionHandler: params.compressionHandler,
24
24
  patternHandler: this.patternHandler
25
25
  });
26
26
  }
@@ -1 +1 @@
1
- {"version":3,"names":["createEntity","Converter","createAccessPatterns","AccessPatternHandler","ListSuccessResult","Storage","constructor","params","entity","client","tableName","gsiAmount","patterns","patternHandler","converter","compressor","fetch","id","tenant","result","get","PK","SK","error","Error","success","data","oneFromStorage","ex","store","auditLog","structuredClone","item","oneToStorage","put","list","handle","create","listFromStorage","items","lastEvaluatedKey","createStorage"],"sources":["Storage.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createEntity } from \"~/storage/entity.js\";\nimport type {\n IStorage,\n IStorageFetchParams,\n IStorageFetchResult,\n IStorageListParams,\n IStorageListResult,\n IStorageStoreParams,\n IStorageStoreResult\n} from \"~/storage/abstractions/Storage.js\";\nimport type { ICompressor } from \"@webiny/utils/compression/index.js\";\nimport { Converter } from \"~/storage/Converter.js\";\nimport { createAccessPatterns } from \"~/storage/accessPatterns/index.js\";\nimport { AccessPatternHandler } from \"~/storage/AccessPatternHandler.js\";\nimport { ListSuccessResult } from \"~/storage/results/index.js\";\n\nexport interface IStorageParams {\n compressor: ICompressor;\n client: DynamoDBDocument;\n tableName: string | undefined;\n}\n\nexport class Storage implements IStorage {\n private readonly entity;\n private readonly converter;\n private readonly patternHandler;\n\n public constructor(params: IStorageParams) {\n const { entity } = createEntity({\n client: params.client,\n tableName: params.tableName,\n gsiAmount: 10\n });\n\n this.entity = entity;\n\n const patterns = createAccessPatterns({\n entity\n });\n this.patternHandler = new AccessPatternHandler({\n patterns\n });\n\n this.converter = new Converter({\n compressor: params.compressor,\n patternHandler: this.patternHandler\n });\n }\n\n public async fetch(params: IStorageFetchParams): Promise<IStorageFetchResult> {\n const { id, tenant } = params;\n\n try {\n const result = await this.entity.get({\n PK: `T#${tenant}#AUDIT_LOG`,\n SK: `${id}`\n });\n if (!result) {\n return {\n error: new Error(`Audit log entry \"${id}\" not found.`),\n success: false\n };\n }\n return {\n data: await this.converter.oneFromStorage(result),\n success: true\n };\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n }\n\n public async store(params: IStorageStoreParams): Promise<IStorageStoreResult> {\n const auditLog = structuredClone(params.data);\n\n try {\n const item = await this.converter.oneToStorage(auditLog);\n await this.entity.put(item);\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n\n return {\n success: true,\n data: auditLog\n };\n }\n\n public async list(params: IStorageListParams): Promise<IStorageListResult> {\n try {\n const result = await this.patternHandler.handle(params);\n\n return ListSuccessResult.create({\n data: await this.converter.listFromStorage(result.items),\n lastEvaluatedKey: result.lastEvaluatedKey\n });\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n }\n}\n\nexport const createStorage = (params: IStorageParams): IStorage => {\n return new Storage(params);\n};\n"],"mappings":"AACA,SAASA,YAAY;AAWrB,SAASC,SAAS;AAClB,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAQ1B,OAAO,MAAMC,OAAO,CAAqB;EAK9BC,WAAWA,CAACC,MAAsB,EAAE;IACvC,MAAM;MAAEC;IAAO,CAAC,GAAGR,YAAY,CAAC;MAC5BS,MAAM,EAAEF,MAAM,CAACE,MAAM;MACrBC,SAAS,EAAEH,MAAM,CAACG,SAAS;MAC3BC,SAAS,EAAE;IACf,CAAC,CAAC;IAEF,IAAI,CAACH,MAAM,GAAGA,MAAM;IAEpB,MAAMI,QAAQ,GAAGV,oBAAoB,CAAC;MAClCM;IACJ,CAAC,CAAC;IACF,IAAI,CAACK,cAAc,GAAG,IAAIV,oBAAoB,CAAC;MAC3CS;IACJ,CAAC,CAAC;IAEF,IAAI,CAACE,SAAS,GAAG,IAAIb,SAAS,CAAC;MAC3Bc,UAAU,EAAER,MAAM,CAACQ,UAAU;MAC7BF,cAAc,EAAE,IAAI,CAACA;IACzB,CAAC,CAAC;EACN;EAEA,MAAaG,KAAKA,CAACT,MAA2B,EAAgC;IAC1E,MAAM;MAAEU,EAAE;MAAEC;IAAO,CAAC,GAAGX,MAAM;IAE7B,IAAI;MACA,MAAMY,MAAM,GAAG,MAAM,IAAI,CAACX,MAAM,CAACY,GAAG,CAAC;QACjCC,EAAE,EAAE,KAAKH,MAAM,YAAY;QAC3BI,EAAE,EAAE,GAAGL,EAAE;MACb,CAAC,CAAC;MACF,IAAI,CAACE,MAAM,EAAE;QACT,OAAO;UACHI,KAAK,EAAE,IAAIC,KA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AsB,IAAe;EAC/D,OAAO,IAAIF,OAAO,CAACE,MAAM,CAAC;AAC9B,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createEntity","Converter","createAccessPatterns","AccessPatternHandler","ListSuccessResult","Storage","constructor","params","entity","client","tableName","gsiAmount","patterns","patternHandler","converter","compressionHandler","fetch","id","tenant","result","get","PK","SK","error","Error","success","data","oneFromStorage","ex","store","auditLog","structuredClone","item","oneToStorage","put","list","handle","create","listFromStorage","items","lastEvaluatedKey","createStorage"],"sources":["Storage.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createEntity } from \"~/storage/entity.js\";\nimport type {\n IStorage,\n IStorageFetchParams,\n IStorageFetchResult,\n IStorageListParams,\n IStorageListResult,\n IStorageStoreParams,\n IStorageStoreResult\n} from \"~/storage/abstractions/Storage.js\";\nimport { Converter } from \"~/storage/Converter.js\";\nimport { createAccessPatterns } from \"~/storage/accessPatterns/index.js\";\nimport { AccessPatternHandler } from \"~/storage/AccessPatternHandler.js\";\nimport { ListSuccessResult } from \"~/storage/results/index.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\nexport interface IStorageParams {\n compressionHandler: CompressionHandler.Interface;\n client: DynamoDBDocument;\n tableName: string | undefined;\n}\n\nexport class Storage implements IStorage {\n private readonly entity;\n private readonly converter;\n private readonly patternHandler;\n\n public constructor(params: IStorageParams) {\n const { entity } = createEntity({\n client: params.client,\n tableName: params.tableName,\n gsiAmount: 10\n });\n\n this.entity = entity;\n\n const patterns = createAccessPatterns({\n entity\n });\n this.patternHandler = new AccessPatternHandler({\n patterns\n });\n\n this.converter = new Converter({\n compressionHandler: params.compressionHandler,\n patternHandler: this.patternHandler\n });\n }\n\n public async fetch(params: IStorageFetchParams): Promise<IStorageFetchResult> {\n const { id, tenant } = params;\n\n try {\n const result = await this.entity.get({\n PK: `T#${tenant}#AUDIT_LOG`,\n SK: `${id}`\n });\n if (!result) {\n return {\n error: new Error(`Audit log entry \"${id}\" not found.`),\n success: false\n };\n }\n return {\n data: await this.converter.oneFromStorage(result),\n success: true\n };\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n }\n\n public async store(params: IStorageStoreParams): Promise<IStorageStoreResult> {\n const auditLog = structuredClone(params.data);\n\n try {\n const item = await this.converter.oneToStorage(auditLog);\n await this.entity.put(item);\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n\n return {\n success: true,\n data: auditLog\n };\n }\n\n public async list(params: IStorageListParams): Promise<IStorageListResult> {\n try {\n const result = await this.patternHandler.handle(params);\n\n return ListSuccessResult.create({\n data: await this.converter.listFromStorage(result.items),\n lastEvaluatedKey: result.lastEvaluatedKey\n });\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n }\n}\n\nexport const createStorage = (params: IStorageParams): IStorage => {\n return new Storage(params);\n};\n"],"mappings":"AACA,SAASA,YAAY;AAUrB,SAASC,SAAS;AAClB,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAS1B,OAAO,MAAMC,OAAO,CAAqB;EAK9BC,WAAWA,CAACC,MAAsB,EAAE;IACvC,MAAM;MAAEC;IAAO,CAAC,GAAGR,YAAY,CAAC;MAC5BS,MAAM,EAAEF,MAAM,CAACE,MAAM;MACrBC,SAAS,EAAEH,MAAM,CAACG,SAAS;MAC3BC,SAAS,EAAE;IACf,CAAC,CAAC;IAEF,IAAI,CAACH,MAAM,GAAGA,MAAM;IAEpB,MAAMI,QAAQ,GAAGV,oBAAoB,CAAC;MAClCM;IACJ,CAAC,CAAC;IACF,IAAI,CAACK,cAAc,GAAG,IAAIV,oBAAoB,CAAC;MAC3CS;IACJ,CAAC,CAAC;IAEF,IAAI,CAACE,SAAS,GAAG,IAAIb,SAAS,CAAC;MAC3Bc,kBAAkB,EAAER,MAAM,CAACQ,kBAAkB;MAC7CF,cAAc,EAAE,IAAI,CAACA;IACzB,CAAC,CAAC;EACN;EAEA,M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AAiB,CAACiC,MAAM,CAAC;QAC5BX,IAAI,EAAE,MAAM,IAAI,CAACZ,SAAS,CAACwB,eAAe,CAACnB,MAAM,CAACoB,KAAK,CAAC;QACxDC,gBAAgB,EAAErB,MAAM,CAACqB;MAC7B,CAAC,CAAC;IACN,CAAC,CAAC,OAAOZ,EAAE,EAAE;MACT,OAAO;QACHL,KAAK,EAAEK,EAAE;QACTH,OAAO,EAAE;MACb,CAAC;IACL;EACJ;AACJ;AAEA,OAAO,MAAMgB,aAAa,GAAIlC,MAAsB,IAAe;EAC/D,OAAO,IAAIF,OAAO,CAACE,MAAM,CAAC;AAC9B,CAAC","ignoreList":[]}
@@ -1 +1 @@
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
+ {"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 +1 @@
1
- {"version":3,"names":["BaseAccessPattern","createPartitionKey","params","tenant","app","entity","action","createdBy","AppEntityActionCreatedByAccessPattern","handles","mustInclude","mustNotInclude","list","options","createOptions","result","query","partitionKey","populateResult","createKeys","item","time","createdOn","getTime","id","sortKey"],"sources":["AppEntityActionCreatedByAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"~/storage/types.js\";\nimport type { IStorageListByAppEntityActionCreatedByParams } from \"~/storage/abstractions/Storage.js\";\nimport { BaseAccessPattern } from \"~/storage/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/storage/abstractions/AccessPattern.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n action: string;\n entity: string;\n createdBy: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}#ACTION#${params.action}#CREATEDBY#${params.createdBy}`;\n};\n\nexport class AppEntityActionCreatedByAccessPattern<\n T extends\n IStorageListByAppEntityActionCreatedByParams = IStorageListByAppEntityActionCreatedByParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\", \"action\", \"entity\", \"createdBy\"],\n mustNotInclude: [\"entityId\"]\n };\n }\n\n public async list(params: T): Promise<IAccessPatternListResult> {\n const options = this.createOptions(params);\n\n const result = await this.query({\n partitionKey: createPartitionKey(params),\n options\n });\n return this.populateResult(result);\n }\n\n public createKeys(item: IAuditLog): IAccessPatternCreateKeysResult {\n const time = item.createdOn.getTime();\n\n return {\n partitionKey: createPartitionKey({\n ...item,\n createdBy: item.createdBy.id\n }),\n sortKey: time\n };\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB;AAe1B,MAAMC,kBAAkB,GAAIC,MAAiC,IAAK;EAC9D,OAAO,KAAKA,MAAM,CAACC,MAAM,kBAAkBD,MAAM,CAACE,GAAG,WAAWF,MAAM,CAACG,MAAM,WAAWH,MAAM,CAACI,MAAM,cAAcJ,MAAM,CAACK,SAAS,EAAE;AACzI,CAAC;AAED,OAAO,MAAMC,qCAAqC,SAGxCR,iBAAiB,CAAI;EACXS,OAAOA,CAAA,EAA0B;IAC7C,OAAO;MACHC,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC;MACrDC,cAAc,EAAE,CAAC,UAAU;IAC/B,CAAC;EACL;EAEA,MAAaC,IAAIA,CAACV,MAAS,EAAqC;IAC5D,MAAMW,OAAO,GAAG,IAAI,CAACC,aAAa,CAACZ,MAAM,CAAC;IAE1C,MAAMa,MAAM,GAAG,MAAM,IAAI,CAACC,KAAK,CAAC;MAC5BC,YAAY,EAAEhB,kBAAkB,CAACC,MAAM,CAAC;MACxCW;IACJ,CAAC,CAAC;IACF,OAAO,IAAI,CAACK,cAAc,CAACH,MAAM,CAAC;EACtC;EAEOI,UAAUA,CAACC,IAAe,EAAkC;IAC/D,MAAMC,IAAI,GAAGD,IAAI,CAACE,SAAS,CAACC,OAAO,CAAC,CAAC;IAErC,OAAO;MACHN,YAAY,EAAEhB,kBAAkB,CAAC;QAC7B,GAAGmB,IAAI;QACPb,SAAS,EAAEa,IAAI,CAACb,SAAS,CAACiB;MAC9B,CAAC,CAAC;MACFC,OAAO,EAAEJ;IACb,CAAC;EACL;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["BaseAccessPattern","createPartitionKey","params","tenant","app","entity","action","createdBy","AppEntityActionCreatedByAccessPattern","handles","mustInclude","mustNotInclude","list","options","createOptions","result","query","partitionKey","populateResult","createKeys","item","time","createdOn","getTime","id","sortKey"],"sources":["AppEntityActionCreatedByAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"~/storage/types.js\";\nimport type { IStorageListByAppEntityActionCreatedByParams } from \"~/storage/abstractions/Storage.js\";\nimport { BaseAccessPattern } from \"~/storage/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/storage/abstractions/AccessPattern.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n action: string;\n entity: string;\n createdBy: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}#ACTION#${params.action}#CREATEDBY#${params.createdBy}`;\n};\n\nexport class AppEntityActionCreatedByAccessPattern<\n T extends IStorageListByAppEntityActionCreatedByParams =\n IStorageListByAppEntityActionCreatedByParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\", \"action\", \"entity\", \"createdBy\"],\n mustNotInclude: [\"entityId\"]\n };\n }\n\n public async list(params: T): Promise<IAccessPatternListResult> {\n const options = this.createOptions(params);\n\n const result = await this.query({\n partitionKey: createPartitionKey(params),\n options\n });\n return this.populateResult(result);\n }\n\n public createKeys(item: IAuditLog): IAccessPatternCreateKeysResult {\n const time = item.createdOn.getTime();\n\n return {\n partitionKey: createPartitionKey({\n ...item,\n createdBy: item.createdBy.id\n }),\n sortKey: time\n };\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB;AAe1B,MAAMC,kBAAkB,GAAIC,MAAiC,IAAK;EAC9D,OAAO,KAAKA,MAAM,CAACC,MAAM,kBAAkBD,MAAM,CAACE,GAAG,WAAWF,MAAM,CAACG,MAAM,WAAWH,MAAM,CAACI,MAAM,cAAcJ,MAAM,CAACK,SAAS,EAAE;AACzI,CAAC;AAED,OAAO,MAAMC,qCAAqC,SAGxCR,iBAAiB,CAAI;EACXS,OAAOA,CAAA,EAA0B;IAC7C,OAAO;MACHC,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC;MACrDC,cAAc,EAAE,CAAC,UAAU;IAC/B,CAAC;EACL;EAEA,MAAaC,IAAIA,CAACV,MAAS,EAAqC;IAC5D,MAAMW,OAAO,GAAG,IAAI,CAACC,aAAa,CAACZ,MAAM,CAAC;IAE1C,MAAMa,MAAM,GAAG,MAAM,IAAI,CAACC,KAAK,CAAC;MAC5BC,YAAY,EAAEhB,kBAAkB,CAACC,MAAM,CAAC;MACxCW;IACJ,CAAC,CAAC;IACF,OAAO,IAAI,CAACK,cAAc,CAACH,MAAM,CAAC;EACtC;EAEOI,UAAUA,CAACC,IAAe,EAAkC;IAC/D,MAAMC,IAAI,GAAGD,IAAI,CAACE,SAAS,CAACC,OAAO,CAAC,CAAC;IAErC,OAAO;MACHN,YAAY,EAAEhB,kBAAkB,CAAC;QAC7B,GAAGmB,IAAI;QACPb,SAAS,EAAEa,IAAI,CAACb,SAAS,CAACiB;MAC9B,CAAC,CAAC;MACFC,OAAO,EAAEJ;IACb,CAAC;EACL;AACJ","ignoreList":[]}