@assemblis/contracts 0.1.0 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assemblis/contracts",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,43 +1,65 @@
1
1
  import z from 'zod';
2
2
  import { ImageSchema, ReportContentSchema, ReportSchema } from './base';
3
3
  import { isoDateString, maybe } from './utils';
4
+ import { ApiEndpoint, ApiEndpointSchema, ApiRestMethod } from '../types';
4
5
 
5
- export const GetAccountReportsSchema = {
6
+ export const GetAccountReportsSchema: ApiEndpointSchema = {
7
+ endpoint: () => ApiEndpoint.ACCOUNT_REPORTS,
8
+ method: ApiRestMethod.GET,
6
9
  payload: z.never(),
7
10
  response: z.object({ reports: ReportSchema.array() })
8
11
  };
9
12
 
10
- export const GetAccountReportsIdSchema = {
13
+ export const GetAccountReportsIdSchema: ApiEndpointSchema = {
14
+ endpoint: (reportId: string) => `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}`,
15
+ method: ApiRestMethod.GET,
11
16
  payload: z.never(),
12
17
  response: ReportSchema
13
18
  };
14
19
 
15
- export const PostAccountReportsSchema = {
20
+ export const PostAccountReportsSchema: ApiEndpointSchema = {
21
+ endpoint: () => ApiEndpoint.ACCOUNT_REPORTS,
22
+ method: ApiRestMethod.POST,
16
23
  payload: maybe(ReportContentSchema.omit({ cover_image_id: true })),
17
24
  response: ReportSchema
18
25
  };
19
26
 
20
- export const PutAccountReportsIdContentSchema = {
27
+ export const PutAccountReportsIdContentSchema: ApiEndpointSchema = {
28
+ endpoint: (reportId: string) =>
29
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/content`,
30
+ method: ApiRestMethod.PUT,
21
31
  payload: ReportContentSchema.omit({ cover_image_id: true }),
22
32
  response: ReportSchema
23
33
  };
24
34
 
25
- export const PatchAccountReportsIdDiscardSchema = {
35
+ export const PatchAccountReportsIdDiscardSchema: ApiEndpointSchema = {
36
+ endpoint: (reportId: string) =>
37
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/discard`,
38
+ method: ApiRestMethod.PATCH,
26
39
  payload: z.never(),
27
40
  response: maybe(ReportSchema)
28
41
  };
29
42
 
30
- export const PatchAccountReportsIdPublishSchema = {
43
+ export const PatchAccountReportsIdPublishSchema: ApiEndpointSchema = {
44
+ endpoint: (reportId: string) =>
45
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/publish`,
46
+ method: ApiRestMethod.PATCH,
31
47
  payload: z.object({ published_at: isoDateString }),
32
48
  response: ReportSchema
33
49
  };
34
50
 
35
- export const PatchAccountReportsIdUnpublishSchema = {
51
+ export const PatchAccountReportsIdUnpublishSchema: ApiEndpointSchema = {
52
+ endpoint: (reportId: string) =>
53
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/unpublish`,
54
+ method: ApiRestMethod.PATCH,
36
55
  payload: z.never(),
37
56
  response: ReportSchema
38
57
  };
39
58
 
40
- export const PostAccountReportsIdCoverImageSchema = {
59
+ export const PostAccountReportsIdCoverImageSchema: ApiEndpointSchema = {
60
+ endpoint: (reportId: string) =>
61
+ `${ApiEndpoint.ACCOUNT_REPORTS}/${reportId}/cover-image`,
62
+ method: ApiRestMethod.POST,
41
63
  payload: ImageSchema.pick({ alt: true }),
42
64
  response: ReportSchema
43
65
  };
package/src/types/api.ts CHANGED
@@ -1,4 +1,4 @@
1
- import z from 'zod';
1
+ import z, { ZodType } from 'zod';
2
2
  import {
3
3
  AssembliesListSchema,
4
4
  AssemblyDetailSchema,
@@ -13,6 +13,14 @@ import {
13
13
  SurveyResponseSchema,
14
14
  SurveySchema
15
15
  } from '../schemas';
16
+ import { ApiRestMethod } from './enums';
17
+
18
+ export type ApiEndpointSchema = {
19
+ endpoint: (...params: string[]) => string;
20
+ method: ApiRestMethod;
21
+ payload: ZodType;
22
+ response: ZodType;
23
+ };
16
24
 
17
25
  export type PublishReportPayload = z.infer<
18
26
  (typeof PatchAccountReportsIdPublishSchema)['payload']
@@ -1,6 +1,12 @@
1
1
  import z from 'zod';
2
- import { ReportSchema, UserSchema, ReportContentSchema } from '../schemas/base';
2
+ import {
3
+ ReportSchema,
4
+ UserSchema,
5
+ ReportContentSchema,
6
+ ImageSchema
7
+ } from '../schemas/base';
3
8
 
9
+ export type Image = z.infer<typeof ImageSchema>;
4
10
  export type Report = z.infer<typeof ReportSchema>;
5
11
  export type ReportContent = z.infer<typeof ReportContentSchema>;
6
12
  export type User = z.infer<typeof UserSchema>;