@webiny/api-audit-logs-ddb 6.6.0-alpha.0 → 6.6.0-alpha.2
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.
|
@@ -48,10 +48,14 @@ class BaseAccessPattern {
|
|
|
48
48
|
reverse: "DESC" === params.sort,
|
|
49
49
|
index: this.index
|
|
50
50
|
};
|
|
51
|
-
if (params.createdOn_lte || params.createdOn_gte)
|
|
52
|
-
toGteTime(params.createdOn_gte)
|
|
53
|
-
toLteTime(params.createdOn_lte)
|
|
54
|
-
|
|
51
|
+
if (params.createdOn_lte || params.createdOn_gte) {
|
|
52
|
+
const lower = toGteTime(params.createdOn_gte);
|
|
53
|
+
const upper = toLteTime(params.createdOn_lte);
|
|
54
|
+
options.between = [
|
|
55
|
+
lower,
|
|
56
|
+
Math.max(lower, upper)
|
|
57
|
+
];
|
|
58
|
+
}
|
|
55
59
|
return options;
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessPatterns/BaseAccessPattern.js","sources":["../../src/accessPatterns/BaseAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"@webiny/api-audit-logs/storage/types.js\";\nimport type { IIndexStorageItem, IStorageItem } from \"~/types.js\";\nimport { createStartKey } from \"~/startKey.js\";\nimport type { IStorageListParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport type {\n IAccessPattern,\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/abstractions/AccessPattern.js\";\nimport type { AuditLogsEntity } from \"~/entity.js\";\nimport type { IEntityQueryAllParams, IEntityQueryPerPageResult } from \"@webiny/db-dynamodb\";\n\nconst toGteTime = (date?: Date): number => {\n if (!date) {\n return 0;\n }\n return date.getTime();\n};\nconst toLteTime = (date?: Date): number => {\n if (!date) {\n return Date.now();\n }\n return date.getTime();\n};\n\nexport interface ICreateOptionsParams {\n limit?: number;\n sort?: \"ASC\" | \"DESC\";\n after?: string;\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n}\n\nexport interface IBaseAccessPatternParams {\n index: string | undefined;\n entity: AuditLogsEntity;\n}\n\nexport interface IAccessPatternQueryParams {\n partitionKey: string;\n options: IEntityQueryAllParams[\"options\"];\n}\n\nexport abstract class BaseAccessPattern<T> implements IAccessPattern<T> {\n public readonly index;\n protected readonly entity;\n\n public constructor(params: IBaseAccessPatternParams) {\n this.index = params.index;\n this.entity = params.entity;\n }\n\n public abstract handles(): IAccessPatternHandles;\n\n public canHandle(params: IStorageListParams): boolean {\n const handles = this.handles();\n for (const key of handles.mustInclude) {\n if (!params[key]) {\n return false;\n }\n }\n for (const key of handles.mustNotInclude) {\n if (!!params[key]) {\n return false;\n }\n }\n if (!handles.shouldInclude?.length) {\n return true;\n }\n\n for (const key of handles.shouldInclude) {\n if (!!params[key]) {\n return true;\n }\n }\n return false;\n }\n\n protected async query<T extends IStorageItem = IStorageItem>(\n params: IAccessPatternQueryParams\n ) {\n return this.entity.queryPerPage<T>({\n partitionKey: params.partitionKey,\n options: params.options\n });\n }\n\n protected async populateResult(\n input: Awaited<IEntityQueryPerPageResult<IIndexStorageItem>>\n ): Promise<IEntityQueryPerPageResult<IStorageItem>> {\n const reader = this.entity.createEntityReader({\n read: input.items.map(item => {\n return {\n PK: item.PK,\n SK: item.SK\n };\n })\n });\n const result = await reader.execute();\n\n return {\n ...input,\n items: input.items\n .map(item => {\n return result.find(i => {\n return i.PK === item.PK && i.SK === item.SK;\n });\n })\n .filter((item): item is IStorageItem => !!item)\n };\n }\n\n public abstract list(params: T): Promise<IAccessPatternListResult>;\n public abstract createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;\n\n protected createOptions(params: ICreateOptionsParams): IEntityQueryAllParams[\"options\"] {\n const options: IEntityQueryAllParams[\"options\"] = {\n limit: params.limit || 25,\n
|
|
1
|
+
{"version":3,"file":"accessPatterns/BaseAccessPattern.js","sources":["../../src/accessPatterns/BaseAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"@webiny/api-audit-logs/storage/types.js\";\nimport type { IIndexStorageItem, IStorageItem } from \"~/types.js\";\nimport { createStartKey } from \"~/startKey.js\";\nimport type { IStorageListParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport type {\n IAccessPattern,\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/abstractions/AccessPattern.js\";\nimport type { AuditLogsEntity } from \"~/entity.js\";\nimport type { IEntityQueryAllParams, IEntityQueryPerPageResult } from \"@webiny/db-dynamodb\";\n\nconst toGteTime = (date?: Date): number => {\n if (!date) {\n return 0;\n }\n return date.getTime();\n};\nconst toLteTime = (date?: Date): number => {\n if (!date) {\n return Date.now();\n }\n return date.getTime();\n};\n\nexport interface ICreateOptionsParams {\n limit?: number;\n sort?: \"ASC\" | \"DESC\";\n after?: string;\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n}\n\nexport interface IBaseAccessPatternParams {\n index: string | undefined;\n entity: AuditLogsEntity;\n}\n\nexport interface IAccessPatternQueryParams {\n partitionKey: string;\n options: IEntityQueryAllParams[\"options\"];\n}\n\nexport abstract class BaseAccessPattern<T> implements IAccessPattern<T> {\n public readonly index;\n protected readonly entity;\n\n public constructor(params: IBaseAccessPatternParams) {\n this.index = params.index;\n this.entity = params.entity;\n }\n\n public abstract handles(): IAccessPatternHandles;\n\n public canHandle(params: IStorageListParams): boolean {\n const handles = this.handles();\n for (const key of handles.mustInclude) {\n if (!params[key]) {\n return false;\n }\n }\n for (const key of handles.mustNotInclude) {\n if (!!params[key]) {\n return false;\n }\n }\n if (!handles.shouldInclude?.length) {\n return true;\n }\n\n for (const key of handles.shouldInclude) {\n if (!!params[key]) {\n return true;\n }\n }\n return false;\n }\n\n protected async query<T extends IStorageItem = IStorageItem>(\n params: IAccessPatternQueryParams\n ) {\n return this.entity.queryPerPage<T>({\n partitionKey: params.partitionKey,\n options: params.options\n });\n }\n\n protected async populateResult(\n input: Awaited<IEntityQueryPerPageResult<IIndexStorageItem>>\n ): Promise<IEntityQueryPerPageResult<IStorageItem>> {\n const reader = this.entity.createEntityReader({\n read: input.items.map(item => {\n return {\n PK: item.PK,\n SK: item.SK\n };\n })\n });\n const result = await reader.execute();\n\n return {\n ...input,\n items: input.items\n .map(item => {\n return result.find(i => {\n return i.PK === item.PK && i.SK === item.SK;\n });\n })\n .filter((item): item is IStorageItem => !!item)\n };\n }\n\n public abstract list(params: T): Promise<IAccessPatternListResult>;\n public abstract createKeys(item: IAuditLog): IAccessPatternCreateKeysResult;\n\n protected createOptions(params: ICreateOptionsParams): IEntityQueryAllParams[\"options\"] {\n const options: IEntityQueryAllParams[\"options\"] = {\n limit: params.limit || 25,\n startKey: createStartKey({\n after: params.after\n }),\n reverse: params.sort === \"DESC\",\n index: this.index\n };\n\n if (params.createdOn_lte || params.createdOn_gte) {\n const lower = toGteTime(params.createdOn_gte);\n const upper = toLteTime(params.createdOn_lte);\n options!.between = [lower, Math.max(lower, upper)];\n }\n\n return options;\n }\n}\n"],"names":["toGteTime","date","toLteTime","Date","BaseAccessPattern","params","handles","key","input","reader","item","result","i","options","createStartKey","lower","upper","Math"],"mappings":";AAaA,MAAMA,YAAY,CAACC;IACf,IAAI,CAACA,MACD,OAAO;IAEX,OAAOA,KAAK,OAAO;AACvB;AACA,MAAMC,YAAY,CAACD;IACf,IAAI,CAACA,MACD,OAAOE,KAAK,GAAG;IAEnB,OAAOF,KAAK,OAAO;AACvB;AAoBO,MAAeG;IAIlB,YAAmBC,MAAgC,CAAE;QACjD,IAAI,CAAC,KAAK,GAAGA,OAAO,KAAK;QACzB,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;IAC/B;IAIO,UAAUA,MAA0B,EAAW;QAClD,MAAMC,UAAU,IAAI,CAAC,OAAO;QAC5B,KAAK,MAAMC,OAAOD,QAAQ,WAAW,CACjC,IAAI,CAACD,MAAM,CAACE,IAAI,EACZ,OAAO;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,QAAS,OAAO,GAAG;gBAACE;gBAAOE,KAAK,GAAG,CAACF,OAAOC;aAAO;QACtD;QAEA,OAAOH;IACX;AACJ"}
|
package/cursorSchema.d.ts
CHANGED
package/cursorSchema.js
CHANGED
package/cursorSchema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursorSchema.js","sources":["../src/cursorSchema.ts"],"sourcesContent":["import zod from \"zod\";\nimport { decodeCursor } from \"@webiny/db-dynamodb\";\n\nconst schema = zod\n .string()\n .transform(value => {\n const decoded = decodeCursor(value);\n if (!decoded) {\n throw new Error(\"Invalid cursor.\");\n }\n try {\n return JSON.parse(decoded);\n } catch {\n return decoded;\n }\n })\n .pipe(\n zod.object({\n
|
|
1
|
+
{"version":3,"file":"cursorSchema.js","sources":["../src/cursorSchema.ts"],"sourcesContent":["import zod from \"zod\";\nimport { decodeCursor } from \"@webiny/db-dynamodb\";\n\nconst schema = zod\n .string()\n .transform(value => {\n const decoded = decodeCursor(value);\n if (!decoded) {\n throw new Error(\"Invalid cursor.\");\n }\n try {\n return JSON.parse(decoded);\n } catch {\n return decoded;\n }\n })\n .pipe(\n zod\n .object({\n PK: zod.string(),\n SK: zod.string()\n })\n .passthrough()\n );\n\nexport const fetchCursor = (input: unknown) => {\n const result = schema.safeParse(input);\n if (!result.success) {\n return undefined;\n }\n return result.data;\n};\n"],"names":["schema","zod","value","decoded","decodeCursor","Error","JSON","fetchCursor","input","result"],"mappings":";;AAGA,MAAMA,SAASC,IAAAA,MACJ,GACN,SAAS,CAACC,CAAAA;IACP,MAAMC,UAAUC,aAAaF;IAC7B,IAAI,CAACC,SACD,MAAM,IAAIE,MAAM;IAEpB,IAAI;QACA,OAAOC,KAAK,KAAK,CAACH;IACtB,EAAE,OAAM;QACJ,OAAOA;IACX;AACJ,GACC,IAAI,CACDF,IAAAA,MACW,CAAC;IACJ,IAAIA,IAAI,MAAM;IACd,IAAIA,IAAI,MAAM;AAClB,GACC,WAAW;AAGjB,MAAMM,cAAc,CAACC;IACxB,MAAMC,SAAST,OAAO,SAAS,CAACQ;IAChC,IAAI,CAACC,OAAO,OAAO,EACf;IAEJ,OAAOA,OAAO,IAAI;AACtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-audit-logs-ddb",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-audit-logs",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
"./*": "./*"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@webiny/api": "6.6.0-alpha.
|
|
25
|
-
"@webiny/api-audit-logs": "6.6.0-alpha.
|
|
26
|
-
"@webiny/aws-sdk": "6.6.0-alpha.
|
|
27
|
-
"@webiny/db-dynamodb": "6.6.0-alpha.
|
|
28
|
-
"@webiny/error": "6.6.0-alpha.
|
|
29
|
-
"@webiny/feature": "6.6.0-alpha.
|
|
30
|
-
"@webiny/handler": "6.6.0-alpha.
|
|
31
|
-
"@webiny/utils": "6.6.0-alpha.
|
|
24
|
+
"@webiny/api": "6.6.0-alpha.2",
|
|
25
|
+
"@webiny/api-audit-logs": "6.6.0-alpha.2",
|
|
26
|
+
"@webiny/aws-sdk": "6.6.0-alpha.2",
|
|
27
|
+
"@webiny/db-dynamodb": "6.6.0-alpha.2",
|
|
28
|
+
"@webiny/error": "6.6.0-alpha.2",
|
|
29
|
+
"@webiny/feature": "6.6.0-alpha.2",
|
|
30
|
+
"@webiny/handler": "6.6.0-alpha.2",
|
|
31
|
+
"@webiny/utils": "6.6.0-alpha.2",
|
|
32
32
|
"zod": "4.4.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@webiny/
|
|
36
|
-
"@webiny/
|
|
35
|
+
"@webiny/api-core": "6.6.0-alpha.2",
|
|
36
|
+
"@webiny/build-tools": "6.6.0-alpha.2",
|
|
37
37
|
"rimraf": "6.1.3",
|
|
38
38
|
"typescript": "7.0.2"
|
|
39
39
|
},
|
package/startKey.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
1
|
import type { IStorageListParams } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
|
|
2
|
-
export
|
|
3
|
-
PK: string;
|
|
4
|
-
SK: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const createStartKey: (params: Pick<IStorageListParams, "after">) => ICreateStartKeyResult | undefined;
|
|
2
|
+
export declare const createStartKey: (params: Pick<IStorageListParams, "after">) => Record<string, unknown> | undefined;
|
package/startKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startKey.js","sources":["../src/startKey.ts"],"sourcesContent":["import type { IStorageListParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport { fetchCursor } from \"~/cursorSchema.js\";\n\nexport
|
|
1
|
+
{"version":3,"file":"startKey.js","sources":["../src/startKey.ts"],"sourcesContent":["import type { IStorageListParams } from \"@webiny/api-audit-logs/storage/abstractions/Storage.js\";\nimport { fetchCursor } from \"~/cursorSchema.js\";\n\nexport const createStartKey = (\n params: Pick<IStorageListParams, \"after\">\n): Record<string, unknown> | undefined => {\n if (!params.after) {\n return undefined;\n }\n return fetchCursor(params.after);\n};\n"],"names":["createStartKey","params","fetchCursor"],"mappings":";AAGO,MAAMA,iBAAiB,CAC1BC;IAEA,IAAI,CAACA,OAAO,KAAK,EACb;IAEJ,OAAOC,YAAYD,OAAO,KAAK;AACnC"}
|