@flipboxlabs/aws-audit-sdk 1.2.2 → 1.2.3
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 +13 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -1
- package/dist/repository.d.ts +1 -1
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +4 -8
- package/dist/test-config.d.ts +2 -2
- package/package.json +1 -1
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
|
-
|
|
38
|
-
|
|
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;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -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;
|
|
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
|
};
|
package/dist/repository.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
4
|
+
import { type AuditConfig } from "./config.js";
|
|
5
5
|
import { type Audit } from "./schema/audit.js";
|
|
6
6
|
import { type Pagination } from "./schema/model.js";
|
|
7
7
|
import type { UpsertAuditInput } from "./schema/service.js";
|
package/dist/repository.d.ts.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../src/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAA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B;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAU9B;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;CAS1B"}
|
package/dist/repository.js
CHANGED
|
@@ -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
6
|
import { AuditListItemPayloadSchema, 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(
|
|
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(
|
|
262
|
+
const ttlAttribute = this.constructTTLAttribute(this.config.ttlSeconds);
|
|
267
263
|
const expressionAttributeNames = {};
|
|
268
264
|
const expressionAttributeValues = {
|
|
269
265
|
":emptyList": [],
|
|
@@ -544,7 +540,7 @@ export class AuditRepository {
|
|
|
544
540
|
* @returns TTL attribute with Unix timestamp in seconds
|
|
545
541
|
* @internal
|
|
546
542
|
*/
|
|
547
|
-
constructTTLAttribute(ttlSeconds =
|
|
543
|
+
constructTTLAttribute(ttlSeconds = DEFAULT_TTL_SECONDS, date) {
|
|
548
544
|
const ttl = date || new Date();
|
|
549
545
|
if (ttlSeconds) {
|
|
550
546
|
ttl.setSeconds(ttl.getSeconds() + ttlSeconds);
|
package/dist/test-config.d.ts
CHANGED
|
@@ -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;
|