@agroyaar/sdk 2.0.2 → 2.0.4

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
@@ -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: path,
79
+ url: finalPath,
72
80
  params: config2?.params,
73
81
  data: config2?.body
74
82
  });
@@ -221,9 +229,7 @@ var createMechanizationServices = (client) => ({
221
229
  }
222
230
  );
223
231
  return import_ts_belt2.R.Ok(
224
- mappers.getMechanizationsList(
225
- response.content["application/json"].result.data.mechanizations
226
- )
232
+ mappers.getMechanizationsList(response.result.data.mechanizations)
227
233
  );
228
234
  } catch (error) {
229
235
  return wrapError(error);
@@ -234,14 +240,19 @@ var createMechanizationServices = (client) => ({
234
240
  mechanizationId
235
241
  }) => {
236
242
  try {
237
- console.log(farmerId, mechanizationId);
238
243
  const response = await client.typed(
239
244
  "get",
240
- "/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors"
245
+ "/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors",
246
+ {
247
+ pathParams: {
248
+ farmerId,
249
+ mechanizationId
250
+ }
251
+ }
241
252
  );
242
253
  return import_ts_belt2.R.Ok(
243
254
  mappers.getMotorizedMechanizationSensors(
244
- response.content["application/json"].result.data.motorizedMechanizationSensors
255
+ response.result.data.motorizedMechanizationSensors
245
256
  )
246
257
  );
247
258
  } catch (error) {
@@ -306,7 +317,7 @@ var createMechanizationServices = (client) => ({
306
317
  }
307
318
  }
308
319
  );
309
- const questions = data.result?.data?.mechanizationsQuestions;
320
+ const questions = data.result.data.mechanizationsQuestions;
310
321
  if (!questions) {
311
322
  throw new Error(
312
323
  "Invalid API response: 'mechanizationsQuestions' missing"
@@ -334,7 +345,7 @@ var createMechanizationServices = (client) => ({
334
345
  );
335
346
  return import_ts_belt2.R.Ok(
336
347
  mappers.getMechanizationMovementChanges(
337
- response.content["application/json"].result.data.movementChanges
348
+ response.result.data.movementChanges
338
349
  )
339
350
  );
340
351
  } catch (error) {
package/dist/index.d.ts CHANGED
@@ -925,8 +925,7 @@ interface components {
925
925
  readonly model: string;
926
926
  /** @example shrek */
927
927
  readonly commonName: string;
928
- /** @example 0 */
929
- readonly manufactureYear: number;
928
+ readonly manufactureYear: string;
930
929
  /** @example code */
931
930
  readonly code: string;
932
931
  /** @example deviceCode */
@@ -1364,7 +1363,6 @@ interface operations {
1364
1363
  responses: {
1365
1364
  /** @description لیست اطلاعات با موفقیت دریافت شد */
1366
1365
  200: {
1367
- result: any;
1368
1366
  headers: {
1369
1367
  [name: string]: unknown;
1370
1368
  };
@@ -2926,20 +2924,30 @@ type RequestParams<Op> = Op extends {
2926
2924
  };
2927
2925
  } ? Q extends object ? Q : never : never;
2928
2926
  type RequestBody<Op> = Op extends {
2929
- requestBody: {
2927
+ requestBody?: {
2930
2928
  content: {
2931
2929
  "application/json": infer B;
2932
2930
  };
2933
2931
  };
2934
2932
  } ? B : never;
2933
+ type PathParams<Op> = Op extends {
2934
+ parameters?: {
2935
+ path?: infer P;
2936
+ };
2937
+ } ? P extends object ? P : never : never;
2935
2938
  type ResponseData<Op> = Op extends {
2936
2939
  responses: {
2937
- 200: infer R;
2940
+ 200: {
2941
+ content: {
2942
+ "application/json": infer R;
2943
+ };
2944
+ };
2938
2945
  };
2939
2946
  } ? R : unknown;
2940
2947
 
2941
2948
  type ExtendedClient = AxiosInstance & {
2942
2949
  typed: <M extends HttpMethod, P extends ExtractPathsByMethod<M>, Op extends PathOperation<M, P>>(_method: M, _path: P, _config?: {
2950
+ pathParams?: PathParams<Op>;
2943
2951
  params?: RequestParams<Op>;
2944
2952
  body?: RequestBody<Op>;
2945
2953
  }) => Promise<ResponseData<Op>>;
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: path,
43
+ url: finalPath,
36
44
  params: config2?.params,
37
45
  data: config2?.body
38
46
  });
@@ -185,9 +193,7 @@ var createMechanizationServices = (client) => ({
185
193
  }
186
194
  );
187
195
  return R2.Ok(
188
- mappers.getMechanizationsList(
189
- response.content["application/json"].result.data.mechanizations
190
- )
196
+ mappers.getMechanizationsList(response.result.data.mechanizations)
191
197
  );
192
198
  } catch (error) {
193
199
  return wrapError(error);
@@ -198,14 +204,19 @@ var createMechanizationServices = (client) => ({
198
204
  mechanizationId
199
205
  }) => {
200
206
  try {
201
- console.log(farmerId, mechanizationId);
202
207
  const response = await client.typed(
203
208
  "get",
204
- "/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors"
209
+ "/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors",
210
+ {
211
+ pathParams: {
212
+ farmerId,
213
+ mechanizationId
214
+ }
215
+ }
205
216
  );
206
217
  return R2.Ok(
207
218
  mappers.getMotorizedMechanizationSensors(
208
- response.content["application/json"].result.data.motorizedMechanizationSensors
219
+ response.result.data.motorizedMechanizationSensors
209
220
  )
210
221
  );
211
222
  } catch (error) {
@@ -270,7 +281,7 @@ var createMechanizationServices = (client) => ({
270
281
  }
271
282
  }
272
283
  );
273
- const questions = data.result?.data?.mechanizationsQuestions;
284
+ const questions = data.result.data.mechanizationsQuestions;
274
285
  if (!questions) {
275
286
  throw new Error(
276
287
  "Invalid API response: 'mechanizationsQuestions' missing"
@@ -298,7 +309,7 @@ var createMechanizationServices = (client) => ({
298
309
  );
299
310
  return R2.Ok(
300
311
  mappers.getMechanizationMovementChanges(
301
- response.content["application/json"].result.data.movementChanges
312
+ response.result.data.movementChanges
302
313
  )
303
314
  );
304
315
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agroyaar/sdk",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",