@flipboxlabs/aws-audit-sdk 1.2.2 → 1.4.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/dist/config.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import * as z from "zod/v4";
2
+ /**
3
+ * Default TTL for audit records in seconds (90 days).
4
+ */
5
+ export declare const DEFAULT_TTL_SECONDS: number;
2
6
  /**
3
7
  * Input configuration for defining audit apps and resource types.
4
8
  */
@@ -6,6 +10,12 @@ export interface AuditConfigInput {
6
10
  readonly apps: readonly string[];
7
11
  readonly resourceTypes: readonly string[];
8
12
  readonly service?: string;
13
+ /**
14
+ * Time-to-live for audit records in seconds.
15
+ * DynamoDB will automatically delete records after this period.
16
+ * @default 7776000 (90 days)
17
+ */
18
+ readonly ttlSeconds?: number;
9
19
  }
10
20
  /**
11
21
  * Creates an audit configuration object with typed schemas.
@@ -33,9 +43,9 @@ export interface AuditConfigInput {
33
43
  * config.schemas.app.parse('Invalid'); // ❌ throws
34
44
  * ```
35
45
  */
36
- export declare function defineAuditConfig<const C extends AuditConfigInput>(input: C): {
37
- service: string | undefined;
38
- } & C & {
46
+ export declare function defineAuditConfig<const C extends AuditConfigInput>(input: C): C & {
47
+ ttlSeconds: number;
48
+ readonly service: string | undefined;
39
49
  schemas: {
40
50
  app: z.ZodEnum<{
41
51
  [x: string]: string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;YAkB1D;QACZ,GAAG,oBAAM;QACT,YAAY,6BAAe;KAC5B;EAEJ;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;YAqB1D;QACZ,GAAG,oBAAM;QACT,YAAY,6BAAe;KAC5B;EAEJ;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
package/dist/config.js CHANGED
@@ -1,4 +1,8 @@
1
1
  import * as z from "zod/v4";
2
+ /**
3
+ * Default TTL for audit records in seconds (90 days).
4
+ */
5
+ export const DEFAULT_TTL_SECONDS = 60 * 60 * 24 * 90;
2
6
  /**
3
7
  * Creates an audit configuration object with typed schemas.
4
8
  *
@@ -36,8 +40,11 @@ export function defineAuditConfig(input) {
36
40
  }),
37
41
  };
38
42
  return {
39
- service: process.env.SERVICE,
40
43
  ...input,
44
+ ttlSeconds: input.ttlSeconds ?? DEFAULT_TTL_SECONDS,
45
+ get service() {
46
+ return input.service ?? process.env.SERVICE;
47
+ },
41
48
  schemas,
42
49
  _types: {},
43
50
  };
@@ -79,6 +79,10 @@ export declare const DynamoDB: {
79
79
  readonly LSI1_S_SORT_KEY: "LSI1_S_SK";
80
80
  /** LSI1 (Numeric) sort key */
81
81
  readonly LSI1_N_SORT_KEY: "LSI1_N_SK";
82
+ /** GSI2 (String-String) partition key - for status-based queries */
83
+ readonly GSI2_SS_PARTITION_KEY: "GSI2_SS_PK";
84
+ /** GSI2 (String-String) sort key - for status-based queries */
85
+ readonly GSI2_SS_SORT_KEY: "GSI2_SS_SK";
82
86
  };
83
87
  /** Secondary index names */
84
88
  readonly Indexes: {
@@ -86,6 +90,8 @@ export declare const DynamoDB: {
86
90
  readonly GSI1_SS: "GSI1_SS";
87
91
  /** Global Secondary Index 1 - String partition, Numeric sort */
88
92
  readonly GSI1_SN: "GSI1_SN";
93
+ /** Global Secondary Index 2 - String partition, String sort (status-based queries) */
94
+ readonly GSI2_SS: "GSI2_SS";
89
95
  /** Local Secondary Index 1 - String sort key */
90
96
  readonly LSI1_S: "LSI1_S";
91
97
  /** Local Secondary Index 1 - Numeric sort key */
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAE7C;;GAEG;AACH,KAAK,UAAU,GAAG;IAChB,wDAAwD;IACxD,GAAG,EAAE,MAAM,CAAC;IAEZ,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,KAAK,SAAS,GAAG,UAAU,GAAG;IAC5B,yCAAyC;IACzC,GAAG,EAAE;QACH,qCAAqC;QACrC,MAAM,EAAE,MAAM,CAAC;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CAAC;QACf,qBAAqB;QACrB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ;IACnB,oCAAoC;;QAElC,6DAA6D;iCAC7C,UAAU;QAC1B,4CAA4C;gCAC7B,SAAS;;IAE1B,mCAAmC;;QAEjC,4BAA4B;;QAE5B,uBAAuB;;QAGvB,yCAAyC;;QAEzC,oCAAoC;;QAGpC,yCAAyC;;QAEzC,oCAAoC;;QAGpC,6BAA6B;;QAE7B,8BAA8B;;QAG9B,oEAAoE;;QAEpE,+DAA+D;;;IAGjE,4BAA4B;;QAE1B,+DAA+D;;QAE/D,gEAAgE;;QAGhE,sFAAsF;;QAGtF,gDAAgD;;QAEhD,iDAAiD;;;IAGnD,8BAA8B;;QAE5B,2DAA2D;;;CAGrD,CAAC;AA0CX;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,WAAW;IACtB,wCAAwC;;QAEtC,8DAA8D;iCAC9C,UAAU;QAC1B,6CAA6C;gCAC9B,SAAS;;IAE1B,yCAAyC;;IAEzC,wDAAwD;;QAEtD,yDAAyD;;QAEzD,8CAA8C;;;CAGxC,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAClC,CAAC,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC"}
package/dist/constants.js CHANGED
@@ -57,6 +57,10 @@ export const DynamoDB = {
57
57
  LSI1_S_SORT_KEY: "LSI1_S_SK",
58
58
  /** LSI1 (Numeric) sort key */
59
59
  LSI1_N_SORT_KEY: "LSI1_N_SK",
60
+ /** GSI2 (String-String) partition key - for status-based queries */
61
+ GSI2_SS_PARTITION_KEY: "GSI2_SS_PK",
62
+ /** GSI2 (String-String) sort key - for status-based queries */
63
+ GSI2_SS_SORT_KEY: "GSI2_SS_SK",
60
64
  },
61
65
  /** Secondary index names */
62
66
  Indexes: {
@@ -64,6 +68,8 @@ export const DynamoDB = {
64
68
  GSI1_SS: "GSI1_SS",
65
69
  /** Global Secondary Index 1 - String partition, Numeric sort */
66
70
  GSI1_SN: "GSI1_SN",
71
+ /** Global Secondary Index 2 - String partition, String sort (status-based queries) */
72
+ GSI2_SS: "GSI2_SS",
67
73
  /** Local Secondary Index 1 - String sort key */
68
74
  LSI1_S: "LSI1_S",
69
75
  /** Local Secondary Index 1 - Numeric sort key */
@@ -1,8 +1,9 @@
1
1
  import type { Logger } from "@aws-lambda-powertools/logger";
2
2
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
3
3
  import type { NativeAttributeValue } from "@aws-sdk/util-dynamodb";
4
- import type { AuditConfig } from "./config.js";
4
+ import { type AuditConfig } from "./config.js";
5
5
  import { type Audit } from "./schema/audit.js";
6
+ import type { AnyStatus } from "./schema/log.js";
6
7
  import { type Pagination } from "./schema/model.js";
7
8
  import type { UpsertAuditInput } from "./schema/service.js";
8
9
  import type { AnyApp, AnyResourceType, InferApp, InferResourceType } from "./types.js";
@@ -87,6 +88,25 @@ export type TypedListTraceItems<C extends AuditConfig> = {
87
88
  id?: string;
88
89
  };
89
90
  };
91
+ /**
92
+ * Options for listing audit items by status with typed App and ResourceType.
93
+ * @typeParam C - The audit config type for type inference
94
+ */
95
+ export type TypedListByStatusOptions<C extends AuditConfig> = {
96
+ /** Tenant/organization identifier for multi-tenancy support (optional) */
97
+ tenantId?: string;
98
+ /** Status to filter by (success, warn, fail, skip) */
99
+ status: AnyStatus;
100
+ /** Optional application filter */
101
+ app?: InferApp<C>;
102
+ /** Optional resource filter */
103
+ resource?: {
104
+ /** Filter by resource type */
105
+ type?: InferResourceType<C>;
106
+ /** Filter by resource ID */
107
+ id?: string;
108
+ };
109
+ };
90
110
  /**
91
111
  * Repository for managing audit records in DynamoDB.
92
112
  *
@@ -276,6 +296,8 @@ export declare class AuditRepository<C extends AuditConfig> {
276
296
  id?: string | number | undefined;
277
297
  };
278
298
  operation: string;
299
+ updatedAt?: string | undefined;
300
+ createdAt?: string | undefined;
279
301
  tenantId?: string | undefined;
280
302
  source?: {
281
303
  app: string;
@@ -346,6 +368,62 @@ export declare class AuditRepository<C extends AuditConfig> {
346
368
  id?: string | number | undefined;
347
369
  };
348
370
  operation: string;
371
+ updatedAt?: string | undefined;
372
+ createdAt?: string | undefined;
373
+ tenantId?: string | undefined;
374
+ source?: {
375
+ app: string;
376
+ type: string;
377
+ id?: string | number | undefined;
378
+ } | undefined;
379
+ context?: Record<string, string | number | boolean | {
380
+ [key: string]: string | number | boolean | /*elided*/ any;
381
+ }> | undefined;
382
+ message?: string | undefined;
383
+ rerunable?: boolean | undefined;
384
+ trace?: string | undefined;
385
+ event?: {
386
+ detail: string | undefined;
387
+ source?: string | undefined;
388
+ "detail-type"?: string | undefined;
389
+ } | undefined;
390
+ error?: any;
391
+ attempts?: {
392
+ number: number;
393
+ status: "success" | "warn" | "fail" | "skip";
394
+ at: string;
395
+ error?: any;
396
+ }[] | undefined;
397
+ }[];
398
+ pagination?: {
399
+ pageSize?: string | number | null | undefined;
400
+ nextToken?: string | null | undefined;
401
+ } | undefined;
402
+ }>;
403
+ /**
404
+ * Lists audit records by status with date ordering and optional filters.
405
+ *
406
+ * Queries the GSI2_SS index to retrieve all audits with a specific status,
407
+ * ordered by creation date (most recent first by default).
408
+ * Supports optional filtering by app, resource type, and resource ID.
409
+ *
410
+ * @param params - Query parameters including status and optional filters
411
+ * @param pagination - Optional pagination settings (pageSize, nextToken)
412
+ * @returns Paginated collection of audit records in reverse date order
413
+ */
414
+ listByStatus(params: TypedListByStatusOptions<C>, pagination?: Pagination): Promise<{
415
+ items: {
416
+ id: string;
417
+ status: "success" | "warn" | "fail" | "skip";
418
+ tier: number;
419
+ target: {
420
+ app: string;
421
+ type: string;
422
+ id?: string | number | undefined;
423
+ };
424
+ operation: string;
425
+ updatedAt?: string | undefined;
426
+ createdAt?: string | undefined;
349
427
  tenantId?: string | undefined;
350
428
  source?: {
351
429
  app: string;
@@ -423,6 +501,18 @@ export declare class AuditRepository<C extends AuditConfig> {
423
501
  * @internal
424
502
  */
425
503
  private constructGSI1_SN;
504
+ /**
505
+ * Constructs GSI2_SS (String-String) index keys for status-based queries.
506
+ *
507
+ * The partition key is the status value (optionally prefixed with tenantId),
508
+ * and the sort key combines createdAt timestamp with id for date ordering
509
+ * while ensuring uniqueness.
510
+ *
511
+ * @param item - The audit storage item
512
+ * @returns GSI2_SS key attributes
513
+ * @internal
514
+ */
515
+ private constructGSI2_SS;
426
516
  /**
427
517
  * Constructs the TTL attribute for automatic item expiration.
428
518
  *
@@ -459,5 +549,13 @@ export declare class AuditRepository<C extends AuditConfig> {
459
549
  * @internal
460
550
  */
461
551
  private transformListItem;
552
+ /**
553
+ * Transforms a status listing item into an audit list item payload.
554
+ *
555
+ * @param item - Raw listing item from GSI2_SS query
556
+ * @returns Parsed audit list item payload
557
+ * @internal
558
+ */
559
+ private transformStatusListItem;
462
560
  }
463
561
  //# sourceMappingURL=repository.d.ts.map
@@ -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,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EACL,KAAK,KAAK,EAIX,MAAM,mBAAmB,CAAC;AAC3B,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;AASvF;;GAEG;AACH,MAAM,WAAW,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,CAAC,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAqEtF;;;;;;;;OAQG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;;;;;;;;OAUG;IACH,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;IAUzB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;CAahC"}
@@ -1,16 +1,12 @@
1
1
  import { BatchWriteItemCommand, DynamoDBClient, GetItemCommand, QueryCommand, UpdateItemCommand, } from "@aws-sdk/client-dynamodb";
2
2
  import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
3
+ import { DEFAULT_TTL_SECONDS } from "./config.js";
3
4
  import { DynamoDB } from "./constants.js";
4
5
  import { decodeNextPageToken, encodeNextPageToken } from "./repository.utils.js";
5
- import { AuditListItemPayloadSchema, AuditPayloadSchema, AuditSchema, } from "./schema/audit.js";
6
+ import { AuditPayloadSchema, AuditSchema } from "./schema/audit.js";
6
7
  import { PaginationCollectionSchema } from "./schema/model.js";
7
8
  import { AuditStorageSchema } from "./schema/storage.js";
8
9
  import { getTraceParts } from "./utils.js";
9
- /**
10
- * Default TTL for audit records in seconds (90 days).
11
- * Records will be automatically deleted by DynamoDB after this period.
12
- */
13
- const DEFAULT_TTL = 60 * 60 * 24 * 90; // 90 days
14
10
  /**
15
11
  * Repository for managing audit records in DynamoDB.
16
12
  *
@@ -165,7 +161,7 @@ export class AuditRepository {
165
161
  app: payload.target.app,
166
162
  }),
167
163
  ...this.constructSecondaryKeys(payload),
168
- ...this.constructTTLAttribute(DEFAULT_TTL),
164
+ ...this.constructTTLAttribute(this.config.ttlSeconds),
169
165
  ...payload,
170
166
  }, {
171
167
  removeUndefinedValues: true,
@@ -263,7 +259,7 @@ export class AuditRepository {
263
259
  app: payload.target.app,
264
260
  });
265
261
  const secondaryKeys = this.constructSecondaryKeys(payload);
266
- const ttlAttribute = this.constructTTLAttribute(DEFAULT_TTL);
262
+ const ttlAttribute = this.constructTTLAttribute(this.config.ttlSeconds);
267
263
  const expressionAttributeNames = {};
268
264
  const expressionAttributeValues = {
269
265
  ":emptyList": [],
@@ -451,6 +447,74 @@ export class AuditRepository {
451
447
  },
452
448
  });
453
449
  }
450
+ /**
451
+ * Lists audit records by status with date ordering and optional filters.
452
+ *
453
+ * Queries the GSI2_SS index to retrieve all audits with a specific status,
454
+ * ordered by creation date (most recent first by default).
455
+ * Supports optional filtering by app, resource type, and resource ID.
456
+ *
457
+ * @param params - Query parameters including status and optional filters
458
+ * @param pagination - Optional pagination settings (pageSize, nextToken)
459
+ * @returns Paginated collection of audit records in reverse date order
460
+ */
461
+ async listByStatus(params, pagination) {
462
+ const startKey = decodeNextPageToken(pagination?.nextToken);
463
+ const pageSize = Number(pagination?.pageSize || 100);
464
+ const pkBase = params.status;
465
+ const pk = params.tenantId ? `${params.tenantId}#${pkBase}` : pkBase;
466
+ const filters = [];
467
+ const ExpressionAttributeValues = {
468
+ ":PK": pk,
469
+ };
470
+ const ExpressionAttributeNames = {
471
+ "#PK": DynamoDB.Keys.GSI2_SS_PARTITION_KEY,
472
+ };
473
+ if (params?.resource?.id) {
474
+ Object.assign(ExpressionAttributeValues, {
475
+ ":resourceId": params.resource.id,
476
+ });
477
+ ExpressionAttributeNames["#target"] = "target";
478
+ ExpressionAttributeNames["#id"] = "id";
479
+ filters.push("#target.#id = :resourceId");
480
+ }
481
+ if (params?.resource?.type) {
482
+ Object.assign(ExpressionAttributeValues, {
483
+ ":resourceType": params.resource.type,
484
+ });
485
+ ExpressionAttributeNames["#target"] = "target";
486
+ ExpressionAttributeNames["#type"] = "type";
487
+ filters.push("#target.#type = :resourceType");
488
+ }
489
+ if (params?.app) {
490
+ Object.assign(ExpressionAttributeValues, {
491
+ ":app": params.app,
492
+ });
493
+ ExpressionAttributeNames["#target"] = "target";
494
+ ExpressionAttributeNames["#app"] = "app";
495
+ filters.push("#target.#app = :app");
496
+ }
497
+ // Audits with other resources will have a compound id, filter these out
498
+ Object.assign(ExpressionAttributeValues, { ":isParent": "#" });
499
+ filters.push("not contains(SK, :isParent)");
500
+ const { Items: items, LastEvaluatedKey: lastEvaluatedKey } = await this.client.send(new QueryCommand({
501
+ ScanIndexForward: false,
502
+ IndexName: DynamoDB.Indexes.GSI2_SS,
503
+ ExpressionAttributeValues: marshall(ExpressionAttributeValues),
504
+ ExpressionAttributeNames,
505
+ KeyConditionExpression: "#PK = :PK",
506
+ TableName: DynamoDB.Table.Name(),
507
+ Limit: pageSize,
508
+ ExclusiveStartKey: startKey ? marshall(startKey) : undefined,
509
+ FilterExpression: filters.length > 0 ? filters.join(" AND ") : undefined,
510
+ }));
511
+ return PaginationCollectionSchema(AuditPayloadSchema).parse({
512
+ items: items?.map((i) => this.transformStatusListItem(unmarshall(i))),
513
+ pagination: {
514
+ nextToken: lastEvaluatedKey ? encodeNextPageToken(unmarshall(lastEvaluatedKey)) : undefined,
515
+ },
516
+ });
517
+ }
454
518
  /**
455
519
  * Constructs the DynamoDB primary key from identifiers.
456
520
  *
@@ -490,6 +554,7 @@ export class AuditRepository {
490
554
  app: item.target.app,
491
555
  }),
492
556
  ...this.constructGSI1_SN(item),
557
+ ...this.constructGSI2_SS(item),
493
558
  };
494
559
  }
495
560
  /**
@@ -536,6 +601,26 @@ export class AuditRepository {
536
601
  [DynamoDB.Keys.GSI1_SN_SORT_KEY]: stage,
537
602
  };
538
603
  }
604
+ /**
605
+ * Constructs GSI2_SS (String-String) index keys for status-based queries.
606
+ *
607
+ * The partition key is the status value (optionally prefixed with tenantId),
608
+ * and the sort key combines createdAt timestamp with id for date ordering
609
+ * while ensuring uniqueness.
610
+ *
611
+ * @param item - The audit storage item
612
+ * @returns GSI2_SS key attributes
613
+ * @internal
614
+ */
615
+ constructGSI2_SS(item) {
616
+ const pkBase = item.status;
617
+ return {
618
+ [DynamoDB.Keys.GSI2_SS_PARTITION_KEY]: (item.tenantId
619
+ ? `${item.tenantId}#${pkBase}`
620
+ : pkBase),
621
+ [DynamoDB.Keys.GSI2_SS_SORT_KEY]: `${item.createdAt}#${item.id}`,
622
+ };
623
+ }
539
624
  /**
540
625
  * Constructs the TTL attribute for automatic item expiration.
541
626
  *
@@ -544,7 +629,7 @@ export class AuditRepository {
544
629
  * @returns TTL attribute with Unix timestamp in seconds
545
630
  * @internal
546
631
  */
547
- constructTTLAttribute(ttlSeconds = DEFAULT_TTL, date) {
632
+ constructTTLAttribute(ttlSeconds = DEFAULT_TTL_SECONDS, date) {
548
633
  const ttl = date || new Date();
549
634
  if (ttlSeconds) {
550
635
  ttl.setSeconds(ttl.getSeconds() + ttlSeconds);
@@ -579,7 +664,7 @@ export class AuditRepository {
579
664
  */
580
665
  transformTraceListItem(item) {
581
666
  const [id] = item.SK.split("#");
582
- return AuditListItemPayloadSchema.parse({
667
+ return AuditPayloadSchema.parse({
583
668
  trace: `${item.GSI1_SN_PK}:${item.GSI1_SN_SK}`,
584
669
  ...item,
585
670
  id: id,
@@ -594,10 +679,28 @@ export class AuditRepository {
594
679
  */
595
680
  transformListItem(item) {
596
681
  const [id] = item.SK.split("#");
597
- return AuditListItemPayloadSchema.parse({
682
+ return AuditPayloadSchema.parse({
598
683
  trace: `${item.GSI1_SN_PK}:${item.GSI1_SN_SK}`,
599
684
  ...item,
600
685
  id: id,
601
686
  });
602
687
  }
688
+ /**
689
+ * Transforms a status listing item into an audit list item payload.
690
+ *
691
+ * @param item - Raw listing item from GSI2_SS query
692
+ * @returns Parsed audit list item payload
693
+ * @internal
694
+ */
695
+ transformStatusListItem(item) {
696
+ const [id] = item.SK.split("#");
697
+ const trace = item.GSI1_SN_PK !== undefined && item.GSI1_SN_SK !== undefined
698
+ ? `${item.GSI1_SN_PK}:${item.GSI1_SN_SK}`
699
+ : undefined;
700
+ return AuditPayloadSchema.parse({
701
+ trace,
702
+ ...item,
703
+ id: id,
704
+ });
705
+ }
603
706
  }
@@ -92,6 +92,8 @@ export type Audit = z.output<typeof AuditSchema>;
92
92
  * suitable for JSON serialization in API responses.
93
93
  */
94
94
  export declare const AuditPayloadSchema: z.ZodObject<{
95
+ updatedAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
96
+ createdAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
95
97
  id: z.ZodString;
96
98
  tenantId: z.ZodOptional<z.ZodString>;
97
99
  status: z.ZodEnum<{
@@ -142,61 +144,4 @@ export declare const AuditPayloadSchema: z.ZodObject<{
142
144
  * Output type for audit payloads.
143
145
  */
144
146
  export type AuditPayload = z.output<typeof AuditPayloadSchema>;
145
- /**
146
- * Schema for audit list item payloads.
147
- *
148
- * Same as AuditPayloadSchema, used for items in list responses
149
- * where a lighter payload is sufficient.
150
- */
151
- export declare const AuditListItemPayloadSchema: z.ZodObject<{
152
- id: z.ZodString;
153
- tenantId: z.ZodOptional<z.ZodString>;
154
- status: z.ZodEnum<{
155
- success: "success";
156
- warn: "warn";
157
- fail: "fail";
158
- skip: "skip";
159
- }>;
160
- tier: z.ZodDefault<z.ZodNumber>;
161
- target: z.ZodObject<{
162
- app: z.ZodString;
163
- id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
164
- type: z.ZodString;
165
- }, z.core.$strip>;
166
- source: z.ZodOptional<z.ZodObject<{
167
- app: z.ZodString;
168
- id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
169
- type: z.ZodString;
170
- }, z.core.$strip>>;
171
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<string | number | boolean | {
172
- [key: string]: string | number | boolean | /*elided*/ any;
173
- }, unknown, z.core.$ZodTypeInternals<string | number | boolean | {
174
- [key: string]: string | number | boolean | /*elided*/ any;
175
- }, unknown>>>>;
176
- operation: z.ZodString;
177
- message: z.ZodOptional<z.ZodString>;
178
- rerunable: z.ZodOptional<z.ZodBoolean>;
179
- trace: z.ZodOptional<z.ZodString>;
180
- event: z.ZodOptional<z.ZodObject<{
181
- source: z.ZodOptional<z.ZodString>;
182
- "detail-type": z.ZodOptional<z.ZodString>;
183
- detail: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>>, z.ZodTransform<string | undefined, string | Record<string, any> | undefined>>;
184
- }, z.core.$strip>>;
185
- error: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodCustom<Error, Error>, z.ZodTransform<any, Error>>, z.ZodRecord<z.ZodAny, z.ZodAny>]>>;
186
- attempts: z.ZodOptional<z.ZodArray<z.ZodObject<{
187
- number: z.ZodNumber;
188
- status: z.ZodEnum<{
189
- success: "success";
190
- warn: "warn";
191
- fail: "fail";
192
- skip: "skip";
193
- }>;
194
- error: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodCustom<Error, Error>, z.ZodTransform<any, Error>>, z.ZodRecord<z.ZodAny, z.ZodAny>]>>;
195
- at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
196
- }, z.core.$strip>>>;
197
- }, z.core.$strip>;
198
- /**
199
- * Output type for audit list item payloads.
200
- */
201
- export type AuditAuditListItemPayload = z.output<typeof AuditListItemPayloadSchema>;
202
147
  //# sourceMappingURL=audit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/schema/audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAMtB,CAAC;AAEH;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAa,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC"}
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/schema/audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAMtB,CAAC;AAEH;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAM7B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import * as z from "zod/v4";
2
- import { BaseSchema, DateTimeObjectSchema } from "./common.js";
2
+ import { BaseSchema, DateTimeObjectSchema, DateTimeStringSchema } from "./common.js";
3
3
  /**
4
4
  * Schema for fully-hydrated audit records retrieved from storage.
5
5
  *
@@ -38,11 +38,10 @@ export const AuditSchema = z.object({
38
38
  * Uses the base schema without timestamp transformation,
39
39
  * suitable for JSON serialization in API responses.
40
40
  */
41
- export const AuditPayloadSchema = BaseSchema;
42
- /**
43
- * Schema for audit list item payloads.
44
- *
45
- * Same as AuditPayloadSchema, used for items in list responses
46
- * where a lighter payload is sufficient.
47
- */
48
- export const AuditListItemPayloadSchema = BaseSchema;
41
+ export const AuditPayloadSchema = z.object({
42
+ ...BaseSchema.shape,
43
+ /** Last update timestamp - ISO string suitable for JSON API responses */
44
+ updatedAt: DateTimeStringSchema.optional(),
45
+ /** Creation timestamp - ISO string suitable for JSON API responses */
46
+ createdAt: DateTimeStringSchema.optional(),
47
+ });
package/dist/service.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { AuditConfig } from "./config.js";
3
3
  import { AuditEventBus } from "./events/bus.js";
4
4
  import { AuditRepository } from "./repository.js";
5
5
  import type { Audit } from "./schema/audit.js";
6
+ import type { AnyStatus } from "./schema/log.js";
6
7
  import type { Pagination } from "./schema/model.js";
7
8
  import { type UpsertAuditInput } from "./schema/service.js";
8
9
  import type { InferApp, InferResourceType } from "./types.js";
@@ -58,6 +59,25 @@ export type TypedListTraceItems<C extends AuditConfig> = {
58
59
  id?: string;
59
60
  };
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
+ };
61
81
  /**
62
82
  * High-level service for managing audit records with typed App and ResourceType.
63
83
  *
@@ -192,6 +212,8 @@ export declare class AuditService<C extends AuditConfig> {
192
212
  id?: string | number | undefined;
193
213
  };
194
214
  operation: string;
215
+ updatedAt?: string | undefined;
216
+ createdAt?: string | undefined;
195
217
  tenantId?: string | undefined;
196
218
  source?: {
197
219
  app: string;
@@ -251,6 +273,63 @@ export declare class AuditService<C extends AuditConfig> {
251
273
  id?: string | number | undefined;
252
274
  };
253
275
  operation: string;
276
+ updatedAt?: string | undefined;
277
+ createdAt?: string | undefined;
278
+ tenantId?: string | undefined;
279
+ source?: {
280
+ app: string;
281
+ type: string;
282
+ id?: string | number | undefined;
283
+ } | undefined;
284
+ context?: Record<string, string | number | boolean | {
285
+ [key: string]: string | number | boolean | /*elided*/ any;
286
+ }> | undefined;
287
+ message?: string | undefined;
288
+ rerunable?: boolean | undefined;
289
+ trace?: string | undefined;
290
+ event?: {
291
+ detail: string | undefined;
292
+ source?: string | undefined;
293
+ "detail-type"?: string | undefined;
294
+ } | undefined;
295
+ error?: any;
296
+ attempts?: {
297
+ number: number;
298
+ status: "success" | "warn" | "fail" | "skip";
299
+ at: string;
300
+ error?: any;
301
+ }[] | undefined;
302
+ }[];
303
+ pagination?: {
304
+ pageSize?: string | number | null | undefined;
305
+ nextToken?: string | null | undefined;
306
+ } | undefined;
307
+ }>;
308
+ /**
309
+ * Lists audit records by status with date ordering and pagination.
310
+ *
311
+ * Retrieves all audits with a specific status (e.g., 'fail', 'warn'),
312
+ * ordered by creation date (most recent first).
313
+ * Supports optional filtering by app, resource type, and resource ID.
314
+ *
315
+ * @param params - Query parameters including status and optional filters
316
+ * @param pagination - Optional pagination settings
317
+ * @returns Paginated collection of status-filtered audit records
318
+ * @throws Re-throws any storage errors after logging
319
+ */
320
+ listByStatus(params: TypedListByStatusOptions<C>, pagination?: Pagination): Promise<{
321
+ items: {
322
+ id: string;
323
+ status: "success" | "warn" | "fail" | "skip";
324
+ tier: number;
325
+ target: {
326
+ app: string;
327
+ type: string;
328
+ id?: string | number | undefined;
329
+ };
330
+ operation: string;
331
+ updatedAt?: string | undefined;
332
+ createdAt?: string | undefined;
254
333
  tenantId?: string | undefined;
255
334
  source?: {
256
335
  app: string;
@@ -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,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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8C/D;;;;;;;;;;;;;;;;;;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
@@ -212,4 +212,27 @@ export class AuditService {
212
212
  throw error;
213
213
  }
214
214
  }
215
+ /**
216
+ * Lists audit records by status with date ordering and pagination.
217
+ *
218
+ * Retrieves all audits with a specific status (e.g., 'fail', 'warn'),
219
+ * ordered by creation date (most recent first).
220
+ * Supports optional filtering by app, resource type, and resource ID.
221
+ *
222
+ * @param params - Query parameters including status and optional filters
223
+ * @param pagination - Optional pagination settings
224
+ * @returns Paginated collection of status-filtered audit records
225
+ * @throws Re-throws any storage errors after logging
226
+ */
227
+ async listByStatus(params, pagination) {
228
+ try {
229
+ return await this.storage.listByStatus(params, pagination);
230
+ }
231
+ catch (error) {
232
+ this.logger.error("An error occurred while trying to list items by status", {
233
+ error,
234
+ });
235
+ throw error;
236
+ }
237
+ }
215
238
  }
@@ -3,11 +3,11 @@
3
3
  * Provides sample apps and resource types for testing.
4
4
  */
5
5
  export declare const testConfig: {
6
- service: string | undefined;
7
- } & {
8
6
  readonly apps: readonly ["App1", "TestApp"];
9
7
  readonly resourceTypes: readonly ["Unknown", "User", "Order"];
10
8
  } & {
9
+ ttlSeconds: number;
10
+ readonly service: string | undefined;
11
11
  schemas: {
12
12
  app: import("zod/v4").ZodEnum<{
13
13
  [x: string]: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipboxlabs/aws-audit-sdk",
3
- "version": "1.2.2",
3
+ "version": "1.4.0",
4
4
  "description": "AWS Audit SDK - Core SDK for audit logging and event management",
5
5
  "keywords": [
6
6
  "audit",