@dakkitor/api-contracts 1.1.0 → 1.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.
@@ -4,22 +4,23 @@ exports.clientsContract = exports.PaginatedResponseSchema = exports.Autocomplete
4
4
  const core_1 = require("@ts-rest/core");
5
5
  const zod_1 = require("zod");
6
6
  const error_schemas_1 = require("../common/error-schemas");
7
+ const pagination_schema_1 = require("../common/pagination.schema");
7
8
  const ClientStatusSchema = zod_1.z.enum([
8
9
  'APPROVED',
9
10
  'PENDING_VERIFICATION',
10
11
  'BLACKLISTED',
11
12
  ]);
12
13
  const UserSchema = zod_1.z.object({
13
- id: zod_1.z.string().uuid(),
14
+ id: zod_1.z.uuid(),
14
15
  firstName: zod_1.z.string(),
15
16
  lastName: zod_1.z.string(),
16
- email: zod_1.z.string().email(),
17
+ email: zod_1.z.email(),
17
18
  });
18
19
  exports.ClientSchema = zod_1.z.object({
19
- id: zod_1.z.string().uuid().describe('Client ID'),
20
+ id: zod_1.z.uuid().describe('Client ID'),
20
21
  name: zod_1.z.string().describe('Client Name'),
21
22
  crn: zod_1.z.string().describe('Company Registration Number'),
22
- govLink: zod_1.z.string().url().describe('Government Registration Link'),
23
+ govLink: zod_1.z.url().describe('Government Registration Link'),
23
24
  status: ClientStatusSchema.describe('Client Status'),
24
25
  director: zod_1.z.string().describe('Director Name'),
25
26
  blacklistReason: zod_1.z
@@ -28,21 +29,20 @@ exports.ClientSchema = zod_1.z.object({
28
29
  .optional()
29
30
  .describe('Reason for Blacklisting'),
30
31
  lastUpdatedBy: UserSchema.describe('Last Updated By'),
31
- createdAt: zod_1.z.date().describe('Creation Date'),
32
- updatedAt: zod_1.z.date().describe('Last Update Date'),
32
+ createdAt: zod_1.z.iso.datetime().describe('Creation Date'),
33
+ updatedAt: zod_1.z.iso.datetime().describe('Last Update Date'),
33
34
  version: zod_1.z.number().describe('Version Number'),
34
35
  agentClientLinks: zod_1.z.object({ agentId: zod_1.z.string() }).describe('Agent Link'),
35
36
  });
36
37
  exports.CreateClientSchema = zod_1.z.object({
37
38
  name: zod_1.z.string().max(255).describe('Client Name'),
38
- govLink: zod_1.z.string().url().max(2048).describe('Government Registration Link'),
39
+ govLink: zod_1.z.url().max(2048).describe('Government Registration Link'),
39
40
  director: zod_1.z.string().max(255).describe('Director Name'),
40
41
  });
41
42
  exports.UpdateClientSchema = zod_1.z
42
43
  .object({
43
44
  name: zod_1.z.string().max(255).optional().describe('Client Name'),
44
45
  govLink: zod_1.z
45
- .string()
46
46
  .url()
47
47
  .max(2048)
48
48
  .optional()
@@ -77,17 +77,12 @@ exports.ClientAutocompleteResponseSchema = zod_1.z.object({
77
77
  exports.AutocompleteQuerySchema = zod_1.z.object({
78
78
  search: zod_1.z.string().optional().describe('Search...'),
79
79
  });
80
- exports.PaginatedResponseSchema = zod_1.z.object({
81
- data: zod_1.z.array(exports.ClientSchema).describe('Client records'),
82
- total: zod_1.z.number().describe('Total count'),
83
- limit: zod_1.z.number().describe('Results per page'),
84
- skip: zod_1.z.number().describe('Records skipped'),
85
- });
80
+ exports.PaginatedResponseSchema = (0, pagination_schema_1.createPaginatedResponseSchema)(exports.ClientSchema);
86
81
  const c = (0, core_1.initContract)();
87
- exports.clientsContract = c.router({
82
+ const clientsContractConfig = {
88
83
  create: {
89
84
  method: 'POST',
90
- path: '/clients',
85
+ path: '/v2/clients',
91
86
  responses: {
92
87
  201: exports.ClientSchema,
93
88
  400: error_schemas_1.ErrorResponseSchema,
@@ -101,7 +96,7 @@ exports.clientsContract = c.router({
101
96
  },
102
97
  findAll: {
103
98
  method: 'GET',
104
- path: '/clients',
99
+ path: '/v2/clients',
105
100
  responses: {
106
101
  200: exports.PaginatedResponseSchema,
107
102
  400: error_schemas_1.ErrorResponseSchema,
@@ -114,7 +109,7 @@ exports.clientsContract = c.router({
114
109
  },
115
110
  autocomplete: {
116
111
  method: 'GET',
117
- path: '/clients/autocomplete',
112
+ path: '/v2/clients/autocomplete',
118
113
  responses: {
119
114
  200: zod_1.z.array(exports.ClientAutocompleteResponseSchema),
120
115
  400: error_schemas_1.ErrorResponseSchema,
@@ -127,7 +122,7 @@ exports.clientsContract = c.router({
127
122
  },
128
123
  findOne: {
129
124
  method: 'GET',
130
- path: '/clients/:id',
125
+ path: '/v2/clients/:id',
131
126
  responses: {
132
127
  200: exports.ClientSchema,
133
128
  400: error_schemas_1.ErrorResponseSchema,
@@ -137,13 +132,13 @@ exports.clientsContract = c.router({
137
132
  500: error_schemas_1.ErrorResponseSchema,
138
133
  },
139
134
  pathParams: zod_1.z.object({
140
- id: zod_1.z.string().uuid(),
135
+ id: zod_1.z.uuid(),
141
136
  }),
142
137
  summary: 'Get a client by ID',
143
138
  },
144
139
  update: {
145
140
  method: 'PATCH',
146
- path: '/clients/:id',
141
+ path: '/v2/clients/:id',
147
142
  responses: {
148
143
  200: exports.ClientSchema,
149
144
  400: error_schemas_1.ErrorResponseSchema,
@@ -154,14 +149,14 @@ exports.clientsContract = c.router({
154
149
  500: error_schemas_1.ErrorResponseSchema,
155
150
  },
156
151
  pathParams: zod_1.z.object({
157
- id: zod_1.z.string().uuid(),
152
+ id: zod_1.z.uuid(),
158
153
  }),
159
154
  body: exports.UpdateClientSchema,
160
155
  summary: 'Update a client',
161
156
  },
162
157
  remove: {
163
158
  method: 'DELETE',
164
- path: '/clients/:id',
159
+ path: '/v2/clients/:id',
165
160
  responses: {
166
161
  204: zod_1.z.null(),
167
162
  400: error_schemas_1.ErrorResponseSchema,
@@ -171,11 +166,11 @@ exports.clientsContract = c.router({
171
166
  500: error_schemas_1.ErrorResponseSchema,
172
167
  },
173
168
  pathParams: zod_1.z.object({
174
- id: zod_1.z.string().uuid(),
169
+ id: zod_1.z.uuid(),
175
170
  }),
176
171
  body: zod_1.z.undefined(),
177
172
  summary: 'Delete a client',
178
173
  },
179
- }, {
180
- pathPrefix: '/v2', // We handle prefix in path or global prefix
181
- });
174
+ };
175
+ const clientsContractRouter = c.router(clientsContractConfig);
176
+ exports.clientsContract = clientsContractRouter;
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ export declare const createPaginatedResponseSchema: <T extends z.ZodTypeAny>(itemSchema: T) => z.ZodObject<{
3
+ data: z.ZodArray<T>;
4
+ total: z.ZodNumber;
5
+ limit: z.ZodNumber;
6
+ skip: z.ZodNumber;
7
+ }, z.core.$strip>;
8
+ //# sourceMappingURL=pagination.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.schema.d.ts","sourceRoot":"","sources":["../../contracts/common/pagination.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,6BAA6B,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAClE,YAAY,CAAC;;;;;iBAQd,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPaginatedResponseSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const createPaginatedResponseSchema = (itemSchema) => {
6
+ return zod_1.z.object({
7
+ data: zod_1.z.array(itemSchema).describe('Records'),
8
+ total: zod_1.z.number().describe('Total count'),
9
+ limit: zod_1.z.number().describe('Results per page'),
10
+ skip: zod_1.z.number().describe('Records skipped'),
11
+ });
12
+ };
13
+ exports.createPaginatedResponseSchema = createPaginatedResponseSchema;