@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,63 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.autonomousMonitoringStatsResponseSchema = exports.autonomousMonitoringStatsResourceSchema = exports.autonomousMonitoringStatsAttributesSchema = exports.learnedPatternSchema = exports.effectivenessSchema = exports.crossSourceMatchSchema = exports.sourceStatsSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const common_schemas_1 = require("./common.schemas");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createJsonApiResourceSchema, jsonApiSingleResponseSchema, } from './common.schemas';
|
|
6
3
|
/**
|
|
7
4
|
* Admin schemas for autonomous monitoring analytics
|
|
8
5
|
*/
|
|
9
6
|
// Source statistics
|
|
10
|
-
|
|
11
|
-
recommendations:
|
|
12
|
-
tasksCreated:
|
|
13
|
-
tasksUpdated:
|
|
14
|
-
skipped:
|
|
15
|
-
avgConfidence:
|
|
16
|
-
tasksCompleted:
|
|
17
|
-
successfulOutcomes:
|
|
18
|
-
successRate:
|
|
7
|
+
export const sourceStatsSchema = z.object({
|
|
8
|
+
recommendations: z.number(),
|
|
9
|
+
tasksCreated: z.number(),
|
|
10
|
+
tasksUpdated: z.number(),
|
|
11
|
+
skipped: z.number(),
|
|
12
|
+
avgConfidence: z.number(),
|
|
13
|
+
tasksCompleted: z.number().optional(),
|
|
14
|
+
successfulOutcomes: z.number().optional(),
|
|
15
|
+
successRate: z.number().optional(),
|
|
19
16
|
});
|
|
20
17
|
// Cross-source match
|
|
21
|
-
|
|
22
|
-
issueType:
|
|
23
|
-
sources:
|
|
24
|
-
occurrences:
|
|
25
|
-
tasksCreated:
|
|
26
|
-
deduplicationRate:
|
|
18
|
+
export const crossSourceMatchSchema = z.object({
|
|
19
|
+
issueType: z.string(),
|
|
20
|
+
sources: z.array(z.string()),
|
|
21
|
+
occurrences: z.number(),
|
|
22
|
+
tasksCreated: z.number(),
|
|
23
|
+
deduplicationRate: z.number(),
|
|
27
24
|
});
|
|
28
25
|
// Effectiveness metrics
|
|
29
|
-
|
|
30
|
-
tasksCompleted:
|
|
31
|
-
successfulOutcomes:
|
|
32
|
-
successRate:
|
|
33
|
-
avgImprovementScore:
|
|
26
|
+
export const effectivenessSchema = z.object({
|
|
27
|
+
tasksCompleted: z.number(),
|
|
28
|
+
successfulOutcomes: z.number(),
|
|
29
|
+
successRate: z.number(),
|
|
30
|
+
avgImprovementScore: z.number(),
|
|
34
31
|
});
|
|
35
32
|
// Learned pattern
|
|
36
|
-
|
|
37
|
-
issueType:
|
|
38
|
-
bestSource:
|
|
39
|
-
bestSourceScore:
|
|
40
|
-
worstSource:
|
|
41
|
-
worstSourceScore:
|
|
33
|
+
export const learnedPatternSchema = z.object({
|
|
34
|
+
issueType: z.string(),
|
|
35
|
+
bestSource: z.string(),
|
|
36
|
+
bestSourceScore: z.number(),
|
|
37
|
+
worstSource: z.string(),
|
|
38
|
+
worstSourceScore: z.number(),
|
|
42
39
|
});
|
|
43
40
|
// Autonomous monitoring stats attributes
|
|
44
|
-
|
|
45
|
-
overall:
|
|
46
|
-
totalRecommendations:
|
|
47
|
-
tasksCreated:
|
|
48
|
-
tasksUpdated:
|
|
49
|
-
skipped:
|
|
50
|
-
deduplicationRate:
|
|
41
|
+
export const autonomousMonitoringStatsAttributesSchema = z.object({
|
|
42
|
+
overall: z.object({
|
|
43
|
+
totalRecommendations: z.number(),
|
|
44
|
+
tasksCreated: z.number(),
|
|
45
|
+
tasksUpdated: z.number(),
|
|
46
|
+
skipped: z.number(),
|
|
47
|
+
deduplicationRate: z.number(),
|
|
51
48
|
}),
|
|
52
|
-
bySource:
|
|
53
|
-
crossSourceMatches:
|
|
54
|
-
effectiveness:
|
|
55
|
-
learnedPatterns:
|
|
56
|
-
totalPatterns:
|
|
57
|
-
patterns:
|
|
49
|
+
bySource: z.record(z.string(), sourceStatsSchema),
|
|
50
|
+
crossSourceMatches: z.array(crossSourceMatchSchema),
|
|
51
|
+
effectiveness: z.record(z.string(), effectivenessSchema),
|
|
52
|
+
learnedPatterns: z.object({
|
|
53
|
+
totalPatterns: z.number(),
|
|
54
|
+
patterns: z.array(learnedPatternSchema),
|
|
58
55
|
}),
|
|
59
56
|
});
|
|
60
57
|
// Resource schema
|
|
61
|
-
|
|
58
|
+
export const autonomousMonitoringStatsResourceSchema = createJsonApiResourceSchema('autonomous-monitoring-stats', autonomousMonitoringStatsAttributesSchema);
|
|
62
59
|
// Response schema
|
|
63
|
-
|
|
60
|
+
export const autonomousMonitoringStatsResponseSchema = jsonApiSingleResponseSchema(autonomousMonitoringStatsResourceSchema);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const recommendations_schemas_1 = require("./recommendations.schemas");
|
|
6
|
-
const common_schemas_1 = require("./common.schemas");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { recommendationSchema } from './recommendations.schemas';
|
|
3
|
+
import { createJsonApiResourceSchema, jsonApiSingleResponseSchema, jsonApiCollectionResponseSchema, timestampsSchema, } from './common.schemas';
|
|
7
4
|
/**
|
|
8
5
|
* Agent Workflow Schemas
|
|
9
6
|
*
|
|
@@ -12,59 +9,59 @@ const common_schemas_1 = require("./common.schemas");
|
|
|
12
9
|
* process of turning a recommendation into a task.
|
|
13
10
|
*/
|
|
14
11
|
// The overall status of an agent workflow
|
|
15
|
-
|
|
12
|
+
export const agentWorkflowStatusSchema = z.enum([
|
|
16
13
|
'in_progress',
|
|
17
14
|
'completed',
|
|
18
15
|
'failed',
|
|
19
16
|
]);
|
|
20
17
|
// The final outcome of a recommendation-to-task workflow
|
|
21
|
-
|
|
18
|
+
export const workflowOutcomeSchema = z.enum([
|
|
22
19
|
'task_created',
|
|
23
20
|
'task_updated',
|
|
24
21
|
'no_action_needed',
|
|
25
22
|
'error',
|
|
26
23
|
]);
|
|
27
24
|
// The outcome for a single recommendation within a workflow
|
|
28
|
-
|
|
25
|
+
export const recommendationOutcomeSchema = z.enum([
|
|
29
26
|
'created',
|
|
30
27
|
'updated',
|
|
31
28
|
'skipped',
|
|
32
29
|
'error',
|
|
33
30
|
]);
|
|
34
31
|
// Result for a single recommendation processed by the agent
|
|
35
|
-
|
|
36
|
-
recommendation:
|
|
37
|
-
outcome:
|
|
38
|
-
taskId:
|
|
39
|
-
reason:
|
|
32
|
+
export const agentRecommendationResultSchema = z.object({
|
|
33
|
+
recommendation: recommendationSchema,
|
|
34
|
+
outcome: recommendationOutcomeSchema,
|
|
35
|
+
taskId: z.string().uuid().optional(),
|
|
36
|
+
reason: z.string(),
|
|
40
37
|
});
|
|
41
38
|
// The `agentResults` object that will be stored as JSON in the database
|
|
42
|
-
|
|
43
|
-
summary:
|
|
44
|
-
sourceType:
|
|
45
|
-
tasksCreated:
|
|
46
|
-
tasksUpdated:
|
|
47
|
-
skipped:
|
|
39
|
+
export const agentResultsSchema = z.object({
|
|
40
|
+
summary: z.object({
|
|
41
|
+
sourceType: z.string(),
|
|
42
|
+
tasksCreated: z.number().int(),
|
|
43
|
+
tasksUpdated: z.number().int(),
|
|
44
|
+
skipped: z.number().int(),
|
|
48
45
|
}),
|
|
49
|
-
results:
|
|
46
|
+
results: z.array(agentRecommendationResultSchema),
|
|
50
47
|
// Optionally include other agent reviews for full traceability
|
|
51
|
-
taskReview:
|
|
48
|
+
taskReview: z.any().optional(),
|
|
52
49
|
});
|
|
53
50
|
// The main attributes for an AgentWorkflow record
|
|
54
|
-
|
|
55
|
-
workflowType:
|
|
56
|
-
triggerEvent:
|
|
57
|
-
triggerId:
|
|
58
|
-
fieldId:
|
|
59
|
-
farmId:
|
|
60
|
-
status:
|
|
61
|
-
outcome:
|
|
62
|
-
agentResults:
|
|
63
|
-
errorMessage:
|
|
64
|
-
completedAt:
|
|
65
|
-
}).merge(
|
|
51
|
+
export const agentWorkflowAttributesSchema = z.object({
|
|
52
|
+
workflowType: z.literal('recommendation_to_task'),
|
|
53
|
+
triggerEvent: z.string(), // e.g., 'observation.analysis.completed'
|
|
54
|
+
triggerId: z.string(), // ID of the observation, alert, etc.
|
|
55
|
+
fieldId: z.string().uuid(),
|
|
56
|
+
farmId: z.string().uuid(),
|
|
57
|
+
status: agentWorkflowStatusSchema,
|
|
58
|
+
outcome: workflowOutcomeSchema.nullable(),
|
|
59
|
+
agentResults: agentResultsSchema.nullable(),
|
|
60
|
+
errorMessage: z.string().nullable(),
|
|
61
|
+
completedAt: z.date().nullable(),
|
|
62
|
+
}).merge(timestampsSchema);
|
|
66
63
|
// JSON:API resource schemas
|
|
67
|
-
|
|
64
|
+
export const agentWorkflowResourceSchema = createJsonApiResourceSchema('agent-workflows', agentWorkflowAttributesSchema);
|
|
68
65
|
// Response schemas
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
export const agentWorkflowResponseSchema = jsonApiSingleResponseSchema(agentWorkflowResourceSchema);
|
|
67
|
+
export const agentWorkflowListResponseSchema = jsonApiCollectionResponseSchema(agentWorkflowResourceSchema);
|
|
@@ -1,77 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.conversationListResponseSchema = exports.conversationListResourceSchema = exports.conversationListAttributesSchema = exports.conversationListItemSchema = exports.conversationHistoryResponseSchema = exports.conversationHistoryResourceSchema = exports.conversationHistoryAttributesSchema = exports.conversationHistoryMessageSchema = exports.agentChatResponseSchema = exports.agentChatResponseResourceSchema = exports.agentChatResponseAttributesSchema = exports.chatRequestSchema = exports.chatRequestAttributesSchema = exports.toolCallResultSchema = exports.conversationMessageSchema = exports.messageRoleSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const common_schemas_1 = require("./common.schemas");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createJsonApiResourceSchema, jsonApiSingleResponseSchema, } from './common.schemas';
|
|
6
3
|
/**
|
|
7
4
|
* Agents schemas - JSON:API compliant
|
|
8
5
|
*/
|
|
9
6
|
// Conversation message role enum
|
|
10
|
-
|
|
7
|
+
export const messageRoleSchema = z.enum(['user', 'assistant']);
|
|
11
8
|
// Conversation message schema
|
|
12
|
-
|
|
13
|
-
role:
|
|
14
|
-
content:
|
|
9
|
+
export const conversationMessageSchema = z.object({
|
|
10
|
+
role: messageRoleSchema,
|
|
11
|
+
content: z.string().min(1),
|
|
15
12
|
});
|
|
16
13
|
// Tool call result schema
|
|
17
|
-
|
|
18
|
-
tool:
|
|
19
|
-
result:
|
|
14
|
+
export const toolCallResultSchema = z.object({
|
|
15
|
+
tool: z.string(),
|
|
16
|
+
result: z.unknown(), // Tool results can be any shape
|
|
20
17
|
});
|
|
21
18
|
// Chat request attributes schema
|
|
22
|
-
|
|
23
|
-
message:
|
|
24
|
-
farmId:
|
|
25
|
-
conversationId:
|
|
26
|
-
conversationHistory:
|
|
19
|
+
export const chatRequestAttributesSchema = z.object({
|
|
20
|
+
message: z.string().min(1).max(5000),
|
|
21
|
+
farmId: z.string().uuid().optional(),
|
|
22
|
+
conversationId: z.string().uuid().optional(), // Continue existing conversation
|
|
23
|
+
conversationHistory: z.array(conversationMessageSchema).optional(),
|
|
27
24
|
});
|
|
28
25
|
// Chat request input (JSON:API format)
|
|
29
|
-
|
|
30
|
-
type:
|
|
31
|
-
attributes:
|
|
26
|
+
export const chatRequestSchema = z.object({
|
|
27
|
+
type: z.literal('agent-chat-requests'),
|
|
28
|
+
attributes: chatRequestAttributesSchema,
|
|
32
29
|
});
|
|
33
30
|
// Agent chat response attributes schema
|
|
34
|
-
|
|
35
|
-
response:
|
|
36
|
-
toolCalls:
|
|
37
|
-
conversationId:
|
|
31
|
+
export const agentChatResponseAttributesSchema = z.object({
|
|
32
|
+
response: z.string(),
|
|
33
|
+
toolCalls: z.array(toolCallResultSchema).optional(),
|
|
34
|
+
conversationId: z.string().uuid(), // Return conversation ID for continuing
|
|
38
35
|
});
|
|
39
36
|
// Agent chat response resource (JSON:API resource object)
|
|
40
|
-
|
|
37
|
+
export const agentChatResponseResourceSchema = createJsonApiResourceSchema('agent-chat-responses', agentChatResponseAttributesSchema);
|
|
41
38
|
// Agent chat response (JSON:API single response)
|
|
42
|
-
|
|
39
|
+
export const agentChatResponseSchema = jsonApiSingleResponseSchema(agentChatResponseResourceSchema);
|
|
43
40
|
// Conversation history message schema (with timestamp)
|
|
44
|
-
|
|
45
|
-
role:
|
|
46
|
-
content:
|
|
47
|
-
createdAt:
|
|
41
|
+
export const conversationHistoryMessageSchema = z.object({
|
|
42
|
+
role: messageRoleSchema,
|
|
43
|
+
content: z.string(),
|
|
44
|
+
createdAt: z.string().datetime().optional(),
|
|
48
45
|
});
|
|
49
46
|
// Conversation history response attributes
|
|
50
|
-
|
|
51
|
-
messages:
|
|
52
|
-
conversationId:
|
|
47
|
+
export const conversationHistoryAttributesSchema = z.object({
|
|
48
|
+
messages: z.array(conversationHistoryMessageSchema),
|
|
49
|
+
conversationId: z.string().uuid(),
|
|
53
50
|
});
|
|
54
51
|
// Conversation history resource
|
|
55
|
-
|
|
52
|
+
export const conversationHistoryResourceSchema = createJsonApiResourceSchema('conversation-histories', conversationHistoryAttributesSchema);
|
|
56
53
|
// Conversation history response
|
|
57
|
-
|
|
54
|
+
export const conversationHistoryResponseSchema = jsonApiSingleResponseSchema(conversationHistoryResourceSchema);
|
|
58
55
|
// Conversation list item schema
|
|
59
|
-
|
|
60
|
-
id:
|
|
61
|
-
title:
|
|
62
|
-
summary:
|
|
63
|
-
farmId:
|
|
64
|
-
messageCount:
|
|
65
|
-
lastMessageAt:
|
|
66
|
-
createdAt:
|
|
67
|
-
updatedAt:
|
|
56
|
+
export const conversationListItemSchema = z.object({
|
|
57
|
+
id: z.string().uuid(),
|
|
58
|
+
title: z.string().nullable(),
|
|
59
|
+
summary: z.string().nullable(),
|
|
60
|
+
farmId: z.string().uuid().nullable(),
|
|
61
|
+
messageCount: z.number().int().min(0),
|
|
62
|
+
lastMessageAt: z.string().datetime().nullable(),
|
|
63
|
+
createdAt: z.string().datetime(),
|
|
64
|
+
updatedAt: z.string().datetime(),
|
|
68
65
|
});
|
|
69
66
|
// Conversation list response attributes
|
|
70
|
-
|
|
71
|
-
conversations:
|
|
72
|
-
total:
|
|
67
|
+
export const conversationListAttributesSchema = z.object({
|
|
68
|
+
conversations: z.array(conversationListItemSchema),
|
|
69
|
+
total: z.number().int().min(0),
|
|
73
70
|
});
|
|
74
71
|
// Conversation list resource
|
|
75
|
-
|
|
72
|
+
export const conversationListResourceSchema = createJsonApiResourceSchema('conversation-lists', conversationListAttributesSchema);
|
|
76
73
|
// Conversation list response
|
|
77
|
-
|
|
74
|
+
export const conversationListResponseSchema = jsonApiSingleResponseSchema(conversationListResourceSchema);
|
|
@@ -1,73 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.analyticsResponseSchema = exports.analyticsResourceSchema = exports.analyticsAttributesSchema = exports.profitabilityAnalysisSchema = exports.fieldPerformanceSchema = exports.marketDataSchema = exports.yieldDataSchema = exports.performanceDataPointSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const common_schemas_1 = require("./common.schemas");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createJsonApiResourceSchema, jsonApiSingleResponseSchema } from './common.schemas';
|
|
6
3
|
/**
|
|
7
4
|
* Analytics schemas - JSON:API compliant
|
|
8
5
|
*/
|
|
9
6
|
// Performance data point (for trend charts)
|
|
10
|
-
|
|
11
|
-
date:
|
|
12
|
-
ndvi:
|
|
13
|
-
moisture:
|
|
14
|
-
rainfall:
|
|
7
|
+
export const performanceDataPointSchema = z.object({
|
|
8
|
+
date: z.string().datetime(),
|
|
9
|
+
ndvi: z.number().nullable(),
|
|
10
|
+
moisture: z.number().nullable(),
|
|
11
|
+
rainfall: z.number().nullable(),
|
|
15
12
|
});
|
|
16
13
|
// Yield data
|
|
17
|
-
|
|
18
|
-
forecast:
|
|
19
|
-
target:
|
|
20
|
-
revenue:
|
|
21
|
-
costs:
|
|
14
|
+
export const yieldDataSchema = z.object({
|
|
15
|
+
forecast: z.number().nonnegative(),
|
|
16
|
+
target: z.number().nonnegative(),
|
|
17
|
+
revenue: z.number().nonnegative(),
|
|
18
|
+
costs: z.number().nonnegative(),
|
|
22
19
|
});
|
|
23
20
|
// Market data
|
|
24
|
-
|
|
25
|
-
id:
|
|
26
|
-
crop:
|
|
27
|
-
price:
|
|
28
|
-
trend:
|
|
21
|
+
export const marketDataSchema = z.object({
|
|
22
|
+
id: z.string().uuid(),
|
|
23
|
+
crop: z.string(),
|
|
24
|
+
price: z.string(), // e.g., "₦28,500/100kg"
|
|
25
|
+
trend: z.enum(['up', 'down', 'stable']),
|
|
29
26
|
});
|
|
30
27
|
// Field performance
|
|
31
|
-
|
|
32
|
-
id:
|
|
33
|
-
name:
|
|
34
|
-
ndvi:
|
|
35
|
-
trend:
|
|
36
|
-
moisture:
|
|
37
|
-
issue:
|
|
28
|
+
export const fieldPerformanceSchema = z.object({
|
|
29
|
+
id: z.string().uuid(),
|
|
30
|
+
name: z.string(),
|
|
31
|
+
ndvi: z.number(),
|
|
32
|
+
trend: z.enum(['up', 'down', 'stable']),
|
|
33
|
+
moisture: z.string(),
|
|
34
|
+
issue: z.string().nullable(),
|
|
38
35
|
});
|
|
39
36
|
// Profitability analysis
|
|
40
|
-
|
|
41
|
-
totalRevenue:
|
|
42
|
-
totalCosts:
|
|
43
|
-
netProfit:
|
|
44
|
-
profitMargin:
|
|
45
|
-
fieldBreakdown:
|
|
46
|
-
fieldId:
|
|
47
|
-
fieldName:
|
|
48
|
-
revenue:
|
|
49
|
-
costs:
|
|
50
|
-
profit:
|
|
51
|
-
margin:
|
|
37
|
+
export const profitabilityAnalysisSchema = z.object({
|
|
38
|
+
totalRevenue: z.number().nonnegative(),
|
|
39
|
+
totalCosts: z.number().nonnegative(),
|
|
40
|
+
netProfit: z.number(),
|
|
41
|
+
profitMargin: z.number(), // Percentage
|
|
42
|
+
fieldBreakdown: z.array(z.object({
|
|
43
|
+
fieldId: z.string().uuid(),
|
|
44
|
+
fieldName: z.string(),
|
|
45
|
+
revenue: z.number().nonnegative(),
|
|
46
|
+
costs: z.number().nonnegative(),
|
|
47
|
+
profit: z.number(),
|
|
48
|
+
margin: z.number(),
|
|
52
49
|
})).optional(),
|
|
53
|
-
cropBreakdown:
|
|
54
|
-
crop:
|
|
55
|
-
revenue:
|
|
56
|
-
costs:
|
|
57
|
-
profit:
|
|
58
|
-
margin:
|
|
50
|
+
cropBreakdown: z.array(z.object({
|
|
51
|
+
crop: z.string(),
|
|
52
|
+
revenue: z.number().nonnegative(),
|
|
53
|
+
costs: z.number().nonnegative(),
|
|
54
|
+
profit: z.number(),
|
|
55
|
+
margin: z.number(),
|
|
59
56
|
})).optional(),
|
|
60
57
|
});
|
|
61
58
|
// Analytics attributes schema (for JSON:API attributes object)
|
|
62
|
-
|
|
63
|
-
farmId:
|
|
64
|
-
performanceData:
|
|
65
|
-
yield:
|
|
66
|
-
marketData:
|
|
67
|
-
fieldPerformance:
|
|
68
|
-
profitability:
|
|
59
|
+
export const analyticsAttributesSchema = z.object({
|
|
60
|
+
farmId: z.string().uuid(),
|
|
61
|
+
performanceData: z.array(performanceDataPointSchema),
|
|
62
|
+
yield: yieldDataSchema,
|
|
63
|
+
marketData: z.array(marketDataSchema),
|
|
64
|
+
fieldPerformance: z.array(fieldPerformanceSchema),
|
|
65
|
+
profitability: profitabilityAnalysisSchema.optional(),
|
|
69
66
|
});
|
|
70
67
|
// Analytics resource (JSON:API resource object)
|
|
71
|
-
|
|
68
|
+
export const analyticsResourceSchema = createJsonApiResourceSchema('analytics', analyticsAttributesSchema);
|
|
72
69
|
// Analytics response (JSON:API format)
|
|
73
|
-
|
|
70
|
+
export const analyticsResponseSchema = jsonApiSingleResponseSchema(analyticsResourceSchema);
|