@assemblis/contracts 0.1.1 → 0.1.3

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.
@@ -1,11 +1,3 @@
1
1
  import z, { ZodType } from 'zod';
2
2
  export declare const isoDateString: z.ZodISODateTime;
3
- export declare const maybe: <T extends ZodType<unknown>>(
4
- _: T
5
- ) => z.ZodPipe<
6
- z.ZodOptional<z.ZodNullable<T>>,
7
- z.ZodTransform<
8
- Awaited<NonNullable<z.core.output<T>>> | null,
9
- z.core.output<T> | null | undefined
10
- >
11
- >;
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>>;
@@ -1,57 +1,31 @@
1
- import z from 'zod';
2
- import {
3
- AssembliesListSchema,
4
- AssemblyDetailSchema,
5
- AssemblyOverviewSchema,
6
- FeedbackSchema,
7
- LogSchema,
8
- PatchAccountReportsIdPublishSchema,
9
- PinListSchema,
10
- PinSchema,
11
- PostAccountReportsIdCoverImageSchema,
12
- RegisterSchema,
13
- SurveyResponseSchema,
14
- SurveySchema
15
- } from '../schemas';
16
- export type PublishReportPayload = z.infer<
17
- (typeof PatchAccountReportsIdPublishSchema)['payload']
18
- >;
19
- export type ImageMetadataPayload = z.infer<
20
- (typeof PostAccountReportsIdCoverImageSchema)['payload']
21
- >;
22
- export type AssemblyDetailPayload = z.infer<
23
- (typeof AssemblyDetailSchema)['payload']
24
- >;
25
- export type AssemblyOverviewPayload = z.infer<
26
- (typeof AssemblyOverviewSchema)['payload']
27
- >;
28
- export type AssembliesListPayload = z.infer<
29
- (typeof AssembliesListSchema)['payload']
30
- >;
1
+ import z, { ZodType } from 'zod';
2
+ import { AssembliesListSchema, AssemblyDetailSchema, AssemblyOverviewSchema, FeedbackSchema, LogSchema, PatchAccountReportsIdPublishSchema, PinListSchema, PinSchema, PostAccountReportsIdCoverImageSchema, RegisterSchema, SurveyResponseSchema, SurveySchema } from '../schemas';
3
+ import { ApiRestMethod } from './enums';
4
+ export type ApiEndpointSchema = {
5
+ endpoint: (...params: string[]) => string;
6
+ method: ApiRestMethod;
7
+ payload: ZodType;
8
+ response: ZodType;
9
+ };
10
+ export type PublishReportPayload = z.infer<(typeof PatchAccountReportsIdPublishSchema)['payload']>;
11
+ export type ImageMetadataPayload = z.infer<(typeof PostAccountReportsIdCoverImageSchema)['payload']>;
12
+ export type AssemblyDetailPayload = z.infer<(typeof AssemblyDetailSchema)['payload']>;
13
+ export type AssemblyOverviewPayload = z.infer<(typeof AssemblyOverviewSchema)['payload']>;
14
+ export type AssembliesListPayload = z.infer<(typeof AssembliesListSchema)['payload']>;
31
15
  export type FeedbackPayload = z.infer<(typeof FeedbackSchema)['payload']>;
32
16
  export type LogPayload = z.infer<(typeof LogSchema)['payload']>;
33
17
  export type PinPayload = z.infer<(typeof PinSchema)['payload']>;
34
18
  export type PinListPayload = z.infer<(typeof PinListSchema)['payload']>;
35
19
  export type RegisterPayload = z.infer<(typeof RegisterSchema)['payload']>;
36
20
  export type SurveyPayload = z.infer<(typeof SurveySchema)['payload']>;
37
- export type SurveyResponsePayload = z.infer<
38
- (typeof SurveyResponseSchema)['payload']
39
- >;
40
- export type AssemblyDetailResponse = z.infer<
41
- (typeof AssemblyDetailSchema)['response']
42
- >;
43
- export type AssemblyOverviewResponse = z.infer<
44
- (typeof AssemblyOverviewSchema)['response']
45
- >;
46
- export type AssembliesListResponse = z.infer<
47
- (typeof AssembliesListSchema)['response']
48
- >;
21
+ export type SurveyResponsePayload = z.infer<(typeof SurveyResponseSchema)['payload']>;
22
+ export type AssemblyDetailResponse = z.infer<(typeof AssemblyDetailSchema)['response']>;
23
+ export type AssemblyOverviewResponse = z.infer<(typeof AssemblyOverviewSchema)['response']>;
24
+ export type AssembliesListResponse = z.infer<(typeof AssembliesListSchema)['response']>;
49
25
  export type FeedbackResponse = z.infer<(typeof FeedbackSchema)['response']>;
50
26
  export type LogResponse = z.infer<(typeof LogSchema)['response']>;
51
27
  export type PinResponse = z.infer<(typeof PinSchema)['response']>;
52
28
  export type PinListResponse = z.infer<(typeof PinListSchema)['response']>;
53
29
  export type RegisterResponse = z.infer<(typeof RegisterSchema)['response']>;
54
30
  export type SurveyResponse = z.infer<(typeof SurveySchema)['response']>;
55
- export type SurveyResponseResponse = z.infer<
56
- (typeof SurveyResponseSchema)['response']
57
- >;
31
+ export type SurveyResponseResponse = z.infer<(typeof SurveyResponseSchema)['response']>;
@@ -1,27 +1,27 @@
1
1
  export declare enum ApiRestMethod {
2
- GET = 'GET',
3
- POST = 'POST',
4
- PUT = 'PUT',
5
- PATCH = 'PATCH'
2
+ GET = "GET",
3
+ POST = "POST",
4
+ PUT = "PUT",
5
+ PATCH = "PATCH"
6
6
  }
7
7
  export declare enum ApiRouteParameter {
8
- ID = ':ID',
9
- NAME = ':NAME'
8
+ ID = ":ID",
9
+ NAME = ":NAME"
10
10
  }
11
11
  export declare enum ApiEndpoint {
12
- ACCOUNT_REPORTS = '/account/reports',
13
- ASSEMBLIES = '/assemblies',
14
- FEEDBACK = '/feedback',
15
- INTEREST_ASSEMBLIS = '/interest/assemblis',
16
- INTEREST_MUTIRAO = '/interest/mutirao',
17
- LOGS = '/logs',
18
- PINS = '/pins',
19
- SURVEYS = '/surveys',
20
- SURVEY_RESPONSES = '/assemblies/:ID/survey-responses/:NAME'
12
+ ACCOUNT_REPORTS = "/account/reports",
13
+ ASSEMBLIES = "/assemblies",
14
+ FEEDBACK = "/feedback",
15
+ INTEREST_ASSEMBLIS = "/interest/assemblis",
16
+ INTEREST_MUTIRAO = "/interest/mutirao",
17
+ LOGS = "/logs",
18
+ PINS = "/pins",
19
+ SURVEYS = "/surveys",
20
+ SURVEY_RESPONSES = "/assemblies/:ID/survey-responses/:NAME"
21
21
  }
22
22
  export declare enum SurveyName {
23
- DELIBERATION = 'deliberation',
24
- DEMOGRAPHIC_DATA = 'demographic-data',
25
- PRE_ASSEMBLY = 'pre-assembly',
26
- POST_ASSEMBLY = 'post-assembly'
23
+ DELIBERATION = "deliberation",
24
+ DEMOGRAPHIC_DATA = "demographic-data",
25
+ PRE_ASSEMBLY = "pre-assembly",
26
+ POST_ASSEMBLY = "post-assembly"
27
27
  }
@@ -1,5 +1,6 @@
1
1
  import z from 'zod';
2
- import { ReportSchema, UserSchema, ReportContentSchema } from '../schemas/base';
2
+ import { ReportSchema, UserSchema, ReportContentSchema, ImageSchema } from '../schemas/base';
3
+ export type Image = z.infer<typeof ImageSchema>;
3
4
  export type Report = z.infer<typeof ReportSchema>;
4
5
  export type ReportContent = z.infer<typeof ReportContentSchema>;
5
6
  export type User = z.infer<typeof UserSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assemblis/contracts",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,43 +1,67 @@
1
1
  import z from 'zod';
2
+
3
+ import { ApiEndpoint, ApiRestMethod } from '../types';
4
+
2
5
  import { ImageSchema, ReportContentSchema, ReportSchema } from './base';
3
6
  import { isoDateString, maybe } from './utils';
4
7
 
5
8
  export const GetAccountReportsSchema = {
9
+ endpoint: () => ApiEndpoint.ACCOUNT_REPORTS,
10
+ method: ApiRestMethod.GET,
6
11
  payload: z.never(),
7
12
  response: z.object({ reports: ReportSchema.array() })
8
13
  };
9
14
 
10
15
  export const GetAccountReportsIdSchema = {
16
+ endpoint: (reportId: string) => `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}`,
17
+ method: ApiRestMethod.GET,
11
18
  payload: z.never(),
12
19
  response: ReportSchema
13
20
  };
14
21
 
15
22
  export const PostAccountReportsSchema = {
23
+ endpoint: () => ApiEndpoint.ACCOUNT_REPORTS,
24
+ method: ApiRestMethod.POST,
16
25
  payload: maybe(ReportContentSchema.omit({ cover_image_id: true })),
17
26
  response: ReportSchema
18
27
  };
19
28
 
20
29
  export const PutAccountReportsIdContentSchema = {
30
+ endpoint: (reportId: string) =>
31
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/content`,
32
+ method: ApiRestMethod.PUT,
21
33
  payload: ReportContentSchema.omit({ cover_image_id: true }),
22
34
  response: ReportSchema
23
35
  };
24
36
 
25
37
  export const PatchAccountReportsIdDiscardSchema = {
38
+ endpoint: (reportId: string) =>
39
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/discard`,
40
+ method: ApiRestMethod.PATCH,
26
41
  payload: z.never(),
27
42
  response: maybe(ReportSchema)
28
43
  };
29
44
 
30
45
  export const PatchAccountReportsIdPublishSchema = {
46
+ endpoint: (reportId: string) =>
47
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/publish`,
48
+ method: ApiRestMethod.PATCH,
31
49
  payload: z.object({ published_at: isoDateString }),
32
50
  response: ReportSchema
33
51
  };
34
52
 
35
53
  export const PatchAccountReportsIdUnpublishSchema = {
54
+ endpoint: (reportId: string) =>
55
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/unpublish`,
56
+ method: ApiRestMethod.PATCH,
36
57
  payload: z.never(),
37
58
  response: ReportSchema
38
59
  };
39
60
 
40
61
  export const PostAccountReportsIdCoverImageSchema = {
62
+ endpoint: (reportId: string) =>
63
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/cover-image`,
64
+ method: ApiRestMethod.POST,
41
65
  payload: ImageSchema.pick({ alt: true }),
42
66
  response: ReportSchema
43
67
  };