@agroyaar/sdk 1.0.9-1 → 1.1.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 +17 -42
- package/dist/index.d.ts +5 -12
- package/dist/index.mjs +17 -42
- package/package.json +1 -1
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
|
-
|
69
|
-
|
70
|
-
|
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;
|
@@ -89,12 +86,7 @@ var mappers = {
|
|
89
86
|
seasonProcessIds: response.seasonProcessIds,
|
90
87
|
machineUsageIds: response.machineUsageIds
|
91
88
|
}),
|
92
|
-
getMechanizationVarietyList: (response) => response.map(mappers.getMechanizationVariety)
|
93
|
-
getSpeedChangesChart: (response) => ({
|
94
|
-
speed: response.speed,
|
95
|
-
date: response.date
|
96
|
-
}),
|
97
|
-
getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart)
|
89
|
+
getMechanizationVarietyList: (response) => response.map(mappers.getMechanizationVariety)
|
98
90
|
};
|
99
91
|
|
100
92
|
// src/services/dashboard/mechanization/mechanization.service.ts
|
@@ -116,29 +108,12 @@ var createMechanizationServices = (client) => ({
|
|
116
108
|
console.error("MechanizationVariety API Error:", err);
|
117
109
|
return import_ts_belt.R.Error(err);
|
118
110
|
}
|
119
|
-
},
|
120
|
-
getSpeedChangesChartData: async ({
|
121
|
-
farmerId,
|
122
|
-
mechanizationId
|
123
|
-
}) => {
|
124
|
-
try {
|
125
|
-
const { data } = await client.get(
|
126
|
-
`/farmers/${farmerId}/mechanizations/${mechanizationId}/sensors/speed-changes`
|
127
|
-
);
|
128
|
-
return import_ts_belt.R.Ok(
|
129
|
-
mappers.getSpeedChangesChartPointsList(data.result.data.speedChanges)
|
130
|
-
);
|
131
|
-
} catch (error) {
|
132
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
133
|
-
console.error("SpeedChangesChartPointsList API Error:", err);
|
134
|
-
return import_ts_belt.R.Error(err);
|
135
|
-
}
|
136
111
|
}
|
137
112
|
});
|
138
113
|
|
139
114
|
// src/index.ts
|
140
|
-
var createSDK = (config) => {
|
141
|
-
const client = createClient(config);
|
115
|
+
var createSDK = (config, middlewares = []) => {
|
116
|
+
const client = createClient(config, middlewares);
|
142
117
|
return {
|
143
118
|
dashboardServices: {
|
144
119
|
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> = {
|
@@ -21,27 +23,18 @@ type MechanizationVarietyModel = {
|
|
21
23
|
type MechanizationVarietyVariables = {
|
22
24
|
kindName: "MOTORIZED" | "NON_MOTORIZED";
|
23
25
|
};
|
24
|
-
type SpeedChangesChartModel = {
|
25
|
-
speed: number;
|
26
|
-
date: string;
|
27
|
-
};
|
28
|
-
type SpeedChangesChartVariables = {
|
29
|
-
farmerId: string;
|
30
|
-
mechanizationId: string;
|
31
|
-
};
|
32
26
|
|
33
27
|
type ClientConfig = {
|
34
28
|
readonly baseURL: string;
|
35
|
-
readonly token?: string;
|
36
29
|
};
|
30
|
+
declare const createClient: (config: ClientConfig, middlewares?: ((_config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig)[]) => axios.AxiosInstance;
|
37
31
|
|
38
|
-
declare const createSDK: (config: ClientConfig) => {
|
32
|
+
declare const createSDK: (config: ClientConfig, middlewares?: Parameters<typeof createClient>[1]) => {
|
39
33
|
dashboardServices: {
|
40
34
|
mechanization: {
|
41
35
|
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[]>>;
|
43
36
|
};
|
44
37
|
};
|
45
38
|
};
|
46
39
|
|
47
|
-
export { type MechanizationVarietyModel, type MechanizationVarietyVariables,
|
40
|
+
export { type MechanizationVarietyModel, type MechanizationVarietyVariables, 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
|
-
|
33
|
-
|
34
|
-
|
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;
|
@@ -53,12 +50,7 @@ var mappers = {
|
|
53
50
|
seasonProcessIds: response.seasonProcessIds,
|
54
51
|
machineUsageIds: response.machineUsageIds
|
55
52
|
}),
|
56
|
-
getMechanizationVarietyList: (response) => response.map(mappers.getMechanizationVariety)
|
57
|
-
getSpeedChangesChart: (response) => ({
|
58
|
-
speed: response.speed,
|
59
|
-
date: response.date
|
60
|
-
}),
|
61
|
-
getSpeedChangesChartPointsList: (response) => response.map(mappers.getSpeedChangesChart)
|
53
|
+
getMechanizationVarietyList: (response) => response.map(mappers.getMechanizationVariety)
|
62
54
|
};
|
63
55
|
|
64
56
|
// src/services/dashboard/mechanization/mechanization.service.ts
|
@@ -80,29 +72,12 @@ var createMechanizationServices = (client) => ({
|
|
80
72
|
console.error("MechanizationVariety API Error:", err);
|
81
73
|
return R.Error(err);
|
82
74
|
}
|
83
|
-
},
|
84
|
-
getSpeedChangesChartData: async ({
|
85
|
-
farmerId,
|
86
|
-
mechanizationId
|
87
|
-
}) => {
|
88
|
-
try {
|
89
|
-
const { data } = await client.get(
|
90
|
-
`/farmers/${farmerId}/mechanizations/${mechanizationId}/sensors/speed-changes`
|
91
|
-
);
|
92
|
-
return R.Ok(
|
93
|
-
mappers.getSpeedChangesChartPointsList(data.result.data.speedChanges)
|
94
|
-
);
|
95
|
-
} catch (error) {
|
96
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
97
|
-
console.error("SpeedChangesChartPointsList API Error:", err);
|
98
|
-
return R.Error(err);
|
99
|
-
}
|
100
75
|
}
|
101
76
|
});
|
102
77
|
|
103
78
|
// src/index.ts
|
104
|
-
var createSDK = (config) => {
|
105
|
-
const client = createClient(config);
|
79
|
+
var createSDK = (config, middlewares = []) => {
|
80
|
+
const client = createClient(config, middlewares);
|
106
81
|
return {
|
107
82
|
dashboardServices: {
|
108
83
|
mechanization: createMechanizationServices(client)
|