@vitalfit/sdk 0.2.8 → 0.3.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.d.cts CHANGED
@@ -1384,6 +1384,13 @@ declare class PolicyService {
1384
1384
  updatePolicy(policyId: string, data: updatePolicy, jwt: string): Promise<void>;
1385
1385
  }
1386
1386
 
1387
+ declare class AuditService {
1388
+ private client;
1389
+ constructor(client: Client);
1390
+ getAllLogs(jwt: string, userId: string, { page, limit, sort, search }: PaginationRequest): Promise<PaginatedTotal<AuditLog[]>>;
1391
+ getUserLogs(jwt: string, userId: string, { page, limit, sort, search }: PaginationRequest): Promise<PaginatedTotal<AuditLog[]>>;
1392
+ }
1393
+
1387
1394
  declare class APIError extends Error {
1388
1395
  status: number;
1389
1396
  messages: string[];
@@ -1414,6 +1421,7 @@ declare class VitalFit {
1414
1421
  staff: StaffService;
1415
1422
  wishList: WishListService;
1416
1423
  policy: PolicyService;
1424
+ audit: AuditService;
1417
1425
  constructor(isDevMode: boolean, origin?: string);
1418
1426
  static getInstance(isDevMode?: boolean): VitalFit;
1419
1427
  version(): string;
package/dist/index.d.ts CHANGED
@@ -1384,6 +1384,13 @@ declare class PolicyService {
1384
1384
  updatePolicy(policyId: string, data: updatePolicy, jwt: string): Promise<void>;
1385
1385
  }
1386
1386
 
1387
+ declare class AuditService {
1388
+ private client;
1389
+ constructor(client: Client);
1390
+ getAllLogs(jwt: string, userId: string, { page, limit, sort, search }: PaginationRequest): Promise<PaginatedTotal<AuditLog[]>>;
1391
+ getUserLogs(jwt: string, userId: string, { page, limit, sort, search }: PaginationRequest): Promise<PaginatedTotal<AuditLog[]>>;
1392
+ }
1393
+
1387
1394
  declare class APIError extends Error {
1388
1395
  status: number;
1389
1396
  messages: string[];
@@ -1414,6 +1421,7 @@ declare class VitalFit {
1414
1421
  staff: StaffService;
1415
1422
  wishList: WishListService;
1416
1423
  policy: PolicyService;
1424
+ audit: AuditService;
1417
1425
  constructor(isDevMode: boolean, origin?: string);
1418
1426
  static getInstance(isDevMode?: boolean): VitalFit;
1419
1427
  version(): string;
package/dist/index.js CHANGED
@@ -24,12 +24,9 @@ var Client = class {
24
24
  client;
25
25
  isRefreshing = false;
26
26
  failedQueue = [];
27
- // Guardamos los tokens internamente en el cliente
28
27
  accessToken;
29
28
  refreshToken;
30
- // Callback para notificar al frontend (AuthProvider) que los tokens cambiaron
31
29
  onTokenUpdate;
32
- // Callback para forzar logout si el refresh falla
33
30
  onLogout;
34
31
  constructor(isDevMode, origin) {
35
32
  let headers = {
@@ -44,7 +41,6 @@ var Client = class {
44
41
  });
45
42
  this.setupInterceptors();
46
43
  }
47
- // Configurar callbacks desde el AuthProvider
48
44
  setCallbacks(onTokenUpdate, onLogout) {
49
45
  this.onTokenUpdate = onTokenUpdate;
50
46
  this.onLogout = onLogout;
@@ -87,16 +83,19 @@ var Client = class {
87
83
  originalRequest._retry = true;
88
84
  this.isRefreshing = true;
89
85
  try {
90
- const response = await axios.post(`${this.client.defaults.baseURL}/auth/refresh`, {
91
- refresh_token: this.refreshToken
92
- });
93
- const { access_token, refresh_token } = response.data;
94
- this.setTokens(access_token, refresh_token);
86
+ const response = await axios.post(
87
+ `${this.client.defaults.baseURL}/auth/refresh`,
88
+ {
89
+ refresh_token: this.refreshToken
90
+ }
91
+ );
92
+ const { token, refresh_token } = response.data;
93
+ this.setTokens(token, refresh_token);
95
94
  if (this.onTokenUpdate) {
96
- this.onTokenUpdate(access_token, refresh_token);
95
+ this.onTokenUpdate(token, refresh_token);
97
96
  }
98
- this.processQueue(null, access_token);
99
- originalRequest.headers["Authorization"] = `Bearer ${access_token}`;
97
+ this.processQueue(null, token);
98
+ originalRequest.headers["Authorization"] = `Bearer ${token}`;
100
99
  return this.client(originalRequest);
101
100
  } catch (refreshError) {
102
101
  this.processQueue(refreshError, null);
@@ -112,7 +111,7 @@ var Client = class {
112
111
  );
113
112
  }
114
113
  async call(method, config) {
115
- const tokenToUse = this.accessToken || config.jwt;
114
+ const tokenToUse = config.jwt || this.accessToken;
116
115
  const axiosConfig = {
117
116
  method,
118
117
  url: config.url,
@@ -2175,6 +2174,42 @@ var PolicyService = class {
2175
2174
  }
2176
2175
  };
2177
2176
 
2177
+ // src/services/audit.ts
2178
+ var AuditService = class {
2179
+ client;
2180
+ constructor(client) {
2181
+ this.client = client;
2182
+ this.getUserLogs = this.getUserLogs.bind(this);
2183
+ this.getAllLogs = this.getAllLogs.bind(this);
2184
+ }
2185
+ async getAllLogs(jwt, userId, { page = 10, limit = 10, sort = "desc", search }) {
2186
+ const response = await this.client.get({
2187
+ url: `/audit-logs`,
2188
+ jwt,
2189
+ params: {
2190
+ page,
2191
+ limit,
2192
+ sort,
2193
+ search
2194
+ }
2195
+ });
2196
+ return response;
2197
+ }
2198
+ async getUserLogs(jwt, userId, { page = 10, limit = 10, sort = "desc", search }) {
2199
+ const response = await this.client.get({
2200
+ url: `/audit-logs/user/${userId}`,
2201
+ jwt,
2202
+ params: {
2203
+ page,
2204
+ limit,
2205
+ sort,
2206
+ search
2207
+ }
2208
+ });
2209
+ return response;
2210
+ }
2211
+ };
2212
+
2178
2213
  // src/types/auth.ts
2179
2214
  var UserGender = /* @__PURE__ */ ((UserGender2) => {
2180
2215
  UserGender2["male"] = "male";
@@ -2299,6 +2334,7 @@ var VitalFit = class _VitalFit {
2299
2334
  staff;
2300
2335
  wishList;
2301
2336
  policy;
2337
+ audit;
2302
2338
  constructor(isDevMode, origin) {
2303
2339
  this.client = new Client(isDevMode, origin);
2304
2340
  this.auth = new AuthService(this.client);
@@ -2321,6 +2357,7 @@ var VitalFit = class _VitalFit {
2321
2357
  this.staff = new StaffService(this.client);
2322
2358
  this.wishList = new WishListService(this.client);
2323
2359
  this.policy = new PolicyService(this.client);
2360
+ this.audit = new AuditService(this.client);
2324
2361
  }
2325
2362
  static getInstance(isDevMode = false) {
2326
2363
  if (!_VitalFit.instance) {
@@ -2329,7 +2366,7 @@ var VitalFit = class _VitalFit {
2329
2366
  return _VitalFit.instance;
2330
2367
  }
2331
2368
  version() {
2332
- return "0.2.8";
2369
+ return "0.3.0";
2333
2370
  }
2334
2371
  };
2335
2372
  export {