@dakkitor/api-contracts 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/README.md +57 -0
- package/dist/clients/clients.contract.d.ts +1515 -0
- package/dist/clients/clients.contract.d.ts.map +1 -0
- package/dist/clients/clients.contract.js +181 -0
- package/dist/common/error-schemas.d.ts +32 -0
- package/dist/common/error-schemas.d.ts.map +1 -0
- package/dist/common/error-schemas.js +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/package.json +37 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.contract.d.ts","sourceRoot":"","sources":["../../contracts/clients/clients.contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBvB,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;EAI7B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4B5B,CAAC;AAEJ,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;EAK7B,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;;;;;;;EAG3C,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;EAElC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKlC,CAAC;AAIH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,MAAM,MAAM,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiG3B,CAAC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clientsContract = exports.PaginatedResponseSchema = exports.AutocompleteQuerySchema = exports.ClientAutocompleteResponseSchema = exports.FilterClientSchema = exports.UpdateClientSchema = exports.CreateClientSchema = exports.ClientSchema = void 0;
|
|
4
|
+
const core_1 = require("@ts-rest/core");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const error_schemas_1 = require("../common/error-schemas");
|
|
7
|
+
const ClientStatusSchema = zod_1.z.enum([
|
|
8
|
+
'APPROVED',
|
|
9
|
+
'PENDING_VERIFICATION',
|
|
10
|
+
'BLACKLISTED',
|
|
11
|
+
]);
|
|
12
|
+
const UserSchema = zod_1.z.object({
|
|
13
|
+
id: zod_1.z.string().uuid(),
|
|
14
|
+
firstName: zod_1.z.string(),
|
|
15
|
+
lastName: zod_1.z.string(),
|
|
16
|
+
email: zod_1.z.string().email(),
|
|
17
|
+
});
|
|
18
|
+
exports.ClientSchema = zod_1.z.object({
|
|
19
|
+
id: zod_1.z.string().uuid().describe('Client ID'),
|
|
20
|
+
name: zod_1.z.string().describe('Client Name'),
|
|
21
|
+
crn: zod_1.z.string().describe('Company Registration Number'),
|
|
22
|
+
govLink: zod_1.z.string().url().describe('Government Registration Link'),
|
|
23
|
+
status: ClientStatusSchema.describe('Client Status'),
|
|
24
|
+
director: zod_1.z.string().describe('Director Name'),
|
|
25
|
+
blacklistReason: zod_1.z
|
|
26
|
+
.string()
|
|
27
|
+
.nullable()
|
|
28
|
+
.optional()
|
|
29
|
+
.describe('Reason for Blacklisting'),
|
|
30
|
+
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'),
|
|
33
|
+
version: zod_1.z.number().describe('Version Number'),
|
|
34
|
+
agentClientLinks: zod_1.z.object({ agentId: zod_1.z.string() }).describe('Agent Link'),
|
|
35
|
+
});
|
|
36
|
+
exports.CreateClientSchema = zod_1.z.object({
|
|
37
|
+
name: zod_1.z.string().max(255).describe('Client Name'),
|
|
38
|
+
govLink: zod_1.z.string().url().max(2048).describe('Government Registration Link'),
|
|
39
|
+
director: zod_1.z.string().max(255).describe('Director Name'),
|
|
40
|
+
});
|
|
41
|
+
exports.UpdateClientSchema = zod_1.z
|
|
42
|
+
.object({
|
|
43
|
+
name: zod_1.z.string().max(255).optional().describe('Client Name'),
|
|
44
|
+
govLink: zod_1.z
|
|
45
|
+
.string()
|
|
46
|
+
.url()
|
|
47
|
+
.max(2048)
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('Government Registration Link'),
|
|
50
|
+
director: zod_1.z.string().max(255).optional().describe('Director Name'),
|
|
51
|
+
status: ClientStatusSchema.optional().describe('Client Status'),
|
|
52
|
+
blacklistReason: zod_1.z
|
|
53
|
+
.string()
|
|
54
|
+
.nullable()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('Reason for Blacklisting'),
|
|
57
|
+
})
|
|
58
|
+
.refine((data) => {
|
|
59
|
+
if (data.status === 'BLACKLISTED' && !data.blacklistReason) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}, {
|
|
64
|
+
message: 'blacklistReason is required when status is BLACKLISTED',
|
|
65
|
+
path: ['blacklistReason'],
|
|
66
|
+
});
|
|
67
|
+
exports.FilterClientSchema = zod_1.z.object({
|
|
68
|
+
limit: zod_1.z.coerce.number().default(50).describe('Results per page'),
|
|
69
|
+
page: zod_1.z.coerce.number().default(1).describe('Page number'),
|
|
70
|
+
search: zod_1.z.string().optional().describe('Search by name'),
|
|
71
|
+
status: ClientStatusSchema.optional().describe('Filter by Status'),
|
|
72
|
+
});
|
|
73
|
+
exports.ClientAutocompleteResponseSchema = zod_1.z.object({
|
|
74
|
+
id: zod_1.z.string().uuid().describe('Client ID'),
|
|
75
|
+
name: zod_1.z.string().describe('Client Name'),
|
|
76
|
+
});
|
|
77
|
+
exports.AutocompleteQuerySchema = zod_1.z.object({
|
|
78
|
+
search: zod_1.z.string().optional().describe('Search...'),
|
|
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
|
+
});
|
|
86
|
+
const c = (0, core_1.initContract)();
|
|
87
|
+
exports.clientsContract = c.router({
|
|
88
|
+
create: {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
path: '/clients',
|
|
91
|
+
responses: {
|
|
92
|
+
201: exports.ClientSchema,
|
|
93
|
+
400: error_schemas_1.ErrorResponseSchema,
|
|
94
|
+
401: error_schemas_1.ErrorResponseSchema,
|
|
95
|
+
403: error_schemas_1.ErrorResponseSchema,
|
|
96
|
+
409: error_schemas_1.ErrorResponseSchema,
|
|
97
|
+
500: error_schemas_1.ErrorResponseSchema,
|
|
98
|
+
},
|
|
99
|
+
body: exports.CreateClientSchema,
|
|
100
|
+
summary: 'Create a new client',
|
|
101
|
+
},
|
|
102
|
+
findAll: {
|
|
103
|
+
method: 'GET',
|
|
104
|
+
path: '/clients',
|
|
105
|
+
responses: {
|
|
106
|
+
200: exports.PaginatedResponseSchema,
|
|
107
|
+
400: error_schemas_1.ErrorResponseSchema,
|
|
108
|
+
401: error_schemas_1.ErrorResponseSchema,
|
|
109
|
+
403: error_schemas_1.ErrorResponseSchema,
|
|
110
|
+
500: error_schemas_1.ErrorResponseSchema,
|
|
111
|
+
},
|
|
112
|
+
query: exports.FilterClientSchema,
|
|
113
|
+
summary: 'Get all clients',
|
|
114
|
+
},
|
|
115
|
+
autocomplete: {
|
|
116
|
+
method: 'GET',
|
|
117
|
+
path: '/clients/autocomplete',
|
|
118
|
+
responses: {
|
|
119
|
+
200: zod_1.z.array(exports.ClientAutocompleteResponseSchema),
|
|
120
|
+
400: error_schemas_1.ErrorResponseSchema,
|
|
121
|
+
401: error_schemas_1.ErrorResponseSchema,
|
|
122
|
+
403: error_schemas_1.ErrorResponseSchema,
|
|
123
|
+
500: error_schemas_1.ErrorResponseSchema,
|
|
124
|
+
},
|
|
125
|
+
query: exports.AutocompleteQuerySchema,
|
|
126
|
+
summary: 'Get clients for autocomplete',
|
|
127
|
+
},
|
|
128
|
+
findOne: {
|
|
129
|
+
method: 'GET',
|
|
130
|
+
path: '/clients/:id',
|
|
131
|
+
responses: {
|
|
132
|
+
200: exports.ClientSchema,
|
|
133
|
+
400: error_schemas_1.ErrorResponseSchema,
|
|
134
|
+
401: error_schemas_1.ErrorResponseSchema,
|
|
135
|
+
403: error_schemas_1.ErrorResponseSchema,
|
|
136
|
+
404: error_schemas_1.ErrorResponseSchema,
|
|
137
|
+
500: error_schemas_1.ErrorResponseSchema,
|
|
138
|
+
},
|
|
139
|
+
pathParams: zod_1.z.object({
|
|
140
|
+
id: zod_1.z.string().uuid(),
|
|
141
|
+
}),
|
|
142
|
+
summary: 'Get a client by ID',
|
|
143
|
+
},
|
|
144
|
+
update: {
|
|
145
|
+
method: 'PATCH',
|
|
146
|
+
path: '/clients/:id',
|
|
147
|
+
responses: {
|
|
148
|
+
200: exports.ClientSchema,
|
|
149
|
+
400: error_schemas_1.ErrorResponseSchema,
|
|
150
|
+
401: error_schemas_1.ErrorResponseSchema,
|
|
151
|
+
403: error_schemas_1.ErrorResponseSchema,
|
|
152
|
+
404: error_schemas_1.ErrorResponseSchema,
|
|
153
|
+
409: error_schemas_1.ErrorResponseSchema,
|
|
154
|
+
500: error_schemas_1.ErrorResponseSchema,
|
|
155
|
+
},
|
|
156
|
+
pathParams: zod_1.z.object({
|
|
157
|
+
id: zod_1.z.string().uuid(),
|
|
158
|
+
}),
|
|
159
|
+
body: exports.UpdateClientSchema,
|
|
160
|
+
summary: 'Update a client',
|
|
161
|
+
},
|
|
162
|
+
remove: {
|
|
163
|
+
method: 'DELETE',
|
|
164
|
+
path: '/clients/:id',
|
|
165
|
+
responses: {
|
|
166
|
+
204: zod_1.z.null(),
|
|
167
|
+
400: error_schemas_1.ErrorResponseSchema,
|
|
168
|
+
401: error_schemas_1.ErrorResponseSchema,
|
|
169
|
+
403: error_schemas_1.ErrorResponseSchema,
|
|
170
|
+
404: error_schemas_1.ErrorResponseSchema,
|
|
171
|
+
500: error_schemas_1.ErrorResponseSchema,
|
|
172
|
+
},
|
|
173
|
+
pathParams: zod_1.z.object({
|
|
174
|
+
id: zod_1.z.string().uuid(),
|
|
175
|
+
}),
|
|
176
|
+
body: zod_1.z.undefined(),
|
|
177
|
+
summary: 'Delete a client',
|
|
178
|
+
},
|
|
179
|
+
}, {
|
|
180
|
+
pathPrefix: '/v2', // We handle prefix in path or global prefix
|
|
181
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Shared error response schema matching IErrorResponse interface.
|
|
4
|
+
* This ensures type consistency between backend error handling and contract definitions.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ErrorResponseSchema: z.ZodObject<{
|
|
7
|
+
statusCode: z.ZodNumber;
|
|
8
|
+
message: z.ZodString;
|
|
9
|
+
code: z.ZodString;
|
|
10
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
11
|
+
timestamp: z.ZodString;
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
correlationId: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
statusCode: number;
|
|
16
|
+
message: string;
|
|
17
|
+
code: string;
|
|
18
|
+
timestamp: string;
|
|
19
|
+
path: string;
|
|
20
|
+
details?: unknown;
|
|
21
|
+
correlationId?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
statusCode: number;
|
|
24
|
+
message: string;
|
|
25
|
+
code: string;
|
|
26
|
+
timestamp: string;
|
|
27
|
+
path: string;
|
|
28
|
+
details?: unknown;
|
|
29
|
+
correlationId?: string | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
export type ErrorResponseV2 = z.infer<typeof ErrorResponseSchema>;
|
|
32
|
+
//# sourceMappingURL=error-schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-schemas.d.ts","sourceRoot":"","sources":["../../contracts/common/error-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;EAQ9B,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorResponseSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Shared error response schema matching IErrorResponse interface.
|
|
7
|
+
* This ensures type consistency between backend error handling and contract definitions.
|
|
8
|
+
*/
|
|
9
|
+
exports.ErrorResponseSchema = zod_1.z.object({
|
|
10
|
+
statusCode: zod_1.z.number().describe('HTTP Status Code'),
|
|
11
|
+
message: zod_1.z.string().describe('Human-readable error message'),
|
|
12
|
+
code: zod_1.z.string().describe('Machine-readable error code'),
|
|
13
|
+
details: zod_1.z.unknown().optional().describe('Additional error details'),
|
|
14
|
+
timestamp: zod_1.z.string().describe('Error timestamp'),
|
|
15
|
+
path: zod_1.z.string().describe('Request path'),
|
|
16
|
+
correlationId: zod_1.z.string().optional().describe('Request correlation ID'),
|
|
17
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../contracts/index.ts"],"names":[],"mappings":"AACA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Export all contracts
|
|
18
|
+
__exportStar(require("./clients/clients.contract"), exports);
|
|
19
|
+
__exportStar(require("./common/error-schemas"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dakkitor/api-contracts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript API contracts using ts-rest and Zod",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"typescript",
|
|
17
|
+
"api",
|
|
18
|
+
"contracts",
|
|
19
|
+
"ts-rest",
|
|
20
|
+
"zod",
|
|
21
|
+
"types"
|
|
22
|
+
],
|
|
23
|
+
"author": "Doru",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@ts-rest/core": "^3.30.0",
|
|
27
|
+
"zod": "^3.22.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@ts-rest/core": "^3.30.0",
|
|
31
|
+
"typescript": "^5.3.3",
|
|
32
|
+
"zod": "^3.22.4"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|