@assemblis/contracts 0.2.5 → 1.0.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/dist/index.js +1 -1
- package/dist/schemas/api.d.ts +220 -62
- package/dist/schemas/base.d.ts +48 -7
- package/dist/schemas/index.d.ts +1 -1
- package/dist/schemas/utils.d.ts +2 -0
- package/dist/types/enums.d.ts +10 -22
- package/dist/types/index.d.ts +0 -1
- package/dist/types/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/schemas/api.ts +83 -21
- package/src/schemas/base.ts +51 -7
- package/src/schemas/index.ts +1 -1
- package/src/schemas/utils.ts +17 -0
- package/src/types/enums.ts +11 -25
- package/src/types/index.ts +0 -1
- package/src/types/types.ts +6 -3
- package/src/schemas/legacy.ts +0 -328
- package/src/types/api.ts +0 -66
package/dist/schemas/base.d.ts
CHANGED
|
@@ -17,10 +17,6 @@ export declare const InterestSchema: z.ZodObject<{
|
|
|
17
17
|
country: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
18
18
|
organisation: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
19
19
|
}, z.core.$strip>;
|
|
20
|
-
export declare const OptionSchema: z.ZodObject<{
|
|
21
|
-
label: z.ZodString;
|
|
22
|
-
value: z.ZodCoercedNumber<unknown>;
|
|
23
|
-
}, z.core.$strip>;
|
|
24
20
|
export declare const ReportContentSchema: z.ZodObject<{
|
|
25
21
|
published_at: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
26
22
|
title: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
@@ -40,17 +36,19 @@ export declare const ReportContentSchema: z.ZodObject<{
|
|
|
40
36
|
cover_image_id: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
41
37
|
}, z.core.$strip>;
|
|
42
38
|
export declare const ReportSchema: z.ZodObject<{
|
|
43
|
-
|
|
39
|
+
server_id: z.ZodUUID;
|
|
40
|
+
client_id: z.ZodUUID;
|
|
41
|
+
display_seq: z.ZodInt;
|
|
44
42
|
created_at: z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>;
|
|
45
43
|
updated_at: z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>;
|
|
46
44
|
published_at: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
47
45
|
state: z.ZodEnum<{
|
|
48
46
|
DISCARDED: "DISCARDED";
|
|
49
|
-
DRAFTED: "DRAFTED";
|
|
50
47
|
PUBLISHED: "PUBLISHED";
|
|
51
48
|
CHANGED: "CHANGED";
|
|
49
|
+
DRAFTED: "DRAFTED";
|
|
52
50
|
}>;
|
|
53
|
-
|
|
51
|
+
slug: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
54
52
|
draft_content: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
55
53
|
published_at: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
56
54
|
title: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
@@ -174,3 +172,46 @@ export declare const UserSchema: z.ZodObject<{
|
|
|
174
172
|
sub: z.ZodString;
|
|
175
173
|
is_mutirao: z.ZodBoolean;
|
|
176
174
|
}, z.core.$strip>;
|
|
175
|
+
export declare const AssemblySchema: z.ZodObject<{
|
|
176
|
+
id: z.ZodUUID;
|
|
177
|
+
created_at: z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>;
|
|
178
|
+
updated_at: z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>;
|
|
179
|
+
image_src: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
180
|
+
has_image: z.ZodBoolean;
|
|
181
|
+
user_id: z.ZodUUID;
|
|
182
|
+
published_at: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
183
|
+
name: z.ZodString;
|
|
184
|
+
about: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
185
|
+
topics: z.ZodArray<z.ZodString>;
|
|
186
|
+
country: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
187
|
+
hide: z.ZodDefault<z.ZodBoolean>;
|
|
188
|
+
}, z.core.$strip>;
|
|
189
|
+
export declare const PinSchema: z.ZodObject<{
|
|
190
|
+
id: z.ZodUUID;
|
|
191
|
+
created_at: z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>;
|
|
192
|
+
updated_at: z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>;
|
|
193
|
+
country: z.ZodString;
|
|
194
|
+
text: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
195
|
+
hide: z.ZodBoolean;
|
|
196
|
+
image_src: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
|
|
197
|
+
has_image: z.ZodBoolean;
|
|
198
|
+
}, z.core.$strip>;
|
|
199
|
+
export declare const LogSchema: z.ZodObject<{
|
|
200
|
+
message: z.ZodOptional<z.ZodString>;
|
|
201
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
|
|
202
|
+
metadata: z.ZodObject<{
|
|
203
|
+
origin: z.ZodString;
|
|
204
|
+
route: z.ZodString;
|
|
205
|
+
status: z.ZodNumber;
|
|
206
|
+
}, z.core.$strip>;
|
|
207
|
+
}, z.core.$strip>;
|
|
208
|
+
export declare const RegisterSchema: z.ZodObject<{
|
|
209
|
+
type: z.ZodLiteral<"user.created">;
|
|
210
|
+
object: z.ZodLiteral<"event">;
|
|
211
|
+
data: z.ZodObject<{
|
|
212
|
+
id: z.ZodString;
|
|
213
|
+
email_addresses: z.ZodArray<z.ZodObject<{
|
|
214
|
+
email_address: z.ZodString;
|
|
215
|
+
}, z.core.$strip>>;
|
|
216
|
+
}, z.core.$strip>;
|
|
217
|
+
}, z.core.$strip>;
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './api';
|
|
2
|
-
export
|
|
2
|
+
export { resolvePath, type ExtractParams } from './utils';
|
package/dist/schemas/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import z, { ZodType } from 'zod';
|
|
2
2
|
export declare const isoDateString: z.ZodPipe<z.ZodCoercedDate<unknown>, z.ZodTransform<string, Date>>;
|
|
3
3
|
export declare const maybe: <T extends ZodType<unknown>>(_: T) => z.ZodPipe<z.ZodOptional<z.ZodNullable<T>>, z.ZodTransform<Awaited<NonNullable<z.core.output<T>>> | null, z.core.output<T> | null | undefined>>;
|
|
4
|
+
export type ExtractParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractParams<`/${Rest}`> : T extends `${string}:${infer Param}` ? Param : never;
|
|
5
|
+
export declare function resolvePath<T extends string>(template: T, params: Record<ExtractParams<T>, string>): string;
|
package/dist/types/enums.d.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
export declare enum ApiRestMethod {
|
|
2
|
-
GET = "GET",
|
|
3
|
-
POST = "POST",
|
|
4
|
-
PUT = "PUT",
|
|
5
|
-
PATCH = "PATCH"
|
|
6
|
-
}
|
|
7
|
-
export declare enum ApiRouteParameter {
|
|
8
|
-
ID = ":ID",
|
|
9
|
-
NAME = ":NAME"
|
|
10
|
-
}
|
|
11
1
|
export declare enum ApiEndpoint {
|
|
2
|
+
ACCOUNT = "/account",
|
|
12
3
|
ACCOUNT_REPORTS = "/account/reports",
|
|
13
|
-
ASSEMBLIES = "/assemblies",
|
|
14
|
-
FEEDBACK = "/feedback",
|
|
15
4
|
INTEREST = "/interest",
|
|
16
|
-
INTEREST_ASSEMBLIS = "/interest/assemblis",
|
|
17
5
|
LOGS = "/logs",
|
|
6
|
+
PING = "/ping",
|
|
18
7
|
PINS = "/pins",
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
REGISTER = "/register",
|
|
9
|
+
REPORTS = "/reports"
|
|
10
|
+
}
|
|
11
|
+
export declare enum ApiRestMethod {
|
|
12
|
+
GET = "GET",
|
|
13
|
+
POST = "POST",
|
|
14
|
+
PUT = "PUT",
|
|
15
|
+
PATCH = "PATCH"
|
|
22
16
|
}
|
|
23
17
|
export declare enum ReportState {
|
|
24
18
|
DISCARDED = "DISCARDED",
|
|
@@ -26,9 +20,3 @@ export declare enum ReportState {
|
|
|
26
20
|
PUBLISHED = "PUBLISHED",
|
|
27
21
|
CHANGED = "CHANGED"
|
|
28
22
|
}
|
|
29
|
-
export declare enum SurveyName {
|
|
30
|
-
DELIBERATION = "deliberation",
|
|
31
|
-
DEMOGRAPHIC_DATA = "demographic-data",
|
|
32
|
-
PRE_ASSEMBLY = "pre-assembly",
|
|
33
|
-
POST_ASSEMBLY = "post-assembly"
|
|
34
|
-
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { ImageSchema, PinSchema, ReportContentSchema, ReportSchema, UserSchema } from '../schemas/base';
|
|
3
3
|
export type Image = z.infer<typeof ImageSchema>;
|
|
4
|
+
export type Pin = z.infer<typeof PinSchema>;
|
|
4
5
|
export type Report = z.infer<typeof ReportSchema>;
|
|
5
6
|
export type ReportContent = z.infer<typeof ReportContentSchema>;
|
|
6
7
|
export type User = z.infer<typeof UserSchema>;
|
package/package.json
CHANGED
package/src/schemas/api.ts
CHANGED
|
@@ -3,32 +3,33 @@ import z from 'zod';
|
|
|
3
3
|
import { ApiEndpoint, ApiRestMethod } from '../types';
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
AssemblySchema,
|
|
6
7
|
ImageSchema,
|
|
7
8
|
InterestSchema,
|
|
9
|
+
LogSchema,
|
|
10
|
+
PinSchema,
|
|
11
|
+
RegisterSchema,
|
|
8
12
|
ReportContentSchema,
|
|
9
13
|
ReportSchema
|
|
10
14
|
} from './base';
|
|
11
15
|
import { isoDateString, maybe } from './utils';
|
|
12
16
|
|
|
13
|
-
type AccountEndpoint = `/account/${string}`;
|
|
14
|
-
|
|
15
17
|
export const GetAccountReportsSchema = {
|
|
16
|
-
endpoint:
|
|
18
|
+
endpoint: ApiEndpoint.ACCOUNT_REPORTS as const,
|
|
17
19
|
method: ApiRestMethod.GET,
|
|
18
20
|
payload: z.never(),
|
|
19
21
|
response: z.object({ reports: ReportSchema.array(), total: z.int() })
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export const GetAccountReportsIdSchema = {
|
|
23
|
-
endpoint:
|
|
24
|
-
`${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}`,
|
|
25
|
+
endpoint: `${ApiEndpoint.ACCOUNT_REPORTS}/:client_id` as const,
|
|
25
26
|
method: ApiRestMethod.GET,
|
|
26
27
|
payload: z.never(),
|
|
27
28
|
response: maybe(ReportSchema)
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
export const PostAccountReportsSchema = {
|
|
31
|
-
endpoint:
|
|
32
|
+
endpoint: ApiEndpoint.ACCOUNT_REPORTS as const,
|
|
32
33
|
method: ApiRestMethod.POST,
|
|
33
34
|
payload: z.object({
|
|
34
35
|
client_id: z.uuid(),
|
|
@@ -38,8 +39,7 @@ export const PostAccountReportsSchema = {
|
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
export const PutAccountReportsIdContentSchema = {
|
|
41
|
-
endpoint:
|
|
42
|
-
`${ApiEndpoint.ACCOUNT_REPORTS}/${clientId}/content`,
|
|
42
|
+
endpoint: `${ApiEndpoint.ACCOUNT_REPORTS}/:client_id/content` as const,
|
|
43
43
|
method: ApiRestMethod.PUT,
|
|
44
44
|
payload: ReportContentSchema.omit({
|
|
45
45
|
published_at: true,
|
|
@@ -49,54 +49,116 @@ export const PutAccountReportsIdContentSchema = {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export const PatchAccountReportsIdDiscardSchema = {
|
|
52
|
-
endpoint:
|
|
53
|
-
`${ApiEndpoint.ACCOUNT_REPORTS}/${clientId}/discard`,
|
|
52
|
+
endpoint: `${ApiEndpoint.ACCOUNT_REPORTS}/:client_id/discard` as const,
|
|
54
53
|
method: ApiRestMethod.PATCH,
|
|
55
54
|
payload: z.nullish(z.object()),
|
|
56
55
|
response: maybe(ReportSchema)
|
|
57
56
|
};
|
|
58
57
|
|
|
59
58
|
export const PatchAccountReportsIdPublishSchema = {
|
|
60
|
-
endpoint:
|
|
61
|
-
`${ApiEndpoint.ACCOUNT_REPORTS}/${clientId}/publish`,
|
|
59
|
+
endpoint: `${ApiEndpoint.ACCOUNT_REPORTS}/:client_id/publish` as const,
|
|
62
60
|
method: ApiRestMethod.PATCH,
|
|
63
61
|
payload: z.object({ published_at: isoDateString }),
|
|
64
62
|
response: ReportSchema
|
|
65
63
|
};
|
|
66
64
|
|
|
67
65
|
export const PatchAccountReportsIdUnpublishSchema = {
|
|
68
|
-
endpoint:
|
|
69
|
-
`${ApiEndpoint.ACCOUNT_REPORTS}/${clientId}/unpublish`,
|
|
66
|
+
endpoint: `${ApiEndpoint.ACCOUNT_REPORTS}/:client_id/unpublish` as const,
|
|
70
67
|
method: ApiRestMethod.PATCH,
|
|
71
68
|
payload: z.nullish(z.object()),
|
|
72
69
|
response: ReportSchema
|
|
73
70
|
};
|
|
74
71
|
|
|
75
72
|
export const PostAccountReportsIdCoverImageSchema = {
|
|
76
|
-
endpoint:
|
|
77
|
-
`${ApiEndpoint.ACCOUNT_REPORTS}/${clientId}/cover-image`,
|
|
73
|
+
endpoint: `${ApiEndpoint.ACCOUNT_REPORTS}/:client_id/cover-image` as const,
|
|
78
74
|
method: ApiRestMethod.POST,
|
|
79
75
|
payload: ImageSchema.pick({ alt: true }),
|
|
80
76
|
response: ReportSchema
|
|
81
77
|
};
|
|
82
78
|
|
|
83
79
|
export const PostInterestSchema = {
|
|
84
|
-
endpoint:
|
|
80
|
+
endpoint: ApiEndpoint.INTEREST as const,
|
|
85
81
|
method: ApiRestMethod.POST,
|
|
86
82
|
payload: InterestSchema,
|
|
87
83
|
response: z.string()
|
|
88
84
|
};
|
|
89
85
|
|
|
86
|
+
export const PostInterestAssemblisSchema = {
|
|
87
|
+
endpoint: `${ApiEndpoint.INTEREST}/assemblis` as const,
|
|
88
|
+
method: ApiRestMethod.POST,
|
|
89
|
+
payload: InterestSchema.omit({ listIds: true }),
|
|
90
|
+
response: z.string()
|
|
91
|
+
};
|
|
92
|
+
|
|
90
93
|
export const GetReportsSchema = {
|
|
91
|
-
endpoint:
|
|
94
|
+
endpoint: ApiEndpoint.REPORTS as const,
|
|
92
95
|
method: ApiRestMethod.GET,
|
|
93
96
|
payload: z.never(),
|
|
94
|
-
response: z.object({
|
|
97
|
+
response: z.object({
|
|
98
|
+
reports: ReportSchema.array(),
|
|
99
|
+
total: z.int()
|
|
100
|
+
})
|
|
95
101
|
};
|
|
96
102
|
|
|
97
|
-
export const
|
|
98
|
-
endpoint:
|
|
103
|
+
export const GetReportsSlugSchema = {
|
|
104
|
+
endpoint: `${ApiEndpoint.REPORTS}/:slug` as const,
|
|
99
105
|
method: ApiRestMethod.GET,
|
|
100
106
|
payload: z.never(),
|
|
101
107
|
response: maybe(ReportSchema)
|
|
102
108
|
};
|
|
109
|
+
|
|
110
|
+
export const GetPinsSchema = {
|
|
111
|
+
endpoint: ApiEndpoint.PINS as const,
|
|
112
|
+
method: ApiRestMethod.GET,
|
|
113
|
+
payload: z.never(),
|
|
114
|
+
response: z.object({
|
|
115
|
+
assemblies: AssemblySchema.array(),
|
|
116
|
+
pins: PinSchema.array()
|
|
117
|
+
})
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const PostPinSchema = {
|
|
121
|
+
endpoint: ApiEndpoint.PINS as const,
|
|
122
|
+
method: ApiRestMethod.POST,
|
|
123
|
+
payload: z.object({
|
|
124
|
+
country: z.string(),
|
|
125
|
+
email: z.string(),
|
|
126
|
+
text: maybe(z.string())
|
|
127
|
+
}),
|
|
128
|
+
response: PinSchema
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const PatchPinHideSchema = {
|
|
132
|
+
endpoint: `${ApiEndpoint.PINS}/:id/hide` as const,
|
|
133
|
+
method: ApiRestMethod.PATCH,
|
|
134
|
+
payload: z.never(),
|
|
135
|
+
response: PinSchema
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const GetPingSchema = {
|
|
139
|
+
endpoint: ApiEndpoint.PING as const,
|
|
140
|
+
method: ApiRestMethod.GET,
|
|
141
|
+
payload: z.never(),
|
|
142
|
+
response: z.never()
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const PostLogsInfoSchema = {
|
|
146
|
+
endpoint: `${ApiEndpoint.LOGS}/info` as const,
|
|
147
|
+
method: ApiRestMethod.POST,
|
|
148
|
+
payload: LogSchema,
|
|
149
|
+
response: z.string()
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const PostLogsErrorSchema = {
|
|
153
|
+
endpoint: `${ApiEndpoint.LOGS}/error` as const,
|
|
154
|
+
method: ApiRestMethod.POST,
|
|
155
|
+
payload: LogSchema,
|
|
156
|
+
response: z.string()
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const PostRegisterSchema = {
|
|
160
|
+
endpoint: ApiEndpoint.REGISTER as const,
|
|
161
|
+
method: ApiRestMethod.POST,
|
|
162
|
+
payload: RegisterSchema,
|
|
163
|
+
response: z.string()
|
|
164
|
+
};
|
package/src/schemas/base.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Base type schemas
|
|
2
2
|
|
|
3
3
|
import z from 'zod';
|
|
4
|
+
|
|
4
5
|
import { isoDateString, maybe } from './utils';
|
|
5
6
|
|
|
6
7
|
export const ImageSchema = z.object({
|
|
@@ -35,11 +36,6 @@ export const InterestSchema = z.object({
|
|
|
35
36
|
.transform((_) => _ ?? undefined)
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
export const OptionSchema = z.object({
|
|
39
|
-
label: z.string(),
|
|
40
|
-
value: z.coerce.number().int()
|
|
41
|
-
});
|
|
42
|
-
|
|
43
39
|
export const ReportContentSchema = z.object({
|
|
44
40
|
published_at: maybe(isoDateString),
|
|
45
41
|
title: maybe(z.string()),
|
|
@@ -60,12 +56,14 @@ export const ReportContentSchema = z.object({
|
|
|
60
56
|
});
|
|
61
57
|
|
|
62
58
|
export const ReportSchema = z.object({
|
|
63
|
-
|
|
59
|
+
server_id: z.uuid(),
|
|
60
|
+
client_id: z.uuid(),
|
|
61
|
+
display_seq: z.int(),
|
|
64
62
|
created_at: isoDateString,
|
|
65
63
|
updated_at: isoDateString,
|
|
66
64
|
published_at: maybe(isoDateString),
|
|
67
65
|
state: z.enum(['DISCARDED', 'DRAFTED', 'PUBLISHED', 'CHANGED']),
|
|
68
|
-
|
|
66
|
+
slug: maybe(z.string()),
|
|
69
67
|
draft_content: maybe(ReportContentSchema),
|
|
70
68
|
published_content: maybe(ReportContentSchema),
|
|
71
69
|
media: z.object({ images: ImageSchema.array() })
|
|
@@ -78,3 +76,49 @@ export const UserSchema = z.object({
|
|
|
78
76
|
sub: z.string(),
|
|
79
77
|
is_mutirao: z.boolean()
|
|
80
78
|
});
|
|
79
|
+
|
|
80
|
+
// Pins
|
|
81
|
+
export const AssemblySchema = z.object({
|
|
82
|
+
id: z.uuid(),
|
|
83
|
+
created_at: isoDateString,
|
|
84
|
+
updated_at: isoDateString,
|
|
85
|
+
image_src: maybe(z.string()),
|
|
86
|
+
has_image: z.boolean().meta({ deprecated: true }),
|
|
87
|
+
user_id: z.uuid().meta({ deprecated: true }),
|
|
88
|
+
published_at: maybe(isoDateString),
|
|
89
|
+
name: z.string(),
|
|
90
|
+
about: maybe(z.string()),
|
|
91
|
+
topics: z.string().array(),
|
|
92
|
+
country: maybe(z.string()),
|
|
93
|
+
hide: z.boolean().default(false)
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export const PinSchema = z.object({
|
|
97
|
+
id: z.uuid(),
|
|
98
|
+
created_at: z.coerce.date().transform((_) => _.toISOString()),
|
|
99
|
+
updated_at: z.coerce.date().transform((_) => _.toISOString()),
|
|
100
|
+
country: z.string(),
|
|
101
|
+
text: maybe(z.string()),
|
|
102
|
+
hide: z.boolean(),
|
|
103
|
+
image_src: maybe(z.string()),
|
|
104
|
+
has_image: z.boolean().meta({ deprecated: true })
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export const LogSchema = z.object({
|
|
108
|
+
message: z.string().optional(),
|
|
109
|
+
data: z.record(z.string(), z.string().optional()).optional(),
|
|
110
|
+
metadata: z.object({
|
|
111
|
+
origin: z.string(),
|
|
112
|
+
route: z.string(),
|
|
113
|
+
status: z.number()
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const RegisterSchema = z.object({
|
|
118
|
+
type: z.literal('user.created'),
|
|
119
|
+
object: z.literal('event'),
|
|
120
|
+
data: z.object({
|
|
121
|
+
id: z.string(),
|
|
122
|
+
email_addresses: z.object({ email_address: z.string() }).array()
|
|
123
|
+
})
|
|
124
|
+
});
|
package/src/schemas/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './api';
|
|
2
|
-
export
|
|
2
|
+
export { resolvePath, type ExtractParams } from './utils';
|
package/src/schemas/utils.ts
CHANGED
|
@@ -3,3 +3,20 @@ import z, { ZodType } from 'zod';
|
|
|
3
3
|
export const isoDateString = z.coerce.date().transform((_) => _.toISOString());
|
|
4
4
|
export const maybe = <T extends ZodType<unknown>>(_: T) =>
|
|
5
5
|
_.nullish().transform((_) => _ ?? null);
|
|
6
|
+
|
|
7
|
+
export type ExtractParams<T extends string> =
|
|
8
|
+
T extends `${string}:${infer Param}/${infer Rest}`
|
|
9
|
+
? Param | ExtractParams<`/${Rest}`>
|
|
10
|
+
: T extends `${string}:${infer Param}`
|
|
11
|
+
? Param
|
|
12
|
+
: never;
|
|
13
|
+
|
|
14
|
+
export function resolvePath<T extends string>(
|
|
15
|
+
template: T,
|
|
16
|
+
params: Record<ExtractParams<T>, string>
|
|
17
|
+
): string {
|
|
18
|
+
return (Object.keys(params) as ExtractParams<T>[]).reduce(
|
|
19
|
+
(path, key) => path.replace(`:${key}`, params[key]),
|
|
20
|
+
template as string
|
|
21
|
+
);
|
|
22
|
+
}
|
package/src/types/enums.ts
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
export enum ApiRestMethod {
|
|
2
|
-
GET = 'GET',
|
|
3
|
-
POST = 'POST',
|
|
4
|
-
PUT = 'PUT',
|
|
5
|
-
PATCH = 'PATCH'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export enum ApiRouteParameter {
|
|
9
|
-
ID = ':ID',
|
|
10
|
-
NAME = ':NAME'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
1
|
export enum ApiEndpoint {
|
|
2
|
+
ACCOUNT = '/account',
|
|
14
3
|
ACCOUNT_REPORTS = '/account/reports',
|
|
15
|
-
ASSEMBLIES = '/assemblies',
|
|
16
|
-
FEEDBACK = '/feedback',
|
|
17
4
|
INTEREST = '/interest',
|
|
18
|
-
INTEREST_ASSEMBLIS = '/interest/assemblis',
|
|
19
5
|
LOGS = '/logs',
|
|
6
|
+
PING = '/ping',
|
|
20
7
|
PINS = '/pins',
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
REGISTER = '/register',
|
|
9
|
+
REPORTS = '/reports'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum ApiRestMethod {
|
|
13
|
+
GET = 'GET',
|
|
14
|
+
POST = 'POST',
|
|
15
|
+
PUT = 'PUT',
|
|
16
|
+
PATCH = 'PATCH'
|
|
24
17
|
}
|
|
25
18
|
|
|
26
19
|
export enum ReportState {
|
|
@@ -29,10 +22,3 @@ export enum ReportState {
|
|
|
29
22
|
PUBLISHED = 'PUBLISHED',
|
|
30
23
|
CHANGED = 'CHANGED'
|
|
31
24
|
}
|
|
32
|
-
|
|
33
|
-
export enum SurveyName {
|
|
34
|
-
DELIBERATION = 'deliberation',
|
|
35
|
-
DEMOGRAPHIC_DATA = 'demographic-data',
|
|
36
|
-
PRE_ASSEMBLY = 'pre-assembly',
|
|
37
|
-
POST_ASSEMBLY = 'post-assembly'
|
|
38
|
-
}
|
package/src/types/index.ts
CHANGED
package/src/types/types.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
+
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
ImageSchema,
|
|
5
|
+
PinSchema,
|
|
5
6
|
ReportContentSchema,
|
|
6
|
-
|
|
7
|
+
ReportSchema,
|
|
8
|
+
UserSchema
|
|
7
9
|
} from '../schemas/base';
|
|
8
10
|
|
|
9
11
|
export type Image = z.infer<typeof ImageSchema>;
|
|
12
|
+
export type Pin = z.infer<typeof PinSchema>;
|
|
10
13
|
export type Report = z.infer<typeof ReportSchema>;
|
|
11
14
|
export type ReportContent = z.infer<typeof ReportContentSchema>;
|
|
12
15
|
export type User = z.infer<typeof UserSchema>;
|