@deepintel-ltd/farmpro-contracts 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +279 -0
  2. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,279 @@
1
+ # FarmPro API Contracts
2
+
3
+ Type-safe API contracts for FarmPro API using [ts-rest](https://ts-rest.com/) and [Zod](https://zod.dev/).
4
+
5
+ ## Overview
6
+
7
+ This package provides comprehensive, type-safe API contracts for all FarmPro modules. The contracts follow RESTful principles and use Zod schemas for runtime validation.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @farmpro/contracts
13
+ ```
14
+
15
+ ## Structure
16
+
17
+ The contracts are organized into modules:
18
+
19
+ ```
20
+ src/
21
+ ├── index.ts # Main exports
22
+ ├── routes/ # API route definitions
23
+ │ ├── index.ts # Main contract combining all routers
24
+ │ ├── farms.routes.ts
25
+ │ ├── fields.routes.ts
26
+ │ ├── tasks.routes.ts
27
+ │ ├── inventory.routes.ts
28
+ │ ├── finance.routes.ts
29
+ │ ├── harvest.routes.ts
30
+ │ ├── soil-tests.routes.ts
31
+ │ ├── weather.routes.ts
32
+ │ ├── team.routes.ts
33
+ │ ├── equipment.routes.ts
34
+ │ ├── documents.routes.ts
35
+ │ ├── suppliers.routes.ts
36
+ │ └── analytics.routes.ts
37
+ └── schemas/ # Zod schemas
38
+ ├── common.schemas.ts # Shared schemas (pagination, errors, GeoJSON)
39
+ ├── farms.schemas.ts
40
+ ├── fields.schemas.ts
41
+ ├── tasks.schemas.ts
42
+ ├── inventory.schemas.ts
43
+ ├── finance.schemas.ts
44
+ ├── harvest.schemas.ts
45
+ ├── soil-tests.schemas.ts
46
+ ├── weather.schemas.ts
47
+ ├── team.schemas.ts
48
+ ├── equipment.schemas.ts
49
+ ├── documents.schemas.ts
50
+ ├── suppliers.schemas.ts
51
+ └── analytics.schemas.ts
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ ### Backend (NestJS)
57
+
58
+ ```typescript
59
+ import { apiContract } from '@farmpro/contracts';
60
+ import { TsRestHandler, tsRestHandler } from '@ts-rest/nest';
61
+
62
+ @Controller()
63
+ export class FarmsController {
64
+ @TsRestHandler(apiContract.farms)
65
+ async handler() {
66
+ return tsRestHandler(apiContract.farms, {
67
+ listFarms: async ({ query }) => {
68
+ // Implementation
69
+ },
70
+ createFarm: async ({ body }) => {
71
+ // Implementation
72
+ },
73
+ // ... other handlers
74
+ });
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### Frontend
80
+
81
+ ```typescript
82
+ import { initClient } from '@ts-rest/core';
83
+ import { apiContract } from '@farmpro/contracts';
84
+
85
+ const client = initClient(apiContract, {
86
+ baseUrl: 'http://localhost:3000/api',
87
+ baseHeaders: {
88
+ 'Content-Type': 'application/json',
89
+ },
90
+ });
91
+
92
+ // Use the client
93
+ const farms = await client.farms.listFarms({ query: { page: 1, limit: 20 } });
94
+ const farm = await client.farms.createFarm({ body: { name: 'My Farm', location: 'Kano' } });
95
+ ```
96
+
97
+ ## API Modules
98
+
99
+ ### Authentication
100
+ - `POST /auth/login` - Login with email and password
101
+ - `POST /auth/signup` - Register new user
102
+ - `POST /auth/google/initiate` - Initiate Google OAuth flow
103
+ - `POST /auth/google/callback` - Handle Google OAuth callback
104
+ - `POST /auth/refresh` - Refresh access token
105
+ - `POST /auth/logout` - Logout user
106
+ - `POST /auth/password/reset-request` - Request password reset
107
+ - `POST /auth/password/reset` - Reset password with token
108
+ - `POST /auth/password/change` - Change password (authenticated)
109
+ - `POST /auth/email/verify` - Verify email address
110
+ - `POST /auth/email/resend-verification` - Resend verification email
111
+
112
+ ### Users
113
+ - `GET /user/profile` - Get current user profile
114
+ - `PATCH /user/profile` - Update user profile
115
+
116
+ ### Farms
117
+ - `GET /farms` - List farms
118
+ - `POST /farms` - Create farm
119
+ - `GET /farms/:id` - Get farm
120
+ - `PATCH /farms/:id` - Update farm
121
+ - `DELETE /farms/:id` - Delete farm
122
+
123
+ ### Fields
124
+ - `GET /farms/:farmId/fields` - List fields
125
+ - `POST /farms/:farmId/fields` - Create field
126
+ - `GET /farms/:farmId/fields/:id` - Get field
127
+ - `PATCH /farms/:farmId/fields/:id` - Update field
128
+ - `DELETE /farms/:farmId/fields/:id` - Delete field
129
+
130
+ ### Tasks
131
+ - `GET /farms/:farmId/tasks` - List tasks
132
+ - `POST /farms/:farmId/tasks` - Create task
133
+ - `GET /farms/:farmId/tasks/:id` - Get task
134
+ - `PATCH /farms/:farmId/tasks/:id` - Update task
135
+ - `POST /farms/:farmId/tasks/:id/complete` - Complete task
136
+ - `DELETE /farms/:farmId/tasks/:id` - Delete task
137
+ - `POST /farms/:farmId/tasks/:id/notes` - Add task note
138
+
139
+ ### Inventory
140
+ - `GET /farms/:farmId/inventory` - List inventory items
141
+ - `POST /farms/:farmId/inventory` - Create inventory item
142
+ - `GET /farms/:farmId/inventory/:id` - Get inventory item
143
+ - `PATCH /farms/:farmId/inventory/:id` - Update inventory item
144
+ - `DELETE /farms/:farmId/inventory/:id` - Delete inventory item
145
+ - `POST /farms/:farmId/inventory/purchase` - Log purchase
146
+
147
+ ### Finance
148
+ - Budget: `GET`, `POST`, `PATCH`, `DELETE /farms/:farmId/budget`
149
+ - Expenses: `GET`, `POST`, `PATCH`, `DELETE /farms/:farmId/expenses`
150
+ - Revenue: `GET`, `POST`, `PATCH`, `DELETE /farms/:farmId/revenue`
151
+ - `GET /farms/:farmId/finance/summary` - Finance summary
152
+
153
+ ### Harvest
154
+ - `GET /farms/:farmId/harvests` - List harvests
155
+ - `POST /farms/:farmId/harvests` - Create harvest
156
+ - `GET /farms/:farmId/harvests/:id` - Get harvest
157
+ - `PATCH /farms/:farmId/harvests/:id` - Update harvest
158
+ - `DELETE /farms/:farmId/harvests/:id` - Delete harvest
159
+
160
+ ### Soil Tests
161
+ - `GET /farms/:farmId/soil-tests` - List soil tests
162
+ - `POST /farms/:farmId/soil-tests` - Create soil test
163
+ - `GET /farms/:farmId/soil-tests/:id` - Get soil test
164
+ - `PATCH /farms/:farmId/soil-tests/:id` - Update soil test
165
+ - `DELETE /farms/:farmId/soil-tests/:id` - Delete soil test
166
+
167
+ ### Weather
168
+ - `GET /farms/:farmId/weather` - Get weather data
169
+
170
+ ### Team
171
+ - `GET /farms/:farmId/team` - List team members
172
+ - `POST /farms/:farmId/team` - Create team member
173
+ - `GET /farms/:farmId/team/:id` - Get team member
174
+ - `PATCH /farms/:farmId/team/:id` - Update team member
175
+ - `DELETE /farms/:farmId/team/:id` - Delete team member
176
+
177
+ ### Equipment
178
+ - `GET /farms/:farmId/equipment` - List equipment
179
+ - `POST /farms/:farmId/equipment` - Create equipment
180
+ - `GET /farms/:farmId/equipment/:id` - Get equipment
181
+ - `PATCH /farms/:farmId/equipment/:id` - Update equipment
182
+ - `DELETE /farms/:farmId/equipment/:id` - Delete equipment
183
+ - `POST /farms/:farmId/equipment/:id/maintenance` - Add maintenance record
184
+
185
+ ### Documents
186
+ - `GET /farms/:farmId/documents` - List documents
187
+ - `POST /farms/:farmId/documents` - Create document
188
+ - `GET /farms/:farmId/documents/:id` - Get document
189
+ - `PATCH /farms/:farmId/documents/:id` - Update document
190
+ - `DELETE /farms/:farmId/documents/:id` - Delete document
191
+
192
+ ### Suppliers
193
+ - Suppliers: `GET`, `POST`, `PATCH`, `DELETE /farms/:farmId/suppliers`
194
+ - Buyers: `GET`, `POST`, `PATCH`, `DELETE /farms/:farmId/buyers`
195
+
196
+ ### Analytics
197
+ - `GET /farms/:farmId/analytics` - Get analytics data
198
+
199
+ ## Common Features
200
+
201
+ ### Pagination
202
+ Most list endpoints support pagination:
203
+ ```typescript
204
+ {
205
+ page?: number; // Default: 1
206
+ limit?: number; // Default: 20, Max: 100
207
+ }
208
+ ```
209
+
210
+ ### Date Range Filtering
211
+ Many endpoints support date range filtering:
212
+ ```typescript
213
+ {
214
+ startDate?: string; // ISO datetime
215
+ endDate?: string; // ISO datetime
216
+ }
217
+ ```
218
+
219
+ ### GeoJSON Support
220
+ Farms and fields support GeoJSON geometry for boundaries:
221
+ ```typescript
222
+ {
223
+ type: 'Polygon' | 'MultiPolygon' | 'Point' | 'LineString';
224
+ coordinates: number[][][] | number[][] | number[];
225
+ }
226
+ ```
227
+
228
+ ### Error Responses
229
+ All endpoints return standardized error responses:
230
+ ```typescript
231
+ {
232
+ message: string;
233
+ code?: string;
234
+ errors?: Array<{
235
+ field?: string;
236
+ message: string;
237
+ }>;
238
+ }
239
+ ```
240
+
241
+ ## Type Safety
242
+
243
+ All schemas export TypeScript types:
244
+
245
+ ```typescript
246
+ import type {
247
+ FarmResponse,
248
+ CreateFarmInput,
249
+ FieldResponse,
250
+ TaskResponse,
251
+ // ... etc
252
+ } from '@farmpro/contracts';
253
+ ```
254
+
255
+ ## Development
256
+
257
+ ### Building
258
+
259
+ ```bash
260
+ npm run build
261
+ ```
262
+
263
+ ### Type Checking
264
+
265
+ ```bash
266
+ npm run type-check
267
+ ```
268
+
269
+ ### Publishing
270
+
271
+ ```bash
272
+ npm run prepublishOnly # Builds and validates
273
+ npm publish
274
+ ```
275
+
276
+ ## License
277
+
278
+ ISC
279
+
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@deepintel-ltd/farmpro-contracts",
3
+ "version": "1.0.1",
4
+ "description": "Type-safe API contracts for FarmPro API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "clean": "rm -rf dist",
14
+ "prepublishOnly": "npm run clean && npm run build",
15
+ "type-check": "tsc --noEmit",
16
+ "validate": "npm run type-check"
17
+ },
18
+ "keywords": [
19
+ "api",
20
+ "contracts",
21
+ "typescript",
22
+ "zod",
23
+ "ts-rest",
24
+ "agriculture",
25
+ "farming",
26
+ "farmpro"
27
+ ],
28
+ "author": "",
29
+ "license": "ISC",
30
+ "dependencies": {
31
+ "@ts-rest/core": "^3.52.1",
32
+ "zod": "^3.25.76"
33
+ },
34
+ "devDependencies": {
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "peerDependencies": {
38
+ "@ts-rest/core": "^3.52.0",
39
+ "zod": "^3.25.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "registry": "https://registry.npmjs.org/"
44
+ }
45
+ }