@agroyaar/sdk 1.0.8-1 → 1.0.8-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 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;
@@ -124,7 +121,7 @@ var createMechanizationServices = (client) => ({
124
121
  getMechanizations: async ({ kindName }) => {
125
122
  try {
126
123
  const { data } = await client.get(
127
- `/farmers/{farmerId}/mechanizations?kindName=${kindName}`
124
+ `/farmers/681f11f87eeba74f9bb8f422/mechanizations?kindName=${kindName}`
128
125
  );
129
126
  return import_ts_belt.R.Ok(
130
127
  mappers.getMechanizationsList(data.result.data.mechanizations)
@@ -138,8 +135,8 @@ var createMechanizationServices = (client) => ({
138
135
  });
139
136
 
140
137
  // src/index.ts
141
- var createSDK = (config) => {
142
- const client = createClient(config);
138
+ var createSDK = (config, middlewares = []) => {
139
+ const client = createClient(config, middlewares);
143
140
  return {
144
141
  dashboardServices: {
145
142
  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> = {
@@ -64,10 +66,10 @@ type MechanizationVariables = {
64
66
 
65
67
  type ClientConfig = {
66
68
  readonly baseURL: string;
67
- readonly token?: string;
68
69
  };
70
+ declare const createClient: (config: ClientConfig, middlewares?: ((_config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig)[]) => axios.AxiosInstance;
69
71
 
70
- declare const createSDK: (config: ClientConfig) => {
72
+ declare const createSDK: (config: ClientConfig, middlewares?: Parameters<typeof createClient>[1]) => {
71
73
  dashboardServices: {
72
74
  mechanization: {
73
75
  getMechanizationVarieties: ({ kindName, }: MechanizationVarietyVariables) => Promise<_mobily_ts_belt.Ok<MechanizationVarietyModel[]> | _mobily_ts_belt.Error<Error>>;
@@ -76,4 +78,4 @@ declare const createSDK: (config: ClientConfig) => {
76
78
  };
77
79
  };
78
80
 
79
- export { type MechanizationMachineUsageKind, type MechanizationMachineUsageType, type MechanizationSeasonProcessKind, type MechanizationSeasonProcessType, type MechanizationType, type MechanizationVarietyModel, type MechanizationVarietyVariables, type ServiceType, type Status, type StatusType, type TaskType, type VarietyKind, createSDK };
81
+ 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;
@@ -88,7 +85,7 @@ var createMechanizationServices = (client) => ({
88
85
  getMechanizations: async ({ kindName }) => {
89
86
  try {
90
87
  const { data } = await client.get(
91
- `/farmers/{farmerId}/mechanizations?kindName=${kindName}`
88
+ `/farmers/681f11f87eeba74f9bb8f422/mechanizations?kindName=${kindName}`
92
89
  );
93
90
  return R.Ok(
94
91
  mappers.getMechanizationsList(data.result.data.mechanizations)
@@ -102,8 +99,8 @@ var createMechanizationServices = (client) => ({
102
99
  });
103
100
 
104
101
  // src/index.ts
105
- var createSDK = (config) => {
106
- const client = createClient(config);
102
+ var createSDK = (config, middlewares = []) => {
103
+ const client = createClient(config, middlewares);
107
104
  return {
108
105
  dashboardServices: {
109
106
  mechanization: createMechanizationServices(client)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agroyaar/sdk",
3
- "version": "1.0.8-1",
3
+ "version": "1.0.8-3",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",