@webiny/api-audit-logs 6.3.0 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstractions.js +2 -3
- package/abstractions.js.map +1 -1
- package/config.js +2 -1
- package/config.js.map +1 -1
- package/context/AuditLogsContextValue.js +115 -125
- package/context/AuditLogsContextValue.js.map +1 -1
- package/context/index.js +21 -27
- package/context/index.js.map +1 -1
- package/events/AuditLogAfterCreateEvent.js +8 -5
- package/events/AuditLogAfterCreateEvent.js.map +1 -1
- package/events/AuditLogAfterUpdateEvent.js +8 -5
- package/events/AuditLogAfterUpdateEvent.js.map +1 -1
- package/events/AuditLogBeforeCreateEvent.js +8 -5
- package/events/AuditLogBeforeCreateEvent.js.map +1 -1
- package/events/AuditLogBeforeUpdateEvent.js +8 -5
- package/events/AuditLogBeforeUpdateEvent.js.map +1 -1
- package/events/abstractions.js +5 -24
- package/events/abstractions.js.map +1 -1
- package/events/index.js +0 -2
- package/graphql/schema.js +37 -48
- package/graphql/schema.js.map +1 -1
- package/graphql/validation.d.ts +3 -3
- package/graphql/validation.js +26 -30
- package/graphql/validation.js.map +1 -1
- package/index.js +18 -15
- package/index.js.map +1 -1
- package/package.json +26 -26
- package/storage/AccessPatternHandler.js +31 -52
- package/storage/AccessPatternHandler.js.map +1 -1
- package/storage/Converter.js +45 -48
- package/storage/Converter.js.map +1 -1
- package/storage/Storage.js +69 -77
- package/storage/Storage.js.map +1 -1
- package/storage/abstractions/AccessPattern.js +0 -3
- package/storage/abstractions/AccessPatternHandler.js +0 -3
- package/storage/abstractions/Converter.js +0 -3
- package/storage/abstractions/Storage.js +0 -3
- package/storage/accessPatterns/AppAccessPattern.js +31 -25
- package/storage/accessPatterns/AppAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppCreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/AppCreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityAccessPattern.js +31 -25
- package/storage/accessPatterns/AppEntityAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityActionAccessPattern.js +31 -25
- package/storage/accessPatterns/AppEntityActionAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/AppEntityActionCreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/AppEntityCreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/BaseAccessPattern.js +47 -70
- package/storage/accessPatterns/BaseAccessPattern.js.map +1 -1
- package/storage/accessPatterns/CreatedByAccessPattern.js +34 -28
- package/storage/accessPatterns/CreatedByAccessPattern.js.map +1 -1
- package/storage/accessPatterns/CreatedOnAccessPattern.js +34 -26
- package/storage/accessPatterns/CreatedOnAccessPattern.js.map +1 -1
- package/storage/accessPatterns/DefaultAccessPattern.js +31 -32
- package/storage/accessPatterns/DefaultAccessPattern.js.map +1 -1
- package/storage/accessPatterns/EntityIdAccessPattern.js +32 -27
- package/storage/accessPatterns/EntityIdAccessPattern.js.map +1 -1
- package/storage/accessPatterns/index.js +44 -34
- package/storage/accessPatterns/index.js.map +1 -1
- package/storage/cursorSchema.js +15 -18
- package/storage/cursorSchema.js.map +1 -1
- package/storage/entity.js +115 -122
- package/storage/entity.js.map +1 -1
- package/storage/results/ListErrorResult.js +9 -8
- package/storage/results/ListErrorResult.js.map +1 -1
- package/storage/results/ListSuccessResult.js +13 -12
- package/storage/results/ListSuccessResult.js.map +1 -1
- package/storage/results/index.js +0 -2
- package/storage/startKey.js +4 -5
- package/storage/startKey.js.map +1 -1
- package/storage/types.js +0 -3
- package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js +26 -25
- package/subscriptions/aco/handlers/AuditLogFolderAfterCreateHandler.js.map +1 -1
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js +29 -28
- package/subscriptions/aco/handlers/AuditLogFolderAfterDeleteHandler.js.map +1 -1
- package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js +32 -32
- package/subscriptions/aco/handlers/AuditLogFolderAfterUpdateHandler.js.map +1 -1
- package/subscriptions/aco/index.js +5 -4
- package/subscriptions/aco/index.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js +21 -20
- package/subscriptions/fileManager/handlers/AuditLogFileAfterCreateHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js +21 -20
- package/subscriptions/fileManager/handlers/AuditLogFileAfterDeleteHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js +24 -24
- package/subscriptions/fileManager/handlers/AuditLogFileAfterUpdateHandler.js.map +1 -1
- package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js +24 -24
- package/subscriptions/fileManager/handlers/AuditLogSettingsAfterUpdateHandler.js.map +1 -1
- package/subscriptions/fileManager/index.js +6 -8
- package/subscriptions/fileManager/index.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js +26 -29
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterPublishEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterRestoreFromBinEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUnpublishEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js +24 -27
- package/subscriptions/headlessCms/handlers/AuditLogEntryAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js +21 -23
- package/subscriptions/headlessCms/handlers/AuditLogEntryRevisionAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js +24 -24
- package/subscriptions/headlessCms/handlers/AuditLogGroupAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterCreateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js +21 -20
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterDeleteEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.js +24 -24
- package/subscriptions/headlessCms/handlers/AuditLogModelAfterUpdateEventHandler.js.map +1 -1
- package/subscriptions/headlessCms/index.js +16 -20
- package/subscriptions/headlessCms/index.js.map +1 -1
- package/subscriptions/index.js +8 -7
- package/subscriptions/index.js.map +1 -1
- package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js +23 -22
- package/subscriptions/mailer/handlers/AuditLogMailerSettingsAfterSaveHandler.js.map +1 -1
- package/subscriptions/mailer/index.js +3 -3
- package/subscriptions/mailer/index.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js +31 -37
- package/subscriptions/security/handlers/AuditLogApiKeyAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js +31 -37
- package/subscriptions/security/handlers/AuditLogApiKeyAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js +35 -42
- package/subscriptions/security/handlers/AuditLogApiKeyAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogRoleAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogRoleAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js +24 -24
- package/subscriptions/security/handlers/AuditLogRoleAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogTeamAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogTeamAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js +24 -24
- package/subscriptions/security/handlers/AuditLogTeamAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogUserAfterCreateHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js +21 -20
- package/subscriptions/security/handlers/AuditLogUserAfterDeleteHandler.js.map +1 -1
- package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js +24 -24
- package/subscriptions/security/handlers/AuditLogUserAfterUpdateHandler.js.map +1 -1
- package/subscriptions/security/handlers/cleanupApiKey.js +10 -16
- package/subscriptions/security/handlers/cleanupApiKey.js.map +1 -1
- package/subscriptions/security/index.js +14 -20
- package/subscriptions/security/index.js.map +1 -1
- package/subscriptions/websiteBuilder/index.js +14 -16
- package/subscriptions/websiteBuilder/index.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterCreateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterCreateRevisionFromHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterDeleteHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js +23 -23
- package/subscriptions/websiteBuilder/pages/PageAfterDuplicateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterMoveHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterPublishHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js +20 -19
- package/subscriptions/websiteBuilder/pages/PageAfterUnpublishHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js +23 -23
- package/subscriptions/websiteBuilder/pages/PageAfterUpdateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js +20 -19
- package/subscriptions/websiteBuilder/redirects/RedirectAfterCreateHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js +20 -19
- package/subscriptions/websiteBuilder/redirects/RedirectAfterDeleteHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js +20 -19
- package/subscriptions/websiteBuilder/redirects/RedirectAfterMoveHandler.js.map +1 -1
- package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js +23 -23
- package/subscriptions/websiteBuilder/redirects/RedirectAfterUpdateHandler.js.map +1 -1
- package/types.js +0 -3
- package/utils/expiresAt.js +14 -19
- package/utils/expiresAt.js.map +1 -1
- package/utils/getAuditConfig.js +79 -98
- package/utils/getAuditConfig.js.map +1 -1
- package/utils/getAuditObject.js +14 -15
- package/utils/getAuditObject.js.map +1 -1
- package/events/index.js.map +0 -1
- package/storage/abstractions/AccessPattern.js.map +0 -1
- package/storage/abstractions/AccessPatternHandler.js.map +0 -1
- package/storage/abstractions/Converter.js.map +0 -1
- package/storage/abstractions/Storage.js.map +0 -1
- package/storage/results/index.js.map +0 -1
- package/storage/types.js.map +0 -1
- package/types.js.map +0 -1
package/graphql/schema.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return !!context.auditLogs;
|
|
8
|
-
},
|
|
9
|
-
typeDefs: `
|
|
4
|
+
const createGraphQLSchema = ()=>new GraphQLSchemaPlugin({
|
|
5
|
+
isApplicable: (context)=>!!context.auditLogs,
|
|
6
|
+
typeDefs: `
|
|
10
7
|
type AuditLogCreatedBy {
|
|
11
8
|
id: ID!
|
|
12
9
|
displayName: String
|
|
@@ -78,49 +75,41 @@ export const createGraphQLSchema = () => {
|
|
|
78
75
|
auditLogs: AuditLogsQuery
|
|
79
76
|
}
|
|
80
77
|
`,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
resolvers: {
|
|
79
|
+
Query: {
|
|
80
|
+
auditLogs: ()=>({})
|
|
81
|
+
},
|
|
82
|
+
AuditLogsQuery: {
|
|
83
|
+
async getAuditLog (_, args, context) {
|
|
84
|
+
return resolve(async ()=>{
|
|
85
|
+
const validation = await getValidationSchema.safeParseAsync(args);
|
|
86
|
+
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;
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
async listAuditLogs (_, args, context) {
|
|
93
|
+
return resolveList(async ()=>{
|
|
94
|
+
const validation = await listValidationSchema.safeParseAsync(args);
|
|
95
|
+
if (!validation.success) throw createZodError(validation.error);
|
|
96
|
+
const result = await context.auditLogs.listAuditLogs({
|
|
97
|
+
...validation.data,
|
|
98
|
+
...validation.data.where
|
|
99
|
+
});
|
|
100
|
+
if (result.error) throw result.error;
|
|
101
|
+
return {
|
|
102
|
+
items: result.items,
|
|
103
|
+
meta: {
|
|
104
|
+
...result.meta,
|
|
105
|
+
totalCount: 0
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
91
110
|
}
|
|
92
|
-
const result = await context.auditLogs.getAuditLog(validation.data.id);
|
|
93
|
-
if (!result) {
|
|
94
|
-
throw new NotFoundError(`Audit log with id "${validation.data.id}" not found.`);
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
async listAuditLogs(_, args, context) {
|
|
100
|
-
return resolveList(async () => {
|
|
101
|
-
const validation = await listValidationSchema.safeParseAsync(args);
|
|
102
|
-
if (!validation.success) {
|
|
103
|
-
throw createZodError(validation.error);
|
|
104
|
-
}
|
|
105
|
-
const result = await context.auditLogs.listAuditLogs({
|
|
106
|
-
...validation.data,
|
|
107
|
-
...validation.data.where
|
|
108
|
-
});
|
|
109
|
-
if (result.error) {
|
|
110
|
-
throw result.error;
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
items: result.items,
|
|
114
|
-
meta: {
|
|
115
|
-
...result.meta,
|
|
116
|
-
totalCount: 0
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
111
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
};
|
|
112
|
+
});
|
|
113
|
+
export { createGraphQLSchema };
|
|
125
114
|
|
|
126
115
|
//# sourceMappingURL=schema.js.map
|
package/graphql/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
package/graphql/validation.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare const listValidationSchema: zod.ZodObject<{
|
|
|
7
7
|
app: zod.ZodOptional<zod.ZodString>;
|
|
8
8
|
entity: zod.ZodOptional<zod.ZodString>;
|
|
9
9
|
entityId: zod.ZodOptional<zod.ZodString>;
|
|
10
|
-
createdOn_gte: zod.
|
|
11
|
-
createdOn_lte: zod.
|
|
10
|
+
createdOn_gte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
|
|
11
|
+
createdOn_lte: zod.ZodPreprocess<zod.ZodOptional<zod.ZodDate>>;
|
|
12
12
|
createdBy: zod.ZodOptional<zod.ZodString>;
|
|
13
13
|
action: zod.ZodOptional<zod.ZodString>;
|
|
14
14
|
}, zod.core.$strip>;
|
|
@@ -17,5 +17,5 @@ export declare const listValidationSchema: zod.ZodObject<{
|
|
|
17
17
|
ASC: "ASC";
|
|
18
18
|
DESC: "DESC";
|
|
19
19
|
}>>;
|
|
20
|
-
limit: zod.ZodDefault<zod.
|
|
20
|
+
limit: zod.ZodDefault<zod.ZodPreprocess<zod.ZodOptional<zod.ZodNumber>>>;
|
|
21
21
|
}, zod.core.$strip>;
|
package/graphql/validation.js
CHANGED
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import zod from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const getValidationSchema = zod.object({
|
|
3
|
+
id: zod.string().min(1, "ID is required.")
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (typeof input == "string") {
|
|
29
|
-
return parseInt(input);
|
|
30
|
-
}
|
|
31
|
-
return input;
|
|
32
|
-
}, zod.number().min(1).max(100).optional()).default(25)
|
|
5
|
+
const listValidationSchema = zod.object({
|
|
6
|
+
where: zod.object({
|
|
7
|
+
app: zod.string().min(1, "App is required.").optional(),
|
|
8
|
+
entity: zod.string().optional(),
|
|
9
|
+
entityId: zod.string().min(1, "Entity ID is required.").optional(),
|
|
10
|
+
createdOn_gte: zod.preprocess((input)=>{
|
|
11
|
+
if ("string" == typeof input || input instanceof Date) return new Date(input);
|
|
12
|
+
}, zod.date().optional()),
|
|
13
|
+
createdOn_lte: zod.preprocess((input)=>{
|
|
14
|
+
if ("string" == typeof input || input instanceof Date) return new Date(input);
|
|
15
|
+
}, zod.date().optional()),
|
|
16
|
+
createdBy: zod.string().optional(),
|
|
17
|
+
action: zod.string().optional()
|
|
18
|
+
}),
|
|
19
|
+
after: zod.string().optional(),
|
|
20
|
+
sort: zod["enum"]([
|
|
21
|
+
"ASC",
|
|
22
|
+
"DESC"
|
|
23
|
+
]).optional(),
|
|
24
|
+
limit: zod.preprocess((input)=>{
|
|
25
|
+
if ("string" == typeof input) return parseInt(input);
|
|
26
|
+
return input;
|
|
27
|
+
}, zod.number().min(1).max(100).optional()).default(25)
|
|
33
28
|
});
|
|
29
|
+
export { getValidationSchema, listValidationSchema };
|
|
34
30
|
|
|
35
31
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/validation.js","sources":["../../src/graphql/validation.ts"],"sourcesContent":["import zod from \"zod\";\n\nexport const getValidationSchema = zod.object({\n id: zod.string().min(1, \"ID is required.\")\n});\n\nexport const listValidationSchema = zod.object({\n where: zod.object({\n app: zod.string().min(1, \"App is required.\").optional(),\n entity: zod.string().optional(),\n entityId: zod.string().min(1, \"Entity ID is required.\").optional(),\n createdOn_gte: zod.preprocess(input => {\n if (typeof input == \"string\" || input instanceof Date) {\n return new Date(input);\n }\n return undefined;\n }, zod.date().optional()),\n createdOn_lte: zod.preprocess(input => {\n if (typeof input == \"string\" || input instanceof Date) {\n return new Date(input);\n }\n return undefined;\n }, zod.date().optional()),\n createdBy: zod.string().optional(),\n action: zod.string().optional()\n }),\n after: zod.string().optional(),\n sort: zod.enum([\"ASC\", \"DESC\"]).optional(),\n limit: zod\n .preprocess(input => {\n if (typeof input == \"string\") {\n return parseInt(input);\n }\n return input;\n }, zod.number().min(1).max(100).optional())\n .default(25)\n});\n"],"names":["getValidationSchema","zod","listValidationSchema","input","Date","parseInt"],"mappings":";AAEO,MAAMA,sBAAsBC,IAAI,MAAM,CAAC;IAC1C,IAAIA,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG;AAC5B;AAEO,MAAMC,uBAAuBD,IAAI,MAAM,CAAC;IAC3C,OAAOA,IAAI,MAAM,CAAC;QACd,KAAKA,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG,oBAAoB,QAAQ;QACrD,QAAQA,IAAI,MAAM,GAAG,QAAQ;QAC7B,UAAUA,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG,0BAA0B,QAAQ;QAChE,eAAeA,IAAI,UAAU,CAACE,CAAAA;YAC1B,IAAI,AAAgB,YAAhB,OAAOA,SAAqBA,iBAAiBC,MAC7C,OAAO,IAAIA,KAAKD;QAGxB,GAAGF,IAAI,IAAI,GAAG,QAAQ;QACtB,eAAeA,IAAI,UAAU,CAACE,CAAAA;YAC1B,IAAI,AAAgB,YAAhB,OAAOA,SAAqBA,iBAAiBC,MAC7C,OAAO,IAAIA,KAAKD;QAGxB,GAAGF,IAAI,IAAI,GAAG,QAAQ;QACtB,WAAWA,IAAI,MAAM,GAAG,QAAQ;QAChC,QAAQA,IAAI,MAAM,GAAG,QAAQ;IACjC;IACA,OAAOA,IAAI,MAAM,GAAG,QAAQ;IAC5B,MAAMA,GAAG,CAAHA,OAAQ,CAAC;QAAC;QAAO;KAAO,EAAE,QAAQ;IACxC,OAAOA,IAAAA,UACQ,CAACE,CAAAA;QACR,IAAI,AAAgB,YAAhB,OAAOA,OACP,OAAOE,SAASF;QAEpB,OAAOA;IACX,GAAGF,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,KAAK,QAAQ,IACvC,OAAO,CAAC;AACjB"}
|
package/index.js
CHANGED
|
@@ -3,21 +3,24 @@ 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
|
-
export const createAuditLogs = params => {
|
|
7
|
-
const subscriptionsPlugin = new ContextPlugin(context => {
|
|
8
|
-
if (!context.wcp.canUseFeature("auditLogs")) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
context.container.registerInstance(AuditLogsContext, context);
|
|
12
|
-
createSubscriptionHooks(context);
|
|
13
|
-
});
|
|
14
|
-
subscriptionsPlugin.name = "auditLogs.context.subscriptions";
|
|
15
|
-
return [subscriptionsPlugin, createGraphQLSchema(), createAuditLogsContext({
|
|
16
|
-
tableName: params?.tableName,
|
|
17
|
-
deleteLogsAfterDays: params?.deleteLogsAfterDays,
|
|
18
|
-
documentClient: params?.documentClient
|
|
19
|
-
})];
|
|
20
|
-
};
|
|
21
6
|
export * from "./config.js";
|
|
7
|
+
const createAuditLogs = (params)=>{
|
|
8
|
+
const subscriptionsPlugin = new ContextPlugin((context)=>{
|
|
9
|
+
if (!context.wcp.canUseFeature("auditLogs")) return;
|
|
10
|
+
context.container.registerInstance(AuditLogsContext, context);
|
|
11
|
+
createSubscriptionHooks(context);
|
|
12
|
+
});
|
|
13
|
+
subscriptionsPlugin.name = "auditLogs.context.subscriptions";
|
|
14
|
+
return [
|
|
15
|
+
subscriptionsPlugin,
|
|
16
|
+
createGraphQLSchema(),
|
|
17
|
+
createAuditLogsContext({
|
|
18
|
+
tableName: params?.tableName,
|
|
19
|
+
deleteLogsAfterDays: params?.deleteLogsAfterDays,
|
|
20
|
+
documentClient: params?.documentClient
|
|
21
|
+
})
|
|
22
|
+
];
|
|
23
|
+
};
|
|
24
|
+
export { createAuditLogs };
|
|
22
25
|
|
|
23
26
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { AuditLogsContext } from \"./abstractions.js\";\n\nexport interface ICreateAuditLogsParams {\n deleteLogsAfterDays: number | undefined;\n tableName?: string;\n documentClient?: DynamoDBDocument;\n}\n\nexport const createAuditLogs = (params?: ICreateAuditLogsParams) => {\n const subscriptionsPlugin = new ContextPlugin<AuditLogsContext.Interface>(context => {\n if (!context.wcp.canUseFeature(\"auditLogs\")) {\n return;\n }\n\n context.container.registerInstance(AuditLogsContext, context);\n\n createSubscriptionHooks(context);\n });\n\n subscriptionsPlugin.name = \"auditLogs.context.subscriptions\";\n return [\n subscriptionsPlugin,\n createGraphQLSchema(),\n createAuditLogsContext({\n tableName: params?.tableName,\n deleteLogsAfterDays: params?.deleteLogsAfterDays,\n documentClient: params?.documentClient\n })\n ];\n};\nexport * from \"~/config.js\";\n"],"names":["createAuditLogs","params","subscriptionsPlugin","ContextPlugin","context","AuditLogsContext","createSubscriptionHooks","createGraphQLSchema","createAuditLogsContext"],"mappings":";;;;;;AAaO,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,WAAWP,QAAQ;YACnB,qBAAqBA,QAAQ;YAC7B,gBAAgBA,QAAQ;QAC5B;KACH;AACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-audit-logs",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.0",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "./index.js",
|
|
6
6
|
"./*": "./*"
|
|
@@ -23,33 +23,33 @@
|
|
|
23
23
|
"directory": "dist"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@webiny/handler-aws": "6.
|
|
27
|
-
"@webiny/plugins": "6.
|
|
28
|
-
"@webiny/project-utils": "6.
|
|
29
|
-
"graphql": "16.
|
|
26
|
+
"@webiny/handler-aws": "6.4.0-beta.0",
|
|
27
|
+
"@webiny/plugins": "6.4.0-beta.0",
|
|
28
|
+
"@webiny/project-utils": "6.4.0-beta.0",
|
|
29
|
+
"graphql": "16.14.0",
|
|
30
30
|
"typescript": "6.0.3",
|
|
31
|
-
"vitest": "4.1.
|
|
31
|
+
"vitest": "4.1.6"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@webiny/api": "6.
|
|
35
|
-
"@webiny/api-aco": "6.
|
|
36
|
-
"@webiny/api-core": "6.
|
|
37
|
-
"@webiny/api-file-manager": "6.
|
|
38
|
-
"@webiny/api-headless-cms": "6.
|
|
39
|
-
"@webiny/api-mailer": "6.
|
|
40
|
-
"@webiny/api-website-builder": "6.
|
|
41
|
-
"@webiny/aws-sdk": "6.
|
|
42
|
-
"@webiny/build-tools": "6.
|
|
43
|
-
"@webiny/common-audit-logs": "6.
|
|
44
|
-
"@webiny/db-dynamodb": "6.
|
|
45
|
-
"@webiny/error": "6.
|
|
46
|
-
"@webiny/feature": "6.
|
|
47
|
-
"@webiny/handler": "6.
|
|
48
|
-
"@webiny/handler-db": "6.
|
|
49
|
-
"@webiny/handler-graphql": "6.
|
|
50
|
-
"@webiny/utils": "6.
|
|
51
|
-
"@webiny/wcp": "6.
|
|
52
|
-
"zod": "4.3
|
|
34
|
+
"@webiny/api": "6.4.0-beta.0",
|
|
35
|
+
"@webiny/api-aco": "6.4.0-beta.0",
|
|
36
|
+
"@webiny/api-core": "6.4.0-beta.0",
|
|
37
|
+
"@webiny/api-file-manager": "6.4.0-beta.0",
|
|
38
|
+
"@webiny/api-headless-cms": "6.4.0-beta.0",
|
|
39
|
+
"@webiny/api-mailer": "6.4.0-beta.0",
|
|
40
|
+
"@webiny/api-website-builder": "6.4.0-beta.0",
|
|
41
|
+
"@webiny/aws-sdk": "6.4.0-beta.0",
|
|
42
|
+
"@webiny/build-tools": "6.4.0-beta.0",
|
|
43
|
+
"@webiny/common-audit-logs": "6.4.0-beta.0",
|
|
44
|
+
"@webiny/db-dynamodb": "6.4.0-beta.0",
|
|
45
|
+
"@webiny/error": "6.4.0-beta.0",
|
|
46
|
+
"@webiny/feature": "6.4.0-beta.0",
|
|
47
|
+
"@webiny/handler": "6.4.0-beta.0",
|
|
48
|
+
"@webiny/handler-db": "6.4.0-beta.0",
|
|
49
|
+
"@webiny/handler-graphql": "6.4.0-beta.0",
|
|
50
|
+
"@webiny/utils": "6.4.0-beta.0",
|
|
51
|
+
"@webiny/wcp": "6.4.0-beta.0",
|
|
52
|
+
"zod": "4.4.3"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
|
|
55
55
|
}
|
|
@@ -1,60 +1,39 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
class AccessPatternHandler {
|
|
3
|
+
constructor(params){
|
|
4
|
+
if (0 === params.patterns.length) throw new WebinyError({
|
|
5
|
+
message: "At least one access pattern must be provided.",
|
|
6
|
+
code: "ACCESS_PATTERN_NOT_PROVIDED"
|
|
7
|
+
});
|
|
8
|
+
this.patterns = params.patterns;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
});
|
|
10
|
+
async handle(params) {
|
|
11
|
+
const pattern = this.find(params);
|
|
12
|
+
if (!pattern) throw new WebinyError({
|
|
13
|
+
message: "No access pattern found for the given parameters.",
|
|
14
|
+
code: "ACCESS_PATTERN_NOT_FOUND",
|
|
15
|
+
data: {
|
|
16
|
+
...params
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return await pattern.list(params);
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (!pattern) {
|
|
30
|
-
throw new WebinyError({
|
|
31
|
-
message: "No default access pattern found.",
|
|
32
|
-
code: "DEFAULT_ACCESS_PATTERN_NOT_FOUND"
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return pattern;
|
|
36
|
-
}
|
|
37
|
-
listIndexPatterns() {
|
|
38
|
-
return this.patterns.filter(pattern => {
|
|
39
|
-
return pattern.index !== undefined;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
find(params) {
|
|
43
|
-
/**
|
|
44
|
-
* First we need to go through all the patterns and find the one that can handle the given params.
|
|
45
|
-
*/
|
|
46
|
-
for (const pattern of this.patterns) {
|
|
47
|
-
if (pattern.canHandle(params)) {
|
|
21
|
+
getDefaultPattern() {
|
|
22
|
+
const pattern = this.patterns.find((pattern)=>void 0 === pattern.index);
|
|
23
|
+
if (!pattern) throw new WebinyError({
|
|
24
|
+
message: "No default access pattern found.",
|
|
25
|
+
code: "DEFAULT_ACCESS_PATTERN_NOT_FOUND"
|
|
26
|
+
});
|
|
48
27
|
return pattern;
|
|
49
|
-
}
|
|
50
28
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
29
|
+
listIndexPatterns() {
|
|
30
|
+
return this.patterns.filter((pattern)=>void 0 !== pattern.index);
|
|
31
|
+
}
|
|
32
|
+
find(params) {
|
|
33
|
+
for (const pattern of this.patterns)if (pattern.canHandle(params)) return pattern;
|
|
34
|
+
return this.patterns.find((pattern)=>void 0 === pattern.index);
|
|
35
|
+
}
|
|
58
36
|
}
|
|
37
|
+
export { AccessPatternHandler };
|
|
59
38
|
|
|
60
39
|
//# sourceMappingURL=AccessPatternHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"storage/AccessPatternHandler.js","sources":["../../src/storage/AccessPatternHandler.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport type { IStorageListParams } from \"~/storage/abstractions/Storage.js\";\nimport type {\n IAccessPatternHandler,\n IAccessPatternHandlerHandleResult\n} from \"~/storage/abstractions/AccessPatternHandler.js\";\nimport type { IAccessPattern } from \"~/storage/abstractions/AccessPattern.js\";\n\nexport interface IAccessPatternHandlerParams {\n patterns: IAccessPattern<unknown>[];\n}\n\nexport class AccessPatternHandler implements IAccessPatternHandler {\n private readonly patterns;\n\n public constructor(params: IAccessPatternHandlerParams) {\n if (params.patterns.length === 0) {\n throw new WebinyError({\n message: \"At least one access pattern must be provided.\",\n code: \"ACCESS_PATTERN_NOT_PROVIDED\"\n });\n }\n this.patterns = params.patterns;\n }\n\n public async handle(params: IStorageListParams): Promise<IAccessPatternHandlerHandleResult> {\n const pattern = this.find(params);\n if (!pattern) {\n throw new WebinyError({\n message: \"No access pattern found for the given parameters.\",\n code: \"ACCESS_PATTERN_NOT_FOUND\",\n data: {\n ...params\n }\n });\n }\n\n return await pattern.list(params);\n }\n\n public getDefaultPattern(): IAccessPattern<unknown> {\n const pattern = this.patterns.find(pattern => {\n return pattern.index === undefined;\n });\n if (!pattern) {\n throw new WebinyError({\n message: \"No default access pattern found.\",\n code: \"DEFAULT_ACCESS_PATTERN_NOT_FOUND\"\n });\n }\n return pattern;\n }\n\n public listIndexPatterns(): IAccessPattern<unknown>[] {\n return this.patterns.filter(pattern => {\n return pattern.index !== undefined;\n });\n }\n\n private find(params: IStorageListParams): IAccessPattern<unknown> | undefined {\n /**\n * First we need to go through all the patterns and find the one that can handle the given params.\n */\n for (const pattern of this.patterns) {\n if (pattern.canHandle(params)) {\n return pattern;\n }\n }\n /**\n * If none can handle, let's find one which has index set to undefined (default pattern).\n */\n return this.patterns.find(pattern => {\n return pattern.index === undefined;\n });\n }\n}\n"],"names":["AccessPatternHandler","params","WebinyError","pattern","undefined"],"mappings":";AAYO,MAAMA;IAGT,YAAmBC,MAAmC,CAAE;QACpD,IAAIA,AAA2B,MAA3BA,OAAO,QAAQ,CAAC,MAAM,EACtB,MAAM,IAAIC,YAAY;YAClB,SAAS;YACT,MAAM;QACV;QAEJ,IAAI,CAAC,QAAQ,GAAGD,OAAO,QAAQ;IACnC;IAEA,MAAa,OAAOA,MAA0B,EAA8C;QACxF,MAAME,UAAU,IAAI,CAAC,IAAI,CAACF;QAC1B,IAAI,CAACE,SACD,MAAM,IAAID,YAAY;YAClB,SAAS;YACT,MAAM;YACN,MAAM;gBACF,GAAGD,MAAM;YACb;QACJ;QAGJ,OAAO,MAAME,QAAQ,IAAI,CAACF;IAC9B;IAEO,oBAA6C;QAChD,MAAME,UAAU,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACA,CAAAA,UACxBA,AAAkBC,WAAlBD,QAAQ,KAAK;QAExB,IAAI,CAACA,SACD,MAAM,IAAID,YAAY;YAClB,SAAS;YACT,MAAM;QACV;QAEJ,OAAOC;IACX;IAEO,oBAA+C;QAClD,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACA,CAAAA,UACjBA,AAAkBC,WAAlBD,QAAQ,KAAK;IAE5B;IAEQ,KAAKF,MAA0B,EAAuC;QAI1E,KAAK,MAAME,WAAW,IAAI,CAAC,QAAQ,CAC/B,IAAIA,QAAQ,SAAS,CAACF,SAClB,OAAOE;QAMf,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACA,CAAAA,UACfA,AAAkBC,WAAlBD,QAAQ,KAAK;IAE5B;AACJ"}
|
package/storage/Converter.js
CHANGED
|
@@ -1,52 +1,49 @@
|
|
|
1
1
|
import { convertExpiresAtToUnixTimestamp } from "../utils/expiresAt.js";
|
|
2
|
-
const convertToDateTime = value
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
expiresAt: convertExpiresAtToUnixTimestamp(auditLog.expiresAt)
|
|
48
|
-
};
|
|
49
|
-
}
|
|
2
|
+
const convertToDateTime = (value)=>new Date(value);
|
|
3
|
+
class Converter {
|
|
4
|
+
constructor(params){
|
|
5
|
+
this.compressionHandler = params.compressionHandler;
|
|
6
|
+
this.patternHandler = params.patternHandler;
|
|
7
|
+
}
|
|
8
|
+
async oneFromStorage(item) {
|
|
9
|
+
return {
|
|
10
|
+
...item.data,
|
|
11
|
+
expiresAt: convertToDateTime(item.data.expiresAt),
|
|
12
|
+
content: await this.compressionHandler.decompress(JSON.parse(item.data.content)),
|
|
13
|
+
createdOn: new Date(item.data.createdOn)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async listFromStorage(items) {
|
|
17
|
+
return await Promise.all(items.map(async (item)=>await this.oneFromStorage(item)));
|
|
18
|
+
}
|
|
19
|
+
async oneToStorage(auditLog) {
|
|
20
|
+
const defaultPattern = this.patternHandler.getDefaultPattern();
|
|
21
|
+
const defaultKeys = defaultPattern.createKeys(auditLog);
|
|
22
|
+
const patterns = this.patternHandler.listIndexPatterns();
|
|
23
|
+
const keys = patterns.reduce((output, pattern)=>{
|
|
24
|
+
const patternKeys = pattern.createKeys(auditLog);
|
|
25
|
+
return {
|
|
26
|
+
...output,
|
|
27
|
+
[`${pattern.index}_PK`]: patternKeys.partitionKey,
|
|
28
|
+
[`${pattern.index}_SK`]: patternKeys.sortKey
|
|
29
|
+
};
|
|
30
|
+
}, {});
|
|
31
|
+
return {
|
|
32
|
+
PK: defaultKeys.partitionKey,
|
|
33
|
+
SK: defaultKeys.sortKey,
|
|
34
|
+
...keys,
|
|
35
|
+
TYPE: "auditLog.log",
|
|
36
|
+
GSI_TENANT: auditLog.tenant,
|
|
37
|
+
data: {
|
|
38
|
+
...auditLog,
|
|
39
|
+
expiresAt: auditLog.expiresAt.toISOString(),
|
|
40
|
+
content: JSON.stringify(await this.compressionHandler.compress(auditLog.content)),
|
|
41
|
+
createdOn: auditLog.createdOn.toISOString()
|
|
42
|
+
},
|
|
43
|
+
expiresAt: convertExpiresAtToUnixTimestamp(auditLog.expiresAt)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
50
46
|
}
|
|
47
|
+
export { Converter };
|
|
51
48
|
|
|
52
49
|
//# sourceMappingURL=Converter.js.map
|