@webiny/api-audit-logs 6.2.0 → 6.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-audit-logs",
3
- "version": "6.2.0",
3
+ "version": "6.3.0-beta.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "repository": {
@@ -20,33 +20,33 @@
20
20
  "directory": "dist"
21
21
  },
22
22
  "devDependencies": {
23
- "@webiny/handler-aws": "6.2.0",
24
- "@webiny/plugins": "6.2.0",
25
- "@webiny/project-utils": "6.2.0",
23
+ "@webiny/handler-aws": "6.3.0-beta.0",
24
+ "@webiny/plugins": "6.3.0-beta.0",
25
+ "@webiny/project-utils": "6.3.0-beta.0",
26
26
  "graphql": "16.13.2",
27
- "typescript": "5.9.3",
27
+ "typescript": "6.0.3",
28
28
  "vitest": "4.1.4"
29
29
  },
30
30
  "dependencies": {
31
- "@webiny/api": "6.2.0",
32
- "@webiny/api-aco": "6.2.0",
33
- "@webiny/api-core": "6.2.0",
34
- "@webiny/api-file-manager": "6.2.0",
35
- "@webiny/api-headless-cms": "6.2.0",
36
- "@webiny/api-mailer": "6.2.0",
37
- "@webiny/api-website-builder": "6.2.0",
38
- "@webiny/aws-sdk": "6.2.0",
39
- "@webiny/build-tools": "6.2.0",
40
- "@webiny/common-audit-logs": "6.2.0",
41
- "@webiny/db-dynamodb": "6.2.0",
42
- "@webiny/error": "6.2.0",
43
- "@webiny/feature": "6.2.0",
44
- "@webiny/handler": "6.2.0",
45
- "@webiny/handler-db": "6.2.0",
46
- "@webiny/handler-graphql": "6.2.0",
47
- "@webiny/utils": "6.2.0",
48
- "@webiny/wcp": "6.2.0",
31
+ "@webiny/api": "6.3.0-beta.0",
32
+ "@webiny/api-aco": "6.3.0-beta.0",
33
+ "@webiny/api-core": "6.3.0-beta.0",
34
+ "@webiny/api-file-manager": "6.3.0-beta.0",
35
+ "@webiny/api-headless-cms": "6.3.0-beta.0",
36
+ "@webiny/api-mailer": "6.3.0-beta.0",
37
+ "@webiny/api-website-builder": "6.3.0-beta.0",
38
+ "@webiny/aws-sdk": "6.3.0-beta.0",
39
+ "@webiny/build-tools": "6.3.0-beta.0",
40
+ "@webiny/common-audit-logs": "6.3.0-beta.0",
41
+ "@webiny/db-dynamodb": "6.3.0-beta.0",
42
+ "@webiny/error": "6.3.0-beta.0",
43
+ "@webiny/feature": "6.3.0-beta.0",
44
+ "@webiny/handler": "6.3.0-beta.0",
45
+ "@webiny/handler-db": "6.3.0-beta.0",
46
+ "@webiny/handler-graphql": "6.3.0-beta.0",
47
+ "@webiny/utils": "6.3.0-beta.0",
48
+ "@webiny/wcp": "6.3.0-beta.0",
49
49
  "zod": "4.3.6"
50
50
  },
51
- "gitHead": "3d3148358b6febbc857371930871743bec3b3939"
51
+ "gitHead": "94c21e58aebc9855bf1ae972423281faa0f5c135"
52
52
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Storage.ts"],"sourcesContent":["import type { IAuditLog } from \"~/storage/types.js\";\n\nexport interface IStorageFetchParams {\n id: string;\n tenant: string;\n}\n\nexport interface IStorageFetchErrorResult {\n error: Error;\n data?: never;\n success: false;\n}\n\nexport interface IStorageFetchSuccessResult {\n data: IAuditLog;\n success: true;\n error?: never;\n}\n\nexport type IStorageFetchResult = IStorageFetchErrorResult | IStorageFetchSuccessResult;\n\nexport interface IStorageStoreParams {\n data: IAuditLog;\n}\n\nexport interface IStorageStoreErrorResult {\n error: Error;\n data?: never;\n success: false;\n}\n\nexport interface IStorageStoreSuccessResult {\n data: IAuditLog;\n success: true;\n error?: never;\n}\n\nexport type IStorageStoreResult = IStorageStoreErrorResult | IStorageStoreSuccessResult;\n\n// PK / SK\nexport interface IStorageListDefaultParams {\n tenant: string;\n sort?: \"ASC\" | \"DESC\";\n after?: string;\n limit: number | undefined;\n\n app?: never;\n createdBy?: never;\n action?: never;\n entityId?: never;\n}\n\n// GSI1_PK / GSI1_SK\nexport interface IStorageListByAppParams {\n tenant: string;\n app: string;\n after?: string;\n sort?: \"ASC\" | \"DESC\";\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n limit: number | undefined;\n\n entity?: never;\n createdBy?: never;\n action?: never;\n entityId?: never;\n}\n\n// GSI2_PK / GSI2_SK\nexport interface IStorageListByAppCreatedByParams\n extends Omit<IStorageListByAppParams, \"createdBy\"> {\n createdBy: string;\n}\n\n// GSI3_PK / GSI3_SK\nexport interface IStorageListByAppEntityParams extends Omit<IStorageListByAppParams, \"entity\"> {\n entity: string;\n}\n// GSI4_PK / GSI4_SK\nexport interface IStorageListByEntityIdParams extends Omit<IStorageListByAppParams, \"entityId\"> {\n entityId: string;\n}\n// GSI5_PK / GSI5_SK\nexport interface IStorageListByActionParams extends Omit<IStorageListByAppParams, \"action\"> {\n action: string;\n}\n\n// GSI6_PK / GSI6_SK\nexport interface IStorageListByAppEntityActionCreatedByParams\n extends Omit<IStorageListByAppParams, \"action\" | \"entity\" | \"createdBy\"> {\n createdBy: string;\n entity: string;\n action: string;\n}\n// GSI7_PK / GSI7_SK\nexport interface IStorageListByAppEntityActionParams\n extends Omit<IStorageListByAppParams, \"entity\" | \"action\"> {\n entity: string;\n action: string;\n}\n// GSI8_PK / GSI8_SK\nexport interface IStorageListByAppEntityCreatedByParams\n extends Omit<IStorageListByAppParams, \"createdBy\" | \"entity\"> {\n createdBy: string;\n entity: string;\n}\n\n// GSI9_PK / GSI9_SK\nexport interface IStorageListByCreatedByParams extends Omit<IStorageListByAppParams, \"createdBy\"> {\n createdBy: string;\n}\n\n// GSI10_PK / GSI10_SK\nexport interface IStorageListByCreatedOnParams extends IStorageListByAppParams {\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n}\n\nexport type IStorageListParams =\n | IStorageListByAppParams\n | IStorageListByAppCreatedByParams\n | IStorageListByAppEntityParams\n | IStorageListByEntityIdParams\n | IStorageListByActionParams\n | IStorageListByAppEntityActionCreatedByParams\n | IStorageListByAppEntityActionParams\n | IStorageListByAppEntityCreatedByParams\n | IStorageListByCreatedByParams\n | IStorageListByCreatedOnParams;\n\nexport interface IStorageListSuccessResultMeta {\n after?: string;\n hasMoreItems: boolean;\n}\n\nexport interface IStorageListSuccessResult {\n data: IAuditLog[];\n meta: IStorageListSuccessResultMeta;\n success: true;\n error?: never;\n}\n\nexport interface IStorageListErrorResult {\n error: Error;\n data?: never;\n meta?: never;\n success: false;\n}\n\nexport type IStorageListResult = IStorageListErrorResult | IStorageListSuccessResult;\n\nexport interface IStorage {\n fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;\n store(params: IStorageStoreParams): Promise<IStorageStoreResult>;\n list(params: IStorageListParams): Promise<IStorageListResult>;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["Storage.ts"],"sourcesContent":["import type { IAuditLog } from \"~/storage/types.js\";\n\nexport interface IStorageFetchParams {\n id: string;\n tenant: string;\n}\n\nexport interface IStorageFetchErrorResult {\n error: Error;\n data?: never;\n success: false;\n}\n\nexport interface IStorageFetchSuccessResult {\n data: IAuditLog;\n success: true;\n error?: never;\n}\n\nexport type IStorageFetchResult = IStorageFetchErrorResult | IStorageFetchSuccessResult;\n\nexport interface IStorageStoreParams {\n data: IAuditLog;\n}\n\nexport interface IStorageStoreErrorResult {\n error: Error;\n data?: never;\n success: false;\n}\n\nexport interface IStorageStoreSuccessResult {\n data: IAuditLog;\n success: true;\n error?: never;\n}\n\nexport type IStorageStoreResult = IStorageStoreErrorResult | IStorageStoreSuccessResult;\n\n// PK / SK\nexport interface IStorageListDefaultParams {\n tenant: string;\n sort?: \"ASC\" | \"DESC\";\n after?: string;\n limit: number | undefined;\n\n app?: never;\n createdBy?: never;\n action?: never;\n entityId?: never;\n}\n\n// GSI1_PK / GSI1_SK\nexport interface IStorageListByAppParams {\n tenant: string;\n app: string;\n after?: string;\n sort?: \"ASC\" | \"DESC\";\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n limit: number | undefined;\n\n entity?: never;\n createdBy?: never;\n action?: never;\n entityId?: never;\n}\n\n// GSI2_PK / GSI2_SK\nexport interface IStorageListByAppCreatedByParams extends Omit<\n IStorageListByAppParams,\n \"createdBy\"\n> {\n createdBy: string;\n}\n\n// GSI3_PK / GSI3_SK\nexport interface IStorageListByAppEntityParams extends Omit<IStorageListByAppParams, \"entity\"> {\n entity: string;\n}\n// GSI4_PK / GSI4_SK\nexport interface IStorageListByEntityIdParams extends Omit<IStorageListByAppParams, \"entityId\"> {\n entityId: string;\n}\n// GSI5_PK / GSI5_SK\nexport interface IStorageListByActionParams extends Omit<IStorageListByAppParams, \"action\"> {\n action: string;\n}\n\n// GSI6_PK / GSI6_SK\nexport interface IStorageListByAppEntityActionCreatedByParams extends Omit<\n IStorageListByAppParams,\n \"action\" | \"entity\" | \"createdBy\"\n> {\n createdBy: string;\n entity: string;\n action: string;\n}\n// GSI7_PK / GSI7_SK\nexport interface IStorageListByAppEntityActionParams extends Omit<\n IStorageListByAppParams,\n \"entity\" | \"action\"\n> {\n entity: string;\n action: string;\n}\n// GSI8_PK / GSI8_SK\nexport interface IStorageListByAppEntityCreatedByParams extends Omit<\n IStorageListByAppParams,\n \"createdBy\" | \"entity\"\n> {\n createdBy: string;\n entity: string;\n}\n\n// GSI9_PK / GSI9_SK\nexport interface IStorageListByCreatedByParams extends Omit<IStorageListByAppParams, \"createdBy\"> {\n createdBy: string;\n}\n\n// GSI10_PK / GSI10_SK\nexport interface IStorageListByCreatedOnParams extends IStorageListByAppParams {\n createdOn_gte?: Date;\n createdOn_lte?: Date;\n}\n\nexport type IStorageListParams =\n | IStorageListByAppParams\n | IStorageListByAppCreatedByParams\n | IStorageListByAppEntityParams\n | IStorageListByEntityIdParams\n | IStorageListByActionParams\n | IStorageListByAppEntityActionCreatedByParams\n | IStorageListByAppEntityActionParams\n | IStorageListByAppEntityCreatedByParams\n | IStorageListByCreatedByParams\n | IStorageListByCreatedOnParams;\n\nexport interface IStorageListSuccessResultMeta {\n after?: string;\n hasMoreItems: boolean;\n}\n\nexport interface IStorageListSuccessResult {\n data: IAuditLog[];\n meta: IStorageListSuccessResultMeta;\n success: true;\n error?: never;\n}\n\nexport interface IStorageListErrorResult {\n error: Error;\n data?: never;\n meta?: never;\n success: false;\n}\n\nexport type IStorageListResult = IStorageListErrorResult | IStorageListSuccessResult;\n\nexport interface IStorage {\n fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;\n store(params: IStorageStoreParams): Promise<IStorageStoreResult>;\n list(params: IStorageListParams): Promise<IStorageListResult>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["BaseAccessPattern","createPartitionKey","params","tenant","app","entity","action","createdBy","AppEntityActionCreatedByAccessPattern","handles","mustInclude","mustNotInclude","list","options","createOptions","result","query","partitionKey","populateResult","createKeys","item","time","createdOn","getTime","id","sortKey"],"sources":["AppEntityActionCreatedByAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"~/storage/types.js\";\nimport type { IStorageListByAppEntityActionCreatedByParams } from \"~/storage/abstractions/Storage.js\";\nimport { BaseAccessPattern } from \"~/storage/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/storage/abstractions/AccessPattern.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n action: string;\n entity: string;\n createdBy: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}#ACTION#${params.action}#CREATEDBY#${params.createdBy}`;\n};\n\nexport class AppEntityActionCreatedByAccessPattern<\n T extends\n IStorageListByAppEntityActionCreatedByParams = IStorageListByAppEntityActionCreatedByParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\", \"action\", \"entity\", \"createdBy\"],\n mustNotInclude: [\"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({\n ...item,\n createdBy: item.createdBy.id\n }),\n sortKey: time\n };\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB;AAe1B,MAAMC,kBAAkB,GAAIC,MAAiC,IAAK;EAC9D,OAAO,KAAKA,MAAM,CAACC,MAAM,kBAAkBD,MAAM,CAACE,GAAG,WAAWF,MAAM,CAACG,MAAM,WAAWH,MAAM,CAACI,MAAM,cAAcJ,MAAM,CAACK,SAAS,EAAE;AACzI,CAAC;AAED,OAAO,MAAMC,qCAAqC,SAGxCR,iBAAiB,CAAI;EACXS,OAAOA,CAAA,EAA0B;IAC7C,OAAO;MACHC,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC;MACrDC,cAAc,EAAE,CAAC,UAAU;IAC/B,CAAC;EACL;EAEA,MAAaC,IAAIA,CAACV,MAAS,EAAqC;IAC5D,MAAMW,OAAO,GAAG,IAAI,CAACC,aAAa,CAACZ,MAAM,CAAC;IAE1C,MAAMa,MAAM,GAAG,MAAM,IAAI,CAACC,KAAK,CAAC;MAC5BC,YAAY,EAAEhB,kBAAkB,CAACC,MAAM,CAAC;MACxCW;IACJ,CAAC,CAAC;IACF,OAAO,IAAI,CAACK,cAAc,CAACH,MAAM,CAAC;EACtC;EAEOI,UAAUA,CAACC,IAAe,EAAkC;IAC/D,MAAMC,IAAI,GAAGD,IAAI,CAACE,SAAS,CAACC,OAAO,CAAC,CAAC;IAErC,OAAO;MACHN,YAAY,EAAEhB,kBAAkB,CAAC;QAC7B,GAAGmB,IAAI;QACPb,SAAS,EAAEa,IAAI,CAACb,SAAS,CAACiB;MAC9B,CAAC,CAAC;MACFC,OAAO,EAAEJ;IACb,CAAC;EACL;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["BaseAccessPattern","createPartitionKey","params","tenant","app","entity","action","createdBy","AppEntityActionCreatedByAccessPattern","handles","mustInclude","mustNotInclude","list","options","createOptions","result","query","partitionKey","populateResult","createKeys","item","time","createdOn","getTime","id","sortKey"],"sources":["AppEntityActionCreatedByAccessPattern.ts"],"sourcesContent":["import type { IAuditLog } from \"~/storage/types.js\";\nimport type { IStorageListByAppEntityActionCreatedByParams } from \"~/storage/abstractions/Storage.js\";\nimport { BaseAccessPattern } from \"~/storage/accessPatterns/BaseAccessPattern.js\";\nimport type {\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"~/storage/abstractions/AccessPattern.js\";\n\ninterface ICreatePartitionKeyParams {\n tenant: string;\n app: string;\n action: string;\n entity: string;\n createdBy: string;\n}\n\nconst createPartitionKey = (params: ICreatePartitionKeyParams) => {\n return `T#${params.tenant}#AUDIT_LOG#APP#${params.app}#ENTITY#${params.entity}#ACTION#${params.action}#CREATEDBY#${params.createdBy}`;\n};\n\nexport class AppEntityActionCreatedByAccessPattern<\n T extends IStorageListByAppEntityActionCreatedByParams =\n IStorageListByAppEntityActionCreatedByParams\n> extends BaseAccessPattern<T> {\n public override handles(): IAccessPatternHandles {\n return {\n mustInclude: [\"app\", \"action\", \"entity\", \"createdBy\"],\n mustNotInclude: [\"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({\n ...item,\n createdBy: item.createdBy.id\n }),\n sortKey: time\n };\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB;AAe1B,MAAMC,kBAAkB,GAAIC,MAAiC,IAAK;EAC9D,OAAO,KAAKA,MAAM,CAACC,MAAM,kBAAkBD,MAAM,CAACE,GAAG,WAAWF,MAAM,CAACG,MAAM,WAAWH,MAAM,CAACI,MAAM,cAAcJ,MAAM,CAACK,SAAS,EAAE;AACzI,CAAC;AAED,OAAO,MAAMC,qCAAqC,SAGxCR,iBAAiB,CAAI;EACXS,OAAOA,CAAA,EAA0B;IAC7C,OAAO;MACHC,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC;MACrDC,cAAc,EAAE,CAAC,UAAU;IAC/B,CAAC;EACL;EAEA,MAAaC,IAAIA,CAACV,MAAS,EAAqC;IAC5D,MAAMW,OAAO,GAAG,IAAI,CAACC,aAAa,CAACZ,MAAM,CAAC;IAE1C,MAAMa,MAAM,GAAG,MAAM,IAAI,CAACC,KAAK,CAAC;MAC5BC,YAAY,EAAEhB,kBAAkB,CAACC,MAAM,CAAC;MACxCW;IACJ,CAAC,CAAC;IACF,OAAO,IAAI,CAACK,cAAc,CAACH,MAAM,CAAC;EACtC;EAEOI,UAAUA,CAACC,IAAe,EAAkC;IAC/D,MAAMC,IAAI,GAAGD,IAAI,CAACE,SAAS,CAACC,OAAO,CAAC,CAAC;IAErC,OAAO;MACHN,YAAY,EAAEhB,kBAAkB,CAAC;QAC7B,GAAGmB,IAAI;QACPb,SAAS,EAAEa,IAAI,CAACb,SAAS,CAACiB;MAC9B,CAAC,CAAC;MACFC,OAAO,EAAEJ;IACb,CAAC;EACL;AACJ","ignoreList":[]}
@@ -66,6 +66,7 @@ export class BaseAccessPattern {
66
66
  createOptions(params) {
67
67
  const options = {
68
68
  limit: params.limit || 25,
69
+ // @ts-expect-error
69
70
  startKey: createStartKey({
70
71
  after: params.after
71
72
  }),
@@ -1 +1 @@
1
- {"version":3,"names":["createStartKey","toGteTime","date","getTime","toLteTime","Date","now","BaseAccessPattern","constructor","params","index","entity","canHandle","handles","key","mustInclude","mustNotInclude","shouldInclude","length","query","queryPerPage","partitionKey","options","populateResult","input","reader","createEntityReader","read","items","map","item","PK","SK","result","execute","find","i","filter","createOptions","limit","startKey","after","reverse","sort","createdOn_lte","createdOn_gte","between"],"sources":["BaseAccessPattern.ts"],"sourcesContent":["import type { IAuditLog, IIndexStorageItem, IStorageItem } from \"~/storage/types.js\";\nimport { createStartKey } from \"~/storage/startKey.js\";\nimport type { IStorageListParams } from \"../abstractions/Storage.js\";\nimport type {\n IAccessPattern,\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"../abstractions/AccessPattern.js\";\nimport type { AuditLogsEntity } from \"~/storage/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 options.between = [toGteTime(params.createdOn_gte), toLteTime(params.createdOn_lte)];\n }\n\n return options;\n }\n}\n"],"mappings":"AACA,SAASA,cAAc;AAWvB,MAAMC,SAAS,GAAIC,IAAW,IAAa;EACvC,IAAI,CAACA,IAAI,EAAE;IACP,OAAO,CAAC;EACZ;EACA,OAAOA,IAAI,CAACC,OAAO,CAAC,CAAC;AACzB,CAAC;AACD,MAAMC,SAAS,GAAIF,IAAW,IAAa;EACvC,IAAI,CAACA,IAAI,EAAE;IACP,OAAOG,IAAI,CAACC,GAAG,CAAC,CAAC;EACrB;EACA,OAAOJ,IAAI,CAACC,OAAO,CAAC,CAAC;AACzB,CAAC;AAoBD,OAAO,MAAeI,iBAAiB,CAAiC;EAI7DC,WAAWA,CAACC,MAAgC,EAAE;IACjD,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;IACzB,IAAI,CAACC,MAAM,GAAGF,MAAM,CAACE,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,CAACC,IAAI,IAAI;QACT,OAAOG,MAAM,CAACE,IAAI,CAACC,CAAC,IAAI;UACpB,OAAOA,CAAC,CAACL,EAAE,KAAKD,IAAI,CAACC,EAAE,IAAIK,CAAC,CAACJ,EAAE,KAAKF,IAAI,CAACE,EAAE;QAC/C,CAAC,CAAC;MACN,CAAC,CAAC,CACDK,MAAM,CAAEP,IAAI,IAA2B,CAAC,CAACA,IAAI;IACtD,CAAC;EACL;EAKUQ,aAAaA,CAAC7B,MAA4B,EAAoC;IACpF,MAAMa,OAAyC,GAAG;MAC9CiB,KAAK,EAAE9B,MAAM,CAAC8B,KAAK,IAAI,EAAE;MACzBC,QAAQ,EAAExC,cAAc,CAAC;QACrByC,KAAK,EAAEhC,MAAM,CAACgC;MAClB,CAAC,CAAC;MACFC,OAAO,EAAEjC,MAAM,CAACkC,IAAI,KAAK,MAAM;MAC/BjC,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC;IAED,IAAID,MAAM,CAACmC,aAAa,IAAInC,MAAM,CAACoC,aAAa,EAAE;MAC9CvB,OAAO,CAACwB,OAAO,GAAG,CAAC7C,SAAS,CAACQ,MAAM,CAACoC,aAAa,CAAC,EAAEzC,SAAS,CAACK,MAAM,CAACmC,aAAa,CAAC,CAAC;IACxF;IAEA,OAAOtB,OAAO;EAClB;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["createStartKey","toGteTime","date","getTime","toLteTime","Date","now","BaseAccessPattern","constructor","params","index","entity","canHandle","handles","key","mustInclude","mustNotInclude","shouldInclude","length","query","queryPerPage","partitionKey","options","populateResult","input","reader","createEntityReader","read","items","map","item","PK","SK","result","execute","find","i","filter","createOptions","limit","startKey","after","reverse","sort","createdOn_lte","createdOn_gte","between"],"sources":["BaseAccessPattern.ts"],"sourcesContent":["import type { IAuditLog, IIndexStorageItem, IStorageItem } from \"~/storage/types.js\";\nimport { createStartKey } from \"~/storage/startKey.js\";\nimport type { IStorageListParams } from \"../abstractions/Storage.js\";\nimport type {\n IAccessPattern,\n IAccessPatternCreateKeysResult,\n IAccessPatternHandles,\n IAccessPatternListResult\n} from \"../abstractions/AccessPattern.js\";\nimport type { AuditLogsEntity } from \"~/storage/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 // @ts-expect-error\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 options!.between = [toGteTime(params.createdOn_gte), toLteTime(params.createdOn_lte)];\n }\n\n return options;\n }\n}\n"],"mappings":"AACA,SAASA,cAAc;AAWvB,MAAMC,SAAS,GAAIC,IAAW,IAAa;EACvC,IAAI,CAACA,IAAI,EAAE;IACP,OAAO,CAAC;EACZ;EACA,OAAOA,IAAI,CAACC,OAAO,CAAC,CAAC;AACzB,CAAC;AACD,MAAMC,SAAS,GAAIF,IAAW,IAAa;EACvC,IAAI,CAACA,IAAI,EAAE;IACP,OAAOG,IAAI,CAACC,GAAG,CAAC,CAAC;EACrB;EACA,OAAOJ,IAAI,CAACC,OAAO,CAAC,CAAC;AACzB,CAAC;AAoBD,OAAO,MAAeI,iBAAiB,CAAiC;EAI7DC,WAAWA,CAACC,MAAgC,EAAE;IACjD,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;IACzB,IAAI,CAACC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC/B;EAIOC,SAASA,CAACH,MAA0B,EAAW;IAClD,MAAMI,OAAO,GAAG,IAAI,CAACA,OAAO,CAAC,CAAC;IAC9B,KAAK,MAAMC,GAAG,IAAID,OAAO,CAACE,WAAW,EAAE;MACnC,IAAI,CAACN,MAAM,CAACK,GAAG,CAAC,EAAE;QACd,OAAO,KAAK;MAChB;IACJ;IACA,KAAK,MAAMA,GAAG,IAAID,OAAO,CAACG,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L;EAKUQ,aAAaA,CAAC7B,MAA4B,EAAoC;IACpF,MAAMa,OAAyC,GAAG;MAC9CiB,KAAK,EAAE9B,MAAM,CAAC8B,KAAK,IAAI,EAAE;MACzB;MACAC,QAAQ,EAAExC,cAAc,CAAC;QACrByC,KAAK,EAAEhC,MAAM,CAACgC;MAClB,CAAC,CAAC;MACFC,OAAO,EAAEjC,MAAM,CAACkC,IAAI,KAAK,MAAM;MAC/BjC,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC;IAED,IAAID,MAAM,CAACmC,aAAa,IAAInC,MAAM,CAACoC,aAAa,EAAE;MAC9CvB,OAAO,CAAEwB,OAAO,GAAG,CAAC7C,SAAS,CAACQ,MAAM,CAACoC,aAAa,CAAC,EAAEzC,SAAS,CAACK,MAAM,CAACmC,aAAa,CAAC,CAAC;IACzF;IAEA,OAAOtB,OAAO;EAClB;AACJ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["createEntity","baseCreateEntity","createTable","createTableGSIIndexes","count","result","i","partitionKey","sortKey","params","gsiAmount","client","tableName","name","process","env","DB_TABLE_AUDIT_LOGS","Error","table","documentClient","indexes","entity","attributes","PK","SK","GSI_TENANT","type","required","GSI1_PK","GSI1_SK","GSI2_PK","GSI2_SK","GSI3_PK","GSI3_SK","GSI4_PK","GSI4_SK","GSI5_PK","GSI5_SK","GSI6_PK","GSI6_SK","GSI7_PK","GSI7_SK","GSI8_PK","GSI8_SK","GSI9_PK","GSI9_SK","data"],"sources":["entity.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport { createEntity as baseCreateEntity, createTable } from \"@webiny/db-dynamodb\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IStorageAuditLog } from \"~/storage/types.js\";\n\nexport interface IAuditLogsEntityAttributes\n extends Omit<IStandardEntityAttributes<IStorageAuditLog>, \"GSI1_SK\" | \"GSI2_SK\" | \"expiresAt\"> {\n GSI1_PK: string;\n GSI1_SK: number;\n GSI2_PK: string;\n GSI2_SK: number;\n GSI3_PK: string;\n GSI3_SK: number;\n GSI4_PK: string;\n GSI4_SK: number;\n GSI5_PK: string;\n GSI5_SK: number;\n GSI6_PK: string;\n GSI6_SK: number;\n GSI7_PK: string;\n GSI7_SK: number;\n GSI8_PK: string;\n GSI8_SK: number;\n GSI9_PK: string;\n GSI9_SK: number;\n expiresAt: number;\n}\n\nexport type AuditLogsEntity = IEntity<IAuditLogsEntityAttributes>;\n\nexport interface ICreateEntityParams {\n client: DynamoDBDocument;\n gsiAmount: number;\n tableName: string | undefined;\n}\n\nexport interface ICreateEntityResult {\n entity: AuditLogsEntity;\n table: ReturnType<typeof createTable>;\n}\n\nconst createTableGSIIndexes = (count: number) => {\n const result: GenericRecord = {};\n for (let i = 1; i <= count; i++) {\n result[`GSI${i}`] = {\n partitionKey: `GSI${i}_PK`,\n sortKey: `GSI${i}_SK`\n };\n }\n return result;\n};\n\nexport const createEntity = (params: ICreateEntityParams): ICreateEntityResult => {\n const { gsiAmount, client, tableName } = params;\n const name = tableName || process.env.DB_TABLE_AUDIT_LOGS;\n if (!name) {\n throw new Error(\"Missing env.DB_TABLE_AUDIT_LOGS environment variable.\");\n }\n const table = createTable({\n documentClient: client,\n name,\n indexes: {\n ...createTableGSIIndexes(gsiAmount)\n }\n });\n\n const entity = baseCreateEntity<IAuditLogsEntityAttributes>({\n name: \"AuditLogs\",\n table: table.table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI_TENANT: {\n type: \"string\",\n required: true\n },\n GSI1_PK: {\n type: \"string\",\n required: true\n },\n GSI1_SK: {\n type: \"number\",\n required: true\n },\n GSI2_PK: {\n type: \"string\",\n required: true\n },\n GSI2_SK: {\n type: \"number\",\n required: true\n },\n GSI3_PK: {\n type: \"string\",\n required: true\n },\n GSI3_SK: {\n type: \"number\",\n required: true\n },\n GSI4_PK: {\n type: \"string\",\n required: true\n },\n GSI4_SK: {\n type: \"number\",\n required: true\n },\n GSI5_PK: {\n type: \"string\",\n required: true\n },\n GSI5_SK: {\n type: \"number\",\n required: true\n },\n GSI6_PK: {\n type: \"string\",\n required: true\n },\n GSI6_SK: {\n type: \"number\",\n required: true\n },\n GSI7_PK: {\n type: \"string\",\n required: true\n },\n GSI7_SK: {\n type: \"number\",\n required: true\n },\n GSI8_PK: {\n type: \"string\",\n required: true\n },\n GSI8_SK: {\n type: \"number\",\n required: true\n },\n GSI9_PK: {\n type: \"string\",\n required: true\n },\n GSI9_SK: {\n type: \"number\",\n required: true\n },\n data: {\n type: \"map\",\n required: true\n }\n }\n });\n\n return {\n entity,\n table\n };\n};\n"],"mappings":"AAEA,SAASA,YAAY,IAAIC,gBAAgB,EAAEC,WAAW,QAAQ,qBAAqB;AAwCnF,MAAMC,qBAAqB,GAAIC,KAAa,IAAK;EAC7C,MAAMC,MAAqB,GAAG,CAAC,CAAC;EAChC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIF,KAAK,EAAEE,CAAC,EAAE,EAAE;IAC7BD,MAAM,CAAC,MAAMC,CAAC,EAAE,CAAC,GAAG;MAChBC,YAAY,EAAE,MAAMD,CAAC,KAAK;MAC1BE,OAAO,EAAE,MAAMF,CAAC;IACpB,CAAC;EACL;EACA,OAAOD,MAAM;AACjB,CAAC;AAED,OAAO,MAAML,YAAY,GAAIS,MAA2B,IAA0B;EAC9E,MAAM;IAAEC,SAAS;IAAEC,MAAM;IAAEC;EAAU,CAAC,GAAGH,MAAM;EAC/C,MAAMI,IAAI,GAAGD,SAAS,IAAIE,OAAO,CAACC,GAAG,CAACC,mBAAmB;EACzD,IAAI,CAACH,IAAI,EAAE;IACP,MAAM,IAAII,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EACA,MAAMC,KAAK,GAAGhB,WAAW,CAAC;IACtBiB,cAAc,EAAER,MAAM;IACtBE,IAAI;IACJO,OA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,EAAE;MACd,CAAC;MACDa,OAAO,EAAE;QACLd,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDc,OAAO,EAAE;QACLf,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDe,OAAO,EAAE;QACLhB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDgB,OAAO,EAAE;QACLjB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDiB,OAAO,EAAE;QACLlB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDkB,OAAO,EAAE;QACLnB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDmB,IAAI,EAAE;QACFpB,IAAI,EAAE,KAAK;QACXC,QAAQ,EAAE;MACd;IACJ;EACJ,CAAC,CAAC;EAEF,OAAO;IACHN,MAAM;IACNH;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createEntity","baseCreateEntity","createTable","createTableGSIIndexes","count","result","i","partitionKey","sortKey","params","gsiAmount","client","tableName","name","process","env","DB_TABLE_AUDIT_LOGS","Error","table","documentClient","indexes","entity","attributes","PK","SK","GSI_TENANT","type","required","GSI1_PK","GSI1_SK","GSI2_PK","GSI2_SK","GSI3_PK","GSI3_SK","GSI4_PK","GSI4_SK","GSI5_PK","GSI5_SK","GSI6_PK","GSI6_SK","GSI7_PK","GSI7_SK","GSI8_PK","GSI8_SK","GSI9_PK","GSI9_SK","data"],"sources":["entity.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport { createEntity as baseCreateEntity, createTable } from \"@webiny/db-dynamodb\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IStorageAuditLog } from \"~/storage/types.js\";\n\nexport interface IAuditLogsEntityAttributes extends Omit<\n IStandardEntityAttributes<IStorageAuditLog>,\n \"GSI1_SK\" | \"GSI2_SK\" | \"expiresAt\"\n> {\n GSI1_PK: string;\n GSI1_SK: number;\n GSI2_PK: string;\n GSI2_SK: number;\n GSI3_PK: string;\n GSI3_SK: number;\n GSI4_PK: string;\n GSI4_SK: number;\n GSI5_PK: string;\n GSI5_SK: number;\n GSI6_PK: string;\n GSI6_SK: number;\n GSI7_PK: string;\n GSI7_SK: number;\n GSI8_PK: string;\n GSI8_SK: number;\n GSI9_PK: string;\n GSI9_SK: number;\n expiresAt: number;\n}\n\nexport type AuditLogsEntity = IEntity<IAuditLogsEntityAttributes>;\n\nexport interface ICreateEntityParams {\n client: DynamoDBDocument;\n gsiAmount: number;\n tableName: string | undefined;\n}\n\nexport interface ICreateEntityResult {\n entity: AuditLogsEntity;\n table: ReturnType<typeof createTable>;\n}\n\nconst createTableGSIIndexes = (count: number) => {\n const result: GenericRecord = {};\n for (let i = 1; i <= count; i++) {\n result[`GSI${i}`] = {\n partitionKey: `GSI${i}_PK`,\n sortKey: `GSI${i}_SK`\n };\n }\n return result;\n};\n\nexport const createEntity = (params: ICreateEntityParams): ICreateEntityResult => {\n const { gsiAmount, client, tableName } = params;\n const name = tableName || process.env.DB_TABLE_AUDIT_LOGS;\n if (!name) {\n throw new Error(\"Missing env.DB_TABLE_AUDIT_LOGS environment variable.\");\n }\n const table = createTable({\n documentClient: client,\n name,\n indexes: {\n ...createTableGSIIndexes(gsiAmount)\n }\n });\n\n const entity = baseCreateEntity<IAuditLogsEntityAttributes>({\n name: \"AuditLogs\",\n table: table.table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI_TENANT: {\n type: \"string\",\n required: true\n },\n GSI1_PK: {\n type: \"string\",\n required: true\n },\n GSI1_SK: {\n type: \"number\",\n required: true\n },\n GSI2_PK: {\n type: \"string\",\n required: true\n },\n GSI2_SK: {\n type: \"number\",\n required: true\n },\n GSI3_PK: {\n type: \"string\",\n required: true\n },\n GSI3_SK: {\n type: \"number\",\n required: true\n },\n GSI4_PK: {\n type: \"string\",\n required: true\n },\n GSI4_SK: {\n type: \"number\",\n required: true\n },\n GSI5_PK: {\n type: \"string\",\n required: true\n },\n GSI5_SK: {\n type: \"number\",\n required: true\n },\n GSI6_PK: {\n type: \"string\",\n required: true\n },\n GSI6_SK: {\n type: \"number\",\n required: true\n },\n GSI7_PK: {\n type: \"string\",\n required: true\n },\n GSI7_SK: {\n type: \"number\",\n required: true\n },\n GSI8_PK: {\n type: \"string\",\n required: true\n },\n GSI8_SK: {\n type: \"number\",\n required: true\n },\n GSI9_PK: {\n type: \"string\",\n required: true\n },\n GSI9_SK: {\n type: \"number\",\n required: true\n },\n data: {\n type: \"map\",\n required: true\n }\n }\n });\n\n return {\n entity,\n table\n };\n};\n"],"mappings":"AAEA,SAASA,YAAY,IAAIC,gBAAgB,EAAEC,WAAW,QAAQ,qBAAqB;AA0CnF,MAAMC,qBAAqB,GAAIC,KAAa,IAAK;EAC7C,MAAMC,MAAqB,GAAG,CAAC,CAAC;EAChC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIF,KAAK,EAAEE,CAAC,EAAE,EAAE;IAC7BD,MAAM,CAAC,MAAMC,CAAC,EAAE,CAAC,GAAG;MAChBC,YAAY,EAAE,MAAMD,CAAC,KAAK;MAC1BE,OAAO,EAAE,MAAMF,CAAC;IACpB,CAAC;EACL;EACA,OAAOD,MAAM;AACjB,CAAC;AAED,OAAO,MAAML,YAAY,GAAIS,MAA2B,IAA0B;EAC9E,MAAM;IAAEC,SAAS;IAAEC,MAAM;IAAEC;EAAU,CAAC,GAAGH,MAAM;EAC/C,MAAMI,IAAI,GAAGD,SAAS,IAAIE,OAAO,CAACC,GAAG,CAACC,mBAAmB;EACzD,IAAI,CAACH,IAAI,EAAE;IACP,MAAM,IAAII,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EACA,MAAMC,KAAK,GAAGhB,WAA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C;MACDY,OAAO,EAAE;QACLb,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDa,OAAO,EAAE;QACLd,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDc,OAAO,EAAE;QACLf,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDe,OAAO,EAAE;QACLhB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDgB,OAAO,EAAE;QACLjB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDiB,OAAO,EAAE;QACLlB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDkB,OAAO,EAAE;QACLnB,IAAI,EAAE,QAAQ;QACdC,QAAQ,EAAE;MACd,CAAC;MACDmB,IAAI,EAAE;QACFpB,IAAI,EAAE,KAAK;QACXC,QAAQ,EAAE;MACd;IACJ;EACJ,CAAC,CAAC;EAEF,OAAO;IACHN,MAAM;IACNH;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { Action, App, Entity } from \"@webiny/common-audit-logs/types.js\";\nimport type { DbContext } from \"@webiny/handler-db/types.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport type { IStorageListParams } from \"~/storage/abstractions/Storage.js\";\n\nexport interface AuditLogPayload\n extends Omit<IAuditLog, \"id\" | \"tenant\" | \"createdOn\" | \"createdBy\" | \"expiresAt\" | \"content\"> {\n content: GenericRecord;\n}\n\nexport interface IListAuditLogsParams extends Omit<IStorageListParams, \"tenant\" | \"limit\" | \"app\"> {\n app?: string;\n limit?: number;\n}\n\nexport interface IListAuditLogsResultMeta {\n cursor: string | null;\n hasMoreItems: boolean;\n}\n\nexport interface IListAuditLogsSuccessResult {\n items: IAuditLog[];\n meta: IListAuditLogsResultMeta;\n error?: never;\n}\n\nexport interface IListAuditLogsErrorResult {\n items?: never;\n meta?: never;\n error: Error;\n}\n\nexport type IListAuditLogsResult = IListAuditLogsSuccessResult | IListAuditLogsErrorResult;\n\nexport interface AuditLogsContextValue {\n deleteLogsAfterDays: number | undefined;\n createAuditLog(payload: AuditLogPayload): Promise<IAuditLog>;\n updateAuditLog(original: IAuditLog, payload: Partial<AuditLogPayload>): Promise<IAuditLog>;\n getAuditLog(id: string): Promise<IAuditLog | null>;\n listAuditLogs(params: IListAuditLogsParams): Promise<IListAuditLogsResult>;\n}\n\nexport interface AuditLogsContext extends ApiCoreContext, Pick<DbContext, \"db\"> {\n auditLogs: AuditLogsContextValue;\n}\n\nexport interface AuditObject {\n [app: string]: EntityObject;\n}\n\nexport interface EntityObject {\n [entity: string]: ActionObject;\n}\n\nexport interface ActionObject {\n [action: string]: AuditAction;\n}\n\nexport interface AuditAction {\n app: App;\n entity: Entity;\n action: Action;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { Action, App, Entity } from \"@webiny/common-audit-logs/types.js\";\nimport type { DbContext } from \"@webiny/handler-db/types.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { IAuditLog } from \"~/storage/types.js\";\nimport type { IStorageListParams } from \"~/storage/abstractions/Storage.js\";\n\nexport interface AuditLogPayload extends Omit<\n IAuditLog,\n \"id\" | \"tenant\" | \"createdOn\" | \"createdBy\" | \"expiresAt\" | \"content\"\n> {\n content: GenericRecord;\n}\n\nexport interface IListAuditLogsParams extends Omit<IStorageListParams, \"tenant\" | \"limit\" | \"app\"> {\n app?: string;\n limit?: number;\n}\n\nexport interface IListAuditLogsResultMeta {\n cursor: string | null;\n hasMoreItems: boolean;\n}\n\nexport interface IListAuditLogsSuccessResult {\n items: IAuditLog[];\n meta: IListAuditLogsResultMeta;\n error?: never;\n}\n\nexport interface IListAuditLogsErrorResult {\n items?: never;\n meta?: never;\n error: Error;\n}\n\nexport type IListAuditLogsResult = IListAuditLogsSuccessResult | IListAuditLogsErrorResult;\n\nexport interface AuditLogsContextValue {\n deleteLogsAfterDays: number | undefined;\n createAuditLog(payload: AuditLogPayload): Promise<IAuditLog>;\n updateAuditLog(original: IAuditLog, payload: Partial<AuditLogPayload>): Promise<IAuditLog>;\n getAuditLog(id: string): Promise<IAuditLog | null>;\n listAuditLogs(params: IListAuditLogsParams): Promise<IListAuditLogsResult>;\n}\n\nexport interface AuditLogsContext extends ApiCoreContext, Pick<DbContext, \"db\"> {\n auditLogs: AuditLogsContextValue;\n}\n\nexport interface AuditObject {\n [app: string]: EntityObject;\n}\n\nexport interface EntityObject {\n [entity: string]: ActionObject;\n}\n\nexport interface ActionObject {\n [action: string]: AuditAction;\n}\n\nexport interface AuditAction {\n app: App;\n entity: Entity;\n action: Action;\n}\n"],"mappings":"","ignoreList":[]}