@flipboxlabs/aws-audit-sdk 1.1.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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/audits.d.ts +188 -0
- package/dist/audits.d.ts.map +1 -0
- package/dist/audits.js +225 -0
- package/dist/batch/batch-processor.d.ts +81 -0
- package/dist/batch/batch-processor.d.ts.map +1 -0
- package/dist/batch/batch-processor.js +102 -0
- package/dist/batch/index.d.ts +2 -0
- package/dist/batch/index.d.ts.map +1 -0
- package/dist/batch/index.js +1 -0
- package/dist/config.d.ts +65 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/constants.d.ts +147 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +191 -0
- package/dist/events/batch-handler.d.ts +62 -0
- package/dist/events/batch-handler.d.ts.map +1 -0
- package/dist/events/batch-handler.js +92 -0
- package/dist/events/bus.d.ts +79 -0
- package/dist/events/bus.d.ts.map +1 -0
- package/dist/events/bus.js +86 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/middleware/middy.d.ts +66 -0
- package/dist/middleware/middy.d.ts.map +1 -0
- package/dist/middleware/middy.js +105 -0
- package/dist/repository.d.ts +421 -0
- package/dist/repository.d.ts.map +1 -0
- package/dist/repository.js +486 -0
- package/dist/repository.utils.d.ts +37 -0
- package/dist/repository.utils.d.ts.map +1 -0
- package/dist/repository.utils.js +70 -0
- package/dist/schema/audit.d.ts +202 -0
- package/dist/schema/audit.d.ts.map +1 -0
- package/dist/schema/audit.js +48 -0
- package/dist/schema/common.d.ts +128 -0
- package/dist/schema/common.d.ts.map +1 -0
- package/dist/schema/common.js +148 -0
- package/dist/schema/index.d.ts +27 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +26 -0
- package/dist/schema/log.d.ts +211 -0
- package/dist/schema/log.d.ts.map +1 -0
- package/dist/schema/log.js +179 -0
- package/dist/schema/model.d.ts +110 -0
- package/dist/schema/model.d.ts.map +1 -0
- package/dist/schema/model.js +86 -0
- package/dist/schema/service.d.ts +189 -0
- package/dist/schema/service.d.ts.map +1 -0
- package/dist/schema/service.js +89 -0
- package/dist/schema/storage.d.ts +105 -0
- package/dist/schema/storage.d.ts.map +1 -0
- package/dist/schema/storage.js +63 -0
- package/dist/service.d.ts +285 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +237 -0
- package/dist/test-config.d.ts +56 -0
- package/dist/test-config.d.ts.map +1 -0
- package/dist/test-config.js +24 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +231 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +313 -0
- package/package.json +85 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
/**
|
|
3
|
+
* Schema for audit upsert operations via the AuditService.
|
|
4
|
+
*
|
|
5
|
+
* Extends _BaseLogAuditSchema with additional fields for service-layer operations:
|
|
6
|
+
* - `id`: Optional identifier (auto-generated if not provided)
|
|
7
|
+
* - `rerunable`: Flag indicating if the audit's operation can be retried
|
|
8
|
+
* - `attempts`: History of execution attempts for retry tracking
|
|
9
|
+
* - `createdAt`: Original creation timestamp (preserved on retries)
|
|
10
|
+
*
|
|
11
|
+
* This schema is used by {@link AuditService.upsertItem} for validating
|
|
12
|
+
* audit entries before storage and event emission.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const audit = UpsertAuditSchema.parse({
|
|
17
|
+
* operation: 'processPayment',
|
|
18
|
+
* target: { app: 'Payments', type: 'Payment', id: 'pay-123' },
|
|
19
|
+
* status: 'success',
|
|
20
|
+
* rerunable: true,
|
|
21
|
+
* event: {
|
|
22
|
+
* source: 'payments.service',
|
|
23
|
+
* 'detail-type': 'PaymentRequested',
|
|
24
|
+
* detail: { amount: 99.99 },
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // With explicit ID for idempotent upserts
|
|
32
|
+
* const audit = UpsertAuditSchema.parse({
|
|
33
|
+
* id: 'idempotent-key-123',
|
|
34
|
+
* operation: 'createOrder',
|
|
35
|
+
* target: { app: 'Orders', type: 'Order', id: 'order-456' },
|
|
36
|
+
* status: 'success',
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const UpsertAuditSchema: z.ZodObject<{
|
|
41
|
+
id: z.ZodOptional<z.ZodString>;
|
|
42
|
+
rerunable: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
attempts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
44
|
+
number: z.ZodNumber;
|
|
45
|
+
status: z.ZodEnum<{
|
|
46
|
+
success: "success";
|
|
47
|
+
warn: "warn";
|
|
48
|
+
fail: "fail";
|
|
49
|
+
skip: "skip";
|
|
50
|
+
}>;
|
|
51
|
+
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>]>>;
|
|
52
|
+
at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
|
|
53
|
+
}, z.core.$strip>>>;
|
|
54
|
+
createdAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
|
|
55
|
+
operation: z.ZodString;
|
|
56
|
+
tenantId: z.ZodOptional<z.ZodString>;
|
|
57
|
+
tier: z.ZodDefault<z.ZodNumber>;
|
|
58
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
59
|
+
success: "success";
|
|
60
|
+
warn: "warn";
|
|
61
|
+
fail: "fail";
|
|
62
|
+
skip: "skip";
|
|
63
|
+
}>>;
|
|
64
|
+
target: z.ZodObject<{
|
|
65
|
+
app: z.ZodString;
|
|
66
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
67
|
+
type: z.ZodString;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
source: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
app: z.ZodString;
|
|
71
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
72
|
+
type: z.ZodString;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<string | number | boolean | {
|
|
75
|
+
[key: string]: string | number | boolean | /*elided*/ any;
|
|
76
|
+
}, unknown, z.core.$ZodTypeInternals<string | number | boolean | {
|
|
77
|
+
[key: string]: string | number | boolean | /*elided*/ any;
|
|
78
|
+
}, unknown>>>>;
|
|
79
|
+
resources: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
|
|
80
|
+
app: z.ZodString;
|
|
81
|
+
type: z.ZodString;
|
|
82
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
83
|
+
}, z.core.$strip>>, z.ZodSet<z.ZodObject<{
|
|
84
|
+
app: z.ZodString;
|
|
85
|
+
type: z.ZodString;
|
|
86
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
87
|
+
}, z.core.$strip>>]>>, z.ZodTransform<{
|
|
88
|
+
app: string;
|
|
89
|
+
type: string;
|
|
90
|
+
id?: string | number | undefined;
|
|
91
|
+
}[] | undefined, Set<{
|
|
92
|
+
app: string;
|
|
93
|
+
type: string;
|
|
94
|
+
id?: string | number | undefined;
|
|
95
|
+
}> | {
|
|
96
|
+
app: string;
|
|
97
|
+
type: string;
|
|
98
|
+
id?: string | number | undefined;
|
|
99
|
+
}[] | undefined>>;
|
|
100
|
+
message: z.ZodOptional<z.ZodString>;
|
|
101
|
+
trace: z.ZodOptional<z.ZodString>;
|
|
102
|
+
event: z.ZodOptional<z.ZodObject<{
|
|
103
|
+
source: z.ZodOptional<z.ZodString>;
|
|
104
|
+
"detail-type": z.ZodOptional<z.ZodString>;
|
|
105
|
+
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>>;
|
|
106
|
+
}, z.core.$strip>>;
|
|
107
|
+
error: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Error, Error>]>>, z.ZodTransform<string | undefined, string | Error | undefined>>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
/**
|
|
110
|
+
* Input type for UpsertAuditSchema.
|
|
111
|
+
*
|
|
112
|
+
* Use this type when building audit objects for upsert operations.
|
|
113
|
+
*/
|
|
114
|
+
export type UpsertAuditInput = z.input<typeof UpsertAuditSchema>;
|
|
115
|
+
/**
|
|
116
|
+
* Output type from UpsertAuditSchema.
|
|
117
|
+
*
|
|
118
|
+
* Validated and transformed audit ready for storage.
|
|
119
|
+
*/
|
|
120
|
+
export type UpsertAudit = z.output<typeof UpsertAuditSchema>;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a UpsertAuditSchema with typed app and resourceType schemas.
|
|
123
|
+
*
|
|
124
|
+
* Use this when you have a config with strict app/resourceType enums
|
|
125
|
+
* to get runtime validation against those specific values.
|
|
126
|
+
*
|
|
127
|
+
* @param resourceReferenceSchema - The typed resource reference schema from config.schemas.resourceReference
|
|
128
|
+
* @returns A UpsertAuditSchema that validates against the provided resource reference schema
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const config = defineAuditConfig({
|
|
133
|
+
* apps: ['Orders', 'Inventory'] as const,
|
|
134
|
+
* resourceTypes: ['Order', 'Product'] as const,
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* const typedSchema = createTypedUpsertAuditSchema(config.schemas.resourceReference);
|
|
138
|
+
* typedSchema.parse({
|
|
139
|
+
* operation: 'createOrder',
|
|
140
|
+
* target: { app: 'Orders', type: 'Order', id: '123' },
|
|
141
|
+
* }); // Validates app/type against config
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function createTypedUpsertAuditSchema<T extends z.ZodObject<{
|
|
145
|
+
app: z.ZodTypeAny;
|
|
146
|
+
type: z.ZodTypeAny;
|
|
147
|
+
id: z.ZodTypeAny;
|
|
148
|
+
}>>(resourceReferenceSchema: T): z.ZodObject<{
|
|
149
|
+
id: z.ZodOptional<z.ZodString>;
|
|
150
|
+
rerunable: z.ZodOptional<z.ZodBoolean>;
|
|
151
|
+
attempts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
152
|
+
number: z.ZodNumber;
|
|
153
|
+
status: z.ZodEnum<{
|
|
154
|
+
success: "success";
|
|
155
|
+
warn: "warn";
|
|
156
|
+
fail: "fail";
|
|
157
|
+
skip: "skip";
|
|
158
|
+
}>;
|
|
159
|
+
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>]>>;
|
|
160
|
+
at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
|
|
161
|
+
}, z.core.$strip>>>;
|
|
162
|
+
createdAt: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
|
|
163
|
+
operation: z.ZodString;
|
|
164
|
+
tenantId: z.ZodOptional<z.ZodString>;
|
|
165
|
+
tier: z.ZodDefault<z.ZodNumber>;
|
|
166
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
167
|
+
success: "success";
|
|
168
|
+
warn: "warn";
|
|
169
|
+
fail: "fail";
|
|
170
|
+
skip: "skip";
|
|
171
|
+
}>>;
|
|
172
|
+
target: T;
|
|
173
|
+
source: z.ZodOptional<T>;
|
|
174
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<string | number | boolean | {
|
|
175
|
+
[key: string]: string | number | boolean | /*elided*/ any;
|
|
176
|
+
}, unknown, z.core.$ZodTypeInternals<string | number | boolean | {
|
|
177
|
+
[key: string]: string | number | boolean | /*elided*/ any;
|
|
178
|
+
}, unknown>>>>;
|
|
179
|
+
resources: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<T>, z.ZodSet<T>]>>, z.ZodTransform<z.core.output<T>[] | undefined, z.core.output<T>[] | Set<z.core.output<T>> | undefined>>;
|
|
180
|
+
message: z.ZodOptional<z.ZodString>;
|
|
181
|
+
trace: z.ZodOptional<z.ZodString>;
|
|
182
|
+
event: z.ZodOptional<z.ZodObject<{
|
|
183
|
+
source: z.ZodOptional<z.ZodString>;
|
|
184
|
+
"detail-type": z.ZodOptional<z.ZodString>;
|
|
185
|
+
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>>;
|
|
186
|
+
}, z.core.$strip>>;
|
|
187
|
+
error: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Error, Error>]>>, z.ZodTransform<string | undefined, string | Error | undefined>>;
|
|
188
|
+
}, z.core.$strip>;
|
|
189
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/schema/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAU5B,CAAC;AAEH;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,4BAA4B,CAC3C,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC;IACrB,GAAG,EAAE,CAAC,CAAC,UAAU,CAAC;IAClB,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC;IACnB,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC;CACjB,CAAC,EACD,uBAAuB,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAc3B"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { AttemptSchema, DateTimeStringSchema } from "./common.js";
|
|
3
|
+
import { _BaseLogAuditSchema, createTypedLogAuditSchema } from "./log.js";
|
|
4
|
+
/**
|
|
5
|
+
* Schema for audit upsert operations via the AuditService.
|
|
6
|
+
*
|
|
7
|
+
* Extends _BaseLogAuditSchema with additional fields for service-layer operations:
|
|
8
|
+
* - `id`: Optional identifier (auto-generated if not provided)
|
|
9
|
+
* - `rerunable`: Flag indicating if the audit's operation can be retried
|
|
10
|
+
* - `attempts`: History of execution attempts for retry tracking
|
|
11
|
+
* - `createdAt`: Original creation timestamp (preserved on retries)
|
|
12
|
+
*
|
|
13
|
+
* This schema is used by {@link AuditService.upsertItem} for validating
|
|
14
|
+
* audit entries before storage and event emission.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const audit = UpsertAuditSchema.parse({
|
|
19
|
+
* operation: 'processPayment',
|
|
20
|
+
* target: { app: 'Payments', type: 'Payment', id: 'pay-123' },
|
|
21
|
+
* status: 'success',
|
|
22
|
+
* rerunable: true,
|
|
23
|
+
* event: {
|
|
24
|
+
* source: 'payments.service',
|
|
25
|
+
* 'detail-type': 'PaymentRequested',
|
|
26
|
+
* detail: { amount: 99.99 },
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // With explicit ID for idempotent upserts
|
|
34
|
+
* const audit = UpsertAuditSchema.parse({
|
|
35
|
+
* id: 'idempotent-key-123',
|
|
36
|
+
* operation: 'createOrder',
|
|
37
|
+
* target: { app: 'Orders', type: 'Order', id: 'order-456' },
|
|
38
|
+
* status: 'success',
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export const UpsertAuditSchema = z.object({
|
|
43
|
+
..._BaseLogAuditSchema.shape,
|
|
44
|
+
/** Optional audit ID - auto-generated if not provided */
|
|
45
|
+
id: z.string().optional(),
|
|
46
|
+
/** Whether the audited operation can be re-run/retried */
|
|
47
|
+
rerunable: z.boolean().optional(),
|
|
48
|
+
/** History of execution attempts for retry tracking */
|
|
49
|
+
attempts: z.array(AttemptSchema).optional(),
|
|
50
|
+
/** Original creation timestamp (preserved on retries) */
|
|
51
|
+
createdAt: DateTimeStringSchema.optional(),
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Creates a UpsertAuditSchema with typed app and resourceType schemas.
|
|
55
|
+
*
|
|
56
|
+
* Use this when you have a config with strict app/resourceType enums
|
|
57
|
+
* to get runtime validation against those specific values.
|
|
58
|
+
*
|
|
59
|
+
* @param resourceReferenceSchema - The typed resource reference schema from config.schemas.resourceReference
|
|
60
|
+
* @returns A UpsertAuditSchema that validates against the provided resource reference schema
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const config = defineAuditConfig({
|
|
65
|
+
* apps: ['Orders', 'Inventory'] as const,
|
|
66
|
+
* resourceTypes: ['Order', 'Product'] as const,
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* const typedSchema = createTypedUpsertAuditSchema(config.schemas.resourceReference);
|
|
70
|
+
* typedSchema.parse({
|
|
71
|
+
* operation: 'createOrder',
|
|
72
|
+
* target: { app: 'Orders', type: 'Order', id: '123' },
|
|
73
|
+
* }); // Validates app/type against config
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function createTypedUpsertAuditSchema(resourceReferenceSchema) {
|
|
77
|
+
const typedLogSchema = createTypedLogAuditSchema(resourceReferenceSchema);
|
|
78
|
+
return z.object({
|
|
79
|
+
...typedLogSchema.shape,
|
|
80
|
+
/** Optional audit ID - auto-generated if not provided */
|
|
81
|
+
id: z.string().optional(),
|
|
82
|
+
/** Whether the audited operation can be re-run/retried */
|
|
83
|
+
rerunable: z.boolean().optional(),
|
|
84
|
+
/** History of execution attempts for retry tracking */
|
|
85
|
+
attempts: z.array(AttemptSchema).optional(),
|
|
86
|
+
/** Original creation timestamp (preserved on retries) */
|
|
87
|
+
createdAt: DateTimeStringSchema.optional(),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
/**
|
|
3
|
+
* Schema for audit records being written to DynamoDB storage.
|
|
4
|
+
*
|
|
5
|
+
* Extends BaseSchema with storage-specific fields and transformations:
|
|
6
|
+
* - `id`: Auto-generated KSUID if not provided
|
|
7
|
+
* - `updatedAt`: Defaults to current time, normalized to ISO string
|
|
8
|
+
* - `createdAt`: Defaults to current time, normalized to ISO string
|
|
9
|
+
*
|
|
10
|
+
* This schema handles the conversion between application types (Date)
|
|
11
|
+
* and storage types (ISO string) for DynamoDB compatibility.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // With auto-generated values
|
|
16
|
+
* const storage = AuditStorageSchema.parse({
|
|
17
|
+
* operation: 'createUser',
|
|
18
|
+
* status: 'success',
|
|
19
|
+
* target: { app: 'MyApp', type: 'User', id: 'user-123' },
|
|
20
|
+
* tier: 2,
|
|
21
|
+
* });
|
|
22
|
+
* // storage.id is auto-generated KSUID
|
|
23
|
+
* // storage.updatedAt is current time as ISO string
|
|
24
|
+
* // storage.createdAt is current time as ISO string
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // With explicit Date objects
|
|
30
|
+
* const storage = AuditStorageSchema.parse({
|
|
31
|
+
* id: 'custom-id',
|
|
32
|
+
* operation: 'updateUser',
|
|
33
|
+
* status: 'success',
|
|
34
|
+
* target: { app: 'MyApp', type: 'User', id: 'user-123' },
|
|
35
|
+
* tier: 2,
|
|
36
|
+
* updatedAt: new Date(),
|
|
37
|
+
* createdAt: new Date('2024-01-01'),
|
|
38
|
+
* });
|
|
39
|
+
* // Dates are converted to ISO strings
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const AuditStorageSchema: z.ZodObject<{
|
|
43
|
+
id: z.ZodDefault<z.ZodString>;
|
|
44
|
+
updatedAt: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
|
|
45
|
+
createdAt: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
|
|
46
|
+
tenantId: z.ZodOptional<z.ZodString>;
|
|
47
|
+
status: z.ZodEnum<{
|
|
48
|
+
success: "success";
|
|
49
|
+
warn: "warn";
|
|
50
|
+
fail: "fail";
|
|
51
|
+
skip: "skip";
|
|
52
|
+
}>;
|
|
53
|
+
tier: z.ZodDefault<z.ZodNumber>;
|
|
54
|
+
target: z.ZodObject<{
|
|
55
|
+
app: z.ZodString;
|
|
56
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
57
|
+
type: z.ZodString;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
source: z.ZodOptional<z.ZodObject<{
|
|
60
|
+
app: z.ZodString;
|
|
61
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
62
|
+
type: z.ZodString;
|
|
63
|
+
}, z.core.$strip>>;
|
|
64
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<string | number | boolean | {
|
|
65
|
+
[key: string]: string | number | boolean | /*elided*/ any;
|
|
66
|
+
}, unknown, z.core.$ZodTypeInternals<string | number | boolean | {
|
|
67
|
+
[key: string]: string | number | boolean | /*elided*/ any;
|
|
68
|
+
}, unknown>>>>;
|
|
69
|
+
operation: z.ZodString;
|
|
70
|
+
message: z.ZodOptional<z.ZodString>;
|
|
71
|
+
rerunable: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
trace: z.ZodOptional<z.ZodString>;
|
|
73
|
+
event: z.ZodOptional<z.ZodObject<{
|
|
74
|
+
source: z.ZodOptional<z.ZodString>;
|
|
75
|
+
"detail-type": z.ZodOptional<z.ZodString>;
|
|
76
|
+
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>>;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
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>]>>;
|
|
79
|
+
attempts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
80
|
+
number: z.ZodNumber;
|
|
81
|
+
status: z.ZodEnum<{
|
|
82
|
+
success: "success";
|
|
83
|
+
warn: "warn";
|
|
84
|
+
fail: "fail";
|
|
85
|
+
skip: "skip";
|
|
86
|
+
}>;
|
|
87
|
+
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>]>>;
|
|
88
|
+
at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
|
|
89
|
+
}, z.core.$strip>>>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
/**
|
|
92
|
+
* Input type for AuditStorageSchema.
|
|
93
|
+
*
|
|
94
|
+
* Accepts Date objects or ISO strings for timestamps.
|
|
95
|
+
* ID is optional (auto-generated if not provided).
|
|
96
|
+
*/
|
|
97
|
+
export type AuditStorageInput = z.input<typeof AuditStorageSchema>;
|
|
98
|
+
/**
|
|
99
|
+
* Output type from AuditStorageSchema.
|
|
100
|
+
*
|
|
101
|
+
* All timestamps are ISO strings, ID is always present.
|
|
102
|
+
* Ready for DynamoDB storage.
|
|
103
|
+
*/
|
|
104
|
+
export type AuditStorage = z.output<typeof AuditStorageSchema>;
|
|
105
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/schema/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmB7B,CAAC;AAEH;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { generateAuditId } from "../utils.js";
|
|
3
|
+
import { BaseSchema, DateTimeStringSchema } from "./common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Schema for audit records being written to DynamoDB storage.
|
|
6
|
+
*
|
|
7
|
+
* Extends BaseSchema with storage-specific fields and transformations:
|
|
8
|
+
* - `id`: Auto-generated KSUID if not provided
|
|
9
|
+
* - `updatedAt`: Defaults to current time, normalized to ISO string
|
|
10
|
+
* - `createdAt`: Defaults to current time, normalized to ISO string
|
|
11
|
+
*
|
|
12
|
+
* This schema handles the conversion between application types (Date)
|
|
13
|
+
* and storage types (ISO string) for DynamoDB compatibility.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // With auto-generated values
|
|
18
|
+
* const storage = AuditStorageSchema.parse({
|
|
19
|
+
* operation: 'createUser',
|
|
20
|
+
* status: 'success',
|
|
21
|
+
* target: { app: 'MyApp', type: 'User', id: 'user-123' },
|
|
22
|
+
* tier: 2,
|
|
23
|
+
* });
|
|
24
|
+
* // storage.id is auto-generated KSUID
|
|
25
|
+
* // storage.updatedAt is current time as ISO string
|
|
26
|
+
* // storage.createdAt is current time as ISO string
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // With explicit Date objects
|
|
32
|
+
* const storage = AuditStorageSchema.parse({
|
|
33
|
+
* id: 'custom-id',
|
|
34
|
+
* operation: 'updateUser',
|
|
35
|
+
* status: 'success',
|
|
36
|
+
* target: { app: 'MyApp', type: 'User', id: 'user-123' },
|
|
37
|
+
* tier: 2,
|
|
38
|
+
* updatedAt: new Date(),
|
|
39
|
+
* createdAt: new Date('2024-01-01'),
|
|
40
|
+
* });
|
|
41
|
+
* // Dates are converted to ISO strings
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const AuditStorageSchema = z.object({
|
|
45
|
+
...BaseSchema.shape,
|
|
46
|
+
/**
|
|
47
|
+
* Unique audit identifier.
|
|
48
|
+
* Auto-generates a KSUID if not provided.
|
|
49
|
+
*/
|
|
50
|
+
id: z.string().default(generateAuditId()),
|
|
51
|
+
/**
|
|
52
|
+
* Last update timestamp.
|
|
53
|
+
* Accepts ISO string or Date, outputs ISO string.
|
|
54
|
+
* Defaults to current time.
|
|
55
|
+
*/
|
|
56
|
+
updatedAt: DateTimeStringSchema.default(() => new Date().toISOString()),
|
|
57
|
+
/**
|
|
58
|
+
* Creation timestamp.
|
|
59
|
+
* Accepts ISO string or Date, outputs ISO string.
|
|
60
|
+
* Defaults to current time.
|
|
61
|
+
*/
|
|
62
|
+
createdAt: DateTimeStringSchema.default(() => new Date().toISOString()),
|
|
63
|
+
});
|