@agroyaar/sdk 1.0.9-1 → 1.1.2

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
@@ -37,16 +37,6 @@ module.exports = __toCommonJS(src_exports);
37
37
  // src/core/client.ts
38
38
  var import_axios = __toESM(require("axios"), 1);
39
39
 
40
- // src/middlewares/logger.ts
41
- var requestLogger = (config) => {
42
- console.log(`[Request] ${config.method?.toUpperCase()} ${config.url}`);
43
- return config;
44
- };
45
- var responseLogger = (response) => {
46
- console.log(`[Response] ${response.status} ${response.config.url}`);
47
- return response;
48
- };
49
-
50
40
  // src/middlewares/errorHandler.ts
51
41
  var errorHandler = (error) => {
52
42
  console.error("[HTTP Error]", {
@@ -57,20 +47,27 @@ var errorHandler = (error) => {
57
47
  return Promise.reject(error);
58
48
  };
59
49
 
50
+ // src/middlewares/logger.ts
51
+ var requestLogger = (config) => {
52
+ console.log(`[Request] ${config.method?.toUpperCase()} ${config.url}`);
53
+ return config;
54
+ };
55
+ var responseLogger = (response) => {
56
+ console.log(`[Response] ${response.status} ${response.config.url}`);
57
+ return response;
58
+ };
59
+
60
60
  // src/core/client.ts
61
- var createClient = (config) => {
61
+ var createClient = (config, middlewares = []) => {
62
62
  const client = import_axios.default.create({
63
63
  baseURL: config.baseURL,
64
64
  headers: {
65
65
  "Content-Type": "application/json"
66
66
  }
67
67
  });
68
- client.interceptors.request.use((request) => {
69
- if (config.token) {
70
- request.headers.Authorization = `Bearer ${config.token}`;
71
- }
72
- return request;
73
- });
68
+ for (const middleware of middlewares) {
69
+ client.interceptors.request.use(middleware);
70
+ }
74
71
  client.interceptors.request.use(requestLogger);
75
72
  client.interceptors.response.use(responseLogger, errorHandler);
76
73
  return client;
@@ -90,11 +87,23 @@ var mappers = {
90
87
  machineUsageIds: response.machineUsageIds
91
88
  }),
92
89
  getMechanizationVarietyList: (response) => response.map(mappers.getMechanizationVariety),
93
- getSpeedChangesChart: (response) => ({
94
- speed: response.speed,
95
- date: response.date
90
+ getMechanization: (response) => ({
91
+ id: response.id,
92
+ commonName: response.commonName,
93
+ model: response.model,
94
+ avatarURL: response.avatarURL,
95
+ manufactureYear: response.manufactureYear,
96
+ code: response.code,
97
+ variety: {
98
+ id: response.id,
99
+ name: response.variety.name,
100
+ iconURL: response.variety.iconURL,
101
+ kind: response.variety.kind,
102
+ seasonProcessIds: response.variety.seasonProcessIds,
103
+ machineUsageIds: response.variety.machineUsageIds
104
+ }
96
105
  }),
97
- getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart)
106
+ getMechanizationsList: (response) => response.map(mappers.getMechanization)
98
107
  };
99
108
 
100
109
  // src/services/dashboard/mechanization/mechanization.service.ts
@@ -117,28 +126,25 @@ var createMechanizationServices = (client) => ({
117
126
  return import_ts_belt.R.Error(err);
118
127
  }
119
128
  },
120
- getSpeedChangesChartData: async ({
121
- farmerId,
122
- mechanizationId
123
- }) => {
129
+ getMechanizations: async ({ kindName }) => {
124
130
  try {
125
131
  const { data } = await client.get(
126
- `/farmers/${farmerId}/mechanizations/${mechanizationId}/sensors/speed-changes`
132
+ `/farmers/681f11f87eeba74f9bb8f422/mechanizations?kindName=${kindName}`
127
133
  );
128
134
  return import_ts_belt.R.Ok(
129
- mappers.getSpeedChangesChartPointsList(data.result.data.speedChanges)
135
+ mappers.getMechanizationsList(data.result.data.mechanizations)
130
136
  );
131
137
  } catch (error) {
132
138
  const err = error instanceof Error ? error : new Error(String(error));
133
- console.error("SpeedChangesChartPointsList API Error:", err);
139
+ console.error("Mechanization API Error:", err);
134
140
  return import_ts_belt.R.Error(err);
135
141
  }
136
142
  }
137
143
  });
138
144
 
139
145
  // src/index.ts
140
- var createSDK = (config) => {
141
- const client = createClient(config);
146
+ var createSDK = (config, middlewares = []) => {
147
+ const client = createClient(config, middlewares);
142
148
  return {
143
149
  dashboardServices: {
144
150
  mechanization: createMechanizationServices(client)
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as _mobily_ts_belt from '@mobily/ts-belt';
2
+ import * as axios from 'axios';
3
+ import { InternalAxiosRequestConfig } from 'axios';
2
4
 
3
5
  declare const __brand: unique symbol;
4
6
  type Brand<B> = {
@@ -8,40 +10,73 @@ type Branded<T, B> = Brand<B> & T;
8
10
 
9
11
  declare namespace Identifiers {
10
12
  type MechanizationVarietyId = Branded<string, "mechanizationVarietyId-id">;
13
+ type MechanizationId = Branded<string, "mechanizationId-id">;
11
14
  }
12
15
 
16
+ type ServiceType = "EXPERIMENT" | "VISIT" | "CHILLING_REQUIREMENT" | "CULTIVAR_RECOMMENDATION" | "FIRST_SAFFRON_IRRIGATION_DATE_RECOMMENDATION" | "HARVEST_DATE_RECOMMENDATION" | "QUESTIONNAIRE" | "SOWING_DATE_RECOMMENDATIONS" | "WEATHER_STATION" | "YIELD_GAP";
17
+ type StatusType = "ACTIVE" | "ACTIVE_LEADING_EXPERT" | "APPROVED_EXPERIMENT_ANALYSIS_REQUEST" | "APPROVED_MISSION" | "APPROVED_RESIDENT_LEADING_EXPERT" | "ARCHIVED" | "AWAITING_APPROVAL_EXPERIMENT_ANALYSIS_REQUEST" | "AWAITING_APPROVAL_MISSION" | "AWAITING_APPROVAL_RESIDENT_LEADING_EXPERT" | "AWAITING_COLLEAGUE_APPROVAL_REQUEST" | "AWAITING_MISSION_COMPLETION_REQUEST" | "AWAITING_PAYMENT_REQUEST" | "AWAITING_PURCHASE_REQUEST" | "AWAITING_REVIEW_ACTIVATION" | "AWAITING_REVIEW_DATA_MISSION" | "AWAITING_REVIEW_INQUIRY" | "AWAITING_REVIEW_MISSION_DATA_REQUEST" | "AWAITING_REVIEW_MODIFICATION" | "AWAITING_REVIEW_OFFER" | "AWAITING_REVIEW_REGISTRATION" | "AWAITING_REVIEW_REQUEST" | "AWAITING_SAMPLE_DELIVERY_LABORATORY_MISSION" | "AWAITING_SEND_REQUEST" | "AWAITING_SIGNING_CONTRACT" | "AWAITING_START_EXPERIMENT_ANALYSIS_REQUEST" | "AWAITING_START_MISSION" | "AWAITING_SUBMIT_ACTIVATION" | "AWAITING_VERIFICATION_CHARGE_WALLET_TRANSACTION" | "CANCELED_EXPERIMENT_ANALYSIS_REQUEST" | "CANCELED_MISSION" | "CANCELED_REQUEST" | "COMPLETED" | "COMPLETED_EXPERIMENT_ANALYSIS_REQUEST" | "COMPLETED_MISSION" | "COMPLETED_REGISTRATION" | "COMPLETED_REQUEST" | "CONFIRMED" | "CONFIRMED_ACTIVATION" | "CONFIRMED_REGISTRATION" | "DONE" | "DRAFT" | "DRAFT_EXPERIMENT_ANALYSIS_REQUEST" | "DRAFT_MISSION" | "FAILED" | "FAILED_CHARGE_WALLET_TRANSACTION" | "INACTIVE" | "INVALID" | "INVALID_DEVICE_PUSH_TOKEN" | "IN_PROGRESS_EXPERIMENT_ANALYSIS_REQUEST" | "IN_PROGRESS_MISSION" | "PAID" | "PASS_PAYMENT" | "PENDING" | "PROCESSING" | "REJECTED" | "REJECTED_ACTIVATION" | "REJECTED_EXPERIMENT_ANALYSIS_REQUEST" | "REJECTED_MISSION" | "REJECTED_MODIFICATION" | "REJECTED_REGISTRATION" | "REJECTED_RESIDENT_LEADING_EXPERT" | "SUBMIT" | "SUCCESS" | "SUCCESS_PAYMENT_WALLET_TRANSACTION" | "VALID" | "VALID_DEVICE_PUSH_TOKEN" | "VERIFIED" | "VERIFIED_CHARGE_WALLET_TRANSACTION" | "WRITING" | "AWAITING_APPROVAL_RESIDENT_LEADING_EXPERT" | "APPROVED_RESIDENT_LEADING_EXPERT" | "REJECTED_RESIDENT_LEADING_EXPERT";
18
+ type TaskType = "SAMPLING_REQUEST" | "SAMPLING_MISSION" | "ANALYSIS_REQUEST" | "MAP_DRAWING" | "WATER_SAMPLE_CONTROL" | "WATER_ANALYSIS_MEASUREMENT" | "WATER_EXPERIMENT_TECHNICAL_REVIEW" | "PLANT_SAMPLE_CONTROL" | "PLANT_ANALYSIS_MEASUREMENT" | "PLANT_EXPERIMENT_TECHNICAL_REVIEW" | "SOIL_SAMPLE_CONTROL" | "SOIL_ANALYSIS_MEASUREMENT" | "SOIL_EXPERIMENT_TECHNICAL_REVIEW" | "SENDING_REPORTS" | "TECHNICAL_REVIEW" | "EXPERIMENT_ANALYSIS_RESULTS_CONTROL" | "EXPERIMENT_RECOMMENDATION_ANALYSIS_RESULTS" | "SUPPORT_EXPERIMENTS" | "VISIT_REQUEST" | "FOLLOW_UP_VISIT" | "VISIT_MAP_DRAWING" | "VISIT_SENDING_REPORTS" | "SUPPORT_VISITS";
19
+ type MechanizationType = "MOTORIZED" | "NON_MOTORIZED";
20
+ type MechanizationSeasonProcessType = "GROWING" | "HARVESTING" | "PLANTING" | "TRANSPORTATION";
21
+ type MechanizationMachineUsageType = "BALER" | "CRUSHING" | "CRUST_BREAKER" | "FERTILIZER_SPREADER" | "FORAGE_COLLECTOR" | "FURROWER" | "GRASS_CUTTER" | "GRINDING" | "HARVESTING" | "LEVELING" | "LOADER" | "MULTI_PURPOSE" | "SEEDER" | "SPRAYER" | "TILLAGE" | "TRANSPORTATION" | "WEEDER";
22
+
23
+ type Status = {
24
+ id: string;
25
+ label: string;
26
+ name: StatusType;
27
+ };
28
+ type VarietyKind = {
29
+ id: string;
30
+ label: string;
31
+ name: MechanizationType;
32
+ };
33
+ type MechanizationSeasonProcessKind = {
34
+ id: string;
35
+ label: string;
36
+ name: MechanizationSeasonProcessType;
37
+ };
38
+ type MechanizationMachineUsageKind = {
39
+ id: string;
40
+ label: string;
41
+ name: MechanizationMachineUsageType;
42
+ };
43
+
13
44
  type MechanizationVarietyModel = {
14
45
  id: Identifiers.MechanizationVarietyId;
15
46
  name: string;
16
47
  iconURL: string;
17
- kind: string;
48
+ kind: VarietyKind;
18
49
  seasonProcessIds: string[];
19
50
  machineUsageIds: string[];
20
51
  };
21
52
  type MechanizationVarietyVariables = {
22
- kindName: "MOTORIZED" | "NON_MOTORIZED";
53
+ kindName: MechanizationType;
23
54
  };
24
- type SpeedChangesChartModel = {
25
- speed: number;
26
- date: string;
55
+ type MechanizationModel = {
56
+ id: Identifiers.MechanizationId;
57
+ model: string;
58
+ commonName: string;
59
+ avatarURL: string;
60
+ manufactureYear: string;
61
+ code: string;
62
+ variety: MechanizationVarietyModel;
27
63
  };
28
- type SpeedChangesChartVariables = {
29
- farmerId: string;
30
- mechanizationId: string;
64
+ type MechanizationVariables = {
65
+ kindName: MechanizationType;
31
66
  };
32
67
 
33
68
  type ClientConfig = {
34
69
  readonly baseURL: string;
35
- readonly token?: string;
36
70
  };
71
+ declare const createClient: (config: ClientConfig, middlewares?: ((_config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig)[]) => axios.AxiosInstance;
37
72
 
38
- declare const createSDK: (config: ClientConfig) => {
73
+ declare const createSDK: (config: ClientConfig, middlewares?: Parameters<typeof createClient>[1]) => {
39
74
  dashboardServices: {
40
75
  mechanization: {
41
76
  getMechanizationVarieties: ({ kindName, }: MechanizationVarietyVariables) => Promise<_mobily_ts_belt.Ok<MechanizationVarietyModel[]> | _mobily_ts_belt.Error<Error>>;
42
- getSpeedChangesChartData: ({ farmerId, mechanizationId, }: SpeedChangesChartVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<SpeedChangesChartModel[]>>;
77
+ getMechanizations: ({ kindName }: MechanizationVariables) => Promise<_mobily_ts_belt.Error<Error> | _mobily_ts_belt.Ok<MechanizationModel[]>>;
43
78
  };
44
79
  };
45
80
  };
46
81
 
47
- export { type MechanizationVarietyModel, type MechanizationVarietyVariables, type SpeedChangesChartModel, type SpeedChangesChartVariables, createSDK };
82
+ export { type MechanizationMachineUsageKind, type MechanizationMachineUsageType, type MechanizationModel, type MechanizationSeasonProcessKind, type MechanizationSeasonProcessType, type MechanizationType, type MechanizationVariables, type MechanizationVarietyModel, type MechanizationVarietyVariables, type ServiceType, type Status, type StatusType, type TaskType, type VarietyKind, createSDK };
package/dist/index.mjs CHANGED
@@ -1,16 +1,6 @@
1
1
  // src/core/client.ts
2
2
  import axios from "axios";
3
3
 
4
- // src/middlewares/logger.ts
5
- var requestLogger = (config) => {
6
- console.log(`[Request] ${config.method?.toUpperCase()} ${config.url}`);
7
- return config;
8
- };
9
- var responseLogger = (response) => {
10
- console.log(`[Response] ${response.status} ${response.config.url}`);
11
- return response;
12
- };
13
-
14
4
  // src/middlewares/errorHandler.ts
15
5
  var errorHandler = (error) => {
16
6
  console.error("[HTTP Error]", {
@@ -21,20 +11,27 @@ var errorHandler = (error) => {
21
11
  return Promise.reject(error);
22
12
  };
23
13
 
14
+ // src/middlewares/logger.ts
15
+ var requestLogger = (config) => {
16
+ console.log(`[Request] ${config.method?.toUpperCase()} ${config.url}`);
17
+ return config;
18
+ };
19
+ var responseLogger = (response) => {
20
+ console.log(`[Response] ${response.status} ${response.config.url}`);
21
+ return response;
22
+ };
23
+
24
24
  // src/core/client.ts
25
- var createClient = (config) => {
25
+ var createClient = (config, middlewares = []) => {
26
26
  const client = axios.create({
27
27
  baseURL: config.baseURL,
28
28
  headers: {
29
29
  "Content-Type": "application/json"
30
30
  }
31
31
  });
32
- client.interceptors.request.use((request) => {
33
- if (config.token) {
34
- request.headers.Authorization = `Bearer ${config.token}`;
35
- }
36
- return request;
37
- });
32
+ for (const middleware of middlewares) {
33
+ client.interceptors.request.use(middleware);
34
+ }
38
35
  client.interceptors.request.use(requestLogger);
39
36
  client.interceptors.response.use(responseLogger, errorHandler);
40
37
  return client;
@@ -54,11 +51,23 @@ var mappers = {
54
51
  machineUsageIds: response.machineUsageIds
55
52
  }),
56
53
  getMechanizationVarietyList: (response) => response.map(mappers.getMechanizationVariety),
57
- getSpeedChangesChart: (response) => ({
58
- speed: response.speed,
59
- date: response.date
54
+ getMechanization: (response) => ({
55
+ id: response.id,
56
+ commonName: response.commonName,
57
+ model: response.model,
58
+ avatarURL: response.avatarURL,
59
+ manufactureYear: response.manufactureYear,
60
+ code: response.code,
61
+ variety: {
62
+ id: response.id,
63
+ name: response.variety.name,
64
+ iconURL: response.variety.iconURL,
65
+ kind: response.variety.kind,
66
+ seasonProcessIds: response.variety.seasonProcessIds,
67
+ machineUsageIds: response.variety.machineUsageIds
68
+ }
60
69
  }),
61
- getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart)
70
+ getMechanizationsList: (response) => response.map(mappers.getMechanization)
62
71
  };
63
72
 
64
73
  // src/services/dashboard/mechanization/mechanization.service.ts
@@ -81,28 +90,25 @@ var createMechanizationServices = (client) => ({
81
90
  return R.Error(err);
82
91
  }
83
92
  },
84
- getSpeedChangesChartData: async ({
85
- farmerId,
86
- mechanizationId
87
- }) => {
93
+ getMechanizations: async ({ kindName }) => {
88
94
  try {
89
95
  const { data } = await client.get(
90
- `/farmers/${farmerId}/mechanizations/${mechanizationId}/sensors/speed-changes`
96
+ `/farmers/681f11f87eeba74f9bb8f422/mechanizations?kindName=${kindName}`
91
97
  );
92
98
  return R.Ok(
93
- mappers.getSpeedChangesChartPointsList(data.result.data.speedChanges)
99
+ mappers.getMechanizationsList(data.result.data.mechanizations)
94
100
  );
95
101
  } catch (error) {
96
102
  const err = error instanceof Error ? error : new Error(String(error));
97
- console.error("SpeedChangesChartPointsList API Error:", err);
103
+ console.error("Mechanization API Error:", err);
98
104
  return R.Error(err);
99
105
  }
100
106
  }
101
107
  });
102
108
 
103
109
  // src/index.ts
104
- var createSDK = (config) => {
105
- const client = createClient(config);
110
+ var createSDK = (config, middlewares = []) => {
111
+ const client = createClient(config, middlewares);
106
112
  return {
107
113
  dashboardServices: {
108
114
  mechanization: createMechanizationServices(client)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agroyaar/sdk",
3
- "version": "1.0.9-1",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",