@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.cjs +51 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +51 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -64,12 +64,9 @@ var Client = class {
|
|
|
64
64
|
client;
|
|
65
65
|
isRefreshing = false;
|
|
66
66
|
failedQueue = [];
|
|
67
|
-
// Guardamos los tokens internamente en el cliente
|
|
68
67
|
accessToken;
|
|
69
68
|
refreshToken;
|
|
70
|
-
// Callback para notificar al frontend (AuthProvider) que los tokens cambiaron
|
|
71
69
|
onTokenUpdate;
|
|
72
|
-
// Callback para forzar logout si el refresh falla
|
|
73
70
|
onLogout;
|
|
74
71
|
constructor(isDevMode, origin) {
|
|
75
72
|
let headers = {
|
|
@@ -84,7 +81,6 @@ var Client = class {
|
|
|
84
81
|
});
|
|
85
82
|
this.setupInterceptors();
|
|
86
83
|
}
|
|
87
|
-
// Configurar callbacks desde el AuthProvider
|
|
88
84
|
setCallbacks(onTokenUpdate, onLogout) {
|
|
89
85
|
this.onTokenUpdate = onTokenUpdate;
|
|
90
86
|
this.onLogout = onLogout;
|
|
@@ -127,16 +123,19 @@ var Client = class {
|
|
|
127
123
|
originalRequest._retry = true;
|
|
128
124
|
this.isRefreshing = true;
|
|
129
125
|
try {
|
|
130
|
-
const response = await import_axios.default.post(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
126
|
+
const response = await import_axios.default.post(
|
|
127
|
+
`${this.client.defaults.baseURL}/auth/refresh`,
|
|
128
|
+
{
|
|
129
|
+
refresh_token: this.refreshToken
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
const { token, refresh_token } = response.data;
|
|
133
|
+
this.setTokens(token, refresh_token);
|
|
135
134
|
if (this.onTokenUpdate) {
|
|
136
|
-
this.onTokenUpdate(
|
|
135
|
+
this.onTokenUpdate(token, refresh_token);
|
|
137
136
|
}
|
|
138
|
-
this.processQueue(null,
|
|
139
|
-
originalRequest.headers["Authorization"] = `Bearer ${
|
|
137
|
+
this.processQueue(null, token);
|
|
138
|
+
originalRequest.headers["Authorization"] = `Bearer ${token}`;
|
|
140
139
|
return this.client(originalRequest);
|
|
141
140
|
} catch (refreshError) {
|
|
142
141
|
this.processQueue(refreshError, null);
|
|
@@ -152,7 +151,7 @@ var Client = class {
|
|
|
152
151
|
);
|
|
153
152
|
}
|
|
154
153
|
async call(method, config) {
|
|
155
|
-
const tokenToUse =
|
|
154
|
+
const tokenToUse = config.jwt || this.accessToken;
|
|
156
155
|
const axiosConfig = {
|
|
157
156
|
method,
|
|
158
157
|
url: config.url,
|
|
@@ -2215,6 +2214,42 @@ var PolicyService = class {
|
|
|
2215
2214
|
}
|
|
2216
2215
|
};
|
|
2217
2216
|
|
|
2217
|
+
// src/services/audit.ts
|
|
2218
|
+
var AuditService = class {
|
|
2219
|
+
client;
|
|
2220
|
+
constructor(client) {
|
|
2221
|
+
this.client = client;
|
|
2222
|
+
this.getUserLogs = this.getUserLogs.bind(this);
|
|
2223
|
+
this.getAllLogs = this.getAllLogs.bind(this);
|
|
2224
|
+
}
|
|
2225
|
+
async getAllLogs(jwt, userId, { page = 10, limit = 10, sort = "desc", search }) {
|
|
2226
|
+
const response = await this.client.get({
|
|
2227
|
+
url: `/audit-logs`,
|
|
2228
|
+
jwt,
|
|
2229
|
+
params: {
|
|
2230
|
+
page,
|
|
2231
|
+
limit,
|
|
2232
|
+
sort,
|
|
2233
|
+
search
|
|
2234
|
+
}
|
|
2235
|
+
});
|
|
2236
|
+
return response;
|
|
2237
|
+
}
|
|
2238
|
+
async getUserLogs(jwt, userId, { page = 10, limit = 10, sort = "desc", search }) {
|
|
2239
|
+
const response = await this.client.get({
|
|
2240
|
+
url: `/audit-logs/user/${userId}`,
|
|
2241
|
+
jwt,
|
|
2242
|
+
params: {
|
|
2243
|
+
page,
|
|
2244
|
+
limit,
|
|
2245
|
+
sort,
|
|
2246
|
+
search
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
return response;
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
|
|
2218
2253
|
// src/types/auth.ts
|
|
2219
2254
|
var UserGender = /* @__PURE__ */ ((UserGender2) => {
|
|
2220
2255
|
UserGender2["male"] = "male";
|
|
@@ -2339,6 +2374,7 @@ var VitalFit = class _VitalFit {
|
|
|
2339
2374
|
staff;
|
|
2340
2375
|
wishList;
|
|
2341
2376
|
policy;
|
|
2377
|
+
audit;
|
|
2342
2378
|
constructor(isDevMode, origin) {
|
|
2343
2379
|
this.client = new Client(isDevMode, origin);
|
|
2344
2380
|
this.auth = new AuthService(this.client);
|
|
@@ -2361,6 +2397,7 @@ var VitalFit = class _VitalFit {
|
|
|
2361
2397
|
this.staff = new StaffService(this.client);
|
|
2362
2398
|
this.wishList = new WishListService(this.client);
|
|
2363
2399
|
this.policy = new PolicyService(this.client);
|
|
2400
|
+
this.audit = new AuditService(this.client);
|
|
2364
2401
|
}
|
|
2365
2402
|
static getInstance(isDevMode = false) {
|
|
2366
2403
|
if (!_VitalFit.instance) {
|
|
@@ -2369,7 +2406,7 @@ var VitalFit = class _VitalFit {
|
|
|
2369
2406
|
return _VitalFit.instance;
|
|
2370
2407
|
}
|
|
2371
2408
|
version() {
|
|
2372
|
-
return "0.
|
|
2409
|
+
return "0.3.0";
|
|
2373
2410
|
}
|
|
2374
2411
|
};
|
|
2375
2412
|
// Annotate the CommonJS export names for ESM import in node:
|