@webiny/api-audit-logs 6.4.12-beta.5 → 6.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstractions.d.ts +5 -0
- package/abstractions.js +2 -1
- package/abstractions.js.map +1 -1
- package/context/AuditLogsContextValue.js +1 -1
- package/context/AuditLogsContextValue.js.map +1 -1
- package/context/index.d.ts +0 -3
- package/context/index.js +2 -8
- package/context/index.js.map +1 -1
- package/graphql/validation.d.ts +3 -3
- package/index.d.ts +1 -4
- package/index.js +1 -3
- package/index.js.map +1 -1
- package/package.json +23 -25
- package/storage/types.d.ts +0 -35
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js +4 -7
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js.map +1 -1
- package/subscriptions/ai/handlers/AuditLogAiAfterGenerateTextHandler.d.ts +11 -0
- package/subscriptions/ai/handlers/AuditLogAiAfterGenerateTextHandler.js +41 -0
- package/subscriptions/ai/handlers/AuditLogAiAfterGenerateTextHandler.js.map +1 -0
- package/subscriptions/ai/handlers/AuditLogAiBeforeGenerateTextHandler.d.ts +11 -0
- package/subscriptions/ai/handlers/AuditLogAiBeforeGenerateTextHandler.js +38 -0
- package/subscriptions/ai/handlers/AuditLogAiBeforeGenerateTextHandler.js.map +1 -0
- package/subscriptions/ai/handlers/AuditLogAiGenerateTextErrorHandler.d.ts +11 -0
- package/subscriptions/ai/handlers/AuditLogAiGenerateTextErrorHandler.js +40 -0
- package/subscriptions/ai/handlers/AuditLogAiGenerateTextErrorHandler.js.map +1 -0
- package/subscriptions/ai/index.d.ts +2 -0
- package/subscriptions/ai/index.js +11 -0
- package/subscriptions/ai/index.js.map +1 -0
- package/subscriptions/index.js +2 -0
- package/subscriptions/index.js.map +1 -1
- package/storage/AccessPatternHandler.d.ts +0 -14
- package/storage/AccessPatternHandler.js +0 -39
- package/storage/AccessPatternHandler.js.map +0 -1
- package/storage/Converter.d.ts +0 -16
- package/storage/Converter.js +0 -49
- package/storage/Converter.js.map +0 -1
- package/storage/Storage.d.ts +0 -18
- package/storage/Storage.js +0 -81
- package/storage/Storage.js.map +0 -1
- package/storage/abstractions/AccessPattern.d.ts +0 -24
- package/storage/abstractions/AccessPattern.js +0 -0
- package/storage/abstractions/AccessPatternHandler.d.ts +0 -13
- package/storage/abstractions/AccessPatternHandler.js +0 -0
- package/storage/abstractions/Converter.d.ts +0 -6
- package/storage/abstractions/Converter.js +0 -0
- package/storage/accessPatterns/AppAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/AppAccessPattern.js +0 -35
- package/storage/accessPatterns/AppAccessPattern.js.map +0 -1
- package/storage/accessPatterns/AppCreatedByAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/AppCreatedByAccessPattern.js +0 -38
- package/storage/accessPatterns/AppCreatedByAccessPattern.js.map +0 -1
- package/storage/accessPatterns/AppEntityAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/AppEntityAccessPattern.js +0 -35
- package/storage/accessPatterns/AppEntityAccessPattern.js.map +0 -1
- package/storage/accessPatterns/AppEntityActionAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/AppEntityActionAccessPattern.js +0 -35
- package/storage/accessPatterns/AppEntityActionAccessPattern.js.map +0 -1
- package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js +0 -38
- package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js.map +0 -1
- package/storage/accessPatterns/AppEntityCreatedByAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js +0 -38
- package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js.map +0 -1
- package/storage/accessPatterns/BaseAccessPattern.d.ts +0 -32
- package/storage/accessPatterns/BaseAccessPattern.js +0 -60
- package/storage/accessPatterns/BaseAccessPattern.js.map +0 -1
- package/storage/accessPatterns/CreatedByAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/CreatedByAccessPattern.js +0 -38
- package/storage/accessPatterns/CreatedByAccessPattern.js.map +0 -1
- package/storage/accessPatterns/CreatedOnAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/CreatedOnAccessPattern.js +0 -38
- package/storage/accessPatterns/CreatedOnAccessPattern.js.map +0 -1
- package/storage/accessPatterns/DefaultAccessPattern.d.ts +0 -15
- package/storage/accessPatterns/DefaultAccessPattern.js +0 -35
- package/storage/accessPatterns/DefaultAccessPattern.js.map +0 -1
- package/storage/accessPatterns/EntityIdAccessPattern.d.ts +0 -9
- package/storage/accessPatterns/EntityIdAccessPattern.js +0 -38
- package/storage/accessPatterns/EntityIdAccessPattern.js.map +0 -1
- package/storage/accessPatterns/index.d.ts +0 -6
- package/storage/accessPatterns/index.js +0 -57
- package/storage/accessPatterns/index.js.map +0 -1
- package/storage/cursorSchema.d.ts +0 -4
- package/storage/cursorSchema.js +0 -22
- package/storage/cursorSchema.js.map +0 -1
- package/storage/entity.d.ts +0 -36
- package/storage/entity.js +0 -120
- package/storage/entity.js.map +0 -1
- package/storage/results/ListErrorResult.d.ts +0 -10
- package/storage/results/ListErrorResult.js +0 -12
- package/storage/results/ListErrorResult.js.map +0 -1
- package/storage/results/ListSuccessResult.d.ts +0 -14
- package/storage/results/ListSuccessResult.js +0 -17
- package/storage/results/ListSuccessResult.js.map +0 -1
- package/storage/results/index.d.ts +0 -2
- package/storage/results/index.js +0 -2
- package/storage/startKey.d.ts +0 -6
- package/storage/startKey.js +0 -8
- package/storage/startKey.js.map +0 -1
package/abstractions.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { AuditLogsContext as Context } from "./types.js";
|
|
2
|
+
import type { IStorage } from "./storage/abstractions/Storage.js";
|
|
2
3
|
export declare const AuditLogsContext: import("@webiny/di").Abstraction<Context>;
|
|
3
4
|
export declare namespace AuditLogsContext {
|
|
4
5
|
type Interface = Context;
|
|
5
6
|
}
|
|
7
|
+
export declare const AuditLogsStorage: import("@webiny/di").Abstraction<IStorage>;
|
|
8
|
+
export declare namespace AuditLogsStorage {
|
|
9
|
+
type Interface = IStorage;
|
|
10
|
+
}
|
package/abstractions.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
const AuditLogsContext = createAbstraction("AuditLogsContext");
|
|
3
|
-
|
|
3
|
+
const AuditLogsStorage = createAbstraction("AuditLogsStorage");
|
|
4
|
+
export { AuditLogsContext, AuditLogsStorage };
|
|
4
5
|
|
|
5
6
|
//# sourceMappingURL=abstractions.js.map
|
package/abstractions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstractions.js","sources":["../src/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { AuditLogsContext as Context } from \"~/types.js\";\n\n// TODO: this is a bridge for legacy context; needs review and refactor of code that uses it.\n\nexport const AuditLogsContext = createAbstraction<Context>(\"AuditLogsContext\");\n\nexport namespace AuditLogsContext {\n export type Interface = Context;\n}\n"],"names":["AuditLogsContext","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"abstractions.js","sources":["../src/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { AuditLogsContext as Context } from \"~/types.js\";\nimport type { IStorage } from \"~/storage/abstractions/Storage.js\";\n\n// TODO: this is a bridge for legacy context; needs review and refactor of code that uses it.\n\nexport const AuditLogsContext = createAbstraction<Context>(\"AuditLogsContext\");\n\nexport namespace AuditLogsContext {\n export type Interface = Context;\n}\n\nexport const AuditLogsStorage = createAbstraction<IStorage>(\"AuditLogsStorage\");\n\nexport namespace AuditLogsStorage {\n export type Interface = IStorage;\n}\n"],"names":["AuditLogsContext","createAbstraction","AuditLogsStorage"],"mappings":";AAMO,MAAMA,mBAAmBC,kBAA2B;AAMpD,MAAMC,mBAAmBD,kBAA4B"}
|
|
@@ -105,7 +105,7 @@ class AuditLogsContextValueImpl {
|
|
|
105
105
|
for (const permission of permissions){
|
|
106
106
|
if ("*" === permission.name) return;
|
|
107
107
|
if ("al.*" === permission.name) return;
|
|
108
|
-
|
|
108
|
+
if (permission.name === `al.${auditLog.action}`) return;
|
|
109
109
|
}
|
|
110
110
|
throw new NotAuthorizedError({
|
|
111
111
|
message: "You cannot access audit logs."
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context/AuditLogsContextValue.js","sources":["../../src/context/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"],"names":["AuditLogsContextValueImpl","params","payload","context","expiresAt","convertExpiresAtDaysToDate","auditLog","mdbid","Date","JSON","beforeCreateEvent","AuditLogBeforeCreateEvent","input","Object","result","afterCreateEvent","AuditLogAfterCreateEvent","original","beforeUpdateEvent","AuditLogBeforeUpdateEvent","afterUpdateEvent","AuditLogAfterUpdateEvent","id","Error","permissions","permission","NotAuthorizedError","identity","createAuditLogsContextValue"],"mappings":";;;;AA2BA,MAAMA;IAMF,YAAmBC,MAAoC,CAAE;QACrD,IAAI,CAAC,UAAU,GAAGA,OAAO,UAAU;QACnC,IAAI,CAAC,mBAAmB,GAAGA,OAAO,mBAAmB;QACrD,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,cAAc,GAAGA,OAAO,cAAc;IAC/C;IAEA,MAAa,eAAeC,OAAwB,EAAsB;QACtE,MAAMC,UAAU,IAAI,CAAC,UAAU;QAC/B,MAAMC,YAAYC,2BAA2B,IAAI,CAAC,mBAAmB;QAErE,MAAMC,WAAsB;YACxB,IAAIC;YACJ,QAAQ,IAAI,CAAC,WAAW;YACxB,WAAW,IAAI,CAAC,WAAW;YAC3B,WAAW,IAAIC;YACf,GAAGN,OAAO;YACV,SAASO,KAAK,SAAS,CAACP,QAAQ,OAAO;YACvCE;QACJ;QACA,MAAM,IAAI,CAAC,gBAAgB,CAACE;QAE5B,MAAMI,oBAAoB,IAAIC,0BAA0B;YACpD,UAAUL;YACVH;YACA,aAAYS,KAAK;gBACbC,OAAO,MAAM,CAACP,UAAUM;YAC5B;QACJ;QACA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACF;QAElC,MAAMI,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YACpC,MAAMR;QACV;QACA,IAAIQ,OAAO,OAAO,EAAE;YAChB,MAAMC,mBAAmB,IAAIC,yBAAyB;gBAClD,UAAUV;gBACVH;YACJ;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACY;YAClC,OAAOD,OAAO,IAAI;QACtB;QACA,MAAMA,OAAO,KAAK;IACtB;IAEA,MAAa,eACTG,QAAmB,EACnBf,OAAiC,EACf;QAClB,MAAMC,UAAU,IAAI,CAAC,UAAU;QAC/B,MAAMG,WAAsB;YACxB,GAAGW,QAAQ;YACX,GAAGf,OAAO;YACV,SAASA,QAAQ,OAAO,GAAGO,KAAK,SAAS,CAACP,QAAQ,OAAO,IAAIe,SAAS,OAAO;QACjF;QACA,MAAM,IAAI,CAAC,gBAAgB,CAACX;QAE5B,MAAMY,oBAAoB,IAAIC,0BAA0B;YACpDF;YACAX;YACAH;YACA,aAAYS,KAAK;gBACbC,OAAO,MAAM,CAACP,UAAUM;YAC5B;QACJ;QACA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACM;QAElC,MAAMJ,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YACpC,MAAMR;QACV;QACA,IAAIQ,OAAO,OAAO,EAAE;YAChB,MAAMM,mBAAmB,IAAIC,yBAAyB;gBAClD,UAAUJ;gBACV,UAAUX;gBACVH;YACJ;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACiB;YAClC,OAAON,OAAO,IAAI;QACtB;QACA,MAAMA,OAAO,KAAK;IACtB;IAEA,MAAa,YAAYQ,EAAU,EAA6B;QAC5D,MAAMR,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YACpCQ;YACA,QAAQ,IAAI,CAAC,WAAW;QAC5B;QACA,IAAIR,OAAO,OAAO,EAAE;YAChB,MAAM,IAAI,CAAC,gBAAgB,CAACA,OAAO,IAAI;YACvC,OAAOA,OAAO,IAAI;QACtB;QACA,MAAMA,OAAO,KAAK;IACtB;IAEA,MAAa,cAAcb,MAA4B,EAAiC;QACpF,MAAMa,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACnC,GAAGb,MAAM;YACT,QAAQ,IAAI,CAAC,WAAW;QAC5B;QACA,IAAIa,OAAO,OAAO,EACd,OAAO;YACH,OAAOA,OAAO,IAAI;YAClB,MAAM;gBACF,QAAQA,OAAO,IAAI,CAAC,KAAK,IAAI;gBAC7B,cAAcA,OAAO,IAAI,CAAC,YAAY;YAC1C;QACJ;QAEJ,MAAMA,OAAO,KAAK;IACtB;IAEA,MAAc,iBAAiBR,QAAmC,EAAiB;QAC/E,IAAI,CAACA,SAAS,MAAM,EAChB,MAAM,IAAIiB,MAAM;QAEpB,MAAMC,cAAc,MAAM,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,cAAc,CAAC;QACpE,KAAK,MAAMC,cAAcD,YAAa;YAClC,IAAIC,AAAoB,QAApBA,WAAW,IAAI,EACf;YAEJ,IAAIA,AAAoB,WAApBA,WAAW,IAAI,EACf;
|
|
1
|
+
{"version":3,"file":"context/AuditLogsContextValue.js","sources":["../../src/context/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"],"names":["AuditLogsContextValueImpl","params","payload","context","expiresAt","convertExpiresAtDaysToDate","auditLog","mdbid","Date","JSON","beforeCreateEvent","AuditLogBeforeCreateEvent","input","Object","result","afterCreateEvent","AuditLogAfterCreateEvent","original","beforeUpdateEvent","AuditLogBeforeUpdateEvent","afterUpdateEvent","AuditLogAfterUpdateEvent","id","Error","permissions","permission","NotAuthorizedError","identity","createAuditLogsContextValue"],"mappings":"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"}
|
package/context/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
2
|
import type { AuditLogsContext } from "../types.js";
|
|
4
3
|
export interface ISetupContextOptions {
|
|
5
4
|
deleteLogsAfterDays: number | undefined;
|
|
6
|
-
tableName: string | undefined;
|
|
7
|
-
documentClient: DynamoDBDocument | undefined;
|
|
8
5
|
}
|
|
9
6
|
export declare const createAuditLogsContext: (params?: ISetupContextOptions) => ContextPlugin<AuditLogsContext>;
|
package/context/index.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
|
2
2
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
3
|
import { createAuditLogsContextValue } from "./AuditLogsContextValue.js";
|
|
4
|
-
import {
|
|
5
|
-
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
4
|
+
import { AuditLogsStorage } from "../abstractions.js";
|
|
6
5
|
const getDeleteLogsAfterDays = (days)=>{
|
|
7
6
|
if (days && days > 0) return days;
|
|
8
7
|
return 60;
|
|
9
8
|
};
|
|
10
9
|
const createAuditLogsContext = (params)=>{
|
|
11
10
|
const plugin = new ContextPlugin(async (context)=>{
|
|
12
|
-
const
|
|
13
|
-
const storage = createStorage({
|
|
14
|
-
tableName: params?.tableName,
|
|
15
|
-
client: params?.documentClient || context.db.driver.getClient(),
|
|
16
|
-
compressionHandler
|
|
17
|
-
});
|
|
11
|
+
const storage = context.container.resolve(AuditLogsStorage);
|
|
18
12
|
const eventPublisher = context.container.resolve(EventPublisher);
|
|
19
13
|
context.auditLogs = createAuditLogsContextValue({
|
|
20
14
|
getContext: ()=>context,
|
package/context/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context/index.js","sources":["../../src/context/index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"context/index.js","sources":["../../src/context/index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\nimport { createAuditLogsContextValue } from \"./AuditLogsContextValue.js\";\nimport { AuditLogsStorage } from \"~/abstractions.js\";\n\nexport interface ISetupContextOptions {\n deleteLogsAfterDays: number | 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 = context.container.resolve(AuditLogsStorage);\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"],"names":["getDeleteLogsAfterDays","days","createAuditLogsContext","params","plugin","ContextPlugin","context","storage","AuditLogsStorage","eventPublisher","EventPublisher","createAuditLogsContextValue"],"mappings":";;;;AAUA,MAAMA,yBAAyB,CAACC;IAC5B,IAAIA,QAAQA,OAAO,GACf,OAAOA;IAKX,OAAO;AACX;AAEO,MAAMC,yBAAyB,CAACC;IACnC,MAAMC,SAAS,IAAIC,cAAgC,OAAMC;QACrD,MAAMC,UAAUD,QAAQ,SAAS,CAAC,OAAO,CAACE;QAE1C,MAAMC,iBAAiBH,QAAQ,SAAS,CAAC,OAAO,CAACI;QAEjDJ,QAAQ,SAAS,GAAGK,4BAA4B;YAC5C,YAAY,IACDL;YAEX,qBAAqBN,uBAAuBG,QAAQ;YACpDI;YACAE;QACJ;IACJ;IAEAL,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX"}
|
package/graphql/validation.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare const listValidationSchema: zod.ZodObject<{
|
|
|
7
7
|
app: zod.ZodOptional<zod.ZodString>;
|
|
8
8
|
entity: zod.ZodOptional<zod.ZodString>;
|
|
9
9
|
entityId: zod.ZodOptional<zod.ZodString>;
|
|
10
|
-
createdOn_gte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate
|
|
11
|
-
createdOn_lte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate
|
|
10
|
+
createdOn_gte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
|
|
11
|
+
createdOn_lte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
|
|
12
12
|
createdBy: zod.ZodOptional<zod.ZodString>;
|
|
13
13
|
action: zod.ZodOptional<zod.ZodString>;
|
|
14
14
|
}, zod.core.$strip>;
|
|
@@ -17,5 +17,5 @@ export declare const listValidationSchema: zod.ZodObject<{
|
|
|
17
17
|
ASC: "ASC";
|
|
18
18
|
DESC: "DESC";
|
|
19
19
|
}>>;
|
|
20
|
-
limit: zod.ZodDefault<zod.ZodPreprocess<zod.ZodOptional<zod.ZodNumber
|
|
20
|
+
limit: zod.ZodDefault<zod.ZodPreprocess<zod.ZodOptional<zod.ZodNumber>>>;
|
|
21
21
|
}, zod.core.$strip>;
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
2
|
export interface ICreateAuditLogsParams {
|
|
4
|
-
deleteLogsAfterDays
|
|
5
|
-
tableName?: string;
|
|
6
|
-
documentClient?: DynamoDBDocument;
|
|
3
|
+
deleteLogsAfterDays?: number | undefined;
|
|
7
4
|
}
|
|
8
5
|
export declare const createAuditLogs: (params?: ICreateAuditLogsParams) => (ContextPlugin<import("./types.js").AuditLogsContext> | import("@webiny/handler-graphql/index.js").GraphQLSchemaPlugin<import("./types.js").AuditLogsContext>)[];
|
|
9
6
|
export * from "./config.js";
|
package/index.js
CHANGED
|
@@ -15,9 +15,7 @@ const createAuditLogs = (params)=>{
|
|
|
15
15
|
subscriptionsPlugin,
|
|
16
16
|
createGraphQLSchema(),
|
|
17
17
|
createAuditLogsContext({
|
|
18
|
-
|
|
19
|
-
deleteLogsAfterDays: params?.deleteLogsAfterDays,
|
|
20
|
-
documentClient: params?.documentClient
|
|
18
|
+
deleteLogsAfterDays: params?.deleteLogsAfterDays
|
|
21
19
|
})
|
|
22
20
|
];
|
|
23
21
|
};
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/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
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/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 { AuditLogsContext } from \"./abstractions.js\";\n\nexport interface ICreateAuditLogsParams {\n deleteLogsAfterDays?: number | undefined;\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 deleteLogsAfterDays: params?.deleteLogsAfterDays\n })\n ];\n};\nexport * from \"~/config.js\";\n"],"names":["createAuditLogs","params","subscriptionsPlugin","ContextPlugin","context","AuditLogsContext","createSubscriptionHooks","createGraphQLSchema","createAuditLogsContext"],"mappings":";;;;;;AAUO,MAAMA,kBAAkB,CAACC;IAC5B,MAAMC,sBAAsB,IAAIC,cAA0CC,CAAAA;QACtE,IAAI,CAACA,QAAQ,GAAG,CAAC,aAAa,CAAC,cAC3B;QAGJA,QAAQ,SAAS,CAAC,gBAAgB,CAACC,kBAAkBD;QAErDE,wBAAwBF;IAC5B;IAEAF,oBAAoB,IAAI,GAAG;IAC3B,OAAO;QACHA;QACAK;QACAC,uBAAuB;YACnB,qBAAqBP,QAAQ;QACjC;KACH;AACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-audit-logs",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0-beta.1",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "./index.js",
|
|
6
6
|
"./*": "./*"
|
|
@@ -22,33 +22,31 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@webiny/handler-aws": "6.
|
|
26
|
-
"@webiny/plugins": "6.
|
|
27
|
-
"@webiny/project-utils": "6.
|
|
25
|
+
"@webiny/handler-aws": "6.5.0-beta.1",
|
|
26
|
+
"@webiny/plugins": "6.5.0-beta.1",
|
|
27
|
+
"@webiny/project-utils": "6.5.0-beta.1",
|
|
28
28
|
"graphql": "16.14.2",
|
|
29
|
-
"typescript": "
|
|
30
|
-
"vitest": "
|
|
29
|
+
"typescript": "7.0.2",
|
|
30
|
+
"vitest": "4.1.10"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@webiny/api": "6.
|
|
34
|
-
"@webiny/api-aco": "6.
|
|
35
|
-
"@webiny/api-core": "6.
|
|
36
|
-
"@webiny/api-file-manager": "6.
|
|
37
|
-
"@webiny/api-headless-cms": "6.
|
|
38
|
-
"@webiny/api-mailer": "6.
|
|
39
|
-
"@webiny/api-website-builder": "6.
|
|
40
|
-
"@webiny/
|
|
41
|
-
"@webiny/
|
|
42
|
-
"@webiny/
|
|
43
|
-
"@webiny/
|
|
44
|
-
"@webiny/
|
|
45
|
-
"@webiny/
|
|
46
|
-
"@webiny/handler": "6.
|
|
47
|
-
"@webiny/
|
|
48
|
-
"@webiny/
|
|
49
|
-
"
|
|
50
|
-
"@webiny/wcp": "6.4.12-beta.5",
|
|
51
|
-
"zod": "4.6.5"
|
|
33
|
+
"@webiny/api": "6.5.0-beta.1",
|
|
34
|
+
"@webiny/api-aco": "6.5.0-beta.1",
|
|
35
|
+
"@webiny/api-core": "6.5.0-beta.1",
|
|
36
|
+
"@webiny/api-file-manager": "6.5.0-beta.1",
|
|
37
|
+
"@webiny/api-headless-cms": "6.5.0-beta.1",
|
|
38
|
+
"@webiny/api-mailer": "6.5.0-beta.1",
|
|
39
|
+
"@webiny/api-website-builder": "6.5.0-beta.1",
|
|
40
|
+
"@webiny/build-tools": "6.5.0-beta.1",
|
|
41
|
+
"@webiny/common-audit-logs": "6.5.0-beta.1",
|
|
42
|
+
"@webiny/error": "6.5.0-beta.1",
|
|
43
|
+
"@webiny/feature": "6.5.0-beta.1",
|
|
44
|
+
"@webiny/handler": "6.5.0-beta.1",
|
|
45
|
+
"@webiny/handler-db": "6.5.0-beta.1",
|
|
46
|
+
"@webiny/handler-graphql": "6.5.0-beta.1",
|
|
47
|
+
"@webiny/utils": "6.5.0-beta.1",
|
|
48
|
+
"@webiny/wcp": "6.5.0-beta.1",
|
|
49
|
+
"zod": "4.4.3"
|
|
52
50
|
},
|
|
53
51
|
"webiny": {
|
|
54
52
|
"publishFrom": "dist"
|
package/storage/types.d.ts
CHANGED
|
@@ -17,38 +17,3 @@ export interface IAuditLog {
|
|
|
17
17
|
expiresAt: Date;
|
|
18
18
|
content: string;
|
|
19
19
|
}
|
|
20
|
-
export interface IStorageAuditLog extends Omit<IAuditLog, "createdOn" | "content" | "expiresAt"> {
|
|
21
|
-
expiresAt: string;
|
|
22
|
-
createdOn: string;
|
|
23
|
-
content: string;
|
|
24
|
-
}
|
|
25
|
-
export interface IStorageItem {
|
|
26
|
-
PK: string;
|
|
27
|
-
SK: string;
|
|
28
|
-
TYPE: string;
|
|
29
|
-
GSI_TENANT: string;
|
|
30
|
-
GSI1_PK: string;
|
|
31
|
-
GSI1_SK: number;
|
|
32
|
-
GSI2_PK: string;
|
|
33
|
-
GSI2_SK: number;
|
|
34
|
-
GSI3_PK: string;
|
|
35
|
-
GSI3_SK: number;
|
|
36
|
-
GSI4_PK: string;
|
|
37
|
-
GSI4_SK: number;
|
|
38
|
-
GSI5_PK: string;
|
|
39
|
-
GSI5_SK: number;
|
|
40
|
-
GSI6_PK: string;
|
|
41
|
-
GSI6_SK: number;
|
|
42
|
-
GSI7_PK: string;
|
|
43
|
-
GSI7_SK: number;
|
|
44
|
-
GSI8_PK: string;
|
|
45
|
-
GSI8_SK: number;
|
|
46
|
-
GSI9_PK: string;
|
|
47
|
-
GSI9_SK: number;
|
|
48
|
-
data: IStorageAuditLog;
|
|
49
|
-
expiresAt: number;
|
|
50
|
-
}
|
|
51
|
-
export interface IIndexStorageItem {
|
|
52
|
-
PK: string;
|
|
53
|
-
SK: string;
|
|
54
|
-
}
|
|
@@ -10,18 +10,15 @@ class AuditLogFolderAfterDeleteHandlerImpl {
|
|
|
10
10
|
async handle(event) {
|
|
11
11
|
try {
|
|
12
12
|
const { folder } = event.payload;
|
|
13
|
-
if ("
|
|
13
|
+
if ("PbPage" === folder.type) {
|
|
14
|
+
const createAuditLog = getAuditConfig(AUDIT.PAGE_BUILDER.PAGE_FOLDER.DELETE);
|
|
15
|
+
await createAuditLog("Folder deleted", folder, folder.id, this.context);
|
|
16
|
+
} else if ("FmFile" === folder.type) {
|
|
14
17
|
const createAuditLog = getAuditConfig(AUDIT.FILE_MANAGER.FILE_FOLDER.DELETE);
|
|
15
18
|
await createAuditLog("Folder deleted", folder, folder.id, this.context);
|
|
16
19
|
} else if (folder.type.startsWith("cms:")) {
|
|
17
20
|
const createAuditLog = getAuditConfig(AUDIT.HEADLESS_CMS.MODEL_FOLDER.DELETE);
|
|
18
21
|
await createAuditLog("Folder deleted", folder, folder.id, this.context);
|
|
19
|
-
} else if ("wb:page" === folder.type) {
|
|
20
|
-
const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.PAGE_FOLDER.DELETE);
|
|
21
|
-
await createAuditLog("Folder deleted", folder, folder.id, this.context);
|
|
22
|
-
} else if ("wb:redirect" === folder.type) {
|
|
23
|
-
const createAuditLog = getAuditConfig(AUDIT.WEBSITE_BUILDER.REDIRECT_FOLDER.DELETE);
|
|
24
|
-
await createAuditLog("Folder deleted", folder, folder.id, this.context);
|
|
25
22
|
}
|
|
26
23
|
} catch (error) {
|
|
27
24
|
throw _webiny_error.from(error, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js","sources":["../../../../src/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FolderAfterDeleteEventHandler } from \"@webiny/api-aco/features/folder/DeleteFolder/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\n\nclass AuditLogFolderAfterDeleteHandlerImpl implements FolderAfterDeleteEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: FolderAfterDeleteEventHandler.Event): Promise<void> {\n try {\n const { folder } = event.payload;\n if (folder.type === \"
|
|
1
|
+
{"version":3,"file":"subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js","sources":["../../../../src/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FolderAfterDeleteEventHandler } from \"@webiny/api-aco/features/folder/DeleteFolder/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\n\nclass AuditLogFolderAfterDeleteHandlerImpl implements FolderAfterDeleteEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: FolderAfterDeleteEventHandler.Event): Promise<void> {\n try {\n const { folder } = event.payload;\n if (folder.type === \"PbPage\") {\n const createAuditLog = getAuditConfig(AUDIT.PAGE_BUILDER.PAGE_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n } else if (folder.type === \"FmFile\") {\n const createAuditLog = getAuditConfig(AUDIT.FILE_MANAGER.FILE_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n } else if (folder.type.startsWith(\"cms:\")) {\n const createAuditLog = getAuditConfig(AUDIT.HEADLESS_CMS.MODEL_FOLDER.DELETE);\n await createAuditLog(\"Folder deleted\", folder, folder.id, this.context);\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing AuditLogFolderAfterDeleteHandler\",\n code: \"AUDIT_LOGS_AFTER_FOLDER_DELETE_HANDLER\"\n });\n }\n }\n}\n\nexport const AuditLogFolderAfterDeleteHandler = FolderAfterDeleteEventHandler.createImplementation({\n implementation: AuditLogFolderAfterDeleteHandlerImpl,\n dependencies: [AuditLogsContext]\n});\n"],"names":["AuditLogFolderAfterDeleteHandlerImpl","context","event","folder","createAuditLog","getAuditConfig","AUDIT","error","WebinyError","AuditLogFolderAfterDeleteHandler","FolderAfterDeleteEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IACF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA0C,EAAiB;QACpE,IAAI;YACA,MAAM,EAAEC,MAAM,EAAE,GAAGD,MAAM,OAAO;YAChC,IAAIC,AAAgB,aAAhBA,OAAO,IAAI,EAAe;gBAC1B,MAAMC,iBAAiBC,eAAeC,MAAM,YAAY,CAAC,WAAW,CAAC,MAAM;gBAC3E,MAAMF,eAAe,kBAAkBD,QAAQA,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO;YAC1E,OAAO,IAAIA,AAAgB,aAAhBA,OAAO,IAAI,EAAe;gBACjC,MAAMC,iBAAiBC,eAAeC,MAAM,YAAY,CAAC,WAAW,CAAC,MAAM;gBAC3E,MAAMF,eAAe,kBAAkBD,QAAQA,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO;YAC1E,OAAO,IAAIA,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS;gBACvC,MAAMC,iBAAiBC,eAAeC,MAAM,YAAY,CAAC,YAAY,CAAC,MAAM;gBAC5E,MAAMF,eAAe,kBAAkBD,QAAQA,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO;YAC1E;QACJ,EAAE,OAAOI,OAAO;YACZ,MAAMC,cAAAA,IAAgB,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,mCAAmCC,8BAA8B,oBAAoB,CAAC;IAC/F,gBAAgBV;IAChB,cAAc;QAACW;KAAiB;AACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AiAfterGenerateTextEventHandler } from "@webiny/api-core/features/ai/index.js";
|
|
2
|
+
import { AuditLogsContext } from "../../../abstractions.js";
|
|
3
|
+
declare class AuditLogAiAfterGenerateTextHandlerImpl implements AiAfterGenerateTextEventHandler.Interface {
|
|
4
|
+
private context;
|
|
5
|
+
constructor(context: AuditLogsContext.Interface);
|
|
6
|
+
handle(event: AiAfterGenerateTextEventHandler.Event): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare const AuditLogAiAfterGenerateTextHandler: typeof AuditLogAiAfterGenerateTextHandlerImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-core/features/ai/events").AiAfterGenerateTextEvent>>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import _webiny_error from "@webiny/error";
|
|
2
|
+
import { AiAfterGenerateTextEventHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { AuditLogsContext } from "../../../abstractions.js";
|
|
4
|
+
import { AUDIT } from "../../../config.js";
|
|
5
|
+
import { getAuditConfig } from "../../../utils/getAuditConfig.js";
|
|
6
|
+
class AuditLogAiAfterGenerateTextHandlerImpl {
|
|
7
|
+
constructor(context){
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
async handle(event) {
|
|
11
|
+
try {
|
|
12
|
+
const { requestId, result, duration } = event.payload;
|
|
13
|
+
const createAuditLog = getAuditConfig(AUDIT.AI.TEXT.GENERATE);
|
|
14
|
+
await createAuditLog("AI Generate Text", {
|
|
15
|
+
after: {
|
|
16
|
+
status: "success",
|
|
17
|
+
duration: Math.round(duration),
|
|
18
|
+
text: result.text,
|
|
19
|
+
usage: result.usage,
|
|
20
|
+
finishReason: result.finishReason,
|
|
21
|
+
steps: result.steps.length,
|
|
22
|
+
toolCalls: result.steps.reduce((sum, step)=>sum + step.toolCalls.length, 0)
|
|
23
|
+
}
|
|
24
|
+
}, requestId, this.context);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw _webiny_error.from(error, {
|
|
27
|
+
message: "Error while executing AuditLogAiAfterGenerateTextHandler",
|
|
28
|
+
code: "AUDIT_LOGS_AI_AFTER_GENERATE_TEXT"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const AuditLogAiAfterGenerateTextHandler = AiAfterGenerateTextEventHandler.createImplementation({
|
|
34
|
+
implementation: AuditLogAiAfterGenerateTextHandlerImpl,
|
|
35
|
+
dependencies: [
|
|
36
|
+
AuditLogsContext
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
export { AuditLogAiAfterGenerateTextHandler };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=AuditLogAiAfterGenerateTextHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions/ai/handlers/AuditLogAiAfterGenerateTextHandler.js","sources":["../../../../src/subscriptions/ai/handlers/AuditLogAiAfterGenerateTextHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AiAfterGenerateTextEventHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\n\nclass AuditLogAiAfterGenerateTextHandlerImpl implements AiAfterGenerateTextEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: AiAfterGenerateTextEventHandler.Event): Promise<void> {\n try {\n const { requestId, result, duration } = event.payload;\n const createAuditLog = getAuditConfig(AUDIT.AI.TEXT.GENERATE);\n\n await createAuditLog(\n \"AI Generate Text\",\n {\n after: {\n status: \"success\",\n duration: Math.round(duration),\n text: result.text,\n usage: result.usage,\n finishReason: result.finishReason,\n steps: result.steps.length,\n toolCalls: result.steps.reduce(\n (sum, step) => sum + step.toolCalls.length,\n 0\n )\n }\n },\n requestId,\n this.context\n );\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing AuditLogAiAfterGenerateTextHandler\",\n code: \"AUDIT_LOGS_AI_AFTER_GENERATE_TEXT\"\n });\n }\n }\n}\n\nexport const AuditLogAiAfterGenerateTextHandler =\n AiAfterGenerateTextEventHandler.createImplementation({\n implementation: AuditLogAiAfterGenerateTextHandlerImpl,\n dependencies: [AuditLogsContext]\n });\n"],"names":["AuditLogAiAfterGenerateTextHandlerImpl","context","event","requestId","result","duration","createAuditLog","getAuditConfig","AUDIT","Math","sum","step","error","WebinyError","AuditLogAiAfterGenerateTextHandler","AiAfterGenerateTextEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IACF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA4C,EAAiB;QACtE,IAAI;YACA,MAAM,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,EAAE,GAAGH,MAAM,OAAO;YACrD,MAAMI,iBAAiBC,eAAeC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ;YAE5D,MAAMF,eACF,oBACA;gBACI,OAAO;oBACH,QAAQ;oBACR,UAAUG,KAAK,KAAK,CAACJ;oBACrB,MAAMD,OAAO,IAAI;oBACjB,OAAOA,OAAO,KAAK;oBACnB,cAAcA,OAAO,YAAY;oBACjC,OAAOA,OAAO,KAAK,CAAC,MAAM;oBAC1B,WAAWA,OAAO,KAAK,CAAC,MAAM,CAC1B,CAACM,KAAKC,OAASD,MAAMC,KAAK,SAAS,CAAC,MAAM,EAC1C;gBAER;YACJ,GACAR,WACA,IAAI,CAAC,OAAO;QAEpB,EAAE,OAAOS,OAAO;YACZ,MAAMC,cAAAA,IAAgB,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,qCACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBf;IAChB,cAAc;QAACgB;KAAiB;AACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AiBeforeGenerateTextEventHandler } from "@webiny/api-core/features/ai/index.js";
|
|
2
|
+
import { AuditLogsContext } from "../../../abstractions.js";
|
|
3
|
+
declare class AuditLogAiBeforeGenerateTextHandlerImpl implements AiBeforeGenerateTextEventHandler.Interface {
|
|
4
|
+
private context;
|
|
5
|
+
constructor(context: AuditLogsContext.Interface);
|
|
6
|
+
handle(event: AiBeforeGenerateTextEventHandler.Event): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare const AuditLogAiBeforeGenerateTextHandler: typeof AuditLogAiBeforeGenerateTextHandlerImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-core/features/ai/events").AiBeforeGenerateTextEvent>>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _webiny_error from "@webiny/error";
|
|
2
|
+
import { AiBeforeGenerateTextEventHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { AuditLogsContext } from "../../../abstractions.js";
|
|
4
|
+
import { AUDIT } from "../../../config.js";
|
|
5
|
+
import { getAuditConfig } from "../../../utils/getAuditConfig.js";
|
|
6
|
+
class AuditLogAiBeforeGenerateTextHandlerImpl {
|
|
7
|
+
constructor(context){
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
async handle(event) {
|
|
11
|
+
try {
|
|
12
|
+
const { requestId, params } = event.payload;
|
|
13
|
+
const createAuditLog = getAuditConfig(AUDIT.AI.TEXT.GENERATE);
|
|
14
|
+
await createAuditLog("AI Generate Text", {
|
|
15
|
+
before: {
|
|
16
|
+
model: params.model,
|
|
17
|
+
system: params.system,
|
|
18
|
+
prompt: params.prompt,
|
|
19
|
+
tools: params.tools ? Object.keys(params.tools) : []
|
|
20
|
+
}
|
|
21
|
+
}, requestId, this.context);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw _webiny_error.from(error, {
|
|
24
|
+
message: "Error while executing AuditLogAiBeforeGenerateTextHandler",
|
|
25
|
+
code: "AUDIT_LOGS_AI_BEFORE_GENERATE_TEXT"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const AuditLogAiBeforeGenerateTextHandler = AiBeforeGenerateTextEventHandler.createImplementation({
|
|
31
|
+
implementation: AuditLogAiBeforeGenerateTextHandlerImpl,
|
|
32
|
+
dependencies: [
|
|
33
|
+
AuditLogsContext
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
export { AuditLogAiBeforeGenerateTextHandler };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=AuditLogAiBeforeGenerateTextHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions/ai/handlers/AuditLogAiBeforeGenerateTextHandler.js","sources":["../../../../src/subscriptions/ai/handlers/AuditLogAiBeforeGenerateTextHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AiBeforeGenerateTextEventHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\n\nclass AuditLogAiBeforeGenerateTextHandlerImpl\n implements AiBeforeGenerateTextEventHandler.Interface\n{\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: AiBeforeGenerateTextEventHandler.Event): Promise<void> {\n try {\n const { requestId, params } = event.payload;\n const createAuditLog = getAuditConfig(AUDIT.AI.TEXT.GENERATE);\n\n await createAuditLog(\n \"AI Generate Text\",\n {\n before: {\n model: params.model,\n system: params.system,\n prompt: params.prompt,\n tools: params.tools ? Object.keys(params.tools) : []\n }\n },\n requestId,\n this.context\n );\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing AuditLogAiBeforeGenerateTextHandler\",\n code: \"AUDIT_LOGS_AI_BEFORE_GENERATE_TEXT\"\n });\n }\n }\n}\n\nexport const AuditLogAiBeforeGenerateTextHandler =\n AiBeforeGenerateTextEventHandler.createImplementation({\n implementation: AuditLogAiBeforeGenerateTextHandlerImpl,\n dependencies: [AuditLogsContext]\n });\n"],"names":["AuditLogAiBeforeGenerateTextHandlerImpl","context","event","requestId","params","createAuditLog","getAuditConfig","AUDIT","Object","error","WebinyError","AuditLogAiBeforeGenerateTextHandler","AiBeforeGenerateTextEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IAGF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA6C,EAAiB;QACvE,IAAI;YACA,MAAM,EAAEC,SAAS,EAAEC,MAAM,EAAE,GAAGF,MAAM,OAAO;YAC3C,MAAMG,iBAAiBC,eAAeC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ;YAE5D,MAAMF,eACF,oBACA;gBACI,QAAQ;oBACJ,OAAOD,OAAO,KAAK;oBACnB,QAAQA,OAAO,MAAM;oBACrB,QAAQA,OAAO,MAAM;oBACrB,OAAOA,OAAO,KAAK,GAAGI,OAAO,IAAI,CAACJ,OAAO,KAAK,IAAI,EAAE;gBACxD;YACJ,GACAD,WACA,IAAI,CAAC,OAAO;QAEpB,EAAE,OAAOM,OAAO;YACZ,MAAMC,cAAAA,IAAgB,CAACD,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,sCACTC,iCAAiC,oBAAoB,CAAC;IAClD,gBAAgBZ;IAChB,cAAc;QAACa;KAAiB;AACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AiGenerateTextErrorEventHandler } from "@webiny/api-core/features/ai/index.js";
|
|
2
|
+
import { AuditLogsContext } from "../../../abstractions.js";
|
|
3
|
+
declare class AuditLogAiGenerateTextErrorHandlerImpl implements AiGenerateTextErrorEventHandler.Interface {
|
|
4
|
+
private context;
|
|
5
|
+
constructor(context: AuditLogsContext.Interface);
|
|
6
|
+
handle(event: AiGenerateTextErrorEventHandler.Event): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare const AuditLogAiGenerateTextErrorHandler: typeof AuditLogAiGenerateTextErrorHandlerImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-core/features/ai/events").AiGenerateTextErrorEvent>>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _webiny_error from "@webiny/error";
|
|
2
|
+
import { AiGenerateTextErrorEventHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { AuditLogsContext } from "../../../abstractions.js";
|
|
4
|
+
import { AUDIT } from "../../../config.js";
|
|
5
|
+
import { getAuditConfig } from "../../../utils/getAuditConfig.js";
|
|
6
|
+
class AuditLogAiGenerateTextErrorHandlerImpl {
|
|
7
|
+
constructor(context){
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
async handle(event) {
|
|
11
|
+
try {
|
|
12
|
+
const { requestId, error, duration } = event.payload;
|
|
13
|
+
const createAuditLog = getAuditConfig(AUDIT.AI.TEXT.GENERATE);
|
|
14
|
+
await createAuditLog("AI Generate Text", {
|
|
15
|
+
after: {
|
|
16
|
+
status: "error",
|
|
17
|
+
duration: Math.round(duration),
|
|
18
|
+
error: {
|
|
19
|
+
message: error.message,
|
|
20
|
+
name: error.name
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, requestId, this.context);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
throw _webiny_error.from(err, {
|
|
26
|
+
message: "Error while executing AuditLogAiGenerateTextErrorHandler",
|
|
27
|
+
code: "AUDIT_LOGS_AI_GENERATE_TEXT_ERROR"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const AuditLogAiGenerateTextErrorHandler = AiGenerateTextErrorEventHandler.createImplementation({
|
|
33
|
+
implementation: AuditLogAiGenerateTextErrorHandlerImpl,
|
|
34
|
+
dependencies: [
|
|
35
|
+
AuditLogsContext
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { AuditLogAiGenerateTextErrorHandler };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=AuditLogAiGenerateTextErrorHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions/ai/handlers/AuditLogAiGenerateTextErrorHandler.js","sources":["../../../../src/subscriptions/ai/handlers/AuditLogAiGenerateTextErrorHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AiGenerateTextErrorEventHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { AUDIT } from \"~/config.js\";\nimport { getAuditConfig } from \"~/utils/getAuditConfig.js\";\n\nclass AuditLogAiGenerateTextErrorHandlerImpl implements AiGenerateTextErrorEventHandler.Interface {\n constructor(private context: AuditLogsContext.Interface) {}\n\n async handle(event: AiGenerateTextErrorEventHandler.Event): Promise<void> {\n try {\n const { requestId, error, duration } = event.payload;\n const createAuditLog = getAuditConfig(AUDIT.AI.TEXT.GENERATE);\n\n await createAuditLog(\n \"AI Generate Text\",\n {\n after: {\n status: \"error\",\n duration: Math.round(duration),\n error: {\n message: error.message,\n name: error.name\n }\n }\n },\n requestId,\n this.context\n );\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Error while executing AuditLogAiGenerateTextErrorHandler\",\n code: \"AUDIT_LOGS_AI_GENERATE_TEXT_ERROR\"\n });\n }\n }\n}\n\nexport const AuditLogAiGenerateTextErrorHandler =\n AiGenerateTextErrorEventHandler.createImplementation({\n implementation: AuditLogAiGenerateTextErrorHandlerImpl,\n dependencies: [AuditLogsContext]\n });\n"],"names":["AuditLogAiGenerateTextErrorHandlerImpl","context","event","requestId","error","duration","createAuditLog","getAuditConfig","AUDIT","Math","err","WebinyError","AuditLogAiGenerateTextErrorHandler","AiGenerateTextErrorEventHandler","AuditLogsContext"],"mappings":";;;;;AAMA,MAAMA;IACF,YAAoBC,OAAmC,CAAE;aAArCA,OAAO,GAAPA;IAAsC;IAE1D,MAAM,OAAOC,KAA4C,EAAiB;QACtE,IAAI;YACA,MAAM,EAAEC,SAAS,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGH,MAAM,OAAO;YACpD,MAAMI,iBAAiBC,eAAeC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ;YAE5D,MAAMF,eACF,oBACA;gBACI,OAAO;oBACH,QAAQ;oBACR,UAAUG,KAAK,KAAK,CAACJ;oBACrB,OAAO;wBACH,SAASD,MAAM,OAAO;wBACtB,MAAMA,MAAM,IAAI;oBACpB;gBACJ;YACJ,GACAD,WACA,IAAI,CAAC,OAAO;QAEpB,EAAE,OAAOO,KAAK;YACV,MAAMC,cAAAA,IAAgB,CAACD,KAAK;gBACxB,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ;AAEO,MAAME,qCACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBb;IAChB,cAAc;QAACc;KAAiB;AACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AuditLogAiBeforeGenerateTextHandler } from "./handlers/AuditLogAiBeforeGenerateTextHandler.js";
|
|
2
|
+
import { AuditLogAiAfterGenerateTextHandler } from "./handlers/AuditLogAiAfterGenerateTextHandler.js";
|
|
3
|
+
import { AuditLogAiGenerateTextErrorHandler } from "./handlers/AuditLogAiGenerateTextErrorHandler.js";
|
|
4
|
+
const createAiHooks = (context)=>{
|
|
5
|
+
context.container.register(AuditLogAiBeforeGenerateTextHandler);
|
|
6
|
+
context.container.register(AuditLogAiAfterGenerateTextHandler);
|
|
7
|
+
context.container.register(AuditLogAiGenerateTextErrorHandler);
|
|
8
|
+
};
|
|
9
|
+
export { createAiHooks };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions/ai/index.js","sources":["../../../src/subscriptions/ai/index.ts"],"sourcesContent":["import { AuditLogAiBeforeGenerateTextHandler } from \"./handlers/AuditLogAiBeforeGenerateTextHandler.js\";\nimport { AuditLogAiAfterGenerateTextHandler } from \"./handlers/AuditLogAiAfterGenerateTextHandler.js\";\nimport { AuditLogAiGenerateTextErrorHandler } from \"./handlers/AuditLogAiGenerateTextErrorHandler.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\n\nexport const createAiHooks = (context: AuditLogsContext) => {\n context.container.register(AuditLogAiBeforeGenerateTextHandler);\n context.container.register(AuditLogAiAfterGenerateTextHandler);\n context.container.register(AuditLogAiGenerateTextErrorHandler);\n};\n"],"names":["createAiHooks","context","AuditLogAiBeforeGenerateTextHandler","AuditLogAiAfterGenerateTextHandler","AuditLogAiGenerateTextErrorHandler"],"mappings":";;;AAKO,MAAMA,gBAAgB,CAACC;IAC1BA,QAAQ,SAAS,CAAC,QAAQ,CAACC;IAC3BD,QAAQ,SAAS,CAAC,QAAQ,CAACE;IAC3BF,QAAQ,SAAS,CAAC,QAAQ,CAACG;AAC/B"}
|
package/subscriptions/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createSecurityHooks } from "./security/index.js";
|
|
|
4
4
|
import { createMailerHooks } from "./mailer/index.js";
|
|
5
5
|
import { createAcoHooks } from "./aco/index.js";
|
|
6
6
|
import { createWebsiteBuilderHooks } from "./websiteBuilder/index.js";
|
|
7
|
+
import { createAiHooks } from "./ai/index.js";
|
|
7
8
|
const createSubscriptionHooks = (context)=>{
|
|
8
9
|
createFileManagerHooks(context);
|
|
9
10
|
createHeadlessCmsHooks(context);
|
|
@@ -11,6 +12,7 @@ const createSubscriptionHooks = (context)=>{
|
|
|
11
12
|
createMailerHooks(context);
|
|
12
13
|
createAcoHooks(context);
|
|
13
14
|
createWebsiteBuilderHooks(context);
|
|
15
|
+
createAiHooks(context);
|
|
14
16
|
};
|
|
15
17
|
export { createSubscriptionHooks };
|
|
16
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptions/index.js","sources":["../../src/subscriptions/index.ts"],"sourcesContent":["import { createFileManagerHooks } from \"./fileManager/index.js\";\nimport { createHeadlessCmsHooks } from \"./headlessCms/index.js\";\nimport { createSecurityHooks } from \"./security/index.js\";\nimport { createMailerHooks } from \"./mailer/index.js\";\nimport { createAcoHooks } from \"./aco/index.js\";\nimport { createWebsiteBuilderHooks } from \"~/subscriptions/websiteBuilder/index.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\n\nexport const createSubscriptionHooks = (context: AuditLogsContext) => {\n createFileManagerHooks(context);\n createHeadlessCmsHooks(context);\n createSecurityHooks(context);\n createMailerHooks(context);\n createAcoHooks(context);\n createWebsiteBuilderHooks(context);\n};\n"],"names":["createSubscriptionHooks","context","createFileManagerHooks","createHeadlessCmsHooks","createSecurityHooks","createMailerHooks","createAcoHooks","createWebsiteBuilderHooks"],"mappings":"
|
|
1
|
+
{"version":3,"file":"subscriptions/index.js","sources":["../../src/subscriptions/index.ts"],"sourcesContent":["import { createFileManagerHooks } from \"./fileManager/index.js\";\nimport { createHeadlessCmsHooks } from \"./headlessCms/index.js\";\nimport { createSecurityHooks } from \"./security/index.js\";\nimport { createMailerHooks } from \"./mailer/index.js\";\nimport { createAcoHooks } from \"./aco/index.js\";\nimport { createWebsiteBuilderHooks } from \"~/subscriptions/websiteBuilder/index.js\";\nimport { createAiHooks } from \"./ai/index.js\";\nimport type { AuditLogsContext } from \"~/types.js\";\n\nexport const createSubscriptionHooks = (context: AuditLogsContext) => {\n createFileManagerHooks(context);\n createHeadlessCmsHooks(context);\n createSecurityHooks(context);\n createMailerHooks(context);\n createAcoHooks(context);\n createWebsiteBuilderHooks(context);\n createAiHooks(context);\n};\n"],"names":["createSubscriptionHooks","context","createFileManagerHooks","createHeadlessCmsHooks","createSecurityHooks","createMailerHooks","createAcoHooks","createWebsiteBuilderHooks","createAiHooks"],"mappings":";;;;;;;AASO,MAAMA,0BAA0B,CAACC;IACpCC,uBAAuBD;IACvBE,uBAAuBF;IACvBG,oBAAoBH;IACpBI,kBAAkBJ;IAClBK,eAAeL;IACfM,0BAA0BN;IAC1BO,cAAcP;AAClB"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { IStorageListParams } from "../storage/abstractions/Storage.js";
|
|
2
|
-
import type { IAccessPatternHandler, IAccessPatternHandlerHandleResult } from "../storage/abstractions/AccessPatternHandler.js";
|
|
3
|
-
import type { IAccessPattern } from "../storage/abstractions/AccessPattern.js";
|
|
4
|
-
export interface IAccessPatternHandlerParams {
|
|
5
|
-
patterns: IAccessPattern<unknown>[];
|
|
6
|
-
}
|
|
7
|
-
export declare class AccessPatternHandler implements IAccessPatternHandler {
|
|
8
|
-
private readonly patterns;
|
|
9
|
-
constructor(params: IAccessPatternHandlerParams);
|
|
10
|
-
handle(params: IStorageListParams): Promise<IAccessPatternHandlerHandleResult>;
|
|
11
|
-
getDefaultPattern(): IAccessPattern<unknown>;
|
|
12
|
-
listIndexPatterns(): IAccessPattern<unknown>[];
|
|
13
|
-
private find;
|
|
14
|
-
}
|