@webiny/api-audit-logs-ddb 0.0.0-unstable.0d717d18dd
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/AccessPatternHandler.d.ts +14 -0
- package/AccessPatternHandler.js +39 -0
- package/AccessPatternHandler.js.map +1 -0
- package/AuditLogsDdbFeature.d.ts +8 -0
- package/AuditLogsDdbFeature.js +24 -0
- package/AuditLogsDdbFeature.js.map +1 -0
- package/Converter.d.ts +17 -0
- package/Converter.js +49 -0
- package/Converter.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/Storage.d.ts +18 -0
- package/Storage.js +81 -0
- package/Storage.js.map +1 -0
- package/abstractions/AccessPattern.d.ts +25 -0
- package/abstractions/AccessPattern.js +0 -0
- package/abstractions/AccessPatternHandler.d.ts +13 -0
- package/abstractions/AccessPatternHandler.js +0 -0
- package/abstractions/Converter.d.ts +7 -0
- package/abstractions/Converter.js +0 -0
- package/accessPatterns/AppAccessPattern.d.ts +9 -0
- package/accessPatterns/AppAccessPattern.js +35 -0
- package/accessPatterns/AppAccessPattern.js.map +1 -0
- package/accessPatterns/AppCreatedByAccessPattern.d.ts +9 -0
- package/accessPatterns/AppCreatedByAccessPattern.js +38 -0
- package/accessPatterns/AppCreatedByAccessPattern.js.map +1 -0
- package/accessPatterns/AppEntityAccessPattern.d.ts +9 -0
- package/accessPatterns/AppEntityAccessPattern.js +35 -0
- package/accessPatterns/AppEntityAccessPattern.js.map +1 -0
- package/accessPatterns/AppEntityActionAccessPattern.d.ts +9 -0
- package/accessPatterns/AppEntityActionAccessPattern.js +35 -0
- package/accessPatterns/AppEntityActionAccessPattern.js.map +1 -0
- package/accessPatterns/AppEntityActionCreatedByAccessPattern.d.ts +9 -0
- package/accessPatterns/AppEntityActionCreatedByAccessPattern.js +38 -0
- package/accessPatterns/AppEntityActionCreatedByAccessPattern.js.map +1 -0
- package/accessPatterns/AppEntityCreatedByAccessPattern.d.ts +9 -0
- package/accessPatterns/AppEntityCreatedByAccessPattern.js +38 -0
- package/accessPatterns/AppEntityCreatedByAccessPattern.js.map +1 -0
- package/accessPatterns/BaseAccessPattern.d.ts +33 -0
- package/accessPatterns/BaseAccessPattern.js +64 -0
- package/accessPatterns/BaseAccessPattern.js.map +1 -0
- package/accessPatterns/CreatedByAccessPattern.d.ts +9 -0
- package/accessPatterns/CreatedByAccessPattern.js +38 -0
- package/accessPatterns/CreatedByAccessPattern.js.map +1 -0
- package/accessPatterns/CreatedOnAccessPattern.d.ts +9 -0
- package/accessPatterns/CreatedOnAccessPattern.js +38 -0
- package/accessPatterns/CreatedOnAccessPattern.js.map +1 -0
- package/accessPatterns/DefaultAccessPattern.d.ts +15 -0
- package/accessPatterns/DefaultAccessPattern.js +35 -0
- package/accessPatterns/DefaultAccessPattern.js.map +1 -0
- package/accessPatterns/EntityIdAccessPattern.d.ts +9 -0
- package/accessPatterns/EntityIdAccessPattern.js +38 -0
- package/accessPatterns/EntityIdAccessPattern.js.map +1 -0
- package/accessPatterns/index.d.ts +6 -0
- package/accessPatterns/index.js +57 -0
- package/accessPatterns/index.js.map +1 -0
- package/cursorSchema.d.ts +5 -0
- package/cursorSchema.js +22 -0
- package/cursorSchema.js.map +1 -0
- package/entity.d.ts +36 -0
- package/entity.js +120 -0
- package/entity.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.js +17 -0
- package/index.js.map +1 -0
- package/package.json +46 -0
- package/results/ListErrorResult.d.ts +10 -0
- package/results/ListErrorResult.js +12 -0
- package/results/ListErrorResult.js.map +1 -0
- package/results/ListSuccessResult.d.ts +14 -0
- package/results/ListSuccessResult.js +17 -0
- package/results/ListSuccessResult.js.map +1 -0
- package/results/index.d.ts +2 -0
- package/results/index.js +2 -0
- package/startKey.d.ts +2 -0
- package/startKey.js +8 -0
- package/startKey.js.map +1 -0
- package/types.d.ts +36 -0
- package/types.js +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IStorageListParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
2
|
+
import type { IAccessPatternHandler, IAccessPatternHandlerHandleResult } from "./abstractions/AccessPatternHandler.js";
|
|
3
|
+
import type { IAccessPattern } from "./abstractions/AccessPattern.js";
|
|
4
|
+
export interface IAccessPatternHandlerParams {
|
|
5
|
+
patterns: IAccessPattern<unknown>[];
|
|
6
|
+
}
|
|
7
|
+
export declare class AccessPatternHandler implements IAccessPatternHandler {
|
|
8
|
+
private readonly patterns;
|
|
9
|
+
constructor(params: IAccessPatternHandlerParams);
|
|
10
|
+
handle(params: IStorageListParams): Promise<IAccessPatternHandlerHandleResult>;
|
|
11
|
+
getDefaultPattern(): IAccessPattern<unknown>;
|
|
12
|
+
listIndexPatterns(): IAccessPattern<unknown>[];
|
|
13
|
+
private find;
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { WebinyError } from "@webiny/error";
|
|
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
|
+
}
|
|
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);
|
|
20
|
+
}
|
|
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
|
+
});
|
|
27
|
+
return pattern;
|
|
28
|
+
}
|
|
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
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export { AccessPatternHandler };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=AccessPatternHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccessPatternHandler.js","sources":["../src/AccessPatternHandler.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport type { IStorageListParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport type {\n IAccessPatternHandler,\n IAccessPatternHandlerHandleResult\n} from \"~/abstractions/AccessPatternHandler.js\";\nimport type { IAccessPattern } from \"~/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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Container } from "@webiny/feature/api";
|
|
2
|
+
export interface AuditLogsDdbFeatureConfig {
|
|
3
|
+
tableName?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const AuditLogsDdbFeature: {
|
|
6
|
+
name: string;
|
|
7
|
+
register(container: Container, context?: AuditLogsDdbFeatureConfig | undefined): void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { DynamoDBClient } from "@webiny/db-dynamodb";
|
|
3
|
+
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
4
|
+
import { CompressionFeature } from "@webiny/utils/features/compression/feature.js";
|
|
5
|
+
import { AuditLogsStorage } from "@webiny/api-audit-logs/abstractions.js";
|
|
6
|
+
import { createStorage } from "./Storage.js";
|
|
7
|
+
const AuditLogsDdbFeature = createFeature({
|
|
8
|
+
name: "AuditLogsDdb",
|
|
9
|
+
register (container, config = {}) {
|
|
10
|
+
CompressionFeature.register(container);
|
|
11
|
+
container.registerFactory(AuditLogsStorage, ()=>{
|
|
12
|
+
const db = container.resolve(DynamoDBClient);
|
|
13
|
+
const compressionHandler = container.resolve(CompressionHandler);
|
|
14
|
+
return createStorage({
|
|
15
|
+
client: db.client,
|
|
16
|
+
tableName: config.tableName ?? process.env.DB_TABLE,
|
|
17
|
+
compressionHandler
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export { AuditLogsDdbFeature };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=AuditLogsDdbFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuditLogsDdbFeature.js","sources":["../src/AuditLogsDdbFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { DynamoDBClient } from \"@webiny/db-dynamodb\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { CompressionFeature } from \"@webiny/utils/features/compression/feature.js\";\nimport { AuditLogsStorage } from \"@webiny/api-audit-logs/abstractions.js\";\nimport { createStorage } from \"./Storage.js\";\n\nexport interface AuditLogsDdbFeatureConfig {\n tableName?: string;\n}\n\nexport const AuditLogsDdbFeature = createFeature({\n name: \"AuditLogsDdb\",\n register(container: Container, config: AuditLogsDdbFeatureConfig = {}) {\n CompressionFeature.register(container);\n // Lazy factory: DynamoDBClient and CompressionHandler are resolved at first use\n container.registerFactory(AuditLogsStorage, () => {\n const db = container.resolve(DynamoDBClient);\n const compressionHandler = container.resolve(CompressionHandler);\n return createStorage({\n client: db.client,\n tableName: config.tableName ?? process.env.DB_TABLE,\n compressionHandler\n });\n });\n }\n});\n"],"names":["AuditLogsDdbFeature","createFeature","container","config","CompressionFeature","AuditLogsStorage","db","DynamoDBClient","compressionHandler","CompressionHandler","createStorage","process"],"mappings":";;;;;;AAWO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAoB,EAAEC,SAAoC,CAAC,CAAC;QACjEC,mBAAmB,QAAQ,CAACF;QAE5BA,UAAU,eAAe,CAACG,kBAAkB;YACxC,MAAMC,KAAKJ,UAAU,OAAO,CAACK;YAC7B,MAAMC,qBAAqBN,UAAU,OAAO,CAACO;YAC7C,OAAOC,cAAc;gBACjB,QAAQJ,GAAG,MAAM;gBACjB,WAAWH,OAAO,SAAS,IAAIQ,QAAQ,GAAG,CAAC,QAAQ;gBACnDH;YACJ;QACJ;IACJ;AACJ"}
|
package/Converter.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IConverter } from "./abstractions/Converter.js";
|
|
2
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
3
|
+
import type { IStorageItem } from "./types.js";
|
|
4
|
+
import type { IAccessPatternHandler } from "./abstractions/AccessPatternHandler.js";
|
|
5
|
+
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
6
|
+
export interface IConverterParams {
|
|
7
|
+
compressionHandler: CompressionHandler.Interface;
|
|
8
|
+
patternHandler: IAccessPatternHandler;
|
|
9
|
+
}
|
|
10
|
+
export declare class Converter implements IConverter {
|
|
11
|
+
private readonly compressionHandler;
|
|
12
|
+
private readonly patternHandler;
|
|
13
|
+
constructor(params: IConverterParams);
|
|
14
|
+
oneFromStorage(item: IStorageItem): Promise<IAuditLog>;
|
|
15
|
+
listFromStorage(items: IStorageItem[]): Promise<IAuditLog[]>;
|
|
16
|
+
oneToStorage(auditLog: IAuditLog): Promise<IStorageItem>;
|
|
17
|
+
}
|
package/Converter.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { convertExpiresAtToUnixTimestamp } from "@webiny/api-audit-logs/utils/expiresAt.js";
|
|
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
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export { Converter };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=Converter.js.map
|
package/Converter.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Converter.js","sources":["../src/Converter.ts"],"sourcesContent":["import type { IConverter } from \"~/abstractions/Converter.js\";\nimport type { IAuditLog } from \"@webiny/api-audit-logs/storage/types.js\";\nimport type { IStorageItem } from \"~/types.js\";\nimport type { IAccessPatternHandler } from \"~/abstractions/AccessPatternHandler.js\";\nimport { convertExpiresAtToUnixTimestamp } from \"@webiny/api-audit-logs/utils/expiresAt.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\nconst convertToDateTime = (value: string): Date => {\n return new Date(value);\n};\n\nexport interface IConverterParams {\n compressionHandler: CompressionHandler.Interface;\n patternHandler: IAccessPatternHandler;\n}\n\ntype PickOnlyGSIKeys<T> = {\n [K in keyof T]: K extends `GSI${string}` ? K : never;\n}[keyof T];\n\ntype PickedGSIKeys = Pick<IStorageItem, PickOnlyGSIKeys<IStorageItem>>;\n\nexport class Converter implements IConverter {\n private readonly compressionHandler;\n private readonly patternHandler;\n\n public constructor(params: IConverterParams) {\n this.compressionHandler = params.compressionHandler;\n this.patternHandler = params.patternHandler;\n }\n\n public async oneFromStorage(item: IStorageItem): Promise<IAuditLog> {\n return {\n ...item.data,\n expiresAt: convertToDateTime(item.data.expiresAt),\n content: await this.compressionHandler.decompress(JSON.parse(item.data.content)),\n createdOn: new Date(item.data.createdOn)\n };\n }\n\n public async listFromStorage(items: IStorageItem[]): Promise<IAuditLog[]> {\n return await Promise.all(\n items.map(async item => {\n return await this.oneFromStorage(item);\n })\n );\n }\n\n public async oneToStorage(auditLog: IAuditLog): Promise<IStorageItem> {\n const defaultPattern = this.patternHandler.getDefaultPattern();\n\n const defaultKeys = defaultPattern.createKeys(auditLog);\n\n const patterns = this.patternHandler.listIndexPatterns();\n\n const keys = patterns.reduce<PickedGSIKeys>((output, pattern) => {\n const patternKeys = pattern.createKeys(auditLog);\n return {\n ...output,\n [`${pattern.index}_PK`]: patternKeys.partitionKey,\n [`${pattern.index}_SK`]: patternKeys.sortKey\n };\n }, {} as PickedGSIKeys);\n\n return {\n PK: defaultKeys.partitionKey,\n SK: defaultKeys.sortKey as unknown as string,\n ...keys,\n TYPE: \"auditLog.log\",\n GSI_TENANT: auditLog.tenant,\n data: {\n ...auditLog,\n expiresAt: auditLog.expiresAt.toISOString(),\n content: JSON.stringify(await this.compressionHandler.compress(auditLog.content)),\n createdOn: auditLog.createdOn.toISOString()\n },\n expiresAt: convertExpiresAtToUnixTimestamp(auditLog.expiresAt)\n };\n }\n}\n"],"names":["convertToDateTime","value","Date","Converter","params","item","JSON","items","Promise","auditLog","defaultPattern","defaultKeys","patterns","keys","output","pattern","patternKeys","convertExpiresAtToUnixTimestamp"],"mappings":";AAOA,MAAMA,oBAAoB,CAACC,QAChB,IAAIC,KAAKD;AAcb,MAAME;IAIT,YAAmBC,MAAwB,CAAE;QACzC,IAAI,CAAC,kBAAkB,GAAGA,OAAO,kBAAkB;QACnD,IAAI,CAAC,cAAc,GAAGA,OAAO,cAAc;IAC/C;IAEA,MAAa,eAAeC,IAAkB,EAAsB;QAChE,OAAO;YACH,GAAGA,KAAK,IAAI;YACZ,WAAWL,kBAAkBK,KAAK,IAAI,CAAC,SAAS;YAChD,SAAS,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAACC,KAAK,KAAK,CAACD,KAAK,IAAI,CAAC,OAAO;YAC9E,WAAW,IAAIH,KAAKG,KAAK,IAAI,CAAC,SAAS;QAC3C;IACJ;IAEA,MAAa,gBAAgBE,KAAqB,EAAwB;QACtE,OAAO,MAAMC,QAAQ,GAAG,CACpBD,MAAM,GAAG,CAAC,OAAMF,OACL,MAAM,IAAI,CAAC,cAAc,CAACA;IAG7C;IAEA,MAAa,aAAaI,QAAmB,EAAyB;QAClE,MAAMC,iBAAiB,IAAI,CAAC,cAAc,CAAC,iBAAiB;QAE5D,MAAMC,cAAcD,eAAe,UAAU,CAACD;QAE9C,MAAMG,WAAW,IAAI,CAAC,cAAc,CAAC,iBAAiB;QAEtD,MAAMC,OAAOD,SAAS,MAAM,CAAgB,CAACE,QAAQC;YACjD,MAAMC,cAAcD,QAAQ,UAAU,CAACN;YACvC,OAAO;gBACH,GAAGK,MAAM;gBACT,CAAC,GAAGC,QAAQ,KAAK,CAAC,GAAG,CAAC,CAAC,EAAEC,YAAY,YAAY;gBACjD,CAAC,GAAGD,QAAQ,KAAK,CAAC,GAAG,CAAC,CAAC,EAAEC,YAAY,OAAO;YAChD;QACJ,GAAG,CAAC;QAEJ,OAAO;YACH,IAAIL,YAAY,YAAY;YAC5B,IAAIA,YAAY,OAAO;YACvB,GAAGE,IAAI;YACP,MAAM;YACN,YAAYJ,SAAS,MAAM;YAC3B,MAAM;gBACF,GAAGA,QAAQ;gBACX,WAAWA,SAAS,SAAS,CAAC,WAAW;gBACzC,SAASH,KAAK,SAAS,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAACG,SAAS,OAAO;gBAC/E,WAAWA,SAAS,SAAS,CAAC,WAAW;YAC7C;YACA,WAAWQ,gCAAgCR,SAAS,SAAS;QACjE;IACJ;AACJ"}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/api-audit-logs-ddb
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/Storage.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { IStorage, IStorageFetchParams, IStorageFetchResult, IStorageListParams, IStorageListResult, IStorageStoreParams, IStorageStoreResult } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
3
|
+
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
4
|
+
export interface IStorageParams {
|
|
5
|
+
compressionHandler: CompressionHandler.Interface;
|
|
6
|
+
client: DynamoDBDocument;
|
|
7
|
+
tableName: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare class Storage implements IStorage {
|
|
10
|
+
private readonly entity;
|
|
11
|
+
private readonly converter;
|
|
12
|
+
private readonly patternHandler;
|
|
13
|
+
constructor(params: IStorageParams);
|
|
14
|
+
fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;
|
|
15
|
+
store(params: IStorageStoreParams): Promise<IStorageStoreResult>;
|
|
16
|
+
list(params: IStorageListParams): Promise<IStorageListResult>;
|
|
17
|
+
}
|
|
18
|
+
export declare const createStorage: (params: IStorageParams) => IStorage;
|
package/Storage.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createEntity } from "./entity.js";
|
|
2
|
+
import { Converter } from "./Converter.js";
|
|
3
|
+
import { createAccessPatterns } from "./accessPatterns/index.js";
|
|
4
|
+
import { AccessPatternHandler } from "./AccessPatternHandler.js";
|
|
5
|
+
import { ListSuccessResult } from "./results/index.js";
|
|
6
|
+
class Storage {
|
|
7
|
+
constructor(params){
|
|
8
|
+
const { entity } = createEntity({
|
|
9
|
+
client: params.client,
|
|
10
|
+
tableName: params.tableName,
|
|
11
|
+
gsiAmount: 10
|
|
12
|
+
});
|
|
13
|
+
this.entity = entity;
|
|
14
|
+
const patterns = createAccessPatterns({
|
|
15
|
+
entity
|
|
16
|
+
});
|
|
17
|
+
this.patternHandler = new AccessPatternHandler({
|
|
18
|
+
patterns
|
|
19
|
+
});
|
|
20
|
+
this.converter = new Converter({
|
|
21
|
+
compressionHandler: params.compressionHandler,
|
|
22
|
+
patternHandler: this.patternHandler
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async fetch(params) {
|
|
26
|
+
const { id, tenant } = params;
|
|
27
|
+
try {
|
|
28
|
+
const result = await this.entity.get({
|
|
29
|
+
PK: `T#${tenant}#AUDIT_LOG`,
|
|
30
|
+
SK: `${id}`
|
|
31
|
+
});
|
|
32
|
+
if (!result) return {
|
|
33
|
+
error: new Error(`Audit log entry "${id}" not found.`),
|
|
34
|
+
success: false
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
data: await this.converter.oneFromStorage(result),
|
|
38
|
+
success: true
|
|
39
|
+
};
|
|
40
|
+
} catch (ex) {
|
|
41
|
+
return {
|
|
42
|
+
error: ex,
|
|
43
|
+
success: false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async store(params) {
|
|
48
|
+
const auditLog = structuredClone(params.data);
|
|
49
|
+
try {
|
|
50
|
+
const item = await this.converter.oneToStorage(auditLog);
|
|
51
|
+
await this.entity.put(item);
|
|
52
|
+
} catch (ex) {
|
|
53
|
+
return {
|
|
54
|
+
error: ex,
|
|
55
|
+
success: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
success: true,
|
|
60
|
+
data: auditLog
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async list(params) {
|
|
64
|
+
try {
|
|
65
|
+
const result = await this.patternHandler.handle(params);
|
|
66
|
+
return ListSuccessResult.create({
|
|
67
|
+
data: await this.converter.listFromStorage(result.items),
|
|
68
|
+
lastEvaluatedKey: result.lastEvaluatedKey
|
|
69
|
+
});
|
|
70
|
+
} catch (ex) {
|
|
71
|
+
return {
|
|
72
|
+
error: ex,
|
|
73
|
+
success: false
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const createStorage = (params)=>new Storage(params);
|
|
79
|
+
export { Storage, createStorage };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=Storage.js.map
|
package/Storage.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.js","sources":["../src/Storage.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createEntity } from \"~/entity.js\";\nimport type {\n IStorage,\n IStorageFetchParams,\n IStorageFetchResult,\n IStorageListParams,\n IStorageListResult,\n IStorageStoreParams,\n IStorageStoreResult\n} from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport { Converter } from \"~/Converter.js\";\nimport { createAccessPatterns } from \"~/accessPatterns/index.js\";\nimport { AccessPatternHandler } from \"~/AccessPatternHandler.js\";\nimport { ListSuccessResult } from \"~/results/index.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\nexport interface IStorageParams {\n compressionHandler: CompressionHandler.Interface;\n client: DynamoDBDocument;\n tableName: string | undefined;\n}\n\nexport class Storage implements IStorage {\n private readonly entity;\n private readonly converter;\n private readonly patternHandler;\n\n public constructor(params: IStorageParams) {\n const { entity } = createEntity({\n client: params.client,\n tableName: params.tableName,\n gsiAmount: 10\n });\n\n this.entity = entity;\n\n const patterns = createAccessPatterns({\n entity\n });\n this.patternHandler = new AccessPatternHandler({\n patterns\n });\n\n this.converter = new Converter({\n compressionHandler: params.compressionHandler,\n patternHandler: this.patternHandler\n });\n }\n\n public async fetch(params: IStorageFetchParams): Promise<IStorageFetchResult> {\n const { id, tenant } = params;\n\n try {\n const result = await this.entity.get({\n PK: `T#${tenant}#AUDIT_LOG`,\n SK: `${id}`\n });\n if (!result) {\n return {\n error: new Error(`Audit log entry \"${id}\" not found.`),\n success: false\n };\n }\n return {\n data: await this.converter.oneFromStorage(result),\n success: true\n };\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n }\n\n public async store(params: IStorageStoreParams): Promise<IStorageStoreResult> {\n const auditLog = structuredClone(params.data);\n\n try {\n const item = await this.converter.oneToStorage(auditLog);\n await this.entity.put(item);\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n\n return {\n success: true,\n data: auditLog\n };\n }\n\n public async list(params: IStorageListParams): Promise<IStorageListResult> {\n try {\n const result = await this.patternHandler.handle(params);\n\n return ListSuccessResult.create({\n data: await this.converter.listFromStorage(result.items),\n lastEvaluatedKey: result.lastEvaluatedKey\n });\n } catch (ex) {\n return {\n error: ex,\n success: false\n };\n }\n }\n}\n\nexport const createStorage = (params: IStorageParams): IStorage => {\n return new Storage(params);\n};\n"],"names":["Storage","params","entity","createEntity","patterns","createAccessPatterns","AccessPatternHandler","Converter","id","tenant","result","Error","ex","auditLog","structuredClone","item","ListSuccessResult","createStorage"],"mappings":";;;;;AAuBO,MAAMA;IAKT,YAAmBC,MAAsB,CAAE;QACvC,MAAM,EAAEC,MAAM,EAAE,GAAGC,aAAa;YAC5B,QAAQF,OAAO,MAAM;YACrB,WAAWA,OAAO,SAAS;YAC3B,WAAW;QACf;QAEA,IAAI,CAAC,MAAM,GAAGC;QAEd,MAAME,WAAWC,qBAAqB;YAClCH;QACJ;QACA,IAAI,CAAC,cAAc,GAAG,IAAII,qBAAqB;YAC3CF;QACJ;QAEA,IAAI,CAAC,SAAS,GAAG,IAAIG,UAAU;YAC3B,oBAAoBN,OAAO,kBAAkB;YAC7C,gBAAgB,IAAI,CAAC,cAAc;QACvC;IACJ;IAEA,MAAa,MAAMA,MAA2B,EAAgC;QAC1E,MAAM,EAAEO,EAAE,EAAEC,MAAM,EAAE,GAAGR;QAEvB,IAAI;YACA,MAAMS,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;gBACjC,IAAI,CAAC,EAAE,EAAED,OAAO,UAAU,CAAC;gBAC3B,IAAI,GAAGD,IAAI;YACf;YACA,IAAI,CAACE,QACD,OAAO;gBACH,OAAO,IAAIC,MAAM,CAAC,iBAAiB,EAAEH,GAAG,YAAY,CAAC;gBACrD,SAAS;YACb;YAEJ,OAAO;gBACH,MAAM,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CAACE;gBAC1C,SAAS;YACb;QACJ,EAAE,OAAOE,IAAI;YACT,OAAO;gBACH,OAAOA;gBACP,SAAS;YACb;QACJ;IACJ;IAEA,MAAa,MAAMX,MAA2B,EAAgC;QAC1E,MAAMY,WAAWC,gBAAgBb,OAAO,IAAI;QAE5C,IAAI;YACA,MAAMc,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAACF;YAC/C,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAACE;QAC1B,EAAE,OAAOH,IAAI;YACT,OAAO;gBACH,OAAOA;gBACP,SAAS;YACb;QACJ;QAEA,OAAO;YACH,SAAS;YACT,MAAMC;QACV;IACJ;IAEA,MAAa,KAAKZ,MAA0B,EAA+B;QACvE,IAAI;YACA,MAAMS,SAAS,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAACT;YAEhD,OAAOe,kBAAkB,MAAM,CAAC;gBAC5B,MAAM,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAACN,OAAO,KAAK;gBACvD,kBAAkBA,OAAO,gBAAgB;YAC7C;QACJ,EAAE,OAAOE,IAAI;YACT,OAAO;gBACH,OAAOA;gBACP,SAAS;YACb;QACJ;IACJ;AACJ;AAEO,MAAMK,gBAAgB,CAAChB,SACnB,IAAID,QAAQC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
2
|
+
import type { IStorageItem } from "../types.js";
|
|
3
|
+
import type { IStorageListParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
4
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
5
|
+
export interface IAccessPatternCreateKeysResult {
|
|
6
|
+
partitionKey: string;
|
|
7
|
+
sortKey: string | number;
|
|
8
|
+
}
|
|
9
|
+
export interface IAccessPatternListResult {
|
|
10
|
+
items: IStorageItem[];
|
|
11
|
+
lastEvaluatedKey?: GenericRecord;
|
|
12
|
+
}
|
|
13
|
+
export type IAccessPatternHandlesKeys = keyof IStorageListParams;
|
|
14
|
+
export interface IAccessPatternHandles {
|
|
15
|
+
shouldInclude?: IAccessPatternHandlesKeys[];
|
|
16
|
+
mustInclude: IAccessPatternHandlesKeys[];
|
|
17
|
+
mustNotInclude: IAccessPatternHandlesKeys[];
|
|
18
|
+
}
|
|
19
|
+
export interface IAccessPattern<T> {
|
|
20
|
+
index: string | undefined;
|
|
21
|
+
handles(): IAccessPatternHandles;
|
|
22
|
+
canHandle(params: IStorageListParams): boolean;
|
|
23
|
+
list(params: T): Promise<IAccessPatternListResult>;
|
|
24
|
+
createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;
|
|
25
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
|
+
import type { IStorageItem } from "../types.js";
|
|
3
|
+
import type { IAccessPattern } from "../abstractions/AccessPattern.js";
|
|
4
|
+
import type { IStorageListParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
5
|
+
export interface IAccessPatternHandlerHandleResult {
|
|
6
|
+
items: IStorageItem[];
|
|
7
|
+
lastEvaluatedKey?: GenericRecord;
|
|
8
|
+
}
|
|
9
|
+
export interface IAccessPatternHandler {
|
|
10
|
+
handle(params: IStorageListParams): Promise<IAccessPatternHandlerHandleResult>;
|
|
11
|
+
getDefaultPattern(): IAccessPattern<unknown>;
|
|
12
|
+
listIndexPatterns(): IAccessPattern<unknown>[];
|
|
13
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
2
|
+
import type { IStorageItem } from "../types.js";
|
|
3
|
+
export interface IConverter {
|
|
4
|
+
oneFromStorage(item: IStorageItem): Promise<IAuditLog>;
|
|
5
|
+
listFromStorage(items: IStorageItem[]): Promise<IAuditLog[]>;
|
|
6
|
+
oneToStorage(auditLog: IAuditLog): Promise<IStorageItem>;
|
|
7
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
2
|
+
import type { IStorageListByAppParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
3
|
+
import { BaseAccessPattern } from "../accessPatterns/BaseAccessPattern.js";
|
|
4
|
+
import type { IAccessPatternCreateKeysResult, IAccessPatternHandles, IAccessPatternListResult } from "../abstractions/AccessPattern.js";
|
|
5
|
+
export declare class AppAccessPattern<T extends IStorageListByAppParams = IStorageListByAppParams> extends BaseAccessPattern<T> {
|
|
6
|
+
handles(): IAccessPatternHandles;
|
|
7
|
+
list(params: T): Promise<IAccessPatternListResult>;
|
|
8
|
+
createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseAccessPattern } from "./BaseAccessPattern.js";
|
|
2
|
+
const createPartitionKey = (params)=>`T#${params.tenant}#AUDIT_LOG#APP#${params.app}`;
|
|
3
|
+
class AppAccessPattern extends BaseAccessPattern {
|
|
4
|
+
handles() {
|
|
5
|
+
return {
|
|
6
|
+
mustInclude: [
|
|
7
|
+
"app"
|
|
8
|
+
],
|
|
9
|
+
mustNotInclude: [
|
|
10
|
+
"createdBy",
|
|
11
|
+
"action",
|
|
12
|
+
"entityId",
|
|
13
|
+
"entity"
|
|
14
|
+
]
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async list(params) {
|
|
18
|
+
const options = this.createOptions(params);
|
|
19
|
+
const result = await this.query({
|
|
20
|
+
partitionKey: createPartitionKey(params),
|
|
21
|
+
options
|
|
22
|
+
});
|
|
23
|
+
return this.populateResult(result);
|
|
24
|
+
}
|
|
25
|
+
createKeys(item) {
|
|
26
|
+
const time = item.createdOn.getTime();
|
|
27
|
+
return {
|
|
28
|
+
partitionKey: createPartitionKey(item),
|
|
29
|
+
sortKey: time
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export { AppAccessPattern };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=AppAccessPattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessPatterns/AppAccessPattern.js","sources":["../../src/accessPatterns/AppAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"@webiny/api-audit-logs/storage/types.js\";\nimport type { IStorageListByAppParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport { BaseAccessPattern } from \"~/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/abstractions/AccessPattern.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}`;\n};\n\nexport class AppAccessPattern<\n T extends IStorageListByAppParams = IStorageListByAppParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\"],\n mustNotInclude: [\"createdBy\", \"action\", \"entityId\", \"entity\"]\n };\n }\n\n public async list(params: T): Promise<IAccessPatternListResult> {\n const options = this.createOptions(params);\n\n const result = await this.query({\n partitionKey: createPartitionKey(params),\n options\n });\n return this.populateResult(result);\n }\n\n public createKeys(item: IAuditLog): IAccessPatternCreateKeysResult {\n const time = item.createdOn.getTime();\n return {\n partitionKey: createPartitionKey(item),\n sortKey: time\n };\n }\n}\n"],"names":["createPartitionKey","params","AppAccessPattern","BaseAccessPattern","options","result","item","time"],"mappings":";AAcA,MAAMA,qBAAqB,CAACC,SACjB,CAAC,EAAE,EAAEA,OAAO,MAAM,CAAC,eAAe,EAAEA,OAAO,GAAG,EAAE;AAGpD,MAAMC,yBAEHC;IACU,UAAiC;QAC7C,OAAO;YACH,aAAa;gBAAC;aAAM;YACpB,gBAAgB;gBAAC;gBAAa;gBAAU;gBAAY;aAAS;QACjE;IACJ;IAEA,MAAa,KAAKF,MAAS,EAAqC;QAC5D,MAAMG,UAAU,IAAI,CAAC,aAAa,CAACH;QAEnC,MAAMI,SAAS,MAAM,IAAI,CAAC,KAAK,CAAC;YAC5B,cAAcL,mBAAmBC;YACjCG;QACJ;QACA,OAAO,IAAI,CAAC,cAAc,CAACC;IAC/B;IAEO,WAAWC,IAAe,EAAkC;QAC/D,MAAMC,OAAOD,KAAK,SAAS,CAAC,OAAO;QACnC,OAAO;YACH,cAAcN,mBAAmBM;YACjC,SAASC;QACb;IACJ;AACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
2
|
+
import { BaseAccessPattern } from "../accessPatterns/BaseAccessPattern.js";
|
|
3
|
+
import type { IAccessPatternCreateKeysResult, IAccessPatternHandles, IAccessPatternListResult } from "../abstractions/AccessPattern.js";
|
|
4
|
+
import type { IStorageListByAppCreatedByParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
5
|
+
export declare class AppCreatedByAccessPattern<T extends IStorageListByAppCreatedByParams = IStorageListByAppCreatedByParams> extends BaseAccessPattern<T> {
|
|
6
|
+
handles(): IAccessPatternHandles;
|
|
7
|
+
list(params: T): Promise<IAccessPatternListResult>;
|
|
8
|
+
createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseAccessPattern } from "./BaseAccessPattern.js";
|
|
2
|
+
const createPartitionKey = (params)=>`T#${params.tenant}#AUDIT_LOG#APP#${params.app}#CREATEDBY#${params.createdBy}`;
|
|
3
|
+
class AppCreatedByAccessPattern extends BaseAccessPattern {
|
|
4
|
+
handles() {
|
|
5
|
+
return {
|
|
6
|
+
mustInclude: [
|
|
7
|
+
"app",
|
|
8
|
+
"createdBy"
|
|
9
|
+
],
|
|
10
|
+
mustNotInclude: [
|
|
11
|
+
"action",
|
|
12
|
+
"entityId",
|
|
13
|
+
"entity"
|
|
14
|
+
]
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async list(params) {
|
|
18
|
+
const options = this.createOptions(params);
|
|
19
|
+
const result = await this.query({
|
|
20
|
+
partitionKey: createPartitionKey(params),
|
|
21
|
+
options
|
|
22
|
+
});
|
|
23
|
+
return this.populateResult(result);
|
|
24
|
+
}
|
|
25
|
+
createKeys(item) {
|
|
26
|
+
const time = item.createdOn.getTime();
|
|
27
|
+
return {
|
|
28
|
+
partitionKey: createPartitionKey({
|
|
29
|
+
...item,
|
|
30
|
+
createdBy: item.createdBy.id
|
|
31
|
+
}),
|
|
32
|
+
sortKey: time
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export { AppCreatedByAccessPattern };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=AppCreatedByAccessPattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessPatterns/AppCreatedByAccessPattern.js","sources":["../../src/accessPatterns/AppCreatedByAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"@webiny/api-audit-logs/storage/types.js\";\nimport { BaseAccessPattern } from \"~/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/abstractions/AccessPattern.js\";\nimport type { IStorageListByAppCreatedByParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n createdBy: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}#CREATEDBY#${params.createdBy}`;\n};\n\nexport class AppCreatedByAccessPattern<\n T extends IStorageListByAppCreatedByParams = IStorageListByAppCreatedByParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\", \"createdBy\"],\n mustNotInclude: [\"action\", \"entityId\", \"entity\"]\n };\n }\n\n public async list(params: T): Promise<IAccessPatternListResult> {\n const options = this.createOptions(params);\n\n const result = await this.query({\n partitionKey: createPartitionKey(params),\n options\n });\n return this.populateResult(result);\n }\n\n public createKeys(item: IAuditLog): IAccessPatternCreateKeysResult {\n const time = item.createdOn.getTime();\n\n return {\n partitionKey: createPartitionKey({\n ...item,\n createdBy: item.createdBy.id\n }),\n sortKey: time\n };\n }\n}\n"],"names":["createPartitionKey","params","AppCreatedByAccessPattern","BaseAccessPattern","options","result","item","time"],"mappings":";AAeA,MAAMA,qBAAqB,CAACC,SACjB,CAAC,EAAE,EAAEA,OAAO,MAAM,CAAC,eAAe,EAAEA,OAAO,GAAG,CAAC,WAAW,EAAEA,OAAO,SAAS,EAAE;AAGlF,MAAMC,kCAEHC;IACU,UAAiC;QAC7C,OAAO;YACH,aAAa;gBAAC;gBAAO;aAAY;YACjC,gBAAgB;gBAAC;gBAAU;gBAAY;aAAS;QACpD;IACJ;IAEA,MAAa,KAAKF,MAAS,EAAqC;QAC5D,MAAMG,UAAU,IAAI,CAAC,aAAa,CAACH;QAEnC,MAAMI,SAAS,MAAM,IAAI,CAAC,KAAK,CAAC;YAC5B,cAAcL,mBAAmBC;YACjCG;QACJ;QACA,OAAO,IAAI,CAAC,cAAc,CAACC;IAC/B;IAEO,WAAWC,IAAe,EAAkC;QAC/D,MAAMC,OAAOD,KAAK,SAAS,CAAC,OAAO;QAEnC,OAAO;YACH,cAAcN,mBAAmB;gBAC7B,GAAGM,IAAI;gBACP,WAAWA,KAAK,SAAS,CAAC,EAAE;YAChC;YACA,SAASC;QACb;IACJ;AACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
2
|
+
import type { IStorageListByAppEntityParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
3
|
+
import { BaseAccessPattern } from "../accessPatterns/BaseAccessPattern.js";
|
|
4
|
+
import type { IAccessPatternCreateKeysResult, IAccessPatternHandles, IAccessPatternListResult } from "../abstractions/AccessPattern.js";
|
|
5
|
+
export declare class AppEntityAccessPattern<T extends IStorageListByAppEntityParams = IStorageListByAppEntityParams> extends BaseAccessPattern<T> {
|
|
6
|
+
handles(): IAccessPatternHandles;
|
|
7
|
+
list(params: T): Promise<IAccessPatternListResult>;
|
|
8
|
+
createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseAccessPattern } from "./BaseAccessPattern.js";
|
|
2
|
+
const createPartitionKey = (params)=>`T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}`;
|
|
3
|
+
class AppEntityAccessPattern extends BaseAccessPattern {
|
|
4
|
+
handles() {
|
|
5
|
+
return {
|
|
6
|
+
mustInclude: [
|
|
7
|
+
"app",
|
|
8
|
+
"entity"
|
|
9
|
+
],
|
|
10
|
+
mustNotInclude: [
|
|
11
|
+
"createdBy",
|
|
12
|
+
"action",
|
|
13
|
+
"entityId"
|
|
14
|
+
]
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async list(params) {
|
|
18
|
+
const options = this.createOptions(params);
|
|
19
|
+
const result = await this.query({
|
|
20
|
+
partitionKey: createPartitionKey(params),
|
|
21
|
+
options
|
|
22
|
+
});
|
|
23
|
+
return this.populateResult(result);
|
|
24
|
+
}
|
|
25
|
+
createKeys(item) {
|
|
26
|
+
const time = item.createdOn.getTime();
|
|
27
|
+
return {
|
|
28
|
+
partitionKey: createPartitionKey(item),
|
|
29
|
+
sortKey: time
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export { AppEntityAccessPattern };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=AppEntityAccessPattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessPatterns/AppEntityAccessPattern.js","sources":["../../src/accessPatterns/AppEntityAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"@webiny/api-audit-logs/storage/types.js\";\nimport type { IStorageListByAppEntityParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport { BaseAccessPattern } from \"~/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/abstractions/AccessPattern.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n entity: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}`;\n};\nexport class AppEntityAccessPattern<\n T extends IStorageListByAppEntityParams = IStorageListByAppEntityParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\", \"entity\"],\n mustNotInclude: [\"createdBy\", \"action\", \"entityId\"]\n };\n }\n\n public async list(params: T): Promise<IAccessPatternListResult> {\n const options = this.createOptions(params);\n\n const result = await this.query({\n partitionKey: createPartitionKey(params),\n options\n });\n return this.populateResult(result);\n }\n\n public createKeys(item: IAuditLog): IAccessPatternCreateKeysResult {\n const time = item.createdOn.getTime();\n\n return {\n partitionKey: createPartitionKey(item),\n sortKey: time\n };\n }\n}\n"],"names":["createPartitionKey","params","AppEntityAccessPattern","BaseAccessPattern","options","result","item","time"],"mappings":";AAeA,MAAMA,qBAAqB,CAACC,SACjB,CAAC,EAAE,EAAEA,OAAO,MAAM,CAAC,eAAe,EAAEA,OAAO,GAAG,CAAC,QAAQ,EAAEA,OAAO,MAAM,EAAE;AAE5E,MAAMC,+BAEHC;IACU,UAAiC;QAC7C,OAAO;YACH,aAAa;gBAAC;gBAAO;aAAS;YAC9B,gBAAgB;gBAAC;gBAAa;gBAAU;aAAW;QACvD;IACJ;IAEA,MAAa,KAAKF,MAAS,EAAqC;QAC5D,MAAMG,UAAU,IAAI,CAAC,aAAa,CAACH;QAEnC,MAAMI,SAAS,MAAM,IAAI,CAAC,KAAK,CAAC;YAC5B,cAAcL,mBAAmBC;YACjCG;QACJ;QACA,OAAO,IAAI,CAAC,cAAc,CAACC;IAC/B;IAEO,WAAWC,IAAe,EAAkC;QAC/D,MAAMC,OAAOD,KAAK,SAAS,CAAC,OAAO;QAEnC,OAAO;YACH,cAAcN,mBAAmBM;YACjC,SAASC;QACb;IACJ;AACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
2
|
+
import type { IStorageListByAppEntityActionParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
3
|
+
import { BaseAccessPattern } from "../accessPatterns/BaseAccessPattern.js";
|
|
4
|
+
import type { IAccessPatternCreateKeysResult, IAccessPatternHandles, IAccessPatternListResult } from "../abstractions/AccessPattern.js";
|
|
5
|
+
export declare class AppEntityActionAccessPattern<T extends IStorageListByAppEntityActionParams = IStorageListByAppEntityActionParams> extends BaseAccessPattern<T> {
|
|
6
|
+
handles(): IAccessPatternHandles;
|
|
7
|
+
list(params: T): Promise<IAccessPatternListResult>;
|
|
8
|
+
createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseAccessPattern } from "./BaseAccessPattern.js";
|
|
2
|
+
const createPartitionKey = (params)=>`T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}#ACTION#${params.action}`;
|
|
3
|
+
class AppEntityActionAccessPattern extends BaseAccessPattern {
|
|
4
|
+
handles() {
|
|
5
|
+
return {
|
|
6
|
+
mustInclude: [
|
|
7
|
+
"app",
|
|
8
|
+
"entity",
|
|
9
|
+
"action"
|
|
10
|
+
],
|
|
11
|
+
mustNotInclude: [
|
|
12
|
+
"entityId",
|
|
13
|
+
"createdBy"
|
|
14
|
+
]
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async list(params) {
|
|
18
|
+
const options = this.createOptions(params);
|
|
19
|
+
const result = await this.query({
|
|
20
|
+
partitionKey: createPartitionKey(params),
|
|
21
|
+
options
|
|
22
|
+
});
|
|
23
|
+
return this.populateResult(result);
|
|
24
|
+
}
|
|
25
|
+
createKeys(item) {
|
|
26
|
+
const time = item.createdOn.getTime();
|
|
27
|
+
return {
|
|
28
|
+
partitionKey: createPartitionKey(item),
|
|
29
|
+
sortKey: time
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export { AppEntityActionAccessPattern };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=AppEntityActionAccessPattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessPatterns/AppEntityActionAccessPattern.js","sources":["../../src/accessPatterns/AppEntityActionAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"@webiny/api-audit-logs/storage/types.js\";\nimport type { IStorageListByAppEntityActionParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport { BaseAccessPattern } from \"~/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/abstractions/AccessPattern.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n entity: string;\n action: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}#ACTION#${params.action}`;\n};\n\nexport class AppEntityActionAccessPattern<\n T extends IStorageListByAppEntityActionParams = IStorageListByAppEntityActionParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\", \"entity\", \"action\"],\n mustNotInclude: [\"entityId\", \"createdBy\"]\n };\n }\n\n public async list(params: T): Promise<IAccessPatternListResult> {\n const options = this.createOptions(params);\n\n const result = await this.query({\n partitionKey: createPartitionKey(params),\n options\n });\n return this.populateResult(result);\n }\n\n public createKeys(item: IAuditLog): IAccessPatternCreateKeysResult {\n const time = item.createdOn.getTime();\n\n return {\n partitionKey: createPartitionKey(item),\n sortKey: time\n };\n }\n}\n"],"names":["createPartitionKey","params","AppEntityActionAccessPattern","BaseAccessPattern","options","result","item","time"],"mappings":";AAgBA,MAAMA,qBAAqB,CAACC,SACjB,CAAC,EAAE,EAAEA,OAAO,MAAM,CAAC,eAAe,EAAEA,OAAO,GAAG,CAAC,QAAQ,EAAEA,OAAO,MAAM,CAAC,QAAQ,EAAEA,OAAO,MAAM,EAAE;AAGpG,MAAMC,qCAEHC;IACU,UAAiC;QAC7C,OAAO;YACH,aAAa;gBAAC;gBAAO;gBAAU;aAAS;YACxC,gBAAgB;gBAAC;gBAAY;aAAY;QAC7C;IACJ;IAEA,MAAa,KAAKF,MAAS,EAAqC;QAC5D,MAAMG,UAAU,IAAI,CAAC,aAAa,CAACH;QAEnC,MAAMI,SAAS,MAAM,IAAI,CAAC,KAAK,CAAC;YAC5B,cAAcL,mBAAmBC;YACjCG;QACJ;QACA,OAAO,IAAI,CAAC,cAAc,CAACC;IAC/B;IAEO,WAAWC,IAAe,EAAkC;QAC/D,MAAMC,OAAOD,KAAK,SAAS,CAAC,OAAO;QAEnC,OAAO;YACH,cAAcN,mBAAmBM;YACjC,SAASC;QACb;IACJ;AACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAuditLog } from "@webiny/api-audit-logs/storage/types.js";
|
|
2
|
+
import type { IStorageListByAppEntityActionCreatedByParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
3
|
+
import { BaseAccessPattern } from "../accessPatterns/BaseAccessPattern.js";
|
|
4
|
+
import type { IAccessPatternCreateKeysResult, IAccessPatternHandles, IAccessPatternListResult } from "../abstractions/AccessPattern.js";
|
|
5
|
+
export declare class AppEntityActionCreatedByAccessPattern<T extends IStorageListByAppEntityActionCreatedByParams = IStorageListByAppEntityActionCreatedByParams> extends BaseAccessPattern<T> {
|
|
6
|
+
handles(): IAccessPatternHandles;
|
|
7
|
+
list(params: T): Promise<IAccessPatternListResult>;
|
|
8
|
+
createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;
|
|
9
|
+
}
|