@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,211 @@
1
+ import * as z from "zod/v4";
2
+ /**
3
+ * Audit operation status values.
4
+ *
5
+ * Used to indicate the outcome of an audited operation:
6
+ * - `SUCCESS`: Operation completed successfully
7
+ * - `WARN`: Operation completed with warnings
8
+ * - `FAIL`: Operation failed
9
+ * - `SKIP`: Operation was skipped
10
+ */
11
+ export declare const Status: {
12
+ readonly SUCCESS: "success";
13
+ readonly WARN: "warn";
14
+ readonly FAIL: "fail";
15
+ readonly SKIP: "skip";
16
+ };
17
+ /**
18
+ * Union type of all valid status values.
19
+ */
20
+ export type AnyStatus = (typeof Status)[keyof typeof Status];
21
+ /**
22
+ * Schema for escalation tier values (1-3).
23
+ * @internal
24
+ */
25
+ export declare const TierSchema: z.ZodNumber;
26
+ /**
27
+ * Schema for audit status enum values.
28
+ * @internal
29
+ */
30
+ export declare const StatusSchema: z.ZodEnum<{
31
+ success: "success";
32
+ warn: "warn";
33
+ fail: "fail";
34
+ skip: "skip";
35
+ }>;
36
+ /**
37
+ * Schema for application identifier values.
38
+ * Accepts any string; use config.schemas.app for strict validation.
39
+ * @internal
40
+ */
41
+ export declare const AppSchema: z.ZodString;
42
+ /**
43
+ * Schema for resource type values.
44
+ * Accepts any string; use config.schemas.resourceType for strict validation.
45
+ * @internal
46
+ */
47
+ export declare const ResourceTypeSchema: z.ZodString;
48
+ /**
49
+ * Schema for resource references (target/source).
50
+ *
51
+ * Identifies a resource within an application by app, type, and optional ID.
52
+ * @internal
53
+ */
54
+ export declare const ResourceReferenceSchema: 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
+ /**
60
+ * Schema for additional related resources.
61
+ *
62
+ * Same structure as ResourceReferenceSchema, used for linking
63
+ * secondary resources to an audit entry.
64
+ * @internal
65
+ */
66
+ export declare const AdditionalResourceSchema: z.ZodObject<{
67
+ app: z.ZodString;
68
+ type: z.ZodString;
69
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
70
+ }, z.core.$strip>;
71
+ /**
72
+ * Recursive type for context values.
73
+ *
74
+ * Supports primitives (string, number, boolean) and nested objects
75
+ * for flexible metadata storage.
76
+ */
77
+ type ContextValue = string | number | boolean | {
78
+ [key: string]: ContextValue;
79
+ };
80
+ /**
81
+ * Schema for the context object - a flexible key-value store.
82
+ * @internal
83
+ */
84
+ export declare const ContextSchema: z.ZodRecord<z.ZodString, z.ZodType<ContextValue, unknown, z.core.$ZodTypeInternals<ContextValue, unknown>>>;
85
+ /**
86
+ * Base schema for audit entries destined for CloudWatch Logs.
87
+ *
88
+ * @internal Use `createTypedLogAuditSchema` instead for type-safe validation
89
+ * with your config's app and resourceType enums.
90
+ *
91
+ * This schema accepts any string for app and resourceType values.
92
+ * For strict validation against configured values, use the factory function.
93
+ *
94
+ * **Transformations:**
95
+ * - `resources`: Set is converted to Array
96
+ * - `error`: Error instances are serialized to JSON strings
97
+ * - `tier`: Defaults to 2 (INFO) if not provided
98
+ * - `status`: Defaults to 'success' if not provided
99
+ */
100
+ export declare const _BaseLogAuditSchema: z.ZodObject<{
101
+ id: z.ZodOptional<z.ZodString>;
102
+ operation: z.ZodString;
103
+ tenantId: z.ZodOptional<z.ZodString>;
104
+ tier: z.ZodDefault<z.ZodNumber>;
105
+ status: z.ZodDefault<z.ZodEnum<{
106
+ success: "success";
107
+ warn: "warn";
108
+ fail: "fail";
109
+ skip: "skip";
110
+ }>>;
111
+ target: z.ZodObject<{
112
+ app: z.ZodString;
113
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
114
+ type: z.ZodString;
115
+ }, z.core.$strip>;
116
+ source: z.ZodOptional<z.ZodObject<{
117
+ app: z.ZodString;
118
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
119
+ type: z.ZodString;
120
+ }, z.core.$strip>>;
121
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<ContextValue, unknown, z.core.$ZodTypeInternals<ContextValue, unknown>>>>;
122
+ resources: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
123
+ app: z.ZodString;
124
+ type: z.ZodString;
125
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
126
+ }, z.core.$strip>>, z.ZodSet<z.ZodObject<{
127
+ app: z.ZodString;
128
+ type: z.ZodString;
129
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
130
+ }, z.core.$strip>>]>>, z.ZodTransform<{
131
+ app: string;
132
+ type: string;
133
+ id?: string | number | undefined;
134
+ }[] | undefined, Set<{
135
+ app: string;
136
+ type: string;
137
+ id?: string | number | undefined;
138
+ }> | {
139
+ app: string;
140
+ type: string;
141
+ id?: string | number | undefined;
142
+ }[] | undefined>>;
143
+ message: z.ZodOptional<z.ZodString>;
144
+ trace: z.ZodOptional<z.ZodString>;
145
+ event: z.ZodOptional<z.ZodObject<{
146
+ source: z.ZodOptional<z.ZodString>;
147
+ "detail-type": z.ZodOptional<z.ZodString>;
148
+ 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>>;
149
+ }, z.core.$strip>>;
150
+ error: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Error, Error>]>>, z.ZodTransform<string | undefined, string | Error | undefined>>;
151
+ }, z.core.$strip>;
152
+ /**
153
+ * Input type for log audit schemas.
154
+ *
155
+ * Use this type when building audit objects before validation.
156
+ * Accepts Error instances and Set for resources.
157
+ */
158
+ export type LogAuditInput = z.input<typeof _BaseLogAuditSchema>;
159
+ /**
160
+ * Creates a LogAuditSchema with typed app and resourceType schemas.
161
+ *
162
+ * Use this when you have a config with strict app/resourceType enums
163
+ * to get runtime validation against those specific values.
164
+ *
165
+ * @param resourceReferenceSchema - The typed resource reference schema from config.schemas.resourceReference
166
+ * @returns A LogAuditSchema that validates against the provided resource reference schema
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const config = defineAuditConfig({
171
+ * apps: ['Orders', 'Inventory'] as const,
172
+ * resourceTypes: ['Order', 'Product'] as const,
173
+ * });
174
+ *
175
+ * const typedSchema = createTypedLogAuditSchema(config.schemas.resourceReference);
176
+ * typedSchema.parse({
177
+ * operation: 'createOrder',
178
+ * target: { app: 'Orders', type: 'Order', id: '123' },
179
+ * }); // Validates app/type against config
180
+ * ```
181
+ */
182
+ export declare function createTypedLogAuditSchema<T extends z.ZodObject<{
183
+ app: z.ZodTypeAny;
184
+ type: z.ZodTypeAny;
185
+ id: z.ZodTypeAny;
186
+ }>>(resourceReferenceSchema: T): z.ZodObject<{
187
+ id: z.ZodOptional<z.ZodString>;
188
+ operation: z.ZodString;
189
+ tenantId: z.ZodOptional<z.ZodString>;
190
+ tier: z.ZodDefault<z.ZodNumber>;
191
+ status: z.ZodDefault<z.ZodEnum<{
192
+ success: "success";
193
+ warn: "warn";
194
+ fail: "fail";
195
+ skip: "skip";
196
+ }>>;
197
+ target: T;
198
+ source: z.ZodOptional<T>;
199
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<ContextValue, unknown, z.core.$ZodTypeInternals<ContextValue, unknown>>>>;
200
+ resources: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<T>, z.ZodSet<T>]>>, z.ZodTransform<z.core.output<T>[] | undefined, Set<z.core.output<T>> | z.core.output<T>[] | undefined>>;
201
+ message: z.ZodOptional<z.ZodString>;
202
+ trace: z.ZodOptional<z.ZodString>;
203
+ event: z.ZodOptional<z.ZodObject<{
204
+ source: z.ZodOptional<z.ZodString>;
205
+ "detail-type": z.ZodOptional<z.ZodString>;
206
+ 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>>;
207
+ }, z.core.$strip>>;
208
+ error: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Error, Error>]>>, z.ZodTransform<string | undefined, string | Error | undefined>>;
209
+ }, z.core.$strip>;
210
+ export {};
211
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/schema/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAG5B;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM;;;;;CAKT,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,UAAU,aAAiC,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;EAAgC,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,SAAS,aAAa,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;;;iBAOlC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;iBAEnC,CAAC;AAEH;;;;;GAKG;AACH,KAAK,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAC;AAehF;;;GAGG;AACH,eAAO,MAAM,aAAa,6GAA6C,CAAC;AAExE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuC9B,CAAC;AAEH;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,CACxC,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;;;;;;;;;;;;;;;;;;;;;;;kBA4B3B"}
@@ -0,0 +1,179 @@
1
+ import * as z from "zod/v4";
2
+ import { EventBridgeEventSchema } from "./model.js";
3
+ /**
4
+ * Audit operation status values.
5
+ *
6
+ * Used to indicate the outcome of an audited operation:
7
+ * - `SUCCESS`: Operation completed successfully
8
+ * - `WARN`: Operation completed with warnings
9
+ * - `FAIL`: Operation failed
10
+ * - `SKIP`: Operation was skipped
11
+ */
12
+ export const Status = {
13
+ SUCCESS: "success",
14
+ WARN: "warn",
15
+ FAIL: "fail",
16
+ SKIP: "skip",
17
+ };
18
+ /**
19
+ * Schema for escalation tier values (1-3).
20
+ * @internal
21
+ */
22
+ export const TierSchema = z.number().int().gte(1).lte(3);
23
+ /**
24
+ * Schema for audit status enum values.
25
+ * @internal
26
+ */
27
+ export const StatusSchema = z.enum(Object.values(Status));
28
+ /**
29
+ * Schema for application identifier values.
30
+ * Accepts any string; use config.schemas.app for strict validation.
31
+ * @internal
32
+ */
33
+ export const AppSchema = z.string();
34
+ /**
35
+ * Schema for resource type values.
36
+ * Accepts any string; use config.schemas.resourceType for strict validation.
37
+ * @internal
38
+ */
39
+ export const ResourceTypeSchema = z.string();
40
+ /**
41
+ * Schema for resource references (target/source).
42
+ *
43
+ * Identifies a resource within an application by app, type, and optional ID.
44
+ * @internal
45
+ */
46
+ export const ResourceReferenceSchema = z.object({
47
+ /** Application that owns this resource */
48
+ app: AppSchema,
49
+ /** Unique identifier within the resource type (optional) */
50
+ id: z.union([z.string(), z.number()]).optional(),
51
+ /** Type/category of the resource */
52
+ type: ResourceTypeSchema,
53
+ });
54
+ /**
55
+ * Schema for additional related resources.
56
+ *
57
+ * Same structure as ResourceReferenceSchema, used for linking
58
+ * secondary resources to an audit entry.
59
+ * @internal
60
+ */
61
+ export const AdditionalResourceSchema = ResourceReferenceSchema.extend({
62
+ id: z.union([z.string(), z.number()]).optional(),
63
+ });
64
+ /**
65
+ * Schema for recursive context values.
66
+ *
67
+ * Validates nested key-value structures for audit metadata.
68
+ * @internal
69
+ */
70
+ const recursiveValueSchema = z.union([
71
+ z.string(),
72
+ z.number(),
73
+ z.boolean(),
74
+ z.lazy(() => z.record(z.string(), recursiveValueSchema)),
75
+ ]);
76
+ /**
77
+ * Schema for the context object - a flexible key-value store.
78
+ * @internal
79
+ */
80
+ export const ContextSchema = z.record(z.string(), recursiveValueSchema);
81
+ /**
82
+ * Base schema for audit entries destined for CloudWatch Logs.
83
+ *
84
+ * @internal Use `createTypedLogAuditSchema` instead for type-safe validation
85
+ * with your config's app and resourceType enums.
86
+ *
87
+ * This schema accepts any string for app and resourceType values.
88
+ * For strict validation against configured values, use the factory function.
89
+ *
90
+ * **Transformations:**
91
+ * - `resources`: Set is converted to Array
92
+ * - `error`: Error instances are serialized to JSON strings
93
+ * - `tier`: Defaults to 2 (INFO) if not provided
94
+ * - `status`: Defaults to 'success' if not provided
95
+ */
96
+ export const _BaseLogAuditSchema = z.object({
97
+ /** Optional audit ID for retry correlation. If provided, retries with the same ID are correlated. */
98
+ id: z.string().optional(),
99
+ /** Name of the operation being audited (required) */
100
+ operation: z.string(),
101
+ /** Tenant identifier for multi-tenancy support (optional) */
102
+ tenantId: z.string().optional(),
103
+ /** Escalation tier for visibility (1=internal, 2=info, 3=public). Defaults to 2. */
104
+ tier: TierSchema.default(2),
105
+ /** Outcome status of the operation. Defaults to 'success'. */
106
+ status: StatusSchema.default(Status.SUCCESS),
107
+ /** The primary resource being audited (required) */
108
+ target: ResourceReferenceSchema,
109
+ /** The resource that initiated the operation (optional) */
110
+ source: ResourceReferenceSchema.optional(),
111
+ /** Additional metadata as key-value pairs (optional) */
112
+ context: ContextSchema.optional(),
113
+ /** Additional resources affected by this operation. Set is converted to Array. */
114
+ resources: z
115
+ .union([z.array(AdditionalResourceSchema), z.set(AdditionalResourceSchema)])
116
+ .optional()
117
+ .pipe(z.transform((val) => (val instanceof Set ? Array.from(val) : val))),
118
+ /** Human-readable description of the audit (optional) */
119
+ message: z.string().optional(),
120
+ /** Trace identifier for distributed tracing (optional) */
121
+ trace: z.string().optional(),
122
+ /** Original EventBridge event that triggered this audit (optional) */
123
+ event: EventBridgeEventSchema.optional(),
124
+ /** Error details if the operation failed. Error instances are JSON serialized. */
125
+ error: z
126
+ .union([z.string(), z.instanceof(Error)])
127
+ .optional()
128
+ .pipe(z.transform((e) => e instanceof Error
129
+ ? JSON.stringify(e, Object.getOwnPropertyNames(e))
130
+ : e)),
131
+ });
132
+ /**
133
+ * Creates a LogAuditSchema with typed app and resourceType schemas.
134
+ *
135
+ * Use this when you have a config with strict app/resourceType enums
136
+ * to get runtime validation against those specific values.
137
+ *
138
+ * @param resourceReferenceSchema - The typed resource reference schema from config.schemas.resourceReference
139
+ * @returns A LogAuditSchema that validates against the provided resource reference schema
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const config = defineAuditConfig({
144
+ * apps: ['Orders', 'Inventory'] as const,
145
+ * resourceTypes: ['Order', 'Product'] as const,
146
+ * });
147
+ *
148
+ * const typedSchema = createTypedLogAuditSchema(config.schemas.resourceReference);
149
+ * typedSchema.parse({
150
+ * operation: 'createOrder',
151
+ * target: { app: 'Orders', type: 'Order', id: '123' },
152
+ * }); // Validates app/type against config
153
+ * ```
154
+ */
155
+ export function createTypedLogAuditSchema(resourceReferenceSchema) {
156
+ return z.object({
157
+ id: z.string().optional(),
158
+ operation: z.string(),
159
+ tenantId: z.string().optional(),
160
+ tier: TierSchema.default(2),
161
+ status: StatusSchema.default(Status.SUCCESS),
162
+ target: resourceReferenceSchema,
163
+ source: resourceReferenceSchema.optional(),
164
+ context: ContextSchema.optional(),
165
+ resources: z
166
+ .union([z.array(resourceReferenceSchema), z.set(resourceReferenceSchema)])
167
+ .optional()
168
+ .pipe(z.transform((val) => (val instanceof Set ? Array.from(val) : val))),
169
+ message: z.string().optional(),
170
+ trace: z.string().optional(),
171
+ event: EventBridgeEventSchema.optional(),
172
+ error: z
173
+ .union([z.string(), z.instanceof(Error)])
174
+ .optional()
175
+ .pipe(z.transform((e) => e instanceof Error
176
+ ? JSON.stringify(e, Object.getOwnPropertyNames(e))
177
+ : e)),
178
+ });
179
+ }
@@ -0,0 +1,110 @@
1
+ import * as z from "zod/v4";
2
+ /**
3
+ * Schema for EventBridge event data embedded in audit records.
4
+ *
5
+ * Captures the essential fields from an EventBridge event for replay
6
+ * and debugging purposes. The detail field is automatically serialized
7
+ * to a JSON string if provided as an object.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const event = EventBridgeEventSchema.parse({
12
+ * source: 'orders.service',
13
+ * 'detail-type': 'OrderCreated',
14
+ * detail: { orderId: '123', amount: 99.99 },
15
+ * });
16
+ * // event.detail is now '{"orderId":"123","amount":99.99}'
17
+ * ```
18
+ */
19
+ export declare const EventBridgeEventSchema: z.ZodObject<{
20
+ source: z.ZodOptional<z.ZodString>;
21
+ "detail-type": z.ZodOptional<z.ZodString>;
22
+ 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>>;
23
+ }, z.core.$strip>;
24
+ /**
25
+ * Inferred output type from EventBridgeEventSchema.
26
+ * Note: detail is always a string after transformation.
27
+ */
28
+ export type EventBridgeEvent = z.output<typeof EventBridgeEventSchema>;
29
+ /**
30
+ * Schema for pagination parameters in list queries.
31
+ *
32
+ * Used to control page size and cursor-based pagination
33
+ * for DynamoDB query operations.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const pagination = PaginationSchema.parse({
38
+ * pageSize: 25,
39
+ * nextToken: 'abc123...',
40
+ * });
41
+ * ```
42
+ */
43
+ export declare const PaginationSchema: z.ZodObject<{
44
+ pageSize: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
45
+ nextToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
+ }, z.core.$strip>;
47
+ /**
48
+ * Inferred output type from PaginationSchema.
49
+ */
50
+ export type Pagination = z.output<typeof PaginationSchema>;
51
+ /**
52
+ * Factory function to create a collection schema with a specific item type.
53
+ *
54
+ * @param itemSchema - Zod schema for the collection items
55
+ * @returns A schema that validates an object with an `items` array
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const UserCollectionSchema = CollectionSchema(UserSchema);
60
+ * const result = UserCollectionSchema.parse({ items: [user1, user2] });
61
+ * ```
62
+ */
63
+ export declare const CollectionSchema: <T extends z.ZodTypeAny>(itemSchema: T) => z.ZodObject<{
64
+ items: z.ZodArray<T>;
65
+ }, z.core.$strip>;
66
+ /**
67
+ * Generic collection type containing an array of items.
68
+ *
69
+ * @typeParam I - The type of items in the collection
70
+ */
71
+ export type Collection<I> = {
72
+ items: I[];
73
+ };
74
+ /**
75
+ * Factory function to create a paginated collection schema.
76
+ *
77
+ * Extends the basic collection with optional pagination metadata
78
+ * for cursor-based pagination support.
79
+ *
80
+ * @param itemSchema - Zod schema for the collection items
81
+ * @returns A schema that validates items array with optional pagination
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const PaginatedAuditsSchema = PaginationCollectionSchema(AuditSchema);
86
+ * const result = PaginatedAuditsSchema.parse({
87
+ * items: [audit1, audit2],
88
+ * pagination: { nextToken: 'xyz789' },
89
+ * });
90
+ * ```
91
+ */
92
+ export declare const PaginationCollectionSchema: <T extends z.ZodTypeAny>(itemSchema: T) => z.ZodObject<{
93
+ items: z.ZodArray<T>;
94
+ pagination: z.ZodOptional<z.ZodObject<{
95
+ pageSize: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
96
+ nextToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
97
+ }, z.core.$strip>>;
98
+ }, z.core.$strip>;
99
+ /**
100
+ * Generic paginated collection type.
101
+ *
102
+ * Extends Collection with optional pagination metadata for
103
+ * cursor-based navigation through large result sets.
104
+ *
105
+ * @typeParam I - The type of items in the collection
106
+ */
107
+ export type PaginationCollection<I> = Collection<I> & {
108
+ pagination?: Pagination;
109
+ };
110
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/schema/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB;;;;iBAcjC,CAAC;AAEH;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEvE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB;;;iBAK3B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC;;iBAGnE,CAAC;AAEJ;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC3B,KAAK,EAAE,CAAC,EAAE,CAAC;CACX,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAChE,YAAY,CAAC;;;;;;iBAKX,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG;IACrD,UAAU,CAAC,EAAE,UAAU,CAAC;CACxB,CAAC"}
@@ -0,0 +1,86 @@
1
+ import * as z from "zod/v4";
2
+ /**
3
+ * Schema for EventBridge event data embedded in audit records.
4
+ *
5
+ * Captures the essential fields from an EventBridge event for replay
6
+ * and debugging purposes. The detail field is automatically serialized
7
+ * to a JSON string if provided as an object.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const event = EventBridgeEventSchema.parse({
12
+ * source: 'orders.service',
13
+ * 'detail-type': 'OrderCreated',
14
+ * detail: { orderId: '123', amount: 99.99 },
15
+ * });
16
+ * // event.detail is now '{"orderId":"123","amount":99.99}'
17
+ * ```
18
+ */
19
+ export const EventBridgeEventSchema = z.object({
20
+ /** The source service that generated the event */
21
+ source: z.string().optional(),
22
+ /** The type/category of the event */
23
+ "detail-type": z.string().optional(),
24
+ /** Event payload - objects are automatically JSON stringified */
25
+ detail: z
26
+ .union([z.string(), z.record(z.string(), z.any())])
27
+ .optional()
28
+ .pipe(z.transform((val) => typeof val === "object" ? JSON.stringify(val) : val)),
29
+ });
30
+ /**
31
+ * Schema for pagination parameters in list queries.
32
+ *
33
+ * Used to control page size and cursor-based pagination
34
+ * for DynamoDB query operations.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const pagination = PaginationSchema.parse({
39
+ * pageSize: 25,
40
+ * nextToken: 'abc123...',
41
+ * });
42
+ * ```
43
+ */
44
+ export const PaginationSchema = z.object({
45
+ /** Number of items per page (string or number accepted) */
46
+ pageSize: z.union([z.string(), z.number()]).nullable().optional(),
47
+ /** Cursor token for fetching the next page */
48
+ nextToken: z.string().nullable().optional(),
49
+ });
50
+ /**
51
+ * Factory function to create a collection schema with a specific item type.
52
+ *
53
+ * @param itemSchema - Zod schema for the collection items
54
+ * @returns A schema that validates an object with an `items` array
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const UserCollectionSchema = CollectionSchema(UserSchema);
59
+ * const result = UserCollectionSchema.parse({ items: [user1, user2] });
60
+ * ```
61
+ */
62
+ export const CollectionSchema = (itemSchema) => z.object({
63
+ items: z.array(itemSchema),
64
+ });
65
+ /**
66
+ * Factory function to create a paginated collection schema.
67
+ *
68
+ * Extends the basic collection with optional pagination metadata
69
+ * for cursor-based pagination support.
70
+ *
71
+ * @param itemSchema - Zod schema for the collection items
72
+ * @returns A schema that validates items array with optional pagination
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const PaginatedAuditsSchema = PaginationCollectionSchema(AuditSchema);
77
+ * const result = PaginatedAuditsSchema.parse({
78
+ * items: [audit1, audit2],
79
+ * pagination: { nextToken: 'xyz789' },
80
+ * });
81
+ * ```
82
+ */
83
+ export const PaginationCollectionSchema = (itemSchema) => z.object({
84
+ items: z.array(itemSchema),
85
+ pagination: PaginationSchema.optional(),
86
+ });