@deepintel-ltd/farmpro-contracts 1.5.8 → 1.5.10
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/index.js +50 -92
- package/dist/routes/admin.routes.js +13 -16
- package/dist/routes/agent-workflows.routes.js +81 -84
- package/dist/routes/agents.routes.js +29 -32
- package/dist/routes/analytics.routes.js +11 -14
- package/dist/routes/auth.routes.js +55 -58
- package/dist/routes/categories.routes.js +23 -26
- package/dist/routes/documents.routes.js +67 -70
- package/dist/routes/equipment.routes.js +55 -58
- package/dist/routes/farms.routes.js +32 -35
- package/dist/routes/field-monitoring.routes.d.ts +8 -1
- package/dist/routes/field-monitoring.routes.d.ts.map +1 -1
- package/dist/routes/field-monitoring.routes.js +77 -74
- package/dist/routes/field-observations.routes.js +41 -44
- package/dist/routes/fields.routes.js +44 -47
- package/dist/routes/finance.routes.js +121 -124
- package/dist/routes/harvest.routes.js +46 -49
- package/dist/routes/health.routes.js +6 -9
- package/dist/routes/index.js +51 -54
- package/dist/routes/input-usage.routes.js +14 -17
- package/dist/routes/inventory.routes.js +57 -60
- package/dist/routes/seasonal-plans.routes.js +14 -17
- package/dist/routes/soil-tests.routes.js +45 -48
- package/dist/routes/suppliers.routes.js +70 -73
- package/dist/routes/tasks.routes.js +65 -68
- package/dist/routes/team.routes.d.ts +306 -0
- package/dist/routes/team.routes.d.ts.map +1 -1
- package/dist/routes/team.routes.js +79 -60
- package/dist/routes/users.routes.js +13 -16
- package/dist/routes/weather.routes.js +10 -13
- package/dist/schemas/admin.schemas.js +43 -46
- package/dist/schemas/agent-workflows.schemas.js +34 -37
- package/dist/schemas/agents.schemas.js +46 -49
- package/dist/schemas/analytics.schemas.js +51 -54
- package/dist/schemas/auth.schemas.js +96 -99
- package/dist/schemas/categories.schemas.js +27 -30
- package/dist/schemas/common.schemas.js +89 -95
- package/dist/schemas/documents.schemas.js +59 -62
- package/dist/schemas/equipment.schemas.js +86 -89
- package/dist/schemas/farms.schemas.js +40 -43
- package/dist/schemas/field-monitoring.schemas.js +207 -210
- package/dist/schemas/field-observations.schemas.js +93 -96
- package/dist/schemas/fields.schemas.js +82 -85
- package/dist/schemas/finance.schemas.js +134 -137
- package/dist/schemas/harvest.schemas.js +46 -49
- package/dist/schemas/health.schemas.js +14 -17
- package/dist/schemas/input-usage.schemas.js +21 -24
- package/dist/schemas/inventory.schemas.js +58 -61
- package/dist/schemas/recommendations.schemas.js +22 -25
- package/dist/schemas/seasonal-plans.schemas.js +21 -24
- package/dist/schemas/soil-tests.schemas.js +70 -73
- package/dist/schemas/suppliers.schemas.js +90 -93
- package/dist/schemas/tasks.schemas.js +93 -96
- package/dist/schemas/team.schemas.js +35 -38
- package/dist/schemas/users.schemas.js +19 -22
- package/dist/schemas/weather.schemas.js +32 -35
- package/package.json +9 -1
|
@@ -1,159 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.emailVerificationResponseSchema = exports.logoutResponseSchema = exports.passwordResetResponseSchema = exports.refreshTokenResponseSchema = exports.googleAuthInitiateResponseSchema = exports.authResponseSchema = exports.refreshTokenResourceSchema = exports.googleAuthInitiateResourceSchema = exports.authSessionResourceSchema = exports.authUserResourceSchema = exports.refreshTokenResponseAttributesSchema = exports.googleAuthInitiateResponseAttributesSchema = exports.authSessionAttributesSchema = exports.authUserAttributesSchema = exports.logoutSchema = exports.resendVerificationSchema = exports.verifyEmailSchema = exports.changePasswordSchema = exports.resetPasswordSchema = exports.requestPasswordResetSchema = exports.refreshTokenSchema = exports.googleAuthCallbackSchema = exports.googleAuthInitiateSchema = exports.signupSchema = exports.loginSchema = exports.logoutAttributesSchema = exports.resendVerificationAttributesSchema = exports.verifyEmailAttributesSchema = exports.changePasswordAttributesSchema = exports.resetPasswordAttributesSchema = exports.requestPasswordResetAttributesSchema = exports.refreshTokenAttributesSchema = exports.googleAuthCallbackAttributesSchema = exports.googleAuthInitiateAttributesSchema = exports.signupAttributesSchema = exports.loginAttributesSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const common_schemas_1 = require("./common.schemas");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { timestampsSchema, createJsonApiResourceSchema, jsonApiSingleResponseSchema, jsonApiSuccessResponseSchema } from './common.schemas';
|
|
6
3
|
/**
|
|
7
4
|
* Authentication schemas - JSON:API compliant
|
|
8
5
|
*/
|
|
9
6
|
// Login attributes
|
|
10
|
-
|
|
11
|
-
email:
|
|
12
|
-
password:
|
|
7
|
+
export const loginAttributesSchema = z.object({
|
|
8
|
+
email: z.string().email(),
|
|
9
|
+
password: z.string().min(8),
|
|
13
10
|
});
|
|
14
11
|
// Signup attributes
|
|
15
|
-
|
|
16
|
-
name:
|
|
17
|
-
email:
|
|
18
|
-
password:
|
|
12
|
+
export const signupAttributesSchema = z.object({
|
|
13
|
+
name: z.string().min(1).max(200),
|
|
14
|
+
email: z.string().email(),
|
|
15
|
+
password: z.string().min(8).regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
|
|
19
16
|
.regex(/[a-z]/, 'Password must contain at least one lowercase letter')
|
|
20
17
|
.regex(/[0-9]/, 'Password must contain at least one number'),
|
|
21
18
|
});
|
|
22
19
|
// Google OAuth initiate attributes
|
|
23
|
-
|
|
24
|
-
redirectUri:
|
|
20
|
+
export const googleAuthInitiateAttributesSchema = z.object({
|
|
21
|
+
redirectUri: z.string().url().optional(),
|
|
25
22
|
});
|
|
26
23
|
// Google OAuth callback attributes
|
|
27
|
-
|
|
28
|
-
code:
|
|
29
|
-
state:
|
|
24
|
+
export const googleAuthCallbackAttributesSchema = z.object({
|
|
25
|
+
code: z.string().min(1),
|
|
26
|
+
state: z.string().optional(),
|
|
30
27
|
});
|
|
31
28
|
// Token refresh attributes
|
|
32
|
-
|
|
33
|
-
refreshToken:
|
|
29
|
+
export const refreshTokenAttributesSchema = z.object({
|
|
30
|
+
refreshToken: z.string().min(1),
|
|
34
31
|
});
|
|
35
32
|
// Password reset request attributes
|
|
36
|
-
|
|
37
|
-
email:
|
|
33
|
+
export const requestPasswordResetAttributesSchema = z.object({
|
|
34
|
+
email: z.string().email(),
|
|
38
35
|
});
|
|
39
36
|
// Password reset attributes
|
|
40
|
-
|
|
41
|
-
token:
|
|
42
|
-
newPassword:
|
|
37
|
+
export const resetPasswordAttributesSchema = z.object({
|
|
38
|
+
token: z.string().min(1),
|
|
39
|
+
newPassword: z.string().min(8).regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
|
|
43
40
|
.regex(/[a-z]/, 'Password must contain at least one lowercase letter')
|
|
44
41
|
.regex(/[0-9]/, 'Password must contain at least one number'),
|
|
45
42
|
});
|
|
46
43
|
// Change password attributes
|
|
47
|
-
|
|
48
|
-
currentPassword:
|
|
49
|
-
newPassword:
|
|
44
|
+
export const changePasswordAttributesSchema = z.object({
|
|
45
|
+
currentPassword: z.string().min(1),
|
|
46
|
+
newPassword: z.string().min(8).regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
|
|
50
47
|
.regex(/[a-z]/, 'Password must contain at least one lowercase letter')
|
|
51
48
|
.regex(/[0-9]/, 'Password must contain at least one number'),
|
|
52
49
|
});
|
|
53
50
|
// Verify email attributes
|
|
54
|
-
|
|
55
|
-
token:
|
|
51
|
+
export const verifyEmailAttributesSchema = z.object({
|
|
52
|
+
token: z.string().min(1),
|
|
56
53
|
});
|
|
57
54
|
// Resend verification attributes
|
|
58
|
-
|
|
59
|
-
email:
|
|
55
|
+
export const resendVerificationAttributesSchema = z.object({
|
|
56
|
+
email: z.string().email(),
|
|
60
57
|
});
|
|
61
58
|
// Logout attributes
|
|
62
|
-
|
|
63
|
-
refreshToken:
|
|
59
|
+
export const logoutAttributesSchema = z.object({
|
|
60
|
+
refreshToken: z.string().optional(),
|
|
64
61
|
});
|
|
65
62
|
// JSON:API input schemas
|
|
66
|
-
|
|
67
|
-
type:
|
|
68
|
-
attributes:
|
|
63
|
+
export const loginSchema = z.object({
|
|
64
|
+
type: z.literal('auth'),
|
|
65
|
+
attributes: loginAttributesSchema,
|
|
69
66
|
});
|
|
70
|
-
|
|
71
|
-
type:
|
|
72
|
-
attributes:
|
|
67
|
+
export const signupSchema = z.object({
|
|
68
|
+
type: z.literal('users'),
|
|
69
|
+
attributes: signupAttributesSchema,
|
|
73
70
|
});
|
|
74
|
-
|
|
75
|
-
type:
|
|
76
|
-
attributes:
|
|
71
|
+
export const googleAuthInitiateSchema = z.object({
|
|
72
|
+
type: z.literal('auth'),
|
|
73
|
+
attributes: googleAuthInitiateAttributesSchema,
|
|
77
74
|
});
|
|
78
|
-
|
|
79
|
-
type:
|
|
80
|
-
attributes:
|
|
75
|
+
export const googleAuthCallbackSchema = z.object({
|
|
76
|
+
type: z.literal('auth'),
|
|
77
|
+
attributes: googleAuthCallbackAttributesSchema,
|
|
81
78
|
});
|
|
82
|
-
|
|
83
|
-
type:
|
|
84
|
-
attributes:
|
|
79
|
+
export const refreshTokenSchema = z.object({
|
|
80
|
+
type: z.literal('auth'),
|
|
81
|
+
attributes: refreshTokenAttributesSchema,
|
|
85
82
|
});
|
|
86
|
-
|
|
87
|
-
type:
|
|
88
|
-
attributes:
|
|
83
|
+
export const requestPasswordResetSchema = z.object({
|
|
84
|
+
type: z.literal('auth'),
|
|
85
|
+
attributes: requestPasswordResetAttributesSchema,
|
|
89
86
|
});
|
|
90
|
-
|
|
91
|
-
type:
|
|
92
|
-
attributes:
|
|
87
|
+
export const resetPasswordSchema = z.object({
|
|
88
|
+
type: z.literal('auth'),
|
|
89
|
+
attributes: resetPasswordAttributesSchema,
|
|
93
90
|
});
|
|
94
|
-
|
|
95
|
-
type:
|
|
96
|
-
attributes:
|
|
91
|
+
export const changePasswordSchema = z.object({
|
|
92
|
+
type: z.literal('auth'),
|
|
93
|
+
attributes: changePasswordAttributesSchema,
|
|
97
94
|
});
|
|
98
|
-
|
|
99
|
-
type:
|
|
100
|
-
attributes:
|
|
95
|
+
export const verifyEmailSchema = z.object({
|
|
96
|
+
type: z.literal('auth'),
|
|
97
|
+
attributes: verifyEmailAttributesSchema,
|
|
101
98
|
});
|
|
102
|
-
|
|
103
|
-
type:
|
|
104
|
-
attributes:
|
|
99
|
+
export const resendVerificationSchema = z.object({
|
|
100
|
+
type: z.literal('auth'),
|
|
101
|
+
attributes: resendVerificationAttributesSchema,
|
|
105
102
|
});
|
|
106
|
-
|
|
107
|
-
type:
|
|
108
|
-
attributes:
|
|
103
|
+
export const logoutSchema = z.object({
|
|
104
|
+
type: z.literal('auth'),
|
|
105
|
+
attributes: logoutAttributesSchema,
|
|
109
106
|
});
|
|
110
107
|
// User attributes schema (for auth responses)
|
|
111
|
-
|
|
112
|
-
name:
|
|
113
|
-
email:
|
|
114
|
-
phone:
|
|
115
|
-
emailVerified:
|
|
116
|
-
avatar:
|
|
117
|
-
}).merge(
|
|
108
|
+
export const authUserAttributesSchema = z.object({
|
|
109
|
+
name: z.string(),
|
|
110
|
+
email: z.string().email(),
|
|
111
|
+
phone: z.string().nullable(),
|
|
112
|
+
emailVerified: z.boolean(),
|
|
113
|
+
avatar: z.string().url().nullable(),
|
|
114
|
+
}).merge(timestampsSchema);
|
|
118
115
|
// Auth session attributes schema
|
|
119
|
-
|
|
120
|
-
accessToken:
|
|
121
|
-
refreshToken:
|
|
122
|
-
expiresIn:
|
|
123
|
-
tokenType:
|
|
116
|
+
export const authSessionAttributesSchema = z.object({
|
|
117
|
+
accessToken: z.string(),
|
|
118
|
+
refreshToken: z.string(),
|
|
119
|
+
expiresIn: z.number(), // seconds
|
|
120
|
+
tokenType: z.literal('Bearer').default('Bearer'),
|
|
124
121
|
});
|
|
125
122
|
// Google OAuth initiate response attributes
|
|
126
|
-
|
|
127
|
-
authUrl:
|
|
128
|
-
state:
|
|
123
|
+
export const googleAuthInitiateResponseAttributesSchema = z.object({
|
|
124
|
+
authUrl: z.string().url(),
|
|
125
|
+
state: z.string(),
|
|
129
126
|
});
|
|
130
127
|
// Token refresh response attributes
|
|
131
|
-
|
|
132
|
-
accessToken:
|
|
133
|
-
refreshToken:
|
|
134
|
-
expiresIn:
|
|
135
|
-
tokenType:
|
|
128
|
+
export const refreshTokenResponseAttributesSchema = z.object({
|
|
129
|
+
accessToken: z.string(),
|
|
130
|
+
refreshToken: z.string().optional(),
|
|
131
|
+
expiresIn: z.number(),
|
|
132
|
+
tokenType: z.literal('Bearer').default('Bearer'),
|
|
136
133
|
});
|
|
137
134
|
// User resource (JSON:API)
|
|
138
|
-
|
|
135
|
+
export const authUserResourceSchema = createJsonApiResourceSchema('users', authUserAttributesSchema);
|
|
139
136
|
// Auth session resource (JSON:API)
|
|
140
|
-
|
|
137
|
+
export const authSessionResourceSchema = createJsonApiResourceSchema('sessions', authSessionAttributesSchema);
|
|
141
138
|
// Google OAuth initiate resource
|
|
142
|
-
|
|
139
|
+
export const googleAuthInitiateResourceSchema = createJsonApiResourceSchema('auth-urls', googleAuthInitiateResponseAttributesSchema);
|
|
143
140
|
// Token refresh resource
|
|
144
|
-
|
|
141
|
+
export const refreshTokenResourceSchema = createJsonApiResourceSchema('sessions', refreshTokenResponseAttributesSchema);
|
|
145
142
|
// Auth response (login/signup) - compound document with user and session
|
|
146
|
-
|
|
147
|
-
data:
|
|
148
|
-
meta:
|
|
149
|
-
message:
|
|
143
|
+
export const authResponseSchema = z.object({
|
|
144
|
+
data: z.array(z.union([authUserResourceSchema, authSessionResourceSchema])),
|
|
145
|
+
meta: z.object({
|
|
146
|
+
message: z.string().optional(),
|
|
150
147
|
}).optional(),
|
|
151
148
|
});
|
|
152
149
|
// Google OAuth initiate response
|
|
153
|
-
|
|
150
|
+
export const googleAuthInitiateResponseSchema = jsonApiSingleResponseSchema(googleAuthInitiateResourceSchema);
|
|
154
151
|
// Token refresh response
|
|
155
|
-
|
|
152
|
+
export const refreshTokenResponseSchema = jsonApiSingleResponseSchema(refreshTokenResourceSchema);
|
|
156
153
|
// Simple success responses
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
154
|
+
export const passwordResetResponseSchema = jsonApiSuccessResponseSchema;
|
|
155
|
+
export const logoutResponseSchema = jsonApiSuccessResponseSchema;
|
|
156
|
+
export const emailVerificationResponseSchema = jsonApiSuccessResponseSchema;
|
|
@@ -1,47 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getCategoriesQuerySchema = exports.categoryListResponseSchema = exports.categoryResponseSchema = exports.categoryResourceSchema = exports.updateCategorySchema = exports.createCategorySchema = exports.updateCategoryAttributesSchema = exports.createCategoryAttributesSchema = exports.categoryAttributesSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const common_schemas_1 = require("./common.schemas");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { timestampsSchema, createJsonApiResourceSchema, jsonApiSingleResponseSchema, jsonApiCollectionResponseSchema } from './common.schemas';
|
|
6
3
|
/**
|
|
7
4
|
* Category schemas - JSON:API compliant
|
|
8
5
|
* Categories are universal and can be used for tasks, budgets, and expenses
|
|
9
6
|
*/
|
|
10
7
|
// Category attributes schema (for JSON:API attributes object)
|
|
11
|
-
|
|
12
|
-
name:
|
|
13
|
-
farmId:
|
|
14
|
-
isDefault:
|
|
15
|
-
}).merge(
|
|
8
|
+
export const categoryAttributesSchema = z.object({
|
|
9
|
+
name: z.string(),
|
|
10
|
+
farmId: z.string().uuid().nullable(),
|
|
11
|
+
isDefault: z.boolean(),
|
|
12
|
+
}).merge(timestampsSchema);
|
|
16
13
|
// Category attributes for creation (input)
|
|
17
|
-
|
|
18
|
-
name:
|
|
19
|
-
farmId:
|
|
20
|
-
isDefault:
|
|
14
|
+
export const createCategoryAttributesSchema = z.object({
|
|
15
|
+
name: z.string().min(1).max(100),
|
|
16
|
+
farmId: z.string().uuid().optional(), // Optional - if not provided, creates system default
|
|
17
|
+
isDefault: z.boolean().optional().default(false),
|
|
21
18
|
});
|
|
22
19
|
// Category attributes for update (input)
|
|
23
|
-
|
|
24
|
-
name:
|
|
25
|
-
isDefault:
|
|
20
|
+
export const updateCategoryAttributesSchema = z.object({
|
|
21
|
+
name: z.string().min(1).max(100).optional(),
|
|
22
|
+
isDefault: z.boolean().optional(),
|
|
26
23
|
});
|
|
27
24
|
// Create category input (JSON:API format)
|
|
28
|
-
|
|
29
|
-
type:
|
|
30
|
-
attributes:
|
|
25
|
+
export const createCategorySchema = z.object({
|
|
26
|
+
type: z.literal('categories'),
|
|
27
|
+
attributes: createCategoryAttributesSchema,
|
|
31
28
|
});
|
|
32
29
|
// Update category input (JSON:API format)
|
|
33
|
-
|
|
34
|
-
type:
|
|
35
|
-
id:
|
|
36
|
-
attributes:
|
|
30
|
+
export const updateCategorySchema = z.object({
|
|
31
|
+
type: z.literal('categories'),
|
|
32
|
+
id: z.string().uuid(),
|
|
33
|
+
attributes: updateCategoryAttributesSchema,
|
|
37
34
|
});
|
|
38
35
|
// Category resource (JSON:API resource object)
|
|
39
|
-
|
|
36
|
+
export const categoryResourceSchema = createJsonApiResourceSchema('categories', categoryAttributesSchema);
|
|
40
37
|
// Category responses (JSON:API format)
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
export const categoryResponseSchema = jsonApiSingleResponseSchema(categoryResourceSchema);
|
|
39
|
+
export const categoryListResponseSchema = jsonApiCollectionResponseSchema(categoryResourceSchema);
|
|
43
40
|
// Get categories query parameters
|
|
44
|
-
|
|
45
|
-
farmId:
|
|
46
|
-
includeDefaults:
|
|
41
|
+
export const getCategoriesQuerySchema = z.object({
|
|
42
|
+
farmId: z.string().uuid().optional(),
|
|
43
|
+
includeDefaults: z.coerce.boolean().optional().default(true),
|
|
47
44
|
});
|
|
@@ -1,122 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dateRangeQuerySchema = exports.paginationQuerySchema = exports.errorResponseSchema = exports.createJsonApiResourceSchema = exports.timestampsSchema = exports.idParamSchema = exports.jsonApiSuccessResponseSchema = exports.jsonApiErrorResponseSchema = exports.jsonApiErrorSchema = exports.jsonApiIncludeQuerySchema = exports.jsonApiFieldsQuerySchema = exports.jsonApiFilterQuerySchema = exports.jsonApiSortQuerySchema = exports.jsonApiPaginationMetaSchema = exports.jsonApiPaginationLinksSchema = exports.jsonApiPaginationQuerySchema = exports.jsonApiCollectionResponseSchema = exports.jsonApiSingleResponseSchema = exports.jsonApiResourceSchema = exports.geoJSONGeometrySchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
1
|
+
import { z } from 'zod';
|
|
5
2
|
/**
|
|
6
3
|
* Common schemas used across all API contracts - JSON:API compliant
|
|
7
4
|
*/
|
|
8
5
|
// GeoJSON Geometry Schema (Polygon, MultiPolygon, Point, LineString)
|
|
9
|
-
|
|
10
|
-
type:
|
|
11
|
-
coordinates:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
export const geoJSONGeometrySchema = z.object({
|
|
7
|
+
type: z.enum(['Polygon', 'MultiPolygon', 'Point', 'LineString']),
|
|
8
|
+
coordinates: z.union([
|
|
9
|
+
z.array(z.array(z.array(z.number()))), // Polygon: [[[lng, lat], ...]]
|
|
10
|
+
z.array(z.array(z.array(z.array(z.number())))), // MultiPolygon: [[[[lng, lat], ...]]]
|
|
11
|
+
z.array(z.number()), // Point: [lng, lat]
|
|
12
|
+
z.array(z.array(z.number())), // LineString: [[lng, lat], ...]
|
|
16
13
|
]),
|
|
17
14
|
});
|
|
18
15
|
// JSON:API Resource Object Base
|
|
19
|
-
|
|
20
|
-
type:
|
|
21
|
-
id:
|
|
22
|
-
attributes:
|
|
23
|
-
relationships:
|
|
24
|
-
links:
|
|
25
|
-
meta:
|
|
16
|
+
export const jsonApiResourceSchema = z.object({
|
|
17
|
+
type: z.string(),
|
|
18
|
+
id: z.string(),
|
|
19
|
+
attributes: z.record(z.unknown()).optional(),
|
|
20
|
+
relationships: z.record(z.unknown()).optional(),
|
|
21
|
+
links: z.record(z.string()).optional(),
|
|
22
|
+
meta: z.record(z.unknown()).optional(),
|
|
26
23
|
});
|
|
27
24
|
// JSON:API Single Resource Response
|
|
28
|
-
const jsonApiSingleResponseSchema = (resourceSchema) =>
|
|
25
|
+
export const jsonApiSingleResponseSchema = (resourceSchema) => z.object({
|
|
29
26
|
data: resourceSchema,
|
|
30
|
-
included:
|
|
31
|
-
meta:
|
|
32
|
-
links:
|
|
27
|
+
included: z.array(jsonApiResourceSchema).optional(),
|
|
28
|
+
meta: z.record(z.unknown()).optional(),
|
|
29
|
+
links: z.record(z.string()).optional(),
|
|
33
30
|
});
|
|
34
|
-
exports.jsonApiSingleResponseSchema = jsonApiSingleResponseSchema;
|
|
35
31
|
// JSON:API Collection Response
|
|
36
|
-
const jsonApiCollectionResponseSchema = (resourceSchema) =>
|
|
37
|
-
data:
|
|
38
|
-
included:
|
|
39
|
-
meta:
|
|
40
|
-
links:
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'page[
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
'filter[
|
|
65
|
-
'filter[
|
|
66
|
-
'filter[
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
zod_1.z.string() // comma-separated field names
|
|
32
|
+
export const jsonApiCollectionResponseSchema = (resourceSchema) => z.object({
|
|
33
|
+
data: z.array(resourceSchema),
|
|
34
|
+
included: z.array(jsonApiResourceSchema).optional(),
|
|
35
|
+
meta: z.record(z.unknown()).optional(),
|
|
36
|
+
links: z.record(z.string()).optional(),
|
|
37
|
+
});
|
|
38
|
+
export const jsonApiPaginationQuerySchema = z.object({
|
|
39
|
+
'page[number]': z.coerce.number().int().positive().default(1).optional(),
|
|
40
|
+
'page[size]': z.coerce.number().int().positive().max(100).default(20).optional(),
|
|
41
|
+
});
|
|
42
|
+
export const jsonApiPaginationLinksSchema = z.object({
|
|
43
|
+
first: z.string().optional(),
|
|
44
|
+
last: z.string().optional(),
|
|
45
|
+
prev: z.string().optional(),
|
|
46
|
+
next: z.string().optional(),
|
|
47
|
+
self: z.string(),
|
|
48
|
+
});
|
|
49
|
+
export const jsonApiPaginationMetaSchema = z.object({
|
|
50
|
+
totalRecords: z.number().int().nonnegative(),
|
|
51
|
+
totalPages: z.number().int().nonnegative(),
|
|
52
|
+
currentPage: z.number().int().positive(),
|
|
53
|
+
pageSize: z.number().int().positive(),
|
|
54
|
+
});
|
|
55
|
+
export const jsonApiSortQuerySchema = z.object({
|
|
56
|
+
sort: z.string().optional(), // e.g., "name,-createdAt"
|
|
57
|
+
});
|
|
58
|
+
export const jsonApiFilterQuerySchema = z.object({
|
|
59
|
+
'filter[startDate]': z.string().datetime().optional(),
|
|
60
|
+
'filter[endDate]': z.string().datetime().optional(),
|
|
61
|
+
'filter[status]': z.string().optional(),
|
|
62
|
+
'filter[crop]': z.string().optional(),
|
|
63
|
+
});
|
|
64
|
+
export const jsonApiFieldsQuerySchema = z.record(z.string(), // resource type
|
|
65
|
+
z.string() // comma-separated field names
|
|
71
66
|
).optional();
|
|
72
|
-
|
|
73
|
-
include:
|
|
67
|
+
export const jsonApiIncludeQuerySchema = z.object({
|
|
68
|
+
include: z.string().optional(), // e.g., "fields,team"
|
|
74
69
|
});
|
|
75
|
-
|
|
76
|
-
id:
|
|
77
|
-
links:
|
|
78
|
-
about:
|
|
70
|
+
export const jsonApiErrorSchema = z.object({
|
|
71
|
+
id: z.string().optional(),
|
|
72
|
+
links: z.object({
|
|
73
|
+
about: z.string().optional(),
|
|
79
74
|
}).optional(),
|
|
80
|
-
status:
|
|
81
|
-
code:
|
|
82
|
-
title:
|
|
83
|
-
detail:
|
|
84
|
-
source:
|
|
85
|
-
pointer:
|
|
86
|
-
parameter:
|
|
75
|
+
status: z.string().optional(), // HTTP status code as string
|
|
76
|
+
code: z.string().optional(), // Application-specific error code
|
|
77
|
+
title: z.string().optional(), // Short, human-readable summary
|
|
78
|
+
detail: z.string().optional(), // Human-readable explanation
|
|
79
|
+
source: z.object({
|
|
80
|
+
pointer: z.string().optional(), // JSON Pointer to associated field
|
|
81
|
+
parameter: z.string().optional(), // Query parameter that caused the error
|
|
87
82
|
}).optional(),
|
|
88
|
-
meta:
|
|
83
|
+
meta: z.record(z.unknown()).optional(),
|
|
89
84
|
});
|
|
90
|
-
|
|
91
|
-
errors:
|
|
92
|
-
meta:
|
|
85
|
+
export const jsonApiErrorResponseSchema = z.object({
|
|
86
|
+
errors: z.array(jsonApiErrorSchema),
|
|
87
|
+
meta: z.record(z.unknown()).optional(),
|
|
93
88
|
});
|
|
94
|
-
|
|
95
|
-
meta:
|
|
96
|
-
message:
|
|
89
|
+
export const jsonApiSuccessResponseSchema = z.object({
|
|
90
|
+
meta: z.object({
|
|
91
|
+
message: z.string(),
|
|
97
92
|
}),
|
|
98
93
|
});
|
|
99
|
-
|
|
100
|
-
id:
|
|
94
|
+
export const idParamSchema = z.object({
|
|
95
|
+
id: z.string().uuid(),
|
|
101
96
|
});
|
|
102
|
-
|
|
103
|
-
createdAt:
|
|
104
|
-
updatedAt:
|
|
97
|
+
export const timestampsSchema = z.object({
|
|
98
|
+
createdAt: z.string().datetime(),
|
|
99
|
+
updatedAt: z.string().datetime(),
|
|
105
100
|
});
|
|
106
101
|
// Helper to create a JSON:API resource schema
|
|
107
|
-
const createJsonApiResourceSchema = (resourceType, attributesSchema) =>
|
|
108
|
-
type:
|
|
109
|
-
id:
|
|
102
|
+
export const createJsonApiResourceSchema = (resourceType, attributesSchema) => z.object({
|
|
103
|
+
type: z.literal(resourceType),
|
|
104
|
+
id: z.string(),
|
|
110
105
|
attributes: attributesSchema,
|
|
111
|
-
relationships:
|
|
112
|
-
links:
|
|
113
|
-
meta:
|
|
106
|
+
relationships: z.record(z.unknown()).optional(),
|
|
107
|
+
links: z.record(z.string()).optional(),
|
|
108
|
+
meta: z.record(z.unknown()).optional(),
|
|
114
109
|
});
|
|
115
|
-
exports.createJsonApiResourceSchema = createJsonApiResourceSchema;
|
|
116
110
|
// Backward compatibility exports (deprecated - use JSON:API versions)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
'filter[startDate]':
|
|
121
|
-
'filter[endDate]':
|
|
111
|
+
export const errorResponseSchema = jsonApiErrorResponseSchema;
|
|
112
|
+
export const paginationQuerySchema = jsonApiPaginationQuerySchema;
|
|
113
|
+
export const dateRangeQuerySchema = z.object({
|
|
114
|
+
'filter[startDate]': z.string().datetime().optional(),
|
|
115
|
+
'filter[endDate]': z.string().datetime().optional(),
|
|
122
116
|
});
|