@agroyaar/sdk 2.0.2 → 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 +16 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +16 -3
- 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
|
});
|
|
@@ -234,10 +242,15 @@ var createMechanizationServices = (client) => ({
|
|
|
234
242
|
mechanizationId
|
|
235
243
|
}) => {
|
|
236
244
|
try {
|
|
237
|
-
console.log(farmerId, mechanizationId);
|
|
238
245
|
const response = await client.typed(
|
|
239
246
|
"get",
|
|
240
|
-
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors"
|
|
247
|
+
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors",
|
|
248
|
+
{
|
|
249
|
+
pathParams: {
|
|
250
|
+
farmerId,
|
|
251
|
+
mechanizationId
|
|
252
|
+
}
|
|
253
|
+
}
|
|
241
254
|
);
|
|
242
255
|
return import_ts_belt2.R.Ok(
|
|
243
256
|
mappers.getMotorizedMechanizationSensors(
|
package/dist/index.d.ts
CHANGED
|
@@ -2932,6 +2932,11 @@ type RequestBody<Op> = Op extends {
|
|
|
2932
2932
|
};
|
|
2933
2933
|
};
|
|
2934
2934
|
} ? B : never;
|
|
2935
|
+
type PathParams<Op> = Op extends {
|
|
2936
|
+
parameters?: {
|
|
2937
|
+
path?: infer P;
|
|
2938
|
+
};
|
|
2939
|
+
} ? P extends object ? P : never : never;
|
|
2935
2940
|
type ResponseData<Op> = Op extends {
|
|
2936
2941
|
responses: {
|
|
2937
2942
|
200: infer R;
|
|
@@ -2940,6 +2945,7 @@ type ResponseData<Op> = Op extends {
|
|
|
2940
2945
|
|
|
2941
2946
|
type ExtendedClient = AxiosInstance & {
|
|
2942
2947
|
typed: <M extends HttpMethod, P extends ExtractPathsByMethod<M>, Op extends PathOperation<M, P>>(_method: M, _path: P, _config?: {
|
|
2948
|
+
pathParams?: PathParams<Op>;
|
|
2943
2949
|
params?: RequestParams<Op>;
|
|
2944
2950
|
body?: RequestBody<Op>;
|
|
2945
2951
|
}) => 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:
|
|
43
|
+
url: finalPath,
|
|
36
44
|
params: config2?.params,
|
|
37
45
|
data: config2?.body
|
|
38
46
|
});
|
|
@@ -198,10 +206,15 @@ var createMechanizationServices = (client) => ({
|
|
|
198
206
|
mechanizationId
|
|
199
207
|
}) => {
|
|
200
208
|
try {
|
|
201
|
-
console.log(farmerId, mechanizationId);
|
|
202
209
|
const response = await client.typed(
|
|
203
210
|
"get",
|
|
204
|
-
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors"
|
|
211
|
+
"/farmers/{farmerId}/mechanizations/{mechanizationId}/sensors",
|
|
212
|
+
{
|
|
213
|
+
pathParams: {
|
|
214
|
+
farmerId,
|
|
215
|
+
mechanizationId
|
|
216
|
+
}
|
|
217
|
+
}
|
|
205
218
|
);
|
|
206
219
|
return R2.Ok(
|
|
207
220
|
mappers.getMotorizedMechanizationSensors(
|