@deepintel-ltd/farmpro-contracts 1.7.1 → 1.7.3

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,172 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Normalized internal message format
4
+ */
5
+ export declare const whatsappMessageSchema: z.ZodObject<{
6
+ id: z.ZodString;
7
+ messageId: z.ZodString;
8
+ from: z.ZodString;
9
+ type: z.ZodEnum<["text", "voice", "image", "location", "document"]>;
10
+ content: z.ZodOptional<z.ZodString>;
11
+ mediaId: z.ZodOptional<z.ZodString>;
12
+ location: z.ZodOptional<z.ZodObject<{
13
+ latitude: z.ZodNumber;
14
+ longitude: z.ZodNumber;
15
+ }, "strip", z.ZodTypeAny, {
16
+ latitude: number;
17
+ longitude: number;
18
+ }, {
19
+ latitude: number;
20
+ longitude: number;
21
+ }>>;
22
+ timestamp: z.ZodDate;
23
+ }, "strip", z.ZodTypeAny, {
24
+ type: "location" | "text" | "voice" | "image" | "document";
25
+ id: string;
26
+ timestamp: Date;
27
+ messageId: string;
28
+ from: string;
29
+ location?: {
30
+ latitude: number;
31
+ longitude: number;
32
+ } | undefined;
33
+ content?: string | undefined;
34
+ mediaId?: string | undefined;
35
+ }, {
36
+ type: "location" | "text" | "voice" | "image" | "document";
37
+ id: string;
38
+ timestamp: Date;
39
+ messageId: string;
40
+ from: string;
41
+ location?: {
42
+ latitude: number;
43
+ longitude: number;
44
+ } | undefined;
45
+ content?: string | undefined;
46
+ mediaId?: string | undefined;
47
+ }>;
48
+ export type WhatsAppMessage = z.infer<typeof whatsappMessageSchema>;
49
+ /**
50
+ * Intent classification for routing messages
51
+ */
52
+ export declare const intentSchema: z.ZodEnum<["question", "task_create", "task_list", "expense_log", "observation", "status", "weather", "inventory", "set_farm", "help", "unknown"]>;
53
+ export type Intent = z.infer<typeof intentSchema>;
54
+ /**
55
+ * WhatsApp webhook verification query parameters
56
+ */
57
+ export declare const webhookVerifyQuerySchema: z.ZodObject<{
58
+ 'hub.mode': z.ZodString;
59
+ 'hub.verify_token': z.ZodString;
60
+ 'hub.challenge': z.ZodString;
61
+ }, "strip", z.ZodTypeAny, {
62
+ 'hub.mode': string;
63
+ 'hub.verify_token': string;
64
+ 'hub.challenge': string;
65
+ }, {
66
+ 'hub.mode': string;
67
+ 'hub.verify_token': string;
68
+ 'hub.challenge': string;
69
+ }>;
70
+ export type WebhookVerifyQuery = z.infer<typeof webhookVerifyQuerySchema>;
71
+ /**
72
+ * Webhook response for successful message handling
73
+ */
74
+ export declare const webhookMessageResponseSchema: z.ZodObject<{
75
+ status: z.ZodLiteral<"ok">;
76
+ }, "strip", z.ZodTypeAny, {
77
+ status: "ok";
78
+ }, {
79
+ status: "ok";
80
+ }>;
81
+ export type WebhookMessageResponse = z.infer<typeof webhookMessageResponseSchema>;
82
+ export declare const phoneLinkAttributesSchema: z.ZodObject<{
83
+ id: z.ZodString;
84
+ userId: z.ZodString;
85
+ phoneNumber: z.ZodString;
86
+ whatsappId: z.ZodNullable<z.ZodString>;
87
+ isVerified: z.ZodBoolean;
88
+ defaultFarmId: z.ZodNullable<z.ZodString>;
89
+ language: z.ZodString;
90
+ createdAt: z.ZodString;
91
+ updatedAt: z.ZodString;
92
+ }, "strip", z.ZodTypeAny, {
93
+ id: string;
94
+ createdAt: string;
95
+ updatedAt: string;
96
+ userId: string;
97
+ phoneNumber: string;
98
+ whatsappId: string | null;
99
+ isVerified: boolean;
100
+ defaultFarmId: string | null;
101
+ language: string;
102
+ }, {
103
+ id: string;
104
+ createdAt: string;
105
+ updatedAt: string;
106
+ userId: string;
107
+ phoneNumber: string;
108
+ whatsappId: string | null;
109
+ isVerified: boolean;
110
+ defaultFarmId: string | null;
111
+ language: string;
112
+ }>;
113
+ export type PhoneLinkAttributes = z.infer<typeof phoneLinkAttributesSchema>;
114
+ export declare const chatSessionAttributesSchema: z.ZodObject<{
115
+ id: z.ZodString;
116
+ phoneLinkId: z.ZodString;
117
+ conversationId: z.ZodNullable<z.ZodString>;
118
+ lastActivity: z.ZodString;
119
+ context: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
120
+ createdAt: z.ZodString;
121
+ updatedAt: z.ZodString;
122
+ }, "strip", z.ZodTypeAny, {
123
+ id: string;
124
+ createdAt: string;
125
+ updatedAt: string;
126
+ conversationId: string | null;
127
+ phoneLinkId: string;
128
+ lastActivity: string;
129
+ context: Record<string, unknown> | null;
130
+ }, {
131
+ id: string;
132
+ createdAt: string;
133
+ updatedAt: string;
134
+ conversationId: string | null;
135
+ phoneLinkId: string;
136
+ lastActivity: string;
137
+ context: Record<string, unknown> | null;
138
+ }>;
139
+ export type ChatSessionAttributes = z.infer<typeof chatSessionAttributesSchema>;
140
+ export declare const outboundMessageAttributesSchema: z.ZodObject<{
141
+ id: z.ZodString;
142
+ phoneLinkId: z.ZodString;
143
+ content: z.ZodString;
144
+ mediaUrl: z.ZodNullable<z.ZodString>;
145
+ status: z.ZodEnum<["pending", "sent", "failed"]>;
146
+ attempts: z.ZodNumber;
147
+ sentAt: z.ZodNullable<z.ZodString>;
148
+ error: z.ZodNullable<z.ZodString>;
149
+ createdAt: z.ZodString;
150
+ }, "strip", z.ZodTypeAny, {
151
+ status: "pending" | "failed" | "sent";
152
+ id: string;
153
+ createdAt: string;
154
+ content: string;
155
+ error: string | null;
156
+ phoneLinkId: string;
157
+ mediaUrl: string | null;
158
+ attempts: number;
159
+ sentAt: string | null;
160
+ }, {
161
+ status: "pending" | "failed" | "sent";
162
+ id: string;
163
+ createdAt: string;
164
+ content: string;
165
+ error: string | null;
166
+ phoneLinkId: string;
167
+ mediaUrl: string | null;
168
+ attempts: number;
169
+ sentAt: string | null;
170
+ }>;
171
+ export type OutboundMessageAttributes = z.infer<typeof outboundMessageAttributesSchema>;
172
+ //# sourceMappingURL=whatsapp-gateway.schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whatsapp-gateway.schemas.d.ts","sourceRoot":"","sources":["../../src/schemas/whatsapp-gateway.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAchC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMpE;;GAEG;AACH,eAAO,MAAM,YAAY,oJAYvB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAMlD;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;EAInC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAMlF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUpC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAM5E,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;EAQtC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAMhF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU1C,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { z } from 'zod';
2
+ // =============================================================================
3
+ // WhatsApp Message Types
4
+ // =============================================================================
5
+ /**
6
+ * Normalized internal message format
7
+ */
8
+ export const whatsappMessageSchema = z.object({
9
+ id: z.string(),
10
+ messageId: z.string(),
11
+ from: z.string(), // WhatsApp ID (phone number)
12
+ type: z.enum(['text', 'voice', 'image', 'location', 'document']),
13
+ content: z.string().optional(),
14
+ mediaId: z.string().optional(),
15
+ location: z
16
+ .object({
17
+ latitude: z.number(),
18
+ longitude: z.number(),
19
+ })
20
+ .optional(),
21
+ timestamp: z.date(),
22
+ });
23
+ // =============================================================================
24
+ // Intent Classification
25
+ // =============================================================================
26
+ /**
27
+ * Intent classification for routing messages
28
+ */
29
+ export const intentSchema = z.enum([
30
+ 'question', // Agronomic question -> AgentsService
31
+ 'task_create', // Create task -> TasksService
32
+ 'task_list', // List tasks -> TasksService
33
+ 'expense_log', // Log expense -> FinanceService
34
+ 'observation', // Record observation -> FieldMonitoringService
35
+ 'status', // Farm/field status -> Multiple services
36
+ 'weather', // Weather query -> WeatherService
37
+ 'inventory', // Check inventory -> InventoryService
38
+ 'set_farm', // Set default farm
39
+ 'help', // Show help menu
40
+ 'unknown', // Fallback to AI
41
+ ]);
42
+ // =============================================================================
43
+ // Webhook Schemas
44
+ // =============================================================================
45
+ /**
46
+ * WhatsApp webhook verification query parameters
47
+ */
48
+ export const webhookVerifyQuerySchema = z.object({
49
+ 'hub.mode': z.string(),
50
+ 'hub.verify_token': z.string(),
51
+ 'hub.challenge': z.string(),
52
+ });
53
+ /**
54
+ * Webhook response for successful message handling
55
+ */
56
+ export const webhookMessageResponseSchema = z.object({
57
+ status: z.literal('ok'),
58
+ });
59
+ // =============================================================================
60
+ // Phone Link Schemas
61
+ // =============================================================================
62
+ export const phoneLinkAttributesSchema = z.object({
63
+ id: z.string().uuid(),
64
+ userId: z.string().uuid(),
65
+ phoneNumber: z.string(),
66
+ whatsappId: z.string().nullable(),
67
+ isVerified: z.boolean(),
68
+ defaultFarmId: z.string().uuid().nullable(),
69
+ language: z.string(),
70
+ createdAt: z.string().datetime(),
71
+ updatedAt: z.string().datetime(),
72
+ });
73
+ // =============================================================================
74
+ // Chat Session Schemas
75
+ // =============================================================================
76
+ export const chatSessionAttributesSchema = z.object({
77
+ id: z.string().uuid(),
78
+ phoneLinkId: z.string().uuid(),
79
+ conversationId: z.string().uuid().nullable(),
80
+ lastActivity: z.string().datetime(),
81
+ context: z.record(z.unknown()).nullable(),
82
+ createdAt: z.string().datetime(),
83
+ updatedAt: z.string().datetime(),
84
+ });
85
+ // =============================================================================
86
+ // Outbound Message Schemas
87
+ // =============================================================================
88
+ export const outboundMessageAttributesSchema = z.object({
89
+ id: z.string().uuid(),
90
+ phoneLinkId: z.string().uuid(),
91
+ content: z.string(),
92
+ mediaUrl: z.string().nullable(),
93
+ status: z.enum(['pending', 'sent', 'failed']),
94
+ attempts: z.number().int(),
95
+ sentAt: z.string().datetime().nullable(),
96
+ error: z.string().nullable(),
97
+ createdAt: z.string().datetime(),
98
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepintel-ltd/farmpro-contracts",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "Type-safe API contracts for FarmPro API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",