@agroyaar/sdk 2.0.1 → 2.0.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.
- package/dist/index.cjs +105 -20
- package/dist/index.d.ts +39 -189
- package/dist/index.mjs +105 -20
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,10 @@ var responseLogger = (response) => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
// src/core/client.ts
|
|
61
|
+
var interpolatePath = (template, params) => Object.entries(params).reduce(
|
|
62
|
+
(path, [key, value]) => path.replace(`{${key}}`, encodeURIComponent(String(value))),
|
|
63
|
+
template
|
|
64
|
+
);
|
|
61
65
|
var createClient = (config, middlewares = []) => {
|
|
62
66
|
const client = import_axios.default.create({
|
|
63
67
|
baseURL: config.baseURL,
|
|
@@ -66,9 +70,13 @@ var createClient = (config, middlewares = []) => {
|
|
|
66
70
|
}
|
|
67
71
|
});
|
|
68
72
|
client.typed = async function(method, path, config2) {
|
|
73
|
+
const finalPath = config2?.pathParams ? interpolatePath(
|
|
74
|
+
path,
|
|
75
|
+
config2.pathParams
|
|
76
|
+
) : path;
|
|
69
77
|
const res = await client.request({
|
|
70
78
|
method,
|
|
71
|
-
url:
|
|
79
|
+
url: finalPath,
|
|
72
80
|
params: config2?.params,
|
|
73
81
|
data: config2?.body
|
|
74
82
|
});
|
|
@@ -102,16 +110,16 @@ var mappers = {
|
|
|
102
110
|
date: response.date
|
|
103
111
|
}),
|
|
104
112
|
getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart),
|
|
105
|
-
getMechanization: (
|
|
106
|
-
id:
|
|
107
|
-
commonName:
|
|
108
|
-
model:
|
|
109
|
-
avatarURL:
|
|
110
|
-
manufactureYear:
|
|
111
|
-
code:
|
|
112
|
-
kind:
|
|
113
|
-
kindName:
|
|
114
|
-
variety: mappers.getMechanizationVariety(
|
|
113
|
+
getMechanization: (dto) => ({
|
|
114
|
+
id: dto.id,
|
|
115
|
+
commonName: dto.commonName,
|
|
116
|
+
model: dto.model,
|
|
117
|
+
avatarURL: dto.avatarURL,
|
|
118
|
+
manufactureYear: dto.manufactureYear,
|
|
119
|
+
code: dto.code,
|
|
120
|
+
kind: dto.kind,
|
|
121
|
+
kindName: dto.kindName,
|
|
122
|
+
variety: mappers.getMechanizationVariety(dto.variety)
|
|
115
123
|
}),
|
|
116
124
|
getMechanizationsList: (response) => response.map(mappers.getMechanization),
|
|
117
125
|
getSeasonsProcess: (response) => ({
|
|
@@ -151,7 +159,22 @@ var mappers = {
|
|
|
151
159
|
type: dto.kindName,
|
|
152
160
|
options: dto.options.map((item) => ({ label: item.label, value: item.id }))
|
|
153
161
|
}),
|
|
154
|
-
getQuestions: (dto) => dto.map(mappers.getQuestion)
|
|
162
|
+
getQuestions: (dto) => dto.map(mappers.getQuestion),
|
|
163
|
+
getMechanizationMovementChange: ({
|
|
164
|
+
date,
|
|
165
|
+
heading,
|
|
166
|
+
latitude,
|
|
167
|
+
longitude
|
|
168
|
+
}) => ({
|
|
169
|
+
longitude,
|
|
170
|
+
latitude,
|
|
171
|
+
date,
|
|
172
|
+
heading
|
|
173
|
+
}),
|
|
174
|
+
getMechanizationMovementChanges: (response) => response.map(mappers.getMechanizationMovementChange),
|
|
175
|
+
DeleteTrackingDeviceData: (response) => ({
|
|
176
|
+
deviceCode: response.deviceCode
|
|
177
|
+
})
|
|
155
178
|
};
|
|
156
179
|
|
|
157
180
|
// src/utils/wrapError.ts
|
|
@@ -194,13 +217,21 @@ var createMechanizationServices = (client) => ({
|
|
|
194
217
|
return wrapError(error);
|
|
195
218
|
}
|
|
196
219
|
},
|
|
197
|
-
getMechanizations: async (
|
|
220
|
+
getMechanizations: async (variables) => {
|
|
198
221
|
try {
|
|
199
|
-
const
|
|
200
|
-
|
|
222
|
+
const response = await client.typed(
|
|
223
|
+
"get",
|
|
224
|
+
"/farmers/{farmerId}/mechanizations",
|
|
225
|
+
{
|
|
226
|
+
params: {
|
|
227
|
+
kindName: variables.kindName
|
|
228
|
+
}
|
|
229
|
+
}
|
|
201
230
|
);
|
|
202
231
|
return import_ts_belt2.R.Ok(
|
|
203
|
-
mappers.getMechanizationsList(
|
|
232
|
+
mappers.getMechanizationsList(
|
|
233
|
+
response.content["application/json"].result.data.mechanizations
|
|
234
|
+
)
|
|
204
235
|
);
|
|
205
236
|
} catch (error) {
|
|
206
237
|
return wrapError(error);
|
|
@@ -211,10 +242,19 @@ var createMechanizationServices = (client) => ({
|
|
|
211
242
|
mechanizationId
|
|
212
243
|
}) => {
|
|
213
244
|
try {
|
|
214
|
-
const
|
|
245
|
+
const response = await client.typed(
|
|
246
|
+
"get",
|
|
247
|
+
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors",
|
|
248
|
+
{
|
|
249
|
+
pathParams: {
|
|
250
|
+
farmerId,
|
|
251
|
+
mechanizationId
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
);
|
|
215
255
|
return import_ts_belt2.R.Ok(
|
|
216
256
|
mappers.getMotorizedMechanizationSensors(
|
|
217
|
-
|
|
257
|
+
response.content["application/json"].result.data.motorizedMechanizationSensors
|
|
218
258
|
)
|
|
219
259
|
);
|
|
220
260
|
} catch (error) {
|
|
@@ -279,14 +319,59 @@ var createMechanizationServices = (client) => ({
|
|
|
279
319
|
}
|
|
280
320
|
}
|
|
281
321
|
);
|
|
322
|
+
const questions = data.result?.data?.mechanizationsQuestions;
|
|
323
|
+
if (!questions) {
|
|
324
|
+
throw new Error(
|
|
325
|
+
"Invalid API response: 'mechanizationsQuestions' missing"
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
return import_ts_belt2.R.Ok(mappers.getQuestions(questions));
|
|
329
|
+
} catch (error) {
|
|
330
|
+
return wrapError(error);
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
getMechanizationMovementChanges: async ({
|
|
334
|
+
fromDate,
|
|
335
|
+
toDate
|
|
336
|
+
}) => {
|
|
337
|
+
try {
|
|
338
|
+
const response = await client.typed(
|
|
339
|
+
"get",
|
|
340
|
+
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors/movement-changes",
|
|
341
|
+
{
|
|
342
|
+
params: {
|
|
343
|
+
fromDate,
|
|
344
|
+
toDate
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
);
|
|
282
348
|
return import_ts_belt2.R.Ok(
|
|
283
|
-
mappers.
|
|
284
|
-
|
|
349
|
+
mappers.getMechanizationMovementChanges(
|
|
350
|
+
response.content["application/json"].result.data.movementChanges
|
|
285
351
|
)
|
|
286
352
|
);
|
|
287
353
|
} catch (error) {
|
|
288
354
|
return wrapError(error);
|
|
289
355
|
}
|
|
356
|
+
},
|
|
357
|
+
DeleteTrackingDeviceCode: async ({
|
|
358
|
+
farmerId,
|
|
359
|
+
mechanizationId,
|
|
360
|
+
verificationToken
|
|
361
|
+
}) => {
|
|
362
|
+
try {
|
|
363
|
+
const { data } = await client.delete(
|
|
364
|
+
`/farmers/${farmerId}/mechanizations/${mechanizationId}/delete-device-code`,
|
|
365
|
+
{
|
|
366
|
+
data: verificationToken
|
|
367
|
+
}
|
|
368
|
+
);
|
|
369
|
+
return import_ts_belt2.R.Ok(mappers.DeleteTrackingDeviceData(data));
|
|
370
|
+
} catch (error) {
|
|
371
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
372
|
+
console.error("UpdateTrackingDevice API Error:", err);
|
|
373
|
+
return import_ts_belt2.R.Error(err);
|
|
374
|
+
}
|
|
290
375
|
}
|
|
291
376
|
});
|
|
292
377
|
|
package/dist/index.d.ts
CHANGED
|
@@ -11,175 +11,10 @@ declare namespace Identifiers {
|
|
|
11
11
|
type MechanizationVarietyId = Branded<string, "mechanizationVariety-id">;
|
|
12
12
|
type MechanizationId = Branded<string, "mechanization-id">;
|
|
13
13
|
type SeasonsProcessId = Branded<string, " seasonsProcess-id">;
|
|
14
|
-
type
|
|
14
|
+
type MotorizedMechanizationSensorId = Branded<string, "motorized-mechanization-sensorsId-id">;
|
|
15
15
|
type FarmerId = Branded<string, "farmer-id">;
|
|
16
16
|
type QuestionId = Branded<string, "question-id">;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type FarmerDTO = {
|
|
20
|
-
id: string;
|
|
21
|
-
username: string;
|
|
22
|
-
firstName: string;
|
|
23
|
-
lastName: string;
|
|
24
|
-
fullName: string;
|
|
25
|
-
phoneNumber: string;
|
|
26
|
-
nationalCode: string;
|
|
27
|
-
farmerCode: string;
|
|
28
|
-
birthDate: string;
|
|
29
|
-
avatar: string;
|
|
30
|
-
province: string;
|
|
31
|
-
provinceId: number;
|
|
32
|
-
city: string;
|
|
33
|
-
cityId: number;
|
|
34
|
-
zone: string;
|
|
35
|
-
address: string;
|
|
36
|
-
postalCode: number;
|
|
37
|
-
role: string;
|
|
38
|
-
productsIds: number[];
|
|
39
|
-
status: string;
|
|
40
|
-
walletBalance: number;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type MechanizationAnswerOptionDTO = {
|
|
44
|
-
id: string;
|
|
45
|
-
label: string;
|
|
46
|
-
mechanizationQuestionId: string;
|
|
47
|
-
};
|
|
48
|
-
type InformationDTO = {
|
|
49
|
-
id: string;
|
|
50
|
-
status: Status;
|
|
51
|
-
answerOptions: MechanizationAnswerOptionDTO;
|
|
52
|
-
answerValue: string;
|
|
53
|
-
mechanizationId: string;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
declare namespace ServerResponseTypes {
|
|
57
|
-
namespace Dashboard {
|
|
58
|
-
type MechanizationVarietyDTO = {
|
|
59
|
-
id: string;
|
|
60
|
-
name: string;
|
|
61
|
-
code: string;
|
|
62
|
-
iconURL: string;
|
|
63
|
-
kind: VarietyKind;
|
|
64
|
-
kindName: MechanizationType;
|
|
65
|
-
seasonsProcess: MechanizationSeasonProcessKind[];
|
|
66
|
-
seasonProcessIds: string[];
|
|
67
|
-
machinesUsage: MechanizationMachineUsageKind[];
|
|
68
|
-
machineUsageIds: string[];
|
|
69
|
-
mechanizationQuestions: string[];
|
|
70
|
-
};
|
|
71
|
-
type MechanizationDTO = {
|
|
72
|
-
id: string;
|
|
73
|
-
model: string;
|
|
74
|
-
commonName: string;
|
|
75
|
-
avatarURL: string;
|
|
76
|
-
manufactureYear: string;
|
|
77
|
-
code: string;
|
|
78
|
-
kind: VarietyKind;
|
|
79
|
-
kindName: MechanizationType;
|
|
80
|
-
deviceCode: string;
|
|
81
|
-
status: Status;
|
|
82
|
-
farmer: FarmerDTO;
|
|
83
|
-
farmerId: string;
|
|
84
|
-
variety: MechanizationVarietyDTO;
|
|
85
|
-
information: InformationDTO[];
|
|
86
|
-
};
|
|
87
|
-
type MotorizedMechanizationSensorsDTO = {
|
|
88
|
-
id: string;
|
|
89
|
-
speed: number;
|
|
90
|
-
heading: number;
|
|
91
|
-
latitude: number;
|
|
92
|
-
longitude: number;
|
|
93
|
-
fuelLevel: number;
|
|
94
|
-
engineRpm: number;
|
|
95
|
-
deviceCode: string;
|
|
96
|
-
stateEngine: boolean;
|
|
97
|
-
engineOilPressure: boolean;
|
|
98
|
-
engineWaterTemperature: string;
|
|
99
|
-
batteryChargePercentage: string;
|
|
100
|
-
mechanizationId: string;
|
|
101
|
-
mechanization: MechanizationDTO;
|
|
102
|
-
};
|
|
103
|
-
type TrackingDeviceResultDTO = {
|
|
104
|
-
model: string;
|
|
105
|
-
commonName: string;
|
|
106
|
-
manufactureYear: number;
|
|
107
|
-
code: string;
|
|
108
|
-
deviceCode: string;
|
|
109
|
-
status: {
|
|
110
|
-
id: string;
|
|
111
|
-
label: string;
|
|
112
|
-
name: string;
|
|
113
|
-
};
|
|
114
|
-
farmer: {
|
|
115
|
-
id: string;
|
|
116
|
-
createdAt: string;
|
|
117
|
-
updatedAt: string;
|
|
118
|
-
deletedAt: string | null;
|
|
119
|
-
firstName: string;
|
|
120
|
-
lastName: string;
|
|
121
|
-
phoneNumber: string;
|
|
122
|
-
city: {};
|
|
123
|
-
cityId: string;
|
|
124
|
-
nationalCode: string;
|
|
125
|
-
province: {};
|
|
126
|
-
provinceId: string;
|
|
127
|
-
zone: string;
|
|
128
|
-
farmerCode: string;
|
|
129
|
-
avatar: string;
|
|
130
|
-
walletBalance: number;
|
|
131
|
-
status: string;
|
|
132
|
-
};
|
|
133
|
-
farmerId: string;
|
|
134
|
-
variety: {
|
|
135
|
-
id: string;
|
|
136
|
-
name: string;
|
|
137
|
-
code: string;
|
|
138
|
-
iconURL: string;
|
|
139
|
-
kind: {
|
|
140
|
-
id: string;
|
|
141
|
-
label: string;
|
|
142
|
-
name: string;
|
|
143
|
-
};
|
|
144
|
-
kindName: string;
|
|
145
|
-
seasonsProcess: {
|
|
146
|
-
id: string;
|
|
147
|
-
label: string;
|
|
148
|
-
name: string;
|
|
149
|
-
}[];
|
|
150
|
-
seasonProcessIds: string[];
|
|
151
|
-
machinesUsage: {
|
|
152
|
-
id: string;
|
|
153
|
-
label: string;
|
|
154
|
-
name: string;
|
|
155
|
-
}[];
|
|
156
|
-
machineUsageIds: string[];
|
|
157
|
-
mechanizationQuestions: string[];
|
|
158
|
-
};
|
|
159
|
-
information: {
|
|
160
|
-
id: string;
|
|
161
|
-
createdAt: string;
|
|
162
|
-
updatedAt: string;
|
|
163
|
-
deletedAt: string | null;
|
|
164
|
-
status: {
|
|
165
|
-
id: string;
|
|
166
|
-
label: string;
|
|
167
|
-
name: string;
|
|
168
|
-
};
|
|
169
|
-
answerOptions: {
|
|
170
|
-
id: string;
|
|
171
|
-
label: string;
|
|
172
|
-
mechanizationQuestionId: string;
|
|
173
|
-
};
|
|
174
|
-
answerValue: string;
|
|
175
|
-
mechanizationId: string;
|
|
176
|
-
}[];
|
|
177
|
-
};
|
|
178
|
-
type SpeedChangesChartDTO = {
|
|
179
|
-
speed: number;
|
|
180
|
-
date: string;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
17
|
+
type MechanizationMovementChangeId = Branded<string, " movement-changes-id">;
|
|
183
18
|
}
|
|
184
19
|
|
|
185
20
|
type ServiceType = "EXPERIMENT" | "VISIT" | "CHILLING_REQUIREMENT" | "CULTIVAR_RECOMMENDATION" | "FIRST_SAFFRON_IRRIGATION_DATE_RECOMMENDATION" | "HARVEST_DATE_RECOMMENDATION" | "QUESTIONNAIRE" | "SOWING_DATE_RECOMMENDATIONS" | "WEATHER_STATION" | "YIELD_GAP";
|
|
@@ -189,14 +24,6 @@ type MechanizationType = "MOTORIZED" | "NON_MOTORIZED";
|
|
|
189
24
|
type MechanizationSeasonProcessType = "GROWING" | "HARVESTING" | "PLANTING" | "TRANSPORTATION";
|
|
190
25
|
type MechanizationMachineUsageType = "BALER" | "CRUSHING" | "CRUST_BREAKER" | "FERTILIZER_SPREADER" | "FORAGE_COLLECTOR" | "FURROWER" | "GRASS_CUTTER" | "GRINDING" | "HARVESTING" | "LEVELING" | "LOADER" | "MULTI_PURPOSE" | "SEEDER" | "SPRAYER" | "TILLAGE" | "TRANSPORTATION" | "WEEDER";
|
|
191
26
|
|
|
192
|
-
type ServerResponse<T> = {
|
|
193
|
-
message: string;
|
|
194
|
-
code: string;
|
|
195
|
-
data: T;
|
|
196
|
-
};
|
|
197
|
-
type BaseResponse<T> = {
|
|
198
|
-
result: ServerResponse<T>;
|
|
199
|
-
};
|
|
200
27
|
type Status = {
|
|
201
28
|
id: string;
|
|
202
29
|
label: string;
|
|
@@ -217,15 +44,6 @@ type MechanizationMachineUsageKind = {
|
|
|
217
44
|
label: string;
|
|
218
45
|
name: MechanizationMachineUsageType;
|
|
219
46
|
};
|
|
220
|
-
type MechanizationListData = {
|
|
221
|
-
meta: Record<string, unknown>;
|
|
222
|
-
totalItems: number;
|
|
223
|
-
mechanizations: ServerResponseTypes.Dashboard.MechanizationDTO[];
|
|
224
|
-
};
|
|
225
|
-
type MotorizedMechanizationSensorsData = {
|
|
226
|
-
meta: Record<string, unknown>;
|
|
227
|
-
motorizedMechanizationSensors: ServerResponseTypes.Dashboard.MotorizedMechanizationSensorsDTO;
|
|
228
|
-
};
|
|
229
47
|
|
|
230
48
|
type MechanizationVarietyModel = {
|
|
231
49
|
id: Identifiers.MechanizationVarietyId;
|
|
@@ -244,7 +62,7 @@ type MechanizationModel = {
|
|
|
244
62
|
model: string;
|
|
245
63
|
commonName: string;
|
|
246
64
|
avatarURL: string;
|
|
247
|
-
manufactureYear:
|
|
65
|
+
manufactureYear: number;
|
|
248
66
|
code: string;
|
|
249
67
|
kind: VarietyKind;
|
|
250
68
|
kindName: MechanizationType;
|
|
@@ -271,8 +89,8 @@ type MotorizedMechanizationSensorsModel = {
|
|
|
271
89
|
deviceCode: string;
|
|
272
90
|
stateEngine: boolean;
|
|
273
91
|
engineOilPressure: boolean;
|
|
274
|
-
engineWaterTemperature:
|
|
275
|
-
batteryChargePercentage:
|
|
92
|
+
engineWaterTemperature: number;
|
|
93
|
+
batteryChargePercentage: number;
|
|
276
94
|
mechanizationId: string;
|
|
277
95
|
};
|
|
278
96
|
type MotorizedMechanizationSensorsVariables = {
|
|
@@ -316,6 +134,21 @@ type MechanizationQuestionModel = {
|
|
|
316
134
|
type GetMechanizationQuestionVariable = {
|
|
317
135
|
varietyId: string;
|
|
318
136
|
};
|
|
137
|
+
type MechanizationMovementChangesModel = {
|
|
138
|
+
longitude: number;
|
|
139
|
+
latitude: number;
|
|
140
|
+
heading: number;
|
|
141
|
+
date: string;
|
|
142
|
+
};
|
|
143
|
+
type MechanizationMovementChangesVariable = {
|
|
144
|
+
fromDate?: string | null | undefined;
|
|
145
|
+
toDate?: string | null | undefined;
|
|
146
|
+
};
|
|
147
|
+
type DeleteTrackingDeviceVariables = {
|
|
148
|
+
farmerId: Identifiers.FarmerId;
|
|
149
|
+
mechanizationId: Identifiers.MechanizationId;
|
|
150
|
+
verificationToken: string;
|
|
151
|
+
};
|
|
319
152
|
|
|
320
153
|
/**
|
|
321
154
|
* This file was auto-generated by openapi-typescript.
|
|
@@ -1080,6 +913,13 @@ interface components {
|
|
|
1080
913
|
readonly mechanizationId: string;
|
|
1081
914
|
};
|
|
1082
915
|
Mechanization: {
|
|
916
|
+
readonly id: string;
|
|
917
|
+
/** Format: date-time */
|
|
918
|
+
readonly createdAt: string;
|
|
919
|
+
/** Format: date-time */
|
|
920
|
+
readonly updatedAt: string;
|
|
921
|
+
/** Format: date-time */
|
|
922
|
+
readonly deletedAt: string;
|
|
1083
923
|
readonly avatarURL: string;
|
|
1084
924
|
/** @example pride */
|
|
1085
925
|
readonly model: string;
|
|
@@ -1097,6 +937,8 @@ interface components {
|
|
|
1097
937
|
readonly variety: components["schemas"]["MechanizationVariety"];
|
|
1098
938
|
readonly information: components["schemas"]["MechanizationInformation"][];
|
|
1099
939
|
readonly kind: components["schemas"]["MechanizationKind"];
|
|
940
|
+
/** @enum {string} */
|
|
941
|
+
readonly kindName: "MOTORIZED" | "NON_MOTORIZED";
|
|
1100
942
|
};
|
|
1101
943
|
MechanizationResponseData: {
|
|
1102
944
|
readonly meta: Record<string, never>;
|
|
@@ -3090,6 +2932,11 @@ type RequestBody<Op> = Op extends {
|
|
|
3090
2932
|
};
|
|
3091
2933
|
};
|
|
3092
2934
|
} ? B : never;
|
|
2935
|
+
type PathParams<Op> = Op extends {
|
|
2936
|
+
parameters?: {
|
|
2937
|
+
path?: infer P;
|
|
2938
|
+
};
|
|
2939
|
+
} ? P extends object ? P : never : never;
|
|
3093
2940
|
type ResponseData<Op> = Op extends {
|
|
3094
2941
|
responses: {
|
|
3095
2942
|
200: infer R;
|
|
@@ -3098,6 +2945,7 @@ type ResponseData<Op> = Op extends {
|
|
|
3098
2945
|
|
|
3099
2946
|
type ExtendedClient = AxiosInstance & {
|
|
3100
2947
|
typed: <M extends HttpMethod, P extends ExtractPathsByMethod<M>, Op extends PathOperation<M, P>>(_method: M, _path: P, _config?: {
|
|
2948
|
+
pathParams?: PathParams<Op>;
|
|
3101
2949
|
params?: RequestParams<Op>;
|
|
3102
2950
|
body?: RequestBody<Op>;
|
|
3103
2951
|
}) => Promise<ResponseData<Op>>;
|
|
@@ -3113,14 +2961,16 @@ declare const createSDK: (config: ClientConfig, middlewares?: Parameters<typeof
|
|
|
3113
2961
|
mechanization: {
|
|
3114
2962
|
getMechanizationVarieties: ({ kindName, }: MechanizationVarietyVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationVarietyModel[]>>;
|
|
3115
2963
|
getSpeedChangesChartData: ({ farmerId, mechanizationId, }: SpeedChangesChartVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<SpeedChangesChartModel[]>>;
|
|
3116
|
-
getMechanizations: (
|
|
2964
|
+
getMechanizations: (variables: MechanizationVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationModel[]>>;
|
|
3117
2965
|
getMotorizedMechanizationSensors: ({ farmerId, mechanizationId, }: MotorizedMechanizationSensorsVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MotorizedMechanizationSensorsModel>>;
|
|
3118
2966
|
SubmitTrackingDeviceCode: ({ farmerId, mechanizationId, deviceCode, }: SubmitTrackingDeviceVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<TrackingDeviceCodeModel>>;
|
|
3119
2967
|
getSeasonsProcess: () => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<SeasonsProcessModel[]>>;
|
|
3120
2968
|
UpdateTrackingDeviceCode: ({ farmerId, mechanizationId, deviceCode, verificationToken, }: UpdateTrackingDeviceVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<TrackingDeviceCodeModel>>;
|
|
3121
2969
|
getMechanizationQuestionList: ({ varietyId, }: GetMechanizationQuestionVariable) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationQuestionModel[]>>;
|
|
2970
|
+
getMechanizationMovementChanges: ({ fromDate, toDate, }: MechanizationMovementChangesVariable) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationMovementChangesModel[]>>;
|
|
2971
|
+
DeleteTrackingDeviceCode: ({ farmerId, mechanizationId, verificationToken, }: DeleteTrackingDeviceVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<TrackingDeviceCodeModel>>;
|
|
3122
2972
|
};
|
|
3123
2973
|
};
|
|
3124
2974
|
};
|
|
3125
2975
|
|
|
3126
|
-
export { type
|
|
2976
|
+
export { type DeleteTrackingDeviceVariables, type GetMechanizationQuestionVariable, Identifiers, type MechanizationMachineUsageKind, type MechanizationMachineUsageType, type MechanizationModel, type MechanizationMovementChangesModel, type MechanizationMovementChangesVariable, type MechanizationQuestionModel, type MechanizationSeasonProcessKind, type MechanizationSeasonProcessType, type MechanizationType, type MechanizationVariables, type MechanizationVarietyModel, type MechanizationVarietyVariables, type MotorizedMechanizationSensorsModel, type MotorizedMechanizationSensorsVariables, type SeasonsProcessModel, type ServiceType, type SpeedChangesChartModel, type SpeedChangesChartVariables, type Status, type StatusType, type SubmitTrackingDeviceVariables, type TaskType, type TrackingDeviceCodeModel, type UpdateTrackingDeviceVariables, type VarietyKind, createSDK };
|
package/dist/index.mjs
CHANGED
|
@@ -22,6 +22,10 @@ var responseLogger = (response) => {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
// src/core/client.ts
|
|
25
|
+
var interpolatePath = (template, params) => Object.entries(params).reduce(
|
|
26
|
+
(path, [key, value]) => path.replace(`{${key}}`, encodeURIComponent(String(value))),
|
|
27
|
+
template
|
|
28
|
+
);
|
|
25
29
|
var createClient = (config, middlewares = []) => {
|
|
26
30
|
const client = axios.create({
|
|
27
31
|
baseURL: config.baseURL,
|
|
@@ -30,9 +34,13 @@ var createClient = (config, middlewares = []) => {
|
|
|
30
34
|
}
|
|
31
35
|
});
|
|
32
36
|
client.typed = async function(method, path, config2) {
|
|
37
|
+
const finalPath = config2?.pathParams ? interpolatePath(
|
|
38
|
+
path,
|
|
39
|
+
config2.pathParams
|
|
40
|
+
) : path;
|
|
33
41
|
const res = await client.request({
|
|
34
42
|
method,
|
|
35
|
-
url:
|
|
43
|
+
url: finalPath,
|
|
36
44
|
params: config2?.params,
|
|
37
45
|
data: config2?.body
|
|
38
46
|
});
|
|
@@ -66,16 +74,16 @@ var mappers = {
|
|
|
66
74
|
date: response.date
|
|
67
75
|
}),
|
|
68
76
|
getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart),
|
|
69
|
-
getMechanization: (
|
|
70
|
-
id:
|
|
71
|
-
commonName:
|
|
72
|
-
model:
|
|
73
|
-
avatarURL:
|
|
74
|
-
manufactureYear:
|
|
75
|
-
code:
|
|
76
|
-
kind:
|
|
77
|
-
kindName:
|
|
78
|
-
variety: mappers.getMechanizationVariety(
|
|
77
|
+
getMechanization: (dto) => ({
|
|
78
|
+
id: dto.id,
|
|
79
|
+
commonName: dto.commonName,
|
|
80
|
+
model: dto.model,
|
|
81
|
+
avatarURL: dto.avatarURL,
|
|
82
|
+
manufactureYear: dto.manufactureYear,
|
|
83
|
+
code: dto.code,
|
|
84
|
+
kind: dto.kind,
|
|
85
|
+
kindName: dto.kindName,
|
|
86
|
+
variety: mappers.getMechanizationVariety(dto.variety)
|
|
79
87
|
}),
|
|
80
88
|
getMechanizationsList: (response) => response.map(mappers.getMechanization),
|
|
81
89
|
getSeasonsProcess: (response) => ({
|
|
@@ -115,7 +123,22 @@ var mappers = {
|
|
|
115
123
|
type: dto.kindName,
|
|
116
124
|
options: dto.options.map((item) => ({ label: item.label, value: item.id }))
|
|
117
125
|
}),
|
|
118
|
-
getQuestions: (dto) => dto.map(mappers.getQuestion)
|
|
126
|
+
getQuestions: (dto) => dto.map(mappers.getQuestion),
|
|
127
|
+
getMechanizationMovementChange: ({
|
|
128
|
+
date,
|
|
129
|
+
heading,
|
|
130
|
+
latitude,
|
|
131
|
+
longitude
|
|
132
|
+
}) => ({
|
|
133
|
+
longitude,
|
|
134
|
+
latitude,
|
|
135
|
+
date,
|
|
136
|
+
heading
|
|
137
|
+
}),
|
|
138
|
+
getMechanizationMovementChanges: (response) => response.map(mappers.getMechanizationMovementChange),
|
|
139
|
+
DeleteTrackingDeviceData: (response) => ({
|
|
140
|
+
deviceCode: response.deviceCode
|
|
141
|
+
})
|
|
119
142
|
};
|
|
120
143
|
|
|
121
144
|
// src/utils/wrapError.ts
|
|
@@ -158,13 +181,21 @@ var createMechanizationServices = (client) => ({
|
|
|
158
181
|
return wrapError(error);
|
|
159
182
|
}
|
|
160
183
|
},
|
|
161
|
-
getMechanizations: async (
|
|
184
|
+
getMechanizations: async (variables) => {
|
|
162
185
|
try {
|
|
163
|
-
const
|
|
164
|
-
|
|
186
|
+
const response = await client.typed(
|
|
187
|
+
"get",
|
|
188
|
+
"/farmers/{farmerId}/mechanizations",
|
|
189
|
+
{
|
|
190
|
+
params: {
|
|
191
|
+
kindName: variables.kindName
|
|
192
|
+
}
|
|
193
|
+
}
|
|
165
194
|
);
|
|
166
195
|
return R2.Ok(
|
|
167
|
-
mappers.getMechanizationsList(
|
|
196
|
+
mappers.getMechanizationsList(
|
|
197
|
+
response.content["application/json"].result.data.mechanizations
|
|
198
|
+
)
|
|
168
199
|
);
|
|
169
200
|
} catch (error) {
|
|
170
201
|
return wrapError(error);
|
|
@@ -175,10 +206,19 @@ var createMechanizationServices = (client) => ({
|
|
|
175
206
|
mechanizationId
|
|
176
207
|
}) => {
|
|
177
208
|
try {
|
|
178
|
-
const
|
|
209
|
+
const response = await client.typed(
|
|
210
|
+
"get",
|
|
211
|
+
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors",
|
|
212
|
+
{
|
|
213
|
+
pathParams: {
|
|
214
|
+
farmerId,
|
|
215
|
+
mechanizationId
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
);
|
|
179
219
|
return R2.Ok(
|
|
180
220
|
mappers.getMotorizedMechanizationSensors(
|
|
181
|
-
|
|
221
|
+
response.content["application/json"].result.data.motorizedMechanizationSensors
|
|
182
222
|
)
|
|
183
223
|
);
|
|
184
224
|
} catch (error) {
|
|
@@ -243,14 +283,59 @@ var createMechanizationServices = (client) => ({
|
|
|
243
283
|
}
|
|
244
284
|
}
|
|
245
285
|
);
|
|
286
|
+
const questions = data.result?.data?.mechanizationsQuestions;
|
|
287
|
+
if (!questions) {
|
|
288
|
+
throw new Error(
|
|
289
|
+
"Invalid API response: 'mechanizationsQuestions' missing"
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
return R2.Ok(mappers.getQuestions(questions));
|
|
293
|
+
} catch (error) {
|
|
294
|
+
return wrapError(error);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
getMechanizationMovementChanges: async ({
|
|
298
|
+
fromDate,
|
|
299
|
+
toDate
|
|
300
|
+
}) => {
|
|
301
|
+
try {
|
|
302
|
+
const response = await client.typed(
|
|
303
|
+
"get",
|
|
304
|
+
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors/movement-changes",
|
|
305
|
+
{
|
|
306
|
+
params: {
|
|
307
|
+
fromDate,
|
|
308
|
+
toDate
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
);
|
|
246
312
|
return R2.Ok(
|
|
247
|
-
mappers.
|
|
248
|
-
|
|
313
|
+
mappers.getMechanizationMovementChanges(
|
|
314
|
+
response.content["application/json"].result.data.movementChanges
|
|
249
315
|
)
|
|
250
316
|
);
|
|
251
317
|
} catch (error) {
|
|
252
318
|
return wrapError(error);
|
|
253
319
|
}
|
|
320
|
+
},
|
|
321
|
+
DeleteTrackingDeviceCode: async ({
|
|
322
|
+
farmerId,
|
|
323
|
+
mechanizationId,
|
|
324
|
+
verificationToken
|
|
325
|
+
}) => {
|
|
326
|
+
try {
|
|
327
|
+
const { data } = await client.delete(
|
|
328
|
+
`/farmers/${farmerId}/mechanizations/${mechanizationId}/delete-device-code`,
|
|
329
|
+
{
|
|
330
|
+
data: verificationToken
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
return R2.Ok(mappers.DeleteTrackingDeviceData(data));
|
|
334
|
+
} catch (error) {
|
|
335
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
336
|
+
console.error("UpdateTrackingDevice API Error:", err);
|
|
337
|
+
return R2.Error(err);
|
|
338
|
+
}
|
|
254
339
|
}
|
|
255
340
|
});
|
|
256
341
|
|