@assemblis/contracts 0.0.1

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/src/schemas.ts ADDED
@@ -0,0 +1,348 @@
1
+ import {
2
+ boolean,
3
+ coerce,
4
+ literal,
5
+ number,
6
+ object,
7
+ record,
8
+ string,
9
+ unknown,
10
+ undefined,
11
+ type ZodType
12
+ } from 'zod';
13
+
14
+ const coercedDate = coerce.date;
15
+ const maybe = <T extends ZodType<unknown>>(_: T) =>
16
+ _.nullish().transform((_) => _ ?? null);
17
+
18
+ const OptionSchema = object({ label: string(), value: coerce.number().int() });
19
+
20
+ export const UserSchema = {
21
+ payload: undefined(),
22
+ response: object({
23
+ id: string().uuid(),
24
+ created_at: coercedDate(),
25
+ updated_at: coercedDate(),
26
+ sub: string(),
27
+ is_mutirao: boolean()
28
+ })
29
+ };
30
+
31
+ // Surveys
32
+ const SurveyQuestionSchema = object({
33
+ id: string().uuid(),
34
+ text: string()
35
+ });
36
+
37
+ export const SurveySchema = {
38
+ payload: undefined(),
39
+ response: object({
40
+ id: string().uuid(),
41
+ created_at: coercedDate(),
42
+ updated_at: coercedDate(),
43
+ name: string(),
44
+ sections: object({
45
+ primary: SurveyQuestionSchema,
46
+ secondary: SurveyQuestionSchema.array(),
47
+ options: OptionSchema.array()
48
+ }).array()
49
+ })
50
+ };
51
+
52
+ export const SurveyResponseSchema = {
53
+ payload: object({
54
+ answers: object({
55
+ question_id: string().uuid(),
56
+ answer_value: coerce.number().int()
57
+ }).array()
58
+ }),
59
+ response: object({
60
+ total: number().int()
61
+ })
62
+ };
63
+
64
+ // Action Plans
65
+ const ActionPlanSchema = object({
66
+ visible_on_profile: boolean(),
67
+ description: maybe(string())
68
+ });
69
+
70
+ const ActionSchema = object({
71
+ text: string(),
72
+ agreed: maybe(coerce.number().int()),
73
+ against: maybe(coerce.number().int()),
74
+ abstained: maybe(coerce.number().int()),
75
+ include_in_action_plan: boolean().default(true),
76
+ assembly_id: string().uuid()
77
+ });
78
+
79
+ const TaskSchema = object({
80
+ text: string(),
81
+ complete: boolean().default(false),
82
+ action_id: string().uuid(),
83
+ assembly_id: string().uuid()
84
+ });
85
+
86
+ // Assembly Overviews
87
+ const BaseAssemblyOverviewSchema = object({
88
+ published_at: maybe(coercedDate()),
89
+ name: string(),
90
+ about: maybe(string()),
91
+ topics: string().array(),
92
+ country: maybe(string()),
93
+ hide: boolean().default(false)
94
+ });
95
+ export const AssemblyOverviewSchema = {
96
+ payload: BaseAssemblyOverviewSchema,
97
+ response: BaseAssemblyOverviewSchema.extend({
98
+ id: string().uuid(),
99
+ created_at: coercedDate(),
100
+ updated_at: coercedDate(),
101
+ has_image: boolean(),
102
+ image_src: maybe(string())
103
+ })
104
+ };
105
+ export const AssembliesListSchema = {
106
+ payload: undefined(),
107
+ response: object({
108
+ assemblies: AssemblyOverviewSchema.response.array()
109
+ })
110
+ };
111
+
112
+ // Assembly Details
113
+ const OrganisationSchema = object({
114
+ visible_on_profile: boolean(),
115
+ name: maybe(string()),
116
+ description: maybe(string()),
117
+ type: maybe(string())
118
+ });
119
+ const EventDetailsSchema = object({
120
+ visible_on_profile: boolean(),
121
+ registration_link: maybe(string()),
122
+ start_date: maybe(coercedDate())
123
+ });
124
+ const StorySchema = object({
125
+ visible_on_profile: boolean(),
126
+ background: maybe(string())
127
+ });
128
+ const SupportersSchema = object({
129
+ visible_on_profile: boolean(),
130
+ organisation_types: string().array(),
131
+ description: maybe(string())
132
+ });
133
+ const FundersSchema = object({
134
+ visible_on_profile: boolean(),
135
+ organisation_types: string().array(),
136
+ description: maybe(string())
137
+ });
138
+ const FacilitationSchema = object({
139
+ visible_on_profile: boolean(),
140
+ decision_method: maybe(string())
141
+ });
142
+ const ParticipantsSchema = object({
143
+ visible_on_profile: boolean(),
144
+ recruitment_method: maybe(string()),
145
+ community: maybe(string())
146
+ });
147
+ const SupportSchema = object({
148
+ visible_on_profile: boolean(),
149
+ support_options: string().array()
150
+ });
151
+ const SurveyDetailsSchema = object({
152
+ visible_on_profile: boolean()
153
+ });
154
+ export const AssemblyDetailSchema = {
155
+ payload: AssemblyOverviewSchema.payload.extend({
156
+ organisation: maybe(
157
+ OrganisationSchema.extend({
158
+ id: string().uuid().optional()
159
+ })
160
+ ),
161
+ event_details: maybe(EventDetailsSchema),
162
+ story: maybe(StorySchema),
163
+ supporters: maybe(SupportersSchema),
164
+ funders: maybe(FundersSchema),
165
+ facilitation: maybe(FacilitationSchema),
166
+ participants: maybe(ParticipantsSchema),
167
+ support: maybe(SupportSchema),
168
+ action_plan: maybe(
169
+ ActionPlanSchema.extend({
170
+ actions: ActionSchema.omit({ assembly_id: true })
171
+ .extend({
172
+ id: string().uuid().optional(),
173
+ tasks: TaskSchema.omit({
174
+ action_id: true,
175
+ assembly_id: true
176
+ })
177
+ .extend({
178
+ id: string().uuid().optional()
179
+ })
180
+ .array(),
181
+ updates: unknown().array()
182
+ })
183
+ .array(),
184
+ updates: unknown().array()
185
+ })
186
+ ),
187
+ surveys: maybe(SurveyDetailsSchema)
188
+ }),
189
+ response: AssemblyOverviewSchema.response.extend({
190
+ is_own: boolean(),
191
+ organisation: maybe(
192
+ OrganisationSchema.extend({
193
+ id: string().uuid(),
194
+ created_at: coercedDate(),
195
+ updated_at: coercedDate()
196
+ })
197
+ ),
198
+ event_details: maybe(
199
+ EventDetailsSchema.extend({
200
+ created_at: coercedDate(),
201
+ updated_at: coercedDate()
202
+ })
203
+ ),
204
+ story: maybe(
205
+ StorySchema.extend({
206
+ created_at: coercedDate(),
207
+ updated_at: coercedDate()
208
+ })
209
+ ),
210
+ supporters: maybe(
211
+ SupportersSchema.extend({
212
+ created_at: coercedDate(),
213
+ updated_at: coercedDate()
214
+ })
215
+ ),
216
+ funders: maybe(
217
+ FundersSchema.extend({
218
+ created_at: coercedDate(),
219
+ updated_at: coercedDate()
220
+ })
221
+ ),
222
+ facilitation: maybe(
223
+ FacilitationSchema.extend({
224
+ created_at: coercedDate(),
225
+ updated_at: coercedDate()
226
+ })
227
+ ),
228
+ participants: maybe(
229
+ ParticipantsSchema.extend({
230
+ created_at: coercedDate(),
231
+ updated_at: coercedDate()
232
+ })
233
+ ),
234
+ support: maybe(
235
+ SupportSchema.extend({
236
+ created_at: coercedDate(),
237
+ updated_at: coercedDate()
238
+ })
239
+ ),
240
+ action_plan: maybe(
241
+ ActionPlanSchema.extend({
242
+ actions: ActionSchema.omit({ assembly_id: true })
243
+ .extend({
244
+ id: string().uuid(),
245
+ created_at: coercedDate(),
246
+ updated_at: coercedDate(),
247
+ tasks: TaskSchema.omit({
248
+ action_id: true,
249
+ assembly_id: true
250
+ })
251
+ .extend({
252
+ id: string().uuid(),
253
+ created_at: coercedDate(),
254
+ updated_at: coercedDate()
255
+ })
256
+ .array(),
257
+ updates: unknown().array()
258
+ })
259
+ .extend({
260
+ created_at: coercedDate(),
261
+ updated_at: coercedDate()
262
+ })
263
+ .array(),
264
+ updates: unknown().array()
265
+ }).and(
266
+ object({
267
+ created_at: coercedDate(),
268
+ updated_at: coercedDate()
269
+ })
270
+ )
271
+ ),
272
+ surveys: maybe(
273
+ SurveyDetailsSchema.extend({
274
+ created_at: coercedDate(),
275
+ updated_at: coercedDate()
276
+ }).extend({
277
+ data: record(
278
+ string(),
279
+ object({
280
+ total: number().int(),
281
+ responses: record(string(), OptionSchema.array())
282
+ })
283
+ )
284
+ })
285
+ )
286
+ })
287
+ };
288
+
289
+ export const FeedbackSchema = {
290
+ payload: object({
291
+ route: string(),
292
+ text: string(),
293
+ metadata: unknown()
294
+ }),
295
+ response: string()
296
+ };
297
+
298
+ export const LogSchema = {
299
+ payload: object({
300
+ message: string().optional(),
301
+ data: record(string(), string().optional()).optional(),
302
+ metadata: object({
303
+ origin: string(),
304
+ route: string(),
305
+ status: number()
306
+ })
307
+ }),
308
+ response: string()
309
+ };
310
+
311
+ export const RegisterSchema = {
312
+ payload: object({
313
+ type: literal('user.created'),
314
+ object: literal('event'),
315
+ data: object({
316
+ id: string(),
317
+ email_addresses: object({
318
+ email_address: string()
319
+ }).array()
320
+ })
321
+ }),
322
+ response: string()
323
+ };
324
+
325
+ export const PinSchema = {
326
+ payload: object({
327
+ country: string(),
328
+ email: string(),
329
+ text: maybe(string())
330
+ }),
331
+ response: object({
332
+ id: string().uuid(),
333
+ created_at: coercedDate(),
334
+ updated_at: coercedDate(),
335
+ country: string(),
336
+ text: maybe(string()),
337
+ hide: boolean(),
338
+ has_image: boolean(),
339
+ image_src: maybe(string())
340
+ })
341
+ };
342
+ export const PinListSchema = {
343
+ payload: undefined(),
344
+ response: object({
345
+ assemblies: AssemblyOverviewSchema.response.array(),
346
+ pins: PinSchema.response.array()
347
+ })
348
+ };
package/src/types.ts ADDED
@@ -0,0 +1,77 @@
1
+ import z from 'zod';
2
+ import {
3
+ AssembliesListSchema,
4
+ AssemblyDetailSchema,
5
+ AssemblyOverviewSchema,
6
+ FeedbackSchema,
7
+ LogSchema,
8
+ PinListSchema,
9
+ PinSchema,
10
+ RegisterSchema,
11
+ SurveyResponseSchema,
12
+ SurveySchema,
13
+ UserSchema
14
+ } from './schemas';
15
+
16
+ export enum Method {
17
+ GET = 'GET',
18
+ POST = 'POST',
19
+ PUT = 'PUT',
20
+ PATCH = 'PATCH'
21
+ }
22
+
23
+ export enum RouteParameters {
24
+ ID = ':ID',
25
+ NAME = ':NAME'
26
+ }
27
+
28
+ export enum Endpoint {
29
+ ASSEMBLIES = '/assemblies',
30
+ FEEDBACK = '/feedback',
31
+ INTEREST_ASSEMBLIS = '/interest/assemblis',
32
+ INTEREST_MUTIRAO = '/interest/mutirao',
33
+ LOGS = '/logs',
34
+ PINS = '/pins',
35
+ SURVEYS = '/surveys',
36
+ SURVEY_RESPONSES = '/assemblies/:ID/survey-responses/:NAME'
37
+ }
38
+
39
+ export type AssemblyDetailPayload = z.infer<
40
+ (typeof AssemblyDetailSchema)['payload']
41
+ >;
42
+ export type AssemblyOverviewPayload = z.infer<
43
+ (typeof AssemblyOverviewSchema)['payload']
44
+ >;
45
+ export type AssembliesListPayload = z.infer<
46
+ (typeof AssembliesListSchema)['payload']
47
+ >;
48
+ export type FeedbackPayload = z.infer<(typeof FeedbackSchema)['payload']>;
49
+ export type LogPayload = z.infer<(typeof LogSchema)['payload']>;
50
+ export type PinPayload = z.infer<(typeof PinSchema)['payload']>;
51
+ export type PinListPayload = z.infer<(typeof PinListSchema)['payload']>;
52
+ export type RegisterPayload = z.infer<(typeof RegisterSchema)['payload']>;
53
+ export type SurveyPayload = z.infer<(typeof SurveySchema)['payload']>;
54
+ export type SurveyResponsePayload = z.infer<
55
+ (typeof SurveyResponseSchema)['payload']
56
+ >;
57
+ export type UserPayload = z.infer<(typeof UserSchema)['payload']>;
58
+
59
+ export type AssemblyDetailResponse = z.infer<
60
+ (typeof AssemblyDetailSchema)['response']
61
+ >;
62
+ export type AssemblyOverviewResponse = z.infer<
63
+ (typeof AssemblyOverviewSchema)['response']
64
+ >;
65
+ export type AssembliesListResponse = z.infer<
66
+ (typeof AssembliesListSchema)['response']
67
+ >;
68
+ export type FeedbackResponse = z.infer<(typeof FeedbackSchema)['response']>;
69
+ export type LogResponse = z.infer<(typeof LogSchema)['response']>;
70
+ export type PinResponse = z.infer<(typeof PinSchema)['response']>;
71
+ export type PinListResponse = z.infer<(typeof PinListSchema)['response']>;
72
+ export type RegisterResponse = z.infer<(typeof RegisterSchema)['response']>;
73
+ export type SurveyResponse = z.infer<(typeof SurveySchema)['response']>;
74
+ export type SurveyResponseResponse = z.infer<
75
+ (typeof SurveyResponseSchema)['response']
76
+ >;
77
+ export type UserResponse = z.infer<(typeof UserSchema)['response']>;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["DOM", "ES2023"],
4
+ "skipLibCheck": true,
5
+ "strict": true,
6
+ "declaration": true,
7
+ "esModuleInterop": true,
8
+ "resolveJsonModule": true,
9
+ "baseUrl": ".",
10
+ "outDir": "dist"
11
+ },
12
+ "include": ["src"],
13
+ "exclude": ["node_modules", "dist"]
14
+ }