-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.ts
113 lines (106 loc) · 2.88 KB
/
lib.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { z } from 'zod';
export const encryptedDataSchema = z.object({
iv: z.string(),
salt: z.string(),
cipherText: z.string(),
});
const baseRequestsTableSchema = z.object({
id: z.string().uuid(),
parent_id: z.string().uuid().nullable(),
created_at: z.date(),
tags: z.record(z.string(), z.string()),
diff_paths: z.array(z.string()).nullable(),
diff_added_count: z.number().nullable(),
diff_removed_count: z.number().nullable(),
control_req_url: z.string(),
control_req_method: z.string(),
control_res_http_status: z.number(),
control_started_at: z.date(),
control_ended_at: z.date(),
shadow_req_url: z.string(),
shadow_req_method: z.string(),
shadow_res_http_status: z.number(),
shadow_started_at: z.date(),
shadow_ended_at: z.date(),
});
export const encryptedRequestsTableSchema = baseRequestsTableSchema.extend({
diff_patches: encryptedDataSchema.nullable(),
control_req_headers: encryptedDataSchema,
control_res_body: encryptedDataSchema,
shadow_res_body: encryptedDataSchema,
shadow_res_headers: encryptedDataSchema,
});
export type EncryptedRequestTable = z.infer<
typeof encryptedRequestsTableSchema
>;
export const decryptedRequestsTableSchema = baseRequestsTableSchema.extend({
diff_patches: z
.array(
z.object({
op: z.string(),
path: z.string(),
value: z.unknown(),
})
)
.nullable(),
control_req_headers: z.record(z.string(), z.string()),
control_res_body: z.string(),
shadow_res_body: z.string(),
shadow_res_headers: z.record(z.string(), z.string()),
});
export type DecryptedRequestTable = z.infer<
typeof decryptedRequestsTableSchema
>;
export const publicRequestSchema = z.object({
id: z.string(),
created_at: z.string(),
tags: z.record(z.string(), z.string()),
diff: z
.object({
added: z.number(),
removed: z.number(),
paths: z.array(z.string()),
patches: z
.array(
z.object({
op: z.string(),
path: z.string(),
value: z.unknown(),
})
)
.nullable(),
})
.nullable(),
control: z.object({
request: z.object({
url: z.string(),
method: z.string(),
headers: z.record(z.string(), z.string()),
}),
response: z.object({
status: z.number(),
body: z.string(),
}),
}),
shadow: z.object({
request: z.object({
url: z.string(),
method: z.string(),
headers: z.record(z.string(), z.string()),
}),
response: z.object({
status: z.number(),
body: z.string(),
headers: z.record(z.string(), z.string()),
}),
}),
});
export type PublicRequest = z.infer<typeof publicRequestSchema>;
export const api = {
'/shadows/:id': publicRequestSchema.extend({
replays: z.array(publicRequestSchema),
}),
} as const;
export type PublicApi = {
[Path in keyof typeof api]: { data: z.infer<(typeof api)[Path]> };
};