@webiny/api-audit-logs-ddb 0.0.0-unstable.3fddf667ea → 0.0.0-unstable.48a4e5b6c1

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.
@@ -1,22 +1,15 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
- import { DynamoDBClient } from "@webiny/db-dynamodb";
3
- import { CompressionHandler } from "@webiny/utils/exports/api.js";
4
2
  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";
3
+ import { AuditLogsDdbConfig } from "./abstractions/AuditLogsDdbConfig.js";
4
+ import { DdbAuditLogsStorage } from "./DdbAuditLogsStorage.js";
7
5
  const AuditLogsDdbFeature = createFeature({
8
6
  name: "AuditLogsDdb",
9
7
  register (container, config = {}) {
10
8
  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,
17
- compressionHandler
18
- });
9
+ container.registerInstance(AuditLogsDdbConfig, {
10
+ tableName: config.tableName
19
11
  });
12
+ container.register(DdbAuditLogsStorage).inContainerScope();
20
13
  }
21
14
  });
22
15
  export { AuditLogsDdbFeature };
@@ -1 +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 // Audit logs have their own table (`DB_TABLE_AUDIT_LOGS`, which the entity falls back\n // to), with numeric index sort keys. Passing `DB_TABLE` here sent them to the main\n // table, whose GSI1_SK is a string, and every audited write failed there.\n tableName: config.tableName,\n compressionHandler\n });\n });\n }\n});\n"],"names":["AuditLogsDdbFeature","createFeature","container","config","CompressionFeature","AuditLogsStorage","db","DynamoDBClient","compressionHandler","CompressionHandler","createStorage"],"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;gBAIjB,WAAWH,OAAO,SAAS;gBAC3BK;YACJ;QACJ;IACJ;AACJ"}
1
+ {"version":3,"file":"AuditLogsDdbFeature.js","sources":["../src/AuditLogsDdbFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { CompressionFeature } from \"@webiny/utils/features/compression/feature.js\";\nimport { AuditLogsDdbConfig } from \"~/abstractions/AuditLogsDdbConfig.js\";\nimport { DdbAuditLogsStorage } from \"./DdbAuditLogsStorage.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 // Registered once, in the root, and built in each tenant scope with the scope's tenant.\n // Audit logs have their own table (`DB_TABLE_AUDIT_LOGS`, which the entity falls back to),\n // with numeric index sort keys. Passing `DB_TABLE` here sent them to the main table, whose\n // GSI1_SK is a string, and every audited write failed there.\n container.registerInstance(AuditLogsDdbConfig, { tableName: config.tableName });\n container.register(DdbAuditLogsStorage).inContainerScope();\n }\n});\n"],"names":["AuditLogsDdbFeature","createFeature","container","config","CompressionFeature","AuditLogsDdbConfig","DdbAuditLogsStorage"],"mappings":";;;;AASO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAoB,EAAEC,SAAoC,CAAC,CAAC;QACjEC,mBAAmB,QAAQ,CAACF;QAK5BA,UAAU,gBAAgB,CAACG,oBAAoB;YAAE,WAAWF,OAAO,SAAS;QAAC;QAC7ED,UAAU,QAAQ,CAACI,qBAAqB,gBAAgB;IAC5D;AACJ"}
@@ -0,0 +1,14 @@
1
+ import { DynamoDBClient } from "@webiny/db-dynamodb";
2
+ import { CompressionHandler } from "@webiny/utils/exports/api.js";
3
+ import { AuditLogsStorage } from "@webiny/api-audit-logs/abstractions.js";
4
+ import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
5
+ import { AuditLogsDdbConfig } from "./abstractions/AuditLogsDdbConfig.js";
6
+ import { Storage } from "./Storage.js";
7
+ /** Audit logs on DynamoDB, built in each tenant scope for the scope's tenant. */
8
+ declare class DdbAuditLogsStorageImpl extends Storage implements AuditLogsStorage.Interface {
9
+ constructor(db: DynamoDBClient.Interface, compressionHandler: CompressionHandler.Interface, scopeTenant: ScopeTenant.Interface, config?: AuditLogsDdbConfig.Interface);
10
+ }
11
+ export declare const DdbAuditLogsStorage: typeof DdbAuditLogsStorageImpl & {
12
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-audit-logs/storage/abstractions/Storage.js").IStorage>;
13
+ };
14
+ export {};
@@ -0,0 +1,33 @@
1
+ import { DynamoDBClient } from "@webiny/db-dynamodb";
2
+ import { CompressionHandler } from "@webiny/utils/exports/api.js";
3
+ import { AuditLogsStorage } from "@webiny/api-audit-logs/abstractions.js";
4
+ import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
5
+ import { AuditLogsDdbConfig } from "./abstractions/AuditLogsDdbConfig.js";
6
+ import { Storage } from "./Storage.js";
7
+ class DdbAuditLogsStorageImpl extends Storage {
8
+ constructor(db, compressionHandler, scopeTenant, config){
9
+ super({
10
+ client: db.client,
11
+ tableName: config?.tableName,
12
+ compressionHandler,
13
+ scopeTenant
14
+ });
15
+ }
16
+ }
17
+ const DdbAuditLogsStorage = AuditLogsStorage.createImplementation({
18
+ implementation: DdbAuditLogsStorageImpl,
19
+ dependencies: [
20
+ DynamoDBClient,
21
+ CompressionHandler,
22
+ ScopeTenant,
23
+ [
24
+ AuditLogsDdbConfig,
25
+ {
26
+ optional: true
27
+ }
28
+ ]
29
+ ]
30
+ });
31
+ export { DdbAuditLogsStorage };
32
+
33
+ //# sourceMappingURL=DdbAuditLogsStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DdbAuditLogsStorage.js","sources":["../src/DdbAuditLogsStorage.ts"],"sourcesContent":["import { DynamoDBClient } from \"@webiny/db-dynamodb\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { AuditLogsStorage } from \"@webiny/api-audit-logs/abstractions.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { AuditLogsDdbConfig } from \"~/abstractions/AuditLogsDdbConfig.js\";\nimport { Storage } from \"./Storage.js\";\n\n/** Audit logs on DynamoDB, built in each tenant scope for the scope's tenant. */\nclass DdbAuditLogsStorageImpl extends Storage implements AuditLogsStorage.Interface {\n public constructor(\n db: DynamoDBClient.Interface,\n compressionHandler: CompressionHandler.Interface,\n scopeTenant: ScopeTenant.Interface,\n config?: AuditLogsDdbConfig.Interface\n ) {\n super({ client: db.client, tableName: config?.tableName, compressionHandler, scopeTenant });\n }\n}\n\nexport const DdbAuditLogsStorage = AuditLogsStorage.createImplementation({\n implementation: DdbAuditLogsStorageImpl,\n dependencies: [\n DynamoDBClient,\n CompressionHandler,\n ScopeTenant,\n [AuditLogsDdbConfig, { optional: true }]\n ]\n});\n"],"names":["DdbAuditLogsStorageImpl","Storage","db","compressionHandler","scopeTenant","config","DdbAuditLogsStorage","AuditLogsStorage","DynamoDBClient","CompressionHandler","ScopeTenant","AuditLogsDdbConfig"],"mappings":";;;;;;AAQA,MAAMA,gCAAgCC;IAClC,YACIC,EAA4B,EAC5BC,kBAAgD,EAChDC,WAAkC,EAClCC,MAAqC,CACvC;QACE,KAAK,CAAC;YAAE,QAAQH,GAAG,MAAM;YAAE,WAAWG,QAAQ;YAAWF;YAAoBC;QAAY;IAC7F;AACJ;AAEO,MAAME,sBAAsBC,iBAAiB,oBAAoB,CAAC;IACrE,gBAAgBP;IAChB,cAAc;QACVQ;QACAC;QACAC;QACA;YAACC;YAAoB;gBAAE,UAAU;YAAK;SAAE;KAC3C;AACL"}
package/Storage.d.ts CHANGED
@@ -1,15 +1,19 @@
1
1
  import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
2
  import type { IStorage, IStorageFetchParams, IStorageFetchResult, IStorageListParams, IStorageListResult, IStorageStoreParams, IStorageStoreResult } from "@webiny/api-audit-logs/storage/abstractions/Storage.js";
3
3
  import { CompressionHandler } from "@webiny/utils/exports/api.js";
4
+ import type { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
4
5
  export interface IStorageParams {
5
6
  compressionHandler: CompressionHandler.Interface;
6
7
  client: DynamoDBDocument;
7
8
  tableName: string | undefined;
9
+ /** The tenant the storage acts on: its tenant scope's. */
10
+ scopeTenant: ScopeTenant.Interface;
8
11
  }
9
12
  export declare class Storage implements IStorage {
10
13
  private readonly entity;
11
14
  private readonly converter;
12
15
  private readonly patternHandler;
16
+ private readonly scopeTenant;
13
17
  constructor(params: IStorageParams);
14
18
  fetch(params: IStorageFetchParams): Promise<IStorageFetchResult>;
15
19
  store(params: IStorageStoreParams): Promise<IStorageStoreResult>;
package/Storage.js CHANGED
@@ -3,14 +3,30 @@ import { Converter } from "./Converter.js";
3
3
  import { createAccessPatterns } from "./accessPatterns/index.js";
4
4
  import { AccessPatternHandler } from "./AccessPatternHandler.js";
5
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,
6
+ const entities = new WeakMap();
7
+ const getEntity = (client, tableName)=>{
8
+ let byTable = entities.get(client);
9
+ if (!byTable) {
10
+ byTable = new Map();
11
+ entities.set(client, byTable);
12
+ }
13
+ const key = tableName ?? "";
14
+ let created = byTable.get(key);
15
+ if (!created) {
16
+ created = createEntity({
17
+ client,
18
+ tableName,
11
19
  gsiAmount: 10
12
20
  });
21
+ byTable.set(key, created);
22
+ }
23
+ return created;
24
+ };
25
+ class Storage {
26
+ constructor(params){
27
+ const { entity } = getEntity(params.client, params.tableName);
13
28
  this.entity = entity;
29
+ this.scopeTenant = params.scopeTenant;
14
30
  const patterns = createAccessPatterns({
15
31
  entity
16
32
  });
@@ -23,8 +39,9 @@ class Storage {
23
39
  });
24
40
  }
25
41
  async fetch(params) {
26
- const { id, tenant } = params;
42
+ const { id } = params;
27
43
  try {
44
+ const tenant = this.scopeTenant.getId();
28
45
  const result = await this.entity.get({
29
46
  PK: `T#${tenant}#AUDIT_LOG`,
30
47
  SK: `${id}`
@@ -47,6 +64,7 @@ class Storage {
47
64
  async store(params) {
48
65
  const auditLog = structuredClone(params.data);
49
66
  try {
67
+ auditLog.tenant = this.scopeTenant.getId();
50
68
  const item = await this.converter.oneToStorage(auditLog);
51
69
  await this.entity.put(item);
52
70
  } catch (ex) {
@@ -62,7 +80,10 @@ class Storage {
62
80
  }
63
81
  async list(params) {
64
82
  try {
65
- const result = await this.patternHandler.handle(params);
83
+ const result = await this.patternHandler.handle({
84
+ ...params,
85
+ tenant: this.scopeTenant.getId()
86
+ });
66
87
  return ListSuccessResult.create({
67
88
  data: await this.converter.listFromStorage(result.items),
68
89
  lastEvaluatedKey: result.lastEvaluatedKey
package/Storage.js.map CHANGED
@@ -1 +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"}
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\";\nimport type { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\nexport interface IStorageParams {\n compressionHandler: CompressionHandler.Interface;\n client: DynamoDBDocument;\n tableName: string | undefined;\n /** The tenant the storage acts on: its tenant scope's. */\n scopeTenant: ScopeTenant.Interface;\n}\n\n/**\n * The entity, built once per client and table: the storage itself is built per tenant scope.\n */\nconst entities = new WeakMap<DynamoDBDocument, Map<string, ReturnType<typeof createEntity>>>();\n\nconst getEntity = (client: DynamoDBDocument, tableName: string | undefined) => {\n let byTable = entities.get(client);\n if (!byTable) {\n byTable = new Map();\n entities.set(client, byTable);\n }\n const key = tableName ?? \"\";\n let created = byTable.get(key);\n if (!created) {\n created = createEntity({ client, tableName, gsiAmount: 10 });\n byTable.set(key, created);\n }\n return created;\n};\n\nexport class Storage implements IStorage {\n private readonly entity;\n private readonly converter;\n private readonly patternHandler;\n private readonly scopeTenant: ScopeTenant.Interface;\n\n public constructor(params: IStorageParams) {\n const { entity } = getEntity(params.client, params.tableName);\n\n this.entity = entity;\n this.scopeTenant = params.scopeTenant;\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 } = params;\n\n try {\n const tenant = this.scopeTenant.getId();\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 // Stored with its scope's tenant, whatever tenant it carries.\n auditLog.tenant = this.scopeTenant.getId();\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({\n ...params,\n tenant: this.scopeTenant.getId()\n });\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":["entities","WeakMap","getEntity","client","tableName","byTable","Map","key","created","createEntity","Storage","params","entity","patterns","createAccessPatterns","AccessPatternHandler","Converter","id","tenant","result","Error","ex","auditLog","structuredClone","item","ListSuccessResult","createStorage"],"mappings":";;;;;AA6BA,MAAMA,WAAW,IAAIC;AAErB,MAAMC,YAAY,CAACC,QAA0BC;IACzC,IAAIC,UAAUL,SAAS,GAAG,CAACG;IAC3B,IAAI,CAACE,SAAS;QACVA,UAAU,IAAIC;QACdN,SAAS,GAAG,CAACG,QAAQE;IACzB;IACA,MAAME,MAAMH,aAAa;IACzB,IAAII,UAAUH,QAAQ,GAAG,CAACE;IAC1B,IAAI,CAACC,SAAS;QACVA,UAAUC,aAAa;YAAEN;YAAQC;YAAW,WAAW;QAAG;QAC1DC,QAAQ,GAAG,CAACE,KAAKC;IACrB;IACA,OAAOA;AACX;AAEO,MAAME;IAMT,YAAmBC,MAAsB,CAAE;QACvC,MAAM,EAAEC,MAAM,EAAE,GAAGV,UAAUS,OAAO,MAAM,EAAEA,OAAO,SAAS;QAE5D,IAAI,CAAC,MAAM,GAAGC;QACd,IAAI,CAAC,WAAW,GAAGD,OAAO,WAAW;QAErC,MAAME,WAAWC,qBAAqB;YAClCF;QACJ;QACA,IAAI,CAAC,cAAc,GAAG,IAAIG,qBAAqB;YAC3CF;QACJ;QAEA,IAAI,CAAC,SAAS,GAAG,IAAIG,UAAU;YAC3B,oBAAoBL,OAAO,kBAAkB;YAC7C,gBAAgB,IAAI,CAAC,cAAc;QACvC;IACJ;IAEA,MAAa,MAAMA,MAA2B,EAAgC;QAC1E,MAAM,EAAEM,EAAE,EAAE,GAAGN;QAEf,IAAI;YACA,MAAMO,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;YACrC,MAAMC,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,MAAMV,MAA2B,EAAgC;QAC1E,MAAMW,WAAWC,gBAAgBZ,OAAO,IAAI;QAE5C,IAAI;YAEAW,SAAS,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK;YACxC,MAAME,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,KAAKX,MAA0B,EAA+B;QACvE,IAAI;YACA,MAAMQ,SAAS,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;gBAC5C,GAAGR,MAAM;gBACT,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK;YAClC;YAEA,OAAOc,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,CAACf,SACnB,IAAID,QAAQC"}
@@ -0,0 +1,8 @@
1
+ export interface IAuditLogsDdbConfig {
2
+ /** Falls back to the entity's own default (`DB_TABLE_AUDIT_LOGS`). */
3
+ tableName?: string;
4
+ }
5
+ export declare const AuditLogsDdbConfig: import("@webiny/di").Abstraction<IAuditLogsDdbConfig>;
6
+ export declare namespace AuditLogsDdbConfig {
7
+ type Interface = IAuditLogsDdbConfig;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const AuditLogsDdbConfig = createAbstraction("AuditLogsDdbConfig");
3
+ export { AuditLogsDdbConfig };
4
+
5
+ //# sourceMappingURL=AuditLogsDdbConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstractions/AuditLogsDdbConfig.js","sources":["../../src/abstractions/AuditLogsDdbConfig.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IAuditLogsDdbConfig {\n /** Falls back to the entity's own default (`DB_TABLE_AUDIT_LOGS`). */\n tableName?: string;\n}\n\nexport const AuditLogsDdbConfig = createAbstraction<IAuditLogsDdbConfig>(\"AuditLogsDdbConfig\");\n\nexport namespace AuditLogsDdbConfig {\n export type Interface = IAuditLogsDdbConfig;\n}\n"],"names":["AuditLogsDdbConfig","createAbstraction"],"mappings":";AAOO,MAAMA,qBAAqBC,kBAAuC"}
package/cursorSchema.js CHANGED
@@ -1,10 +1,11 @@
1
+ import { parseJson } from "@webiny/utils/parseJson.js";
1
2
  import zod from "zod";
2
3
  import { decodeCursor } from "@webiny/db-dynamodb";
3
4
  const schema = zod.string().transform((value)=>{
4
5
  const decoded = decodeCursor(value);
5
6
  if (!decoded) throw new Error("Invalid cursor.");
6
7
  try {
7
- return JSON.parse(decoded);
8
+ return parseJson(decoded);
8
9
  } catch {
9
10
  return decoded;
10
11
  }
@@ -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\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"}
1
+ {"version":3,"file":"cursorSchema.js","sources":["../src/cursorSchema.ts"],"sourcesContent":["import { parseJson } from \"@webiny/utils/parseJson.js\";\nimport 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 parseJson(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","parseJson","fetchCursor","input","result"],"mappings":";;;AAIA,MAAMA,SAASC,IAAAA,MACJ,GACN,SAAS,CAACC,CAAAA;IACP,MAAMC,UAAUC,aAAaF;IAC7B,IAAI,CAACC,SACD,MAAM,IAAIE,MAAM;IAEpB,IAAI;QACA,OAAOC,UAAUH;IACrB,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/index.js CHANGED
@@ -1,15 +1,14 @@
1
1
  import { createRegisterExtensionPlugin } from "@webiny/handler";
2
- import { createStorage } from "./Storage.js";
3
- import { AuditLogsStorage } from "@webiny/api-audit-logs/abstractions.js";
4
- import { CompressionHandler } from "@webiny/utils/exports/api.js";
2
+ import { DynamoDBClientFeature } from "@webiny/db-dynamodb";
3
+ import { AuditLogsDdbConfig } from "./abstractions/AuditLogsDdbConfig.js";
4
+ import { DdbAuditLogsStorage } from "./DdbAuditLogsStorage.js";
5
5
  const registerAuditLogsDdbStorageOperations = (params)=>createRegisterExtensionPlugin((context)=>{
6
- const compressionHandler = context.container.resolve(CompressionHandler);
7
- const storage = createStorage({
8
- client: params.documentClient,
9
- tableName: params.tableName,
10
- compressionHandler
6
+ const container = context.container;
7
+ DynamoDBClientFeature.register(container, params.documentClient);
8
+ container.registerInstance(AuditLogsDdbConfig, {
9
+ tableName: params.tableName
11
10
  });
12
- context.container.registerInstance(AuditLogsStorage, storage);
11
+ container.register(DdbAuditLogsStorage).inContainerScope();
13
12
  });
14
13
  export { AuditLogsDdbFeature } from "./AuditLogsDdbFeature.js";
15
14
  export { registerAuditLogsDdbStorageOperations };
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { createStorage } from \"~/Storage.js\";\nimport { AuditLogsStorage } from \"@webiny/api-audit-logs/abstractions.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\ninterface RegisterAuditLogsDdbStorageOperationsParams {\n documentClient: DynamoDBDocument;\n tableName?: string;\n}\n\nexport const registerAuditLogsDdbStorageOperations = (\n params: RegisterAuditLogsDdbStorageOperationsParams\n) => {\n return createRegisterExtensionPlugin(context => {\n const compressionHandler = context.container.resolve(CompressionHandler);\n const storage = createStorage({\n client: params.documentClient,\n tableName: params.tableName,\n compressionHandler\n });\n context.container.registerInstance(AuditLogsStorage, storage);\n });\n};\nexport { AuditLogsDdbFeature } from \"./AuditLogsDdbFeature.js\";\nexport type { AuditLogsDdbFeatureConfig } from \"./AuditLogsDdbFeature.js\";\n"],"names":["registerAuditLogsDdbStorageOperations","params","createRegisterExtensionPlugin","context","compressionHandler","CompressionHandler","storage","createStorage","AuditLogsStorage"],"mappings":";;;;AAWO,MAAMA,wCAAwC,CACjDC,SAEOC,8BAA8BC,CAAAA;QACjC,MAAMC,qBAAqBD,QAAQ,SAAS,CAAC,OAAO,CAACE;QACrD,MAAMC,UAAUC,cAAc;YAC1B,QAAQN,OAAO,cAAc;YAC7B,WAAWA,OAAO,SAAS;YAC3BG;QACJ;QACAD,QAAQ,SAAS,CAAC,gBAAgB,CAACK,kBAAkBF;IACzD"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { DynamoDBClientFeature } from \"@webiny/db-dynamodb\";\nimport { AuditLogsDdbConfig } from \"~/abstractions/AuditLogsDdbConfig.js\";\nimport { DdbAuditLogsStorage } from \"./DdbAuditLogsStorage.js\";\n\ninterface RegisterAuditLogsDdbStorageOperationsParams {\n documentClient: DynamoDBDocument;\n tableName?: string;\n}\n\nexport const registerAuditLogsDdbStorageOperations = (\n params: RegisterAuditLogsDdbStorageOperationsParams\n) => {\n return createRegisterExtensionPlugin(context => {\n const container = context.container;\n // The storage injects `DynamoDBClient`; this one wraps the given document client.\n // `CompressionHandler` is already registered, so `AuditLogsDdbFeature` (which registers\n // the compressors again) isn't used here.\n DynamoDBClientFeature.register(container, params.documentClient);\n container.registerInstance(AuditLogsDdbConfig, { tableName: params.tableName });\n container.register(DdbAuditLogsStorage).inContainerScope();\n });\n};\nexport { AuditLogsDdbFeature } from \"./AuditLogsDdbFeature.js\";\nexport type { AuditLogsDdbFeatureConfig } from \"./AuditLogsDdbFeature.js\";\n"],"names":["registerAuditLogsDdbStorageOperations","params","createRegisterExtensionPlugin","context","container","DynamoDBClientFeature","AuditLogsDdbConfig","DdbAuditLogsStorage"],"mappings":";;;;AAWO,MAAMA,wCAAwC,CACjDC,SAEOC,8BAA8BC,CAAAA;QACjC,MAAMC,YAAYD,QAAQ,SAAS;QAInCE,sBAAsB,QAAQ,CAACD,WAAWH,OAAO,cAAc;QAC/DG,UAAU,gBAAgB,CAACE,oBAAoB;YAAE,WAAWL,OAAO,SAAS;QAAC;QAC7EG,UAAU,QAAQ,CAACG,qBAAqB,gBAAgB;IAC5D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-audit-logs-ddb",
3
- "version": "0.0.0-unstable.3fddf667ea",
3
+ "version": "0.0.0-unstable.48a4e5b6c1",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "@webiny/api-audit-logs",
@@ -21,20 +21,20 @@
21
21
  "./*": "./*"
22
22
  },
23
23
  "dependencies": {
24
- "@webiny/api": "0.0.0-unstable.3fddf667ea",
25
- "@webiny/api-audit-logs": "0.0.0-unstable.3fddf667ea",
26
- "@webiny/aws-sdk": "0.0.0-unstable.3fddf667ea",
27
- "@webiny/db-dynamodb": "0.0.0-unstable.3fddf667ea",
28
- "@webiny/error": "0.0.0-unstable.3fddf667ea",
29
- "@webiny/feature": "0.0.0-unstable.3fddf667ea",
30
- "@webiny/handler": "0.0.0-unstable.3fddf667ea",
31
- "@webiny/utils": "0.0.0-unstable.3fddf667ea",
24
+ "@webiny/api": "0.0.0-unstable.48a4e5b6c1",
25
+ "@webiny/api-audit-logs": "0.0.0-unstable.48a4e5b6c1",
26
+ "@webiny/api-core": "0.0.0-unstable.48a4e5b6c1",
27
+ "@webiny/aws-sdk": "0.0.0-unstable.48a4e5b6c1",
28
+ "@webiny/db-dynamodb": "0.0.0-unstable.48a4e5b6c1",
29
+ "@webiny/error": "0.0.0-unstable.48a4e5b6c1",
30
+ "@webiny/feature": "0.0.0-unstable.48a4e5b6c1",
31
+ "@webiny/handler": "0.0.0-unstable.48a4e5b6c1",
32
+ "@webiny/utils": "0.0.0-unstable.48a4e5b6c1",
32
33
  "zod": "4.6.7"
33
34
  },
34
35
  "devDependencies": {
35
- "@webiny/api-core": "0.0.0-unstable.3fddf667ea",
36
- "@webiny/build-tools": "0.0.0-unstable.3fddf667ea",
37
- "rimraf": "6.1.3",
36
+ "@webiny/build-tools": "0.0.0-unstable.48a4e5b6c1",
37
+ "rimraf": "6.1.4",
38
38
  "typescript": "7.0.2"
39
39
  },
40
40
  "publishConfig": {