@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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dist/audits.d.ts +188 -0
  4. package/dist/audits.d.ts.map +1 -0
  5. package/dist/audits.js +225 -0
  6. package/dist/batch/batch-processor.d.ts +81 -0
  7. package/dist/batch/batch-processor.d.ts.map +1 -0
  8. package/dist/batch/batch-processor.js +102 -0
  9. package/dist/batch/index.d.ts +2 -0
  10. package/dist/batch/index.d.ts.map +1 -0
  11. package/dist/batch/index.js +1 -0
  12. package/dist/config.d.ts +65 -0
  13. package/dist/config.d.ts.map +1 -0
  14. package/dist/config.js +44 -0
  15. package/dist/constants.d.ts +147 -0
  16. package/dist/constants.d.ts.map +1 -0
  17. package/dist/constants.js +191 -0
  18. package/dist/events/batch-handler.d.ts +62 -0
  19. package/dist/events/batch-handler.d.ts.map +1 -0
  20. package/dist/events/batch-handler.js +92 -0
  21. package/dist/events/bus.d.ts +79 -0
  22. package/dist/events/bus.d.ts.map +1 -0
  23. package/dist/events/bus.js +86 -0
  24. package/dist/events/index.d.ts +3 -0
  25. package/dist/events/index.d.ts.map +1 -0
  26. package/dist/events/index.js +2 -0
  27. package/dist/index.d.ts +9 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +8 -0
  30. package/dist/middleware/middy.d.ts +66 -0
  31. package/dist/middleware/middy.d.ts.map +1 -0
  32. package/dist/middleware/middy.js +105 -0
  33. package/dist/repository.d.ts +421 -0
  34. package/dist/repository.d.ts.map +1 -0
  35. package/dist/repository.js +486 -0
  36. package/dist/repository.utils.d.ts +37 -0
  37. package/dist/repository.utils.d.ts.map +1 -0
  38. package/dist/repository.utils.js +70 -0
  39. package/dist/schema/audit.d.ts +202 -0
  40. package/dist/schema/audit.d.ts.map +1 -0
  41. package/dist/schema/audit.js +48 -0
  42. package/dist/schema/common.d.ts +128 -0
  43. package/dist/schema/common.d.ts.map +1 -0
  44. package/dist/schema/common.js +148 -0
  45. package/dist/schema/index.d.ts +27 -0
  46. package/dist/schema/index.d.ts.map +1 -0
  47. package/dist/schema/index.js +26 -0
  48. package/dist/schema/log.d.ts +211 -0
  49. package/dist/schema/log.d.ts.map +1 -0
  50. package/dist/schema/log.js +179 -0
  51. package/dist/schema/model.d.ts +110 -0
  52. package/dist/schema/model.d.ts.map +1 -0
  53. package/dist/schema/model.js +86 -0
  54. package/dist/schema/service.d.ts +189 -0
  55. package/dist/schema/service.d.ts.map +1 -0
  56. package/dist/schema/service.js +89 -0
  57. package/dist/schema/storage.d.ts +105 -0
  58. package/dist/schema/storage.d.ts.map +1 -0
  59. package/dist/schema/storage.js +63 -0
  60. package/dist/service.d.ts +285 -0
  61. package/dist/service.d.ts.map +1 -0
  62. package/dist/service.js +237 -0
  63. package/dist/test-config.d.ts +56 -0
  64. package/dist/test-config.d.ts.map +1 -0
  65. package/dist/test-config.js +24 -0
  66. package/dist/types.d.ts +40 -0
  67. package/dist/types.d.ts.map +1 -0
  68. package/dist/types.js +1 -0
  69. package/dist/utils.d.ts +231 -0
  70. package/dist/utils.d.ts.map +1 -0
  71. package/dist/utils.js +313 -0
  72. package/package.json +85 -0
@@ -0,0 +1,202 @@
1
+ import * as z from "zod/v4";
2
+ /**
3
+ * Schema for fully-hydrated audit records retrieved from storage.
4
+ *
5
+ * Extends BaseSchema with timestamp fields that are transformed
6
+ * from ISO strings to Date objects for easier manipulation.
7
+ *
8
+ * This schema is used when reading audit records from DynamoDB,
9
+ * where timestamps are stored as ISO 8601 strings.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const audit = AuditSchema.parse({
14
+ * id: 'audit-123',
15
+ * operation: 'createUser',
16
+ * status: 'success',
17
+ * target: { app: 'MyApp', type: 'User', id: 'user-456' },
18
+ * tier: 2,
19
+ * updatedAt: '2024-01-15T10:30:00.000Z',
20
+ * createdAt: '2024-01-15T10:30:00.000Z',
21
+ * });
22
+ *
23
+ * // audit.updatedAt is now a Date object
24
+ * console.log(audit.updatedAt?.toISOString());
25
+ * ```
26
+ */
27
+ export declare const AuditSchema: z.ZodObject<{
28
+ updatedAt: z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<Date, string | Date>>;
29
+ createdAt: z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<Date, string | Date>>;
30
+ id: z.ZodString;
31
+ tenantId: z.ZodOptional<z.ZodString>;
32
+ status: z.ZodEnum<{
33
+ success: "success";
34
+ warn: "warn";
35
+ fail: "fail";
36
+ skip: "skip";
37
+ }>;
38
+ tier: z.ZodDefault<z.ZodNumber>;
39
+ target: z.ZodObject<{
40
+ app: z.ZodString;
41
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
42
+ type: z.ZodString;
43
+ }, z.core.$strip>;
44
+ source: z.ZodOptional<z.ZodObject<{
45
+ app: z.ZodString;
46
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
47
+ type: z.ZodString;
48
+ }, z.core.$strip>>;
49
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<string | number | boolean | {
50
+ [key: string]: string | number | boolean | /*elided*/ any;
51
+ }, unknown, z.core.$ZodTypeInternals<string | number | boolean | {
52
+ [key: string]: string | number | boolean | /*elided*/ any;
53
+ }, unknown>>>>;
54
+ operation: z.ZodString;
55
+ message: z.ZodOptional<z.ZodString>;
56
+ rerunable: z.ZodOptional<z.ZodBoolean>;
57
+ trace: z.ZodOptional<z.ZodString>;
58
+ event: z.ZodOptional<z.ZodObject<{
59
+ source: z.ZodOptional<z.ZodString>;
60
+ "detail-type": z.ZodOptional<z.ZodString>;
61
+ 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>>;
62
+ }, z.core.$strip>>;
63
+ 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>]>>;
64
+ attempts: z.ZodOptional<z.ZodArray<z.ZodObject<{
65
+ number: z.ZodNumber;
66
+ status: z.ZodEnum<{
67
+ success: "success";
68
+ warn: "warn";
69
+ fail: "fail";
70
+ skip: "skip";
71
+ }>;
72
+ 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>]>>;
73
+ at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
74
+ }, z.core.$strip>>>;
75
+ }, z.core.$strip>;
76
+ /**
77
+ * Input type for AuditSchema.
78
+ *
79
+ * Accepts ISO 8601 datetime strings for timestamps.
80
+ */
81
+ export type AuditInput = z.input<typeof AuditSchema>;
82
+ /**
83
+ * Output type from AuditSchema.
84
+ *
85
+ * Timestamps are Date objects (or undefined).
86
+ */
87
+ export type Audit = z.output<typeof AuditSchema>;
88
+ /**
89
+ * Schema for audit payloads in API responses.
90
+ *
91
+ * Uses the base schema without timestamp transformation,
92
+ * suitable for JSON serialization in API responses.
93
+ */
94
+ export declare const AuditPayloadSchema: z.ZodObject<{
95
+ id: z.ZodString;
96
+ tenantId: z.ZodOptional<z.ZodString>;
97
+ status: z.ZodEnum<{
98
+ success: "success";
99
+ warn: "warn";
100
+ fail: "fail";
101
+ skip: "skip";
102
+ }>;
103
+ tier: z.ZodDefault<z.ZodNumber>;
104
+ target: z.ZodObject<{
105
+ app: z.ZodString;
106
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
107
+ type: z.ZodString;
108
+ }, z.core.$strip>;
109
+ source: z.ZodOptional<z.ZodObject<{
110
+ app: z.ZodString;
111
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
112
+ type: z.ZodString;
113
+ }, z.core.$strip>>;
114
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<string | number | boolean | {
115
+ [key: string]: string | number | boolean | /*elided*/ any;
116
+ }, unknown, z.core.$ZodTypeInternals<string | number | boolean | {
117
+ [key: string]: string | number | boolean | /*elided*/ any;
118
+ }, unknown>>>>;
119
+ operation: z.ZodString;
120
+ message: z.ZodOptional<z.ZodString>;
121
+ rerunable: z.ZodOptional<z.ZodBoolean>;
122
+ trace: z.ZodOptional<z.ZodString>;
123
+ event: z.ZodOptional<z.ZodObject<{
124
+ source: z.ZodOptional<z.ZodString>;
125
+ "detail-type": z.ZodOptional<z.ZodString>;
126
+ 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>>;
127
+ }, z.core.$strip>>;
128
+ 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>]>>;
129
+ attempts: z.ZodOptional<z.ZodArray<z.ZodObject<{
130
+ number: z.ZodNumber;
131
+ status: z.ZodEnum<{
132
+ success: "success";
133
+ warn: "warn";
134
+ fail: "fail";
135
+ skip: "skip";
136
+ }>;
137
+ 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>]>>;
138
+ at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
139
+ }, z.core.$strip>>>;
140
+ }, z.core.$strip>;
141
+ /**
142
+ * Output type for audit payloads.
143
+ */
144
+ 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
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +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,CAC/C,OAAO,0BAA0B,CACjC,CAAC"}
@@ -0,0 +1,48 @@
1
+ import * as z from "zod/v4";
2
+ import { BaseSchema, DateTimeObjectSchema } from "./common.js";
3
+ /**
4
+ * Schema for fully-hydrated audit records retrieved from storage.
5
+ *
6
+ * Extends BaseSchema with timestamp fields that are transformed
7
+ * from ISO strings to Date objects for easier manipulation.
8
+ *
9
+ * This schema is used when reading audit records from DynamoDB,
10
+ * where timestamps are stored as ISO 8601 strings.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const audit = AuditSchema.parse({
15
+ * id: 'audit-123',
16
+ * operation: 'createUser',
17
+ * status: 'success',
18
+ * target: { app: 'MyApp', type: 'User', id: 'user-456' },
19
+ * tier: 2,
20
+ * updatedAt: '2024-01-15T10:30:00.000Z',
21
+ * createdAt: '2024-01-15T10:30:00.000Z',
22
+ * });
23
+ *
24
+ * // audit.updatedAt is now a Date object
25
+ * console.log(audit.updatedAt?.toISOString());
26
+ * ```
27
+ */
28
+ export const AuditSchema = z.object({
29
+ ...BaseSchema.shape,
30
+ /** Last update timestamp - ISO string transformed to Date */
31
+ updatedAt: DateTimeObjectSchema,
32
+ /** Creation timestamp - ISO string transformed to Date */
33
+ createdAt: DateTimeObjectSchema,
34
+ });
35
+ /**
36
+ * Schema for audit payloads in API responses.
37
+ *
38
+ * Uses the base schema without timestamp transformation,
39
+ * suitable for JSON serialization in API responses.
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;
@@ -0,0 +1,128 @@
1
+ import * as z from "zod/v4";
2
+ /**
3
+ * Escalation tiers for audit visibility
4
+ * - INTERNAL (1): Internal system audits, not shown to end users
5
+ * - INFO (2): Informational audits, shown in detailed views
6
+ * - PUBLIC (3): Public audits, shown in summary views
7
+ */
8
+ export declare const Tier: {
9
+ readonly INTERNAL: 1;
10
+ readonly INFO: 2;
11
+ readonly PUBLIC: 3;
12
+ };
13
+ export type AnyTier = (typeof Tier)[keyof typeof Tier];
14
+ /**
15
+ * Schema for audit status values (success, warn, fail, skip)
16
+ */
17
+ export declare const StatusSchema: z.ZodEnum<{
18
+ success: "success";
19
+ warn: "warn";
20
+ fail: "fail";
21
+ skip: "skip";
22
+ }>;
23
+ /**
24
+ * Schema for referencing a resource within an application
25
+ * Used to identify the target or source of an audit
26
+ */
27
+ declare const ResourceReferenceSchema: z.ZodObject<{
28
+ app: z.ZodString;
29
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
30
+ type: z.ZodString;
31
+ }, z.core.$strip>;
32
+ export type ResourceReference = z.output<typeof ResourceReferenceSchema>;
33
+ /**
34
+ * Schema for additional related resources
35
+ * Extends ResourceReferenceSchema for linking secondary resources to an audit
36
+ */
37
+ declare const AdditionalResourceSchema: z.ZodObject<{
38
+ app: z.ZodString;
39
+ type: z.ZodString;
40
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
41
+ }, z.core.$strip>;
42
+ export type AdditionalResource = z.output<typeof AdditionalResourceSchema>;
43
+ /**
44
+ * Recursive type for context values
45
+ * Supports strings, numbers, booleans, and nested objects
46
+ */
47
+ type ContextValue = string | number | boolean | {
48
+ [key: string]: ContextValue;
49
+ };
50
+ export declare const DateTimeObjectSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<Date, string | Date>>;
51
+ /**
52
+ * Schema for datetime fields that accept ISO strings or Date objects.
53
+ * Transforms Date objects to ISO strings for storage compatibility.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * DateTimeSchema.parse("2024-01-01T12:00:00.000Z"); // "2024-01-01T12:00:00.000Z"
58
+ * DateTimeSchema.parse(new Date()); // "2024-01-15T10:30:00.000Z"
59
+ * ```
60
+ */
61
+ export declare const DateTimeStringSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>;
62
+ /**
63
+ * Schema for tracking individual retry attempts
64
+ * Each attempt records the outcome and timing of a single execution
65
+ */
66
+ export declare const AttemptSchema: z.ZodObject<{
67
+ number: z.ZodNumber;
68
+ status: z.ZodEnum<{
69
+ success: "success";
70
+ warn: "warn";
71
+ fail: "fail";
72
+ skip: "skip";
73
+ }>;
74
+ 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>]>>;
75
+ at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
76
+ }, z.core.$strip>;
77
+ export type Attempt = z.output<typeof AttemptSchema>;
78
+ /**
79
+ * Base schema for audit records
80
+ * Internal use only within the schema directory - not exported from index
81
+ *
82
+ * @internal
83
+ */
84
+ export declare const BaseSchema: z.ZodObject<{
85
+ id: z.ZodString;
86
+ tenantId: z.ZodOptional<z.ZodString>;
87
+ status: z.ZodEnum<{
88
+ success: "success";
89
+ warn: "warn";
90
+ fail: "fail";
91
+ skip: "skip";
92
+ }>;
93
+ tier: z.ZodDefault<z.ZodNumber>;
94
+ target: z.ZodObject<{
95
+ app: z.ZodString;
96
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
97
+ type: z.ZodString;
98
+ }, z.core.$strip>;
99
+ source: z.ZodOptional<z.ZodObject<{
100
+ app: z.ZodString;
101
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
102
+ type: z.ZodString;
103
+ }, z.core.$strip>>;
104
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<ContextValue, unknown, z.core.$ZodTypeInternals<ContextValue, unknown>>>>;
105
+ operation: z.ZodString;
106
+ message: z.ZodOptional<z.ZodString>;
107
+ rerunable: z.ZodOptional<z.ZodBoolean>;
108
+ trace: z.ZodOptional<z.ZodString>;
109
+ event: z.ZodOptional<z.ZodObject<{
110
+ source: z.ZodOptional<z.ZodString>;
111
+ "detail-type": z.ZodOptional<z.ZodString>;
112
+ 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>>;
113
+ }, z.core.$strip>>;
114
+ 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>]>>;
115
+ attempts: z.ZodOptional<z.ZodArray<z.ZodObject<{
116
+ number: z.ZodNumber;
117
+ status: z.ZodEnum<{
118
+ success: "success";
119
+ warn: "warn";
120
+ fail: "fail";
121
+ skip: "skip";
122
+ }>;
123
+ 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>]>>;
124
+ at: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodCustom<Date, Date>]>, z.ZodTransform<string, string | Date>>>;
125
+ }, z.core.$strip>>>;
126
+ }, z.core.$strip>;
127
+ export {};
128
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/schema/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;;;;GAKG;AACH,eAAO,MAAM,IAAI;;;;CAIP,CAAC;AACX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,OAAO,IAAI,CAAC,CAAC;AAOvD;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;EAAgC,CAAC;AAc1D;;;GAGG;AACH,QAAA,MAAM,uBAAuB;;;;iBAI3B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEzE;;;GAGG;AACH,QAAA,MAAM,wBAAwB;;;;iBAE5B,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE3E;;;GAGG;AACH,KAAK,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAC;AAwChF,eAAO,MAAM,oBAAoB,kHAEE,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,oHAEoC,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;iBASxB,CAAC;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6BrB,CAAC"}
@@ -0,0 +1,148 @@
1
+ import * as z from "zod/v4";
2
+ import { Status } from "./log.js";
3
+ import { EventBridgeEventSchema } from "./model.js";
4
+ /**
5
+ * Escalation tiers for audit visibility
6
+ * - INTERNAL (1): Internal system audits, not shown to end users
7
+ * - INFO (2): Informational audits, shown in detailed views
8
+ * - PUBLIC (3): Public audits, shown in summary views
9
+ */
10
+ export const Tier = {
11
+ INTERNAL: 1,
12
+ INFO: 2,
13
+ PUBLIC: 3,
14
+ };
15
+ /**
16
+ * Schema for escalation tier values (1-3)
17
+ */
18
+ const TierSchema = z.number().int().gte(1).lte(3);
19
+ /**
20
+ * Schema for audit status values (success, warn, fail, skip)
21
+ */
22
+ export const StatusSchema = z.enum(Object.values(Status));
23
+ /**
24
+ * Schema for application identifiers.
25
+ * Accepts any string; use config.schemas.app for strict validation.
26
+ */
27
+ const AppSchema = z.string();
28
+ /**
29
+ * Schema for resource type identifiers.
30
+ * Accepts any string; use config.schemas.resourceType for strict validation.
31
+ */
32
+ const ResourceTypeSchema = z.string();
33
+ /**
34
+ * Schema for referencing a resource within an application
35
+ * Used to identify the target or source of an audit
36
+ */
37
+ const ResourceReferenceSchema = z.object({
38
+ app: AppSchema,
39
+ id: z.union([z.string(), z.number()]).optional(),
40
+ type: ResourceTypeSchema,
41
+ });
42
+ /**
43
+ * Schema for additional related resources
44
+ * Extends ResourceReferenceSchema for linking secondary resources to an audit
45
+ */
46
+ const AdditionalResourceSchema = ResourceReferenceSchema.extend({
47
+ id: z.union([z.string(), z.number()]).optional(),
48
+ });
49
+ /**
50
+ * Schema for recursive context values
51
+ * Allows nested key-value structures for storing audit metadata
52
+ */
53
+ const RecursiveContextValueSchema = z.union([
54
+ z.string(),
55
+ z.number(),
56
+ z.boolean(),
57
+ z.lazy(() => z.record(z.string(), RecursiveContextValueSchema)),
58
+ ]);
59
+ /**
60
+ * Schema for audit context - a key-value store for additional metadata
61
+ */
62
+ const ContextSchema = z.record(z.string(), RecursiveContextValueSchema);
63
+ /**
64
+ * Schema for error details in audits and attempts.
65
+ * Handles string errors (with optional JSON parsing), Error instances, and plain objects.
66
+ */
67
+ const ErrorSchema = z
68
+ .union([
69
+ z.string().transform((error) => {
70
+ try {
71
+ return JSON.parse(error);
72
+ }
73
+ catch {
74
+ return error;
75
+ }
76
+ }),
77
+ z
78
+ .instanceof(Error)
79
+ .transform((error) => JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))),
80
+ z.record(z.any(), z.any()),
81
+ ])
82
+ .optional();
83
+ export const DateTimeObjectSchema = z
84
+ .union([z.iso.datetime(), z.instanceof(Date)])
85
+ .transform((val) => new Date(val));
86
+ /**
87
+ * Schema for datetime fields that accept ISO strings or Date objects.
88
+ * Transforms Date objects to ISO strings for storage compatibility.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * DateTimeSchema.parse("2024-01-01T12:00:00.000Z"); // "2024-01-01T12:00:00.000Z"
93
+ * DateTimeSchema.parse(new Date()); // "2024-01-15T10:30:00.000Z"
94
+ * ```
95
+ */
96
+ export const DateTimeStringSchema = z
97
+ .union([z.iso.datetime(), z.instanceof(Date)])
98
+ .transform((val) => (val instanceof Date ? val.toISOString() : val));
99
+ /**
100
+ * Schema for tracking individual retry attempts
101
+ * Each attempt records the outcome and timing of a single execution
102
+ */
103
+ export const AttemptSchema = z.object({
104
+ /** Sequential attempt number (1-indexed) */
105
+ number: z.number().int().min(1),
106
+ /** Outcome of this attempt */
107
+ status: StatusSchema,
108
+ /** Error details if the attempt failed */
109
+ error: ErrorSchema,
110
+ /** ISO timestamp when this attempt occurred */
111
+ at: DateTimeStringSchema.default(() => new Date().toISOString()),
112
+ });
113
+ /**
114
+ * Base schema for audit records
115
+ * Internal use only within the schema directory - not exported from index
116
+ *
117
+ * @internal
118
+ */
119
+ export const BaseSchema = z.object({
120
+ /** Unique identifier for the audit record */
121
+ id: z.string(),
122
+ /** Tenant identifier for multi-tenancy support (optional) */
123
+ tenantId: z.string().optional(),
124
+ /** Current status of the audited operation */
125
+ status: StatusSchema,
126
+ /** Escalation tier for visibility (defaults to INFO) */
127
+ tier: TierSchema.default(2),
128
+ /** The primary resource being audited */
129
+ target: ResourceReferenceSchema,
130
+ /** The resource that initiated the operation (optional) */
131
+ source: ResourceReferenceSchema.optional(),
132
+ /** Additional metadata as key-value pairs */
133
+ context: ContextSchema.optional(),
134
+ /** Name of the operation being audited */
135
+ operation: z.string(),
136
+ /** Human-readable description of the audit */
137
+ message: z.string().optional(),
138
+ /** Whether this audit can be re-run/retried */
139
+ rerunable: z.boolean().optional(),
140
+ /** Trace identifier for distributed tracing */
141
+ trace: z.string().optional(),
142
+ /** Original EventBridge event that triggered this audit */
143
+ event: EventBridgeEventSchema.optional(),
144
+ /** Error details if the operation failed */
145
+ error: ErrorSchema,
146
+ /** History of all execution attempts for retry tracking */
147
+ attempts: z.array(AttemptSchema).optional(),
148
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Schema module barrel file.
3
+ *
4
+ * Re-exports all schema definitions, types, and validation utilities
5
+ * for use throughout the audit SDK.
6
+ *
7
+ * @module schema
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * AuditSchema,
13
+ * createTypedLogAuditSchema,
14
+ * Status,
15
+ * Tier,
16
+ * type Audit,
17
+ * type LogAuditInput,
18
+ * } from '@flipboxlabs/aws-audit-sdk/schema';
19
+ * ```
20
+ */
21
+ export * from "./audit.js";
22
+ export { type AdditionalResource, type AnyTier, type ResourceReference, Tier, } from "./common.js";
23
+ export { type AnyStatus, createTypedLogAuditSchema, type LogAuditInput, Status, } from "./log.js";
24
+ export * from "./model.js";
25
+ export * from "./service.js";
26
+ export * from "./storage.js";
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACtB,IAAI,GACJ,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,SAAS,EACd,yBAAyB,EACzB,KAAK,aAAa,EAClB,MAAM,GACN,MAAM,UAAU,CAAC;AAClB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Schema module barrel file.
3
+ *
4
+ * Re-exports all schema definitions, types, and validation utilities
5
+ * for use throughout the audit SDK.
6
+ *
7
+ * @module schema
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * AuditSchema,
13
+ * createTypedLogAuditSchema,
14
+ * Status,
15
+ * Tier,
16
+ * type Audit,
17
+ * type LogAuditInput,
18
+ * } from '@flipboxlabs/aws-audit-sdk/schema';
19
+ * ```
20
+ */
21
+ export * from "./audit.js";
22
+ export { Tier, } from "./common.js";
23
+ export { createTypedLogAuditSchema, Status, } from "./log.js";
24
+ export * from "./model.js";
25
+ export * from "./service.js";
26
+ export * from "./storage.js";