@deepintel-ltd/farmpro-contracts 1.7.21 → 1.8.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device-gateway.schemas.d.ts","sourceRoot":"","sources":["../../src/schemas/device-gateway.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB;;;;;;;;;EAG5B,CAAC;AAEH,eAAO,MAAM,kBAAkB,sEAK7B,CAAC;AAEH,eAAO,MAAM,oBAAoB,sDAA8C,CAAC;AAEhF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;EASjC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;EAGhC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW7B,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGlC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;EAMrC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;EAGtC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;EAOjC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAErC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;EAItC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;EAQ9B,CAAC;AAEH,eAAO,MAAM,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAErC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;EAItC,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUzB,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEtC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;EAKvC,CAAC;AAEH,eAAO,MAAM,6BAA6B;;;;;;;;;EAGxC,CAAC"}
@@ -0,0 +1,165 @@
1
+ import { z } from 'zod';
2
+ export const deviceErrorSchema = z.object({
3
+ message: z.string(),
4
+ code: z.string(),
5
+ });
6
+ export const actuatorTypeSchema = z.enum([
7
+ 'IRRIGATION_VALVE',
8
+ 'FERT_PUMP_A',
9
+ 'FERT_PUMP_B',
10
+ 'FAN',
11
+ ]);
12
+ export const actuatorStatesSchema = z.record(z.string(), z.string()).optional();
13
+ export const heartbeatRequestSchema = z.object({
14
+ deviceId: z.string().uuid(),
15
+ firmwareVersion: z.string().max(50).optional(),
16
+ uptimeSec: z.number().int().nonnegative().optional(),
17
+ wifiRssi: z.number().optional(),
18
+ freeHeap: z.number().int().nonnegative().optional(),
19
+ bufferedReadingsCount: z.number().int().nonnegative().optional(),
20
+ bufferOverflow: z.boolean().optional(),
21
+ actuatorStates: actuatorStatesSchema,
22
+ });
23
+ export const pumpCalibrationSchema = z.object({
24
+ mlPerSecond: z.number().positive(),
25
+ calibratedAt: z.string().datetime().optional(),
26
+ });
27
+ export const deviceConfigSchema = z.object({
28
+ heartbeatIntervalSec: z.number().int().positive().optional(),
29
+ commandPollIntervalSec: z.number().int().positive().optional(),
30
+ sensorIntervals: z.record(z.string(), z.number().int().positive()).optional(),
31
+ pumpCalibration: z
32
+ .object({
33
+ fert_pump_a: pumpCalibrationSchema.optional(),
34
+ fert_pump_b: pumpCalibrationSchema.optional(),
35
+ })
36
+ .optional(),
37
+ gpioMap: z.record(z.string(), z.number().int()).optional(),
38
+ });
39
+ export const heartbeatResponseSchema = z.object({
40
+ serverTime: z.string().datetime(),
41
+ config: deviceConfigSchema,
42
+ });
43
+ export const sensorReadingRequestSchema = z.object({
44
+ value: z.number(),
45
+ unit: z.string().max(20),
46
+ quality: z.enum(['good', 'fair', 'poor']).optional(),
47
+ readAt: z.string().datetime(),
48
+ metadata: z.record(z.string(), z.unknown()).optional(),
49
+ });
50
+ export const sensorReadingResponseSchema = z.object({
51
+ readingId: z.string().uuid(),
52
+ alertTriggered: z.boolean(),
53
+ });
54
+ export const batchReadingItemSchema = z.object({
55
+ sensorId: z.string().uuid(),
56
+ value: z.number(),
57
+ unit: z.string().max(20),
58
+ quality: z.enum(['good', 'fair', 'poor']).optional(),
59
+ readAt: z.string().datetime(),
60
+ metadata: z.record(z.string(), z.unknown()).optional(),
61
+ });
62
+ export const batchReadingsRequestSchema = z.object({
63
+ readings: z.array(batchReadingItemSchema).min(1).max(500),
64
+ });
65
+ export const batchReadingsResponseSchema = z.object({
66
+ accepted: z.number().int().nonnegative(),
67
+ rejected: z.number().int().nonnegative(),
68
+ alertsTriggered: z.number().int().nonnegative(),
69
+ });
70
+ export const deviceCommandSchema = z.object({
71
+ id: z.string().uuid(),
72
+ actuatorId: z.string().uuid(),
73
+ actuatorType: actuatorTypeSchema,
74
+ command: z.enum(['ON', 'OFF', 'PULSE']),
75
+ durationSec: z.number().int().positive().nullable().optional(),
76
+ source: z.string(),
77
+ createdAt: z.string().datetime(),
78
+ });
79
+ export const listCommandsQuerySchema = z.object({
80
+ deviceId: z.string().uuid(),
81
+ });
82
+ export const listCommandsResponseSchema = z.object({
83
+ commands: z.array(deviceCommandSchema),
84
+ });
85
+ export const commandAckRequestSchema = z.object({
86
+ status: z.enum(['acked', 'failed']),
87
+ executedAt: z.string().datetime(),
88
+ error: z.string().optional(),
89
+ metadata: z.record(z.string(), z.unknown()).optional(),
90
+ });
91
+ export const commandAckResponseSchema = z.object({
92
+ success: z.boolean(),
93
+ });
94
+ export const snapshotUploadResponseSchema = z.object({
95
+ snapshotId: z.string().uuid(),
96
+ imageUrl: z.string(),
97
+ analysisQueued: z.boolean(),
98
+ });
99
+ // Admin (JWT) schemas
100
+ export const createDeviceRequestSchema = z.object({
101
+ name: z.string().min(1).max(200),
102
+ config: deviceConfigSchema.optional(),
103
+ });
104
+ export const createDeviceResponseSchema = z.object({
105
+ device: z.object({
106
+ id: z.string().uuid(),
107
+ name: z.string(),
108
+ fieldId: z.string().uuid(),
109
+ farmId: z.string().uuid(),
110
+ createdAt: z.string().datetime(),
111
+ }),
112
+ apiKey: z.string(),
113
+ });
114
+ export const deviceSummarySchema = z.object({
115
+ id: z.string().uuid(),
116
+ name: z.string(),
117
+ fieldId: z.string().uuid(),
118
+ farmId: z.string().uuid(),
119
+ lastSeenAt: z.string().datetime().nullable(),
120
+ bufferedReadingsCount: z.number().int().nullable(),
121
+ bufferOverflow: z.boolean(),
122
+ firmwareVersion: z.string().nullable(),
123
+ isOnline: z.boolean(),
124
+ config: deviceConfigSchema.nullable(),
125
+ createdAt: z.string().datetime(),
126
+ });
127
+ export const listDevicesResponseSchema = z.object({
128
+ devices: z.array(deviceSummarySchema),
129
+ });
130
+ export const updateDeviceRequestSchema = z.object({
131
+ name: z.string().min(1).max(200).optional(),
132
+ config: deviceConfigSchema.optional(),
133
+ });
134
+ export const updateDeviceResponseSchema = z.object({
135
+ device: deviceSummarySchema,
136
+ });
137
+ export const createActuatorRequestSchema = z.object({
138
+ type: actuatorTypeSchema,
139
+ name: z.string().min(1).max(200),
140
+ gpioPin: z.number().int().optional(),
141
+ });
142
+ export const actuatorSchema = z.object({
143
+ id: z.string().uuid(),
144
+ deviceId: z.string().uuid(),
145
+ fieldId: z.string().uuid(),
146
+ farmId: z.string().uuid(),
147
+ type: actuatorTypeSchema,
148
+ name: z.string(),
149
+ gpioPin: z.number().int().nullable(),
150
+ status: z.string(),
151
+ lastCommandAt: z.string().datetime().nullable(),
152
+ });
153
+ export const listActuatorsResponseSchema = z.object({
154
+ actuators: z.array(actuatorSchema),
155
+ });
156
+ export const actuatorCommandRequestSchema = z.object({
157
+ command: z.enum(['ON', 'OFF', 'PULSE']),
158
+ durationSec: z.number().int().positive().optional(),
159
+ source: z.enum(['manual', 'schedule', 'rule']).default('manual'),
160
+ metadata: z.record(z.string(), z.unknown()).optional(),
161
+ });
162
+ export const actuatorCommandResponseSchema = z.object({
163
+ commandId: z.string().uuid(),
164
+ status: z.string(),
165
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepintel-ltd/farmpro-contracts",
3
- "version": "1.7.21",
3
+ "version": "1.8.0",
4
4
  "description": "Type-safe API contracts for FarmPro API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",