@webiny/api-audit-logs 6.5.2-beta.2 → 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.
Files changed (32) hide show
  1. package/features/GetAuditLog/GetAuditLogUseCase.d.ts +13 -0
  2. package/features/GetAuditLog/GetAuditLogUseCase.js +32 -0
  3. package/features/GetAuditLog/GetAuditLogUseCase.js.map +1 -0
  4. package/features/GetAuditLog/abstractions.d.ts +10 -0
  5. package/features/GetAuditLog/abstractions.js +5 -0
  6. package/features/GetAuditLog/abstractions.js.map +1 -0
  7. package/features/GetAuditLog/feature.d.ts +4 -0
  8. package/features/GetAuditLog/feature.js +11 -0
  9. package/features/GetAuditLog/feature.js.map +1 -0
  10. package/features/GetAuditLog/index.d.ts +2 -0
  11. package/features/GetAuditLog/index.js +2 -0
  12. package/features/ListAuditLogs/ListAuditLogsUseCase.d.ts +17 -0
  13. package/features/ListAuditLogs/ListAuditLogsUseCase.js +37 -0
  14. package/features/ListAuditLogs/ListAuditLogsUseCase.js.map +1 -0
  15. package/features/ListAuditLogs/abstractions.d.ts +11 -0
  16. package/features/ListAuditLogs/abstractions.js +5 -0
  17. package/features/ListAuditLogs/abstractions.js.map +1 -0
  18. package/features/ListAuditLogs/feature.d.ts +4 -0
  19. package/features/ListAuditLogs/feature.js +11 -0
  20. package/features/ListAuditLogs/feature.js.map +1 -0
  21. package/features/ListAuditLogs/index.d.ts +2 -0
  22. package/features/ListAuditLogs/index.js +2 -0
  23. package/features/shared/canAccessAuditLogs.d.ts +5 -0
  24. package/features/shared/canAccessAuditLogs.js +7 -0
  25. package/features/shared/canAccessAuditLogs.js.map +1 -0
  26. package/graphql/schema.js +12 -7
  27. package/graphql/schema.js.map +1 -1
  28. package/index.js +4 -0
  29. package/index.js.map +1 -1
  30. package/package.json +20 -20
  31. package/utils/expiresAt.js +1 -1
  32. package/utils/expiresAt.js.map +1 -1
@@ -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,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const GetAuditLogUseCase = createAbstraction("GetAuditLogUseCase");
3
+ export { GetAuditLogUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -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,4 @@
1
+ export declare const GetAuditLogFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -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,2 @@
1
+ export { GetAuditLogUseCase } from "./abstractions.js";
2
+ export { GetAuditLogFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { GetAuditLogUseCase } from "./abstractions.js";
2
+ export { GetAuditLogFeature } from "./feature.js";
@@ -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,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const ListAuditLogsUseCase = createAbstraction("ListAuditLogsUseCase");
3
+ export { ListAuditLogsUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -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,4 @@
1
+ export declare const ListAuditLogsFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -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,2 @@
1
+ export { ListAuditLogsUseCase } from "./abstractions.js";
2
+ export { ListAuditLogsFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { ListAuditLogsUseCase } from "./abstractions.js";
2
+ export { ListAuditLogsFeature } from "./feature.js";
@@ -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,7 @@
1
+ const canAccessAuditLogs = async (identityContext)=>{
2
+ const permissions = await identityContext.getPermissions("al.*");
3
+ return permissions.length > 0;
4
+ };
5
+ export { canAccessAuditLogs };
6
+
7
+ //# sourceMappingURL=canAccessAuditLogs.js.map
@@ -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 result = await context.auditLogs.getAuditLog(validation.data.id);
88
- if (!result) throw new NotFoundError(`Audit log with id "${validation.data.id}" not found.`);
89
- return result;
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 result = await context.auditLogs.listAuditLogs({
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.error) throw result.error;
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
  };
@@ -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 context.auditLogs.getAuditLog(validation.data.id);\n if (!result) {\n throw new NotFoundError(\n `Audit log with id \"${validation.data.id}\" not found.`\n );\n }\n return result;\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 result = await context.auditLogs.listAuditLogs({\n ...validation.data,\n ...validation.data.where\n });\n if (result.error) {\n throw result.error;\n }\n return {\n items: result.items,\n meta: {\n ...result.meta,\n totalCount: 0\n }\n };\n });\n }\n }\n }\n });\n};\n"],"names":["createGraphQLSchema","GraphQLSchemaPlugin","context","_","args","resolve","validation","getValidationSchema","createZodError","result","NotFoundError","resolveList","listValidationSchema"],"mappings":";;;AAsBO,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,SAAS,MAAMP,QAAQ,SAAS,CAAC,WAAW,CAACI,WAAW,IAAI,CAAC,EAAE;wBACrE,IAAI,CAACG,QACD,MAAM,IAAIC,cACN,CAAC,mBAAmB,EAAEJ,WAAW,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC;wBAG9D,OAAOG;oBACX;gBACJ;gBACA,MAAM,eAAcN,CAAC,EAAEC,IAAwB,EAAEF,OAAO;oBACpD,OAAOS,YAAY;wBACf,MAAML,aAAa,MAAMM,qBAAqB,cAAc,CAACR;wBAC7D,IAAI,CAACE,WAAW,OAAO,EACnB,MAAME,eAAeF,WAAW,KAAK;wBAEzC,MAAMG,SAAS,MAAMP,QAAQ,SAAS,CAAC,aAAa,CAAC;4BACjD,GAAGI,WAAW,IAAI;4BAClB,GAAGA,WAAW,IAAI,CAAC,KAAK;wBAC5B;wBACA,IAAIG,OAAO,KAAK,EACZ,MAAMA,OAAO,KAAK;wBAEtB,OAAO;4BACH,OAAOA,OAAO,KAAK;4BACnB,MAAM;gCACF,GAAGA,OAAO,IAAI;gCACd,YAAY;4BAChB;wBACJ;oBACJ;gBACJ;YACJ;QACJ;IACJ"}
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":";;;;;;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"}
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.2",
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.2",
26
- "@webiny/plugins": "6.5.2-beta.2",
27
- "@webiny/project-utils": "6.5.2-beta.2",
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
28
  "graphql": "16.15.0",
29
29
  "typescript": "7.0.2",
30
30
  "vitest": "5.1.0"
31
31
  },
32
32
  "dependencies": {
33
- "@webiny/api": "6.5.2-beta.2",
34
- "@webiny/api-aco": "6.5.2-beta.2",
35
- "@webiny/api-core": "6.5.2-beta.2",
36
- "@webiny/api-file-manager": "6.5.2-beta.2",
37
- "@webiny/api-headless-cms": "6.5.2-beta.2",
38
- "@webiny/api-mailer": "6.5.2-beta.2",
39
- "@webiny/api-website-builder": "6.5.2-beta.2",
40
- "@webiny/build-tools": "6.5.2-beta.2",
41
- "@webiny/common-audit-logs": "6.5.2-beta.2",
42
- "@webiny/error": "6.5.2-beta.2",
43
- "@webiny/feature": "6.5.2-beta.2",
44
- "@webiny/handler": "6.5.2-beta.2",
45
- "@webiny/handler-db": "6.5.2-beta.2",
46
- "@webiny/handler-graphql": "6.5.2-beta.2",
47
- "@webiny/utils": "6.5.2-beta.2",
48
- "@webiny/wcp": "6.5.2-beta.2",
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": {
@@ -1,6 +1,6 @@
1
1
  const convertExpiresAtDaysToDate = (days)=>{
2
2
  const date = new Date();
3
- date.setTime(24 * days * 3600000 + date.getTime());
3
+ date.setTime(24 * days * 60 * 60 * 1000 + date.getTime());
4
4
  return date;
5
5
  };
6
6
  const convertExpiresAtToUnixTimestamp = (expiresAt)=>{
@@ -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,OAAAA,UAA6BC,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"}
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"}