@webiny/api-audit-logs 6.5.2-beta.1 → 6.5.2-beta.3
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/context/AuditLogsContextValue.js +9 -0
- package/context/AuditLogsContextValue.js.map +1 -1
- package/features/GetAuditLog/GetAuditLogUseCase.d.ts +13 -0
- package/features/GetAuditLog/GetAuditLogUseCase.js +32 -0
- package/features/GetAuditLog/GetAuditLogUseCase.js.map +1 -0
- package/features/GetAuditLog/abstractions.d.ts +10 -0
- package/features/GetAuditLog/abstractions.js +5 -0
- package/features/GetAuditLog/abstractions.js.map +1 -0
- package/features/GetAuditLog/feature.d.ts +4 -0
- package/features/GetAuditLog/feature.js +11 -0
- package/features/GetAuditLog/feature.js.map +1 -0
- package/features/GetAuditLog/index.d.ts +2 -0
- package/features/GetAuditLog/index.js +2 -0
- package/features/ListAuditLogs/ListAuditLogsUseCase.d.ts +17 -0
- package/features/ListAuditLogs/ListAuditLogsUseCase.js +37 -0
- package/features/ListAuditLogs/ListAuditLogsUseCase.js.map +1 -0
- package/features/ListAuditLogs/abstractions.d.ts +11 -0
- package/features/ListAuditLogs/abstractions.js +5 -0
- package/features/ListAuditLogs/abstractions.js.map +1 -0
- package/features/ListAuditLogs/feature.d.ts +4 -0
- package/features/ListAuditLogs/feature.js +11 -0
- package/features/ListAuditLogs/feature.js.map +1 -0
- package/features/ListAuditLogs/index.d.ts +2 -0
- package/features/ListAuditLogs/index.js +2 -0
- package/features/shared/canAccessAuditLogs.d.ts +5 -0
- package/features/shared/canAccessAuditLogs.js +7 -0
- package/features/shared/canAccessAuditLogs.js.map +1 -0
- package/graphql/schema.js +12 -7
- package/graphql/schema.js.map +1 -1
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/package.json +22 -22
- package/utils/expiresAt.js +1 -1
- package/utils/expiresAt.js.map +1 -1
|
@@ -86,6 +86,7 @@ class AuditLogsContextValueImpl {
|
|
|
86
86
|
throw result.error;
|
|
87
87
|
}
|
|
88
88
|
async listAuditLogs(params) {
|
|
89
|
+
await this.checkListPermissions();
|
|
89
90
|
const result = await this.storage.list({
|
|
90
91
|
...params,
|
|
91
92
|
tenant: this.getTenantId()
|
|
@@ -99,6 +100,14 @@ class AuditLogsContextValueImpl {
|
|
|
99
100
|
};
|
|
100
101
|
throw result.error;
|
|
101
102
|
}
|
|
103
|
+
async checkListPermissions() {
|
|
104
|
+
const permissions = await this.getContext().security.getPermissions("al.*");
|
|
105
|
+
const hasAccess = permissions.some((permission)=>"*" === permission.name || "al.*" === permission.name);
|
|
106
|
+
if (hasAccess) return;
|
|
107
|
+
throw new NotAuthorizedError({
|
|
108
|
+
message: "You cannot access audit logs."
|
|
109
|
+
});
|
|
110
|
+
}
|
|
102
111
|
async checkPermissions(auditLog) {
|
|
103
112
|
if (!auditLog.action) throw new Error("Audit log action is not defined. Cannot check permissions.");
|
|
104
113
|
const permissions = await this.getContext().security.getPermissions("al.*");
|
|
@@ -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":";;;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AM,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;iBACG,IAAIA,WAAW,IAAI,KAAK,CAAC,GAAG,EAAEnB,SAAS,MAAM,EAAE,EAClD;QAER;QAEA,MAAM,IAAIoB,mBAAmB;YACzB,SAAS;QACb;IACJ;IAEQ,cAAsB;QAC1B,OAAO,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,gBAAgB,GAAG,EAAE;IAC1D;IAEQ,cAAkC;QACtC,MAAMC,WAAW,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,WAAW;QACvD,OAAO;YACH,IAAIA,SAAS,EAAE;YACf,MAAMA,SAAS,IAAI;YACnB,aAAaA,SAAS,WAAW,IAAI;QACzC;IACJ;AACJ;AAEO,MAAMC,8BAA8B,CACvC3B,SAEO,IAAID,0BAA0BC"}
|
|
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 await this.checkListPermissions();\n\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 /**\n * Listing returns logs of every action, so it needs full audit logs access.\n */\n private async checkListPermissions(): Promise<void> {\n const permissions = await this.getContext().security.getPermissions(\"al.*\");\n const hasAccess = permissions.some(permission => {\n return permission.name === \"*\" || permission.name === \"al.*\";\n });\n if (hasAccess) {\n return;\n }\n throw new NotAuthorizedError({\n message: \"You cannot access audit logs.\"\n });\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","permissions","hasAccess","permission","NotAuthorizedError","Error","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;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AaA,SAAS,WAAW,IAAI;QACzC;IACJ;AACJ;AAEO,MAAMC,8BAA8B,CACvC5B,SAEO,IAAID,0BAA0BC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
import { AuditLogsContext } from "../../abstractions.js";
|
|
3
|
+
import { GetAuditLogUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
4
|
+
declare class GetAuditLogUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
5
|
+
private identityContext;
|
|
6
|
+
private context;
|
|
7
|
+
constructor(identityContext: IdentityContext.Interface, context: AuditLogsContext.Interface);
|
|
8
|
+
execute(id: string): UseCaseAbstraction.Return;
|
|
9
|
+
}
|
|
10
|
+
export declare const GetAuditLogUseCaseImplementation: typeof GetAuditLogUseCaseImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetAuditLogUseCase>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
|
+
import { NotAuthorizedError } from "@webiny/api-core/features/security/shared/errors.js";
|
|
4
|
+
import { AuditLogsContext } from "../../abstractions.js";
|
|
5
|
+
import { canAccessAuditLogs } from "../shared/canAccessAuditLogs.js";
|
|
6
|
+
import { GetAuditLogUseCase } from "./abstractions.js";
|
|
7
|
+
class GetAuditLogUseCaseImpl {
|
|
8
|
+
constructor(identityContext, context){
|
|
9
|
+
this.identityContext = identityContext;
|
|
10
|
+
this.context = context;
|
|
11
|
+
}
|
|
12
|
+
async execute(id) {
|
|
13
|
+
if (!await canAccessAuditLogs(this.identityContext)) return Result.fail(new NotAuthorizedError({
|
|
14
|
+
message: "You cannot access audit logs."
|
|
15
|
+
}));
|
|
16
|
+
try {
|
|
17
|
+
return Result.ok(await this.context.auditLogs.getAuditLog(id));
|
|
18
|
+
} catch (ex) {
|
|
19
|
+
return Result.fail(ex);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const GetAuditLogUseCaseImplementation = GetAuditLogUseCase.createImplementation({
|
|
24
|
+
implementation: GetAuditLogUseCaseImpl,
|
|
25
|
+
dependencies: [
|
|
26
|
+
IdentityContext,
|
|
27
|
+
AuditLogsContext
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
export { GetAuditLogUseCaseImplementation };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=GetAuditLogUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetAuditLog/GetAuditLogUseCase.js","sources":["../../../src/features/GetAuditLog/GetAuditLogUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/errors.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { canAccessAuditLogs } from \"~/features/shared/canAccessAuditLogs.js\";\nimport { GetAuditLogUseCase as UseCaseAbstraction } from \"./abstractions.js\";\n\nclass GetAuditLogUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private context: AuditLogsContext.Interface\n ) {}\n\n async execute(id: string): UseCaseAbstraction.Return {\n /* The check runs before the record is loaded, so the response does not reveal whether the ID exists. */\n if (!(await canAccessAuditLogs(this.identityContext))) {\n return Result.fail(\n new NotAuthorizedError({ message: \"You cannot access audit logs.\" })\n );\n }\n\n try {\n return Result.ok(await this.context.auditLogs.getAuditLog(id));\n } catch (ex) {\n return Result.fail(ex);\n }\n }\n}\n\nexport const GetAuditLogUseCaseImplementation = UseCaseAbstraction.createImplementation({\n implementation: GetAuditLogUseCaseImpl,\n dependencies: [IdentityContext, AuditLogsContext]\n});\n"],"names":["GetAuditLogUseCaseImpl","identityContext","context","id","canAccessAuditLogs","Result","NotAuthorizedError","ex","GetAuditLogUseCaseImplementation","UseCaseAbstraction","IdentityContext","AuditLogsContext"],"mappings":";;;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,OAAmC,CAC7C;aAFUD,eAAe,GAAfA;aACAC,OAAO,GAAPA;IACT;IAEH,MAAM,QAAQC,EAAU,EAA6B;QAEjD,IAAI,CAAE,MAAMC,mBAAmB,IAAI,CAAC,eAAe,GAC/C,OAAOC,OAAO,IAAI,CACd,IAAIC,mBAAmB;YAAE,SAAS;QAAgC;QAI1E,IAAI;YACA,OAAOD,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAACF;QAC9D,EAAE,OAAOI,IAAI;YACT,OAAOF,OAAO,IAAI,CAACE;QACvB;IACJ;AACJ;AAEO,MAAMC,mCAAmCC,mBAAAA,oBAAuC,CAAC;IACpF,gBAAgBT;IAChB,cAAc;QAACU;QAAiBC;KAAiB;AACrD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { IAuditLog } from "../../storage/types.js";
|
|
3
|
+
export interface IGetAuditLogUseCase {
|
|
4
|
+
execute(id: string): Promise<Result<IAuditLog | null, Error>>;
|
|
5
|
+
}
|
|
6
|
+
export declare const GetAuditLogUseCase: import("@webiny/di").Abstraction<IGetAuditLogUseCase>;
|
|
7
|
+
export declare namespace GetAuditLogUseCase {
|
|
8
|
+
type Interface = IGetAuditLogUseCase;
|
|
9
|
+
type Return = Promise<Result<IAuditLog | null, Error>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetAuditLog/abstractions.js","sources":["../../../src/features/GetAuditLog/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { IAuditLog } from \"~/storage/types.js\";\n\nexport interface IGetAuditLogUseCase {\n execute(id: string): Promise<Result<IAuditLog | null, Error>>;\n}\n\nexport const GetAuditLogUseCase = createAbstraction<IGetAuditLogUseCase>(\"GetAuditLogUseCase\");\n\nexport namespace GetAuditLogUseCase {\n export type Interface = IGetAuditLogUseCase;\n export type Return = Promise<Result<IAuditLog | null, Error>>;\n}\n"],"names":["GetAuditLogUseCase","createAbstraction"],"mappings":";AAQO,MAAMA,qBAAqBC,kBAAuC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetAuditLogUseCaseImplementation } from "./GetAuditLogUseCase.js";
|
|
3
|
+
const GetAuditLogFeature = createFeature({
|
|
4
|
+
name: "GetAuditLog",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GetAuditLogUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { GetAuditLogFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetAuditLog/feature.js","sources":["../../../src/features/GetAuditLog/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetAuditLogUseCaseImplementation } from \"./GetAuditLogUseCase.js\";\n\nexport const GetAuditLogFeature = createFeature({\n name: \"GetAuditLog\",\n register(container) {\n container.register(GetAuditLogUseCaseImplementation);\n }\n});\n"],"names":["GetAuditLogFeature","createFeature","container","GetAuditLogUseCaseImplementation"],"mappings":";;AAGO,MAAMA,qBAAqBC,cAAc;IAC5C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
import { AuditLogsContext } from "../../abstractions.js";
|
|
3
|
+
import { ListAuditLogsUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Lists the audit logs for the API. Internal code that needs the logs regardless of who triggered
|
|
6
|
+
* it (e.g. merging of the recent logs) reads them through `context.auditLogs`.
|
|
7
|
+
*/
|
|
8
|
+
declare class ListAuditLogsUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
9
|
+
private identityContext;
|
|
10
|
+
private context;
|
|
11
|
+
constructor(identityContext: IdentityContext.Interface, context: AuditLogsContext.Interface);
|
|
12
|
+
execute(params: UseCaseAbstraction.Params): UseCaseAbstraction.Return;
|
|
13
|
+
}
|
|
14
|
+
export declare const ListAuditLogsUseCaseImplementation: typeof ListAuditLogsUseCaseImpl & {
|
|
15
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IListAuditLogsUseCase>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
|
+
import { NotAuthorizedError } from "@webiny/api-core/features/security/shared/errors.js";
|
|
4
|
+
import { AuditLogsContext } from "../../abstractions.js";
|
|
5
|
+
import { canAccessAuditLogs } from "../shared/canAccessAuditLogs.js";
|
|
6
|
+
import { ListAuditLogsUseCase } from "./abstractions.js";
|
|
7
|
+
class ListAuditLogsUseCaseImpl {
|
|
8
|
+
constructor(identityContext, context){
|
|
9
|
+
this.identityContext = identityContext;
|
|
10
|
+
this.context = context;
|
|
11
|
+
}
|
|
12
|
+
async execute(params) {
|
|
13
|
+
if (!await canAccessAuditLogs(this.identityContext)) return Result.fail(new NotAuthorizedError({
|
|
14
|
+
message: "You cannot access audit logs."
|
|
15
|
+
}));
|
|
16
|
+
try {
|
|
17
|
+
const result = await this.context.auditLogs.listAuditLogs(params);
|
|
18
|
+
if (result.error) return Result.fail(result.error);
|
|
19
|
+
return Result.ok({
|
|
20
|
+
items: result.items,
|
|
21
|
+
meta: result.meta
|
|
22
|
+
});
|
|
23
|
+
} catch (ex) {
|
|
24
|
+
return Result.fail(ex);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const ListAuditLogsUseCaseImplementation = ListAuditLogsUseCase.createImplementation({
|
|
29
|
+
implementation: ListAuditLogsUseCaseImpl,
|
|
30
|
+
dependencies: [
|
|
31
|
+
IdentityContext,
|
|
32
|
+
AuditLogsContext
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
export { ListAuditLogsUseCaseImplementation };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=ListAuditLogsUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ListAuditLogs/ListAuditLogsUseCase.js","sources":["../../../src/features/ListAuditLogs/ListAuditLogsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/errors.js\";\nimport { AuditLogsContext } from \"~/abstractions.js\";\nimport { canAccessAuditLogs } from \"~/features/shared/canAccessAuditLogs.js\";\nimport { ListAuditLogsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\n\n/**\n * Lists the audit logs for the API. Internal code that needs the logs regardless of who triggered\n * it (e.g. merging of the recent logs) reads them through `context.auditLogs`.\n */\nclass ListAuditLogsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private context: AuditLogsContext.Interface\n ) {}\n\n async execute(params: UseCaseAbstraction.Params): UseCaseAbstraction.Return {\n if (!(await canAccessAuditLogs(this.identityContext))) {\n return Result.fail(\n new NotAuthorizedError({ message: \"You cannot access audit logs.\" })\n );\n }\n\n try {\n const result = await this.context.auditLogs.listAuditLogs(params);\n if (result.error) {\n return Result.fail(result.error);\n }\n\n return Result.ok({\n items: result.items,\n meta: result.meta\n });\n } catch (ex) {\n return Result.fail(ex);\n }\n }\n}\n\nexport const ListAuditLogsUseCaseImplementation = UseCaseAbstraction.createImplementation({\n implementation: ListAuditLogsUseCaseImpl,\n dependencies: [IdentityContext, AuditLogsContext]\n});\n"],"names":["ListAuditLogsUseCaseImpl","identityContext","context","params","canAccessAuditLogs","Result","NotAuthorizedError","result","ex","ListAuditLogsUseCaseImplementation","UseCaseAbstraction","IdentityContext","AuditLogsContext"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,OAAmC,CAC7C;aAFUD,eAAe,GAAfA;aACAC,OAAO,GAAPA;IACT;IAEH,MAAM,QAAQC,MAAiC,EAA6B;QACxE,IAAI,CAAE,MAAMC,mBAAmB,IAAI,CAAC,eAAe,GAC/C,OAAOC,OAAO,IAAI,CACd,IAAIC,mBAAmB;YAAE,SAAS;QAAgC;QAI1E,IAAI;YACA,MAAMC,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAACJ;YAC1D,IAAII,OAAO,KAAK,EACZ,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;YAGnC,OAAOF,OAAO,EAAE,CAAC;gBACb,OAAOE,OAAO,KAAK;gBACnB,MAAMA,OAAO,IAAI;YACrB;QACJ,EAAE,OAAOC,IAAI;YACT,OAAOH,OAAO,IAAI,CAACG;QACvB;IACJ;AACJ;AAEO,MAAMC,qCAAqCC,qBAAAA,oBAAuC,CAAC;IACtF,gBAAgBV;IAChB,cAAc;QAACW;QAAiBC;KAAiB;AACrD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { IListAuditLogsParams, IListAuditLogsSuccessResult } from "../../types.js";
|
|
3
|
+
export interface IListAuditLogsUseCase {
|
|
4
|
+
execute(params: IListAuditLogsParams): Promise<Result<IListAuditLogsSuccessResult, Error>>;
|
|
5
|
+
}
|
|
6
|
+
export declare const ListAuditLogsUseCase: import("@webiny/di").Abstraction<IListAuditLogsUseCase>;
|
|
7
|
+
export declare namespace ListAuditLogsUseCase {
|
|
8
|
+
type Interface = IListAuditLogsUseCase;
|
|
9
|
+
type Params = IListAuditLogsParams;
|
|
10
|
+
type Return = Promise<Result<IListAuditLogsSuccessResult, Error>>;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ListAuditLogs/abstractions.js","sources":["../../../src/features/ListAuditLogs/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { IListAuditLogsParams, IListAuditLogsSuccessResult } from \"~/types.js\";\n\nexport interface IListAuditLogsUseCase {\n execute(params: IListAuditLogsParams): Promise<Result<IListAuditLogsSuccessResult, Error>>;\n}\n\nexport const ListAuditLogsUseCase =\n createAbstraction<IListAuditLogsUseCase>(\"ListAuditLogsUseCase\");\n\nexport namespace ListAuditLogsUseCase {\n export type Interface = IListAuditLogsUseCase;\n export type Params = IListAuditLogsParams;\n export type Return = Promise<Result<IListAuditLogsSuccessResult, Error>>;\n}\n"],"names":["ListAuditLogsUseCase","createAbstraction"],"mappings":";AAQO,MAAMA,uBACTC,kBAAyC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ListAuditLogsUseCaseImplementation } from "./ListAuditLogsUseCase.js";
|
|
3
|
+
const ListAuditLogsFeature = createFeature({
|
|
4
|
+
name: "ListAuditLogs",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(ListAuditLogsUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { ListAuditLogsFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ListAuditLogs/feature.js","sources":["../../../src/features/ListAuditLogs/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListAuditLogsUseCaseImplementation } from \"./ListAuditLogsUseCase.js\";\n\nexport const ListAuditLogsFeature = createFeature({\n name: \"ListAuditLogs\",\n register(container) {\n container.register(ListAuditLogsUseCaseImplementation);\n }\n});\n"],"names":["ListAuditLogsFeature","createFeature","container","ListAuditLogsUseCaseImplementation"],"mappings":";;AAGO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Reading audit logs requires full access or the `al.*` permission.
|
|
4
|
+
*/
|
|
5
|
+
export declare const canAccessAuditLogs: (identityContext: IdentityContext.Interface) => Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/shared/canAccessAuditLogs.js","sources":["../../../src/features/shared/canAccessAuditLogs.ts"],"sourcesContent":["import type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\n/**\n * Reading audit logs requires full access or the `al.*` permission.\n */\nexport const canAccessAuditLogs = async (\n identityContext: IdentityContext.Interface\n): Promise<boolean> => {\n const permissions = await identityContext.getPermissions(\"al.*\");\n\n return permissions.length > 0;\n};\n"],"names":["canAccessAuditLogs","identityContext","permissions"],"mappings":"AAKO,MAAMA,qBAAqB,OAC9BC;IAEA,MAAMC,cAAc,MAAMD,gBAAgB,cAAc,CAAC;IAEzD,OAAOC,YAAY,MAAM,GAAG;AAChC"}
|
package/graphql/schema.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { GraphQLSchemaPlugin, NotFoundError, resolve, resolveList } from "@webiny/handler-graphql";
|
|
2
2
|
import { getValidationSchema, listValidationSchema } from "./validation.js";
|
|
3
3
|
import { createZodError } from "@webiny/utils";
|
|
4
|
+
import { GetAuditLogUseCase } from "../features/GetAuditLog/index.js";
|
|
5
|
+
import { ListAuditLogsUseCase } from "../features/ListAuditLogs/index.js";
|
|
4
6
|
const createGraphQLSchema = ()=>new GraphQLSchemaPlugin({
|
|
5
7
|
isApplicable: (context)=>!!context.auditLogs,
|
|
6
8
|
typeDefs: `
|
|
@@ -84,24 +86,27 @@ const createGraphQLSchema = ()=>new GraphQLSchemaPlugin({
|
|
|
84
86
|
return resolve(async ()=>{
|
|
85
87
|
const validation = await getValidationSchema.safeParseAsync(args);
|
|
86
88
|
if (!validation.success) throw createZodError(validation.error);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
const getAuditLog = context.container.resolve(GetAuditLogUseCase);
|
|
90
|
+
const result = await getAuditLog.execute(validation.data.id);
|
|
91
|
+
if (result.isFail()) throw result.error;
|
|
92
|
+
if (!result.value) throw new NotFoundError(`Audit log with id "${validation.data.id}" not found.`);
|
|
93
|
+
return result.value;
|
|
90
94
|
});
|
|
91
95
|
},
|
|
92
96
|
async listAuditLogs (_, args, context) {
|
|
93
97
|
return resolveList(async ()=>{
|
|
94
98
|
const validation = await listValidationSchema.safeParseAsync(args);
|
|
95
99
|
if (!validation.success) throw createZodError(validation.error);
|
|
96
|
-
const
|
|
100
|
+
const listAuditLogs = context.container.resolve(ListAuditLogsUseCase);
|
|
101
|
+
const result = await listAuditLogs.execute({
|
|
97
102
|
...validation.data,
|
|
98
103
|
...validation.data.where
|
|
99
104
|
});
|
|
100
|
-
if (result.
|
|
105
|
+
if (result.isFail()) throw result.error;
|
|
101
106
|
return {
|
|
102
|
-
items: result.items,
|
|
107
|
+
items: result.value.items,
|
|
103
108
|
meta: {
|
|
104
|
-
...result.meta,
|
|
109
|
+
...result.value.meta,
|
|
105
110
|
totalCount: 0
|
|
106
111
|
}
|
|
107
112
|
};
|
package/graphql/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/schema.js","sources":["../../src/graphql/schema.ts"],"sourcesContent":["import { GraphQLSchemaPlugin, NotFoundError, resolve, resolveList } from \"@webiny/handler-graphql\";\nimport type { AuditLogsContext } from \"~/types.js\";\nimport { getValidationSchema, listValidationSchema } from \"./validation.js\";\nimport { createZodError } from \"@webiny/utils\";\n\ninterface IListAuditLogsWhere {\n app?: string;\n action?: string;\n createdBy?: string;\n entity?: string;\n entityId?: string;\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n}\n\ninterface IListAuditLogsArgs {\n where?: IListAuditLogsWhere;\n sort?: \"ASC\" | \"DESC\";\n limit?: number;\n after?: string;\n}\n\nexport const createGraphQLSchema = () => {\n return new GraphQLSchemaPlugin<AuditLogsContext>({\n isApplicable: context => {\n return !!context.auditLogs;\n },\n typeDefs: `\n type AuditLogCreatedBy {\n id: ID!\n displayName: String\n type: String\n }\n type AuditLog {\n id: ID!\n createdBy: AuditLogCreatedBy!\n createdOn: DateTime!\n app: String!\n action: String!\n message: String!\n entity: String!\n entityId: String!\n tags: [String!]!\n expiresAt: DateTime!\n content: String\n }\n \n type AuditLogListMeta {\n cursor: String\n hasMoreItems: Boolean!\n }\n \n type AuditLogError {\n code: String\n message: String!\n data: JSON\n stack: String\n }\n \n type AuditLogListResponse {\n data: [AuditLog!]\n meta: AuditLogListMeta\n error: AuditLogError\n }\n \n type AuditLogGetResponse {\n data: AuditLog\n error: AuditLogError\n }\n \n enum AuditLogsSort {\n ASC\n DESC\n }\n \n input ListAuditLogsWhere {\n app: String\n action: String\n createdBy: String\n entity: String\n entityId: String\n createdOn_gte: DateTime\n createdOn_lte: DateTime\n }\n \n type AuditLogsQuery {\n getAuditLog(id: ID!): AuditLogGetResponse\n listAuditLogs(\n where: ListAuditLogsWhere\n sort: AuditLogsSort\n limit: Number\n after: String\n ): AuditLogListResponse!\n }\n \n extend type Query {\n auditLogs: AuditLogsQuery\n }\n `,\n resolvers: {\n Query: {\n auditLogs: () => ({})\n },\n AuditLogsQuery: {\n async getAuditLog(_, args, context) {\n return resolve(async () => {\n const validation = await getValidationSchema.safeParseAsync(args);\n\n if (!validation.success) {\n throw createZodError(validation.error);\n }\n\n const result = await
|
|
1
|
+
{"version":3,"file":"graphql/schema.js","sources":["../../src/graphql/schema.ts"],"sourcesContent":["import { GraphQLSchemaPlugin, NotFoundError, resolve, resolveList } from \"@webiny/handler-graphql\";\nimport type { AuditLogsContext } from \"~/types.js\";\nimport { getValidationSchema, listValidationSchema } from \"./validation.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { GetAuditLogUseCase } from \"~/features/GetAuditLog/index.js\";\nimport { ListAuditLogsUseCase } from \"~/features/ListAuditLogs/index.js\";\n\ninterface IListAuditLogsWhere {\n app?: string;\n action?: string;\n createdBy?: string;\n entity?: string;\n entityId?: string;\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n}\n\ninterface IListAuditLogsArgs {\n where?: IListAuditLogsWhere;\n sort?: \"ASC\" | \"DESC\";\n limit?: number;\n after?: string;\n}\n\nexport const createGraphQLSchema = () => {\n return new GraphQLSchemaPlugin<AuditLogsContext>({\n isApplicable: context => {\n return !!context.auditLogs;\n },\n typeDefs: `\n type AuditLogCreatedBy {\n id: ID!\n displayName: String\n type: String\n }\n type AuditLog {\n id: ID!\n createdBy: AuditLogCreatedBy!\n createdOn: DateTime!\n app: String!\n action: String!\n message: String!\n entity: String!\n entityId: String!\n tags: [String!]!\n expiresAt: DateTime!\n content: String\n }\n \n type AuditLogListMeta {\n cursor: String\n hasMoreItems: Boolean!\n }\n \n type AuditLogError {\n code: String\n message: String!\n data: JSON\n stack: String\n }\n \n type AuditLogListResponse {\n data: [AuditLog!]\n meta: AuditLogListMeta\n error: AuditLogError\n }\n \n type AuditLogGetResponse {\n data: AuditLog\n error: AuditLogError\n }\n \n enum AuditLogsSort {\n ASC\n DESC\n }\n \n input ListAuditLogsWhere {\n app: String\n action: String\n createdBy: String\n entity: String\n entityId: String\n createdOn_gte: DateTime\n createdOn_lte: DateTime\n }\n \n type AuditLogsQuery {\n getAuditLog(id: ID!): AuditLogGetResponse\n listAuditLogs(\n where: ListAuditLogsWhere\n sort: AuditLogsSort\n limit: Number\n after: String\n ): AuditLogListResponse!\n }\n \n extend type Query {\n auditLogs: AuditLogsQuery\n }\n `,\n resolvers: {\n Query: {\n auditLogs: () => ({})\n },\n AuditLogsQuery: {\n async getAuditLog(_, args, context) {\n return resolve(async () => {\n const validation = await getValidationSchema.safeParseAsync(args);\n\n if (!validation.success) {\n throw createZodError(validation.error);\n }\n\n const getAuditLog = context.container.resolve(GetAuditLogUseCase);\n const result = await getAuditLog.execute(validation.data.id);\n if (result.isFail()) {\n throw result.error;\n }\n if (!result.value) {\n throw new NotFoundError(\n `Audit log with id \"${validation.data.id}\" not found.`\n );\n }\n return result.value;\n });\n },\n async listAuditLogs(_, args: IListAuditLogsArgs, context) {\n return resolveList(async () => {\n const validation = await listValidationSchema.safeParseAsync(args);\n if (!validation.success) {\n throw createZodError(validation.error);\n }\n const listAuditLogs = context.container.resolve(ListAuditLogsUseCase);\n const result = await listAuditLogs.execute({\n ...validation.data,\n ...validation.data.where\n });\n if (result.isFail()) {\n throw result.error;\n }\n return {\n items: result.value.items,\n meta: {\n ...result.value.meta,\n totalCount: 0\n }\n };\n });\n }\n }\n }\n });\n};\n"],"names":["createGraphQLSchema","GraphQLSchemaPlugin","context","_","args","resolve","validation","getValidationSchema","createZodError","getAuditLog","GetAuditLogUseCase","result","NotFoundError","resolveList","listValidationSchema","listAuditLogs","ListAuditLogsUseCase"],"mappings":";;;;;AAwBO,MAAMA,sBAAsB,IACxB,IAAIC,oBAAsC;QAC7C,cAAcC,CAAAA,UACH,CAAC,CAACA,QAAQ,SAAS;QAE9B,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAuEX,CAAC;QACD,WAAW;YACP,OAAO;gBACH,WAAW,IAAO,EAAC;YACvB;YACA,gBAAgB;gBACZ,MAAM,aAAYC,CAAC,EAAEC,IAAI,EAAEF,OAAO;oBAC9B,OAAOG,QAAQ;wBACX,MAAMC,aAAa,MAAMC,oBAAoB,cAAc,CAACH;wBAE5D,IAAI,CAACE,WAAW,OAAO,EACnB,MAAME,eAAeF,WAAW,KAAK;wBAGzC,MAAMG,cAAcP,QAAQ,SAAS,CAAC,OAAO,CAACQ;wBAC9C,MAAMC,SAAS,MAAMF,YAAY,OAAO,CAACH,WAAW,IAAI,CAAC,EAAE;wBAC3D,IAAIK,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;wBAEtB,IAAI,CAACA,OAAO,KAAK,EACb,MAAM,IAAIC,cACN,CAAC,mBAAmB,EAAEN,WAAW,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC;wBAG9D,OAAOK,OAAO,KAAK;oBACvB;gBACJ;gBACA,MAAM,eAAcR,CAAC,EAAEC,IAAwB,EAAEF,OAAO;oBACpD,OAAOW,YAAY;wBACf,MAAMP,aAAa,MAAMQ,qBAAqB,cAAc,CAACV;wBAC7D,IAAI,CAACE,WAAW,OAAO,EACnB,MAAME,eAAeF,WAAW,KAAK;wBAEzC,MAAMS,gBAAgBb,QAAQ,SAAS,CAAC,OAAO,CAACc;wBAChD,MAAML,SAAS,MAAMI,cAAc,OAAO,CAAC;4BACvC,GAAGT,WAAW,IAAI;4BAClB,GAAGA,WAAW,IAAI,CAAC,KAAK;wBAC5B;wBACA,IAAIK,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;wBAEtB,OAAO;4BACH,OAAOA,OAAO,KAAK,CAAC,KAAK;4BACzB,MAAM;gCACF,GAAGA,OAAO,KAAK,CAAC,IAAI;gCACpB,YAAY;4BAChB;wBACJ;oBACJ;gBACJ;YACJ;QACJ;IACJ"}
|
package/index.js
CHANGED
|
@@ -3,11 +3,15 @@ import { createSubscriptionHooks } from "./subscriptions/index.js";
|
|
|
3
3
|
import { createAuditLogsContext } from "./context/index.js";
|
|
4
4
|
import { createGraphQLSchema } from "./graphql/schema.js";
|
|
5
5
|
import { AuditLogsContext } from "./abstractions.js";
|
|
6
|
+
import { GetAuditLogFeature } from "./features/GetAuditLog/index.js";
|
|
7
|
+
import { ListAuditLogsFeature } from "./features/ListAuditLogs/index.js";
|
|
6
8
|
export * from "./config.js";
|
|
7
9
|
const createAuditLogs = (params)=>{
|
|
8
10
|
const subscriptionsPlugin = new ContextPlugin((context)=>{
|
|
9
11
|
if (!context.wcp.canUseFeature("auditLogs")) return;
|
|
10
12
|
context.container.registerInstance(AuditLogsContext, context);
|
|
13
|
+
GetAuditLogFeature.register(context.container);
|
|
14
|
+
ListAuditLogsFeature.register(context.container);
|
|
11
15
|
createSubscriptionHooks(context);
|
|
12
16
|
});
|
|
13
17
|
subscriptionsPlugin.name = "auditLogs.context.subscriptions";
|
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 { 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":"
|
|
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\";\nimport { GetAuditLogFeature } from \"~/features/GetAuditLog/index.js\";\nimport { ListAuditLogsFeature } from \"~/features/ListAuditLogs/index.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 GetAuditLogFeature.register(context.container);\n ListAuditLogsFeature.register(context.container);\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","GetAuditLogFeature","ListAuditLogsFeature","createSubscriptionHooks","createGraphQLSchema","createAuditLogsContext"],"mappings":";;;;;;;;AAYO,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,mBAAmB,QAAQ,CAACF,QAAQ,SAAS;QAC7CG,qBAAqB,QAAQ,CAACH,QAAQ,SAAS;QAE/CI,wBAAwBJ;IAC5B;IAEAF,oBAAoB,IAAI,GAAG;IAC3B,OAAO;QACHA;QACAO;QACAC,uBAAuB;YACnB,qBAAqBT,QAAQ;QACjC;KACH;AACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-audit-logs",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.3",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "./index.js",
|
|
6
6
|
"./*": "./*"
|
|
@@ -22,30 +22,30 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
26
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
27
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
28
|
-
"graphql": "16.
|
|
25
|
+
"@webiny/handler-aws": "6.5.2-beta.3",
|
|
26
|
+
"@webiny/plugins": "6.5.2-beta.3",
|
|
27
|
+
"@webiny/project-utils": "6.5.2-beta.3",
|
|
28
|
+
"graphql": "16.15.0",
|
|
29
29
|
"typescript": "7.0.2",
|
|
30
|
-
"vitest": "5.0
|
|
30
|
+
"vitest": "5.1.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@webiny/api": "6.5.2-beta.
|
|
34
|
-
"@webiny/api-aco": "6.5.2-beta.
|
|
35
|
-
"@webiny/api-core": "6.5.2-beta.
|
|
36
|
-
"@webiny/api-file-manager": "6.5.2-beta.
|
|
37
|
-
"@webiny/api-headless-cms": "6.5.2-beta.
|
|
38
|
-
"@webiny/api-mailer": "6.5.2-beta.
|
|
39
|
-
"@webiny/api-website-builder": "6.5.2-beta.
|
|
40
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
41
|
-
"@webiny/common-audit-logs": "6.5.2-beta.
|
|
42
|
-
"@webiny/error": "6.5.2-beta.
|
|
43
|
-
"@webiny/feature": "6.5.2-beta.
|
|
44
|
-
"@webiny/handler": "6.5.2-beta.
|
|
45
|
-
"@webiny/handler-db": "6.5.2-beta.
|
|
46
|
-
"@webiny/handler-graphql": "6.5.2-beta.
|
|
47
|
-
"@webiny/utils": "6.5.2-beta.
|
|
48
|
-
"@webiny/wcp": "6.5.2-beta.
|
|
33
|
+
"@webiny/api": "6.5.2-beta.3",
|
|
34
|
+
"@webiny/api-aco": "6.5.2-beta.3",
|
|
35
|
+
"@webiny/api-core": "6.5.2-beta.3",
|
|
36
|
+
"@webiny/api-file-manager": "6.5.2-beta.3",
|
|
37
|
+
"@webiny/api-headless-cms": "6.5.2-beta.3",
|
|
38
|
+
"@webiny/api-mailer": "6.5.2-beta.3",
|
|
39
|
+
"@webiny/api-website-builder": "6.5.2-beta.3",
|
|
40
|
+
"@webiny/build-tools": "6.5.2-beta.3",
|
|
41
|
+
"@webiny/common-audit-logs": "6.5.2-beta.3",
|
|
42
|
+
"@webiny/error": "6.5.2-beta.3",
|
|
43
|
+
"@webiny/feature": "6.5.2-beta.3",
|
|
44
|
+
"@webiny/handler": "6.5.2-beta.3",
|
|
45
|
+
"@webiny/handler-db": "6.5.2-beta.3",
|
|
46
|
+
"@webiny/handler-graphql": "6.5.2-beta.3",
|
|
47
|
+
"@webiny/utils": "6.5.2-beta.3",
|
|
48
|
+
"@webiny/wcp": "6.5.2-beta.3",
|
|
49
49
|
"zod": "4.6.7"
|
|
50
50
|
},
|
|
51
51
|
"webiny": {
|
package/utils/expiresAt.js
CHANGED
package/utils/expiresAt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/expiresAt.js","sources":["../../src/utils/expiresAt.ts"],"sourcesContent":["export const convertExpiresAtDaysToDate = (days: number): Date => {\n const date = new Date();\n date.setTime(days * 24 * 60 * 60 * 1000 + date.getTime());\n return date;\n};\n\nexport const convertExpiresAtToUnixTimestamp = (expiresAt: Date | string): number => {\n if (typeof expiresAt === \"string\") {\n expiresAt = new Date(expiresAt);\n }\n return Math.floor(expiresAt.getTime() / 1000);\n};\n\nexport const convertUnixTimestampToDate = (\n expiresAt: number | undefined | null\n): Date | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return new Date(expiresAt * 1000);\n};\n\nexport const convertUnixTimestampToISODateString = (\n expiresAt: number | undefined | null\n): string | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return convertUnixTimestampToDate(expiresAt)?.toISOString();\n};\n"],"names":["convertExpiresAtDaysToDate","days","date","Date","convertExpiresAtToUnixTimestamp","expiresAt","Math","convertUnixTimestampToDate","convertUnixTimestampToISODateString"],"mappings":"AAAO,MAAMA,6BAA6B,CAACC;IACvC,MAAMC,OAAO,IAAIC;IACjBD,KAAK,OAAO,CAACD,AAAO,KAAPA,
|
|
1
|
+
{"version":3,"file":"utils/expiresAt.js","sources":["../../src/utils/expiresAt.ts"],"sourcesContent":["export const convertExpiresAtDaysToDate = (days: number): Date => {\n const date = new Date();\n date.setTime(days * 24 * 60 * 60 * 1000 + date.getTime());\n return date;\n};\n\nexport const convertExpiresAtToUnixTimestamp = (expiresAt: Date | string): number => {\n if (typeof expiresAt === \"string\") {\n expiresAt = new Date(expiresAt);\n }\n return Math.floor(expiresAt.getTime() / 1000);\n};\n\nexport const convertUnixTimestampToDate = (\n expiresAt: number | undefined | null\n): Date | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return new Date(expiresAt * 1000);\n};\n\nexport const convertUnixTimestampToISODateString = (\n expiresAt: number | undefined | null\n): string | undefined => {\n if (!expiresAt) {\n return undefined;\n }\n return convertUnixTimestampToDate(expiresAt)?.toISOString();\n};\n"],"names":["convertExpiresAtDaysToDate","days","date","Date","convertExpiresAtToUnixTimestamp","expiresAt","Math","convertUnixTimestampToDate","convertUnixTimestampToISODateString"],"mappings":"AAAO,MAAMA,6BAA6B,CAACC;IACvC,MAAMC,OAAO,IAAIC;IACjBD,KAAK,OAAO,CAACD,AAAO,KAAPA,OAAY,KAAK,KAAK,OAAOC,KAAK,OAAO;IACtD,OAAOA;AACX;AAEO,MAAME,kCAAkC,CAACC;IAC5C,IAAI,AAAqB,YAArB,OAAOA,WACPA,YAAY,IAAIF,KAAKE;IAEzB,OAAOC,KAAK,KAAK,CAACD,UAAU,OAAO,KAAK;AAC5C;AAEO,MAAME,6BAA6B,CACtCF;IAEA,IAAI,CAACA,WACD;IAEJ,OAAO,IAAIF,KAAKE,AAAY,OAAZA;AACpB;AAEO,MAAMG,sCAAsC,CAC/CH;IAEA,IAAI,CAACA,WACD;IAEJ,OAAOE,2BAA2BF,YAAY;AAClD"}
|