@dakkitor/api-contracts 1.1.4 → 1.1.5
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/dist/client-contacts/client-contacts.contract.d.ts +187 -187
- package/dist/client-contacts/client-contacts.contract.d.ts.map +1 -1
- package/dist/client-contacts/client-contacts.contract.js +12 -6
- package/dist/clients/clients.contract.d.ts +153 -93
- package/dist/clients/clients.contract.d.ts.map +1 -1
- package/dist/clients/clients.contract.js +67 -19
- package/dist/common/api-responses.d.ts +105 -0
- package/dist/common/api-responses.d.ts.map +1 -0
- package/dist/common/api-responses.js +107 -0
- package/dist/common/error-schemas.d.ts.map +1 -1
- package/dist/common/error-schemas.js +6 -2
- package/dist/common/openapi-metadata.d.ts +65 -0
- package/dist/common/openapi-metadata.d.ts.map +1 -0
- package/dist/common/openapi-metadata.js +155 -0
- package/dist/index.d.ts +212 -181
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/package.json +7 -5
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.clientsContractRouter = exports.PaginatedResponseSchema = exports.AutocompleteQuerySchema = exports.ClientAutocompleteResponseSchema = exports.FilterClientSchema = exports.UpdateClientSchema = exports.CreateClientSchema = exports.ClientSchema = exports.ClientUserSchema = void 0;
|
|
4
|
+
const zod_openapi_1 = require("@anatine/zod-openapi");
|
|
4
5
|
const core_1 = require("@ts-rest/core");
|
|
5
6
|
const zod_1 = require("zod");
|
|
6
7
|
const error_schemas_1 = require("../common/error-schemas");
|
|
7
8
|
const pagination_schema_1 = require("../common/pagination.schema");
|
|
9
|
+
(0, zod_openapi_1.extendZodWithOpenApi)(zod_1.z);
|
|
8
10
|
const ClientStatusSchema = zod_1.z.enum([
|
|
9
11
|
'APPROVED',
|
|
10
12
|
'PENDING_VERIFICATION',
|
|
11
13
|
'BLACKLISTED',
|
|
12
14
|
]);
|
|
15
|
+
const SortOrderSchema = zod_1.z.enum(['ASC', 'DESC']);
|
|
16
|
+
const ClientSortableFieldsSchema = zod_1.z.enum([
|
|
17
|
+
'name',
|
|
18
|
+
'director',
|
|
19
|
+
'createdAt',
|
|
20
|
+
'updatedAt',
|
|
21
|
+
]);
|
|
22
|
+
const DateRangeSchema = zod_1.z.object({
|
|
23
|
+
from: zod_1.z.string().datetime().optional(),
|
|
24
|
+
to: zod_1.z.string().datetime().optional(),
|
|
25
|
+
});
|
|
13
26
|
exports.ClientUserSchema = zod_1.z.object({
|
|
14
27
|
id: zod_1.z.string().uuid(),
|
|
15
28
|
firstName: zod_1.z.string(),
|
|
16
29
|
lastName: zod_1.z.string(),
|
|
17
30
|
email: zod_1.z.string().email(),
|
|
18
31
|
});
|
|
19
|
-
exports.ClientSchema = zod_1.z
|
|
32
|
+
exports.ClientSchema = zod_1.z
|
|
33
|
+
.object({
|
|
20
34
|
id: zod_1.z.string().uuid().describe('Client ID'),
|
|
21
35
|
name: zod_1.z.string().describe('Client Name'),
|
|
22
36
|
crn: zod_1.z.string().describe('Company Registration Number'),
|
|
@@ -33,12 +47,19 @@ exports.ClientSchema = zod_1.z.object({
|
|
|
33
47
|
updatedAt: zod_1.z.string().datetime().describe('Last Update Date'),
|
|
34
48
|
version: zod_1.z.number().describe('Version Number'),
|
|
35
49
|
agentClientLinks: zod_1.z.object({ agentId: zod_1.z.string() }).describe('Agent Link'),
|
|
36
|
-
})
|
|
37
|
-
|
|
50
|
+
})
|
|
51
|
+
.openapi({ title: 'Client' });
|
|
52
|
+
exports.CreateClientSchema = zod_1.z
|
|
53
|
+
.object({
|
|
38
54
|
name: zod_1.z.string().max(255).describe('Client Name'),
|
|
39
|
-
govLink: zod_1.z
|
|
55
|
+
govLink: zod_1.z
|
|
56
|
+
.string()
|
|
57
|
+
.url()
|
|
58
|
+
.max(2048)
|
|
59
|
+
.describe('Government Registration Link'),
|
|
40
60
|
director: zod_1.z.string().max(255).describe('Director Name'),
|
|
41
|
-
})
|
|
61
|
+
})
|
|
62
|
+
.openapi({ title: 'CreateClient' });
|
|
42
63
|
exports.UpdateClientSchema = zod_1.z
|
|
43
64
|
.object({
|
|
44
65
|
name: zod_1.z.string().max(255).optional().describe('Client Name'),
|
|
@@ -66,19 +87,46 @@ exports.UpdateClientSchema = zod_1.z
|
|
|
66
87
|
path: ['blacklistReason'],
|
|
67
88
|
});
|
|
68
89
|
exports.FilterClientSchema = zod_1.z.object({
|
|
69
|
-
limit: zod_1.z.coerce
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
90
|
+
limit: zod_1.z.coerce
|
|
91
|
+
.number()
|
|
92
|
+
.default(50)
|
|
93
|
+
.describe('The number of items to return per page.'),
|
|
94
|
+
page: zod_1.z.coerce.number().default(1).describe('The page number to retrieve.'),
|
|
95
|
+
name: zod_1.z
|
|
96
|
+
.string()
|
|
97
|
+
.optional()
|
|
98
|
+
.describe('Filter by client name (case-insensitive contains match)'),
|
|
99
|
+
status: ClientStatusSchema.optional().describe('Filter by client status'),
|
|
100
|
+
director: zod_1.z
|
|
101
|
+
.string()
|
|
102
|
+
.optional()
|
|
103
|
+
.describe('Filter by director name (case-insensitive contains match)'),
|
|
104
|
+
createdAt: DateRangeSchema.optional().describe('Filter by created date range.'),
|
|
105
|
+
sortBy: ClientSortableFieldsSchema.optional().describe('The field to sort the results by.'),
|
|
106
|
+
sortOrder: SortOrderSchema.optional().describe('The order to sort the results by.'),
|
|
73
107
|
});
|
|
74
|
-
exports.ClientAutocompleteResponseSchema = zod_1.z
|
|
108
|
+
exports.ClientAutocompleteResponseSchema = zod_1.z
|
|
109
|
+
.object({
|
|
75
110
|
id: zod_1.z.string().uuid().describe('Client ID'),
|
|
76
111
|
name: zod_1.z.string().describe('Client Name'),
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
112
|
+
})
|
|
113
|
+
.openapi({ title: 'ClientAutocomplete' });
|
|
114
|
+
exports.AutocompleteQuerySchema = zod_1.z
|
|
115
|
+
.object({
|
|
116
|
+
query: zod_1.z
|
|
117
|
+
.string()
|
|
118
|
+
.optional()
|
|
119
|
+
.describe('Search query string to filter results'),
|
|
120
|
+
id: zod_1.z
|
|
121
|
+
.string()
|
|
122
|
+
.uuid()
|
|
123
|
+
.optional()
|
|
124
|
+
.describe('Specific record ID to include in results'),
|
|
125
|
+
})
|
|
126
|
+
.openapi({ title: 'AutocompleteQuery' });
|
|
127
|
+
exports.PaginatedResponseSchema = (0, pagination_schema_1.createPaginatedResponseSchema)(exports.ClientSchema)
|
|
128
|
+
.describe('Resources retrieved successfully.')
|
|
129
|
+
.openapi({ title: 'ClientsPaginatedResponse' });
|
|
82
130
|
const c = (0, core_1.initContract)();
|
|
83
131
|
exports.clientsContractRouter = c.router({
|
|
84
132
|
create: {
|
|
@@ -117,7 +165,7 @@ exports.clientsContractRouter = c.router({
|
|
|
117
165
|
404: error_schemas_1.ErrorResponseSchema,
|
|
118
166
|
},
|
|
119
167
|
pathParams: zod_1.z.object({
|
|
120
|
-
id: zod_1.z.string().uuid(),
|
|
168
|
+
id: zod_1.z.string().uuid().describe('Client ID'),
|
|
121
169
|
}),
|
|
122
170
|
summary: 'Get a client by ID',
|
|
123
171
|
},
|
|
@@ -130,7 +178,7 @@ exports.clientsContractRouter = c.router({
|
|
|
130
178
|
409: error_schemas_1.ErrorResponseSchema,
|
|
131
179
|
},
|
|
132
180
|
pathParams: zod_1.z.object({
|
|
133
|
-
id: zod_1.z.string().uuid(),
|
|
181
|
+
id: zod_1.z.string().uuid().describe('Client ID'),
|
|
134
182
|
}),
|
|
135
183
|
body: exports.UpdateClientSchema,
|
|
136
184
|
summary: 'Update a client',
|
|
@@ -139,11 +187,11 @@ exports.clientsContractRouter = c.router({
|
|
|
139
187
|
method: 'DELETE',
|
|
140
188
|
path: '/v2/clients/:id',
|
|
141
189
|
responses: {
|
|
142
|
-
204:
|
|
190
|
+
204: zod_1.z.undefined(),
|
|
143
191
|
404: error_schemas_1.ErrorResponseSchema,
|
|
144
192
|
},
|
|
145
193
|
pathParams: zod_1.z.object({
|
|
146
|
-
id: zod_1.z.string().uuid(),
|
|
194
|
+
id: zod_1.z.string().uuid().describe('Client ID'),
|
|
147
195
|
}),
|
|
148
196
|
body: c.noBody(),
|
|
149
197
|
summary: 'Delete a client',
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export declare const CommonErrorResponses: {
|
|
2
|
+
readonly 400: {
|
|
3
|
+
readonly description: "Bad Request. The request could not be understood by the server due to malformed syntax or invalid data.";
|
|
4
|
+
readonly content: {
|
|
5
|
+
readonly 'application/json': {
|
|
6
|
+
readonly schema: {
|
|
7
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
8
|
+
};
|
|
9
|
+
readonly example: {
|
|
10
|
+
readonly statusCode: 400;
|
|
11
|
+
readonly message: "Input validation failed or request is malformed.";
|
|
12
|
+
readonly code: "VALIDATION_ERROR";
|
|
13
|
+
readonly timestamp: "2024-01-01T12:00:00.000Z";
|
|
14
|
+
readonly path: "/v1/example-endpoint";
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly 401: {
|
|
20
|
+
readonly description: "Unauthorized. The user is not authenticated or token is missing/invalid.";
|
|
21
|
+
readonly content: {
|
|
22
|
+
readonly 'application/json': {
|
|
23
|
+
readonly schema: {
|
|
24
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
25
|
+
};
|
|
26
|
+
readonly example: {
|
|
27
|
+
readonly statusCode: 401;
|
|
28
|
+
readonly message: "Authentication required or token is invalid.";
|
|
29
|
+
readonly code: "UNAUTHORIZED";
|
|
30
|
+
readonly timestamp: "2024-01-01T12:00:00.000Z";
|
|
31
|
+
readonly path: "/v1/example-endpoint";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly 403: {
|
|
37
|
+
readonly description: "Forbidden. The user does not have the necessary permissions for this resource.";
|
|
38
|
+
readonly content: {
|
|
39
|
+
readonly 'application/json': {
|
|
40
|
+
readonly schema: {
|
|
41
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
42
|
+
};
|
|
43
|
+
readonly example: {
|
|
44
|
+
readonly statusCode: 403;
|
|
45
|
+
readonly message: "Access to this resource is forbidden.";
|
|
46
|
+
readonly code: "FORBIDDEN";
|
|
47
|
+
readonly timestamp: "2024-01-01T12:00:00.000Z";
|
|
48
|
+
readonly path: "/v1/example-endpoint";
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
readonly 404: {
|
|
54
|
+
readonly description: "Not Found. The requested resource could not be found.";
|
|
55
|
+
readonly content: {
|
|
56
|
+
readonly 'application/json': {
|
|
57
|
+
readonly schema: {
|
|
58
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
59
|
+
};
|
|
60
|
+
readonly example: {
|
|
61
|
+
readonly statusCode: 404;
|
|
62
|
+
readonly message: "The requested resource could not be found.";
|
|
63
|
+
readonly code: "RESOURCE_NOT_FOUND";
|
|
64
|
+
readonly timestamp: "2024-01-01T12:00:00.000Z";
|
|
65
|
+
readonly path: "/v1/example-endpoint";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
readonly 409: {
|
|
71
|
+
readonly description: "Conflict. The resource already exists.";
|
|
72
|
+
readonly content: {
|
|
73
|
+
readonly 'application/json': {
|
|
74
|
+
readonly schema: {
|
|
75
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
76
|
+
};
|
|
77
|
+
readonly example: {
|
|
78
|
+
readonly statusCode: 409;
|
|
79
|
+
readonly message: "A conflict occurred with the current state of the resource.";
|
|
80
|
+
readonly code: "RESOURCE_CONFLICT";
|
|
81
|
+
readonly timestamp: "2024-01-01T12:00:00.000Z";
|
|
82
|
+
readonly path: "/v1/example-endpoint";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
readonly 500: {
|
|
88
|
+
readonly description: "Internal Server Error. An unexpected error occurred on the server.";
|
|
89
|
+
readonly content: {
|
|
90
|
+
readonly 'application/json': {
|
|
91
|
+
readonly schema: {
|
|
92
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
93
|
+
};
|
|
94
|
+
readonly example: {
|
|
95
|
+
readonly statusCode: 500;
|
|
96
|
+
readonly message: "An unexpected error occurred on the server.";
|
|
97
|
+
readonly code: "INTERNAL_SERVER_ERROR";
|
|
98
|
+
readonly timestamp: "2024-01-01T12:00:00.000Z";
|
|
99
|
+
readonly path: "/v1/example-endpoint";
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=api-responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-responses.d.ts","sourceRoot":"","sources":["../../contracts/common/api-responses.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4GvB,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonErrorResponses = void 0;
|
|
4
|
+
exports.CommonErrorResponses = {
|
|
5
|
+
400: {
|
|
6
|
+
description: 'Bad Request. The request could not be understood by the server due to malformed syntax or invalid data.',
|
|
7
|
+
content: {
|
|
8
|
+
'application/json': {
|
|
9
|
+
schema: {
|
|
10
|
+
$ref: '#/components/schemas/ErrorResponse',
|
|
11
|
+
},
|
|
12
|
+
example: {
|
|
13
|
+
statusCode: 400,
|
|
14
|
+
message: 'Input validation failed or request is malformed.',
|
|
15
|
+
code: 'VALIDATION_ERROR',
|
|
16
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
17
|
+
path: '/v1/example-endpoint',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
401: {
|
|
23
|
+
description: 'Unauthorized. The user is not authenticated or token is missing/invalid.',
|
|
24
|
+
content: {
|
|
25
|
+
'application/json': {
|
|
26
|
+
schema: {
|
|
27
|
+
$ref: '#/components/schemas/ErrorResponse',
|
|
28
|
+
},
|
|
29
|
+
example: {
|
|
30
|
+
statusCode: 401,
|
|
31
|
+
message: 'Authentication required or token is invalid.',
|
|
32
|
+
code: 'UNAUTHORIZED',
|
|
33
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
34
|
+
path: '/v1/example-endpoint',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
403: {
|
|
40
|
+
description: 'Forbidden. The user does not have the necessary permissions for this resource.',
|
|
41
|
+
content: {
|
|
42
|
+
'application/json': {
|
|
43
|
+
schema: {
|
|
44
|
+
$ref: '#/components/schemas/ErrorResponse',
|
|
45
|
+
},
|
|
46
|
+
example: {
|
|
47
|
+
statusCode: 403,
|
|
48
|
+
message: 'Access to this resource is forbidden.',
|
|
49
|
+
code: 'FORBIDDEN',
|
|
50
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
51
|
+
path: '/v1/example-endpoint',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
404: {
|
|
57
|
+
description: 'Not Found. The requested resource could not be found.',
|
|
58
|
+
content: {
|
|
59
|
+
'application/json': {
|
|
60
|
+
schema: {
|
|
61
|
+
$ref: '#/components/schemas/ErrorResponse',
|
|
62
|
+
},
|
|
63
|
+
example: {
|
|
64
|
+
statusCode: 404,
|
|
65
|
+
message: 'The requested resource could not be found.',
|
|
66
|
+
code: 'RESOURCE_NOT_FOUND',
|
|
67
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
68
|
+
path: '/v1/example-endpoint',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
409: {
|
|
74
|
+
description: 'Conflict. The resource already exists.',
|
|
75
|
+
content: {
|
|
76
|
+
'application/json': {
|
|
77
|
+
schema: {
|
|
78
|
+
$ref: '#/components/schemas/ErrorResponse',
|
|
79
|
+
},
|
|
80
|
+
example: {
|
|
81
|
+
statusCode: 409,
|
|
82
|
+
message: 'A conflict occurred with the current state of the resource.',
|
|
83
|
+
code: 'RESOURCE_CONFLICT',
|
|
84
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
85
|
+
path: '/v1/example-endpoint',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
500: {
|
|
91
|
+
description: 'Internal Server Error. An unexpected error occurred on the server.',
|
|
92
|
+
content: {
|
|
93
|
+
'application/json': {
|
|
94
|
+
schema: {
|
|
95
|
+
$ref: '#/components/schemas/ErrorResponse',
|
|
96
|
+
},
|
|
97
|
+
example: {
|
|
98
|
+
statusCode: 500,
|
|
99
|
+
message: 'An unexpected error occurred on the server.',
|
|
100
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
101
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
102
|
+
path: '/v1/example-endpoint',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-schemas.d.ts","sourceRoot":"","sources":["../../contracts/common/error-schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error-schemas.d.ts","sourceRoot":"","sources":["../../contracts/common/error-schemas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;EAUM,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ErrorResponseSchema = void 0;
|
|
4
|
+
const zod_openapi_1 = require("@anatine/zod-openapi");
|
|
4
5
|
const zod_1 = require("zod");
|
|
6
|
+
(0, zod_openapi_1.extendZodWithOpenApi)(zod_1.z);
|
|
5
7
|
/**
|
|
6
8
|
* Shared error response schema matching IErrorResponse interface.
|
|
7
9
|
* This ensures type consistency between backend error handling and contract definitions.
|
|
8
10
|
*/
|
|
9
|
-
exports.ErrorResponseSchema = zod_1.z
|
|
11
|
+
exports.ErrorResponseSchema = zod_1.z
|
|
12
|
+
.object({
|
|
10
13
|
statusCode: zod_1.z.number().describe('HTTP Status Code'),
|
|
11
14
|
message: zod_1.z.string().describe('Human-readable error message'),
|
|
12
15
|
code: zod_1.z.string().describe('Machine-readable error code'),
|
|
@@ -14,4 +17,5 @@ exports.ErrorResponseSchema = zod_1.z.object({
|
|
|
14
17
|
timestamp: zod_1.z.string().describe('Error timestamp'),
|
|
15
18
|
path: zod_1.z.string().describe('Request path'),
|
|
16
19
|
correlationId: zod_1.z.string().optional().describe('Request correlation ID'),
|
|
17
|
-
})
|
|
20
|
+
})
|
|
21
|
+
.openapi({ title: 'ErrorResponse' });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project: Internal Recruitment Platform API
|
|
3
|
+
* File: openapi-metadata.ts
|
|
4
|
+
*
|
|
5
|
+
* Description: TypeScript types for OpenAPI metadata that can be attached to ts-rest routes.
|
|
6
|
+
* This metadata structure matches the patterns from api-responses.decorator.ts and will be
|
|
7
|
+
* used to post-process the generated OpenAPI spec.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Metadata for a single response status code.
|
|
11
|
+
*/
|
|
12
|
+
export interface ResponseMetadata {
|
|
13
|
+
/**
|
|
14
|
+
* Description of the response.
|
|
15
|
+
*/
|
|
16
|
+
description?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Example response data.
|
|
19
|
+
*/
|
|
20
|
+
example?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Metadata for OpenAPI documentation that can be attached to ts-rest routes.
|
|
24
|
+
*/
|
|
25
|
+
export interface OpenApiMetadata {
|
|
26
|
+
/**
|
|
27
|
+
* Tags for grouping endpoints in Swagger UI.
|
|
28
|
+
*/
|
|
29
|
+
tags?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Custom response metadata for each status code.
|
|
32
|
+
* Keys are status codes (e.g., '200', '201', '400', '401', etc.)
|
|
33
|
+
*/
|
|
34
|
+
responses?: Record<string, ResponseMetadata>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Standard error response examples and descriptions
|
|
38
|
+
*/
|
|
39
|
+
export declare const STANDARD_ERROR_RESPONSES: Record<number, ResponseMetadata>;
|
|
40
|
+
/**
|
|
41
|
+
* Helper to create metadata for standard CRUD operations
|
|
42
|
+
*/
|
|
43
|
+
export declare const createStandardMetadata: {
|
|
44
|
+
/**
|
|
45
|
+
* Metadata for CREATE operations (201)
|
|
46
|
+
*/
|
|
47
|
+
create: (customResponses?: Record<string, ResponseMetadata>) => OpenApiMetadata;
|
|
48
|
+
/**
|
|
49
|
+
* Metadata for FIND ONE operations (200)
|
|
50
|
+
*/
|
|
51
|
+
findOne: (customResponses?: Record<string, ResponseMetadata>) => OpenApiMetadata;
|
|
52
|
+
/**
|
|
53
|
+
* Metadata for FIND ALL operations (200)
|
|
54
|
+
*/
|
|
55
|
+
findAll: (customResponses?: Record<string, ResponseMetadata>) => OpenApiMetadata;
|
|
56
|
+
/**
|
|
57
|
+
* Metadata for UPDATE operations (200)
|
|
58
|
+
*/
|
|
59
|
+
update: (customResponses?: Record<string, ResponseMetadata>) => OpenApiMetadata;
|
|
60
|
+
/**
|
|
61
|
+
* Metadata for DELETE operations (204)
|
|
62
|
+
*/
|
|
63
|
+
delete: (customResponses?: Record<string, ResponseMetadata>) => OpenApiMetadata;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=openapi-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-metadata.d.ts","sourceRoot":"","sources":["../../contracts/common/openapi-metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAiErE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB;IACjC;;OAEG;+BAEiB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KACjD,eAAe;IAWlB;;OAEG;gCAEiB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KACjD,eAAe;IAWlB;;OAEG;gCAEiB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KACjD,eAAe;IAUlB;;OAEG;+BAEiB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KACjD,eAAe;IAuBlB;;OAEG;+BAEiB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KACjD,eAAe;CAUnB,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Project: Internal Recruitment Platform API
|
|
4
|
+
* File: openapi-metadata.ts
|
|
5
|
+
*
|
|
6
|
+
* Description: TypeScript types for OpenAPI metadata that can be attached to ts-rest routes.
|
|
7
|
+
* This metadata structure matches the patterns from api-responses.decorator.ts and will be
|
|
8
|
+
* used to post-process the generated OpenAPI spec.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createStandardMetadata = exports.STANDARD_ERROR_RESPONSES = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Standard error response examples and descriptions
|
|
14
|
+
*/
|
|
15
|
+
exports.STANDARD_ERROR_RESPONSES = {
|
|
16
|
+
400: {
|
|
17
|
+
description: 'Bad Request. The request could not be understood by the server due to malformed syntax or invalid data.',
|
|
18
|
+
example: {
|
|
19
|
+
statusCode: 400,
|
|
20
|
+
message: 'Input validation failed or request is malformed.',
|
|
21
|
+
code: 'VALIDATION_ERROR',
|
|
22
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
23
|
+
path: '/v2/example-endpoint',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
401: {
|
|
27
|
+
description: 'Unauthorized. The user is not authenticated or token is missing/invalid.',
|
|
28
|
+
example: {
|
|
29
|
+
statusCode: 401,
|
|
30
|
+
message: 'Authentication required or token is invalid.',
|
|
31
|
+
code: 'UNAUTHORIZED',
|
|
32
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
33
|
+
path: '/v2/example-endpoint',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
403: {
|
|
37
|
+
description: 'Forbidden. The user does not have the necessary permissions for this resource.',
|
|
38
|
+
example: {
|
|
39
|
+
statusCode: 403,
|
|
40
|
+
message: 'Access to this resource is forbidden.',
|
|
41
|
+
code: 'FORBIDDEN',
|
|
42
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
43
|
+
path: '/v2/example-endpoint',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
404: {
|
|
47
|
+
description: 'Not Found. The requested resource could not be found.',
|
|
48
|
+
example: {
|
|
49
|
+
statusCode: 404,
|
|
50
|
+
message: 'The requested resource could not be found.',
|
|
51
|
+
code: 'RESOURCE_NOT_FOUND',
|
|
52
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
53
|
+
path: '/v2/example-endpoint',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
409: {
|
|
57
|
+
description: 'Conflict. The resource already exists.',
|
|
58
|
+
example: {
|
|
59
|
+
statusCode: 409,
|
|
60
|
+
message: 'A conflict occurred with the current state of the resource.',
|
|
61
|
+
code: 'RESOURCE_CONFLICT',
|
|
62
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
63
|
+
path: '/v2/example-endpoint',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
500: {
|
|
67
|
+
description: 'Internal Server Error. An unexpected error occurred on the server.',
|
|
68
|
+
example: {
|
|
69
|
+
statusCode: 500,
|
|
70
|
+
message: 'An unexpected error occurred on the server.',
|
|
71
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
72
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
73
|
+
path: '/v2/example-endpoint',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Helper to create metadata for standard CRUD operations
|
|
79
|
+
*/
|
|
80
|
+
exports.createStandardMetadata = {
|
|
81
|
+
/**
|
|
82
|
+
* Metadata for CREATE operations (201)
|
|
83
|
+
*/
|
|
84
|
+
create: (customResponses) => ({
|
|
85
|
+
responses: {
|
|
86
|
+
201: {
|
|
87
|
+
description: 'Resource created successfully.',
|
|
88
|
+
},
|
|
89
|
+
...exports.STANDARD_ERROR_RESPONSES,
|
|
90
|
+
409: exports.STANDARD_ERROR_RESPONSES[409],
|
|
91
|
+
...customResponses,
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
/**
|
|
95
|
+
* Metadata for FIND ONE operations (200)
|
|
96
|
+
*/
|
|
97
|
+
findOne: (customResponses) => ({
|
|
98
|
+
responses: {
|
|
99
|
+
200: {
|
|
100
|
+
description: 'Resource retrieved successfully.',
|
|
101
|
+
},
|
|
102
|
+
...exports.STANDARD_ERROR_RESPONSES,
|
|
103
|
+
404: exports.STANDARD_ERROR_RESPONSES[404],
|
|
104
|
+
...customResponses,
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
/**
|
|
108
|
+
* Metadata for FIND ALL operations (200)
|
|
109
|
+
*/
|
|
110
|
+
findAll: (customResponses) => ({
|
|
111
|
+
responses: {
|
|
112
|
+
200: {
|
|
113
|
+
description: 'Resources retrieved successfully.',
|
|
114
|
+
},
|
|
115
|
+
...exports.STANDARD_ERROR_RESPONSES,
|
|
116
|
+
...customResponses,
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
/**
|
|
120
|
+
* Metadata for UPDATE operations (200)
|
|
121
|
+
*/
|
|
122
|
+
update: (customResponses) => ({
|
|
123
|
+
responses: {
|
|
124
|
+
200: {
|
|
125
|
+
description: 'Resource updated successfully.',
|
|
126
|
+
},
|
|
127
|
+
...exports.STANDARD_ERROR_RESPONSES,
|
|
128
|
+
404: exports.STANDARD_ERROR_RESPONSES[404],
|
|
129
|
+
409: {
|
|
130
|
+
description: 'Conflict. The resource already exists or the update causes a conflict.',
|
|
131
|
+
example: {
|
|
132
|
+
statusCode: 409,
|
|
133
|
+
message: 'A conflict occurred with the current state of the resource during update.',
|
|
134
|
+
code: 'RESOURCE_CONFLICT',
|
|
135
|
+
timestamp: '2024-01-01T12:00:00.000Z',
|
|
136
|
+
path: '/v2/example-endpoint',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
...customResponses,
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
/**
|
|
143
|
+
* Metadata for DELETE operations (204)
|
|
144
|
+
*/
|
|
145
|
+
delete: (customResponses) => ({
|
|
146
|
+
responses: {
|
|
147
|
+
204: {
|
|
148
|
+
description: 'Resource deleted successfully.',
|
|
149
|
+
},
|
|
150
|
+
...exports.STANDARD_ERROR_RESPONSES,
|
|
151
|
+
404: exports.STANDARD_ERROR_RESPONSES[404],
|
|
152
|
+
...customResponses,
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
};
|