@flipboxlabs/aws-audit-sdk 1.4.1 → 1.5.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.
@@ -53,22 +53,32 @@ export type TypedIdentifiers<C extends AuditConfig> = {
53
53
  resourceType: InferResourceType<C>;
54
54
  };
55
55
  /**
56
- * Options for listing audit items by resource with typed App and ResourceType.
56
+ * Options for listing audit objects by resource with typed App and ResourceType.
57
57
  * @typeParam C - The audit config type for type inference
58
58
  */
59
- export type TypedListItemsOptions<C extends AuditConfig> = {
59
+ export type TypedListObjectsOptions<C extends AuditConfig> = {
60
60
  /** Tenant/organization identifier for multi-tenancy support (optional) */
61
61
  tenantId?: string;
62
62
  /** Resource identification */
63
63
  resource: {
64
64
  /** Type of the resource */
65
65
  type: InferResourceType<C>;
66
- /** Unique identifier of the resource */
67
- id: string;
68
66
  };
69
67
  /** Application owning the resource */
70
68
  app: InferApp<C>;
71
69
  };
70
+ /**
71
+ * Options for listing audit items by resource with typed App and ResourceType.
72
+ * @typeParam C - The audit config type for type inference
73
+ */
74
+ export type TypedListItemsOptions<C extends AuditConfig> = Omit<TypedListObjectsOptions<C>, "resource"> & {
75
+ resource: {
76
+ /** Type of the resource */
77
+ type: InferResourceType<C>;
78
+ /** Unique identifier of the resource */
79
+ id: string;
80
+ };
81
+ };
72
82
  /**
73
83
  * Options for listing audit items by trace ID with typed App and ResourceType.
74
84
  * @typeParam C - The audit config type for type inference
@@ -259,6 +269,49 @@ export declare class AuditRepository<C extends AuditConfig> {
259
269
  error?: unknown;
260
270
  at: string;
261
271
  }): Promise<number>;
272
+ listObjects(params: TypedListObjectsOptions<C>, pagination?: Pagination): Promise<{
273
+ items: {
274
+ id: string;
275
+ status: "success" | "warn" | "fail" | "skip";
276
+ tier: number;
277
+ target: {
278
+ app: string;
279
+ type: string;
280
+ id?: string | number | undefined;
281
+ };
282
+ operation: string;
283
+ message: string | undefined;
284
+ updatedAt?: string | undefined;
285
+ createdAt?: string | undefined;
286
+ tenantId?: string | undefined;
287
+ source?: {
288
+ app: string;
289
+ type: string;
290
+ id?: string | number | undefined;
291
+ } | undefined;
292
+ context?: Record<string, string | number | boolean | {
293
+ [key: string]: string | number | boolean | /*elided*/ any;
294
+ }> | undefined;
295
+ rerunable?: boolean | undefined;
296
+ trace?: string | undefined;
297
+ event?: {
298
+ detail: string | undefined;
299
+ source?: string | undefined;
300
+ "detail-type"?: string | undefined;
301
+ } | undefined;
302
+ error?: any;
303
+ attempts?: {
304
+ number: number;
305
+ status: "success" | "warn" | "fail" | "skip";
306
+ at: string;
307
+ error?: any;
308
+ }[] | undefined;
309
+ }[];
310
+ pagination?: {
311
+ pageSize?: string | number | null | undefined;
312
+ nextToken?: string | null | undefined;
313
+ } | undefined;
314
+ }>;
262
315
  /**
263
316
  * Lists audit records for a specific resource with pagination.
264
317
  *
@@ -1 +1 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../src/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAEL,cAAc,EAKf,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAGpE,OAAO,EAAE,KAAK,KAAK,EAAmC,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,UAAU,EAA8B,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGvF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,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OAAO,CAAC,gBAAgB;IAgBxB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;IAe7B;;;;;;;;;OASG;IACH,OAAO,CAAC,aAAa;IAQrB;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAU9B;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAczB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;CAahC"}
@@ -308,7 +308,58 @@ export class AuditRepository {
308
308
  throw new Error("UpdateItem did not return attributes");
309
309
  }
310
310
  const updated = unmarshall(result.Attributes);
311
- return updated.attempts.length;
311
+ const attemptNumber = updated.attempts.length;
312
+ if (attemptNumber !== currentAttempt.number) {
313
+ await this.client.send(new UpdateItemCommand({
314
+ TableName: DynamoDB.Table.Name(),
315
+ Key: marshall(primaryKey, {
316
+ removeUndefinedValues: true,
317
+ convertEmptyValues: true,
318
+ convertClassInstanceToMap: true,
319
+ }),
320
+ UpdateExpression: `SET #attempts[${attemptNumber - 1}].#number = :attemptNumber`,
321
+ ExpressionAttributeNames: {
322
+ "#attempts": "attempts",
323
+ "#number": "number",
324
+ },
325
+ ExpressionAttributeValues: marshall({
326
+ ":attemptNumber": attemptNumber,
327
+ }),
328
+ }));
329
+ }
330
+ return attemptNumber;
331
+ }
332
+ async listObjects(params, pagination) {
333
+ const startKey = decodeNextPageToken(pagination?.nextToken);
334
+ const pageSize = Number(pagination?.pageSize || 100);
335
+ const pkBase = `${params.app}.${params.resource.type}`;
336
+ const pk = params.tenantId ? `${params.tenantId}#${pkBase}` : pkBase;
337
+ const { Items: items, LastEvaluatedKey: lastEvaluatedKey } = await this.client.send(new QueryCommand({
338
+ ScanIndexForward: false,
339
+ IndexName: DynamoDB.Indexes.LSI1_N,
340
+ ExpressionAttributeValues: marshall({
341
+ ":PK": pk,
342
+ }),
343
+ ExpressionAttributeNames: {
344
+ "#PK": DynamoDB.Keys.PARTITION_KEY,
345
+ },
346
+ KeyConditionExpression: "#PK=:PK",
347
+ TableName: DynamoDB.Table.Name(),
348
+ Limit: pageSize,
349
+ ExclusiveStartKey: startKey
350
+ ? marshall(startKey, {
351
+ removeUndefinedValues: true,
352
+ convertEmptyValues: true,
353
+ convertClassInstanceToMap: true,
354
+ })
355
+ : undefined,
356
+ }));
357
+ return PaginationCollectionSchema(AuditPayloadSchema).parse({
358
+ items: items?.map((i) => this.transformListItem(unmarshall(i))),
359
+ pagination: {
360
+ nextToken: lastEvaluatedKey ? encodeNextPageToken(unmarshall(lastEvaluatedKey)) : undefined,
361
+ },
362
+ });
312
363
  }
313
364
  /**
314
365
  * Lists audit records for a specific resource with pagination.
@@ -679,8 +730,11 @@ export class AuditRepository {
679
730
  */
680
731
  transformListItem(item) {
681
732
  const [id] = item.SK.split("#");
733
+ const trace = item.GSI1_SN_PK !== undefined && item.GSI1_SN_SK !== undefined
734
+ ? `${item.GSI1_SN_PK}:${item.GSI1_SN_SK}`
735
+ : undefined;
682
736
  return AuditPayloadSchema.parse({
683
- trace: `${item.GSI1_SN_PK}:${item.GSI1_SN_SK}`,
737
+ trace,
684
738
  ...item,
685
739
  id: id,
686
740
  });
package/dist/service.d.ts CHANGED
@@ -1,83 +1,11 @@
1
1
  import type { Logger } from "@aws-lambda-powertools/logger";
2
2
  import type { AuditConfig } from "./config.js";
3
3
  import { AuditEventBus } from "./events/bus.js";
4
- import { AuditRepository } from "./repository.js";
4
+ import { AuditRepository, type TypedIdentifiers, type TypedListByStatusOptions, type TypedListItemsOptions, type TypedListObjectsOptions, type TypedListTraceItems } from "./repository.js";
5
5
  import type { Audit } from "./schema/audit.js";
6
- import type { AnyStatus } from "./schema/log.js";
7
6
  import type { Pagination } from "./schema/model.js";
8
7
  import { type UpsertAuditInput } from "./schema/service.js";
9
- import type { InferApp, InferResourceType } from "./types.js";
10
- /**
11
- * Typed identifiers for locating audit records.
12
- * Uses config-derived App and ResourceType types for strict typing.
13
- */
14
- export type TypedIdentifiers<C extends AuditConfig> = {
15
- /** Tenant/organization identifier for multi-tenancy support (optional) */
16
- tenantId?: string;
17
- /** Unique audit record identifier */
18
- id: string | number;
19
- /** Application that owns this audit record */
20
- app: InferApp<C>;
21
- /** Optional resource identifier within the application */
22
- resourceId?: string | number;
23
- /** Type of resource being audited */
24
- resourceType: InferResourceType<C>;
25
- };
26
- /**
27
- * Typed options for listing audit items by resource.
28
- * Uses config-derived App and ResourceType types for strict typing.
29
- */
30
- export type TypedListItemsOptions<C extends AuditConfig> = {
31
- /** Tenant/organization identifier for multi-tenancy support (optional) */
32
- tenantId?: string;
33
- /** Resource identification */
34
- resource: {
35
- /** Type of the resource */
36
- type: InferResourceType<C>;
37
- /** Unique identifier of the resource */
38
- id: string;
39
- };
40
- /** Application owning the resource */
41
- app: InferApp<C>;
42
- };
43
- /**
44
- * Typed options for listing audit items by trace ID.
45
- * Uses config-derived App and ResourceType types for strict typing.
46
- */
47
- export type TypedListTraceItems<C extends AuditConfig> = {
48
- /** Tenant/organization identifier for multi-tenancy support (optional) */
49
- tenantId?: string;
50
- /** Trace ID to query for related audit records */
51
- trace: string;
52
- /** Optional application filter */
53
- app?: InferApp<C>;
54
- /** Optional resource filter */
55
- resource?: {
56
- /** Filter by resource type */
57
- type?: InferResourceType<C>;
58
- /** Filter by resource ID */
59
- id?: string;
60
- };
61
- };
62
- /**
63
- * Typed options for listing audit items by status.
64
- * Uses config-derived App and ResourceType types for strict typing.
65
- */
66
- export type TypedListByStatusOptions<C extends AuditConfig> = {
67
- /** Tenant/organization identifier for multi-tenancy support (optional) */
68
- tenantId?: string;
69
- /** Status to filter by (success, warn, fail, skip) */
70
- status: AnyStatus;
71
- /** Optional application filter */
72
- app?: InferApp<C>;
73
- /** Optional resource filter */
74
- resource?: {
75
- /** Filter by resource type */
76
- type?: InferResourceType<C>;
77
- /** Filter by resource ID */
78
- id?: string;
79
- };
80
- };
8
+ export type { TypedIdentifiers, TypedListByStatusOptions, TypedListObjectsOptions, TypedListItemsOptions, TypedListTraceItems, } from "./repository.js";
81
9
  /**
82
10
  * High-level service for managing audit records with typed App and ResourceType.
83
11
  *
@@ -182,6 +110,68 @@ export declare class AuditService<C extends AuditConfig> {
182
110
  * ```
183
111
  */
184
112
  upsertItem(input: UpsertAuditInput): Promise<void>;
113
+ /**
114
+ * Lists audit records with filtering and pagination.
115
+ *
116
+ * Queries audits based on resource type and app.
117
+ * Results are paginated in descending tier and creation order.
118
+ *
119
+ * @param params - Query parameters for filtering
120
+ * @param pagination - Optional pagination settings
121
+ * @returns Paginated collection of audit records
122
+ * @throws Re-throws any storage errors after logging
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const { items, pagination } = await service.listObjects({
127
+ * resource: { type: 'Order' },
128
+ * app: 'Orders',
129
+ * });
130
+ * ```
131
+ */
132
+ listObjects(params: TypedListObjectsOptions<C>, pagination?: Pagination): Promise<{
133
+ items: {
134
+ id: string;
135
+ status: "success" | "warn" | "fail" | "skip";
136
+ tier: number;
137
+ target: {
138
+ app: string;
139
+ type: string;
140
+ id?: string | number | undefined;
141
+ };
142
+ operation: string;
143
+ message: string | undefined;
144
+ updatedAt?: string | undefined;
145
+ createdAt?: string | undefined;
146
+ tenantId?: string | undefined;
147
+ source?: {
148
+ app: string;
149
+ type: string;
150
+ id?: string | number | undefined;
151
+ } | undefined;
152
+ context?: Record<string, string | number | boolean | {
153
+ [key: string]: string | number | boolean | /*elided*/ any;
154
+ }> | undefined;
155
+ rerunable?: boolean | undefined;
156
+ trace?: string | undefined;
157
+ event?: {
158
+ detail: string | undefined;
159
+ source?: string | undefined;
160
+ "detail-type"?: string | undefined;
161
+ } | undefined;
162
+ error?: any;
163
+ attempts?: {
164
+ number: number;
165
+ status: "success" | "warn" | "fail" | "skip";
166
+ at: string;
167
+ error?: any;
168
+ }[] | undefined;
169
+ }[];
170
+ pagination?: {
171
+ pageSize?: string | number | null | undefined;
172
+ nextToken?: string | null | undefined;
173
+ } | undefined;
174
+ }>;
185
175
  /**
186
176
  * Lists audit records with filtering and pagination.
187
177
  *
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAgC,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,WAAW,IAAI;IACpD,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,8CAA8C;IAC9C,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACjB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,qCAAqC;IACrC,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;CACpC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,WAAW,IAAI;IACzD,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,QAAQ,EAAE;QACR,2BAA2B;Q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IACU,WAAW,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAYpF;;;;;;;;;;;;;;;;;;OAkBG;IACU,SAAS,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAYhF;;;;;;;;;;;;;;;;;OAiBG;IACU,cAAc,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAYnF;;;;;;;;;;;OAWG;IACU,YAAY,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWvF"}
package/dist/service.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AuditEventBus } from "./events/bus.js";
2
- import { AuditRepository } from "./repository.js";
2
+ import { AuditRepository, } from "./repository.js";
3
3
  import { createTypedUpsertAuditSchema } from "./schema/service.js";
4
+ import { generateAuditId } from "./utils.js";
4
5
  /**
5
6
  * High-level service for managing audit records with typed App and ResourceType.
6
7
  *
@@ -119,7 +120,11 @@ export class AuditService {
119
120
  */
120
121
  async upsertItem(input) {
121
122
  const schema = createTypedUpsertAuditSchema(this.config.schemas.resourceReference);
122
- const item = schema.parse(input);
123
+ const parsed = schema.parse(input);
124
+ const item = {
125
+ ...parsed,
126
+ id: parsed.id ?? generateAuditId(),
127
+ };
123
128
  const now = new Date().toISOString();
124
129
  // Build current attempt record
125
130
  const currentAttempt = {
@@ -137,9 +142,9 @@ export class AuditService {
137
142
  .filter((resource) => !!resource.id)
138
143
  .map((resource) => ({
139
144
  ...item,
140
- ...resource,
141
145
  id: `${item.id}#${resource.app}.${resource.type}#${resource.id}`, // deterministic ID for retry correlation
142
- // Source
146
+ // Link the related resource back to the original audit target.
147
+ target: resource,
143
148
  source: item.target,
144
149
  rerunable: item.rerunable !== undefined ? item.rerunable : !!item.event,
145
150
  // Remove these (they are only needed on the parent)
@@ -153,6 +158,36 @@ export class AuditService {
153
158
  }
154
159
  await this.events?.upserted([item]);
155
160
  }
161
+ /**
162
+ * Lists audit records with filtering and pagination.
163
+ *
164
+ * Queries audits based on resource type and app.
165
+ * Results are paginated in descending tier and creation order.
166
+ *
167
+ * @param params - Query parameters for filtering
168
+ * @param pagination - Optional pagination settings
169
+ * @returns Paginated collection of audit records
170
+ * @throws Re-throws any storage errors after logging
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * const { items, pagination } = await service.listObjects({
175
+ * resource: { type: 'Order' },
176
+ * app: 'Orders',
177
+ * });
178
+ * ```
179
+ */
180
+ async listObjects(params, pagination) {
181
+ try {
182
+ return await this.storage.listObjects(params, pagination);
183
+ }
184
+ catch (error) {
185
+ this.logger.error("An error occurred while trying to list objects", {
186
+ error,
187
+ });
188
+ throw error;
189
+ }
190
+ }
156
191
  /**
157
192
  * Lists audit records with filtering and pagination.
158
193
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipboxlabs/aws-audit-sdk",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "AWS Audit SDK - Core SDK for audit logging and event management",
5
5
  "keywords": [
6
6
  "audit",