@agroyaar/sdk 2.0.4 → 2.0.5-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.
package/dist/index.cjs CHANGED
@@ -110,18 +110,18 @@ var mappers = {
110
110
  date: response.date
111
111
  }),
112
112
  getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart),
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)
113
+ getMechanization: (res) => ({
114
+ id: res.id,
115
+ commonName: res.commonName,
116
+ model: res.model,
117
+ avatarURL: res.avatarURL,
118
+ manufactureYear: res.manufactureYear,
119
+ code: res.code,
120
+ kind: res.kind,
121
+ kindName: res.kindName,
122
+ variety: mappers.getMechanizationVariety(res.variety)
123
123
  }),
124
- getMechanizationsList: (response) => response.map(mappers.getMechanization),
124
+ getMechanizations: (response) => response.map(mappers.getMechanization),
125
125
  getSeasonsProcess: (response) => ({
126
126
  id: response.id,
127
127
  label: response.label,
@@ -217,20 +217,22 @@ var createMechanizationServices = (client) => ({
217
217
  return wrapError(error);
218
218
  }
219
219
  },
220
- getMechanizations: async (variables) => {
220
+ getMechanizations: async ({ farmerId, kindName }) => {
221
221
  try {
222
222
  const response = await client.typed(
223
223
  "get",
224
224
  "/farmers/{farmerId}/mechanizations",
225
225
  {
226
226
  params: {
227
- kindName: variables.kindName
227
+ kindName
228
+ },
229
+ pathParams: {
230
+ farmerId
228
231
  }
229
232
  }
230
233
  );
231
- return import_ts_belt2.R.Ok(
232
- mappers.getMechanizationsList(response.result.data.mechanizations)
233
- );
234
+ const mechanizations = response.result.data.mechanizations;
235
+ return mechanizations ? import_ts_belt2.R.Ok(mappers.getMechanizations(mechanizations)) : import_ts_belt2.R.Error("missing questions in response");
234
236
  } catch (error) {
235
237
  return wrapError(error);
236
238
  }
@@ -250,11 +252,12 @@ var createMechanizationServices = (client) => ({
250
252
  }
251
253
  }
252
254
  );
253
- return import_ts_belt2.R.Ok(
255
+ const motorizedMechanizationSensors = response.result.data.motorizedMechanizationSensors;
256
+ return motorizedMechanizationSensors ? import_ts_belt2.R.Ok(
254
257
  mappers.getMotorizedMechanizationSensors(
255
- response.result.data.motorizedMechanizationSensors
258
+ motorizedMechanizationSensors
256
259
  )
257
- );
260
+ ) : import_ts_belt2.R.Error("missing questions in response");
258
261
  } catch (error) {
259
262
  return wrapError(error);
260
263
  }
@@ -317,18 +320,15 @@ var createMechanizationServices = (client) => ({
317
320
  }
318
321
  }
319
322
  );
320
- const questions = data.result.data.mechanizationsQuestions;
321
- if (!questions) {
322
- throw new Error(
323
- "Invalid API response: 'mechanizationsQuestions' missing"
324
- );
325
- }
326
- return import_ts_belt2.R.Ok(mappers.getQuestions(questions));
323
+ const maybeQuestions = data?.result?.data.mechanizationsQuestions;
324
+ return maybeQuestions ? import_ts_belt2.R.Ok(mappers.getQuestions(maybeQuestions)) : import_ts_belt2.R.Error("missing questions in response");
327
325
  } catch (error) {
328
326
  return wrapError(error);
329
327
  }
330
328
  },
331
329
  getMechanizationMovementChanges: async ({
330
+ farmerId,
331
+ mechanizationId,
332
332
  fromDate,
333
333
  toDate
334
334
  }) => {
@@ -340,14 +340,15 @@ var createMechanizationServices = (client) => ({
340
340
  params: {
341
341
  fromDate,
342
342
  toDate
343
+ },
344
+ pathParams: {
345
+ farmerId,
346
+ mechanizationId
343
347
  }
344
348
  }
345
349
  );
346
- return import_ts_belt2.R.Ok(
347
- mappers.getMechanizationMovementChanges(
348
- response.result.data.movementChanges
349
- )
350
- );
350
+ const movementChanges = response.result.data.movementChanges;
351
+ return movementChanges ? import_ts_belt2.R.Ok(mappers.getMechanizationMovementChanges(movementChanges)) : import_ts_belt2.R.Error("missing questions in response");
351
352
  } catch (error) {
352
353
  return wrapError(error);
353
354
  }
package/dist/index.d.ts CHANGED
@@ -62,7 +62,7 @@ type MechanizationModel = {
62
62
  model: string;
63
63
  commonName: string;
64
64
  avatarURL: string;
65
- manufactureYear: number;
65
+ manufactureYear: string;
66
66
  code: string;
67
67
  kind: VarietyKind;
68
68
  kindName: MechanizationType;
@@ -141,6 +141,8 @@ type MechanizationMovementChangesModel = {
141
141
  date: string;
142
142
  };
143
143
  type MechanizationMovementChangesVariable = {
144
+ farmerId: string;
145
+ mechanizationId: string;
144
146
  fromDate?: string | null | undefined;
145
147
  toDate?: string | null | undefined;
146
148
  };
@@ -2963,13 +2965,13 @@ declare const createSDK: (config: ClientConfig, middlewares?: Parameters<typeof
2963
2965
  mechanization: {
2964
2966
  getMechanizationVarieties: ({ kindName, }: MechanizationVarietyVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationVarietyModel[]>>;
2965
2967
  getSpeedChangesChartData: ({ farmerId, mechanizationId, }: SpeedChangesChartVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<SpeedChangesChartModel[]>>;
2966
- getMechanizations: (variables: MechanizationVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationModel[]>>;
2967
- getMotorizedMechanizationSensors: ({ farmerId, mechanizationId, }: MotorizedMechanizationSensorsVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MotorizedMechanizationSensorsModel>>;
2968
+ getMechanizations: ({ farmerId, kindName }: MechanizationVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationModel[]> | _mobily_ts_belt.Error<"missing questions in response">>;
2969
+ getMotorizedMechanizationSensors: ({ farmerId, mechanizationId, }: MotorizedMechanizationSensorsVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Error<"missing questions in response"> | _mobily_ts_belt.Ok<MotorizedMechanizationSensorsModel>>;
2968
2970
  SubmitTrackingDeviceCode: ({ farmerId, mechanizationId, deviceCode, }: SubmitTrackingDeviceVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<TrackingDeviceCodeModel>>;
2969
2971
  getSeasonsProcess: () => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<SeasonsProcessModel[]>>;
2970
2972
  UpdateTrackingDeviceCode: ({ farmerId, mechanizationId, deviceCode, verificationToken, }: UpdateTrackingDeviceVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<TrackingDeviceCodeModel>>;
2971
- getMechanizationQuestionList: ({ varietyId, }: GetMechanizationQuestionVariable) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationQuestionModel[]>>;
2972
- getMechanizationMovementChanges: ({ fromDate, toDate, }: MechanizationMovementChangesVariable) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationMovementChangesModel[]>>;
2973
+ getMechanizationQuestionList: ({ varietyId, }: GetMechanizationQuestionVariable) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Error<"missing questions in response"> | _mobily_ts_belt.Ok<MechanizationQuestionModel[]>>;
2974
+ getMechanizationMovementChanges: ({ farmerId, mechanizationId, fromDate, toDate, }: MechanizationMovementChangesVariable) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Error<"missing questions in response"> | _mobily_ts_belt.Ok<MechanizationMovementChangesModel[]>>;
2973
2975
  DeleteTrackingDeviceCode: ({ farmerId, mechanizationId, verificationToken, }: DeleteTrackingDeviceVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<TrackingDeviceCodeModel>>;
2974
2976
  };
2975
2977
  };
package/dist/index.mjs CHANGED
@@ -74,18 +74,18 @@ var mappers = {
74
74
  date: response.date
75
75
  }),
76
76
  getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart),
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)
77
+ getMechanization: (res) => ({
78
+ id: res.id,
79
+ commonName: res.commonName,
80
+ model: res.model,
81
+ avatarURL: res.avatarURL,
82
+ manufactureYear: res.manufactureYear,
83
+ code: res.code,
84
+ kind: res.kind,
85
+ kindName: res.kindName,
86
+ variety: mappers.getMechanizationVariety(res.variety)
87
87
  }),
88
- getMechanizationsList: (response) => response.map(mappers.getMechanization),
88
+ getMechanizations: (response) => response.map(mappers.getMechanization),
89
89
  getSeasonsProcess: (response) => ({
90
90
  id: response.id,
91
91
  label: response.label,
@@ -181,20 +181,22 @@ var createMechanizationServices = (client) => ({
181
181
  return wrapError(error);
182
182
  }
183
183
  },
184
- getMechanizations: async (variables) => {
184
+ getMechanizations: async ({ farmerId, kindName }) => {
185
185
  try {
186
186
  const response = await client.typed(
187
187
  "get",
188
188
  "/farmers/{farmerId}/mechanizations",
189
189
  {
190
190
  params: {
191
- kindName: variables.kindName
191
+ kindName
192
+ },
193
+ pathParams: {
194
+ farmerId
192
195
  }
193
196
  }
194
197
  );
195
- return R2.Ok(
196
- mappers.getMechanizationsList(response.result.data.mechanizations)
197
- );
198
+ const mechanizations = response.result.data.mechanizations;
199
+ return mechanizations ? R2.Ok(mappers.getMechanizations(mechanizations)) : R2.Error("missing questions in response");
198
200
  } catch (error) {
199
201
  return wrapError(error);
200
202
  }
@@ -214,11 +216,12 @@ var createMechanizationServices = (client) => ({
214
216
  }
215
217
  }
216
218
  );
217
- return R2.Ok(
219
+ const motorizedMechanizationSensors = response.result.data.motorizedMechanizationSensors;
220
+ return motorizedMechanizationSensors ? R2.Ok(
218
221
  mappers.getMotorizedMechanizationSensors(
219
- response.result.data.motorizedMechanizationSensors
222
+ motorizedMechanizationSensors
220
223
  )
221
- );
224
+ ) : R2.Error("missing questions in response");
222
225
  } catch (error) {
223
226
  return wrapError(error);
224
227
  }
@@ -281,18 +284,15 @@ var createMechanizationServices = (client) => ({
281
284
  }
282
285
  }
283
286
  );
284
- const questions = data.result.data.mechanizationsQuestions;
285
- if (!questions) {
286
- throw new Error(
287
- "Invalid API response: 'mechanizationsQuestions' missing"
288
- );
289
- }
290
- return R2.Ok(mappers.getQuestions(questions));
287
+ const maybeQuestions = data?.result?.data.mechanizationsQuestions;
288
+ return maybeQuestions ? R2.Ok(mappers.getQuestions(maybeQuestions)) : R2.Error("missing questions in response");
291
289
  } catch (error) {
292
290
  return wrapError(error);
293
291
  }
294
292
  },
295
293
  getMechanizationMovementChanges: async ({
294
+ farmerId,
295
+ mechanizationId,
296
296
  fromDate,
297
297
  toDate
298
298
  }) => {
@@ -304,14 +304,15 @@ var createMechanizationServices = (client) => ({
304
304
  params: {
305
305
  fromDate,
306
306
  toDate
307
+ },
308
+ pathParams: {
309
+ farmerId,
310
+ mechanizationId
307
311
  }
308
312
  }
309
313
  );
310
- return R2.Ok(
311
- mappers.getMechanizationMovementChanges(
312
- response.result.data.movementChanges
313
- )
314
- );
314
+ const movementChanges = response.result.data.movementChanges;
315
+ return movementChanges ? R2.Ok(mappers.getMechanizationMovementChanges(movementChanges)) : R2.Error("missing questions in response");
315
316
  } catch (error) {
316
317
  return wrapError(error);
317
318
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agroyaar/sdk",
3
- "version": "2.0.4",
3
+ "version": "2.0.5-0",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",